@trpc/tanstack-react-query 11.1.3-alpha-tmp-issues-6785.34 → 11.1.3-alpha-tmp-tsdown.23

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 (62) hide show
  1. package/dist/_virtual/rolldown_runtime.js +30 -0
  2. package/dist/index.d.mts +8 -0
  3. package/dist/index.d.ts +8 -10
  4. package/dist/index.js +6 -10
  5. package/dist/index.mjs +5 -3
  6. package/dist/internals/Context.d.mts +28 -0
  7. package/dist/internals/Context.d.mts.map +1 -0
  8. package/dist/internals/Context.d.ts +21 -14
  9. package/dist/internals/Context.d.ts.map +1 -1
  10. package/dist/internals/Context.js +42 -63
  11. package/dist/internals/Context.mjs +41 -41
  12. package/dist/internals/Context.mjs.map +1 -0
  13. package/dist/internals/createOptionsProxy.d.mts +161 -0
  14. package/dist/internals/createOptionsProxy.d.mts.map +1 -0
  15. package/dist/internals/createOptionsProxy.d.ts +141 -141
  16. package/dist/internals/createOptionsProxy.d.ts.map +1 -1
  17. package/dist/internals/createOptionsProxy.js +107 -109
  18. package/dist/internals/createOptionsProxy.mjs +106 -106
  19. package/dist/internals/createOptionsProxy.mjs.map +1 -0
  20. package/dist/internals/infiniteQueryOptions.d.mts +55 -0
  21. package/dist/internals/infiniteQueryOptions.d.mts.map +1 -0
  22. package/dist/internals/infiniteQueryOptions.d.ts +40 -46
  23. package/dist/internals/infiniteQueryOptions.d.ts.map +1 -1
  24. package/dist/internals/infiniteQueryOptions.js +28 -35
  25. package/dist/internals/infiniteQueryOptions.mjs +27 -32
  26. package/dist/internals/infiniteQueryOptions.mjs.map +1 -0
  27. package/dist/internals/mutationOptions.d.mts +34 -0
  28. package/dist/internals/mutationOptions.d.mts.map +1 -0
  29. package/dist/internals/mutationOptions.d.ts +25 -34
  30. package/dist/internals/mutationOptions.d.ts.map +1 -1
  31. package/dist/internals/mutationOptions.js +30 -36
  32. package/dist/internals/mutationOptions.mjs +30 -33
  33. package/dist/internals/mutationOptions.mjs.map +1 -0
  34. package/dist/internals/queryOptions.d.mts +46 -0
  35. package/dist/internals/queryOptions.d.mts.map +1 -0
  36. package/dist/internals/queryOptions.d.ts +37 -49
  37. package/dist/internals/queryOptions.d.ts.map +1 -1
  38. package/dist/internals/queryOptions.js +31 -39
  39. package/dist/internals/queryOptions.mjs +30 -36
  40. package/dist/internals/queryOptions.mjs.map +1 -0
  41. package/dist/internals/subscriptionOptions.d.mts +66 -0
  42. package/dist/internals/subscriptionOptions.d.mts.map +1 -0
  43. package/dist/internals/subscriptionOptions.d.ts +53 -60
  44. package/dist/internals/subscriptionOptions.d.ts.map +1 -1
  45. package/dist/internals/subscriptionOptions.js +123 -171
  46. package/dist/internals/subscriptionOptions.mjs +122 -149
  47. package/dist/internals/subscriptionOptions.mjs.map +1 -0
  48. package/dist/internals/types.d.mts +84 -0
  49. package/dist/internals/types.d.mts.map +1 -0
  50. package/dist/internals/types.d.ts +43 -42
  51. package/dist/internals/types.d.ts.map +1 -1
  52. package/dist/internals/utils.js +70 -99
  53. package/dist/internals/utils.mjs +69 -96
  54. package/dist/internals/utils.mjs.map +1 -0
  55. package/package.json +20 -15
  56. package/src/internals/mutationOptions.ts +2 -2
  57. package/src/internals/queryOptions.ts +1 -1
  58. package/src/internals/subscriptionOptions.ts +1 -0
  59. package/dist/bundle-analysis.json +0 -128
  60. package/dist/index.d.ts.map +0 -1
  61. package/dist/internals/utils.d.ts +0 -36
  62. package/dist/internals/utils.d.ts.map +0 -1
