@trpc/react-query 10.12.0 → 10.13.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/context-1da55110.js +38 -0
- package/dist/{createHooksInternal-bea01a09.mjs → createHooksInternal-416876ed.mjs} +9 -9
- package/dist/{createHooksInternal-944e222b.js → createHooksInternal-6e6e8b27.js} +9 -9
- package/dist/createHooksInternal-b290d49e.js +481 -0
- package/dist/createTRPCReact.d.ts +1 -1
- package/dist/createTRPCReact.d.ts.map +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/interop.d.ts +1 -1
- package/dist/interop.d.ts.map +1 -1
- package/dist/queryClient-77734cc3.js +8 -0
- package/dist/shared/hooks/createHooksInternal.d.ts +0 -5
- package/dist/shared/hooks/createHooksInternal.d.ts.map +1 -1
- package/dist/shared/hooks/createRootHooks.d.ts +7 -0
- package/dist/shared/hooks/createRootHooks.d.ts.map +1 -0
- package/dist/shared/index.d.ts +1 -1
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +1 -1
- package/dist/shared/index.mjs +1 -1
- package/dist/shared/proxy/decorationProxy.d.ts +1 -1
- package/dist/shared/proxy/decorationProxy.d.ts.map +1 -1
- package/dist/shared/proxy/utilsProxy.d.ts +9 -4
- package/dist/shared/proxy/utilsProxy.d.ts.map +1 -1
- package/package.json +9 -8
- package/src/createTRPCReact.tsx +1 -1
- package/src/internals/getArrayQueryKey.ts +7 -0
- package/src/internals/getQueryKey.ts +2 -1
- package/src/interop.ts +1 -1
- package/src/shared/hooks/createHooksInternal.tsx +1 -7
- package/src/shared/hooks/createRootHooks.tsx +10 -0
- package/src/shared/index.ts +1 -1
- package/src/shared/proxy/decorationProxy.ts +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 };
|
|
@@ -179,14 +179,6 @@ function getClientArgs(pathAndInput, opts) {
|
|
|
179
179
|
return ref.current;
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
-
/**
|
|
183
|
-
* Create strongly typed react hooks
|
|
184
|
-
* @internal
|
|
185
|
-
* @deprecated
|
|
186
|
-
*/ function createHooksInternal(config) {
|
|
187
|
-
return createRootHooks(config);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
182
|
/**
|
|
191
183
|
* @internal
|
|
192
184
|
*/ function createRootHooks(config) {
|
|
@@ -408,7 +400,7 @@ function getClientArgs(pathAndInput, opts) {
|
|
|
408
400
|
});
|
|
409
401
|
return hook;
|
|
410
402
|
}
|
|
411
|
-
/* istanbul ignore next */ function useSubscription(pathAndInput, opts) {
|
|
403
|
+
/* istanbul ignore next -- @preserve */ function useSubscription(pathAndInput, opts) {
|
|
412
404
|
const enabled = opts?.enabled ?? true;
|
|
413
405
|
const queryKey = hashQueryKey(pathAndInput);
|
|
414
406
|
const { client } = useContext();
|
|
@@ -530,4 +522,12 @@ function getClientArgs(pathAndInput, opts) {
|
|
|
530
522
|
};
|
|
531
523
|
}
|
|
532
524
|
|
|
525
|
+
/**
|
|
526
|
+
* Create strongly typed react hooks
|
|
527
|
+
* @internal
|
|
528
|
+
* @deprecated
|
|
529
|
+
*/ function createHooksInternal(config) {
|
|
530
|
+
return createRootHooks(config);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
533
|
export { TRPCContext as T, createReactQueryUtilsProxy as a, createReactProxyDecoration as b, createHooksInternal as c, getClientArgs as d, createUseQueriesProxy as e, createRootHooks as f, getQueryKey as g, contextProps as h };
|
|
@@ -185,14 +185,6 @@ function getClientArgs(pathAndInput, opts) {
|
|
|
185
185
|
return ref.current;
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
/**
|
|
189
|
-
* Create strongly typed react hooks
|
|
190
|
-
* @internal
|
|
191
|
-
* @deprecated
|
|
192
|
-
*/ function createHooksInternal(config) {
|
|
193
|
-
return createRootHooks(config);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
188
|
/**
|
|
197
189
|
* @internal
|
|
198
190
|
*/ function createRootHooks(config) {
|
|
@@ -414,7 +406,7 @@ function getClientArgs(pathAndInput, opts) {
|
|
|
414
406
|
});
|
|
415
407
|
return hook;
|
|
416
408
|
}
|
|
417
|
-
/* istanbul ignore next */ function useSubscription(pathAndInput, opts) {
|
|
409
|
+
/* istanbul ignore next -- @preserve */ function useSubscription(pathAndInput, opts) {
|
|
418
410
|
const enabled = opts?.enabled ?? true;
|
|
419
411
|
const queryKey = reactQuery.hashQueryKey(pathAndInput);
|
|
420
412
|
const { client } = useContext();
|
|
@@ -536,6 +528,14 @@ function getClientArgs(pathAndInput, opts) {
|
|
|
536
528
|
};
|
|
537
529
|
}
|
|
538
530
|
|
|
531
|
+
/**
|
|
532
|
+
* Create strongly typed react hooks
|
|
533
|
+
* @internal
|
|
534
|
+
* @deprecated
|
|
535
|
+
*/ function createHooksInternal(config) {
|
|
536
|
+
return createRootHooks(config);
|
|
537
|
+
}
|
|
538
|
+
|
|
539
539
|
exports.TRPCContext = TRPCContext;
|
|
540
540
|
exports.contextProps = contextProps;
|
|
541
541
|
exports.createHooksInternal = createHooksInternal;
|
|
@@ -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
|
+
* @internal
|
|
163
|
+
*/
|
|
164
|
+
function createRootHooks(config) {
|
|
165
|
+
const mutationSuccessOverride = config?.unstable_overrides?.useMutation?.onSuccess ??
|
|
166
|
+
((options) => options.originalFn());
|
|
167
|
+
const Context = (config?.context ??
|
|
168
|
+
TRPCContext);
|
|
169
|
+
const ReactQueryContext = config?.reactQueryContext;
|
|
170
|
+
const createClient = (opts) => {
|
|
171
|
+
return createTRPCClient(opts);
|
|
172
|
+
};
|
|
173
|
+
const TRPCProvider = (props) => {
|
|
174
|
+
const { abortOnUnmount = false, client, queryClient, ssrContext } = props;
|
|
175
|
+
const [ssrState, setSSRState] = useState(props.ssrState ?? false);
|
|
176
|
+
useEffect(() => {
|
|
177
|
+
// Only updating state to `mounted` if we are using SSR.
|
|
178
|
+
// This makes it so we don't have an unnecessary re-render when opting out of SSR.
|
|
179
|
+
setSSRState((state) => (state ? 'mounted' : false));
|
|
180
|
+
}, []);
|
|
181
|
+
return (React.createElement(Context.Provider, { value: {
|
|
182
|
+
abortOnUnmount,
|
|
183
|
+
queryClient,
|
|
184
|
+
client,
|
|
185
|
+
ssrContext: ssrContext || null,
|
|
186
|
+
ssrState,
|
|
187
|
+
fetchQuery: useCallback((pathAndInput, opts) => {
|
|
188
|
+
return queryClient.fetchQuery({
|
|
189
|
+
...opts,
|
|
190
|
+
queryKey: getArrayQueryKey(pathAndInput, 'query'),
|
|
191
|
+
queryFn: () => client.query(...getClientArgs(pathAndInput, opts)),
|
|
192
|
+
});
|
|
193
|
+
}, [client, queryClient]),
|
|
194
|
+
fetchInfiniteQuery: useCallback((pathAndInput, opts) => {
|
|
195
|
+
return queryClient.fetchInfiniteQuery({
|
|
196
|
+
...opts,
|
|
197
|
+
queryKey: getArrayQueryKey(pathAndInput, 'infinite'),
|
|
198
|
+
queryFn: ({ pageParam }) => {
|
|
199
|
+
const [path, input] = pathAndInput;
|
|
200
|
+
const actualInput = { ...input, cursor: pageParam };
|
|
201
|
+
return client.query(...getClientArgs([path, actualInput], opts));
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
}, [client, queryClient]),
|
|
205
|
+
prefetchQuery: useCallback((pathAndInput, opts) => {
|
|
206
|
+
return queryClient.prefetchQuery({
|
|
207
|
+
...opts,
|
|
208
|
+
queryKey: getArrayQueryKey(pathAndInput, 'query'),
|
|
209
|
+
queryFn: () => client.query(...getClientArgs(pathAndInput, opts)),
|
|
210
|
+
});
|
|
211
|
+
}, [client, queryClient]),
|
|
212
|
+
prefetchInfiniteQuery: useCallback((pathAndInput, opts) => {
|
|
213
|
+
return queryClient.prefetchInfiniteQuery({
|
|
214
|
+
...opts,
|
|
215
|
+
queryKey: getArrayQueryKey(pathAndInput, 'infinite'),
|
|
216
|
+
queryFn: ({ pageParam }) => {
|
|
217
|
+
const [path, input] = pathAndInput;
|
|
218
|
+
const actualInput = { ...input, cursor: pageParam };
|
|
219
|
+
return client.query(...getClientArgs([path, actualInput], opts));
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
}, [client, queryClient]),
|
|
223
|
+
invalidateQueries: useCallback((queryKey, filters, options) => {
|
|
224
|
+
return queryClient.invalidateQueries({
|
|
225
|
+
...filters,
|
|
226
|
+
queryKey: getArrayQueryKey(queryKey, 'any'),
|
|
227
|
+
}, options);
|
|
228
|
+
}, [queryClient]),
|
|
229
|
+
resetQueries: useCallback((...args) => {
|
|
230
|
+
const [queryKey, filters, options] = args;
|
|
231
|
+
return queryClient.resetQueries({
|
|
232
|
+
...filters,
|
|
233
|
+
queryKey: getArrayQueryKey(queryKey, 'any'),
|
|
234
|
+
}, options);
|
|
235
|
+
}, [queryClient]),
|
|
236
|
+
refetchQueries: useCallback((...args) => {
|
|
237
|
+
const [queryKey, filters, options] = args;
|
|
238
|
+
return queryClient.refetchQueries({
|
|
239
|
+
...filters,
|
|
240
|
+
queryKey: getArrayQueryKey(queryKey, 'any'),
|
|
241
|
+
}, options);
|
|
242
|
+
}, [queryClient]),
|
|
243
|
+
cancelQuery: useCallback((pathAndInput) => {
|
|
244
|
+
return queryClient.cancelQueries({
|
|
245
|
+
queryKey: getArrayQueryKey(pathAndInput, 'any'),
|
|
246
|
+
});
|
|
247
|
+
}, [queryClient]),
|
|
248
|
+
setQueryData: useCallback((...args) => {
|
|
249
|
+
const [queryKey, ...rest] = args;
|
|
250
|
+
return queryClient.setQueryData(getArrayQueryKey(queryKey, 'query'), ...rest);
|
|
251
|
+
}, [queryClient]),
|
|
252
|
+
getQueryData: useCallback((...args) => {
|
|
253
|
+
const [queryKey, ...rest] = args;
|
|
254
|
+
return queryClient.getQueryData(getArrayQueryKey(queryKey, 'query'), ...rest);
|
|
255
|
+
}, [queryClient]),
|
|
256
|
+
setInfiniteQueryData: useCallback((...args) => {
|
|
257
|
+
const [queryKey, ...rest] = args;
|
|
258
|
+
return queryClient.setQueryData(getArrayQueryKey(queryKey, 'infinite'), ...rest);
|
|
259
|
+
}, [queryClient]),
|
|
260
|
+
getInfiniteQueryData: useCallback((...args) => {
|
|
261
|
+
const [queryKey, ...rest] = args;
|
|
262
|
+
return queryClient.getQueryData(getArrayQueryKey(queryKey, 'infinite'), ...rest);
|
|
263
|
+
}, [queryClient]),
|
|
264
|
+
} }, props.children));
|
|
265
|
+
};
|
|
266
|
+
function useContext() {
|
|
267
|
+
return React.useContext(Context);
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Hack to make sure errors return `status`='error` when doing SSR
|
|
271
|
+
* @link https://github.com/trpc/trpc/pull/1645
|
|
272
|
+
*/
|
|
273
|
+
function useSSRQueryOptionsIfNeeded(pathAndInput, type, opts) {
|
|
274
|
+
const { queryClient, ssrState } = useContext();
|
|
275
|
+
return ssrState &&
|
|
276
|
+
ssrState !== 'mounted' &&
|
|
277
|
+
queryClient.getQueryCache().find(getArrayQueryKey(pathAndInput, type))
|
|
278
|
+
?.state.status === 'error'
|
|
279
|
+
? {
|
|
280
|
+
retryOnMount: false,
|
|
281
|
+
...opts,
|
|
282
|
+
}
|
|
283
|
+
: opts;
|
|
284
|
+
}
|
|
285
|
+
function useQuery$1(
|
|
286
|
+
// FIXME path should be a tuple in next major
|
|
287
|
+
pathAndInput, opts) {
|
|
288
|
+
const { abortOnUnmount, client, ssrState, queryClient, prefetchQuery } = useContext();
|
|
289
|
+
if (typeof window === 'undefined' &&
|
|
290
|
+
ssrState === 'prepass' &&
|
|
291
|
+
opts?.trpc?.ssr !== false &&
|
|
292
|
+
opts?.enabled !== false &&
|
|
293
|
+
!queryClient.getQueryCache().find(getArrayQueryKey(pathAndInput, 'query'))) {
|
|
294
|
+
void prefetchQuery(pathAndInput, opts);
|
|
295
|
+
}
|
|
296
|
+
const ssrOpts = useSSRQueryOptionsIfNeeded(pathAndInput, 'query', opts);
|
|
297
|
+
// request option should take priority over global
|
|
298
|
+
const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? abortOnUnmount;
|
|
299
|
+
const hook = useQuery({
|
|
300
|
+
...ssrOpts,
|
|
301
|
+
queryKey: getArrayQueryKey(pathAndInput, 'query'),
|
|
302
|
+
queryFn: (queryFunctionContext) => {
|
|
303
|
+
const actualOpts = {
|
|
304
|
+
...ssrOpts,
|
|
305
|
+
trpc: {
|
|
306
|
+
...ssrOpts?.trpc,
|
|
307
|
+
...(shouldAbortOnUnmount
|
|
308
|
+
? { signal: queryFunctionContext.signal }
|
|
309
|
+
: {}),
|
|
310
|
+
},
|
|
311
|
+
};
|
|
312
|
+
return client.query(...getClientArgs(pathAndInput, actualOpts));
|
|
313
|
+
},
|
|
314
|
+
context: ReactQueryContext,
|
|
315
|
+
});
|
|
316
|
+
hook.trpc = useHookResult({
|
|
317
|
+
path: pathAndInput[0],
|
|
318
|
+
});
|
|
319
|
+
return hook;
|
|
320
|
+
}
|
|
321
|
+
function useMutation$1(
|
|
322
|
+
// FIXME: this should only be a tuple path in next major
|
|
323
|
+
path, opts) {
|
|
324
|
+
const { client } = useContext();
|
|
325
|
+
const queryClient = useQueryClient({ context: ReactQueryContext });
|
|
326
|
+
const actualPath = Array.isArray(path) ? path[0] : path;
|
|
327
|
+
const hook = useMutation({
|
|
328
|
+
...opts,
|
|
329
|
+
mutationKey: [actualPath.split('.')],
|
|
330
|
+
mutationFn: (input) => {
|
|
331
|
+
return client.mutation(...getClientArgs([actualPath, input], opts));
|
|
332
|
+
},
|
|
333
|
+
context: ReactQueryContext,
|
|
334
|
+
onSuccess(...args) {
|
|
335
|
+
const originalFn = () => opts?.onSuccess?.(...args);
|
|
336
|
+
return mutationSuccessOverride({
|
|
337
|
+
originalFn,
|
|
338
|
+
queryClient,
|
|
339
|
+
meta: opts?.meta ?? {},
|
|
340
|
+
});
|
|
341
|
+
},
|
|
342
|
+
});
|
|
343
|
+
hook.trpc = useHookResult({
|
|
344
|
+
path: actualPath,
|
|
345
|
+
});
|
|
346
|
+
return hook;
|
|
347
|
+
}
|
|
348
|
+
/* istanbul ignore next -- @preserve */
|
|
349
|
+
function useSubscription(pathAndInput, opts) {
|
|
350
|
+
const enabled = opts?.enabled ?? true;
|
|
351
|
+
const queryKey = hashQueryKey(pathAndInput);
|
|
352
|
+
const { client } = useContext();
|
|
353
|
+
return useEffect(() => {
|
|
354
|
+
if (!enabled) {
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
const [path, input] = pathAndInput;
|
|
358
|
+
let isStopped = false;
|
|
359
|
+
const subscription = client.subscription(path, (input ?? undefined), {
|
|
360
|
+
onStarted: () => {
|
|
361
|
+
if (!isStopped) {
|
|
362
|
+
opts.onStarted?.();
|
|
363
|
+
}
|
|
364
|
+
},
|
|
365
|
+
onData: (data) => {
|
|
366
|
+
if (!isStopped) {
|
|
367
|
+
// FIXME this shouldn't be needed as both should be `unknown` in next major
|
|
368
|
+
opts.onData(data);
|
|
369
|
+
}
|
|
370
|
+
},
|
|
371
|
+
onError: (err) => {
|
|
372
|
+
if (!isStopped) {
|
|
373
|
+
opts.onError?.(err);
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
});
|
|
377
|
+
return () => {
|
|
378
|
+
isStopped = true;
|
|
379
|
+
subscription.unsubscribe();
|
|
380
|
+
};
|
|
381
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
382
|
+
}, [queryKey, enabled]);
|
|
383
|
+
}
|
|
384
|
+
function useInfiniteQuery$1(pathAndInput, opts) {
|
|
385
|
+
const [path, input] = pathAndInput;
|
|
386
|
+
const { client, ssrState, prefetchInfiniteQuery, queryClient, abortOnUnmount, } = useContext();
|
|
387
|
+
if (typeof window === 'undefined' &&
|
|
388
|
+
ssrState === 'prepass' &&
|
|
389
|
+
opts?.trpc?.ssr !== false &&
|
|
390
|
+
opts?.enabled !== false &&
|
|
391
|
+
!queryClient
|
|
392
|
+
.getQueryCache()
|
|
393
|
+
.find(getArrayQueryKey(pathAndInput, 'infinite'))) {
|
|
394
|
+
void prefetchInfiniteQuery(pathAndInput, opts);
|
|
395
|
+
}
|
|
396
|
+
const ssrOpts = useSSRQueryOptionsIfNeeded(pathAndInput, 'infinite', opts);
|
|
397
|
+
// request option should take priority over global
|
|
398
|
+
const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? abortOnUnmount;
|
|
399
|
+
const hook = useInfiniteQuery({
|
|
400
|
+
...ssrOpts,
|
|
401
|
+
queryKey: getArrayQueryKey(pathAndInput, 'infinite'),
|
|
402
|
+
queryFn: (queryFunctionContext) => {
|
|
403
|
+
const actualOpts = {
|
|
404
|
+
...ssrOpts,
|
|
405
|
+
trpc: {
|
|
406
|
+
...ssrOpts?.trpc,
|
|
407
|
+
...(shouldAbortOnUnmount
|
|
408
|
+
? { signal: queryFunctionContext.signal }
|
|
409
|
+
: {}),
|
|
410
|
+
},
|
|
411
|
+
};
|
|
412
|
+
const actualInput = {
|
|
413
|
+
...(input ?? {}),
|
|
414
|
+
cursor: queryFunctionContext.pageParam ?? opts?.initialCursor,
|
|
415
|
+
};
|
|
416
|
+
// FIXME as any shouldn't be needed as client should be untyped too
|
|
417
|
+
return client.query(...getClientArgs([path, actualInput], actualOpts));
|
|
418
|
+
},
|
|
419
|
+
context: ReactQueryContext,
|
|
420
|
+
});
|
|
421
|
+
hook.trpc = useHookResult({
|
|
422
|
+
path,
|
|
423
|
+
});
|
|
424
|
+
return hook;
|
|
425
|
+
}
|
|
426
|
+
const useQueries$1 = (queriesCallback, context) => {
|
|
427
|
+
const { ssrState, queryClient, prefetchQuery, client } = useContext();
|
|
428
|
+
const proxy = createUseQueriesProxy(client);
|
|
429
|
+
const queries = queriesCallback(proxy);
|
|
430
|
+
if (typeof window === 'undefined' && ssrState === 'prepass') {
|
|
431
|
+
for (const query of queries) {
|
|
432
|
+
const queryOption = query;
|
|
433
|
+
if (queryOption.trpc?.ssr !== false &&
|
|
434
|
+
!queryClient
|
|
435
|
+
.getQueryCache()
|
|
436
|
+
.find(getArrayQueryKey(queryOption.queryKey, 'query'))) {
|
|
437
|
+
void prefetchQuery(queryOption.queryKey, queryOption);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
return useQueries({
|
|
442
|
+
queries: queries.map((query) => ({
|
|
443
|
+
...query,
|
|
444
|
+
queryKey: getArrayQueryKey(query.queryKey, 'query'),
|
|
445
|
+
})),
|
|
446
|
+
context,
|
|
447
|
+
});
|
|
448
|
+
};
|
|
449
|
+
const useDehydratedState = (client, trpcState) => {
|
|
450
|
+
const transformed = useMemo(() => {
|
|
451
|
+
if (!trpcState) {
|
|
452
|
+
return trpcState;
|
|
453
|
+
}
|
|
454
|
+
return client.runtime.transformer.deserialize(trpcState);
|
|
455
|
+
}, [trpcState, client]);
|
|
456
|
+
return transformed;
|
|
457
|
+
};
|
|
458
|
+
return {
|
|
459
|
+
Provider: TRPCProvider,
|
|
460
|
+
createClient,
|
|
461
|
+
useContext,
|
|
462
|
+
useQuery: useQuery$1,
|
|
463
|
+
useQueries: useQueries$1,
|
|
464
|
+
useMutation: useMutation$1,
|
|
465
|
+
useSubscription,
|
|
466
|
+
useDehydratedState,
|
|
467
|
+
useInfiniteQuery: useInfiniteQuery$1,
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
472
|
+
/**
|
|
473
|
+
* Create strongly typed react hooks
|
|
474
|
+
* @internal
|
|
475
|
+
* @deprecated
|
|
476
|
+
*/
|
|
477
|
+
function createHooksInternal(config) {
|
|
478
|
+
return createRootHooks(config);
|
|
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 };
|
|
@@ -5,7 +5,7 @@ import { inferTransformedProcedureOutput, inferTransformedSubscriptionOutput } f
|
|
|
5
5
|
import { QueryKey, QueryType } from './internals/getArrayQueryKey';
|
|
6
6
|
import { TRPCUseQueries } from './internals/useQueries';
|
|
7
7
|
import { CreateReactUtilsProxy } from './shared';
|
|
8
|
-
import { CreateReactQueryHooks } from './shared/hooks/
|
|
8
|
+
import { CreateReactQueryHooks } from './shared/hooks/createRootHooks';
|
|
9
9
|
import { CreateClient, DefinedUseTRPCQueryOptions, DefinedUseTRPCQueryResult, TRPCProvider, UseDehydratedState, UseTRPCInfiniteQueryOptions, UseTRPCInfiniteQueryResult, UseTRPCInfiniteQuerySuccessResult, UseTRPCMutationOptions, UseTRPCMutationResult, UseTRPCQueryOptions, UseTRPCQueryResult, UseTRPCQuerySuccessResult, UseTRPCSubscriptionOptions } from './shared/hooks/types';
|
|
10
10
|
import { CreateTRPCReactOptions } from './shared/types';
|
|
11
11
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTRPCReact.d.ts","sourceRoot":"","sources":["../src/createTRPCReact.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EACL,oBAAoB,EACpB,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,wBAAwB,EACxB,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,EACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAEL,+BAA+B,EAC/B,kCAAkC,EACnC,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EACL,qBAAqB,EAGtB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,qBAAqB,EAEtB,MAAM,
|
|
1
|
+
{"version":3,"file":"createTRPCReact.d.ts","sourceRoot":"","sources":["../src/createTRPCReact.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EACL,oBAAoB,EACpB,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,wBAAwB,EACxB,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,EACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAEL,+BAA+B,EAC/B,kCAAkC,EACnC,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EACL,qBAAqB,EAGtB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,qBAAqB,EAEtB,MAAM,gCAAgC,CAAC;AACx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AEb,IAAI,CAAC,EAAE,sBAAsB,CAAC,OAAO,CAAC,GACrC,eAAe,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,CAAC,CAK/C"}
|
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-6e6e8b27.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-416876ed.mjs';
|
|
3
|
+
export { g as getQueryKey } from './createHooksInternal-416876ed.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,IA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SAAS,SAAS,GACjC,EAAE,GACF,CAAC,KAAK,CAAC,EAAE,sBAAsB,CAAC,eAAe,CAAC,EAAE,IAAI,CAAC,EAAE,SAAS,CAAC,CAAC;AAExE,aAAK,SAAS,CACZ,kBAAkB,SACd,iBAAiB,GACjB,oBAAoB,GACpB,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/interop.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AnyRouter } from '@trpc/server';
|
|
2
2
|
import { CreateTRPCReact } from './createTRPCReact';
|
|
3
3
|
import { CreateTRPCReactOptions } from './shared';
|
|
4
|
-
import { CreateReactQueryHooks } from './shared/hooks/
|
|
4
|
+
import { CreateReactQueryHooks } from './shared/hooks/createRootHooks';
|
|
5
5
|
/**
|
|
6
6
|
* @deprecated use `createTRPCReact` instead
|
|
7
7
|
*/
|
package/dist/interop.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interop.d.ts","sourceRoot":"","sources":["../src/interop.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,eAAe,EAA4B,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EACL,qBAAqB,EAEtB,MAAM,
|
|
1
|
+
{"version":3,"file":"interop.d.ts","sourceRoot":"","sources":["../src/interop.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,eAAe,EAA4B,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EACL,qBAAqB,EAEtB,MAAM,gCAAgC,CAAC;AAExC;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,SAAS,SAAS,EACzB,WAAW,GAAG,OAAO,EACrB,MAAM,GAAG,IAAI,EAEb,IAAI,CAAC,EAAE,sBAAsB,CAAC,OAAO,CAAC,GACrC,qBAAqB,CAAC,OAAO,EAAE,WAAW,CAAC,GAAG;IAC/C,KAAK,EAAE,eAAe,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;CACtD,CAQA"}
|
|
@@ -25,9 +25,4 @@ export declare function createRootHooks<TRouter extends AnyRouter, TSSRContext =
|
|
|
25
25
|
input: Record<any, unknown>
|
|
26
26
|
], opts?: UseTRPCInfiniteQueryOptions<unknown, unknown, unknown, TRPCClientErrorLike<TRouter>> | undefined) => UseTRPCInfiniteQueryResult<unknown, TRPCClientErrorLike<TRouter>>;
|
|
27
27
|
};
|
|
28
|
-
/**
|
|
29
|
-
* @deprecated
|
|
30
|
-
* DELETE ME
|
|
31
|
-
*/
|
|
32
|
-
export * from './deprecated/createHooksInternal';
|
|
33
28
|
//# sourceMappingURL=createHooksInternal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createHooksInternal.d.ts","sourceRoot":"","sources":["../../../src/shared/hooks/createHooksInternal.tsx"],"names":[],"mappings":"AAWA,OAAO,EAAE,mBAAmB,EAAoB,MAAM,cAAc,CAAC;AACrE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAI3D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,OAAO,EAAE,sBAAsB,EAAuB,MAAM,UAAU,CAAC;AACvE,OAAO,EACL,YAAY,EACZ,YAAY,EAEZ,kBAAkB,EAClB,2BAA2B,EAC3B,0BAA0B,EAC1B,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,0BAA0B,EAC3B,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,wBAAgB,eAAe,CAC7B,OAAO,SAAS,SAAS,EACzB,WAAW,GAAG,OAAO,EACrB,MAAM,CAAC,EAAE,sBAAsB,CAAC,OAAO,CAAC;;;;6BAwNxB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,CAAC;;wBAiD1C,MAAM,GAAG,CAAC,MAAM,CAAC;oCAoCT;QAEZ,IAAI,EAAE,MAAM;QACZ,GAAG,IAAI,EAAE,OAAO,EAAE;KACnB;;qCA4Ca;QAEZ,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC;KAC5B;EAqHJ
|
|
1
|
+
{"version":3,"file":"createHooksInternal.d.ts","sourceRoot":"","sources":["../../../src/shared/hooks/createHooksInternal.tsx"],"names":[],"mappings":"AAWA,OAAO,EAAE,mBAAmB,EAAoB,MAAM,cAAc,CAAC;AACrE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAI3D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,OAAO,EAAE,sBAAsB,EAAuB,MAAM,UAAU,CAAC;AACvE,OAAO,EACL,YAAY,EACZ,YAAY,EAEZ,kBAAkB,EAClB,2BAA2B,EAC3B,0BAA0B,EAC1B,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,0BAA0B,EAC3B,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,wBAAgB,eAAe,CAC7B,OAAO,SAAS,SAAS,EACzB,WAAW,GAAG,OAAO,EACrB,MAAM,CAAC,EAAE,sBAAsB,CAAC,OAAO,CAAC;;;;6BAwNxB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,CAAC;;wBAiD1C,MAAM,GAAG,CAAC,MAAM,CAAC;oCAoCT;QAEZ,IAAI,EAAE,MAAM;QACZ,GAAG,IAAI,EAAE,OAAO,EAAE;KACnB;;qCA4Ca;QAEZ,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC;KAC5B;EAqHJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRootHooks.d.ts","sourceRoot":"","sources":["../../../src/shared/hooks/createRootHooks.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD;;;GAGG;AACH,cAAc,kCAAkC,CAAC"}
|
package/dist/shared/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export * from './proxy/utilsProxy';
|
|
|
3
3
|
export * from './proxy/useQueriesProxy';
|
|
4
4
|
export type { DecoratedProcedureRecord, DecorateProcedure, } from '../createTRPCReact';
|
|
5
5
|
export type { TRPCUseQueries } from '../internals/useQueries';
|
|
6
|
-
export * from './hooks/
|
|
6
|
+
export * from './hooks/createRootHooks';
|
|
7
7
|
export * from './queryClient';
|
|
8
8
|
export * from './types';
|
|
9
9
|
export * from './hooks/types';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,YAAY,EACV,wBAAwB,EACxB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,YAAY,EACV,wBAAwB,EACxB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAE/B,OAAO;AACL;;GAEG;AACH,aAAa,GACd,MAAM,4BAA4B,CAAC;AAEpC,OAAO;AACL;;GAEG;AACH,WAAW,GACZ,MAAM,wBAAwB,CAAC;AAEhC,cAAc,sBAAsB,CAAC"}
|
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-6e6e8b27.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-416876ed.mjs';
|
|
2
2
|
export { g as getQueryClient } from '../queryClient-4d766c0c.mjs';
|
|
3
3
|
import '@trpc/server/shared';
|
|
4
4
|
import '../getArrayQueryKey-86134f8b.mjs';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorationProxy.d.ts","sourceRoot":"","sources":["../../../src/shared/proxy/decorationProxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAIzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"decorationProxy.d.ts","sourceRoot":"","sources":["../../../src/shared/proxy/decorationProxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAIzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEjE;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,SAAS,SAAS,EACzB,WAAW,GAAG,OAAO,EACrB,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,qBAAqB,CAAC,OAAO,EAAE,WAAW,CAAC,WA2CjE"}
|
|
@@ -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,EACN,
|
|
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,KAAK,EACL,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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AAS,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.1",
|
|
4
4
|
"description": "tRPC React lib",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -57,28 +57,29 @@
|
|
|
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.1",
|
|
61
|
+
"@trpc/server": "10.13.1",
|
|
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.1",
|
|
68
|
+
"@trpc/server": "10.13.1",
|
|
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",
|
|
77
|
-
"tsx": "^3.
|
|
78
|
+
"tsx": "^3.12.3",
|
|
78
79
|
"zod": "^3.0.0"
|
|
79
80
|
},
|
|
80
81
|
"publishConfig": {
|
|
81
82
|
"access": "public"
|
|
82
83
|
},
|
|
83
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "861a1f60359e1a5dffbcbfa6c0e55f4944138a25"
|
|
84
85
|
}
|
package/src/createTRPCReact.tsx
CHANGED
|
@@ -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>
|
package/src/interop.ts
CHANGED
|
@@ -340,7 +340,7 @@ export function createRootHooks<
|
|
|
340
340
|
return hook;
|
|
341
341
|
}
|
|
342
342
|
|
|
343
|
-
/* istanbul ignore next */
|
|
343
|
+
/* istanbul ignore next -- @preserve */
|
|
344
344
|
function useSubscription(
|
|
345
345
|
pathAndInput: [
|
|
346
346
|
// FIXME: tuple me in next major
|
|
@@ -512,9 +512,3 @@ export function createRootHooks<
|
|
|
512
512
|
useInfiniteQuery,
|
|
513
513
|
};
|
|
514
514
|
}
|
|
515
|
-
|
|
516
|
-
/**
|
|
517
|
-
* @deprecated
|
|
518
|
-
* DELETE ME
|
|
519
|
-
*/
|
|
520
|
-
export * from './deprecated/createHooksInternal';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// NOTE: This indirection is only needed to break a circular-reference.
|
|
2
|
+
// After removal of `hooks/deprecated/createHooksInternal` file,
|
|
3
|
+
// `hooks/createHooksInternal` can be swapped for all `createRootHooks` imports.
|
|
4
|
+
export { createRootHooks } from './createHooksInternal';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated
|
|
8
|
+
* DELETE ME
|
|
9
|
+
*/
|
|
10
|
+
export * from './deprecated/createHooksInternal';
|
package/src/shared/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ export type {
|
|
|
6
6
|
DecorateProcedure,
|
|
7
7
|
} from '../createTRPCReact';
|
|
8
8
|
export type { TRPCUseQueries } from '../internals/useQueries';
|
|
9
|
-
export * from './hooks/
|
|
9
|
+
export * from './hooks/createRootHooks';
|
|
10
10
|
export * from './queryClient';
|
|
11
11
|
export * from './types';
|
|
12
12
|
export * from './hooks/types';
|
|
@@ -2,7 +2,7 @@ import { AnyRouter } from '@trpc/server';
|
|
|
2
2
|
import { createRecursiveProxy } from '@trpc/server/shared';
|
|
3
3
|
import { getArrayQueryKey } from '../../internals/getArrayQueryKey';
|
|
4
4
|
import { getQueryKeyInternal } from '../../internals/getQueryKey';
|
|
5
|
-
import { CreateReactQueryHooks } from '../hooks/
|
|
5
|
+
import { CreateReactQueryHooks } from '../hooks/createRootHooks';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Create proxy for decorating procedures
|
|
@@ -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
|
|