quetch 0.33.0 → 0.33.2
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/COLLATOR_DEFAULT.d.ts +1 -0
- package/dist/constants/COLLATOR_DEFAULT.js +5 -0
- package/dist/constants/COLLATOR_DEFAULT.js.map +1 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/constants.js.map +1 -1
- package/dist/tools/comparatorFieldValues.d.ts +1 -1
- package/dist/tools/comparatorFieldValues.js +24 -3
- package/dist/tools/comparatorFieldValues.js.map +1 -1
- package/dist/types/CombineUnion.d.ts +1 -1
- package/dist/types/Context.d.ts +2 -2
- package/dist/types/FieldFiltered.d.ts +3 -0
- package/dist/types/FieldKey.d.ts +4 -1
- package/dist/types/NormalizedPathFieldSettings.d.ts +4 -0
- package/dist/types/Path.d.ts +4 -1
- package/dist/types/PathFiltered.d.ts +3 -0
- package/dist/types/Primitive.d.ts +3 -0
- package/dist/types/Result.d.ts +2 -2
- package/doc/README.md +1 -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/comparatorFieldValues.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/fieldListUnion.md +1 -1
- package/doc/functions/filterChildren.md +1 -1
- package/doc/functions/filterFromValue.md +1 -1
- package/doc/functions/get.md +1 -1
- package/doc/functions/groupFilters.md +1 -1
- package/doc/functions/identity.md +1 -1
- package/doc/functions/intrinsicFilter.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/querySettings.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/functions/transformerFilterChildren.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 +2 -2
- package/doc/type-aliases/Context.md +2 -2
- package/doc/type-aliases/CustomFieldAggregateMap.md +1 -1
- package/doc/type-aliases/CustomFieldMap.md +1 -1
- package/doc/type-aliases/Decrement.md +1 -1
- package/doc/type-aliases/DepthLimit.md +1 -1
- package/doc/type-aliases/Field.md +1 -1
- package/doc/type-aliases/FieldFiltered.md +3 -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 +4 -2
- 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 +1 -1
- 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/FilterWithField.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/InjectCustomFields.md +1 -1
- package/doc/type-aliases/IntersectUnion.md +1 -1
- package/doc/type-aliases/IntrinsicFilter.md +1 -1
- 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/NormalizedPathFieldSettings.md +7 -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 +4 -2
- package/doc/type-aliases/PathFiltered.md +3 -1
- package/doc/type-aliases/Prettify.md +1 -1
- package/doc/type-aliases/Primitive.md +3 -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 +7 -1
- 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 +2 -2
- package/doc/variables/CACHE.md +1 -1
- package/doc/variables/COLLATOR_DEFAULT.md +13 -0
- package/doc/variables/FILTER_ANY.md +1 -1
- package/doc/variables/FILTER_NONE.md +1 -1
- package/doc/variables/SELF.md +1 -1
- package/lib/constants/COLLATOR_DEFAULT.ts +4 -0
- package/lib/constants.ts +1 -0
- package/lib/tools/comparatorFieldValues.ts +24 -2
- package/lib/types/CombineUnion.ts +1 -1
- package/lib/types/Context.ts +10 -6
- package/lib/types/FieldFiltered.ts +3 -0
- package/lib/types/FieldKey.ts +4 -1
- package/lib/types/NormalizedPathFieldSettings.ts +4 -0
- package/lib/types/Path.ts +4 -1
- package/lib/types/PathFiltered.ts +3 -0
- package/lib/types/Primitive.ts +3 -0
- package/lib/types/Result.ts +27 -25
- package/package.json +1 -1
|
@@ -19,6 +19,7 @@ export function comparatorFieldValues<T>({
|
|
|
19
19
|
pathField = "path" as FieldFiltered<T, string>,
|
|
20
20
|
pathFieldSeparator = "/",
|
|
21
21
|
pathFieldSeparatorEscape = "\\",
|
|
22
|
+
collator,
|
|
22
23
|
}: NormalizedPathFieldSettings<T> = EMPTY_OBJECT): QuerySettings<T>["compareFieldValues"] {
|
|
23
24
|
const fieldSeparatorRegexp = new RegExp(
|
|
24
25
|
!pathFieldSeparatorEscape
|
|
@@ -45,9 +46,30 @@ export function comparatorFieldValues<T>({
|
|
|
45
46
|
fieldSeparatorRegexp,
|
|
46
47
|
"\x00",
|
|
47
48
|
);
|
|
48
|
-
if (
|
|
49
|
+
if (collator) {
|
|
50
|
+
const comparison = collator.compare(normalizedA, normalizedB);
|
|
51
|
+
return descending
|
|
52
|
+
? comparison > 0
|
|
53
|
+
? -1
|
|
54
|
+
: comparison < 0
|
|
55
|
+
? 1
|
|
56
|
+
: 0
|
|
57
|
+
: comparison > 0
|
|
58
|
+
? 1
|
|
59
|
+
: comparison < 0
|
|
60
|
+
? -1
|
|
61
|
+
: 0;
|
|
62
|
+
}
|
|
63
|
+
const comparison = normalizedA.localeCompare(normalizedB, undefined, {
|
|
64
|
+
numeric: true,
|
|
65
|
+
});
|
|
66
|
+
const comparisonNormalized = comparison > 0 ? 1 : comparison < 0 ? -1 : 0;
|
|
67
|
+
if (comparisonNormalized > 0) {
|
|
49
68
|
return descending ? -1 : 1;
|
|
50
69
|
}
|
|
51
|
-
|
|
70
|
+
if (comparisonNormalized < 0) {
|
|
71
|
+
return descending ? 1 : -1;
|
|
72
|
+
}
|
|
73
|
+
return 0;
|
|
52
74
|
};
|
|
53
75
|
}
|
package/lib/types/Context.ts
CHANGED
|
@@ -10,10 +10,14 @@ import type { Primitive } from "./Primitive.js";
|
|
|
10
10
|
*
|
|
11
11
|
* It can be a partial object of the type `T` or a primitive value wrapped in an object with the `SELF` key.
|
|
12
12
|
*/
|
|
13
|
-
export type Context<T> = [
|
|
13
|
+
export type Context<T> = [unknown] extends [T]
|
|
14
14
|
? any
|
|
15
|
-
:
|
|
16
|
-
?
|
|
17
|
-
:
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
: [0] extends [1 & T]
|
|
16
|
+
? any
|
|
17
|
+
: T extends Primitive
|
|
18
|
+
? { [SELF]: T }
|
|
19
|
+
: T extends undefined
|
|
20
|
+
? never
|
|
21
|
+
: {
|
|
22
|
+
[K in keyof T]?: T[K];
|
|
23
|
+
};
|
|
@@ -2,6 +2,9 @@ import type { CombineUnion } from "./CombineUnion";
|
|
|
2
2
|
import type { KeyFiltered } from "./KeyFiltered";
|
|
3
3
|
import type { PathFiltered } from "./PathFiltered";
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Returns union of keys and paths whose mapped value extend the provided `P` type.
|
|
7
|
+
*/
|
|
5
8
|
export type FieldFiltered<T, P> = KeyOrPathFiltered<CombineUnion<T>, P>;
|
|
6
9
|
|
|
7
10
|
type KeyOrPathFiltered<T, P> = KeyFiltered<T, P> | PathFiltered<T, P>;
|
package/lib/types/FieldKey.ts
CHANGED
|
@@ -3,8 +3,11 @@ import type { SELF } from "../constants/SELF.ts";
|
|
|
3
3
|
import type { Key } from "./Key.ts";
|
|
4
4
|
import type { Primitive } from "./Primitive";
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Returns the type of keys that can be used to select fields from a value of type `T`.
|
|
8
|
+
*/
|
|
6
9
|
export type FieldKey<T> = [unknown] extends [T]
|
|
7
10
|
? Key
|
|
8
|
-
: T extends Primitive
|
|
11
|
+
: T extends Primitive | undefined
|
|
9
12
|
? typeof SELF
|
|
10
13
|
: keyof T;
|
package/lib/types/Path.ts
CHANGED
|
@@ -3,13 +3,16 @@ import type { DepthLimit } from "./DepthLimit";
|
|
|
3
3
|
import type { Key } from "./Key";
|
|
4
4
|
import type { Primitive } from "./Primitive";
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Returns the type of paths that can be used to select fields from a value of type `T`, with an optional depth limit `D`.
|
|
8
|
+
*/
|
|
6
9
|
export type Path<T, D = DepthLimit> = [unknown] extends [T]
|
|
7
10
|
? readonly (Key | never)[]
|
|
8
11
|
: [0] extends [1 & T]
|
|
9
12
|
? readonly (Key | never)[]
|
|
10
13
|
: D extends -1
|
|
11
14
|
? never
|
|
12
|
-
: T extends Primitive
|
|
15
|
+
: T extends Primitive | undefined
|
|
13
16
|
? readonly never[]
|
|
14
17
|
: T extends Array<infer P>
|
|
15
18
|
? readonly [number] | readonly [number, ...Path<P, Decrement<D>>]
|
|
@@ -2,6 +2,9 @@ import type { Decrement } from "./Decrement";
|
|
|
2
2
|
import type { DepthLimit } from "./DepthLimit";
|
|
3
3
|
import type { Key } from "./Key";
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Returns the type of paths that can be used to select fields from a value of type `T` whose mapped value extend the provided `P` type, with an optional depth limit `D`.
|
|
7
|
+
*/
|
|
5
8
|
export type PathFiltered<T, P, D = DepthLimit> = [unknown] extends [T]
|
|
6
9
|
? readonly (Key | never)[]
|
|
7
10
|
: [0] extends [1 & T]
|
package/lib/types/Primitive.ts
CHANGED
package/lib/types/Result.ts
CHANGED
|
@@ -8,37 +8,39 @@ import type { QueryRead } from "./QueryRead";
|
|
|
8
8
|
import type { QueryReadMultiple } from "./QueryReadMultiple";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Picks fields `F` from
|
|
11
|
+
* Picks fields `F` from value `T`.
|
|
12
12
|
*/
|
|
13
13
|
type PickFields<T, F extends readonly Field<T>[]> = [unknown] extends [T]
|
|
14
14
|
? T
|
|
15
15
|
: T extends Primitive
|
|
16
16
|
? T
|
|
17
|
-
:
|
|
18
|
-
?
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
17
|
+
: T extends undefined
|
|
18
|
+
? never
|
|
19
|
+
: [F] extends [readonly [infer J, ...infer R]]
|
|
20
|
+
? Merge<
|
|
21
|
+
| // J is a single key
|
|
22
|
+
([J] extends [keyof T]
|
|
23
|
+
? PickField<T, J, T[J]>
|
|
24
|
+
: // J is a path
|
|
25
|
+
[J] extends [readonly [infer K, ...infer S]]
|
|
26
|
+
? [K] extends [keyof T]
|
|
27
|
+
? PickField<
|
|
28
|
+
T,
|
|
29
|
+
K,
|
|
30
|
+
PickFields<
|
|
31
|
+
T[K],
|
|
32
|
+
S extends readonly Field<T[K]>[] ? S : never
|
|
33
|
+
>
|
|
31
34
|
>
|
|
32
|
-
|
|
33
|
-
: never
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
: never;
|
|
35
|
+
: never
|
|
36
|
+
: never)
|
|
37
|
+
| (R extends readonly never[]
|
|
38
|
+
? never
|
|
39
|
+
: R extends readonly Field<T>[]
|
|
40
|
+
? PickFields<T, R>
|
|
41
|
+
: never)
|
|
42
|
+
>
|
|
43
|
+
: never;
|
|
42
44
|
|
|
43
45
|
type Merge<T> = Prettify<IntersectUnion<T>>;
|
|
44
46
|
|