@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.
- package/dist/bundle-analysis.json +59 -76
- package/dist/createTRPCReact.d.ts +47 -17
- package/dist/createTRPCReact.d.ts.map +1 -1
- package/dist/internals/context.d.ts +43 -21
- package/dist/internals/context.d.ts.map +1 -1
- package/dist/internals/getQueryKey.d.ts +2 -2
- package/dist/internals/getQueryKey.js +3 -3
- package/dist/internals/getQueryKey.mjs +3 -3
- package/dist/internals/trpcResult.d.ts +18 -0
- package/dist/internals/trpcResult.d.ts.map +1 -0
- package/dist/internals/trpcResult.js +63 -0
- package/dist/internals/trpcResult.mjs +40 -0
- package/dist/internals/useQueries.d.ts +1 -1
- package/dist/internals/useQueries.d.ts.map +1 -1
- package/dist/rsc.d.ts +1 -1
- package/dist/rsc.d.ts.map +1 -1
- package/dist/rsc.js +4 -4
- package/dist/rsc.mjs +4 -4
- package/dist/server/ssgProxy.d.ts +7 -24
- package/dist/server/ssgProxy.d.ts.map +1 -1
- package/dist/server/ssgProxy.js +21 -4
- package/dist/server/ssgProxy.mjs +21 -4
- package/dist/shared/hooks/createHooksInternal.d.ts +4 -2
- package/dist/shared/hooks/createHooksInternal.d.ts.map +1 -1
- package/dist/shared/hooks/createHooksInternal.js +160 -93
- package/dist/shared/hooks/createHooksInternal.mjs +156 -89
- package/dist/shared/hooks/types.d.ts +38 -159
- package/dist/shared/hooks/types.d.ts.map +1 -1
- package/dist/shared/index.js +0 -7
- package/dist/shared/index.mjs +0 -1
- package/dist/shared/polymorphism/mutationLike.d.ts.map +1 -1
- package/dist/shared/polymorphism/queryLike.d.ts.map +1 -1
- package/dist/shared/polymorphism/routerLike.d.ts.map +1 -1
- package/dist/shared/proxy/decorationProxy.js +1 -1
- package/dist/shared/proxy/decorationProxy.mjs +1 -1
- package/dist/shared/proxy/useQueriesProxy.d.ts.map +1 -1
- package/dist/shared/proxy/utilsProxy.d.ts +45 -20
- package/dist/shared/proxy/utilsProxy.d.ts.map +1 -1
- package/dist/shared/proxy/utilsProxy.js +4 -0
- package/dist/shared/proxy/utilsProxy.mjs +4 -0
- package/dist/shared/types.d.ts +60 -2
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/utils/createUtilityFunctions.d.ts +2 -2
- package/dist/utils/createUtilityFunctions.d.ts.map +1 -1
- package/dist/utils/createUtilityFunctions.js +69 -3
- package/dist/utils/createUtilityFunctions.mjs +69 -3
- package/dist/utils/inferReactQueryProcedure.d.ts +2 -2
- package/dist/utils/inferReactQueryProcedure.d.ts.map +1 -1
- package/package.json +22 -19
- package/src/createTRPCReact.tsx +276 -65
- package/src/internals/context.tsx +105 -24
- package/src/internals/getQueryKey.ts +2 -2
- package/src/internals/trpcResult.ts +55 -0
- package/src/internals/useQueries.ts +36 -31
- package/src/rsc.tsx +6 -6
- package/src/server/ssgProxy.ts +23 -66
- package/src/shared/hooks/createHooksInternal.tsx +222 -151
- package/src/shared/hooks/types.ts +64 -348
- package/src/shared/polymorphism/mutationLike.ts +8 -6
- package/src/shared/polymorphism/queryLike.ts +12 -14
- package/src/shared/polymorphism/routerLike.ts +4 -4
- package/src/shared/proxy/useQueriesProxy.ts +4 -4
- package/src/shared/proxy/utilsProxy.ts +153 -25
- package/src/shared/types.ts +229 -1
- package/src/utils/createUtilityFunctions.ts +90 -2
- package/src/utils/inferReactQueryProcedure.ts +8 -6
- package/dist/internals/useHookResult.d.ts +0 -8
- package/dist/internals/useHookResult.d.ts.map +0 -1
- package/dist/internals/useHookResult.js +0 -35
- package/dist/internals/useHookResult.mjs +0 -14
- package/dist/shared/hooks/types.js +0 -133
- package/dist/shared/hooks/types.mjs +0 -126
- package/src/internals/useHookResult.ts +0 -17
|
@@ -10,6 +10,7 @@ import type {
|
|
|
10
10
|
RefetchQueryFilters,
|
|
11
11
|
ResetOptions,
|
|
12
12
|
SetDataOptions,
|
|
13
|
+
SkipToken,
|
|
13
14
|
Updater,
|
|
14
15
|
} from '@tanstack/react-query';
|
|
15
16
|
import type { TRPCClientError } from '@trpc/client';
|
|
@@ -44,13 +45,135 @@ import {
|
|
|
44
45
|
} from '../../internals/getQueryKey';
|
|
45
46
|
import type { InferMutationOptions } from '../../utils/inferReactQueryProcedure';
|
|
46
47
|
import type { ExtractCursorType } from '../hooks/types';
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
import type {
|
|
49
|
+
DefinedTRPCInfiniteQueryOptionsIn,
|
|
50
|
+
DefinedTRPCInfiniteQueryOptionsOut,
|
|
51
|
+
DefinedTRPCQueryOptionsIn,
|
|
52
|
+
DefinedTRPCQueryOptionsOut,
|
|
53
|
+
UndefinedTRPCInfiniteQueryOptionsIn,
|
|
54
|
+
UndefinedTRPCInfiniteQueryOptionsOut,
|
|
55
|
+
UndefinedTRPCQueryOptionsIn,
|
|
56
|
+
UndefinedTRPCQueryOptionsOut,
|
|
57
|
+
UnusedSkipTokenTRPCInfiniteQueryOptionsIn,
|
|
58
|
+
UnusedSkipTokenTRPCInfiniteQueryOptionsOut,
|
|
59
|
+
UnusedSkipTokenTRPCQueryOptionsIn,
|
|
60
|
+
UnusedSkipTokenTRPCQueryOptionsOut,
|
|
61
|
+
} from '../types';
|
|
62
|
+
|
|
63
|
+
export type DecorateQueryProcedure<
|
|
49
64
|
TRoot extends AnyRootTypes,
|
|
50
65
|
TProcedure extends AnyQueryProcedure,
|
|
51
66
|
> = {
|
|
52
67
|
/**
|
|
53
|
-
* @
|
|
68
|
+
* @see https://tanstack.com/query/latest/docs/framework/react/reference/queryOptions#queryoptions
|
|
69
|
+
*/
|
|
70
|
+
queryOptions<
|
|
71
|
+
TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
72
|
+
TData = TQueryFnData,
|
|
73
|
+
>(
|
|
74
|
+
input: inferProcedureInput<TProcedure> | SkipToken,
|
|
75
|
+
opts: DefinedTRPCQueryOptionsIn<
|
|
76
|
+
TQueryFnData,
|
|
77
|
+
TData,
|
|
78
|
+
TRPCClientError<TRoot>
|
|
79
|
+
>,
|
|
80
|
+
): DefinedTRPCQueryOptionsOut<TQueryFnData, TData, TRPCClientError<TRoot>>;
|
|
81
|
+
/**
|
|
82
|
+
* @see https://tanstack.com/query/latest/docs/framework/react/reference/queryOptions#queryoptions
|
|
83
|
+
*/
|
|
84
|
+
queryOptions<
|
|
85
|
+
TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
86
|
+
TData = TQueryFnData,
|
|
87
|
+
>(
|
|
88
|
+
input: inferProcedureInput<TProcedure> | SkipToken,
|
|
89
|
+
opts?: UnusedSkipTokenTRPCQueryOptionsIn<
|
|
90
|
+
TQueryFnData,
|
|
91
|
+
TData,
|
|
92
|
+
TRPCClientError<TRoot>
|
|
93
|
+
>,
|
|
94
|
+
): UnusedSkipTokenTRPCQueryOptionsOut<
|
|
95
|
+
TQueryFnData,
|
|
96
|
+
TData,
|
|
97
|
+
TRPCClientError<TRoot>
|
|
98
|
+
>;
|
|
99
|
+
/**
|
|
100
|
+
* @see https://tanstack.com/query/latest/docs/framework/react/reference/queryOptions#queryoptions
|
|
101
|
+
*/
|
|
102
|
+
queryOptions<
|
|
103
|
+
TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
104
|
+
TData = TQueryFnData,
|
|
105
|
+
>(
|
|
106
|
+
input: inferProcedureInput<TProcedure> | SkipToken,
|
|
107
|
+
opts?: UndefinedTRPCQueryOptionsIn<
|
|
108
|
+
TQueryFnData,
|
|
109
|
+
TData,
|
|
110
|
+
TRPCClientError<TRoot>
|
|
111
|
+
>,
|
|
112
|
+
): UndefinedTRPCQueryOptionsOut<TQueryFnData, TData, TRPCClientError<TRoot>>;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @see https://tanstack.com/query/latest/docs/framework/react/reference/infiniteQueryOptions#infinitequeryoptions
|
|
116
|
+
*/
|
|
117
|
+
infiniteQueryOptions<
|
|
118
|
+
TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
119
|
+
TData = TQueryFnData,
|
|
120
|
+
>(
|
|
121
|
+
input: inferProcedureInput<TProcedure> | SkipToken,
|
|
122
|
+
opts: DefinedTRPCInfiniteQueryOptionsIn<
|
|
123
|
+
inferProcedureInput<TProcedure>,
|
|
124
|
+
TQueryFnData,
|
|
125
|
+
TData,
|
|
126
|
+
TRPCClientError<TRoot>
|
|
127
|
+
>,
|
|
128
|
+
): DefinedTRPCInfiniteQueryOptionsOut<
|
|
129
|
+
inferProcedureInput<TProcedure>,
|
|
130
|
+
TQueryFnData,
|
|
131
|
+
TData,
|
|
132
|
+
TRPCClientError<TRoot>
|
|
133
|
+
>;
|
|
134
|
+
/**
|
|
135
|
+
* @see https://tanstack.com/query/latest/docs/framework/react/reference/infiniteQueryOptions#infinitequeryoptions
|
|
136
|
+
*/
|
|
137
|
+
infiniteQueryOptions<
|
|
138
|
+
TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
139
|
+
TData = TQueryFnData,
|
|
140
|
+
>(
|
|
141
|
+
input: inferProcedureInput<TProcedure>,
|
|
142
|
+
opts: UnusedSkipTokenTRPCInfiniteQueryOptionsIn<
|
|
143
|
+
inferProcedureInput<TProcedure>,
|
|
144
|
+
TQueryFnData,
|
|
145
|
+
TData,
|
|
146
|
+
TRPCClientError<TRoot>
|
|
147
|
+
>,
|
|
148
|
+
): UnusedSkipTokenTRPCInfiniteQueryOptionsOut<
|
|
149
|
+
inferProcedureInput<TProcedure>,
|
|
150
|
+
TQueryFnData,
|
|
151
|
+
TData,
|
|
152
|
+
TRPCClientError<TRoot>
|
|
153
|
+
>;
|
|
154
|
+
/**
|
|
155
|
+
* @see https://tanstack.com/query/latest/docs/framework/react/reference/infiniteQueryOptions#infinitequeryoptions
|
|
156
|
+
*/
|
|
157
|
+
infiniteQueryOptions<
|
|
158
|
+
TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
159
|
+
TData = TQueryFnData,
|
|
160
|
+
>(
|
|
161
|
+
input: inferProcedureInput<TProcedure> | SkipToken,
|
|
162
|
+
opts?: UndefinedTRPCInfiniteQueryOptionsIn<
|
|
163
|
+
inferProcedureInput<TProcedure>,
|
|
164
|
+
TQueryFnData,
|
|
165
|
+
TData,
|
|
166
|
+
TRPCClientError<TRoot>
|
|
167
|
+
>,
|
|
168
|
+
): UndefinedTRPCInfiniteQueryOptionsOut<
|
|
169
|
+
inferProcedureInput<TProcedure>,
|
|
170
|
+
TQueryFnData,
|
|
171
|
+
TData,
|
|
172
|
+
TRPCClientError<TRoot>
|
|
173
|
+
>;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchquery
|
|
54
177
|
*/
|
|
55
178
|
fetch(
|
|
56
179
|
input: inferProcedureInput<TProcedure>,
|
|
@@ -61,7 +184,7 @@ type DecorateQueryProcedure<
|
|
|
61
184
|
): Promise<inferTransformedProcedureOutput<TRoot, TProcedure>>;
|
|
62
185
|
|
|
63
186
|
/**
|
|
64
|
-
* @
|
|
187
|
+
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchinfinitequery
|
|
65
188
|
*/
|
|
66
189
|
fetchInfinite(
|
|
67
190
|
input: inferProcedureInput<TProcedure>,
|
|
@@ -78,7 +201,7 @@ type DecorateQueryProcedure<
|
|
|
78
201
|
>;
|
|
79
202
|
|
|
80
203
|
/**
|
|
81
|
-
* @
|
|
204
|
+
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientprefetchquery
|
|
82
205
|
*/
|
|
83
206
|
prefetch(
|
|
84
207
|
input: inferProcedureInput<TProcedure>,
|
|
@@ -89,7 +212,7 @@ type DecorateQueryProcedure<
|
|
|
89
212
|
): Promise<void>;
|
|
90
213
|
|
|
91
214
|
/**
|
|
92
|
-
* @
|
|
215
|
+
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientprefetchinfinitequery
|
|
93
216
|
*/
|
|
94
217
|
prefetchInfinite(
|
|
95
218
|
input: inferProcedureInput<TProcedure>,
|
|
@@ -101,7 +224,7 @@ type DecorateQueryProcedure<
|
|
|
101
224
|
): Promise<void>;
|
|
102
225
|
|
|
103
226
|
/**
|
|
104
|
-
* @
|
|
227
|
+
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientensurequerydata
|
|
105
228
|
*/
|
|
106
229
|
ensureData(
|
|
107
230
|
input: inferProcedureInput<TProcedure>,
|
|
@@ -112,7 +235,7 @@ type DecorateQueryProcedure<
|
|
|
112
235
|
): Promise<inferTransformedProcedureOutput<TRoot, TProcedure>>;
|
|
113
236
|
|
|
114
237
|
/**
|
|
115
|
-
* @
|
|
238
|
+
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientinvalidatequeries
|
|
116
239
|
*/
|
|
117
240
|
invalidate(
|
|
118
241
|
input?: DeepPartial<inferProcedureInput<TProcedure>>,
|
|
@@ -135,7 +258,7 @@ type DecorateQueryProcedure<
|
|
|
135
258
|
): Promise<void>;
|
|
136
259
|
|
|
137
260
|
/**
|
|
138
|
-
* @
|
|
261
|
+
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientrefetchqueries
|
|
139
262
|
*/
|
|
140
263
|
refetch(
|
|
141
264
|
input?: inferProcedureInput<TProcedure>,
|
|
@@ -144,7 +267,7 @@ type DecorateQueryProcedure<
|
|
|
144
267
|
): Promise<void>;
|
|
145
268
|
|
|
146
269
|
/**
|
|
147
|
-
* @
|
|
270
|
+
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientcancelqueries
|
|
148
271
|
*/
|
|
149
272
|
cancel(
|
|
150
273
|
input?: inferProcedureInput<TProcedure>,
|
|
@@ -152,7 +275,7 @@ type DecorateQueryProcedure<
|
|
|
152
275
|
): Promise<void>;
|
|
153
276
|
|
|
154
277
|
/**
|
|
155
|
-
* @
|
|
278
|
+
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientresetqueries
|
|
156
279
|
*/
|
|
157
280
|
reset(
|
|
158
281
|
input?: inferProcedureInput<TProcedure>,
|
|
@@ -160,7 +283,7 @@ type DecorateQueryProcedure<
|
|
|
160
283
|
): Promise<void>;
|
|
161
284
|
|
|
162
285
|
/**
|
|
163
|
-
* @
|
|
286
|
+
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
|
|
164
287
|
*/
|
|
165
288
|
setData(
|
|
166
289
|
/**
|
|
@@ -175,7 +298,7 @@ type DecorateQueryProcedure<
|
|
|
175
298
|
): void;
|
|
176
299
|
|
|
177
300
|
/**
|
|
178
|
-
* @
|
|
301
|
+
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
|
|
179
302
|
*/
|
|
180
303
|
setQueriesData(
|
|
181
304
|
/**
|
|
@@ -191,7 +314,7 @@ type DecorateQueryProcedure<
|
|
|
191
314
|
): [QueryKey, inferTransformedProcedureOutput<TRoot, TProcedure>];
|
|
192
315
|
|
|
193
316
|
/**
|
|
194
|
-
* @
|
|
317
|
+
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
|
|
195
318
|
*/
|
|
196
319
|
setInfiniteData(
|
|
197
320
|
input: inferProcedureInput<TProcedure>,
|
|
@@ -211,14 +334,14 @@ type DecorateQueryProcedure<
|
|
|
211
334
|
): void;
|
|
212
335
|
|
|
213
336
|
/**
|
|
214
|
-
* @
|
|
337
|
+
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata
|
|
215
338
|
*/
|
|
216
339
|
getData(
|
|
217
340
|
input?: inferProcedureInput<TProcedure>,
|
|
218
341
|
): inferTransformedProcedureOutput<TRoot, TProcedure> | undefined;
|
|
219
342
|
|
|
220
343
|
/**
|
|
221
|
-
* @
|
|
344
|
+
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata
|
|
222
345
|
*/
|
|
223
346
|
getInfiniteData(
|
|
224
347
|
input?: inferProcedureInput<TProcedure>,
|
|
@@ -234,14 +357,14 @@ type DecorateMutationProcedure<
|
|
|
234
357
|
TRoot extends AnyRootTypes,
|
|
235
358
|
TProcedure extends AnyMutationProcedure,
|
|
236
359
|
> = {
|
|
237
|
-
setMutationDefaults(
|
|
360
|
+
setMutationDefaults<TMeta = unknown>(
|
|
238
361
|
options:
|
|
239
|
-
| InferMutationOptions<TRoot, TProcedure>
|
|
362
|
+
| InferMutationOptions<TRoot, TProcedure, TMeta>
|
|
240
363
|
| ((args: {
|
|
241
364
|
canonicalMutationFn: NonNullable<
|
|
242
365
|
InferMutationOptions<TRoot, TProcedure>['mutationFn']
|
|
243
366
|
>;
|
|
244
|
-
}) => InferMutationOptions<TRoot, TProcedure>),
|
|
367
|
+
}) => InferMutationOptions<TRoot, TProcedure, TMeta>),
|
|
245
368
|
): void;
|
|
246
369
|
|
|
247
370
|
getMutationDefaults(): InferMutationOptions<TRoot, TProcedure> | undefined;
|
|
@@ -256,8 +379,8 @@ type DecorateMutationProcedure<
|
|
|
256
379
|
type DecorateRouter = {
|
|
257
380
|
/**
|
|
258
381
|
* Invalidate the full router
|
|
259
|
-
* @
|
|
260
|
-
* @
|
|
382
|
+
* @see https://trpc.io/docs/v10/useContext#query-invalidation
|
|
383
|
+
* @see https://tanstack.com/query/v5/docs/framework/react/guides/query-invalidation
|
|
261
384
|
*/
|
|
262
385
|
invalidate(
|
|
263
386
|
input?: undefined,
|
|
@@ -277,10 +400,10 @@ export type DecoratedProcedureUtilsRecord<
|
|
|
277
400
|
? $Value extends RouterRecord
|
|
278
401
|
? DecoratedProcedureUtilsRecord<TRoot, $Value> & DecorateRouter
|
|
279
402
|
: $Value extends AnyQueryProcedure
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
403
|
+
? DecorateQueryProcedure<TRoot, $Value>
|
|
404
|
+
: $Value extends AnyMutationProcedure
|
|
405
|
+
? DecorateMutationProcedure<TRoot, $Value>
|
|
406
|
+
: never
|
|
284
407
|
: never;
|
|
285
408
|
}; // Add functions that should be available at utils root
|
|
286
409
|
|
|
@@ -308,6 +431,7 @@ export const getQueryType = (
|
|
|
308
431
|
utilName: keyof AnyDecoratedProcedure,
|
|
309
432
|
): QueryType => {
|
|
310
433
|
switch (utilName) {
|
|
434
|
+
case 'queryOptions':
|
|
311
435
|
case 'fetch':
|
|
312
436
|
case 'ensureData':
|
|
313
437
|
case 'prefetch':
|
|
@@ -316,6 +440,7 @@ export const getQueryType = (
|
|
|
316
440
|
case 'setQueriesData':
|
|
317
441
|
return 'query';
|
|
318
442
|
|
|
443
|
+
case 'infiniteQueryOptions':
|
|
319
444
|
case 'fetchInfinite':
|
|
320
445
|
case 'prefetchInfinite':
|
|
321
446
|
case 'getInfiniteData':
|
|
@@ -350,6 +475,9 @@ function createRecursiveUtilsProxy<TRouter extends AnyRouter>(
|
|
|
350
475
|
const queryKey = getQueryKeyInternal(path, input, queryType);
|
|
351
476
|
|
|
352
477
|
const contextMap: Record<keyof AnyDecoratedProcedure, () => unknown> = {
|
|
478
|
+
infiniteQueryOptions: () =>
|
|
479
|
+
context.infiniteQueryOptions(path, queryKey, args[0]),
|
|
480
|
+
queryOptions: () => context.queryOptions(path, queryKey, ...args),
|
|
353
481
|
/**
|
|
354
482
|
* DecorateQueryProcedure
|
|
355
483
|
*/
|
package/src/shared/types.ts
CHANGED
|
@@ -1,8 +1,236 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
DataTag,
|
|
3
|
+
DefinedInitialDataInfiniteOptions,
|
|
4
|
+
DefinedInitialDataOptions,
|
|
5
|
+
InfiniteData,
|
|
6
|
+
QueryClient,
|
|
7
|
+
UndefinedInitialDataInfiniteOptions,
|
|
8
|
+
UndefinedInitialDataOptions,
|
|
9
|
+
UnusedSkipTokenInfiniteOptions,
|
|
10
|
+
UnusedSkipTokenOptions,
|
|
11
|
+
} from '@tanstack/react-query';
|
|
2
12
|
import type {
|
|
3
13
|
AnyRouter,
|
|
14
|
+
DistributiveOmit,
|
|
4
15
|
MaybePromise,
|
|
5
16
|
} from '@trpc/server/unstable-core-do-not-import';
|
|
17
|
+
import type { TRPCQueryKey } from '../internals/getQueryKey';
|
|
18
|
+
import type {
|
|
19
|
+
coerceAsyncIterableToArray,
|
|
20
|
+
ExtractCursorType,
|
|
21
|
+
TRPCReactRequestOptions,
|
|
22
|
+
} from './hooks/types';
|
|
23
|
+
|
|
24
|
+
export interface TRPCQueryBaseOptions {
|
|
25
|
+
/**
|
|
26
|
+
* tRPC-related options
|
|
27
|
+
*/
|
|
28
|
+
trpc?: TRPCReactRequestOptions;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface TRPCQueryOptionsResult {
|
|
32
|
+
trpc: {
|
|
33
|
+
path: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
type TRPCOptionOverrides = 'queryKey' | 'queryFn' | 'queryHashFn' | 'queryHash';
|
|
38
|
+
type TRPCInfiniteOptionOverrides = TRPCOptionOverrides | 'initialPageParam';
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* QueryOptions API helpers
|
|
42
|
+
*/
|
|
43
|
+
export interface UndefinedTRPCQueryOptionsIn<TQueryFnData, TData, TError>
|
|
44
|
+
extends DistributiveOmit<
|
|
45
|
+
UndefinedInitialDataOptions<
|
|
46
|
+
coerceAsyncIterableToArray<TQueryFnData>,
|
|
47
|
+
TError,
|
|
48
|
+
coerceAsyncIterableToArray<TData>,
|
|
49
|
+
TRPCQueryKey
|
|
50
|
+
>,
|
|
51
|
+
TRPCOptionOverrides
|
|
52
|
+
>,
|
|
53
|
+
TRPCQueryBaseOptions {}
|
|
54
|
+
|
|
55
|
+
export interface UndefinedTRPCQueryOptionsOut<TQueryFnData, TOutput, TError>
|
|
56
|
+
extends UndefinedInitialDataOptions<
|
|
57
|
+
coerceAsyncIterableToArray<TQueryFnData>,
|
|
58
|
+
TError,
|
|
59
|
+
coerceAsyncIterableToArray<TOutput>,
|
|
60
|
+
TRPCQueryKey
|
|
61
|
+
>,
|
|
62
|
+
TRPCQueryOptionsResult {
|
|
63
|
+
queryKey: DataTag<TRPCQueryKey, coerceAsyncIterableToArray<TOutput>>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface DefinedTRPCQueryOptionsIn<TQueryFnData, TData, TError>
|
|
67
|
+
extends DistributiveOmit<
|
|
68
|
+
DefinedInitialDataOptions<
|
|
69
|
+
coerceAsyncIterableToArray<TQueryFnData>,
|
|
70
|
+
TError,
|
|
71
|
+
coerceAsyncIterableToArray<TData>,
|
|
72
|
+
TRPCQueryKey
|
|
73
|
+
>,
|
|
74
|
+
TRPCOptionOverrides
|
|
75
|
+
>,
|
|
76
|
+
TRPCQueryBaseOptions {}
|
|
77
|
+
|
|
78
|
+
export interface DefinedTRPCQueryOptionsOut<TQueryFnData, TData, TError>
|
|
79
|
+
extends DefinedInitialDataOptions<
|
|
80
|
+
coerceAsyncIterableToArray<TQueryFnData>,
|
|
81
|
+
TError,
|
|
82
|
+
coerceAsyncIterableToArray<TData>,
|
|
83
|
+
TRPCQueryKey
|
|
84
|
+
>,
|
|
85
|
+
TRPCQueryOptionsResult {
|
|
86
|
+
queryKey: DataTag<TRPCQueryKey, coerceAsyncIterableToArray<TData>>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface UnusedSkipTokenTRPCQueryOptionsIn<TQueryFnData, TData, TError>
|
|
90
|
+
extends DistributiveOmit<
|
|
91
|
+
UnusedSkipTokenOptions<
|
|
92
|
+
coerceAsyncIterableToArray<TQueryFnData>,
|
|
93
|
+
TError,
|
|
94
|
+
coerceAsyncIterableToArray<TData>,
|
|
95
|
+
TRPCQueryKey
|
|
96
|
+
>,
|
|
97
|
+
TRPCOptionOverrides
|
|
98
|
+
>,
|
|
99
|
+
TRPCQueryBaseOptions {}
|
|
100
|
+
|
|
101
|
+
export interface UnusedSkipTokenTRPCQueryOptionsOut<
|
|
102
|
+
TQueryFnData,
|
|
103
|
+
TOutput,
|
|
104
|
+
TError,
|
|
105
|
+
> extends UnusedSkipTokenOptions<
|
|
106
|
+
coerceAsyncIterableToArray<TQueryFnData>,
|
|
107
|
+
TError,
|
|
108
|
+
coerceAsyncIterableToArray<TOutput>,
|
|
109
|
+
TRPCQueryKey
|
|
110
|
+
>,
|
|
111
|
+
TRPCQueryOptionsResult {
|
|
112
|
+
queryKey: DataTag<TRPCQueryKey, coerceAsyncIterableToArray<TOutput>>;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* InifiniteQueryOptions helpers
|
|
117
|
+
*/
|
|
118
|
+
export interface UndefinedTRPCInfiniteQueryOptionsIn<
|
|
119
|
+
TInput,
|
|
120
|
+
TQueryFnData,
|
|
121
|
+
TData,
|
|
122
|
+
TError,
|
|
123
|
+
> extends DistributiveOmit<
|
|
124
|
+
UndefinedInitialDataInfiniteOptions<
|
|
125
|
+
TQueryFnData,
|
|
126
|
+
TError,
|
|
127
|
+
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
|
|
128
|
+
TRPCQueryKey,
|
|
129
|
+
NonNullable<ExtractCursorType<TInput>> | null
|
|
130
|
+
>,
|
|
131
|
+
TRPCInfiniteOptionOverrides
|
|
132
|
+
>,
|
|
133
|
+
TRPCQueryBaseOptions {
|
|
134
|
+
initialCursor?: NonNullable<ExtractCursorType<TInput>> | null;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export interface UndefinedTRPCInfiniteQueryOptionsOut<
|
|
138
|
+
TInput,
|
|
139
|
+
TQueryFnData,
|
|
140
|
+
TData,
|
|
141
|
+
TError,
|
|
142
|
+
> extends DistributiveOmit<
|
|
143
|
+
UndefinedInitialDataInfiniteOptions<
|
|
144
|
+
TQueryFnData,
|
|
145
|
+
TError,
|
|
146
|
+
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
|
|
147
|
+
TRPCQueryKey,
|
|
148
|
+
NonNullable<ExtractCursorType<TInput>> | null
|
|
149
|
+
>,
|
|
150
|
+
'initialPageParam'
|
|
151
|
+
>,
|
|
152
|
+
TRPCQueryOptionsResult {
|
|
153
|
+
queryKey: DataTag<TRPCQueryKey, TData>;
|
|
154
|
+
initialPageParam: NonNullable<ExtractCursorType<TInput>> | null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface DefinedTRPCInfiniteQueryOptionsIn<
|
|
158
|
+
TInput,
|
|
159
|
+
TQueryFnData,
|
|
160
|
+
TData,
|
|
161
|
+
TError,
|
|
162
|
+
> extends DistributiveOmit<
|
|
163
|
+
DefinedInitialDataInfiniteOptions<
|
|
164
|
+
TQueryFnData,
|
|
165
|
+
TError,
|
|
166
|
+
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
|
|
167
|
+
TRPCQueryKey,
|
|
168
|
+
NonNullable<ExtractCursorType<TInput>> | null
|
|
169
|
+
>,
|
|
170
|
+
TRPCInfiniteOptionOverrides
|
|
171
|
+
>,
|
|
172
|
+
TRPCQueryBaseOptions {
|
|
173
|
+
initialCursor?: NonNullable<ExtractCursorType<TInput>> | null;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface DefinedTRPCInfiniteQueryOptionsOut<
|
|
177
|
+
TInput,
|
|
178
|
+
TQueryFnData,
|
|
179
|
+
TData,
|
|
180
|
+
TError,
|
|
181
|
+
> extends DistributiveOmit<
|
|
182
|
+
DefinedInitialDataInfiniteOptions<
|
|
183
|
+
TQueryFnData,
|
|
184
|
+
TError,
|
|
185
|
+
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
|
|
186
|
+
TRPCQueryKey,
|
|
187
|
+
NonNullable<ExtractCursorType<TInput>> | null
|
|
188
|
+
>,
|
|
189
|
+
'initialPageParam'
|
|
190
|
+
>,
|
|
191
|
+
TRPCQueryOptionsResult {
|
|
192
|
+
queryKey: DataTag<TRPCQueryKey, TData>;
|
|
193
|
+
initialPageParam: NonNullable<ExtractCursorType<TInput>> | null;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export interface UnusedSkipTokenTRPCInfiniteQueryOptionsIn<
|
|
197
|
+
TInput,
|
|
198
|
+
TQueryFnData,
|
|
199
|
+
TData,
|
|
200
|
+
TError,
|
|
201
|
+
> extends DistributiveOmit<
|
|
202
|
+
UnusedSkipTokenInfiniteOptions<
|
|
203
|
+
TQueryFnData,
|
|
204
|
+
TError,
|
|
205
|
+
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
|
|
206
|
+
TRPCQueryKey,
|
|
207
|
+
NonNullable<ExtractCursorType<TInput>> | null
|
|
208
|
+
>,
|
|
209
|
+
TRPCInfiniteOptionOverrides
|
|
210
|
+
>,
|
|
211
|
+
TRPCQueryBaseOptions {
|
|
212
|
+
initialCursor?: NonNullable<ExtractCursorType<TInput>> | null;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export interface UnusedSkipTokenTRPCInfiniteQueryOptionsOut<
|
|
216
|
+
TInput,
|
|
217
|
+
TQueryFnData,
|
|
218
|
+
TData,
|
|
219
|
+
TError,
|
|
220
|
+
> extends DistributiveOmit<
|
|
221
|
+
UnusedSkipTokenInfiniteOptions<
|
|
222
|
+
TQueryFnData,
|
|
223
|
+
TError,
|
|
224
|
+
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
|
|
225
|
+
TRPCQueryKey,
|
|
226
|
+
NonNullable<ExtractCursorType<TInput>> | null
|
|
227
|
+
>,
|
|
228
|
+
'initialPageParam'
|
|
229
|
+
>,
|
|
230
|
+
TRPCQueryOptionsResult {
|
|
231
|
+
queryKey: DataTag<TRPCQueryKey, TData>;
|
|
232
|
+
initialPageParam: NonNullable<ExtractCursorType<TInput>> | null;
|
|
233
|
+
}
|
|
6
234
|
|
|
7
235
|
/**
|
|
8
236
|
* @internal
|
|
@@ -1,9 +1,21 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { QueryFunctionContext } from '@tanstack/react-query';
|
|
2
|
+
import {
|
|
3
|
+
infiniteQueryOptions,
|
|
4
|
+
queryOptions,
|
|
5
|
+
skipToken,
|
|
6
|
+
type QueryClient,
|
|
7
|
+
} from '@tanstack/react-query';
|
|
2
8
|
import type { CreateTRPCClient } from '@trpc/client';
|
|
3
9
|
import { getUntypedClient, TRPCUntypedClient } from '@trpc/client';
|
|
4
10
|
import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
|
|
11
|
+
import { isAsyncIterable } from '@trpc/server/unstable-core-do-not-import';
|
|
5
12
|
import { getClientArgs } from '../internals/getClientArgs';
|
|
6
|
-
import type {
|
|
13
|
+
import type { TRPCQueryKey } from '../internals/getQueryKey';
|
|
14
|
+
import {
|
|
15
|
+
buildQueryFromAsyncIterable,
|
|
16
|
+
createTRPCOptionsResult,
|
|
17
|
+
} from '../internals/trpcResult';
|
|
18
|
+
import { type TRPCQueryUtils } from '../shared';
|
|
7
19
|
|
|
8
20
|
export interface CreateQueryUtilsOptions<TRouter extends AnyRouter> {
|
|
9
21
|
/**
|
|
@@ -30,6 +42,82 @@ export function createUtilityFunctions<TRouter extends AnyRouter>(
|
|
|
30
42
|
client instanceof TRPCUntypedClient ? client : getUntypedClient(client);
|
|
31
43
|
|
|
32
44
|
return {
|
|
45
|
+
infiniteQueryOptions: (path, queryKey, opts) => {
|
|
46
|
+
const inputIsSkipToken = queryKey[1]?.input === skipToken;
|
|
47
|
+
|
|
48
|
+
const queryFn = async (
|
|
49
|
+
queryFnContext: QueryFunctionContext<TRPCQueryKey, unknown>,
|
|
50
|
+
): Promise<unknown> => {
|
|
51
|
+
const actualOpts = {
|
|
52
|
+
...opts,
|
|
53
|
+
trpc: {
|
|
54
|
+
...opts?.trpc,
|
|
55
|
+
...(opts?.trpc?.abortOnUnmount
|
|
56
|
+
? { signal: queryFnContext.signal }
|
|
57
|
+
: { signal: null }),
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const result = await untypedClient.query(
|
|
62
|
+
...getClientArgs(queryKey, actualOpts, {
|
|
63
|
+
direction: queryFnContext.direction,
|
|
64
|
+
pageParam: queryFnContext.pageParam,
|
|
65
|
+
}),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
return result;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return Object.assign(
|
|
72
|
+
infiniteQueryOptions({
|
|
73
|
+
...opts,
|
|
74
|
+
initialData: opts?.initialData as any,
|
|
75
|
+
queryKey,
|
|
76
|
+
queryFn: inputIsSkipToken ? skipToken : queryFn,
|
|
77
|
+
initialPageParam: (opts?.initialCursor as any) ?? null,
|
|
78
|
+
}),
|
|
79
|
+
{ trpc: createTRPCOptionsResult({ path }) },
|
|
80
|
+
);
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
queryOptions: (path, queryKey, opts) => {
|
|
84
|
+
const inputIsSkipToken = queryKey[1]?.input === skipToken;
|
|
85
|
+
|
|
86
|
+
const queryFn = async (
|
|
87
|
+
queryFnContext: QueryFunctionContext<TRPCQueryKey>,
|
|
88
|
+
): Promise<unknown> => {
|
|
89
|
+
const actualOpts = {
|
|
90
|
+
...opts,
|
|
91
|
+
trpc: {
|
|
92
|
+
...opts?.trpc,
|
|
93
|
+
...(opts?.trpc?.abortOnUnmount
|
|
94
|
+
? { signal: queryFnContext.signal }
|
|
95
|
+
: { signal: null }),
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const result = await untypedClient.query(
|
|
100
|
+
...getClientArgs(queryKey, actualOpts),
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
if (isAsyncIterable(result)) {
|
|
104
|
+
return buildQueryFromAsyncIterable(result, queryClient, queryKey);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return result;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
return Object.assign(
|
|
111
|
+
queryOptions({
|
|
112
|
+
...opts,
|
|
113
|
+
initialData: opts?.initialData as any,
|
|
114
|
+
queryKey,
|
|
115
|
+
queryFn: inputIsSkipToken ? skipToken : queryFn,
|
|
116
|
+
}),
|
|
117
|
+
{ trpc: createTRPCOptionsResult({ path }) },
|
|
118
|
+
);
|
|
119
|
+
},
|
|
120
|
+
|
|
33
121
|
fetchQuery: (queryKey, opts) => {
|
|
34
122
|
return queryClient.fetchQuery({
|
|
35
123
|
...opts,
|