@trpc/react-query 11.0.0-alpha-tmp-subscription-connection-state.488 → 11.0.0-alpha-tmp-12-06-react.665

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 (73) hide show
  1. package/dist/bundle-analysis.json +59 -76
  2. package/dist/createTRPCReact.d.ts +47 -17
  3. package/dist/createTRPCReact.d.ts.map +1 -1
  4. package/dist/internals/context.d.ts +43 -21
  5. package/dist/internals/context.d.ts.map +1 -1
  6. package/dist/internals/getQueryKey.d.ts +2 -2
  7. package/dist/internals/getQueryKey.js +3 -3
  8. package/dist/internals/getQueryKey.mjs +3 -3
  9. package/dist/internals/trpcResult.d.ts +18 -0
  10. package/dist/internals/trpcResult.d.ts.map +1 -0
  11. package/dist/internals/trpcResult.js +63 -0
  12. package/dist/internals/trpcResult.mjs +40 -0
  13. package/dist/internals/useQueries.d.ts +1 -1
  14. package/dist/internals/useQueries.d.ts.map +1 -1
  15. package/dist/rsc.d.ts +1 -1
  16. package/dist/rsc.d.ts.map +1 -1
  17. package/dist/rsc.js +4 -4
  18. package/dist/rsc.mjs +4 -4
  19. package/dist/server/ssgProxy.d.ts +7 -24
  20. package/dist/server/ssgProxy.d.ts.map +1 -1
  21. package/dist/server/ssgProxy.js +21 -4
  22. package/dist/server/ssgProxy.mjs +21 -4
  23. package/dist/shared/hooks/createHooksInternal.d.ts +4 -2
  24. package/dist/shared/hooks/createHooksInternal.d.ts.map +1 -1
  25. package/dist/shared/hooks/createHooksInternal.js +160 -93
  26. package/dist/shared/hooks/createHooksInternal.mjs +156 -89
  27. package/dist/shared/hooks/types.d.ts +38 -159
  28. package/dist/shared/hooks/types.d.ts.map +1 -1
  29. package/dist/shared/index.js +0 -7
  30. package/dist/shared/index.mjs +0 -1
  31. package/dist/shared/polymorphism/mutationLike.d.ts.map +1 -1
  32. package/dist/shared/polymorphism/queryLike.d.ts.map +1 -1
  33. package/dist/shared/polymorphism/routerLike.d.ts.map +1 -1
  34. package/dist/shared/proxy/decorationProxy.js +1 -1
  35. package/dist/shared/proxy/decorationProxy.mjs +1 -1
  36. package/dist/shared/proxy/useQueriesProxy.d.ts.map +1 -1
  37. package/dist/shared/proxy/utilsProxy.d.ts +45 -20
  38. package/dist/shared/proxy/utilsProxy.d.ts.map +1 -1
  39. package/dist/shared/proxy/utilsProxy.js +4 -0
  40. package/dist/shared/proxy/utilsProxy.mjs +4 -0
  41. package/dist/shared/types.d.ts +60 -2
  42. package/dist/shared/types.d.ts.map +1 -1
  43. package/dist/utils/createUtilityFunctions.d.ts +2 -2
  44. package/dist/utils/createUtilityFunctions.d.ts.map +1 -1
  45. package/dist/utils/createUtilityFunctions.js +69 -3
  46. package/dist/utils/createUtilityFunctions.mjs +69 -3
  47. package/dist/utils/inferReactQueryProcedure.d.ts +2 -2
  48. package/dist/utils/inferReactQueryProcedure.d.ts.map +1 -1
  49. package/package.json +22 -19
  50. package/src/createTRPCReact.tsx +276 -65
  51. package/src/internals/context.tsx +105 -24
  52. package/src/internals/getQueryKey.ts +2 -2
  53. package/src/internals/trpcResult.ts +55 -0
  54. package/src/internals/useQueries.ts +36 -31
  55. package/src/rsc.tsx +6 -6
  56. package/src/server/ssgProxy.ts +23 -66
  57. package/src/shared/hooks/createHooksInternal.tsx +222 -151
  58. package/src/shared/hooks/types.ts +64 -348
  59. package/src/shared/polymorphism/mutationLike.ts +8 -6
  60. package/src/shared/polymorphism/queryLike.ts +12 -14
  61. package/src/shared/polymorphism/routerLike.ts +4 -4
  62. package/src/shared/proxy/useQueriesProxy.ts +4 -4
  63. package/src/shared/proxy/utilsProxy.ts +153 -25
  64. package/src/shared/types.ts +229 -1
  65. package/src/utils/createUtilityFunctions.ts +90 -2
  66. package/src/utils/inferReactQueryProcedure.ts +8 -6
  67. package/dist/internals/useHookResult.d.ts +0 -8
  68. package/dist/internals/useHookResult.d.ts.map +0 -1
  69. package/dist/internals/useHookResult.js +0 -35
  70. package/dist/internals/useHookResult.mjs +0 -14
  71. package/dist/shared/hooks/types.js +0 -133
  72. package/dist/shared/hooks/types.mjs +0 -126
  73. package/src/internals/useHookResult.ts +0 -17
