quetch 0.32.2 → 0.33.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/comparatorFieldValues.js +11 -4
- package/dist/tools/comparatorFieldValues.js.map +1 -1
- package/dist/tools/normalizeOrder.js.map +1 -1
- package/dist/tools/sortItemList.js +3 -3
- package/dist/tools/sortItemList.js.map +1 -1
- package/dist/types/FieldKey.d.ts +1 -1
- package/dist/types/QuerySettings.d.ts +3 -2
- package/dist/types/ValueMap.d.ts +1 -1
- package/lib/tools/comparatorFieldValues.ts +11 -4
- package/lib/tools/normalizeOrder.ts +1 -1
- package/lib/tools/sortItemList.test.ts +58 -0
- package/lib/tools/sortItemList.ts +8 -3
- package/lib/types/FieldKey.ts +4 -4
- package/lib/types/QuerySettings.ts +3 -1
- package/lib/types/ValueMap.ts +10 -8
- package/package.json +1 -1
|
@@ -10,17 +10,24 @@ import { sameField } from "./sameField.js";
|
|
|
10
10
|
export function comparatorFieldValues({ pathField = "path", pathFieldSeparator = "/", pathFieldSeparatorEscape = "\\", } = EMPTY_OBJECT) {
|
|
11
11
|
const fieldSeparatorRegexp = new RegExp(!pathFieldSeparatorEscape
|
|
12
12
|
? escapeRegex(pathFieldSeparator)
|
|
13
|
-
: `(
|
|
14
|
-
return (field, a, b) => {
|
|
13
|
+
: `(?<!(?:${escapeRegex(pathFieldSeparatorEscape)}{2})*${escapeRegex(pathFieldSeparatorEscape)})${escapeRegex(pathFieldSeparator)}`, "g");
|
|
14
|
+
return (field, descending, a, b) => {
|
|
15
15
|
if (!sameField(field, pathField)) {
|
|
16
16
|
return undefined;
|
|
17
17
|
}
|
|
18
|
+
// Parents should always appear before their children, regardless of the order direction
|
|
19
|
+
if (a.startsWith(`${b}${pathFieldSeparator}`)) {
|
|
20
|
+
return 1;
|
|
21
|
+
}
|
|
22
|
+
if (b.startsWith(`${a}${pathFieldSeparator}`)) {
|
|
23
|
+
return -1;
|
|
24
|
+
}
|
|
18
25
|
const normalizedA = a.replaceAll?.(fieldSeparatorRegexp, "\x00");
|
|
19
26
|
const normalizedB = b.replaceAll?.(fieldSeparatorRegexp, "\x00");
|
|
20
27
|
if (normalizedA > normalizedB) {
|
|
21
|
-
return 1;
|
|
28
|
+
return descending ? -1 : 1;
|
|
22
29
|
}
|
|
23
|
-
return -1;
|
|
30
|
+
return descending ? 1 : -1;
|
|
24
31
|
};
|
|
25
32
|
}
|
|
26
33
|
//# sourceMappingURL=comparatorFieldValues.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comparatorFieldValues.js","sourceRoot":"","sources":["../../lib/tools/comparatorFieldValues.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAQ5C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAI,EACvC,SAAS,GAAG,MAAkC,EAC9C,kBAAkB,GAAG,GAAG,EACxB,wBAAwB,GAAG,IAAI,MACG,YAAY;IAC9C,MAAM,oBAAoB,GAAG,IAAI,MAAM,CACrC,CAAC,wBAAwB;QACvB,CAAC,CAAC,WAAW,CAAC,kBAAkB,CAAC;QACjC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"comparatorFieldValues.js","sourceRoot":"","sources":["../../lib/tools/comparatorFieldValues.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAQ5C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAI,EACvC,SAAS,GAAG,MAAkC,EAC9C,kBAAkB,GAAG,GAAG,EACxB,wBAAwB,GAAG,IAAI,MACG,YAA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AO,GAAG,KAAK,CAAC,OAAkD,CAAC;AAEzE;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAI,KAAe;IAI/C,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAChD,OAAO;YACL,KAAK,EAAE,KAAY;YACnB,UAAU,EAAE,KAAK;SAClB,CAAC;IACJ,CAAC;IACD,OAAO,
|
|
1
|
+
{"version":3,"file":"normalizeOrder.js","sourceRoot":"","sources":["../../lib/tools/normalizeOrder.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,GAAG,KAAK,CAAC,OAAkD,CAAC;AAEzE;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAI,KAAe;IAI/C,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAChD,OAAO;YACL,KAAK,EAAE,KAAY;YACnB,UAAU,EAAE,KAAK;SAClB,CAAC;IACJ,CAAC;IACD,OAAO,KAA6C,CAAC;AACvD,CAAC"}
|
|
@@ -17,7 +17,7 @@ export function sortItemList(orderList, value, settings) {
|
|
|
17
17
|
const normalizedOrder = orderList.map(normalizeOrder);
|
|
18
18
|
return value.toSorted((a, b) => {
|
|
19
19
|
for (let index = 0; index < normalizedOrder.length; index++) {
|
|
20
|
-
const { field, descending } = normalizedOrder[index];
|
|
20
|
+
const { field, descending = false } = normalizedOrder[index];
|
|
21
21
|
const valueA = get(a, field);
|
|
22
22
|
const valueB = get(b, field);
|
|
23
23
|
if (valueA === valueB) {
|
|
@@ -29,7 +29,7 @@ export function sortItemList(orderList, value, settings) {
|
|
|
29
29
|
if (valueB == null) {
|
|
30
30
|
return descending ? -1 : 1;
|
|
31
31
|
}
|
|
32
|
-
const comparison = compareFieldValues?.(field, valueA, valueB);
|
|
32
|
+
const comparison = compareFieldValues?.(field, descending, valueA, valueB);
|
|
33
33
|
if (comparison === undefined) {
|
|
34
34
|
if (valueA > valueB) {
|
|
35
35
|
return descending ? -1 : 1;
|
|
@@ -39,7 +39,7 @@ export function sortItemList(orderList, value, settings) {
|
|
|
39
39
|
if (comparison === 0) {
|
|
40
40
|
continue;
|
|
41
41
|
}
|
|
42
|
-
return
|
|
42
|
+
return comparison;
|
|
43
43
|
}
|
|
44
44
|
return 0;
|
|
45
45
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sortItemList.js","sourceRoot":"","sources":["../../lib/tools/sortItemList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAI5C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAC1B,SAAmD,EACnD,KAAmB,EACnB,QAA2B;IAE3B,IAAI,SAAS,KAAK,SAAS,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,EAAE,kBAAkB,EAAE,GAAG,QAAQ,IAAI,YAAY,CAAC;IACxD,MAAM,eAAe,GAAG,SAAS,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACtD,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAC7B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,eAAe,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;YAC5D,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,eAAe,CAAC,KAAK,CAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"sortItemList.js","sourceRoot":"","sources":["../../lib/tools/sortItemList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAI5C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;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U,EACV,MAAM,EACN,MAAM,CACP,CAAC;YACF,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;gBAC7B,IAAI,MAAM,GAAG,MAAM,EAAE,CAAC;oBACpB,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC7B,CAAC;gBACD,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7B,CAAC;YACD,IAAI,UAAU,KAAK,CAAC,EAAE,CAAC;gBACrB,SAAS;YACX,CAAC;YACD,OAAO,UAAU,CAAC;QACpB,CAAC;QACD,OAAO,CAAC,CAAC;IACX,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/types/FieldKey.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { SELF } from "../constants/SELF.ts";
|
|
2
2
|
import type { Key } from "./Key.ts";
|
|
3
3
|
import type { Primitive } from "./Primitive";
|
|
4
|
-
export type FieldKey<T> =
|
|
4
|
+
export type FieldKey<T> = [unknown] extends [T] ? Key : T extends Primitive ? typeof SELF : keyof T;
|
|
@@ -17,12 +17,13 @@ export type QuerySettings<T> = {
|
|
|
17
17
|
*
|
|
18
18
|
* This function is called only when both `a` and `b` are defined and different. If it returns `undefined`, the default comparison operators are used as a fallback.
|
|
19
19
|
*
|
|
20
|
+
* @param field - The field for which the values are compared.
|
|
21
|
+
* @param descending - Whether the comparison is for a descending order.
|
|
20
22
|
* @param a - The first value to compare.
|
|
21
23
|
* @param b - The second value to compare.
|
|
22
|
-
* @param field - The field for which the values are compared.
|
|
23
24
|
* @returns `-1` if `a` should be sorted before `b`, `1` if `a` should be sorted after `b`, `0` if they are considered equal, or `undefined` to use the default comparison operators.
|
|
24
25
|
*/
|
|
25
|
-
compareFieldValues?<T>(field: Field<T>, a: NonNullable<any>, b: NonNullable<any>): -1 | 0 | 1 | undefined;
|
|
26
|
+
compareFieldValues?<T>(field: Field<T>, descending: boolean, a: NonNullable<any>, b: NonNullable<any>): -1 | 0 | 1 | undefined;
|
|
26
27
|
/**
|
|
27
28
|
* Abort signal to abort the query.
|
|
28
29
|
*/
|
package/dist/types/ValueMap.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ import type { Primitive } from "./Primitive";
|
|
|
2
2
|
/**
|
|
3
3
|
* Maps the properties of the provided value `T` to a specific value `V`.
|
|
4
4
|
*/
|
|
5
|
-
export type ValueMap<T, V> = T extends Primitive ? V : T extends Array<infer P> ? Record<number, ValueMap<P, V>> : T extends object ? {
|
|
5
|
+
export type ValueMap<T, V> = [unknown] extends [T] ? V : T extends Primitive ? V : T extends Array<infer P> ? Record<number, ValueMap<P, V>> : T extends object ? {
|
|
6
6
|
[K in keyof T]?: ValueMap<T[K], V>;
|
|
7
7
|
} : never;
|
|
@@ -23,13 +23,20 @@ export function comparatorFieldValues<T>({
|
|
|
23
23
|
const fieldSeparatorRegexp = new RegExp(
|
|
24
24
|
!pathFieldSeparatorEscape
|
|
25
25
|
? escapeRegex(pathFieldSeparator)
|
|
26
|
-
: `(
|
|
26
|
+
: `(?<!(?:${escapeRegex(pathFieldSeparatorEscape)}{2})*${escapeRegex(pathFieldSeparatorEscape)})${escapeRegex(pathFieldSeparator)}`,
|
|
27
27
|
"g",
|
|
28
28
|
);
|
|
29
|
-
return (field, a, b) => {
|
|
29
|
+
return (field, descending, a, b) => {
|
|
30
30
|
if (!sameField(field, pathField)) {
|
|
31
31
|
return undefined;
|
|
32
32
|
}
|
|
33
|
+
// Parents should always appear before their children, regardless of the order direction
|
|
34
|
+
if ((a as string).startsWith(`${b}${pathFieldSeparator}`)) {
|
|
35
|
+
return 1;
|
|
36
|
+
}
|
|
37
|
+
if ((b as string).startsWith(`${a}${pathFieldSeparator}`)) {
|
|
38
|
+
return -1;
|
|
39
|
+
}
|
|
33
40
|
const normalizedA = (a as string).replaceAll?.(
|
|
34
41
|
fieldSeparatorRegexp,
|
|
35
42
|
"\x00",
|
|
@@ -39,8 +46,8 @@ export function comparatorFieldValues<T>({
|
|
|
39
46
|
"\x00",
|
|
40
47
|
);
|
|
41
48
|
if (normalizedA > normalizedB) {
|
|
42
|
-
return 1;
|
|
49
|
+
return descending ? -1 : 1;
|
|
43
50
|
}
|
|
44
|
-
return -1;
|
|
51
|
+
return descending ? 1 : -1;
|
|
45
52
|
};
|
|
46
53
|
}
|
|
@@ -143,3 +143,61 @@ test("sorts items with separator setting", () => {
|
|
|
143
143
|
{ path: "a\\.b.c" },
|
|
144
144
|
]);
|
|
145
145
|
});
|
|
146
|
+
|
|
147
|
+
test("sorts trees appropriately", () => {
|
|
148
|
+
expect(
|
|
149
|
+
sortItemList(
|
|
150
|
+
[{ descending: false, field: "path" }],
|
|
151
|
+
[
|
|
152
|
+
{ path: "a" },
|
|
153
|
+
{ path: "a/b" },
|
|
154
|
+
{ path: "a/c" },
|
|
155
|
+
{ path: "a.b" },
|
|
156
|
+
{ path: "a/b/c" },
|
|
157
|
+
{ path: "a.b.c" },
|
|
158
|
+
{ path: "a/b.c" },
|
|
159
|
+
{ path: "a\\/b.c" },
|
|
160
|
+
{ path: "a.b/c" },
|
|
161
|
+
],
|
|
162
|
+
querySettings(),
|
|
163
|
+
),
|
|
164
|
+
).toEqual([
|
|
165
|
+
{ path: "a" },
|
|
166
|
+
{ path: "a/b" },
|
|
167
|
+
{ path: "a/b/c" },
|
|
168
|
+
{ path: "a/b.c" },
|
|
169
|
+
{ path: "a/c" },
|
|
170
|
+
{ path: "a.b" },
|
|
171
|
+
{ path: "a.b/c" },
|
|
172
|
+
{ path: "a.b.c" },
|
|
173
|
+
{ path: "a\\/b.c" },
|
|
174
|
+
]);
|
|
175
|
+
|
|
176
|
+
expect(
|
|
177
|
+
sortItemList(
|
|
178
|
+
[{ descending: true, field: "path" }],
|
|
179
|
+
[
|
|
180
|
+
{ path: "a" },
|
|
181
|
+
{ path: "a/c" },
|
|
182
|
+
{ path: "a/b" },
|
|
183
|
+
{ path: "a.b" },
|
|
184
|
+
{ path: "a/b/c" },
|
|
185
|
+
{ path: "a.b.c" },
|
|
186
|
+
{ path: "a/b.c" },
|
|
187
|
+
{ path: "a\\/b.c" },
|
|
188
|
+
{ path: "a.b/c" },
|
|
189
|
+
],
|
|
190
|
+
querySettings(),
|
|
191
|
+
),
|
|
192
|
+
).toEqual([
|
|
193
|
+
{ path: "a\\/b.c" },
|
|
194
|
+
{ path: "a.b.c" },
|
|
195
|
+
{ path: "a.b" },
|
|
196
|
+
{ path: "a.b/c" },
|
|
197
|
+
{ path: "a" },
|
|
198
|
+
{ path: "a/c" },
|
|
199
|
+
{ path: "a/b.c" },
|
|
200
|
+
{ path: "a/b" },
|
|
201
|
+
{ path: "a/b/c" },
|
|
202
|
+
]);
|
|
203
|
+
});
|
|
@@ -25,7 +25,7 @@ export function sortItemList<T>(
|
|
|
25
25
|
const normalizedOrder = orderList.map(normalizeOrder);
|
|
26
26
|
return value.toSorted((a, b) => {
|
|
27
27
|
for (let index = 0; index < normalizedOrder.length; index++) {
|
|
28
|
-
const { field, descending } = normalizedOrder[index]!;
|
|
28
|
+
const { field, descending = false } = normalizedOrder[index]!;
|
|
29
29
|
const valueA = get(a, field);
|
|
30
30
|
const valueB = get(b, field);
|
|
31
31
|
if (valueA === valueB) {
|
|
@@ -37,7 +37,12 @@ export function sortItemList<T>(
|
|
|
37
37
|
if (valueB == null) {
|
|
38
38
|
return descending ? -1 : 1;
|
|
39
39
|
}
|
|
40
|
-
const comparison = compareFieldValues?.(
|
|
40
|
+
const comparison = compareFieldValues?.(
|
|
41
|
+
field,
|
|
42
|
+
descending,
|
|
43
|
+
valueA,
|
|
44
|
+
valueB,
|
|
45
|
+
);
|
|
41
46
|
if (comparison === undefined) {
|
|
42
47
|
if (valueA > valueB) {
|
|
43
48
|
return descending ? -1 : 1;
|
|
@@ -47,7 +52,7 @@ export function sortItemList<T>(
|
|
|
47
52
|
if (comparison === 0) {
|
|
48
53
|
continue;
|
|
49
54
|
}
|
|
50
|
-
return
|
|
55
|
+
return comparison;
|
|
51
56
|
}
|
|
52
57
|
return 0;
|
|
53
58
|
});
|
package/lib/types/FieldKey.ts
CHANGED
|
@@ -3,8 +3,8 @@ 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
|
-
export type FieldKey<T> =
|
|
7
|
-
?
|
|
8
|
-
:
|
|
9
|
-
?
|
|
6
|
+
export type FieldKey<T> = [unknown] extends [T]
|
|
7
|
+
? Key
|
|
8
|
+
: T extends Primitive
|
|
9
|
+
? typeof SELF
|
|
10
10
|
: keyof T;
|
|
@@ -18,13 +18,15 @@ export type QuerySettings<T> = {
|
|
|
18
18
|
*
|
|
19
19
|
* This function is called only when both `a` and `b` are defined and different. If it returns `undefined`, the default comparison operators are used as a fallback.
|
|
20
20
|
*
|
|
21
|
+
* @param field - The field for which the values are compared.
|
|
22
|
+
* @param descending - Whether the comparison is for a descending order.
|
|
21
23
|
* @param a - The first value to compare.
|
|
22
24
|
* @param b - The second value to compare.
|
|
23
|
-
* @param field - The field for which the values are compared.
|
|
24
25
|
* @returns `-1` if `a` should be sorted before `b`, `1` if `a` should be sorted after `b`, `0` if they are considered equal, or `undefined` to use the default comparison operators.
|
|
25
26
|
*/
|
|
26
27
|
compareFieldValues?<T>(
|
|
27
28
|
field: Field<T>,
|
|
29
|
+
descending: boolean,
|
|
28
30
|
a: NonNullable<any>,
|
|
29
31
|
b: NonNullable<any>,
|
|
30
32
|
): -1 | 0 | 1 | undefined;
|
package/lib/types/ValueMap.ts
CHANGED
|
@@ -3,12 +3,14 @@ import type { Primitive } from "./Primitive";
|
|
|
3
3
|
/**
|
|
4
4
|
* Maps the properties of the provided value `T` to a specific value `V`.
|
|
5
5
|
*/
|
|
6
|
-
export type ValueMap<T, V> =
|
|
6
|
+
export type ValueMap<T, V> = [unknown] extends [T]
|
|
7
7
|
? V
|
|
8
|
-
: T extends
|
|
9
|
-
?
|
|
10
|
-
: T extends
|
|
11
|
-
?
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
: T extends Primitive
|
|
9
|
+
? V
|
|
10
|
+
: T extends Array<infer P>
|
|
11
|
+
? Record<number, ValueMap<P, V>>
|
|
12
|
+
: T extends object
|
|
13
|
+
? {
|
|
14
|
+
[K in keyof T]?: ValueMap<T[K], V>;
|
|
15
|
+
}
|
|
16
|
+
: never;
|