quetch 0.9.2 → 0.10.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.
Files changed (76) 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/queryItemList.d.ts +3 -8
  20. package/dist/tools/queryItemList.js.map +1 -1
  21. package/dist/types/CustomFetch.d.ts +1 -7
  22. package/dist/types/Group.d.ts +0 -2
  23. package/dist/types/Parameters.d.ts +1 -0
  24. package/dist/types/Parameters.js +2 -0
  25. package/dist/types/Parameters.js.map +1 -0
  26. package/dist/types/Query.d.ts +2 -36
  27. package/dist/types/QueryAggregate.d.ts +15 -0
  28. package/dist/types/QueryCreate.d.ts +18 -0
  29. package/dist/types/QueryCreateMultiple.d.ts +15 -0
  30. package/dist/types/QueryDelete.d.ts +15 -2
  31. package/dist/types/QueryDeleteMultiple.d.ts +15 -2
  32. package/dist/types/QueryMethod.d.ts +1 -1
  33. package/dist/types/QueryRead.d.ts +15 -0
  34. package/dist/types/QueryReadMultiple.d.ts +15 -0
  35. package/dist/types/QuerySettings.d.ts +22 -1
  36. package/dist/types/QueryUpdate.d.ts +15 -0
  37. package/dist/types/QueryUpdateMultiple.d.ts +15 -0
  38. package/dist/types/Result.d.ts +15 -12
  39. package/dist/types.d.ts +2 -2
  40. package/doc/README.md +228 -292
  41. package/doc/interfaces/CustomFetch.md +5 -30
  42. package/lib/errors/RequestError.ts +2 -2
  43. package/lib/middlewares/aggregate.ts +9 -4
  44. package/lib/middlewares/cache.ts +21 -18
  45. package/lib/middlewares/fetchLocal.ts +2 -15
  46. package/lib/tools/defineCheckQuery.ts +8 -12
  47. package/lib/tools/defineCustomFetch.ts +12 -34
  48. package/lib/tools/defineGenericFetch.ts +14 -20
  49. package/lib/tools/filterItem.ts +1 -1
  50. package/lib/tools/queryItemList.ts +8 -20
  51. package/lib/types/CustomFetch.ts +1 -7
  52. package/lib/types/Group.ts +0 -3
  53. package/lib/types/Parameters.ts +1 -0
  54. package/lib/types/Query.ts +9 -43
  55. package/lib/types/QueryAggregate.ts +15 -0
  56. package/lib/types/QueryCreate.ts +19 -0
  57. package/lib/types/QueryCreateMultiple.ts +16 -0
  58. package/lib/types/QueryDelete.ts +15 -2
  59. package/lib/types/QueryDeleteMultiple.ts +15 -2
  60. package/lib/types/QueryMethod.ts +1 -1
  61. package/lib/types/QueryRead.ts +15 -0
  62. package/lib/types/QueryReadMultiple.ts +15 -0
  63. package/lib/types/QuerySettings.ts +22 -1
  64. package/lib/types/QueryUpdate.ts +15 -0
  65. package/lib/types/QueryUpdateMultiple.ts +15 -0
  66. package/lib/types/Result.ts +13 -22
  67. package/lib/types.ts +2 -2
  68. package/package.json +1 -1
  69. package/dist/types/CustomRequest.d.ts +0 -16
  70. package/dist/types/CustomRequest.js +0 -2
  71. package/dist/types/CustomRequest.js.map +0 -1
  72. package/dist/types/QueryAny.d.ts +0 -7
  73. package/dist/types/QueryAny.js +0 -2
  74. package/dist/types/QueryAny.js.map +0 -1
  75. package/lib/types/CustomRequest.ts +0 -21
  76. package/lib/types/QueryAny.ts +0 -8
@@ -12,49 +12,24 @@
12
12
 
13
13
  ### CustomFetch
14
14
 
