@trpc/react-query 11.0.0-next.92 → 11.0.0-rc.330

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 (109) hide show
  1. package/README.md +4 -4
  2. package/dist/bundle-analysis.json +83 -51
  3. package/dist/createTRPCQueryUtils.d.ts +4 -0
  4. package/dist/createTRPCQueryUtils.d.ts.map +1 -0
  5. package/dist/createTRPCQueryUtils.js +16 -0
  6. package/dist/createTRPCQueryUtils.mjs +14 -0
  7. package/dist/createTRPCReact.d.ts +55 -40
  8. package/dist/createTRPCReact.d.ts.map +1 -1
  9. package/dist/createTRPCReact.js +58 -0
  10. package/dist/createTRPCReact.mjs +36 -0
  11. package/dist/index.d.ts +2 -1
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +8 -36
  14. package/dist/index.mjs +3 -35
  15. package/dist/internals/context.d.ts +23 -18
  16. package/dist/internals/context.d.ts.map +1 -1
  17. package/dist/internals/context.js +33 -0
  18. package/dist/internals/context.mjs +11 -0
  19. package/dist/internals/getClientArgs.d.ts +8 -2
  20. package/dist/internals/getClientArgs.d.ts.map +1 -1
  21. package/dist/internals/getClientArgs.js +24 -0
  22. package/dist/internals/getClientArgs.mjs +22 -0
  23. package/dist/internals/getQueryKey.d.ts +8 -13
  24. package/dist/internals/getQueryKey.d.ts.map +1 -1
  25. package/dist/internals/getQueryKey.js +60 -0
  26. package/dist/internals/getQueryKey.mjs +57 -0
  27. package/dist/internals/useHookResult.d.ts +4 -6
  28. package/dist/internals/useHookResult.d.ts.map +1 -1
  29. package/dist/internals/useHookResult.js +35 -0
  30. package/dist/internals/useHookResult.mjs +14 -0
  31. package/dist/internals/useQueries.d.ts +32 -4
  32. package/dist/internals/useQueries.d.ts.map +1 -1
  33. package/dist/server/index.js +2 -103
  34. package/dist/server/index.mjs +1 -104
  35. package/dist/server/ssgProxy.d.ts +21 -21
  36. package/dist/server/ssgProxy.d.ts.map +1 -1
  37. package/dist/server/ssgProxy.js +109 -0
  38. package/dist/server/ssgProxy.mjs +107 -0
  39. package/dist/shared/hooks/createHooksInternal.d.ts +8 -31
  40. package/dist/shared/hooks/createHooksInternal.d.ts.map +1 -1
  41. package/dist/{createHooksInternal-e2034194.js → shared/hooks/createHooksInternal.js} +98 -226
  42. package/dist/{createHooksInternal-3d8ebfcf.mjs → shared/hooks/createHooksInternal.mjs} +70 -210
  43. package/dist/shared/hooks/types.d.ts +11 -7
  44. package/dist/shared/hooks/types.d.ts.map +1 -1
  45. package/dist/shared/index.d.ts +2 -2
  46. package/dist/shared/index.d.ts.map +1 -1
  47. package/dist/shared/index.js +14 -15
  48. package/dist/shared/index.mjs +7 -7
  49. package/dist/shared/polymorphism/mutationLike.d.ts +6 -7
  50. package/dist/shared/polymorphism/mutationLike.d.ts.map +1 -1
  51. package/dist/shared/polymorphism/queryLike.d.ts +10 -7
  52. package/dist/shared/polymorphism/queryLike.d.ts.map +1 -1
  53. package/dist/shared/polymorphism/routerLike.d.ts +6 -6
  54. package/dist/shared/polymorphism/routerLike.d.ts.map +1 -1
  55. package/dist/shared/polymorphism/utilsLike.d.ts +3 -3
  56. package/dist/shared/polymorphism/utilsLike.d.ts.map +1 -1
  57. package/dist/shared/proxy/decorationProxy.d.ts +2 -2
  58. package/dist/shared/proxy/decorationProxy.d.ts.map +1 -1
  59. package/dist/shared/proxy/decorationProxy.js +31 -0
  60. package/dist/shared/proxy/decorationProxy.mjs +29 -0
  61. package/dist/shared/proxy/useQueriesProxy.d.ts +14 -8
  62. package/dist/shared/proxy/useQueriesProxy.d.ts.map +1 -1
  63. package/dist/shared/proxy/useQueriesProxy.js +25 -0
  64. package/dist/shared/proxy/useQueriesProxy.mjs +23 -0
  65. package/dist/shared/proxy/utilsProxy.d.ts +28 -24
  66. package/dist/shared/proxy/utilsProxy.d.ts.map +1 -1
  67. package/dist/shared/proxy/utilsProxy.js +89 -0
  68. package/dist/shared/proxy/utilsProxy.mjs +85 -0
  69. package/dist/shared/queryClient.d.ts +2 -1
  70. package/dist/shared/queryClient.d.ts.map +1 -1
  71. package/dist/{queryClient-4d766c0c.mjs → shared/queryClient.mjs} +1 -1
  72. package/dist/shared/types.d.ts +2 -2
  73. package/dist/shared/types.d.ts.map +1 -1
  74. package/dist/utils/createUtilityFunctions.d.ts +23 -0
  75. package/dist/utils/createUtilityFunctions.d.ts.map +1 -0
  76. package/dist/utils/createUtilityFunctions.js +100 -0
  77. package/dist/utils/createUtilityFunctions.mjs +98 -0
  78. package/dist/utils/inferReactQueryProcedure.d.ts +11 -10
  79. package/dist/utils/inferReactQueryProcedure.d.ts.map +1 -1
  80. package/package.json +18 -18
  81. package/src/createTRPCQueryUtils.tsx +11 -0
  82. package/src/createTRPCReact.tsx +139 -163
  83. package/src/index.ts +6 -1
  84. package/src/internals/context.tsx +27 -18
  85. package/src/internals/getClientArgs.ts +16 -4
  86. package/src/internals/getQueryKey.ts +51 -62
  87. package/src/internals/useHookResult.ts +12 -13
  88. package/src/internals/useQueries.ts +129 -4
  89. package/src/server/ssgProxy.ts +59 -57
  90. package/src/shared/hooks/createHooksInternal.tsx +115 -246
  91. package/src/shared/hooks/types.ts +15 -7
  92. package/src/shared/index.ts +5 -2
  93. package/src/shared/polymorphism/mutationLike.ts +21 -15
  94. package/src/shared/polymorphism/queryLike.ts +34 -14
  95. package/src/shared/polymorphism/routerLike.ts +29 -15
  96. package/src/shared/polymorphism/utilsLike.ts +6 -3
  97. package/src/shared/proxy/decorationProxy.ts +3 -3
  98. package/src/shared/proxy/useQueriesProxy.ts +65 -28
  99. package/src/shared/proxy/utilsProxy.ts +113 -86
  100. package/src/shared/queryClient.ts +2 -1
  101. package/src/shared/types.ts +5 -2
  102. package/src/utils/createUtilityFunctions.ts +137 -0
  103. package/src/utils/inferReactQueryProcedure.ts +38 -28
  104. package/dist/createHooksInternal-dce6e141.js +0 -435
  105. package/dist/queryClient-1c8d7d8a.js +0 -8
  106. package/dist/utilsProxy-00894da2.mjs +0 -121
  107. package/dist/utilsProxy-27bd93c1.js +0 -128
  108. package/dist/utilsProxy-7e396600.js +0 -114
  109. /package/dist/{queryClient-358a9a75.js → shared/queryClient.js} +0 -0
