@wix/filter-builder
Advanced tools
Comparing version 1.0.39 to 1.0.40
@@ -20,4 +20,3 @@ "use strict"; | ||
} | ||
var _default = filterBuilder; | ||
exports.default = _default; | ||
var _default = exports.default = filterBuilder; | ||
//# sourceMappingURL=filter-builder.js.map |
@@ -42,5 +42,3 @@ "use strict"; | ||
isNotEmpty(field) { | ||
const _this$_filterValidato = this._filterValidator('.isNotEmpty').arityIsOne(arguments).validFieldName(field).validateAndAggregate(), | ||
newInvalidArguments = _this$_filterValidato[0], | ||
valid = _this$_filterValidato[1]; | ||
const [newInvalidArguments, valid] = this._filterValidator('.isNotEmpty').arityIsOne(arguments).validFieldName(field).validateAndAggregate(); | ||
if (valid) { | ||
@@ -52,5 +50,3 @@ return this.ne(field, null); | ||
isEmpty(field) { | ||
const _this$_filterValidato2 = this._filterValidator('.isEmpty').arityIsOne(arguments).validFieldName(field).validateAndAggregate(), | ||
newInvalidArguments = _this$_filterValidato2[0], | ||
valid = _this$_filterValidato2[1]; | ||
const [newInvalidArguments, valid] = this._filterValidator('.isEmpty').arityIsOne(arguments).validFieldName(field).validateAndAggregate(); | ||
if (valid) { | ||
@@ -77,5 +73,3 @@ return this.eq(field, null); | ||
or(orQuery) { | ||
const _this$_filterValidato3 = this._filterValidator('.or').arityIsOne(arguments).isInstanceOfSameClass(orQuery).validateAndAggregate(), | ||
newInvalidArguments = _this$_filterValidato3[0], | ||
valid = _this$_filterValidato3[1]; | ||
const [newInvalidArguments, valid] = this._filterValidator('.or').arityIsOne(arguments).isInstanceOfSameClass(orQuery).validateAndAggregate(); | ||
if (valid) { | ||
@@ -91,5 +85,3 @@ const prefix = isEmptyAnd(this.filterTree) ? [] : [this.filterTree]; | ||
and(andQuery) { | ||
const _this$_filterValidato4 = this._filterValidator('.and').arityIsOne(arguments).isInstanceOfSameClass(andQuery).validateAndAggregate(), | ||
newInvalidArguments = _this$_filterValidato4[0], | ||
valid = _this$_filterValidato4[1]; | ||
const [newInvalidArguments, valid] = this._filterValidator('.and').arityIsOne(arguments).isInstanceOfSameClass(andQuery).validateAndAggregate(); | ||
if (valid) { | ||
@@ -103,5 +95,3 @@ const prefix = isEmptyAnd(this.filterTree) ? [] : [this.filterTree]; | ||
not(notQuery) { | ||
const _this$_filterValidato5 = this._filterValidator('.not').arityIsOne(arguments).isInstanceOfSameClass(notQuery).validateAndAggregate(), | ||
newInvalidArguments = _this$_filterValidato5[0], | ||
valid = _this$_filterValidato5[1]; | ||
const [newInvalidArguments, valid] = this._filterValidator('.not').arityIsOne(arguments).isInstanceOfSameClass(notQuery).validateAndAggregate(); | ||
if (valid) { | ||
@@ -119,5 +109,3 @@ const newFilterTree = (0, _clone.default)(this.filterTree); | ||
between(field, rangeStart, rangeEnd) { | ||
const _this$_filterValidato6 = this._filterValidator('.between').arityIsThree(arguments).sameType(rangeStart, rangeEnd).typeIsStringNumberOrDate(rangeStart).typeIsStringNumberOrDate(rangeEnd).validateAndAggregate(), | ||
newInvalidArguments = _this$_filterValidato6[0], | ||
valid = _this$_filterValidato6[1]; | ||
const [newInvalidArguments, valid] = this._filterValidator('.between').arityIsThree(arguments).sameType(rangeStart, rangeEnd).typeIsStringNumberOrDate(rangeStart).typeIsStringNumberOrDate(rangeEnd).validateAndAggregate(); | ||
if (valid) { | ||
@@ -138,7 +126,4 @@ return this.ge(field, rangeStart).lt(field, rangeEnd); | ||
_binaryAnd(filterOperatorSymbol, operatorName, args) { | ||
const _Array$prototype$slic = Array.prototype.slice.call(args), | ||
field = _Array$prototype$slic[0], | ||
operand = _Array$prototype$slic[1]; | ||
const _this$_filterValidato7 = this._filterValidator(operatorName).arityIsTwo(args).validFieldName(field).validateAndAggregate(), | ||
newInvalidArguments = _this$_filterValidato7[0]; | ||
const [field, operand] = Array.prototype.slice.call(args); | ||
const [newInvalidArguments] = this._filterValidator(operatorName).arityIsTwo(args).validFieldName(field).validateAndAggregate(); | ||
const newFilterTree = this._makeNewFilter(field, filterOperatorSymbol, operand); | ||
@@ -148,7 +133,4 @@ return this._copy(newFilterTree, newInvalidArguments); | ||
_AndLogicalEquivalence(filterOperatorSymbol, operatorName, args) { | ||
const _Array$prototype$slic2 = Array.prototype.slice.call(args), | ||
field = _Array$prototype$slic2[0], | ||
operand = _Array$prototype$slic2[1]; | ||
const _this$_filterValidato8 = this._filterValidator(operatorName).arityIsTwo(args).validFieldName(field).typeIsStringNumberOrDate(operand).validateAndAggregate(), | ||
newInvalidArguments = _this$_filterValidato8[0]; | ||
const [field, operand] = Array.prototype.slice.call(args); | ||
const [newInvalidArguments] = this._filterValidator(operatorName).arityIsTwo(args).validFieldName(field).typeIsStringNumberOrDate(operand).validateAndAggregate(); | ||
const newFilterTree = this._makeNewFilter(field, filterOperatorSymbol, operand); | ||
@@ -158,7 +140,4 @@ return this._copy(newFilterTree, newInvalidArguments); | ||
_AndStringOperand(filterOperatorName, operatorName, args) { | ||
const _Array$prototype$slic3 = Array.prototype.slice.call(args), | ||
field = _Array$prototype$slic3[0], | ||
operand = _Array$prototype$slic3[1]; | ||
const _this$_filterValidato9 = this._filterValidator(operatorName).arityIsTwo(args).validFieldName(field).typeIsString(operand).validateAndAggregate(), | ||
newInvalidArguments = _this$_filterValidato9[0]; | ||
const [field, operand] = Array.prototype.slice.call(args); | ||
const [newInvalidArguments] = this._filterValidator(operatorName).arityIsTwo(args).validFieldName(field).typeIsString(operand).validateAndAggregate(); | ||
const newFilterTree = this._makeNewFilter(field, filterOperatorName, operand); | ||
@@ -168,8 +147,5 @@ return this._copy(newFilterTree, newInvalidArguments); | ||
_AndSetOperand(filterOperatorName, operatorName, args) { | ||
const _Array$prototype$slic4 = Array.prototype.slice.call(args), | ||
field = _Array$prototype$slic4[0], | ||
rawOperands = _Array$prototype$slic4.slice(1); | ||
const [field, ...rawOperands] = Array.prototype.slice.call(args); | ||
const operands = (0, _typeUtils.isArray)(rawOperands[0]) ? rawOperands[0] : rawOperands; | ||
const _this$_filterValidato10 = this._filterValidator(operatorName).arityIsAtLeastTwo(args).validFieldName(field).typeIsStringNumberOrDateForAll(operands).validateAndAggregate(), | ||
newInvalidArguments = _this$_filterValidato10[0]; | ||
const [newInvalidArguments] = this._filterValidator(operatorName).arityIsAtLeastTwo(args).validFieldName(field).typeIsStringNumberOrDateForAll(operands).validateAndAggregate(); | ||
const newFilterTree = this._makeNewFilter(field, filterOperatorName, operands); | ||
@@ -244,4 +220,3 @@ return this._copy(newFilterTree, newInvalidArguments); | ||
} | ||
var _default = filterMixin; | ||
exports.default = _default; | ||
var _default = exports.default = filterMixin; | ||
//# sourceMappingURL=filter-mixin.js.map |
@@ -16,4 +16,3 @@ "use strict"; | ||
exports.wixDataEncoder = _wixDataEncoder.wixDataEncoder; | ||
var _default = _filterBuilder.filterBuilder; | ||
exports.default = _default; | ||
var _default = exports.default = _filterBuilder.filterBuilder; | ||
//# sourceMappingURL=index.js.map |
@@ -7,4 +7,3 @@ "use strict"; | ||
function optimisedQuery(query) { | ||
const _fullyOptimised = fullyOptimised(query), | ||
newQuery = _fullyOptimised[0]; | ||
const [newQuery] = fullyOptimised(query); | ||
return newQuery; | ||
@@ -28,8 +27,4 @@ } | ||
function fullyOptimisedObject(query) { | ||
const _fullEntriesOptimisat = fullEntriesOptimisation(query), | ||
queryAfterOptimisingEntries = _fullEntriesOptimisat[0], | ||
changedStage1 = _fullEntriesOptimisat[1]; | ||
const _fullObjectOptimisati = fullObjectOptimisation(queryAfterOptimisingEntries), | ||
queryAfterFullOptimisation = _fullObjectOptimisati[0], | ||
changedStage2 = _fullObjectOptimisati[1]; | ||
const [queryAfterOptimisingEntries, changedStage1] = fullEntriesOptimisation(query); | ||
const [queryAfterFullOptimisation, changedStage2] = fullObjectOptimisation(queryAfterOptimisingEntries); | ||
const changed = changedStage1 || changedStage2; | ||
@@ -42,4 +37,3 @@ return [queryAfterFullOptimisation, changed]; | ||
} | ||
const _fullyOptimised2 = fullyOptimised(updatedQuery), | ||
finalQuery = _fullyOptimised2[0]; | ||
const [finalQuery] = fullyOptimised(updatedQuery); | ||
return [finalQuery, true]; | ||
@@ -57,5 +51,3 @@ } | ||
function entryOptimisation([key, value]) { | ||
const _fullyOptimised3 = fullyOptimised(value), | ||
newValue = _fullyOptimised3[0], | ||
changed = _fullyOptimised3[1]; | ||
const [newValue, changed] = fullyOptimised(value); | ||
return [key, newValue, changed]; | ||
@@ -62,0 +54,0 @@ } |
import chai from 'chai'; | ||
import { filterBuilder, wixDataEncoder } from '..'; | ||
var expect = chai.expect; | ||
function inAnd() { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
const expect = chai.expect; | ||
function inAnd(...args) { | ||
return { $and: args }; | ||
} | ||
describe('filter', function () { | ||
var filter = filterBuilder(); | ||
const filter = filterBuilder(); | ||
describe('custom encoders', function () { | ||
it('encode date with wixDataEncoder', function () { | ||
var now = new Date(); | ||
var filterWithEncoder = filterBuilder({ encoder: wixDataEncoder }); | ||
const now = new Date(); | ||
const filterWithEncoder = filterBuilder({ encoder: wixDataEncoder }); | ||
expect(filterWithEncoder.eq('x', now).getFilterModel()).to.be.eql({ | ||
@@ -22,4 +18,4 @@ x: { $date: now.toJSON() }, | ||
it('encode with custom encoder', function () { | ||
var encoder = function () { return 3; }; | ||
var filterWithEncoder = filterBuilder({ encoder: encoder }); | ||
const encoder = () => 3; | ||
const filterWithEncoder = filterBuilder({ encoder }); | ||
expect(filterWithEncoder.eq('x', 'a').getFilterModel()).to.be.eql({ | ||
@@ -65,45 +61,45 @@ x: 3, | ||
it('should accept valid arguments for all types of queries', function () { | ||
expect(function () { return filter.eq('x', 0); }).to.not.throw(Error); | ||
expect(function () { return filter.ne('x', 0); }).to.not.throw(Error); | ||
expect(function () { return filter.gt('x', 0); }).to.not.throw(Error); | ||
expect(function () { return filter.ge('x', 0); }).to.not.throw(Error); | ||
expect(function () { return filter.lt('x', 0); }).to.not.throw(Error); | ||
expect(function () { return filter.le('x', 0); }).to.not.throw(Error); | ||
expect(function () { return filter.startsWith('x', ''); }).to.not.throw(Error); | ||
expect(function () { return filter.endsWith('x', ''); }).to.not.throw(Error); | ||
expect(function () { return filter.contains('x', ''); }).to.not.throw(Error); | ||
expect(() => filter.eq('x', 0)).to.not.throw(Error); | ||
expect(() => filter.ne('x', 0)).to.not.throw(Error); | ||
expect(() => filter.gt('x', 0)).to.not.throw(Error); | ||
expect(() => filter.ge('x', 0)).to.not.throw(Error); | ||
expect(() => filter.lt('x', 0)).to.not.throw(Error); | ||
expect(() => filter.le('x', 0)).to.not.throw(Error); | ||
expect(() => filter.startsWith('x', '')).to.not.throw(Error); | ||
expect(() => filter.endsWith('x', '')).to.not.throw(Error); | ||
expect(() => filter.contains('x', '')).to.not.throw(Error); | ||
}); | ||
var filterTreeGetters = ['_build', 'getFilterModel']; | ||
const filterTreeGetters = ['_build', 'getFilterModel']; | ||
filterTreeGetters.forEach(function (filterTreeGetter) { | ||
describe(filterTreeGetter, function () { | ||
it('should throw error if builder is called with too little arguments', function () { | ||
expect(function () { return filter.eq('x')._build(); }).to.throw('Invalid .eq usage. .eq requires two parameters.'); | ||
expect(function () { return filter.ne('x')._build(); }).to.throw('Invalid .ne usage. .ne requires two parameters.'); | ||
expect(function () { return filter.gt('x')._build(); }).to.throw('Invalid .gt usage. .gt requires two parameters.'); | ||
expect(function () { return filter.ge('x')._build(); }).to.throw('Invalid .ge usage. .ge requires two parameters.'); | ||
expect(function () { return filter.lt('x')._build(); }).to.throw('Invalid .lt usage. .lt requires two parameters.'); | ||
expect(function () { return filter.le('x')._build(); }).to.throw('Invalid .le usage. .le requires two parameters.'); | ||
expect(function () { return filter.startsWith('x')._build(); }).to.throw('Invalid .startsWith usage. .startsWith requires two parameters.'); | ||
expect(function () { return filter.endsWith('x')._build(); }).to.throw('Invalid .endsWith usage. .endsWith requires two parameters.'); | ||
expect(function () { return filter.contains('x')._build(); }).to.throw('Invalid .contains usage. .contains requires two parameters.'); | ||
expect(function () { return filter.isNotEmpty()._build(); }).to.throw('Invalid .isNotEmpty usage. .isNotEmpty requires one parameter.'); | ||
expect(function () { return filter.isEmpty()._build(); }).to.throw('Invalid .isEmpty usage. .isEmpty requires one parameter.'); | ||
expect(function () { return filter.isNotEmpty(1)._build(); }).to.throw('Invalid .isNotEmpty field value [Number]. .isNotEmpty field must be a String.'); | ||
expect(function () { return filter.isEmpty(1)._build(); }).to.throw('Invalid .isEmpty field value [Number]. .isEmpty field must be a String.'); | ||
expect(function () { return filter.or()._build(); }).to.throw('Invalid .or usage. .or requires one parameter.'); | ||
expect(function () { return filter.and()._build(); }).to.throw('Invalid .and usage. .and requires one parameter.'); | ||
expect(function () { return filter.not()._build(); }).to.throw('Invalid .not usage. .not requires one parameter.'); | ||
expect(function () { return filter.between()._build(); }).to.throw('Invalid .between usage. .between requires three parameters.'); | ||
expect(function () { return filter.between('x')._build(); }).to.throw('Invalid .between usage. .between requires three parameters.'); | ||
expect(function () { return filter.between('x', 'x')._build(); }).to.throw('Invalid .between usage. .between requires three parameters.'); | ||
expect(function () { return filter.hasSome('x')._build(); }).to.throw('Invalid .hasSome usage. .hasSome requires at least two parameters.'); | ||
expect(function () { return filter.hasAll('x')._build(); }).to.throw('Invalid .hasAll usage. .hasAll requires at least two parameters.'); | ||
expect(() => filter.eq('x')._build()).to.throw('Invalid .eq usage. .eq requires two parameters.'); | ||
expect(() => filter.ne('x')._build()).to.throw('Invalid .ne usage. .ne requires two parameters.'); | ||
expect(() => filter.gt('x')._build()).to.throw('Invalid .gt usage. .gt requires two parameters.'); | ||
expect(() => filter.ge('x')._build()).to.throw('Invalid .ge usage. .ge requires two parameters.'); | ||
expect(() => filter.lt('x')._build()).to.throw('Invalid .lt usage. .lt requires two parameters.'); | ||
expect(() => filter.le('x')._build()).to.throw('Invalid .le usage. .le requires two parameters.'); | ||
expect(() => filter.startsWith('x')._build()).to.throw('Invalid .startsWith usage. .startsWith requires two parameters.'); | ||
expect(() => filter.endsWith('x')._build()).to.throw('Invalid .endsWith usage. .endsWith requires two parameters.'); | ||
expect(() => filter.contains('x')._build()).to.throw('Invalid .contains usage. .contains requires two parameters.'); | ||
expect(() => filter.isNotEmpty()._build()).to.throw('Invalid .isNotEmpty usage. .isNotEmpty requires one parameter.'); | ||
expect(() => filter.isEmpty()._build()).to.throw('Invalid .isEmpty usage. .isEmpty requires one parameter.'); | ||
expect(() => filter.isNotEmpty(1)._build()).to.throw('Invalid .isNotEmpty field value [Number]. .isNotEmpty field must be a String.'); | ||
expect(() => filter.isEmpty(1)._build()).to.throw('Invalid .isEmpty field value [Number]. .isEmpty field must be a String.'); | ||
expect(() => filter.or()._build()).to.throw('Invalid .or usage. .or requires one parameter.'); | ||
expect(() => filter.and()._build()).to.throw('Invalid .and usage. .and requires one parameter.'); | ||
expect(() => filter.not()._build()).to.throw('Invalid .not usage. .not requires one parameter.'); | ||
expect(() => filter.between()._build()).to.throw('Invalid .between usage. .between requires three parameters.'); | ||
expect(() => filter.between('x')._build()).to.throw('Invalid .between usage. .between requires three parameters.'); | ||
expect(() => filter.between('x', 'x')._build()).to.throw('Invalid .between usage. .between requires three parameters.'); | ||
expect(() => filter.hasSome('x')._build()).to.throw('Invalid .hasSome usage. .hasSome requires at least two parameters.'); | ||
expect(() => filter.hasAll('x')._build()).to.throw('Invalid .hasAll usage. .hasAll requires at least two parameters.'); | ||
}); | ||
it('should validate the type of the other query', function () { | ||
expect(function () { return filter.or(null)._build(); }).to.throw('Invalid .or parameter [Null]. .or expects FilterBuilder only.'); | ||
expect(function () { return filter.or({})._build(); }).to.throw('Invalid .or parameter [Object]. .or expects FilterBuilder only.'); | ||
expect(function () { return filter.or([])._build(); }).to.throw('Invalid .or parameter [Array]. .or expects FilterBuilder only.'); | ||
expect(function () { return filter.not(null)._build(); }).to.throw('Invalid .not parameter [Null]. .not expects FilterBuilder only'); | ||
expect(function () { return filter.not({})._build(); }).to.throw('Invalid .not parameter [Object]. .not expects FilterBuilder only'); | ||
expect(function () { return filter.not([])._build(); }).to.throw('Invalid .not parameter [Array]. .not expects FilterBuilder only'); | ||
expect(() => filter.or(null)._build()).to.throw('Invalid .or parameter [Null]. .or expects FilterBuilder only.'); | ||
expect(() => filter.or({})._build()).to.throw('Invalid .or parameter [Object]. .or expects FilterBuilder only.'); | ||
expect(() => filter.or([])._build()).to.throw('Invalid .or parameter [Array]. .or expects FilterBuilder only.'); | ||
expect(() => filter.not(null)._build()).to.throw('Invalid .not parameter [Null]. .not expects FilterBuilder only'); | ||
expect(() => filter.not({})._build()).to.throw('Invalid .not parameter [Object]. .not expects FilterBuilder only'); | ||
expect(() => filter.not([])._build()).to.throw('Invalid .not parameter [Array]. .not expects FilterBuilder only'); | ||
}); | ||
@@ -130,3 +126,3 @@ it('should return filter tree', function () { | ||
it('should produce correct filter tree', function () { | ||
var f = filter.eq('x', 1).or(filter.eq('y', 2)); | ||
const f = filter.eq('x', 1).or(filter.eq('y', 2)); | ||
expect(f.getFilterModel()).to.be.eql({ $or: [{ x: 1 }, { y: 2 }] }); | ||
@@ -136,3 +132,3 @@ expect(f.eq('z', 3).getFilterModel()).to.be.eql(inAnd({ $or: [{ x: 1 }, { y: 2 }] }, { z: 3 })); | ||
it('should produce valid query if used directly', function () { | ||
var f = filter.or(filter.eq('x', 1)); | ||
const f = filter.or(filter.eq('x', 1)); | ||
expect(f.filterTree).to.be.eql(inAnd({ $or: [inAnd({ x: 1 })] })); | ||
@@ -143,3 +139,3 @@ }); | ||
it('should produce correct filter tree', function () { | ||
var f = filter.eq('x', 1).and(filter.eq('y', 2)); | ||
const f = filter.eq('x', 1).and(filter.eq('y', 2)); | ||
expect(f.getFilterModel()).to.be.eql({ x: 1, y: 2 }); | ||
@@ -151,3 +147,3 @@ expect(f.eq('x', 3).getFilterModel()).to.be.eql({ | ||
it('should produce valid query if used directly', function () { | ||
var f = filter.and(filter.eq('x', 1)); | ||
const f = filter.and(filter.eq('x', 1)); | ||
expect(f.filterTree).to.be.eql(inAnd({ $and: [{ x: 1 }] })); | ||
@@ -158,3 +154,3 @@ }); | ||
it('should produce the correct filter tree', function () { | ||
var f = filter.eq('x', 1).not(filter.eq('y', 2).eq('z', 3)); | ||
const f = filter.eq('x', 1).not(filter.eq('y', 2).eq('z', 3)); | ||
expect(f.getFilterModel()).to.be.eql(inAnd({ x: 1 }, { $not: [{ y: 2, z: 3 }] })); | ||
@@ -165,21 +161,21 @@ }); | ||
it('should produce the correct filter tree for numbers', function () { | ||
var f = filter.between('field', 1, 3); | ||
const f = filter.between('field', 1, 3); | ||
expect(f.getFilterModel()).to.be.eql(inAnd({ field: { $gte: 1 } }, { field: { $lt: 3 } })); | ||
}); | ||
it('should produce the correct filter tree for dates', function () { | ||
var startDate = new Date(); | ||
var endDate = new Date(); | ||
const startDate = new Date(); | ||
const endDate = new Date(); | ||
endDate.setYear(startDate.getYear() + 1); | ||
var f = filter.between('field', startDate, endDate); | ||
const f = filter.between('field', startDate, endDate); | ||
expect(f.getFilterModel()).to.be.eql(inAnd({ field: { $gte: startDate } }, { field: { $lt: endDate } })); | ||
}); | ||
it('should produce the correct filter tree for strings', function () { | ||
var f = filter.between('field', 'start', 'end'); | ||
const f = filter.between('field', 'start', 'end'); | ||
expect(f.getFilterModel()).to.be.eql(inAnd({ field: { $gte: 'start' } }, { field: { $lt: 'end' } })); | ||
}); | ||
describe('validation', function () { | ||
var filterTreeGetters = ['_build', 'getFilterModel']; | ||
const filterTreeGetters = ['_build', 'getFilterModel']; | ||
filterTreeGetters.forEach(function (filterTreeGetter) { | ||
describe(filterTreeGetter, function () { | ||
var invalidExamples = [ | ||
const invalidExamples = [ | ||
[1, new Date(), 'Number', 'Date'], | ||
@@ -191,4 +187,3 @@ [1, '2015-02-02', 'Number', 'String'], | ||
]; | ||
invalidExamples.forEach(function (_a) { | ||
var first = _a[0], second = _a[1], firstType = _a[2], secondType = _a[3]; | ||
invalidExamples.forEach(function ([first, second, firstType, secondType,]) { | ||
it("should reject invalid query.between('x'," + | ||
@@ -201,6 +196,6 @@ first + | ||
filter.between('x', first, second)[filterTreeGetter](); | ||
}).to.throw("Invalid .between parameter values [".concat(firstType, "] and [").concat(secondType, "]. Both parameters must be of the same type.")); | ||
}).to.throw(`Invalid .between parameter values [${firstType}] and [${secondType}]. Both parameters must be of the same type.`); | ||
expect(function () { | ||
filter.between('x', second, first)[filterTreeGetter](); | ||
}).to.throw("Invalid .between parameter values [".concat(secondType, "] and [").concat(firstType, "]. Both parameters must be of the same type.")); | ||
}).to.throw(`Invalid .between parameter values [${secondType}] and [${firstType}]. Both parameters must be of the same type.`); | ||
}); | ||
@@ -214,21 +209,21 @@ }); | ||
it('should return a new filter instance with the new filterTree value set', function () { | ||
var newFilter = filter.setFilterModel(inAnd({ a: { $gte: 'b' } }, { a: 1 }, { a: { $lte: 4 } })); | ||
const newFilter = filter.setFilterModel(inAnd({ a: { $gte: 'b' } }, { a: 1 }, { a: { $lte: 4 } })); | ||
expect(newFilter).not.to.equal(filter); | ||
}); | ||
it('should set filterTree to the filterModel value when the value is a valid filterTree', function () { | ||
var newFilter = filter.setFilterModel(inAnd({ a: { $gte: 'b' } }, { a: 1 }, { a: { $lte: 4 } })); | ||
const newFilter = filter.setFilterModel(inAnd({ a: { $gte: 'b' } }, { a: 1 }, { a: { $lte: 4 } })); | ||
expect(newFilter.getFilterModel()).to.be.eql(inAnd({ a: { $gte: 'b' } }, { a: 1 }, { a: { $lte: 4 } })); | ||
}); | ||
it('should set filterTree to the filterModel value even when the value is not a valid filterTree', function () { | ||
var newFilter = filter.setFilterModel(5); | ||
const newFilter = filter.setFilterModel(5); | ||
expect(newFilter.getFilterModel()).to.be.eql(5); | ||
}); | ||
it('should set invalidArguments to an empty array when the value is a valid filterTree', function () { | ||
var invalidFilter = filter.eq('x'); | ||
var newFilter = invalidFilter.setFilterModel(inAnd({ a: { $gte: 'b' } }, { a: 1 }, { a: { $lte: 4 } })); | ||
const invalidFilter = filter.eq('x'); | ||
const newFilter = invalidFilter.setFilterModel(inAnd({ a: { $gte: 'b' } }, { a: 1 }, { a: { $lte: 4 } })); | ||
expect(newFilter.invalidArguments).to.be.eql([]); | ||
}); | ||
it('should set invalidArguments to an empty array when the value is not a valid filterTree', function () { | ||
var invalidFilter = filter.eq('x'); | ||
var newFilter = invalidFilter.setFilterModel(5); | ||
const invalidFilter = filter.eq('x'); | ||
const newFilter = invalidFilter.setFilterModel(5); | ||
expect(newFilter.invalidArguments).to.be.eql([]); | ||
@@ -235,0 +230,0 @@ }); |
import chai from 'chai'; | ||
import { optimisedQuery as optimised } from '../query-optimiser'; | ||
var expect = chai.expect; | ||
describe('query optimisations', function () { | ||
describe('$and with single element', function () { | ||
const expect = chai.expect; | ||
describe('query optimisations', () => { | ||
describe('$and with single element', () => { | ||
testCase('gets unwrapped', { $and: [{ a: 1 }] }, { a: 1 }); | ||
}); | ||
describe('$and with object pieces', function () { | ||
describe('$and with object pieces', () => { | ||
testCase('gets unwrapped as object', { $and: [{ a: 1 }, { b: 2 }] }, { a: 1, b: 2 }); | ||
testCase('remains if keys overlap', { $and: [{ a: 1 }, { b: 2 }, { a: 1 }] }, { $and: [{ a: 1 }, { b: 2 }, { a: 1 }] }); | ||
testCase("nested operators don't get merged", { $and: [{ a: 1 }, { $lte: 4 }, { b: 2 }] }, { $and: [{ a: 1, b: 2 }, { $lte: 4 }] }); | ||
it('merges empty objects', function () { | ||
var actualOutput = optimised({ $and: [{}, {}, {}] }); | ||
it('merges empty objects', () => { | ||
const actualOutput = optimised({ $and: [{}, {}, {}] }); | ||
expect(actualOutput).to.be.eql({}); | ||
}); | ||
}); | ||
describe('empty $and', function () { | ||
describe('empty $and', () => { | ||
testCase('is removed', { $and: [{ $and: [] }] }, {}); | ||
testCase('is removed when nested', { $and: [{ $and: [] }] }, {}); | ||
}); | ||
describe('nested $and', function () { | ||
describe('nested $and', () => { | ||
testCase('get flattened', { | ||
@@ -26,6 +26,6 @@ $and: [{ a: 1 }, { $and: [{ a: 1 }] }, { $and: [{ a: 1 }, { a: 1 }] }], | ||
}); | ||
describe('nested $or', function () { | ||
describe('nested $or', () => { | ||
testCase('get flattened', { $or: [{ a: 1 }, { $or: [{ a: 1 }] }, { $or: [{ a: 1 }, { a: 1 }] }] }, { $or: [{ a: 1 }, { a: 1 }, { a: 1 }, { a: 1 }] }); | ||
}); | ||
describe('type compatibility', function () { | ||
describe('type compatibility', () => { | ||
testCase('maintains date objects', { x: [new Date('2020-01-01T00:00:00Z')] }, { x: [new Date('2020-01-01T00:00:00Z')] }); | ||
@@ -35,4 +35,4 @@ }); | ||
function testCase(description, input, expectedOutput) { | ||
it(description, function () { | ||
var actualOutput = optimised(input); | ||
it(description, () => { | ||
const actualOutput = optimised(input); | ||
expect(actualOutput).to.be.eql(expectedOutput); | ||
@@ -39,0 +39,0 @@ }); |
@@ -6,3 +6,3 @@ import { isDate } from './type-utils'; | ||
} | ||
var temp = null; | ||
let temp = null; | ||
if (isDate(obj)) { | ||
@@ -13,3 +13,3 @@ temp = new Date(obj.getTime()); | ||
temp = obj.constructor(); | ||
for (var key in obj) { | ||
for (const key in obj) { | ||
temp[key] = clone(obj[key]); | ||
@@ -16,0 +16,0 @@ } |
@@ -1,23 +0,11 @@ | ||
import { __extends } from "tslib"; | ||
import filterMixin from './filter-mixin'; | ||
var FilterBuilder = (function (_super) { | ||
__extends(FilterBuilder, _super); | ||
function FilterBuilder() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
export class FilterBuilder extends filterMixin() { | ||
get constructorName() { | ||
return 'FilterBuilder'; | ||
} | ||
Object.defineProperty(FilterBuilder.prototype, "constructorName", { | ||
get: function () { | ||
return 'FilterBuilder'; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
FilterBuilder.prototype._build = function () { | ||
_build() { | ||
return this.getFilterModel(); | ||
}; | ||
return FilterBuilder; | ||
}(filterMixin())); | ||
export { FilterBuilder }; | ||
export function filterBuilder(params) { | ||
if (params === void 0) { params = {}; } | ||
} | ||
} | ||
export function filterBuilder(params = {}) { | ||
return new FilterBuilder(params); | ||
@@ -24,0 +12,0 @@ } |
@@ -1,2 +0,1 @@ | ||
import { __assign, __extends, __spreadArray } from "tslib"; | ||
import { isArray, isFunction } from './type-utils'; | ||
@@ -6,261 +5,207 @@ import clone from './clone'; | ||
import { optimisedQuery } from './query-optimiser'; | ||
var filterMixin = function (Base) { | ||
if (Base === void 0) { Base = (function () { | ||
function class_1() { | ||
const filterMixin = (Base = class { | ||
}) => class extends Base { | ||
constructor(obj = {}) { | ||
super(obj); | ||
this.filterTree = obj.filterTree || { $and: [] }; | ||
this.invalidArguments = obj.invalidArguments || []; | ||
this.encoder = obj.encoder || {}; | ||
} | ||
eq(...args) { | ||
return this._binaryAnd('$eq', '.eq', args); | ||
} | ||
ne(...args) { | ||
return this._binaryAnd('$ne', '.ne', args); | ||
} | ||
ge(...args) { | ||
return this._AndLogicalEquivalence('$gte', '.ge', args); | ||
} | ||
gt(...args) { | ||
return this._AndLogicalEquivalence('$gt', '.gt', args); | ||
} | ||
le(...args) { | ||
return this._AndLogicalEquivalence('$lte', '.le', args); | ||
} | ||
lt(...args) { | ||
return this._AndLogicalEquivalence('$lt', '.lt', args); | ||
} | ||
isNotEmpty(field) { | ||
const [newInvalidArguments, valid] = this._filterValidator('.isNotEmpty') | ||
.arityIsOne(arguments) | ||
.validFieldName(field) | ||
.validateAndAggregate(); | ||
if (valid) { | ||
return this.ne(field, null); | ||
} | ||
return class_1; | ||
}()); } | ||
return (function (_super) { | ||
__extends(class_2, _super); | ||
function class_2(obj) { | ||
if (obj === void 0) { obj = {}; } | ||
var _this = _super.call(this, obj) || this; | ||
_this.filterTree = obj.filterTree || { $and: [] }; | ||
_this.invalidArguments = obj.invalidArguments || []; | ||
_this.encoder = obj.encoder || {}; | ||
return _this; | ||
return this._copy(this.filterTree, newInvalidArguments); | ||
} | ||
isEmpty(field) { | ||
const [newInvalidArguments, valid] = this._filterValidator('.isEmpty') | ||
.arityIsOne(arguments) | ||
.validFieldName(field) | ||
.validateAndAggregate(); | ||
if (valid) { | ||
return this.eq(field, null); | ||
} | ||
class_2.prototype.eq = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return this._binaryAnd('$eq', '.eq', args); | ||
}; | ||
class_2.prototype.ne = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return this._binaryAnd('$ne', '.ne', args); | ||
}; | ||
class_2.prototype.ge = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return this._AndLogicalEquivalence('$gte', '.ge', args); | ||
}; | ||
class_2.prototype.gt = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return this._AndLogicalEquivalence('$gt', '.gt', args); | ||
}; | ||
class_2.prototype.le = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return this._AndLogicalEquivalence('$lte', '.le', args); | ||
}; | ||
class_2.prototype.lt = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return this._AndLogicalEquivalence('$lt', '.lt', args); | ||
}; | ||
class_2.prototype.isNotEmpty = function (field) { | ||
var _a = this._filterValidator('.isNotEmpty') | ||
.arityIsOne(arguments) | ||
.validFieldName(field) | ||
.validateAndAggregate(), newInvalidArguments = _a[0], valid = _a[1]; | ||
if (valid) { | ||
return this.ne(field, null); | ||
} | ||
return this._copy(this.filterTree, newInvalidArguments); | ||
} | ||
startsWith(...args) { | ||
return this._AndStringOperand('$startsWith', '.startsWith', args); | ||
} | ||
endsWith(...args) { | ||
return this._AndStringOperand('$endsWith', '.endsWith', args); | ||
} | ||
contains(...args) { | ||
return this._AndStringOperand('$contains', '.contains', args); | ||
} | ||
hasSome(...args) { | ||
return this._AndSetOperand('$hasSome', '.hasSome', args); | ||
} | ||
hasAll(...args) { | ||
return this._AndSetOperand('$hasAll', '.hasAll', args); | ||
} | ||
or(orQuery) { | ||
const [newInvalidArguments, valid] = this._filterValidator('.or') | ||
.arityIsOne(arguments) | ||
.isInstanceOfSameClass(orQuery) | ||
.validateAndAggregate(); | ||
if (valid) { | ||
const prefix = isEmptyAnd(this.filterTree) ? [] : [this.filterTree]; | ||
return this._copy(inAnd({ $or: [...prefix, orQuery.filterTree] }), newInvalidArguments.concat(orQuery.invalidArguments)); | ||
} | ||
else { | ||
return this._copy(this.filterTree, newInvalidArguments); | ||
}; | ||
class_2.prototype.isEmpty = function (field) { | ||
var _a = this._filterValidator('.isEmpty') | ||
.arityIsOne(arguments) | ||
.validFieldName(field) | ||
.validateAndAggregate(), newInvalidArguments = _a[0], valid = _a[1]; | ||
if (valid) { | ||
return this.eq(field, null); | ||
} | ||
} | ||
} | ||
and(andQuery) { | ||
const [newInvalidArguments, valid] = this._filterValidator('.and') | ||
.arityIsOne(arguments) | ||
.isInstanceOfSameClass(andQuery) | ||
.validateAndAggregate(); | ||
if (valid) { | ||
const prefix = isEmptyAnd(this.filterTree) ? [] : [this.filterTree]; | ||
return this._copy(inAnd(...prefix, andQuery.filterTree), newInvalidArguments.concat(andQuery.invalidArguments)); | ||
} | ||
else { | ||
return this._copy(this.filterTree, newInvalidArguments); | ||
}; | ||
class_2.prototype.startsWith = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return this._AndStringOperand('$startsWith', '.startsWith', args); | ||
}; | ||
class_2.prototype.endsWith = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return this._AndStringOperand('$endsWith', '.endsWith', args); | ||
}; | ||
class_2.prototype.contains = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return this._AndStringOperand('$contains', '.contains', args); | ||
}; | ||
class_2.prototype.hasSome = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return this._AndSetOperand('$hasSome', '.hasSome', args); | ||
}; | ||
class_2.prototype.hasAll = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return this._AndSetOperand('$hasAll', '.hasAll', args); | ||
}; | ||
class_2.prototype.or = function (orQuery) { | ||
var _a = this._filterValidator('.or') | ||
.arityIsOne(arguments) | ||
.isInstanceOfSameClass(orQuery) | ||
.validateAndAggregate(), newInvalidArguments = _a[0], valid = _a[1]; | ||
if (valid) { | ||
var prefix = isEmptyAnd(this.filterTree) ? [] : [this.filterTree]; | ||
return this._copy(inAnd({ $or: __spreadArray(__spreadArray([], prefix, true), [orQuery.filterTree], false) }), newInvalidArguments.concat(orQuery.invalidArguments)); | ||
} | ||
else { | ||
return this._copy(this.filterTree, newInvalidArguments); | ||
} | ||
}; | ||
class_2.prototype.and = function (andQuery) { | ||
var _a = this._filterValidator('.and') | ||
.arityIsOne(arguments) | ||
.isInstanceOfSameClass(andQuery) | ||
.validateAndAggregate(), newInvalidArguments = _a[0], valid = _a[1]; | ||
if (valid) { | ||
var prefix = isEmptyAnd(this.filterTree) ? [] : [this.filterTree]; | ||
return this._copy(inAnd.apply(void 0, __spreadArray(__spreadArray([], prefix, false), [andQuery.filterTree], false)), newInvalidArguments.concat(andQuery.invalidArguments)); | ||
} | ||
else { | ||
return this._copy(this.filterTree, newInvalidArguments); | ||
} | ||
}; | ||
class_2.prototype.not = function (notQuery) { | ||
var _a = this._filterValidator('.not') | ||
.arityIsOne(arguments) | ||
.isInstanceOfSameClass(notQuery) | ||
.validateAndAggregate(), newInvalidArguments = _a[0], valid = _a[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); | ||
} | ||
}; | ||
class_2.prototype.between = function (field, rangeStart, rangeEnd) { | ||
var _a = this._filterValidator('.between') | ||
.arityIsThree(arguments) | ||
.sameType(rangeStart, rangeEnd) | ||
.typeIsStringNumberOrDate(rangeStart) | ||
.typeIsStringNumberOrDate(rangeEnd) | ||
.validateAndAggregate(), newInvalidArguments = _a[0], valid = _a[1]; | ||
if (valid) { | ||
return this.ge(field, rangeStart).lt(field, rangeEnd); | ||
} | ||
} | ||
} | ||
not(notQuery) { | ||
const [newInvalidArguments, valid] = this._filterValidator('.not') | ||
.arityIsOne(arguments) | ||
.isInstanceOfSameClass(notQuery) | ||
.validateAndAggregate(); | ||
if (valid) { | ||
const newFilterTree = clone(this.filterTree); | ||
const notClause = { $not: [notQuery.filterTree] }; | ||
const resultingFilter = inAndOptimized(newFilterTree, notClause); | ||
return this._copy(resultingFilter, newInvalidArguments.concat(notQuery.invalidArguments)); | ||
} | ||
else { | ||
return this._copy(this.filterTree, newInvalidArguments); | ||
}; | ||
class_2.prototype.getFilterModel = function () { | ||
if (this.invalidArguments.length > 0) { | ||
throw new Error(this.invalidArguments.join(' ')); | ||
} | ||
return optimisedQuery(this.filterTree); | ||
}; | ||
class_2.prototype.setFilterModel = function (filterModel) { | ||
return this._copy(filterModel, []); | ||
}; | ||
class_2.prototype._binaryAnd = function (filterOperatorSymbol, operatorName, args) { | ||
var _a = Array.prototype.slice.call(args), field = _a[0], operand = _a[1]; | ||
var newInvalidArguments = this._filterValidator(operatorName) | ||
.arityIsTwo(args) | ||
.validFieldName(field) | ||
.validateAndAggregate()[0]; | ||
var newFilterTree = this._makeNewFilter(field, filterOperatorSymbol, operand); | ||
return this._copy(newFilterTree, newInvalidArguments); | ||
}; | ||
class_2.prototype._AndLogicalEquivalence = function (filterOperatorSymbol, operatorName, args) { | ||
var _a = Array.prototype.slice.call(args), field = _a[0], operand = _a[1]; | ||
var newInvalidArguments = this._filterValidator(operatorName) | ||
.arityIsTwo(args) | ||
.validFieldName(field) | ||
.typeIsStringNumberOrDate(operand) | ||
.validateAndAggregate()[0]; | ||
var newFilterTree = this._makeNewFilter(field, filterOperatorSymbol, operand); | ||
return this._copy(newFilterTree, newInvalidArguments); | ||
}; | ||
class_2.prototype._AndStringOperand = function (filterOperatorName, operatorName, args) { | ||
var _a = Array.prototype.slice.call(args), field = _a[0], operand = _a[1]; | ||
var newInvalidArguments = this._filterValidator(operatorName) | ||
.arityIsTwo(args) | ||
.validFieldName(field) | ||
.typeIsString(operand) | ||
.validateAndAggregate()[0]; | ||
var newFilterTree = this._makeNewFilter(field, filterOperatorName, operand); | ||
return this._copy(newFilterTree, newInvalidArguments); | ||
}; | ||
class_2.prototype._AndSetOperand = function (filterOperatorName, operatorName, args) { | ||
var _a = Array.prototype.slice.call(args), field = _a[0], rawOperands = _a.slice(1); | ||
var operands = isArray(rawOperands[0]) ? rawOperands[0] : rawOperands; | ||
var newInvalidArguments = this._filterValidator(operatorName) | ||
.arityIsAtLeastTwo(args) | ||
.validFieldName(field) | ||
.typeIsStringNumberOrDateForAll(operands) | ||
.validateAndAggregate()[0]; | ||
var newFilterTree = this._makeNewFilter(field, filterOperatorName, operands); | ||
return this._copy(newFilterTree, newInvalidArguments); | ||
}; | ||
class_2.prototype._makeNewFilter = function (field, filterOperatorName, operand) { | ||
var newFilterTree = clone(this.filterTree); | ||
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; | ||
} | ||
}; | ||
class_2.prototype._buildFilter = function (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; | ||
} | ||
}; | ||
class_2.prototype._encode = function (operand) { | ||
if (isFunction(this.encoder)) { | ||
return this.encoder(operand); | ||
} | ||
else { | ||
return operand; | ||
} | ||
}; | ||
class_2.prototype._copy = function (filterTree, invalidArguments) { | ||
return new this.constructor(__assign(__assign({}, this), { filterTree: filterTree, invalidArguments: invalidArguments })); | ||
}; | ||
class_2.prototype._filterValidator = function (filterOperatorName) { | ||
return new FilterValidator(filterOperatorName, this.invalidArguments, this.constructor); | ||
}; | ||
return class_2; | ||
}(Base)); | ||
} | ||
} | ||
between(field, rangeStart, rangeEnd) { | ||
const [newInvalidArguments, valid] = this._filterValidator('.between') | ||
.arityIsThree(arguments) | ||
.sameType(rangeStart, rangeEnd) | ||
.typeIsStringNumberOrDate(rangeStart) | ||
.typeIsStringNumberOrDate(rangeEnd) | ||
.validateAndAggregate(); | ||
if (valid) { | ||
return this.ge(field, rangeStart).lt(field, rangeEnd); | ||
} | ||
return this._copy(this.filterTree, newInvalidArguments); | ||
} | ||
getFilterModel() { | ||
if (this.invalidArguments.length > 0) { | ||
throw new Error(this.invalidArguments.join(' ')); | ||
} | ||
return optimisedQuery(this.filterTree); | ||
} | ||
setFilterModel(filterModel) { | ||
return this._copy(filterModel, []); | ||
} | ||
_binaryAnd(filterOperatorSymbol, operatorName, args) { | ||
const [field, operand] = Array.prototype.slice.call(args); | ||
const [newInvalidArguments] = this._filterValidator(operatorName) | ||
.arityIsTwo(args) | ||
.validFieldName(field) | ||
.validateAndAggregate(); | ||
const newFilterTree = this._makeNewFilter(field, filterOperatorSymbol, operand); | ||
return this._copy(newFilterTree, newInvalidArguments); | ||
} | ||
_AndLogicalEquivalence(filterOperatorSymbol, operatorName, args) { | ||
const [field, operand] = Array.prototype.slice.call(args); | ||
const [newInvalidArguments] = this._filterValidator(operatorName) | ||
.arityIsTwo(args) | ||
.validFieldName(field) | ||
.typeIsStringNumberOrDate(operand) | ||
.validateAndAggregate(); | ||
const newFilterTree = this._makeNewFilter(field, filterOperatorSymbol, operand); | ||
return this._copy(newFilterTree, newInvalidArguments); | ||
} | ||
_AndStringOperand(filterOperatorName, operatorName, args) { | ||
const [field, operand] = Array.prototype.slice.call(args); | ||
const [newInvalidArguments] = this._filterValidator(operatorName) | ||
.arityIsTwo(args) | ||
.validFieldName(field) | ||
.typeIsString(operand) | ||
.validateAndAggregate(); | ||
const newFilterTree = this._makeNewFilter(field, filterOperatorName, operand); | ||
return this._copy(newFilterTree, newInvalidArguments); | ||
} | ||
_AndSetOperand(filterOperatorName, operatorName, args) { | ||
const [field, ...rawOperands] = Array.prototype.slice.call(args); | ||
const operands = isArray(rawOperands[0]) ? rawOperands[0] : rawOperands; | ||
const [newInvalidArguments] = this._filterValidator(operatorName) | ||
.arityIsAtLeastTwo(args) | ||
.validFieldName(field) | ||
.typeIsStringNumberOrDateForAll(operands) | ||
.validateAndAggregate(); | ||
const newFilterTree = this._makeNewFilter(field, filterOperatorName, operands); | ||
return this._copy(newFilterTree, newInvalidArguments); | ||
} | ||
_makeNewFilter(field, filterOperatorName, operand) { | ||
const newFilterTree = clone(this.filterTree); | ||
const serializableOperand = operand === undefined ? null : operand; | ||
const newFilter = this._buildFilter(field, filterOperatorName, serializableOperand); | ||
if (isArray(newFilterTree.$and)) { | ||
newFilterTree.$and.push(newFilter); | ||
return newFilterTree; | ||
} | ||
else { | ||
const result = isEmptyObject(newFilterTree) | ||
? inAnd(newFilter) | ||
: inAnd(newFilterTree, newFilter); | ||
return result; | ||
} | ||
} | ||
_buildFilter(field, filterOperatorName, operand) { | ||
if (filterOperatorName !== '$eq') { | ||
const newFilter = {}; | ||
newFilter[field] = {}; | ||
newFilter[field][filterOperatorName] = this._encode(operand); | ||
return newFilter; | ||
} | ||
else { | ||
const newFilter = {}; | ||
newFilter[field] = this._encode(operand); | ||
return newFilter; | ||
} | ||
} | ||
_encode(operand) { | ||
if (isFunction(this.encoder)) { | ||
return this.encoder(operand); | ||
} | ||
else { | ||
return operand; | ||
} | ||
} | ||
_copy(filterTree, invalidArguments) { | ||
return new this.constructor(Object.assign(Object.assign({}, this), { filterTree, invalidArguments })); | ||
} | ||
_filterValidator(filterOperatorName) { | ||
return new FilterValidator(filterOperatorName, this.invalidArguments, this.constructor); | ||
} | ||
}; | ||
@@ -273,7 +218,3 @@ function isConjunctiveFormFilter(filterTree) { | ||
} | ||
function inAnd() { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
function inAnd(...args) { | ||
return { | ||
@@ -283,13 +224,7 @@ $and: args, | ||
} | ||
function inAndOptimized() { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
function inAndOptimized(...args) { | ||
return { | ||
$and: args.reduce(function (aggr, val) { | ||
return isConjunctiveFormFilter(val) | ||
? aggr.concat(val.$and) | ||
: aggr.concat([val]); | ||
}, []), | ||
$and: args.reduce((aggr, val) => isConjunctiveFormFilter(val) | ||
? aggr.concat(val.$and) | ||
: aggr.concat([val]), []), | ||
}; | ||
@@ -296,0 +231,0 @@ } |
import { typeForDisplay, isDate, isString, isNumber } from './type-utils'; | ||
import clone from './clone'; | ||
var FilterValidator = (function () { | ||
function FilterValidator(operatorName, previousInvalidArguments, ctor) { | ||
export class FilterValidator { | ||
constructor(operatorName, previousInvalidArguments, ctor) { | ||
this._validations = []; | ||
@@ -10,78 +10,44 @@ this.operatorName = operatorName; | ||
} | ||
FilterValidator.prototype.typeIsString = function (value) { | ||
var _this = this; | ||
return this.addValidation(function () { return isString(value); }, function () { | ||
return "Invalid ".concat(_this.operatorName, " parameter value [").concat(typeForDisplay(value), "]. ").concat(_this.operatorName, " parameter must be a String."); | ||
}); | ||
}; | ||
FilterValidator.prototype.typeIsStringNumberOrDate = function (value) { | ||
var _this = this; | ||
return this.addValidation(function () { return isDateStringOrNumber(value); }, function () { | ||
return "Invalid ".concat(_this.operatorName, " parameter value [").concat(typeForDisplay(value), "]. Valid ").concat(_this.operatorName, " parameter types are String, Number or Date."); | ||
}); | ||
}; | ||
FilterValidator.prototype.sameType = function (first, second) { | ||
var _this = this; | ||
return this.addValidation(function () { return typeForDisplay(first) === typeForDisplay(second); }, function () { | ||
return "Invalid ".concat(_this.operatorName, " parameter values [").concat(typeForDisplay(first), "] and [").concat(typeForDisplay(second), "]. Both parameters must be of the same type."); | ||
}); | ||
}; | ||
FilterValidator.prototype.typeIsStringNumberOrDateForAll = function (values) { | ||
var _this = this; | ||
return this.addValidation(function () { return values.every(isDateStringOrNumber); }, function () { | ||
return "Invalid ".concat(_this.operatorName, " usage. ").concat(_this.operatorName, " supports only Number, String or Date items."); | ||
}); | ||
}; | ||
FilterValidator.prototype.validFieldName = function (field) { | ||
var _this = this; | ||
return this.addValidation(function () { return isString(field); }, function () { | ||
return "Invalid ".concat(_this.operatorName, " field value [").concat(typeForDisplay(field), "]. ").concat(_this.operatorName, " field must be a String."); | ||
}); | ||
}; | ||
FilterValidator.prototype.isInstanceOfSameClass = function (obj) { | ||
var _this = this; | ||
return this.addValidation(function () { return obj instanceof _this.ctor; }, function () { | ||
return "Invalid ".concat(_this.operatorName, " parameter [").concat(typeForDisplay(obj), "]. ").concat(_this.operatorName, " expects FilterBuilder only."); | ||
}); | ||
}; | ||
FilterValidator.prototype.arityIsOne = function (args) { | ||
var _this = this; | ||
return this.addValidation(function () { return args.length === 1; }, function () { | ||
return "Invalid ".concat(_this.operatorName, " usage. ").concat(_this.operatorName, " requires one parameter."); | ||
}); | ||
}; | ||
FilterValidator.prototype.arityIsTwo = function (args) { | ||
var _this = this; | ||
return this.addValidation(function () { return args.length === 2; }, function () { | ||
return "Invalid ".concat(_this.operatorName, " usage. ").concat(_this.operatorName, " requires two parameters."); | ||
}); | ||
}; | ||
FilterValidator.prototype.arityIsThree = function (args) { | ||
var _this = this; | ||
return this.addValidation(function () { return args.length === 3; }, function () { | ||
return "Invalid ".concat(_this.operatorName, " usage. ").concat(_this.operatorName, " requires three parameters."); | ||
}); | ||
}; | ||
FilterValidator.prototype.arityIsAtLeastTwo = function (args) { | ||
var _this = this; | ||
return this.addValidation(function () { return args.length >= 2; }, function () { | ||
return "Invalid ".concat(_this.operatorName, " usage. ").concat(_this.operatorName, " requires at least two parameters."); | ||
}); | ||
}; | ||
FilterValidator.prototype.addValidation = function (predicateFn, messageFn) { | ||
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: predicateFn, | ||
messageFn: messageFn, | ||
predicateFn, | ||
messageFn, | ||
}); | ||
return this; | ||
}; | ||
FilterValidator.prototype.validateAndAggregate = function () { | ||
var _this = this; | ||
var valid = this._validations.every(function (_a) { | ||
var predicateFn = _a.predicateFn, messageFn = _a.messageFn; | ||
return _this._appendIfInvalid(predicateFn(), messageFn()); | ||
}); | ||
} | ||
validateAndAggregate() { | ||
const valid = this._validations.every(({ predicateFn, messageFn }) => this._appendIfInvalid(predicateFn(), messageFn())); | ||
return [this._invalidArguments, valid]; | ||
}; | ||
FilterValidator.prototype._appendIfInvalid = function (valid, message) { | ||
} | ||
_appendIfInvalid(valid, message) { | ||
if (!valid) { | ||
@@ -92,6 +58,4 @@ this._invalidArguments.push(message); | ||
return true; | ||
}; | ||
return FilterValidator; | ||
}()); | ||
export { FilterValidator }; | ||
} | ||
} | ||
function isDateStringOrNumber(value) { | ||
@@ -98,0 +62,0 @@ return isString(value) || isNumber(value) || isDate(value); |
@@ -1,3 +0,2 @@ | ||
import { __assign, __spreadArray } from "tslib"; | ||
var optimisations = [ | ||
const optimisations = [ | ||
optimisedUnaryAnd, | ||
@@ -10,3 +9,3 @@ optimisedEmptyAnd, | ||
export function optimisedQuery(query) { | ||
var newQuery = fullyOptimised(query)[0]; | ||
const [newQuery] = fullyOptimised(query); | ||
return newQuery; | ||
@@ -26,54 +25,39 @@ } | ||
function fullyOptimisedArray(query) { | ||
var optimisedElements = query.map(fullyOptimised); | ||
var somethingChanged = 0 < optimisedElements.filter(function (_a) { | ||
var elementChanged = _a[1]; | ||
return elementChanged; | ||
}).length; | ||
var newElements = optimisedElements.map(function (_a) { | ||
var element = _a[0]; | ||
return element; | ||
}); | ||
const optimisedElements = query.map(fullyOptimised); | ||
const somethingChanged = 0 < optimisedElements.filter(([, elementChanged]) => elementChanged).length; | ||
const newElements = optimisedElements.map(([element]) => element); | ||
return [newElements, somethingChanged]; | ||
} | ||
function fullyOptimisedObject(query) { | ||
var _a = fullEntriesOptimisation(query), queryAfterOptimisingEntries = _a[0], changedStage1 = _a[1]; | ||
var _b = fullObjectOptimisation(queryAfterOptimisingEntries), queryAfterFullOptimisation = _b[0], changedStage2 = _b[1]; | ||
var changed = changedStage1 || changedStage2; | ||
const [queryAfterOptimisingEntries, changedStage1] = fullEntriesOptimisation(query); | ||
const [queryAfterFullOptimisation, changedStage2] = fullObjectOptimisation(queryAfterOptimisingEntries); | ||
const changed = changedStage1 || changedStage2; | ||
return [queryAfterFullOptimisation, changed]; | ||
function fullObjectOptimisation(query) { | ||
var updatedQuery = applyFirstOptimisation(query); | ||
const updatedQuery = applyFirstOptimisation(query); | ||
if (!updatedQuery) { | ||
return [query, false]; | ||
} | ||
var finalQuery = fullyOptimised(updatedQuery)[0]; | ||
const [finalQuery] = fullyOptimised(updatedQuery); | ||
return [finalQuery, true]; | ||
} | ||
function fullEntriesOptimisation(query) { | ||
var changedEntries = Object.entries(query) | ||
const changedEntries = Object.entries(query) | ||
.map(entryOptimisation) | ||
.filter(function (_a) { | ||
var changed = _a[2]; | ||
return changed; | ||
}); | ||
var newQuery = __assign(__assign({}, query), entriesAsObject(changedEntries)); | ||
var changed = !!changedEntries.length; | ||
.filter(([, , changed]) => changed); | ||
const newQuery = Object.assign(Object.assign({}, query), entriesAsObject(changedEntries)); | ||
const changed = !!changedEntries.length; | ||
return [newQuery, changed]; | ||
} | ||
function entryOptimisation(_a) { | ||
var key = _a[0], value = _a[1]; | ||
var _b = fullyOptimised(value), newValue = _b[0], changed = _b[1]; | ||
function entryOptimisation([key, value]) { | ||
const [newValue, changed] = fullyOptimised(value); | ||
return [key, newValue, changed]; | ||
} | ||
function entriesAsObject(entries) { | ||
return entries.reduce(function (acc, _a) { | ||
var _b; | ||
var key = _a[0], value = _a[1]; | ||
return (__assign(__assign({}, acc), (_b = {}, _b[key] = value, _b))); | ||
}, {}); | ||
return entries.reduce((acc, [key, value]) => (Object.assign(Object.assign({}, acc), { [key]: value })), {}); | ||
} | ||
} | ||
function applyFirstOptimisation(node) { | ||
for (var _i = 0, optimisations_1 = optimisations; _i < optimisations_1.length; _i++) { | ||
var optimisation = optimisations_1[_i]; | ||
var newNode = optimisation(node); | ||
for (const optimisation of optimisations) { | ||
const newNode = optimisation(node); | ||
if (newNode) { | ||
@@ -85,3 +69,3 @@ return newNode; | ||
function optimisedUnaryAnd(node) { | ||
var args = node.$and; | ||
const args = node.$and; | ||
if (Array.isArray(args) && args.length === 1) { | ||
@@ -92,3 +76,3 @@ return args[0]; | ||
function optimisedEmptyAnd(node) { | ||
var args = node.$and; | ||
const args = node.$and; | ||
if (Array.isArray(args) && args.length === 0) { | ||
@@ -100,14 +84,14 @@ return {}; | ||
function optimisedAndsAsObjects(node) { | ||
var args = node.$and; | ||
const args = node.$and; | ||
if (!args) { | ||
return; | ||
} | ||
var basicObjects = []; | ||
var operatorObjects = []; | ||
args.forEach(function (arg) { | ||
let basicObjects = []; | ||
let operatorObjects = []; | ||
args.forEach((arg) => { | ||
if (isOperator(arg)) { | ||
operatorObjects = __spreadArray(__spreadArray([], operatorObjects, true), [arg], false); | ||
operatorObjects = [...operatorObjects, arg]; | ||
} | ||
else { | ||
basicObjects = __spreadArray(__spreadArray([], basicObjects, true), [arg], false); | ||
basicObjects = [...basicObjects, arg]; | ||
} | ||
@@ -118,18 +102,18 @@ }); | ||
} | ||
var combinedBasicObjects = Object.assign.apply(Object, __spreadArray([{}], basicObjects, false)); | ||
return { $and: __spreadArray([combinedBasicObjects], operatorObjects, true) }; | ||
const combinedBasicObjects = Object.assign({}, ...basicObjects); | ||
return { $and: [combinedBasicObjects, ...operatorObjects] }; | ||
function isOperator(node) { | ||
var keys = Object.keys(node); | ||
return keys.every(function (name) { return name.startsWith('$'); }) && keys.length > 0; | ||
const keys = Object.keys(node); | ||
return keys.every((name) => name.startsWith('$')) && keys.length > 0; | ||
} | ||
function haveOverlappingFields(objects) { | ||
var nonUniqueKeys = objects | ||
.map(function (it) { return Object.keys(it); }) | ||
.reduce(function (a, b) { return __spreadArray(__spreadArray([], a, true), b, true); }, []); | ||
var uniqueKeys = unique(nonUniqueKeys); | ||
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) { | ||
var dict = {}; | ||
values.forEach(function (v) { return (dict[v] = true); }); | ||
const dict = {}; | ||
values.forEach((v) => (dict[v] = true)); | ||
return Object.keys(dict); | ||
@@ -139,16 +123,16 @@ } | ||
function optimisedNestedAnds(node) { | ||
var args = node.$and; | ||
const args = node.$and; | ||
if (!args) { | ||
return; | ||
} | ||
var hasNestedAnds = !!args.find(function (it) { return it.$and; }); | ||
const hasNestedAnds = !!args.find((it) => it.$and); | ||
if (!hasNestedAnds) { | ||
return; | ||
} | ||
var newArgs = args.reduce(function (result, current) { | ||
var and = current.$and; | ||
const newArgs = args.reduce((result, current) => { | ||
const and = current.$and; | ||
if (!and) { | ||
return __spreadArray(__spreadArray([], result, true), [current], false); | ||
return [...result, current]; | ||
} | ||
return __spreadArray(__spreadArray([], result, true), and, true); | ||
return [...result, ...and]; | ||
}, []); | ||
@@ -158,16 +142,16 @@ return { $and: newArgs }; | ||
function optimisedNestedOrs(node) { | ||
var args = node.$or; | ||
const args = node.$or; | ||
if (!args) { | ||
return; | ||
} | ||
var hasNestedOrs = !!args.find(function (it) { return it.$or; }); | ||
const hasNestedOrs = !!args.find((it) => it.$or); | ||
if (!hasNestedOrs) { | ||
return; | ||
} | ||
var newArgs = args.reduce(function (result, current) { | ||
var or = current.$or; | ||
const newArgs = args.reduce((result, current) => { | ||
const or = current.$or; | ||
if (!or) { | ||
return __spreadArray(__spreadArray([], result, true), [current], false); | ||
return [...result, current]; | ||
} | ||
return __spreadArray(__spreadArray([], result, true), or, true); | ||
return [...result, ...or]; | ||
}, []); | ||
@@ -174,0 +158,0 @@ return { $or: newArgs }; |
@@ -36,6 +36,6 @@ import getKind from 'kind-of'; | ||
} | ||
var first = str.slice(0, 1).toUpperCase(); | ||
var rest = str.slice(1, str.length); | ||
const first = str.slice(0, 1).toUpperCase(); | ||
const rest = str.slice(1, str.length); | ||
return first + rest; | ||
} | ||
//# sourceMappingURL=type-utils.js.map |
@@ -10,153 +10,11 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
root["platformized-filter-builder"] = factory(); | ||
})((typeof self !== 'undefined' ? self : this), function() { | ||
return /******/ (function() { // webpackBootstrap | ||
})((typeof self !== 'undefined' ? self : this), () => { | ||
return /******/ (() => { // webpackBootstrap | ||
/******/ var __webpack_modules__ = ({ | ||
/***/ 50: | ||
/*!****************************************************************************************************************!*\ | ||
!*** ../../node_modules/@wix/yoshi-webpack-utils/node_modules/@babel/runtime/helpers/assertThisInitialized.js ***! | ||
\****************************************************************************************************************/ | ||
/***/ (function(module) { | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
} | ||
module.exports = _assertThisInitialized; | ||
module.exports["default"] = module.exports, module.exports.__esModule = true; | ||
/***/ }), | ||
/***/ 523: | ||
/*!******************************************************************************************************!*\ | ||
!*** ../../node_modules/@wix/yoshi-webpack-utils/node_modules/@babel/runtime/helpers/createClass.js ***! | ||
\******************************************************************************************************/ | ||
/***/ (function(module) { | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
module.exports = _createClass; | ||
module.exports["default"] = module.exports, module.exports.__esModule = true; | ||
/***/ }), | ||
/***/ 695: | ||
/*!*********************************************************************************************************!*\ | ||
!*** ../../node_modules/@wix/yoshi-webpack-utils/node_modules/@babel/runtime/helpers/defineProperty.js ***! | ||
\*********************************************************************************************************/ | ||
/***/ (function(module) { | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
module.exports = _defineProperty; | ||
module.exports["default"] = module.exports, module.exports.__esModule = true; | ||
/***/ }), | ||
/***/ 710: | ||
/*!**************************************************************************************************!*\ | ||
!*** ../../node_modules/@wix/yoshi-webpack-utils/node_modules/@babel/runtime/helpers/extends.js ***! | ||
\**************************************************************************************************/ | ||
/***/ (function(module) { | ||
function _extends() { | ||
module.exports = _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
module.exports["default"] = module.exports, module.exports.__esModule = true; | ||
return _extends.apply(this, arguments); | ||
} | ||
module.exports = _extends; | ||
module.exports["default"] = module.exports, module.exports.__esModule = true; | ||
/***/ }), | ||
/***/ 333: | ||
/*!********************************************************************************************************!*\ | ||
!*** ../../node_modules/@wix/yoshi-webpack-utils/node_modules/@babel/runtime/helpers/inheritsLoose.js ***! | ||
\********************************************************************************************************/ | ||
/***/ (function(module, __unused_webpack_exports, __webpack_require__) { | ||
var setPrototypeOf = __webpack_require__(/*! ./setPrototypeOf.js */ 814); | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
setPrototypeOf(subClass, superClass); | ||
} | ||
module.exports = _inheritsLoose; | ||
module.exports["default"] = module.exports, module.exports.__esModule = true; | ||
/***/ }), | ||
/***/ 814: | ||
/*!*********************************************************************************************************!*\ | ||
!*** ../../node_modules/@wix/yoshi-webpack-utils/node_modules/@babel/runtime/helpers/setPrototypeOf.js ***! | ||
\*********************************************************************************************************/ | ||
/***/ (function(module) { | ||
function _setPrototypeOf(o, p) { | ||
module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
module.exports["default"] = module.exports, module.exports.__esModule = true; | ||
return _setPrototypeOf(o, p); | ||
} | ||
module.exports = _setPrototypeOf; | ||
module.exports["default"] = module.exports, module.exports.__esModule = true; | ||
/***/ }), | ||
/***/ 347: | ||
/***/ 24: | ||
/*!**********************!*\ | ||
!*** ./validator.ts ***! | ||
\**********************/ | ||
/***/ (function() { | ||
/***/ (() => { | ||
@@ -167,7 +25,7 @@ | ||
/***/ 366: | ||
/***/ 182: | ||
/*!*******************************************!*\ | ||
!*** ../../node_modules/kind-of/index.js ***! | ||
\*******************************************/ | ||
/***/ (function(module) { | ||
/***/ ((module) => { | ||
@@ -323,2 +181,83 @@ var toString = Object.prototype.toString; | ||
/***/ }), | ||
/***/ 668: | ||
/*!********************************************************************************************************!*\ | ||
!*** ../../node_modules/@wix/babel-preset-yoshi/node_modules/@babel/runtime/helpers/defineProperty.js ***! | ||
\********************************************************************************************************/ | ||
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { | ||
var toPropertyKey = __webpack_require__(/*! ./toPropertyKey.js */ 403); | ||
function _defineProperty(obj, key, value) { | ||
key = toPropertyKey(key); | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
module.exports = _defineProperty, module.exports.__esModule = true, module.exports["default"] = module.exports; | ||
/***/ }), | ||
/***/ 350: | ||
/*!*****************************************************************************************************!*\ | ||
!*** ../../node_modules/@wix/babel-preset-yoshi/node_modules/@babel/runtime/helpers/toPrimitive.js ***! | ||
\*****************************************************************************************************/ | ||
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { | ||
var _typeof = (__webpack_require__(/*! ./typeof.js */ 311)["default"]); | ||
function toPrimitive(t, r) { | ||
if ("object" != _typeof(t) || !t) return t; | ||
var e = t[Symbol.toPrimitive]; | ||
if (void 0 !== e) { | ||
var i = e.call(t, r || "default"); | ||
if ("object" != _typeof(i)) return i; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return ("string" === r ? String : Number)(t); | ||
} | ||
module.exports = toPrimitive, module.exports.__esModule = true, module.exports["default"] = module.exports; | ||
/***/ }), | ||
/***/ 403: | ||
/*!*******************************************************************************************************!*\ | ||
!*** ../../node_modules/@wix/babel-preset-yoshi/node_modules/@babel/runtime/helpers/toPropertyKey.js ***! | ||
\*******************************************************************************************************/ | ||
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { | ||
var _typeof = (__webpack_require__(/*! ./typeof.js */ 311)["default"]); | ||
var toPrimitive = __webpack_require__(/*! ./toPrimitive.js */ 350); | ||
function toPropertyKey(t) { | ||
var i = toPrimitive(t, "string"); | ||
return "symbol" == _typeof(i) ? i : String(i); | ||
} | ||
module.exports = toPropertyKey, module.exports.__esModule = true, module.exports["default"] = module.exports; | ||
/***/ }), | ||
/***/ 311: | ||
/*!************************************************************************************************!*\ | ||
!*** ../../node_modules/@wix/babel-preset-yoshi/node_modules/@babel/runtime/helpers/typeof.js ***! | ||
\************************************************************************************************/ | ||
/***/ ((module) => { | ||
function _typeof(o) { | ||
"@babel/helpers - typeof"; | ||
return (module.exports = _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { | ||
return typeof o; | ||
} : function (o) { | ||
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; | ||
}, module.exports.__esModule = true, module.exports["default"] = module.exports), _typeof(o); | ||
} | ||
module.exports = _typeof, module.exports.__esModule = true, module.exports["default"] = module.exports; | ||
/***/ }) | ||
@@ -354,17 +293,17 @@ | ||
/******/ /* webpack/runtime/compat get default export */ | ||
/******/ !function() { | ||
/******/ (() => { | ||
/******/ // getDefaultExport function for compatibility with non-harmony modules | ||
/******/ __webpack_require__.n = function(module) { | ||
/******/ __webpack_require__.n = (module) => { | ||
/******/ var getter = module && module.__esModule ? | ||
/******/ function() { return module['default']; } : | ||
/******/ function() { return module; }; | ||
/******/ () => (module['default']) : | ||
/******/ () => (module); | ||
/******/ __webpack_require__.d(getter, { a: getter }); | ||
/******/ return getter; | ||
/******/ }; | ||
/******/ }(); | ||
/******/ })(); | ||
/******/ | ||
/******/ /* webpack/runtime/define property getters */ | ||
/******/ !function() { | ||
/******/ (() => { | ||
/******/ // define getter functions for harmony exports | ||
/******/ __webpack_require__.d = function(exports, definition) { | ||
/******/ __webpack_require__.d = (exports, definition) => { | ||
/******/ for(var key in definition) { | ||
@@ -376,13 +315,13 @@ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { | ||
/******/ }; | ||
/******/ }(); | ||
/******/ })(); | ||
/******/ | ||
/******/ /* webpack/runtime/hasOwnProperty shorthand */ | ||
/******/ !function() { | ||
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } | ||
/******/ }(); | ||
/******/ (() => { | ||
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) | ||
/******/ })(); | ||
/******/ | ||
/******/ /* webpack/runtime/make namespace object */ | ||
/******/ !function() { | ||
/******/ (() => { | ||
/******/ // define __esModule on exports | ||
/******/ __webpack_require__.r = function(exports) { | ||
/******/ __webpack_require__.r = (exports) => { | ||
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
@@ -393,3 +332,3 @@ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | ||
/******/ }; | ||
/******/ }(); | ||
/******/ })(); | ||
/******/ | ||
@@ -399,3 +338,3 @@ /************************************************************************/ | ||
// This entry need to be wrapped in an IIFE because it need to be in strict mode. | ||
!function() { | ||
(() => { | ||
"use strict"; | ||
@@ -410,51 +349,40 @@ /*!******************************!*\ | ||
__webpack_require__.d(__webpack_exports__, { | ||
"Validator": function() { return /* reexport */ validator.Validator; }, | ||
"default": function() { return /* binding */ index; }, | ||
"filterBuilder": function() { return /* reexport */ filterBuilder; }, | ||
"filterMixin": function() { return /* reexport */ filter_mixin; }, | ||
"optimiseQuery": function() { return /* reexport */ optimisedQuery; }, | ||
"wixDataEncoder": function() { return /* reexport */ wixDataEncoder; } | ||
Validator: () => (/* reexport */ validator.Validator), | ||
"default": () => (/* binding */ index), | ||
filterBuilder: () => (/* reexport */ filterBuilder), | ||
filterMixin: () => (/* reexport */ filter_mixin), | ||
optimiseQuery: () => (/* reexport */ optimisedQuery), | ||
wixDataEncoder: () => (/* reexport */ wixDataEncoder) | ||
}); | ||
// EXTERNAL MODULE: ../../node_modules/@wix/yoshi-webpack-utils/node_modules/@babel/runtime/helpers/createClass.js | ||
var createClass = __webpack_require__(523); | ||
var createClass_default = /*#__PURE__*/__webpack_require__.n(createClass); | ||
// EXTERNAL MODULE: ../../node_modules/@wix/yoshi-webpack-utils/node_modules/@babel/runtime/helpers/inheritsLoose.js | ||
var inheritsLoose = __webpack_require__(333); | ||
var inheritsLoose_default = /*#__PURE__*/__webpack_require__.n(inheritsLoose); | ||
// EXTERNAL MODULE: ../../node_modules/@wix/yoshi-webpack-utils/node_modules/@babel/runtime/helpers/extends.js | ||
var helpers_extends = __webpack_require__(710); | ||
var extends_default = /*#__PURE__*/__webpack_require__.n(helpers_extends); | ||
// EXTERNAL MODULE: ../../node_modules/@wix/yoshi-webpack-utils/node_modules/@babel/runtime/helpers/assertThisInitialized.js | ||
var assertThisInitialized = __webpack_require__(50); | ||
var assertThisInitialized_default = /*#__PURE__*/__webpack_require__.n(assertThisInitialized); | ||
// EXTERNAL MODULE: ../../node_modules/@wix/yoshi-webpack-utils/node_modules/@babel/runtime/helpers/defineProperty.js | ||
var defineProperty = __webpack_require__(695); | ||
// EXTERNAL MODULE: ../../node_modules/@wix/babel-preset-yoshi/node_modules/@babel/runtime/helpers/defineProperty.js | ||
var defineProperty = __webpack_require__(668); | ||
var defineProperty_default = /*#__PURE__*/__webpack_require__.n(defineProperty); | ||
// EXTERNAL MODULE: ../../node_modules/kind-of/index.js | ||
var kind_of = __webpack_require__(366); | ||
var kind_of = __webpack_require__(182); | ||
var kind_of_default = /*#__PURE__*/__webpack_require__.n(kind_of); | ||
;// 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 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;} | ||
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;}const first=str.slice(0,1).toUpperCase();const rest=str.slice(1,str.length);return first+rest;} | ||
;// CONCATENATED MODULE: ./clone.ts | ||
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;} | ||
function clone(obj){if(obj==null||typeof obj!=='object'){return obj;}let temp=null;if(isDate(obj)){temp=new Date(obj.getTime());}else{temp=obj.constructor();for(const key in obj){temp[key]=clone(obj[key]);}}return temp;} | ||
;// CONCATENATED MODULE: ./filter-validator.ts | ||
var FilterValidator=/*#__PURE__*/function(){function FilterValidator(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);}var _proto=FilterValidator.prototype;_proto.typeIsString=function typeIsString(value){var _this=this;return this.addValidation(function(){return isString(value);},function(){return"Invalid "+_this.operatorName+" parameter value ["+typeForDisplay(value)+"]. "+_this.operatorName+" parameter must be a String.";});};_proto.typeIsStringNumberOrDate=function typeIsStringNumberOrDate(value){var _this2=this;return this.addValidation(function(){return isDateStringOrNumber(value);},function(){return"Invalid "+_this2.operatorName+" parameter value ["+typeForDisplay(value)+"]. Valid "+_this2.operatorName+" parameter types are String, Number or Date.";});};_proto.sameType=function sameType(first,second){var _this3=this;return this.addValidation(function(){return typeForDisplay(first)===typeForDisplay(second);},function(){return"Invalid "+_this3.operatorName+" parameter values ["+typeForDisplay(first)+"] and ["+typeForDisplay(second)+"]. Both parameters must be of the same type.";});};_proto.typeIsStringNumberOrDateForAll=function typeIsStringNumberOrDateForAll(values){var _this4=this;return this.addValidation(function(){return values.every(isDateStringOrNumber);},function(){return"Invalid "+_this4.operatorName+" usage. "+_this4.operatorName+" supports only Number, String or Date items.";});};_proto.validFieldName=function validFieldName(field){var _this5=this;return this.addValidation(function(){return isString(field);},function(){return"Invalid "+_this5.operatorName+" field value ["+typeForDisplay(field)+"]. "+_this5.operatorName+" field must be a String.";});};_proto.isInstanceOfSameClass=function isInstanceOfSameClass(obj){var _this6=this;return this.addValidation(function(){return obj instanceof _this6.ctor;},function(){return"Invalid "+_this6.operatorName+" parameter ["+typeForDisplay(obj)+"]. "+_this6.operatorName+" expects FilterBuilder only.";});};_proto.arityIsOne=function arityIsOne(args){var _this7=this;return this.addValidation(function(){return args.length===1;},function(){return"Invalid "+_this7.operatorName+" usage. "+_this7.operatorName+" requires one parameter.";});};_proto.arityIsTwo=function arityIsTwo(args){var _this8=this;return this.addValidation(function(){return args.length===2;},function(){return"Invalid "+_this8.operatorName+" usage. "+_this8.operatorName+" requires two parameters.";});};_proto.arityIsThree=function arityIsThree(args){var _this9=this;return this.addValidation(function(){return args.length===3;},function(){return"Invalid "+_this9.operatorName+" usage. "+_this9.operatorName+" requires three parameters.";});};_proto.arityIsAtLeastTwo=function arityIsAtLeastTwo(args){var _this10=this;return this.addValidation(function(){return args.length>=2;},function(){return"Invalid "+_this10.operatorName+" usage. "+_this10.operatorName+" requires at least two parameters.";});};_proto.addValidation=function addValidation(predicateFn,messageFn){this._validations.push({predicateFn:predicateFn,messageFn:messageFn});return this;};_proto.validateAndAggregate=function validateAndAggregate(){var _this11=this;var valid=this._validations.every(function(_ref){var predicateFn=_ref.predicateFn,messageFn=_ref.messageFn;return _this11._appendIfInvalid(predicateFn(),messageFn());});return[this._invalidArguments,valid];};_proto._appendIfInvalid=function _appendIfInvalid(valid,message){if(!valid){this._invalidArguments.push(message);return false;}return true;};return FilterValidator;}();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 | ||
function _createForOfIteratorHelperLoose(o,allowArrayLike){var it=typeof Symbol!=="undefined"&&o[Symbol.iterator]||o["@@iterator"];if(it)return(it=it.call(o)).next.bind(it);if(Array.isArray(o)||(it=_unsupportedIterableToArray(o))||allowArrayLike&&o&&typeof o.length==="number"){if(it)o=it;var i=0;return function(){if(i>=o.length)return{done:true};return{done:false,value:o[i++]};};}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 _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2;}var optimisations=[optimisedUnaryAnd,optimisedEmptyAnd,optimisedAndsAsObjects,optimisedNestedAnds,optimisedNestedOrs];function optimisedQuery(query){var _fullyOptimised=fullyOptimised(query),newQuery=_fullyOptimised[0];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){var optimisedElements=query.map(fullyOptimised);var somethingChanged=0<optimisedElements.filter(function(_ref){var elementChanged=_ref[1];return elementChanged;}).length;var newElements=optimisedElements.map(function(_ref2){var element=_ref2[0];return element;});return[newElements,somethingChanged];}function fullyOptimisedObject(query){var _fullEntriesOptimisat=fullEntriesOptimisation(query),queryAfterOptimisingEntries=_fullEntriesOptimisat[0],changedStage1=_fullEntriesOptimisat[1];var _fullObjectOptimisati=fullObjectOptimisation(queryAfterOptimisingEntries),queryAfterFullOptimisation=_fullObjectOptimisati[0],changedStage2=_fullObjectOptimisati[1];var changed=changedStage1||changedStage2;return[queryAfterFullOptimisation,changed];function fullObjectOptimisation(query){var updatedQuery=applyFirstOptimisation(query);if(!updatedQuery){return[query,false];}var _fullyOptimised2=fullyOptimised(updatedQuery),finalQuery=_fullyOptimised2[0];return[finalQuery,true];}function fullEntriesOptimisation(query){var changedEntries=Object.entries(query).map(entryOptimisation).filter(function(_ref3){var changed=_ref3[2];return changed;});var newQuery=extends_default()({},query,entriesAsObject(changedEntries));var changed=!!changedEntries.length;return[newQuery,changed];}function entryOptimisation(_ref4){var key=_ref4[0],value=_ref4[1];var _fullyOptimised3=fullyOptimised(value),newValue=_fullyOptimised3[0],changed=_fullyOptimised3[1];return[key,newValue,changed];}function entriesAsObject(entries){return entries.reduce(function(acc,_ref5){var _extends2;var key=_ref5[0],value=_ref5[1];return extends_default()({},acc,(_extends2={},_extends2[key]=value,_extends2));},{});}}function applyFirstOptimisation(node){for(var _iterator=_createForOfIteratorHelperLoose(optimisations),_step;!(_step=_iterator()).done;){var optimisation=_step.value;var newNode=optimisation(node);if(newNode){return newNode;}}}function optimisedUnaryAnd(node){var args=node.$and;if(Array.isArray(args)&&args.length===1){return args[0];}}function optimisedEmptyAnd(node){var args=node.$and;if(Array.isArray(args)&&args.length===0){return{};}return null;}function optimisedAndsAsObjects(node){var args=node.$and;if(!args){return;}var basicObjects=[];var operatorObjects=[];args.forEach(function(arg){if(isOperator(arg)){operatorObjects=[].concat(operatorObjects,[arg]);}else{basicObjects=[].concat(basicObjects,[arg]);}});if(basicObjects.length<=1||haveOverlappingFields(basicObjects)){return;}var combinedBasicObjects=Object.assign.apply(Object,[{}].concat(basicObjects));return{$and:[combinedBasicObjects].concat(operatorObjects)};function isOperator(node){var keys=Object.keys(node);return keys.every(function(name){return name.startsWith('$');})&&keys.length>0;}function haveOverlappingFields(objects){var nonUniqueKeys=objects.map(function(it){return Object.keys(it);}).reduce(function(a,b){return[].concat(a,b);},[]);var uniqueKeys=unique(nonUniqueKeys);return uniqueKeys.length!==nonUniqueKeys.length;}function unique(values){var dict={};values.forEach(function(v){return dict[v]=true;});return Object.keys(dict);}}function optimisedNestedAnds(node){var args=node.$and;if(!args){return;}var hasNestedAnds=!!args.find(function(it){return it.$and;});if(!hasNestedAnds){return;}var newArgs=args.reduce(function(result,current){var and=current.$and;if(!and){return[].concat(result,[current]);}return[].concat(result,and);},[]);return{$and:newArgs};}function optimisedNestedOrs(node){var args=node.$or;if(!args){return;}var hasNestedOrs=!!args.find(function(it){return it.$or;});if(!hasNestedOrs){return;}var newArgs=args.reduce(function(result,current){var or=current.$or;if(!or){return[].concat(result,[current]);}return[].concat(result,or);},[]);return{$or:newArgs};}function instanceOfIgnoredType(obj){return obj instanceof Date;} | ||
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;} | ||
;// 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);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, | ||
const filterMixin=function(Base){if(Base===void 0){Base=class{};}return class extends Base{constructor(obj){if(obj===void 0){obj={};}super(obj);defineProperty_default()(this,"filterTree",void 0);defineProperty_default()(this,"invalidArguments",void 0);defineProperty_default()(this,"encoder",void 0);this.filterTree=obj.filterTree||{$and:[]};this.invalidArguments=obj.invalidArguments||[];this.encoder=obj.encoder||{};}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);}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);}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);}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);}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);}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);}isNotEmpty(field){const[newInvalidArguments,valid]=this._filterValidator('.isNotEmpty').arityIsOne(arguments).validFieldName(field).validateAndAggregate();if(valid){return this.ne(field,null);}return this._copy(this.filterTree,newInvalidArguments);}isEmpty(field){const[newInvalidArguments,valid]=this._filterValidator('.isEmpty').arityIsOne(arguments).validFieldName(field).validateAndAggregate();if(valid){return this.eq(field,null);}return this._copy(this.filterTree,newInvalidArguments);}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);}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);}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);}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);}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);}or(orQuery){const[newInvalidArguments,valid]=this._filterValidator('.or').arityIsOne(arguments).isInstanceOfSameClass(orQuery).validateAndAggregate();if(valid){const prefix=isEmptyAnd(this.filterTree)?[]:[this.filterTree];return this._copy(inAnd({$or:[...prefix,orQuery.filterTree]}),newInvalidArguments.concat(orQuery.invalidArguments));}else{return this._copy(this.filterTree,newInvalidArguments);}}and(andQuery){const[newInvalidArguments,valid]=this._filterValidator('.and').arityIsOne(arguments).isInstanceOfSameClass(andQuery).validateAndAggregate();if(valid){const prefix=isEmptyAnd(this.filterTree)?[]:[this.filterTree];return this._copy(inAnd(...prefix,andQuery.filterTree),newInvalidArguments.concat(andQuery.invalidArguments));}else{return this._copy(this.filterTree,newInvalidArguments);}}not(notQuery){const[newInvalidArguments,valid]=this._filterValidator('.not').arityIsOne(arguments).isInstanceOfSameClass(notQuery).validateAndAggregate();if(valid){const newFilterTree=clone(this.filterTree);const notClause={$not:[notQuery.filterTree]};const resultingFilter=inAndOptimized(newFilterTree,notClause);return this._copy(resultingFilter,newInvalidArguments.concat(notQuery.invalidArguments));}else{return this._copy(this.filterTree,newInvalidArguments);}}between(field,rangeStart,rangeEnd){const[newInvalidArguments,valid]=this._filterValidator('.between').arityIsThree(arguments).sameType(rangeStart,rangeEnd).typeIsStringNumberOrDate(rangeStart).typeIsStringNumberOrDate(rangeEnd).validateAndAggregate();if(valid){return this.ge(field,rangeStart).lt(field,rangeEnd);}return this._copy(this.filterTree,newInvalidArguments);}getFilterModel(){if(this.invalidArguments.length>0){throw new Error(this.invalidArguments.join(' '));}return optimisedQuery(this.filterTree);}setFilterModel(filterModel){return this._copy(filterModel,[]);}_binaryAnd(filterOperatorSymbol,operatorName,args){const[field,operand]=Array.prototype.slice.call(args);const[newInvalidArguments]=this._filterValidator(operatorName).arityIsTwo(args).validFieldName(field).validateAndAggregate();const newFilterTree=this._makeNewFilter(field,filterOperatorSymbol,operand);return this._copy(newFilterTree,newInvalidArguments);}_AndLogicalEquivalence(filterOperatorSymbol,operatorName,args){const[field,operand]=Array.prototype.slice.call(args);const[newInvalidArguments]=this._filterValidator(operatorName).arityIsTwo(args).validFieldName(field).typeIsStringNumberOrDate(operand).validateAndAggregate();const newFilterTree=this._makeNewFilter(field,filterOperatorSymbol,operand);return this._copy(newFilterTree,newInvalidArguments);}_AndStringOperand(filterOperatorName,operatorName,args){const[field,operand]=Array.prototype.slice.call(args);const[newInvalidArguments]=this._filterValidator(operatorName).arityIsTwo(args).validFieldName(field).typeIsString(operand).validateAndAggregate();const newFilterTree=this._makeNewFilter(field,filterOperatorName,operand);return this._copy(newFilterTree,newInvalidArguments);}_AndSetOperand(filterOperatorName,operatorName,args){const[field,...rawOperands]=Array.prototype.slice.call(args);const operands=isArray(rawOperands[0])?rawOperands[0]:rawOperands;const[newInvalidArguments]=this._filterValidator(operatorName).arityIsAtLeastTwo(args).validFieldName(field).typeIsStringNumberOrDateForAll(operands).validateAndAggregate();const newFilterTree=this._makeNewFilter(field,filterOperatorName,operands);return this._copy(newFilterTree,newInvalidArguments);}_makeNewFilter(field,filterOperatorName,operand){const 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._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); | ||
const serializableOperand=operand===undefined?null:operand;const newFilter=this._buildFilter(field,filterOperatorName,serializableOperand);if(isArray(newFilterTree.$and)){newFilterTree.$and.push(newFilter);return newFilterTree;}else{const result=isEmptyObject(newFilterTree)?inAnd(newFilter):inAnd(newFilterTree,newFilter);return result;}}_buildFilter(field,filterOperatorName,operand){if(filterOperatorName!=='$eq'){const newFilter={};newFilter[field]={};newFilter[field][filterOperatorName]=this._encode(operand);return newFilter;}else{const newFilter={};newFilter[field]=this._encode(operand);return newFilter;}}_encode(operand){if(isFunction(this.encoder)){return this.encoder(operand);}else{return operand;}}_copy(filterTree,invalidArguments){// @ts-ignore-next-line | ||
return new this.constructor({...this,filterTree,invalidArguments});}_filterValidator(filterOperatorName){return new FilterValidator(filterOperatorName,this.invalidArguments,this.constructor);}};};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((aggr,val)=>isConjunctiveFormFilter(val)?aggr.concat(val.$and):aggr.concat([val]),[])};}function isEmptyAnd(node){return node&&node.$and&&node.$and.length===0;}/* harmony default export */ const 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(params){if(params===void 0){params={};}return new FilterBuilder(params);}/* harmony default export */ var filter_builder = ((/* unused pure expression or super */ null && (filterBuilder))); | ||
class FilterBuilder extends filter_mixin(){get constructorName(){return'FilterBuilder';}_build(){return this.getFilterModel();}}function filterBuilder(params){if(params===void 0){params={};}return new FilterBuilder(params);}/* harmony default export */ const filter_builder = ((/* unused pure expression or super */ null && (filterBuilder))); | ||
// EXTERNAL MODULE: ./validator.ts | ||
var validator = __webpack_require__(347); | ||
var validator = __webpack_require__(24); | ||
;// CONCATENATED MODULE: ./wix-data-encoder.ts | ||
function wixDataEncoder(operand){if(isDate(operand)){return{$date:operand.toJSON()};}else{return operand;}} | ||
;// CONCATENATED MODULE: ./index.ts | ||
/* harmony default export */ var index = (filterBuilder); | ||
}(); | ||
/* harmony default export */ const index = (filterBuilder); | ||
})(); | ||
/******/ return __webpack_exports__; | ||
@@ -461,0 +389,0 @@ /******/ })() |
@@ -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={50: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},523: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},695: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},710: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},333:function(t,r,e){var n=e(814);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},814: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},347:function(){},366: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"}}},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 F.Validator},default:function(){return M},filterBuilder:function(){return T},filterMixin:function(){return S},optimiseQuery:function(){return x},wixDataEncoder:function(){return V}});var t=e(523),r=e.n(t),i=e(333),a=e.n(i),o=e(710),u=e.n(o),s=e(50),c=e.n(s),l=e(695),f=e.n(l),d=e(366),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=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(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return{$and:r}}function N(t){return t&&t.$and&&0===t.$and.length}var S=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),f()(c()(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];return r[1]?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];return r[1]?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];if(r[1]){var n=N(this.filterTree)?[]:[this.filterTree];return this._copy(w({$or:[].concat(n,[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];if(r[1]){var n=N(this.filterTree)?[]:[this.filterTree];return this._copy(w.apply(void 0,n.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];if(r[1]){var n=function(){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 v(r.$and)?t.concat(r.$and):t.concat([r])}),[])}}(m(this.filterTree),{$not:[t.filterTree]});return this._copy(n,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];return n[1]?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],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 v(i.$and)?(i.$and.push(o),i):(n=i,0===Object.keys(n).length?w(o):w(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)},$=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}(S());function T(t){return void 0===t&&(t={}),new $(t)}var F=e(347);function V(t){return h(t)?{$date:t.toJSON()}:t}var M=T}(),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:()=>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})())); | ||
//# sourceMappingURL=filter-builder.umd.min.js.map |
{ | ||
"filter-builder.js": "https://static.parastorage.com/services/filter-builder/8119fafb150e8d508c3321ed7739e7e3c82922c844f07d93348abb74/filter-builder.umd.js" | ||
"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/8119fafb150e8d508c3321ed7739e7e3c82922c844f07d93348abb74/filter-builder.umd.min.js" | ||
"filter-builder.js": "https://static.parastorage.com/services/filter-builder/d383849e128e48818d9e5f0aa6030adb7d2c8fb2a019860c5b6cd286/filter-builder.umd.min.js" | ||
} |
{ | ||
"name": "@wix/filter-builder", | ||
"version": "1.0.39", | ||
"version": "1.0.40", | ||
"license": "UNLICENSED", | ||
@@ -42,5 +42,5 @@ "author": { | ||
"@types/node": "^14.18.61", | ||
"@wix/eslint-config-yoshi": "^5.162.14", | ||
"@wix/jest-yoshi-preset": "^5.162.14", | ||
"@wix/yoshi-flow-library": "^5.162.14", | ||
"@wix/eslint-config-yoshi": "^6.88.1", | ||
"@wix/jest-yoshi-preset": "^6.88.1", | ||
"@wix/yoshi-flow-library": "^6.88.1", | ||
"chai": "~3.5.0", | ||
@@ -93,3 +93,3 @@ "express": "^4.18.2", | ||
}, | ||
"falconPackageHash": "e7efb303b65daaec40b58192971c67fccb6dde4954403de99b497a69" | ||
"falconPackageHash": "0352d7472f44f18f497facd8adf5b3f7c45dbeb0077e211efaf2f1cd" | ||
} |
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
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
404261
2492