quetch 0.6.4 → 0.6.6
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/middlewares/aggregate.js +5 -5
- package/dist/middlewares/aggregate.js.map +1 -1
- package/dist/middlewares/combine.js +2 -0
- package/dist/middlewares/combine.js.map +1 -1
- package/dist/middlewares/fetchLocal.d.ts +1 -1
- package/dist/middlewares/log.js +1 -0
- package/dist/middlewares/log.js.map +1 -1
- package/dist/tools/defineCustomFetch.d.ts +4 -4
- package/dist/tools/defineCustomFetch.js.map +1 -1
- package/dist/tools/defineGenericFetch.d.ts +2 -2
- package/dist/tools/defineGenericFetch.js.map +1 -1
- package/dist/tools/filterFromContext.js +1 -1
- package/dist/tools/filterFromContext.js.map +1 -1
- package/dist/tools/normalizeOrder.js +1 -1
- package/dist/tools/normalizeOrder.js.map +1 -1
- package/dist/tools/queryItemList.d.ts +2 -2
- package/dist/tools/queryItemList.js.map +1 -1
- package/dist/types/FilterKeys.d.ts +3 -3
- package/dist/types/Result.d.ts +3 -5
- package/lib/middlewares/aggregate.ts +5 -5
- package/lib/middlewares/combine.ts +2 -0
- package/lib/middlewares/fetchLocal.ts +1 -1
- package/lib/middlewares/log.ts +2 -0
- package/lib/tools/defineCustomFetch.ts +10 -5
- package/lib/tools/defineGenericFetch.ts +3 -3
- package/lib/tools/filterFromContext.ts +1 -1
- package/lib/tools/filterItem.test.ts +32 -32
- package/lib/tools/normalizeOrder.ts +1 -1
- package/lib/tools/queryItemList.test.ts +46 -46
- package/lib/tools/queryItemList.ts +4 -3
- package/lib/tools/sortItemList.test.ts +3 -3
- package/lib/types/FilterKeys.ts +4 -3
- package/lib/types/QueryReadMultiple.ts +0 -1
- package/lib/types/Result.ts +8 -7
- package/package.json +11 -2
|
@@ -24,14 +24,14 @@ export function aggregate({ queryGroupId = ({ type, method = "get" }) => {
|
|
|
24
24
|
}
|
|
25
25
|
return `${context.id}`;
|
|
26
26
|
}, mergeQuery = (query, _currentQuery) => query, delay = 200, queryForGroup = (queryList, _) => ({
|
|
27
|
-
type: queryList[0].type,
|
|
28
|
-
method: "read",
|
|
29
|
-
multiple: true,
|
|
30
27
|
filter: {
|
|
31
|
-
operator: "include",
|
|
32
28
|
field: "id",
|
|
29
|
+
operator: "include",
|
|
33
30
|
value: queryList.map((query) => query.context.id),
|
|
34
31
|
},
|
|
32
|
+
method: "read",
|
|
33
|
+
multiple: true,
|
|
34
|
+
type: queryList[0].type,
|
|
35
35
|
}), resultForQuery = (resultList, query) => {
|
|
36
36
|
const result = resultList.find((result) => result.id === query.context.id);
|
|
37
37
|
if (result === undefined) {
|
|
@@ -59,8 +59,8 @@ export function aggregate({ queryGroupId = ({ type, method = "get" }) => {
|
|
|
59
59
|
? next(queryMap.values().next().value)
|
|
60
60
|
: next(queryForGroup([...queryMap.values()], groupId));
|
|
61
61
|
})(),
|
|
62
|
-
requestMap: new Map(),
|
|
63
62
|
queryMap,
|
|
63
|
+
requestMap: new Map(),
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
const { groupRequest, requestMap, queryMap } = queryGroupMap.get(groupId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aggregate.js","sourceRoot":"","sources":["../../lib/middlewares/aggregate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C;;;;;;;;;GASG;AACH,MAAM,UAAU,SAAS,CAAiD,EACxE,YAAY,GAAG,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,KAAK,EAAE,EAAE,EAAE;IAC1C,IAAI,MAAM,KAAK,KAAK,EAAE;QACpB,OAAO,SAAS,CAAC;KAClB;IACD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,OAAO,SAAS,CAAC;KAClB;IACD,OAAO,IAAI,CAAC;AACd,CAAC,EACD,OAAO,GAAG,CAAC,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CAAC;IACjB,CAAC,CAA0B,CAAC;AAC9B,CAAC"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
function combine(...handlerList) {
|
|
2
|
+
// eslint-disable-next-line func-names
|
|
2
3
|
return function (input, next) {
|
|
3
4
|
function dispatch(input, index) {
|
|
4
5
|
const handler = handlerList[index];
|
|
5
6
|
if (!handler) {
|
|
6
7
|
return next(input);
|
|
7
8
|
}
|
|
9
|
+
// eslint-disable-next-line func-names, prefer-arrow-callback
|
|
8
10
|
const result = handler(input, function (input) {
|
|
9
11
|
return dispatch(input, index + 1);
|
|
10
12
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"combine.js","sourceRoot":"","sources":["../../lib/middlewares/combine.ts"],"names":[],"mappings":"AAs2BA,SAAS,OAAO,CA8Cd,GAAG,WAsBF;IAED,OAAO,UAAU,KAAK,EAAE,IAAI;QAC1B,SAAS,QAAQ,CAAC,KAAU,EAAE,KAAa;YACzC,MAAM,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;YACnC,IAAI,CAAC,OAAO,EAAE;gBACZ,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;aACpB;YACD,MAAM,MAAM,GAAQ,OAAO,CAAC,KAAK,EAAE,UAAU,KAAK;gBAChD,OAAO,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;YACpC,CAAC,CAAC,CAAC;YACH,IAAI,MAAM,KAAK,SAAS,EAAE;gBACxB,MAAM,IAAI,KAAK,CAAC,oBAAoB,KAAK,4BAA4B,CAAC,CAAC;aACxE;YACD,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,OAAO,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAC5B,CAAC,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"combine.js","sourceRoot":"","sources":["../../lib/middlewares/combine.ts"],"names":[],"mappings":"AAs2BA,SAAS,OAAO,CA8Cd,GAAG,WAsBF;IAED,sCAAsC;IACtC,OAAO,UAAU,KAAK,EAAE,IAAI;QAC1B,SAAS,QAAQ,CAAC,KAAU,EAAE,KAAa;YACzC,MAAM,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;YACnC,IAAI,CAAC,OAAO,EAAE;gBACZ,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;aACpB;YACD,6DAA6D;YAC7D,MAAM,MAAM,GAAQ,OAAO,CAAC,KAAK,EAAE,UAAU,KAAK;gBAChD,OAAO,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;YACpC,CAAC,CAAC,CAAC;YACH,IAAI,MAAM,KAAK,SAAS,EAAE;gBACxB,MAAM,IAAI,KAAK,CAAC,oBAAoB,KAAK,4BAA4B,CAAC,CAAC;aACxE;YACD,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,OAAO,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAC5B,CAAC,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -4,7 +4,7 @@ import type { CustomFieldMap, Handler, Query } from "../types";
|
|
|
4
4
|
*
|
|
5
5
|
* @returns Promise that resolves to the response.
|
|
6
6
|
*/
|
|
7
|
-
export declare function fetchLocal<T extends object>(): Handler<Query<T,
|
|
7
|
+
export declare function fetchLocal<T extends object>(): Handler<Query<T, undefined> & {
|
|
8
8
|
type: T[];
|
|
9
9
|
customFields: never;
|
|
10
10
|
}, any, never, never>;
|
package/dist/middlewares/log.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../lib/middlewares/log.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../lib/middlewares/log.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAI7B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC;;;;;GAKG;AACH,MAAM,UAAU,GAAG,CAAe,KAAK,GAAG,OAAO;IAC/C,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;QACzC,OAAO,QAAQ,CAAC;KACjB;IACD,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QAC3B,+BAA+B;QAC/B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrB,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAC7B,IAAI;YACF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAsB,CAAC,CAAC;YAClD,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YAC9B,OAAO,CAAC,QAAQ,EAAE,CAAC;YACnB,OAAO,MAAsB,CAAC;SAC/B;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YAC5B,OAAO,CAAC,QAAQ,EAAE,CAAC;YACnB,MAAM,KAAK,CAAC;SACb;QACD,8BAA8B;IAChC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -9,17 +9,17 @@ export declare function defineCustomFetch<M extends Record<string, object>>(hand
|
|
|
9
9
|
type: Key | any[];
|
|
10
10
|
customFields?: CustomFieldMap<any>;
|
|
11
11
|
}, any, never, never>): {
|
|
12
|
-
<K extends keyof M, T extends M[K], const Q extends Query<T,
|
|
12
|
+
<K extends keyof M, T extends M[K], const Q extends Query<T, undefined>>(query: Q & {
|
|
13
13
|
type: K;
|
|
14
14
|
customFields?: undefined;
|
|
15
|
-
}): Promise<Result<T, Q,
|
|
15
|
+
}): Promise<Result<T, Q, undefined>>;
|
|
16
16
|
<K_1 extends keyof M, T_1 extends M[K_1], const Q_1 extends Query<T_1, C>, const C extends CustomFieldMap<T_1>>(query: Q_1 & {
|
|
17
17
|
type: K_1;
|
|
18
18
|
customFields: C;
|
|
19
19
|
}): Promise<Result<T_1, Q_1, C>>;
|
|
20
|
-
<T_2 extends object, const Q_2 extends Query<T_2,
|
|
20
|
+
<T_2 extends object, const Q_2 extends Query<T_2, undefined>>(type: T_2[], query: Q_2 & {
|
|
21
21
|
customFields?: undefined;
|
|
22
|
-
}): Promise<Result<T_2, Q_2,
|
|
22
|
+
}): Promise<Result<T_2, Q_2, undefined>>;
|
|
23
23
|
<T_3 extends object, const Q_3 extends Query<T_3, C_1>, const C_1 extends CustomFieldMap<T_3>>(query: Q_3 & {
|
|
24
24
|
type: T_3[];
|
|
25
25
|
customFields: C_1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineCustomFetch.js","sourceRoot":"","sources":["../../lib/tools/defineCustomFetch.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAC/B,OAKC;
|
|
1
|
+
{"version":3,"file":"defineCustomFetch.js","sourceRoot":"","sources":["../../lib/tools/defineCustomFetch.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAC/B,OAKC;IA2BD,KAAK,UAAU,WAAW,CAKxB,KAA8C;QAC9C,OAAO,MAAM,OAAO,CAAC,KAAY,EAAE,IAAI,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -3,10 +3,10 @@ export declare function defineGenericFetch<K extends string>(handler: Handler<Qu
|
|
|
3
3
|
type: Key | any[];
|
|
4
4
|
customFields?: CustomFieldMap<any>;
|
|
5
5
|
}, any, never, never>): <T extends object>() => {
|
|
6
|
-
<const Q extends Query<T,
|
|
6
|
+
<const Q extends Query<T, undefined>>(query: Q & {
|
|
7
7
|
type: K | T[];
|
|
8
8
|
customFields?: undefined;
|
|
9
|
-
}): Promise<Result<T, Q,
|
|
9
|
+
}): Promise<Result<T, Q, undefined>>;
|
|
10
10
|
<const Q_1 extends Query<T, C>, const C extends CustomFieldMap<T>>(query: Q_1 & {
|
|
11
11
|
type: K | T[];
|
|
12
12
|
customFields: C;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineGenericFetch.js","sourceRoot":"","sources":["../../lib/tools/defineGenericFetch.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,UAAU,kBAAkB,CAChC,OAKC;IAED,mHAAmH;IACnH,SAAS,YAAY;QAQnB,KAAK,UAAU,WAAW,CAIxB,KAA8C;YAE9C,OAAO,MAAM,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"defineGenericFetch.js","sourceRoot":"","sources":["../../lib/tools/defineGenericFetch.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,UAAU,kBAAkB,CAChC,OAKC;IAED,mHAAmH;IACnH,SAAS,YAAY;QAQnB,KAAK,UAAU,WAAW,CAIxB,KAA8C;YAE9C,OAAO,MAAM,OAAO,CAAC,KAAY,EAAE,IAAI,CAAC,CAAC;QAC3C,CAAC;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filterFromContext.js","sourceRoot":"","sources":["../../lib/tools/filterFromContext.ts"],"names":[],"mappings":"AAEA,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;AAE3B,MAAM,UAAU,iBAAiB,CAC/B,OAAmB;IAEnB,OAAO;QACL,QAAQ,EAAE,KAAK;QACf,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;YAC/C,QAAQ,EAAE,OAAO;YACjB,KAAK;
|
|
1
|
+
{"version":3,"file":"filterFromContext.js","sourceRoot":"","sources":["../../lib/tools/filterFromContext.ts"],"names":[],"mappings":"AAEA,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;AAE3B,MAAM,UAAU,iBAAiB,CAC/B,OAAmB;IAEnB,OAAO;QACL,QAAQ,EAAE,KAAK;QACf,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;YAC/C,KAAK;YACL,QAAQ,EAAE,OAAO;YACjB,KAAK;SACN,CAAC,CAAgB;KACnB,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalizeOrder.js","sourceRoot":"","sources":["../../lib/tools/normalizeOrder.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,cAAc,CAC5B,KAAe;IAEf,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,OAAO,KAAK,CAAC;KACd;IACD,OAAO;QACL,
|
|
1
|
+
{"version":3,"file":"normalizeOrder.js","sourceRoot":"","sources":["../../lib/tools/normalizeOrder.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,cAAc,CAC5B,KAAe;IAEf,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,OAAO,KAAK,CAAC;KACd;IACD,OAAO;QACL,UAAU,EAAE,KAAK;QACjB,KAAK,EAAE,KAAK;KACb,CAAC;AACJ,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { CustomFieldMap, Query, Result } from "../types.js";
|
|
2
|
-
declare function queryItemList<T extends object, const Q extends Query<T,
|
|
2
|
+
declare function queryItemList<T extends object, const Q extends Query<T, undefined>>(query: Q & {
|
|
3
3
|
type: T[];
|
|
4
4
|
customFields?: never;
|
|
5
|
-
}): Result<T, Q,
|
|
5
|
+
}): Result<T, Q, undefined>;
|
|
6
6
|
declare function queryItemList<T extends object, const Q extends Query<T, C>, const C extends CustomFieldMap<T>>(query: Q & {
|
|
7
7
|
type: T[];
|
|
8
8
|
customFields: C;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryItemList.js","sourceRoot":"","sources":["../../lib/tools/queryItemList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"queryItemList.js","sourceRoot":"","sources":["../../lib/tools/queryItemList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAa5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,SAAS,qBAAqB,CAC5B,OAAoB,EACpB,MAAkB;IAElB,IAAI,OAAO,KAAK,SAAS,EAAE;QACzB,OAAO,MAAM,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;KACtC;IACD,IAAI,MAAM,KAAK,SAAS,EAAE;QACxB,OAAO,iBAAiB,CAAC,OAAO,CAAC,CAAC;KACnC;IACD,OAAO;QACL,QAAQ,EAAE,KAAK;QACf,KAAK,EAAE,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;KAC5C,CAAC;AACJ,CAAC;AAED,SAAS,mBAAmB,CAC1B,UAAgC;IAEhC,IAAI,UAAU,KAAK,QAAQ,EAAE;QAC3B,OAAO,UAAU,CAAC;KACnB;IACD,OAAO,UAAU,CAAC,QAAQ,CAAC;AAC7B,CAAC;AAUD,SAAS,aAAa,CAIpB,KAA0C;IAC1C,MAAM,IAAI,GAAG,KAAK,CAAC,IAAW,CAAC;IAC/B,QAAQ,KAAK,CAAC,MAAM,EAAE;QACpB,KAAK,MAAM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CAAC;SAClC;QACD,KAAK,WAAW,CAAC,CAAC;YAChB,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC;YAC9C,QAAQ,mBAAmB,CAAC,UAAU,CAAC,EAAE;gBACvC,KAAK,QAAQ,CAAC,CAAC;oBACb,IAAI,MAAM,KAAK,SAAS,IAAI,OAAO,KAAK,SAAS,EAAE;wBACjD,OAAO,IAAI,CAAC,MAAyB,CAAC;qBACvC;oBACD,MAAM,gBAAgB,GAAG,qBAAqB,CAC5C,OAAO,EACP,MAAmB,CACpB,CAAC;oBACF,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;wBAClC,IAAI,UAAU,CAAC,gBAAgB,EAAE,IAAI,CAAC,EAAE;4BACtC,OAAO,MAAM,GAAG,CAAC,CAAC;yBACnB;wBACD,OAAO,MAAM,CAAC;oBAChB,CAAC,EAAE,CAAW,CAAoB,CAAC;iBACpC;gBACD,OAAO,CAAC,CAAC;oBACP,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;iBACpC;aACF;SACF;QACD,OAAO,CAAC,CAAC;YACP,MAAM,IAAI,KAAK,CAAC,yBAAyB,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;SAC3D;KACF;AACH,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns object type with field extending the provided `P` type.
|
|
3
3
|
*/
|
|
4
|
-
export type FilterKeys<T extends object, P> = {
|
|
5
|
-
[K in keyof T
|
|
6
|
-
}
|
|
4
|
+
export type FilterKeys<T extends object, P> = keyof T & keyof {
|
|
5
|
+
[K in keyof T as T[K] extends P ? K : never]-?: T[K];
|
|
6
|
+
};
|
package/dist/types/Result.d.ts
CHANGED
|
@@ -2,19 +2,17 @@ import type { CustomFieldMap } from "./CustomFieldMap";
|
|
|
2
2
|
import type { InjectCustomFields } from "./InjectCustomFields";
|
|
3
3
|
import type { Item } from "./Item";
|
|
4
4
|
import type { Query } from "./Query";
|
|
5
|
-
export type PickFields<T extends object, F extends string | number | symbol> = [
|
|
6
|
-
F
|
|
7
|
-
] extends [keyof T] ? {
|
|
5
|
+
export type PickFields<T extends object | undefined, F extends string | number | symbol> = [F] extends [keyof T] ? {
|
|
8
6
|
readonly [K in F]: T[K];
|
|
9
7
|
} : {
|
|
10
8
|
readonly [K in keyof T]: T[K];
|
|
11
9
|
};
|
|
12
|
-
export type ResultRead<T extends object, Q extends Query<T, C>, C extends CustomFieldMap<T
|
|
10
|
+
export type ResultRead<T extends object, Q extends Query<T, C>, C extends CustomFieldMap<T> | undefined, U extends InjectCustomFields<T, C> | undefined = InjectCustomFields<T, C>> = [C] extends [CustomFieldMap<T>] ? [Q] extends [{
|
|
13
11
|
fields: (keyof U)[];
|
|
14
12
|
}] ? PickFields<U, Item<Q["fields"]>> : U : [Q] extends [{
|
|
15
13
|
fields: (keyof T)[];
|
|
16
14
|
}] ? PickFields<T, Item<Q["fields"]>> : T;
|
|
17
|
-
export type Result<T extends object, Q extends Query<T, C>, C extends CustomFieldMap<T
|
|
15
|
+
export type Result<T extends object, Q extends Query<T, C>, C extends CustomFieldMap<T> | undefined, U extends InjectCustomFields<T, C> | undefined = InjectCustomFields<T, C>> = [Q] extends [{
|
|
18
16
|
method: "read";
|
|
19
17
|
}] ? [Q] extends [{
|
|
20
18
|
multiple: true;
|
|
@@ -32,14 +32,14 @@ export function aggregate<I extends QueryAny, O, In extends QueryAny, On>({
|
|
|
32
32
|
mergeQuery = (query, _currentQuery) => query,
|
|
33
33
|
delay = 200,
|
|
34
34
|
queryForGroup = (queryList, _): QueryAny => ({
|
|
35
|
-
type: queryList[0].type,
|
|
36
|
-
method: "read",
|
|
37
|
-
multiple: true,
|
|
38
35
|
filter: {
|
|
39
|
-
operator: "include",
|
|
40
36
|
field: "id",
|
|
37
|
+
operator: "include",
|
|
41
38
|
value: queryList.map((query) => query.context!.id),
|
|
42
39
|
},
|
|
40
|
+
method: "read",
|
|
41
|
+
multiple: true,
|
|
42
|
+
type: queryList[0].type,
|
|
43
43
|
}),
|
|
44
44
|
resultForQuery = (resultList, query) => {
|
|
45
45
|
const result = resultList.find(
|
|
@@ -87,8 +87,8 @@ export function aggregate<I extends QueryAny, O, In extends QueryAny, On>({
|
|
|
87
87
|
queryForGroup([...queryMap.values()], groupId) as unknown as In,
|
|
88
88
|
);
|
|
89
89
|
})(),
|
|
90
|
-
requestMap: new Map(),
|
|
91
90
|
queryMap,
|
|
91
|
+
requestMap: new Map(),
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
94
|
const { groupRequest, requestMap, queryMap } = queryGroupMap.get(groupId)!;
|
|
@@ -938,12 +938,14 @@ function combine<
|
|
|
938
938
|
Handler<I20, O20, I21, O21>?,
|
|
939
939
|
]
|
|
940
940
|
): Handler<I0, O0, I21, O21> {
|
|
941
|
+
// eslint-disable-next-line func-names
|
|
941
942
|
return function (input, next) {
|
|
942
943
|
function dispatch(input: any, index: number) {
|
|
943
944
|
const handler = handlerList[index];
|
|
944
945
|
if (!handler) {
|
|
945
946
|
return next(input);
|
|
946
947
|
}
|
|
948
|
+
// eslint-disable-next-line func-names, prefer-arrow-callback
|
|
947
949
|
const result: any = handler(input, function (input) {
|
|
948
950
|
return dispatch(input, index + 1);
|
|
949
951
|
});
|
|
@@ -7,7 +7,7 @@ import type { CustomFieldMap, Handler, Query } from "../types";
|
|
|
7
7
|
* @returns Promise that resolves to the response.
|
|
8
8
|
*/
|
|
9
9
|
export function fetchLocal<T extends object>(): Handler<
|
|
10
|
-
Query<T,
|
|
10
|
+
Query<T, undefined> & { type: T[]; customFields: never },
|
|
11
11
|
any,
|
|
12
12
|
never,
|
|
13
13
|
never
|
package/lib/middlewares/log.ts
CHANGED
|
@@ -19,18 +19,23 @@ export function defineCustomFetch<M extends Record<string, object>>(
|
|
|
19
19
|
async function customFetch<
|
|
20
20
|
K extends keyof M,
|
|
21
21
|
T extends M[K],
|
|
22
|
-
const Q extends Query<T,
|
|
23
|
-
>(
|
|
22
|
+
const Q extends Query<T, undefined>,
|
|
23
|
+
>(
|
|
24
|
+
query: Q & { type: K; customFields?: never },
|
|
25
|
+
): Promise<Result<T, Q, undefined>>;
|
|
24
26
|
async function customFetch<
|
|
25
27
|
K extends keyof M,
|
|
26
28
|
T extends M[K],
|
|
27
29
|
const Q extends Query<T, C>,
|
|
28
30
|
const C extends CustomFieldMap<T>,
|
|
29
31
|
>(query: Q & { type: K; customFields: C }): Promise<Result<T, Q, C>>;
|
|
30
|
-
async function customFetch<
|
|
32
|
+
async function customFetch<
|
|
33
|
+
T extends object,
|
|
34
|
+
const Q extends Query<T, undefined>,
|
|
35
|
+
>(
|
|
31
36
|
type: T[],
|
|
32
37
|
query: Q & { customFields?: never },
|
|
33
|
-
): Promise<Result<T, Q,
|
|
38
|
+
): Promise<Result<T, Q, undefined>>;
|
|
34
39
|
async function customFetch<
|
|
35
40
|
T extends object,
|
|
36
41
|
const Q extends Query<T, C>,
|
|
@@ -42,7 +47,7 @@ export function defineCustomFetch<M extends Record<string, object>>(
|
|
|
42
47
|
const Q extends Query<T, C>,
|
|
43
48
|
const C extends CustomFieldMap<T>,
|
|
44
49
|
>(query: Q & { type: T[] | K; customFields?: C }): Promise<Result<T, Q, C>> {
|
|
45
|
-
return await handler(query, cork);
|
|
50
|
+
return await handler(query as any, cork);
|
|
46
51
|
}
|
|
47
52
|
return customFetch;
|
|
48
53
|
}
|
|
@@ -12,9 +12,9 @@ export function defineGenericFetch<K extends string>(
|
|
|
12
12
|
) {
|
|
13
13
|
// FIXME: Until https://github.com/microsoft/TypeScript/issues/26242 gets resolved, the fetcher needs to be curried
|
|
14
14
|
function genericFetch<T extends object>() {
|
|
15
|
-
async function customFetch<const Q extends Query<T,
|
|
15
|
+
async function customFetch<const Q extends Query<T, undefined>>(
|
|
16
16
|
query: Q & { type: K | T[]; customFields?: never },
|
|
17
|
-
): Promise<Result<T, Q,
|
|
17
|
+
): Promise<Result<T, Q, undefined>>;
|
|
18
18
|
async function customFetch<
|
|
19
19
|
const Q extends Query<T, C>,
|
|
20
20
|
const C extends CustomFieldMap<T>,
|
|
@@ -25,7 +25,7 @@ export function defineGenericFetch<K extends string>(
|
|
|
25
25
|
>(
|
|
26
26
|
query: Q & { type: K | T[]; customFields?: C },
|
|
27
27
|
): Promise<Result<T, Q, C>> {
|
|
28
|
-
return await handler(query, cork);
|
|
28
|
+
return await handler(query as any, cork);
|
|
29
29
|
}
|
|
30
30
|
return customFetch;
|
|
31
31
|
}
|
|
@@ -8,8 +8,8 @@ test("tests filter lists", () => {
|
|
|
8
8
|
{
|
|
9
9
|
operator: "all",
|
|
10
10
|
value: [
|
|
11
|
-
{
|
|
12
|
-
{
|
|
11
|
+
{ field: "a", operator: "equal", value: "foo" },
|
|
12
|
+
{ field: "b", operator: "equal", value: "bar" },
|
|
13
13
|
],
|
|
14
14
|
},
|
|
15
15
|
{ a: "foo", b: "bar" },
|
|
@@ -20,8 +20,8 @@ test("tests filter lists", () => {
|
|
|
20
20
|
{
|
|
21
21
|
operator: "all",
|
|
22
22
|
value: [
|
|
23
|
-
{
|
|
24
|
-
{
|
|
23
|
+
{ field: "a", operator: "equal", value: "foo" },
|
|
24
|
+
{ field: "b", operator: "equal", value: "baz" },
|
|
25
25
|
],
|
|
26
26
|
},
|
|
27
27
|
{ a: "foo", b: "bar" },
|
|
@@ -57,8 +57,8 @@ test("tests filter lists", () => {
|
|
|
57
57
|
{
|
|
58
58
|
operator: "any",
|
|
59
59
|
value: [
|
|
60
|
-
{
|
|
61
|
-
{
|
|
60
|
+
{ field: "a", operator: "equal", value: "foo" },
|
|
61
|
+
{ field: "b", operator: "equal", value: "baz" },
|
|
62
62
|
],
|
|
63
63
|
},
|
|
64
64
|
{ a: "foo", b: "bar" },
|
|
@@ -69,8 +69,8 @@ test("tests filter lists", () => {
|
|
|
69
69
|
{
|
|
70
70
|
operator: "none",
|
|
71
71
|
value: [
|
|
72
|
-
{
|
|
73
|
-
{
|
|
72
|
+
{ field: "a", operator: "equal", value: "a" },
|
|
73
|
+
{ field: "b", operator: "equal", value: "b" },
|
|
74
74
|
],
|
|
75
75
|
},
|
|
76
76
|
{ a: "foo", b: "bar" },
|
|
@@ -81,8 +81,8 @@ test("tests filter lists", () => {
|
|
|
81
81
|
{
|
|
82
82
|
operator: "none",
|
|
83
83
|
value: [
|
|
84
|
-
{
|
|
85
|
-
{
|
|
84
|
+
{ field: "a", operator: "equal", value: "a" },
|
|
85
|
+
{ field: "b", operator: "equal", value: "b" },
|
|
86
86
|
],
|
|
87
87
|
},
|
|
88
88
|
{ a: "foo", b: "bar" },
|
|
@@ -92,42 +92,42 @@ test("tests filter lists", () => {
|
|
|
92
92
|
|
|
93
93
|
test("tests filter on string values", () => {
|
|
94
94
|
expect(
|
|
95
|
-
filterItem({
|
|
95
|
+
filterItem({ field: "a", operator: "equal", value: "foo" }, { a: "foo" }),
|
|
96
96
|
).toBeTruthy();
|
|
97
97
|
expect(
|
|
98
|
-
filterItem({
|
|
98
|
+
filterItem({ field: "a", operator: "equal", value: "bar" }, { a: "foo" }),
|
|
99
99
|
).toBeFalsy();
|
|
100
100
|
expect(
|
|
101
101
|
filterItem(
|
|
102
|
-
{
|
|
102
|
+
{ field: "a", operator: "notEqual", value: "bar" },
|
|
103
103
|
{ a: "foo" },
|
|
104
104
|
),
|
|
105
105
|
).toBeTruthy();
|
|
106
106
|
expect(
|
|
107
107
|
filterItem(
|
|
108
|
-
{
|
|
108
|
+
{ field: "a", operator: "include", value: "bar" },
|
|
109
109
|
{ a: "foobar" },
|
|
110
110
|
),
|
|
111
111
|
).toBeTruthy();
|
|
112
112
|
expect(
|
|
113
113
|
filterItem(
|
|
114
|
-
{
|
|
114
|
+
{ field: "a", operator: "intersect", value: ["foo", "bar", "foobar"] },
|
|
115
115
|
{ a: "foobar" },
|
|
116
116
|
),
|
|
117
117
|
).toBeTruthy();
|
|
118
118
|
expect(
|
|
119
119
|
filterItem(
|
|
120
|
-
{
|
|
120
|
+
{ field: "a", operator: "intersect", value: ["foo", "bar"] },
|
|
121
121
|
{ a: "foobar" },
|
|
122
122
|
),
|
|
123
123
|
).toBeFalsy();
|
|
124
124
|
expect(
|
|
125
125
|
filterItem(
|
|
126
126
|
{
|
|
127
|
-
operator: "match",
|
|
128
127
|
field: "a",
|
|
129
|
-
|
|
128
|
+
operator: "match",
|
|
130
129
|
options: { ignoreCase: true },
|
|
130
|
+
value: "^FOO",
|
|
131
131
|
},
|
|
132
132
|
{ a: "foobar" },
|
|
133
133
|
),
|
|
@@ -135,10 +135,10 @@ test("tests filter on string values", () => {
|
|
|
135
135
|
expect(
|
|
136
136
|
filterItem(
|
|
137
137
|
{
|
|
138
|
-
operator: "match",
|
|
139
138
|
field: "a",
|
|
140
|
-
|
|
139
|
+
operator: "match",
|
|
141
140
|
options: { ignoreCase: true },
|
|
141
|
+
value: "FOO$",
|
|
142
142
|
},
|
|
143
143
|
{ a: "foobar" },
|
|
144
144
|
),
|
|
@@ -147,26 +147,26 @@ test("tests filter on string values", () => {
|
|
|
147
147
|
|
|
148
148
|
test("tests filter on number values", () => {
|
|
149
149
|
expect(
|
|
150
|
-
filterItem({
|
|
150
|
+
filterItem({ field: "a", operator: "equal", value: 1 }, { a: 1 }),
|
|
151
151
|
).toBeTruthy();
|
|
152
152
|
expect(
|
|
153
|
-
filterItem({
|
|
153
|
+
filterItem({ field: "a", operator: "notEqual", value: 2 }, { a: 1 }),
|
|
154
154
|
).toBeTruthy();
|
|
155
155
|
expect(
|
|
156
|
-
filterItem({
|
|
156
|
+
filterItem({ field: "a", operator: "greaterThan", value: 0 }, { a: 1 }),
|
|
157
157
|
).toBeTruthy();
|
|
158
158
|
expect(
|
|
159
159
|
filterItem(
|
|
160
|
-
{
|
|
160
|
+
{ field: "a", operator: "greaterThanOrEqual", value: 1 },
|
|
161
161
|
{ a: 1 },
|
|
162
162
|
),
|
|
163
163
|
).toBeTruthy();
|
|
164
164
|
expect(
|
|
165
|
-
filterItem({
|
|
165
|
+
filterItem({ field: "a", operator: "lowerThan", value: 2 }, { a: 1 }),
|
|
166
166
|
).toBeTruthy();
|
|
167
167
|
expect(
|
|
168
168
|
filterItem(
|
|
169
|
-
{
|
|
169
|
+
{ field: "a", operator: "lowerThanOrEqual", value: 1 },
|
|
170
170
|
{ a: 1 },
|
|
171
171
|
),
|
|
172
172
|
).toBeTruthy();
|
|
@@ -174,29 +174,29 @@ test("tests filter on number values", () => {
|
|
|
174
174
|
|
|
175
175
|
test("tests filter on array values", () => {
|
|
176
176
|
expect(
|
|
177
|
-
filterItem({
|
|
177
|
+
filterItem({ field: "a", operator: "equal", value: [2, 1] }, { a: [1, 2] }),
|
|
178
178
|
).toBeTruthy();
|
|
179
179
|
expect(
|
|
180
|
-
filterItem({
|
|
180
|
+
filterItem({ field: "a", operator: "equal", value: [2] }, { a: [1, 2] }),
|
|
181
181
|
).toBeFalsy();
|
|
182
182
|
expect(
|
|
183
|
-
filterItem({
|
|
183
|
+
filterItem({ field: "a", operator: "include", value: [1] }, { a: [1, 2] }),
|
|
184
184
|
).toBeTruthy();
|
|
185
185
|
expect(
|
|
186
186
|
filterItem(
|
|
187
|
-
{
|
|
187
|
+
{ field: "a", operator: "include", value: [2, 3] },
|
|
188
188
|
{ a: [1, 2] },
|
|
189
189
|
),
|
|
190
190
|
).toBeFalsy();
|
|
191
191
|
expect(
|
|
192
192
|
filterItem(
|
|
193
|
-
{
|
|
193
|
+
{ field: "a", operator: "intersect", value: [2, 3] },
|
|
194
194
|
{ a: [1, 2] },
|
|
195
195
|
),
|
|
196
196
|
).toBeTruthy();
|
|
197
197
|
expect(
|
|
198
198
|
filterItem(
|
|
199
|
-
{
|
|
199
|
+
{ field: "a", operator: "intersect", value: [3, 4] },
|
|
200
200
|
{ a: [1, 2] },
|
|
201
201
|
),
|
|
202
202
|
).toBeFalsy();
|
|
@@ -10,30 +10,30 @@ test("queries a single item", () => {
|
|
|
10
10
|
).toEqual({ a: 1 });
|
|
11
11
|
expect(() =>
|
|
12
12
|
queryItemList({
|
|
13
|
-
type: [{ a: 1 }, { a: 2 }, { a: 3 }],
|
|
14
13
|
context: {
|
|
15
14
|
a: 4,
|
|
16
15
|
},
|
|
16
|
+
type: [{ a: 1 }, { a: 2 }, { a: 3 }],
|
|
17
17
|
}),
|
|
18
18
|
).toThrow("Not found");
|
|
19
19
|
expect(
|
|
20
20
|
queryItemList({
|
|
21
|
-
type: [{ a: 1 }, { a: 2 }, { a: 3 }],
|
|
22
21
|
filter: {
|
|
23
22
|
field: "a",
|
|
24
23
|
operator: "greaterThan",
|
|
25
24
|
value: 1,
|
|
26
25
|
},
|
|
26
|
+
type: [{ a: 1 }, { a: 2 }, { a: 3 }],
|
|
27
27
|
}),
|
|
28
28
|
).toEqual({ a: 2 });
|
|
29
29
|
expect(() =>
|
|
30
30
|
queryItemList({
|
|
31
|
-
type: [{ a: 1 }, { a: 2 }, { a: 3 }],
|
|
32
31
|
filter: {
|
|
33
32
|
field: "a",
|
|
34
33
|
operator: "greaterThanOrEqual",
|
|
35
34
|
value: 4,
|
|
36
35
|
},
|
|
36
|
+
type: [{ a: 1 }, { a: 2 }, { a: 3 }],
|
|
37
37
|
}),
|
|
38
38
|
).toThrow("Not found");
|
|
39
39
|
});
|
|
@@ -41,30 +41,23 @@ test("queries a single item", () => {
|
|
|
41
41
|
test("queries lists of items", () => {
|
|
42
42
|
expect(
|
|
43
43
|
queryItemList({
|
|
44
|
-
type: [{ a: 1 }, { a: 2 }, { a: 3 }],
|
|
45
44
|
multiple: true,
|
|
45
|
+
type: [{ a: 1 }, { a: 2 }, { a: 3 }],
|
|
46
46
|
}),
|
|
47
47
|
).toEqual([{ a: 1 }, { a: 2 }, { a: 3 }]);
|
|
48
48
|
expect(
|
|
49
49
|
queryItemList({
|
|
50
|
-
type: [{ a: 1 }, { a: 2 }, { a: 3 }],
|
|
51
|
-
multiple: true,
|
|
52
50
|
filter: {
|
|
53
51
|
field: "a",
|
|
54
52
|
operator: "greaterThan",
|
|
55
53
|
value: 1,
|
|
56
54
|
},
|
|
55
|
+
multiple: true,
|
|
56
|
+
type: [{ a: 1 }, { a: 2 }, { a: 3 }],
|
|
57
57
|
}),
|
|
58
58
|
).toEqual([{ a: 2 }, { a: 3 }]);
|
|
59
59
|
expect(
|
|
60
60
|
queryItemList({
|
|
61
|
-
type: [
|
|
62
|
-
{ a: 1, c: "a" },
|
|
63
|
-
{ a: 2, c: "a" },
|
|
64
|
-
{ a: 3, c: "b" },
|
|
65
|
-
],
|
|
66
|
-
method: "read",
|
|
67
|
-
multiple: true,
|
|
68
61
|
context: {
|
|
69
62
|
c: "a",
|
|
70
63
|
},
|
|
@@ -73,17 +66,24 @@ test("queries lists of items", () => {
|
|
|
73
66
|
operator: "greaterThan",
|
|
74
67
|
value: 1,
|
|
75
68
|
},
|
|
69
|
+
method: "read",
|
|
70
|
+
multiple: true,
|
|
71
|
+
type: [
|
|
72
|
+
{ a: 1, c: "a" },
|
|
73
|
+
{ a: 2, c: "a" },
|
|
74
|
+
{ a: 3, c: "b" },
|
|
75
|
+
],
|
|
76
76
|
}),
|
|
77
77
|
).toEqual([{ a: 2, c: "a" }]);
|
|
78
78
|
expect(
|
|
79
79
|
queryItemList({
|
|
80
|
-
type: [{ a: 1 }, { a: 2 }, { a: 3 }],
|
|
81
|
-
multiple: true,
|
|
82
80
|
filter: {
|
|
83
81
|
field: "a",
|
|
84
82
|
operator: "greaterThanOrEqual",
|
|
85
83
|
value: 4,
|
|
86
84
|
},
|
|
85
|
+
multiple: true,
|
|
86
|
+
type: [{ a: 1 }, { a: 2 }, { a: 3 }],
|
|
87
87
|
}),
|
|
88
88
|
).toEqual([]);
|
|
89
89
|
});
|
|
@@ -91,6 +91,8 @@ test("queries lists of items", () => {
|
|
|
91
91
|
test("sorts items", () => {
|
|
92
92
|
expect(
|
|
93
93
|
queryItemList({
|
|
94
|
+
multiple: true,
|
|
95
|
+
order: ["a", "c"],
|
|
94
96
|
type: [
|
|
95
97
|
{ a: 1, c: "a" },
|
|
96
98
|
{ a: 2, c: "a" },
|
|
@@ -98,8 +100,6 @@ test("sorts items", () => {
|
|
|
98
100
|
{ a: 2, c: "b" },
|
|
99
101
|
{ a: 1, c: "b" },
|
|
100
102
|
],
|
|
101
|
-
multiple: true,
|
|
102
|
-
order: ["a", "c"],
|
|
103
103
|
}),
|
|
104
104
|
).toEqual([
|
|
105
105
|
{ a: 1, c: "a" },
|
|
@@ -110,6 +110,11 @@ test("sorts items", () => {
|
|
|
110
110
|
]);
|
|
111
111
|
expect(
|
|
112
112
|
queryItemList({
|
|
113
|
+
multiple: true,
|
|
114
|
+
order: [
|
|
115
|
+
{ descending: true, field: "a" },
|
|
116
|
+
{ descending: true, field: "c" },
|
|
117
|
+
],
|
|
113
118
|
type: [
|
|
114
119
|
{ a: 1, c: "a" },
|
|
115
120
|
{ a: 2, c: "a" },
|
|
@@ -117,11 +122,6 @@ test("sorts items", () => {
|
|
|
117
122
|
{ a: 2, c: "b" },
|
|
118
123
|
{ a: 1, c: "b" },
|
|
119
124
|
],
|
|
120
|
-
multiple: true,
|
|
121
|
-
order: [
|
|
122
|
-
{ field: "a", descending: true },
|
|
123
|
-
{ field: "c", descending: true },
|
|
124
|
-
],
|
|
125
125
|
}),
|
|
126
126
|
).toEqual([
|
|
127
127
|
{ a: 3, c: "b" },
|
|
@@ -135,26 +135,20 @@ test("sorts items", () => {
|
|
|
135
135
|
test("aggregates items", () => {
|
|
136
136
|
expect(
|
|
137
137
|
queryItemList({
|
|
138
|
-
type: [
|
|
139
|
-
{ a: 1, c: "a" },
|
|
140
|
-
{ a: 2, c: "a" },
|
|
141
|
-
{ a: 3, c: "b" },
|
|
142
|
-
],
|
|
143
|
-
method: "aggregate",
|
|
144
138
|
aggregator: "length",
|
|
145
139
|
context: {
|
|
146
140
|
c: "a",
|
|
147
141
|
},
|
|
148
|
-
|
|
149
|
-
).toBe(2);
|
|
150
|
-
expect(
|
|
151
|
-
queryItemList({
|
|
142
|
+
method: "aggregate",
|
|
152
143
|
type: [
|
|
153
144
|
{ a: 1, c: "a" },
|
|
154
145
|
{ a: 2, c: "a" },
|
|
155
146
|
{ a: 3, c: "b" },
|
|
156
147
|
],
|
|
157
|
-
|
|
148
|
+
}),
|
|
149
|
+
).toBe(2);
|
|
150
|
+
expect(
|
|
151
|
+
queryItemList({
|
|
158
152
|
aggregator: "length",
|
|
159
153
|
context: {
|
|
160
154
|
c: "a",
|
|
@@ -164,6 +158,12 @@ test("aggregates items", () => {
|
|
|
164
158
|
operator: "greaterThan",
|
|
165
159
|
value: 1,
|
|
166
160
|
},
|
|
161
|
+
method: "aggregate",
|
|
162
|
+
type: [
|
|
163
|
+
{ a: 1, c: "a" },
|
|
164
|
+
{ a: 2, c: "a" },
|
|
165
|
+
{ a: 3, c: "b" },
|
|
166
|
+
],
|
|
167
167
|
}),
|
|
168
168
|
).toBe(1);
|
|
169
169
|
});
|
|
@@ -171,43 +171,43 @@ test("aggregates items", () => {
|
|
|
171
171
|
test("slices items", () => {
|
|
172
172
|
expect(
|
|
173
173
|
queryItemList({
|
|
174
|
+
limit: 1,
|
|
175
|
+
method: "read",
|
|
176
|
+
multiple: true,
|
|
174
177
|
type: [
|
|
175
178
|
{ a: 1, c: "a" },
|
|
176
179
|
{ a: 2, c: "a" },
|
|
177
180
|
{ a: 3, c: "b" },
|
|
178
181
|
],
|
|
179
|
-
method: "read",
|
|
180
|
-
multiple: true,
|
|
181
|
-
limit: 1,
|
|
182
182
|
}),
|
|
183
183
|
).toEqual([{ a: 1, c: "a" }]);
|
|
184
184
|
expect(
|
|
185
185
|
queryItemList({
|
|
186
|
+
context: {
|
|
187
|
+
c: "a",
|
|
188
|
+
},
|
|
189
|
+
method: "read",
|
|
190
|
+
multiple: true,
|
|
191
|
+
offset: 1,
|
|
186
192
|
type: [
|
|
187
193
|
{ a: 1, c: "a" },
|
|
188
194
|
{ a: 2, c: "a" },
|
|
189
195
|
{ a: 3, c: "b" },
|
|
190
196
|
],
|
|
191
|
-
method: "read",
|
|
192
|
-
multiple: true,
|
|
193
|
-
context: {
|
|
194
|
-
c: "a",
|
|
195
|
-
},
|
|
196
|
-
offset: 1,
|
|
197
197
|
}),
|
|
198
198
|
).toEqual([{ a: 2, c: "a" }]);
|
|
199
199
|
expect(
|
|
200
200
|
queryItemList({
|
|
201
|
+
limit: 2,
|
|
202
|
+
method: "read",
|
|
203
|
+
multiple: true,
|
|
204
|
+
offset: 1,
|
|
201
205
|
type: [
|
|
202
206
|
{ a: 1, c: "a" },
|
|
203
207
|
{ a: 2, c: "a" },
|
|
204
208
|
{ a: 3, c: "b" },
|
|
205
209
|
{ a: 2, c: "b" },
|
|
206
210
|
],
|
|
207
|
-
method: "read",
|
|
208
|
-
multiple: true,
|
|
209
|
-
offset: 1,
|
|
210
|
-
limit: 2,
|
|
211
211
|
}),
|
|
212
212
|
).toEqual([
|
|
213
213
|
{ a: 2, c: "a" },
|
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
Filter,
|
|
8
8
|
Order,
|
|
9
9
|
Query,
|
|
10
|
+
QueryAny,
|
|
10
11
|
Result,
|
|
11
12
|
} from "../types.js";
|
|
12
13
|
|
|
@@ -39,9 +40,9 @@ function normalizeAggregator<T extends object>(
|
|
|
39
40
|
return aggregator.operator;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
function queryItemList<T extends object, const Q extends Query<T,
|
|
43
|
+
function queryItemList<T extends object, const Q extends Query<T, undefined>>(
|
|
43
44
|
query: Q & { type: T[]; customFields?: never },
|
|
44
|
-
): Result<T, Q,
|
|
45
|
+
): Result<T, Q, undefined>;
|
|
45
46
|
function queryItemList<
|
|
46
47
|
T extends object,
|
|
47
48
|
const Q extends Query<T, C>,
|
|
@@ -85,7 +86,7 @@ function queryItemList<
|
|
|
85
86
|
);
|
|
86
87
|
const result = data.find((item) => filterItem(normalizedFilter, item));
|
|
87
88
|
if (result === undefined) {
|
|
88
|
-
throw new RequestError("Not found", 404, query);
|
|
89
|
+
throw new RequestError("Not found", 404, query as QueryAny);
|
|
89
90
|
}
|
|
90
91
|
return result as Result<T, Q, C>;
|
|
91
92
|
}
|
|
@@ -24,8 +24,8 @@ test("sorts items", () => {
|
|
|
24
24
|
expect(
|
|
25
25
|
sortItemList(
|
|
26
26
|
[
|
|
27
|
-
{ field: "a"
|
|
28
|
-
{ field: "c"
|
|
27
|
+
{ descending: true, field: "a" },
|
|
28
|
+
{ descending: true, field: "c" },
|
|
29
29
|
],
|
|
30
30
|
[
|
|
31
31
|
{ a: 1, c: "a" },
|
|
@@ -44,7 +44,7 @@ test("sorts items", () => {
|
|
|
44
44
|
]);
|
|
45
45
|
expect(
|
|
46
46
|
sortItemList(
|
|
47
|
-
["a", { field: "c"
|
|
47
|
+
["a", { descending: true, field: "c" }],
|
|
48
48
|
[
|
|
49
49
|
{ a: 1, c: "a" },
|
|
50
50
|
{ a: 2, c: "a" },
|
package/lib/types/FilterKeys.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns object type with field extending the provided `P` type.
|
|
3
3
|
*/
|
|
4
|
-
export type FilterKeys<T extends object, P> =
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export type FilterKeys<T extends object, P> = keyof T &
|
|
5
|
+
keyof {
|
|
6
|
+
[K in keyof T as T[K] extends P ? K : never]-?: T[K];
|
|
7
|
+
};
|
package/lib/types/Result.ts
CHANGED
|
@@ -3,17 +3,18 @@ import type { InjectCustomFields } from "./InjectCustomFields";
|
|
|
3
3
|
import type { Item } from "./Item";
|
|
4
4
|
import type { Query } from "./Query";
|
|
5
5
|
|
|
6
|
-
export type PickFields<
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
export type PickFields<
|
|
7
|
+
T extends object | undefined,
|
|
8
|
+
F extends string | number | symbol,
|
|
9
|
+
> = [F] extends [keyof T]
|
|
9
10
|
? { readonly [K in F]: T[K] }
|
|
10
11
|
: { readonly [K in keyof T]: T[K] };
|
|
11
12
|
|
|
12
13
|
export type ResultRead<
|
|
13
14
|
T extends object,
|
|
14
15
|
Q extends Query<T, C>,
|
|
15
|
-
C extends CustomFieldMap<T
|
|
16
|
-
U extends InjectCustomFields<T, C> = InjectCustomFields<T, C>,
|
|
16
|
+
C extends CustomFieldMap<T> | undefined,
|
|
17
|
+
U extends InjectCustomFields<T, C> | undefined = InjectCustomFields<T, C>,
|
|
17
18
|
> = [C] extends [CustomFieldMap<T>]
|
|
18
19
|
? [Q] extends [{ fields: (keyof U)[] }]
|
|
19
20
|
? PickFields<U, Item<Q["fields"]>>
|
|
@@ -25,8 +26,8 @@ export type ResultRead<
|
|
|
25
26
|
export type Result<
|
|
26
27
|
T extends object,
|
|
27
28
|
Q extends Query<T, C>,
|
|
28
|
-
C extends CustomFieldMap<T
|
|
29
|
-
U extends InjectCustomFields<T, C> = InjectCustomFields<T, C>,
|
|
29
|
+
C extends CustomFieldMap<T> | undefined,
|
|
30
|
+
U extends InjectCustomFields<T, C> | undefined = InjectCustomFields<T, C>,
|
|
30
31
|
> = [Q] extends [{ method: "read" }]
|
|
31
32
|
? [Q] extends [{ multiple: true }]
|
|
32
33
|
? ResultRead<T, Q, C, U>[]
|
package/package.json
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quetch",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/main.js",
|
|
6
6
|
"exports": {
|
|
7
7
|
"types": "./dist/main.d.ts",
|
|
8
8
|
"import": "./dist/main.js"
|
|
9
9
|
},
|
|
10
|
+
"author": "David Bonnet <david@bonnet.cc>",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/nevoland/quetch.git"
|
|
15
|
+
},
|
|
10
16
|
"files": [
|
|
11
17
|
"dist",
|
|
12
18
|
"lib",
|
|
@@ -40,7 +46,9 @@
|
|
|
40
46
|
"release:beta": "npm version prerelease --preid=beta && git push origin --follow-tags && npm publish --tag=next"
|
|
41
47
|
},
|
|
42
48
|
"devDependencies": {
|
|
49
|
+
"@eslint/js": "^8.53.0",
|
|
43
50
|
"@preact/preset-vite": "^2.5.0",
|
|
51
|
+
"@types/eslint": "^8.44.6",
|
|
44
52
|
"@types/node": "^20.8.3",
|
|
45
53
|
"@typescript-eslint/parser": "^6.7.4",
|
|
46
54
|
"autoprefixer": "^10.4.16",
|
|
@@ -50,6 +58,7 @@
|
|
|
50
58
|
"eslint-config-prettier": "^9.0.0",
|
|
51
59
|
"eslint-plugin-import": "^2.28.1",
|
|
52
60
|
"eslint-plugin-inferno": "^7.32.2",
|
|
61
|
+
"eslint-plugin-sort-keys": "^2.3.5",
|
|
53
62
|
"eslint-plugin-tailwindcss": "^3.13.0",
|
|
54
63
|
"eslint-plugin-vitest": "^0.3.2",
|
|
55
64
|
"postcss": "^8.4.31",
|
|
@@ -67,6 +76,6 @@
|
|
|
67
76
|
},
|
|
68
77
|
"dependencies": {
|
|
69
78
|
"@davidbonnet/get-global": "^2.0.1",
|
|
70
|
-
"futurise": "^1.2.
|
|
79
|
+
"futurise": "^1.2.3"
|
|
71
80
|
}
|
|
72
81
|
}
|