quetch 0.9.2 → 0.10.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.
Files changed (78) hide show
  1. package/dist/errors/RequestError.d.ts +3 -3
  2. package/dist/errors/RequestError.js.map +1 -1
  3. package/dist/middlewares/aggregate.d.ts +9 -3
  4. package/dist/middlewares/aggregate.js.map +1 -1
  5. package/dist/middlewares/cache.d.ts +6 -5
  6. package/dist/middlewares/cache.js.map +1 -1
  7. package/dist/middlewares/fetchLocal.d.ts +2 -7
  8. package/dist/middlewares/fetchLocal.js +5 -0
  9. package/dist/middlewares/fetchLocal.js.map +1 -1
  10. package/dist/tools/defineCheckQuery.d.ts +3 -7
  11. package/dist/tools/defineCheckQuery.js.map +1 -1
  12. package/dist/tools/defineCustomFetch.d.ts +8 -20
  13. package/dist/tools/defineCustomFetch.js +3 -3
  14. package/dist/tools/defineCustomFetch.js.map +1 -1
  15. package/dist/tools/defineGenericFetch.d.ts +14 -13
  16. package/dist/tools/defineGenericFetch.js +9 -0
  17. package/dist/tools/defineGenericFetch.js.map +1 -1
  18. package/dist/tools/filterItem.d.ts +1 -1
  19. package/dist/tools/filterItem.js +3 -0
  20. package/dist/tools/filterItem.js.map +1 -1
  21. package/dist/tools/queryItemList.d.ts +3 -8
  22. package/dist/tools/queryItemList.js.map +1 -1
  23. package/dist/types/CustomFetch.d.ts +1 -7
  24. package/dist/types/Group.d.ts +0 -2
  25. package/dist/types/Parameters.d.ts +1 -0
  26. package/dist/types/Parameters.js +2 -0
  27. package/dist/types/Parameters.js.map +1 -0
  28. package/dist/types/Query.d.ts +2 -36
  29. package/dist/types/QueryAggregate.d.ts +15 -0
  30. package/dist/types/QueryCreate.d.ts +18 -0
  31. package/dist/types/QueryCreateMultiple.d.ts +15 -0
  32. package/dist/types/QueryDelete.d.ts +15 -2
  33. package/dist/types/QueryDeleteMultiple.d.ts +15 -2
  34. package/dist/types/QueryMethod.d.ts +1 -1
  35. package/dist/types/QueryRead.d.ts +15 -0
  36. package/dist/types/QueryReadMultiple.d.ts +15 -0
  37. package/dist/types/QuerySettings.d.ts +22 -1
  38. package/dist/types/QueryUpdate.d.ts +15 -0
  39. package/dist/types/QueryUpdateMultiple.d.ts +15 -0
  40. package/dist/types/Result.d.ts +15 -12
  41. package/dist/types.d.ts +2 -2
  42. package/doc/README.md +228 -292
  43. package/doc/interfaces/CustomFetch.md +5 -30
  44. package/lib/errors/RequestError.ts +2 -2
  45. package/lib/middlewares/aggregate.ts +9 -4
  46. package/lib/middlewares/cache.ts +21 -18
  47. package/lib/middlewares/fetchLocal.ts +2 -15
  48. package/lib/tools/defineCheckQuery.ts +8 -12
  49. package/lib/tools/defineCustomFetch.ts +12 -34
  50. package/lib/tools/defineGenericFetch.ts +14 -20
  51. package/lib/tools/filterItem.ts +4 -1
  52. package/lib/tools/queryItemList.ts +8 -20
  53. package/lib/types/CustomFetch.ts +1 -7
  54. package/lib/types/Group.ts +0 -3
  55. package/lib/types/Parameters.ts +1 -0
  56. package/lib/types/Query.ts +9 -43
  57. package/lib/types/QueryAggregate.ts +15 -0
  58. package/lib/types/QueryCreate.ts +19 -0
  59. package/lib/types/QueryCreateMultiple.ts +16 -0
  60. package/lib/types/QueryDelete.ts +15 -2
  61. package/lib/types/QueryDeleteMultiple.ts +15 -2
  62. package/lib/types/QueryMethod.ts +1 -1
  63. package/lib/types/QueryRead.ts +15 -0
  64. package/lib/types/QueryReadMultiple.ts +15 -0
  65. package/lib/types/QuerySettings.ts +22 -1
  66. package/lib/types/QueryUpdate.ts +15 -0
  67. package/lib/types/QueryUpdateMultiple.ts +15 -0
  68. package/lib/types/Result.ts +13 -22
  69. package/lib/types.ts +2 -2
  70. package/package.json +1 -1
  71. package/dist/types/CustomRequest.d.ts +0 -16
  72. package/dist/types/CustomRequest.js +0 -2
  73. package/dist/types/CustomRequest.js.map +0 -1
  74. package/dist/types/QueryAny.d.ts +0 -7
  75. package/dist/types/QueryAny.js +0 -2
  76. package/dist/types/QueryAny.js.map +0 -1
  77. package/lib/types/CustomRequest.ts +0 -21
  78. package/lib/types/QueryAny.ts +0 -8
