1 | "use strict";
|
2 | var __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 | };
|
7 | Object.defineProperty(exports, "__esModule", { value: true });
|
8 | exports.isFilterList = exports.FilterList = void 0;
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | var FilterList = (function () {
|
14 | |
15 |
|
16 |
|
17 |
|
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 |
|
27 |
|
28 |
|
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 | }());
|
63 | exports.FilterList = FilterList;
|
64 | function isFilterList(filterable) {
|
65 | return (typeof filterable['field'] === 'undefined' &&
|
66 | typeof filterable['operator'] === 'undefined' &&
|
67 | typeof filterable['value'] === 'undefined' &&
|
68 | typeof filterable['flatten'] === 'function');
|
69 | }
|
70 | exports.isFilterList = isFilterList;
|
71 |
|
\ | No newline at end of file |