@trpc/tanstack-react-query 11.0.0-rc.808 → 11.0.0-rc.817

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.
@@ -1,5 +1,9 @@
1
1
  import type { DataTag, QueryClient, QueryFilters } from '@tanstack/react-query';
2
- import type { TRPCClient, TRPCRequestOptions } from '@trpc/client';
2
+ import type {
3
+ TRPCClient,
4
+ TRPCClientErrorLike,
5
+ TRPCRequestOptions,
6
+ } from '@trpc/client';
3
7
  import { getUntypedClient, TRPCUntypedClient } from '@trpc/client';
4
8
  import type {
5
9
  AnyTRPCProcedure,
@@ -28,10 +32,12 @@ import {
28
32
  type TRPCSubscriptionOptions,
29
33
  } from './subscriptionOptions';
30
34
  import type {
31
- QueryType,
35
+ OptionalCursorInput,
32
36
  ResolverDef,
37
+ TRPCInfiniteData,
33
38
  TRPCMutationKey,
34
39
  TRPCQueryKey,
40
+ WithRequired,
35
41
  } from './types';
36
42
  import {
37
43
  getMutationKeyInternal,
@@ -39,61 +45,133 @@ import {
39
45
  unwrapLazyArg,
40
46
  } from './utils';
41
47
 
42
- export interface DecorateQueryKeyable {
48
+ export interface DecorateRouterKeyable {
43
49
  /**
44
- * Calculate the TanStack Query Key for a Route
50
+ * Calculate the TanStack Query Key for any path, could be used to invalidate every procedure beneath this path
45
51
  *
46
52
  * @see https://tanstack.com/query/latest/docs/framework/react/guides/query-keys
47
53
  * @see https://trpc.io/docs/client/tanstack-react-query/usage#queryKey
48
54
  */
49
- queryKey: () => TRPCQueryKey;
55
+ pathKey: () => TRPCQueryKey;
50
56
 
51
57
  /**
52
- * Calculate a TanStack Query Filter for a Route
58
+ * Calculate a TanStack Query Filter for any path, could be used to manipulate every procedure beneath this path
53
59
  *
54
60
  * @see https://tanstack.com/query/latest/docs/framework/react/guides/filters
55
61
  * @see https://trpc.io/docs/client/tanstack-react-query/usage#queryFilter
56
62
  */
57
- queryFilter: (input?: undefined, filters?: QueryFilters) => QueryFilters;
63
+ pathFilter: (
64
+ filters?: QueryFilters<unknown, unknown, unknown, TRPCQueryKey>,
65
+ ) => WithRequired<
66
+ QueryFilters<unknown, unknown, unknown, TRPCQueryKey>,
67
+ 'queryKey'
68
+ >;
69
+ }
70
+
71
+ interface TypeHelper<TDef extends ResolverDef> {
72
+ /**
73
+ * @internal prefer using inferInput and inferOutput to access types
74
+ */
75
+ '~types': {
76
+ input: TDef['input'];
77
+ output: TDef['output'];
78
+ errorShape: TDef['errorShape'];
79
+ };
58
80
  }
59
81
 
60
82
  export type inferInput<
61
83
  TProcedure extends
84
+ | DecorateInfiniteQueryProcedure<any>
62
85
  | DecorateQueryProcedure<any>
63
86
  | DecorateMutationProcedure<any>,
64
87
  > = TProcedure['~types']['input'];
65
88
 
66
89
  export type inferOutput<
67
90
  TProcedure extends
91
+ | DecorateInfiniteQueryProcedure<any>
68
92
  | DecorateQueryProcedure<any>
69
93
  | DecorateMutationProcedure<any>,
70
94
  > = TProcedure['~types']['output'];
71
95
 
72
- export interface DecorateQueryProcedure<TDef extends ResolverDef> {
96
+ export interface DecorateInfiniteQueryProcedure<TDef extends ResolverDef>
97
+ extends TypeHelper<TDef> {
73
98
  /**
74
- * @internal prefer using inferInput and inferOutput to access types
99
+ * Create a set of type-safe infinite query options that can be passed to `useInfiniteQuery`, `prefetchInfiniteQuery` etc.
100
+ *
101
+ * @see https://tanstack.com/query/latest/docs/framework/react/reference/infiniteQueryOptions#infinitequeryoptions
102
+ * @see https://trpc.io/docs/client/tanstack-react-query/usage#infiniteQueryOptions
75
103
  */
76
- '~types': {
77
- input: TDef['input'];
78
- output: TDef['output'];
79
- errorShape: TDef['errorShape'];
80
- };
104
+ infiniteQueryOptions: TRPCInfiniteQueryOptions<TDef>;
81
105
 
82
106
  /**
83
- * Create a set of type-safe query options that can be passed to `useQuery`, `prefetchQuery` etc.
107
+ * Calculate the TanStack Query Key for a Infinite Query Procedure
84
108
  *
85
- * @see https://tanstack.com/query/latest/docs/framework/react/reference/queryOptions#queryoptions
86
- * @see https://trpc.io/docs/client/tanstack-react-query/usage#queryOptions
109
+ * @see https://tanstack.com/query/latest/docs/framework/react/guides/query-keys
110
+ * @see https://trpc.io/docs/client/tanstack-react-query/usage#queryKey
87
111
  */
88
- queryOptions: TRPCQueryOptions<TDef>;
112
+ infiniteQueryKey: (input?: Partial<TDef['input']>) => DataTag<
113
+ TRPCQueryKey,
114
+ TRPCInfiniteData<TDef['input'], TDef['output']>,
115
+ TRPCClientErrorLike<{
116
+ transformer: TDef['transformer'];
117
+ errorShape: TDef['errorShape'];
118
+ }>
119
+ >;
89
120
 
90
121
  /**
91
- * Create a set of type-safe infinite query options that can be passed to `useInfiniteQuery`, `prefetchInfiniteQuery` etc.
122
+ * Calculate a TanStack Query Filter for a Infinite Query Procedure
92
123
  *
93
- * @see https://tanstack.com/query/latest/docs/framework/react/reference/infiniteQueryOptions#infinitequeryoptions
94
- * @see https://trpc.io/docs/client/tanstack-react-query/usage#infiniteQueryOptions
124
+ * @see https://tanstack.com/query/latest/docs/framework/react/guides/filters
125
+ * @see https://trpc.io/docs/client/tanstack-react-query/usage#queryFilter
95
126
  */
96
- infiniteQueryOptions: TRPCInfiniteQueryOptions<TDef>;
127
+ infiniteQueryFilter: (
128
+ input?: Partial<TDef['input']>,
129
+ filters?: QueryFilters<
130
+ TRPCInfiniteData<TDef['input'], TDef['output']>,
131
+ TRPCClientErrorLike<{
132
+ transformer: TDef['transformer'];
133
+ errorShape: TDef['errorShape'];
134
+ }>,
135
+ TRPCInfiniteData<TDef['input'], TDef['output']>,
136
+ DataTag<
137
+ TRPCQueryKey,
138
+ TRPCInfiniteData<TDef['input'], TDef['output']>,
139
+ TRPCClientErrorLike<{
140
+ transformer: TDef['transformer'];
141
+ errorShape: TDef['errorShape'];
142
+ }>
143
+ >
144
+ >,
145
+ ) => WithRequired<
146
+ QueryFilters<
147
+ TRPCInfiniteData<TDef['input'], TDef['output']>,
148
+ TRPCClientErrorLike<{
149
+ transformer: TDef['transformer'];
150
+ errorShape: TDef['errorShape'];
151
+ }>,
152
+ TRPCInfiniteData<TDef['input'], TDef['output']>,
153
+ DataTag<
154
+ TRPCQueryKey,
155
+ TRPCInfiniteData<TDef['input'], TDef['output']>,
156
+ TRPCClientErrorLike<{
157
+ transformer: TDef['transformer'];
158
+ errorShape: TDef['errorShape'];
159
+ }>
160
+ >
161
+ >,
162
+ 'queryKey'
163
+ >;
164
+ }
165
+ export interface DecorateQueryProcedure<TDef extends ResolverDef>
166
+ extends TypeHelper<TDef>,
167
+ DecorateRouterKeyable {
168
+ /**
169
+ * Create a set of type-safe query options that can be passed to `useQuery`, `prefetchQuery` etc.
170
+ *
171
+ * @see https://tanstack.com/query/latest/docs/framework/react/reference/queryOptions#queryoptions
172
+ * @see https://trpc.io/docs/client/tanstack-react-query/usage#queryOptions
173
+ */
174
+ queryOptions: TRPCQueryOptions<TDef>;
97
175
 
98
176
  /**
99
177
  * Calculate the TanStack Query Key for a Query Procedure
@@ -101,9 +179,14 @@ export interface DecorateQueryProcedure<TDef extends ResolverDef> {
101
179
  * @see https://tanstack.com/query/latest/docs/framework/react/guides/query-keys
102
180
  * @see https://trpc.io/docs/client/tanstack-react-query/usage#queryKey
103
181
  */
104
- queryKey: (
105
- input?: TDef['input'],
106
- ) => DataTag<TRPCQueryKey, TDef['output'], TDef['errorShape']>;
182
+ queryKey: (input?: Partial<TDef['input']>) => DataTag<
183
+ TRPCQueryKey,
184
+ TDef['output'],
185
+ TRPCClientErrorLike<{
186
+ transformer: TDef['transformer'];
187
+ errorShape: TDef['errorShape'];
188
+ }>
189
+ >;
107
190
 
108
191
  /**
109
192
  * Calculate a TanStack Query Filter for a Query Procedure
@@ -112,25 +195,46 @@ export interface DecorateQueryProcedure<TDef extends ResolverDef> {
112
195
  * @see https://trpc.io/docs/client/tanstack-react-query/usage#queryFilter
113
196
  */
114
197
  queryFilter: (
115
- input?: TDef['input'],
116
- filters?: QueryFilters<TDef['output'], TDef['errorShape']>,
117
- ) => QueryFilters<
118
- TDef['output'],
119
- TDef['errorShape'],
120
- TDef['output'],
121
- DataTag<TRPCQueryKey, TDef['output'], TDef['errorShape']>
198
+ input?: Partial<TDef['input']>,
199
+ filters?: QueryFilters<
200
+ TDef['output'],
201
+ TRPCClientErrorLike<{
202
+ transformer: TDef['transformer'];
203
+ errorShape: TDef['errorShape'];
204
+ }>,
205
+ TDef['output'],
206
+ DataTag<
207
+ TRPCQueryKey,
208
+ TDef['output'],
209
+ TRPCClientErrorLike<{
210
+ transformer: TDef['transformer'];
211
+ errorShape: TDef['errorShape'];
212
+ }>
213
+ >
214
+ >,
215
+ ) => WithRequired<
216
+ QueryFilters<
217
+ TDef['output'],
218
+ TRPCClientErrorLike<{
219
+ transformer: TDef['transformer'];
220
+ errorShape: TDef['errorShape'];
221
+ }>,
222
+ TDef['output'],
223
+ DataTag<
224
+ TRPCQueryKey,
225
+ TDef['output'],
226
+ TRPCClientErrorLike<{
227
+ transformer: TDef['transformer'];
228
+ errorShape: TDef['errorShape'];
229
+ }>
230
+ >
231
+ >,
232
+ 'queryKey'
122
233
  >;
123
234
  }
124
235
 
125
- export interface DecorateMutationProcedure<TDef extends ResolverDef> {
126
- /**
127
- * @internal prefer using inferInput and inferOutput to access types
128
- */
129
- '~types': {
130
- input: TDef['input'];
131
- output: TDef['output'];
132
- };
133
-
236
+ export interface DecorateMutationProcedure<TDef extends ResolverDef>
237
+ extends TypeHelper<TDef> {
134
238
  /**
135
239
  * Create a set of type-safe mutation options that can be passed to `useMutation`
136
240
  *
@@ -159,7 +263,10 @@ export type DecorateProcedure<
159
263
  TType extends TRPCProcedureType,
160
264
  TDef extends ResolverDef,
161
265
  > = TType extends 'query'
162
- ? DecorateQueryProcedure<TDef>
266
+ ? DecorateQueryProcedure<TDef> &
267
+ (TDef['input'] extends OptionalCursorInput
268
+ ? DecorateInfiniteQueryProcedure<TDef>
269
+ : Record<string, never>)
163
270
  : TType extends 'mutation'
164
271
  ? DecorateMutationProcedure<TDef>
165
272
  : TType extends 'subscription'
@@ -169,13 +276,13 @@ export type DecorateProcedure<
169
276
  /**
170
277
  * @internal
171
278
  */
172
- export type DecoratedProcedureUtilsRecord<
279
+ export type DecoratedRouterRecord<
173
280
  TRoot extends AnyTRPCRootTypes,
174
281
  TRecord extends TRPCRouterRecord,
175
282
  > = {
176
283
  [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value
177
284
  ? $Value extends TRPCRouterRecord
178
- ? DecoratedProcedureUtilsRecord<TRoot, $Value> & DecorateQueryKeyable
285
+ ? DecoratedRouterRecord<TRoot, $Value> & DecorateRouterKeyable
179
286
  : $Value extends AnyTRPCProcedure
180
287
  ? DecorateProcedure<
181
288
  $Value['_def']['type'],
@@ -191,11 +298,11 @@ export type DecoratedProcedureUtilsRecord<
191
298
  };
192
299
 
193
300
  export type TRPCOptionsProxy<TRouter extends AnyTRPCRouter> =
194
- DecoratedProcedureUtilsRecord<
301
+ DecoratedRouterRecord<
195
302
  TRouter['_def']['_config']['$types'],
196
303
  TRouter['_def']['record']
197
304
  > &
198
- DecorateQueryKeyable;
305
+ DecorateRouterKeyable;
199
306
 
200
307
  export interface TRPCOptionsProxyOptionsBase {
201
308
  queryClient: QueryClient | (() => QueryClient);
@@ -228,19 +335,10 @@ export type TRPCOptionsProxyOptions<TRouter extends AnyTRPCRouter> =
228
335
 
229
336
  type UtilsMethods =
230
337
  | keyof DecorateQueryProcedure<any>
338
+ | keyof DecorateInfiniteQueryProcedure<any>
231
339
  | keyof DecorateMutationProcedure<any>
232
- | keyof DecorateSubscriptionProcedure<any>;
233
-
234
- function getQueryType(method: UtilsMethods) {
235
- const map: Partial<Record<UtilsMethods, QueryType>> = {
236
- queryOptions: 'query',
237
- infiniteQueryOptions: 'infinite',
238
- subscriptionOptions: 'any',
239
- mutationOptions: 'any',
240
- };
241
-
242
- return map[method];
243
- }
340
+ | keyof DecorateSubscriptionProcedure<any>
341
+ | keyof DecorateRouterKeyable;
244
342
 
245
343
  /**
246
344
  * Create a typed proxy from your router types. Can also be used on the server.
@@ -280,45 +378,59 @@ export function createTRPCOptionsProxy<TRouter extends AnyTRPCRouter>(
280
378
  const utilName = path.pop() as UtilsMethods;
281
379
  const [arg1, arg2] = args as any[];
282
380
 
283
- function getQueryKey() {
284
- const queryType = getQueryType(utilName);
285
-
286
- return getQueryKeyInternal(path, arg1, queryType ?? 'any');
287
- }
288
-
289
381
  const contextMap: Record<UtilsMethods, () => unknown> = {
290
382
  '~types': undefined as any,
291
383
 
292
- mutationKey: () => {
293
- return getMutationKeyInternal(path);
384
+ pathKey: () => {
385
+ return getQueryKeyInternal(path);
386
+ },
387
+ pathFilter: (): QueryFilters => {
388
+ return {
389
+ ...arg1,
390
+ queryKey: getQueryKeyInternal(path),
391
+ };
392
+ },
393
+
394
+ queryOptions: () => {
395
+ return trpcQueryOptions({
396
+ input: arg1,
397
+ opts: arg2,
398
+ path,
399
+ queryClient: opts.queryClient,
400
+ queryKey: getQueryKeyInternal(path, arg1, 'query'),
401
+ query: callIt('query'),
402
+ });
294
403
  },
295
404
  queryKey: () => {
296
- return getQueryKey();
405
+ return getQueryKeyInternal(path, arg1, 'query');
297
406
  },
298
407
  queryFilter: (): QueryFilters => {
299
408
  return {
300
409
  ...arg2,
301
- queryKey: getQueryKey(),
410
+ queryKey: getQueryKeyInternal(path, arg1, 'query'),
302
411
  };
303
412
  },
413
+
304
414
  infiniteQueryOptions: () => {
305
415
  return trpcInfiniteQueryOptions({
416
+ input: arg1,
306
417
  opts: arg2,
307
418
  path,
308
419
  queryClient: opts.queryClient,
309
- queryKey: getQueryKey(),
420
+ queryKey: getQueryKeyInternal(path, arg1, 'infinite'),
310
421
  query: callIt('query'),
311
422
  });
312
423
  },
313
- queryOptions: () => {
314
- return trpcQueryOptions({
315
- opts: arg2,
316
- path,
317
- queryClient: opts.queryClient,
318
- queryKey: getQueryKey(),
319
- query: callIt('query'),
320
- });
424
+ infiniteQueryKey: () => {
425
+ return getQueryKeyInternal(path, arg1, 'infinite');
426
+ },
427
+ infiniteQueryFilter: (): QueryFilters => {
428
+ return {
429
+ ...arg2,
430
+ queryKey: getQueryKeyInternal(path, arg1, 'infinite'),
431
+ };
321
432
  },
433
+
322
434
  mutationOptions: () => {
323
435
  return trpcMutationOptions({
324
436
  opts: arg1,
@@ -328,11 +440,15 @@ export function createTRPCOptionsProxy<TRouter extends AnyTRPCRouter>(
328
440
  overrides: opts.overrides?.mutations,
329
441
  });
330
442
  },
443
+ mutationKey: () => {
444
+ return getMutationKeyInternal(path);
445
+ },
446
+
331
447
  subscriptionOptions: () => {
332
448
  return trpcSubscriptionOptions({
333
449
  opts: arg2,
334
450
  path,
335
- queryKey: getQueryKey(),
451
+ queryKey: getQueryKeyInternal(path, arg1, 'any'),
336
452
  subscribe: callIt('subscription'),
337
453
  });
338
454
  },
@@ -1,7 +1,6 @@
1
1
  import type {
2
2
  DataTag,
3
3
  DefinedInitialDataInfiniteOptions,
4
- InfiniteData,
5
4
  QueryClient,
6
5
  QueryFunction,
7
6
  SkipToken,
@@ -14,6 +13,7 @@ import type { DistributiveOmit } from '@trpc/server/unstable-core-do-not-import'
14
13
  import type {
15
14
  ExtractCursorType,
16
15
  ResolverDef,
16
+ TRPCInfiniteData,
17
17
  TRPCQueryBaseOptions,
18
18
  TRPCQueryKey,
19
19
  TRPCQueryOptionsResult,
@@ -36,7 +36,7 @@ interface UndefinedTRPCInfiniteQueryOptionsIn<
36
36
  UndefinedInitialDataInfiniteOptions<
37
37
  TQueryFnData,
38
38
  TError,
39
- InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
39
+ TRPCInfiniteData<TInput, TData>,
40
40
  TRPCQueryKey,
41
41
  NonNullable<ExtractCursorType<TInput>> | null
42
42
  >,
@@ -55,14 +55,14 @@ interface UndefinedTRPCInfiniteQueryOptionsOut<
55
55
  UndefinedInitialDataInfiniteOptions<
56
56
  TQueryFnData,
57
57
  TError,
58
- InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
58
+ TRPCInfiniteData<TInput, TData>,
59
59
  TRPCQueryKey,
60
60
  NonNullable<ExtractCursorType<TInput>> | null
61
61
  >,
62
62
  'initialPageParam'
63
63
  >,
64
64
  TRPCQueryOptionsResult {
65
- queryKey: DataTag<TRPCQueryKey, TData, TError>;
65
+ queryKey: DataTag<TRPCQueryKey, TRPCInfiniteData<TInput, TData>, TError>;
66
66
  initialPageParam: NonNullable<ExtractCursorType<TInput>> | null;
67
67
  }
68
68
 
@@ -71,7 +71,7 @@ interface DefinedTRPCInfiniteQueryOptionsIn<TInput, TQueryFnData, TData, TError>
71
71
  DefinedInitialDataInfiniteOptions<
72
72
  TQueryFnData,
73
73
  TError,
74
- InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
74
+ TRPCInfiniteData<TInput, TData>,
75
75
  TRPCQueryKey,
76
76
  NonNullable<ExtractCursorType<TInput>> | null
77
77
  >,
@@ -90,14 +90,14 @@ interface DefinedTRPCInfiniteQueryOptionsOut<
90
90
  DefinedInitialDataInfiniteOptions<
91
91
  TQueryFnData,
92
92
  TError,
93
- InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
93
+ TRPCInfiniteData<TInput, TData>,
94
94
  TRPCQueryKey,
95
95
  NonNullable<ExtractCursorType<TInput>> | null
96
96
  >,
97
97
  'initialPageParam'
98
98
  >,
99
99
  TRPCQueryOptionsResult {
100
- queryKey: DataTag<TRPCQueryKey, TData, TError>;
100
+ queryKey: DataTag<TRPCQueryKey, TRPCInfiniteData<TInput, TData>, TError>;
101
101
  initialPageParam: NonNullable<ExtractCursorType<TInput>> | null;
102
102
  }
103
103
 
@@ -110,7 +110,7 @@ interface UnusedSkipTokenTRPCInfiniteQueryOptionsIn<
110
110
  UnusedSkipTokenInfiniteOptions<
111
111
  TQueryFnData,
112
112
  TError,
113
- InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
113
+ TRPCInfiniteData<TInput, TData>,
114
114
  TRPCQueryKey,
115
115
  NonNullable<ExtractCursorType<TInput>> | null
116
116
  >,
@@ -129,14 +129,14 @@ interface UnusedSkipTokenTRPCInfiniteQueryOptionsOut<
129
129
  UnusedSkipTokenInfiniteOptions<
130
130
  TQueryFnData,
131
131
  TError,
132
- InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
132
+ TRPCInfiniteData<TInput, TData>,
133
133
  TRPCQueryKey,
134
134
  NonNullable<ExtractCursorType<TInput>> | null
135
135
  >,
136
136
  'initialPageParam'
137
137
  >,
138
138
  TRPCQueryOptionsResult {
139
- queryKey: DataTag<TRPCQueryKey, TData, TError>;
139
+ queryKey: DataTag<TRPCQueryKey, TRPCInfiniteData<TInput, TData>, TError>;
140
140
  initialPageParam: NonNullable<ExtractCursorType<TInput>> | null;
141
141
  }
142
142
 
@@ -147,13 +147,19 @@ export interface TRPCInfiniteQueryOptions<TDef extends ResolverDef> {
147
147
  TDef['input'],
148
148
  TQueryFnData,
149
149
  TData,
150
- TRPCClientErrorLike<TDef>
150
+ TRPCClientErrorLike<{
151
+ transformer: TDef['transformer'];
152
+ errorShape: TDef['errorShape'];
153
+ }>
151
154
  >,
152
155
  ): DefinedTRPCInfiniteQueryOptionsOut<
153
156
  TDef['input'],
154
157
  TQueryFnData,
155
158
  TData,
156
- TRPCClientErrorLike<TDef>
159
+ TRPCClientErrorLike<{
160
+ transformer: TDef['transformer'];
161
+ errorShape: TDef['errorShape'];
162
+ }>
157
163
  >;
158
164
  <TQueryFnData extends TDef['output'], TData = TQueryFnData>(
159
165
  input: TDef['input'],
@@ -161,13 +167,19 @@ export interface TRPCInfiniteQueryOptions<TDef extends ResolverDef> {
161
167
  TDef['input'],
162
168
  TQueryFnData,
163
169
  TData,
164
- TRPCClientErrorLike<TDef>
170
+ TRPCClientErrorLike<{
171
+ transformer: TDef['transformer'];
172
+ errorShape: TDef['errorShape'];
173
+ }>
165
174
  >,
166
175
  ): UnusedSkipTokenTRPCInfiniteQueryOptionsOut<
167
176
  TDef['input'],
168
177
  TQueryFnData,
169
178
  TData,
170
- TRPCClientErrorLike<TDef>
179
+ TRPCClientErrorLike<{
180
+ transformer: TDef['transformer'];
181
+ errorShape: TDef['errorShape'];
182
+ }>
171
183
  >;
172
184
  <TQueryFnData extends TDef['output'], TData = TQueryFnData>(
173
185
  input: TDef['input'] | SkipToken,
@@ -175,45 +187,42 @@ export interface TRPCInfiniteQueryOptions<TDef extends ResolverDef> {
175
187
  TDef['input'],
176
188
  TQueryFnData,
177
189
  TData,
178
- TRPCClientErrorLike<TDef>
190
+ TRPCClientErrorLike<{
191
+ transformer: TDef['transformer'];
192
+ errorShape: TDef['errorShape'];
193
+ }>
179
194
  >,
180
195
  ): UndefinedTRPCInfiniteQueryOptionsOut<
181
196
  TDef['input'],
182
197
  TQueryFnData,
183
198
  TData,
184
- TRPCClientErrorLike<TDef>
199
+ TRPCClientErrorLike<{
200
+ transformer: TDef['transformer'];
201
+ errorShape: TDef['errorShape'];
202
+ }>
185
203
  >;
186
204
  }
187
205
 
188
206
  type AnyTRPCInfiniteQueryOptionsIn =
189
- | DefinedTRPCInfiniteQueryOptionsIn<unknown, unknown, unknown, unknown>
190
- | UnusedSkipTokenTRPCInfiniteQueryOptionsIn<
191
- unknown,
192
- unknown,
193
- unknown,
194
- unknown
195
- >
196
- | UndefinedTRPCInfiniteQueryOptionsIn<unknown, unknown, unknown, unknown>;
207
+ | DefinedTRPCInfiniteQueryOptionsIn<any, any, any, any>
208
+ | UnusedSkipTokenTRPCInfiniteQueryOptionsIn<any, any, any, any>
209
+ | UndefinedTRPCInfiniteQueryOptionsIn<any, any, any, any>;
197
210
 
198
211
  type AnyTRPCInfiniteQueryOptionsOut =
199
- | DefinedTRPCInfiniteQueryOptionsOut<unknown, unknown, unknown, unknown>
200
- | UnusedSkipTokenTRPCInfiniteQueryOptionsOut<
201
- unknown,
202
- unknown,
203
- unknown,
204
- unknown
205
- >
206
- | UndefinedTRPCInfiniteQueryOptionsOut<unknown, unknown, unknown, unknown>;
212
+ | DefinedTRPCInfiniteQueryOptionsOut<any, any, any, any>
213
+ | UnusedSkipTokenTRPCInfiniteQueryOptionsOut<any, any, any, any>
214
+ | UndefinedTRPCInfiniteQueryOptionsOut<any, any, any, any>;
207
215
 
208
216
  export function trpcInfiniteQueryOptions(args: {
217
+ input: unknown;
209
218
  query: typeof TRPCUntypedClient.prototype.query;
210
219
  queryClient: QueryClient | (() => QueryClient);
211
220
  path: readonly string[];
212
221
  queryKey: TRPCQueryKey;
213
222
  opts: AnyTRPCInfiniteQueryOptionsIn;
214
223
  }): AnyTRPCInfiniteQueryOptionsOut {
215
- const { query, path, queryKey, opts } = args;
216
- const inputIsSkipToken = queryKey[1]?.input === skipToken;
224
+ const { input, query, path, queryKey, opts } = args;
225
+ const inputIsSkipToken = input === skipToken;
217
226
 
218
227
  const queryFn: QueryFunction<unknown, TRPCQueryKey, unknown> = async (
219
228
  queryFnContext,
@@ -169,16 +169,17 @@ type AnyTRPCQueryOptionsOut =
169
169
  * @internal
170
170
  */
171
171
  export function trpcQueryOptions(args: {
172
+ input: unknown;
172
173
  query: typeof TRPCUntypedClient.prototype.query;
173
174
  queryClient: QueryClient | (() => QueryClient);
174
175
  path: readonly string[];
175
176
  queryKey: TRPCQueryKey;
176
177
  opts: AnyTRPCQueryOptionsIn;
177
178
  }): AnyTRPCQueryOptionsOut {
178
- const { query, path, queryKey, opts } = args;
179
+ const { input, query, path, queryKey, opts } = args;
179
180
  const queryClient = unwrapLazyArg(args.queryClient);
180
181
 
181
- const inputIsSkipToken = queryKey[1]?.input === skipToken;
182
+ const inputIsSkipToken = input === skipToken;
182
183
 
183
184
  const queryFn: QueryFunction<unknown, TRPCQueryKey> = async (
184
185
  queryFnContext,
@@ -1,5 +1,14 @@
1
+ import type { InfiniteData } from '@tanstack/react-query';
1
2
  import type { TRPCRequestOptions } from '@trpc/client';
2
3
 
4
+ /**
5
+ * Turn a set of optional properties into required
6
+ * @internal
7
+ */
8
+ export type WithRequired<TObj, TKey extends keyof TObj> = TObj & {
9
+ [P in TKey]-?: TObj[P];
10
+ };
11
+
3
12
  /**
4
13
  * @internal
5
14
  */
@@ -10,13 +19,27 @@ export type ResolverDef = {
10
19
  errorShape: any;
11
20
  };
12
21
 
22
+ /**
23
+ * @remark `void` is here due to https://github.com/trpc/trpc/pull/4374
24
+ */
25
+ type CursorInput = { cursor?: any };
26
+ export type OptionalCursorInput = CursorInput | void;
27
+
13
28
  /**
14
29
  * @internal
15
30
  */
16
- export type ExtractCursorType<TInput> = TInput extends { cursor?: any }
31
+ export type ExtractCursorType<TInput> = TInput extends CursorInput
17
32
  ? TInput['cursor']
18
33
  : unknown;
19
34
 
35
+ /**
36
+ * @internal
37
+ */
38
+ export type TRPCInfiniteData<TInput, TOutput> = InfiniteData<
39
+ TOutput,
40
+ NonNullable<ExtractCursorType<TInput>> | null
41
+ >;
42
+
20
43
  /**
21
44
  * @public
22
45
  */