@trpc/react-query 10.42.0 → 11.0.0-next.91
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle-analysis.json +208 -0
- package/dist/createHooksInternal-3d8ebfcf.mjs +481 -0
- package/dist/createHooksInternal-dce6e141.js +435 -0
- package/dist/createHooksInternal-e2034194.js +490 -0
- package/dist/createTRPCReact.d.ts +46 -45
- package/dist/createTRPCReact.d.ts.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -21
- package/dist/index.mjs +9 -21
- package/dist/internals/context.d.ts +42 -54
- package/dist/internals/context.d.ts.map +1 -1
- package/dist/internals/getClientArgs.d.ts +2 -1
- package/dist/internals/getClientArgs.d.ts.map +1 -1
- package/dist/internals/getQueryKey.d.ts +28 -13
- package/dist/internals/getQueryKey.d.ts.map +1 -1
- package/dist/internals/useQueries.d.ts +4 -4
- package/dist/internals/useQueries.d.ts.map +1 -1
- package/dist/server/index.d.ts +0 -6
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +52 -69
- package/dist/server/index.mjs +52 -69
- package/dist/server/ssgProxy.d.ts +23 -13
- package/dist/server/ssgProxy.d.ts.map +1 -1
- package/dist/shared/hooks/createHooksInternal.d.ts +35 -12
- package/dist/shared/hooks/createHooksInternal.d.ts.map +1 -1
- package/dist/shared/hooks/createRootHooks.d.ts +0 -5
- package/dist/shared/hooks/createRootHooks.d.ts.map +1 -1
- package/dist/shared/hooks/types.d.ts +33 -18
- package/dist/shared/hooks/types.d.ts.map +1 -1
- package/dist/shared/index.js +9 -9
- package/dist/shared/index.mjs +3 -3
- package/dist/shared/polymorphism/mutationLike.d.ts +5 -5
- package/dist/shared/polymorphism/mutationLike.d.ts.map +1 -1
- package/dist/shared/polymorphism/queryLike.d.ts +5 -5
- package/dist/shared/polymorphism/queryLike.d.ts.map +1 -1
- package/dist/shared/polymorphism/routerLike.d.ts +4 -3
- package/dist/shared/polymorphism/routerLike.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/useQueriesProxy.d.ts +6 -6
- package/dist/shared/proxy/useQueriesProxy.d.ts.map +1 -1
- package/dist/shared/proxy/utilsProxy.d.ts +34 -31
- package/dist/shared/proxy/utilsProxy.d.ts.map +1 -1
- package/dist/shared/types.d.ts +0 -12
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/utils/inferReactQueryProcedure.d.ts +7 -7
- package/dist/utils/inferReactQueryProcedure.d.ts.map +1 -1
- package/dist/utilsProxy-00894da2.mjs +121 -0
- package/dist/utilsProxy-27bd93c1.js +128 -0
- package/dist/utilsProxy-7e396600.js +114 -0
- package/package.json +8 -14
- package/src/createTRPCReact.tsx +156 -135
- package/src/index.ts +0 -1
- package/src/internals/context.tsx +93 -164
- package/src/internals/getClientArgs.ts +9 -4
- package/src/internals/getQueryKey.ts +53 -24
- package/src/internals/useQueries.ts +7 -10
- package/src/server/index.ts +0 -8
- package/src/server/ssgProxy.ts +179 -34
- package/src/shared/hooks/createHooksInternal.tsx +298 -207
- package/src/shared/hooks/createRootHooks.tsx +0 -6
- package/src/shared/hooks/types.ts +87 -36
- package/src/shared/polymorphism/mutationLike.ts +11 -8
- package/src/shared/polymorphism/queryLike.ts +17 -12
- package/src/shared/polymorphism/routerLike.ts +15 -9
- package/src/shared/proxy/decorationProxy.ts +9 -31
- package/src/shared/proxy/useQueriesProxy.ts +23 -37
- package/src/shared/proxy/utilsProxy.ts +121 -95
- package/src/shared/types.ts +0 -12
- package/src/utils/inferReactQueryProcedure.ts +28 -30
- package/dist/context-4557b3d3.js +0 -38
- package/dist/createHooksInternal-2e69c447.js +0 -582
- package/dist/createHooksInternal-37b068e0.js +0 -510
- package/dist/createHooksInternal-bdff7171.mjs +0 -568
- package/dist/getArrayQueryKey-4bdb5cc2.js +0 -36
- package/dist/getArrayQueryKey-86134f8b.mjs +0 -34
- package/dist/internals/getArrayQueryKey.d.ts +0 -25
- package/dist/internals/getArrayQueryKey.d.ts.map +0 -1
- package/dist/interop.d.ts +0 -11
- package/dist/interop.d.ts.map +0 -1
- package/dist/server/types.d.ts +0 -14
- package/dist/server/types.d.ts.map +0 -1
- package/dist/shared/hooks/deprecated/createHooksInternal.d.ts +0 -63
- package/dist/shared/hooks/deprecated/createHooksInternal.d.ts.map +0 -1
- package/dist/ssg/index.d.ts +0 -15
- package/dist/ssg/index.d.ts.map +0 -1
- package/dist/ssg/ssg.d.ts +0 -16
- package/dist/ssg/ssg.d.ts.map +0 -1
- package/src/internals/getArrayQueryKey.ts +0 -46
- package/src/interop.ts +0 -29
- package/src/server/types.ts +0 -29
- package/src/shared/hooks/deprecated/createHooksInternal.tsx +0 -641
- package/src/ssg/index.tsx +0 -16
- package/src/ssg/ssg.ts +0 -139
- package/ssg/index.d.ts +0 -1
- package/ssg/index.js +0 -1
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
import { createTRPCClientProxy, TRPCClientError } from '@trpc/client';
|
|
14
14
|
import {
|
|
15
15
|
AnyQueryProcedure,
|
|
16
|
+
AnyRootConfig,
|
|
16
17
|
AnyRouter,
|
|
17
18
|
DeepPartial,
|
|
18
19
|
Filter,
|
|
@@ -26,77 +27,86 @@ import {
|
|
|
26
27
|
} from '@trpc/server/shared';
|
|
27
28
|
import {
|
|
28
29
|
contextProps,
|
|
29
|
-
|
|
30
|
+
DecoratedTRPCContextProps,
|
|
30
31
|
TRPCContextState,
|
|
31
32
|
TRPCFetchInfiniteQueryOptions,
|
|
32
33
|
TRPCFetchQueryOptions,
|
|
33
34
|
} from '../../internals/context';
|
|
34
|
-
import {
|
|
35
|
-
|
|
35
|
+
import {
|
|
36
|
+
getQueryKeyInternal,
|
|
37
|
+
QueryKeyKnown,
|
|
38
|
+
QueryType,
|
|
39
|
+
} from '../../internals/getQueryKey';
|
|
40
|
+
import { ExtractCursorType } from '../hooks/types';
|
|
36
41
|
|
|
37
|
-
type DecorateProcedure<
|
|
42
|
+
type DecorateProcedure<
|
|
43
|
+
TConfig extends AnyRootConfig,
|
|
44
|
+
TProcedure extends AnyQueryProcedure,
|
|
45
|
+
> = {
|
|
38
46
|
/**
|
|
39
|
-
* @link https://tanstack.com/query/
|
|
47
|
+
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchquery
|
|
40
48
|
*/
|
|
41
49
|
fetch(
|
|
42
50
|
input: inferProcedureInput<TProcedure>,
|
|
43
51
|
opts?: TRPCFetchQueryOptions<
|
|
44
|
-
|
|
45
|
-
TRPCClientError<
|
|
46
|
-
inferTransformedProcedureOutput<TProcedure>
|
|
52
|
+
inferTransformedProcedureOutput<TConfig, TProcedure>,
|
|
53
|
+
TRPCClientError<TConfig>
|
|
47
54
|
>,
|
|
48
|
-
): Promise<inferTransformedProcedureOutput<TProcedure>>;
|
|
55
|
+
): Promise<inferTransformedProcedureOutput<TConfig, TProcedure>>;
|
|
49
56
|
|
|
50
57
|
/**
|
|
51
|
-
* @link https://tanstack.com/query/
|
|
58
|
+
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchinfinitequery
|
|
52
59
|
*/
|
|
53
60
|
fetchInfinite(
|
|
54
61
|
input: inferProcedureInput<TProcedure>,
|
|
55
62
|
opts?: TRPCFetchInfiniteQueryOptions<
|
|
56
63
|
inferProcedureInput<TProcedure>,
|
|
57
|
-
|
|
58
|
-
|
|
64
|
+
inferTransformedProcedureOutput<TConfig, TProcedure>,
|
|
65
|
+
TRPCClientError<TConfig>
|
|
59
66
|
>,
|
|
60
|
-
): Promise<
|
|
67
|
+
): Promise<
|
|
68
|
+
InfiniteData<
|
|
69
|
+
inferTransformedProcedureOutput<TConfig, TProcedure>,
|
|
70
|
+
NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null
|
|
71
|
+
>
|
|
72
|
+
>;
|
|
61
73
|
|
|
62
74
|
/**
|
|
63
|
-
* @link https://tanstack.com/query/
|
|
75
|
+
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientprefetchquery
|
|
64
76
|
*/
|
|
65
77
|
prefetch(
|
|
66
78
|
input: inferProcedureInput<TProcedure>,
|
|
67
79
|
opts?: TRPCFetchQueryOptions<
|
|
68
|
-
|
|
69
|
-
TRPCClientError<
|
|
70
|
-
inferTransformedProcedureOutput<TProcedure>
|
|
80
|
+
inferTransformedProcedureOutput<TConfig, TProcedure>,
|
|
81
|
+
TRPCClientError<TConfig>
|
|
71
82
|
>,
|
|
72
83
|
): Promise<void>;
|
|
73
84
|
|
|
74
85
|
/**
|
|
75
|
-
* @link https://tanstack.com/query/
|
|
86
|
+
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientprefetchinfinitequery
|
|
76
87
|
*/
|
|
77
88
|
prefetchInfinite(
|
|
78
89
|
input: inferProcedureInput<TProcedure>,
|
|
79
90
|
opts?: TRPCFetchInfiniteQueryOptions<
|
|
80
91
|
inferProcedureInput<TProcedure>,
|
|
81
|
-
|
|
82
|
-
|
|
92
|
+
inferTransformedProcedureOutput<TConfig, TProcedure>,
|
|
93
|
+
TRPCClientError<TConfig>
|
|
83
94
|
>,
|
|
84
95
|
): Promise<void>;
|
|
85
96
|
|
|
86
97
|
/**
|
|
87
|
-
* @link https://tanstack.com/query/
|
|
98
|
+
* @link https://tanstack.com/query/v5/docs/react/reference/QueryClient#queryclientensurequerydata
|
|
88
99
|
*/
|
|
89
100
|
ensureData(
|
|
90
101
|
input: inferProcedureInput<TProcedure>,
|
|
91
102
|
opts?: TRPCFetchQueryOptions<
|
|
92
|
-
|
|
93
|
-
TRPCClientError<
|
|
94
|
-
inferTransformedProcedureOutput<TProcedure>
|
|
103
|
+
inferTransformedProcedureOutput<TConfig, TProcedure>,
|
|
104
|
+
TRPCClientError<TConfig>
|
|
95
105
|
>,
|
|
96
|
-
): Promise<inferTransformedProcedureOutput<TProcedure>>;
|
|
106
|
+
): Promise<inferTransformedProcedureOutput<TConfig, TProcedure>>;
|
|
97
107
|
|
|
98
108
|
/**
|
|
99
|
-
* @link https://tanstack.com/query/
|
|
109
|
+
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientinvalidatequeries
|
|
100
110
|
*/
|
|
101
111
|
invalidate(
|
|
102
112
|
input?: DeepPartial<inferProcedureInput<TProcedure>>,
|
|
@@ -104,7 +114,7 @@ type DecorateProcedure<TProcedure extends AnyQueryProcedure> = {
|
|
|
104
114
|
predicate?: (
|
|
105
115
|
query: Query<
|
|
106
116
|
inferProcedureInput<TProcedure>,
|
|
107
|
-
TRPCClientError<
|
|
117
|
+
TRPCClientError<TConfig>,
|
|
108
118
|
inferProcedureInput<TProcedure>,
|
|
109
119
|
QueryKeyKnown<
|
|
110
120
|
inferProcedureInput<TProcedure>,
|
|
@@ -119,7 +129,7 @@ type DecorateProcedure<TProcedure extends AnyQueryProcedure> = {
|
|
|
119
129
|
): Promise<void>;
|
|
120
130
|
|
|
121
131
|
/**
|
|
122
|
-
* @link https://tanstack.com/query/
|
|
132
|
+
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientrefetchqueries
|
|
123
133
|
*/
|
|
124
134
|
refetch(
|
|
125
135
|
input?: inferProcedureInput<TProcedure>,
|
|
@@ -128,7 +138,7 @@ type DecorateProcedure<TProcedure extends AnyQueryProcedure> = {
|
|
|
128
138
|
): Promise<void>;
|
|
129
139
|
|
|
130
140
|
/**
|
|
131
|
-
* @link https://tanstack.com/query/
|
|
141
|
+
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientcancelqueries
|
|
132
142
|
*/
|
|
133
143
|
cancel(
|
|
134
144
|
input?: inferProcedureInput<TProcedure>,
|
|
@@ -136,7 +146,7 @@ type DecorateProcedure<TProcedure extends AnyQueryProcedure> = {
|
|
|
136
146
|
): Promise<void>;
|
|
137
147
|
|
|
138
148
|
/**
|
|
139
|
-
* @link https://tanstack.com/query/
|
|
149
|
+
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientresetqueries
|
|
140
150
|
*/
|
|
141
151
|
reset(
|
|
142
152
|
input?: inferProcedureInput<TProcedure>,
|
|
@@ -144,7 +154,7 @@ type DecorateProcedure<TProcedure extends AnyQueryProcedure> = {
|
|
|
144
154
|
): Promise<void>;
|
|
145
155
|
|
|
146
156
|
/**
|
|
147
|
-
* @link https://tanstack.com/query/
|
|
157
|
+
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
|
|
148
158
|
*/
|
|
149
159
|
setData(
|
|
150
160
|
/**
|
|
@@ -152,37 +162,50 @@ type DecorateProcedure<TProcedure extends AnyQueryProcedure> = {
|
|
|
152
162
|
*/
|
|
153
163
|
input: inferProcedureInput<TProcedure>,
|
|
154
164
|
updater: Updater<
|
|
155
|
-
inferTransformedProcedureOutput<TProcedure> | undefined,
|
|
156
|
-
inferTransformedProcedureOutput<TProcedure> | undefined
|
|
165
|
+
inferTransformedProcedureOutput<TConfig, TProcedure> | undefined,
|
|
166
|
+
inferTransformedProcedureOutput<TConfig, TProcedure> | undefined
|
|
157
167
|
>,
|
|
158
168
|
options?: SetDataOptions,
|
|
159
169
|
): void;
|
|
160
170
|
|
|
161
171
|
/**
|
|
162
|
-
* @link https://tanstack.com/query/
|
|
172
|
+
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
|
|
163
173
|
*/
|
|
164
174
|
setInfiniteData(
|
|
165
175
|
input: inferProcedureInput<TProcedure>,
|
|
166
176
|
updater: Updater<
|
|
167
|
-
InfiniteData<
|
|
168
|
-
|
|
177
|
+
| InfiniteData<
|
|
178
|
+
inferTransformedProcedureOutput<TConfig, TProcedure>,
|
|
179
|
+
NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null
|
|
180
|
+
>
|
|
181
|
+
| undefined,
|
|
182
|
+
| InfiniteData<
|
|
183
|
+
inferTransformedProcedureOutput<TConfig, TProcedure>,
|
|
184
|
+
NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null
|
|
185
|
+
>
|
|
186
|
+
| undefined
|
|
169
187
|
>,
|
|
170
188
|
options?: SetDataOptions,
|
|
171
189
|
): void;
|
|
172
190
|
|
|
173
191
|
/**
|
|
174
|
-
* @link https://tanstack.com/query/
|
|
192
|
+
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata
|
|
175
193
|
*/
|
|
176
194
|
getData(
|
|
177
195
|
input?: inferProcedureInput<TProcedure>,
|
|
178
|
-
): inferTransformedProcedureOutput<TProcedure> | undefined;
|
|
196
|
+
): inferTransformedProcedureOutput<TConfig, TProcedure> | undefined;
|
|
179
197
|
|
|
180
198
|
/**
|
|
181
|
-
* @link https://tanstack.com/query/
|
|
199
|
+
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata
|
|
182
200
|
*/
|
|
183
201
|
getInfiniteData(
|
|
184
202
|
input?: inferProcedureInput<TProcedure>,
|
|
185
|
-
):
|
|
203
|
+
):
|
|
204
|
+
| InfiniteData<
|
|
205
|
+
inferTransformedProcedureOutput<TConfig, TProcedure>,
|
|
206
|
+
NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null
|
|
207
|
+
>
|
|
208
|
+
| undefined;
|
|
186
209
|
};
|
|
187
210
|
|
|
188
211
|
/**
|
|
@@ -193,7 +216,7 @@ type DecorateRouter = {
|
|
|
193
216
|
/**
|
|
194
217
|
* Invalidate the full router
|
|
195
218
|
* @link https://trpc.io/docs/v10/useContext#query-invalidation
|
|
196
|
-
* @link https://tanstack.com/query/
|
|
219
|
+
* @link https://tanstack.com/query/v5/docs/react/guides/query-invalidation
|
|
197
220
|
*/
|
|
198
221
|
invalidate(
|
|
199
222
|
input?: undefined,
|
|
@@ -214,32 +237,56 @@ export type DecoratedProcedureUtilsRecord<TRouter extends AnyRouter> =
|
|
|
214
237
|
? DecoratedProcedureUtilsRecord<TRouter['_def']['record'][TKey]> &
|
|
215
238
|
DecorateRouter
|
|
216
239
|
: // utils only apply to queries
|
|
217
|
-
DecorateProcedure<
|
|
240
|
+
DecorateProcedure<
|
|
241
|
+
TRouter['_def']['_config'],
|
|
242
|
+
TRouter['_def']['record'][TKey]
|
|
243
|
+
>;
|
|
218
244
|
}; // Add functions that should be available at utils root
|
|
219
245
|
|
|
220
|
-
type AnyDecoratedProcedure = DecorateProcedure<any>;
|
|
246
|
+
type AnyDecoratedProcedure = DecorateProcedure<any, any>;
|
|
221
247
|
|
|
222
|
-
export type
|
|
248
|
+
export type CreateReactUtils<
|
|
223
249
|
TRouter extends AnyRouter,
|
|
224
250
|
TSSRContext,
|
|
225
251
|
> = ProtectedIntersection<
|
|
226
|
-
|
|
252
|
+
DecoratedTRPCContextProps<TRouter, TSSRContext>,
|
|
227
253
|
DecoratedProcedureUtilsRecord<TRouter>
|
|
228
254
|
>;
|
|
229
255
|
|
|
256
|
+
export const getQueryType = (
|
|
257
|
+
utilName: keyof AnyDecoratedProcedure,
|
|
258
|
+
): QueryType => {
|
|
259
|
+
switch (utilName) {
|
|
260
|
+
case 'fetch':
|
|
261
|
+
case 'ensureData':
|
|
262
|
+
case 'prefetch':
|
|
263
|
+
case 'getData':
|
|
264
|
+
case 'setData':
|
|
265
|
+
return 'query';
|
|
266
|
+
|
|
267
|
+
case 'fetchInfinite':
|
|
268
|
+
case 'prefetchInfinite':
|
|
269
|
+
case 'getInfiniteData':
|
|
270
|
+
case 'setInfiniteData':
|
|
271
|
+
return 'infinite';
|
|
272
|
+
|
|
273
|
+
case 'cancel':
|
|
274
|
+
case 'invalidate':
|
|
275
|
+
case 'refetch':
|
|
276
|
+
case 'reset':
|
|
277
|
+
return 'any';
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
|
|
230
281
|
/**
|
|
231
282
|
* @internal
|
|
232
283
|
*/
|
|
233
|
-
export function
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
type CreateReactUtilsProxyReturnType = CreateReactUtilsProxy<
|
|
238
|
-
TRouter,
|
|
239
|
-
TSSRContext
|
|
240
|
-
>;
|
|
284
|
+
export function createReactQueryUtils<TRouter extends AnyRouter, TSSRContext>(
|
|
285
|
+
context: TRPCContextState<AnyRouter, unknown>,
|
|
286
|
+
) {
|
|
287
|
+
type CreateReactUtilsReturnType = CreateReactUtils<TRouter, TSSRContext>;
|
|
241
288
|
|
|
242
|
-
return createFlatProxy<
|
|
289
|
+
return createFlatProxy<CreateReactUtilsReturnType>((key) => {
|
|
243
290
|
const contextName = key as (typeof contextProps)[number];
|
|
244
291
|
if (contextName === 'client') {
|
|
245
292
|
return createTRPCClientProxy(context.client);
|
|
@@ -248,53 +295,32 @@ export function createReactQueryUtilsProxy<
|
|
|
248
295
|
return context[contextName];
|
|
249
296
|
}
|
|
250
297
|
|
|
251
|
-
return createRecursiveProxy((
|
|
252
|
-
const
|
|
253
|
-
const utilName =
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
AnyDecoratedProcedure[typeof utilName]
|
|
261
|
-
>;
|
|
262
|
-
const queryKey = getQueryKeyInternal(fullPath, input);
|
|
263
|
-
return {
|
|
264
|
-
queryKey,
|
|
265
|
-
updater,
|
|
266
|
-
rest,
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
const [input, ...rest] = args as Parameters<
|
|
271
|
-
AnyDecoratedProcedure[typeof utilName]
|
|
272
|
-
>;
|
|
273
|
-
const queryKey = getQueryKeyInternal(fullPath, input);
|
|
274
|
-
return {
|
|
275
|
-
queryKey,
|
|
276
|
-
rest,
|
|
277
|
-
};
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
const { queryKey, rest, updater } = getOpts(utilName);
|
|
298
|
+
return createRecursiveProxy((opts) => {
|
|
299
|
+
const path = [key, ...opts.path];
|
|
300
|
+
const utilName = path.pop() as keyof AnyDecoratedProcedure;
|
|
301
|
+
const args = [...opts.args] as Parameters<
|
|
302
|
+
AnyDecoratedProcedure[typeof utilName]
|
|
303
|
+
>;
|
|
304
|
+
const input = args.shift(); // args can now be spread when input removed
|
|
305
|
+
const queryType = getQueryType(utilName);
|
|
306
|
+
const queryKey = getQueryKeyInternal(path, input, queryType);
|
|
281
307
|
|
|
282
308
|
const contextMap: Record<keyof AnyDecoratedProcedure, () => unknown> = {
|
|
283
|
-
fetch: () => context.fetchQuery(queryKey, ...
|
|
284
|
-
fetchInfinite: () => context.fetchInfiniteQuery(queryKey,
|
|
285
|
-
prefetch: () => context.prefetchQuery(queryKey, ...
|
|
309
|
+
fetch: () => context.fetchQuery(queryKey, ...args),
|
|
310
|
+
fetchInfinite: () => context.fetchInfiniteQuery(queryKey, args[0]),
|
|
311
|
+
prefetch: () => context.prefetchQuery(queryKey, ...args),
|
|
286
312
|
prefetchInfinite: () =>
|
|
287
|
-
context.prefetchInfiniteQuery(queryKey,
|
|
288
|
-
ensureData: () => context.ensureQueryData(queryKey, ...
|
|
289
|
-
invalidate: () => context.invalidateQueries(queryKey, ...
|
|
290
|
-
reset: () => context.resetQueries(queryKey, ...
|
|
291
|
-
refetch: () => context.refetchQueries(queryKey, ...
|
|
292
|
-
cancel: () => context.cancelQuery(queryKey, ...
|
|
313
|
+
context.prefetchInfiniteQuery(queryKey, args[0]),
|
|
314
|
+
ensureData: () => context.ensureQueryData(queryKey, ...args),
|
|
315
|
+
invalidate: () => context.invalidateQueries(queryKey, ...args),
|
|
316
|
+
reset: () => context.resetQueries(queryKey, ...args),
|
|
317
|
+
refetch: () => context.refetchQueries(queryKey, ...args),
|
|
318
|
+
cancel: () => context.cancelQuery(queryKey, ...args),
|
|
293
319
|
setData: () => {
|
|
294
|
-
context.setQueryData(queryKey,
|
|
320
|
+
context.setQueryData(queryKey, args[0], args[1]);
|
|
295
321
|
},
|
|
296
322
|
setInfiniteData: () => {
|
|
297
|
-
context.setInfiniteQueryData(queryKey,
|
|
323
|
+
context.setInfiniteQueryData(queryKey, args[0], args[1]);
|
|
298
324
|
},
|
|
299
325
|
getData: () => context.getQueryData(queryKey),
|
|
300
326
|
getInfiniteData: () => context.getInfiniteQueryData(queryKey),
|
package/src/shared/types.ts
CHANGED
|
@@ -22,13 +22,6 @@ export interface UseMutationOverride {
|
|
|
22
22
|
* @internal
|
|
23
23
|
*/
|
|
24
24
|
export interface CreateTRPCReactOptions<_TRouter extends AnyRouter> {
|
|
25
|
-
/**
|
|
26
|
-
* Override behaviors of the built-in hooks
|
|
27
|
-
* @deprecated use `overrides` instead
|
|
28
|
-
*/
|
|
29
|
-
unstable_overrides?: {
|
|
30
|
-
useMutation?: Partial<UseMutationOverride>;
|
|
31
|
-
};
|
|
32
25
|
/**
|
|
33
26
|
* Override behaviors of the built-in hooks
|
|
34
27
|
*/
|
|
@@ -47,9 +40,4 @@ export interface CreateTRPCReactOptions<_TRouter extends AnyRouter> {
|
|
|
47
40
|
* @default undefined
|
|
48
41
|
*/
|
|
49
42
|
context?: React.Context<any>;
|
|
50
|
-
/**
|
|
51
|
-
* Override the default React Query context
|
|
52
|
-
* @default undefined
|
|
53
|
-
*/
|
|
54
|
-
reactQueryContext?: React.Context<QueryClient | undefined>;
|
|
55
43
|
}
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
AnyMutationProcedure,
|
|
4
4
|
AnyProcedure,
|
|
5
5
|
AnyQueryProcedure,
|
|
6
|
+
AnyRootConfig,
|
|
6
7
|
AnyRouter,
|
|
7
8
|
inferProcedureInput,
|
|
8
9
|
} from '@trpc/server';
|
|
@@ -18,16 +19,14 @@ import {
|
|
|
18
19
|
* @internal
|
|
19
20
|
*/
|
|
20
21
|
export type InferQueryOptions<
|
|
22
|
+
TConfig extends AnyRootConfig,
|
|
21
23
|
TProcedure extends AnyProcedure,
|
|
22
|
-
|
|
23
|
-
TData = inferTransformedProcedureOutput<TProcedure>,
|
|
24
|
+
TData = inferTransformedProcedureOutput<TConfig, TProcedure>,
|
|
24
25
|
> = Omit<
|
|
25
26
|
UseTRPCQueryOptions<
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
inferTransformedProcedureOutput<TProcedure>,
|
|
30
|
-
TRPCClientErrorLike<TProcedure>,
|
|
27
|
+
inferTransformedProcedureOutput<TConfig, TProcedure>,
|
|
28
|
+
inferTransformedProcedureOutput<TConfig, TProcedure>,
|
|
29
|
+
TRPCClientErrorLike<TConfig>,
|
|
31
30
|
TData
|
|
32
31
|
>,
|
|
33
32
|
'select'
|
|
@@ -36,49 +35,48 @@ export type InferQueryOptions<
|
|
|
36
35
|
/**
|
|
37
36
|
* @internal
|
|
38
37
|
*/
|
|
39
|
-
export type InferMutationOptions<
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
export type InferMutationOptions<
|
|
39
|
+
TConfig extends AnyRootConfig,
|
|
40
|
+
TProcedure extends AnyProcedure,
|
|
41
|
+
> = UseTRPCMutationOptions<
|
|
42
|
+
inferProcedureInput<TProcedure>,
|
|
43
|
+
TRPCClientErrorLike<TConfig>,
|
|
44
|
+
inferTransformedProcedureOutput<TConfig, TProcedure>
|
|
45
|
+
>;
|
|
45
46
|
|
|
46
47
|
/**
|
|
47
48
|
* @internal
|
|
48
49
|
*/
|
|
49
|
-
export type InferQueryResult<
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
export type InferQueryResult<
|
|
51
|
+
TConfig extends AnyRootConfig,
|
|
52
|
+
TProcedure extends AnyProcedure,
|
|
53
|
+
> = UseTRPCQueryResult<
|
|
54
|
+
inferTransformedProcedureOutput<TConfig, TProcedure>,
|
|
55
|
+
TRPCClientErrorLike<TConfig>
|
|
56
|
+
>;
|
|
54
57
|
|
|
55
58
|
/**
|
|
56
59
|
* @internal
|
|
57
60
|
*/
|
|
58
61
|
export type InferMutationResult<
|
|
62
|
+
TConfig extends AnyRootConfig,
|
|
59
63
|
TProcedure extends AnyProcedure,
|
|
60
64
|
TContext = unknown,
|
|
61
65
|
> = UseTRPCMutationResult<
|
|
62
|
-
inferTransformedProcedureOutput<TProcedure>,
|
|
63
|
-
TRPCClientErrorLike<
|
|
66
|
+
inferTransformedProcedureOutput<TConfig, TProcedure>,
|
|
67
|
+
TRPCClientErrorLike<TConfig>,
|
|
64
68
|
inferProcedureInput<TProcedure>,
|
|
65
69
|
TContext
|
|
66
70
|
>;
|
|
67
71
|
|
|
68
|
-
export type inferReactQueryProcedureOptions<
|
|
69
|
-
TRouter extends AnyRouter,
|
|
70
|
-
TPath extends string = '',
|
|
71
|
-
> = {
|
|
72
|
+
export type inferReactQueryProcedureOptions<TRouter extends AnyRouter> = {
|
|
72
73
|
[TKey in keyof TRouter['_def']['record']]: TRouter['_def']['record'][TKey] extends infer TRouterOrProcedure
|
|
73
74
|
? TRouterOrProcedure extends AnyRouter
|
|
74
|
-
? inferReactQueryProcedureOptions<
|
|
75
|
-
TRouterOrProcedure,
|
|
76
|
-
`${TPath}${TKey & string}.`
|
|
77
|
-
>
|
|
75
|
+
? inferReactQueryProcedureOptions<TRouterOrProcedure>
|
|
78
76
|
: TRouterOrProcedure extends AnyMutationProcedure
|
|
79
|
-
? InferMutationOptions<TRouterOrProcedure>
|
|
77
|
+
? InferMutationOptions<TRouter['_def']['_config'], TRouterOrProcedure>
|
|
80
78
|
: TRouterOrProcedure extends AnyQueryProcedure
|
|
81
|
-
? InferQueryOptions<
|
|
79
|
+
? InferQueryOptions<TRouter['_def']['_config'], TRouterOrProcedure>
|
|
82
80
|
: never
|
|
83
81
|
: never;
|
|
84
82
|
};
|
package/dist/context-4557b3d3.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { createContext } from 'react';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* To allow easy interactions with groups of related queries, such as
|
|
5
|
-
* invalidating all queries of a router, we use an array as the path when
|
|
6
|
-
* storing in tanstack query. This function converts from the `.` separated
|
|
7
|
-
* path passed around internally by both the legacy and proxy implementation.
|
|
8
|
-
* https://github.com/trpc/trpc/issues/2611
|
|
9
|
-
**/
|
|
10
|
-
function getArrayQueryKey(queryKey, type) {
|
|
11
|
-
const queryKeyArrayed = Array.isArray(queryKey) ? queryKey : [queryKey];
|
|
12
|
-
const [path, input] = queryKeyArrayed;
|
|
13
|
-
const arrayPath = typeof path !== 'string' || path === '' ? [] : path.split('.');
|
|
14
|
-
// Construct a query key that is easy to destructure and flexible for
|
|
15
|
-
// partial selecting etc.
|
|
16
|
-
// https://github.com/trpc/trpc/issues/3128
|
|
17
|
-
if (!input && (!type || type === 'any'))
|
|
18
|
-
// for `utils.invalidate()` to match all queries (including vanilla react-query)
|
|
19
|
-
// we don't want nested array if path is empty, i.e. `[]` instead of `[[]]`
|
|
20
|
-
return arrayPath.length ? [arrayPath] : [];
|
|
21
|
-
return [
|
|
22
|
-
arrayPath,
|
|
23
|
-
{
|
|
24
|
-
...(typeof input !== 'undefined' && { input: input }),
|
|
25
|
-
...(type && type !== 'any' && { type: type }),
|
|
26
|
-
},
|
|
27
|
-
];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const contextProps = [
|
|
31
|
-
'client',
|
|
32
|
-
'ssrContext',
|
|
33
|
-
'ssrState',
|
|
34
|
-
'abortOnUnmount',
|
|
35
|
-
];
|
|
36
|
-
const TRPCContext = createContext(null);
|
|
37
|
-
|
|
38
|
-
export { TRPCContext as T, contextProps as c, getArrayQueryKey as g };
|