Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-rules-engine-simplified

Package Overview
Dependencies
Maintainers
2
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-rules-engine-simplified - npm Package Compare versions

Comparing version 0.1.10 to 0.1.11

2

dist/json-rules-engine-simplified.js

@@ -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":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):t.properties[e]&&"object"===t.properties[e].type?t.properties[e]: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(Object.assign||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=u.includes=i(function(e,t){if(!u.array(e)&&!u.string(e))throw new TypeError("Expected an array or string");return!(u.string(e)&&!u.string(t))&&(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){var t=void 0!==e&&null!==e;return(0,c.isDevelopment)()&&t?((0,c.isObject)(e)||(0,c.toError)("Expected valid schema object, but got - "+e),function(t){(0,o.validatePredicates)([t.conditions],e),(0,o.validateConditionFields)([t.conditions],e)}):function(){}},a=function e(t,r){var o=this;n(this,e),this.addRule=function(e){o.validate(e),o.rules.push(e)},this.run=function(e){return Promise.resolve((0,i.default)(o.rules,e))},this.rules=[],this.validate=s(r),t&&(0,c.toArray)(t).forEach(function(e){return o.addRule(e)})};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("."),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 v.includes(e)||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),v=["and","or","ternary","every","some","curry","partial","complement","mod"]},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[this.method](function(e){return e[0].apply(null,e[1])})}}]),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)};var i=Array.prototype.every,c=Array.prototype.some;u.and=function(){var e=arguments;return function(t){return i.call(e,function(e){return e(t)})}},u.or=function(){var e=arguments;return function(t){return c.call(e,function(e){return e(t)})}}},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)?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):(0,c.default)(u,n)}):((0,u.toError)("Rule "+JSON.stringify(e)+" with "+t+" can't be processed"),!1)}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){if(Array.isArray(e)){if(e.some(function(e){return s(e,t)}))return!0}return s(e,t)}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),s=function e(t,r){return(0,i.isObject)(r)?Object.keys(r).every(function(n){var o=r[n];return n===c.OR||n===c.AND?!!Array.isArray(o)&&(n===c.OR?o.some(function(r){return e(t,r)}):o.every(function(r){return e(t,r)})):n===c.NOT?!e(t,o):!!u.default[n]&&u.default[n](t,o)}):u.default[r](t)}},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}/*!
!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):t.properties[e]&&"object"===t.properties[e].type?t.properties[e]: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(Object.assign||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=u.includes=i(function(e,t){if(!u.array(e)&&!u.string(e))throw new TypeError("Expected an array or string");return!(u.string(e)&&!u.string(t))&&(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){var t=void 0!==e&&null!==e;return(0,c.isDevelopment)()&&t?((0,c.isObject)(e)||(0,c.toError)("Expected valid schema object, but got - "+e),function(t){(0,o.validatePredicates)([t.conditions],e),(0,o.validateConditionFields)([t.conditions],e)}):function(){}},a=function e(t,r){var o=this;n(this,e),this.addRule=function(e){o.validate(e),o.rules.push(e)},this.run=function(e){return Promise.resolve((0,i.default)(o.rules,e))},this.rules=[],this.validate=s(r),t&&(0,c.toArray)(t).forEach(function(e){return o.addRule(e)})};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,h.isObject)(e)?(0,h.flatMap)(Object.keys(e),function(r){var n=e[r];if((0,h.isObject)(n)||r===v.NOT){if(r===v.OR||r===v.AND)return Array.isArray(n)?(0,h.flatMap)(n,function(e){return o(e,t)}):((0,h.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,h.flatMap)(Object.keys(e),function(r){var i=e[r];if(r===v.OR||r===v.AND)return Array.isArray(i)?(0,h.flatMap)(i,function(e){return u(e,t)}):((0,h.toError)(r+" with "+JSON.stringify(i)+" must be an Array"),[]);if(r===v.NOT)return u(i,t);if(-1!==r.indexOf(".")){var c=r.indexOf("."),s=r.substr(0,c),a=(0,h.extractRefSchema)(s,t);if(a){return u(n({},r.substr(c+1),i),a)}return(0,h.toError)("Can't find schema for "+s),[]}if((0,h.isRefArray)(r,t)){var f=(0,h.extractRefSchema)(r,t);return f?u(i,f):[]}return t.properties[r]?o(i,t):((0,h.toError)("Can't validate "+r),[])})}function i(e,t){var r=(0,h.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 b.includes(e)||void 0===m.default[e]})}function s(e,t){var r=c(e,t);0!==r.length&&(0,h.toError)("Rule contains invalid predicates "+r)}function a(e){return Array.isArray(e)?(0,h.flatMap)(e,a):(0,h.isObject)(e)?(0,h.flatMap)(Object.keys(e),function(t){return a(e[t])}):"string"==typeof e&&e.startsWith("$")?[e.substr(1)]:[]}function f(e){return(0,h.flatMap)(Object.keys(e),function(t){var r=e[t];return t===v.OR||t===v.AND?(0,h.flatMap)(r,f):t===v.NOT?f(r):[t].concat(a(r))})}function l(e){var t=(0,h.flatMap)(e,f);return t.filter(function(e){return-1===e.indexOf(".")}).filter(function(e,r,n){return t.indexOf(e)===r})}function p(e,t){return l(e).filter(function(e){return void 0===t.properties[e]})}function d(e,t){var r=p(e,t);0!==r.length&&(0,h.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.fieldsFromPredicates=a,t.fieldsFromCondition=f,t.listAllFields=l,t.listInvalidFields=p,t.validateConditionFields=d;var y=r(4),m=function(e){return e&&e.__esModule?e:{default:e}}(y),h=r(0),v=r(3),b=["and","or","ternary","every","some","curry","partial","complement","mod"]},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[this.method](function(e){return e[0].apply(null,e[1])})}}]),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)};var i=Array.prototype.every,c=Array.prototype.some;u.and=function(){var e=arguments;return function(t){return i.call(e,function(e){return e(t)})}},u.or=function(){var e=arguments;return function(t){return c.call(e,function(e){return e(t)})}}},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 Array.isArray(e)?e.map(function(e){return o(e,t)}):(0,i.isObject)(e)?Object.keys(e).reduce(function(r,n){return r[n]=o(e[n],t),r},{}):"string"==typeof e&&e.startsWith("$")?(0,l.default)(e.substr(1),t):e}function u(e,t){return(0,i.isObject)(e)&&(0,i.isObject)(t)?Object.keys(e).every(function(r){var n=e[r];if(r===a.OR)return n.some(function(e){return u(e,t)});if(r===a.AND)return n.every(function(e){return u(e,t)});if(r===a.NOT)return!u(n,t);var i=(0,l.default)(r,t);if(Array.isArray(i)){return i.some(function(e){return u(n,e)})||(0,s.default)(i,o(n,t))}return(0,s.default)(i,o(n,t))}):((0,i.toError)("Rule "+JSON.stringify(e)+" with "+t+" can't be processed"),!1)}Object.defineProperty(t,"__esModule",{value:!0}),t.toRelCondition=o,t.default=u;var i=r(0),c=r(12),s=n(c),a=r(3),f=r(13),l=n(f)},function(e,t,r){"use strict";function n(e,t){if(Array.isArray(e)){if(e.some(function(e){return s(e,t)}))return!0}return s(e,t)}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),s=function e(t,r){return(0,i.isObject)(r)?Object.keys(r).every(function(n){var o=r[n];return n===c.OR||n===c.AND?!!Array.isArray(o)&&(n===c.OR?o.some(function(r){return e(t,r)}):o.every(function(r){return e(t,r)})):n===c.NOT?!e(t,o):!!u.default[n]&&u.default[n](t,o)}):u.default[r](t)}},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.

