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

@wix/filter-builder

Package Overview
Dependencies
Maintainers
33
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wix/filter-builder - npm Package Compare versions

Comparing version 1.0.10 to 1.0.11

dist/cjs/wix-data-encoder.js

23

dist/cjs/__tests__/filter.spec.js

@@ -19,2 +19,25 @@ "use strict";

const filter = (0, _.filterBuilder)();
describe('custom encoders', function () {
it('encode date with wixDataEncoder', function () {
const now = new Date();
const filterWithEncoder = (0, _.filterBuilder)({
encoder: _.wixDataEncoder
});
expect(filterWithEncoder.eq('x', now).getFilterModel()).to.be.eql({
x: {
$date: now.toJSON()
}
});
});
it('encode with custom encoder', function () {
const encoder = () => 3;
const filterWithEncoder = (0, _.filterBuilder)({
encoder
});
expect(filterWithEncoder.eq('x', 'a').getFilterModel()).to.be.eql({
x: 3
});
});
});
describe('filter comparison operators', function () {

@@ -21,0 +44,0 @@ it('should produce the correct filter tree', function () {

4

dist/cjs/filter-builder.js

@@ -24,4 +24,4 @@ "use strict";

function filterBuilder() {
return new FilterBuilder({});
function filterBuilder(params = {}) {
return new FilterBuilder(params);
}

@@ -28,0 +28,0 @@

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

(0, _defineProperty2.default)(this, "invalidArguments", void 0);
(0, _defineProperty2.default)(this, "encoder", void 0);
this.filterTree = obj.filterTree || {

@@ -28,2 +29,3 @@ $and: []

this.invalidArguments = obj.invalidArguments || [];
this.encoder = obj.encoder || {};
}

@@ -244,7 +246,7 @@

newFilter[field] = {};
newFilter[field][filterOperatorName] = this._replaceRefs(operand);
newFilter[field][filterOperatorName] = this._encode(operand);
return newFilter;
} else {
const newFilter = {};
newFilter[field] = this._replaceRefs(operand);
newFilter[field] = this._encode(operand);
return newFilter;

@@ -254,5 +256,5 @@ }

_replaceRefs(operand) {
if ((0, _typeUtils.isArray)(operand)) {
return operand.map(op => this._replaceRefs(op));
_encode(operand) {
if ((0, _typeUtils.isFunction)(this.encoder)) {
return this.encoder(operand);
} else {

@@ -259,0 +261,0 @@ return operand;

@@ -23,4 +23,8 @@ "use strict";

exports.Validator = _validator.Validator;
var _wixDataEncoder = require("./wix-data-encoder");
exports.wixDataEncoder = _wixDataEncoder.wixDataEncoder;
var _default = _filterBuilder.filterBuilder;
exports.default = _default;
//# sourceMappingURL=index.js.map
import chai from 'chai';
import { filterBuilder } from '..';
import { filterBuilder, wixDataEncoder } from '..';
var expect = chai.expect;

@@ -13,2 +13,18 @@ function inAnd() {

var filter = filterBuilder();
describe('custom encoders', function () {
it('encode date with wixDataEncoder', function () {
var now = new Date();
var filterWithEncoder = filterBuilder({ encoder: wixDataEncoder });
expect(filterWithEncoder.eq('x', now).getFilterModel()).to.be.eql({
x: { $date: now.toJSON() },
});
});
it('encode with custom encoder', function () {
var encoder = function () { return 3; };
var filterWithEncoder = filterBuilder({ encoder: encoder });
expect(filterWithEncoder.eq('x', 'a').getFilterModel()).to.be.eql({
x: 3,
});
});
});
describe('filter comparison operators', function () {

@@ -15,0 +31,0 @@ it('should produce the correct filter tree', function () {

@@ -21,6 +21,7 @@ import { __extends } from "tslib";

export { FilterBuilder };
export function filterBuilder() {
return new FilterBuilder({});
export function filterBuilder(params) {
if (params === void 0) { params = {}; }
return new FilterBuilder(params);
}
export default filterBuilder;
//# sourceMappingURL=filter-builder.js.map
import { __assign, __extends, __spreadArray } from "tslib";
import { isArray } from './type-utils';
import { isArray, isFunction } from './type-utils';
import clone from './clone';

@@ -19,2 +19,3 @@ import { FilterValidator } from './filter-validator';

_this.invalidArguments = obj.invalidArguments || [];
_this.encoder = obj.encoder || {};
return _this;

@@ -240,3 +241,3 @@ }

newFilter[field] = {};
newFilter[field][filterOperatorName] = this._replaceRefs(operand);
newFilter[field][filterOperatorName] = this._encode(operand);
return newFilter;

@@ -246,10 +247,9 @@ }

var newFilter = {};
newFilter[field] = this._replaceRefs(operand);
newFilter[field] = this._encode(operand);
return newFilter;
}
};
class_2.prototype._replaceRefs = function (operand) {
var _this = this;
if (isArray(operand)) {
return operand.map(function (op) { return _this._replaceRefs(op); });
class_2.prototype._encode = function (operand) {
if (isFunction(this.encoder)) {
return this.encoder(operand);
}

@@ -256,0 +256,0 @@ else {

import { filterBuilder } from './filter-builder';
import filterMixin from './filter-mixin';
import { optimisedQuery as optimiseQuery } from './query-optimiser';
export { filterMixin, filterBuilder, optimiseQuery };
import { wixDataEncoder } from './wix-data-encoder';
export { filterMixin, filterBuilder, optimiseQuery, wixDataEncoder };
export default filterBuilder;
//# sourceMappingURL=index.js.map

@@ -396,3 +396,3 @@ (function webpackUniversalModuleDefinition(root, factory) {

/*!******************************!*\
!*** ./index.ts + 6 modules ***!
!*** ./index.ts + 7 modules ***!
\******************************/

@@ -408,3 +408,4 @@ // ESM COMPAT FLAG

"filterMixin": function() { return /* reexport */ filter_mixin; },
"optimiseQuery": function() { return /* reexport */ optimisedQuery; }
"optimiseQuery": function() { return /* reexport */ optimisedQuery; },
"wixDataEncoder": function() { return /* reexport */ wixDataEncoder; }
});

@@ -431,3 +432,3 @@

;// CONCATENATED MODULE: ./type-utils.ts
function isObject(obj){return getKind(obj)==='object';}function isArray(arr){return kind_of_default()(arr)==='array';}function isDate(obj){return kind_of_default()(obj)==='date';}function isNumber(obj){return kind_of_default()(obj)==='number';}function isBoolean(obj){return getKind(obj)==='boolean';}function isString(obj){return kind_of_default()(obj)==='string';}function isFunction(obj){return getKind(obj)==='function';}function typeForDisplay(obj){return upperCaseFirst(kind_of_default()(obj));}function isUndefined(obj){return getKind(obj)==='undefined';}function isNull(obj){return getKind(obj)==='null';}function upperCaseFirst(str){if(!isString(str)){return str;}var first=str.slice(0,1).toUpperCase();var rest=str.slice(1,str.length);return first+rest;}
function isObject(obj){return getKind(obj)==='object';}function isArray(arr){return kind_of_default()(arr)==='array';}function isDate(obj){return kind_of_default()(obj)==='date';}function isNumber(obj){return kind_of_default()(obj)==='number';}function isBoolean(obj){return getKind(obj)==='boolean';}function isString(obj){return kind_of_default()(obj)==='string';}function isFunction(obj){return kind_of_default()(obj)==='function';}function typeForDisplay(obj){return upperCaseFirst(kind_of_default()(obj));}function isUndefined(obj){return getKind(obj)==='undefined';}function isNull(obj){return getKind(obj)==='null';}function upperCaseFirst(str){if(!isString(str)){return str;}var first=str.slice(0,1).toUpperCase();var rest=str.slice(1,str.length);return first+rest;}
;// CONCATENATED MODULE: ./clone.ts

@@ -440,11 +441,13 @@ function clone(obj){if(obj==null||typeof obj!=='object'){return obj;}var temp=null;if(isDate(obj)){temp=new Date(obj.getTime());}else{temp=obj.constructor();for(var key in obj){temp[key]=clone(obj[key]);}}return temp;}

;// CONCATENATED MODULE: ./filter-mixin.ts
var filterMixin=function filterMixin(Base){if(Base===void 0){Base=function Base(){};}return/*#__PURE__*/function(_Base){inheritsLoose_default()(_class2,_Base);function _class2(obj){var _this;if(obj===void 0){obj={};}_this=_Base.call(this,obj)||this;defineProperty_default()(assertThisInitialized_default()(_this),"filterTree",void 0);defineProperty_default()(assertThisInitialized_default()(_this),"invalidArguments",void 0);_this.filterTree=obj.filterTree||{$and:[]};_this.invalidArguments=obj.invalidArguments||[];return _this;}var _proto=_class2.prototype;_proto.eq=function eq(){for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}return this._binaryAnd('$eq','.eq',args);};_proto.ne=function ne(){for(var _len2=arguments.length,args=new Array(_len2),_key2=0;_key2<_len2;_key2++){args[_key2]=arguments[_key2];}return this._binaryAnd('$ne','.ne',args);};_proto.ge=function ge(){for(var _len3=arguments.length,args=new Array(_len3),_key3=0;_key3<_len3;_key3++){args[_key3]=arguments[_key3];}return this._AndLogicalEquivalence('$gte','.ge',args);};_proto.gt=function gt(){for(var _len4=arguments.length,args=new Array(_len4),_key4=0;_key4<_len4;_key4++){args[_key4]=arguments[_key4];}return this._AndLogicalEquivalence('$gt','.gt',args);};_proto.le=function le(){for(var _len5=arguments.length,args=new Array(_len5),_key5=0;_key5<_len5;_key5++){args[_key5]=arguments[_key5];}return this._AndLogicalEquivalence('$lte','.le',args);};_proto.lt=function lt(){for(var _len6=arguments.length,args=new Array(_len6),_key6=0;_key6<_len6;_key6++){args[_key6]=arguments[_key6];}return this._AndLogicalEquivalence('$lt','.lt',args);};_proto.isNotEmpty=function isNotEmpty(field){var _this$_filterValidato=this._filterValidator('.isNotEmpty').arityIsOne(arguments).validFieldName(field).validateAndAggregate(),newInvalidArguments=_this$_filterValidato[0],valid=_this$_filterValidato[1];if(valid){return this.ne(field,null);}return this._copy(this.filterTree,newInvalidArguments);};_proto.isEmpty=function isEmpty(field){var _this$_filterValidato2=this._filterValidator('.isEmpty').arityIsOne(arguments).validFieldName(field).validateAndAggregate(),newInvalidArguments=_this$_filterValidato2[0],valid=_this$_filterValidato2[1];if(valid){return this.eq(field,null);}return this._copy(this.filterTree,newInvalidArguments);};_proto.startsWith=function startsWith(){for(var _len7=arguments.length,args=new Array(_len7),_key7=0;_key7<_len7;_key7++){args[_key7]=arguments[_key7];}return this._AndStringOperand('$startsWith','.startsWith',args);};_proto.endsWith=function endsWith(){for(var _len8=arguments.length,args=new Array(_len8),_key8=0;_key8<_len8;_key8++){args[_key8]=arguments[_key8];}return this._AndStringOperand('$endsWith','.endsWith',args);};_proto.contains=function contains(){for(var _len9=arguments.length,args=new Array(_len9),_key9=0;_key9<_len9;_key9++){args[_key9]=arguments[_key9];}return this._AndStringOperand('$contains','.contains',args);};_proto.hasSome=function hasSome(){for(var _len10=arguments.length,args=new Array(_len10),_key10=0;_key10<_len10;_key10++){args[_key10]=arguments[_key10];}return this._AndSetOperand('$hasSome','.hasSome',args);};_proto.hasAll=function hasAll(){for(var _len11=arguments.length,args=new Array(_len11),_key11=0;_key11<_len11;_key11++){args[_key11]=arguments[_key11];}return this._AndSetOperand('$hasAll','.hasAll',args);};_proto.or=function or(orQuery){var _this$_filterValidato3=this._filterValidator('.or').arityIsOne(arguments).isInstanceOfSameClass(orQuery).validateAndAggregate(),newInvalidArguments=_this$_filterValidato3[0],valid=_this$_filterValidato3[1];if(valid){var prefix=isEmptyAnd(this.filterTree)?[]:[this.filterTree];return this._copy(inAnd({$or:[].concat(prefix,[orQuery.filterTree])}),newInvalidArguments.concat(orQuery.invalidArguments));}else{return this._copy(this.filterTree,newInvalidArguments);}};_proto.and=function and(andQuery){var _this$_filterValidato4=this._filterValidator('.and').arityIsOne(arguments).isInstanceOfSameClass(andQuery).validateAndAggregate(),newInvalidArguments=_this$_filterValidato4[0],valid=_this$_filterValidato4[1];if(valid){var prefix=isEmptyAnd(this.filterTree)?[]:[this.filterTree];return this._copy(inAnd.apply(void 0,prefix.concat([andQuery.filterTree])),newInvalidArguments.concat(andQuery.invalidArguments));}else{return this._copy(this.filterTree,newInvalidArguments);}};_proto.not=function not(notQuery){var _this$_filterValidato5=this._filterValidator('.not').arityIsOne(arguments).isInstanceOfSameClass(notQuery).validateAndAggregate(),newInvalidArguments=_this$_filterValidato5[0],valid=_this$_filterValidato5[1];if(valid){var newFilterTree=clone(this.filterTree);var notClause={$not:[notQuery.filterTree]};var resultingFilter=inAndOptimized(newFilterTree,notClause);return this._copy(resultingFilter,newInvalidArguments.concat(notQuery.invalidArguments));}else{return this._copy(this.filterTree,newInvalidArguments);}};_proto.between=function between(field,rangeStart,rangeEnd){var _this$_filterValidato6=this._filterValidator('.between').arityIsThree(arguments).sameType(rangeStart,rangeEnd).typeIsStringNumberOrDate(rangeStart).typeIsStringNumberOrDate(rangeEnd).validateAndAggregate(),newInvalidArguments=_this$_filterValidato6[0],valid=_this$_filterValidato6[1];if(valid){return this.ge(field,rangeStart).lt(field,rangeEnd);}return this._copy(this.filterTree,newInvalidArguments);};_proto.getFilterModel=function getFilterModel(){if(this.invalidArguments.length>0){throw new Error(this.invalidArguments.join(' '));}return optimisedQuery(this.filterTree);};_proto.setFilterModel=function setFilterModel(filterModel){return this._copy(filterModel,[]);};_proto._binaryAnd=function _binaryAnd(filterOperatorSymbol,operatorName,args){var _Array$prototype$slic=Array.prototype.slice.call(args),field=_Array$prototype$slic[0],operand=_Array$prototype$slic[1];var _this$_filterValidato7=this._filterValidator(operatorName).arityIsTwo(args).validFieldName(field).validateAndAggregate(),newInvalidArguments=_this$_filterValidato7[0];var newFilterTree=this._makeNewFilter(field,filterOperatorSymbol,operand);return this._copy(newFilterTree,newInvalidArguments);};_proto._AndLogicalEquivalence=function _AndLogicalEquivalence(filterOperatorSymbol,operatorName,args){var _Array$prototype$slic2=Array.prototype.slice.call(args),field=_Array$prototype$slic2[0],operand=_Array$prototype$slic2[1];var _this$_filterValidato8=this._filterValidator(operatorName).arityIsTwo(args).validFieldName(field).typeIsStringNumberOrDate(operand).validateAndAggregate(),newInvalidArguments=_this$_filterValidato8[0];var newFilterTree=this._makeNewFilter(field,filterOperatorSymbol,operand);return this._copy(newFilterTree,newInvalidArguments);};_proto._AndStringOperand=function _AndStringOperand(filterOperatorName,operatorName,args){var _Array$prototype$slic3=Array.prototype.slice.call(args),field=_Array$prototype$slic3[0],operand=_Array$prototype$slic3[1];var _this$_filterValidato9=this._filterValidator(operatorName).arityIsTwo(args).validFieldName(field).typeIsString(operand).validateAndAggregate(),newInvalidArguments=_this$_filterValidato9[0];var newFilterTree=this._makeNewFilter(field,filterOperatorName,operand);return this._copy(newFilterTree,newInvalidArguments);};_proto._AndSetOperand=function _AndSetOperand(filterOperatorName,operatorName,args){var _Array$prototype$slic4=Array.prototype.slice.call(args),field=_Array$prototype$slic4[0],rawOperands=_Array$prototype$slic4.slice(1);var operands=isArray(rawOperands[0])?rawOperands[0]:rawOperands;var _this$_filterValidato10=this._filterValidator(operatorName).arityIsAtLeastTwo(args).validFieldName(field).typeIsStringNumberOrDateForAll(operands).validateAndAggregate(),newInvalidArguments=_this$_filterValidato10[0];var newFilterTree=this._makeNewFilter(field,filterOperatorName,operands);return this._copy(newFilterTree,newInvalidArguments);};_proto._makeNewFilter=function _makeNewFilter(field,filterOperatorName,operand){var newFilterTree=clone(this.filterTree);// filters with 'undefined' value are lost during serialization,
var filterMixin=function filterMixin(Base){if(Base===void 0){Base=function Base(){};}return/*#__PURE__*/function(_Base){inheritsLoose_default()(_class2,_Base);function _class2(obj){var _this;if(obj===void 0){obj={};}_this=_Base.call(this,obj)||this;defineProperty_default()(assertThisInitialized_default()(_this),"filterTree",void 0);defineProperty_default()(assertThisInitialized_default()(_this),"invalidArguments",void 0);defineProperty_default()(assertThisInitialized_default()(_this),"encoder",void 0);_this.filterTree=obj.filterTree||{$and:[]};_this.invalidArguments=obj.invalidArguments||[];_this.encoder=obj.encoder||{};return _this;}var _proto=_class2.prototype;_proto.eq=function eq(){for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}return this._binaryAnd('$eq','.eq',args);};_proto.ne=function ne(){for(var _len2=arguments.length,args=new Array(_len2),_key2=0;_key2<_len2;_key2++){args[_key2]=arguments[_key2];}return this._binaryAnd('$ne','.ne',args);};_proto.ge=function ge(){for(var _len3=arguments.length,args=new Array(_len3),_key3=0;_key3<_len3;_key3++){args[_key3]=arguments[_key3];}return this._AndLogicalEquivalence('$gte','.ge',args);};_proto.gt=function gt(){for(var _len4=arguments.length,args=new Array(_len4),_key4=0;_key4<_len4;_key4++){args[_key4]=arguments[_key4];}return this._AndLogicalEquivalence('$gt','.gt',args);};_proto.le=function le(){for(var _len5=arguments.length,args=new Array(_len5),_key5=0;_key5<_len5;_key5++){args[_key5]=arguments[_key5];}return this._AndLogicalEquivalence('$lte','.le',args);};_proto.lt=function lt(){for(var _len6=arguments.length,args=new Array(_len6),_key6=0;_key6<_len6;_key6++){args[_key6]=arguments[_key6];}return this._AndLogicalEquivalence('$lt','.lt',args);};_proto.isNotEmpty=function isNotEmpty(field){var _this$_filterValidato=this._filterValidator('.isNotEmpty').arityIsOne(arguments).validFieldName(field).validateAndAggregate(),newInvalidArguments=_this$_filterValidato[0],valid=_this$_filterValidato[1];if(valid){return this.ne(field,null);}return this._copy(this.filterTree,newInvalidArguments);};_proto.isEmpty=function isEmpty(field){var _this$_filterValidato2=this._filterValidator('.isEmpty').arityIsOne(arguments).validFieldName(field).validateAndAggregate(),newInvalidArguments=_this$_filterValidato2[0],valid=_this$_filterValidato2[1];if(valid){return this.eq(field,null);}return this._copy(this.filterTree,newInvalidArguments);};_proto.startsWith=function startsWith(){for(var _len7=arguments.length,args=new Array(_len7),_key7=0;_key7<_len7;_key7++){args[_key7]=arguments[_key7];}return this._AndStringOperand('$startsWith','.startsWith',args);};_proto.endsWith=function endsWith(){for(var _len8=arguments.length,args=new Array(_len8),_key8=0;_key8<_len8;_key8++){args[_key8]=arguments[_key8];}return this._AndStringOperand('$endsWith','.endsWith',args);};_proto.contains=function contains(){for(var _len9=arguments.length,args=new Array(_len9),_key9=0;_key9<_len9;_key9++){args[_key9]=arguments[_key9];}return this._AndStringOperand('$contains','.contains',args);};_proto.hasSome=function hasSome(){for(var _len10=arguments.length,args=new Array(_len10),_key10=0;_key10<_len10;_key10++){args[_key10]=arguments[_key10];}return this._AndSetOperand('$hasSome','.hasSome',args);};_proto.hasAll=function hasAll(){for(var _len11=arguments.length,args=new Array(_len11),_key11=0;_key11<_len11;_key11++){args[_key11]=arguments[_key11];}return this._AndSetOperand('$hasAll','.hasAll',args);};_proto.or=function or(orQuery){var _this$_filterValidato3=this._filterValidator('.or').arityIsOne(arguments).isInstanceOfSameClass(orQuery).validateAndAggregate(),newInvalidArguments=_this$_filterValidato3[0],valid=_this$_filterValidato3[1];if(valid){var prefix=isEmptyAnd(this.filterTree)?[]:[this.filterTree];return this._copy(inAnd({$or:[].concat(prefix,[orQuery.filterTree])}),newInvalidArguments.concat(orQuery.invalidArguments));}else{return this._copy(this.filterTree,newInvalidArguments);}};_proto.and=function and(andQuery){var _this$_filterValidato4=this._filterValidator('.and').arityIsOne(arguments).isInstanceOfSameClass(andQuery).validateAndAggregate(),newInvalidArguments=_this$_filterValidato4[0],valid=_this$_filterValidato4[1];if(valid){var prefix=isEmptyAnd(this.filterTree)?[]:[this.filterTree];return this._copy(inAnd.apply(void 0,prefix.concat([andQuery.filterTree])),newInvalidArguments.concat(andQuery.invalidArguments));}else{return this._copy(this.filterTree,newInvalidArguments);}};_proto.not=function not(notQuery){var _this$_filterValidato5=this._filterValidator('.not').arityIsOne(arguments).isInstanceOfSameClass(notQuery).validateAndAggregate(),newInvalidArguments=_this$_filterValidato5[0],valid=_this$_filterValidato5[1];if(valid){var newFilterTree=clone(this.filterTree);var notClause={$not:[notQuery.filterTree]};var resultingFilter=inAndOptimized(newFilterTree,notClause);return this._copy(resultingFilter,newInvalidArguments.concat(notQuery.invalidArguments));}else{return this._copy(this.filterTree,newInvalidArguments);}};_proto.between=function between(field,rangeStart,rangeEnd){var _this$_filterValidato6=this._filterValidator('.between').arityIsThree(arguments).sameType(rangeStart,rangeEnd).typeIsStringNumberOrDate(rangeStart).typeIsStringNumberOrDate(rangeEnd).validateAndAggregate(),newInvalidArguments=_this$_filterValidato6[0],valid=_this$_filterValidato6[1];if(valid){return this.ge(field,rangeStart).lt(field,rangeEnd);}return this._copy(this.filterTree,newInvalidArguments);};_proto.getFilterModel=function getFilterModel(){if(this.invalidArguments.length>0){throw new Error(this.invalidArguments.join(' '));}return optimisedQuery(this.filterTree);};_proto.setFilterModel=function setFilterModel(filterModel){return this._copy(filterModel,[]);};_proto._binaryAnd=function _binaryAnd(filterOperatorSymbol,operatorName,args){var _Array$prototype$slic=Array.prototype.slice.call(args),field=_Array$prototype$slic[0],operand=_Array$prototype$slic[1];var _this$_filterValidato7=this._filterValidator(operatorName).arityIsTwo(args).validFieldName(field).validateAndAggregate(),newInvalidArguments=_this$_filterValidato7[0];var newFilterTree=this._makeNewFilter(field,filterOperatorSymbol,operand);return this._copy(newFilterTree,newInvalidArguments);};_proto._AndLogicalEquivalence=function _AndLogicalEquivalence(filterOperatorSymbol,operatorName,args){var _Array$prototype$slic2=Array.prototype.slice.call(args),field=_Array$prototype$slic2[0],operand=_Array$prototype$slic2[1];var _this$_filterValidato8=this._filterValidator(operatorName).arityIsTwo(args).validFieldName(field).typeIsStringNumberOrDate(operand).validateAndAggregate(),newInvalidArguments=_this$_filterValidato8[0];var newFilterTree=this._makeNewFilter(field,filterOperatorSymbol,operand);return this._copy(newFilterTree,newInvalidArguments);};_proto._AndStringOperand=function _AndStringOperand(filterOperatorName,operatorName,args){var _Array$prototype$slic3=Array.prototype.slice.call(args),field=_Array$prototype$slic3[0],operand=_Array$prototype$slic3[1];var _this$_filterValidato9=this._filterValidator(operatorName).arityIsTwo(args).validFieldName(field).typeIsString(operand).validateAndAggregate(),newInvalidArguments=_this$_filterValidato9[0];var newFilterTree=this._makeNewFilter(field,filterOperatorName,operand);return this._copy(newFilterTree,newInvalidArguments);};_proto._AndSetOperand=function _AndSetOperand(filterOperatorName,operatorName,args){var _Array$prototype$slic4=Array.prototype.slice.call(args),field=_Array$prototype$slic4[0],rawOperands=_Array$prototype$slic4.slice(1);var operands=isArray(rawOperands[0])?rawOperands[0]:rawOperands;var _this$_filterValidato10=this._filterValidator(operatorName).arityIsAtLeastTwo(args).validFieldName(field).typeIsStringNumberOrDateForAll(operands).validateAndAggregate(),newInvalidArguments=_this$_filterValidato10[0];var newFilterTree=this._makeNewFilter(field,filterOperatorName,operands);return this._copy(newFilterTree,newInvalidArguments);};_proto._makeNewFilter=function _makeNewFilter(field,filterOperatorName,operand){var newFilterTree=clone(this.filterTree);// filters with 'undefined' value are lost during serialization,
// e.g. { val: { $ne: undefined } | translates to { val: {} }
// Replacing 'undefined' with 'null' retains the filter.
var serializableOperand=operand===undefined?null:operand;var newFilter=this._buildFilter(field,filterOperatorName,serializableOperand);if(isArray(newFilterTree.$and)){newFilterTree.$and.push(newFilter);return newFilterTree;}else{var result=isEmptyObject(newFilterTree)?inAnd(newFilter):inAnd(newFilterTree,newFilter);return result;}};_proto._buildFilter=function _buildFilter(field,filterOperatorName,operand){if(filterOperatorName!=='$eq'){var newFilter={};newFilter[field]={};newFilter[field][filterOperatorName]=this._replaceRefs(operand);return newFilter;}else{var _newFilter={};_newFilter[field]=this._replaceRefs(operand);return _newFilter;}};_proto._replaceRefs=function _replaceRefs(operand){var _this2=this;if(isArray(operand)){return operand.map(function(op){return _this2._replaceRefs(op);});}else{return operand;}};_proto._copy=function _copy(filterTree,invalidArguments){// @ts-ignore-next-line
var serializableOperand=operand===undefined?null:operand;var newFilter=this._buildFilter(field,filterOperatorName,serializableOperand);if(isArray(newFilterTree.$and)){newFilterTree.$and.push(newFilter);return newFilterTree;}else{var result=isEmptyObject(newFilterTree)?inAnd(newFilter):inAnd(newFilterTree,newFilter);return result;}};_proto._buildFilter=function _buildFilter(field,filterOperatorName,operand){if(filterOperatorName!=='$eq'){var newFilter={};newFilter[field]={};newFilter[field][filterOperatorName]=this._encode(operand);return newFilter;}else{var _newFilter={};_newFilter[field]=this._encode(operand);return _newFilter;}};_proto._encode=function _encode(operand){if(isFunction(this.encoder)){return this.encoder(operand);}else{return operand;}};_proto._copy=function _copy(filterTree,invalidArguments){// @ts-ignore-next-line
return new this.constructor(extends_default()({},this,{filterTree:filterTree,invalidArguments:invalidArguments}));};_proto._filterValidator=function _filterValidator(filterOperatorName){return new FilterValidator(filterOperatorName,this.invalidArguments,this.constructor);};return _class2;}(Base);};function isConjunctiveFormFilter(filterTree){return isArray(filterTree.$and);}function isEmptyObject(obj){return Object.keys(obj).length===0;}function inAnd(){for(var _len12=arguments.length,args=new Array(_len12),_key12=0;_key12<_len12;_key12++){args[_key12]=arguments[_key12];}return{$and:args};}function inAndOptimized(){for(var _len13=arguments.length,args=new Array(_len13),_key13=0;_key13<_len13;_key13++){args[_key13]=arguments[_key13];}return{$and:args.reduce(function(aggr,val){return isConjunctiveFormFilter(val)?aggr.concat(val.$and):aggr.concat([val]);},[])};}function isEmptyAnd(node){return node&&node.$and&&node.$and.length===0;}/* harmony default export */ var filter_mixin = (filterMixin);
;// CONCATENATED MODULE: ./filter-builder.ts
var FilterBuilder=/*#__PURE__*/function(_filterMixin){inheritsLoose_default()(FilterBuilder,_filterMixin);function FilterBuilder(){return _filterMixin.apply(this,arguments)||this;}var _proto=FilterBuilder.prototype;_proto._build=function _build(){return this.getFilterModel();};createClass_default()(FilterBuilder,[{key:"constructorName",get:function get(){return'FilterBuilder';}}]);return FilterBuilder;}(filter_mixin());function filterBuilder(){return new FilterBuilder({});}/* harmony default export */ var filter_builder = ((/* unused pure expression or super */ null && (filterBuilder)));
var FilterBuilder=/*#__PURE__*/function(_filterMixin){inheritsLoose_default()(FilterBuilder,_filterMixin);function FilterBuilder(){return _filterMixin.apply(this,arguments)||this;}var _proto=FilterBuilder.prototype;_proto._build=function _build(){return this.getFilterModel();};createClass_default()(FilterBuilder,[{key:"constructorName",get:function get(){return'FilterBuilder';}}]);return FilterBuilder;}(filter_mixin());function filterBuilder(params){if(params===void 0){params={};}return new FilterBuilder(params);}/* harmony default export */ var filter_builder = ((/* unused pure expression or super */ null && (filterBuilder)));
// EXTERNAL MODULE: ./validator.ts
var validator = __webpack_require__(476);
;// CONCATENATED MODULE: ./wix-data-encoder.ts
function wixDataEncoder(operand){if(isDate(operand)){return{$date:operand.toJSON()};}else{return operand;}}
;// CONCATENATED MODULE: ./index.ts

@@ -451,0 +454,0 @@ /* harmony default export */ var index = (filterBuilder);

@@ -1,2 +0,2 @@

!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define("platformized-filter-builder",[],r):"object"==typeof exports?exports["platformized-filter-builder"]=r():t["platformized-filter-builder"]=r()}("undefined"!=typeof self?self:this,(function(){return function(){var t={306:function(t){var r=Object.prototype.toString;t.exports=function(t){var e=typeof t;return"undefined"===e?"undefined":null===t?"null":!0===t||!1===t||t instanceof Boolean?"boolean":"string"===e||t instanceof String?"string":"number"===e||t instanceof Number?"number":"function"===e||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]"===(e=r.call(t))?"regexp":"[object Date]"===e?"date":"[object Arguments]"===e?"arguments":"[object Error]"===e?"error":"[object Promise]"===e?"promise":function(t){return t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}(t)?"buffer":"[object Set]"===e?"set":"[object WeakSet]"===e?"weakset":"[object Map]"===e?"map":"[object WeakMap]"===e?"weakmap":"[object Symbol]"===e?"symbol":"[object Map Iterator]"===e?"mapiterator":"[object Set Iterator]"===e?"setiterator":"[object String Iterator]"===e?"stringiterator":"[object Array Iterator]"===e?"arrayiterator":"[object Int8Array]"===e?"int8array":"[object Uint8Array]"===e?"uint8array":"[object Uint8ClampedArray]"===e?"uint8clampedarray":"[object Int16Array]"===e?"int16array":"[object Uint16Array]"===e?"uint16array":"[object Int32Array]"===e?"int32array":"[object Uint32Array]"===e?"uint32array":"[object Float32Array]"===e?"float32array":"[object Float64Array]"===e?"float64array":"object"}},663:function(t){t.exports=function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t},t.exports.default=t.exports,t.exports.__esModule=!0},587:function(t){function r(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}t.exports=function(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t},t.exports.default=t.exports,t.exports.__esModule=!0},837:function(t){t.exports=function(t,r,e){return r in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t},t.exports.default=t.exports,t.exports.__esModule=!0},921:function(t){function r(){return t.exports=r=Object.assign||function(t){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])}return t},t.exports.default=t.exports,t.exports.__esModule=!0,r.apply(this,arguments)}t.exports=r,t.exports.default=t.exports,t.exports.__esModule=!0},354:function(t,r,e){var n=e(262);t.exports=function(t,r){t.prototype=Object.create(r.prototype),t.prototype.constructor=t,n(t,r)},t.exports.default=t.exports,t.exports.__esModule=!0},262:function(t){function r(e,n){return t.exports=r=Object.setPrototypeOf||function(t,r){return t.__proto__=r,t},t.exports.default=t.exports,t.exports.__esModule=!0,r(e,n)}t.exports=r,t.exports.default=t.exports,t.exports.__esModule=!0},476:function(){}},r={};function e(n){var i=r[n];if(void 0!==i)return i.exports;var a=r[n]={exports:{}};return t[n](a,a.exports,e),a.exports}e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,{a:r}),r},e.d=function(t,r){for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},e.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return function(){"use strict";e.r(n),e.d(n,{Validator:function(){return M.Validator},default:function(){return E},filterBuilder:function(){return V},filterMixin:function(){return T},optimiseQuery:function(){return x}});var t=e(587),r=e.n(t),i=e(354),a=e.n(i),o=e(921),u=e.n(o),s=e(663),c=e.n(s),l=e(837),f=e.n(l),d=e(306),p=e.n(d);function h(t){return"array"===p()(t)}function v(t){return"date"===p()(t)}function y(t){return"string"===p()(t)}function g(t){return function(t){if(!y(t))return t;var r=t.slice(0,1).toUpperCase(),e=t.slice(1,t.length);return r+e}(p()(t))}function m(t){if(null==t||"object"!=typeof t)return t;var r=null;if(v(t))r=new Date(t.getTime());else for(var e in r=t.constructor(),t)r[e]=m(t[e]);return r}var A=function(){function t(t,r,e){f()(this,"ctor",void 0),f()(this,"_invalidArguments",void 0),f()(this,"_validations",void 0),f()(this,"operatorName",void 0),this._validations=[],this.operatorName=t,this.ctor=e,this._invalidArguments=m(r)}var r=t.prototype;return r.typeIsString=function(t){var r=this;return this.addValidation((function(){return y(t)}),(function(){return"Invalid "+r.operatorName+" parameter value ["+g(t)+"]. "+r.operatorName+" parameter must be a String."}))},r.typeIsStringNumberOrDate=function(t){var r=this;return this.addValidation((function(){return b(t)}),(function(){return"Invalid "+r.operatorName+" parameter value ["+g(t)+"]. Valid "+r.operatorName+" parameter types are String, Number or Date."}))},r.sameType=function(t,r){var e=this;return this.addValidation((function(){return g(t)===g(r)}),(function(){return"Invalid "+e.operatorName+" parameter values ["+g(t)+"] and ["+g(r)+"]. Both parameters must be of the same type."}))},r.typeIsStringNumberOrDateForAll=function(t){var r=this;return this.addValidation((function(){return t.every(b)}),(function(){return"Invalid "+r.operatorName+" usage. "+r.operatorName+" supports only Number, String or Date items."}))},r.validFieldName=function(t){var r=this;return this.addValidation((function(){return y(t)}),(function(){return"Invalid "+r.operatorName+" field value ["+g(t)+"]. "+r.operatorName+" field must be a String."}))},r.isInstanceOfSameClass=function(t){var r=this;return this.addValidation((function(){return t instanceof r.ctor}),(function(){return"Invalid "+r.operatorName+" parameter ["+g(t)+"]. "+r.operatorName+" expects FilterBuilder only."}))},r.arityIsOne=function(t){var r=this;return this.addValidation((function(){return 1===t.length}),(function(){return"Invalid "+r.operatorName+" usage. "+r.operatorName+" requires one parameter."}))},r.arityIsTwo=function(t){var r=this;return this.addValidation((function(){return 2===t.length}),(function(){return"Invalid "+r.operatorName+" usage. "+r.operatorName+" requires two parameters."}))},r.arityIsThree=function(t){var r=this;return this.addValidation((function(){return 3===t.length}),(function(){return"Invalid "+r.operatorName+" usage. "+r.operatorName+" requires three parameters."}))},r.arityIsAtLeastTwo=function(t){var r=this;return this.addValidation((function(){return t.length>=2}),(function(){return"Invalid "+r.operatorName+" usage. "+r.operatorName+" requires at least two parameters."}))},r.addValidation=function(t,r){return this._validations.push({predicateFn:t,messageFn:r}),this},r.validateAndAggregate=function(){var t=this,r=this._validations.every((function(r){var e=r.predicateFn,n=r.messageFn;return t._appendIfInvalid(e(),n())}));return[this._invalidArguments,r]},r._appendIfInvalid=function(t,r){return!!t||(this._invalidArguments.push(r),!1)},t}();function b(t){return y(t)||(r=t,"number"===p()(r))||v(t);var r}function _(t,r){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(e)return(e=e.call(t)).next.bind(e);if(Array.isArray(t)||(e=function(t,r){if(!t)return;if("string"==typeof t)return j(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);"Object"===e&&t.constructor&&(e=t.constructor.name);if("Map"===e||"Set"===e)return Array.from(t);if("Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return j(t,r)}(t))||r&&t&&"number"==typeof t.length){e&&(t=e);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function j(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}var I=[function(t){var r=t.$and;if(Array.isArray(r)&&1===r.length)return r[0]},function(t){var r=t.$and;if(Array.isArray(r)&&0===r.length)return{};return null},function(t){var r=t.$and;if(!r)return;var e=[],n=[];if(r.forEach((function(t){!function(t){var r=Object.keys(t);return r.every((function(t){return t.startsWith("$")}))&&r.length>0}(t)?e=[].concat(e,[t]):n=[].concat(n,[t])})),e.length<=1||function(t){var r=t.map((function(t){return Object.keys(t)})).reduce((function(t,r){return[].concat(t,r)}),[]);return(e=r,n={},e.forEach((function(t){return n[t]=!0})),Object.keys(n)).length!==r.length;var e,n}(e))return;return{$and:[Object.assign.apply(Object,[{}].concat(e))].concat(n)}},function(t){var r=t.$and;if(!r)return;if(!r.find((function(t){return t.$and})))return;return{$and:r.reduce((function(t,r){var e=r.$and;return[].concat(t,e||[r])}),[])}},function(t){var r=t.$or;if(!r)return;if(!r.find((function(t){return t.$or})))return;return{$or:r.reduce((function(t,r){var e=r.$or;return[].concat(t,e||[r])}),[])}}];function x(t){return O(t)[0]}function O(t){return Array.isArray(t)?function(t){var r=t.map(O),e=0<r.filter((function(t){return t[1]})).length;return[r.map((function(t){return t[0]})),e]}(t):"object"!=typeof t||null===t||t instanceof Date?[t,!1]:function(t){var r=c(t),e=r[0],n=r[1],i=s(e),a=i[0],o=i[1];return[a,n||o];function s(t){var r=function(t){for(var r,e=_(I);!(r=e()).done;){var n=(0,r.value)(t);if(n)return n}}(t);return r?[O(r)[0],!0]:[t,!1]}function c(t){var r=Object.entries(t).map(l).filter((function(t){return t[2]}));return[u()({},t,f(r)),!!r.length]}function l(t){var r=t[0],e=O(t[1]);return[r,e[0],e[1]]}function f(t){return t.reduce((function(t,r){var e,n=r[0],i=r[1];return u()({},t,((e={})[n]=i,e))}),{})}}(t)}function w(t){return h(t.$and)}function N(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return{$and:r}}function S(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return{$and:r.reduce((function(t,r){return w(r)?t.concat(r.$and):t.concat([r])}),[])}}function $(t){return t&&t.$and&&0===t.$and.length}var T=function(t){return void 0===t&&(t=function(){}),function(t){function r(r){var e;return void 0===r&&(r={}),e=t.call(this,r)||this,f()(c()(e),"filterTree",void 0),f()(c()(e),"invalidArguments",void 0),e.filterTree=r.filterTree||{$and:[]},e.invalidArguments=r.invalidArguments||[],e}a()(r,t);var e=r.prototype;return e.eq=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return this._binaryAnd("$eq",".eq",r)},e.ne=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return this._binaryAnd("$ne",".ne",r)},e.ge=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return this._AndLogicalEquivalence("$gte",".ge",r)},e.gt=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return this._AndLogicalEquivalence("$gt",".gt",r)},e.le=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return this._AndLogicalEquivalence("$lte",".le",r)},e.lt=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return this._AndLogicalEquivalence("$lt",".lt",r)},e.isNotEmpty=function(t){var r=this._filterValidator(".isNotEmpty").arityIsOne(arguments).validFieldName(t).validateAndAggregate(),e=r[0],n=r[1];return n?this.ne(t,null):this._copy(this.filterTree,e)},e.isEmpty=function(t){var r=this._filterValidator(".isEmpty").arityIsOne(arguments).validFieldName(t).validateAndAggregate(),e=r[0],n=r[1];return n?this.eq(t,null):this._copy(this.filterTree,e)},e.startsWith=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return this._AndStringOperand("$startsWith",".startsWith",r)},e.endsWith=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return this._AndStringOperand("$endsWith",".endsWith",r)},e.contains=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return this._AndStringOperand("$contains",".contains",r)},e.hasSome=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return this._AndSetOperand("$hasSome",".hasSome",r)},e.hasAll=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return this._AndSetOperand("$hasAll",".hasAll",r)},e.or=function(t){var r=this._filterValidator(".or").arityIsOne(arguments).isInstanceOfSameClass(t).validateAndAggregate(),e=r[0],n=r[1];if(n){var i=$(this.filterTree)?[]:[this.filterTree];return this._copy(N({$or:[].concat(i,[t.filterTree])}),e.concat(t.invalidArguments))}return this._copy(this.filterTree,e)},e.and=function(t){var r=this._filterValidator(".and").arityIsOne(arguments).isInstanceOfSameClass(t).validateAndAggregate(),e=r[0],n=r[1];if(n){var i=$(this.filterTree)?[]:[this.filterTree];return this._copy(N.apply(void 0,i.concat([t.filterTree])),e.concat(t.invalidArguments))}return this._copy(this.filterTree,e)},e.not=function(t){var r=this._filterValidator(".not").arityIsOne(arguments).isInstanceOfSameClass(t).validateAndAggregate(),e=r[0],n=r[1];if(n){var i=m(this.filterTree),a={$not:[t.filterTree]},o=S(i,a);return this._copy(o,e.concat(t.invalidArguments))}return this._copy(this.filterTree,e)},e.between=function(t,r,e){var n=this._filterValidator(".between").arityIsThree(arguments).sameType(r,e).typeIsStringNumberOrDate(r).typeIsStringNumberOrDate(e).validateAndAggregate(),i=n[0],a=n[1];return a?this.ge(t,r).lt(t,e):this._copy(this.filterTree,i)},e.getFilterModel=function(){if(this.invalidArguments.length>0)throw new Error(this.invalidArguments.join(" "));return x(this.filterTree)},e.setFilterModel=function(t){return this._copy(t,[])},e._binaryAnd=function(t,r,e){var n=Array.prototype.slice.call(e),i=n[0],a=n[1],o=this._filterValidator(r).arityIsTwo(e).validFieldName(i).validateAndAggregate()[0],u=this._makeNewFilter(i,t,a);return this._copy(u,o)},e._AndLogicalEquivalence=function(t,r,e){var n=Array.prototype.slice.call(e),i=n[0],a=n[1],o=this._filterValidator(r).arityIsTwo(e).validFieldName(i).typeIsStringNumberOrDate(a).validateAndAggregate()[0],u=this._makeNewFilter(i,t,a);return this._copy(u,o)},e._AndStringOperand=function(t,r,e){var n=Array.prototype.slice.call(e),i=n[0],a=n[1],o=this._filterValidator(r).arityIsTwo(e).validFieldName(i).typeIsString(a).validateAndAggregate()[0],u=this._makeNewFilter(i,t,a);return this._copy(u,o)},e._AndSetOperand=function(t,r,e){var n=Array.prototype.slice.call(e),i=n[0],a=n.slice(1),o=h(a[0])?a[0]:a,u=this._filterValidator(r).arityIsAtLeastTwo(e).validFieldName(i).typeIsStringNumberOrDateForAll(o).validateAndAggregate()[0],s=this._makeNewFilter(i,t,o);return this._copy(s,u)},e._makeNewFilter=function(t,r,e){var n,i=m(this.filterTree),a=void 0===e?null:e,o=this._buildFilter(t,r,a);return h(i.$and)?(i.$and.push(o),i):(n=i,0===Object.keys(n).length?N(o):N(i,o))},e._buildFilter=function(t,r,e){if("$eq"!==r){var n={};return n[t]={},n[t][r]=this._replaceRefs(e),n}var i={};return i[t]=this._replaceRefs(e),i},e._replaceRefs=function(t){var r=this;return h(t)?t.map((function(t){return r._replaceRefs(t)})):t},e._copy=function(t,r){return new this.constructor(u()({},this,{filterTree:t,invalidArguments:r}))},e._filterValidator=function(t){return new A(t,this.invalidArguments,this.constructor)},r}(t)},F=function(t){function e(){return t.apply(this,arguments)||this}return a()(e,t),e.prototype._build=function(){return this.getFilterModel()},r()(e,[{key:"constructorName",get:function(){return"FilterBuilder"}}]),e}(T());function V(){return new F({})}var M=e(476),E=V}(),n}()}));
!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define("platformized-filter-builder",[],r):"object"==typeof exports?exports["platformized-filter-builder"]=r():t["platformized-filter-builder"]=r()}("undefined"!=typeof self?self:this,(function(){return function(){var t={306:function(t){var r=Object.prototype.toString;t.exports=function(t){var e=typeof t;return"undefined"===e?"undefined":null===t?"null":!0===t||!1===t||t instanceof Boolean?"boolean":"string"===e||t instanceof String?"string":"number"===e||t instanceof Number?"number":"function"===e||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]"===(e=r.call(t))?"regexp":"[object Date]"===e?"date":"[object Arguments]"===e?"arguments":"[object Error]"===e?"error":"[object Promise]"===e?"promise":function(t){return t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}(t)?"buffer":"[object Set]"===e?"set":"[object WeakSet]"===e?"weakset":"[object Map]"===e?"map":"[object WeakMap]"===e?"weakmap":"[object Symbol]"===e?"symbol":"[object Map Iterator]"===e?"mapiterator":"[object Set Iterator]"===e?"setiterator":"[object String Iterator]"===e?"stringiterator":"[object Array Iterator]"===e?"arrayiterator":"[object Int8Array]"===e?"int8array":"[object Uint8Array]"===e?"uint8array":"[object Uint8ClampedArray]"===e?"uint8clampedarray":"[object Int16Array]"===e?"int16array":"[object Uint16Array]"===e?"uint16array":"[object Int32Array]"===e?"int32array":"[object Uint32Array]"===e?"uint32array":"[object Float32Array]"===e?"float32array":"[object Float64Array]"===e?"float64array":"object"}},663:function(t){t.exports=function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t},t.exports.default=t.exports,t.exports.__esModule=!0},587:function(t){function r(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}t.exports=function(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t},t.exports.default=t.exports,t.exports.__esModule=!0},837:function(t){t.exports=function(t,r,e){return r in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t},t.exports.default=t.exports,t.exports.__esModule=!0},921:function(t){function r(){return t.exports=r=Object.assign||function(t){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])}return t},t.exports.default=t.exports,t.exports.__esModule=!0,r.apply(this,arguments)}t.exports=r,t.exports.default=t.exports,t.exports.__esModule=!0},354:function(t,r,e){var n=e(262);t.exports=function(t,r){t.prototype=Object.create(r.prototype),t.prototype.constructor=t,n(t,r)},t.exports.default=t.exports,t.exports.__esModule=!0},262:function(t){function r(e,n){return t.exports=r=Object.setPrototypeOf||function(t,r){return t.__proto__=r,t},t.exports.default=t.exports,t.exports.__esModule=!0,r(e,n)}t.exports=r,t.exports.default=t.exports,t.exports.__esModule=!0},476:function(){}},r={};function e(n){var i=r[n];if(void 0!==i)return i.exports;var a=r[n]={exports:{}};return t[n](a,a.exports,e),a.exports}e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,{a:r}),r},e.d=function(t,r){for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},e.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return function(){"use strict";e.r(n),e.d(n,{Validator:function(){return M.Validator},default:function(){return k},filterBuilder:function(){return V},filterMixin:function(){return T},optimiseQuery:function(){return x},wixDataEncoder:function(){return E}});var t=e(587),r=e.n(t),i=e(354),a=e.n(i),o=e(921),u=e.n(o),c=e(663),s=e.n(c),l=e(837),f=e.n(l),d=e(306),p=e.n(d);function v(t){return"array"===p()(t)}function h(t){return"date"===p()(t)}function y(t){return"string"===p()(t)}function g(t){return function(t){if(!y(t))return t;var r=t.slice(0,1).toUpperCase(),e=t.slice(1,t.length);return r+e}(p()(t))}function m(t){if(null==t||"object"!=typeof t)return t;var r=null;if(h(t))r=new Date(t.getTime());else for(var e in r=t.constructor(),t)r[e]=m(t[e]);return r}var A=function(){function t(t,r,e){f()(this,"ctor",void 0),f()(this,"_invalidArguments",void 0),f()(this,"_validations",void 0),f()(this,"operatorName",void 0),this._validations=[],this.operatorName=t,this.ctor=e,this._invalidArguments=m(r)}var r=t.prototype;return r.typeIsString=function(t){var r=this;return this.addValidation((function(){return y(t)}),(function(){return"Invalid "+r.operatorName+" parameter value ["+g(t)+"]. "+r.operatorName+" parameter must be a String."}))},r.typeIsStringNumberOrDate=function(t){var r=this;return this.addValidation((function(){return b(t)}),(function(){return"Invalid "+r.operatorName+" parameter value ["+g(t)+"]. Valid "+r.operatorName+" parameter types are String, Number or Date."}))},r.sameType=function(t,r){var e=this;return this.addValidation((function(){return g(t)===g(r)}),(function(){return"Invalid "+e.operatorName+" parameter values ["+g(t)+"] and ["+g(r)+"]. Both parameters must be of the same type."}))},r.typeIsStringNumberOrDateForAll=function(t){var r=this;return this.addValidation((function(){return t.every(b)}),(function(){return"Invalid "+r.operatorName+" usage. "+r.operatorName+" supports only Number, String or Date items."}))},r.validFieldName=function(t){var r=this;return this.addValidation((function(){return y(t)}),(function(){return"Invalid "+r.operatorName+" field value ["+g(t)+"]. "+r.operatorName+" field must be a String."}))},r.isInstanceOfSameClass=function(t){var r=this;return this.addValidation((function(){return t instanceof r.ctor}),(function(){return"Invalid "+r.operatorName+" parameter ["+g(t)+"]. "+r.operatorName+" expects FilterBuilder only."}))},r.arityIsOne=function(t){var r=this;return this.addValidation((function(){return 1===t.length}),(function(){return"Invalid "+r.operatorName+" usage. "+r.operatorName+" requires one parameter."}))},r.arityIsTwo=function(t){var r=this;return this.addValidation((function(){return 2===t.length}),(function(){return"Invalid "+r.operatorName+" usage. "+r.operatorName+" requires two parameters."}))},r.arityIsThree=function(t){var r=this;return this.addValidation((function(){return 3===t.length}),(function(){return"Invalid "+r.operatorName+" usage. "+r.operatorName+" requires three parameters."}))},r.arityIsAtLeastTwo=function(t){var r=this;return this.addValidation((function(){return t.length>=2}),(function(){return"Invalid "+r.operatorName+" usage. "+r.operatorName+" requires at least two parameters."}))},r.addValidation=function(t,r){return this._validations.push({predicateFn:t,messageFn:r}),this},r.validateAndAggregate=function(){var t=this,r=this._validations.every((function(r){var e=r.predicateFn,n=r.messageFn;return t._appendIfInvalid(e(),n())}));return[this._invalidArguments,r]},r._appendIfInvalid=function(t,r){return!!t||(this._invalidArguments.push(r),!1)},t}();function b(t){return y(t)||(r=t,"number"===p()(r))||h(t);var r}function _(t,r){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(e)return(e=e.call(t)).next.bind(e);if(Array.isArray(t)||(e=function(t,r){if(!t)return;if("string"==typeof t)return j(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);"Object"===e&&t.constructor&&(e=t.constructor.name);if("Map"===e||"Set"===e)return Array.from(t);if("Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return j(t,r)}(t))||r&&t&&"number"==typeof t.length){e&&(t=e);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function j(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}var I=[function(t){var r=t.$and;if(Array.isArray(r)&&1===r.length)return r[0]},function(t){var r=t.$and;if(Array.isArray(r)&&0===r.length)return{};return null},function(t){var r=t.$and;if(!r)return;var e=[],n=[];if(r.forEach((function(t){!function(t){var r=Object.keys(t);return r.every((function(t){return t.startsWith("$")}))&&r.length>0}(t)?e=[].concat(e,[t]):n=[].concat(n,[t])})),e.length<=1||function(t){var r=t.map((function(t){return Object.keys(t)})).reduce((function(t,r){return[].concat(t,r)}),[]);return(e=r,n={},e.forEach((function(t){return n[t]=!0})),Object.keys(n)).length!==r.length;var e,n}(e))return;return{$and:[Object.assign.apply(Object,[{}].concat(e))].concat(n)}},function(t){var r=t.$and;if(!r)return;if(!r.find((function(t){return t.$and})))return;return{$and:r.reduce((function(t,r){var e=r.$and;return[].concat(t,e||[r])}),[])}},function(t){var r=t.$or;if(!r)return;if(!r.find((function(t){return t.$or})))return;return{$or:r.reduce((function(t,r){var e=r.$or;return[].concat(t,e||[r])}),[])}}];function x(t){return O(t)[0]}function O(t){return Array.isArray(t)?function(t){var r=t.map(O),e=0<r.filter((function(t){return t[1]})).length;return[r.map((function(t){return t[0]})),e]}(t):"object"!=typeof t||null===t||t instanceof Date?[t,!1]:function(t){var r=s(t),e=r[0],n=r[1],i=c(e),a=i[0],o=i[1];return[a,n||o];function c(t){var r=function(t){for(var r,e=_(I);!(r=e()).done;){var n=(0,r.value)(t);if(n)return n}}(t);return r?[O(r)[0],!0]:[t,!1]}function s(t){var r=Object.entries(t).map(l).filter((function(t){return t[2]}));return[u()({},t,f(r)),!!r.length]}function l(t){var r=t[0],e=O(t[1]);return[r,e[0],e[1]]}function f(t){return t.reduce((function(t,r){var e,n=r[0],i=r[1];return u()({},t,((e={})[n]=i,e))}),{})}}(t)}function w(t){return v(t.$and)}function N(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return{$and:r}}function S(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return{$and:r.reduce((function(t,r){return w(r)?t.concat(r.$and):t.concat([r])}),[])}}function $(t){return t&&t.$and&&0===t.$and.length}var T=function(t){return void 0===t&&(t=function(){}),function(t){function r(r){var e;return void 0===r&&(r={}),e=t.call(this,r)||this,f()(s()(e),"filterTree",void 0),f()(s()(e),"invalidArguments",void 0),f()(s()(e),"encoder",void 0),e.filterTree=r.filterTree||{$and:[]},e.invalidArguments=r.invalidArguments||[],e.encoder=r.encoder||{},e}a()(r,t);var e=r.prototype;return e.eq=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return this._binaryAnd("$eq",".eq",r)},e.ne=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return this._binaryAnd("$ne",".ne",r)},e.ge=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return this._AndLogicalEquivalence("$gte",".ge",r)},e.gt=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return this._AndLogicalEquivalence("$gt",".gt",r)},e.le=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return this._AndLogicalEquivalence("$lte",".le",r)},e.lt=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return this._AndLogicalEquivalence("$lt",".lt",r)},e.isNotEmpty=function(t){var r=this._filterValidator(".isNotEmpty").arityIsOne(arguments).validFieldName(t).validateAndAggregate(),e=r[0],n=r[1];return n?this.ne(t,null):this._copy(this.filterTree,e)},e.isEmpty=function(t){var r=this._filterValidator(".isEmpty").arityIsOne(arguments).validFieldName(t).validateAndAggregate(),e=r[0],n=r[1];return n?this.eq(t,null):this._copy(this.filterTree,e)},e.startsWith=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return this._AndStringOperand("$startsWith",".startsWith",r)},e.endsWith=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return this._AndStringOperand("$endsWith",".endsWith",r)},e.contains=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return this._AndStringOperand("$contains",".contains",r)},e.hasSome=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return this._AndSetOperand("$hasSome",".hasSome",r)},e.hasAll=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return this._AndSetOperand("$hasAll",".hasAll",r)},e.or=function(t){var r=this._filterValidator(".or").arityIsOne(arguments).isInstanceOfSameClass(t).validateAndAggregate(),e=r[0],n=r[1];if(n){var i=$(this.filterTree)?[]:[this.filterTree];return this._copy(N({$or:[].concat(i,[t.filterTree])}),e.concat(t.invalidArguments))}return this._copy(this.filterTree,e)},e.and=function(t){var r=this._filterValidator(".and").arityIsOne(arguments).isInstanceOfSameClass(t).validateAndAggregate(),e=r[0],n=r[1];if(n){var i=$(this.filterTree)?[]:[this.filterTree];return this._copy(N.apply(void 0,i.concat([t.filterTree])),e.concat(t.invalidArguments))}return this._copy(this.filterTree,e)},e.not=function(t){var r=this._filterValidator(".not").arityIsOne(arguments).isInstanceOfSameClass(t).validateAndAggregate(),e=r[0],n=r[1];if(n){var i=m(this.filterTree),a={$not:[t.filterTree]},o=S(i,a);return this._copy(o,e.concat(t.invalidArguments))}return this._copy(this.filterTree,e)},e.between=function(t,r,e){var n=this._filterValidator(".between").arityIsThree(arguments).sameType(r,e).typeIsStringNumberOrDate(r).typeIsStringNumberOrDate(e).validateAndAggregate(),i=n[0],a=n[1];return a?this.ge(t,r).lt(t,e):this._copy(this.filterTree,i)},e.getFilterModel=function(){if(this.invalidArguments.length>0)throw new Error(this.invalidArguments.join(" "));return x(this.filterTree)},e.setFilterModel=function(t){return this._copy(t,[])},e._binaryAnd=function(t,r,e){var n=Array.prototype.slice.call(e),i=n[0],a=n[1],o=this._filterValidator(r).arityIsTwo(e).validFieldName(i).validateAndAggregate()[0],u=this._makeNewFilter(i,t,a);return this._copy(u,o)},e._AndLogicalEquivalence=function(t,r,e){var n=Array.prototype.slice.call(e),i=n[0],a=n[1],o=this._filterValidator(r).arityIsTwo(e).validFieldName(i).typeIsStringNumberOrDate(a).validateAndAggregate()[0],u=this._makeNewFilter(i,t,a);return this._copy(u,o)},e._AndStringOperand=function(t,r,e){var n=Array.prototype.slice.call(e),i=n[0],a=n[1],o=this._filterValidator(r).arityIsTwo(e).validFieldName(i).typeIsString(a).validateAndAggregate()[0],u=this._makeNewFilter(i,t,a);return this._copy(u,o)},e._AndSetOperand=function(t,r,e){var n=Array.prototype.slice.call(e),i=n[0],a=n.slice(1),o=v(a[0])?a[0]:a,u=this._filterValidator(r).arityIsAtLeastTwo(e).validFieldName(i).typeIsStringNumberOrDateForAll(o).validateAndAggregate()[0],c=this._makeNewFilter(i,t,o);return this._copy(c,u)},e._makeNewFilter=function(t,r,e){var n,i=m(this.filterTree),a=void 0===e?null:e,o=this._buildFilter(t,r,a);return v(i.$and)?(i.$and.push(o),i):(n=i,0===Object.keys(n).length?N(o):N(i,o))},e._buildFilter=function(t,r,e){if("$eq"!==r){var n={};return n[t]={},n[t][r]=this._encode(e),n}var i={};return i[t]=this._encode(e),i},e._encode=function(t){return r=this.encoder,"function"===p()(r)?this.encoder(t):t;var r},e._copy=function(t,r){return new this.constructor(u()({},this,{filterTree:t,invalidArguments:r}))},e._filterValidator=function(t){return new A(t,this.invalidArguments,this.constructor)},r}(t)},F=function(t){function e(){return t.apply(this,arguments)||this}return a()(e,t),e.prototype._build=function(){return this.getFilterModel()},r()(e,[{key:"constructorName",get:function(){return"FilterBuilder"}}]),e}(T());function V(t){return void 0===t&&(t={}),new F(t)}var M=e(476);function E(t){return h(t)?{$date:t.toJSON()}:t}var k=V}(),n}()}));
//# sourceMappingURL=filter-builder.umd.min.js.map
{
"filter-builder.js": "https://static.parastorage.com/services/filter-builder/6bf817bca69d4c7e5982164f43a4d405a632dda471bf34a584c03b9b/filter-builder.umd.js"
"filter-builder.js": "https://static.parastorage.com/services/filter-builder/2eb4832247638db8ab64cf87850c5e5cad98e758187b789dd7e2e80e/filter-builder.umd.js"
}
{
"filter-builder.js": "https://static.parastorage.com/services/filter-builder/6bf817bca69d4c7e5982164f43a4d405a632dda471bf34a584c03b9b/filter-builder.umd.min.js"
"filter-builder.js": "https://static.parastorage.com/services/filter-builder/2eb4832247638db8ab64cf87850c5e5cad98e758187b789dd7e2e80e/filter-builder.umd.min.js"
}

