@wix/filter-builder
Advanced tools
Comparing version 1.0.52 to 1.0.53
@@ -14,16 +14,6 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
/***/ 24: | ||
/*!**********************!*\ | ||
!*** ./validator.ts ***! | ||
\**********************/ | ||
/***/ (() => { | ||
/***/ }), | ||
/***/ 182: | ||
/*!*******************************************!*\ | ||
!*** ../../node_modules/kind-of/index.js ***! | ||
\*******************************************/ | ||
/***/ 555: | ||
/*!****************************************!*\ | ||
!*** ../node_modules/kind-of/index.js ***! | ||
\****************************************/ | ||
/***/ ((module) => { | ||
@@ -182,2 +172,12 @@ | ||
/***/ 24: | ||
/*!**********************!*\ | ||
!*** ./validator.ts ***! | ||
\**********************/ | ||
/***/ (() => { | ||
/***/ }), | ||
/***/ 668: | ||
@@ -355,4 +355,4 @@ /*!********************************************************************************************************!*\ | ||
var defineProperty_default = /*#__PURE__*/__webpack_require__.n(defineProperty); | ||
// EXTERNAL MODULE: ../../node_modules/kind-of/index.js | ||
var kind_of = __webpack_require__(182); | ||
// EXTERNAL MODULE: ../node_modules/kind-of/index.js | ||
var kind_of = __webpack_require__(555); | ||
var kind_of_default = /*#__PURE__*/__webpack_require__.n(kind_of); | ||
@@ -359,0 +359,0 @@ ;// CONCATENATED MODULE: ./type-utils.ts |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("platformized-filter-builder",[],e):"object"==typeof exports?exports["platformized-filter-builder"]=e():t["platformized-filter-builder"]=e()}("undefined"!=typeof self?self:this,(()=>(()=>{var t={24:()=>{},182:t=>{var e=Object.prototype.toString;t.exports=function(t){var r=typeof t;return"undefined"===r?"undefined":null===t?"null":!0===t||!1===t||t instanceof Boolean?"boolean":"string"===r||t instanceof String?"string":"number"===r||t instanceof Number?"number":"function"===r||t instanceof Function?void 0!==t.constructor.name&&"Generator"===t.constructor.name.slice(0,9)?"generatorfunction":"function":void 0!==Array.isArray&&Array.isArray(t)?"array":t instanceof RegExp?"regexp":t instanceof Date?"date":"[object RegExp]"===(r=e.call(t))?"regexp":"[object Date]"===r?"date":"[object Arguments]"===r?"arguments":"[object Error]"===r?"error":"[object Promise]"===r?"promise":function(t){return t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}(t)?"buffer":"[object Set]"===r?"set":"[object WeakSet]"===r?"weakset":"[object Map]"===r?"map":"[object WeakMap]"===r?"weakmap":"[object Symbol]"===r?"symbol":"[object Map Iterator]"===r?"mapiterator":"[object Set Iterator]"===r?"setiterator":"[object String Iterator]"===r?"stringiterator":"[object Array Iterator]"===r?"arrayiterator":"[object Int8Array]"===r?"int8array":"[object Uint8Array]"===r?"uint8array":"[object Uint8ClampedArray]"===r?"uint8clampedarray":"[object Int16Array]"===r?"int16array":"[object Uint16Array]"===r?"uint16array":"[object Int32Array]"===r?"int32array":"[object Uint32Array]"===r?"uint32array":"[object Float32Array]"===r?"float32array":"[object Float64Array]"===r?"float64array":"object"}},668:(t,e,r)=>{var n=r(403);t.exports=function(t,e,r){return(e=n(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t},t.exports.__esModule=!0,t.exports.default=t.exports},350:(t,e,r)=>{var n=r(311).default;t.exports=function(t,e){if("object"!=n(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var i=r.call(t,e||"default");if("object"!=n(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)},t.exports.__esModule=!0,t.exports.default=t.exports},403:(t,e,r)=>{var n=r(311).default,i=r(350);t.exports=function(t){var e=i(t,"string");return"symbol"==n(e)?e:String(e)},t.exports.__esModule=!0,t.exports.default=t.exports},311:t=>{function e(r){return t.exports=e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t.exports.__esModule=!0,t.exports.default=t.exports,e(r)}t.exports=e,t.exports.__esModule=!0,t.exports.default=t.exports}},e={};function r(n){var i=e[n];if(void 0!==i)return i.exports;var a=e[n]={exports:{}};return t[n](a,a.exports,r),a.exports}r.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return r.d(e,{a:e}),e},r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return(()=>{"use strict";r.r(n),r.d(n,{Validator:()=>_.Validator,default:()=>I,filterBuilder:()=>b,filterMixin:()=>v,optimiseQuery:()=>p,wixDataEncoder:()=>$});var t=r(668),e=r.n(t),i=r(182),a=r.n(i);function o(t){return"array"===a()(t)}function s(t){return"date"===a()(t)}function l(t){return"string"===a()(t)}function u(t){return function(t){if(!l(t))return t;const e=t.slice(0,1).toUpperCase(),r=t.slice(1,t.length);return e+r}(a()(t))}function d(t){if(null==t||"object"!=typeof t)return t;let e=null;if(s(t))e=new Date(t.getTime());else{e=t.constructor();for(const r in t)e[r]=d(t[r])}return e}class c{constructor(t,r,n){e()(this,"ctor",void 0),e()(this,"_invalidArguments",void 0),e()(this,"_validations",void 0),e()(this,"operatorName",void 0),this._validations=[],this.operatorName=t,this.ctor=n,this._invalidArguments=d(r)}typeIsString(t){return this.addValidation((()=>l(t)),(()=>`Invalid ${this.operatorName} parameter value [${u(t)}]. ${this.operatorName} parameter must be a String.`))}typeIsStringNumberOrDate(t){return this.addValidation((()=>f(t)),(()=>`Invalid ${this.operatorName} parameter value [${u(t)}]. Valid ${this.operatorName} parameter types are String, Number or Date.`))}sameType(t,e){return this.addValidation((()=>u(t)===u(e)),(()=>`Invalid ${this.operatorName} parameter values [${u(t)}] and [${u(e)}]. Both parameters must be of the same type.`))}typeIsStringNumberOrDateForAll(t){return this.addValidation((()=>t.every(f)),(()=>`Invalid ${this.operatorName} usage. ${this.operatorName} supports only Number, String or Date items.`))}validFieldName(t){return this.addValidation((()=>l(t)),(()=>`Invalid ${this.operatorName} field value [${u(t)}]. ${this.operatorName} field must be a String.`))}isInstanceOfSameClass(t){return this.addValidation((()=>t instanceof this.ctor),(()=>`Invalid ${this.operatorName} parameter [${u(t)}]. ${this.operatorName} expects FilterBuilder only.`))}arityIsOne(t){return this.addValidation((()=>1===t.length),(()=>`Invalid ${this.operatorName} usage. ${this.operatorName} requires one parameter.`))}arityIsTwo(t){return this.addValidation((()=>2===t.length),(()=>`Invalid ${this.operatorName} usage. ${this.operatorName} requires two parameters.`))}arityIsThree(t){return this.addValidation((()=>3===t.length),(()=>`Invalid ${this.operatorName} usage. ${this.operatorName} requires three parameters.`))}arityIsAtLeastTwo(t){return this.addValidation((()=>t.length>=2),(()=>`Invalid ${this.operatorName} usage. ${this.operatorName} requires at least two parameters.`))}addValidation(t,e){return this._validations.push({predicateFn:t,messageFn:e}),this}validateAndAggregate(){const t=this._validations.every((t=>{let{predicateFn:e,messageFn:r}=t;return this._appendIfInvalid(e(),r())}));return[this._invalidArguments,t]}_appendIfInvalid(t,e){return!!t||(this._invalidArguments.push(e),!1)}}function f(t){return l(t)||(e=t,"number"===a()(e))||s(t);var e}const h=[function(t){const e=t.$and;if(Array.isArray(e)&&1===e.length)return e[0]},function(t){const e=t.$and;if(Array.isArray(e)&&0===e.length)return{};return null},function(t){const e=t.$and;if(!e)return;let r=[],n=[];if(e.forEach((t=>{!function(t){const e=Object.keys(t);return e.every((t=>t.startsWith("$")))&&e.length>0}(t)?r=[...r,t]:n=[...n,t]})),r.length<=1||function(t){const e=t.map((t=>Object.keys(t))).reduce(((t,e)=>[...t,...e]),[]);return function(t){const e={};return t.forEach((t=>e[t]=!0)),Object.keys(e)}(e).length!==e.length}(r))return;return{$and:[Object.assign({},...r),...n]}},function(t){const e=t.$and;if(!e)return;if(!e.find((t=>t.$and)))return;return{$and:e.reduce(((t,e)=>{const r=e.$and;return r?[...t,...r]:[...t,e]}),[])}},function(t){const e=t.$or;if(!e)return;if(!e.find((t=>t.$or)))return;return{$or:e.reduce(((t,e)=>{const r=e.$or;return r?[...t,...r]:[...t,e]}),[])}}];function p(t){const[e]=y(t);return e}function y(t){return Array.isArray(t)?function(t){const e=t.map(y),r=0<e.filter((t=>{let[,e]=t;return e})).length;return[e.map((t=>{let[e]=t;return e})),r]}(t):"object"!=typeof t||null===t||t instanceof Date?[t,!1]:function(t){const[e,r]=o(t),[n,i]=a(e);return[n,r||i];function a(t){const e=function(t){for(const e of h){const r=e(t);if(r)return r}}(t);if(!e)return[t,!1];const[r]=y(e);return[r,!0]}function o(t){const e=Object.entries(t).map(s).filter((t=>{let[,,e]=t;return e}));return[{...t,...l(e)},!!e.length]}function s(t){let[e,r]=t;const[n,i]=y(r);return[e,n,i]}function l(t){return t.reduce(((t,e)=>{let[r,n]=e;return{...t,[r]:n}}),{})}}(t)}function g(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return{$and:e}}function m(t){return t&&t.$and&&0===t.$and.length}const v=function(t){return void 0===t&&(t=class{}),class extends t{constructor(t){void 0===t&&(t={}),super(t),e()(this,"filterTree",void 0),e()(this,"invalidArguments",void 0),e()(this,"encoder",void 0),this.filterTree=t.filterTree||{$and:[]},this.invalidArguments=t.invalidArguments||[],this.encoder=t.encoder||{}}eq(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return this._binaryAnd("$eq",".eq",e)}ne(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return this._binaryAnd("$ne",".ne",e)}ge(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return this._AndLogicalEquivalence("$gte",".ge",e)}gt(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return this._AndLogicalEquivalence("$gt",".gt",e)}le(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return this._AndLogicalEquivalence("$lte",".le",e)}lt(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return this._AndLogicalEquivalence("$lt",".lt",e)}isNotEmpty(t){const[e,r]=this._filterValidator(".isNotEmpty").arityIsOne(arguments).validFieldName(t).validateAndAggregate();return r?this.ne(t,null):this._copy(this.filterTree,e)}isEmpty(t){const[e,r]=this._filterValidator(".isEmpty").arityIsOne(arguments).validFieldName(t).validateAndAggregate();return r?this.eq(t,null):this._copy(this.filterTree,e)}startsWith(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return this._AndStringOperand("$startsWith",".startsWith",e)}endsWith(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return this._AndStringOperand("$endsWith",".endsWith",e)}contains(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return this._AndStringOperand("$contains",".contains",e)}hasSome(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return this._AndSetOperand("$hasSome",".hasSome",e)}hasAll(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return this._AndSetOperand("$hasAll",".hasAll",e)}or(t){const[e,r]=this._filterValidator(".or").arityIsOne(arguments).isInstanceOfSameClass(t).validateAndAggregate();if(r){const r=m(this.filterTree)?[]:[this.filterTree];return this._copy(g({$or:[...r,t.filterTree]}),e.concat(t.invalidArguments))}return this._copy(this.filterTree,e)}and(t){const[e,r]=this._filterValidator(".and").arityIsOne(arguments).isInstanceOfSameClass(t).validateAndAggregate();if(r){const r=m(this.filterTree)?[]:[this.filterTree];return this._copy(g(...r,t.filterTree),e.concat(t.invalidArguments))}return this._copy(this.filterTree,e)}not(t){const[e,r]=this._filterValidator(".not").arityIsOne(arguments).isInstanceOfSameClass(t).validateAndAggregate();if(r){const r=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return{$and:e.reduce(((t,e)=>o(e.$and)?t.concat(e.$and):t.concat([e])),[])}}(d(this.filterTree),{$not:[t.filterTree]});return this._copy(r,e.concat(t.invalidArguments))}return this._copy(this.filterTree,e)}between(t,e,r){const[n,i]=this._filterValidator(".between").arityIsThree(arguments).sameType(e,r).typeIsStringNumberOrDate(e).typeIsStringNumberOrDate(r).validateAndAggregate();return i?this.ge(t,e).lt(t,r):this._copy(this.filterTree,n)}getFilterModel(){if(this.invalidArguments.length>0)throw new Error(this.invalidArguments.join(" "));return p(this.filterTree)}setFilterModel(t){return this._copy(t,[])}_binaryAnd(t,e,r){const[n,i]=Array.prototype.slice.call(r),[a]=this._filterValidator(e).arityIsTwo(r).validFieldName(n).validateAndAggregate(),o=this._makeNewFilter(n,t,i);return this._copy(o,a)}_AndLogicalEquivalence(t,e,r){const[n,i]=Array.prototype.slice.call(r),[a]=this._filterValidator(e).arityIsTwo(r).validFieldName(n).typeIsStringNumberOrDate(i).validateAndAggregate(),o=this._makeNewFilter(n,t,i);return this._copy(o,a)}_AndStringOperand(t,e,r){const[n,i]=Array.prototype.slice.call(r),[a]=this._filterValidator(e).arityIsTwo(r).validFieldName(n).typeIsString(i).validateAndAggregate(),o=this._makeNewFilter(n,t,i);return this._copy(o,a)}_AndSetOperand(t,e,r){const[n,...i]=Array.prototype.slice.call(r),a=o(i[0])?i[0]:i,[s]=this._filterValidator(e).arityIsAtLeastTwo(r).validFieldName(n).typeIsStringNumberOrDateForAll(a).validateAndAggregate(),l=this._makeNewFilter(n,t,a);return this._copy(l,s)}_makeNewFilter(t,e,r){const n=d(this.filterTree),i=void 0===r?null:r,a=this._buildFilter(t,e,i);if(o(n.$and))return n.$and.push(a),n;return s=n,0===Object.keys(s).length?g(a):g(n,a);var s}_buildFilter(t,e,r){if("$eq"!==e){const n={};return n[t]={},n[t][e]=this._encode(r),n}{const e={};return e[t]=this._encode(r),e}}_encode(t){return e=this.encoder,"function"===a()(e)?this.encoder(t):t;var e}_copy(t,e){return new this.constructor({...this,filterTree:t,invalidArguments:e})}_filterValidator(t){return new c(t,this.invalidArguments,this.constructor)}}};class A extends(v()){get constructorName(){return"FilterBuilder"}_build(){return this.getFilterModel()}}function b(t){return void 0===t&&(t={}),new A(t)}var _=r(24);function $(t){return s(t)?{$date:t.toJSON()}:t}const I=b})(),n})())); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("platformized-filter-builder",[],e):"object"==typeof exports?exports["platformized-filter-builder"]=e():t["platformized-filter-builder"]=e()}("undefined"!=typeof self?self:this,(()=>(()=>{var t={555:t=>{var e=Object.prototype.toString;t.exports=function(t){var r=typeof t;return"undefined"===r?"undefined":null===t?"null":!0===t||!1===t||t instanceof Boolean?"boolean":"string"===r||t instanceof String?"string":"number"===r||t instanceof Number?"number":"function"===r||t instanceof Function?void 0!==t.constructor.name&&"Generator"===t.constructor.name.slice(0,9)?"generatorfunction":"function":void 0!==Array.isArray&&Array.isArray(t)?"array":t instanceof RegExp?"regexp":t instanceof Date?"date":"[object RegExp]"===(r=e.call(t))?"regexp":"[object Date]"===r?"date":"[object Arguments]"===r?"arguments":"[object Error]"===r?"error":"[object Promise]"===r?"promise":function(t){return t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}(t)?"buffer":"[object Set]"===r?"set":"[object WeakSet]"===r?"weakset":"[object Map]"===r?"map":"[object WeakMap]"===r?"weakmap":"[object Symbol]"===r?"symbol":"[object Map Iterator]"===r?"mapiterator":"[object Set Iterator]"===r?"setiterator":"[object String Iterator]"===r?"stringiterator":"[object Array Iterator]"===r?"arrayiterator":"[object Int8Array]"===r?"int8array":"[object Uint8Array]"===r?"uint8array":"[object Uint8ClampedArray]"===r?"uint8clampedarray":"[object Int16Array]"===r?"int16array":"[object Uint16Array]"===r?"uint16array":"[object Int32Array]"===r?"int32array":"[object Uint32Array]"===r?"uint32array":"[object Float32Array]"===r?"float32array":"[object Float64Array]"===r?"float64array":"object"}},24:()=>{},668:(t,e,r)=>{var n=r(403);t.exports=function(t,e,r){return(e=n(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t},t.exports.__esModule=!0,t.exports.default=t.exports},350:(t,e,r)=>{var n=r(311).default;t.exports=function(t,e){if("object"!=n(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var i=r.call(t,e||"default");if("object"!=n(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)},t.exports.__esModule=!0,t.exports.default=t.exports},403:(t,e,r)=>{var n=r(311).default,i=r(350);t.exports=function(t){var e=i(t,"string");return"symbol"==n(e)?e:String(e)},t.exports.__esModule=!0,t.exports.default=t.exports},311:t=>{function e(r){return t.exports=e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t.exports.__esModule=!0,t.exports.default=t.exports,e(r)}t.exports=e,t.exports.__esModule=!0,t.exports.default=t.exports}},e={};function r(n){var i=e[n];if(void 0!==i)return i.exports;var a=e[n]={exports:{}};return t[n](a,a.exports,r),a.exports}r.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return r.d(e,{a:e}),e},r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return(()=>{"use strict";r.r(n),r.d(n,{Validator:()=>_.Validator,default:()=>I,filterBuilder:()=>b,filterMixin:()=>v,optimiseQuery:()=>p,wixDataEncoder:()=>$});var t=r(668),e=r.n(t),i=r(555),a=r.n(i);function o(t){return"array"===a()(t)}function s(t){return"date"===a()(t)}function l(t){return"string"===a()(t)}function u(t){return function(t){if(!l(t))return t;const e=t.slice(0,1).toUpperCase(),r=t.slice(1,t.length);return e+r}(a()(t))}function d(t){if(null==t||"object"!=typeof t)return t;let e=null;if(s(t))e=new Date(t.getTime());else{e=t.constructor();for(const r in t)e[r]=d(t[r])}return e}class c{constructor(t,r,n){e()(this,"ctor",void 0),e()(this,"_invalidArguments",void 0),e()(this,"_validations",void 0),e()(this,"operatorName",void 0),this._validations=[],this.operatorName=t,this.ctor=n,this._invalidArguments=d(r)}typeIsString(t){return this.addValidation((()=>l(t)),(()=>`Invalid ${this.operatorName} parameter value [${u(t)}]. ${this.operatorName} parameter must be a String.`))}typeIsStringNumberOrDate(t){return this.addValidation((()=>f(t)),(()=>`Invalid ${this.operatorName} parameter value [${u(t)}]. Valid ${this.operatorName} parameter types are String, Number or Date.`))}sameType(t,e){return this.addValidation((()=>u(t)===u(e)),(()=>`Invalid ${this.operatorName} parameter values [${u(t)}] and [${u(e)}]. Both parameters must be of the same type.`))}typeIsStringNumberOrDateForAll(t){return this.addValidation((()=>t.every(f)),(()=>`Invalid ${this.operatorName} usage. ${this.operatorName} supports only Number, String or Date items.`))}validFieldName(t){return this.addValidation((()=>l(t)),(()=>`Invalid ${this.operatorName} field value [${u(t)}]. ${this.operatorName} field must be a String.`))}isInstanceOfSameClass(t){return this.addValidation((()=>t instanceof this.ctor),(()=>`Invalid ${this.operatorName} parameter [${u(t)}]. ${this.operatorName} expects FilterBuilder only.`))}arityIsOne(t){return this.addValidation((()=>1===t.length),(()=>`Invalid ${this.operatorName} usage. ${this.operatorName} requires one parameter.`))}arityIsTwo(t){return this.addValidation((()=>2===t.length),(()=>`Invalid ${this.operatorName} usage. ${this.operatorName} requires two parameters.`))}arityIsThree(t){return this.addValidation((()=>3===t.length),(()=>`Invalid ${this.operatorName} usage. ${this.operatorName} requires three parameters.`))}arityIsAtLeastTwo(t){return this.addValidation((()=>t.length>=2),(()=>`Invalid ${this.operatorName} usage. ${this.operatorName} requires at least two parameters.`))}addValidation(t,e){return this._validations.push({predicateFn:t,messageFn:e}),this}validateAndAggregate(){const t=this._validations.every((t=>{let{predicateFn:e,messageFn:r}=t;return this._appendIfInvalid(e(),r())}));return[this._invalidArguments,t]}_appendIfInvalid(t,e){return!!t||(this._invalidArguments.push(e),!1)}}function f(t){return l(t)||(e=t,"number"===a()(e))||s(t);var e}const h=[function(t){const e=t.$and;if(Array.isArray(e)&&1===e.length)return e[0]},function(t){const e=t.$and;if(Array.isArray(e)&&0===e.length)return{};return null},function(t){const e=t.$and;if(!e)return;let r=[],n=[];if(e.forEach((t=>{!function(t){const e=Object.keys(t);return e.every((t=>t.startsWith("$")))&&e.length>0}(t)?r=[...r,t]:n=[...n,t]})),r.length<=1||function(t){const e=t.map((t=>Object.keys(t))).reduce(((t,e)=>[...t,...e]),[]);return function(t){const e={};return t.forEach((t=>e[t]=!0)),Object.keys(e)}(e).length!==e.length}(r))return;return{$and:[Object.assign({},...r),...n]}},function(t){const e=t.$and;if(!e)return;if(!e.find((t=>t.$and)))return;return{$and:e.reduce(((t,e)=>{const r=e.$and;return r?[...t,...r]:[...t,e]}),[])}},function(t){const e=t.$or;if(!e)return;if(!e.find((t=>t.$or)))return;return{$or:e.reduce(((t,e)=>{const r=e.$or;return r?[...t,...r]:[...t,e]}),[])}}];function p(t){const[e]=y(t);return e}function y(t){return Array.isArray(t)?function(t){const e=t.map(y),r=0<e.filter((t=>{let[,e]=t;return e})).length;return[e.map((t=>{let[e]=t;return e})),r]}(t):"object"!=typeof t||null===t||t instanceof Date?[t,!1]:function(t){const[e,r]=o(t),[n,i]=a(e);return[n,r||i];function a(t){const e=function(t){for(const e of h){const r=e(t);if(r)return r}}(t);if(!e)return[t,!1];const[r]=y(e);return[r,!0]}function o(t){const e=Object.entries(t).map(s).filter((t=>{let[,,e]=t;return e}));return[{...t,...l(e)},!!e.length]}function s(t){let[e,r]=t;const[n,i]=y(r);return[e,n,i]}function l(t){return t.reduce(((t,e)=>{let[r,n]=e;return{...t,[r]:n}}),{})}}(t)}function g(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return{$and:e}}function m(t){return t&&t.$and&&0===t.$and.length}const v=function(t){return void 0===t&&(t=class{}),class extends t{constructor(t){void 0===t&&(t={}),super(t),e()(this,"filterTree",void 0),e()(this,"invalidArguments",void 0),e()(this,"encoder",void 0),this.filterTree=t.filterTree||{$and:[]},this.invalidArguments=t.invalidArguments||[],this.encoder=t.encoder||{}}eq(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return this._binaryAnd("$eq",".eq",e)}ne(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return this._binaryAnd("$ne",".ne",e)}ge(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return this._AndLogicalEquivalence("$gte",".ge",e)}gt(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return this._AndLogicalEquivalence("$gt",".gt",e)}le(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return this._AndLogicalEquivalence("$lte",".le",e)}lt(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return this._AndLogicalEquivalence("$lt",".lt",e)}isNotEmpty(t){const[e,r]=this._filterValidator(".isNotEmpty").arityIsOne(arguments).validFieldName(t).validateAndAggregate();return r?this.ne(t,null):this._copy(this.filterTree,e)}isEmpty(t){const[e,r]=this._filterValidator(".isEmpty").arityIsOne(arguments).validFieldName(t).validateAndAggregate();return r?this.eq(t,null):this._copy(this.filterTree,e)}startsWith(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return this._AndStringOperand("$startsWith",".startsWith",e)}endsWith(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return this._AndStringOperand("$endsWith",".endsWith",e)}contains(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return this._AndStringOperand("$contains",".contains",e)}hasSome(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return this._AndSetOperand("$hasSome",".hasSome",e)}hasAll(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return this._AndSetOperand("$hasAll",".hasAll",e)}or(t){const[e,r]=this._filterValidator(".or").arityIsOne(arguments).isInstanceOfSameClass(t).validateAndAggregate();if(r){const r=m(this.filterTree)?[]:[this.filterTree];return this._copy(g({$or:[...r,t.filterTree]}),e.concat(t.invalidArguments))}return this._copy(this.filterTree,e)}and(t){const[e,r]=this._filterValidator(".and").arityIsOne(arguments).isInstanceOfSameClass(t).validateAndAggregate();if(r){const r=m(this.filterTree)?[]:[this.filterTree];return this._copy(g(...r,t.filterTree),e.concat(t.invalidArguments))}return this._copy(this.filterTree,e)}not(t){const[e,r]=this._filterValidator(".not").arityIsOne(arguments).isInstanceOfSameClass(t).validateAndAggregate();if(r){const r=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return{$and:e.reduce(((t,e)=>o(e.$and)?t.concat(e.$and):t.concat([e])),[])}}(d(this.filterTree),{$not:[t.filterTree]});return this._copy(r,e.concat(t.invalidArguments))}return this._copy(this.filterTree,e)}between(t,e,r){const[n,i]=this._filterValidator(".between").arityIsThree(arguments).sameType(e,r).typeIsStringNumberOrDate(e).typeIsStringNumberOrDate(r).validateAndAggregate();return i?this.ge(t,e).lt(t,r):this._copy(this.filterTree,n)}getFilterModel(){if(this.invalidArguments.length>0)throw new Error(this.invalidArguments.join(" "));return p(this.filterTree)}setFilterModel(t){return this._copy(t,[])}_binaryAnd(t,e,r){const[n,i]=Array.prototype.slice.call(r),[a]=this._filterValidator(e).arityIsTwo(r).validFieldName(n).validateAndAggregate(),o=this._makeNewFilter(n,t,i);return this._copy(o,a)}_AndLogicalEquivalence(t,e,r){const[n,i]=Array.prototype.slice.call(r),[a]=this._filterValidator(e).arityIsTwo(r).validFieldName(n).typeIsStringNumberOrDate(i).validateAndAggregate(),o=this._makeNewFilter(n,t,i);return this._copy(o,a)}_AndStringOperand(t,e,r){const[n,i]=Array.prototype.slice.call(r),[a]=this._filterValidator(e).arityIsTwo(r).validFieldName(n).typeIsString(i).validateAndAggregate(),o=this._makeNewFilter(n,t,i);return this._copy(o,a)}_AndSetOperand(t,e,r){const[n,...i]=Array.prototype.slice.call(r),a=o(i[0])?i[0]:i,[s]=this._filterValidator(e).arityIsAtLeastTwo(r).validFieldName(n).typeIsStringNumberOrDateForAll(a).validateAndAggregate(),l=this._makeNewFilter(n,t,a);return this._copy(l,s)}_makeNewFilter(t,e,r){const n=d(this.filterTree),i=void 0===r?null:r,a=this._buildFilter(t,e,i);if(o(n.$and))return n.$and.push(a),n;return s=n,0===Object.keys(s).length?g(a):g(n,a);var s}_buildFilter(t,e,r){if("$eq"!==e){const n={};return n[t]={},n[t][e]=this._encode(r),n}{const e={};return e[t]=this._encode(r),e}}_encode(t){return e=this.encoder,"function"===a()(e)?this.encoder(t):t;var e}_copy(t,e){return new this.constructor({...this,filterTree:t,invalidArguments:e})}_filterValidator(t){return new c(t,this.invalidArguments,this.constructor)}}};class A extends(v()){get constructorName(){return"FilterBuilder"}_build(){return this.getFilterModel()}}function b(t){return void 0===t&&(t={}),new A(t)}var _=r(24);function $(t){return s(t)?{$date:t.toJSON()}:t}const I=b})(),n})())); | ||
//# sourceMappingURL=filter-builder.umd.min.js.map |
{ | ||
"filter-builder.js": "https://static.parastorage.com/services/filter-builder/55d90eac87efe1b3f5dfa23f7068f21e505ad916bf7ea53f0e2fa8cb/filter-builder.umd.js" | ||
"filter-builder.js": "https://static.parastorage.com/services/filter-builder/316127df8bed58c303b7c222ca68bdb6c10f5e230fc372e7c8821ddc/filter-builder.umd.js" | ||
} |
{ | ||
"filter-builder.js": "https://static.parastorage.com/services/filter-builder/55d90eac87efe1b3f5dfa23f7068f21e505ad916bf7ea53f0e2fa8cb/filter-builder.umd.min.js" | ||
"filter-builder.js": "https://static.parastorage.com/services/filter-builder/316127df8bed58c303b7c222ca68bdb6c10f5e230fc372e7c8821ddc/filter-builder.umd.min.js" | ||
} |
{ | ||
"name": "@wix/filter-builder", | ||
"version": "1.0.52", | ||
"version": "1.0.53", | ||
"license": "UNLICENSED", | ||
@@ -42,5 +42,5 @@ "author": { | ||
"@types/node": "^14.18.61", | ||
"@wix/eslint-config-yoshi": "^6.93.0", | ||
"@wix/jest-yoshi-preset": "^6.93.0", | ||
"@wix/yoshi-flow-library": "^6.93.0", | ||
"@wix/eslint-config-yoshi": "^6.93.1", | ||
"@wix/jest-yoshi-preset": "^6.93.1", | ||
"@wix/yoshi-flow-library": "^6.93.1", | ||
"chai": "~3.5.0", | ||
@@ -93,3 +93,3 @@ "express": "^4.18.2", | ||
}, | ||
"falconPackageHash": "545c106153cd3ed23abeb59e0a5df1fb40181c04bbdf3b9d85096c55" | ||
"falconPackageHash": "c2619e402b38d2a731cf64b8518bd893cf81a7f8373f1681aa13eff5" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
404548