UNPKG

3.2 kBJavaScriptView Raw
1"use strict";
2var __spreadArray = (this && this.__spreadArray) || function (to, from) {
3 for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
4 to[j] = from[i];
5 return to;
6};
7Object.defineProperty(exports, "__esModule", { value: true });
8exports.isFilterList = exports.FilterList = void 0;
9/**
10 * Data structure to combine [[Filterable]]s conjunctively and / or disjunctively. A FilterList matches when all filterables within the `andFilters` match and when at least one filterable within the `orFilters` matches. Should not be used directly.
11 * @typeparam EntityT -
12 */
13var FilterList = /** @class */ (function () {
14 /**
15 * Creates an instance of FilterList.
16 * @param andFilters - Filters to be combined by logical conjunction (`and`)
17 * @param orFilters - Filters to be combined by logical disjunction (`or`)
18 */
19 function FilterList(andFilters, orFilters) {
20 if (andFilters === void 0) { andFilters = []; }
21 if (orFilters === void 0) { orFilters = []; }
22 this.andFilters = andFilters;
23 this.orFilters = orFilters;
24 }
25 /**
26 * @deprecated Since v1.28.1. This function should not be used, since some OData Services might not support the flattened filter expression.
27 * Flattens `andFilters` and `orFilters` as far as possible while staying logically equivalent.
28 * @returns Flattened filter list.
29 */
30 FilterList.prototype.flatten = function () {
31 this._flatten('andFilters');
32 this._flatten('orFilters');
33 return this;
34 };
35 FilterList.prototype.canFlatten = function (property) {
36 var otherProperty = property === 'andFilters' ? 'orFilters' : 'andFilters';
37 return this[property].some(function (filter) {
38 return filter instanceof FilterList &&
39 (!filter.isEmpty(property) || filter.isEmpty(otherProperty));
40 });
41 };
42 FilterList.prototype.isEmpty = function (property) {
43 return !this[property].length;
44 };
45 FilterList.prototype._flatten = function (property) {
46 var otherProperty = property === 'andFilters' ? 'orFilters' : 'andFilters';
47 while (this.canFlatten(property)) {
48 this[property] = this[property].reduce(function (flatList, current) {
49 if (current instanceof FilterList) {
50 var flattenedFilters = __spreadArray(__spreadArray([], flatList), current[property]);
51 if (current[otherProperty].length) {
52 current[property] = [];
53 flattenedFilters.push(current.flatten());
54 }
55 return flattenedFilters;
56 }
57 return __spreadArray(__spreadArray([], flatList), [current]);
58 }, []);
59 }
60 };
61 return FilterList;
62}());
63exports.FilterList = FilterList;
64function isFilterList(filterable) {
65 return (typeof filterable['field'] === 'undefined' &&
66 typeof filterable['operator'] === 'undefined' &&
67 typeof filterable['value'] === 'undefined' &&
68 typeof filterable['flatten'] === 'function');
69}
70exports.isFilterList = isFilterList;
71//# sourceMappingURL=filter-list.js.map
\No newline at end of file