@@ -1,12 +1,19 @@
1
+ import type { Context } from "./Context";
1
2
  import type { Filter } from "./Filter";
2
3
  import type { Group } from "./Group";
3
4
  import type { Order } from "./Order";
5
+ import type { Parameters } from "./Parameters";
6
+ import type { QuerySettings } from "./QuerySettings";
4
7
  /**
5
8
  * Query for getting a list of items.
6
9
  */
7
10
  export type QueryReadMultiple<T extends object> = {
8
11
  method?: "read";
9
12
  multiple: true;
13
+ /**
14
+ * Common item properties to use for identifying the item.
15
+ */
16
+ context?: Context<T>;
10
17
  /**
11
18
  * Offset of the first matching item.
12
19
  */
@@ -31,4 +38,12 @@ export type QueryReadMultiple<T extends object> = {
31
38
  * Groups items by specified fields.
32
39
  */
33
40
  group?: Group<T>[];
41
+ /**
42
+ * Query parameters.
43
+ */
44
+ parameters?: Parameters;
45
+ /**
46
+ * Query settings.
47
+ */
48
+ settings?: QuerySettings<T>;
34
49
  };
@@ -1,8 +1,29 @@
1
1
  import type { Filter } from "./Filter";
2
2
  import type { FilterChildren } from "./FilterChildren";
3
3
  import type { FilterKeys } from "./FilterKeys";
4
+ /**
5
+ * Settings to use when doing a query.
6
+ */
4
7
  export type QuerySettings<T extends object> = {
8
+ /**
9
+ * String used to separate the path nodes of an item.
10
+ */
5
11
  pathFieldSeparator?: string;
12
+ /**
13
+ * Field key to that contains the path value of an item.
14
+ */
6
15
  pathFieldKey?: FilterKeys<T, string>;
7
- transformFilterChildren?: (filter: FilterChildren<T>) => Filter<T>;
16
+ /**
17
+ * Returns a filter that captures the items expressed by the provided `FilterChildren`. The return filter cannot use filters of type `FilterChildren`.
18
+ *
19
+ * @param filter The provided `FilterChildren` to express.
20
+ * @returns A filter that captures the items expressed by the provided `FilterChildren`.
21
+ */
22
+ transformFilterChildren?: (filter: FilterChildren<T>) => Exclude<Filter<T>, {
23
+ operator: "children";
24
+ }>;
25
+ /**
26
+ * Abort signal to abort the query.
27
+ */
28
+ signal?: AbortSignal;
8
29
  };
@@ -1,10 +1,17 @@
1
+ import type { Context } from "./Context";
1
2
  import type { Filter } from "./Filter";
3
+ import type { Parameters } from "./Parameters";
4
+ import type { QuerySettings } from "./QuerySettings";
2
5
  /**
3
6
  * Query for updating an item.
4
7
  */
5
8
  export type QueryUpdate<T extends object> = {
6
9
  method: "update";
7
10
  multiple?: false;
11
+ /**
12
+ * Common item properties to use for identifying the context in which to update the item.
13
+ */
14
+ context?: Context<T>;
8
15
  /**
9
16
  * Partial property values to update.
10
17
  */
@@ -16,4 +23,12 @@ export type QueryUpdate<T extends object> = {
16
23
  offset?: never;
17
24
  order: never;
18
25
  group?: never;
26
+ /**
27
+ * Query parameters.
28
+ */
29
+ parameters?: Parameters;
30
+ /**
31
+ * Query settings.
32
+ */
33
+ settings?: QuerySettings<T>;
19
34
  };
@@ -1,11 +1,18 @@
1
+ import type { Context } from "./Context";
1
2
  import type { Filter } from "./Filter";
2
3
  import type { Order } from "./Order";
4
+ import type { Parameters } from "./Parameters";
5
+ import type { QuerySettings } from "./QuerySettings";
3
6
  /**
4
7
  * Query for updating multiple items.
5
8
  */
6
9
  export type QueryUpdateMultiple<T extends object> = {
7
10
  method: "update";
8
11
  multiple: true;
12
+ /**
13
+ * Common item properties to use for identifying the context in which to update the item.
14
+ */
15
+ context?: Context<T>;
9
16
  /**
10
17
  * Partial property values to update.
11
18
  */
@@ -23,4 +30,12 @@ export type QueryUpdateMultiple<T extends object> = {
23
30
  * Sets the upper bound of the number of items to update.
24
31
  */
25
32
  limit?: number;
33
+ /**
34
+ * Query parameters.
35
+ */
36
+ parameters?: Parameters;
37
+ /**
38
+ * Query settings.
39
+ */
40
+ settings?: QuerySettings<T>;
26
41
  };
@@ -1,23 +1,26 @@
1
- import type { CustomFieldMap } from "./CustomFieldMap";
2
- import type { InjectCustomFields } from "./InjectCustomFields";
3
1
  import type { Item } from "./Item";
4
2
  import type { Query } from "./Query";
3
+ /**
4
+ * Picks fields `F` from object `T`.
5
+ */
5
6
  export type PickFields<T extends object | undefined, F extends string | number | symbol> = [F] extends [keyof T] ? {
6
7
  readonly [K in F]: T[K];
7
8
  } : {
8
9
  readonly [K in keyof T]: T[K];
9
10
  };
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 [{
11
- fields: (keyof U)[];
12
- }] ? PickFields<U, Item<Q["fields"]>> : U : [Q] extends [{
13
- fields: (keyof T)[];
14
- }] ? PickFields<T, Item<Q["fields"]>> : 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 [{
16
- method: "read";
17
- }] ? [Q] extends [{
11
+ export type ResultRead<T extends object, Q extends Query<T>> = [Q] extends [
12
+ {
13
+ fields: (keyof T)[];
14
+ }
15
+ ] ? PickFields<T, Item<Q["fields"]>> : T;
16
+ export type Result<T extends object, Q extends Query<T>> = [Q] extends [
17
+ {
18
+ method: "read";
19
+ }
20
+ ] ? [Q] extends [{
18
21
  multiple: true;
19
- }] ? ResultRead<T, Q, C, U>[] : ResultRead<T, Q, C, U> : [Q] extends [{
22
+ }] ? ResultRead<T, Q>[] : ResultRead<T, Q> : [Q] extends [{
20
23
  method: "aggregate";
21
24
  }] ? number : [Q] extends [{
22
25
  multiple: true;
23
- }] ? ResultRead<T, Q, C, U>[] : ResultRead<T, Q, C, U>;
26
+ }] ? ResultRead<T, Q>[] : ResultRead<T, Q>;
package/dist/types.d.ts CHANGED
@@ -5,7 +5,6 @@ export type { Context } from "./types/Context";
5
5
  export type { CustomFetch } from "./types/CustomFetch";
6
6
  export type { CustomFieldAggregateMap } from "./types/CustomFieldAggregateMap";
7
7
  export type { CustomFieldMap } from "./types/CustomFieldMap";
8
- export type { CustomRequest } from "./types/CustomRequest";
9
8
  export type { FieldFunction } from "./types/FieldFunction";
10
9
  export type { FieldFunctionCustom } from "./types/FieldFunctionCustom";
11
10
  export type { FieldFunctionFormatDate } from "./types/FieldFunctionFormatDate";
@@ -14,6 +13,7 @@ export type { Filter } from "./types/Filter";
14
13
  export type { FilterArray } from "./types/FilterArray";
15
14
  export type { FilterBoolean } from "./types/FilterBoolean";
16
15
  export type { FilterChildren } from "./types/FilterChildren";
16
+ export type { FilterCustom } from "./types/FilterCustom";
17
17
  export type { FilterField } from "./types/FilterField";
18
18
  export type { FilterGroup } from "./types/FilterGroup";
19
19
  export type { FilterKeys } from "./types/FilterKeys";
@@ -32,9 +32,9 @@ export type { Key } from "./types/Key";
32
32
  export type { Mutable } from "./types/Mutable";
33
33
  export type { NextHandler } from "./types/NextHandler";
34
34
  export type { Order } from "./types/Order";
35
+ export type { Parameters } from "./types/Parameters";
35
36
  export type { Query } from "./types/Query";
36
37
  export type { QueryAggregate } from "./types/QueryAggregate";
37
- export type { QueryAny } from "./types/QueryAny";
38
38
  export type { QueryCreate } from "./types/QueryCreate";
39
39
  export type { QueryCreateMultiple } from "./types/QueryCreateMultiple";
40
40
  export type { QueryDelete } from "./types/QueryDelete";