@@ -22,18 +22,35 @@ import type {
22
22
  TRPCUntypedClient,
23
23
  } from '@trpc/client';
24
24
  import type {
25
+ AnyClientTypes,
25
26
  AnyRouter,
26
27
  DistributiveOmit,
27
28
  } from '@trpc/server/unstable-core-do-not-import';
28
29
  import * as React from 'react';
29
- import type { ExtractCursorType } from '../shared';
30
+ import type {
31
+ DefinedTRPCInfiniteQueryOptionsIn,
32
+ DefinedTRPCInfiniteQueryOptionsOut,
33
+ DefinedTRPCQueryOptionsIn,
34
+ DefinedTRPCQueryOptionsOut,
35
+ ExtractCursorType,
36
+ UndefinedTRPCInfiniteQueryOptionsIn,
37
+ UndefinedTRPCInfiniteQueryOptionsOut,
38
+ UndefinedTRPCQueryOptionsIn,
39
+ UndefinedTRPCQueryOptionsOut,
40
+ } from '../shared';
30
41
  import type { TRPCMutationKey, TRPCQueryKey } from './getQueryKey';
31
42
 
32
- export type TRPCFetchQueryOptions<TOutput, TError> = DistributiveOmit<
33
- FetchQueryOptions<TOutput, TError>,
34
- 'queryKey'
35
- > &
36
- TRPCRequestOptions;
43
+ interface TRPCUseUtilsOptions {
44
+ /**
45
+ * tRPC-related options
46
+ */
47
+ trpc?: TRPCRequestOptions;
48
+ }
49
+ export interface TRPCFetchQueryOptions<TOutput, TError>
50
+ extends DistributiveOmit<FetchQueryOptions<TOutput, TError>, 'queryKey'>,
51
+ TRPCUseUtilsOptions {
52
+ //
53
+ }
37
54
 
38
55
  export type TRPCFetchInfiniteQueryOptions<TInput, TOutput, TError> =
39
56
  DistributiveOmit<
@@ -46,7 +63,7 @@ export type TRPCFetchInfiniteQueryOptions<TInput, TOutput, TError> =
46
63
  >,
47
64
  'queryKey' | 'initialPageParam'
48
65
  > &