@@ -1,29 +1,43 @@
1
- import {
1
+ import type {
2
2
  AnyMutationProcedure,
3
- AnyProcedure,
4
3
  AnyQueryProcedure,
5
- AnyRootConfig,
4
+ AnyRootTypes,
6
5
  AnyRouter,
7
- } from '@trpc/server';
8
- import { MutationLike } from './mutationLike';
9
- import { QueryLike } from './queryLike';
6
+ RouterRecord,
7
+ } from '@trpc/server/unstable-core-do-not-import';
8
+ import type { MutationLike } from './mutationLike';
9
+ import type { QueryLike } from './queryLike';
10
10
 
11
11
  /**
12
12
  * Use to describe a route path which matches a given route's interface
13
13
  */
14
14
  export type RouterLike<TRouter extends AnyRouter> = RouterLikeInner<
15
- TRouter['_def']['_config'],
15
+ TRouter['_def']['_config']['$types'],
16
16
  TRouter['_def']['procedures']
17
17
  >;
18
18
  export type RouterLikeInner<
19
- TConfig extends AnyRootConfig,
20
- TProcedures extends AnyProcedure,
19
+ TRoot extends AnyRootTypes,
20
+ TRecord extends RouterRecord,
21
21
  > = {
22
- [TKey in keyof TProcedures]: TProcedures[TKey] extends AnyRouter
23
- ? RouterLikeInner<TConfig, TProcedures[TKey]['_def']['record']>
24
- : TProcedures[TKey] extends AnyQueryProcedure
25
- ? QueryLike<TConfig, TProcedures[TKey]>
26
- : TProcedures[TKey] extends AnyMutationProcedure
27
- ? MutationLike<TConfig, TProcedures[TKey]>
22
+ [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value
23
+ ? $Value extends RouterRecord
24
+ ? RouterLikeInner<TRoot, $Value>
25
+ : $Value extends AnyQueryProcedure
26
+ ? QueryLike<TRoot, $Value>
27
+ : $Value extends AnyMutationProcedure
28
+ ? MutationLike<TRoot, $Value>
29
+ : never
28
30
  : never;
29
31
  };
32
+
33
+ // /**
34
+ // * Use to describe a route path which matches a given route's interface
35
+ // */
36
+ // export type RouterLike<TRouter extends AnyRouter> = RouterLikeInner<
37
+ // TRouter['_def']['_config']['$types'],
38
+ // TRouter['_def']['procedures']
39
+ // >;
40
+ // export type RouterLikeInner<
41
+ // TRoot extends AnyRootTypes,
42
+ // TRecord extends RouterRecord,
43
+ // > = DecorateRouterRecord<TRoot, TRecord>;
@@ -1,8 +1,11 @@
1
- import { AnyRouter } from '@trpc/server';
2
- import { DecoratedProcedureUtilsRecord } from '../proxy/utilsProxy';
1
+ import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
2
+ import type { DecoratedProcedureUtilsRecord } from '../proxy/utilsProxy';
3
3
 
4
4
  /**
5
5
  * Use to describe a Utils/Context path which matches the given route's interface
6
6
  */
7
7
  export type UtilsLike<TRouter extends AnyRouter> =
8
- DecoratedProcedureUtilsRecord<TRouter>;
8
+ DecoratedProcedureUtilsRecord<
9
+ TRouter['_def']['_config']['$types'],
10
+ TRouter['_def']['record']
11
+ >;
@@ -1,6 +1,6 @@
1
- import { AnyRouter } from '@trpc/server';
2
- import { createRecursiveProxy } from '@trpc/server/shared';
3
- import { CreateReactQueryHooks } from '../hooks/createHooksInternal';
1
+ import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
2
+ import { createRecursiveProxy } from '@trpc/server/unstable-core-do-not-import';
3
+ import type { CreateReactQueryHooks } from '../hooks/createHooksInternal';
4
4
 
5
5
  /**
6
6
  * Create proxy for decorating procedures
@@ -1,50 +1,84 @@
1
- import { QueryOptions } from '@tanstack/react-query';
2
- import { TRPCClientError, TRPCUntypedClient } from '@trpc/client';
3
- import {
1
+ import type { QueryOptions } from '@tanstack/react-query';
2
+ import type { TRPCClientError, TRPCUntypedClient } from '@trpc/client';
3
+ import type {
4
4
  AnyProcedure,
5
5
  AnyQueryProcedure,
6
- AnyRootConfig,
6
+ AnyRootTypes,
7
7
  AnyRouter,
8
- Filter,
9
8
  inferProcedureInput,
10
- } from '@trpc/server';
11
- import {
12
- createRecursiveProxy,
13
9
  inferTransformedProcedureOutput,
14
- } from '@trpc/server/shared';
10
+ RouterRecord,
11
+ } from '@trpc/server/unstable-core-do-not-import';
12
+ import { createRecursiveProxy } from '@trpc/server/unstable-core-do-not-import';
15
13
  import { getQueryKeyInternal } from '../../internals/getQueryKey';
16
- import { TrpcQueryOptionsForUseQueries } from '../../internals/useQueries';
17
- import { TRPCUseQueryBaseOptions } from '../hooks/types';
14
+ import type {
15
+ TrpcQueryOptionsForUseQueries,
16
+ TrpcQueryOptionsForUseSuspenseQueries,
17
+ } from '../../internals/useQueries';
18
+ import type { TRPCUseQueryBaseOptions } from '../hooks/types';
18
19
 
19
20
  type GetQueryOptions<
20
- TConfig extends AnyRootConfig,
21
+ TRoot extends AnyRootTypes,
21
22
  TProcedure extends AnyProcedure,
22
- > = <TData = inferTransformedProcedureOutput<TConfig, TProcedure>>(
23
+ > = <TData = inferTransformedProcedureOutput<TRoot, TProcedure>>(
23
24
  input: inferProcedureInput<TProcedure>,
24
25
  opts?: TrpcQueryOptionsForUseQueries<
25
- inferTransformedProcedureOutput<TConfig, TProcedure>,
26
+ inferTransformedProcedureOutput<TRoot, TProcedure>,
26
27
  TData,
27
- TRPCClientError<TConfig>
28
+ TRPCClientError<TRoot>
28
29
  >,
29
30
  ) => TrpcQueryOptionsForUseQueries<
30
- inferTransformedProcedureOutput<TConfig, TProcedure>,
31
+ inferTransformedProcedureOutput<TRoot, TProcedure>,
31
32
  TData,
32
- TRPCClientError<TConfig>
33
+ TRPCClientError<TRoot>
33
34
  >;
34
35
 
35
36
  /**
36
37
  * @internal
37
38
  */
38
- export type UseQueriesProcedureRecord<TRouter extends AnyRouter> = {
39
- [TKey in keyof Filter<
40
- TRouter['_def']['record'],
41
- AnyQueryProcedure | AnyRouter
42
- >]: TRouter['_def']['record'][TKey] extends AnyRouter
43
- ? UseQueriesProcedureRecord<TRouter['_def']['record'][TKey]>
44
- : GetQueryOptions<
45
- TRouter['_def']['_config'],
46
- TRouter['_def']['record'][TKey]
47
- >;
39
+ export type UseQueriesProcedureRecord<
40
+ TRoot extends AnyRootTypes,
41
+ TRecord extends RouterRecord,
42
+ > = {
43
+ [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value
44
+ ? $Value extends RouterRecord
45
+ ? UseQueriesProcedureRecord<TRoot, $Value>
46
+ : $Value extends AnyQueryProcedure
47
+ ? GetQueryOptions<TRoot, $Value>
48
+ : never
49
+ : never;
50
+ };
51
+
52
+ type GetSuspenseQueryOptions<
53
+ TRoot extends AnyRootTypes,
54
+ TProcedure extends AnyQueryProcedure,
55
+ > = <TData = inferTransformedProcedureOutput<TRoot, TProcedure>>(
56
+ input: inferProcedureInput<TProcedure>,
57
+ opts?: TrpcQueryOptionsForUseSuspenseQueries<
58
+ inferTransformedProcedureOutput<TRoot, TProcedure>,
59
+ TData,
60
+ TRPCClientError<TRoot>
61
+ >,
62
+ ) => TrpcQueryOptionsForUseSuspenseQueries<
63
+ inferTransformedProcedureOutput<TRoot, TProcedure>,
64
+ TData,
65
+ TRPCClientError<TRoot>
66
+ >;
67
+
68
+ /**
69
+ * @internal
70
+ */
71
+ export type UseSuspenseQueriesProcedureRecord<
72
+ TRoot extends AnyRootTypes,
73
+ TRecord extends RouterRecord,
74
+ > = {
75
+ [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value
76
+ ? $Value extends RouterRecord
77
+ ? UseSuspenseQueriesProcedureRecord<TRoot, $Value>
78
+ : $Value extends AnyQueryProcedure
79
+ ? GetSuspenseQueryOptions<TRoot, $Value>
80
+ : never
81
+ : never;
48
82
  };
49
83
 
50
84
  /**
@@ -71,5 +105,8 @@ export function createUseQueries<TRouter extends AnyRouter>(
71
105
  };
72
106
 
73
107
  return options;
74
- }) as UseQueriesProcedureRecord<TRouter>;
108
+ }) as UseQueriesProcedureRecord<
109
+ TRouter['_def']['_config']['$types'],
110
+ TRouter['_def']['record']
111
+ >;
75
112
  }
@@ -1,4 +1,4 @@
1
- import {
1
+ import type {
2
2
  CancelOptions,
3
3
  InfiniteData,
4
4
  InvalidateOptions,
@@ -10,37 +10,36 @@ import {
10
10
  SetDataOptions,
11
11
  Updater,
12
12
  } from '@tanstack/react-query';
13
- import { createTRPCClientProxy, TRPCClientError } from '@trpc/client';
14
- import {
13
+ import type { TRPCClientError } from '@trpc/client';
14
+ import { createTRPCClientProxy } from '@trpc/client';
15
+ import type {
15
16
  AnyQueryProcedure,
16
- AnyRootConfig,
17
+ AnyRootTypes,
17
18
  AnyRouter,
18
19
  DeepPartial,
19
- Filter,
20
20
  inferProcedureInput,
21
+ inferTransformedProcedureOutput,
21
22
  ProtectedIntersection,
22
- } from '@trpc/server';
23
+ RouterRecord,
24
+ } from '@trpc/server/unstable-core-do-not-import';
23
25
  import {
24
26
  createFlatProxy,
25
27
  createRecursiveProxy,
26
- inferTransformedProcedureOutput,
27
- } from '@trpc/server/shared';
28
- import {
29
- contextProps,
28
+ } from '@trpc/server/unstable-core-do-not-import';
29
+ import type {
30
30
  DecoratedTRPCContextProps,
31
31
  TRPCContextState,
32
32
  TRPCFetchInfiniteQueryOptions,
33
33
  TRPCFetchQueryOptions,
34
+ TRPCQueryUtils,
34
35
  } from '../../internals/context';
35
- import {
36
- getQueryKeyInternal,
37
- QueryKeyKnown,
38
- QueryType,
39
- } from '../../internals/getQueryKey';
40
- import { ExtractCursorType } from '../hooks/types';
36
+ import { contextProps } from '../../internals/context';
37
+ import type { QueryKeyKnown, QueryType } from '../../internals/getQueryKey';
38
+ import { getQueryKeyInternal } from '../../internals/getQueryKey';
39
+ import type { ExtractCursorType } from '../hooks/types';
41
40
 
42
41
  type DecorateProcedure<
43
- TConfig extends AnyRootConfig,
42
+ TRoot extends AnyRootTypes,
44
43
  TProcedure extends AnyQueryProcedure,
45
44
  > = {
46
45
  /**
@@ -49,10 +48,10 @@ type DecorateProcedure<
49
48
  fetch(
50
49
  input: inferProcedureInput<TProcedure>,
51
50
  opts?: TRPCFetchQueryOptions<
52
- inferTransformedProcedureOutput<TConfig, TProcedure>,
53
- TRPCClientError<TConfig>
51
+ inferTransformedProcedureOutput<TRoot, TProcedure>,
52
+ TRPCClientError<TRoot>
54
53
  >,
55
- ): Promise<inferTransformedProcedureOutput<TConfig, TProcedure>>;
54
+ ): Promise<inferTransformedProcedureOutput<TRoot, TProcedure>>;
56
55
 
57
56
  /**
58
57
  * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchinfinitequery
@@ -61,12 +60,12 @@ type DecorateProcedure<
61
60
  input: inferProcedureInput<TProcedure>,
62
61
  opts?: TRPCFetchInfiniteQueryOptions<
63
62
  inferProcedureInput<TProcedure>,
64
- inferTransformedProcedureOutput<TConfig, TProcedure>,
65
- TRPCClientError<TConfig>
63
+ inferTransformedProcedureOutput<TRoot, TProcedure>,
64
+ TRPCClientError<TRoot>
66
65
  >,
67
66
  ): Promise<
68
67
  InfiniteData<
69
- inferTransformedProcedureOutput<TConfig, TProcedure>,
68
+ inferTransformedProcedureOutput<TRoot, TProcedure>,
70
69
  NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null
71
70
  >
72
71
  >;
@@ -77,8 +76,8 @@ type DecorateProcedure<
77
76
  prefetch(
78
77
  input: inferProcedureInput<TProcedure>,
79
78
  opts?: TRPCFetchQueryOptions<
80
- inferTransformedProcedureOutput<TConfig, TProcedure>,
81
- TRPCClientError<TConfig>
79
+ inferTransformedProcedureOutput<TRoot, TProcedure>,
80
+ TRPCClientError<TRoot>
82
81
  >,
83
82
  ): Promise<void>;
84
83
 
@@ -89,21 +88,21 @@ type DecorateProcedure<
89
88
  input: inferProcedureInput<TProcedure>,
90
89
  opts?: TRPCFetchInfiniteQueryOptions<
91
90
  inferProcedureInput<TProcedure>,
92
- inferTransformedProcedureOutput<TConfig, TProcedure>,
93
- TRPCClientError<TConfig>
91
+ inferTransformedProcedureOutput<TRoot, TProcedure>,
92
+ TRPCClientError<TRoot>
94
93
  >,
95
94
  ): Promise<void>;
96
95
 
97
96
  /**
98
- * @link https://tanstack.com/query/v5/docs/react/reference/QueryClient#queryclientensurequerydata
97
+ * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientensurequerydata
99
98
  */
100
99
  ensureData(
101
100
  input: inferProcedureInput<TProcedure>,
102
101
  opts?: TRPCFetchQueryOptions<
103
- inferTransformedProcedureOutput<TConfig, TProcedure>,
104
- TRPCClientError<TConfig>
102
+ inferTransformedProcedureOutput<TRoot, TProcedure>,
103
+ TRPCClientError<TRoot>
105
104
  >,
106
- ): Promise<inferTransformedProcedureOutput<TConfig, TProcedure>>;
105
+ ): Promise<inferTransformedProcedureOutput<TRoot, TProcedure>>;
107
106
 
108
107
  /**
109
108
  * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientinvalidatequeries
@@ -114,7 +113,7 @@ type DecorateProcedure<
114
113
  predicate?: (
115
114
  query: Query<
116
115
  inferProcedureInput<TProcedure>,
117
- TRPCClientError<TConfig>,
116
+ TRPCClientError<TRoot>,
118
117
  inferProcedureInput<TProcedure>,
119
118
  QueryKeyKnown<
120
119
  inferProcedureInput<TProcedure>,
@@ -162,8 +161,8 @@ type DecorateProcedure<
162
161
  */
163
162
  input: inferProcedureInput<TProcedure>,
164
163
  updater: Updater<
165
- inferTransformedProcedureOutput<TConfig, TProcedure> | undefined,
166
- inferTransformedProcedureOutput<TConfig, TProcedure> | undefined
164
+ inferTransformedProcedureOutput<TRoot, TProcedure> | undefined,
165
+ inferTransformedProcedureOutput<TRoot, TProcedure> | undefined
167
166
  >,
168
167
  options?: SetDataOptions,
169
168
  ): void;
@@ -175,12 +174,12 @@ type DecorateProcedure<
175
174
  input: inferProcedureInput<TProcedure>,
176
175
  updater: Updater<
177
176
  | InfiniteData<
178
- inferTransformedProcedureOutput<TConfig, TProcedure>,
177
+ inferTransformedProcedureOutput<TRoot, TProcedure>,
179
178
  NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null
180
179
  >
181
180
  | undefined,
182
181
  | InfiniteData<
183
- inferTransformedProcedureOutput<TConfig, TProcedure>,
182
+ inferTransformedProcedureOutput<TRoot, TProcedure>,
184
183
  NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null
185
184
  >
186
185
  | undefined
@@ -193,7 +192,7 @@ type DecorateProcedure<
193
192
  */
194
193
  getData(
195
194
  input?: inferProcedureInput<TProcedure>,
196
- ): inferTransformedProcedureOutput<TConfig, TProcedure> | undefined;
195
+ ): inferTransformedProcedureOutput<TRoot, TProcedure> | undefined;
197
196
 
198
197
  /**
199
198
  * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata
@@ -202,7 +201,7 @@ type DecorateProcedure<
202
201
  input?: inferProcedureInput<TProcedure>,
203
202
  ):
204
203
  | InfiniteData<
205
- inferTransformedProcedureOutput<TConfig, TProcedure>,
204
+ inferTransformedProcedureOutput<TRoot, TProcedure>,
206
205
  NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null
207
206
  >
208
207
  | undefined;
@@ -216,7 +215,7 @@ type DecorateRouter = {
216
215
  /**
217
216
  * Invalidate the full router
218
217
  * @link https://trpc.io/docs/v10/useContext#query-invalidation
219
- * @link https://tanstack.com/query/v5/docs/react/guides/query-invalidation
218
+ * @link https://tanstack.com/query/v5/docs/framework/react/guides/query-invalidation
220
219
  */
221
220
  invalidate(
222
221
  input?: undefined,
@@ -228,20 +227,19 @@ type DecorateRouter = {
228
227
  /**
229
228
  * @internal
230
229
  */
231
- export type DecoratedProcedureUtilsRecord<TRouter extends AnyRouter> =
232
- DecorateRouter & {
233
- [TKey in keyof Filter<
234
- TRouter['_def']['record'],
235
- AnyQueryProcedure | AnyRouter
236
- >]: TRouter['_def']['record'][TKey] extends AnyRouter
237
- ? DecoratedProcedureUtilsRecord<TRouter['_def']['record'][TKey]> &
238
- DecorateRouter
230
+ export type DecoratedProcedureUtilsRecord<
231
+ TRoot extends AnyRootTypes,
232
+ TRecord extends RouterRecord,
233
+ > = DecorateRouter & {
234
+ [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value
235
+ ? $Value extends RouterRecord
236
+ ? DecoratedProcedureUtilsRecord<TRoot, $Value> & DecorateRouter
239
237
  : // utils only apply to queries
240
- DecorateProcedure<
241
- TRouter['_def']['_config'],
242
- TRouter['_def']['record'][TKey]
243
- >;
244
- }; // Add functions that should be available at utils root
238
+ $Value extends AnyQueryProcedure
239
+ ? DecorateProcedure<TRoot, $Value>
240
+ : never
241
+ : never;
242
+ }; // Add functions that should be available at utils root
245
243
 
246
244
  type AnyDecoratedProcedure = DecorateProcedure<any, any>;
247
245
 
@@ -250,9 +248,18 @@ export type CreateReactUtils<
250
248
  TSSRContext,
251
249
  > = ProtectedIntersection<
252
250
  DecoratedTRPCContextProps<TRouter, TSSRContext>,
253
- DecoratedProcedureUtilsRecord<TRouter>
251
+ DecoratedProcedureUtilsRecord<
252
+ TRouter['_def']['_config']['$types'],
253
+ TRouter['_def']['record']
254
+ >
254
255
  >;
255
256
 
257
+ export type CreateQueryUtils<TRouter extends AnyRouter> =
258
+ DecoratedProcedureUtilsRecord<
259
+ TRouter['_def']['_config']['$types'],
260
+ TRouter['_def']['record']
261
+ >;
262
+
256
263
  export const getQueryType = (
257
264
  utilName: keyof AnyDecoratedProcedure,
258
265
  ): QueryType => {
@@ -278,11 +285,52 @@ export const getQueryType = (
278
285
  }
279
286
  };
280
287
 
288
+ /**
289
+ * @internal
290
+ */
291
+ function createRecursiveUtilsProxy<TRouter extends AnyRouter>(
292
+ context: TRPCQueryUtils<TRouter>,
293
+ key: string,
294
+ ) {
295
+ return createRecursiveProxy((opts) => {
296
+ const path = [key, ...opts.path];
297
+ const utilName = path.pop() as keyof AnyDecoratedProcedure;
298
+ const args = [...opts.args] as Parameters<
299
+ AnyDecoratedProcedure[typeof utilName]
300
+ >;
301
+ const input = args.shift(); // args can now be spread when input removed
302
+ const queryType = getQueryType(utilName);
303
+ const queryKey = getQueryKeyInternal(path, input, queryType);
304
+
305
+ const contextMap: Record<keyof AnyDecoratedProcedure, () => unknown> = {
306
+ fetch: () => context.fetchQuery(queryKey, ...args),
307
+ fetchInfinite: () => context.fetchInfiniteQuery(queryKey, args[0]),
308
+ prefetch: () => context.prefetchQuery(queryKey, ...args),
309
+ prefetchInfinite: () => context.prefetchInfiniteQuery(queryKey, args[0]),
310
+ ensureData: () => context.ensureQueryData(queryKey, ...args),
311
+ invalidate: () => context.invalidateQueries(queryKey, ...args),
312
+ reset: () => context.resetQueries(queryKey, ...args),
313
+ refetch: () => context.refetchQueries(queryKey, ...args),
314
+ cancel: () => context.cancelQuery(queryKey, ...args),
315
+ setData: () => {
316
+ context.setQueryData(queryKey, args[0], args[1]);
317
+ },
318
+ setInfiniteData: () => {
319
+ context.setInfiniteQueryData(queryKey, args[0], args[1]);
320
+ },
321
+ getData: () => context.getQueryData(queryKey),
322
+ getInfiniteData: () => context.getInfiniteQueryData(queryKey),
323
+ };
324
+
325
+ return contextMap[utilName]();
326
+ });
327
+ }
328
+
281
329
  /**
282
330
  * @internal
283
331
  */
284
332
  export function createReactQueryUtils<TRouter extends AnyRouter, TSSRContext>(
285
- context: TRPCContextState<AnyRouter, unknown>,
333
+ context: TRPCContextState<AnyRouter, TSSRContext>,
286
334
  ) {
287
335
  type CreateReactUtilsReturnType = CreateReactUtils<TRouter, TSSRContext>;
288
336
 
@@ -295,38 +343,17 @@ export function createReactQueryUtils<TRouter extends AnyRouter, TSSRContext>(
295
343
  return context[contextName];
296
344
  }
297
345
 
298
- return createRecursiveProxy((opts) => {
299
- const path = [key, ...opts.path];
300
- const utilName = path.pop() as keyof AnyDecoratedProcedure;
301
- const args = [...opts.args] as Parameters<
302
- AnyDecoratedProcedure[typeof utilName]
303
- >;
304
- const input = args.shift(); // args can now be spread when input removed
305
- const queryType = getQueryType(utilName);
306
- const queryKey = getQueryKeyInternal(path, input, queryType);
307
-
308
- const contextMap: Record<keyof AnyDecoratedProcedure, () => unknown> = {
309
- fetch: () => context.fetchQuery(queryKey, ...args),
310
- fetchInfinite: () => context.fetchInfiniteQuery(queryKey, args[0]),
311
- prefetch: () => context.prefetchQuery(queryKey, ...args),
312
- prefetchInfinite: () =>
313
- context.prefetchInfiniteQuery(queryKey, args[0]),
314
- ensureData: () => context.ensureQueryData(queryKey, ...args),
315
- invalidate: () => context.invalidateQueries(queryKey, ...args),
316
- reset: () => context.resetQueries(queryKey, ...args),
317
- refetch: () => context.refetchQueries(queryKey, ...args),
318
- cancel: () => context.cancelQuery(queryKey, ...args),
319
- setData: () => {
320
- context.setQueryData(queryKey, args[0], args[1]);
321
- },
322
- setInfiniteData: () => {
323
- context.setInfiniteQueryData(queryKey, args[0], args[1]);
324
- },
325
- getData: () => context.getQueryData(queryKey),
326
- getInfiniteData: () => context.getInfiniteQueryData(queryKey),
327
- };
346
+ return createRecursiveUtilsProxy(context, key);
347
+ });
348
+ }
328
349
 
329
- return contextMap[utilName]();
330
- });
350
+ /**
351
+ * @internal
352
+ */
353
+ export function createQueryUtilsProxy<TRouter extends AnyRouter>(
354
+ context: TRPCQueryUtils<TRouter>,
355
+ ): CreateQueryUtils<TRouter> {
356
+ return createFlatProxy((key) => {
357
+ return createRecursiveUtilsProxy(context, key);
331
358
  });
332
359
  }
@@ -1,4 +1,5 @@
1
- import { QueryClient, QueryClientConfig } from '@tanstack/react-query';
1
+ import type { QueryClientConfig } from '@tanstack/react-query';
2
+ import { QueryClient } from '@tanstack/react-query';
2
3
 
3
4
  /**
4
5
  * @internal
@@ -1,5 +1,8 @@
1
- import { QueryClient } from '@tanstack/react-query';
2
- import { AnyRouter, MaybePromise } from '@trpc/server';
1
+ import type { QueryClient } from '@tanstack/react-query';
2
+ import type {
3
+ AnyRouter,
4
+ MaybePromise,
5
+ } from '@trpc/server/unstable-core-do-not-import';
3
6
 
4
7
  /**
5
8
  * @internal