15
- ▸ **CustomFetch**<`Q`\>(`query`): `Promise`<[`Result`](../README.md#result)<`T`, `Q`, {}, { readonly [K in string \| number \| symbol]: K extends keyof T ? T[K] : K extends never ? Object[K] extends FieldFunctionCustom<T\> ? ReturnType<Object[K]["value"]\> : Object[K]["operator"] extends "formatDate" ? FieldFunctionReturn[Object[K]["operator"]] : never : never }\>\>
15
+ ▸ **CustomFetch**<`Q`\>(`query`): `Promise`<[`Result`](../README.md#result)<`T`, `Q`\>\>
16
16
 
17
17
  #### Type parameters
18
18
 
19
19
  | Name | Type |
20
20
  | :------ | :------ |
21
- | `Q` | extends [`Query`](../README.md#query)<`T`, {}\> |
21
+ | `Q` | extends [`Query`](../README.md#query)<`T`\> |
22
22
 
23
23
  #### Parameters
24
24
 
25
25
  | Name | Type |
26
26
  | :------ | :------ |
27
- | `query` | `Q` & { `customFields?`: `undefined` } |
27
+ | `query` | `Q` |
28
28
 
29
29
  #### Returns
30
30
 
31
- `Promise`<[`Result`](../README.md#result)<`T`, `Q`, {}, { readonly [K in string \| number \| symbol]: K extends keyof T ? T[K] : K extends never ? Object[K] extends FieldFunctionCustom<T\> ? ReturnType<Object[K]["value"]\> : Object[K]["operator"] extends "formatDate" ? FieldFunctionReturn[Object[K]["operator"]] : never : never }\>\>
31
+ `Promise`<[`Result`](../README.md#result)<`T`, `Q`\>\>
32
32
 
33
33
  #### Defined in
34
34
 
35
- [lib/types/CustomFetch.ts:6](https://github.com/nevoland/quetch/blob/91f8b5b/lib/types/CustomFetch.ts#L6)
36
-
37
- ### CustomFetch
38
-
39
- ▸ **CustomFetch**<`Q`, `C`\>(`query`): `Promise`<[`Result`](../README.md#result)<`T`, `Q`, `C`, [`InjectCustomFields`](../README.md#injectcustomfields)<`T`, `C`\>\>\>
40
-
41
- #### Type parameters
42
-
43
- | Name | Type |
44
- | :------ | :------ |
45
- | `Q` | extends [`Query`](../README.md#query)<`T`, `C`\> |
46
- | `C` | extends [`CustomFieldMap`](../README.md#customfieldmap)<`T`\> |
47
-
48
- #### Parameters
49
-
50
- | Name | Type |
51
- | :------ | :------ |
52
- | `query` | `Q` & { `customFields`: `C` } |
53
-
54
- #### Returns
55
-
56
- `Promise`<[`Result`](../README.md#result)<`T`, `Q`, `C`, [`InjectCustomFields`](../README.md#injectcustomfields)<`T`, `C`\>\>\>
57
-
58
- #### Defined in
59
-
60
- [lib/types/CustomFetch.ts:9](https://github.com/nevoland/quetch/blob/91f8b5b/lib/types/CustomFetch.ts#L9)
35
+ [lib/types/CustomFetch.ts:5](https://github.com/nevoland/quetch/blob/c78a2c0/lib/types/CustomFetch.ts#L5)
@@ -1,4 +1,4 @@
1
- import type { QueryAny } from "../types";
1
+ import type { Query } from "../types/Query";
2
2
 
3
3
  /**
4
4
  * Error to be thrown in case there is an issue with the query call. Only instances of this error will be caught by the `retry()` middleware.
@@ -7,7 +7,7 @@ export class RequestError extends Error {
7
7
  constructor(
8
8
  message: string,
9
9
  public status: number,
10
- public query?: QueryAny,
10
+ public query?: Query<any>,
11
11
  public request?: Request,
12
12
  public response?: Response,
13
13
  ) {
@@ -1,7 +1,7 @@
1
1
  import { sleep } from "futurise";
2
2
 
3
3
  import { RequestError } from "../errors.js";
4
- import type { Handler, QueryAny } from "../types";
4
+ import type { Handler, Query } from "../types";
5
5
 
6
6
  /**
7
7
  * Aggregates multiple incoming query calls into one query.
@@ -13,7 +13,12 @@ import type { Handler, QueryAny } from "../types";
13
13
  * @param options
14
14
  * @returns
15
15
  */
16
- export function aggregate<I extends QueryAny, O, In extends QueryAny, On>({
16
+ export function aggregate<
17
+ I extends Query<any> & { type: any },
18
+ O,
19
+ In extends Query<any> & { type: any },
20
+ On,
21
+ >({
17
22
  queryGroupId = ({ type, method = "get" }) => {
18
23
  if (method !== "get") {
19
24
  return undefined;
@@ -31,7 +36,7 @@ export function aggregate<I extends QueryAny, O, In extends QueryAny, On>({
31
36
  },
32
37
  mergeQuery = (query, _currentQuery) => query,
33
38
  delay = 200,
34
- queryForGroup = (queryList, _): QueryAny => ({
39
+ queryForGroup = (queryList, _) => ({
35
40
  filter: {
36
41
  field: "id",
37
42
  operator: "include",
@@ -55,7 +60,7 @@ export function aggregate<I extends QueryAny, O, In extends QueryAny, On>({
55
60
  queryId?: (query: I) => string | undefined;
56
61
  mergeQuery?: (query: I, currentQuery: I) => I;
57
62
  delay?: number;
58
- queryForGroup: (queryList: I[], group: string) => QueryAny;
63
+ queryForGroup: (queryList: I[], group: string) => Query<any> & { type: any };
59
64
  resultForQuery: (resultList: O[], query: I) => O | never;
60
65
  }): Handler<I, O, In, On> {
61
66
  const queryGroupMap = new Map<
@@ -1,11 +1,28 @@
1
- import type { Handler, QueryAny, Store } from "../types";
1
+ import type { Handler, Query, Store } from "../types";
2
2
 
3
- type CachedItem<I extends QueryAny> = {
3
+ type CachedItem<I extends Query<any>> = {
4
4
  query: I;
5
5
  value: any;
6
6
  };
7
7
 
8
- type CacheOptions<I extends QueryAny> = {
8
+ export function cache<
9
+ I extends Query<any> & { type: any },
10
+ O,
11
+ In extends Query<any>,
12
+ On,
13
+ >({
14
+ itemId = ({ context = {}, method = "read", type }: I) => {
15
+ if (method === "read" && context.id) {
16
+ return `${String(type)}/${context.id}`;
17
+ }
18
+ return undefined;
19
+ },
20
+ store,
21
+ invalidatesItem,
22
+ extendCachedQuery,
23
+ mergeQuery,
24
+ mergeItem,
25
+ }: {
9
26
  /**
10
27
  * Unique identifier for the item to cache.
11
28
  * Returns `undefined` if the item should not be cached.
@@ -34,21 +51,7 @@ type CacheOptions<I extends QueryAny> = {
34
51
  * Only called when `extendCachedQuery` returns a query.
35
52
  */
36
53
  mergeItem: (value: any, cachedValue: any, query: I, cachedQuery: I) => any;
37
- };
38
-
39
- export function cache<I extends QueryAny, O, In extends QueryAny, On>({
40
- itemId = ({ context = {}, method = "read", type }: I) => {
41
- if (method === "read" && context.id) {
42
- return `${String(type)}/${context.id}`;
43
- }
44
- return undefined;
45
- },
46
- store,
47
- invalidatesItem,
48
- extendCachedQuery,
49
- mergeQuery,
50
- mergeItem,
51
- }: CacheOptions<I>): Handler<I, O, In, On> {
54
+ }): Handler<I, O, In, On> {
52
55
  /*
53
56
  Caches the result of a query if `serialize` returns a non-empty string key. The `engine` should follow the `Map` API. Elements are kept in the cache until the `duration` in milliseconds expires.
54
57
  Note that a `duration` set to `Infinity` indefinitely keeps items in the cache.
@@ -1,5 +1,5 @@
1
1
  import { queryItemList } from "../tools/queryItemList.js";
2
- import type { CustomFieldMap, Handler, Query } from "../types";
2
+ import type { Handler, Query } from "../types";
3
3
 
4
4
  /**
5
5
  * Performs the fetch query on local data.
@@ -7,20 +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, undefined> & { type: T[]; customFields: never },
11
- any,
12
- never,
13
- never
14
- >;
15
- export function fetchLocal<
16
- T extends object,
17
- C extends CustomFieldMap<T>,
18
- >(): Handler<Query<T, C> & { type: T[]; customFields: C }, any, never, never>;
19
- export function fetchLocal<
20
- T extends object,
21
- C extends CustomFieldMap<T>,
22
- >(): Handler<
23
- Query<T, C> & { type: T[]; customFields: C | never },
10
+ Query<T> & { type: T[] },
24
11
  any,
25
12
  never,
26
13
  never
@@ -1,4 +1,4 @@
1
- import type { CustomFieldMap, Query } from "../types";
1
+ import type { Query } from "../types";
2
2
 
3
3
  /**
4
4
  * Returns a function that checks queries. This is useful to prevent the query to have its type being narrowed if declared outside of a custom fetcher function argument.
@@ -6,23 +6,19 @@ import type { CustomFieldMap, Query } from "../types";
6
6
  * @returns Function that checks queries.
7
7
  */
8
8
  export function defineCheckQuery<M extends Record<string, object>>() {
9
- function checkQuery<
10
- T extends object,
11
- C extends CustomFieldMap<T>,
12
- const Q extends Query<T, C>,
13
- >(query: Q & { type: T[]; customFields?: C }): typeof query;
9
+ function checkQuery<T extends object, const Q extends Query<T>>(
10
+ query: Q & { type: T[] },
11
+ ): typeof query;
14
12
  function checkQuery<
15
13
  K extends keyof M,
16
14
  T extends M[K],
17
- C extends CustomFieldMap<T>,
18
- const Q extends Query<T, C>,
19
- >(query: Q & { type: K; customFields?: C }): typeof query;
15
+ const Q extends Query<T>,
16
+ >(query: Q & { type: K }): typeof query;
20
17
  function checkQuery<
21
18
  K extends keyof M,
22
19
  T extends M[K] | object,
23
- C extends CustomFieldMap<T>,
24
- const Q extends Query<T, C>,
25
- >(query: Q & { type: K | T[]; customFields?: C }): typeof query {
20
+ const Q extends Query<T>,
21
+ >(query: Q & { type: K | T[] }): typeof query {
26
22
  return query;
27
23
  }
28
24
  return checkQuery;
@@ -1,52 +1,30 @@
1
- import type { CustomFieldMap, Handler, Key, Query, Result } from "../types";
1
+ import type { Handler, Key, Query, Result } from "../types";
2
2
 
3
3
  import { cork } from "./cork.js";
4
4
 
5
5
  /**
6
+ * Returns a custom fetch function that handles a `query`
6
7
  *
7
- *
8
- * @param handler
9
- * @returns
8
+ * @param handler The query handler.
9
+ * @returns A custom fetch function.
10
10
  */
11
11
  export function defineCustomFetch<M extends Record<string, object>>(
12
- handler: Handler<
13
- Query<any, any> & { type: Key | any[]; customFields?: CustomFieldMap<any> },
14
- any,
15
- never,
16
- never
17
- >,
12
+ handler: Handler<Query<any> & { type: Key | any[] }, any, never, never>,
18
13
  ) {
19
14
  async function customFetch<
20
15
  K extends keyof M,
21
16
  T extends M[K],
22
- const Q extends Query<T, undefined>,
23
- >(
24
- query: Q & { type: K; customFields?: never },
25
- ): Promise<Result<T, Q, undefined>>;
26
- async function customFetch<
27
- K extends keyof M,
28
- T extends M[K],
29
- const Q extends Query<T, C>,
30
- const C extends CustomFieldMap<T>,
31
- >(query: Q & { type: K; customFields: C }): Promise<Result<T, Q, C>>;
32
- async function customFetch<
33
- T extends object,
34
- const Q extends Query<T, undefined>,
35
- >(
17
+ const Q extends Query<T>,
18
+ >(query: Q & { type: K }): Promise<Result<T, Q>>;
19
+ async function customFetch<T extends object, const Q extends Query<T>>(
36
20
  type: T[],
37
- query: Q & { customFields?: never },
38
- ): Promise<Result<T, Q, undefined>>;
39
- async function customFetch<
40
- T extends object,
41
- const Q extends Query<T, C>,
42
- const C extends CustomFieldMap<T>,
43
- >(query: Q & { type: T[]; customFields: C }): Promise<Result<T, Q, C>>;
21
+ query: Q,
22
+ ): Promise<Result<T, Q>>;
44
23
  async function customFetch<
45
24
  K extends keyof M,
46
25
  T extends M[K] | object,
47
- const Q extends Query<T, C>,
48
- const C extends CustomFieldMap<T>,
49
- >(query: Q & { type: T[] | K; customFields?: C }): Promise<Result<T, Q, C>> {
26
+ const Q extends Query<T>,
27
+ >(query: Q & { type: T[] | K }): Promise<Result<T, Q>> {
50
28
  return await handler(query as any, cork);
51
29
  }
52
30
  return customFetch;
@@ -1,30 +1,24 @@
1
- import type { CustomFieldMap, Handler, Key, Query, Result } from "../types";
1
+ import type { Handler, Key, Query, Result } from "../types";
2
2
 
3
3
  import { cork } from "./cork.js";
4
4
 
5
+ /**
6
+ * Returns a generic fetch function that has to be called like this:
7
+ * ```ts
8
+ * genericFetch<T>()(query)
9
+ * ```
10
+ *
11
+ * @param handler The query handler.
12
+ * @returns A curried generic fetch function.
13
+ */
5
14
  export function defineGenericFetch<K extends string>(
6
- handler: Handler<
7
- Query<any, any> & { type: Key | any[]; customFields?: CustomFieldMap<any> },
8
- any,
9
- never,
10
- never
11
- >,
15
+ handler: Handler<Query<any> & { type: Key | any[] }, any, never, never>,
12
16
  ) {
13
17
  // FIXME: Until https://github.com/microsoft/TypeScript/issues/26242 gets resolved, the fetcher needs to be curried
14
18
  function genericFetch<T extends object>() {
15
- async function customFetch<const Q extends Query<T, undefined>>(
16
- query: Q & { type: K | T[]; customFields?: never },
17
- ): Promise<Result<T, Q, undefined>>;
18
- async function customFetch<
19
- const Q extends Query<T, C>,
20
- const C extends CustomFieldMap<T>,
21
- >(query: Q & { type: K | T[]; customFields: C }): Promise<Result<T, Q, C>>;
22
- async function customFetch<
23
- const Q extends Query<T, C>,
24
- const C extends CustomFieldMap<T>,
25
- >(
26
- query: Q & { type: K | T[]; customFields?: C },
27
- ): Promise<Result<T, Q, C>> {
19
+ async function customFetch<const Q extends Query<T>>(
20
+ query: Q & { type: K | T[] },
21
+ ): Promise<Result<T, Q>> {
28
22
  return await handler(query as any, cork);
29
23
  }
30
24
  return customFetch;
@@ -1,6 +1,6 @@
1
1
  import { SymbolCache } from "../constants/SymbolCache.js";
2
2
  import type { Any, Filter, FilterKeys } from "../types";
3
- import type { QuerySettings } from "../types/QuerySettings";
3
+ import type { QuerySettings } from "../types/QuerySettings.js";
4
4
 
5
5
  import { filterChildren } from "./filterChildren.js";
6
6
 
@@ -3,11 +3,9 @@ import type {
3
3
  AggregateFunction,
4
4
  AggregateFunctionOperator,
5
5
  Context,
6
- CustomFieldMap,
7
6
  Filter,
8
7
  Order,
9
8
  Query,
10
- QueryAny,
11
9
  Result,
12
10
  } from "../types.js";
13
11
 
@@ -40,19 +38,9 @@ function normalizeAggregator<T extends object>(
40
38
  return aggregator.operator;
41
39
  }
42
40
 
43
- function queryItemList<T extends object, const Q extends Query<T, undefined>>(
44
- query: Q & { type: T[]; customFields?: never },
45
- ): Result<T, Q, undefined>;
46
- function queryItemList<
47
- T extends object,
48
- const Q extends Query<T, C>,
49
- const C extends CustomFieldMap<T>,
50
- >(query: Q & { type: T[]; customFields: C }): Result<T, Q, C>;
51
- function queryItemList<
52
- T extends object,
53
- const Q extends Query<T, C>,
54
- const C extends CustomFieldMap<T>,
55
- >(query: Q & { type: T[]; customFields?: C }): Result<T, Q, C> {
41
+ function queryItemList<T extends object, const Q extends Query<T>>(
42
+ query: Q & { type: T[] },
43
+ ): Result<T, Q> {
56
44
  const data = query.type as T[];
57
45
  switch (query.method) {
58
46
  case "read":
@@ -80,7 +68,7 @@ function queryItemList<
80
68
  if (offset !== 0 || limit !== Infinity) {
81
69
  result = result.slice(offset, offset + limit);
82
70
  }
83
- return result as Result<T, Q, C>;
71
+ return result as Result<T, Q>;
84
72
  }
85
73
  const normalizedFilter = mergeContextAndFilter(
86
74
  context,
@@ -90,16 +78,16 @@ function queryItemList<
90
78
  filterItem(normalizedFilter, item, query.settings),
91
79
  );
92
80
  if (result === undefined) {
93
- throw new RequestError("Not found", 404, query as QueryAny);
81
+ throw new RequestError("Not found", 404, query as Query<any>);
94
82
  }
95
- return result as Result<T, Q, C>;
83
+ return result as Result<T, Q>;
96
84
  }
97
85
  case "aggregate": {
98
86
  const { context, filter, aggregator } = query;
99
87
  switch (normalizeAggregator(aggregator)) {
100
88
  case "length": {
101
89
  if (filter === undefined && context === undefined) {
102
- return data.length as Result<T, Q, C>;
90
+ return data.length as Result<T, Q>;
103
91
  }
104
92
  const normalizedFilter = mergeContextAndFilter(
105
93
  context,
@@ -110,7 +98,7 @@ function queryItemList<
110
98
  return result + 1;
111
99
  }
112
100
  return result;
113
- }, 0 as number) as Result<T, Q, C>;
101
+ }, 0 as number) as Result<T, Q>;
114
102
  }
115
103
  default: {
116
104
  throw new Error("Not implemented");
@@ -1,12 +1,6 @@
1
- import type { CustomFieldMap } from "./CustomFieldMap";
2
1
  import type { Query } from "./Query";
3
2
  import type { Result } from "./Result";
4
3
 
5
4
  export interface CustomFetch<T extends object> {
6
- <Q extends Query<T, {}>>(
7
- query: Q & { customFields?: never },
8
- ): Promise<Result<T, Q, {}>>;
9
- <Q extends Query<T, C>, C extends CustomFieldMap<T>>(
10
- query: Q & { customFields: C },
11
- ): Promise<Result<T, Q, C>>;
5
+ <Q extends Query<T>>(query: Q): Promise<Result<T, Q>>;
12
6
  }
@@ -1,5 +1,3 @@
1
- import type { CustomFieldAggregateMap } from "./CustomFieldAggregateMap";
2
-
3
1
  /**
4
2
  * Specifies how items should be grouped.
5
3
  */
@@ -7,5 +5,4 @@ export type Group<T extends object> =
7
5
  | keyof T
8
6
  | {
9
7
  field: keyof T;
10
- customFields?: CustomFieldAggregateMap<T>;
11
8
  };
@@ -0,0 +1 @@
1
+ export type Parameters = Record<string, string | string[] | number | number[]>;
@@ -1,6 +1,3 @@
1
- import type { Context } from "./Context";
2
- import type { CustomFieldMap } from "./CustomFieldMap";
3
- import type { InjectCustomFields } from "./InjectCustomFields";
4
1
  import type { QueryAggregate } from "./QueryAggregate";
5
2
  import type { QueryCreate } from "./QueryCreate";
6
3
  import type { QueryCreateMultiple } from "./QueryCreateMultiple";
@@ -8,11 +5,18 @@ import type { QueryDelete } from "./QueryDelete";
8
5
  import type { QueryDeleteMultiple } from "./QueryDeleteMultiple";
9
6
  import type { QueryRead } from "./QueryRead";
10
7
  import type { QueryReadMultiple } from "./QueryReadMultiple";
11
- import type { QuerySettings } from "./QuerySettings";
12
8
  import type { QueryUpdate } from "./QueryUpdate";
13
9
  import type { QueryUpdateMultiple } from "./QueryUpdateMultiple";
14
10
 
15
- type QueryBase<T extends object> =
11
+ /**
12
+ * Query that fetches or mutates an entity.
13
+ */
14
+ export type Query<
15
+ /**
16
+ * Type of the object item to be queried.
17
+ */
18
+ T extends object,
19
+ > =
16
20
  | QueryRead<T>
17
21
  | QueryReadMultiple<T>
18
22
  | QueryCreate<T>
@@ -22,41 +26,3 @@ type QueryBase<T extends object> =
22
26
  | QueryDelete<T>
23
27
  | QueryDeleteMultiple<T>
24
28
  | QueryAggregate<T>;
25
-
26
- /**
27
- * Query that fetches or mutates an entity.
28
- */
29
- export type Query<
30
- /**
31
- * Type.
32
- */
33
- T extends object,
34
- /**
35
- * Custom fields.
36
- */
37
- C extends CustomFieldMap<T> | undefined,
38
- /**
39
- * Methods.
40
- */
41
- M extends QueryBase<never>["method"] = QueryBase<never>["method"],
42
- /**
43
- * Multiple.
44
- */
45
- L extends boolean | undefined = boolean,
46
- > = Extract<
47
- QueryBase<InjectCustomFields<T, C>>,
48
- { method?: M; multiple?: L }
49
- > & {
50
- /**
51
- * Common item properties to use for identifying the item.
52
- */
53
- context?: Context<T>;
54
- /**
55
- * Query parameters.
56
- */
57
- parameters?: Record<string, string | string[] | number | number[]>;
58
- /**
59
- * Query settings.
60
- */
61
- settings?: QuerySettings<T>;
62
- };
@@ -1,11 +1,26 @@
1
1
  import type { AggregateFunction } from "./AggregateFunction";
2
+ import type { Context } from "./Context";
2
3
  import type { Filter } from "./Filter";
4
+ import type { Parameters } from "./Parameters";
5
+ import type { QuerySettings } from "./QuerySettings";
3
6
 
4
7
  /**
5
8
  * Query for computing an aggregated value.
6
9
  */
7
10
  export type QueryAggregate<T extends object> = {
8
11
  method: "aggregate";
12
+ /**
13
+ * Common item properties to use for identifying the item.
14
+ */
15
+ context?: Context<T>;
9
16
  aggregator: AggregateFunction<T>;
10
17
  filter?: Filter<T>;
18
+ /**
19
+ * Query parameters.
20
+ */
21
+ parameters?: Parameters;
22
+ /**
23
+ * Query settings.
24
+ */
25
+ settings?: QuerySettings<T>;
11
26
  };
@@ -1,8 +1,27 @@
1
+ import type { Context } from "./Context";
2
+ import type { Parameters } from "./Parameters";
3
+ import type { QuerySettings } from "./QuerySettings";
4
+
1
5
  /**
2
6
  * Query for creating an item.
3
7
  */
4
8
  export type QueryCreate<T extends object> = {
5
9
  method: "create";
6
10
  multiple?: false;
11
+ /**
12
+ * Common item properties to use for identifying the context in which to create the item.
13
+ */
14
+ context?: Context<T>;
15
+ /**
16
+ * Value properties of the item to create.
17
+ */
7
18
  value: Partial<T>;
19
+ /**
20
+ * Query parameters.
21
+ */
22
+ parameters?: Parameters;
23
+ /**
24
+ * Query settings.
25
+ */
26
+ settings?: QuerySettings<T>;
8
27
  };
@@ -1,8 +1,24 @@
1
+ import type { Context } from "./Context";
2
+ import type { Parameters } from "./Parameters";
3
+ import type { QuerySettings } from "./QuerySettings";
4
+
1
5
  /**
2
6
  * Query for creating multiple items.
3
7
  */
4
8
  export type QueryCreateMultiple<T extends object> = {
5
9
  method: "create";
6
10
  multiple: true;
11
+ /**
12
+ * Common item properties to use for identifying the context in which to create the items.
13
+ */
14
+ context?: Context<T>;
7
15
  value: Partial<T>[];
16
+ /**
17
+ * Query parameters.
18
+ */
19
+ parameters?: Parameters;
20
+ /**
21
+ * Query settings.
22
+ */
23
+ settings?: QuerySettings<T>;
8
24
  };
@@ -1,5 +1,7 @@
1
- import type { CustomFieldMap } from "./CustomFieldMap";
1
+ import type { Context } from "./Context";
2
2
  import type { Filter } from "./Filter";
3
+ import type { Parameters } from "./Parameters";
4
+ import type { QuerySettings } from "./QuerySettings";
3
5
 
4
6
  /**
5
7
  * Query for deleting an item.
@@ -7,6 +9,17 @@ import type { Filter } from "./Filter";
7
9
  export type QueryDelete<T extends object> = {
8
10
  method: "delete";
9
11
  multiple?: false;
12
+ /**
13
+ * Common item properties to use for identifying the context in which to delete the item.
14
+ */
15
+ context?: Context<T>;
10
16
  filter?: Filter<T>;
11
- customFields?: CustomFieldMap<T>;
17
+ /**
18
+ * Query parameters.
19
+ */
20
+ parameters?: Parameters;
21
+ /**
22
+ * Query settings.
23
+ */
24
+ settings?: QuerySettings<T>;
12
25
  };
@@ -1,5 +1,7 @@
1
- import type { CustomFieldMap } from "./CustomFieldMap";
1
+ import type { Context } from "./Context";
2
2
  import type { Filter } from "./Filter";
3
+ import type { Parameters } from "./Parameters";
4
+ import type { QuerySettings } from "./QuerySettings";
3
5
 
4
6
  /**
5
7
  * Query for deleting multiple items.
@@ -7,6 +9,17 @@ import type { Filter } from "./Filter";
7
9
  export type QueryDeleteMultiple<T extends object> = {
8
10
  method: "delete";
9
11
  multiple: true;
12
+ /**
13
+ * Common item properties to use for identifying the context in which to delete the item.
14
+ */
15
+ context?: Context<T>;
10
16
  filter?: Filter<T>;
11
- customFields?: CustomFieldMap<T>;
17
+ /**
18
+ * Query parameters.
19
+ */
20
+ parameters?: Parameters;
21
+ /**
22
+ * Query settings.
23
+ */
24
+ settings?: QuerySettings<T>;
12
25
  };
@@ -3,4 +3,4 @@ import type { Query } from "./Query";
3
3
  /**
4
4
  * Available query methods.
5
5
  */
6
- export type QueryMethod = Exclude<Query<never, never>["method"], undefined>;
6
+ export type QueryMethod = Exclude<Query<never>["method"], undefined>;