@trpc/react-query 11.0.0-next.92 → 11.0.0-rc.330
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/README.md +4 -4
- package/dist/bundle-analysis.json +83 -51
- package/dist/createTRPCQueryUtils.d.ts +4 -0
- package/dist/createTRPCQueryUtils.d.ts.map +1 -0
- package/dist/createTRPCQueryUtils.js +16 -0
- package/dist/createTRPCQueryUtils.mjs +14 -0
- package/dist/createTRPCReact.d.ts +55 -40
- package/dist/createTRPCReact.d.ts.map +1 -1
- package/dist/createTRPCReact.js +58 -0
- package/dist/createTRPCReact.mjs +36 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -36
- package/dist/index.mjs +3 -35
- package/dist/internals/context.d.ts +23 -18
- package/dist/internals/context.d.ts.map +1 -1
- package/dist/internals/context.js +33 -0
- package/dist/internals/context.mjs +11 -0
- package/dist/internals/getClientArgs.d.ts +8 -2
- package/dist/internals/getClientArgs.d.ts.map +1 -1
- package/dist/internals/getClientArgs.js +24 -0
- package/dist/internals/getClientArgs.mjs +22 -0
- package/dist/internals/getQueryKey.d.ts +8 -13
- package/dist/internals/getQueryKey.d.ts.map +1 -1
- package/dist/internals/getQueryKey.js +60 -0
- package/dist/internals/getQueryKey.mjs +57 -0
- package/dist/internals/useHookResult.d.ts +4 -6
- package/dist/internals/useHookResult.d.ts.map +1 -1
- package/dist/internals/useHookResult.js +35 -0
- package/dist/internals/useHookResult.mjs +14 -0
- package/dist/internals/useQueries.d.ts +32 -4
- package/dist/internals/useQueries.d.ts.map +1 -1
- package/dist/server/index.js +2 -103
- package/dist/server/index.mjs +1 -104
- package/dist/server/ssgProxy.d.ts +21 -21
- package/dist/server/ssgProxy.d.ts.map +1 -1
- package/dist/server/ssgProxy.js +109 -0
- package/dist/server/ssgProxy.mjs +107 -0
- package/dist/shared/hooks/createHooksInternal.d.ts +8 -31
- package/dist/shared/hooks/createHooksInternal.d.ts.map +1 -1
- package/dist/{createHooksInternal-e2034194.js → shared/hooks/createHooksInternal.js} +98 -226
- package/dist/{createHooksInternal-3d8ebfcf.mjs → shared/hooks/createHooksInternal.mjs} +70 -210
- package/dist/shared/hooks/types.d.ts +11 -7
- package/dist/shared/hooks/types.d.ts.map +1 -1
- package/dist/shared/index.d.ts +2 -2
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +14 -15
- package/dist/shared/index.mjs +7 -7
- package/dist/shared/polymorphism/mutationLike.d.ts +6 -7
- package/dist/shared/polymorphism/mutationLike.d.ts.map +1 -1
- package/dist/shared/polymorphism/queryLike.d.ts +10 -7
- package/dist/shared/polymorphism/queryLike.d.ts.map +1 -1
- package/dist/shared/polymorphism/routerLike.d.ts +6 -6
- package/dist/shared/polymorphism/routerLike.d.ts.map +1 -1
- package/dist/shared/polymorphism/utilsLike.d.ts +3 -3
- package/dist/shared/polymorphism/utilsLike.d.ts.map +1 -1
- package/dist/shared/proxy/decorationProxy.d.ts +2 -2
- package/dist/shared/proxy/decorationProxy.d.ts.map +1 -1
- package/dist/shared/proxy/decorationProxy.js +31 -0
- package/dist/shared/proxy/decorationProxy.mjs +29 -0
- package/dist/shared/proxy/useQueriesProxy.d.ts +14 -8
- package/dist/shared/proxy/useQueriesProxy.d.ts.map +1 -1
- package/dist/shared/proxy/useQueriesProxy.js +25 -0
- package/dist/shared/proxy/useQueriesProxy.mjs +23 -0
- package/dist/shared/proxy/utilsProxy.d.ts +28 -24
- package/dist/shared/proxy/utilsProxy.d.ts.map +1 -1
- package/dist/shared/proxy/utilsProxy.js +89 -0
- package/dist/shared/proxy/utilsProxy.mjs +85 -0
- package/dist/shared/queryClient.d.ts +2 -1
- package/dist/shared/queryClient.d.ts.map +1 -1
- package/dist/{queryClient-4d766c0c.mjs → shared/queryClient.mjs} +1 -1
- package/dist/shared/types.d.ts +2 -2
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/utils/createUtilityFunctions.d.ts +23 -0
- package/dist/utils/createUtilityFunctions.d.ts.map +1 -0
- package/dist/utils/createUtilityFunctions.js +100 -0
- package/dist/utils/createUtilityFunctions.mjs +98 -0
- package/dist/utils/inferReactQueryProcedure.d.ts +11 -10
- package/dist/utils/inferReactQueryProcedure.d.ts.map +1 -1
- package/package.json +18 -18
- package/src/createTRPCQueryUtils.tsx +11 -0
- package/src/createTRPCReact.tsx +139 -163
- package/src/index.ts +6 -1
- package/src/internals/context.tsx +27 -18
- package/src/internals/getClientArgs.ts +16 -4
- package/src/internals/getQueryKey.ts +51 -62
- package/src/internals/useHookResult.ts +12 -13
- package/src/internals/useQueries.ts +129 -4
- package/src/server/ssgProxy.ts +59 -57
- package/src/shared/hooks/createHooksInternal.tsx +115 -246
- package/src/shared/hooks/types.ts +15 -7
- package/src/shared/index.ts +5 -2
- package/src/shared/polymorphism/mutationLike.ts +21 -15
- package/src/shared/polymorphism/queryLike.ts +34 -14
- package/src/shared/polymorphism/routerLike.ts +29 -15
- package/src/shared/polymorphism/utilsLike.ts +6 -3
- package/src/shared/proxy/decorationProxy.ts +3 -3
- package/src/shared/proxy/useQueriesProxy.ts +65 -28
- package/src/shared/proxy/utilsProxy.ts +113 -86
- package/src/shared/queryClient.ts +2 -1
- package/src/shared/types.ts +5 -2
- package/src/utils/createUtilityFunctions.ts +137 -0
- package/src/utils/inferReactQueryProcedure.ts +38 -28
- package/dist/createHooksInternal-dce6e141.js +0 -435
- package/dist/queryClient-1c8d7d8a.js +0 -8
- package/dist/utilsProxy-00894da2.mjs +0 -121
- package/dist/utilsProxy-27bd93c1.js +0 -128
- package/dist/utilsProxy-7e396600.js +0 -114
- /package/dist/{queryClient-358a9a75.js → shared/queryClient.js} +0 -0
package/src/createTRPCReact.tsx
CHANGED
|
@@ -1,37 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import type { SkipToken } from '@tanstack/react-query';
|
|
2
|
+
import type { TRPCClientErrorLike } from '@trpc/client';
|
|
3
|
+
import type {
|
|
4
4
|
AnyProcedure,
|
|
5
|
-
|
|
6
|
-
AnyRootConfig,
|
|
5
|
+
AnyRootTypes,
|
|
7
6
|
AnyRouter,
|
|
8
|
-
AnySubscriptionProcedure,
|
|
9
7
|
inferProcedureInput,
|
|
10
|
-
ProcedureRouterRecord,
|
|
11
|
-
ProtectedIntersection,
|
|
12
|
-
} from '@trpc/server';
|
|
13
|
-
import {
|
|
14
|
-
createFlatProxy,
|
|
15
8
|
inferTransformedProcedureOutput,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
} from './shared/hooks/createHooksInternal';
|
|
29
|
-
import {
|
|
9
|
+
ProcedureType,
|
|
10
|
+
ProtectedIntersection,
|
|
11
|
+
RouterRecord,
|
|
12
|
+
} from '@trpc/server/unstable-core-do-not-import';
|
|
13
|
+
import { createFlatProxy } from '@trpc/server/unstable-core-do-not-import';
|
|
14
|
+
import * as React from 'react';
|
|
15
|
+
import type {
|
|
16
|
+
TRPCUseQueries,
|
|
17
|
+
TRPCUseSuspenseQueries,
|
|
18
|
+
} from './internals/useQueries';
|
|
19
|
+
import type { CreateReactUtils } from './shared';
|
|
20
|
+
import { createReactDecoration, createReactQueryUtils } from './shared';
|
|
21
|
+
import type { CreateReactQueryHooks } from './shared/hooks/createHooksInternal';
|
|
22
|
+
import { createRootHooks } from './shared/hooks/createHooksInternal';
|
|
23
|
+
import type {
|
|
30
24
|
CreateClient,
|
|
31
25
|
DefinedUseTRPCQueryOptions,
|
|
32
26
|
DefinedUseTRPCQueryResult,
|
|
33
27
|
TRPCProvider,
|
|
34
|
-
UseDehydratedState,
|
|
35
28
|
UseTRPCInfiniteQueryOptions,
|
|
36
29
|
UseTRPCInfiniteQueryResult,
|
|
37
30
|
UseTRPCMutationOptions,
|
|
@@ -44,46 +37,46 @@ import {
|
|
|
44
37
|
UseTRPCSuspenseQueryOptions,
|
|
45
38
|
UseTRPCSuspenseQueryResult,
|
|
46
39
|
} from './shared/hooks/types';
|
|
47
|
-
import { CreateTRPCReactOptions } from './shared/types';
|
|
40
|
+
import type { CreateTRPCReactOptions } from './shared/types';
|
|
48
41
|
|
|
42
|
+
type ResolverDef = {
|
|
43
|
+
input: any;
|
|
44
|
+
output: any;
|
|
45
|
+
transformer: boolean;
|
|
46
|
+
errorShape: any;
|
|
47
|
+
};
|
|
49
48
|
/**
|
|
50
49
|
* @internal
|
|
51
50
|
*/
|
|
52
|
-
export interface ProcedureUseQuery<
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
> {
|
|
56
|
-
<
|
|
57
|
-
TQueryFnData extends inferTransformedProcedureOutput<
|
|
58
|
-
TConfig,
|
|
59
|
-
TProcedure
|
|
60
|
-
> = inferTransformedProcedureOutput<TConfig, TProcedure>,
|
|
61
|
-
TData = TQueryFnData,
|
|
62
|
-
>(
|
|
63
|
-
input: inferProcedureInput<TProcedure>,
|
|
51
|
+
export interface ProcedureUseQuery<TDef extends ResolverDef> {
|
|
52
|
+
<TQueryFnData extends TDef['output'] = TDef['output'], TData = TQueryFnData>(
|
|
53
|
+
input: TDef['input'] | SkipToken,
|
|
64
54
|
opts: DefinedUseTRPCQueryOptions<
|
|
65
55
|
TQueryFnData,
|
|
66
56
|
TData,
|
|
67
|
-
TRPCClientErrorLike<
|
|
68
|
-
|
|
57
|
+
TRPCClientErrorLike<{
|
|
58
|
+
errorShape: TDef['errorShape'];
|
|
59
|
+
transformer: TDef['transformer'];
|
|
60
|
+
}>,
|
|
61
|
+
TDef['output']
|
|
69
62
|
>,
|
|
70
|
-
): DefinedUseTRPCQueryResult<
|
|
63
|
+
): DefinedUseTRPCQueryResult<
|
|
64
|
+
TData,
|
|
65
|
+
TRPCClientErrorLike<{
|
|
66
|
+
errorShape: TDef['errorShape'];
|
|
67
|
+
transformer: TDef['transformer'];
|
|
68
|
+
}>
|
|
69
|
+
>;
|
|
71
70
|
|
|
72
|
-
<
|
|
73
|
-
|
|
74
|
-
TConfig,
|
|
75
|
-
TProcedure
|
|
76
|
-
> = inferTransformedProcedureOutput<TConfig, TProcedure>,
|
|
77
|
-
TData = TQueryFnData,
|
|
78
|
-
>(
|
|
79
|
-
input: inferProcedureInput<TProcedure>,
|
|
71
|
+
<TQueryFnData extends TDef['output'] = TDef['output'], TData = TQueryFnData>(
|
|
72
|
+
input: TDef['input'] | SkipToken,
|
|
80
73
|
opts?: UseTRPCQueryOptions<
|
|
81
74
|
TQueryFnData,
|
|
82
75
|
TData,
|
|
83
|
-
TRPCClientErrorLike<
|
|
84
|
-
|
|
76
|
+
TRPCClientErrorLike<TDef>,
|
|
77
|
+
TDef['output']
|
|
85
78
|
>,
|
|
86
|
-
): UseTRPCQueryResult<TData, TRPCClientErrorLike<
|
|
79
|
+
): UseTRPCQueryResult<TData, TRPCClientErrorLike<TDef>>;
|
|
87
80
|
}
|
|
88
81
|
|
|
89
82
|
/**
|
|
@@ -93,132 +86,114 @@ type CursorInput = {
|
|
|
93
86
|
cursor?: any;
|
|
94
87
|
} | void;
|
|
95
88
|
|
|
89
|
+
type ReservedInfiniteQueryKeys = 'cursor' | 'direction';
|
|
96
90
|
/**
|
|
97
91
|
* @internal
|
|
98
92
|
*/
|
|
99
|
-
export type MaybeDecoratedInfiniteQuery<
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
: object;
|
|
93
|
+
export type MaybeDecoratedInfiniteQuery<TDef extends ResolverDef> =
|
|
94
|
+
TDef['input'] extends CursorInput
|
|
95
|
+
? {
|
|
96
|
+
/**
|
|
97
|
+
* @link https://trpc.io/docs/v11/client/react/suspense#useinfinitesuspensequery
|
|
98
|
+
*/
|
|
99
|
+
useInfiniteQuery: (
|
|
100
|
+
input: Omit<TDef['input'], ReservedInfiniteQueryKeys> | SkipToken,
|
|
101
|
+
opts: UseTRPCInfiniteQueryOptions<
|
|
102
|
+
TDef['input'],
|
|
103
|
+
TDef['output'],
|
|
104
|
+
TRPCClientErrorLike<TDef>
|
|
105
|
+
>,
|
|
106
|
+
) => UseTRPCInfiniteQueryResult<
|
|
107
|
+
TDef['output'],
|
|
108
|
+
TRPCClientErrorLike<TDef>,
|
|
109
|
+
TDef['input']
|
|
110
|
+
>;
|
|
111
|
+
/**
|
|
112
|
+
* @link https://trpc.io/docs/v11/client/react/suspense
|
|
113
|
+
*/
|
|
114
|
+
useSuspenseInfiniteQuery: (
|
|
115
|
+
input: Omit<TDef['input'], 'cursor' | 'direction'>,
|
|
116
|
+
opts: UseTRPCSuspenseInfiniteQueryOptions<
|
|
117
|
+
TDef['input'],
|
|
118
|
+
TDef['output'],
|
|
119
|
+
TRPCClientErrorLike<TDef>
|
|
120
|
+
>,
|
|
121
|
+
) => UseTRPCSuspenseInfiniteQueryResult<
|
|
122
|
+
TDef['output'],
|
|
123
|
+
TRPCClientErrorLike<TDef>,
|
|
124
|
+
TDef['input']
|
|
125
|
+
>;
|
|
126
|
+
}
|
|
127
|
+
: object;
|
|
136
128
|
|
|
137
129
|
/**
|
|
138
130
|
* @internal
|
|
139
131
|
*/
|
|
140
|
-
export type DecoratedQueryMethods<
|
|
141
|
-
TConfig extends AnyRootConfig,
|
|
142
|
-
TProcedure extends AnyProcedure,
|
|
143
|
-
> = {
|
|
132
|
+
export type DecoratedQueryMethods<TDef extends ResolverDef> = {
|
|
144
133
|
/**
|
|
145
|
-
* @
|
|
134
|
+
* @link https://trpc.io/docs/v11/client/react/useQuery
|
|
146
135
|
*/
|
|
147
|
-
useQuery: ProcedureUseQuery<
|
|
136
|
+
useQuery: ProcedureUseQuery<TDef>;
|
|
148
137
|
/**
|
|
149
|
-
* @
|
|
138
|
+
* @link https://trpc.io/docs/v11/client/react/suspense#usesuspensequery
|
|
150
139
|
*/
|
|
151
140
|
useSuspenseQuery: <
|
|
152
|
-
TQueryFnData extends
|
|
153
|
-
TConfig,
|
|
154
|
-
TProcedure
|
|
155
|
-
> = inferTransformedProcedureOutput<TConfig, TProcedure>,
|
|
141
|
+
TQueryFnData extends TDef['output'] = TDef['output'],
|
|
156
142
|
TData = TQueryFnData,
|
|
157
143
|
>(
|
|
158
|
-
input:
|
|
144
|
+
input: TDef['input'],
|
|
159
145
|
opts?: UseTRPCSuspenseQueryOptions<
|
|
160
146
|
TQueryFnData,
|
|
161
147
|
TData,
|
|
162
|
-
TRPCClientErrorLike<
|
|
148
|
+
TRPCClientErrorLike<TDef>
|
|
163
149
|
>,
|
|
164
|
-
) => UseTRPCSuspenseQueryResult<TData, TRPCClientErrorLike<
|
|
150
|
+
) => UseTRPCSuspenseQueryResult<TData, TRPCClientErrorLike<TDef>>;
|
|
165
151
|
};
|
|
166
152
|
|
|
167
153
|
/**
|
|
168
154
|
* @internal
|
|
169
155
|
*/
|
|
170
|
-
export type DecoratedQuery<
|
|
171
|
-
|
|
172
|
-
TProcedure extends AnyProcedure,
|
|
173
|
-
> = MaybeDecoratedInfiniteQuery<TProcedure, TConfig> &
|
|
174
|
-
DecoratedQueryMethods<TConfig, TProcedure>;
|
|
156
|
+
export type DecoratedQuery<TDef extends ResolverDef> =
|
|
157
|
+
MaybeDecoratedInfiniteQuery<TDef> & DecoratedQueryMethods<TDef>;
|
|
175
158
|
|
|
176
|
-
|
|
177
|
-
* @internal
|
|
178
|
-
*/
|
|
179
|
-
export interface DecoratedMutation<
|
|
180
|
-
TConfig extends AnyRootConfig,
|
|
181
|
-
TProcedure extends AnyProcedure,
|
|
182
|
-
> {
|
|
159
|
+
export type DecoratedMutation<TDef extends ResolverDef> = {
|
|
183
160
|
/**
|
|
184
|
-
* @
|
|
161
|
+
* @link https://trpc.io/docs/v11/client/react/useMutation
|
|
185
162
|
*/
|
|
186
163
|
useMutation: <TContext = unknown>(
|
|
187
164
|
opts?: UseTRPCMutationOptions<
|
|
188
|
-
|
|
189
|
-
TRPCClientErrorLike<
|
|
190
|
-
|
|
165
|
+
TDef['input'],
|
|
166
|
+
TRPCClientErrorLike<TDef>,
|
|
167
|
+
TDef['output'],
|
|
191
168
|
TContext
|
|
192
169
|
>,
|
|
193
170
|
) => UseTRPCMutationResult<
|
|
194
|
-
|
|
195
|
-
TRPCClientErrorLike<
|
|
196
|
-
|
|
171
|
+
TDef['output'],
|
|
172
|
+
TRPCClientErrorLike<TDef>,
|
|
173
|
+
TDef['input'],
|
|
197
174
|
TContext
|
|
198
175
|
>;
|
|
199
|
-
}
|
|
200
|
-
|
|
176
|
+
};
|
|
201
177
|
/**
|
|
202
178
|
* @internal
|
|
203
179
|
*/
|
|
204
180
|
export type DecorateProcedure<
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
>
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
: TProcedure extends AnySubscriptionProcedure
|
|
181
|
+
TType extends ProcedureType,
|
|
182
|
+
TDef extends ResolverDef,
|
|
183
|
+
> = TType extends 'query'
|
|
184
|
+
? DecoratedQuery<TDef>
|
|
185
|
+
: TType extends 'mutation'
|
|
186
|
+
? DecoratedMutation<TDef>
|
|
187
|
+
: TType extends 'subscription'
|
|
213
188
|
? {
|
|
214
189
|
/**
|
|
215
|
-
* @
|
|
190
|
+
* @link https://trpc.io/docs/v11/subscriptions
|
|
216
191
|
*/
|
|
217
192
|
useSubscription: (
|
|
218
|
-
input:
|
|
193
|
+
input: TDef['input'],
|
|
219
194
|
opts?: UseTRPCSubscriptionOptions<
|
|
220
|
-
|
|
221
|
-
TRPCClientErrorLike<
|
|
195
|
+
TDef['output'],
|
|
196
|
+
TRPCClientErrorLike<TDef>
|
|
222
197
|
>,
|
|
223
198
|
) => void;
|
|
224
199
|
}
|
|
@@ -227,19 +202,24 @@ export type DecorateProcedure<
|
|
|
227
202
|
/**
|
|
228
203
|
* @internal
|
|
229
204
|
*/
|
|
230
|
-
export type
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
TFlags,
|
|
205
|
+
export type DecorateRouterRecord<
|
|
206
|
+
TRoot extends AnyRootTypes,
|
|
207
|
+
TRecord extends RouterRecord,
|
|
234
208
|
> = {
|
|
235
|
-
[TKey in keyof
|
|
236
|
-
?
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
209
|
+
[TKey in keyof TRecord]: TRecord[TKey] extends infer $Value
|
|
210
|
+
? $Value extends RouterRecord
|
|
211
|
+
? DecorateRouterRecord<TRoot, $Value>
|
|
212
|
+
: $Value extends AnyProcedure
|
|
213
|
+
? DecorateProcedure<
|
|
214
|
+
$Value['_def']['type'],
|
|
215
|
+
{
|
|
216
|
+
input: inferProcedureInput<$Value>;
|
|
217
|
+
output: inferTransformedProcedureOutput<TRoot, $Value>;
|
|
218
|
+
transformer: TRoot['transformer'];
|
|
219
|
+
errorShape: TRoot['errorShape'];
|
|
220
|
+
}
|
|
221
|
+
>
|
|
222
|
+
: never
|
|
243
223
|
: never;
|
|
244
224
|
};
|
|
245
225
|
|
|
@@ -250,29 +230,27 @@ export type CreateTRPCReactBase<TRouter extends AnyRouter, TSSRContext> = {
|
|
|
250
230
|
/**
|
|
251
231
|
* @deprecated renamed to `useUtils` and will be removed in a future tRPC version
|
|
252
232
|
*
|
|
253
|
-
* @
|
|
233
|
+
* @link https://trpc.io/docs/v11/client/react/useUtils
|
|
254
234
|
*/
|
|
255
235
|
useContext(): CreateReactUtils<TRouter, TSSRContext>;
|
|
256
236
|
/**
|
|
257
|
-
* @
|
|
237
|
+
* @link https://trpc.io/docs/v11/client/react/useUtils
|
|
258
238
|
*/
|
|
259
239
|
useUtils(): CreateReactUtils<TRouter, TSSRContext>;
|
|
260
240
|
Provider: TRPCProvider<TRouter, TSSRContext>;
|
|
261
241
|
createClient: CreateClient<TRouter>;
|
|
262
242
|
useQueries: TRPCUseQueries<TRouter>;
|
|
263
|
-
|
|
243
|
+
useSuspenseQueries: TRPCUseSuspenseQueries<TRouter>;
|
|
264
244
|
};
|
|
265
245
|
|
|
266
246
|
export type CreateTRPCReact<
|
|
267
247
|
TRouter extends AnyRouter,
|
|
268
248
|
TSSRContext,
|
|
269
|
-
TFlags,
|
|
270
249
|
> = ProtectedIntersection<
|
|
271
250
|
CreateTRPCReactBase<TRouter, TSSRContext>,
|
|
272
|
-
|
|
273
|
-
TRouter['_def']['_config'],
|
|
274
|
-
TRouter['_def']['record']
|
|
275
|
-
TFlags
|
|
251
|
+
DecorateRouterRecord<
|
|
252
|
+
TRouter['_def']['_config']['$types'],
|
|
253
|
+
TRouter['_def']['record']
|
|
276
254
|
>
|
|
277
255
|
>;
|
|
278
256
|
|
|
@@ -282,16 +260,15 @@ export type CreateTRPCReact<
|
|
|
282
260
|
export function createHooksInternal<
|
|
283
261
|
TRouter extends AnyRouter,
|
|
284
262
|
TSSRContext = unknown,
|
|
285
|
-
TFlags = null,
|
|
286
263
|
>(trpc: CreateReactQueryHooks<TRouter, TSSRContext>) {
|
|
287
|
-
type CreateHooksInternal = CreateTRPCReact<TRouter, TSSRContext
|
|
264
|
+
type CreateHooksInternal = CreateTRPCReact<TRouter, TSSRContext>;
|
|
288
265
|
|
|
289
266
|
return createFlatProxy<CreateHooksInternal>((key) => {
|
|
290
267
|
if (key === 'useContext' || key === 'useUtils') {
|
|
291
268
|
return () => {
|
|
292
269
|
const context = trpc.useUtils();
|
|
293
270
|
// create a stable reference of the utils context
|
|
294
|
-
return useMemo(() => {
|
|
271
|
+
return React.useMemo(() => {
|
|
295
272
|
return (createReactQueryUtils as any)(context);
|
|
296
273
|
}, [context]);
|
|
297
274
|
};
|
|
@@ -308,12 +285,11 @@ export function createHooksInternal<
|
|
|
308
285
|
export function createTRPCReact<
|
|
309
286
|
TRouter extends AnyRouter,
|
|
310
287
|
TSSRContext = unknown,
|
|
311
|
-
TFlags = null,
|
|
312
288
|
>(
|
|
313
289
|
opts?: CreateTRPCReactOptions<TRouter>,
|
|
314
|
-
): CreateTRPCReact<TRouter, TSSRContext
|
|
290
|
+
): CreateTRPCReact<TRouter, TSSRContext> {
|
|
315
291
|
const hooks = createRootHooks<TRouter, TSSRContext>(opts);
|
|
316
|
-
const proxy = createHooksInternal<TRouter, TSSRContext
|
|
292
|
+
const proxy = createHooksInternal<TRouter, TSSRContext>(hooks);
|
|
317
293
|
|
|
318
294
|
return proxy as any;
|
|
319
295
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export * from '@trpc/client';
|
|
2
2
|
|
|
3
3
|
export { getQueryKey } from './internals/getQueryKey';
|
|
4
|
-
export {
|
|
4
|
+
export {
|
|
5
|
+
createTRPCReact,
|
|
6
|
+
type CreateTRPCReact,
|
|
7
|
+
type CreateTRPCReactBase,
|
|
8
|
+
} from './createTRPCReact';
|
|
5
9
|
export type { inferReactQueryProcedureOptions } from './utils/inferReactQueryProcedure';
|
|
10
|
+
export { createTRPCQueryUtils } from './createTRPCQueryUtils';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
CancelOptions,
|
|
3
3
|
FetchInfiniteQueryOptions,
|
|
4
4
|
FetchQueryOptions,
|
|
@@ -13,16 +13,19 @@ import {
|
|
|
13
13
|
SetDataOptions,
|
|
14
14
|
Updater,
|
|
15
15
|
} from '@tanstack/react-query';
|
|
16
|
-
import {
|
|
16
|
+
import type {
|
|
17
17
|
CreateTRPCClient,
|
|
18
18
|
TRPCClientError,
|
|
19
19
|
TRPCRequestOptions,
|
|
20
20
|
TRPCUntypedClient,
|
|
21
21
|
} from '@trpc/client';
|
|
22
|
-
import type {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
import type {
|
|
23
|
+
AnyRouter,
|
|
24
|
+
DistributiveOmit,
|
|
25
|
+
} from '@trpc/server/unstable-core-do-not-import';
|
|
26
|
+
import * as React from 'react';
|
|
27
|
+
import type { ExtractCursorType } from '../shared';
|
|
28
|
+
import type { TRPCQueryKey } from './getQueryKey';
|
|
26
29
|
|
|
27
30
|
export type TRPCFetchQueryOptions<TOutput, TError> = DistributiveOmit<
|
|
28
31
|
FetchQueryOptions<TOutput, TError>,
|
|
@@ -106,7 +109,13 @@ export const contextProps: (keyof TRPCContextPropsBase<any, any>)[] = [
|
|
|
106
109
|
export interface TRPCContextState<
|
|
107
110
|
TRouter extends AnyRouter,
|
|
108
111
|
TSSRContext = undefined,
|
|
109
|
-
> extends Required<TRPCContextProps<TRouter, TSSRContext
|
|
112
|
+
> extends Required<TRPCContextProps<TRouter, TSSRContext>>,
|
|
113
|
+
TRPCQueryUtils<TRouter> {}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @internal
|
|
117
|
+
*/
|
|
118
|
+
export interface TRPCQueryUtils<TRouter extends AnyRouter> {
|
|
110
119
|
/**
|
|
111
120
|
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchquery
|
|
112
121
|
*/
|
|
@@ -126,7 +135,7 @@ export interface TRPCContextState<
|
|
|
126
135
|
>,
|
|
127
136
|
) => Promise<InfiniteData<unknown, unknown>>;
|
|
128
137
|
/**
|
|
129
|
-
* @link https://tanstack.com/query/v5/docs/react/guides/prefetching
|
|
138
|
+
* @link https://tanstack.com/query/v5/docs/framework/react/guides/prefetching
|
|
130
139
|
*/
|
|
131
140
|
prefetchQuery: (
|
|
132
141
|
queryKey: TRPCQueryKey,
|
|
@@ -146,7 +155,7 @@ export interface TRPCContextState<
|
|
|
146
155
|
) => Promise<void>;
|
|
147
156
|
|
|
148
157
|
/**
|
|
149
|
-
* @link https://tanstack.com/query/v5/docs/
|
|
158
|
+
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientensurequerydata
|
|
150
159
|
*/
|
|
151
160
|
ensureQueryData: (
|
|
152
161
|
queryKey: TRPCQueryKey,
|
|
@@ -154,7 +163,7 @@ export interface TRPCContextState<
|
|
|
154
163
|
) => Promise<unknown>;
|
|
155
164
|
|
|
156
165
|
/**
|
|
157
|
-
* @link https://tanstack.com/query/v5/docs/react/guides/query-invalidation
|
|
166
|
+
* @link https://tanstack.com/query/v5/docs/framework/react/guides/query-invalidation
|
|
158
167
|
*/
|
|
159
168
|
invalidateQueries: (
|
|
160
169
|
queryKey: TRPCQueryKey,
|
|
@@ -163,7 +172,7 @@ export interface TRPCContextState<
|
|
|
163
172
|
) => Promise<void>;
|
|
164
173
|
|
|
165
174
|
/**
|
|
166
|
-
* @link https://tanstack.com/query/v5/docs/
|
|
175
|
+
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientresetqueries
|
|
167
176
|
*/
|
|
168
177
|
resetQueries: (
|
|
169
178
|
queryKey: TRPCQueryKey,
|
|
@@ -172,7 +181,7 @@ export interface TRPCContextState<
|
|
|
172
181
|
) => Promise<void>;
|
|
173
182
|
|
|
174
183
|
/**
|
|
175
|
-
* @link https://tanstack.com/query/v5/docs/
|
|
184
|
+
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientrefetchqueries
|
|
176
185
|
*/
|
|
177
186
|
refetchQueries: (
|
|
178
187
|
queryKey: TRPCQueryKey,
|
|
@@ -181,7 +190,7 @@ export interface TRPCContextState<
|
|
|
181
190
|
) => Promise<void>;
|
|
182
191
|
|
|
183
192
|
/**
|
|
184
|
-
* @link https://tanstack.com/query/v5/docs/react/guides/query-cancellation
|
|
193
|
+
* @link https://tanstack.com/query/v5/docs/framework/react/guides/query-cancellation
|
|
185
194
|
*/
|
|
186
195
|
cancelQuery: (
|
|
187
196
|
queryKey: TRPCQueryKey,
|
|
@@ -189,7 +198,7 @@ export interface TRPCContextState<
|
|
|
189
198
|
) => Promise<void>;
|
|
190
199
|
|
|
191
200
|
/**
|
|
192
|
-
* @link https://tanstack.com/query/v5/docs/
|
|
201
|
+
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
|
|
193
202
|
*/
|
|
194
203
|
setQueryData: (
|
|
195
204
|
queryKey: TRPCQueryKey,
|
|
@@ -198,11 +207,11 @@ export interface TRPCContextState<
|
|
|
198
207
|
) => void;
|
|
199
208
|
|
|
200
209
|
/**
|
|
201
|
-
* @link https://tanstack.com/query/v5/docs/
|
|
210
|
+
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata
|
|
202
211
|
*/
|
|
203
212
|
getQueryData: (queryKey: TRPCQueryKey) => unknown;
|
|
204
213
|
/**
|
|
205
|
-
* @link https://tanstack.com/query/v5/docs/
|
|
214
|
+
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
|
|
206
215
|
*/
|
|
207
216
|
setInfiniteQueryData: (
|
|
208
217
|
queryKey: TRPCQueryKey,
|
|
@@ -214,10 +223,10 @@ export interface TRPCContextState<
|
|
|
214
223
|
) => void;
|
|
215
224
|
|
|
216
225
|
/**
|
|
217
|
-
* @link https://tanstack.com/query/v5/docs/
|
|
226
|
+
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata
|
|
218
227
|
*/
|
|
219
228
|
getInfiniteQueryData: (
|
|
220
229
|
queryKey: TRPCQueryKey,
|
|
221
230
|
) => InfiniteData<unknown> | undefined;
|
|
222
231
|
}
|
|
223
|
-
export const TRPCContext = createContext(null as any);
|
|
232
|
+
export const TRPCContext = React.createContext?.(null as any);
|
|
@@ -1,12 +1,24 @@
|
|
|
1
|
-
import { TRPCQueryKey } from './getQueryKey';
|
|
1
|
+
import type { TRPCQueryKey } from './getQueryKey';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
3
6
|
export function getClientArgs<TOptions>(
|
|
4
7
|
queryKey: TRPCQueryKey,
|
|
5
8
|
opts: TOptions,
|
|
6
|
-
|
|
9
|
+
infiniteParams?: {
|
|
10
|
+
pageParam: any;
|
|
11
|
+
direction: 'forward' | 'backward';
|
|
12
|
+
},
|
|
7
13
|
) {
|
|
8
14
|
const path = queryKey[0];
|
|
9
|
-
|
|
10
|
-
if (
|
|
15
|
+
let input = queryKey[1]?.input;
|
|
16
|
+
if (infiniteParams) {
|
|
17
|
+
input = {
|
|
18
|
+
...(input ?? {}),
|
|
19
|
+
...(infiniteParams.pageParam ? { cursor: infiniteParams.pageParam } : {}),
|
|
20
|
+
direction: infiniteParams.direction,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
11
23
|
return [path.join('.'), input, (opts as any)?.trpc] as const;
|
|
12
24
|
}
|