@wix/filter-builder
Advanced tools
Comparing version 1.0.40 to 1.0.41
@@ -205,3 +205,3 @@ import { isArray, isFunction } from './type-utils'; | ||
_copy(filterTree, invalidArguments) { | ||
return new this.constructor(Object.assign(Object.assign({}, this), { filterTree, invalidArguments })); | ||
return new this.constructor({ ...this, filterTree, invalidArguments }); | ||
} | ||
@@ -208,0 +208,0 @@ _filterValidator(filterOperatorName) { |
@@ -46,3 +46,3 @@ const optimisations = [ | ||
.filter(([, , changed]) => changed); | ||
const newQuery = Object.assign(Object.assign({}, query), entriesAsObject(changedEntries)); | ||
const newQuery = { ...query, ...entriesAsObject(changedEntries) }; | ||
const changed = !!changedEntries.length; | ||
@@ -56,3 +56,3 @@ return [newQuery, changed]; | ||
function entriesAsObject(entries) { | ||
return entries.reduce((acc, [key, value]) => (Object.assign(Object.assign({}, acc), { [key]: value })), {}); | ||
return entries.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {}); | ||
} | ||
@@ -59,0 +59,0 @@ } |
@@ -361,3 +361,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
;// CONCATENATED MODULE: ./filter-validator.ts | ||
class FilterValidator{constructor(operatorName,previousInvalidArguments,ctor){defineProperty_default()(this,"ctor",void 0);defineProperty_default()(this,"_invalidArguments",void 0);defineProperty_default()(this,"_validations",void 0);defineProperty_default()(this,"operatorName",void 0);this._validations=[];this.operatorName=operatorName;this.ctor=ctor;this._invalidArguments=clone(previousInvalidArguments);}typeIsString(value){return this.addValidation(()=>isString(value),()=>"Invalid "+this.operatorName+" parameter value ["+typeForDisplay(value)+"]. "+this.operatorName+" parameter must be a String.");}typeIsStringNumberOrDate(value){return this.addValidation(()=>isDateStringOrNumber(value),()=>"Invalid "+this.operatorName+" parameter value ["+typeForDisplay(value)+"]. Valid "+this.operatorName+" parameter types are String, Number or Date.");}sameType(first,second){return this.addValidation(()=>typeForDisplay(first)===typeForDisplay(second),()=>"Invalid "+this.operatorName+" parameter values ["+typeForDisplay(first)+"] and ["+typeForDisplay(second)+"]. Both parameters must be of the same type.");}typeIsStringNumberOrDateForAll(values){return this.addValidation(()=>values.every(isDateStringOrNumber),()=>"Invalid "+this.operatorName+" usage. "+this.operatorName+" supports only Number, String or Date items.");}validFieldName(field){return this.addValidation(()=>isString(field),()=>"Invalid "+this.operatorName+" field value ["+typeForDisplay(field)+"]. "+this.operatorName+" field must be a String.");}isInstanceOfSameClass(obj){return this.addValidation(()=>obj instanceof this.ctor,()=>"Invalid "+this.operatorName+" parameter ["+typeForDisplay(obj)+"]. "+this.operatorName+" expects FilterBuilder only.");}arityIsOne(args){return this.addValidation(()=>args.length===1,()=>"Invalid "+this.operatorName+" usage. "+this.operatorName+" requires one parameter.");}arityIsTwo(args){return this.addValidation(()=>args.length===2,()=>"Invalid "+this.operatorName+" usage. "+this.operatorName+" requires two parameters.");}arityIsThree(args){return this.addValidation(()=>args.length===3,()=>"Invalid "+this.operatorName+" usage. "+this.operatorName+" requires three parameters.");}arityIsAtLeastTwo(args){return this.addValidation(()=>args.length>=2,()=>"Invalid "+this.operatorName+" usage. "+this.operatorName+" requires at least two parameters.");}addValidation(predicateFn,messageFn){this._validations.push({predicateFn,messageFn});return this;}validateAndAggregate(){const valid=this._validations.every(_ref=>{let{predicateFn,messageFn}=_ref;return this._appendIfInvalid(predicateFn(),messageFn());});return[this._invalidArguments,valid];}_appendIfInvalid(valid,message){if(!valid){this._invalidArguments.push(message);return false;}return true;}}function isDateStringOrNumber(value){return isString(value)||isNumber(value)||isDate(value);} | ||
class FilterValidator{constructor(operatorName,previousInvalidArguments,ctor){defineProperty_default()(this,"ctor",void 0);defineProperty_default()(this,"_invalidArguments",void 0);defineProperty_default()(this,"_validations",void 0);defineProperty_default()(this,"operatorName",void 0);this._validations=[];this.operatorName=operatorName;this.ctor=ctor;this._invalidArguments=clone(previousInvalidArguments);}typeIsString(value){return this.addValidation(()=>isString(value),()=>`Invalid ${this.operatorName} parameter value [${typeForDisplay(value)}]. ${this.operatorName} parameter must be a String.`);}typeIsStringNumberOrDate(value){return this.addValidation(()=>isDateStringOrNumber(value),()=>`Invalid ${this.operatorName} parameter value [${typeForDisplay(value)}]. Valid ${this.operatorName} parameter types are String, Number or Date.`);}sameType(first,second){return this.addValidation(()=>typeForDisplay(first)===typeForDisplay(second),()=>`Invalid ${this.operatorName} parameter values [${typeForDisplay(first)}] and [${typeForDisplay(second)}]. Both parameters must be of the same type.`);}typeIsStringNumberOrDateForAll(values){return this.addValidation(()=>values.every(isDateStringOrNumber),()=>`Invalid ${this.operatorName} usage. ${this.operatorName} supports only Number, String or Date items.`);}validFieldName(field){return this.addValidation(()=>isString(field),()=>`Invalid ${this.operatorName} field value [${typeForDisplay(field)}]. ${this.operatorName} field must be a String.`);}isInstanceOfSameClass(obj){return this.addValidation(()=>obj instanceof this.ctor,()=>`Invalid ${this.operatorName} parameter [${typeForDisplay(obj)}]. ${this.operatorName} expects FilterBuilder only.`);}arityIsOne(args){return this.addValidation(()=>args.length===1,()=>`Invalid ${this.operatorName} usage. ${this.operatorName} requires one parameter.`);}arityIsTwo(args){return this.addValidation(()=>args.length===2,()=>`Invalid ${this.operatorName} usage. ${this.operatorName} requires two parameters.`);}arityIsThree(args){return this.addValidation(()=>args.length===3,()=>`Invalid ${this.operatorName} usage. ${this.operatorName} requires three parameters.`);}arityIsAtLeastTwo(args){return this.addValidation(()=>args.length>=2,()=>`Invalid ${this.operatorName} usage. ${this.operatorName} requires at least two parameters.`);}addValidation(predicateFn,messageFn){this._validations.push({predicateFn,messageFn});return this;}validateAndAggregate(){const valid=this._validations.every(_ref=>{let{predicateFn,messageFn}=_ref;return this._appendIfInvalid(predicateFn(),messageFn());});return[this._invalidArguments,valid];}_appendIfInvalid(valid,message){if(!valid){this._invalidArguments.push(message);return false;}return true;}}function isDateStringOrNumber(value){return isString(value)||isNumber(value)||isDate(value);} | ||
;// CONCATENATED MODULE: ./query-optimiser.ts | ||
@@ -364,0 +364,0 @@ const optimisations=[optimisedUnaryAnd,optimisedEmptyAnd,optimisedAndsAsObjects,optimisedNestedAnds,optimisedNestedOrs];function optimisedQuery(query){const[newQuery]=fullyOptimised(query);return newQuery;}function fullyOptimised(query){if(Array.isArray(query)){return fullyOptimisedArray(query);}if(typeof query==='object'&&query!==null&&!instanceOfIgnoredType(query)){return fullyOptimisedObject(query);}return[query,false];}function fullyOptimisedArray(query){const optimisedElements=query.map(fullyOptimised);const somethingChanged=0<optimisedElements.filter(_ref=>{let[,elementChanged]=_ref;return elementChanged;}).length;const newElements=optimisedElements.map(_ref2=>{let[element]=_ref2;return element;});return[newElements,somethingChanged];}function fullyOptimisedObject(query){const[queryAfterOptimisingEntries,changedStage1]=fullEntriesOptimisation(query);const[queryAfterFullOptimisation,changedStage2]=fullObjectOptimisation(queryAfterOptimisingEntries);const changed=changedStage1||changedStage2;return[queryAfterFullOptimisation,changed];function fullObjectOptimisation(query){const updatedQuery=applyFirstOptimisation(query);if(!updatedQuery){return[query,false];}const[finalQuery]=fullyOptimised(updatedQuery);return[finalQuery,true];}function fullEntriesOptimisation(query){const changedEntries=Object.entries(query).map(entryOptimisation).filter(_ref3=>{let[,,changed]=_ref3;return changed;});const newQuery={...query,...entriesAsObject(changedEntries)};const changed=!!changedEntries.length;return[newQuery,changed];}function entryOptimisation(_ref4){let[key,value]=_ref4;const[newValue,changed]=fullyOptimised(value);return[key,newValue,changed];}function entriesAsObject(entries){return entries.reduce((acc,_ref5)=>{let[key,value]=_ref5;return{...acc,[key]:value};},{});}}function applyFirstOptimisation(node){for(const optimisation of optimisations){const newNode=optimisation(node);if(newNode){return newNode;}}}function optimisedUnaryAnd(node){const args=node.$and;if(Array.isArray(args)&&args.length===1){return args[0];}}function optimisedEmptyAnd(node){const args=node.$and;if(Array.isArray(args)&&args.length===0){return{};}return null;}function optimisedAndsAsObjects(node){const args=node.$and;if(!args){return;}let basicObjects=[];let operatorObjects=[];args.forEach(arg=>{if(isOperator(arg)){operatorObjects=[...operatorObjects,arg];}else{basicObjects=[...basicObjects,arg];}});if(basicObjects.length<=1||haveOverlappingFields(basicObjects)){return;}const combinedBasicObjects=Object.assign({},...basicObjects);return{$and:[combinedBasicObjects,...operatorObjects]};function isOperator(node){const keys=Object.keys(node);return keys.every(name=>name.startsWith('$'))&&keys.length>0;}function haveOverlappingFields(objects){const nonUniqueKeys=objects.map(it=>Object.keys(it)).reduce((a,b)=>[...a,...b],[]);const uniqueKeys=unique(nonUniqueKeys);return uniqueKeys.length!==nonUniqueKeys.length;}function unique(values){const dict={};values.forEach(v=>dict[v]=true);return Object.keys(dict);}}function optimisedNestedAnds(node){const args=node.$and;if(!args){return;}const hasNestedAnds=!!args.find(it=>it.$and);if(!hasNestedAnds){return;}const newArgs=args.reduce((result,current)=>{const and=current.$and;if(!and){return[...result,current];}return[...result,...and];},[]);return{$and:newArgs};}function optimisedNestedOrs(node){const args=node.$or;if(!args){return;}const hasNestedOrs=!!args.find(it=>it.$or);if(!hasNestedOrs){return;}const newArgs=args.reduce((result,current)=>{const or=current.$or;if(!or){return[...result,current];}return[...result,...or];},[]);return{$or:newArgs};}function instanceOfIgnoredType(obj){return obj instanceof Date;} |
@@ -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:()=>N,filterBuilder:()=>b,filterMixin:()=>v,optimiseQuery:()=>p,wixDataEncoder:()=>I});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 I(t){return s(t)?{$date:t.toJSON()}:t}const N=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={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})())); | ||
//# sourceMappingURL=filter-builder.umd.min.js.map |
{ | ||
"filter-builder.js": "https://static.parastorage.com/services/filter-builder/d383849e128e48818d9e5f0aa6030adb7d2c8fb2a019860c5b6cd286/filter-builder.umd.js" | ||
"filter-builder.js": "https://static.parastorage.com/services/filter-builder/424af9f630c5e83e0e7b80041c6241b5183fcde29ccf0193fe65f9e4/filter-builder.umd.js" | ||
} |
{ | ||
"filter-builder.js": "https://static.parastorage.com/services/filter-builder/d383849e128e48818d9e5f0aa6030adb7d2c8fb2a019860c5b6cd286/filter-builder.umd.min.js" | ||
"filter-builder.js": "https://static.parastorage.com/services/filter-builder/424af9f630c5e83e0e7b80041c6241b5183fcde29ccf0193fe65f9e4/filter-builder.umd.min.js" | ||
} |
{ | ||
"name": "@wix/filter-builder", | ||
"version": "1.0.40", | ||
"version": "1.0.41", | ||
"license": "UNLICENSED", | ||
@@ -42,5 +42,5 @@ "author": { | ||
"@types/node": "^14.18.61", | ||
"@wix/eslint-config-yoshi": "^6.88.1", | ||
"@wix/jest-yoshi-preset": "^6.88.1", | ||
"@wix/yoshi-flow-library": "^6.88.1", | ||
"@wix/eslint-config-yoshi": "^6.89.0", | ||
"@wix/jest-yoshi-preset": "^6.89.0", | ||
"@wix/yoshi-flow-library": "^6.89.0", | ||
"chai": "~3.5.0", | ||
@@ -93,3 +93,3 @@ "express": "^4.18.2", | ||
}, | ||
"falconPackageHash": "0352d7472f44f18f497facd8adf5b3f7c45dbeb0077e211efaf2f1cd" | ||
"falconPackageHash": "a2cf8cfb28730afa4b9a1464c986fb729ee607112cfe1d98efe6fcf4" | ||
} |
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
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
404147