@trpc/react-query 11.0.0-next.91 → 11.0.0-rc.329
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
|
@@ -4,36 +4,33 @@ import {
|
|
|
4
4
|
useQueries as __useQueries,
|
|
5
5
|
useQuery as __useQuery,
|
|
6
6
|
useSuspenseInfiniteQuery as __useSuspenseInfiniteQuery,
|
|
7
|
+
useSuspenseQueries as __useSuspenseQueries,
|
|
7
8
|
useSuspenseQuery as __useSuspenseQuery,
|
|
8
|
-
DehydratedState,
|
|
9
9
|
hashKey,
|
|
10
|
+
skipToken,
|
|
10
11
|
useQueryClient,
|
|
11
12
|
} from '@tanstack/react-query';
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
useRef,
|
|
19
|
-
useState,
|
|
20
|
-
} from 'react';
|
|
21
|
-
import {
|
|
22
|
-
SSRState,
|
|
23
|
-
TRPCContext,
|
|
24
|
-
TRPCContextState,
|
|
25
|
-
} from '../../internals/context';
|
|
13
|
+
import type { TRPCClientErrorLike } from '@trpc/client';
|
|
14
|
+
import { createTRPCUntypedClient } from '@trpc/client';
|
|
15
|
+
import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
|
|
16
|
+
import * as React from 'react';
|
|
17
|
+
import type { SSRState, TRPCContextState } from '../../internals/context';
|
|
18
|
+
import { TRPCContext } from '../../internals/context';
|
|
26
19
|
import { getClientArgs } from '../../internals/getClientArgs';
|
|
27
|
-
import {
|
|
20
|
+
import type { TRPCQueryKey } from '../../internals/getQueryKey';
|
|
21
|
+
import { getQueryKeyInternal } from '../../internals/getQueryKey';
|
|
28
22
|
import { useHookResult } from '../../internals/useHookResult';
|
|
29
|
-
import {
|
|
23
|
+
import type {
|
|
24
|
+
TRPCUseQueries,
|
|
25
|
+
TRPCUseSuspenseQueries,
|
|
26
|
+
} from '../../internals/useQueries';
|
|
27
|
+
import { createUtilityFunctions } from '../../utils/createUtilityFunctions';
|
|
30
28
|
import { createUseQueries } from '../proxy/useQueriesProxy';
|
|
31
|
-
import { CreateTRPCReactOptions, UseMutationOverride } from '../types';
|
|
32
|
-
import {
|
|
29
|
+
import type { CreateTRPCReactOptions, UseMutationOverride } from '../types';
|
|
30
|
+
import type {
|
|
33
31
|
CreateClient,
|
|
34
32
|
TRPCProvider,
|
|
35
33
|
TRPCQueryOptions,
|
|
36
|
-
UseDehydratedState,
|
|
37
34
|
UseTRPCInfiniteQueryOptions,
|
|
38
35
|
UseTRPCInfiniteQueryResult,
|
|
39
36
|
UseTRPCMutationOptions,
|
|
@@ -71,163 +68,38 @@ export function createRootHooks<
|
|
|
71
68
|
|
|
72
69
|
const TRPCProvider: TRPCProvider<TRouter, TSSRContext> = (props) => {
|
|
73
70
|
const { abortOnUnmount = false, client, queryClient, ssrContext } = props;
|
|
74
|
-
const [ssrState, setSSRState] = useState<SSRState>(
|
|
75
|
-
|
|
71
|
+
const [ssrState, setSSRState] = React.useState<SSRState>(
|
|
72
|
+
props.ssrState ?? false,
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const fns = React.useMemo(
|
|
76
|
+
() =>
|
|
77
|
+
createUtilityFunctions({
|
|
78
|
+
client,
|
|
79
|
+
queryClient,
|
|
80
|
+
}),
|
|
81
|
+
[client, queryClient],
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const contextValue = React.useMemo<ProviderContext>(
|
|
85
|
+
() => ({
|
|
86
|
+
abortOnUnmount,
|
|
87
|
+
queryClient,
|
|
88
|
+
client,
|
|
89
|
+
ssrContext: ssrContext ?? null,
|
|
90
|
+
ssrState,
|
|
91
|
+
...fns,
|
|
92
|
+
}),
|
|
93
|
+
[abortOnUnmount, client, fns, queryClient, ssrContext, ssrState],
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
React.useEffect(() => {
|
|
76
97
|
// Only updating state to `mounted` if we are using SSR.
|
|
77
98
|
// This makes it so we don't have an unnecessary re-render when opting out of SSR.
|
|
78
99
|
setSSRState((state) => (state ? 'mounted' : false));
|
|
79
100
|
}, []);
|
|
80
101
|
return (
|
|
81
|
-
<Context.Provider
|
|
82
|
-
value={{
|
|
83
|
-
abortOnUnmount,
|
|
84
|
-
queryClient,
|
|
85
|
-
client,
|
|
86
|
-
ssrContext: ssrContext ?? null,
|
|
87
|
-
ssrState,
|
|
88
|
-
fetchQuery: useCallback(
|
|
89
|
-
(queryKey, opts) => {
|
|
90
|
-
return queryClient.fetchQuery({
|
|
91
|
-
...opts,
|
|
92
|
-
queryKey,
|
|
93
|
-
queryFn: () => client.query(...getClientArgs(queryKey, opts)),
|
|
94
|
-
});
|
|
95
|
-
},
|
|
96
|
-
[client, queryClient],
|
|
97
|
-
),
|
|
98
|
-
fetchInfiniteQuery: useCallback(
|
|
99
|
-
(queryKey, opts) => {
|
|
100
|
-
return queryClient.fetchInfiniteQuery({
|
|
101
|
-
...opts,
|
|
102
|
-
queryKey,
|
|
103
|
-
queryFn: ({ pageParam }) => {
|
|
104
|
-
return client.query(
|
|
105
|
-
...getClientArgs(queryKey, opts, pageParam),
|
|
106
|
-
);
|
|
107
|
-
},
|
|
108
|
-
initialPageParam: opts?.initialCursor ?? null,
|
|
109
|
-
});
|
|
110
|
-
},
|
|
111
|
-
[client, queryClient],
|
|
112
|
-
),
|
|
113
|
-
prefetchQuery: useCallback(
|
|
114
|
-
(queryKey, opts) => {
|
|
115
|
-
return queryClient.prefetchQuery({
|
|
116
|
-
...opts,
|
|
117
|
-
queryKey,
|
|
118
|
-
queryFn: () => client.query(...getClientArgs(queryKey, opts)),
|
|
119
|
-
});
|
|
120
|
-
},
|
|
121
|
-
[client, queryClient],
|
|
122
|
-
),
|
|
123
|
-
prefetchInfiniteQuery: useCallback(
|
|
124
|
-
(queryKey, opts) => {
|
|
125
|
-
return queryClient.prefetchInfiniteQuery({
|
|
126
|
-
...opts,
|
|
127
|
-
queryKey,
|
|
128
|
-
queryFn: ({ pageParam }) => {
|
|
129
|
-
return client.query(
|
|
130
|
-
...getClientArgs(queryKey, opts, pageParam),
|
|
131
|
-
);
|
|
132
|
-
},
|
|
133
|
-
initialPageParam: opts?.initialCursor ?? null,
|
|
134
|
-
});
|
|
135
|
-
},
|
|
136
|
-
[client, queryClient],
|
|
137
|
-
),
|
|
138
|
-
ensureQueryData: useCallback(
|
|
139
|
-
(queryKey, opts) => {
|
|
140
|
-
return queryClient.ensureQueryData({
|
|
141
|
-
...opts,
|
|
142
|
-
queryKey,
|
|
143
|
-
queryFn: () => client.query(...getClientArgs(queryKey, opts)),
|
|
144
|
-
});
|
|
145
|
-
},
|
|
146
|
-
[client, queryClient],
|
|
147
|
-
),
|
|
148
|
-
invalidateQueries: useCallback(
|
|
149
|
-
(queryKey, filters, options) => {
|
|
150
|
-
return queryClient.invalidateQueries(
|
|
151
|
-
{
|
|
152
|
-
...filters,
|
|
153
|
-
queryKey,
|
|
154
|
-
},
|
|
155
|
-
options,
|
|
156
|
-
);
|
|
157
|
-
},
|
|
158
|
-
[queryClient],
|
|
159
|
-
),
|
|
160
|
-
resetQueries: useCallback(
|
|
161
|
-
(queryKey, filters, options) => {
|
|
162
|
-
return queryClient.resetQueries(
|
|
163
|
-
{
|
|
164
|
-
...filters,
|
|
165
|
-
queryKey,
|
|
166
|
-
},
|
|
167
|
-
options,
|
|
168
|
-
);
|
|
169
|
-
},
|
|
170
|
-
[queryClient],
|
|
171
|
-
),
|
|
172
|
-
refetchQueries: useCallback(
|
|
173
|
-
(queryKey, filters, options) => {
|
|
174
|
-
return queryClient.refetchQueries(
|
|
175
|
-
{
|
|
176
|
-
...filters,
|
|
177
|
-
queryKey,
|
|
178
|
-
},
|
|
179
|
-
options,
|
|
180
|
-
);
|
|
181
|
-
},
|
|
182
|
-
[queryClient],
|
|
183
|
-
),
|
|
184
|
-
cancelQuery: useCallback(
|
|
185
|
-
(queryKey, options) => {
|
|
186
|
-
return queryClient.cancelQueries(
|
|
187
|
-
{
|
|
188
|
-
queryKey,
|
|
189
|
-
},
|
|
190
|
-
options,
|
|
191
|
-
);
|
|
192
|
-
},
|
|
193
|
-
[queryClient],
|
|
194
|
-
),
|
|
195
|
-
setQueryData: useCallback(
|
|
196
|
-
(queryKey, updater, options) => {
|
|
197
|
-
return queryClient.setQueryData(
|
|
198
|
-
queryKey,
|
|
199
|
-
updater as any,
|
|
200
|
-
options,
|
|
201
|
-
);
|
|
202
|
-
},
|
|
203
|
-
[queryClient],
|
|
204
|
-
),
|
|
205
|
-
getQueryData: useCallback(
|
|
206
|
-
(queryKey) => {
|
|
207
|
-
return queryClient.getQueryData(queryKey);
|
|
208
|
-
},
|
|
209
|
-
[queryClient],
|
|
210
|
-
),
|
|
211
|
-
setInfiniteQueryData: useCallback(
|
|
212
|
-
(queryKey, updater, options) => {
|
|
213
|
-
return queryClient.setQueryData(
|
|
214
|
-
queryKey,
|
|
215
|
-
updater as any,
|
|
216
|
-
options,
|
|
217
|
-
);
|
|
218
|
-
},
|
|
219
|
-
[queryClient],
|
|
220
|
-
),
|
|
221
|
-
getInfiniteQueryData: useCallback(
|
|
222
|
-
(queryKey) => {
|
|
223
|
-
return queryClient.getQueryData(queryKey);
|
|
224
|
-
},
|
|
225
|
-
[queryClient],
|
|
226
|
-
),
|
|
227
|
-
}}
|
|
228
|
-
>
|
|
229
|
-
{props.children}
|
|
230
|
-
</Context.Provider>
|
|
102
|
+
<Context.Provider value={contextValue}>{props.children}</Context.Provider>
|
|
231
103
|
);
|
|
232
104
|
};
|
|
233
105
|
|
|
@@ -272,11 +144,14 @@ export function createRootHooks<
|
|
|
272
144
|
|
|
273
145
|
const defaultOpts = queryClient.getQueryDefaults(queryKey);
|
|
274
146
|
|
|
147
|
+
const isInputSkipToken = input === skipToken;
|
|
148
|
+
|
|
275
149
|
if (
|
|
276
150
|
typeof window === 'undefined' &&
|
|
277
151
|
ssrState === 'prepass' &&
|
|
278
152
|
opts?.trpc?.ssr !== false &&
|
|
279
153
|
(opts?.enabled ?? defaultOpts?.enabled) !== false &&
|
|
154
|
+
!isInputSkipToken &&
|
|
280
155
|
!queryClient.getQueryCache().find({ queryKey })
|
|
281
156
|
) {
|
|
282
157
|
void prefetchQuery(queryKey, opts as any);
|
|
@@ -293,25 +168,27 @@ export function createRootHooks<
|
|
|
293
168
|
{
|
|
294
169
|
...ssrOpts,
|
|
295
170
|
queryKey: queryKey as any,
|
|
296
|
-
queryFn:
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
171
|
+
queryFn: isInputSkipToken
|
|
172
|
+
? input
|
|
173
|
+
: (queryFunctionContext) => {
|
|
174
|
+
const actualOpts = {
|
|
175
|
+
...ssrOpts,
|
|
176
|
+
trpc: {
|
|
177
|
+
...ssrOpts?.trpc,
|
|
178
|
+
...(shouldAbortOnUnmount
|
|
179
|
+
? { signal: queryFunctionContext.signal }
|
|
180
|
+
: {}),
|
|
181
|
+
},
|
|
182
|
+
};
|
|
306
183
|
|
|
307
|
-
|
|
308
|
-
|
|
184
|
+
return client.query(...getClientArgs(queryKey, actualOpts));
|
|
185
|
+
},
|
|
309
186
|
},
|
|
310
187
|
queryClient,
|
|
311
188
|
) as UseTRPCQueryResult<unknown, TError>;
|
|
312
189
|
|
|
313
190
|
hook.trpc = useHookResult({
|
|
314
|
-
path
|
|
191
|
+
path,
|
|
315
192
|
});
|
|
316
193
|
|
|
317
194
|
return hook;
|
|
@@ -350,7 +227,7 @@ export function createRootHooks<
|
|
|
350
227
|
) as UseTRPCQueryResult<unknown, TError>;
|
|
351
228
|
|
|
352
229
|
hook.trpc = useHookResult({
|
|
353
|
-
path
|
|
230
|
+
path,
|
|
354
231
|
});
|
|
355
232
|
|
|
356
233
|
return [hook.data, hook as any];
|
|
@@ -388,7 +265,7 @@ export function createRootHooks<
|
|
|
388
265
|
) as UseTRPCMutationResult<unknown, TError, unknown, unknown>;
|
|
389
266
|
|
|
390
267
|
hook.trpc = useHookResult({
|
|
391
|
-
path
|
|
268
|
+
path,
|
|
392
269
|
});
|
|
393
270
|
|
|
394
271
|
return hook;
|
|
@@ -404,10 +281,10 @@ export function createRootHooks<
|
|
|
404
281
|
const queryKey = hashKey(getQueryKeyInternal(path, input, 'any'));
|
|
405
282
|
const { client } = useContext();
|
|
406
283
|
|
|
407
|
-
const optsRef = useRef<typeof opts>(opts);
|
|
284
|
+
const optsRef = React.useRef<typeof opts>(opts);
|
|
408
285
|
optsRef.current = opts;
|
|
409
286
|
|
|
410
|
-
useEffect(() => {
|
|
287
|
+
React.useEffect(() => {
|
|
411
288
|
if (!enabled) {
|
|
412
289
|
return;
|
|
413
290
|
}
|
|
@@ -457,11 +334,14 @@ export function createRootHooks<
|
|
|
457
334
|
|
|
458
335
|
const defaultOpts = queryClient.getQueryDefaults(queryKey);
|
|
459
336
|
|
|
337
|
+
const isInputSkipToken = input === skipToken;
|
|
338
|
+
|
|
460
339
|
if (
|
|
461
340
|
typeof window === 'undefined' &&
|
|
462
341
|
ssrState === 'prepass' &&
|
|
463
342
|
opts?.trpc?.ssr !== false &&
|
|
464
343
|
(opts?.enabled ?? defaultOpts?.enabled) !== false &&
|
|
344
|
+
!isInputSkipToken &&
|
|
465
345
|
!queryClient.getQueryCache().find({ queryKey })
|
|
466
346
|
) {
|
|
467
347
|
void prefetchInfiniteQuery(queryKey, { ...defaultOpts, ...opts } as any);
|
|
@@ -481,31 +361,33 @@ export function createRootHooks<
|
|
|
481
361
|
initialPageParam: opts.initialCursor ?? null,
|
|
482
362
|
persister: opts.persister,
|
|
483
363
|
queryKey: queryKey as any,
|
|
484
|
-
queryFn:
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
364
|
+
queryFn: isInputSkipToken
|
|
365
|
+
? input
|
|
366
|
+
: (queryFunctionContext) => {
|
|
367
|
+
const actualOpts = {
|
|
368
|
+
...ssrOpts,
|
|
369
|
+
trpc: {
|
|
370
|
+
...ssrOpts?.trpc,
|
|
371
|
+
...(shouldAbortOnUnmount
|
|
372
|
+
? { signal: queryFunctionContext.signal }
|
|
373
|
+
: {}),
|
|
374
|
+
},
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
return client.query(
|
|
378
|
+
...getClientArgs(queryKey, actualOpts, {
|
|
379
|
+
pageParam:
|
|
380
|
+
queryFunctionContext.pageParam ?? opts.initialCursor,
|
|
381
|
+
direction: queryFunctionContext.direction,
|
|
382
|
+
}),
|
|
383
|
+
);
|
|
492
384
|
},
|
|
493
|
-
};
|
|
494
|
-
|
|
495
|
-
return client.query(
|
|
496
|
-
...getClientArgs(
|
|
497
|
-
queryKey,
|
|
498
|
-
actualOpts,
|
|
499
|
-
queryFunctionContext.pageParam ?? opts.initialCursor,
|
|
500
|
-
),
|
|
501
|
-
);
|
|
502
|
-
},
|
|
503
385
|
},
|
|
504
386
|
queryClient,
|
|
505
387
|
) as UseTRPCInfiniteQueryResult<unknown, TError, unknown>;
|
|
506
388
|
|
|
507
389
|
hook.trpc = useHookResult({
|
|
508
|
-
path
|
|
390
|
+
path,
|
|
509
391
|
});
|
|
510
392
|
return hook;
|
|
511
393
|
}
|
|
@@ -546,11 +428,10 @@ export function createRootHooks<
|
|
|
546
428
|
};
|
|
547
429
|
|
|
548
430
|
return context.client.query(
|
|
549
|
-
...getClientArgs(
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
),
|
|
431
|
+
...getClientArgs(queryKey, actualOpts, {
|
|
432
|
+
pageParam: queryFunctionContext.pageParam ?? opts.initialCursor,
|
|
433
|
+
direction: queryFunctionContext.direction,
|
|
434
|
+
}),
|
|
554
435
|
);
|
|
555
436
|
},
|
|
556
437
|
},
|
|
@@ -558,7 +439,7 @@ export function createRootHooks<
|
|
|
558
439
|
) as UseTRPCInfiniteQueryResult<unknown, TError, unknown>;
|
|
559
440
|
|
|
560
441
|
hook.trpc = useHookResult({
|
|
561
|
-
path
|
|
442
|
+
path,
|
|
562
443
|
});
|
|
563
444
|
|
|
564
445
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
@@ -595,18 +476,26 @@ export function createRootHooks<
|
|
|
595
476
|
);
|
|
596
477
|
};
|
|
597
478
|
|
|
598
|
-
const
|
|
599
|
-
|
|
600
|
-
trpcState,
|
|
479
|
+
const useSuspenseQueries: TRPCUseSuspenseQueries<TRouter> = (
|
|
480
|
+
queriesCallback,
|
|
601
481
|
) => {
|
|
602
|
-
const
|
|
603
|
-
if (!trpcState) {
|
|
604
|
-
return trpcState;
|
|
605
|
-
}
|
|
482
|
+
const { queryClient, client } = useContext();
|
|
606
483
|
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
484
|
+
const proxy = createUseQueries(client);
|
|
485
|
+
|
|
486
|
+
const queries = queriesCallback(proxy);
|
|
487
|
+
|
|
488
|
+
const hook = __useSuspenseQueries(
|
|
489
|
+
{
|
|
490
|
+
queries: queries.map((query) => ({
|
|
491
|
+
...query,
|
|
492
|
+
queryKey: (query as TRPCQueryOptions<any, any>).queryKey,
|
|
493
|
+
})),
|
|
494
|
+
},
|
|
495
|
+
queryClient,
|
|
496
|
+
);
|
|
497
|
+
|
|
498
|
+
return [hook.map((h) => h.data), hook] as any;
|
|
610
499
|
};
|
|
611
500
|
|
|
612
501
|
return {
|
|
@@ -617,33 +506,13 @@ export function createRootHooks<
|
|
|
617
506
|
useQuery,
|
|
618
507
|
useSuspenseQuery,
|
|
619
508
|
useQueries,
|
|
509
|
+
useSuspenseQueries,
|
|
620
510
|
useMutation,
|
|
621
511
|
useSubscription,
|
|
622
|
-
useDehydratedState,
|
|
623
512
|
useInfiniteQuery,
|
|
624
513
|
useSuspenseInfiniteQuery,
|
|
625
514
|
};
|
|
626
515
|
}
|
|
627
|
-
/* istanbul ignore next */
|
|
628
|
-
/**
|
|
629
|
-
* Hack to infer the type of `createReactQueryHooks`
|
|
630
|
-
* @link https://stackoverflow.com/a/59072991
|
|
631
|
-
*/
|
|
632
|
-
class GnClass<TRouter extends AnyRouter, TSSRContext = unknown> {
|
|
633
|
-
fn() {
|
|
634
|
-
return createRootHooks<TRouter, TSSRContext>();
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
type returnTypeInferer<TType> = TType extends (
|
|
639
|
-
a: Record<string, string>,
|
|
640
|
-
) => infer U
|
|
641
|
-
? U
|
|
642
|
-
: never;
|
|
643
|
-
type fooType<TRouter extends AnyRouter, TSSRContext = unknown> = GnClass<
|
|
644
|
-
TRouter,
|
|
645
|
-
TSSRContext
|
|
646
|
-
>['fn'];
|
|
647
516
|
|
|
648
517
|
/**
|
|
649
518
|
* Infer the type of a `createReactQueryHooks` function
|
|
@@ -652,4 +521,4 @@ type fooType<TRouter extends AnyRouter, TSSRContext = unknown> = GnClass<
|
|
|
652
521
|
export type CreateReactQueryHooks<
|
|
653
522
|
TRouter extends AnyRouter,
|
|
654
523
|
TSSRContext = unknown,
|
|
655
|
-
> =
|
|
524
|
+
> = ReturnType<typeof createRootHooks<TRouter, TSSRContext>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
DefinedUseQueryResult,
|
|
3
3
|
DehydratedState,
|
|
4
4
|
InfiniteData,
|
|
@@ -17,16 +17,18 @@ import {
|
|
|
17
17
|
UseSuspenseQueryOptions,
|
|
18
18
|
UseSuspenseQueryResult,
|
|
19
19
|
} from '@tanstack/react-query';
|
|
20
|
-
import {
|
|
20
|
+
import type {
|
|
21
21
|
CreateTRPCClientOptions,
|
|
22
22
|
TRPCRequestOptions,
|
|
23
23
|
TRPCUntypedClient,
|
|
24
24
|
} from '@trpc/client';
|
|
25
|
-
import {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
import {
|
|
25
|
+
import type {
|
|
26
|
+
AnyRouter,
|
|
27
|
+
DistributiveOmit,
|
|
28
|
+
} from '@trpc/server/unstable-core-do-not-import';
|
|
29
|
+
import type { ReactNode } from 'react';
|
|
30
|
+
import type { TRPCContextProps } from '../../internals/context';
|
|
31
|
+
import type { TRPCQueryKey } from '../../internals/getQueryKey';
|
|
30
32
|
|
|
31
33
|
export type OutputWithCursor<TData, TCursor = any> = {
|
|
32
34
|
cursor: TCursor | null;
|
|
@@ -223,3 +225,9 @@ export type UseTRPCSuspenseInfiniteQueryResult<TData, TError, TInput> = [
|
|
|
223
225
|
*/
|
|
224
226
|
export type UseTRPCMutationResult<TData, TError, TVariables, TContext> =
|
|
225
227
|
TRPCHookResult & UseMutationResult<TData, TError, TVariables, TContext>;
|
|
228
|
+
|
|
229
|
+
export interface TRPCHookResult {
|
|
230
|
+
trpc: {
|
|
231
|
+
path: string;
|
|
232
|
+
};
|
|
233
|
+
}
|
package/src/shared/index.ts
CHANGED
|
@@ -2,10 +2,13 @@ export * from './proxy/decorationProxy';
|
|
|
2
2
|
export * from './proxy/utilsProxy';
|
|
3
3
|
export * from './proxy/useQueriesProxy';
|
|
4
4
|
export type {
|
|
5
|
-
|
|
5
|
+
DecorateRouterRecord,
|
|
6
6
|
DecorateProcedure,
|
|
7
7
|
} from '../createTRPCReact';
|
|
8
|
-
export type {
|
|
8
|
+
export type {
|
|
9
|
+
TRPCUseQueries,
|
|
10
|
+
TRPCUseSuspenseQueries,
|
|
11
|
+
} from '../internals/useQueries';
|
|
9
12
|
export * from './hooks/createRootHooks';
|
|
10
13
|
export * from './queryClient';
|
|
11
14
|
export * from './types';
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type {
|
|
2
|
+
AnyProcedure,
|
|
3
|
+
AnyRootTypes,
|
|
4
|
+
inferProcedureInput,
|
|
5
|
+
inferTransformedProcedureOutput,
|
|
6
|
+
} from '@trpc/server/unstable-core-do-not-import';
|
|
7
|
+
import type {
|
|
4
8
|
InferMutationOptions,
|
|
5
9
|
InferMutationResult,
|
|
6
10
|
} from '../../utils/inferReactQueryProcedure';
|
|
@@ -9,26 +13,28 @@ import {
|
|
|
9
13
|
* Use to describe a mutation route which matches a given mutation procedure's interface
|
|
10
14
|
*/
|
|
11
15
|
export type MutationLike<
|
|
12
|
-
|
|
13
|
-
TProcedure extends AnyProcedure
|
|
16
|
+
TRoot extends AnyRootTypes,
|
|
17
|
+
TProcedure extends AnyProcedure,
|
|
14
18
|
> = {
|
|
15
19
|
useMutation: (
|
|
16
|
-
opts?: InferMutationOptions<
|
|
17
|
-
) => InferMutationResult<
|
|
20
|
+
opts?: InferMutationOptions<TRoot, TProcedure>,
|
|
21
|
+
) => InferMutationResult<TRoot, TProcedure>;
|
|
18
22
|
};
|
|
19
23
|
|
|
20
24
|
/**
|
|
21
25
|
* Use to unwrap a MutationLike's input
|
|
22
26
|
*/
|
|
23
|
-
export type InferMutationLikeInput<
|
|
24
|
-
TMutationLike extends MutationLike<any,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
export type InferMutationLikeInput<
|
|
28
|
+
TMutationLike extends MutationLike<any, any>,
|
|
29
|
+
> = TMutationLike extends MutationLike<any, infer $Procedure>
|
|
30
|
+
? inferProcedureInput<$Procedure>
|
|
31
|
+
: never;
|
|
27
32
|
|
|
28
33
|
/**
|
|
29
34
|
* Use to unwrap a MutationLike's data output
|
|
30
35
|
*/
|
|
31
|
-
export type InferMutationLikeData<
|
|
32
|
-
TMutationLike extends MutationLike<
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
export type InferMutationLikeData<
|
|
37
|
+
TMutationLike extends MutationLike<any, any>,
|
|
38
|
+
> = TMutationLike extends MutationLike<infer TRoot, infer TProcedure>
|
|
39
|
+
? inferTransformedProcedureOutput<TRoot, TProcedure>
|
|
40
|
+
: never;
|
|
@@ -1,37 +1,57 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import type { TRPCClientErrorLike } from '@trpc/client';
|
|
2
|
+
import type {
|
|
3
|
+
AnyProcedure,
|
|
4
|
+
AnyRootTypes,
|
|
5
|
+
inferProcedureInput,
|
|
6
|
+
inferProcedureOutput,
|
|
7
|
+
inferTransformedProcedureOutput,
|
|
8
|
+
} from '@trpc/server/unstable-core-do-not-import';
|
|
9
|
+
import type { DecoratedQuery } from '../../createTRPCReact';
|
|
10
|
+
import type {
|
|
4
11
|
InferQueryOptions,
|
|
5
12
|
InferQueryResult,
|
|
6
13
|
} from '../../utils/inferReactQueryProcedure';
|
|
14
|
+
import type { UseTRPCSuspenseQueryResult } from '../hooks/types';
|
|
7
15
|
|
|
8
16
|
/**
|
|
9
17
|
* Use to request a query route which matches a given query procedure's interface
|
|
10
18
|
*/
|
|
11
19
|
export type QueryLike<
|
|
12
|
-
|
|
13
|
-
TProcedure extends AnyProcedure
|
|
20
|
+
TRoot extends AnyRootTypes,
|
|
21
|
+
TProcedure extends AnyProcedure,
|
|
14
22
|
> = {
|
|
15
23
|
useQuery: (
|
|
16
24
|
variables: inferProcedureInput<TProcedure>,
|
|
17
|
-
opts?: InferQueryOptions<
|
|
18
|
-
) => InferQueryResult<
|
|
25
|
+
opts?: InferQueryOptions<TRoot, TProcedure, any>,
|
|
26
|
+
) => InferQueryResult<TRoot, TProcedure>;
|
|
27
|
+
|
|
28
|
+
useSuspenseQuery: (
|
|
29
|
+
variables: inferProcedureInput<TProcedure>,
|
|
30
|
+
opts?: InferQueryOptions<TRoot, TProcedure, any>,
|
|
31
|
+
) => UseTRPCSuspenseQueryResult<
|
|
32
|
+
inferProcedureOutput<TProcedure>,
|
|
33
|
+
TRPCClientErrorLike<TRoot>
|
|
34
|
+
>;
|
|
19
35
|
};
|
|
20
36
|
|
|
21
37
|
/**
|
|
22
38
|
* Use to unwrap a QueryLike's input
|
|
23
39
|
*/
|
|
24
|
-
export type InferQueryLikeInput<
|
|
25
|
-
|
|
26
|
-
>
|
|
40
|
+
export type InferQueryLikeInput<TQueryLike> = TQueryLike extends DecoratedQuery<
|
|
41
|
+
infer $Def
|
|
42
|
+
>
|
|
43
|
+
? $Def['input']
|
|
44
|
+
: TQueryLike extends QueryLike<any, infer TProcedure>
|
|
27
45
|
? inferProcedureInput<TProcedure>
|
|
28
46
|
: never;
|
|
29
47
|
|
|
30
48
|
/**
|
|
31
49
|
* Use to unwrap a QueryLike's data output
|
|
32
50
|
*/
|
|
33
|
-
export type InferQueryLikeData<
|
|
34
|
-
|
|
35
|
-
>
|
|
36
|
-
?
|
|
51
|
+
export type InferQueryLikeData<TQueryLike> = TQueryLike extends DecoratedQuery<
|
|
52
|
+
infer $Def
|
|
53
|
+
>
|
|
54
|
+
? $Def['output']
|
|
55
|
+
: TQueryLike extends QueryLike<infer TRoot, infer TProcedure>
|
|
56
|
+
? inferTransformedProcedureOutput<TRoot, TProcedure>
|
|
37
57
|
: never;
|