quetch 0.26.0 → 0.27.1
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/constants/FILTER_ANY.d.ts +3 -0
- package/dist/constants/FILTER_ANY.js +2 -0
- package/dist/constants/FILTER_ANY.js.map +1 -0
- package/dist/constants/FILTER_NONE.d.ts +3 -0
- package/dist/constants/FILTER_NONE.js +2 -0
- package/dist/constants/FILTER_NONE.js.map +1 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +2 -0
- package/dist/constants.js.map +1 -1
- package/dist/tools/filterChildren.d.ts +2 -2
- package/dist/tools/filterFromValue.d.ts +2 -2
- package/dist/tools/filterFromValue.js +14 -4
- package/dist/tools/filterFromValue.js.map +1 -1
- package/dist/tools/testFilter.js +5 -5
- package/dist/tools/testFilter.js.map +1 -1
- package/dist/types/FilterChildren.d.ts +2 -2
- package/dist/types/IntrinsicFilter.d.ts +7 -0
- package/dist/types/IntrinsicFilter.js +1 -0
- package/dist/types/IntrinsicFilter.js.map +1 -0
- package/dist/types/QuerySettings.d.ts +3 -5
- package/dist/types.d.ts +1 -0
- package/doc/README.md +3 -0
- package/doc/classes/RequestError.md +5 -5
- package/doc/functions/aggregate.md +1 -1
- package/doc/functions/branch.md +1 -1
- package/doc/functions/cache.md +1 -1
- package/doc/functions/combine.md +1 -1
- package/doc/functions/cork.md +1 -1
- package/doc/functions/defineCheckQuery.md +1 -1
- package/doc/functions/defineCustomFetch.md +1 -1
- package/doc/functions/defineGenericFetch.md +1 -1
- package/doc/functions/escapeRegex.md +1 -1
- package/doc/functions/fetchExternal.md +1 -1
- package/doc/functions/fetchLocal.md +1 -1
- package/doc/functions/fieldListFromFilter.md +1 -1
- package/doc/functions/filterChildren.md +3 -3
- package/doc/functions/filterFromValue.md +3 -3
- package/doc/functions/get.md +1 -1
- package/doc/functions/groupFilters.md +2 -2
- package/doc/functions/identity.md +1 -1
- package/doc/functions/isFilterGroup.md +1 -1
- package/doc/functions/log.md +1 -1
- package/doc/functions/normalizeOrder.md +1 -1
- package/doc/functions/queryItemList.md +1 -1
- package/doc/functions/retry.md +1 -1
- package/doc/functions/reverseOrder.md +1 -1
- package/doc/functions/sameField.md +1 -1
- package/doc/functions/sortItemList.md +1 -1
- package/doc/functions/splitPath.md +2 -2
- package/doc/functions/testFilter.md +1 -1
- package/doc/interfaces/CustomFetch.md +1 -1
- package/doc/type-aliases/AggregateFunction.md +1 -1
- package/doc/type-aliases/AggregateFunctionOperator.md +1 -1
- package/doc/type-aliases/CombineUnion.md +1 -1
- package/doc/type-aliases/Context.md +1 -1
- package/doc/type-aliases/CustomFieldAggregateMap.md +1 -1
- package/doc/type-aliases/CustomFieldMap.md +1 -1
- package/doc/type-aliases/Field.md +1 -1
- package/doc/type-aliases/FieldFiltered.md +1 -1
- package/doc/type-aliases/FieldFunction.md +1 -1
- package/doc/type-aliases/FieldFunctionCustom.md +1 -1
- package/doc/type-aliases/FieldFunctionFormatDate.md +1 -1
- package/doc/type-aliases/FieldFunctionReturn.md +1 -1
- package/doc/type-aliases/FieldKey.md +1 -1
- package/doc/type-aliases/FieldMap.md +1 -1
- package/doc/type-aliases/Filter.md +1 -1
- package/doc/type-aliases/FilterArray.md +1 -1
- package/doc/type-aliases/FilterBoolean.md +1 -1
- package/doc/type-aliases/FilterChildren.md +2 -2
- package/doc/type-aliases/FilterCustom.md +1 -1
- package/doc/type-aliases/FilterField.md +1 -1
- package/doc/type-aliases/FilterGroup.md +1 -1
- package/doc/type-aliases/FilterNumber.md +1 -1
- package/doc/type-aliases/FilterOperator.md +1 -1
- package/doc/type-aliases/FilterString.md +1 -1
- package/doc/type-aliases/FilterStringIntersect.md +1 -1
- package/doc/type-aliases/FilterStringMatch.md +1 -1
- package/doc/type-aliases/Get.md +1 -1
- package/doc/type-aliases/Group.md +1 -1
- package/doc/type-aliases/Handler.md +1 -1
- package/doc/type-aliases/Immutable.md +1 -1
- package/doc/type-aliases/Increment.md +1 -1
- package/doc/type-aliases/InjectCustomFields.md +1 -1
- package/doc/type-aliases/IntersectUnion.md +1 -1
- package/doc/type-aliases/IntrinsicFilter.md +19 -0
- package/doc/type-aliases/Item.md +1 -1
- package/doc/type-aliases/Join.md +1 -1
- package/doc/type-aliases/Key.md +1 -1
- package/doc/type-aliases/KeyFiltered.md +1 -1
- package/doc/type-aliases/KeyFromUnion.md +1 -1
- package/doc/type-aliases/Locale.md +1 -1
- package/doc/type-aliases/NextHandler.md +1 -1
- package/doc/type-aliases/Order.md +1 -1
- package/doc/type-aliases/OrderNormalized.md +1 -1
- package/doc/type-aliases/Parameters.md +1 -1
- package/doc/type-aliases/Path.md +1 -1
- package/doc/type-aliases/PathFiltered.md +1 -1
- package/doc/type-aliases/Primitive.md +1 -1
- package/doc/type-aliases/PrimitiveObject.md +1 -1
- package/doc/type-aliases/Query.md +1 -1
- package/doc/type-aliases/QueryAggregate.md +1 -1
- package/doc/type-aliases/QueryCreate.md +1 -1
- package/doc/type-aliases/QueryCreateMultiple.md +1 -1
- package/doc/type-aliases/QueryDelete.md +1 -1
- package/doc/type-aliases/QueryDeleteMultiple.md +1 -1
- package/doc/type-aliases/QueryMethod.md +1 -1
- package/doc/type-aliases/QueryRead.md +1 -1
- package/doc/type-aliases/QueryReadMultiple.md +1 -1
- package/doc/type-aliases/QuerySettings.md +4 -4
- package/doc/type-aliases/QueryUpdate.md +1 -1
- package/doc/type-aliases/QueryUpdateMultiple.md +1 -1
- package/doc/type-aliases/Result.md +1 -1
- package/doc/type-aliases/Store.md +1 -1
- package/doc/type-aliases/Value.md +1 -1
- package/doc/type-aliases/ValueMap.md +1 -1
- package/doc/variables/CACHE.md +1 -1
- package/doc/variables/FILTER_ANY.md +19 -0
- package/doc/variables/FILTER_NONE.md +19 -0
- package/doc/variables/SELF.md +1 -1
- package/lib/constants/FILTER_ANY.ts +1 -0
- package/lib/constants/FILTER_NONE.ts +1 -0
- package/lib/constants.ts +2 -0
- package/lib/tools/filterChildren.ts +2 -2
- package/lib/tools/filterFromValue.ts +19 -9
- package/lib/tools/testFilter.ts +13 -6
- package/lib/types/FilterChildren.ts +2 -2
- package/lib/types/IntrinsicFilter.ts +9 -0
- package/lib/types/QuerySettings.ts +3 -5
- package/lib/types.ts +1 -0
- package/package.json +1 -1
|
@@ -1,21 +1,31 @@
|
|
|
1
1
|
import { EMPTY_ARRAY } from "unchangeable";
|
|
2
2
|
|
|
3
3
|
import { SELF } from "../constants/SELF.js";
|
|
4
|
-
import type {
|
|
4
|
+
import type { IntrinsicFilter } from "../types.js";
|
|
5
5
|
|
|
6
6
|
const { entries } = Object;
|
|
7
7
|
|
|
8
|
-
export function filterFromValue<T>(value: T):
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
export function filterFromValue<T>(value: T): IntrinsicFilter<T> {
|
|
9
|
+
const criteriaValue = criteria(value);
|
|
10
|
+
switch (criteriaValue.length) {
|
|
11
|
+
case 0:
|
|
12
|
+
return {
|
|
13
|
+
operator: "any",
|
|
14
|
+
};
|
|
15
|
+
case 1:
|
|
16
|
+
return criteriaValue[0]!;
|
|
17
|
+
default:
|
|
18
|
+
return {
|
|
19
|
+
operator: "all",
|
|
20
|
+
value: criteria(value),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
13
23
|
}
|
|
14
24
|
|
|
15
25
|
function criteria<T>(
|
|
16
26
|
value: T,
|
|
17
27
|
path: readonly string[] = EMPTY_ARRAY,
|
|
18
|
-
): readonly
|
|
28
|
+
): readonly IntrinsicFilter<T>[] {
|
|
19
29
|
return entriesAndSelf(value).flatMap(([field, value]) => {
|
|
20
30
|
switch (typeof value) {
|
|
21
31
|
case "symbol":
|
|
@@ -36,7 +46,7 @@ function criteria<T>(
|
|
|
36
46
|
field: path.length === 0 ? field : [...path, field],
|
|
37
47
|
operator: "equal",
|
|
38
48
|
value,
|
|
39
|
-
} as
|
|
49
|
+
} as IntrinsicFilter<T>,
|
|
40
50
|
];
|
|
41
51
|
case "object": {
|
|
42
52
|
if (value == null) {
|
|
@@ -45,7 +55,7 @@ function criteria<T>(
|
|
|
45
55
|
field: path.length === 0 ? field : [...path, field],
|
|
46
56
|
operator: "equal",
|
|
47
57
|
value,
|
|
48
|
-
} as
|
|
58
|
+
} as IntrinsicFilter<T>,
|
|
49
59
|
];
|
|
50
60
|
}
|
|
51
61
|
return criteria<T>(value, [...path, field as string]);
|
package/lib/tools/testFilter.ts
CHANGED
|
@@ -38,7 +38,9 @@ export function testFilter<T>(
|
|
|
38
38
|
}
|
|
39
39
|
switch (filter.operator) {
|
|
40
40
|
case "all":
|
|
41
|
-
return filter.value.every((filter) =>
|
|
41
|
+
return filter.value.every((filter) =>
|
|
42
|
+
testFilter(filter, value, settings),
|
|
43
|
+
);
|
|
42
44
|
case "any": {
|
|
43
45
|
const length = filter.value?.length ?? 0;
|
|
44
46
|
const minimum = filter.minimum ?? (length > 0 ? 1 : 0);
|
|
@@ -47,10 +49,13 @@ export function testFilter<T>(
|
|
|
47
49
|
return true;
|
|
48
50
|
}
|
|
49
51
|
if (minimum === 1 && maximum >= length) {
|
|
50
|
-
return filter.value.some((filter) =>
|
|
52
|
+
return filter.value.some((filter) =>
|
|
53
|
+
testFilter(filter, value, settings),
|
|
54
|
+
);
|
|
51
55
|
}
|
|
52
56
|
const matched = filter.value.reduce(
|
|
53
|
-
(count, filter) =>
|
|
57
|
+
(count, filter) =>
|
|
58
|
+
count + (testFilter(filter, value, settings) ? 1 : 0),
|
|
54
59
|
0,
|
|
55
60
|
);
|
|
56
61
|
return matched >= minimum && matched <= maximum;
|
|
@@ -59,7 +64,9 @@ export function testFilter<T>(
|
|
|
59
64
|
if (filter.value === undefined || filter.value.length === 0) {
|
|
60
65
|
return false;
|
|
61
66
|
}
|
|
62
|
-
return filter.value.every(
|
|
67
|
+
return filter.value.every(
|
|
68
|
+
(filter) => !testFilter(filter, value, settings),
|
|
69
|
+
);
|
|
63
70
|
}
|
|
64
71
|
case "exist":
|
|
65
72
|
return get(value, filter.field as any) !== undefined;
|
|
@@ -127,7 +134,7 @@ export function testFilter<T>(
|
|
|
127
134
|
const {
|
|
128
135
|
pathField = "id" as FieldFiltered<T, string>,
|
|
129
136
|
pathFieldSeparator,
|
|
130
|
-
} = settings ||
|
|
137
|
+
} = settings || EMPTY_OBJECT;
|
|
131
138
|
filter[CACHE] = filterChildren(
|
|
132
139
|
filter.value as string,
|
|
133
140
|
pathField,
|
|
@@ -137,7 +144,7 @@ export function testFilter<T>(
|
|
|
137
144
|
}
|
|
138
145
|
}
|
|
139
146
|
}
|
|
140
|
-
return negate(testFilter(filter[CACHE], value), not);
|
|
147
|
+
return negate(testFilter(filter[CACHE], value, settings), not);
|
|
141
148
|
}
|
|
142
149
|
case "custom": {
|
|
143
150
|
return filter.value(value);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CACHE } from "../constants/CACHE.js";
|
|
2
2
|
|
|
3
3
|
import type { Context } from "./Context";
|
|
4
|
-
import type {
|
|
4
|
+
import type { IntrinsicFilter } from "./IntrinsicFilter.js";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Matches the direct children of a specified `value` item.
|
|
@@ -11,5 +11,5 @@ export type FilterChildren<T> = {
|
|
|
11
11
|
operator: "children" | "notChildren";
|
|
12
12
|
value?: Context<T> | string;
|
|
13
13
|
deep?: boolean;
|
|
14
|
-
[CACHE]?:
|
|
14
|
+
[CACHE]?: IntrinsicFilter<T>;
|
|
15
15
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Filter } from "./Filter";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Filter that does not rely on query settings, and thus can be evaluated directly on the items.
|
|
5
|
+
*/
|
|
6
|
+
export type IntrinsicFilter<T> = Exclude<
|
|
7
|
+
Filter<T>,
|
|
8
|
+
{ operator: "children" | "notChildren" | "is" | "notIs" }
|
|
9
|
+
>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FieldFiltered } from "./FieldFiltered";
|
|
2
|
-
import type { Filter } from "./Filter";
|
|
3
2
|
import type { FilterChildren } from "./FilterChildren";
|
|
3
|
+
import type { IntrinsicFilter } from "./IntrinsicFilter";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Settings to use when doing a query.
|
|
@@ -23,14 +23,12 @@ export type QuerySettings<T> = {
|
|
|
23
23
|
*/
|
|
24
24
|
pathFieldSeparator?: string;
|
|
25
25
|
/**
|
|
26
|
-
* Returns a filter that captures the items expressed by the provided `FilterChildren`. The return filter cannot use filters of type `FilterChildren`.
|
|
26
|
+
* Returns a filter that captures the items expressed by the provided `FilterChildren`. The return filter cannot use filters of type `FilterChildren` or `FilterContext`.
|
|
27
27
|
*
|
|
28
28
|
* @param filter The provided `FilterChildren` to express.
|
|
29
29
|
* @returns A filter that captures the items expressed by the provided `FilterChildren`.
|
|
30
30
|
*/
|
|
31
|
-
transformFilterChildren?: (
|
|
32
|
-
filter: FilterChildren<T>,
|
|
33
|
-
) => Exclude<Filter<T>, { operator: "children" | "notChildren" }>;
|
|
31
|
+
transformFilterChildren?: (filter: FilterChildren<T>) => IntrinsicFilter<T>;
|
|
34
32
|
/**
|
|
35
33
|
* Abort signal to abort the query.
|
|
36
34
|
*/
|
package/lib/types.ts
CHANGED
|
@@ -33,6 +33,7 @@ export type { Immutable } from "./types/Immutable";
|
|
|
33
33
|
export type { Increment } from "./types/Increment";
|
|
34
34
|
export type { InjectCustomFields } from "./types/InjectCustomFields";
|
|
35
35
|
export type { IntersectUnion } from "./types/IntersectUnion";
|
|
36
|
+
export type { IntrinsicFilter } from "./types/IntrinsicFilter";
|
|
36
37
|
export type { Item } from "./types/Item";
|
|
37
38
|
export type { Join } from "./types/Join";
|
|
38
39
|
export type { Key } from "./types/Key";
|