quetch 0.6.5 → 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.
@@ -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>;
@@ -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, {}>>(query: Q & {
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, {}>>(type: T_2[], query: Q_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;IAsBD,KAAK,UAAU,WAAW,CAKxB,KAA8C;QAC9C,OAAO,MAAM,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACpC,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC"}
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, {}>>(query: Q & {
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,KAAK,EAAE,IAAI,CAAC,CAAC;QACpC,CAAC;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,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,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, {}>>(query: Q & {
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;AAY5C,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,E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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]-?: T[K] extends P ? K : never;
6
- }[keyof T];
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
+ };
@@ -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>, U extends InjectCustomFields<T, C> = InjectCustomFields<T, C>> = [C] extends [CustomFieldMap<T>] ? [Q] extends [{
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>, U extends InjectCustomFields<T, C> = InjectCustomFields<T, C>> = [Q] extends [{
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;
@@ -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, {}> & { type: T[]; customFields: never },
10
+ Query<T, undefined> & { type: T[]; customFields: never },
11
11
  any,
12
12
  never,
13
13
  never
@@ -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
- >(query: Q & { type: K; customFields?: never }): Promise<Result<T, Q, {}>>;
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<T extends object, const Q extends Query<T, {}>>(
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
  }
@@ -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
  }
@@ -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
- [K in keyof T]-?: T[K] extends P ? K : never;
6
- }[keyof T];
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
+ };
@@ -16,7 +16,6 @@ export type QueryReadMultiple<T extends object> = {
16
16
  * Upper bound of the number of items to return.
17
17
  */
18
18
  limit?: number;
19
-
20
19
  /**
21
20
  * Item fields to pick. If omitted, all fields are picked.
22
21
  */
@@ -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<T extends object, F extends string | number | symbol> = [
7
- F,
8
- ] extends [keyof T]
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,6 +1,6 @@
1
1
  {
2
2
  "name": "quetch",
3
- "version": "0.6.5",
3
+ "version": "0.6.6",
4
4
  "type": "module",
5
5
  "main": "./dist/main.js",
6
6
  "exports": {