@@ -0,0 +1,84 @@
1
+ import { TRPCRequestOptions } from "@trpc/client";
2
+ import { InfiniteData } from "@tanstack/react-query";
3
+
4
+ //#region src/internals/types.d.ts
5
+ /**
6
+ * Turn a set of optional properties into required
7
+ * @internal
8
+ */
9
+ /**
10
+ * Turn a set of optional properties into required
11
+ * @internal
12
+ */
13
+ type WithRequired<TObj, TKey extends keyof TObj> = TObj & { [P in TKey]-?: TObj[P] };
14
+ /**
15
+ * @internal
16
+ */
17
+ type ResolverDef = {
18
+ input: any;
19
+ output: any;
20
+ transformer: boolean;
21
+ errorShape: any;
22
+ };
23
+ /**
24
+ * @remark `void` is here due to https://github.com/trpc/trpc/pull/4374
25
+ */
26
+ type CursorInput = {
27
+ cursor?: any;
28
+ };
29
+ type OptionalCursorInput = CursorInput | void;
30
+ /**
31
+ * @internal
32
+ */
33
+ type ExtractCursorType<TInput> = TInput extends CursorInput ? TInput['cursor'] : unknown;
34
+ /**
35
+ * @internal
36
+ */
37
+ type TRPCInfiniteData<TInput, TOutput> = InfiniteData<TOutput, NonNullable<ExtractCursorType<TInput>> | null>;
38
+ /**
39
+ * @public
40
+ */
41
+ interface TRPCReactRequestOptions extends Omit<TRPCRequestOptions, 'signal'> {
42
+ /**
43
+ * Opt out of SSR for this query by passing `ssr: false`
44
+ */
45
+ ssr?: boolean;
46
+ /**
47
+ * Opt out or into aborting request on unmount
48
+ */
49
+ abortOnUnmount?: boolean;
50
+ }
51
+ /**
52
+ * @public
53
+ */
54
+ interface TRPCQueryBaseOptions {
55
+ /**
56
+ * tRPC-related options
57
+ */
58
+ trpc?: TRPCReactRequestOptions;
59
+ }
60
+ /**
61
+ * @public
62
+ */
63
+ interface TRPCQueryOptionsResult {
64
+ trpc: {
65
+ path: string;
66
+ };
67
+ }
68
+ /**
69
+ * @public
70
+ */
71
+ type QueryType = 'any' | 'infinite' | 'query';
72
+ /**
73
+ * @public
74
+ */
75
+ type TRPCQueryKey = [readonly string[], {
76
+ input?: unknown;
77
+ type?: Exclude<QueryType, 'any'>;
78
+ }?];
79
+ /**
80
+ * @public
81
+ */
82
+ type TRPCMutationKey = [readonly string[]]; //#endregion
83
+ export { ExtractCursorType, OptionalCursorInput, QueryType, ResolverDef, TRPCInfiniteData, TRPCMutationKey, TRPCQueryBaseOptions, TRPCQueryKey, TRPCQueryOptionsResult, TRPCReactRequestOptions, WithRequired };
84
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.mts","names":[],"sources":["../../src/internals/types.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;KAOY,sCAAsC,QAAQ,eAClD,SAAS,KAAK,IADtB;;;;AACQ,KAMI,WAAA,GANJ;EAAI,KAAK,EAAA,GAAA;EAAI,MAAC,EAAA,GAAA;EAAC,WAAA,EAAA,OAAA;;;;AAMvB;;KAUK,WAAA;;AAHL,CAAA;AAIY,KAAA,mBAAA,GAAsB,WAAA,GAAW,IAAA;;;;AAKjC,KAAA,iBAAiB,CAAA,MAAA,CAAA,GAAW,MAAX,SAA0B,WAA1B,GACzB,MADyB,CAAA,QAAA,CAAA,GAAA,OAAA;;;;AACzB,KAMQ,gBANR,CAAA,MAAA,EAAA,OAAA,CAAA,GAM4C,YAN5C,CAOF,OAPE,EAQF,WARE,CAQU,iBARV,CAQ4B,MAR5B,CAAA,CAAA,GAAA,IAAA,CAAA;AAAM;;;UAcO,uBAAA,SAEP,KAAK;EAVH;;;EACH,GACuB,CAAA,EAAA,OAAA;EAAM;;;EAFsB,cAAA,CAAA,EAAA,OAAA;;;;AAQ5D;AAEE,UAce,oBAAA,CAdf;EAAA;;AAAY;SAkBL;;;AAJT;;UAUiB,sBAAA;;IAAA,IAAA,EAAA,MAAA;;;;AASjB;;KAAY,SAAA;;AAKZ;;AAEoC,KAFxB,YAAA,GAEwB,CAAS,SAAjB,MAAA,EAAA,EAAO;;SAAP,QAAQ;GAMpC;;;;KAAY,eAAA"}
@@ -1,83 +1,84 @@
1
- import type { InfiniteData } from '@tanstack/react-query';
2
- import type { TRPCRequestOptions } from '@trpc/client';
1
+ import { InfiniteData } from "@tanstack/react-query";
2
+ import { TRPCRequestOptions } from "@trpc/client";
3
+
4
+ //#region src/internals/types.d.ts
5
+ /**
6
+ * Turn a set of optional properties into required
7
+ * @internal
8
+ */
3
9
  /**
4
10
  * Turn a set of optional properties into required
5
11
  * @internal
6
12
  */
