@trpc/react-query 10.7.0 → 10.8.1
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/{createHooksInternal-de11647d.mjs → createHooksInternal-9c1f8ad9.mjs} +18 -9
- package/dist/{createHooksInternal-9b01c277.js → createHooksInternal-d8e5577b.js} +19 -7
- package/dist/createTRPCReact.d.ts +18 -6
- package/dist/createTRPCReact.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/internals/context.d.ts +35 -19
- package/dist/internals/context.d.ts.map +1 -1
- package/dist/internals/getClientArgs.d.ts +2 -0
- package/dist/internals/getClientArgs.d.ts.map +1 -0
- package/dist/internals/useHookResult.d.ts +10 -0
- package/dist/internals/useHookResult.d.ts.map +1 -0
- package/dist/shared/hooks/createHooksInternal.d.ts +19 -116
- package/dist/shared/hooks/createHooksInternal.d.ts.map +1 -1
- package/dist/shared/hooks/deprecated/createHooksInternal.d.ts +61 -0
- package/dist/shared/hooks/deprecated/createHooksInternal.d.ts.map +1 -0
- package/dist/shared/hooks/types.d.ts +78 -0
- package/dist/shared/hooks/types.d.ts.map +1 -0
- package/dist/shared/index.d.ts +12 -0
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +4 -1
- package/dist/shared/index.mjs +1 -1
- package/dist/shared/proxy/utilsProxy.d.ts +5 -4
- package/dist/shared/proxy/utilsProxy.d.ts.map +1 -1
- package/dist/ssg/ssgProxy.d.ts +3 -3
- package/dist/ssg/ssgProxy.d.ts.map +1 -1
- package/dist/utils/inferReactQueryProcedure.d.ts +1 -1
- package/dist/utils/inferReactQueryProcedure.d.ts.map +1 -1
- package/package.json +8 -6
- package/src/createTRPCReact.tsx +64 -21
- package/src/internals/context.tsx +53 -45
- package/src/internals/getClientArgs.ts +7 -0
- package/src/internals/useHookResult.ts +18 -0
- package/src/shared/hooks/createHooksInternal.tsx +71 -309
- package/src/shared/hooks/deprecated/createHooksInternal.tsx +628 -0
- package/src/shared/hooks/types.ts +151 -0
- package/src/shared/index.ts +17 -0
- package/src/shared/proxy/utilsProxy.ts +6 -3
- package/src/ssg/ssgProxy.ts +8 -4
- package/src/utils/inferReactQueryProcedure.ts +1 -1
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
-
CancelOptions,
|
|
3
2
|
FetchInfiniteQueryOptions,
|
|
4
3
|
FetchQueryOptions,
|
|
4
|
+
QueryClient,
|
|
5
|
+
} from '@tanstack/react-query';
|
|
6
|
+
import {
|
|
7
|
+
CancelOptions,
|
|
5
8
|
InfiniteData,
|
|
6
9
|
InvalidateOptions,
|
|
7
10
|
InvalidateQueryFilters,
|
|
8
|
-
QueryClient,
|
|
9
11
|
RefetchOptions,
|
|
10
12
|
RefetchQueryFilters,
|
|
11
13
|
ResetOptions,
|
|
@@ -15,16 +17,13 @@ import {
|
|
|
15
17
|
} from '@tanstack/react-query';
|
|
16
18
|
import {
|
|
17
19
|
TRPCClient,
|
|
18
|
-
TRPCClientError,
|
|
19
20
|
TRPCRequestOptions,
|
|
20
21
|
inferRouterProxyClient,
|
|
21
22
|
} from '@trpc/client';
|
|
22
|
-
import
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
} from '@trpc/server';
|
|
27
|
-
import type { inferTransformedProcedureOutput } from '@trpc/server/shared';
|
|
23
|
+
import { TRPCClientError } from '@trpc/client';
|
|
24
|
+
import type { AnyRouter } from '@trpc/server';
|
|
25
|
+
import { inferHandlerInput, inferProcedureInput } from '@trpc/server';
|
|
26
|
+
import { inferTransformedProcedureOutput } from '@trpc/server/shared';
|
|
28
27
|
import { createContext } from 'react';
|
|
29
28
|
|
|
30
29
|
export interface TRPCFetchQueryOptions<TInput, TError, TOutput>
|
|
@@ -64,6 +63,9 @@ export interface ProxyTRPCContextProps<TRouter extends AnyRouter, TSSRContext> {
|
|
|
64
63
|
abortOnUnmount?: boolean;
|
|
65
64
|
}
|
|
66
65
|
|
|
66
|
+
/**
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
67
69
|
export type DecoratedProxyTRPCContextProps<
|
|
68
70
|
TRouter extends AnyRouter,
|
|
69
71
|
TSSRContext,
|
|
@@ -87,6 +89,27 @@ export const contextProps: (keyof ProxyTRPCContextProps<any, any>)[] = [
|
|
|
87
89
|
];
|
|
88
90
|
|
|
89
91
|
/** @internal */
|
|
92
|
+
type TRPCContextResetQueries<TRouter extends AnyRouter> =
|
|
93
|
+
/**
|
|
94
|
+
* @link https://react-query.tanstack.com/reference/QueryClient#queryclientresetqueries
|
|
95
|
+
*/
|
|
96
|
+
(<
|
|
97
|
+
TPath extends keyof TRouter['_def']['queries'] & string,
|
|
98
|
+
TInput extends inferProcedureInput<TRouter['_def']['queries'][TPath]>,
|
|
99
|
+
>(
|
|
100
|
+
pathAndInput?: [TPath, TInput?] | TPath,
|
|
101
|
+
filters?: ResetQueryFilters,
|
|
102
|
+
options?: ResetOptions,
|
|
103
|
+
) => Promise<void>) &
|
|
104
|
+
/**
|
|
105
|
+
* @link https://react-query.tanstack.com/reference/QueryClient#queryclientresetqueries
|
|
106
|
+
*/
|
|
107
|
+
((filters?: ResetQueryFilters, options?: ResetOptions) => Promise<void>);
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @deprecated
|
|
111
|
+
* @internal
|
|
112
|
+
**/
|
|
90
113
|
export interface TRPCContextState<
|
|
91
114
|
TRouter extends AnyRouter,
|
|
92
115
|
TSSRContext = undefined,
|
|
@@ -94,7 +117,7 @@ export interface TRPCContextState<
|
|
|
94
117
|
/**
|
|
95
118
|
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientfetchquery
|
|
96
119
|
*/
|
|
97
|
-
fetchQuery<
|
|
120
|
+
fetchQuery: <
|
|
98
121
|
TPath extends keyof TRouter['_def']['queries'] & string,
|
|
99
122
|
TProcedure extends TRouter['_def']['queries'][TPath],
|
|
100
123
|
TOutput extends inferTransformedProcedureOutput<TProcedure>,
|
|
@@ -102,11 +125,11 @@ export interface TRPCContextState<
|
|
|
102
125
|
>(
|
|
103
126
|
pathAndInput: [path: TPath, ...args: inferHandlerInput<TProcedure>],
|
|
104
127
|
opts?: TRPCFetchQueryOptions<TInput, TRPCClientError<TRouter>, TOutput>,
|
|
105
|
-
)
|
|
128
|
+
) => Promise<TOutput>;
|
|
106
129
|
/**
|
|
107
130
|
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientfetchinfinitequery
|
|
108
131
|
*/
|
|
109
|
-
fetchInfiniteQuery<
|
|
132
|
+
fetchInfiniteQuery: <
|
|
110
133
|
TPath extends keyof TRouter['_def']['queries'] & string,
|
|
111
134
|
TProcedure extends TRouter['_def']['queries'][TPath],
|
|
112
135
|
TOutput extends inferTransformedProcedureOutput<TProcedure>,
|
|
@@ -118,11 +141,11 @@ export interface TRPCContextState<
|
|
|
118
141
|
TRPCClientError<TRouter>,
|
|
119
142
|
TOutput
|
|
120
143
|
>,
|
|
121
|
-
)
|
|
144
|
+
) => Promise<InfiniteData<TOutput>>;
|
|
122
145
|
/**
|
|
123
146
|
* @link https://react-query.tanstack.com/guides/prefetching
|
|
124
147
|
*/
|
|
125
|
-
prefetchQuery<
|
|
148
|
+
prefetchQuery: <
|
|
126
149
|
TPath extends keyof TRouter['_def']['queries'] & string,
|
|
127
150
|
TProcedure extends TRouter['_def']['queries'][TPath],
|
|
128
151
|
TOutput extends inferTransformedProcedureOutput<TProcedure>,
|
|
@@ -130,12 +153,12 @@ export interface TRPCContextState<
|
|
|
130
153
|
>(
|
|
131
154
|
pathAndInput: [path: TPath, ...args: inferHandlerInput<TProcedure>],
|
|
132
155
|
opts?: TRPCFetchQueryOptions<TInput, TRPCClientError<TRouter>, TOutput>,
|
|
133
|
-
)
|
|
156
|
+
) => Promise<void>;
|
|
134
157
|
|
|
135
158
|
/**
|
|
136
159
|
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientprefetchinfinitequery
|
|
137
160
|
*/
|
|
138
|
-
prefetchInfiniteQuery<
|
|
161
|
+
prefetchInfiniteQuery: <
|
|
139
162
|
TPath extends keyof TRouter['_def']['queries'] & string,
|
|
140
163
|
TProcedure extends TRouter['_def']['queries'][TPath],
|
|
141
164
|
TOutput extends inferTransformedProcedureOutput<TProcedure>,
|
|
@@ -147,39 +170,24 @@ export interface TRPCContextState<
|
|
|
147
170
|
TRPCClientError<TRouter>,
|
|
148
171
|
TOutput
|
|
149
172
|
>,
|
|
150
|
-
)
|
|
173
|
+
) => Promise<void>;
|
|
151
174
|
|
|
152
175
|
/**
|
|
153
176
|
* @link https://react-query.tanstack.com/guides/query-invalidation
|
|
154
177
|
*/
|
|
155
|
-
invalidateQueries<
|
|
178
|
+
invalidateQueries: <
|
|
156
179
|
TPath extends keyof TRouter['_def']['queries'] & string,
|
|
157
180
|
TInput extends inferProcedureInput<TRouter['_def']['queries'][TPath]>,
|
|
158
181
|
>(
|
|
159
182
|
pathAndInput?: [TPath, TInput?] | TPath,
|
|
160
183
|
filters?: InvalidateQueryFilters,
|
|
161
184
|
options?: InvalidateOptions,
|
|
162
|
-
)
|
|
185
|
+
) => Promise<void>;
|
|
163
186
|
|
|
164
187
|
/**
|
|
165
188
|
* @link https://react-query.tanstack.com/reference/QueryClient#queryclientresetqueries
|
|
166
189
|
*/
|
|
167
|
-
resetQueries<
|
|
168
|
-
TPath extends keyof TRouter['_def']['queries'] & string,
|
|
169
|
-
TInput extends inferProcedureInput<TRouter['_def']['queries'][TPath]>,
|
|
170
|
-
>(
|
|
171
|
-
pathAndInput?: [TPath, TInput?] | TPath,
|
|
172
|
-
filters?: ResetQueryFilters,
|
|
173
|
-
options?: ResetOptions,
|
|
174
|
-
): Promise<void>;
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* @link https://react-query.tanstack.com/reference/QueryClient#queryclientresetqueries
|
|
178
|
-
*/
|
|
179
|
-
resetQueries(
|
|
180
|
-
filters?: ResetQueryFilters,
|
|
181
|
-
options?: ResetOptions,
|
|
182
|
-
): Promise<void>;
|
|
190
|
+
resetQueries: TRPCContextResetQueries<TRouter>;
|
|
183
191
|
|
|
184
192
|
/**
|
|
185
193
|
* @link https://react-query.tanstack.com/reference/QueryClient#queryclientrefetchqueries
|
|
@@ -203,17 +211,17 @@ export interface TRPCContextState<
|
|
|
203
211
|
/**
|
|
204
212
|
* @link https://react-query.tanstack.com/guides/query-cancellation
|
|
205
213
|
*/
|
|
206
|
-
cancelQuery<
|
|
214
|
+
cancelQuery: <
|
|
207
215
|
TPath extends keyof TRouter['_def']['queries'] & string,
|
|
208
216
|
TInput extends inferProcedureInput<TRouter['_def']['queries'][TPath]>,
|
|
209
217
|
>(
|
|
210
218
|
pathAndInput: [TPath, TInput?],
|
|
211
219
|
options?: CancelOptions,
|
|
212
|
-
)
|
|
220
|
+
) => Promise<void>;
|
|
213
221
|
/**
|
|
214
222
|
* @link https://react-query.tanstack.com/reference/QueryClient#queryclientsetquerydata
|
|
215
223
|
*/
|
|
216
|
-
setQueryData<
|
|
224
|
+
setQueryData: <
|
|
217
225
|
TPath extends keyof TRouter['_def']['queries'] & string,
|
|
218
226
|
TInput extends inferProcedureInput<TRouter['_def']['queries'][TPath]>,
|
|
219
227
|
TOutput extends inferTransformedProcedureOutput<
|
|
@@ -223,11 +231,11 @@ export interface TRPCContextState<
|
|
|
223
231
|
pathAndInput: [TPath, TInput?],
|
|
224
232
|
updater: Updater<TOutput | undefined, TOutput | undefined>,
|
|
225
233
|
options?: SetDataOptions,
|
|
226
|
-
)
|
|
234
|
+
) => void;
|
|
227
235
|
/**
|
|
228
236
|
* @link https://react-query.tanstack.com/reference/QueryClient#queryclientgetquerydata
|
|
229
237
|
*/
|
|
230
|
-
getQueryData<
|
|
238
|
+
getQueryData: <
|
|
231
239
|
TPath extends keyof TRouter['_def']['queries'] & string,
|
|
232
240
|
TInput extends inferProcedureInput<TRouter['_def']['queries'][TPath]>,
|
|
233
241
|
TOutput extends inferTransformedProcedureOutput<
|
|
@@ -235,11 +243,11 @@ export interface TRPCContextState<
|
|
|
235
243
|
>,
|
|
236
244
|
>(
|
|
237
245
|
pathAndInput: [TPath, TInput?],
|
|
238
|
-
)
|
|
246
|
+
) => TOutput | undefined;
|
|
239
247
|
/**
|
|
240
248
|
* @link https://react-query.tanstack.com/reference/QueryClient#queryclientsetquerydata
|
|
241
249
|
*/
|
|
242
|
-
setInfiniteQueryData<
|
|
250
|
+
setInfiniteQueryData: <
|
|
243
251
|
TPath extends keyof TRouter['_def']['queries'] & string,
|
|
244
252
|
TInput extends inferProcedureInput<TRouter['_def']['queries'][TPath]>,
|
|
245
253
|
TOutput extends inferTransformedProcedureOutput<
|
|
@@ -252,11 +260,11 @@ export interface TRPCContextState<
|
|
|
252
260
|
InfiniteData<TOutput> | undefined
|
|
253
261
|
>,
|
|
254
262
|
options?: SetDataOptions,
|
|
255
|
-
)
|
|
263
|
+
) => void;
|
|
256
264
|
/**
|
|
257
265
|
* @link https://react-query.tanstack.com/reference/QueryClient#queryclientgetquerydata
|
|
258
266
|
*/
|
|
259
|
-
getInfiniteQueryData<
|
|
267
|
+
getInfiniteQueryData: <
|
|
260
268
|
TPath extends keyof TRouter['_def']['queries'] & string,
|
|
261
269
|
TInput extends inferProcedureInput<TRouter['_def']['queries'][TPath]>,
|
|
262
270
|
TOutput extends inferTransformedProcedureOutput<
|
|
@@ -264,7 +272,7 @@ export interface TRPCContextState<
|
|
|
264
272
|
>,
|
|
265
273
|
>(
|
|
266
274
|
pathAndInput: [TPath, TInput?],
|
|
267
|
-
)
|
|
275
|
+
) => InfiniteData<TOutput> | undefined;
|
|
268
276
|
}
|
|
269
277
|
|
|
270
278
|
export const TRPCContext = createContext(null as any);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface TRPCHookResult {
|
|
4
|
+
trpc: {
|
|
5
|
+
path: string;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Makes a stable reference of the `trpc` prop
|
|
11
|
+
*/
|
|
12
|
+
export function useHookResult(
|
|
13
|
+
value: TRPCHookResult['trpc'],
|
|
14
|
+
): TRPCHookResult['trpc'] {
|
|
15
|
+
const ref = useRef(value);
|
|
16
|
+
ref.current.path = value.path;
|
|
17
|
+
return ref.current;
|
|
18
|
+
}
|