@@ -5,2 +5,3 @@ declare const FilterBuilder_base: {

invalidArguments?: any;
encoder?: any;
}): {

@@ -10,2 +11,3 @@ [x: string]: any;

invalidArguments: any;
encoder: any;
eq(...args: any[]): any;

@@ -36,3 +38,3 @@ ne(...args: any[]): any;

_buildFilter(field: any, filterOperatorName: any, operand: any): {};
_replaceRefs(operand: any): any;
_encode(operand: any): any;
_copy(filterTree: any, invalidArguments: any): any;

@@ -47,4 +49,4 @@ _filterValidator(filterOperatorName: any): import("./validator").Validator;

}
export declare function filterBuilder(): FilterBuilder;
export declare function filterBuilder(params?: {}): FilterBuilder;
export default filterBuilder;
//# sourceMappingURL=filter-builder.d.ts.map

@@ -6,2 +6,3 @@ import { Validator } from './validator';

invalidArguments?;
encoder?;
}): {

@@ -11,2 +12,3 @@ [x: string]: any;

invalidArguments: any;
encoder: any;
eq(...args: any[]): any;

@@ -37,3 +39,3 @@ ne(...args: any[]): any;

_buildFilter(field: any, filterOperatorName: any, operand: any): {};
_replaceRefs(operand: any): any;
_encode(operand: any): any;
_copy(filterTree: any, invalidArguments: any): any;

@@ -40,0 +42,0 @@ _filterValidator(filterOperatorName: any): Validator;

@@ -5,4 +5,5 @@ import { filterBuilder } from './filter-builder';

import { Validator } from './validator';
export { filterMixin, filterBuilder, optimiseQuery, Validator };
import { wixDataEncoder } from './wix-data-encoder';
export { filterMixin, filterBuilder, optimiseQuery, Validator, wixDataEncoder };
export default filterBuilder;
//# sourceMappingURL=index.d.ts.map
{
"name": "@wix/filter-builder",
"version": "1.0.10",
"version": "1.0.11",
"license": "UNLICENSED",

@@ -92,3 +92,3 @@ "author": {

},
"falconPackageHash": "4507fc9f8b0be68e9d4ce5091a7dcc8633b74f106c4c2a3169482f9c"
"falconPackageHash": "b68a0b1b2458464b1d8d419e639c782a8cb4abfd48fbe7539ddd6e7b"
}

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

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

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

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