@trpc/react-query 11.22.2-canary.9.85bcf328a → 11.23.1-canary.10.8a0997add
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-Bp7oeZRj.d.mts → getQueryKey-BI6_waNM.d.mts} +257 -20
- package/dist/getQueryKey-BI6_waNM.d.mts.map +1 -0
- package/dist/{getQueryKey-CcWghL0B.d.cts → getQueryKey-CSENlbGR.d.cts} +257 -20
- 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 +9 -4
- 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 +9 -4
- 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 +12 -20
- package/src/createTRPCQueryUtils.tsx +9 -0
- package/src/createTRPCReact.tsx +42 -8
- package/src/internals/context.tsx +22 -1
- package/src/internals/getQueryKey.ts +27 -9
- package/src/rsc.tsx +8 -0
- package/src/server/ssgProxy.ts +16 -2
- package/src/shared/hooks/createHooksInternal.tsx +6 -5
- package/src/shared/hooks/types.ts +93 -0
- package/src/shared/polymorphism/routerLike.ts +3 -0
- package/src/shared/proxy/decorationProxy.ts +1 -1
- package/src/shared/proxy/utilsProxy.ts +15 -0
- package/src/shared/types.ts +52 -4
- package/src/utils/createUtilityFunctions.ts +1 -1
- package/src/utils/inferReactQueryProcedure.ts +8 -0
- package/dist/getQueryKey-Bp7oeZRj.d.mts.map +0 -1
- package/dist/getQueryKey-CcWghL0B.d.cts.map +0 -1
- package/dist/getQueryKey-D3tJ34z0.mjs.map +0 -1
- package/dist/shared-Bw5jcbcM.mjs.map +0 -1
|
@@ -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',
|
|
@@ -297,7 +315,7 @@ export interface TRPCQueryUtils<TRouter extends AnyRouter> {
|
|
|
297
315
|
/**
|
|
298
316
|
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetqueriesdata
|
|
299
317
|
*/
|
|
300
|
-
//
|
|
318
|
+
// oxlint-disable-next-line max-params -- mirrors TanStack Query's own signature
|
|
301
319
|
setQueriesData: (
|
|
302
320
|
queryKey: TRPCQueryKey,
|
|
303
321
|
filters: QueryFilters,
|
|
@@ -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);
|
|
@@ -16,7 +16,9 @@ export type TRPCQueryKey = [
|
|
|
16
16
|
export type TRPCMutationKey = [readonly string[]]; // = [TRPCQueryKey[0]]
|
|
17
17
|
|
|
18
18
|
type ProcedureOrRouter =
|
|
19
|
-
|
|
19
|
+
| DecoratedMutation<any>
|
|
20
|
+
| DecoratedQuery<any>
|
|
21
|
+
| DecorateRouterRecord<any, any>;
|
|
20
22
|
|
|
21
23
|
/**
|
|
22
24
|
* To allow easy interactions with groups of related queries, such as
|
|
@@ -98,11 +100,22 @@ type GetParams<TProcedureOrRouter extends ProcedureOrRouter> =
|
|
|
98
100
|
: [];
|
|
99
101
|
|
|
100
102
|
/**
|
|
101
|
-
*
|
|
102
|
-
* @param procedureOrRouter - procedure or
|
|
103
|
-
* @param input - input to
|
|
104
|
-
*
|
|
105
|
-
* @
|
|
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
|
|
106
119
|
*/
|
|
107
120
|
export function getQueryKey<TProcedureOrRouter extends ProcedureOrRouter>(
|
|
108
121
|
procedureOrRouter: TProcedureOrRouter,
|
|
@@ -123,9 +136,14 @@ export type QueryKeyKnown<TInput, TType extends Exclude<QueryType, 'any'>> = [
|
|
|
123
136
|
];
|
|
124
137
|
|
|
125
138
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
* @
|
|
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
|
|
129
147
|
*/
|
|
130
148
|
export function getMutationKey<TProcedure extends DecoratedMutation<any>>(
|
|
131
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
|
@@ -37,11 +37,20 @@ import type {
|
|
|
37
37
|
import { getQueryClient, getQueryType } from '../shared';
|
|
38
38
|
|
|
39
39
|
type CreateSSGHelpersInternal<TRouter extends AnyRouter> = {
|
|
40
|
+
/**
|
|
41
|
+
* Call this router directly, without HTTP.
|
|
42
|
+
*/
|
|
40
43
|
router: TRouter;
|
|
44
|
+
/**
|
|
45
|
+
* The context to call procedures with.
|
|
46
|
+
*/
|
|
41
47
|
ctx: inferRouterContext<TRouter>;
|
|
42
48
|
} & TransformerOptions<inferClientTypes<TRouter>>;
|
|
43
49
|
|
|
44
50
|
interface CreateSSGHelpersExternal<TRouter extends AnyRouter> {
|
|
51
|
+
/**
|
|
52
|
+
* Call procedures through this tRPC client.
|
|
53
|
+
*/
|
|
45
54
|
client: TRPCClient<TRouter> | TRPCUntypedClient<TRouter>;
|
|
46
55
|
}
|
|
47
56
|
|
|
@@ -76,8 +85,13 @@ type DecoratedProcedureSSGRecord<
|
|
|
76
85
|
type AnyDecoratedProcedure = Pick<DecorateQueryProcedure<any, any>, SSGFns>;
|
|
77
86
|
|
|
78
87
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
88
|
+
* Creates helpers that fetch or prefetch queries on the server, for
|
|
89
|
+
* server-side rendering and static generation.
|
|
90
|
+
*
|
|
91
|
+
* @deprecated `@trpc/react-query` only gets bug fixes and will be removed in
|
|
92
|
+
* the next major version. Use `@trpc/tanstack-react-query` instead.
|
|
93
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/migrating
|
|
94
|
+
* @see https://trpc.io/docs/client/nextjs/pages-router/server-side-helpers
|
|
81
95
|
*/
|
|
82
96
|
export function createServerSideHelpers<TRouter extends AnyRouter>(
|
|
83
97
|
opts: CreateServerSideHelpersOptions<TRouter>,
|
|
@@ -154,7 +154,7 @@ export function createRootHooks<
|
|
|
154
154
|
* @see https://github.com/trpc/trpc/pull/1645
|
|
155
155
|
*/
|
|
156
156
|
function useSSRQueryOptionsIfNeeded<
|
|
157
|
-
TOptions extends { retryOnMount?:
|
|
157
|
+
TOptions extends { retryOnMount?: unknown } | undefined,
|
|
158
158
|
>(queryKey: TRPCQueryKey, opts: TOptions): TOptions {
|
|
159
159
|
const { queryClient, ssrState } = useContext();
|
|
160
160
|
return ssrState &&
|
|
@@ -258,8 +258,9 @@ export function createRootHooks<
|
|
|
258
258
|
_usePrefetchQuery({
|
|
259
259
|
...opts,
|
|
260
260
|
queryKey: queryKey as any,
|
|
261
|
+
// usePrefetchQuery's types exclude skipToken, but query-core handles it at runtime
|
|
261
262
|
queryFn: isInputSkipToken
|
|
262
|
-
? input
|
|
263
|
+
? (input as never)
|
|
263
264
|
: (queryFunctionContext) => {
|
|
264
265
|
const actualOpts = {
|
|
265
266
|
trpc: {
|
|
@@ -498,7 +499,7 @@ export function createRootHooks<
|
|
|
498
499
|
|
|
499
500
|
currentSubscriptionRef.current = subscription;
|
|
500
501
|
|
|
501
|
-
//
|
|
502
|
+
// oxlint-disable-next-line react/exhaustive-deps
|
|
502
503
|
}, [client, queryKey, enabled, updateState]);
|
|
503
504
|
React.useEffect(() => {
|
|
504
505
|
reset();
|
|
@@ -621,7 +622,7 @@ export function createRootHooks<
|
|
|
621
622
|
initialPageParam: opts.initialCursor ?? null,
|
|
622
623
|
queryKey,
|
|
623
624
|
queryFn: isInputSkipToken
|
|
624
|
-
? input
|
|
625
|
+
? (input as never)
|
|
625
626
|
: (queryFunctionContext) => {
|
|
626
627
|
const actualOpts = {
|
|
627
628
|
...ssrOpts,
|
|
@@ -693,7 +694,7 @@ export function createRootHooks<
|
|
|
693
694
|
path,
|
|
694
695
|
});
|
|
695
696
|
|
|
696
|
-
//
|
|
697
|
+
// oxlint-disable-next-line typescript/no-non-null-assertion
|
|
697
698
|
return [hook.data!, hook as any];
|
|
698
699
|
}
|
|
699
700
|
|
|
@@ -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,
|
|
@@ -14,7 +14,7 @@ export function createReactDecoration<
|
|
|
14
14
|
const pathCopy = [...path];
|
|
15
15
|
|
|
16
16
|
// The last arg is for instance `.useMutation` or `.useQuery()`
|
|
17
|
-
//
|
|
17
|
+
// oxlint-disable-next-line typescript/no-non-null-assertion
|
|
18
18
|
const lastArg = pathCopy.pop()!;
|
|
19
19
|
|
|
20
20
|
if (lastArg === 'useMutation') {
|
|
@@ -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 => {
|