@trpc/react-query 10.12.0 → 10.13.0
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/context-1da55110.js +38 -0
- package/dist/{createHooksInternal-944e222b.js → createHooksInternal-a25045e3.js} +1 -1
- package/dist/createHooksInternal-b748404b.js +481 -0
- package/dist/{createHooksInternal-bea01a09.mjs → createHooksInternal-e1d567c9.mjs} +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +2 -2
- package/dist/internals/getArrayQueryKey.d.ts +8 -0
- package/dist/internals/getArrayQueryKey.d.ts.map +1 -1
- package/dist/internals/getQueryKey.d.ts +2 -1
- package/dist/internals/getQueryKey.d.ts.map +1 -1
- package/dist/queryClient-77734cc3.js +8 -0
- package/dist/shared/index.js +1 -1
- package/dist/shared/index.mjs +1 -1
- package/dist/shared/proxy/utilsProxy.d.ts +9 -4
- package/dist/shared/proxy/utilsProxy.d.ts.map +1 -1
- package/package.json +8 -7
- package/src/internals/getArrayQueryKey.ts +7 -0
- package/src/internals/getQueryKey.ts +2 -1
- package/src/shared/hooks/createHooksInternal.tsx +1 -1
- package/src/shared/proxy/utilsProxy.ts +17 -3
|
@@ -0,0 +1,38 @@
|
|
|
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 };
|
|
@@ -414,7 +414,7 @@ function getClientArgs(pathAndInput, opts) {
|
|
|
414
414
|
});
|
|
415
415
|
return hook;
|
|
416
416
|
}
|
|
417
|
-
/* istanbul ignore next */ function useSubscription(pathAndInput, opts) {
|
|
417
|
+
/* istanbul ignore next -- @preserve */ function useSubscription(pathAndInput, opts) {
|
|
418
418
|
const enabled = opts?.enabled ?? true;
|
|
419
419
|
const queryKey = reactQuery.hashQueryKey(pathAndInput);
|
|
420
420
|
const { client } = useContext();
|
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
import { createRecursiveProxy, createFlatProxy } from '@trpc/server/shared';
|
|
2
|
+
import { g as getArrayQueryKey, c as contextProps, T as TRPCContext } from './context-1da55110.js';
|
|
3
|
+
import { createTRPCClientProxy, createTRPCClient } from '@trpc/client';
|
|
4
|
+
import { useQuery, useQueryClient, useMutation, hashQueryKey, useInfiniteQuery, useQueries } from '@tanstack/react-query';
|
|
5
|
+
import React, { useRef, useState, useEffect, useCallback, useMemo } from 'react';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* We treat `undefined` as an input the same as omitting an `input`
|
|
9
|
+
* https://github.com/trpc/trpc/issues/2290
|
|
10
|
+
*/
|
|
11
|
+
function getQueryKeyInternal(path, input) {
|
|
12
|
+
if (path.length)
|
|
13
|
+
return input === undefined ? [path] : [path, input];
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Method to extract the query key for a procedure
|
|
18
|
+
* @param procedureOrRouter - procedure or AnyRouter
|
|
19
|
+
* @param input - input to procedureOrRouter
|
|
20
|
+
* @param type - defaults to `any`
|
|
21
|
+
* @link https://trpc.io/docs/getQueryKey
|
|
22
|
+
*/
|
|
23
|
+
function getQueryKey(..._params) {
|
|
24
|
+
const [procedureOrRouter, input, type] = _params;
|
|
25
|
+
// @ts-expect-error - we don't expose _def on the type layer
|
|
26
|
+
const path = procedureOrRouter._def().path;
|
|
27
|
+
const dotPath = path.join('.');
|
|
28
|
+
const queryKey = getArrayQueryKey(getQueryKeyInternal(dotPath, input), type ?? 'any');
|
|
29
|
+
return queryKey;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Create proxy for decorating procedures
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
function createReactProxyDecoration(name, hooks) {
|
|
37
|
+
return createRecursiveProxy((opts) => {
|
|
38
|
+
const args = opts.args;
|
|
39
|
+
const pathCopy = [name, ...opts.path];
|
|
40
|
+
// The last arg is for instance `.useMutation` or `.useQuery()`
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
42
|
+
const lastArg = pathCopy.pop();
|
|
43
|
+
// The `path` ends up being something like `post.byId`
|
|
44
|
+
const path = pathCopy.join('.');
|
|
45
|
+
if (lastArg === 'useMutation') {
|
|
46
|
+
return hooks[lastArg](path, ...args);
|
|
47
|
+
}
|
|
48
|
+
const [input, ...rest] = args;
|
|
49
|
+
const queryKey = getQueryKeyInternal(path, input);
|
|
50
|
+
// Expose queryKey helper
|
|
51
|
+
if (lastArg === 'getQueryKey') {
|
|
52
|
+
return getArrayQueryKey(queryKey, rest[0] ?? 'any');
|
|
53
|
+
}
|
|
54
|
+
if (lastArg === '_def') {
|
|
55
|
+
return {
|
|
56
|
+
path: pathCopy,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (lastArg.startsWith('useSuspense')) {
|
|
60
|
+
const opts = rest[0] || {};
|
|
61
|
+
const fn = lastArg === 'useSuspenseQuery' ? 'useQuery' : 'useInfiniteQuery';
|
|
62
|
+
const result = hooks[fn](queryKey, {
|
|
63
|
+
...opts,
|
|
64
|
+
suspense: true,
|
|
65
|
+
enabled: true,
|
|
66
|
+
});
|
|
67
|
+
return [result.data, result];
|
|
68
|
+
}
|
|
69
|
+
return hooks[lastArg](queryKey, ...rest);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @internal
|
|
75
|
+
*/
|
|
76
|
+
function createReactQueryUtilsProxy(context) {
|
|
77
|
+
return createFlatProxy((key) => {
|
|
78
|
+
const contextName = key;
|
|
79
|
+
if (contextName === 'client') {
|
|
80
|
+
return createTRPCClientProxy(context.client);
|
|
81
|
+
}
|
|
82
|
+
if (contextProps.includes(contextName)) {
|
|
83
|
+
return context[contextName];
|
|
84
|
+
}
|
|
85
|
+
return createRecursiveProxy(({ path, args }) => {
|
|
86
|
+
const pathCopy = [key, ...path];
|
|
87
|
+
const utilName = pathCopy.pop();
|
|
88
|
+
const fullPath = pathCopy.join('.');
|
|
89
|
+
const getOpts = (name) => {
|
|
90
|
+
if (['setData', 'setInfiniteData'].includes(name)) {
|
|
91
|
+
const [input, updater, ...rest] = args;
|
|
92
|
+
const queryKey = getQueryKeyInternal(fullPath, input);
|
|
93
|
+
return {
|
|
94
|
+
queryKey,
|
|
95
|
+
updater,
|
|
96
|
+
rest,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
const [input, ...rest] = args;
|
|
100
|
+
const queryKey = getQueryKeyInternal(fullPath, input);
|
|
101
|
+
return {
|
|
102
|
+
queryKey,
|
|
103
|
+
rest,
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
const { queryKey, rest, updater } = getOpts(utilName);
|
|
107
|
+
const contextMap = {
|
|
108
|
+
fetch: () => context.fetchQuery(queryKey, ...rest),
|
|
109
|
+
fetchInfinite: () => context.fetchInfiniteQuery(queryKey, ...rest),
|
|
110
|
+
prefetch: () => context.prefetchQuery(queryKey, ...rest),
|
|
111
|
+
prefetchInfinite: () => context.prefetchInfiniteQuery(queryKey, ...rest),
|
|
112
|
+
invalidate: () => context.invalidateQueries(queryKey, ...rest),
|
|
113
|
+
reset: () => context.resetQueries(queryKey, ...rest),
|
|
114
|
+
refetch: () => context.refetchQueries(queryKey, ...rest),
|
|
115
|
+
cancel: () => context.cancelQuery(queryKey, ...rest),
|
|
116
|
+
setData: () => context.setQueryData(queryKey, updater, ...rest),
|
|
117
|
+
setInfiniteData: () => context.setInfiniteQueryData(queryKey, updater, ...rest),
|
|
118
|
+
getData: () => context.getQueryData(queryKey),
|
|
119
|
+
getInfiniteData: () => context.getInfiniteQueryData(queryKey),
|
|
120
|
+
};
|
|
121
|
+
return contextMap[utilName]();
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Create proxy for `useQueries` options
|
|
128
|
+
* @internal
|
|
129
|
+
*/
|
|
130
|
+
function createUseQueriesProxy(client) {
|
|
131
|
+
return createRecursiveProxy((opts) => {
|
|
132
|
+
const path = opts.path.join('.');
|
|
133
|
+
const [input, ...rest] = opts.args;
|
|
134
|
+
const queryKey = getQueryKeyInternal(path, input);
|
|
135
|
+
const options = {
|
|
136
|
+
queryKey,
|
|
137
|
+
queryFn: () => {
|
|
138
|
+
return client.query(path, input);
|
|
139
|
+
},
|
|
140
|
+
...rest[0],
|
|
141
|
+
};
|
|
142
|
+
return options;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function getClientArgs(pathAndInput, opts) {
|
|
147
|
+
const [path, input] = pathAndInput;
|
|
148
|
+
return [path, input, opts?.trpc];
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Makes a stable reference of the `trpc` prop
|
|
153
|
+
*/
|
|
154
|
+
function useHookResult(value) {
|
|
155
|
+
const ref = useRef(value);
|
|
156
|
+
ref.current.path = value.path;
|
|
157
|
+
return ref.current;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
161
|
+
/**
|
|
162
|
+
* Create strongly typed react hooks
|
|
163
|
+
* @internal
|
|
164
|
+
* @deprecated
|
|
165
|
+
*/
|
|
166
|
+
function createHooksInternal(config) {
|
|
167
|
+
return createRootHooks(config);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
171
|
+
/**
|
|
172
|
+
* @internal
|
|
173
|
+
*/
|
|
174
|
+
function createRootHooks(config) {
|
|
175
|
+
const mutationSuccessOverride = config?.unstable_overrides?.useMutation?.onSuccess ??
|
|
176
|
+
((options) => options.originalFn());
|
|
177
|
+
const Context = (config?.context ??
|
|
178
|
+
TRPCContext);
|
|
179
|
+
const ReactQueryContext = config?.reactQueryContext;
|
|
180
|
+
const createClient = (opts) => {
|
|
181
|
+
return createTRPCClient(opts);
|
|
182
|
+
};
|
|
183
|
+
const TRPCProvider = (props) => {
|
|
184
|
+
const { abortOnUnmount = false, client, queryClient, ssrContext } = props;
|
|
185
|
+
const [ssrState, setSSRState] = useState(props.ssrState ?? false);
|
|
186
|
+
useEffect(() => {
|
|
187
|
+
// Only updating state to `mounted` if we are using SSR.
|
|
188
|
+
// This makes it so we don't have an unnecessary re-render when opting out of SSR.
|
|
189
|
+
setSSRState((state) => (state ? 'mounted' : false));
|
|
190
|
+
}, []);
|
|
191
|
+
return (React.createElement(Context.Provider, { value: {
|
|
192
|
+
abortOnUnmount,
|
|
193
|
+
queryClient,
|
|
194
|
+
client,
|
|
195
|
+
ssrContext: ssrContext || null,
|
|
196
|
+
ssrState,
|
|
197
|
+
fetchQuery: useCallback((pathAndInput, opts) => {
|
|
198
|
+
return queryClient.fetchQuery({
|
|
199
|
+
...opts,
|
|
200
|
+
queryKey: getArrayQueryKey(pathAndInput, 'query'),
|
|
201
|
+
queryFn: () => client.query(...getClientArgs(pathAndInput, opts)),
|
|
202
|
+
});
|
|
203
|
+
}, [client, queryClient]),
|
|
204
|
+
fetchInfiniteQuery: useCallback((pathAndInput, opts) => {
|
|
205
|
+
return queryClient.fetchInfiniteQuery({
|
|
206
|
+
...opts,
|
|
207
|
+
queryKey: getArrayQueryKey(pathAndInput, 'infinite'),
|
|
208
|
+
queryFn: ({ pageParam }) => {
|
|
209
|
+
const [path, input] = pathAndInput;
|
|
210
|
+
const actualInput = { ...input, cursor: pageParam };
|
|
211
|
+
return client.query(...getClientArgs([path, actualInput], opts));
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
}, [client, queryClient]),
|
|
215
|
+
prefetchQuery: useCallback((pathAndInput, opts) => {
|
|
216
|
+
return queryClient.prefetchQuery({
|
|
217
|
+
...opts,
|
|
218
|
+
queryKey: getArrayQueryKey(pathAndInput, 'query'),
|
|
219
|
+
queryFn: () => client.query(...getClientArgs(pathAndInput, opts)),
|
|
220
|
+
});
|
|
221
|
+
}, [client, queryClient]),
|
|
222
|
+
prefetchInfiniteQuery: useCallback((pathAndInput, opts) => {
|
|
223
|
+
return queryClient.prefetchInfiniteQuery({
|
|
224
|
+
...opts,
|
|
225
|
+
queryKey: getArrayQueryKey(pathAndInput, 'infinite'),
|
|
226
|
+
queryFn: ({ pageParam }) => {
|
|
227
|
+
const [path, input] = pathAndInput;
|
|
228
|
+
const actualInput = { ...input, cursor: pageParam };
|
|
229
|
+
return client.query(...getClientArgs([path, actualInput], opts));
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
}, [client, queryClient]),
|
|
233
|
+
invalidateQueries: useCallback((queryKey, filters, options) => {
|
|
234
|
+
return queryClient.invalidateQueries({
|
|
235
|
+
...filters,
|
|
236
|
+
queryKey: getArrayQueryKey(queryKey, 'any'),
|
|
237
|
+
}, options);
|
|
238
|
+
}, [queryClient]),
|
|
239
|
+
resetQueries: useCallback((...args) => {
|
|
240
|
+
const [queryKey, filters, options] = args;
|
|
241
|
+
return queryClient.resetQueries({
|
|
242
|
+
...filters,
|
|
243
|
+
queryKey: getArrayQueryKey(queryKey, 'any'),
|
|
244
|
+
}, options);
|
|
245
|
+
}, [queryClient]),
|
|
246
|
+
refetchQueries: useCallback((...args) => {
|
|
247
|
+
const [queryKey, filters, options] = args;
|
|
248
|
+
return queryClient.refetchQueries({
|
|
249
|
+
...filters,
|
|
250
|
+
queryKey: getArrayQueryKey(queryKey, 'any'),
|
|
251
|
+
}, options);
|
|
252
|
+
}, [queryClient]),
|
|
253
|
+
cancelQuery: useCallback((pathAndInput) => {
|
|
254
|
+
return queryClient.cancelQueries({
|
|
255
|
+
queryKey: getArrayQueryKey(pathAndInput, 'any'),
|
|
256
|
+
});
|
|
257
|
+
}, [queryClient]),
|
|
258
|
+
setQueryData: useCallback((...args) => {
|
|
259
|
+
const [queryKey, ...rest] = args;
|
|
260
|
+
return queryClient.setQueryData(getArrayQueryKey(queryKey, 'query'), ...rest);
|
|
261
|
+
}, [queryClient]),
|
|
262
|
+
getQueryData: useCallback((...args) => {
|
|
263
|
+
const [queryKey, ...rest] = args;
|
|
264
|
+
return queryClient.getQueryData(getArrayQueryKey(queryKey, 'query'), ...rest);
|
|
265
|
+
}, [queryClient]),
|
|
266
|
+
setInfiniteQueryData: useCallback((...args) => {
|
|
267
|
+
const [queryKey, ...rest] = args;
|
|
268
|
+
return queryClient.setQueryData(getArrayQueryKey(queryKey, 'infinite'), ...rest);
|
|
269
|
+
}, [queryClient]),
|
|
270
|
+
getInfiniteQueryData: useCallback((...args) => {
|
|
271
|
+
const [queryKey, ...rest] = args;
|
|
272
|
+
return queryClient.getQueryData(getArrayQueryKey(queryKey, 'infinite'), ...rest);
|
|
273
|
+
}, [queryClient]),
|
|
274
|
+
} }, props.children));
|
|
275
|
+
};
|
|
276
|
+
function useContext() {
|
|
277
|
+
return React.useContext(Context);
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Hack to make sure errors return `status`='error` when doing SSR
|
|
281
|
+
* @link https://github.com/trpc/trpc/pull/1645
|
|
282
|
+
*/
|
|
283
|
+
function useSSRQueryOptionsIfNeeded(pathAndInput, type, opts) {
|
|
284
|
+
const { queryClient, ssrState } = useContext();
|
|
285
|
+
return ssrState &&
|
|
286
|
+
ssrState !== 'mounted' &&
|
|
287
|
+
queryClient.getQueryCache().find(getArrayQueryKey(pathAndInput, type))
|
|
288
|
+
?.state.status === 'error'
|
|
289
|
+
? {
|
|
290
|
+
retryOnMount: false,
|
|
291
|
+
...opts,
|
|
292
|
+
}
|
|
293
|
+
: opts;
|
|
294
|
+
}
|
|
295
|
+
function useQuery$1(
|
|
296
|
+
// FIXME path should be a tuple in next major
|
|
297
|
+
pathAndInput, opts) {
|
|
298
|
+
const { abortOnUnmount, client, ssrState, queryClient, prefetchQuery } = useContext();
|
|
299
|
+
if (typeof window === 'undefined' &&
|
|
300
|
+
ssrState === 'prepass' &&
|
|
301
|
+
opts?.trpc?.ssr !== false &&
|
|
302
|
+
opts?.enabled !== false &&
|
|
303
|
+
!queryClient.getQueryCache().find(getArrayQueryKey(pathAndInput, 'query'))) {
|
|
304
|
+
void prefetchQuery(pathAndInput, opts);
|
|
305
|
+
}
|
|
306
|
+
const ssrOpts = useSSRQueryOptionsIfNeeded(pathAndInput, 'query', opts);
|
|
307
|
+
// request option should take priority over global
|
|
308
|
+
const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? abortOnUnmount;
|
|
309
|
+
const hook = useQuery({
|
|
310
|
+
...ssrOpts,
|
|
311
|
+
queryKey: getArrayQueryKey(pathAndInput, 'query'),
|
|
312
|
+
queryFn: (queryFunctionContext) => {
|
|
313
|
+
const actualOpts = {
|
|
314
|
+
...ssrOpts,
|
|
315
|
+
trpc: {
|
|
316
|
+
...ssrOpts?.trpc,
|
|
317
|
+
...(shouldAbortOnUnmount
|
|
318
|
+
? { signal: queryFunctionContext.signal }
|
|
319
|
+
: {}),
|
|
320
|
+
},
|
|
321
|
+
};
|
|
322
|
+
return client.query(...getClientArgs(pathAndInput, actualOpts));
|
|
323
|
+
},
|
|
324
|
+
context: ReactQueryContext,
|
|
325
|
+
});
|
|
326
|
+
hook.trpc = useHookResult({
|
|
327
|
+
path: pathAndInput[0],
|
|
328
|
+
});
|
|
329
|
+
return hook;
|
|
330
|
+
}
|
|
331
|
+
function useMutation$1(
|
|
332
|
+
// FIXME: this should only be a tuple path in next major
|
|
333
|
+
path, opts) {
|
|
334
|
+
const { client } = useContext();
|
|
335
|
+
const queryClient = useQueryClient({ context: ReactQueryContext });
|
|
336
|
+
const actualPath = Array.isArray(path) ? path[0] : path;
|
|
337
|
+
const hook = useMutation({
|
|
338
|
+
...opts,
|
|
339
|
+
mutationKey: [actualPath.split('.')],
|
|
340
|
+
mutationFn: (input) => {
|
|
341
|
+
return client.mutation(...getClientArgs([actualPath, input], opts));
|
|
342
|
+
},
|
|
343
|
+
context: ReactQueryContext,
|
|
344
|
+
onSuccess(...args) {
|
|
345
|
+
const originalFn = () => opts?.onSuccess?.(...args);
|
|
346
|
+
return mutationSuccessOverride({
|
|
347
|
+
originalFn,
|
|
348
|
+
queryClient,
|
|
349
|
+
meta: opts?.meta ?? {},
|
|
350
|
+
});
|
|
351
|
+
},
|
|
352
|
+
});
|
|
353
|
+
hook.trpc = useHookResult({
|
|
354
|
+
path: actualPath,
|
|
355
|
+
});
|
|
356
|
+
return hook;
|
|
357
|
+
}
|
|
358
|
+
/* istanbul ignore next -- @preserve */
|
|
359
|
+
function useSubscription(pathAndInput, opts) {
|
|
360
|
+
const enabled = opts?.enabled ?? true;
|
|
361
|
+
const queryKey = hashQueryKey(pathAndInput);
|
|
362
|
+
const { client } = useContext();
|
|
363
|
+
return useEffect(() => {
|
|
364
|
+
if (!enabled) {
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
const [path, input] = pathAndInput;
|
|
368
|
+
let isStopped = false;
|
|
369
|
+
const subscription = client.subscription(path, (input ?? undefined), {
|
|
370
|
+
onStarted: () => {
|
|
371
|
+
if (!isStopped) {
|
|
372
|
+
opts.onStarted?.();
|
|
373
|
+
}
|
|
374
|
+
},
|
|
375
|
+
onData: (data) => {
|
|
376
|
+
if (!isStopped) {
|
|
377
|
+
// FIXME this shouldn't be needed as both should be `unknown` in next major
|
|
378
|
+
opts.onData(data);
|
|
379
|
+
}
|
|
380
|
+
},
|
|
381
|
+
onError: (err) => {
|
|
382
|
+
if (!isStopped) {
|
|
383
|
+
opts.onError?.(err);
|
|
384
|
+
}
|
|
385
|
+
},
|
|
386
|
+
});
|
|
387
|
+
return () => {
|
|
388
|
+
isStopped = true;
|
|
389
|
+
subscription.unsubscribe();
|
|
390
|
+
};
|
|
391
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
392
|
+
}, [queryKey, enabled]);
|
|
393
|
+
}
|
|
394
|
+
function useInfiniteQuery$1(pathAndInput, opts) {
|
|
395
|
+
const [path, input] = pathAndInput;
|
|
396
|
+
const { client, ssrState, prefetchInfiniteQuery, queryClient, abortOnUnmount, } = useContext();
|
|
397
|
+
if (typeof window === 'undefined' &&
|
|
398
|
+
ssrState === 'prepass' &&
|
|
399
|
+
opts?.trpc?.ssr !== false &&
|
|
400
|
+
opts?.enabled !== false &&
|
|
401
|
+
!queryClient
|
|
402
|
+
.getQueryCache()
|
|
403
|
+
.find(getArrayQueryKey(pathAndInput, 'infinite'))) {
|
|
404
|
+
void prefetchInfiniteQuery(pathAndInput, opts);
|
|
405
|
+
}
|
|
406
|
+
const ssrOpts = useSSRQueryOptionsIfNeeded(pathAndInput, 'infinite', opts);
|
|
407
|
+
// request option should take priority over global
|
|
408
|
+
const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? abortOnUnmount;
|
|
409
|
+
const hook = useInfiniteQuery({
|
|
410
|
+
...ssrOpts,
|
|
411
|
+
queryKey: getArrayQueryKey(pathAndInput, 'infinite'),
|
|
412
|
+
queryFn: (queryFunctionContext) => {
|
|
413
|
+
const actualOpts = {
|
|
414
|
+
...ssrOpts,
|
|
415
|
+
trpc: {
|
|
416
|
+
...ssrOpts?.trpc,
|
|
417
|
+
...(shouldAbortOnUnmount
|
|
418
|
+
? { signal: queryFunctionContext.signal }
|
|
419
|
+
: {}),
|
|
420
|
+
},
|
|
421
|
+
};
|
|
422
|
+
const actualInput = {
|
|
423
|
+
...(input ?? {}),
|
|
424
|
+
cursor: queryFunctionContext.pageParam ?? opts?.initialCursor,
|
|
425
|
+
};
|
|
426
|
+
// FIXME as any shouldn't be needed as client should be untyped too
|
|
427
|
+
return client.query(...getClientArgs([path, actualInput], actualOpts));
|
|
428
|
+
},
|
|
429
|
+
context: ReactQueryContext,
|
|
430
|
+
});
|
|
431
|
+
hook.trpc = useHookResult({
|
|
432
|
+
path,
|
|
433
|
+
});
|
|
434
|
+
return hook;
|
|
435
|
+
}
|
|
436
|
+
const useQueries$1 = (queriesCallback, context) => {
|
|
437
|
+
const { ssrState, queryClient, prefetchQuery, client } = useContext();
|
|
438
|
+
const proxy = createUseQueriesProxy(client);
|
|
439
|
+
const queries = queriesCallback(proxy);
|
|
440
|
+
if (typeof window === 'undefined' && ssrState === 'prepass') {
|
|
441
|
+
for (const query of queries) {
|
|
442
|
+
const queryOption = query;
|
|
443
|
+
if (queryOption.trpc?.ssr !== false &&
|
|
444
|
+
!queryClient
|
|
445
|
+
.getQueryCache()
|
|
446
|
+
.find(getArrayQueryKey(queryOption.queryKey, 'query'))) {
|
|
447
|
+
void prefetchQuery(queryOption.queryKey, queryOption);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
return useQueries({
|
|
452
|
+
queries: queries.map((query) => ({
|
|
453
|
+
...query,
|
|
454
|
+
queryKey: getArrayQueryKey(query.queryKey, 'query'),
|
|
455
|
+
})),
|
|
456
|
+
context,
|
|
457
|
+
});
|
|
458
|
+
};
|
|
459
|
+
const useDehydratedState = (client, trpcState) => {
|
|
460
|
+
const transformed = useMemo(() => {
|
|
461
|
+
if (!trpcState) {
|
|
462
|
+
return trpcState;
|
|
463
|
+
}
|
|
464
|
+
return client.runtime.transformer.deserialize(trpcState);
|
|
465
|
+
}, [trpcState, client]);
|
|
466
|
+
return transformed;
|
|
467
|
+
};
|
|
468
|
+
return {
|
|
469
|
+
Provider: TRPCProvider,
|
|
470
|
+
createClient,
|
|
471
|
+
useContext,
|
|
472
|
+
useQuery: useQuery$1,
|
|
473
|
+
useQueries: useQueries$1,
|
|
474
|
+
useMutation: useMutation$1,
|
|
475
|
+
useSubscription,
|
|
476
|
+
useDehydratedState,
|
|
477
|
+
useInfiniteQuery: useInfiniteQuery$1,
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
export { createReactQueryUtilsProxy as a, createReactProxyDecoration as b, createHooksInternal as c, getClientArgs as d, createUseQueriesProxy as e, createRootHooks as f, getQueryKey as g };
|
|
@@ -408,7 +408,7 @@ function getClientArgs(pathAndInput, opts) {
|
|
|
408
408
|
});
|
|
409
409
|
return hook;
|
|
410
410
|
}
|
|
411
|
-
/* istanbul ignore next */ function useSubscription(pathAndInput, opts) {
|
|
411
|
+
/* istanbul ignore next -- @preserve */ function useSubscription(pathAndInput, opts) {
|
|
412
412
|
const enabled = opts?.enabled ?? true;
|
|
413
413
|
const queryKey = hashQueryKey(pathAndInput);
|
|
414
414
|
const { client } = useContext();
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var client = require('@trpc/client');
|
|
6
|
-
var createHooksInternal = require('./createHooksInternal-
|
|
6
|
+
var createHooksInternal = require('./createHooksInternal-a25045e3.js');
|
|
7
7
|
var shared = require('@trpc/server/shared');
|
|
8
8
|
var React = require('react');
|
|
9
9
|
require('@tanstack/react-query');
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from '@trpc/client';
|
|
2
|
-
import { c as createHooksInternal, a as createReactQueryUtilsProxy, b as createReactProxyDecoration } from './createHooksInternal-
|
|
3
|
-
export { g as getQueryKey } from './createHooksInternal-
|
|
2
|
+
import { c as createHooksInternal, a as createReactQueryUtilsProxy, b as createReactProxyDecoration } from './createHooksInternal-e1d567c9.mjs';
|
|
3
|
+
export { g as getQueryKey } from './createHooksInternal-e1d567c9.mjs';
|
|
4
4
|
import { createFlatProxy } from '@trpc/server/shared';
|
|
5
5
|
import { useMemo } from 'react';
|
|
6
6
|
import '@tanstack/react-query';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { GetQueryProcedureInput } from './getQueryKey';
|
|
1
2
|
export declare type QueryType = 'query' | 'infinite' | 'any';
|
|
2
3
|
export declare type QueryKey = [
|
|
3
4
|
string[],
|
|
@@ -6,6 +7,13 @@ export declare type QueryKey = [
|
|
|
6
7
|
type?: Exclude<QueryType, 'any'>;
|
|
7
8
|
}?
|
|
8
9
|
];
|
|
10
|
+
export declare type QueryKeyKnown<TInput, TType extends Exclude<QueryType, 'any'>> = [
|
|
11
|
+
string[],
|
|
12
|
+
{
|
|
13
|
+
input?: GetQueryProcedureInput<TInput>;
|
|
14
|
+
type: TType;
|
|
15
|
+
}?
|
|
16
|
+
];
|
|
9
17
|
/**
|
|
10
18
|
* To allow easy interactions with groups of related queries, such as
|
|
11
19
|
* invalidating all queries of a router, we use an array as the path when
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getArrayQueryKey.d.ts","sourceRoot":"","sources":["../../src/internals/getArrayQueryKey.ts"],"names":[],"mappings":"AAAA,oBAAY,SAAS,GAAG,OAAO,GAAG,UAAU,GAAG,KAAK,CAAC;AAErD,oBAAY,QAAQ,GAAG;IACrB,MAAM,EAAE;IACR;QAAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;KAAE,CAAC;CACvD,CAAC;AAEF;;;;;;IAMI;AACJ,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,EAAE,EAChE,IAAI,EAAE,SAAS,GACd,QAAQ,CAqBV"}
|
|
1
|
+
{"version":3,"file":"getArrayQueryKey.d.ts","sourceRoot":"","sources":["../../src/internals/getArrayQueryKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAEvD,oBAAY,SAAS,GAAG,OAAO,GAAG,UAAU,GAAG,KAAK,CAAC;AAErD,oBAAY,QAAQ,GAAG;IACrB,MAAM,EAAE;IACR;QAAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;KAAE,CAAC;CACvD,CAAC;AAEF,oBAAY,aAAa,CAAC,MAAM,EAAE,KAAK,SAAS,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI;IAC3E,MAAM,EAAE;IACR;QAAE,KAAK,CAAC,EAAE,sBAAsB,CAAC,MAAM,CAAC,CAAC;QAAC,IAAI,EAAE,KAAK,CAAA;KAAE,CAAC;CACzD,CAAC;AAEF;;;;;;IAMI;AACJ,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,EAAE,EAChE,IAAI,EAAE,SAAS,GACd,QAAQ,CAqBV"}
|
|
@@ -7,7 +7,8 @@ import { DecorateProcedure, DecoratedProcedureRecord } from '../shared';
|
|
|
7
7
|
*/
|
|
8
8
|
export declare function getQueryKeyInternal(path: string, input: unknown): [string] | [string, unknown];
|
|
9
9
|
declare type GetInfiniteQueryInput<TProcedureInput, TInputWithoutCursor = Omit<TProcedureInput, 'cursor'>> = keyof TInputWithoutCursor extends never ? undefined : DeepPartial<TInputWithoutCursor> | undefined;
|
|
10
|
-
|
|
10
|
+
/** @internal */
|
|
11
|
+
export declare type GetQueryProcedureInput<TProcedureInput> = TProcedureInput extends {
|
|
11
12
|
cursor?: any;
|
|
12
13
|
} ? GetInfiniteQueryInput<TProcedureInput> : DeepPartial<TProcedureInput> | undefined;
|
|
13
14
|
declare type GetQueryParams<TProcedureOrRouter extends AnyQueryProcedure, TProcedureInput = inferProcedureInput<TProcedureOrRouter>> = TProcedureInput extends undefined ? [] : [input?: GetQueryProcedureInput<TProcedureInput>, type?: QueryType];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getQueryKey.d.ts","sourceRoot":"","sources":["../../src/internals/getQueryKey.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,SAAS,EACT,WAAW,EACX,mBAAmB,EACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,SAAS,EAAoB,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAExE;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,GACb,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAG9B;AAED,aAAK,qBAAqB,CACxB,eAAe,EACf,mBAAmB,GAAG,IAAI,CAAC,eAAe,EAAE,QA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ACpB,SAAS,EACb,KAAK,SAAS,MAAM,EACpB,MAAM,IACJ,kBAAkB,SAAS,iBAAiB,GAC5C;IACE,iBAAiB,EAAE,iBAAiB,CAAC,kBAAkB,EAAE,MAAM,EAAE,KAAK,CAAC;IACvE,GAAG,OAAO,EAAE,cAAc,CAAC,kBAAkB,CAAC;CAC/C,GACD,kBAAkB,SAAS,oBAAoB,GAC/C,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,kBAAkB,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,GACzE;IACE,iBAAiB,EAAE,wBAAwB,CACzC,kBAAkB,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,EACpC,MAAM,EACN,GAAG,CACJ;CACF,CAAC;AAEN,aAAK,iBAAiB,CACpB,kBAAkB,SACd,iBAAiB,GACjB,oBAAoB,GACpB,SAAS,EACb,KAAK,SAAS,MAAM,EACpB,MAAM,IACJ,SAAS,CAAC,kBAAkB,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAEjD;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,kBAAkB,SACd,iBAAiB,GACjB,oBAAoB,GACpB,SAAS,EACb,KAAK,SAAS,MAAM,EACpB,MAAM,EACN,GAAG,OAAO,EAAE,iBAAiB,CAAC,kBAAkB,EAAE,KAAK,EAAE,MAAM,CAAC,oDAUjE"}
|
package/dist/shared/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var createHooksInternal = require('../createHooksInternal-
|
|
5
|
+
var createHooksInternal = require('../createHooksInternal-a25045e3.js');
|
|
6
6
|
var queryClient = require('../queryClient-358a9a75.js');
|
|
7
7
|
require('@trpc/server/shared');
|
|
8
8
|
require('../getArrayQueryKey-4bdb5cc2.js');
|
package/dist/shared/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { T as TRPCContext, h as contextProps, c as createHooksInternal, b as createReactProxyDecoration, a as createReactQueryUtilsProxy, f as createRootHooks, e as createUseQueriesProxy, d as getClientArgs } from '../createHooksInternal-
|
|
1
|
+
export { T as TRPCContext, h as contextProps, c as createHooksInternal, b as createReactProxyDecoration, a as createReactQueryUtilsProxy, f as createRootHooks, e as createUseQueriesProxy, d as getClientArgs } from '../createHooksInternal-e1d567c9.mjs';
|
|
2
2
|
export { g as getQueryClient } from '../queryClient-4d766c0c.mjs';
|
|
3
3
|
import '@trpc/server/shared';
|
|
4
4
|
import '../getArrayQueryKey-86134f8b.mjs';
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { CancelOptions, InfiniteData, InvalidateOptions, InvalidateQueryFilters, RefetchOptions, RefetchQueryFilters, ResetOptions, SetDataOptions, Updater } from '@tanstack/react-query';
|
|
1
|
+
import { CancelOptions, InfiniteData, InvalidateOptions, InvalidateQueryFilters, Query, RefetchOptions, RefetchQueryFilters, ResetOptions, SetDataOptions, Updater } from '@tanstack/react-query';
|
|
2
2
|
import { TRPCClientError } from '@trpc/client';
|
|
3
|
-
import { AnyQueryProcedure, AnyRouter, DeepPartial, Filter,
|
|
3
|
+
import { AnyQueryProcedure, AnyRouter, DeepPartial, Filter, ProtectedIntersection, inferProcedureInput } from '@trpc/server';
|
|
4
4
|
import { inferTransformedProcedureOutput } from '@trpc/server/shared';
|
|
5
5
|
import { DecoratedProxyTRPCContextProps, TRPCFetchInfiniteQueryOptions, TRPCFetchQueryOptions } from '../../internals/context';
|
|
6
6
|
import { TRPCContextState } from '../../internals/context';
|
|
7
|
+
import { QueryKeyKnown } from '../../internals/getArrayQueryKey';
|
|
7
8
|
declare type DecorateProcedure<TRouter extends AnyRouter, TProcedure extends AnyQueryProcedure> = {
|
|
8
9
|
/**
|
|
9
10
|
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientfetchquery
|
|
@@ -20,11 +21,15 @@ declare type DecorateProcedure<TRouter extends AnyRouter, TProcedure extends Any
|
|
|
20
21
|
/**
|
|
21
22
|
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientprefetchinfinitequery
|
|
22
23
|
*/
|
|
23
|
-
prefetchInfinite(input: inferProcedureInput<TProcedure>,
|
|
24
|
+
prefetchInfinite(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchInfiniteQueryOptions<inferProcedureInput<TProcedure>, TRPCClientError<TRouter>, inferTransformedProcedureOutput<TProcedure>>): Promise<void>;
|
|
24
25
|
/**
|
|
25
26
|
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientinvalidatequeries
|
|
26
27
|
*/
|
|
27
|
-
invalidate(input?: DeepPartial<inferProcedureInput<TProcedure>>, filters?: InvalidateQueryFilters,
|
|
28
|
+
invalidate(input?: DeepPartial<inferProcedureInput<TProcedure>>, filters?: Omit<InvalidateQueryFilters, 'predicate'> & {
|
|
29
|
+
predicate?: (query: Query<inferProcedureInput<TProcedure>, TRPCClientError<TRouter>, inferProcedureInput<TProcedure>, QueryKeyKnown<inferProcedureInput<TProcedure>, inferProcedureInput<TProcedure> extends {
|
|
30
|
+
cursor?: any;
|
|
31
|
+
} ? 'infinite' : 'query'>>) => boolean;
|
|
32
|
+
}, options?: InvalidateOptions): Promise<void>;
|
|
28
33
|
/**
|
|
29
34
|
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientrefetchqueries
|
|
30
35
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utilsProxy.d.ts","sourceRoot":"","sources":["../../../src/shared/proxy/utilsProxy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,sBAAsB,EACtB,cAAc,EACd,mBAAmB,EACnB,YAAY,EACZ,cAAc,EACd,OAAO,EACR,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAyB,MAAM,cAAc,CAAC;AACtE,OAAO,EACL,iBAAiB,EACjB,SAAS,EACT,WAAW,EACX,MAAM,E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AO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,IAAI,CAAC,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,oBAAY,6BAA6B,CAAC,OAAO,SAAS,SAAS,IAAI;KACpE,IAAI,IAAI,MAAM,MAAM,CACnB,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,EACzB,SAAS,GAAG,iBAAiB,CAC9B,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,GACjD,6BAA6B,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,GAC5D,cAAc,GAEhB,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC;CAChE,GAAG,cAAc,CAAC;AAInB,oBAAY,qBAAqB,CAC/B,OAAO,SAAS,SAAS,EACzB,WAAW,IACT,qBAAqB,CACvB,8BAA8B,CAAC,OAAO,EAAE,WAAW,CAAC,EACpD,6BAA6B,CAAC,OAAO,CAAC,CACvC,CAAC;AAEF;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,SAAS,SAAS,EACzB,WAAW,EACX,OAAO,EAAE,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC,uHAkE9C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/react-query",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.13.0",
|
|
4
4
|
"description": "tRPC React lib",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -57,20 +57,21 @@
|
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"@tanstack/react-query": "^4.3.8",
|
|
60
|
-
"@trpc/client": "10.
|
|
61
|
-
"@trpc/server": "10.
|
|
60
|
+
"@trpc/client": "10.13.0",
|
|
61
|
+
"@trpc/server": "10.13.0",
|
|
62
62
|
"react": ">=16.8.0",
|
|
63
63
|
"react-dom": ">=16.8.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@tanstack/react-query": "^4.3.8",
|
|
67
|
-
"@trpc/client": "10.
|
|
68
|
-
"@trpc/server": "10.
|
|
67
|
+
"@trpc/client": "10.13.0",
|
|
68
|
+
"@trpc/server": "10.13.0",
|
|
69
69
|
"@types/express": "^4.17.12",
|
|
70
70
|
"@types/node": "^18.7.20",
|
|
71
|
+
"@types/react": "^18.0.9",
|
|
71
72
|
"eslint": "^8.30.0",
|
|
72
73
|
"express": "^4.17.1",
|
|
73
|
-
"next": "^13.
|
|
74
|
+
"next": "^13.2.1",
|
|
74
75
|
"react": "^18.2.0",
|
|
75
76
|
"react-dom": "^18.2.0",
|
|
76
77
|
"rollup": "^2.79.1",
|
|
@@ -80,5 +81,5 @@
|
|
|
80
81
|
"publishConfig": {
|
|
81
82
|
"access": "public"
|
|
82
83
|
},
|
|
83
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "1214c2d1d239c6864a32c7df24651899551be8f8"
|
|
84
85
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { GetQueryProcedureInput } from './getQueryKey';
|
|
2
|
+
|
|
1
3
|
export type QueryType = 'query' | 'infinite' | 'any';
|
|
2
4
|
|
|
3
5
|
export type QueryKey = [
|
|
@@ -5,6 +7,11 @@ export type QueryKey = [
|
|
|
5
7
|
{ input?: unknown; type?: Exclude<QueryType, 'any'> }?,
|
|
6
8
|
];
|
|
7
9
|
|
|
10
|
+
export type QueryKeyKnown<TInput, TType extends Exclude<QueryType, 'any'>> = [
|
|
11
|
+
string[],
|
|
12
|
+
{ input?: GetQueryProcedureInput<TInput>; type: TType }?,
|
|
13
|
+
];
|
|
14
|
+
|
|
8
15
|
/**
|
|
9
16
|
* To allow easy interactions with groups of related queries, such as
|
|
10
17
|
* invalidating all queries of a router, we use an array as the path when
|
|
@@ -27,7 +27,8 @@ type GetInfiniteQueryInput<
|
|
|
27
27
|
? undefined
|
|
28
28
|
: DeepPartial<TInputWithoutCursor> | undefined;
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
/** @internal */
|
|
31
|
+
export type GetQueryProcedureInput<TProcedureInput> = TProcedureInput extends {
|
|
31
32
|
cursor?: any;
|
|
32
33
|
}
|
|
33
34
|
? GetInfiniteQueryInput<TProcedureInput>
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
InfiniteData,
|
|
4
4
|
InvalidateOptions,
|
|
5
5
|
InvalidateQueryFilters,
|
|
6
|
+
Query,
|
|
6
7
|
RefetchOptions,
|
|
7
8
|
RefetchQueryFilters,
|
|
8
9
|
ResetOptions,
|
|
@@ -15,7 +16,6 @@ import {
|
|
|
15
16
|
AnyRouter,
|
|
16
17
|
DeepPartial,
|
|
17
18
|
Filter,
|
|
18
|
-
ProcedureOptions,
|
|
19
19
|
ProtectedIntersection,
|
|
20
20
|
inferProcedureInput,
|
|
21
21
|
} from '@trpc/server';
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
contextProps,
|
|
32
32
|
} from '../../internals/context';
|
|
33
33
|
import { TRPCContextState } from '../../internals/context';
|
|
34
|
+
import { QueryKeyKnown } from '../../internals/getArrayQueryKey';
|
|
34
35
|
import { getQueryKeyInternal } from '../../internals/getQueryKey';
|
|
35
36
|
|
|
36
37
|
type DecorateProcedure<
|
|
@@ -78,7 +79,6 @@ type DecorateProcedure<
|
|
|
78
79
|
*/
|
|
79
80
|
prefetchInfinite(
|
|
80
81
|
input: inferProcedureInput<TProcedure>,
|
|
81
|
-
procedureOpts?: ProcedureOptions,
|
|
82
82
|
opts?: TRPCFetchInfiniteQueryOptions<
|
|
83
83
|
inferProcedureInput<TProcedure>,
|
|
84
84
|
TRPCClientError<TRouter>,
|
|
@@ -91,7 +91,21 @@ type DecorateProcedure<
|
|
|
91
91
|
*/
|
|
92
92
|
invalidate(
|
|
93
93
|
input?: DeepPartial<inferProcedureInput<TProcedure>>,
|
|
94
|
-
filters?: InvalidateQueryFilters,
|
|
94
|
+
filters?: Omit<InvalidateQueryFilters, 'predicate'> & {
|
|
95
|
+
predicate?: (
|
|
96
|
+
query: Query<
|
|
97
|
+
inferProcedureInput<TProcedure>,
|
|
98
|
+
TRPCClientError<TRouter>,
|
|
99
|
+
inferProcedureInput<TProcedure>,
|
|
100
|
+
QueryKeyKnown<
|
|
101
|
+
inferProcedureInput<TProcedure>,
|
|
102
|
+
inferProcedureInput<TProcedure> extends { cursor?: any }
|
|
103
|
+
? 'infinite'
|
|
104
|
+
: 'query'
|
|
105
|
+
>
|
|
106
|
+
>,
|
|
107
|
+
) => boolean;
|
|
108
|
+
},
|
|
95
109
|
options?: InvalidateOptions,
|
|
96
110
|
): Promise<void>;
|
|
97
111
|
|