quetch 0.13.0 → 0.15.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/filterChildren.d.ts +2 -2
- package/dist/tools/filterChildren.js.map +1 -1
- package/dist/tools/get.d.ts +14 -0
- package/dist/tools/get.js +36 -0
- package/dist/tools/get.js.map +1 -0
- package/dist/tools/queryItemList.js +4 -4
- package/dist/tools/queryItemList.js.map +1 -1
- package/dist/tools/{filterItem.d.ts → testFilter.d.ts} +2 -2
- package/dist/tools/testFilter.js +214 -0
- package/dist/tools/testFilter.js.map +1 -0
- package/dist/tools.d.ts +2 -1
- package/dist/tools.js +2 -1
- package/dist/tools.js.map +1 -1
- package/dist/types/Field.d.ts +2 -0
- package/dist/types/Field.js +2 -0
- package/dist/types/Field.js.map +1 -0
- package/dist/types/FieldFiltered.d.ts +3 -0
- package/dist/types/FieldFiltered.js +2 -0
- package/dist/types/FieldFiltered.js.map +1 -0
- package/dist/types/FieldFunctionFormatDate.d.ts +2 -2
- package/dist/types/FilterArray.d.ts +4 -4
- package/dist/types/FilterBoolean.d.ts +4 -4
- package/dist/types/FilterChildren.d.ts +1 -1
- package/dist/types/FilterField.d.ts +3 -2
- package/dist/types/FilterNumber.d.ts +4 -4
- package/dist/types/FilterString.d.ts +4 -4
- package/dist/types/FilterStringIntersect.d.ts +4 -4
- package/dist/types/FilterStringMatch.d.ts +5 -8
- package/dist/types/Get.d.ts +2 -3
- package/dist/types/{FilterKeys.d.ts → KeyFiltered.d.ts} +1 -1
- package/dist/types/KeyFiltered.js +2 -0
- package/dist/types/KeyFiltered.js.map +1 -0
- package/dist/types/Path.d.ts +3 -0
- package/dist/types/Path.js +2 -0
- package/dist/types/Path.js.map +1 -0
- package/dist/types/PathFiltered.d.ts +3 -0
- package/dist/types/PathFiltered.js +2 -0
- package/dist/types/PathFiltered.js.map +1 -0
- package/dist/types/QuerySettings.d.ts +2 -2
- package/dist/types/Value.d.ts +15 -0
- package/dist/types/Value.js +2 -0
- package/dist/types/Value.js.map +1 -0
- package/dist/types.d.ts +6 -1
- package/doc/README.md +396 -290
- package/doc/classes/RequestError.md +12 -8
- package/doc/interfaces/CustomFetch.md +5 -5
- package/lib/tools/filterChildren.ts +2 -2
- package/lib/tools/get.test.ts +23 -0
- package/lib/tools/get.ts +57 -0
- package/lib/tools/queryItemList.ts +4 -4
- package/lib/tools/{filterItem.test.ts → testFilter.test.ts} +44 -38
- package/lib/tools/testFilter.ts +320 -0
- package/lib/tools.ts +2 -1
- package/lib/types/Field.ts +3 -0
- package/lib/types/FieldFiltered.ts +6 -0
- package/lib/types/FieldFunctionFormatDate.ts +2 -2
- package/lib/types/FilterArray.ts +4 -4
- package/lib/types/FilterBoolean.ts +4 -4
- package/lib/types/FilterChildren.ts +1 -1
- package/lib/types/FilterField.ts +4 -2
- package/lib/types/FilterNumber.ts +4 -4
- package/lib/types/FilterString.ts +4 -4
- package/lib/types/FilterStringIntersect.ts +4 -4
- package/lib/types/FilterStringMatch.ts +5 -8
- package/lib/types/Get.ts +9 -5
- package/lib/types/{FilterKeys.ts → KeyFiltered.ts} +1 -1
- package/lib/types/Path.ts +7 -0
- package/lib/types/PathFiltered.ts +9 -0
- package/lib/types/QuerySettings.ts +2 -2
- package/lib/types/Value.ts +18 -0
- package/lib/types.ts +6 -1
- package/package.json +9 -7
- package/dist/tools/filterItem.js +0 -197
- package/dist/tools/filterItem.js.map +0 -1
- package/dist/types/FilterKeys.js +0 -2
- package/dist/types/FilterKeys.js.map +0 -1
- package/lib/tools/filterItem.ts +0 -299
|
@@ -27,7 +27,7 @@ Error to be thrown in case there is an issue with the query call. Only instances
|
|
|
27
27
|
|
|
28
28
|
### constructor
|
|
29
29
|
|
|
30
|
-
• **new RequestError**(`message`, `status`, `query?`, `request?`, `response?`)
|
|
30
|
+
• **new RequestError**(`message`, `status`, `query?`, `request?`, `response?`): [`RequestError`](RequestError.md)
|
|
31
31
|
|
|
32
32
|
#### Parameters
|
|
33
33
|
|
|
@@ -35,27 +35,31 @@ Error to be thrown in case there is an issue with the query call. Only instances
|
|
|
35
35
|
| :------ | :------ |
|
|
36
36
|
| `message` | `string` |
|
|
37
37
|
| `status` | `number` |
|
|
38
|
-
| `query?` | [`Query`](../README.md#query)
|
|
38
|
+
| `query?` | [`Query`](../README.md#query)\<`any`\> |
|
|
39
39
|
| `request?` | `Request` |
|
|
40
40
|
| `response?` | `Response` |
|
|
41
41
|
|
|
42
|
+
#### Returns
|
|
43
|
+
|
|
44
|
+
[`RequestError`](RequestError.md)
|
|
45
|
+
|
|
42
46
|
#### Overrides
|
|
43
47
|
|
|
44
48
|
Error.constructor
|
|
45
49
|
|
|
46
50
|
#### Defined in
|
|
47
51
|
|
|
48
|
-
[lib/errors/RequestError.ts:7](https://github.com/nevoland/quetch/blob/
|
|
52
|
+
[lib/errors/RequestError.ts:7](https://github.com/nevoland/quetch/blob/b46dff0534f861059aba3484d2e1d047d841b31f/lib/errors/RequestError.ts#L7)
|
|
49
53
|
|
|
50
54
|
## Properties
|
|
51
55
|
|
|
52
56
|
### query
|
|
53
57
|
|
|
54
|
-
• `Optional` **query**: [`Query`](../README.md#query)
|
|
58
|
+
• `Optional` **query**: [`Query`](../README.md#query)\<`any`\>
|
|
55
59
|
|
|
56
60
|
#### Defined in
|
|
57
61
|
|
|
58
|
-
[lib/errors/RequestError.ts:10](https://github.com/nevoland/quetch/blob/
|
|
62
|
+
[lib/errors/RequestError.ts:10](https://github.com/nevoland/quetch/blob/b46dff0534f861059aba3484d2e1d047d841b31f/lib/errors/RequestError.ts#L10)
|
|
59
63
|
|
|
60
64
|
___
|
|
61
65
|
|
|
@@ -65,7 +69,7 @@ ___
|
|
|
65
69
|
|
|
66
70
|
#### Defined in
|
|
67
71
|
|
|
68
|
-
[lib/errors/RequestError.ts:11](https://github.com/nevoland/quetch/blob/
|
|
72
|
+
[lib/errors/RequestError.ts:11](https://github.com/nevoland/quetch/blob/b46dff0534f861059aba3484d2e1d047d841b31f/lib/errors/RequestError.ts#L11)
|
|
69
73
|
|
|
70
74
|
___
|
|
71
75
|
|
|
@@ -75,7 +79,7 @@ ___
|
|
|
75
79
|
|
|
76
80
|
#### Defined in
|
|
77
81
|
|
|
78
|
-
[lib/errors/RequestError.ts:12](https://github.com/nevoland/quetch/blob/
|
|
82
|
+
[lib/errors/RequestError.ts:12](https://github.com/nevoland/quetch/blob/b46dff0534f861059aba3484d2e1d047d841b31f/lib/errors/RequestError.ts#L12)
|
|
79
83
|
|
|
80
84
|
___
|
|
81
85
|
|
|
@@ -85,4 +89,4 @@ ___
|
|
|
85
89
|
|
|
86
90
|
#### Defined in
|
|
87
91
|
|
|
88
|
-
[lib/errors/RequestError.ts:9](https://github.com/nevoland/quetch/blob/
|
|
92
|
+
[lib/errors/RequestError.ts:9](https://github.com/nevoland/quetch/blob/b46dff0534f861059aba3484d2e1d047d841b31f/lib/errors/RequestError.ts#L9)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[quetch](../README.md) / CustomFetch
|
|
2
2
|
|
|
3
|
-
# Interface: CustomFetch
|
|
3
|
+
# Interface: CustomFetch\<T\>
|
|
4
4
|
|
|
5
5
|
## Type parameters
|
|
6
6
|
|
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
|
|
13
13
|
### CustomFetch
|
|
14
14
|
|
|
15
|
-
▸ **CustomFetch
|
|
15
|
+
▸ **CustomFetch**\<`Q`\>(`query`): `Promise`\<[`Result`](../README.md#result)\<`T`, `Q`\>\>
|
|
16
16
|
|
|
17
17
|
#### Type parameters
|
|
18
18
|
|
|
19
19
|
| Name | Type |
|
|
20
20
|
| :------ | :------ |
|
|
21
|
-
| `Q` | extends [`Query`](../README.md#query)
|
|
21
|
+
| `Q` | extends [`Query`](../README.md#query)\<`T`\> |
|
|
22
22
|
|
|
23
23
|
#### Parameters
|
|
24
24
|
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
|
|
29
29
|
#### Returns
|
|
30
30
|
|
|
31
|
-
`Promise
|
|
31
|
+
`Promise`\<[`Result`](../README.md#result)\<`T`, `Q`\>\>
|
|
32
32
|
|
|
33
33
|
#### Defined in
|
|
34
34
|
|
|
35
|
-
[lib/types/CustomFetch.ts:5](https://github.com/nevoland/quetch/blob/
|
|
35
|
+
[lib/types/CustomFetch.ts:5](https://github.com/nevoland/quetch/blob/b46dff0534f861059aba3484d2e1d047d841b31f/lib/types/CustomFetch.ts#L5)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { FieldFiltered, Filter } from "../types.ts";
|
|
2
2
|
|
|
3
3
|
import { escapeRegex } from "./escapeRegex.js";
|
|
4
4
|
|
|
5
5
|
export function filterChildren<T extends object>(
|
|
6
6
|
parentPath: string,
|
|
7
|
-
pathFieldKey:
|
|
7
|
+
pathFieldKey: FieldFiltered<T, string>,
|
|
8
8
|
deep = false,
|
|
9
9
|
pathSeparator = "/",
|
|
10
10
|
): Filter<T> {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { get } from "./get.js";
|
|
4
|
+
|
|
5
|
+
test("gets properties", () => {
|
|
6
|
+
const value = {
|
|
7
|
+
a: { b: 3, c: true, d: { e: [1, 2, { f: "test" }] } },
|
|
8
|
+
} as const;
|
|
9
|
+
expect(get(value, ["a", "c"])).toBe(value.a.c);
|
|
10
|
+
expect(get(value, ["a", "d", "e", 2, "f"])).toBe(value.a.d.e[2].f);
|
|
11
|
+
expect(get(value, ["a"])).toBe(value.a);
|
|
12
|
+
expect(get(value, "a")).toBe(value.a);
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
expect(get(value, "z")).toBeUndefined();
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
expect(get(value, ["y", "z"])).toBeUndefined();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("returns whole value if no path specified", () => {
|
|
20
|
+
const value = { a: { b: 3, c: true } };
|
|
21
|
+
expect(get(value)).toBe(value);
|
|
22
|
+
expect(get(value, undefined)).toBe(value);
|
|
23
|
+
});
|
package/lib/tools/get.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Path } from "../types";
|
|
2
|
+
|
|
3
|
+
type Get<T, P> = [P] extends [[infer K, ...infer R]]
|
|
4
|
+
? K extends keyof T
|
|
5
|
+
? R extends Path<T[K]>
|
|
6
|
+
? Get<T[K], R>
|
|
7
|
+
: T[K]
|
|
8
|
+
: never
|
|
9
|
+
: [P] extends [keyof T]
|
|
10
|
+
? T[P]
|
|
11
|
+
: T;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Gets the property value of the given `value` at the specified `path` (an array of object property names or array indexes).
|
|
15
|
+
* If the `path` is undefined, returns the `value` itself.
|
|
16
|
+
* If the `path` is a string, it is considered as a path with one item.
|
|
17
|
+
* If the `path` leads to an unknown property, returns `undefined`.
|
|
18
|
+
*
|
|
19
|
+
* @param value The value from which to get the property value.
|
|
20
|
+
* @param path The path leading to the property value or a property name or `undefined`.
|
|
21
|
+
* @returns The property value found at the given path, or `undefined` if it cannot be found.
|
|
22
|
+
*/
|
|
23
|
+
export function get<T, P extends keyof T | Path<T>>(
|
|
24
|
+
value: T,
|
|
25
|
+
path?: P,
|
|
26
|
+
): Get<T, P> {
|
|
27
|
+
if (path === undefined) {
|
|
28
|
+
return value as any;
|
|
29
|
+
}
|
|
30
|
+
switch (typeof path) {
|
|
31
|
+
case "string":
|
|
32
|
+
case "number":
|
|
33
|
+
case "symbol":
|
|
34
|
+
return (value as any)?.[path];
|
|
35
|
+
default: {
|
|
36
|
+
switch (path.length) {
|
|
37
|
+
case 1:
|
|
38
|
+
return (value as any)?.[path[0] as any];
|
|
39
|
+
case 2:
|
|
40
|
+
return (value as any)?.[path[0] as any]?.[path[1] as any];
|
|
41
|
+
case 3:
|
|
42
|
+
return (value as any)?.[path[0] as any]?.[path[1] as any]?.[
|
|
43
|
+
path[2] as any
|
|
44
|
+
];
|
|
45
|
+
case 4:
|
|
46
|
+
return (value as any)?.[path[0] as any]?.[path[1] as any]?.[
|
|
47
|
+
path[2] as any
|
|
48
|
+
]?.[path[3] as any];
|
|
49
|
+
default:
|
|
50
|
+
return path.reduce(
|
|
51
|
+
(value, key) => (value as any)?.[key],
|
|
52
|
+
value,
|
|
53
|
+
) as any;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -10,8 +10,8 @@ import type {
|
|
|
10
10
|
} from "../types.js";
|
|
11
11
|
|
|
12
12
|
import { filterFromContext } from "./filterFromContext.js";
|
|
13
|
-
import { filterItem } from "./filterItem.js";
|
|
14
13
|
import { sortItemList } from "./sortItemList.js";
|
|
14
|
+
import { testFilter } from "./testFilter.js";
|
|
15
15
|
|
|
16
16
|
function mergeContextAndFilter<T extends object>(
|
|
17
17
|
context?: Context<T>,
|
|
@@ -56,7 +56,7 @@ function queryItemList<T extends object, const Q extends Query<T>>(
|
|
|
56
56
|
filter as Filter<T>,
|
|
57
57
|
);
|
|
58
58
|
result = data.filter((item) =>
|
|
59
|
-
|
|
59
|
+
testFilter(normalizedFilter, item, query.settings),
|
|
60
60
|
);
|
|
61
61
|
}
|
|
62
62
|
// Sort
|
|
@@ -75,7 +75,7 @@ function queryItemList<T extends object, const Q extends Query<T>>(
|
|
|
75
75
|
filter as Filter<T>,
|
|
76
76
|
);
|
|
77
77
|
const result = data.find((item) =>
|
|
78
|
-
|
|
78
|
+
testFilter(normalizedFilter, item, query.settings),
|
|
79
79
|
);
|
|
80
80
|
if (result === undefined) {
|
|
81
81
|
throw new RequestError("Not found", 404, query as Query<any>);
|
|
@@ -94,7 +94,7 @@ function queryItemList<T extends object, const Q extends Query<T>>(
|
|
|
94
94
|
filter as Filter<T>,
|
|
95
95
|
);
|
|
96
96
|
return data.reduce((result, item) => {
|
|
97
|
-
if (
|
|
97
|
+
if (testFilter(normalizedFilter, item, query.settings)) {
|
|
98
98
|
return result + 1;
|
|
99
99
|
}
|
|
100
100
|
return result;
|
|
@@ -3,11 +3,11 @@ import { expect, test } from "vitest";
|
|
|
3
3
|
import { SymbolCache } from "../constants.js";
|
|
4
4
|
import type { FilterChildren } from "../types.js";
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { testFilter } from "./testFilter.js";
|
|
7
7
|
|
|
8
8
|
test("tests filter lists", () => {
|
|
9
9
|
expect(
|
|
10
|
-
|
|
10
|
+
testFilter(
|
|
11
11
|
{
|
|
12
12
|
operator: "all",
|
|
13
13
|
value: [
|
|
@@ -19,7 +19,7 @@ test("tests filter lists", () => {
|
|
|
19
19
|
),
|
|
20
20
|
).toBe(true);
|
|
21
21
|
expect(
|
|
22
|
-
|
|
22
|
+
testFilter(
|
|
23
23
|
{
|
|
24
24
|
operator: "all",
|
|
25
25
|
value: [
|
|
@@ -31,7 +31,7 @@ test("tests filter lists", () => {
|
|
|
31
31
|
),
|
|
32
32
|
).toBe(false);
|
|
33
33
|
expect(
|
|
34
|
-
|
|
34
|
+
testFilter(
|
|
35
35
|
{
|
|
36
36
|
operator: "all",
|
|
37
37
|
value: [],
|
|
@@ -40,7 +40,7 @@ test("tests filter lists", () => {
|
|
|
40
40
|
),
|
|
41
41
|
).toBe(true);
|
|
42
42
|
expect(
|
|
43
|
-
|
|
43
|
+
testFilter(
|
|
44
44
|
{
|
|
45
45
|
operator: "any",
|
|
46
46
|
},
|
|
@@ -48,7 +48,7 @@ test("tests filter lists", () => {
|
|
|
48
48
|
),
|
|
49
49
|
).toBe(true);
|
|
50
50
|
expect(
|
|
51
|
-
|
|
51
|
+
testFilter(
|
|
52
52
|
{
|
|
53
53
|
operator: "none",
|
|
54
54
|
},
|
|
@@ -56,7 +56,7 @@ test("tests filter lists", () => {
|
|
|
56
56
|
),
|
|
57
57
|
).toBe(false);
|
|
58
58
|
expect(
|
|
59
|
-
|
|
59
|
+
testFilter(
|
|
60
60
|
{
|
|
61
61
|
operator: "any",
|
|
62
62
|
value: [
|
|
@@ -68,7 +68,7 @@ test("tests filter lists", () => {
|
|
|
68
68
|
),
|
|
69
69
|
).toBe(true);
|
|
70
70
|
expect(
|
|
71
|
-
|
|
71
|
+
testFilter(
|
|
72
72
|
{
|
|
73
73
|
operator: "none",
|
|
74
74
|
value: [
|
|
@@ -80,7 +80,7 @@ test("tests filter lists", () => {
|
|
|
80
80
|
),
|
|
81
81
|
).toBe(true);
|
|
82
82
|
expect(
|
|
83
|
-
|
|
83
|
+
testFilter(
|
|
84
84
|
{
|
|
85
85
|
operator: "none",
|
|
86
86
|
value: [
|
|
@@ -95,10 +95,16 @@ test("tests filter lists", () => {
|
|
|
95
95
|
|
|
96
96
|
test("tests filter on string values", () => {
|
|
97
97
|
expect(
|
|
98
|
-
|
|
98
|
+
testFilter({ field: "a", operator: "equal", value: "foo" }, { a: "foo" }),
|
|
99
99
|
).toBe(true);
|
|
100
100
|
expect(
|
|
101
|
-
|
|
101
|
+
testFilter(
|
|
102
|
+
{ field: "a", operator: "equal", valueField: "b" },
|
|
103
|
+
{ a: "foo", b: "foo" },
|
|
104
|
+
),
|
|
105
|
+
).toBe(true);
|
|
106
|
+
expect(
|
|
107
|
+
testFilter(
|
|
102
108
|
{
|
|
103
109
|
field: "a",
|
|
104
110
|
operator: "equal",
|
|
@@ -109,10 +115,10 @@ test("tests filter on string values", () => {
|
|
|
109
115
|
),
|
|
110
116
|
).toBe(true);
|
|
111
117
|
expect(
|
|
112
|
-
|
|
118
|
+
testFilter({ field: "a", operator: "equal", value: "bar" }, { a: "foo" }),
|
|
113
119
|
).toBe(false);
|
|
114
120
|
expect(
|
|
115
|
-
|
|
121
|
+
testFilter(
|
|
116
122
|
{
|
|
117
123
|
field: "a",
|
|
118
124
|
operator: "equal",
|
|
@@ -123,19 +129,19 @@ test("tests filter on string values", () => {
|
|
|
123
129
|
),
|
|
124
130
|
).toBe(false);
|
|
125
131
|
expect(
|
|
126
|
-
|
|
132
|
+
testFilter(
|
|
127
133
|
{ field: "a", operator: "notEqual", value: "bar" },
|
|
128
134
|
{ a: "foo" },
|
|
129
135
|
),
|
|
130
136
|
).toBe(true);
|
|
131
137
|
expect(
|
|
132
|
-
|
|
138
|
+
testFilter(
|
|
133
139
|
{ field: "a", operator: "include", value: "bar" },
|
|
134
140
|
{ a: "foobar" },
|
|
135
141
|
),
|
|
136
142
|
).toBe(true);
|
|
137
143
|
expect(
|
|
138
|
-
|
|
144
|
+
testFilter(
|
|
139
145
|
{
|
|
140
146
|
field: "a",
|
|
141
147
|
operator: "include",
|
|
@@ -146,13 +152,13 @@ test("tests filter on string values", () => {
|
|
|
146
152
|
),
|
|
147
153
|
).toBe(true);
|
|
148
154
|
expect(
|
|
149
|
-
|
|
155
|
+
testFilter(
|
|
150
156
|
{ field: "a", operator: "intersect", value: ["foo", "bar", "foobar"] },
|
|
151
157
|
{ a: "foobar" },
|
|
152
158
|
),
|
|
153
159
|
).toBe(true);
|
|
154
160
|
expect(
|
|
155
|
-
|
|
161
|
+
testFilter(
|
|
156
162
|
{
|
|
157
163
|
field: "a",
|
|
158
164
|
operator: "intersect",
|
|
@@ -163,13 +169,13 @@ test("tests filter on string values", () => {
|
|
|
163
169
|
),
|
|
164
170
|
).toBe(true);
|
|
165
171
|
expect(
|
|
166
|
-
|
|
172
|
+
testFilter(
|
|
167
173
|
{ field: "a", operator: "intersect", value: ["foo", "bar"] },
|
|
168
174
|
{ a: "foobar" },
|
|
169
175
|
),
|
|
170
176
|
).toBe(false);
|
|
171
177
|
expect(
|
|
172
|
-
|
|
178
|
+
testFilter(
|
|
173
179
|
{
|
|
174
180
|
field: "a",
|
|
175
181
|
operator: "match",
|
|
@@ -180,7 +186,7 @@ test("tests filter on string values", () => {
|
|
|
180
186
|
),
|
|
181
187
|
).toBe(true);
|
|
182
188
|
expect(
|
|
183
|
-
|
|
189
|
+
testFilter(
|
|
184
190
|
{
|
|
185
191
|
field: "a",
|
|
186
192
|
operator: "match",
|
|
@@ -194,25 +200,25 @@ test("tests filter on string values", () => {
|
|
|
194
200
|
|
|
195
201
|
test("tests filter on number values", () => {
|
|
196
202
|
expect(
|
|
197
|
-
|
|
203
|
+
testFilter({ field: "a", operator: "equal", value: 1 }, { a: 1 }),
|
|
198
204
|
).toBe(true);
|
|
199
205
|
expect(
|
|
200
|
-
|
|
206
|
+
testFilter({ field: "a", operator: "notEqual", value: 2 }, { a: 1 }),
|
|
201
207
|
).toBe(true);
|
|
202
208
|
expect(
|
|
203
|
-
|
|
209
|
+
testFilter({ field: "a", operator: "greaterThan", value: 0 }, { a: 1 }),
|
|
204
210
|
).toBe(true);
|
|
205
211
|
expect(
|
|
206
|
-
|
|
212
|
+
testFilter(
|
|
207
213
|
{ field: "a", operator: "greaterThanOrEqual", value: 1 },
|
|
208
214
|
{ a: 1 },
|
|
209
215
|
),
|
|
210
216
|
).toBe(true);
|
|
211
217
|
expect(
|
|
212
|
-
|
|
218
|
+
testFilter({ field: "a", operator: "lowerThan", value: 2 }, { a: 1 }),
|
|
213
219
|
).toBe(true);
|
|
214
220
|
expect(
|
|
215
|
-
|
|
221
|
+
testFilter(
|
|
216
222
|
{ field: "a", operator: "lowerThanOrEqual", value: 1 },
|
|
217
223
|
{ a: 1 },
|
|
218
224
|
),
|
|
@@ -221,28 +227,28 @@ test("tests filter on number values", () => {
|
|
|
221
227
|
|
|
222
228
|
test("tests filter on array values", () => {
|
|
223
229
|
expect(
|
|
224
|
-
|
|
230
|
+
testFilter({ field: "a", operator: "equal", value: [2, 1] }, { a: [1, 2] }),
|
|
225
231
|
).toBe(true);
|
|
226
232
|
expect(
|
|
227
|
-
|
|
233
|
+
testFilter({ field: "a", operator: "equal", value: [2] }, { a: [1, 2] }),
|
|
228
234
|
).toBe(false);
|
|
229
235
|
expect(
|
|
230
|
-
|
|
236
|
+
testFilter({ field: "a", operator: "include", value: [1] }, { a: [1, 2] }),
|
|
231
237
|
).toBe(true);
|
|
232
238
|
expect(
|
|
233
|
-
|
|
239
|
+
testFilter(
|
|
234
240
|
{ field: "a", operator: "include", value: [2, 3] },
|
|
235
241
|
{ a: [1, 2] },
|
|
236
242
|
),
|
|
237
243
|
).toBe(false);
|
|
238
244
|
expect(
|
|
239
|
-
|
|
245
|
+
testFilter(
|
|
240
246
|
{ field: "a", operator: "intersect", value: [2, 3] },
|
|
241
247
|
{ a: [1, 2] },
|
|
242
248
|
),
|
|
243
249
|
).toBe(true);
|
|
244
250
|
expect(
|
|
245
|
-
|
|
251
|
+
testFilter(
|
|
246
252
|
{ field: "a", operator: "intersect", value: [3, 4] },
|
|
247
253
|
{ a: [1, 2] },
|
|
248
254
|
),
|
|
@@ -250,11 +256,11 @@ test("tests filter on array values", () => {
|
|
|
250
256
|
});
|
|
251
257
|
|
|
252
258
|
test("tests filter with children predicates", () => {
|
|
253
|
-
expect(
|
|
259
|
+
expect(testFilter({ operator: "children", value: "a" }, { id: "a/b" })).toBe(
|
|
254
260
|
true,
|
|
255
261
|
);
|
|
256
262
|
expect(
|
|
257
|
-
|
|
263
|
+
testFilter(
|
|
258
264
|
{ operator: "children", value: ".a" },
|
|
259
265
|
{ path: ".a.b" },
|
|
260
266
|
{
|
|
@@ -268,7 +274,7 @@ test("tests filter with children predicates", () => {
|
|
|
268
274
|
value: "a",
|
|
269
275
|
};
|
|
270
276
|
expect(
|
|
271
|
-
|
|
277
|
+
testFilter(
|
|
272
278
|
filterChildren,
|
|
273
279
|
{ path: ".a.b" },
|
|
274
280
|
{
|
|
@@ -283,11 +289,11 @@ test("tests filter with children predicates", () => {
|
|
|
283
289
|
),
|
|
284
290
|
).toBe(true);
|
|
285
291
|
expect(filterChildren[SymbolCache]).toBeDefined();
|
|
286
|
-
expect(
|
|
292
|
+
expect(testFilter({ operator: "children", value: "b" }, { id: "a/b" })).toBe(
|
|
287
293
|
false,
|
|
288
294
|
);
|
|
289
295
|
expect(
|
|
290
|
-
|
|
296
|
+
testFilter(
|
|
291
297
|
{ operator: "children", value: "ba" },
|
|
292
298
|
{ path: ".a.b" },
|
|
293
299
|
{
|