@@ -3,0 +3,0 @@ */

@@ -6,2 +6,3 @@ "use strict";

});
exports.toRelCondition = toRelCondition;
exports.default = conditionsMeet;

@@ -23,2 +24,19 @@

function toRelCondition(refCondition, formData) {
if (Array.isArray(refCondition)) {
return refCondition.map(function (cond) {
return toRelCondition(cond, formData);
});
} else if ((0, _utils.isObject)(refCondition)) {
return Object.keys(refCondition).reduce(function (agg, field) {
agg[field] = toRelCondition(refCondition[field], formData);
return agg;
}, {});
} else if (typeof refCondition === "string" && refCondition.startsWith("$")) {
return (0, _selectn2.default)(refCondition.substr(1), formData);
} else {
return refCondition;
}
}
function conditionsMeet(condition, formData) {

@@ -44,7 +62,8 @@ if (!(0, _utils.isObject)(condition) || !(0, _utils.isObject)(formData)) {

if (Array.isArray(refVal)) {
return refVal.some(function (val) {
var condMeatOnce = refVal.some(function (val) {
return conditionsMeet(refCondition, val);
}) || (0, _checkField2.default)(refVal, refCondition);
});
return condMeatOnce || (0, _checkField2.default)(refVal, toRelCondition(refCondition, formData));
} else {
return (0, _checkField2.default)(refVal, refCondition);
return (0, _checkField2.default)(refVal, toRelCondition(refCondition, formData));
}

@@ -51,0 +70,0 @@ }

@@ -11,2 +11,3 @@ "use strict";

exports.validatePredicates = validatePredicates;
exports.fieldsFromPredicates = fieldsFromPredicates;
exports.fieldsFromCondition = fieldsFromCondition;

@@ -29,2 +30,4 @@ exports.listAllFields = listAllFields;

var UNSUPPORTED_PREDICATES = ["and", "or", "ternary", "every", "some", "curry", "partial", "complement", "mod"];
function predicatesFromRule(rule, schema) {

@@ -106,4 +109,2 @@ if ((0, _utils.isObject)(rule)) {

var UNSUPPORTED_PREDICATES = ["and", "or", "ternary", "every", "some", "curry", "partial", "complement", "mod"];
function listInvalidPredicates(conditions, schema) {

@@ -123,14 +124,26 @@ var refPredicates = listAllPredicates(conditions, schema);

function fieldsFromPredicates(predicate) {
if (Array.isArray(predicate)) {
return (0, _utils.flatMap)(predicate, fieldsFromPredicates);
} else if ((0, _utils.isObject)(predicate)) {
return (0, _utils.flatMap)(Object.keys(predicate), function (field) {
var predicateValue = predicate[field];
return fieldsFromPredicates(predicateValue);
});
} else if (typeof predicate === "string" && predicate.startsWith("$")) {
return [predicate.substr(1)];
} else {
return [];
}
}
function fieldsFromCondition(condition) {
return (0, _utils.flatMap)(Object.keys(condition), function (ref) {
var refCondition = condition[ref];
if (ref === _constants.OR || ref === _constants.AND) {
return (0, _utils.flatMap)(condition[ref], function (w) {
return fieldsFromCondition(w);
});
return (0, _utils.flatMap)(refCondition, fieldsFromCondition);
} else if (ref === _constants.NOT) {
return fieldsFromCondition(condition[ref]);
} else if (ref.indexOf(".") === -1) {
return [ref];
return fieldsFromCondition(refCondition);
} else {
return [];
return [ref].concat(fieldsFromPredicates(refCondition));
}

@@ -141,6 +154,6 @@ });

function listAllFields(conditions) {
var allFields = (0, _utils.flatMap)(conditions, function (condition) {
return fieldsFromCondition(condition);
});
return allFields.filter(function (v, i, a) {
var allFields = (0, _utils.flatMap)(conditions, fieldsFromCondition);
return allFields.filter(function (field) {
return field.indexOf(".") === -1;
}).filter(function (v, i, a) {
return allFields.indexOf(v) === i;

@@ -151,4 +164,4 @@ });

function listInvalidFields(conditions, schema) {
var ruleFields = listAllFields(conditions);
return ruleFields.filter(function (field) {
var allFields = listAllFields(conditions);
return allFields.filter(function (field) {
return schema.properties[field] === undefined;

@@ -155,0 +168,0 @@ });

{
"name": "json-rules-engine-simplified",
"version": "0.1.10",
"version": "0.1.11",
"description": "Simpl JSON rules engine",

@@ -5,0 +5,0 @@ "private": false,

@@ -17,2 +17,3 @@ [![Build Status](https://travis-ci.org/RxNT/json-rules-engine-simplified.svg?branch=master)](https://travis-ci.org/RxNT/json-rules-engine-simplified)

- Declarative conditional logic with [predicates](https://github.com/landau/predicate)
- Relevant conditional logic support
- Support of nested structures with [selectn](https://github.com/wilmoore/selectn.js)

@@ -485,2 +486,31 @@ including composite arrays

## Relevant conditional logic
Sometimes you would want to validate `formData` fields one against the other.
You can do this simply by appending `$` to the beginning of reference.
For example, you want to trigger event only when `a` is less then `b`, when you don't know ahead `a` or `b` values
```js
let schema = {
type: "object",
properties: {
a: { type: "number" },
b: { type: "number" }
}
}
let rules = [{
conditions: {
a: { less: "$b" }
},
event: "some"
}]
let engine = new Engine(schema, rules);
```
This is how you do it, in run time `$b` will be replaces with field `b` value.
Relevant fields work on nested objects as well as on any field condition.
## Events

@@ -487,0 +517,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc