quetch 0.19.5 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/tools/fieldListFromFilter.js +6 -2
- package/dist/tools/fieldListFromFilter.js.map +1 -1
- package/dist/tools/testFilter.js +43 -28
- package/dist/tools/testFilter.js.map +1 -1
- package/dist/types/FilterArray.d.ts +1 -1
- package/dist/types/FilterChildren.d.ts +1 -1
- package/dist/types/FilterField.d.ts +1 -1
- package/dist/types/FilterNumber.d.ts +1 -1
- package/dist/types/FilterString.d.ts +1 -1
- package/dist/types/FilterStringIntersect.d.ts +1 -1
- package/dist/types/FilterStringMatch.d.ts +1 -1
- package/lib/tools/fieldListFromFilter.ts +6 -2
- package/lib/tools/testFilter.test.ts +60 -0
- package/lib/tools/testFilter.ts +60 -37
- package/lib/types/FilterArray.ts +7 -1
- package/lib/types/FilterChildren.ts +1 -1
- package/lib/types/FilterField.ts +1 -1
- package/lib/types/FilterNumber.ts +5 -1
- package/lib/types/FilterString.ts +7 -1
- package/lib/types/FilterStringIntersect.ts +1 -1
- package/lib/types/FilterStringMatch.ts +1 -1
- package/package.json +1 -1
|
@@ -21,8 +21,12 @@ export function fieldListFromFilter(filter) {
|
|
|
21
21
|
case "startWith":
|
|
22
22
|
case "endWith":
|
|
23
23
|
case "match":
|
|
24
|
-
case "exist":
|
|
25
|
-
|
|
24
|
+
case "exist": {
|
|
25
|
+
if ("field" in filter) {
|
|
26
|
+
return [filter.field];
|
|
27
|
+
}
|
|
28
|
+
return EMPTY_ARRAY;
|
|
29
|
+
}
|
|
26
30
|
case "all":
|
|
27
31
|
case "any":
|
|
28
32
|
case "none":
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fieldListFromFilter.js","sourceRoot":"","sources":["../../lib/tools/fieldListFromFilter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAI3C;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAAkB;IAElB,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,WAAW,CAAC;IACrB,CAAC;IACD,QAAQ,MAAM,CAAC,QAAQ,EAAE,CAAC;QACxB,KAAK,OAAO,CAAC;QACb,KAAK,SAAS,CAAC;QACf,KAAK,WAAW,CAAC;QACjB,KAAK,UAAU,CAAC;QAChB,KAAK,aAAa,CAAC;QACnB,KAAK,oBAAoB,CAAC;QAC1B,KAAK,WAAW,CAAC;QACjB,KAAK,kBAAkB,CAAC;QACxB,KAAK,WAAW,CAAC;QACjB,KAAK,SAAS,CAAC;QACf,KAAK,OAAO,CAAC;QACb,KAAK,OAAO;
|
|
1
|
+
{"version":3,"file":"fieldListFromFilter.js","sourceRoot":"","sources":["../../lib/tools/fieldListFromFilter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAI3C;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAAkB;IAElB,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,WAAW,CAAC;IACrB,CAAC;IACD,QAAQ,MAAM,CAAC,QAAQ,EAAE,CAAC;QACxB,KAAK,OAAO,CAAC;QACb,KAAK,SAAS,CAAC;QACf,KAAK,WAAW,CAAC;QACjB,KAAK,UAAU,CAAC;QAChB,KAAK,aAAa,CAAC;QACnB,KAAK,oBAAoB,CAAC;QAC1B,KAAK,WAAW,CAAC;QACjB,KAAK,kBAAkB,CAAC;QACxB,KAAK,WAAW,CAAC;QACjB,KAAK,SAAS,CAAC;QACf,KAAK,OAAO,CAAC;QACb,KAAK,OAAO,CAAC,CAAC,CAAC;YACb,IAAI,OAAO,IAAI,MAAM,EAAE,CAAC;gBACtB,OAAO,CAAC,MAAM,CAAC,KAAiB,CAAC,CAAC;YACpC,CAAC;YACD,OAAO,WAAW,CAAC;QACrB,CAAC;QACD,KAAK,KAAK,CAAC;QACX,KAAK,KAAK,CAAC;QACX,KAAK,MAAM;YACT,OAAO,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,mBAAmB,CAAC,IAAI,WAAW,CAAC;QACnE,KAAK,UAAU,CAAC;QAChB,KAAK,QAAQ;YACX,OAAO,WAAW,CAAC;QACrB;YACE,OAAO,WAAW,CAAC;IACvB,CAAC;AACH,CAAC"}
|
package/dist/tools/testFilter.js
CHANGED
|
@@ -77,7 +77,9 @@ export function testFilter(filter, value, settings) {
|
|
|
77
77
|
}
|
|
78
78
|
return true;
|
|
79
79
|
}
|
|
80
|
-
case "children":
|
|
80
|
+
case "children":
|
|
81
|
+
case "notChildren": {
|
|
82
|
+
const not = filter.operator[0] === "n";
|
|
81
83
|
if (filter[CACHE] === undefined) {
|
|
82
84
|
switch (true) {
|
|
83
85
|
case settings?.transformFilterChildren !== undefined:
|
|
@@ -89,48 +91,54 @@ export function testFilter(filter, value, settings) {
|
|
|
89
91
|
}
|
|
90
92
|
}
|
|
91
93
|
}
|
|
92
|
-
return testFilter(filter[CACHE], value);
|
|
94
|
+
return negate(testFilter(filter[CACHE], value), not);
|
|
93
95
|
}
|
|
94
96
|
case "custom": {
|
|
95
97
|
return filter.value(value);
|
|
96
98
|
}
|
|
97
|
-
case "startWith":
|
|
99
|
+
case "startWith":
|
|
100
|
+
case "notStartWith": {
|
|
101
|
+
const not = filter.operator[0] === "n";
|
|
98
102
|
const rightValue = valueFromFilter(value, filter);
|
|
99
103
|
const leftValue = get(value, filter.field);
|
|
100
104
|
if (leftValue === undefined || leftValue.length < rightValue.length) {
|
|
101
|
-
return false;
|
|
105
|
+
return negate(false, not);
|
|
102
106
|
}
|
|
103
107
|
if (filter.options !== undefined || filter.locale !== undefined) {
|
|
104
|
-
return (rightValue.localeCompare(leftValue.slice(0, rightValue.length), filter.locale, filter.options) === 0);
|
|
108
|
+
return negate(rightValue.localeCompare(leftValue.slice(0, rightValue.length), filter.locale, filter.options) === 0, not);
|
|
105
109
|
}
|
|
106
|
-
return leftValue.startsWith(rightValue) ?? false;
|
|
110
|
+
return negate(leftValue.startsWith(rightValue) ?? false, not);
|
|
107
111
|
}
|
|
108
|
-
case "endWith":
|
|
112
|
+
case "endWith":
|
|
113
|
+
case "notEndWith": {
|
|
114
|
+
const not = filter.operator[0] === "n";
|
|
109
115
|
const rightValue = valueFromFilter(value, filter);
|
|
110
116
|
const leftValue = get(value, filter.field);
|
|
111
117
|
if (leftValue === undefined || leftValue.length < rightValue.length) {
|
|
112
|
-
return false;
|
|
118
|
+
return negate(false, not);
|
|
113
119
|
}
|
|
114
120
|
if (filter.options !== undefined || filter.locale !== undefined) {
|
|
115
|
-
return (rightValue.localeCompare(leftValue.slice(-rightValue.length), filter.locale, filter.options) === 0);
|
|
121
|
+
return negate(rightValue.localeCompare(leftValue.slice(-rightValue.length), filter.locale, filter.options) === 0, not);
|
|
116
122
|
}
|
|
117
|
-
return leftValue.endsWith(rightValue) ?? false;
|
|
123
|
+
return negate(leftValue.endsWith(rightValue) ?? false, not);
|
|
118
124
|
}
|
|
119
|
-
case "include":
|
|
125
|
+
case "include":
|
|
126
|
+
case "notInclude": {
|
|
127
|
+
const not = filter.operator[0] === "n";
|
|
120
128
|
const rightValue = valueFromFilter(value, filter);
|
|
121
129
|
const leftValue = get(value, filter.field);
|
|
122
130
|
if (leftValue == null) {
|
|
123
|
-
return false;
|
|
131
|
+
return negate(false, not);
|
|
124
132
|
}
|
|
125
133
|
if (isArray(rightValue)) {
|
|
126
134
|
// FIXME: Get unique values
|
|
127
135
|
if (!isArray(leftValue) || leftValue.length < rightValue.length) {
|
|
128
|
-
return false;
|
|
136
|
+
return negate(false, not);
|
|
129
137
|
}
|
|
130
|
-
return rightValue.every((value) => leftValue.includes(value));
|
|
138
|
+
return negate(rightValue.every((value) => leftValue.includes(value)), not);
|
|
131
139
|
}
|
|
132
140
|
if (isArray(leftValue) || leftValue.length < rightValue.length) {
|
|
133
|
-
return false;
|
|
141
|
+
return negate(false, not);
|
|
134
142
|
}
|
|
135
143
|
if (filter.options ||
|
|
136
144
|
filter.locale) {
|
|
@@ -138,12 +146,12 @@ export function testFilter(filter, value, settings) {
|
|
|
138
146
|
const end = leftValue.length - length + 1;
|
|
139
147
|
for (let i = 0; i < end; i++) {
|
|
140
148
|
if (rightValue.localeCompare(leftValue.slice(i, i + length), filter.locale, filter.options) === 0) {
|
|
141
|
-
return true;
|
|
149
|
+
return negate(true, not);
|
|
142
150
|
}
|
|
143
151
|
}
|
|
144
|
-
return false;
|
|
152
|
+
return negate(false, not);
|
|
145
153
|
}
|
|
146
|
-
return leftValue.includes?.(rightValue) ?? false;
|
|
154
|
+
return negate(leftValue.includes?.(rightValue) ?? false, not);
|
|
147
155
|
}
|
|
148
156
|
case "greaterThan": {
|
|
149
157
|
const rightValue = valueFromFilter(value, filter);
|
|
@@ -181,36 +189,43 @@ export function testFilter(filter, value, settings) {
|
|
|
181
189
|
}
|
|
182
190
|
return leftValue <= rightValue;
|
|
183
191
|
}
|
|
184
|
-
case "match":
|
|
192
|
+
case "match":
|
|
193
|
+
case "notMatch": {
|
|
194
|
+
const not = filter.operator[0] === "n";
|
|
185
195
|
const rightValue = valueFromFilter(value, filter);
|
|
186
196
|
const leftValue = get(value, filter.field);
|
|
187
197
|
if (leftValue === undefined) {
|
|
188
|
-
return false;
|
|
198
|
+
return negate(false, not);
|
|
189
199
|
}
|
|
190
200
|
if (filter[CACHE] === undefined) {
|
|
191
201
|
filter[CACHE] = new RegExp(rightValue, `${filter.options?.ignoreCase ? "i" : ""}${filter.options?.dotAll ? "s" : ""}`);
|
|
192
202
|
}
|
|
193
|
-
return filter[CACHE].test(leftValue);
|
|
203
|
+
return negate(filter[CACHE].test(leftValue), not);
|
|
194
204
|
}
|
|
195
|
-
case "intersect":
|
|
205
|
+
case "intersect":
|
|
206
|
+
case "notIntersect": {
|
|
207
|
+
const not = filter.operator[0] === "n";
|
|
196
208
|
const rightValue = valueFromFilter(value, filter);
|
|
197
209
|
const leftValue = get(value, filter.field);
|
|
198
210
|
if (leftValue == null) {
|
|
199
|
-
return false;
|
|
211
|
+
return negate(false, not);
|
|
200
212
|
}
|
|
201
213
|
if (isArray(leftValue)) {
|
|
202
|
-
return (isArray(rightValue) &&
|
|
203
|
-
rightValue.some((value) => leftValue.includes(value)));
|
|
214
|
+
return negate(isArray(rightValue) &&
|
|
215
|
+
rightValue.some((value) => leftValue.includes(value)), not);
|
|
204
216
|
}
|
|
205
217
|
if (filter.options ||
|
|
206
218
|
filter.locale) {
|
|
207
|
-
return (leftValue !== undefined &&
|
|
208
|
-
rightValue.some((value) => value.localeCompare(leftValue, filter.locale, filter.options) === 0));
|
|
219
|
+
return negate(leftValue !== undefined &&
|
|
220
|
+
rightValue.some((value) => value.localeCompare(leftValue, filter.locale, filter.options) === 0), not);
|
|
209
221
|
}
|
|
210
|
-
return rightValue.includes(leftValue);
|
|
222
|
+
return negate(rightValue.includes(leftValue), not);
|
|
211
223
|
}
|
|
212
224
|
default:
|
|
213
225
|
throw new Error(`Unknown filter operator '${filter.operator}'`);
|
|
214
226
|
}
|
|
215
227
|
}
|
|
228
|
+
function negate(value, condition) {
|
|
229
|
+
return condition ? !value : value;
|
|
230
|
+
}
|
|
216
231
|
//# sourceMappingURL=testFilter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testFilter.js","sourceRoot":"","sources":["../../lib/tools/testFilter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAI9C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;AAE1B,SAAS,eAAe,CAAI,KAAQ,EAAE,MAAiB;IACrD,IAAI,YAAY,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,CAAC,UAAU,CAAC;QAClB,OAAO,GAAG,CAAS,KAAK,EAAE,MAAM,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MAAM,EAClC,CAAC;gBACD,OAAO,MAAM,CACX,SAAS,KAAK,SAAS;oBACpB,UAAuB,CAAC,IAAI,CAC3B,CAAC,KAAK,EAAE,EAAE,CACR,KAAK,CAAC,aAAa,CACjB,SAAmB,EAClB,MAA0B,CAAC,MAAM,EACjC,MAA0B,CAAC,OAAO,CACpC,KAAK,CAAC,CACV,EACH,GAAG,CACJ,CAAC;YACJ,CAAC;YACD,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,SAAmB,CAAC,EAAE,GAAG,CAAC,CAAC;QAC/D,CAAC;QACD;YACE,MAAM,IAAI,KAAK,CAAC,4BAA6B,MAAc,CAAC,QAAQ,GAAG,CAAC,CAAC;IAC7E,CAAC;AACH,CAAC;AAED,SAAS,MAAM,CAAC,KAAc,EAAE,SAAkB;IAChD,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;AACpC,CAAC"}
|
|
@@ -8,6 +8,6 @@ import type { Value } from "./Value";
|
|
|
8
8
|
* - `intersect` requires at least one item of the value to be present in the array.
|
|
9
9
|
*/
|
|
10
10
|
export type FilterArray<T, P = any> = {
|
|
11
|
-
operator: "equal" | "include" | "intersect";
|
|
11
|
+
operator: "equal" | "include" | "intersect" | "notEqual" | "notInclude" | "notIntersect";
|
|
12
12
|
field: FieldFiltered<T, P[]>;
|
|
13
13
|
} & Value<T, P[]>;
|
|
@@ -6,7 +6,7 @@ import type { Filter } from "./Filter";
|
|
|
6
6
|
* If `deep` is `true`, also captures all the descendants.
|
|
7
7
|
*/
|
|
8
8
|
export type FilterChildren<T> = {
|
|
9
|
-
operator: "children";
|
|
9
|
+
operator: "children" | "notChildren";
|
|
10
10
|
value?: Context<T> | string;
|
|
11
11
|
deep?: boolean;
|
|
12
12
|
[CACHE]?: Filter<T>;
|
|
@@ -4,6 +4,6 @@ import type { Value } from "./Value";
|
|
|
4
4
|
* Checks if a given number field matches a given number value according to a given operator.
|
|
5
5
|
*/
|
|
6
6
|
export type FilterNumber<T> = {
|
|
7
|
-
operator: "equal" | "notEqual" | "greaterThan" | "greaterThanOrEqual" | "lowerThan" | "lowerThanOrEqual";
|
|
7
|
+
operator: "equal" | "notEqual" | "greaterThan" | "greaterThanOrEqual" | "lowerThan" | "lowerThanOrEqual" | "between" | "notBetween" | "betweenOrEqual" | "notBetweenOrEqual";
|
|
8
8
|
field: FieldFiltered<T, number>;
|
|
9
9
|
} & Value<T, number>;
|
|
@@ -5,7 +5,7 @@ import type { Value } from "./Value";
|
|
|
5
5
|
* Checks if a given string field matches a given string value according to a given operator.
|
|
6
6
|
*/
|
|
7
7
|
export type FilterString<T> = {
|
|
8
|
-
operator: "equal" | "notEqual" | "startWith" | "endWith" | "include" | "greaterThan" | "greaterThanOrEqual" | "lowerThan" | "lowerThanOrEqual";
|
|
8
|
+
operator: "equal" | "notEqual" | "startWith" | "notStartWith" | "endWith" | "notEndWith" | "include" | "greaterThan" | "greaterThanOrEqual" | "lowerThan" | "lowerThanOrEqual" | "between" | "notBetween" | "betweenOrEqual" | "notBetweenOrEqual";
|
|
9
9
|
field: FieldFiltered<T, string>;
|
|
10
10
|
options?: Intl.CollatorOptions;
|
|
11
11
|
locale?: Locale;
|
|
@@ -5,7 +5,7 @@ import type { Value } from "./Value";
|
|
|
5
5
|
* Checks if a given string field has any of the provided values.
|
|
6
6
|
*/
|
|
7
7
|
export type FilterStringIntersect<T> = {
|
|
8
|
-
operator: "intersect";
|
|
8
|
+
operator: "intersect" | "notIntersect";
|
|
9
9
|
field: FieldFiltered<T, string>;
|
|
10
10
|
options?: Intl.CollatorOptions;
|
|
11
11
|
locale?: Locale;
|
|
@@ -5,7 +5,7 @@ import type { Value } from "./Value";
|
|
|
5
5
|
* Checks if a given string field matches a given regular expression, the value being a raw regular expression string.
|
|
6
6
|
*/
|
|
7
7
|
export type FilterStringMatch<T> = {
|
|
8
|
-
operator: "match";
|
|
8
|
+
operator: "match" | "notMatch";
|
|
9
9
|
field: FieldFiltered<T, string>;
|
|
10
10
|
/**
|
|
11
11
|
* Regular expression options.
|
|
@@ -26,8 +26,12 @@ export function fieldListFromFilter<T>(
|
|
|
26
26
|
case "startWith":
|
|
27
27
|
case "endWith":
|
|
28
28
|
case "match":
|
|
29
|
-
case "exist":
|
|
30
|
-
|
|
29
|
+
case "exist": {
|
|
30
|
+
if ("field" in filter) {
|
|
31
|
+
return [filter.field as Field<T>];
|
|
32
|
+
}
|
|
33
|
+
return EMPTY_ARRAY;
|
|
34
|
+
}
|
|
31
35
|
case "all":
|
|
32
36
|
case "any":
|
|
33
37
|
case "none":
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { expect, test } from "vitest";
|
|
2
2
|
|
|
3
3
|
import { CACHE } from "../constants/CACHE.js";
|
|
4
|
+
import { SELF } from "../constants.js";
|
|
4
5
|
import type { FilterChildren } from "../types.js";
|
|
5
6
|
|
|
6
7
|
import { filterFromContext } from "./filterFromContext.js";
|
|
@@ -94,6 +95,15 @@ test("tests filter lists", () => {
|
|
|
94
95
|
).toBe(true);
|
|
95
96
|
});
|
|
96
97
|
|
|
98
|
+
test("tests filter on primitive values", () => {
|
|
99
|
+
expect(
|
|
100
|
+
testFilter({ field: SELF, operator: "equal", value: "test" }, "test"),
|
|
101
|
+
).toBe(true);
|
|
102
|
+
expect(
|
|
103
|
+
testFilter({ field: SELF, operator: "include", value: "test" }, "testing"),
|
|
104
|
+
).toBe(true);
|
|
105
|
+
});
|
|
106
|
+
|
|
97
107
|
test("tests filter on string values", () => {
|
|
98
108
|
expect(
|
|
99
109
|
testFilter({ field: "a", operator: "equal", value: "foo" }, { a: "foo" }),
|
|
@@ -247,24 +257,48 @@ test("tests filter on array values", () => {
|
|
|
247
257
|
expect(
|
|
248
258
|
testFilter({ field: "a", operator: "include", value: [1] }, { a: [1, 2] }),
|
|
249
259
|
).toBe(true);
|
|
260
|
+
expect(
|
|
261
|
+
testFilter(
|
|
262
|
+
{ field: "a", operator: "notInclude", value: [1] },
|
|
263
|
+
{ a: [1, 2] },
|
|
264
|
+
),
|
|
265
|
+
).toBe(false);
|
|
250
266
|
expect(
|
|
251
267
|
testFilter(
|
|
252
268
|
{ field: "a", operator: "include", value: [2, 3] },
|
|
253
269
|
{ a: [1, 2] },
|
|
254
270
|
),
|
|
255
271
|
).toBe(false);
|
|
272
|
+
expect(
|
|
273
|
+
testFilter(
|
|
274
|
+
{ field: "a", operator: "notInclude", value: [2, 3] },
|
|
275
|
+
{ a: [1, 2] },
|
|
276
|
+
),
|
|
277
|
+
).toBe(true);
|
|
256
278
|
expect(
|
|
257
279
|
testFilter(
|
|
258
280
|
{ field: "a", operator: "intersect", value: [2, 3] },
|
|
259
281
|
{ a: [1, 2] },
|
|
260
282
|
),
|
|
261
283
|
).toBe(true);
|
|
284
|
+
expect(
|
|
285
|
+
testFilter(
|
|
286
|
+
{ field: "a", operator: "notIntersect", value: [2, 3] },
|
|
287
|
+
{ a: [1, 2] },
|
|
288
|
+
),
|
|
289
|
+
).toBe(false);
|
|
262
290
|
expect(
|
|
263
291
|
testFilter(
|
|
264
292
|
{ field: "a", operator: "intersect", value: [3, 4] },
|
|
265
293
|
{ a: [1, 2] },
|
|
266
294
|
),
|
|
267
295
|
).toBe(false);
|
|
296
|
+
expect(
|
|
297
|
+
testFilter(
|
|
298
|
+
{ field: "a", operator: "notIntersect", value: [3, 4] },
|
|
299
|
+
{ a: [1, 2] },
|
|
300
|
+
),
|
|
301
|
+
).toBe(true);
|
|
268
302
|
});
|
|
269
303
|
|
|
270
304
|
test("tests filter with paths", () => {
|
|
@@ -280,6 +314,9 @@ test("tests filter with children predicates", () => {
|
|
|
280
314
|
expect(testFilter({ operator: "children", value: "a" }, { id: "a/b" })).toBe(
|
|
281
315
|
true,
|
|
282
316
|
);
|
|
317
|
+
expect(
|
|
318
|
+
testFilter({ operator: "notChildren", value: "a" }, { id: "a/b" }),
|
|
319
|
+
).toBe(false);
|
|
283
320
|
expect(
|
|
284
321
|
testFilter(
|
|
285
322
|
{ operator: "children", value: ".a" },
|
|
@@ -290,6 +327,16 @@ test("tests filter with children predicates", () => {
|
|
|
290
327
|
},
|
|
291
328
|
),
|
|
292
329
|
).toBe(true);
|
|
330
|
+
expect(
|
|
331
|
+
testFilter(
|
|
332
|
+
{ operator: "notChildren", value: ".a" },
|
|
333
|
+
{ path: ".a.b" },
|
|
334
|
+
{
|
|
335
|
+
pathFieldKey: "path",
|
|
336
|
+
pathFieldSeparator: ".",
|
|
337
|
+
},
|
|
338
|
+
),
|
|
339
|
+
).toBe(false);
|
|
293
340
|
const filterChildren: FilterChildren<{ path: string }> = {
|
|
294
341
|
operator: "children",
|
|
295
342
|
value: "a",
|
|
@@ -313,6 +360,9 @@ test("tests filter with children predicates", () => {
|
|
|
313
360
|
expect(testFilter({ operator: "children", value: "b" }, { id: "a/b" })).toBe(
|
|
314
361
|
false,
|
|
315
362
|
);
|
|
363
|
+
expect(
|
|
364
|
+
testFilter({ operator: "notChildren", value: "b" }, { id: "a/b" }),
|
|
365
|
+
).toBe(true);
|
|
316
366
|
expect(
|
|
317
367
|
testFilter(
|
|
318
368
|
{ operator: "children", value: "ba" },
|
|
@@ -323,4 +373,14 @@ test("tests filter with children predicates", () => {
|
|
|
323
373
|
},
|
|
324
374
|
),
|
|
325
375
|
).toBe(false);
|
|
376
|
+
expect(
|
|
377
|
+
testFilter(
|
|
378
|
+
{ operator: "notChildren", value: "ba" },
|
|
379
|
+
{ path: ".a.b" },
|
|
380
|
+
{
|
|
381
|
+
pathFieldKey: "path",
|
|
382
|
+
pathFieldSeparator: ".",
|
|
383
|
+
},
|
|
384
|
+
),
|
|
385
|
+
).toBe(true);
|
|
326
386
|
});
|
package/lib/tools/testFilter.ts
CHANGED
|
@@ -103,7 +103,9 @@ export function testFilter<T>(
|
|
|
103
103
|
}
|
|
104
104
|
return true;
|
|
105
105
|
}
|
|
106
|
-
case "children":
|
|
106
|
+
case "children":
|
|
107
|
+
case "notChildren": {
|
|
108
|
+
const not = filter.operator[0] === "n";
|
|
107
109
|
if (filter[CACHE] === undefined) {
|
|
108
110
|
switch (true) {
|
|
109
111
|
case settings?.transformFilterChildren !== undefined:
|
|
@@ -123,60 +125,71 @@ export function testFilter<T>(
|
|
|
123
125
|
}
|
|
124
126
|
}
|
|
125
127
|
}
|
|
126
|
-
return testFilter(filter[CACHE], value);
|
|
128
|
+
return negate(testFilter(filter[CACHE], value), not);
|
|
127
129
|
}
|
|
128
130
|
case "custom": {
|
|
129
131
|
return filter.value(value);
|
|
130
132
|
}
|
|
131
|
-
case "startWith":
|
|
133
|
+
case "startWith":
|
|
134
|
+
case "notStartWith": {
|
|
135
|
+
const not = filter.operator[0] === "n";
|
|
132
136
|
const rightValue = valueFromFilter(value, filter);
|
|
133
137
|
const leftValue = get<T, any>(value, filter.field) as string | undefined;
|
|
134
138
|
if (leftValue === undefined || leftValue.length < rightValue.length) {
|
|
135
|
-
return false;
|
|
139
|
+
return negate(false, not);
|
|
136
140
|
}
|
|
137
141
|
if (filter.options !== undefined || filter.locale !== undefined) {
|
|
138
|
-
return (
|
|
142
|
+
return negate(
|
|
139
143
|
rightValue.localeCompare(
|
|
140
144
|
leftValue.slice(0, rightValue.length),
|
|
141
145
|
filter.locale,
|
|
142
146
|
filter.options,
|
|
143
|
-
) === 0
|
|
147
|
+
) === 0,
|
|
148
|
+
not,
|
|
144
149
|
);
|
|
145
150
|
}
|
|
146
|
-
return leftValue.startsWith(rightValue) ?? false;
|
|
151
|
+
return negate(leftValue.startsWith(rightValue) ?? false, not);
|
|
147
152
|
}
|
|
148
|
-
case "endWith":
|
|
153
|
+
case "endWith":
|
|
154
|
+
case "notEndWith": {
|
|
155
|
+
const not = filter.operator[0] === "n";
|
|
149
156
|
const rightValue = valueFromFilter(value, filter);
|
|
150
157
|
const leftValue = get<T, any>(value, filter.field) as string | undefined;
|
|
151
158
|
if (leftValue === undefined || leftValue.length < rightValue.length) {
|
|
152
|
-
return false;
|
|
159
|
+
return negate(false, not);
|
|
153
160
|
}
|
|
154
161
|
if (filter.options !== undefined || filter.locale !== undefined) {
|
|
155
|
-
return (
|
|
162
|
+
return negate(
|
|
156
163
|
rightValue.localeCompare(
|
|
157
164
|
leftValue.slice(-rightValue.length),
|
|
158
165
|
filter.locale,
|
|
159
166
|
filter.options,
|
|
160
|
-
) === 0
|
|
167
|
+
) === 0,
|
|
168
|
+
not,
|
|
161
169
|
);
|
|
162
170
|
}
|
|
163
|
-
return leftValue.endsWith(rightValue) ?? false;
|
|
171
|
+
return negate(leftValue.endsWith(rightValue) ?? false, not);
|
|
164
172
|
}
|
|
165
|
-
case "include":
|
|
173
|
+
case "include":
|
|
174
|
+
case "notInclude": {
|
|
175
|
+
const not = filter.operator[0] === "n";
|
|
166
176
|
const rightValue = valueFromFilter(value, filter);
|
|
167
177
|
const leftValue = get<T, any>(value, filter.field) as string | any[];
|
|
168
178
|
if (leftValue == null) {
|
|
169
|
-
return false;
|
|
179
|
+
return negate(false, not);
|
|
170
180
|
}
|
|
171
181
|
if (isArray(rightValue)) {
|
|
172
182
|
// FIXME: Get unique values
|
|
173
183
|
if (!isArray(leftValue) || leftValue.length < rightValue.length) {
|
|
174
|
-
return false;
|
|
184
|
+
return negate(false, not);
|
|
175
185
|
}
|
|
176
|
-
return
|
|
186
|
+
return negate(
|
|
187
|
+
rightValue.every((value) => leftValue.includes(value)),
|
|
188
|
+
not,
|
|
189
|
+
);
|
|
177
190
|
}
|
|
178
191
|
if (isArray(leftValue) || leftValue.length < rightValue.length) {
|
|
179
|
-
return false;
|
|
192
|
+
return negate(false, not);
|
|
180
193
|
}
|
|
181
194
|
if (
|
|
182
195
|
(filter as FilterString<T>).options ||
|
|
@@ -192,12 +205,12 @@ export function testFilter<T>(
|
|
|
192
205
|
(filter as FilterString<T>).options,
|
|
193
206
|
) === 0
|
|
194
207
|
) {
|
|
195
|
-
return true;
|
|
208
|
+
return negate(true, not);
|
|
196
209
|
}
|
|
197
210
|
}
|
|
198
|
-
return false;
|
|
211
|
+
return negate(false, not);
|
|
199
212
|
}
|
|
200
|
-
return leftValue.includes?.(rightValue) ?? false;
|
|
213
|
+
return negate(leftValue.includes?.(rightValue) ?? false, not);
|
|
201
214
|
}
|
|
202
215
|
case "greaterThan": {
|
|
203
216
|
const rightValue = valueFromFilter(value, filter);
|
|
@@ -267,11 +280,13 @@ export function testFilter<T>(
|
|
|
267
280
|
}
|
|
268
281
|
return leftValue <= rightValue;
|
|
269
282
|
}
|
|
270
|
-
case "match":
|
|
283
|
+
case "match":
|
|
284
|
+
case "notMatch": {
|
|
285
|
+
const not = filter.operator[0] === "n";
|
|
271
286
|
const rightValue = valueFromFilter(value, filter);
|
|
272
287
|
const leftValue = get<T, any>(value, filter.field) as string | undefined;
|
|
273
288
|
if (leftValue === undefined) {
|
|
274
|
-
return false;
|
|
289
|
+
return negate(false, not);
|
|
275
290
|
}
|
|
276
291
|
if (filter[CACHE] === undefined) {
|
|
277
292
|
filter[CACHE] = new RegExp(
|
|
@@ -281,39 +296,47 @@ export function testFilter<T>(
|
|
|
281
296
|
}`,
|
|
282
297
|
);
|
|
283
298
|
}
|
|
284
|
-
return filter[CACHE].test(leftValue);
|
|
299
|
+
return negate(filter[CACHE].test(leftValue), not);
|
|
285
300
|
}
|
|
286
|
-
case "intersect":
|
|
301
|
+
case "intersect":
|
|
302
|
+
case "notIntersect": {
|
|
303
|
+
const not = filter.operator[0] === "n";
|
|
287
304
|
const rightValue = valueFromFilter(value, filter);
|
|
288
305
|
const leftValue = get<T, any>(value, filter.field);
|
|
289
306
|
if (leftValue == null) {
|
|
290
|
-
return false;
|
|
307
|
+
return negate(false, not);
|
|
291
308
|
}
|
|
292
309
|
if (isArray(leftValue)) {
|
|
293
|
-
return (
|
|
310
|
+
return negate(
|
|
294
311
|
isArray(rightValue) &&
|
|
295
|
-
|
|
312
|
+
rightValue.some((value) => leftValue.includes(value)),
|
|
313
|
+
not,
|
|
296
314
|
);
|
|
297
315
|
}
|
|
298
316
|
if (
|
|
299
317
|
(filter as FilterString<T>).options ||
|
|
300
318
|
(filter as FilterString<T>).locale
|
|
301
319
|
) {
|
|
302
|
-
return (
|
|
320
|
+
return negate(
|
|
303
321
|
leftValue !== undefined &&
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
322
|
+
(rightValue as string[]).some(
|
|
323
|
+
(value) =>
|
|
324
|
+
value.localeCompare(
|
|
325
|
+
leftValue as string,
|
|
326
|
+
(filter as FilterString<T>).locale,
|
|
327
|
+
(filter as FilterString<T>).options,
|
|
328
|
+
) === 0,
|
|
329
|
+
),
|
|
330
|
+
not,
|
|
312
331
|
);
|
|
313
332
|
}
|
|
314
|
-
return rightValue.includes(leftValue as string);
|
|
333
|
+
return negate(rightValue.includes(leftValue as string), not);
|
|
315
334
|
}
|
|
316
335
|
default:
|
|
317
336
|
throw new Error(`Unknown filter operator '${(filter as any).operator}'`);
|
|
318
337
|
}
|
|
319
338
|
}
|
|
339
|
+
|
|
340
|
+
function negate(value: boolean, condition: boolean) {
|
|
341
|
+
return condition ? !value : value;
|
|
342
|
+
}
|
package/lib/types/FilterArray.ts
CHANGED
|
@@ -9,6 +9,12 @@ import type { Value } from "./Value";
|
|
|
9
9
|
* - `intersect` requires at least one item of the value to be present in the array.
|
|
10
10
|
*/
|
|
11
11
|
export type FilterArray<T, P = any> = {
|
|
12
|
-
operator:
|
|
12
|
+
operator:
|
|
13
|
+
| "equal"
|
|
14
|
+
| "include"
|
|
15
|
+
| "intersect"
|
|
16
|
+
| "notEqual"
|
|
17
|
+
| "notInclude"
|
|
18
|
+
| "notIntersect";
|
|
13
19
|
field: FieldFiltered<T, P[]>;
|
|
14
20
|
} & Value<T, P[]>;
|
|
@@ -8,7 +8,7 @@ import type { Filter } from "./Filter";
|
|
|
8
8
|
* If `deep` is `true`, also captures all the descendants.
|
|
9
9
|
*/
|
|
10
10
|
export type FilterChildren<T> = {
|
|
11
|
-
operator: "children";
|
|
11
|
+
operator: "children" | "notChildren";
|
|
12
12
|
value?: Context<T> | string;
|
|
13
13
|
deep?: boolean;
|
|
14
14
|
[CACHE]?: Filter<T>;
|
package/lib/types/FilterField.ts
CHANGED
|
@@ -11,6 +11,10 @@ export type FilterNumber<T> = {
|
|
|
11
11
|
| "greaterThan"
|
|
12
12
|
| "greaterThanOrEqual"
|
|
13
13
|
| "lowerThan"
|
|
14
|
-
| "lowerThanOrEqual"
|
|
14
|
+
| "lowerThanOrEqual"
|
|
15
|
+
| "between"
|
|
16
|
+
| "notBetween"
|
|
17
|
+
| "betweenOrEqual"
|
|
18
|
+
| "notBetweenOrEqual";
|
|
15
19
|
field: FieldFiltered<T, number>;
|
|
16
20
|
} & Value<T, number>;
|
|
@@ -11,12 +11,18 @@ export type FilterString<T> = {
|
|
|
11
11
|
// FIXME: Redundant with `"not"` operator
|
|
12
12
|
| "notEqual"
|
|
13
13
|
| "startWith"
|
|
14
|
+
| "notStartWith"
|
|
14
15
|
| "endWith"
|
|
16
|
+
| "notEndWith"
|
|
15
17
|
| "include"
|
|
16
18
|
| "greaterThan"
|
|
17
19
|
| "greaterThanOrEqual"
|
|
18
20
|
| "lowerThan"
|
|
19
|
-
| "lowerThanOrEqual"
|
|
21
|
+
| "lowerThanOrEqual"
|
|
22
|
+
| "between"
|
|
23
|
+
| "notBetween"
|
|
24
|
+
| "betweenOrEqual"
|
|
25
|
+
| "notBetweenOrEqual";
|
|
20
26
|
field: FieldFiltered<T, string>;
|
|
21
27
|
options?: Intl.CollatorOptions;
|
|
22
28
|
locale?: Locale;
|
|
@@ -6,7 +6,7 @@ import type { Value } from "./Value";
|
|
|
6
6
|
* Checks if a given string field has any of the provided values.
|
|
7
7
|
*/
|
|
8
8
|
export type FilterStringIntersect<T> = {
|
|
9
|
-
operator: "intersect";
|
|
9
|
+
operator: "intersect" | "notIntersect";
|
|
10
10
|
field: FieldFiltered<T, string>;
|
|
11
11
|
options?: Intl.CollatorOptions;
|
|
12
12
|
locale?: Locale;
|
|
@@ -7,7 +7,7 @@ import type { Value } from "./Value";
|
|
|
7
7
|
* Checks if a given string field matches a given regular expression, the value being a raw regular expression string.
|
|
8
8
|
*/
|
|
9
9
|
export type FilterStringMatch<T> = {
|
|
10
|
-
operator: "match";
|
|
10
|
+
operator: "match" | "notMatch";
|
|
11
11
|
field: FieldFiltered<T, string>;
|
|
12
12
|
/**
|
|
13
13
|
* Regular expression options.
|