@trpc/react-query 11.23.0 → 11.23.1-canary.14.507382d73
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/{getQueryKey-BqoKYDMR.d.cts → getQueryKey-BI6_waNM.d.mts} +256 -19
- package/dist/getQueryKey-BI6_waNM.d.mts.map +1 -0
- package/dist/{getQueryKey-CMt5tN9-.d.mts → getQueryKey-CSENlbGR.d.cts} +256 -19
- package/dist/getQueryKey-CSENlbGR.d.cts.map +1 -0
- package/dist/{getQueryKey-D3tJ34z0.mjs → getQueryKey-CWSorJjT.mjs} +25 -9
- package/dist/getQueryKey-CWSorJjT.mjs.map +1 -0
- package/dist/{getQueryKey-Db_3VDGo.cjs → getQueryKey-DASF3nl1.cjs} +24 -8
- package/dist/index.cjs +24 -2
- package/dist/index.d.cts +10 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +10 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +24 -2
- package/dist/index.mjs.map +1 -1
- package/dist/rsc.cjs +9 -1
- package/dist/rsc.d.cts +9 -1
- package/dist/rsc.d.cts.map +1 -1
- package/dist/rsc.d.mts +9 -1
- package/dist/rsc.d.mts.map +1 -1
- package/dist/rsc.mjs +9 -1
- package/dist/rsc.mjs.map +1 -1
- package/dist/server/index.cjs +30 -11
- package/dist/server/index.d.cts +17 -3
- package/dist/server/index.d.cts.map +1 -1
- package/dist/server/index.d.mts +17 -3
- package/dist/server/index.d.mts.map +1 -1
- package/dist/server/index.mjs +30 -11
- package/dist/server/index.mjs.map +1 -1
- package/dist/shared/index.cjs +1 -1
- package/dist/shared/index.d.cts +1 -1
- package/dist/shared/index.d.mts +1 -1
- package/dist/shared/index.mjs +1 -1
- package/dist/{shared-Bw5jcbcM.mjs → shared-DyU-Vz6d.mjs} +11 -2
- package/dist/shared-DyU-Vz6d.mjs.map +1 -0
- package/dist/{shared-ByAY3gMr.cjs → shared-v3jJm-s7.cjs} +10 -1
- package/package.json +6 -6
- package/src/createTRPCQueryUtils.tsx +9 -0
- package/src/createTRPCReact.tsx +40 -7
- package/src/internals/context.tsx +21 -0
- package/src/internals/getQueryKey.ts +24 -8
- package/src/rsc.tsx +8 -0
- package/src/server/ssgProxy.ts +41 -5
- package/src/shared/hooks/types.ts +93 -0
- package/src/shared/polymorphism/routerLike.ts +3 -0
- package/src/shared/proxy/utilsProxy.ts +15 -0
- package/src/shared/types.ts +50 -2
- package/src/utils/inferReactQueryProcedure.ts +8 -0
- package/dist/getQueryKey-BqoKYDMR.d.cts.map +0 -1
- package/dist/getQueryKey-CMt5tN9-.d.mts.map +0 -1
- package/dist/getQueryKey-D3tJ34z0.mjs.map +0 -1
- package/dist/shared-Bw5jcbcM.mjs.map +0 -1
package/src/createTRPCReact.tsx
CHANGED
|
@@ -297,7 +297,7 @@ export type MaybeDecoratedInfiniteQuery<TDef extends ResolverDef> =
|
|
|
297
297
|
TDef['input'] extends CursorInput
|
|
298
298
|
? {
|
|
299
299
|
/**
|
|
300
|
-
* @see https://trpc.io/docs/
|
|
300
|
+
* @see https://trpc.io/docs/client/react/useInfiniteQuery
|
|
301
301
|
*/
|
|
302
302
|
useInfiniteQuery: useTRPCInfiniteQuery<TDef>;
|
|
303
303
|
/**
|
|
@@ -321,12 +321,12 @@ export type MaybeDecoratedInfiniteQuery<TDef extends ResolverDef> =
|
|
|
321
321
|
*/
|
|
322
322
|
export type DecoratedQueryMethods<TDef extends ResolverDef> = {
|
|
323
323
|
/**
|
|
324
|
-
* @see https://trpc.io/docs/
|
|
324
|
+
* @see https://trpc.io/docs/client/react/useQuery
|
|
325
325
|
*/
|
|
326
326
|
useQuery: ProcedureUseQuery<TDef>;
|
|
327
327
|
usePrefetchQuery: ProcedureUsePrefetchQuery<TDef>;
|
|
328
328
|
/**
|
|
329
|
-
* @see https://trpc.io/docs/
|
|
329
|
+
* @see https://trpc.io/docs/client/react/suspense#usesuspensequery
|
|
330
330
|
*/
|
|
331
331
|
useSuspenseQuery: <
|
|
332
332
|
TQueryFnData extends TDef['output'] = TDef['output'],
|
|
@@ -352,7 +352,7 @@ export type DecoratedQuery<TDef extends ResolverDef> =
|
|
|
352
352
|
|
|
353
353
|
export type DecoratedMutation<TDef extends ResolverDef> = {
|
|
354
354
|
/**
|
|
355
|
-
* @see https://trpc.io/docs/
|
|
355
|
+
* @see https://trpc.io/docs/client/react/useMutation
|
|
356
356
|
*/
|
|
357
357
|
useMutation: <TContext = unknown>(
|
|
358
358
|
opts?: UseTRPCMutationOptions<
|
|
@@ -410,7 +410,7 @@ export type DecorateProcedure<
|
|
|
410
410
|
: TType extends 'subscription'
|
|
411
411
|
? {
|
|
412
412
|
/**
|
|
413
|
-
* @see https://trpc.io/docs/
|
|
413
|
+
* @see https://trpc.io/docs/client/react/useSubscription
|
|
414
414
|
*/
|
|
415
415
|
useSubscription: ProcedureUseSubscription<TDef>;
|
|
416
416
|
}
|
|
@@ -447,19 +447,39 @@ export type CreateTRPCReactBase<TRouter extends AnyRouter, TSSRContext> = {
|
|
|
447
447
|
/**
|
|
448
448
|
* @deprecated renamed to `useUtils` and will be removed in a future tRPC version
|
|
449
449
|
*
|
|
450
|
-
* @see https://trpc.io/docs/
|
|
450
|
+
* @see https://trpc.io/docs/client/react/useUtils
|
|
451
451
|
*/
|
|
452
452
|
useContext(): CreateReactUtils<TRouter, TSSRContext>;
|
|
453
453
|
/**
|
|
454
|
-
* @see https://trpc.io/docs/
|
|
454
|
+
* @see https://trpc.io/docs/client/react/useUtils
|
|
455
455
|
*/
|
|
456
456
|
useUtils(): CreateReactUtils<TRouter, TSSRContext>;
|
|
457
|
+
/**
|
|
458
|
+
* Provides the tRPC client and `QueryClient` to the hooks.
|
|
459
|
+
* @see https://trpc.io/docs/client/react/setup#4-add-trpc-providers
|
|
460
|
+
*/
|
|
457
461
|
Provider: TRPCProvider<TRouter, TSSRContext>;
|
|
462
|
+
/**
|
|
463
|
+
* Same as `createTRPCClient`, typed for this router.
|
|
464
|
+
*/
|
|
458
465
|
createClient: typeof createTRPCClient<TRouter>;
|
|
466
|
+
/**
|
|
467
|
+
* @see https://trpc.io/docs/client/react/useQueries
|
|
468
|
+
*/
|
|
459
469
|
useQueries: TRPCUseQueries<TRouter>;
|
|
470
|
+
/**
|
|
471
|
+
* @see https://trpc.io/docs/client/react/suspense#usesuspensequeries
|
|
472
|
+
*/
|
|
460
473
|
useSuspenseQueries: TRPCUseSuspenseQueries<TRouter>;
|
|
461
474
|
};
|
|
462
475
|
|
|
476
|
+
/**
|
|
477
|
+
* The hooks object returned by {@link createTRPCReact}.
|
|
478
|
+
*
|
|
479
|
+
* @deprecated `@trpc/react-query` only gets bug fixes and will be removed in
|
|
480
|
+
* the next major version. Use `@trpc/tanstack-react-query` instead.
|
|
481
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/migrating
|
|
482
|
+
*/
|
|
463
483
|
export type CreateTRPCReact<
|
|
464
484
|
TRouter extends AnyRouter,
|
|
465
485
|
TSSRContext,
|
|
@@ -505,6 +525,19 @@ export function createHooksInternal<
|
|
|
505
525
|
});
|
|
506
526
|
}
|
|
507
527
|
|
|
528
|
+
/**
|
|
529
|
+
* Creates typed React hooks for your router, built on TanStack React Query.
|
|
530
|
+
*
|
|
531
|
+
* @example
|
|
532
|
+
* ```ts
|
|
533
|
+
* export const trpc = createTRPCReact<AppRouter>();
|
|
534
|
+
* ```
|
|
535
|
+
*
|
|
536
|
+
* @deprecated `@trpc/react-query` only gets bug fixes and will be removed in
|
|
537
|
+
* the next major version. Use `@trpc/tanstack-react-query` instead.
|
|
538
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/migrating
|
|
539
|
+
* @see https://trpc.io/docs/client/react/setup
|
|
540
|
+
*/
|
|
508
541
|
export function createTRPCReact<
|
|
509
542
|
TRouter extends AnyRouter,
|
|
510
543
|
TSSRContext = unknown,
|
|
@@ -46,6 +46,9 @@ interface TRPCUseUtilsOptions {
|
|
|
46
46
|
*/
|
|
47
47
|
trpc?: TRPCRequestOptions;
|
|
48
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Options for the `fetch` and `prefetch` helpers.
|
|
51
|
+
*/
|
|
49
52
|
export interface TRPCFetchQueryOptions<TOutput, TError>
|
|
50
53
|
extends
|
|
51
54
|
DistributiveOmit<FetchQueryOptions<TOutput, TError>, 'queryKey'>,
|
|
@@ -53,6 +56,9 @@ export interface TRPCFetchQueryOptions<TOutput, TError>
|
|
|
53
56
|
//
|
|
54
57
|
}
|
|
55
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Options for the `fetchInfinite` and `prefetchInfinite` helpers.
|
|
61
|
+
*/
|
|
56
62
|
export type TRPCFetchInfiniteQueryOptions<TInput, TOutput, TError> =
|
|
57
63
|
DistributiveOmit<
|
|
58
64
|
FetchInfiniteQueryOptions<
|
|
@@ -65,12 +71,18 @@ export type TRPCFetchInfiniteQueryOptions<TInput, TOutput, TError> =
|
|
|
65
71
|
'queryKey' | 'initialPageParam'
|
|
66
72
|
> &
|
|
67
73
|
TRPCUseUtilsOptions & {
|
|
74
|
+
/**
|
|
75
|
+
* The cursor for the first page.
|
|
76
|
+
*/
|
|
68
77
|
initialCursor?: ExtractCursorType<TInput>;
|
|
69
78
|
};
|
|
70
79
|
|
|
71
80
|
/** @internal */
|
|
72
81
|
export type SSRState = 'mounted' | 'mounting' | 'prepass' | false;
|
|
73
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Props shared by the tRPC React context and its `Provider`.
|
|
85
|
+
*/
|
|
74
86
|
export interface TRPCContextPropsBase<TRouter extends AnyRouter, TSSRContext> {
|
|
75
87
|
/**
|
|
76
88
|
* The `TRPCClient`
|
|
@@ -108,6 +120,9 @@ export type DecoratedTRPCContextProps<
|
|
|
108
120
|
client: TRPCClient<TRouter>;
|
|
109
121
|
};
|
|
110
122
|
|
|
123
|
+
/**
|
|
124
|
+
* Props for the tRPC React context: the base props plus a `QueryClient`.
|
|
125
|
+
*/
|
|
111
126
|
export interface TRPCContextProps<
|
|
112
127
|
TRouter extends AnyRouter,
|
|
113
128
|
TSSRContext,
|
|
@@ -118,6 +133,9 @@ export interface TRPCContextProps<
|
|
|
118
133
|
queryClient: QueryClient;
|
|
119
134
|
}
|
|
120
135
|
|
|
136
|
+
/**
|
|
137
|
+
* The keys of {@link TRPCContextPropsBase}.
|
|
138
|
+
*/
|
|
121
139
|
export const contextProps: (keyof TRPCContextPropsBase<any, any>)[] = [
|
|
122
140
|
'client',
|
|
123
141
|
'ssrContext',
|
|
@@ -353,4 +371,7 @@ export interface TRPCQueryUtils<TRouter extends AnyRouter> {
|
|
|
353
371
|
*/
|
|
354
372
|
isMutating: (filters: { mutationKey: TRPCMutationKey }) => number;
|
|
355
373
|
}
|
|
374
|
+
/**
|
|
375
|
+
* The React context that holds the tRPC client and `QueryClient`.
|
|
376
|
+
*/
|
|
356
377
|
export const TRPCContext = React.createContext?.(null as any);
|
|
@@ -100,11 +100,22 @@ type GetParams<TProcedureOrRouter extends ProcedureOrRouter> =
|
|
|
100
100
|
: [];
|
|
101
101
|
|
|
102
102
|
/**
|
|
103
|
-
*
|
|
104
|
-
* @param procedureOrRouter - procedure or
|
|
105
|
-
* @param input - input to
|
|
106
|
-
*
|
|
107
|
-
* @
|
|
103
|
+
* Returns the TanStack Query key for a procedure or router.
|
|
104
|
+
* @param procedureOrRouter - a procedure or router from `createTRPCReact`
|
|
105
|
+
* @param input - the procedure input. Leave it out to match every input in
|
|
106
|
+
* fuzzy operations like `invalidateQueries`.
|
|
107
|
+
* @param type - `'query'`, `'infinite'` or `'any'` (default). `'any'` leaves
|
|
108
|
+
* the type out of the key, so exact reads like `getQueryData` need the same
|
|
109
|
+
* input the query used and the matching type. Infinite query keys leave out
|
|
110
|
+
* `cursor` and `direction`.
|
|
111
|
+
*
|
|
112
|
+
* @deprecated `@trpc/react-query` only gets bug fixes and will be removed in
|
|
113
|
+
* the next major version. Use `@trpc/tanstack-react-query` instead, where
|
|
114
|
+
* each query procedure has a `queryKey()` method and each router has a
|
|
115
|
+
* `pathKey()` method.
|
|
116
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/migrating
|
|
117
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/usage#queryKey
|
|
118
|
+
* @see https://trpc.io/docs/client/react/getQueryKey
|
|
108
119
|
*/
|
|
109
120
|
export function getQueryKey<TProcedureOrRouter extends ProcedureOrRouter>(
|
|
110
121
|
procedureOrRouter: TProcedureOrRouter,
|
|
@@ -125,9 +136,14 @@ export type QueryKeyKnown<TInput, TType extends Exclude<QueryType, 'any'>> = [
|
|
|
125
136
|
];
|
|
126
137
|
|
|
127
138
|
/**
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
* @
|
|
139
|
+
* Returns the TanStack Query mutation key for a procedure.
|
|
140
|
+
*
|
|
141
|
+
* @deprecated `@trpc/react-query` only gets bug fixes and will be removed in
|
|
142
|
+
* the next major version. Use `@trpc/tanstack-react-query` instead, where
|
|
143
|
+
* each mutation has a `mutationKey()` method.
|
|
144
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/migrating
|
|
145
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/usage#mutationKey
|
|
146
|
+
* @see https://trpc.io/docs/client/react/getQueryKey#mutations
|
|
131
147
|
*/
|
|
132
148
|
export function getMutationKey<TProcedure extends DecoratedMutation<any>>(
|
|
133
149
|
procedure: TProcedure,
|
package/src/rsc.tsx
CHANGED
|
@@ -74,6 +74,9 @@ type Caller<TRouter extends AnyRouter> = ReturnType<
|
|
|
74
74
|
|
|
75
75
|
// ts-prune-ignore-next
|
|
76
76
|
/**
|
|
77
|
+
* Creates a server-side caller that can also prefetch queries, plus a
|
|
78
|
+
* `HydrateClient` component that sends the prefetched data to the client.
|
|
79
|
+
*
|
|
77
80
|
* @note This requires `@tanstack/react-query@^5.49.0`
|
|
78
81
|
* @note Make sure to have `dehydrate.serializeData` and `hydrate.deserializeData`
|
|
79
82
|
* set to your data transformer in your `QueryClient` factory.
|
|
@@ -91,6 +94,11 @@ type Caller<TRouter extends AnyRouter> = ReturnType<
|
|
|
91
94
|
* },
|
|
92
95
|
* });
|
|
93
96
|
* ```
|
|
97
|
+
*
|
|
98
|
+
* @deprecated `@trpc/react-query` only gets bug fixes and will be removed in
|
|
99
|
+
* the next major version. Use `@trpc/tanstack-react-query` instead.
|
|
100
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/migrating
|
|
101
|
+
* @see https://trpc.io/docs/client/react/server-components
|
|
94
102
|
*/
|
|
95
103
|
export function createHydrationHelpers<TRouter extends AnyRouter>(
|
|
96
104
|
caller: AnyRouter extends TRouter
|
package/src/server/ssgProxy.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type {
|
|
|
2
2
|
DehydratedState,
|
|
3
3
|
DehydrateOptions,
|
|
4
4
|
QueryClient,
|
|
5
|
+
QueryFunctionContext,
|
|
5
6
|
} from '@tanstack/react-query';
|
|
6
7
|
import { dehydrate } from '@tanstack/react-query';
|
|
7
8
|
import type { TRPCClient } from '@trpc/client';
|
|
@@ -27,6 +28,8 @@ import {
|
|
|
27
28
|
createRecursiveProxy,
|
|
28
29
|
run,
|
|
29
30
|
} from '@trpc/server/unstable-core-do-not-import';
|
|
31
|
+
import { getClientArgs } from '../internals/getClientArgs';
|
|
32
|
+
import type { TRPCQueryKey } from '../internals/getQueryKey';
|
|
30
33
|
import { getQueryKeyInternal } from '../internals/getQueryKey';
|
|
31
34
|
import type {
|
|
32
35
|
CreateTRPCReactQueryClientConfig,
|
|
@@ -37,11 +40,20 @@ import type {
|
|
|
37
40
|
import { getQueryClient, getQueryType } from '../shared';
|
|
38
41
|
|
|
39
42
|
type CreateSSGHelpersInternal<TRouter extends AnyRouter> = {
|
|
43
|
+
/**
|
|
44
|
+
* Call this router directly, without HTTP.
|
|
45
|
+
*/
|
|
40
46
|
router: TRouter;
|
|
47
|
+
/**
|
|
48
|
+
* The context to call procedures with.
|
|
49
|
+
*/
|
|
41
50
|
ctx: inferRouterContext<TRouter>;
|
|
42
51
|
} & TransformerOptions<inferClientTypes<TRouter>>;
|
|
43
52
|
|
|
44
53
|
interface CreateSSGHelpersExternal<TRouter extends AnyRouter> {
|
|
54
|
+
/**
|
|
55
|
+
* Call procedures through this tRPC client.
|
|
56
|
+
*/
|
|
45
57
|
client: TRPCClient<TRouter> | TRPCUntypedClient<TRouter>;
|
|
46
58
|
}
|
|
47
59
|
|
|
@@ -76,8 +88,13 @@ type DecoratedProcedureSSGRecord<
|
|
|
76
88
|
type AnyDecoratedProcedure = Pick<DecorateQueryProcedure<any, any>, SSGFns>;
|
|
77
89
|
|
|
78
90
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
91
|
+
* Creates helpers that fetch or prefetch queries on the server, for
|
|
92
|
+
* server-side rendering and static generation.
|
|
93
|
+
*
|
|
94
|
+
* @deprecated `@trpc/react-query` only gets bug fixes and will be removed in
|
|
95
|
+
* the next major version. Use `@trpc/tanstack-react-query` instead.
|
|
96
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/migrating
|
|
97
|
+
* @see https://trpc.io/docs/client/nextjs/pages-router/server-side-helpers
|
|
81
98
|
*/
|
|
82
99
|
export function createServerSideHelpers<TRouter extends AnyRouter>(
|
|
83
100
|
opts: CreateServerSideHelpersOptions<TRouter>,
|
|
@@ -168,6 +185,20 @@ export function createServerSideHelpers<TRouter extends AnyRouter>(
|
|
|
168
185
|
const queryFn = () =>
|
|
169
186
|
resolvedOpts.query({ path: arrayPath.join('.'), input });
|
|
170
187
|
|
|
188
|
+
const infiniteQueryFn = ({
|
|
189
|
+
pageParam,
|
|
190
|
+
direction,
|
|
191
|
+
}: QueryFunctionContext<TRPCQueryKey, unknown>) => {
|
|
192
|
+
const initialCursor = (args[1] as Maybe<{ initialCursor?: unknown }>)
|
|
193
|
+
?.initialCursor;
|
|
194
|
+
const [path, infiniteInput] = getClientArgs(
|
|
195
|
+
[arrayPath, { input }],
|
|
196
|
+
undefined,
|
|
197
|
+
{ pageParam: pageParam ?? initialCursor, direction },
|
|
198
|
+
);
|
|
199
|
+
return resolvedOpts.query({ path, input: infiniteInput });
|
|
200
|
+
};
|
|
201
|
+
|
|
171
202
|
const queryKey = getQueryKeyInternal(
|
|
172
203
|
arrayPath,
|
|
173
204
|
input,
|
|
@@ -181,7 +212,12 @@ export function createServerSideHelpers<TRouter extends AnyRouter>(
|
|
|
181
212
|
},
|
|
182
213
|
infiniteQueryOptions: () => {
|
|
183
214
|
const args1 = args[1] as Maybe<any>;
|
|
184
|
-
return {
|
|
215
|
+
return {
|
|
216
|
+
...args1,
|
|
217
|
+
queryKey,
|
|
218
|
+
queryFn: infiniteQueryFn,
|
|
219
|
+
initialPageParam: args1?.initialCursor ?? null,
|
|
220
|
+
};
|
|
185
221
|
},
|
|
186
222
|
fetch: () => {
|
|
187
223
|
const args1 = args[1] as Maybe<TRPCFetchQueryOptions<any, any>>;
|
|
@@ -194,7 +230,7 @@ export function createServerSideHelpers<TRouter extends AnyRouter>(
|
|
|
194
230
|
return queryClient.fetchInfiniteQuery({
|
|
195
231
|
...args1,
|
|
196
232
|
queryKey,
|
|
197
|
-
queryFn,
|
|
233
|
+
queryFn: infiniteQueryFn,
|
|
198
234
|
initialPageParam: args1?.initialCursor ?? null,
|
|
199
235
|
});
|
|
200
236
|
},
|
|
@@ -209,7 +245,7 @@ export function createServerSideHelpers<TRouter extends AnyRouter>(
|
|
|
209
245
|
return queryClient.prefetchInfiniteQuery({
|
|
210
246
|
...args1,
|
|
211
247
|
queryKey,
|
|
212
|
-
queryFn,
|
|
248
|
+
queryFn: infiniteQueryFn,
|
|
213
249
|
initialPageParam: args1?.initialCursor ?? null,
|
|
214
250
|
});
|
|
215
251
|
},
|
|
@@ -33,11 +33,17 @@ import type { JSX, ReactNode } from 'react';
|
|
|
33
33
|
import type { TRPCContextProps } from '../../internals/context';
|
|
34
34
|
import type { TRPCQueryKey } from '../../internals/getQueryKey';
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* A page of data and the cursor that fetched it.
|
|
38
|
+
*/
|
|
36
39
|
export type OutputWithCursor<TData, TCursor = any> = {
|
|
37
40
|
cursor: TCursor | null;
|
|
38
41
|
data: TData;
|
|
39
42
|
};
|
|
40
43
|
|
|
44
|
+
/**
|
|
45
|
+
* tRPC options for a single hook call, passed as `trpc`.
|
|
46
|
+
*/
|
|
41
47
|
export interface TRPCReactRequestOptions
|
|
42
48
|
// For RQ, we use their internal AbortSignals instead of letting the user pass their own
|
|
43
49
|
extends Omit<TRPCRequestOptions, 'signal'> {
|
|
@@ -51,6 +57,9 @@ export interface TRPCReactRequestOptions
|
|
|
51
57
|
abortOnUnmount?: boolean;
|
|
52
58
|
}
|
|
53
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Adds the `trpc` option to TanStack Query options.
|
|
62
|
+
*/
|
|
54
63
|
export interface TRPCUseQueryBaseOptions {
|
|
55
64
|
/**
|
|
56
65
|
* tRPC-related options
|
|
@@ -58,6 +67,10 @@ export interface TRPCUseQueryBaseOptions {
|
|
|
58
67
|
trpc?: TRPCReactRequestOptions;
|
|
59
68
|
}
|
|
60
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Options for `useQuery`: TanStack Query options without `queryKey`, plus `trpc`.
|
|
72
|
+
* @see https://trpc.io/docs/client/react/useQuery
|
|
73
|
+
*/
|
|
61
74
|
export interface UseTRPCQueryOptions<
|
|
62
75
|
TOutput,
|
|
63
76
|
TData,
|
|
@@ -71,6 +84,10 @@ export interface UseTRPCQueryOptions<
|
|
|
71
84
|
>,
|
|
72
85
|
TRPCUseQueryBaseOptions {}
|
|
73
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Options for `useSuspenseQuery`.
|
|
89
|
+
* @see https://trpc.io/docs/client/react/suspense#usesuspensequery
|
|
90
|
+
*/
|
|
74
91
|
export interface UseTRPCSuspenseQueryOptions<TOutput, TData, TError>
|
|
75
92
|
extends
|
|
76
93
|
DistributiveOmit<
|
|
@@ -79,6 +96,10 @@ export interface UseTRPCSuspenseQueryOptions<TOutput, TData, TError>
|
|
|
79
96
|
>,
|
|
80
97
|
TRPCUseQueryBaseOptions {}
|
|
81
98
|
|
|
99
|
+
/**
|
|
100
|
+
* Options for `usePrefetchQuery`.
|
|
101
|
+
* @see https://trpc.io/docs/client/react/suspense#component-level-prefetching-with-useprefetchquery
|
|
102
|
+
*/
|
|
82
103
|
export interface UseTRPCPrefetchQueryOptions<TOutput, TData, TError>
|
|
83
104
|
extends
|
|
84
105
|
DistributiveOmit<
|
|
@@ -100,6 +121,9 @@ export interface DefinedUseTRPCQueryOptions<
|
|
|
100
121
|
initialData: InitialDataFunction<TQueryOptsData> | TQueryOptsData;
|
|
101
122
|
}
|
|
102
123
|
|
|
124
|
+
/**
|
|
125
|
+
* TanStack Query options with a tRPC query key.
|
|
126
|
+
*/
|
|
103
127
|
export interface TRPCQueryOptions<TData, TError>
|
|
104
128
|
extends
|
|
105
129
|
DistributiveOmit<QueryOptions<TData, TError, TData, any>, 'queryKey'>,
|
|
@@ -107,10 +131,17 @@ export interface TRPCQueryOptions<TData, TError>
|
|
|
107
131
|
queryKey: TRPCQueryKey;
|
|
108
132
|
}
|
|
109
133
|
|
|
134
|
+
/**
|
|
135
|
+
* The type of the `cursor` field in a procedure's input.
|
|
136
|
+
*/
|
|
110
137
|
export type ExtractCursorType<TInput> = TInput extends { cursor?: any }
|
|
111
138
|
? TInput['cursor']
|
|
112
139
|
: unknown;
|
|
113
140
|
|
|
141
|
+
/**
|
|
142
|
+
* Options for `useInfiniteQuery`. Use `initialCursor` instead of `initialPageParam`.
|
|
143
|
+
* @see https://trpc.io/docs/client/react/useInfiniteQuery
|
|
144
|
+
*/
|
|
114
145
|
export interface UseTRPCInfiniteQueryOptions<TInput, TOutput, TError>
|
|
115
146
|
extends
|
|
116
147
|
DistributiveOmit<
|
|
@@ -124,9 +155,16 @@ export interface UseTRPCInfiniteQueryOptions<TInput, TOutput, TError>
|
|
|
124
155
|
'queryKey' | 'initialPageParam'
|
|
125
156
|
>,
|
|
126
157
|
TRPCUseQueryBaseOptions {
|
|
158
|
+
/**
|
|
159
|
+
* The cursor for the first page.
|
|
160
|
+
*/
|
|
127
161
|
initialCursor?: ExtractCursorType<TInput>;
|
|
128
162
|
}
|
|
129
163
|
|
|
164
|
+
/**
|
|
165
|
+
* Options for `usePrefetchInfiniteQuery`.
|
|
166
|
+
* @see https://trpc.io/docs/client/react/suspense#component-level-prefetching-with-useprefetchinfinitequery
|
|
167
|
+
*/
|
|
130
168
|
export type UseTRPCPrefetchInfiniteQueryOptions<TInput, TOutput, TError> =
|
|
131
169
|
DistributiveOmit<
|
|
132
170
|
FetchInfiniteQueryOptions<
|
|
@@ -139,9 +177,16 @@ export type UseTRPCPrefetchInfiniteQueryOptions<TInput, TOutput, TError> =
|
|
|
139
177
|
'queryKey' | 'initialPageParam'
|
|
140
178
|
> &
|
|
141
179
|
TRPCUseQueryBaseOptions & {
|
|
180
|
+
/**
|
|
181
|
+
* The cursor for the first page.
|
|
182
|
+
*/
|
|
142
183
|
initialCursor?: ExtractCursorType<TInput>;
|
|
143
184
|
};
|
|
144
185
|
|
|
186
|
+
/**
|
|
187
|
+
* Options for `useSuspenseInfiniteQuery`.
|
|
188
|
+
* @see https://trpc.io/docs/client/react/suspense#usesuspenseinfinitequery
|
|
189
|
+
*/
|
|
145
190
|
export interface UseTRPCSuspenseInfiniteQueryOptions<TInput, TOutput, TError>
|
|
146
191
|
extends
|
|
147
192
|
DistributiveOmit<
|
|
@@ -155,9 +200,16 @@ export interface UseTRPCSuspenseInfiniteQueryOptions<TInput, TOutput, TError>
|
|
|
155
200
|
'queryKey' | 'initialPageParam'
|
|
156
201
|
>,
|
|
157
202
|
TRPCUseQueryBaseOptions {
|
|
203
|
+
/**
|
|
204
|
+
* The cursor for the first page.
|
|
205
|
+
*/
|
|
158
206
|
initialCursor?: ExtractCursorType<TInput>;
|
|
159
207
|
}
|
|
160
208
|
|
|
209
|
+
/**
|
|
210
|
+
* Options for `useMutation`.
|
|
211
|
+
* @see https://trpc.io/docs/client/react/useMutation
|
|
212
|
+
*/
|
|
161
213
|
export interface UseTRPCMutationOptions<
|
|
162
214
|
TInput,
|
|
163
215
|
TError,
|
|
@@ -168,6 +220,10 @@ export interface UseTRPCMutationOptions<
|
|
|
168
220
|
UseMutationOptions<TOutput, TError, TInput, TContext>,
|
|
169
221
|
TRPCUseQueryBaseOptions {}
|
|
170
222
|
|
|
223
|
+
/**
|
|
224
|
+
* Options for `useSubscription`.
|
|
225
|
+
* @see https://trpc.io/docs/client/react/useSubscription#options
|
|
226
|
+
*/
|
|
171
227
|
export interface UseTRPCSubscriptionOptions<TOutput, TError> {
|
|
172
228
|
/**
|
|
173
229
|
* @deprecated
|
|
@@ -197,6 +253,10 @@ export interface UseTRPCSubscriptionOptions<TOutput, TError> {
|
|
|
197
253
|
trpc?: Pick<TRPCRequestOptions, 'context'>;
|
|
198
254
|
}
|
|
199
255
|
|
|
256
|
+
/**
|
|
257
|
+
* Fields shared by every `useSubscription` result.
|
|
258
|
+
* @see https://trpc.io/docs/client/react/useSubscription#return-type
|
|
259
|
+
*/
|
|
200
260
|
export interface TRPCSubscriptionBaseResult<TOutput, TError> {
|
|
201
261
|
status: 'idle' | 'connecting' | 'pending' | 'error';
|
|
202
262
|
data: undefined | TOutput;
|
|
@@ -207,6 +267,9 @@ export interface TRPCSubscriptionBaseResult<TOutput, TError> {
|
|
|
207
267
|
reset: () => void;
|
|
208
268
|
}
|
|
209
269
|
|
|
270
|
+
/**
|
|
271
|
+
* `useSubscription` result while the subscription is not running.
|
|
272
|
+
*/
|
|
210
273
|
export interface TRPCSubscriptionIdleResult<
|
|
211
274
|
TOutput,
|
|
212
275
|
> extends TRPCSubscriptionBaseResult<TOutput, null> {
|
|
@@ -215,6 +278,9 @@ export interface TRPCSubscriptionIdleResult<
|
|
|
215
278
|
error: null;
|
|
216
279
|
}
|
|
217
280
|
|
|
281
|
+
/**
|
|
282
|
+
* `useSubscription` result while connecting or reconnecting.
|
|
283
|
+
*/
|
|
218
284
|
export interface TRPCSubscriptionConnectingResult<
|
|
219
285
|
TOutput,
|
|
220
286
|
TError,
|
|
@@ -224,6 +290,10 @@ export interface TRPCSubscriptionConnectingResult<
|
|
|
224
290
|
error: TError | null;
|
|
225
291
|
}
|
|
226
292
|
|
|
293
|
+
/**
|
|
294
|
+
* `useSubscription` result while the subscription is active. It stays
|
|
295
|
+
* `pending` after data arrives, so `data` may be set.
|
|
296
|
+
*/
|
|
227
297
|
export interface TRPCSubscriptionPendingResult<
|
|
228
298
|
TOutput,
|
|
229
299
|
> extends TRPCSubscriptionBaseResult<TOutput, undefined> {
|
|
@@ -232,6 +302,9 @@ export interface TRPCSubscriptionPendingResult<
|
|
|
232
302
|
error: null;
|
|
233
303
|
}
|
|
234
304
|
|
|
305
|
+
/**
|
|
306
|
+
* `useSubscription` result after an error that stopped the subscription.
|
|
307
|
+
*/
|
|
235
308
|
export interface TRPCSubscriptionErrorResult<
|
|
236
309
|
TOutput,
|
|
237
310
|
TError,
|
|
@@ -241,12 +314,19 @@ export interface TRPCSubscriptionErrorResult<
|
|
|
241
314
|
error: TError;
|
|
242
315
|
}
|
|
243
316
|
|
|
317
|
+
/**
|
|
318
|
+
* The result of `useSubscription`. Check `status` to narrow it.
|
|
319
|
+
* @see https://trpc.io/docs/client/react/useSubscription#return-type
|
|
320
|
+
*/
|
|
244
321
|
export type TRPCSubscriptionResult<TOutput, TError> =
|
|
245
322
|
| TRPCSubscriptionIdleResult<TOutput>
|
|
246
323
|
| TRPCSubscriptionConnectingResult<TOutput, TError>
|
|
247
324
|
| TRPCSubscriptionErrorResult<TOutput, TError>
|
|
248
325
|
| TRPCSubscriptionPendingResult<TOutput>;
|
|
249
326
|
|
|
327
|
+
/**
|
|
328
|
+
* Props for the `Provider` from `createTRPCReact`.
|
|
329
|
+
*/
|
|
250
330
|
export interface TRPCProviderProps<
|
|
251
331
|
TRouter extends AnyRouter,
|
|
252
332
|
TSSRContext,
|
|
@@ -255,10 +335,17 @@ export interface TRPCProviderProps<
|
|
|
255
335
|
client: TRPCClient<TRouter> | TRPCUntypedClient<TRouter>;
|
|
256
336
|
}
|
|
257
337
|
|
|
338
|
+
/**
|
|
339
|
+
* The `Provider` component from `createTRPCReact`.
|
|
340
|
+
* @see https://trpc.io/docs/client/react/setup#4-add-trpc-providers
|
|
341
|
+
*/
|
|
258
342
|
export type TRPCProvider<TRouter extends AnyRouter, TSSRContext> = (
|
|
259
343
|
props: TRPCProviderProps<TRouter, TSSRContext>,
|
|
260
344
|
) => JSX.Element;
|
|
261
345
|
|
|
346
|
+
/**
|
|
347
|
+
* A function that creates a tRPC client.
|
|
348
|
+
*/
|
|
262
349
|
export type CreateClient<TRouter extends AnyRouter> = (
|
|
263
350
|
opts: CreateTRPCClientOptions<TRouter>,
|
|
264
351
|
) => TRPCUntypedClient<TRouter>;
|
|
@@ -329,8 +416,14 @@ export type UseTRPCSuspenseInfiniteQueryResult<TData, TError, TInput> = [
|
|
|
329
416
|
export type UseTRPCMutationResult<TData, TError, TVariables, TContext> =
|
|
330
417
|
TRPCHookResult & UseMutationResult<TData, TError, TVariables, TContext>;
|
|
331
418
|
|
|
419
|
+
/**
|
|
420
|
+
* Extra fields that tRPC adds to every hook result.
|
|
421
|
+
*/
|
|
332
422
|
export interface TRPCHookResult {
|
|
333
423
|
trpc: {
|
|
424
|
+
/**
|
|
425
|
+
* The dot-separated procedure path, such as `post.byId`.
|
|
426
|
+
*/
|
|
334
427
|
path: string;
|
|
335
428
|
};
|
|
336
429
|
}
|
|
@@ -15,6 +15,9 @@ export type RouterLike<TRouter extends AnyRouter> = RouterLikeInner<
|
|
|
15
15
|
TRouter['_def']['_config']['$types'],
|
|
16
16
|
TRouter['_def']['record']
|
|
17
17
|
>;
|
|
18
|
+
/**
|
|
19
|
+
* The record behind {@link RouterLike}.
|
|
20
|
+
*/
|
|
18
21
|
export type RouterLikeInner<
|
|
19
22
|
TRoot extends AnyRootTypes,
|
|
20
23
|
TRecord extends RouterRecord,
|
|
@@ -62,6 +62,10 @@ import type {
|
|
|
62
62
|
UnusedSkipTokenTRPCQueryOptionsOut,
|
|
63
63
|
} from '../types';
|
|
64
64
|
|
|
65
|
+
/**
|
|
66
|
+
* The `useUtils` helpers for one query procedure.
|
|
67
|
+
* @see https://trpc.io/docs/client/react/useUtils#helpers
|
|
68
|
+
*/
|
|
65
69
|
export type DecorateQueryProcedure<
|
|
66
70
|
TRoot extends AnyRootTypes,
|
|
67
71
|
TProcedure extends AnyQueryProcedure,
|
|
@@ -412,6 +416,10 @@ export type DecoratedProcedureUtilsRecord<
|
|
|
412
416
|
type AnyDecoratedProcedure = DecorateQueryProcedure<any, any> &
|
|
413
417
|
DecorateMutationProcedure<any, any>;
|
|
414
418
|
|
|
419
|
+
/**
|
|
420
|
+
* What `useUtils()` returns: the context props plus helpers for every procedure.
|
|
421
|
+
* @see https://trpc.io/docs/client/react/useUtils
|
|
422
|
+
*/
|
|
415
423
|
export type CreateReactUtils<
|
|
416
424
|
TRouter extends AnyRouter,
|
|
417
425
|
TSSRContext,
|
|
@@ -423,12 +431,19 @@ export type CreateReactUtils<
|
|
|
423
431
|
>
|
|
424
432
|
>;
|
|
425
433
|
|
|
434
|
+
/**
|
|
435
|
+
* What `createTRPCQueryUtils` returns.
|
|
436
|
+
* @see https://trpc.io/docs/client/react/createTRPCQueryUtils
|
|
437
|
+
*/
|
|
426
438
|
export type CreateQueryUtils<TRouter extends AnyRouter> =
|
|
427
439
|
DecoratedProcedureUtilsRecord<
|
|
428
440
|
TRouter['_def']['_config']['$types'],
|
|
429
441
|
TRouter['_def']['record']
|
|
430
442
|
>;
|
|
431
443
|
|
|
444
|
+
/**
|
|
445
|
+
* Maps a `useUtils` helper name to the kind of query it works on.
|
|
446
|
+
*/
|
|
432
447
|
export const getQueryType = (
|
|
433
448
|
utilName: keyof AnyDecoratedProcedure,
|
|
434
449
|
): QueryType => {
|