7
- export type WithRequired<TObj, TKey extends keyof TObj> = TObj & {
8
- [P in TKey]-?: TObj[P];
9
- };
13
+ type WithRequired<TObj, TKey extends keyof TObj> = TObj & { [P in TKey]-?: TObj[P] };
10
14
  /**
11
15
  * @internal
12
16
  */
13
- export type ResolverDef = {
14
- input: any;
15
- output: any;
16
- transformer: boolean;
17
- errorShape: any;
17
+ type ResolverDef = {
18
+ input: any;
19
+ output: any;
20
+ transformer: boolean;
21
+ errorShape: any;
18
22
  };
19
23
  /**
20
24
  * @remark `void` is here due to https://github.com/trpc/trpc/pull/4374
21
25
  */
22
26
  type CursorInput = {
23
- cursor?: any;
27
+ cursor?: any;
24
28
  };
25
- export type OptionalCursorInput = CursorInput | void;
29
+ type OptionalCursorInput = CursorInput | void;
26
30
  /**
27
31
  * @internal
28
32
  */
29
- export type ExtractCursorType<TInput> = TInput extends CursorInput ? TInput['cursor'] : unknown;
33
+ type ExtractCursorType<TInput> = TInput extends CursorInput ? TInput['cursor'] : unknown;
30
34
  /**
31
35
  * @internal
32
36
  */
33
- export type TRPCInfiniteData<TInput, TOutput> = InfiniteData<TOutput, NonNullable<ExtractCursorType<TInput>> | null>;
37
+ type TRPCInfiniteData<TInput, TOutput> = InfiniteData<TOutput, NonNullable<ExtractCursorType<TInput>> | null>;
34
38
  /**
35
39
  * @public
36
40
  */
37
- export interface TRPCReactRequestOptions extends Omit<TRPCRequestOptions, 'signal'> {
38
- /**
39
- * Opt out of SSR for this query by passing `ssr: false`
40
- */
41
- ssr?: boolean;
42
- /**
43
- * Opt out or into aborting request on unmount
44
- */
45
- abortOnUnmount?: boolean;
41
+ interface TRPCReactRequestOptions extends Omit<TRPCRequestOptions, 'signal'> {
42
+ /**
43
+ * Opt out of SSR for this query by passing `ssr: false`
44
+ */
45
+ ssr?: boolean;
46
+ /**
47
+ * Opt out or into aborting request on unmount
48
+ */
49
+ abortOnUnmount?: boolean;
46
50
  }
47
51
  /**
48
52
  * @public
49
53
  */
50
- export interface TRPCQueryBaseOptions {
51
- /**
52
- * tRPC-related options
53
- */
54
- trpc?: TRPCReactRequestOptions;
54
+ interface TRPCQueryBaseOptions {
55
+ /**
56
+ * tRPC-related options
57
+ */
58
+ trpc?: TRPCReactRequestOptions;
55
59
  }
56
60
  /**
57
61
  * @public
58
62
  */
59
- export interface TRPCQueryOptionsResult {
60
- trpc: {
61
- path: string;
62
- };
63
+ interface TRPCQueryOptionsResult {
64
+ trpc: {
65
+ path: string;
66
+ };
63
67
  }
64
68
  /**
65
69
  * @public
66
70
  */
67
- export type QueryType = 'any' | 'infinite' | 'query';
71
+ type QueryType = 'any' | 'infinite' | 'query';
68
72
  /**
69
73
  * @public
70
74
  */
71
- export type TRPCQueryKey = [
72
- readonly string[],
73
- {
74
- input?: unknown;
75
- type?: Exclude<QueryType, 'any'>;
76
- }?
77
- ];
75
+ type TRPCQueryKey = [readonly string[], {
76
+ input?: unknown;
77
+ type?: Exclude<QueryType, 'any'>;
78
+ }?];
78
79
  /**
79
80
  * @public
80
81
  */
81
- export type TRPCMutationKey = [readonly string[]];
82
- export {};
82
+ type TRPCMutationKey = [readonly string[]]; //#endregion
83
+ export { ExtractCursorType, OptionalCursorInput, QueryType, ResolverDef, TRPCInfiniteData, TRPCMutationKey, TRPCQueryBaseOptions, TRPCQueryKey, TRPCQueryOptionsResult, TRPCReactRequestOptions, WithRequired };
83
84
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/internals/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD;;;GAGG;AACH,MAAM,MAAM,YAAY,CAAC,IAAI,EAAE,IAAI,SAAS,MAAM,IAAI,IAAI,IAAI,GAAG;KAC9D,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,GAAG,CAAC;IACX,MAAM,EAAE,GAAG,CAAC;IACZ,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,GAAG,CAAC;CACjB,CAAC;AAEF;;GAEG;AACH,KAAK,WAAW,GAAG;IAAE,MAAM,CAAC,EAAE,GAAG,CAAA;CAAE,CAAC;AACpC,MAAM,MAAM,mBAAmB,GAAG,WAAW,GAAG,IAAI,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,MAAM,IAAI,MAAM,SAAS,WAAW,GAC9D,MAAM,CAAC,QAAQ,CAAC,GAChB,OAAO,CAAC;AAEZ;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAAC,MAAM,EAAE,OAAO,IAAI,YAAY,CAC1D,OAAO,EACP,WAAW,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAC9C,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,uBAEf,SAAQ,IAAI,CAAC,kBAAkB,EAAE,QAAQ,CAAC;IAC1C;;OAEG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;IACd;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,IAAI,CAAC,EAAE,uBAAuB,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,UAAU,GAAG,OAAO,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,SAAS,MAAM,EAAE;IACjB;QAAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;KAAE,CAAC;CACvD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,SAAS,MAAM,EAAE,CAAC,CAAC"}
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/internals/types.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;KAOY,sCAAsC,QAAQ,eAClD,SAAS,KAAK,IADtB;;;;AACQ,KAMI,WAAA,GANJ;EAAI,KAAK,EAAA,GAAA;EAAI,MAAC,EAAA,GAAA;EAAC,WAAA,EAAA,OAAA;;;;AAMvB;;KAUK,WAAA;;AAHL,CAAA;AAIY,KAAA,mBAAA,GAAsB,WAAA,GAAW,IAAA;;;;AAKjC,KAAA,iBAAiB,CAAA,MAAA,CAAA,GAAW,MAAX,SAA0B,WAA1B,GACzB,MADyB,CAAA,QAAA,CAAA,GAAA,OAAA;;;;AACzB,KAMQ,gBANR,CAAA,MAAA,EAAA,OAAA,CAAA,GAM4C,YAN5C,CAOF,OAPE,EAQF,WARE,CAQU,iBARV,CAQ4B,MAR5B,CAAA,CAAA,GAAA,IAAA,CAAA;AAAM;;;UAcO,uBAAA,SAEP,KAAK;EAVH;;;EACH,GACuB,CAAA,EAAA,OAAA;EAAM;;;EAFsB,cAAA,CAAA,EAAA,OAAA;;;;AAQ5D;AAEE,UAce,oBAAA,CAdf;EAAA;;AAAY;SAkBL;;;AAJT;;UAUiB,sBAAA;;IAAA,IAAA,EAAA,MAAA;;;;AASjB;;KAAY,SAAA;;AAKZ;;AAEoC,KAFxB,YAAA,GAEwB,CAAS,SAAjB,MAAA,EAAA,EAAO;;SAAP,QAAQ;GAMpC;;;;KAAY,eAAA"}
@@ -1,118 +1,89 @@
1
- 'use strict';
2
-
3
- var reactQuery = require('@tanstack/react-query');
4
- var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import');
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
2
+ const __tanstack_react_query = require_rolldown_runtime.__toESM(require("@tanstack/react-query"));
3
+ const __trpc_server_unstable_core_do_not_import = require_rolldown_runtime.__toESM(require("@trpc/server/unstable-core-do-not-import"));
5
4
 
5
+ //#region src/internals/utils.ts
6
6
  /**
7
- * @internal
8
- */ function createTRPCOptionsResult(value) {
9
- const path = value.path.join('.');
10
- return {
11
- path
12
- };
7
+ * @internal
8
+ */
9
+ function createTRPCOptionsResult(value) {
10
+ const path = value.path.join(".");
11
+ return { path };
13
12
  }
14
13
  /**
15
- * @internal
16
- */ function getClientArgs(queryKey, opts, infiniteParams) {
17
- const path = queryKey[0];
18
- let input = queryKey[1]?.input;
19
- if (infiniteParams) {
20
- input = {
21
- ...input ?? {},
22
- ...infiniteParams.pageParam !== undefined ? {
23
- cursor: infiniteParams.pageParam
24
- } : {},
25
- direction: infiniteParams.direction
26
- };
27
- }
28
- return [
29
- path.join('.'),
30
- input,
31
- opts?.trpc
32
- ];
14
+ * @internal
15
+ */
16
+ function getClientArgs(queryKey, opts, infiniteParams) {
17
+ const path = queryKey[0];
18
+ let input = queryKey[1]?.input;
19
+ if (infiniteParams) input = {
20
+ ...input ?? {},
21
+ ...infiniteParams.pageParam !== void 0 ? { cursor: infiniteParams.pageParam } : {},
22
+ direction: infiniteParams.direction
23
+ };
24
+ return [
25
+ path.join("."),
26
+ input,
27
+ opts?.trpc
28
+ ];
33
29
  }
34
30
  /**
35
- * @internal
36
- */ async function buildQueryFromAsyncIterable(asyncIterable, queryClient, queryKey) {
37
- const queryCache = queryClient.getQueryCache();
38
- const query = queryCache.build(queryClient, {
39
- queryKey
40
- });
41
- query.setState({
42
- data: [],
43
- status: 'success'
44
- });
45
- const aggregate = [];
46
- for await (const value of asyncIterable){
47
- aggregate.push(value);
48
- query.setState({
49
- data: [
50
- ...aggregate
51
- ]
52
- });
53
- }
54
- return aggregate;
31
+ * @internal
32
+ */
33
+ async function buildQueryFromAsyncIterable(asyncIterable, queryClient, queryKey) {
34
+ const queryCache = queryClient.getQueryCache();
35
+ const query = queryCache.build(queryClient, { queryKey });
36
+ query.setState({
37
+ data: [],
38
+ status: "success"
39
+ });
40
+ const aggregate = [];
41
+ for await (const value of asyncIterable) {
42
+ aggregate.push(value);
43
+ query.setState({ data: [...aggregate] });
44
+ }
45
+ return aggregate;
55
46
  }
56
47
  /**
57
- * To allow easy interactions with groups of related queries, such as
58
- * invalidating all queries of a router, we use an array as the path when
59
- * storing in tanstack query.
60
- *
61
- * @internal
62
- */ function getQueryKeyInternal(path, input, type) {
63
- // Construct a query key that is easy to destructure and flexible for
64
- // partial selecting etc.
65
- // https://github.com/trpc/trpc/issues/3128
66
- // some parts of the path may be dot-separated, split them up
67
- const splitPath = path.flatMap((part)=>part.split('.'));
68
- if (!input && (!type || type === 'any')) {
69
- // this matches also all mutations (see `getMutationKeyInternal`)
70
- // for `utils.invalidate()` to match all queries (including vanilla react-query)
71
- // we don't want nested array if path is empty, i.e. `[]` instead of `[[]]`
72
- return splitPath.length ? [
73
- splitPath
74
- ] : [];
75
- }
76
- if (type === 'infinite' && unstableCoreDoNotImport.isObject(input) && ('direction' in input || 'cursor' in input)) {
77
- const { cursor: _, direction: __, ...inputWithoutCursorAndDirection } = input;
78
- return [
79
- splitPath,
80
- {
81
- input: inputWithoutCursorAndDirection,
82
- type: 'infinite'
83
- }
84
- ];
85
- }
86
- return [
87
- splitPath,
88
- {
89
- ...typeof input !== 'undefined' && input !== reactQuery.skipToken && {
90
- input: input
91
- },
92
- ...type && type !== 'any' && {
93
- type: type
94
- }
95
- }
96
- ];
48
+ * To allow easy interactions with groups of related queries, such as
49
+ * invalidating all queries of a router, we use an array as the path when
50
+ * storing in tanstack query.
51
+ *
52
+ * @internal
53
+ */
54
+ function getQueryKeyInternal(path, input, type) {
55
+ const splitPath = path.flatMap((part) => part.split("."));
56
+ if (!input && (!type || type === "any")) return splitPath.length ? [splitPath] : [];
57
+ if (type === "infinite" && (0, __trpc_server_unstable_core_do_not_import.isObject)(input) && ("direction" in input || "cursor" in input)) {
58
+ const { cursor: _, direction: __,...inputWithoutCursorAndDirection } = input;
59
+ return [splitPath, {
60
+ input: inputWithoutCursorAndDirection,
61
+ type: "infinite"
62
+ }];
63
+ }
64
+ return [splitPath, {
65
+ ...typeof input !== "undefined" && input !== __tanstack_react_query.skipToken && { input },
66
+ ...type && type !== "any" && { type }
67
+ }];
97
68
  }
98
69
  /**
99
- * @internal
100
- */ function getMutationKeyInternal(path) {
101
- // some parts of the path may be dot-separated, split them up
102
- const splitPath = path.flatMap((part)=>part.split('.'));
103
- return splitPath.length ? [
104
- splitPath
105
- ] : [];
70
+ * @internal
71
+ */
72
+ function getMutationKeyInternal(path) {
73
+ const splitPath = path.flatMap((part) => part.split("."));
74
+ return splitPath.length ? [splitPath] : [];
106
75
  }
107
76
  /**
108
- * @internal
109
- */ function unwrapLazyArg(valueOrLazy) {
110
- return unstableCoreDoNotImport.isFunction(valueOrLazy) ? valueOrLazy() : valueOrLazy;
77
+ * @internal
78
+ */
79
+ function unwrapLazyArg(valueOrLazy) {
80
+ return (0, __trpc_server_unstable_core_do_not_import.isFunction)(valueOrLazy) ? valueOrLazy() : valueOrLazy;
111
81
  }
112
82
 
83
+ //#endregion
113
84
  exports.buildQueryFromAsyncIterable = buildQueryFromAsyncIterable;
114
85
  exports.createTRPCOptionsResult = createTRPCOptionsResult;
115
86
  exports.getClientArgs = getClientArgs;
116
87
  exports.getMutationKeyInternal = getMutationKeyInternal;
117
88
  exports.getQueryKeyInternal = getQueryKeyInternal;
118
- exports.unwrapLazyArg = unwrapLazyArg;
89
+ exports.unwrapLazyArg = unwrapLazyArg;
@@ -1,111 +1,84 @@
1
- import { skipToken } from '@tanstack/react-query';
2
- import { isObject, isFunction } from '@trpc/server/unstable-core-do-not-import';
1
+ import { skipToken } from "@tanstack/react-query";
2
+ import { isFunction, isObject } from "@trpc/server/unstable-core-do-not-import";
3
3
 
4
+ //#region src/internals/utils.ts
4
5
  /**
5
- * @internal
6
- */ function createTRPCOptionsResult(value) {
7
- const path = value.path.join('.');
8
- return {
9
- path
10
- };
6
+ * @internal
7
+ */
8
+ function createTRPCOptionsResult(value) {
9
+ const path = value.path.join(".");
10
+ return { path };
11
11
  }
12
12
  /**
13
- * @internal
14
- */ function getClientArgs(queryKey, opts, infiniteParams) {
15
- const path = queryKey[0];
16
- let input = queryKey[1]?.input;
17
- if (infiniteParams) {
18
- input = {
19
- ...input ?? {},
20
- ...infiniteParams.pageParam !== undefined ? {
21
- cursor: infiniteParams.pageParam
22
- } : {},
23
- direction: infiniteParams.direction
24
- };
25
- }
26
- return [
27
- path.join('.'),
28
- input,
29
- opts?.trpc
30
- ];
13
+ * @internal
14
+ */
15
+ function getClientArgs(queryKey, opts, infiniteParams) {
16
+ const path = queryKey[0];
17
+ let input = queryKey[1]?.input;
18
+ if (infiniteParams) input = {
19
+ ...input ?? {},
20
+ ...infiniteParams.pageParam !== void 0 ? { cursor: infiniteParams.pageParam } : {},
21
+ direction: infiniteParams.direction
22
+ };
23
+ return [
24
+ path.join("."),
25
+ input,
26
+ opts?.trpc
27
+ ];
31
28
  }
32
29
  /**
33
- * @internal
34
- */ async function buildQueryFromAsyncIterable(asyncIterable, queryClient, queryKey) {
35
- const queryCache = queryClient.getQueryCache();
36
- const query = queryCache.build(queryClient, {
37
- queryKey
38
- });
39
- query.setState({
40
- data: [],
41
- status: 'success'
42
- });
43
- const aggregate = [];
44
- for await (const value of asyncIterable){
45
- aggregate.push(value);
46
- query.setState({
47
- data: [
48
- ...aggregate
49
- ]
50
- });
51
- }
52
- return aggregate;
30
+ * @internal
31
+ */
32
+ async function buildQueryFromAsyncIterable(asyncIterable, queryClient, queryKey) {
33
+ const queryCache = queryClient.getQueryCache();
34
+ const query = queryCache.build(queryClient, { queryKey });
35
+ query.setState({
36
+ data: [],
37
+ status: "success"
38
+ });
39
+ const aggregate = [];
40
+ for await (const value of asyncIterable) {
41
+ aggregate.push(value);
42
+ query.setState({ data: [...aggregate] });
43
+ }
44
+ return aggregate;
53
45
  }
54
46
  /**
55
- * To allow easy interactions with groups of related queries, such as
56
- * invalidating all queries of a router, we use an array as the path when
57
- * storing in tanstack query.
58
- *
59
- * @internal
60
- */ function getQueryKeyInternal(path, input, type) {
61
- // Construct a query key that is easy to destructure and flexible for
62
- // partial selecting etc.
63
- // https://github.com/trpc/trpc/issues/3128
64
- // some parts of the path may be dot-separated, split them up
65
- const splitPath = path.flatMap((part)=>part.split('.'));
66
- if (!input && (!type || type === 'any')) {
67
- // this matches also all mutations (see `getMutationKeyInternal`)
68
- // for `utils.invalidate()` to match all queries (including vanilla react-query)
69
- // we don't want nested array if path is empty, i.e. `[]` instead of `[[]]`
70
- return splitPath.length ? [
71
- splitPath
72
- ] : [];
73
- }
74
- if (type === 'infinite' && isObject(input) && ('direction' in input || 'cursor' in input)) {
75
- const { cursor: _, direction: __, ...inputWithoutCursorAndDirection } = input;
76
- return [
77
- splitPath,
78
- {
79
- input: inputWithoutCursorAndDirection,
80
- type: 'infinite'
81
- }
82
- ];
83
- }
84
- return [
85
- splitPath,
86
- {
87
- ...typeof input !== 'undefined' && input !== skipToken && {
88
- input: input
89
- },
90
- ...type && type !== 'any' && {
91
- type: type
92
- }
93
- }
94
- ];
47
+ * To allow easy interactions with groups of related queries, such as
48
+ * invalidating all queries of a router, we use an array as the path when
49
+ * storing in tanstack query.
50
+ *
51
+ * @internal
52
+ */
53
+ function getQueryKeyInternal(path, input, type) {
54
+ const splitPath = path.flatMap((part) => part.split("."));
55
+ if (!input && (!type || type === "any")) return splitPath.length ? [splitPath] : [];
56
+ if (type === "infinite" && isObject(input) && ("direction" in input || "cursor" in input)) {
57
+ const { cursor: _, direction: __,...inputWithoutCursorAndDirection } = input;
58
+ return [splitPath, {
59
+ input: inputWithoutCursorAndDirection,
60
+ type: "infinite"
61
+ }];
62
+ }
63
+ return [splitPath, {
64
+ ...typeof input !== "undefined" && input !== skipToken && { input },
65
+ ...type && type !== "any" && { type }
66
+ }];
95
67
  }
96
68
  /**
97
- * @internal
98
- */ function getMutationKeyInternal(path) {
99
- // some parts of the path may be dot-separated, split them up
100
- const splitPath = path.flatMap((part)=>part.split('.'));
101
- return splitPath.length ? [
102
- splitPath
103
- ] : [];
69
+ * @internal
70
+ */
71
+ function getMutationKeyInternal(path) {
72
+ const splitPath = path.flatMap((part) => part.split("."));
73
+ return splitPath.length ? [splitPath] : [];
104
74
  }
105
75
  /**
106
- * @internal
107
- */ function unwrapLazyArg(valueOrLazy) {
108
- return isFunction(valueOrLazy) ? valueOrLazy() : valueOrLazy;
76
+ * @internal
77
+ */
78
+ function unwrapLazyArg(valueOrLazy) {
79
+ return isFunction(valueOrLazy) ? valueOrLazy() : valueOrLazy;
109
80
  }
110
81
 
82
+ //#endregion
111
83
  export { buildQueryFromAsyncIterable, createTRPCOptionsResult, getClientArgs, getMutationKeyInternal, getQueryKeyInternal, unwrapLazyArg };
84
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","names":["value: {\n path: readonly string[];\n}","queryKey: TRPCQueryKey","opts: TOptions","infiniteParams?: {\n pageParam: any;\n direction: 'forward' | 'backward';\n }","asyncIterable: AsyncIterable<unknown>","queryClient: QueryClient","aggregate: unknown[]","path: readonly string[]","input?: unknown","type?: QueryType","valueOrLazy: T | (() => T)"],"sources":["../../src/internals/utils.ts"],"sourcesContent":["import { skipToken, type QueryClient } from '@tanstack/react-query';\nimport { isFunction, isObject } from '@trpc/server/unstable-core-do-not-import';\nimport type {\n QueryType,\n TRPCMutationKey,\n TRPCQueryKey,\n TRPCQueryOptionsResult,\n} from './types';\n\n/**\n * @internal\n */\nexport function createTRPCOptionsResult(value: {\n path: readonly string[];\n}): TRPCQueryOptionsResult['trpc'] {\n const path = value.path.join('.');\n\n return {\n path,\n };\n}\n\n/**\n * @internal\n */\nexport function getClientArgs<TOptions>(\n queryKey: TRPCQueryKey,\n opts: TOptions,\n infiniteParams?: {\n pageParam: any;\n direction: 'forward' | 'backward';\n },\n) {\n const path = queryKey[0];\n let input = queryKey[1]?.input;\n if (infiniteParams) {\n input = {\n ...(input ?? {}),\n ...(infiniteParams.pageParam !== undefined\n ? { cursor: infiniteParams.pageParam }\n : {}),\n direction: infiniteParams.direction,\n };\n }\n return [path.join('.'), input, (opts as any)?.trpc] as const;\n}\n\n/**\n * @internal\n */\nexport async function buildQueryFromAsyncIterable(\n asyncIterable: AsyncIterable<unknown>,\n queryClient: QueryClient,\n queryKey: TRPCQueryKey,\n) {\n const queryCache = queryClient.getQueryCache();\n\n const query = queryCache.build(queryClient, {\n queryKey,\n });\n\n query.setState({\n data: [],\n status: 'success',\n });\n\n const aggregate: unknown[] = [];\n for await (const value of asyncIterable) {\n aggregate.push(value);\n\n query.setState({\n data: [...aggregate],\n });\n }\n return aggregate;\n}\n\n/**\n * To allow easy interactions with groups of related queries, such as\n * invalidating all queries of a router, we use an array as the path when\n * storing in tanstack query.\n *\n * @internal\n */\nexport function getQueryKeyInternal(\n path: readonly string[],\n input?: unknown,\n type?: QueryType,\n): TRPCQueryKey {\n // Construct a query key that is easy to destructure and flexible for\n // partial selecting etc.\n // https://github.com/trpc/trpc/issues/3128\n\n // some parts of the path may be dot-separated, split them up\n const splitPath = path.flatMap((part) => part.split('.'));\n\n if (!input && (!type || type === 'any')) {\n // this matches also all mutations (see `getMutationKeyInternal`)\n\n // for `utils.invalidate()` to match all queries (including vanilla react-query)\n // we don't want nested array if path is empty, i.e. `[]` instead of `[[]]`\n return splitPath.length ? [splitPath] : ([] as unknown as TRPCQueryKey);\n }\n\n if (\n type === 'infinite' &&\n isObject(input) &&\n ('direction' in input || 'cursor' in input)\n ) {\n const {\n cursor: _,\n direction: __,\n ...inputWithoutCursorAndDirection\n } = input;\n return [\n splitPath,\n {\n input: inputWithoutCursorAndDirection,\n type: 'infinite',\n },\n ];\n }\n\n return [\n splitPath,\n {\n ...(typeof input !== 'undefined' &&\n input !== skipToken && { input: input }),\n ...(type && type !== 'any' && { type: type }),\n },\n ];\n}\n\n/**\n * @internal\n */\nexport function getMutationKeyInternal(\n path: readonly string[],\n): TRPCMutationKey {\n // some parts of the path may be dot-separated, split them up\n const splitPath = path.flatMap((part) => part.split('.'));\n\n return splitPath.length ? [splitPath] : ([] as unknown as TRPCMutationKey);\n}\n\n/**\n * @internal\n */\nexport function unwrapLazyArg<T>(valueOrLazy: T | (() => T)): T {\n return (isFunction(valueOrLazy) ? valueOrLazy() : valueOrLazy) as T;\n}\n"],"mappings":";;;;;;;AAYA,SAAgB,wBAAwBA,OAEL;CACjC,MAAM,OAAO,MAAM,KAAK,KAAK,IAAI;AAEjC,QAAO,EACL,KACD;AACF;;;;AAKD,SAAgB,cACdC,UACAC,MACAC,gBAIA;CACA,MAAM,OAAO,SAAS;CACtB,IAAI,QAAQ,SAAS,IAAI;AACzB,KAAI,eACF,SAAQ;EACN,GAAI,SAAS,CAAE;EACf,GAAI,eAAe,uBACf,EAAE,QAAQ,eAAe,UAAW,IACpC,CAAE;EACN,WAAW,eAAe;CAC3B;AAEH,QAAO;EAAC,KAAK,KAAK,IAAI;EAAE;EAAQ,MAAc;CAAK;AACpD;;;;AAKD,eAAsB,4BACpBC,eACAC,aACAJ,UACA;CACA,MAAM,aAAa,YAAY,eAAe;CAE9C,MAAM,QAAQ,WAAW,MAAM,aAAa,EAC1C,SACD,EAAC;AAEF,OAAM,SAAS;EACb,MAAM,CAAE;EACR,QAAQ;CACT,EAAC;CAEF,MAAMK,YAAuB,CAAE;AAC/B,YAAW,MAAM,SAAS,eAAe;AACvC,YAAU,KAAK,MAAM;AAErB,QAAM,SAAS,EACb,MAAM,CAAC,GAAG,SAAU,EACrB,EAAC;CACH;AACD,QAAO;AACR;;;;;;;;AASD,SAAgB,oBACdC,MACAC,OACAC,MACc;CAMd,MAAM,YAAY,KAAK,QAAQ,CAAC,SAAS,KAAK,MAAM,IAAI,CAAC;AAEzD,MAAK,WAAW,QAAQ,SAAS,OAK/B,QAAO,UAAU,SAAS,CAAC,SAAU,IAAI,CAAE;AAG7C,KACE,SAAS,cACT,SAAS,MAAM,KACd,eAAe,SAAS,YAAY,QACrC;EACA,MAAM,EACJ,QAAQ,GACR,WAAW,GACX,GAAG,gCACJ,GAAG;AACJ,SAAO,CACL,WACA;GACE,OAAO;GACP,MAAM;EACP,CACF;CACF;AAED,QAAO,CACL,WACA;EACE,UAAW,UAAU,eACnB,UAAU,aAAa,EAAS,MAAO;EACzC,GAAI,QAAQ,SAAS,SAAS,EAAQ,KAAM;CAC7C,CACF;AACF;;;;AAKD,SAAgB,uBACdF,MACiB;CAEjB,MAAM,YAAY,KAAK,QAAQ,CAAC,SAAS,KAAK,MAAM,IAAI,CAAC;AAEzD,QAAO,UAAU,SAAS,CAAC,SAAU,IAAI,CAAE;AAC5C;;;;AAKD,SAAgB,cAAiBG,aAA+B;AAC9D,QAAQ,WAAW,YAAY,GAAG,aAAa,GAAG;AACnD"}