49
- TRPCRequestOptions & {
66
+ TRPCUseUtilsOptions & {
50
67
  initialCursor?: ExtractCursorType<TInput>;
51
68
  };
52
69
 
@@ -119,14 +136,78 @@ export interface TRPCContextState<
119
136
  */
120
137
  export interface TRPCQueryUtils<TRouter extends AnyRouter> {
121
138
  /**
122
- * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchquery
139
+ * @see https://tanstack.com/query/latest/docs/framework/react/reference/queryOptions#queryoptions
140
+ */
141
+ queryOptions(
142
+ path: readonly string[], // <-- look into if needed
143
+ queryKey: TRPCQueryKey,
144
+ opts?: UndefinedTRPCQueryOptionsIn<
145
+ unknown,
146
+ unknown,
147
+ TRPCClientError<AnyClientTypes>
148
+ >,
149
+ ): UndefinedTRPCQueryOptionsOut<
150
+ unknown,
151
+ unknown,
152
+ TRPCClientError<AnyClientTypes>
153
+ >;
154
+ queryOptions(
155
+ path: readonly string[], // <-- look into if needed
156
+ queryKey: TRPCQueryKey,
157
+ opts: DefinedTRPCQueryOptionsIn<
158
+ unknown,
159
+ unknown,
160
+ TRPCClientError<AnyClientTypes>
161
+ >,
162
+ ): DefinedTRPCQueryOptionsOut<
163
+ unknown,
164
+ unknown,
165
+ TRPCClientError<AnyClientTypes>
166
+ >;
167
+
168
+ /**
169
+ * @see https://tanstack.com/query/latest/docs/framework/react/reference/infiniteQueryOptions#infinitequeryoptions
170
+ */
171
+ infiniteQueryOptions(
172
+ path: readonly string[], // <-- look into if needed
173
+ queryKey: TRPCQueryKey,
174
+ opts: UndefinedTRPCInfiniteQueryOptionsIn<
175
+ unknown,
176
+ unknown,
177
+ unknown,
178
+ TRPCClientError<AnyClientTypes>
179
+ >,
180
+ ): UndefinedTRPCInfiniteQueryOptionsOut<
181
+ unknown,
182
+ unknown,
183
+ unknown,
184
+ TRPCClientError<AnyClientTypes>
185
+ >;
186
+ infiniteQueryOptions(
187
+ path: readonly string[], // <-- look into if needed
188
+ queryKey: TRPCQueryKey,
189
+ opts: DefinedTRPCInfiniteQueryOptionsIn<
190
+ unknown,
191
+ unknown,
192
+ unknown,
193
+ TRPCClientError<AnyClientTypes>
194
+ >,
195
+ ): DefinedTRPCInfiniteQueryOptionsOut<
196
+ unknown,
197
+ unknown,
198
+ unknown,
199
+ TRPCClientError<AnyClientTypes>
200
+ >;
201
+
202
+ /**
203
+ * @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchquery
123
204
  */
124
205
  fetchQuery: (
125
206
  queryKey: TRPCQueryKey,
126
207
  opts?: TRPCFetchQueryOptions<unknown, TRPCClientError<TRouter>>,
127
208
  ) => Promise<unknown>;
128
209
  /**
129
- * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchinfinitequery
210
+ * @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchinfinitequery
130
211
  */
131
212
  fetchInfiniteQuery: (
132
213
  queryKey: TRPCQueryKey,
@@ -137,7 +218,7 @@ export interface TRPCQueryUtils<TRouter extends AnyRouter> {
137
218
  >,
138
219
  ) => Promise<InfiniteData<unknown, unknown>>;
139
220
  /**
140
- * @link https://tanstack.com/query/v5/docs/framework/react/guides/prefetching
221
+ * @see https://tanstack.com/query/v5/docs/framework/react/guides/prefetching
141
222
  */
142
223
  prefetchQuery: (
143
224
  queryKey: TRPCQueryKey,
@@ -145,7 +226,7 @@ export interface TRPCQueryUtils<TRouter extends AnyRouter> {
145
226
  ) => Promise<void>;
146
227
 
147
228
  /**
148
- * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientprefetchinfinitequery
229
+ * @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientprefetchinfinitequery
149
230
  */
150
231
  prefetchInfiniteQuery: (
151
232
  queryKey: TRPCQueryKey,
@@ -157,7 +238,7 @@ export interface TRPCQueryUtils<TRouter extends AnyRouter> {
157
238
  ) => Promise<void>;
158
239
 
159
240
  /**
160
- * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientensurequerydata
241
+ * @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientensurequerydata
161
242
  */
162
243
  ensureQueryData: (
163
244
  queryKey: TRPCQueryKey,
@@ -165,7 +246,7 @@ export interface TRPCQueryUtils<TRouter extends AnyRouter> {
165
246
  ) => Promise<unknown>;
166
247
 
167
248
  /**
168
- * @link https://tanstack.com/query/v5/docs/framework/react/guides/query-invalidation
249
+ * @see https://tanstack.com/query/v5/docs/framework/react/guides/query-invalidation
169
250
  */
170
251
  invalidateQueries: (
171
252
  queryKey: TRPCQueryKey,
@@ -174,7 +255,7 @@ export interface TRPCQueryUtils<TRouter extends AnyRouter> {
174
255
  ) => Promise<void>;
175
256
 
176
257
  /**
177
- * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientresetqueries
258
+ * @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientresetqueries
178
259
  */
179
260
  resetQueries: (
180
261
  queryKey: TRPCQueryKey,
@@ -183,7 +264,7 @@ export interface TRPCQueryUtils<TRouter extends AnyRouter> {
183
264
  ) => Promise<void>;
184
265
 
185
266
  /**
186
- * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientrefetchqueries
267
+ * @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientrefetchqueries
187
268
  */
188
269
  refetchQueries: (
189
270
  queryKey: TRPCQueryKey,
@@ -192,7 +273,7 @@ export interface TRPCQueryUtils<TRouter extends AnyRouter> {
192
273
  ) => Promise<void>;
193
274
 
194
275
  /**
195
- * @link https://tanstack.com/query/v5/docs/framework/react/guides/query-cancellation
276
+ * @see https://tanstack.com/query/v5/docs/framework/react/guides/query-cancellation
196
277
  */
197
278
  cancelQuery: (
198
279
  queryKey: TRPCQueryKey,
@@ -200,7 +281,7 @@ export interface TRPCQueryUtils<TRouter extends AnyRouter> {
200
281
  ) => Promise<void>;
201
282
 
202
283
  /**
203
- * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
284
+ * @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
204
285
  */
205
286
  setQueryData: (
206
287
  queryKey: TRPCQueryKey,
@@ -209,7 +290,7 @@ export interface TRPCQueryUtils<TRouter extends AnyRouter> {
209
290
  ) => void;
210
291
 
211
292
  /**
212
- * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetqueriesdata
293
+ * @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetqueriesdata
213
294
  */
214
295
  setQueriesData: (
215
296
  queryKey: TRPCQueryKey,
@@ -219,12 +300,12 @@ export interface TRPCQueryUtils<TRouter extends AnyRouter> {
219
300
  ) => [QueryKey, unknown][];
220
301
 
221
302
  /**
222
- * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata
303
+ * @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata
223
304
  */
224
305
  getQueryData: (queryKey: TRPCQueryKey) => unknown;
225
306
 
226
307
  /**
227
- * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
308
+ * @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
228
309
  */
229
310
  setInfiniteQueryData: (
230
311
  queryKey: TRPCQueryKey,
@@ -236,14 +317,14 @@ export interface TRPCQueryUtils<TRouter extends AnyRouter> {
236
317
  ) => void;
237
318
 
238
319
  /**
239
- * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata
320
+ * @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata
240
321
  */
241
322
  getInfiniteQueryData: (
242
323
  queryKey: TRPCQueryKey,
243
324
  ) => InfiniteData<unknown> | undefined;
244
325
 
245
326
  /**
246
- * @link https://tanstack.com/query/latest/docs/reference/QueryClient/#queryclientsetmutationdefaults
327
+ * @see https://tanstack.com/query/latest/docs/reference/QueryClient/#queryclientsetmutationdefaults
247
328
  */
248
329
  setMutationDefaults: (
249
330
  mutationKey: TRPCMutationKey,
@@ -255,14 +336,14 @@ export interface TRPCQueryUtils<TRouter extends AnyRouter> {
255
336
  ) => void;
256
337
 
257
338
  /**
258
- * @link https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientgetmutationdefaults
339
+ * @see https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientgetmutationdefaults
259
340
  */
260
341
  getMutationDefaults: (
261
342
  mutationKey: TRPCMutationKey,
262
343
  ) => MutationOptions | undefined;
263
344
 
264
345
  /**
265
- * @link https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientismutating
346
+ * @see https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientismutating
266
347
  */
267
348
  isMutating: (filters: { mutationKey: TRPCMutationKey }) => number;
268
349
  }
@@ -104,7 +104,7 @@ type GetParams<TProcedureOrRouter extends ProcedureOrRouter> =
104
104
  * @param procedureOrRouter - procedure or AnyRouter
105
105
  * @param input - input to procedureOrRouter
106
106
  * @param type - defaults to `any`
107
- * @link https://trpc.io/docs/v11/getQueryKey
107
+ * @see https://trpc.io/docs/v11/getQueryKey
108
108
  */
109
109
  export function getQueryKey<TProcedureOrRouter extends ProcedureOrRouter>(
110
110
  procedureOrRouter: TProcedureOrRouter,
@@ -127,7 +127,7 @@ export type QueryKeyKnown<TInput, TType extends Exclude<QueryType, 'any'>> = [
127
127
  /**
128
128
  * Method to extract the mutation key for a procedure
129
129
  * @param procedure - procedure
130
- * @link https://trpc.io/docs/v11/getQueryKey#mutations
130
+ * @see https://trpc.io/docs/v11/getQueryKey#mutations
131
131
  */
132
132
  export function getMutationKey<TProcedure extends DecoratedMutation<any>>(
133
133
  procedure: TProcedure,
@@ -0,0 +1,55 @@
1
+ import type { QueryClient } from '@tanstack/react-query';
2
+ import * as React from 'react';
3
+ import type { TRPCQueryOptionsResult } from '../shared';
4
+ import type { TRPCHookResult } from '../shared/hooks/types';
5
+ import type { TRPCQueryKey } from './getQueryKey';
6
+
7
+ export function createTRPCOptionsResult(value: {
8
+ path: readonly string[];
9
+ }): TRPCQueryOptionsResult['trpc'] {
10
+ const path = value.path.join('.');
11
+
12
+ return {
13
+ path,
14
+ };
15
+ }
16
+
17
+ /**
18
+ * Makes a stable reference of the `trpc` prop
19
+ */
20
+ export function useHookResult(value: {
21
+ path: readonly string[];
22
+ }): TRPCHookResult['trpc'] {
23
+ const result = createTRPCOptionsResult(value);
24
+ return React.useMemo(() => result, [result]);
25
+ }
26
+
27
+ /**
28
+ * @internal
29
+ */
30
+ export async function buildQueryFromAsyncIterable(
31
+ asyncIterable: AsyncIterable<unknown>,
32
+ queryClient: QueryClient,
33
+ queryKey: TRPCQueryKey,
34
+ ) {
35
+ const queryCache = queryClient.getQueryCache();
36
+
37
+ const query = queryCache.build(queryClient, {
38
+ queryKey,
39
+ });
40
+
41
+ query.setState({
42
+ data: [],
43
+ status: 'success',
44
+ });
45
+
46
+ const aggregate: unknown[] = [];
47
+ for await (const value of asyncIterable) {
48
+ aggregate.push(value);
49
+
50
+ query.setState({
51
+ data: [...aggregate],
52
+ });
53
+ }
54
+ return aggregate;
55
+ }
@@ -125,19 +125,24 @@ export type QueriesOptions<
125
125
  > = TQueriesOptions extends []
126
126
  ? []
127
127
  : TQueriesOptions extends [infer Head]
128
- ? [...TResult, GetOptions<Head>]
129
- : TQueriesOptions extends [infer Head, ...infer Tail]
130
- ? QueriesOptions<Tail, [...TResult, GetOptions<Head>]>
131
- : unknown[] extends TQueriesOptions
132
- ? TQueriesOptions
133
- : TQueriesOptions extends UseQueryOptionsForUseQueries<
134
- infer TQueryFnData,
135
- infer TError,
136
- infer TData,
137
- infer TQueryKey
138
- >[]
139
- ? UseQueryOptionsForUseQueries<TQueryFnData, TError, TData, TQueryKey>[]
140
- : UseQueryOptionsForUseQueries[];
128
+ ? [...TResult, GetOptions<Head>]
129
+ : TQueriesOptions extends [infer Head, ...infer Tail]
130
+ ? QueriesOptions<Tail, [...TResult, GetOptions<Head>]>
131
+ : unknown[] extends TQueriesOptions
132
+ ? TQueriesOptions
133
+ : TQueriesOptions extends UseQueryOptionsForUseQueries<
134
+ infer TQueryFnData,
135
+ infer TError,
136
+ infer TData,
137
+ infer TQueryKey
138
+ >[]
139
+ ? UseQueryOptionsForUseQueries<
140
+ TQueryFnData,
141
+ TError,
142
+ TData,
143
+ TQueryKey
144
+ >[]
145
+ : UseQueryOptionsForUseQueries[];
141
146
 
142
147
  type GetSuspenseOptions<TQueryOptions> =
143
148
  TQueryOptions extends UseQueryOptionsForUseSuspenseQueries<any, any, any, any>
@@ -153,24 +158,24 @@ export type SuspenseQueriesOptions<
153
158
  > = TQueriesOptions extends []
154
159
  ? []
155
160
  : TQueriesOptions extends [infer Head]
156
- ? [...TResult, GetSuspenseOptions<Head>]
157
- : TQueriesOptions extends [infer Head, ...infer Tail]
158
- ? QueriesOptions<Tail, [...TResult, GetSuspenseOptions<Head>]>
159
- : unknown[] extends TQueriesOptions
160
- ? TQueriesOptions
161
- : TQueriesOptions extends UseQueryOptionsForUseSuspenseQueries<
162
- infer TQueryFnData,
163
- infer TError,
164
- infer TData,
165
- infer TQueryKey
166
- >[]
167
- ? UseQueryOptionsForUseSuspenseQueries<
168
- TQueryFnData,
169
- TError,
170
- TData,
171
- TQueryKey
172
- >[]
173
- : UseQueryOptionsForUseSuspenseQueries[];
161
+ ? [...TResult, GetSuspenseOptions<Head>]
162
+ : TQueriesOptions extends [infer Head, ...infer Tail]
163
+ ? SuspenseQueriesOptions<Tail, [...TResult, GetSuspenseOptions<Head>]>
164
+ : unknown[] extends TQueriesOptions
165
+ ? TQueriesOptions
166
+ : TQueriesOptions extends UseQueryOptionsForUseSuspenseQueries<
167
+ infer TQueryFnData,
168
+ infer TError,
169
+ infer TData,
170
+ infer TQueryKey
171
+ >[]
172
+ ? UseQueryOptionsForUseSuspenseQueries<
173
+ TQueryFnData,
174
+ TError,
175
+ TData,
176
+ TQueryKey
177
+ >[]
178
+ : UseQueryOptionsForUseSuspenseQueries[];
174
179
 
175
180
  /**
176
181
  * @internal
package/src/rsc.tsx CHANGED
@@ -35,9 +35,9 @@ type DecorateProcedure<
35
35
  TRoot extends AnyRootTypes,
36
36
  TProcedure extends AnyProcedure,
37
37
  > = {
38
- (input: inferProcedureInput<TProcedure>): Promise<
39
- inferProcedureOutput<TProcedure>
40
- >;
38
+ (
39
+ input: inferProcedureInput<TProcedure>,
40
+ ): Promise<inferProcedureOutput<TProcedure>>;
41
41
  prefetch: (
42
42
  input: inferProcedureInput<TProcedure>,
43
43
  opts?: TRPCFetchQueryOptions<
@@ -62,8 +62,8 @@ type DecorateRouterRecord<
62
62
  [TKey in keyof TRecord]: TRecord[TKey] extends AnyProcedure
63
63
  ? DecorateProcedure<TRoot, TRecord[TKey]>
64
64
  : TRecord[TKey] extends RouterRecord
65
- ? DecorateRouterRecord<TRoot, TRecord[TKey]>
66
- : never;
65
+ ? DecorateRouterRecord<TRoot, TRecord[TKey]>
66
+ : never;
67
67
  };
68
68
 
69
69
  type Caller<TRouter extends AnyRouter> = ReturnType<
@@ -73,7 +73,7 @@ type Caller<TRouter extends AnyRouter> = ReturnType<
73
73
  // ts-prune-ignore-next
74
74
  /**
75
75
  * @note This requires `@tanstack/react-query@^5.49.0`
76
- * @note Make sure to have `dehyrate.serializeData` and `hydrate.deserializeData`
76
+ * @note Make sure to have `dehydrate.serializeData` and `hydrate.deserializeData`
77
77
  * set to your data transformer in your `QueryClient` factory.
78
78
  * @example
79
79
  * ```ts
@@ -1,11 +1,10 @@
1
1
  import type {
2
2
  DehydratedState,
3
3
  DehydrateOptions,
4
- InfiniteData,
5
4
  QueryClient,
6
5
  } from '@tanstack/react-query';
7
6
  import { dehydrate } from '@tanstack/react-query';
8
- import type { inferRouterClient, TRPCClientError } from '@trpc/client';
7
+ import type { inferRouterClient } from '@trpc/client';
9
8
  import { getUntypedClient, TRPCUntypedClient } from '@trpc/client';
10
9
  import type { CoercedTransformerParameters } from '@trpc/client/unstable-internals';
11
10
  import {
@@ -13,14 +12,11 @@ import {
13
12
  type TransformerOptions,
14
13
  } from '@trpc/client/unstable-internals';
15
14
  import type {
16
- AnyProcedure,
17
15
  AnyQueryProcedure,
18
16
  AnyRootTypes,
19
17
  AnyRouter,
20
18
  inferClientTypes,
21
- inferProcedureInput,
22
19
  inferRouterContext,
23
- inferTransformedProcedureOutput,
24
20
  Maybe,
25
21
  ProtectedIntersection,
26
22
  RouterRecord,
@@ -33,7 +29,7 @@ import {
33
29
  import { getQueryKeyInternal } from '../internals/getQueryKey';
34
30
  import type {
35
31
  CreateTRPCReactQueryClientConfig,
36
- ExtractCursorType,
32
+ DecorateQueryProcedure,
37
33
  TRPCFetchInfiniteQueryOptions,
38
34
  TRPCFetchQueryOptions,
39
35
  } from '../shared';
@@ -52,61 +48,13 @@ type CreateServerSideHelpersOptions<TRouter extends AnyRouter> =
52
48
  CreateTRPCReactQueryClientConfig &
53
49
  (CreateSSGHelpersExternal<TRouter> | CreateSSGHelpersInternal<TRouter>);
54
50
 
55
- type DecorateProcedure<
56
- TRoot extends AnyRootTypes,
57
- TProcedure extends AnyProcedure,
58
- > = {
59
- /**
60
- * @link https://tanstack.com/query/v5/docs/framework/react/guides/prefetching
61
- */
62
- fetch(
63
- input: inferProcedureInput<TProcedure>,
64
- opts?: TRPCFetchQueryOptions<
65
- inferTransformedProcedureOutput<TRoot, TProcedure>,
66
- TRPCClientError<TRoot>
67
- >,
68
- ): Promise<inferTransformedProcedureOutput<TRoot, TProcedure>>;
69
-
70
- /**
71
- * @link https://tanstack.com/query/v5/docs/framework/react/guides/prefetching
72
- */
73
- fetchInfinite(
74
- input: inferProcedureInput<TProcedure>,
75
- opts?: TRPCFetchInfiniteQueryOptions<
76
- inferProcedureInput<TProcedure>,
77
- inferTransformedProcedureOutput<TRoot, TProcedure>,
78
- TRPCClientError<TRoot>
79
- >,
80
- ): Promise<
81
- InfiniteData<
82
- inferTransformedProcedureOutput<TRoot, TProcedure>,
83
- NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null
84
- >
85
- >;
86
-
87
- /**
88
- * @link https://tanstack.com/query/v5/docs/framework/react/guides/prefetching
89
- */
90
- prefetch(
91
- input: inferProcedureInput<TProcedure>,
92
- opts?: TRPCFetchQueryOptions<
93
- inferTransformedProcedureOutput<TRoot, TProcedure>,
94
- TRPCClientError<TRoot>
95
- >,
96
- ): Promise<void>;
97
-
98
- /**
99
- * @link https://tanstack.com/query/v5/docs/framework/react/guides/prefetching
100
- */
101
- prefetchInfinite(
102
- input: inferProcedureInput<TProcedure>,
103
- opts?: TRPCFetchInfiniteQueryOptions<
104
- inferProcedureInput<TProcedure>,
105
- inferTransformedProcedureOutput<TRoot, TProcedure>,
106
- TRPCClientError<TRoot>
107
- >,
108
- ): Promise<void>;
109
- };
51
+ type SSGFns =
52
+ | 'queryOptions'
53
+ | 'infiniteQueryOptions'
54
+ | 'fetch'
55
+ | 'fetchInfinite'
56
+ | 'prefetch'
57
+ | 'prefetchInfinite';
110
58
 
111
59
  /**
112
60
  * @internal
@@ -119,17 +67,17 @@ type DecoratedProcedureSSGRecord<
119
67
  ? $Value extends RouterRecord
120
68
  ? DecoratedProcedureSSGRecord<TRoot, $Value>
121
69
  : // utils only apply to queries
122
- $Value extends AnyQueryProcedure
123
- ? DecorateProcedure<TRoot, $Value>
124
- : never
70
+ $Value extends AnyQueryProcedure
71
+ ? Pick<DecorateQueryProcedure<TRoot, $Value>, SSGFns>
72
+ : never
125
73
  : never;
126
74
  };
127
75
 
128
- type AnyDecoratedProcedure = DecorateProcedure<any, any>;
76
+ type AnyDecoratedProcedure = Pick<DecorateQueryProcedure<any, any>, SSGFns>;
129
77
 
130
78
  /**
131
79
  * Create functions you can use for server-side rendering / static generation
132
- * @link https://trpc.io/docs/v11/client/nextjs/server-side-helpers
80
+ * @see https://trpc.io/docs/v11/client/nextjs/server-side-helpers
133
81
  */
134
82
  export function createServerSideHelpers<TRouter extends AnyRouter>(
135
83
  opts: CreateServerSideHelpersOptions<TRouter>,
@@ -154,6 +102,7 @@ export function createServerSideHelpers<TRouter extends AnyRouter>(
154
102
  getRawInput: async () => queryOpts.input,
155
103
  ctx,
156
104
  type: 'query',
105
+ signal: undefined,
157
106
  });
158
107
  },
159
108
  };
@@ -209,6 +158,14 @@ export function createServerSideHelpers<TRouter extends AnyRouter>(
209
158
  );
210
159
 
211
160
  const helperMap: Record<keyof AnyDecoratedProcedure, () => unknown> = {
161
+ queryOptions: () => {
162
+ const args1 = args[1] as Maybe<any>;
163
+ return { ...args1, queryKey, queryFn };
164
+ },
165
+ infiniteQueryOptions: () => {
166
+ const args1 = args[1] as Maybe<any>;
167
+ return { ...args1, queryKey, queryFn };
168
+ },
212
169
  fetch: () => {
213
170
  const args1 = args[1] as Maybe<TRPCFetchQueryOptions<any, any>>;
214
171
  return queryClient.fetchQuery({ ...args1, queryKey, queryFn });