json-rules-engine-simplified
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.JSONSchemaForm=t():e.JSONSchemaForm=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="/dist/",t(t.s=5)}([function(e,t,r){"use strict";function n(e){return"object"===(void 0===e?"undefined":s(e))&&null!==e}function o(){return!1}function u(e){if(o())throw new ReferenceError(e);console.error(e)}function i(e,t){return t.properties[e]&&"array"===t.properties[e].type&&t.properties[e].items&&t.properties[e].items.$ref}function c(e,t){return e.split("/").filter(function(e){return"#"!==e}).reduce(function(e,t){return e[t]},t)}function a(e,t){return i(e,t)?c(t.properties[e].items.$ref,t):t.properties[e]&&t.properties[e].$ref?c(t.properties[e].$ref,t):void 0}Object.defineProperty(t,"__esModule",{value:!0});var s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};t.isObject=n,t.isDevelopment=o,t.toError=u,t.isRefArray=i,t.extractRefSchema=a;var f=function(e,t){return e.concat(t)};t.flatMap=function(e,t){return e.map(t).reduce(f,[])}},function(e,t,r){"use strict";var n=e.exports,o=Array.prototype.slice,u=function(e,t){return e.toString=function(){return t.toString()},e.src=t,e},i=n.curry=function(e){return u(function(t,r){switch(arguments.length){case 0:throw new TypeError("Function called with no arguments");case 1:return u(function(r){return e(t,r)},e)}return e(t,r)},e)};n.partial=function(e){var t=o.call(arguments,1);return function(){return e.apply(null,t.concat(o.call(arguments)))}},n.complement=n.invert=function(e){return function(){var t=e.apply(null,arguments);return"function"==typeof t?n.complement(t):!t}},n.mod=i(function(e,t){return e%t}),n.assign=i(function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);return e})},function(e,t,r){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o=r(1),u=e.exports,i=o.curry;Object.is?u.is=i(Object.is):u.is=i(function(e,t){return 0===e&&0===t?1/e==1/t:e!==e?t!==t:e===t}),u.exists=function(e){return null!=e},u.truthy=function(e){return!(!e||!u.exists(e))},u.falsey=o.complement(u.truthy),u.equal=i(function(e,t){return e===t}),u.eq=i(function(e,t){return e==t}),u.null=u.equal(null),u.undef=u.equal(void 0),u.lt=u.less=i(function(e,t){return e<t}),u.ltEq=u.le=u.lessEq=i(function(e,t){return u.equal(e,t)||u.less(e,t)}),u.gt=u.greater=i(function(e,t){return e>t}),u.gtEq=u.ge=u.greaterEq=i(function(e,t){return u.equal(e,t)||u.greater(e,t)});var c=Object.prototype.toString,a=i(function(e,t){return u.equal(e,c.call(t))});u.object=u.obj=function(e){return e===Object(e)},u.array=u.arr=Array.isArray||a("[object Array]"),u.date=a("[object Date]"),u.regex=u.regexp=u.rgx=u.RegExp=a("[object RegExp]"),u.finite=Number.isFinite||function(e){return u.number(e)&&isFinite(e)},u.nan=u.NaN=u.is(NaN),u.instance=i(function(e,t){return t instanceof e}),u.arguments=a("[object Arguments]"),u.error=u.instance(Error);var s=i(function(e,t){return u.equal(e,void 0===t?"undefined":n(t))});[["function","fn"],["string","str"],["boolean","bool"]].reduce(function(e,t){return e[t[0]]=e[t[1]]=s(t[0]),e},u),u.number=u.num=function(e){return"number"==typeof e&&u.not.NaN(e)},u.int=function(e){return u.num(e)&&u.zero(o.mod(e,1))},u.pos=function(e){return u.num(e)&&u.greater(e,0)},u.neg=function(e){return u.num(e)&&u.less(e,0)},u.zero=function(e){return u.num(e)&&u.equal(e,0)},u.even=function(e){return u.num(e)&&u.not.zero(e)&&u.zero(o.mod(e,2))},u.odd=function(e){return u.num(e)&&u.not.zero(e)&&u.not.zero(o.mod(e,2))},u.contains=i(function(e,t){if(!u.array(e))throw new TypeError("Expected an array");return u.NaN(t)?e.some(u.NaN):!!~e.indexOf(t)});var f=Object.prototype.hasOwnProperty;u.has=i(function(e,t){return f.call(e,t)}),u.empty=function(e){if(u.not.exists(e))return!0;if(u.arr(e)||u.str(e))return!e.length;if(u.obj(e)){for(var t in e)if(u.has(e,t))return!1;return!0}throw new TypeError},u.primitive=function(e){return u.string(e)||u.num(e)||u.bool(e)||u.null(e)||u.undef(e)||u.NaN(e)},u.matches=i(function(e,t){return e.test(t)}),u.not=Object.keys(u).reduce(function(e,t){return e[t]=o.complement(u[t]),e},{})},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.OR="or",t.AND="and",t.NOT="not"},function(e,t,r){"use strict";var n=r(1),o={};o.VERSION="1.0.0",[n,r(2),r(8),r(9)].reduce(n.assign,o),e.exports=o},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(6),o=function(e){return e&&e.__esModule?e:{default:e}}(n);t.default=o.default},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var o=r(7),u=r(10),i=function(e){return e&&e.__esModule?e:{default:e}}(u),c=r(0),a=function e(t,r){var u=this;if(n(this,e),this.run=function(e){return Promise.resolve((0,i.default)(u.rules,e))},this.rules=t,(0,c.isDevelopment)()){var a=t.map(function(e){return e.conditions});void 0!==r&&null!==r&&((0,c.isObject)(r)?((0,o.validatePredicates)(a,r),(0,o.validateConditionFields)(a,r)):(0,c.toError)("Expected valid schema object, but got - "+r))}};t.default=a},function(e,t,r){"use strict";function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){return(0,m.isObject)(e)?(0,m.flatMap)(Object.keys(e),function(r){var n=e[r];if((0,m.isObject)(n)||r===h.NOT){if(r===h.OR||r===h.AND)return Array.isArray(n)?(0,m.flatMap)(n,function(e){return o(e,t)}):((0,m.toError)('"'+r+'" must be an array'),[]);var u=o(n,t);return u.push(r),u}return o(r,t)}):[e]}function u(e,t){return(0,m.flatMap)(Object.keys(e),function(r){var i=e[r];if(r===h.OR||r===h.AND)return Array.isArray(i)?(0,m.flatMap)(i,function(e){return u(e,t)}):((0,m.toError)(r+" with "+JSON.stringify(i)+" must be an Array"),[]);if(r===h.NOT)return u(i,t);if(-1!==r.indexOf(".")){var c=r.indexOf("."),a=r.substr(0,c),s=(0,m.extractRefSchema)(a,t);if(s){return u(n({},r.substr(c+1),i),s)}return(0,m.toError)("Can't find schema for "+a),[]}if((0,m.isRefArray)(r,t)){var f=(0,m.extractRefSchema)(r,t);return f?u(i,f):[]}return t.properties[r]?o(i,t):((0,m.toError)("Can't validate "+r),[])})}function i(e,t){var r=(0,m.flatMap)(e,function(e){return u(e,t)});return r.filter(function(e,t,n){return r.indexOf(e)===t})}function c(e,t){return i(e,t).filter(function(e){return void 0===y.default[e]})}function a(e,t){var r=c(e,t);0!==r.length&&(0,m.toError)("Rule contains invalid predicates "+r)}function s(e){return(0,m.flatMap)(Object.keys(e),function(t){return t===h.OR||t===h.AND?(0,m.flatMap)(e[t],function(e){return s(e)}):t===h.NOT?s(e[t]):-1===t.indexOf(".")?[t]:[]})}function f(e){var t=(0,m.flatMap)(e,function(e){return s(e)});return t.filter(function(e,r,n){return t.indexOf(e)===r})}function l(e,t){return f(e).filter(function(e){return void 0===t.properties[e]})}function p(e,t){var r=l(e,t);0!==r.length&&(0,m.toError)("Rule contains invalid fields "+r)}Object.defineProperty(t,"__esModule",{value:!0}),t.predicatesFromRule=o,t.predicatesFromCondition=u,t.listAllPredicates=i,t.listInvalidPredicates=c,t.validatePredicates=a,t.fieldsFromCondition=s,t.listAllFields=f,t.listInvalidFields=l,t.validateConditionFields=p;var d=r(4),y=function(e){return e&&e.__esModule?e:{default:e}}(d),m=r(0),h=r(3)},function(e,t,r){"use strict";function n(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function o(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),c=r(2),a=e.exports,s=function(){function e(){u(this,e),this.lazy=[]}return i(e,[{key:"valueOf",value:function(){return this.val()}},{key:"val",value:function(){return this.lazy.map(function(e){return e[0].apply(null,e[1])})[this.method](c.truthy)}}]),e}(),f=function(e){function t(){u(this,t);var e=n(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return e.method="every",e}return o(t,e),t}(s),l=function(e){function t(){u(this,t);var e=n(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return e.method="some",e}return o(t,e),t}(s);[f,l].forEach(function(e){Object.keys(c).reduce(function(e,t){return c.fn(c[t])?(e[t]=function(){return this.lazy.push([c[t],arguments]),this},e):e},e.prototype)}),a.all=a.every=function(){return new f},a.any=a.some=function(){return new l}},function(e,t,r){"use strict";var n=r(2),o=r(1),u=e.exports;u.ternary=function(e,t,r){return n.bool(e)?e?t:r:n.undef(t)?o.partial(u.ternary,e):n.undef(r)?o.partial(u.ternary,e,t):u.ternary(e(t,r),t,r)}},function(e,t,r){"use strict";function n(e,t){return(0,o.flatMap)(e,function(e){var r=e.conditions,n=e.event;return(0,i.default)(r,t)?[n]:[]})}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n;var o=r(0),u=r(11),i=function(e){return e&&e.__esModule?e:{default:e}}(u)},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e,t){return(0,u.isObject)(e)&&(0,u.isObject)(t)||(0,u.toError)("Rule "+e+" with "+t+" can't be processed"),Object.keys(e).every(function(r){var n=e[r];if(r===a.OR)return n.some(function(e){return o(e,t)});if(r===a.AND)return n.every(function(e){return o(e,t)});if(r===a.NOT)return!o(n,t);var u=(0,f.default)(r,t);return Array.isArray(u)?u.some(function(e){return o(n,e)}):(0,c.default)(u,n)})}Object.defineProperty(t,"__esModule",{value:!0}),t.default=o;var u=r(0),i=r(12),c=n(i),a=r(3),s=r(13),f=n(s)},function(e,t,r){"use strict";function n(e,t){return Array.isArray(e)?e.some(function(e){return n(e,t)}):(0,i.isObject)(t)?Object.keys(t).every(function(r){var o=t[r];return r===c.OR||r===c.AND?!!Array.isArray(o)&&(r===c.OR?o.some(function(t){return n(e,t)}):o.every(function(t){return n(e,t)})):r===c.NOT?!n(e,o):!!u.default[r]&&u.default[r](e,o)}):u.default[t](e)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n;var o=r(4),u=function(e){return e&&e.__esModule?e:{default:e}}(o),i=r(0),c=r(3)},function(e,t,r){"use strict";function n(e,t){u("arguments:",{path:e,object:t});for(var r=-1,n="[object Array]"===a.call(e)?e:c(i(e)),o=n.length,s=o?t:void 0;++r<o;){if(Object(s)!==s)return;s=s[n[r]]}return u("ref:",s),"function"==typeof s?s():s}var o=r(14),u=r(16)("selectn"),i=r(20),c=r(21),a=Object.prototype.toString;e.exports=o(n)},function(e,t,r){"use strict";function n(e,t){var r=function r(){return 0===arguments.length?r:arguments.length>1?e.apply(t,arguments):o.call(e,t,arguments[0])};return r.uncurry=function(){return e},r}/*! | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.JSONSchemaForm=t():e.JSONSchemaForm=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="/dist/",t(t.s=5)}([function(e,t,r){"use strict";function n(e){return"object"===(void 0===e?"undefined":f(e))&&null!==e}function o(){return!1}function u(e){return Array.isArray(e)?e:[e]}function i(e){if(o())throw new ReferenceError(e);console.error(e)}function c(e,t){return t.properties[e]&&"array"===t.properties[e].type&&t.properties[e].items&&t.properties[e].items.$ref}function s(e,t){return e.startsWith("#/")?(e.substr(2).split("/"),e.substr(2).split("/").reduce(function(e,t){return e[t]},t)):void i("Only local references supported at this point use json-schema-deref")}function a(e,t){return c(e,t)?s(t.properties[e].items.$ref,t):t.properties[e]&&t.properties[e].$ref?s(t.properties[e].$ref,t):void i(e+" has no $ref field ref schema extraction is impossible")}Object.defineProperty(t,"__esModule",{value:!0});var f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};t.isObject=n,t.isDevelopment=o,t.toArray=u,t.toError=i,t.isRefArray=c,t.extractRefSchema=a;var l=function(e,t){return e.concat(t)};t.flatMap=function(e,t){return e.map(t).reduce(l,[])}},function(e,t,r){"use strict";var n=e.exports,o=Array.prototype.slice,u=function(e,t){return e.toString=function(){return t.toString()},e.src=t,e},i=n.curry=function(e){return u(function(t,r){switch(arguments.length){case 0:throw new TypeError("Function called with no arguments");case 1:return u(function(r){return e(t,r)},e)}return e(t,r)},e)};n.partial=function(e){var t=o.call(arguments,1);return function(){return e.apply(null,t.concat(o.call(arguments)))}},n.complement=n.invert=function(e){return function(){var t=e.apply(null,arguments);return"function"==typeof t?n.complement(t):!t}},n.mod=i(function(e,t){return e%t}),n.assign=i(function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);return e})},function(e,t,r){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o=r(1),u=e.exports,i=o.curry;Object.is?u.is=i(Object.is):u.is=i(function(e,t){return 0===e&&0===t?1/e==1/t:e!==e?t!==t:e===t}),u.exists=function(e){return null!=e},u.truthy=function(e){return!(!e||!u.exists(e))},u.falsey=o.complement(u.truthy),u.equal=i(function(e,t){return e===t}),u.eq=i(function(e,t){return e==t}),u.null=u.equal(null),u.undef=u.equal(void 0),u.lt=u.less=i(function(e,t){return e<t}),u.ltEq=u.le=u.lessEq=i(function(e,t){return u.equal(e,t)||u.less(e,t)}),u.gt=u.greater=i(function(e,t){return e>t}),u.gtEq=u.ge=u.greaterEq=i(function(e,t){return u.equal(e,t)||u.greater(e,t)});var c=Object.prototype.toString,s=i(function(e,t){return u.equal(e,c.call(t))});u.object=u.obj=function(e){return e===Object(e)},u.array=u.arr=Array.isArray||s("[object Array]"),u.date=s("[object Date]"),u.regex=u.regexp=u.rgx=u.RegExp=s("[object RegExp]"),u.finite=Number.isFinite||function(e){return u.number(e)&&isFinite(e)},u.nan=u.NaN=u.is(NaN),u.instance=i(function(e,t){return t instanceof e}),u.arguments=s("[object Arguments]"),u.error=u.instance(Error);var a=i(function(e,t){return u.equal(e,void 0===t?"undefined":n(t))});[["function","fn"],["string","str"],["boolean","bool"]].reduce(function(e,t){return e[t[0]]=e[t[1]]=a(t[0]),e},u),u.number=u.num=function(e){return"number"==typeof e&&u.not.NaN(e)},u.int=function(e){return u.num(e)&&u.zero(o.mod(e,1))},u.pos=function(e){return u.num(e)&&u.greater(e,0)},u.neg=function(e){return u.num(e)&&u.less(e,0)},u.zero=function(e){return u.num(e)&&u.equal(e,0)},u.even=function(e){return u.num(e)&&u.not.zero(e)&&u.zero(o.mod(e,2))},u.odd=function(e){return u.num(e)&&u.not.zero(e)&&u.not.zero(o.mod(e,2))},u.contains=i(function(e,t){if(!u.array(e))throw new TypeError("Expected an array");return u.NaN(t)?e.some(u.NaN):!!~e.indexOf(t)});var f=Object.prototype.hasOwnProperty;u.has=i(function(e,t){return f.call(e,t)}),u.empty=function(e){if(u.not.exists(e))return!0;if(u.arr(e)||u.str(e))return!e.length;if(u.obj(e)){for(var t in e)if(u.has(e,t))return!1;return!0}throw new TypeError},u.primitive=function(e){return u.string(e)||u.num(e)||u.bool(e)||u.null(e)||u.undef(e)||u.NaN(e)},u.matches=i(function(e,t){return e.test(t)}),u.not=Object.keys(u).reduce(function(e,t){return e[t]=o.complement(u[t]),e},{})},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.OR="or",t.AND="and",t.NOT="not"},function(e,t,r){"use strict";var n=r(1),o={};o.VERSION="1.0.0",[n,r(2),r(8),r(9)].reduce(n.assign,o),e.exports=o},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(6),o=function(e){return e&&e.__esModule?e:{default:e}}(n);t.default=o.default},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var o=r(7),u=r(10),i=function(e){return e&&e.__esModule?e:{default:e}}(u),c=r(0),s=function e(t,r){var u=this;if(n(this,e),this.run=function(e){return Promise.resolve((0,i.default)(u.rules,e))},this.rules=t,(0,c.isDevelopment)()){var s=t.map(function(e){return e.conditions});void 0!==r&&null!==r&&((0,c.isObject)(r)?((0,o.validatePredicates)(s,r),(0,o.validateConditionFields)(s,r)):(0,c.toError)("Expected valid schema object, but got - "+r))}};t.default=s},function(e,t,r){"use strict";function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){return(0,m.isObject)(e)?(0,m.flatMap)(Object.keys(e),function(r){var n=e[r];if((0,m.isObject)(n)||r===h.NOT){if(r===h.OR||r===h.AND)return Array.isArray(n)?(0,m.flatMap)(n,function(e){return o(e,t)}):((0,m.toError)('"'+r+'" must be an array'),[]);var u=o(n,t);return u.push(r),u}return o(r,t)}):[e]}function u(e,t){return(0,m.flatMap)(Object.keys(e),function(r){var i=e[r];if(r===h.OR||r===h.AND)return Array.isArray(i)?(0,m.flatMap)(i,function(e){return u(e,t)}):((0,m.toError)(r+" with "+JSON.stringify(i)+" must be an Array"),[]);if(r===h.NOT)return u(i,t);if(-1!==r.indexOf(".")){var c=r.indexOf("."),s=r.substr(0,c),a=(0,m.extractRefSchema)(s,t);if(a){return u(n({},r.substr(c+1),i),a)}return(0,m.toError)("Can't find schema for "+s),[]}if((0,m.isRefArray)(r,t)){var f=(0,m.extractRefSchema)(r,t);return f?u(i,f):[]}return t.properties[r]?o(i,t):((0,m.toError)("Can't validate "+r),[])})}function i(e,t){var r=(0,m.flatMap)(e,function(e){return u(e,t)});return r.filter(function(e,t,n){return r.indexOf(e)===t})}function c(e,t){return i(e,t).filter(function(e){return void 0===y.default[e]})}function s(e,t){var r=c(e,t);0!==r.length&&(0,m.toError)("Rule contains invalid predicates "+r)}function a(e){return(0,m.flatMap)(Object.keys(e),function(t){return t===h.OR||t===h.AND?(0,m.flatMap)(e[t],function(e){return a(e)}):t===h.NOT?a(e[t]):-1===t.indexOf(".")?[t]:[]})}function f(e){var t=(0,m.flatMap)(e,function(e){return a(e)});return t.filter(function(e,r,n){return t.indexOf(e)===r})}function l(e,t){return f(e).filter(function(e){return void 0===t.properties[e]})}function p(e,t){var r=l(e,t);0!==r.length&&(0,m.toError)("Rule contains invalid fields "+r)}Object.defineProperty(t,"__esModule",{value:!0}),t.predicatesFromRule=o,t.predicatesFromCondition=u,t.listAllPredicates=i,t.listInvalidPredicates=c,t.validatePredicates=s,t.fieldsFromCondition=a,t.listAllFields=f,t.listInvalidFields=l,t.validateConditionFields=p;var d=r(4),y=function(e){return e&&e.__esModule?e:{default:e}}(d),m=r(0),h=r(3)},function(e,t,r){"use strict";function n(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function o(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),c=r(2),s=e.exports,a=function(){function e(){u(this,e),this.lazy=[]}return i(e,[{key:"valueOf",value:function(){return this.val()}},{key:"val",value:function(){return this.lazy.map(function(e){return e[0].apply(null,e[1])})[this.method](c.truthy)}}]),e}(),f=function(e){function t(){u(this,t);var e=n(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return e.method="every",e}return o(t,e),t}(a),l=function(e){function t(){u(this,t);var e=n(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return e.method="some",e}return o(t,e),t}(a);[f,l].forEach(function(e){Object.keys(c).reduce(function(e,t){return c.fn(c[t])?(e[t]=function(){return this.lazy.push([c[t],arguments]),this},e):e},e.prototype)}),s.all=s.every=function(){return new f},s.any=s.some=function(){return new l}},function(e,t,r){"use strict";var n=r(2),o=r(1),u=e.exports;u.ternary=function(e,t,r){return n.bool(e)?e?t:r:n.undef(t)?o.partial(u.ternary,e):n.undef(r)?o.partial(u.ternary,e,t):u.ternary(e(t,r),t,r)}},function(e,t,r){"use strict";function n(e,t){return(0,o.flatMap)(e,function(e){var r=e.conditions,n=e.event;return(0,i.default)(r,t)?(0,o.toArray)(n):[]})}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n;var o=r(0),u=r(11),i=function(e){return e&&e.__esModule?e:{default:e}}(u)},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e,t){return(0,u.isObject)(e)&&(0,u.isObject)(t)||(0,u.toError)("Rule "+JSON.stringify(e)+" with "+t+" can't be processed"),Object.keys(e).every(function(r){var n=e[r];if(r===s.OR)return n.some(function(e){return o(e,t)});if(r===s.AND)return n.every(function(e){return o(e,t)});if(r===s.NOT)return!o(n,t);var u=(0,f.default)(r,t);return Array.isArray(u)?u.some(function(e){return o(n,e)}):(0,c.default)(u,n)})}Object.defineProperty(t,"__esModule",{value:!0}),t.default=o;var u=r(0),i=r(12),c=n(i),s=r(3),a=r(13),f=n(a)},function(e,t,r){"use strict";function n(e,t){return Array.isArray(e)?e.some(function(e){return n(e,t)}):(0,i.isObject)(t)?Object.keys(t).every(function(r){var o=t[r];return r===c.OR||r===c.AND?!!Array.isArray(o)&&(r===c.OR?o.some(function(t){return n(e,t)}):o.every(function(t){return n(e,t)})):r===c.NOT?!n(e,o):!!u.default[r]&&u.default[r](e,o)}):u.default[t](e)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n;var o=r(4),u=function(e){return e&&e.__esModule?e:{default:e}}(o),i=r(0),c=r(3)},function(e,t,r){"use strict";function n(e,t){u("arguments:",{path:e,object:t});for(var r=-1,n="[object Array]"===s.call(e)?e:c(i(e)),o=n.length,a=o?t:void 0;++r<o;){if(Object(a)!==a)return;a=a[n[r]]}return u("ref:",a),"function"==typeof a?a():a}var o=r(14),u=r(16)("selectn"),i=r(20),c=r(21),s=Object.prototype.toString;e.exports=o(n)},function(e,t,r){"use strict";function n(e,t){var r=function r(){return 0===arguments.length?r:arguments.length>1?e.apply(t,arguments):o.call(e,t,arguments[0])};return r.uncurry=function(){return e},r}/*! | ||
* imports. | ||
@@ -7,3 +7,3 @@ */ | ||
*/ | ||
e.exports=n},function(e,t,r){"use strict";e.exports=function(e){var t,r=this;if(arguments.length<2)t=function(){if(this instanceof t){var n=r.apply(this,arguments);return Object(n)===n?n:this}return r.apply(e,arguments)};else{for(var n=new Array(arguments.length-1),o=1;o<arguments.length;o++)n[o-1]=arguments[o];t=function(){var o,u=n.length,i=new Array(u+arguments.length);for(o=0;o<u;o++)i[o]=n[o];for(o=0;o<arguments.length;o++)i[u+o]=arguments[o];if(this instanceof t){var c=r.apply(this,i);return Object(c)===c?c:this}return r.apply(e,i)}}return t.prototype=r.prototype,t}},function(e,t,r){"use strict";(function(n){function o(){return!("undefined"==typeof window||!window.process||"renderer"!==window.process.type)||("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))}function u(e){var r=this.useColors;if(e[0]=(r?"%c":"")+this.namespace+(r?" %c":" ")+e[0]+(r?"%c ":" ")+"+"+t.humanize(this.diff),r){var n="color: "+this.color;e.splice(1,0,n,"color: inherit");var o=0,u=0;e[0].replace(/%[a-zA-Z%]/g,function(e){"%%"!==e&&(o++,"%c"===e&&(u=o))}),e.splice(u,0,n)}}function i(){return"object"===("undefined"==typeof console?"undefined":s(console))&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function c(e){try{null==e?t.storage.removeItem("debug"):t.storage.debug=e}catch(e){}}function a(){var e;try{e=t.storage.debug}catch(e){}return!e&&void 0!==n&&"env"in n&&(e=Object({NODE_ENV:"production"}).DEBUG),e}var s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};t=e.exports=r(18),t.log=i,t.formatArgs=u,t.save=c,t.load=a,t.useColors=o,t.storage="undefined"!=typeof chrome&&void 0!==chrome.storage?chrome.storage.local:function(){try{return window.localStorage}catch(e){}}(),t.colors=["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"],t.formatters.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}},t.enable(a())}).call(t,r(17))},function(e,t,r){"use strict";function n(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function u(e){if(l===setTimeout)return setTimeout(e,0);if((l===n||!l)&&setTimeout)return l=setTimeout,setTimeout(e,0);try{return l(e,0)}catch(t){try{return l.call(null,e,0)}catch(t){return l.call(this,e,0)}}}function i(e){if(p===clearTimeout)return clearTimeout(e);if((p===o||!p)&&clearTimeout)return p=clearTimeout,clearTimeout(e);try{return p(e)}catch(t){try{return p.call(null,e)}catch(t){return p.call(this,e)}}}function c(){h&&y&&(h=!1,y.length?m=y.concat(m):v=-1,m.length&&a())}function a(){if(!h){var e=u(c);h=!0;for(var t=m.length;t;){for(y=m,m=[];++v<t;)y&&y[v].run();v=-1,t=m.length}y=null,h=!1,i(e)}}function s(e,t){this.fun=e,this.array=t}function f(){}var l,p,d=e.exports={};!function(){try{l="function"==typeof setTimeout?setTimeout:n}catch(e){l=n}try{p="function"==typeof clearTimeout?clearTimeout:o}catch(e){p=o}}();var y,m=[],h=!1,v=-1;d.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];m.push(new s(e,t)),1!==m.length||h||u(a)},s.prototype.run=function(){this.fun.apply(null,this.array)},d.title="browser",d.browser=!0,d.env={},d.argv=[],d.version="",d.versions={},d.on=f,d.addListener=f,d.once=f,d.off=f,d.removeListener=f,d.removeAllListeners=f,d.emit=f,d.prependListener=f,d.prependOnceListener=f,d.listeners=function(e){return[]},d.binding=function(e){throw new Error("process.binding is not supported")},d.cwd=function(){return"/"},d.chdir=function(e){throw new Error("process.chdir is not supported")},d.umask=function(){return 0}},function(e,t,r){"use strict";function n(e){var r,n=0;for(r in e)n=(n<<5)-n+e.charCodeAt(r),n|=0;return t.colors[Math.abs(n)%t.colors.length]}function o(e){function r(){if(r.enabled){var e=r,n=+new Date,o=n-(s||n);e.diff=o,e.prev=s,e.curr=n,s=n;for(var u=new Array(arguments.length),i=0;i<u.length;i++)u[i]=arguments[i];u[0]=t.coerce(u[0]),"string"!=typeof u[0]&&u.unshift("%O");var c=0;u[0]=u[0].replace(/%([a-zA-Z%])/g,function(r,n){if("%%"===r)return r;c++;var o=t.formatters[n];if("function"==typeof o){var i=u[c];r=o.call(e,i),u.splice(c,1),c--}return r}),t.formatArgs.call(e,u);(r.log||t.log||console.log.bind(console)).apply(e,u)}}return r.namespace=e,r.enabled=t.enabled(e),r.useColors=t.useColors(),r.color=n(e),"function"==typeof t.init&&t.init(r),r}function u(e){t.save(e),t.names=[],t.skips=[];for(var r=("string"==typeof e?e:"").split(/[\s,]+/),n=r.length,o=0;o<n;o++)r[o]&&(e=r[o].replace(/\*/g,".*?"),"-"===e[0]?t.skips.push(new RegExp("^"+e.substr(1)+"$")):t.names.push(new RegExp("^"+e+"$")))}function i(){t.enable("")}function c(e){var r,n;for(r=0,n=t.skips.length;r<n;r++)if(t.skips[r].test(e))return!1;for(r=0,n=t.names.length;r<n;r++)if(t.names[r].test(e))return!0;return!1}function a(e){return e instanceof Error?e.stack||e.message:e}t=e.exports=o.debug=o.default=o,t.coerce=a,t.disable=i,t.enable=u,t.enabled=c,t.humanize=r(19),t.names=[],t.skips=[],t.formatters={};var s},function(e,t,r){"use strict";function n(e){if(e=String(e),!(e.length>100)){var t=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(e);if(t){var r=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return r*p;case"days":case"day":case"d":return r*l;case"hours":case"hour":case"hrs":case"hr":case"h":return r*f;case"minutes":case"minute":case"mins":case"min":case"m":return r*s;case"seconds":case"second":case"secs":case"sec":case"s":return r*a;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}}}function o(e){return e>=l?Math.round(e/l)+"d":e>=f?Math.round(e/f)+"h":e>=s?Math.round(e/s)+"m":e>=a?Math.round(e/a)+"s":e+"ms"}function u(e){return i(e,l,"day")||i(e,f,"hour")||i(e,s,"minute")||i(e,a,"second")||e+" ms"}function i(e,t,r){if(!(e<t))return e<1.5*t?Math.floor(e/t)+" "+r:Math.ceil(e/t)+" "+r+"s"}var c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a=1e3,s=60*a,f=60*s,l=24*f,p=365.25*l;e.exports=function(e,t){t=t||{};var r=void 0===e?"undefined":c(e);if("string"===r&&e.length>0)return n(e);if("number"===r&&!1===isNaN(e))return t.long?u(e):o(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},function(e,t,r){"use strict";function n(e){return"[object String]"=={}.toString.call(e)?e.replace(o,".$1").replace(u,""):""}/*! | ||
e.exports=n},function(e,t,r){"use strict";e.exports=function(e){var t,r=this;if(arguments.length<2)t=function(){if(this instanceof t){var n=r.apply(this,arguments);return Object(n)===n?n:this}return r.apply(e,arguments)};else{for(var n=new Array(arguments.length-1),o=1;o<arguments.length;o++)n[o-1]=arguments[o];t=function(){var o,u=n.length,i=new Array(u+arguments.length);for(o=0;o<u;o++)i[o]=n[o];for(o=0;o<arguments.length;o++)i[u+o]=arguments[o];if(this instanceof t){var c=r.apply(this,i);return Object(c)===c?c:this}return r.apply(e,i)}}return t.prototype=r.prototype,t}},function(e,t,r){"use strict";(function(n){function o(){return!("undefined"==typeof window||!window.process||"renderer"!==window.process.type)||("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))}function u(e){var r=this.useColors;if(e[0]=(r?"%c":"")+this.namespace+(r?" %c":" ")+e[0]+(r?"%c ":" ")+"+"+t.humanize(this.diff),r){var n="color: "+this.color;e.splice(1,0,n,"color: inherit");var o=0,u=0;e[0].replace(/%[a-zA-Z%]/g,function(e){"%%"!==e&&(o++,"%c"===e&&(u=o))}),e.splice(u,0,n)}}function i(){return"object"===("undefined"==typeof console?"undefined":a(console))&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function c(e){try{null==e?t.storage.removeItem("debug"):t.storage.debug=e}catch(e){}}function s(){var e;try{e=t.storage.debug}catch(e){}return!e&&void 0!==n&&"env"in n&&(e=Object({NODE_ENV:"production"}).DEBUG),e}var a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};t=e.exports=r(18),t.log=i,t.formatArgs=u,t.save=c,t.load=s,t.useColors=o,t.storage="undefined"!=typeof chrome&&void 0!==chrome.storage?chrome.storage.local:function(){try{return window.localStorage}catch(e){}}(),t.colors=["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"],t.formatters.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}},t.enable(s())}).call(t,r(17))},function(e,t,r){"use strict";function n(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function u(e){if(l===setTimeout)return setTimeout(e,0);if((l===n||!l)&&setTimeout)return l=setTimeout,setTimeout(e,0);try{return l(e,0)}catch(t){try{return l.call(null,e,0)}catch(t){return l.call(this,e,0)}}}function i(e){if(p===clearTimeout)return clearTimeout(e);if((p===o||!p)&&clearTimeout)return p=clearTimeout,clearTimeout(e);try{return p(e)}catch(t){try{return p.call(null,e)}catch(t){return p.call(this,e)}}}function c(){h&&y&&(h=!1,y.length?m=y.concat(m):v=-1,m.length&&s())}function s(){if(!h){var e=u(c);h=!0;for(var t=m.length;t;){for(y=m,m=[];++v<t;)y&&y[v].run();v=-1,t=m.length}y=null,h=!1,i(e)}}function a(e,t){this.fun=e,this.array=t}function f(){}var l,p,d=e.exports={};!function(){try{l="function"==typeof setTimeout?setTimeout:n}catch(e){l=n}try{p="function"==typeof clearTimeout?clearTimeout:o}catch(e){p=o}}();var y,m=[],h=!1,v=-1;d.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];m.push(new a(e,t)),1!==m.length||h||u(s)},a.prototype.run=function(){this.fun.apply(null,this.array)},d.title="browser",d.browser=!0,d.env={},d.argv=[],d.version="",d.versions={},d.on=f,d.addListener=f,d.once=f,d.off=f,d.removeListener=f,d.removeAllListeners=f,d.emit=f,d.prependListener=f,d.prependOnceListener=f,d.listeners=function(e){return[]},d.binding=function(e){throw new Error("process.binding is not supported")},d.cwd=function(){return"/"},d.chdir=function(e){throw new Error("process.chdir is not supported")},d.umask=function(){return 0}},function(e,t,r){"use strict";function n(e){var r,n=0;for(r in e)n=(n<<5)-n+e.charCodeAt(r),n|=0;return t.colors[Math.abs(n)%t.colors.length]}function o(e){function r(){if(r.enabled){var e=r,n=+new Date,o=n-(a||n);e.diff=o,e.prev=a,e.curr=n,a=n;for(var u=new Array(arguments.length),i=0;i<u.length;i++)u[i]=arguments[i];u[0]=t.coerce(u[0]),"string"!=typeof u[0]&&u.unshift("%O");var c=0;u[0]=u[0].replace(/%([a-zA-Z%])/g,function(r,n){if("%%"===r)return r;c++;var o=t.formatters[n];if("function"==typeof o){var i=u[c];r=o.call(e,i),u.splice(c,1),c--}return r}),t.formatArgs.call(e,u);(r.log||t.log||console.log.bind(console)).apply(e,u)}}return r.namespace=e,r.enabled=t.enabled(e),r.useColors=t.useColors(),r.color=n(e),"function"==typeof t.init&&t.init(r),r}function u(e){t.save(e),t.names=[],t.skips=[];for(var r=("string"==typeof e?e:"").split(/[\s,]+/),n=r.length,o=0;o<n;o++)r[o]&&(e=r[o].replace(/\*/g,".*?"),"-"===e[0]?t.skips.push(new RegExp("^"+e.substr(1)+"$")):t.names.push(new RegExp("^"+e+"$")))}function i(){t.enable("")}function c(e){var r,n;for(r=0,n=t.skips.length;r<n;r++)if(t.skips[r].test(e))return!1;for(r=0,n=t.names.length;r<n;r++)if(t.names[r].test(e))return!0;return!1}function s(e){return e instanceof Error?e.stack||e.message:e}t=e.exports=o.debug=o.default=o,t.coerce=s,t.disable=i,t.enable=u,t.enabled=c,t.humanize=r(19),t.names=[],t.skips=[],t.formatters={};var a},function(e,t,r){"use strict";function n(e){if(e=String(e),!(e.length>100)){var t=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(e);if(t){var r=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return r*p;case"days":case"day":case"d":return r*l;case"hours":case"hour":case"hrs":case"hr":case"h":return r*f;case"minutes":case"minute":case"mins":case"min":case"m":return r*a;case"seconds":case"second":case"secs":case"sec":case"s":return r*s;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}}}function o(e){return e>=l?Math.round(e/l)+"d":e>=f?Math.round(e/f)+"h":e>=a?Math.round(e/a)+"m":e>=s?Math.round(e/s)+"s":e+"ms"}function u(e){return i(e,l,"day")||i(e,f,"hour")||i(e,a,"minute")||i(e,s,"second")||e+" ms"}function i(e,t,r){if(!(e<t))return e<1.5*t?Math.floor(e/t)+" "+r:Math.ceil(e/t)+" "+r+"s"}var c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},s=1e3,a=60*s,f=60*a,l=24*f,p=365.25*l;e.exports=function(e,t){t=t||{};var r=void 0===e?"undefined":c(e);if("string"===r&&e.length>0)return n(e);if("number"===r&&!1===isNaN(e))return t.long?u(e):o(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},function(e,t,r){"use strict";function n(e){return"[object String]"=={}.toString.call(e)?e.replace(o,".$1").replace(u,""):""}/*! | ||
* exports. | ||
@@ -10,0 +10,0 @@ */ |
@@ -22,3 +22,3 @@ "use strict"; | ||
if ((0, _conditionsMeet2.default)(conditions, formData)) { | ||
return [event]; | ||
return (0, _utils.toArray)(event); | ||
} else { | ||
@@ -25,0 +25,0 @@ return []; |
@@ -24,3 +24,3 @@ "use strict"; | ||
if (!(0, _utils.isObject)(conditions) || !(0, _utils.isObject)(formData)) { | ||
(0, _utils.toError)("Rule " + conditions + " with " + formData + " can't be processed"); | ||
(0, _utils.toError)("Rule " + JSON.stringify(conditions) + " with " + formData + " can't be processed"); | ||
} | ||
@@ -27,0 +27,0 @@ return Object.keys(conditions).every(function (ref) { |
@@ -11,2 +11,3 @@ "use strict"; | ||
exports.isDevelopment = isDevelopment; | ||
exports.toArray = toArray; | ||
exports.toError = toError; | ||
@@ -23,2 +24,10 @@ exports.isRefArray = isRefArray; | ||
function toArray(event) { | ||
if (Array.isArray(event)) { | ||
return event; | ||
} else { | ||
return [event]; | ||
} | ||
} | ||
function toError(message) { | ||
@@ -37,8 +46,11 @@ if (isDevelopment()) { | ||
function fetchSchema(ref, schema) { | ||
var relevantSchema = ref.split("/"); | ||
return relevantSchema.filter(function (ref) { | ||
return ref !== "#"; | ||
}).reduce(function (schema, field) { | ||
return schema[field]; | ||
}, schema); | ||
if (ref.startsWith("#/")) { | ||
ref.substr(2).split("/"); | ||
return ref.substr(2).split("/").reduce(function (schema, field) { | ||
return schema[field]; | ||
}, schema); | ||
} else { | ||
toError("Only local references supported at this point use json-schema-deref"); | ||
return undefined; | ||
} | ||
} | ||
@@ -52,2 +64,3 @@ | ||
} else { | ||
toError(field + " has no $ref field ref schema extraction is impossible"); | ||
return undefined; | ||
@@ -54,0 +67,0 @@ } |
{ | ||
"name": "json-rules-engine-simplified", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Simpl JSON rules engine", | ||
@@ -17,3 +17,3 @@ "private": false, | ||
"tdd": "jest --watchAll", | ||
"test": "jest" | ||
"test": "jest --coverage" | ||
}, | ||
@@ -64,2 +64,3 @@ "jest": { | ||
"codemirror": "^5.27.4", | ||
"coveralls": "^2.13.1", | ||
"cross-env": "^5.0.1", | ||
@@ -80,3 +81,2 @@ "css-loader": "^0.28.4", | ||
"jsdom": "^11.1.0", | ||
"json-rules-engine": "^2.0.0", | ||
"lint-staged": "^4.0.0", | ||
@@ -83,0 +83,0 @@ "prettier": "^1.5.2", |
@@ -0,1 +1,4 @@ | ||
[![Build Status](https://travis-ci.org/RxNT/json-rules-engine-simplified.svg?branch=master)](https://travis-ci.org/RxNT/json-rules-engine-simplified) | ||
[![Coverage Status](https://coveralls.io/repos/github/RxNT/json-rules-engine-simplified/badge.svg?branch=master)](https://coveralls.io/github/RxNT/json-rules-engine-simplified?branch=master) | ||
[![npm version](https://badge.fury.io/js/json-rules-engine-simplified.svg)](https://badge.fury.io/js/json-rules-engine-simplified) | ||
# json-rules-engine-simplified | ||
@@ -422,4 +425,79 @@ A simple rules engine expressed in JSON | ||
### Extending available predicates | ||
If for some reason the list of [predicates](https://github.com/landau/predicate) is insufficient for your needs, you can extend them pretty easy, | ||
by specifying additional predicates in global import object. | ||
For example, if we want to add `range` predicate, that would verify, that integer value is in range, we can do it like this: | ||
```js | ||
import predicate from "predicate"; | ||
import Engine from "json-rules-engine-simplified"; | ||
predicate.range = predicate.curry((val, range) => { | ||
return predicate.num(val) && | ||
predicate.array(range) && | ||
predicate.equal(range.length, 2) && | ||
predicate.num(range[0]) && | ||
predicate.num(range[1]) && | ||
predicate.greaterEq(val, range[0]) && | ||
predicate.lessEq(val, range[1]); | ||
}); | ||
let engine = new Engine([{ | ||
conditions: { age: { range: [ 20, 40 ] } }, | ||
event: "hit" | ||
}]); | ||
``` | ||
Validation will automatically catch new extension and work as expected. | ||
## Events | ||
Framework does not put any restrictions on event object, that will be triggered, in case conditions are meet | ||
For example, `event` can be a string: | ||
```js | ||
let rules = [{ | ||
conditions: { ... }, | ||
event: "require" | ||
}] | ||
``` | ||
Or number | ||
```js | ||
let rules = [{ | ||
conditions: { ... }, | ||
event: 4 | ||
}] | ||
``` | ||
Or an `object` | ||
```js | ||
let rules = [{ | ||
conditions: { ... }, | ||
event: { | ||
type: "require", | ||
params: { fields: [ "state" ]} | ||
} | ||
}] | ||
``` | ||
You can even return an array of events, each of which will be added to final array of results | ||
```js | ||
let rules = [{ | ||
conditions: { ... }, | ||
event: [ | ||
{ | ||
type: "require", | ||
params: { field: "state"} | ||
}, | ||
{ | ||
type: "remove", | ||
params: { fields: "fake" } | ||
}, | ||
] | ||
}] | ||
``` | ||
## License | ||
The project is licensed under the Apache Licence 2.0. |
Sorry, the diff of this file is not supported yet
185292
433
502