@trpc/react-query 11.0.0-next.91 → 11.0.0-rc.329

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,37 +1,30 @@
1
- import { TRPCClientErrorLike } from '@trpc/client';
2
- import {
3
- AnyMutationProcedure,
1
+ import type { SkipToken } from '@tanstack/react-query';
2
+ import type { TRPCClientErrorLike } from '@trpc/client';
3
+ import type {
4
4
  AnyProcedure,
5
- AnyQueryProcedure,
6
- AnyRootConfig,
5
+ AnyRootTypes,
7
6
  AnyRouter,
8
- AnySubscriptionProcedure,
9
7
  inferProcedureInput,
10
- ProcedureRouterRecord,
11
- ProtectedIntersection,
12
- } from '@trpc/server';
13
- import {
14
- createFlatProxy,
15
8
  inferTransformedProcedureOutput,
16
- inferTransformedSubscriptionOutput,
17
- } from '@trpc/server/shared';
18
- import { useMemo } from 'react';
19
- import { TRPCUseQueries } from './internals/useQueries';
20
- import {
21
- createReactDecoration,
22
- createReactQueryUtils,
23
- CreateReactUtils,
24
- } from './shared';
25
- import {
26
- CreateReactQueryHooks,
27
- createRootHooks,
28
- } from './shared/hooks/createHooksInternal';
29
- import {
9
+ ProcedureType,
10
+ ProtectedIntersection,
11
+ RouterRecord,
12
+ } from '@trpc/server/unstable-core-do-not-import';
13
+ import { createFlatProxy } from '@trpc/server/unstable-core-do-not-import';
14
+ import * as React from 'react';
15
+ import type {
16
+ TRPCUseQueries,
17
+ TRPCUseSuspenseQueries,
18
+ } from './internals/useQueries';
19
+ import type { CreateReactUtils } from './shared';
20
+ import { createReactDecoration, createReactQueryUtils } from './shared';
21
+ import type { CreateReactQueryHooks } from './shared/hooks/createHooksInternal';
22
+ import { createRootHooks } from './shared/hooks/createHooksInternal';
23
+ import type {
30
24
  CreateClient,
31
25
  DefinedUseTRPCQueryOptions,
32
26
  DefinedUseTRPCQueryResult,
33
27
  TRPCProvider,
34
- UseDehydratedState,
35
28
  UseTRPCInfiniteQueryOptions,
36
29
  UseTRPCInfiniteQueryResult,
37
30
  UseTRPCMutationOptions,
@@ -44,46 +37,46 @@ import {
44
37
  UseTRPCSuspenseQueryOptions,
45
38
  UseTRPCSuspenseQueryResult,
46
39
  } from './shared/hooks/types';
47
- import { CreateTRPCReactOptions } from './shared/types';
40
+ import type { CreateTRPCReactOptions } from './shared/types';
48
41
 
42
+ type ResolverDef = {
43
+ input: any;
44
+ output: any;
45
+ transformer: boolean;
46
+ errorShape: any;
47
+ };
49
48
  /**
50
49
  * @internal
51
50
  */
52
- export interface ProcedureUseQuery<
53
- TConfig extends AnyRootConfig,
54
- TProcedure extends AnyProcedure,
55
- > {
56
- <
57
- TQueryFnData extends inferTransformedProcedureOutput<
58
- TConfig,
59
- TProcedure
60
- > = inferTransformedProcedureOutput<TConfig, TProcedure>,
61
- TData = TQueryFnData,
62
- >(
63
- input: inferProcedureInput<TProcedure>,
51
+ export interface ProcedureUseQuery<TDef extends ResolverDef> {
52
+ <TQueryFnData extends TDef['output'] = TDef['output'], TData = TQueryFnData>(
53
+ input: TDef['input'] | SkipToken,
64
54
  opts: DefinedUseTRPCQueryOptions<
65
55
  TQueryFnData,
66
56
  TData,
67
- TRPCClientErrorLike<TConfig>,
68
- inferTransformedProcedureOutput<TConfig, TProcedure>
57
+ TRPCClientErrorLike<{
58
+ errorShape: TDef['errorShape'];
59
+ transformer: TDef['transformer'];
60
+ }>,
61
+ TDef['output']
69
62
  >,
70
- ): DefinedUseTRPCQueryResult<TData, TRPCClientErrorLike<TConfig>>;
63
+ ): DefinedUseTRPCQueryResult<
64
+ TData,
65
+ TRPCClientErrorLike<{
66
+ errorShape: TDef['errorShape'];
67
+ transformer: TDef['transformer'];
68
+ }>
69
+ >;
71
70
 
72
- <
73
- TQueryFnData extends inferTransformedProcedureOutput<
74
- TConfig,
75
- TProcedure
76
- > = inferTransformedProcedureOutput<TConfig, TProcedure>,
77
- TData = TQueryFnData,
78
- >(
79
- input: inferProcedureInput<TProcedure>,
71
+ <TQueryFnData extends TDef['output'] = TDef['output'], TData = TQueryFnData>(
72
+ input: TDef['input'] | SkipToken,
80
73
  opts?: UseTRPCQueryOptions<
81
74
  TQueryFnData,
82
75
  TData,
83
- TRPCClientErrorLike<TConfig>,
84
- inferTransformedProcedureOutput<TConfig, TProcedure>
76
+ TRPCClientErrorLike<TDef>,
77
+ TDef['output']
85
78
  >,
86
- ): UseTRPCQueryResult<TData, TRPCClientErrorLike<TConfig>>;
79
+ ): UseTRPCQueryResult<TData, TRPCClientErrorLike<TDef>>;
87
80
  }
88
81
 
89
82
  /**
@@ -93,132 +86,114 @@ type CursorInput = {
93
86
  cursor?: any;
94
87
  } | void;
95
88
 
89
+ type ReservedInfiniteQueryKeys = 'cursor' | 'direction';
96
90
  /**
97
91
  * @internal
98
92
  */
99
- export type MaybeDecoratedInfiniteQuery<
100
- TProcedure extends AnyProcedure,
101
- TConfig extends AnyRootConfig,
102
- > = inferProcedureInput<TProcedure> extends CursorInput
103
- ? {
104
- /**
105
- * @see https://trpc.io/docs/client/react/suspense#useinfinitesuspensequery
106
- */
107
- useInfiniteQuery: (
108
- input: Omit<inferProcedureInput<TProcedure>, 'cursor'>,
109
- opts: UseTRPCInfiniteQueryOptions<
110
- inferProcedureInput<TProcedure>,
111
- inferTransformedProcedureOutput<TConfig, TProcedure>,
112
- TRPCClientErrorLike<TConfig>
113
- >,
114
- ) => UseTRPCInfiniteQueryResult<
115
- inferTransformedProcedureOutput<TConfig, TProcedure>,
116
- TRPCClientErrorLike<TConfig>,
117
- inferProcedureInput<TProcedure>
118
- >;
119
- /**
120
- * @see https://trpc.io/docs/client/react/suspense
121
- */
122
- useSuspenseInfiniteQuery: (
123
- input: Omit<inferProcedureInput<TProcedure>, 'cursor'>,
124
- opts: UseTRPCSuspenseInfiniteQueryOptions<
125
- inferProcedureInput<TProcedure>,
126
- inferTransformedProcedureOutput<TConfig, TProcedure>,
127
- TRPCClientErrorLike<TConfig>
128
- >,
129
- ) => UseTRPCSuspenseInfiniteQueryResult<
130
- inferTransformedProcedureOutput<TConfig, TProcedure>,
131
- TRPCClientErrorLike<TConfig>,
132
- inferProcedureInput<TProcedure>
133
- >;
134
- }
135
- : object;
93
+ export type MaybeDecoratedInfiniteQuery<TDef extends ResolverDef> =
94
+ TDef['input'] extends CursorInput
95
+ ? {
96
+ /**
97
+ * @link https://trpc.io/docs/v11/client/react/suspense#useinfinitesuspensequery
98
+ */
99
+ useInfiniteQuery: (
100
+ input: Omit<TDef['input'], ReservedInfiniteQueryKeys> | SkipToken,
101
+ opts: UseTRPCInfiniteQueryOptions<
102
+ TDef['input'],
103
+ TDef['output'],
104
+ TRPCClientErrorLike<TDef>
105
+ >,
106
+ ) => UseTRPCInfiniteQueryResult<
107
+ TDef['output'],
108
+ TRPCClientErrorLike<TDef>,
109
+ TDef['input']
110
+ >;
111
+ /**
112
+ * @link https://trpc.io/docs/v11/client/react/suspense
113
+ */
114
+ useSuspenseInfiniteQuery: (
115
+ input: Omit<TDef['input'], 'cursor' | 'direction'>,
116
+ opts: UseTRPCSuspenseInfiniteQueryOptions<
117
+ TDef['input'],
118
+ TDef['output'],
119
+ TRPCClientErrorLike<TDef>
120
+ >,
121
+ ) => UseTRPCSuspenseInfiniteQueryResult<
122
+ TDef['output'],
123
+ TRPCClientErrorLike<TDef>,
124
+ TDef['input']
125
+ >;
126
+ }
127
+ : object;
136
128
 
137
129
  /**
138
130
  * @internal
139
131
  */
140
- export type DecoratedQueryMethods<
141
- TConfig extends AnyRootConfig,
142
- TProcedure extends AnyProcedure,
143
- > = {
132
+ export type DecoratedQueryMethods<TDef extends ResolverDef> = {
144
133
  /**
145
- * @see https://trpc.io/docs/client/react/useQuery
134
+ * @link https://trpc.io/docs/v11/client/react/useQuery
146
135
  */
147
- useQuery: ProcedureUseQuery<TConfig, TProcedure>;
136
+ useQuery: ProcedureUseQuery<TDef>;
148
137
  /**
149
- * @see https://trpc.io/docs/client/react/suspense#usesuspensequery
138
+ * @link https://trpc.io/docs/v11/client/react/suspense#usesuspensequery
150
139
  */
151
140
  useSuspenseQuery: <
152
- TQueryFnData extends inferTransformedProcedureOutput<
153
- TConfig,
154
- TProcedure
155
- > = inferTransformedProcedureOutput<TConfig, TProcedure>,
141
+ TQueryFnData extends TDef['output'] = TDef['output'],
156
142
  TData = TQueryFnData,
157
143
  >(
158
- input: inferProcedureInput<TProcedure>,
144
+ input: TDef['input'],
159
145
  opts?: UseTRPCSuspenseQueryOptions<
160
146
  TQueryFnData,
161
147
  TData,
162
- TRPCClientErrorLike<TConfig>
148
+ TRPCClientErrorLike<TDef>
163
149
  >,
164
- ) => UseTRPCSuspenseQueryResult<TData, TRPCClientErrorLike<TConfig>>;
150
+ ) => UseTRPCSuspenseQueryResult<TData, TRPCClientErrorLike<TDef>>;
165
151
  };
166
152
 
167
153
  /**
168
154
  * @internal
169
155
  */
170
- export type DecoratedQuery<
171
- TConfig extends AnyRootConfig,
172
- TProcedure extends AnyProcedure,
173
- > = MaybeDecoratedInfiniteQuery<TProcedure, TConfig> &
174
- DecoratedQueryMethods<TConfig, TProcedure>;
156
+ export type DecoratedQuery<TDef extends ResolverDef> =
157
+ MaybeDecoratedInfiniteQuery<TDef> & DecoratedQueryMethods<TDef>;
175
158
 
176
- /**
177
- * @internal
178
- */
179
- export interface DecoratedMutation<
180
- TConfig extends AnyRootConfig,
181
- TProcedure extends AnyProcedure,
182
- > {
159
+ export type DecoratedMutation<TDef extends ResolverDef> = {
183
160
  /**
184
- * @see https://trpc.io/docs/client/react/useMutation
161
+ * @link https://trpc.io/docs/v11/client/react/useMutation
185
162
  */
186
163
  useMutation: <TContext = unknown>(
187
164
  opts?: UseTRPCMutationOptions<
188
- inferProcedureInput<TProcedure>,
189
- TRPCClientErrorLike<TConfig>,
190
- inferTransformedProcedureOutput<TConfig, TProcedure>,
165
+ TDef['input'],
166
+ TRPCClientErrorLike<TDef>,
167
+ TDef['output'],
191
168
  TContext
192
169
  >,
193
170
  ) => UseTRPCMutationResult<
194
- inferTransformedProcedureOutput<TConfig, TProcedure>,
195
- TRPCClientErrorLike<TConfig>,
196
- inferProcedureInput<TProcedure>,
171
+ TDef['output'],
172
+ TRPCClientErrorLike<TDef>,
173
+ TDef['input'],
197
174
  TContext
198
175
  >;
199
- }
200
-
176
+ };
201
177
  /**
202
178
  * @internal
203
179
  */
204
180
  export type DecorateProcedure<
205
- TConfig extends AnyRootConfig,
206
- TProcedure extends AnyProcedure,
207
- _TFlags,
208
- > = TProcedure extends AnyQueryProcedure
209
- ? DecoratedQuery<TConfig, TProcedure>
210
- : TProcedure extends AnyMutationProcedure
211
- ? DecoratedMutation<TConfig, TProcedure>
212
- : TProcedure extends AnySubscriptionProcedure
181
+ TType extends ProcedureType,
182
+ TDef extends ResolverDef,
183
+ > = TType extends 'query'
184
+ ? DecoratedQuery<TDef>
185
+ : TType extends 'mutation'
186
+ ? DecoratedMutation<TDef>
187
+ : TType extends 'subscription'
213
188
  ? {
214
189
  /**
215
- * @see https://trpc.io/docs/subscriptions
190
+ * @link https://trpc.io/docs/v11/subscriptions
216
191
  */
217
192
  useSubscription: (
218
- input: inferProcedureInput<TProcedure>,
193
+ input: TDef['input'],
219
194
  opts?: UseTRPCSubscriptionOptions<
220
- inferTransformedSubscriptionOutput<TConfig, TProcedure>,
221
- TRPCClientErrorLike<TConfig>
195
+ TDef['output'],
196
+ TRPCClientErrorLike<TDef>
222
197
  >,
223
198
  ) => void;
224
199
  }
@@ -227,19 +202,24 @@ export type DecorateProcedure<
227
202
  /**
228
203
  * @internal
229
204
  */
230
- export type DecoratedProcedureRecord<
231
- TConfig extends AnyRootConfig,
232
- TProcedures extends ProcedureRouterRecord,
233
- TFlags,
205
+ export type DecorateRouterRecord<
206
+ TRoot extends AnyRootTypes,
207
+ TRecord extends RouterRecord,
234
208
  > = {
235
- [TKey in keyof TProcedures]: TProcedures[TKey] extends AnyRouter
236
- ? DecoratedProcedureRecord<
237
- TConfig,
238
- TProcedures[TKey]['_def']['record'],
239
- TFlags
240
- >
241
- : TProcedures[TKey] extends AnyProcedure
242
- ? DecorateProcedure<TConfig, TProcedures[TKey], TFlags>
209
+ [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value
210
+ ? $Value extends RouterRecord
211
+ ? DecorateRouterRecord<TRoot, $Value>
212
+ : $Value extends AnyProcedure
213
+ ? DecorateProcedure<
214
+ $Value['_def']['type'],
215
+ {
216
+ input: inferProcedureInput<$Value>;
217
+ output: inferTransformedProcedureOutput<TRoot, $Value>;
218
+ transformer: TRoot['transformer'];
219
+ errorShape: TRoot['errorShape'];
220
+ }
221
+ >
222
+ : never
243
223
  : never;
244
224
  };
245
225
 
@@ -250,29 +230,27 @@ export type CreateTRPCReactBase<TRouter extends AnyRouter, TSSRContext> = {
250
230
  /**
251
231
  * @deprecated renamed to `useUtils` and will be removed in a future tRPC version
252
232
  *
253
- * @see https://trpc.io/docs/client/react/useUtils
233
+ * @link https://trpc.io/docs/v11/client/react/useUtils
254
234
  */
255
235
  useContext(): CreateReactUtils<TRouter, TSSRContext>;
256
236
  /**
257
- * @see https://trpc.io/docs/client/react/useUtils
237
+ * @link https://trpc.io/docs/v11/client/react/useUtils
258
238
  */
259
239
  useUtils(): CreateReactUtils<TRouter, TSSRContext>;
260
240
  Provider: TRPCProvider<TRouter, TSSRContext>;
261
241
  createClient: CreateClient<TRouter>;
262
242
  useQueries: TRPCUseQueries<TRouter>;
263
- useDehydratedState: UseDehydratedState<TRouter>;
243
+ useSuspenseQueries: TRPCUseSuspenseQueries<TRouter>;
264
244
  };
265
245
 
266
246
  export type CreateTRPCReact<
267
247
  TRouter extends AnyRouter,
268
248
  TSSRContext,
269
- TFlags,
270
249
  > = ProtectedIntersection<
271
250
  CreateTRPCReactBase<TRouter, TSSRContext>,
272
- DecoratedProcedureRecord<
273
- TRouter['_def']['_config'],
274
- TRouter['_def']['record'],
275
- TFlags
251
+ DecorateRouterRecord<
252
+ TRouter['_def']['_config']['$types'],
253
+ TRouter['_def']['record']
276
254
  >
277
255
  >;
278
256
 
@@ -282,16 +260,15 @@ export type CreateTRPCReact<
282
260
  export function createHooksInternal<
283
261
  TRouter extends AnyRouter,
284
262
  TSSRContext = unknown,
285
- TFlags = null,
286
263
  >(trpc: CreateReactQueryHooks<TRouter, TSSRContext>) {
287
- type CreateHooksInternal = CreateTRPCReact<TRouter, TSSRContext, TFlags>;
264
+ type CreateHooksInternal = CreateTRPCReact<TRouter, TSSRContext>;
288
265
 
289
266
  return createFlatProxy<CreateHooksInternal>((key) => {
290
267
  if (key === 'useContext' || key === 'useUtils') {
291
268
  return () => {
292
269
  const context = trpc.useUtils();
293
270
  // create a stable reference of the utils context
294
- return useMemo(() => {
271
+ return React.useMemo(() => {
295
272
  return (createReactQueryUtils as any)(context);
296
273
  }, [context]);
297
274
  };
@@ -308,12 +285,11 @@ export function createHooksInternal<
308
285
  export function createTRPCReact<
309
286
  TRouter extends AnyRouter,
310
287
  TSSRContext = unknown,
311
- TFlags = null,
312
288
  >(
313
289
  opts?: CreateTRPCReactOptions<TRouter>,
314
- ): CreateTRPCReact<TRouter, TSSRContext, TFlags> {
290
+ ): CreateTRPCReact<TRouter, TSSRContext> {
315
291
  const hooks = createRootHooks<TRouter, TSSRContext>(opts);
316
- const proxy = createHooksInternal<TRouter, TSSRContext, TFlags>(hooks);
292
+ const proxy = createHooksInternal<TRouter, TSSRContext>(hooks);
317
293
 
318
294
  return proxy as any;
319
295
  }
package/src/index.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  export * from '@trpc/client';
2
2
 
3
3
  export { getQueryKey } from './internals/getQueryKey';
4
- export { createTRPCReact, type CreateTRPCReact } from './createTRPCReact';
4
+ export {
5
+ createTRPCReact,
6
+ type CreateTRPCReact,
7
+ type CreateTRPCReactBase,
8
+ } from './createTRPCReact';
5
9
  export type { inferReactQueryProcedureOptions } from './utils/inferReactQueryProcedure';
10
+ export { createTRPCQueryUtils } from './createTRPCQueryUtils';
@@ -1,4 +1,4 @@
1
- import {
1
+ import type {
2
2
  CancelOptions,
3
3
  FetchInfiniteQueryOptions,
4
4
  FetchQueryOptions,
@@ -13,16 +13,19 @@ import {
13
13
  SetDataOptions,
14
14
  Updater,
15
15
  } from '@tanstack/react-query';
16
- import {
16
+ import type {
17
17
  CreateTRPCClient,
18
18
  TRPCClientError,
19
19
  TRPCRequestOptions,
20
20
  TRPCUntypedClient,
21
21
  } from '@trpc/client';
22
- import type { AnyRouter, DistributiveOmit } from '@trpc/server';
23
- import { createContext } from 'react';
24
- import { ExtractCursorType } from '../shared';
25
- import { TRPCQueryKey } from './getQueryKey';
22
+ import type {
23
+ AnyRouter,
24
+ DistributiveOmit,
25
+ } from '@trpc/server/unstable-core-do-not-import';
26
+ import * as React from 'react';
27
+ import type { ExtractCursorType } from '../shared';
28
+ import type { TRPCQueryKey } from './getQueryKey';
26
29
 
27
30
  export type TRPCFetchQueryOptions<TOutput, TError> = DistributiveOmit<
28
31
  FetchQueryOptions<TOutput, TError>,
@@ -106,7 +109,13 @@ export const contextProps: (keyof TRPCContextPropsBase<any, any>)[] = [
106
109
  export interface TRPCContextState<
107
110
  TRouter extends AnyRouter,
108
111
  TSSRContext = undefined,
109
- > extends Required<TRPCContextProps<TRouter, TSSRContext>> {
112
+ > extends Required<TRPCContextProps<TRouter, TSSRContext>>,
113
+ TRPCQueryUtils<TRouter> {}
114
+
115
+ /**
116
+ * @internal
117
+ */
118
+ export interface TRPCQueryUtils<TRouter extends AnyRouter> {
110
119
  /**
111
120
  * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchquery
112
121
  */
@@ -126,7 +135,7 @@ export interface TRPCContextState<
126
135
  >,
127
136
  ) => Promise<InfiniteData<unknown, unknown>>;
128
137
  /**
129
- * @link https://tanstack.com/query/v5/docs/react/guides/prefetching
138
+ * @link https://tanstack.com/query/v5/docs/framework/react/guides/prefetching
130
139
  */
131
140
  prefetchQuery: (
132
141
  queryKey: TRPCQueryKey,
@@ -146,7 +155,7 @@ export interface TRPCContextState<
146
155
  ) => Promise<void>;
147
156
 
148
157
  /**
149
- * @link https://tanstack.com/query/v5/docs/react/reference/QueryClient#queryclientensurequerydata
158
+ * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientensurequerydata
150
159
  */
151
160
  ensureQueryData: (
152
161
  queryKey: TRPCQueryKey,
@@ -154,7 +163,7 @@ export interface TRPCContextState<
154
163
  ) => Promise<unknown>;
155
164
 
156
165
  /**
157
- * @link https://tanstack.com/query/v5/docs/react/guides/query-invalidation
166
+ * @link https://tanstack.com/query/v5/docs/framework/react/guides/query-invalidation
158
167
  */
159
168
  invalidateQueries: (
160
169
  queryKey: TRPCQueryKey,
@@ -163,7 +172,7 @@ export interface TRPCContextState<
163
172
  ) => Promise<void>;
164
173
 
165
174
  /**
166
- * @link https://tanstack.com/query/v5/docs/react/reference/QueryClient#queryclientresetqueries
175
+ * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientresetqueries
167
176
  */
168
177
  resetQueries: (
169
178
  queryKey: TRPCQueryKey,
@@ -172,7 +181,7 @@ export interface TRPCContextState<
172
181
  ) => Promise<void>;
173
182
 
174
183
  /**
175
- * @link https://tanstack.com/query/v5/docs/react/reference/QueryClient#queryclientrefetchqueries
184
+ * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientrefetchqueries
176
185
  */
177
186
  refetchQueries: (
178
187
  queryKey: TRPCQueryKey,
@@ -181,7 +190,7 @@ export interface TRPCContextState<
181
190
  ) => Promise<void>;
182
191
 
183
192
  /**
184
- * @link https://tanstack.com/query/v5/docs/react/guides/query-cancellation
193
+ * @link https://tanstack.com/query/v5/docs/framework/react/guides/query-cancellation
185
194
  */
186
195
  cancelQuery: (
187
196
  queryKey: TRPCQueryKey,
@@ -189,7 +198,7 @@ export interface TRPCContextState<
189
198
  ) => Promise<void>;
190
199
 
191
200
  /**
192
- * @link https://tanstack.com/query/v5/docs/react/reference/QueryClient#queryclientsetquerydata
201
+ * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
193
202
  */
194
203
  setQueryData: (
195
204
  queryKey: TRPCQueryKey,
@@ -198,11 +207,11 @@ export interface TRPCContextState<
198
207
  ) => void;
199
208
 
200
209
  /**
201
- * @link https://tanstack.com/query/v5/docs/react/reference/QueryClient#queryclientgetquerydata
210
+ * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata
202
211
  */
203
212
  getQueryData: (queryKey: TRPCQueryKey) => unknown;
204
213
  /**
205
- * @link https://tanstack.com/query/v5/docs/react/reference/QueryClient#queryclientsetquerydata
214
+ * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
206
215
  */
207
216
  setInfiniteQueryData: (
208
217
  queryKey: TRPCQueryKey,
@@ -214,10 +223,10 @@ export interface TRPCContextState<
214
223
  ) => void;
215
224
 
216
225
  /**
217
- * @link https://tanstack.com/query/v5/docs/react/reference/QueryClient#queryclientgetquerydata
226
+ * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata
218
227
  */
219
228
  getInfiniteQueryData: (
220
229
  queryKey: TRPCQueryKey,
221
230
  ) => InfiniteData<unknown> | undefined;
222
231
  }
223
- export const TRPCContext = createContext(null as any);
232
+ export const TRPCContext = React.createContext?.(null as any);
@@ -1,12 +1,24 @@
1
- import { TRPCQueryKey } from './getQueryKey';
1
+ import type { TRPCQueryKey } from './getQueryKey';
2
2
 
3
+ /**
4
+ * @internal
5
+ */
3
6
  export function getClientArgs<TOptions>(
4
7
  queryKey: TRPCQueryKey,
5
8
  opts: TOptions,
6
- pageParam?: any,
9
+ infiniteParams?: {
10
+ pageParam: any;
11
+ direction: 'forward' | 'backward';
12
+ },
7
13
  ) {
8
14
  const path = queryKey[0];
9
- const input = queryKey[1]?.input;
10
- if (pageParam) (input as any).cursor = pageParam;
15
+ let input = queryKey[1]?.input;
16
+ if (infiniteParams) {
17
+ input = {
18
+ ...(input ?? {}),
19
+ ...(infiniteParams.pageParam ? { cursor: infiniteParams.pageParam } : {}),
20
+ direction: infiniteParams.direction,
21
+ };
22
+ }
11
23
  return [path.join('.'), input, (opts as any)?.trpc] as const;
12
24
  }