@trpc/react-query 11.0.0-alpha-tmp-export-from-main.213 → 11.0.0-alpha-tmp-export-from-main.217

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.
Files changed (39) hide show
  1. package/dist/createTRPCQueryUtils.js +16 -0
  2. package/dist/createTRPCQueryUtils.mjs +14 -0
  3. package/dist/createTRPCReact.js +58 -0
  4. package/dist/createTRPCReact.mjs +36 -0
  5. package/dist/index.js +10 -64
  6. package/dist/index.mjs +3 -40
  7. package/dist/internals/context.js +33 -0
  8. package/dist/internals/context.mjs +11 -0
  9. package/dist/internals/getClientArgs.js +16 -0
  10. package/dist/internals/getClientArgs.mjs +14 -0
  11. package/dist/internals/getQueryKey.d.ts.map +1 -1
  12. package/dist/internals/getQueryKey.js +57 -0
  13. package/dist/internals/getQueryKey.mjs +54 -0
  14. package/dist/internals/useHookResult.js +32 -0
  15. package/dist/internals/useHookResult.mjs +11 -0
  16. package/dist/server/index.js +2 -102
  17. package/dist/server/index.mjs +1 -103
  18. package/dist/server/ssgProxy.js +107 -0
  19. package/dist/server/ssgProxy.mjs +105 -0
  20. package/dist/{createHooksInternal-5d2fa367.js → shared/hooks/createHooksInternal.js} +28 -183
  21. package/dist/{createHooksInternal-e0b0564e.mjs → shared/hooks/createHooksInternal.mjs} +8 -158
  22. package/dist/shared/index.js +13 -15
  23. package/dist/shared/index.mjs +7 -7
  24. package/dist/shared/proxy/decorationProxy.js +31 -0
  25. package/dist/shared/proxy/decorationProxy.mjs +29 -0
  26. package/dist/shared/proxy/useQueriesProxy.js +25 -0
  27. package/dist/shared/proxy/useQueriesProxy.mjs +23 -0
  28. package/dist/shared/proxy/utilsProxy.js +89 -0
  29. package/dist/{utilsProxy-61a4601f.mjs → shared/proxy/utilsProxy.mjs} +3 -51
  30. package/dist/{queryClient-4d766c0c.mjs → shared/queryClient.mjs} +1 -1
  31. package/dist/utils/createUtilityFunctions.js +94 -0
  32. package/dist/utils/createUtilityFunctions.mjs +92 -0
  33. package/package.json +6 -6
  34. package/src/internals/getQueryKey.ts +19 -1
  35. package/dist/createHooksInternal-4285c71a.js +0 -470
  36. package/dist/queryClient-1c8d7d8a.js +0 -8
  37. package/dist/utilsProxy-0b88c1e3.js +0 -161
  38. package/dist/utilsProxy-ff357a62.js +0 -128
  39. /package/dist/{queryClient-358a9a75.js → shared/queryClient.js} +0 -0
@@ -0,0 +1,92 @@
1
+ import { TRPCUntypedClient, getUntypedClient } from '@trpc/client';
2
+ import { getClientArgs } from '../internals/getClientArgs.mjs';
3
+
4
+ /**
5
+ * Creates a set of utility functions that can be used to interact with `react-query`
6
+ * @param opts the `TRPCClient` and `QueryClient` to use
7
+ * @returns a set of utility functions that can be used to interact with `react-query`
8
+ * @internal
9
+ */ function createUtilityFunctions(opts) {
10
+ const { client , queryClient } = opts;
11
+ const untypedClient = client instanceof TRPCUntypedClient ? client : getUntypedClient(client);
12
+ return {
13
+ fetchQuery: (queryKey, opts)=>{
14
+ return queryClient.fetchQuery({
15
+ ...opts,
16
+ queryKey,
17
+ queryFn: ()=>untypedClient.query(...getClientArgs(queryKey, opts))
18
+ });
19
+ },
20
+ fetchInfiniteQuery: (queryKey, opts)=>{
21
+ return queryClient.fetchInfiniteQuery({
22
+ ...opts,
23
+ queryKey,
24
+ queryFn: ({ pageParam })=>{
25
+ return untypedClient.query(...getClientArgs(queryKey, opts, pageParam));
26
+ },
27
+ initialPageParam: opts?.initialCursor ?? null
28
+ });
29
+ },
30
+ prefetchQuery: (queryKey, opts)=>{
31
+ return queryClient.prefetchQuery({
32
+ ...opts,
33
+ queryKey,
34
+ queryFn: ()=>untypedClient.query(...getClientArgs(queryKey, opts))
35
+ });
36
+ },
37
+ prefetchInfiniteQuery: (queryKey, opts)=>{
38
+ return queryClient.prefetchInfiniteQuery({
39
+ ...opts,
40
+ queryKey,
41
+ queryFn: ({ pageParam })=>{
42
+ return untypedClient.query(...getClientArgs(queryKey, opts, pageParam));
43
+ },
44
+ initialPageParam: opts?.initialCursor ?? null
45
+ });
46
+ },
47
+ ensureQueryData: (queryKey, opts)=>{
48
+ return queryClient.ensureQueryData({
49
+ ...opts,
50
+ queryKey,
51
+ queryFn: ()=>untypedClient.query(...getClientArgs(queryKey, opts))
52
+ });
53
+ },
54
+ invalidateQueries: (queryKey, filters, options)=>{
55
+ return queryClient.invalidateQueries({
56
+ ...filters,
57
+ queryKey
58
+ }, options);
59
+ },
60
+ resetQueries: (queryKey, filters, options)=>{
61
+ return queryClient.resetQueries({
62
+ ...filters,
63
+ queryKey
64
+ }, options);
65
+ },
66
+ refetchQueries: (queryKey, filters, options)=>{
67
+ return queryClient.refetchQueries({
68
+ ...filters,
69
+ queryKey
70
+ }, options);
71
+ },
72
+ cancelQuery: (queryKey, options)=>{
73
+ return queryClient.cancelQueries({
74
+ queryKey
75
+ }, options);
76
+ },
77
+ setQueryData: (queryKey, updater, options)=>{
78
+ return queryClient.setQueryData(queryKey, updater, options);
79
+ },
80
+ getQueryData: (queryKey)=>{
81
+ return queryClient.getQueryData(queryKey);
82
+ },
83
+ setInfiniteQueryData: (queryKey, updater, options)=>{
84
+ return queryClient.setQueryData(queryKey, updater, options);
85
+ },
86
+ getInfiniteQueryData: (queryKey)=>{
87
+ return queryClient.getQueryData(queryKey);
88
+ }
89
+ };
90
+ }
91
+
92
+ export { createUtilityFunctions };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/react-query",
3
- "version": "11.0.0-alpha-tmp-export-from-main.213+855f8bc75",
3
+ "version": "11.0.0-alpha-tmp-export-from-main.217+ef6ef3e1c",
4
4
  "description": "The tRPC React library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -72,17 +72,17 @@
72
72
  }
73
73
  },
74
74
  "dependencies": {
75
- "@trpc/core": "11.0.0-alpha-tmp-export-from-main.213+855f8bc75"
75
+ "@trpc/core": "11.0.0-alpha-tmp-export-from-main.217+ef6ef3e1c"
76
76
  },
77
77
  "peerDependencies": {
78
78
  "@tanstack/react-query": "^5.0.0",
79
- "@trpc/client": "11.0.0-alpha-tmp-export-from-main.213+855f8bc75",
79
+ "@trpc/client": "11.0.0-alpha-tmp-export-from-main.217+ef6ef3e1c",
80
80
  "react": ">=18.2.0",
81
81
  "react-dom": ">=18.2.0"
82
82
  },
83
83
  "devDependencies": {
84
84
  "@tanstack/react-query": "^5.0.0",
85
- "@trpc/client": "11.0.0-alpha-tmp-export-from-main.213+855f8bc75",
85
+ "@trpc/client": "11.0.0-alpha-tmp-export-from-main.217+ef6ef3e1c",
86
86
  "@types/express": "^4.17.17",
87
87
  "@types/node": "^20.10.0",
88
88
  "@types/react": "^18.2.33",
@@ -91,7 +91,7 @@
91
91
  "next": "^14.0.1",
92
92
  "react": "^18.2.0",
93
93
  "react-dom": "^18.2.0",
94
- "rollup": "^2.79.1",
94
+ "rollup": "^4.9.5",
95
95
  "tsx": "^4.0.0",
96
96
  "zod": "^3.0.0"
97
97
  },
@@ -101,5 +101,5 @@
101
101
  "funding": [
102
102
  "https://trpc.io/sponsor"
103
103
  ],
104
- "gitHead": "855f8bc75d6f11780eabf92376c6297f9edf6107"
104
+ "gitHead": "ef6ef3e1c3a4966d30335864d6edf9c94f096717"
105
105
  }
@@ -32,10 +32,28 @@ export function getQueryKeyInternal(
32
32
  // some parts of the path may be dot-separated, split them up
33
33
  const splitPath = path.flatMap((part) => part.split('.'));
34
34
 
35
- if (!input && (!type || type === 'any'))
35
+ if (!input && (!type || type === 'any')) {
36
36
  // for `utils.invalidate()` to match all queries (including vanilla react-query)
37
37
  // we don't want nested array if path is empty, i.e. `[]` instead of `[[]]`
38
38
  return splitPath.length ? [splitPath] : ([] as unknown as TRPCQueryKey);
39
+ }
40
+
41
+ if (
42
+ type === 'infinite' &&
43
+ input &&
44
+ typeof input === 'object' &&
45
+ 'cursor' in input
46
+ ) {
47
+ const { cursor: _, ...inputWithoutCursor } = input;
48
+
49
+ return [
50
+ splitPath,
51
+ {
52
+ input: inputWithoutCursor,
53
+ type: 'infinite',
54
+ },
55
+ ];
56
+ }
39
57
  return [
40
58
  splitPath,
41
59
  {
@@ -1,470 +0,0 @@
1
- import { createRecursiveProxy } from '@trpc/core';
2
- import { useQuery, useSuspenseQuery, useQueryClient, useMutation, hashKey, useInfiniteQuery, useSuspenseInfiniteQuery, useQueries, useSuspenseQueries } from '@tanstack/react-query';
3
- import { TRPCUntypedClient, getUntypedClient, createTRPCUntypedClient } from '@trpc/client';
4
- import * as React from 'react';
5
- import { b as getQueryKeyInternal, T as TRPCContext } from './utilsProxy-ff357a62.js';
6
-
7
- /**
8
- * Create proxy for decorating procedures
9
- * @internal
10
- */
11
- function createReactDecoration(name, hooks) {
12
- return createRecursiveProxy(({ path, args }) => {
13
- const pathCopy = [name, ...path];
14
- // The last arg is for instance `.useMutation` or `.useQuery()`
15
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
16
- const lastArg = pathCopy.pop();
17
- if (lastArg === 'useMutation') {
18
- return hooks[lastArg](pathCopy, ...args);
19
- }
20
- if (lastArg === '_def') {
21
- return {
22
- path: pathCopy,
23
- };
24
- }
25
- const [input, ...rest] = args;
26
- const opts = rest[0] || {};
27
- return hooks[lastArg](pathCopy, input, opts);
28
- });
29
- }
30
-
31
- /**
32
- * Create proxy for `useQueries` options
33
- * @internal
34
- */
35
- function createUseQueries(client) {
36
- return createRecursiveProxy((opts) => {
37
- const arrayPath = opts.path;
38
- const dotPath = arrayPath.join('.');
39
- const [input, _opts] = opts.args;
40
- const options = {
41
- queryKey: getQueryKeyInternal(arrayPath, input, 'query'),
42
- queryFn: () => {
43
- return client.query(dotPath, input, _opts?.trpc);
44
- },
45
- ..._opts,
46
- };
47
- return options;
48
- });
49
- }
50
-
51
- /**
52
- * @internal
53
- */
54
- function getClientArgs(queryKey, opts, pageParam) {
55
- const path = queryKey[0];
56
- const input = queryKey[1]?.input;
57
- if (pageParam)
58
- input.cursor = pageParam;
59
- return [path.join('.'), input, opts?.trpc];
60
- }
61
-
62
- /**
63
- * Makes a stable reference of the `trpc` prop
64
- */
65
- function useHookResult(value) {
66
- const ref = React.useRef(value);
67
- ref.current.path = value.path;
68
- return ref.current;
69
- }
70
-
71
- /**
72
- * Creates a set of utility functions that can be used to interact with `react-query`
73
- * @param opts the `TRPCClient` and `QueryClient` to use
74
- * @returns a set of utility functions that can be used to interact with `react-query`
75
- * @internal
76
- */
77
- function createUtilityFunctions(opts) {
78
- const { client, queryClient } = opts;
79
- const untypedClient = client instanceof TRPCUntypedClient ? client : getUntypedClient(client);
80
- return {
81
- fetchQuery: (queryKey, opts) => {
82
- return queryClient.fetchQuery({
83
- ...opts,
84
- queryKey,
85
- queryFn: () => untypedClient.query(...getClientArgs(queryKey, opts)),
86
- });
87
- },
88
- fetchInfiniteQuery: (queryKey, opts) => {
89
- return queryClient.fetchInfiniteQuery({
90
- ...opts,
91
- queryKey,
92
- queryFn: ({ pageParam }) => {
93
- return untypedClient.query(...getClientArgs(queryKey, opts, pageParam));
94
- },
95
- initialPageParam: opts?.initialCursor ?? null,
96
- });
97
- },
98
- prefetchQuery: (queryKey, opts) => {
99
- return queryClient.prefetchQuery({
100
- ...opts,
101
- queryKey,
102
- queryFn: () => untypedClient.query(...getClientArgs(queryKey, opts)),
103
- });
104
- },
105
- prefetchInfiniteQuery: (queryKey, opts) => {
106
- return queryClient.prefetchInfiniteQuery({
107
- ...opts,
108
- queryKey,
109
- queryFn: ({ pageParam }) => {
110
- return untypedClient.query(...getClientArgs(queryKey, opts, pageParam));
111
- },
112
- initialPageParam: opts?.initialCursor ?? null,
113
- });
114
- },
115
- ensureQueryData: (queryKey, opts) => {
116
- return queryClient.ensureQueryData({
117
- ...opts,
118
- queryKey,
119
- queryFn: () => untypedClient.query(...getClientArgs(queryKey, opts)),
120
- });
121
- },
122
- invalidateQueries: (queryKey, filters, options) => {
123
- return queryClient.invalidateQueries({
124
- ...filters,
125
- queryKey,
126
- }, options);
127
- },
128
- resetQueries: (queryKey, filters, options) => {
129
- return queryClient.resetQueries({
130
- ...filters,
131
- queryKey,
132
- }, options);
133
- },
134
- refetchQueries: (queryKey, filters, options) => {
135
- return queryClient.refetchQueries({
136
- ...filters,
137
- queryKey,
138
- }, options);
139
- },
140
- cancelQuery: (queryKey, options) => {
141
- return queryClient.cancelQueries({
142
- queryKey,
143
- }, options);
144
- },
145
- setQueryData: (queryKey, updater, options) => {
146
- return queryClient.setQueryData(queryKey, updater, options);
147
- },
148
- getQueryData: (queryKey) => {
149
- return queryClient.getQueryData(queryKey);
150
- },
151
- setInfiniteQueryData: (queryKey, updater, options) => {
152
- return queryClient.setQueryData(queryKey, updater, options);
153
- },
154
- getInfiniteQueryData: (queryKey) => {
155
- return queryClient.getQueryData(queryKey);
156
- },
157
- };
158
- }
159
-
160
- /**
161
- * @internal
162
- */
163
- function createRootHooks(config) {
164
- const mutationSuccessOverride = config?.overrides?.useMutation?.onSuccess ??
165
- ((options) => options.originalFn());
166
- const Context = (config?.context ??
167
- TRPCContext);
168
- const createClient = (opts) => {
169
- return createTRPCUntypedClient(opts);
170
- };
171
- const TRPCProvider = (props) => {
172
- const { abortOnUnmount = false, client, queryClient, ssrContext } = props;
173
- const [ssrState, setSSRState] = React.useState(props.ssrState ?? false);
174
- const fns = React.useMemo(() => createUtilityFunctions({
175
- client,
176
- queryClient,
177
- }), [client, queryClient]);
178
- const contextValue = React.useMemo(() => ({
179
- abortOnUnmount,
180
- queryClient,
181
- client,
182
- ssrContext: ssrContext ?? null,
183
- ssrState,
184
- ...fns,
185
- }), [abortOnUnmount, client, fns, queryClient, ssrContext, ssrState]);
186
- React.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: contextValue }, props.children));
192
- };
193
- function useContext() {
194
- const context = React.useContext(Context);
195
- if (!context) {
196
- throw new Error('Unable to find tRPC Context. Did you forget to wrap your App inside `withTRPC` HoC?');
197
- }
198
- return context;
199
- }
200
- /**
201
- * Hack to make sure errors return `status`='error` when doing SSR
202
- * @link https://github.com/trpc/trpc/pull/1645
203
- */
204
- function useSSRQueryOptionsIfNeeded(queryKey, opts) {
205
- const { queryClient, ssrState } = useContext();
206
- return ssrState &&
207
- ssrState !== 'mounted' &&
208
- queryClient.getQueryCache().find({ queryKey })?.state.status === 'error'
209
- ? {
210
- retryOnMount: false,
211
- ...opts,
212
- }
213
- : opts;
214
- }
215
- function useQuery$1(path, input, opts) {
216
- const context = useContext();
217
- const { abortOnUnmount, client, ssrState, queryClient, prefetchQuery } = context;
218
- const queryKey = getQueryKeyInternal(path, input, 'query');
219
- const defaultOpts = queryClient.getQueryDefaults(queryKey);
220
- if (typeof window === 'undefined' &&
221
- ssrState === 'prepass' &&
222
- opts?.trpc?.ssr !== false &&
223
- (opts?.enabled ?? defaultOpts?.enabled) !== false &&
224
- !queryClient.getQueryCache().find({ queryKey })) {
225
- void prefetchQuery(queryKey, opts);
226
- }
227
- const ssrOpts = useSSRQueryOptionsIfNeeded(queryKey, {
228
- ...defaultOpts,
229
- ...opts,
230
- });
231
- const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? config?.abortOnUnmount ?? abortOnUnmount;
232
- const hook = useQuery({
233
- ...ssrOpts,
234
- queryKey: queryKey,
235
- queryFn: (queryFunctionContext) => {
236
- const actualOpts = {
237
- ...ssrOpts,
238
- trpc: {
239
- ...ssrOpts?.trpc,
240
- ...(shouldAbortOnUnmount
241
- ? { signal: queryFunctionContext.signal }
242
- : {}),
243
- },
244
- };
245
- return client.query(...getClientArgs(queryKey, actualOpts));
246
- },
247
- }, queryClient);
248
- hook.trpc = useHookResult({
249
- path: path.join('.'),
250
- });
251
- return hook;
252
- }
253
- function useSuspenseQuery$1(path, input, opts) {
254
- const context = useContext();
255
- const queryKey = getQueryKeyInternal(path, input, 'query');
256
- const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ??
257
- config?.abortOnUnmount ??
258
- context.abortOnUnmount;
259
- const hook = useSuspenseQuery({
260
- ...opts,
261
- queryKey: queryKey,
262
- queryFn: (queryFunctionContext) => {
263
- const actualOpts = {
264
- trpc: {
265
- ...(shouldAbortOnUnmount
266
- ? { signal: queryFunctionContext.signal }
267
- : {}),
268
- },
269
- };
270
- return context.client.query(...getClientArgs(queryKey, actualOpts));
271
- },
272
- }, context.queryClient);
273
- hook.trpc = useHookResult({
274
- path: path.join('.'),
275
- });
276
- return [hook.data, hook];
277
- }
278
- function useMutation$1(path, opts) {
279
- const { client } = useContext();
280
- const queryClient = useQueryClient();
281
- const mutationKey = [path];
282
- const defaultOpts = queryClient.getMutationDefaults(mutationKey);
283
- const hook = useMutation({
284
- ...opts,
285
- mutationKey: mutationKey,
286
- mutationFn: (input) => {
287
- return client.mutation(...getClientArgs([path, { input }], opts));
288
- },
289
- onSuccess(...args) {
290
- const originalFn = () => opts?.onSuccess?.(...args) ?? defaultOpts?.onSuccess?.(...args);
291
- return mutationSuccessOverride({
292
- originalFn,
293
- queryClient,
294
- meta: opts?.meta ?? defaultOpts?.meta ?? {},
295
- });
296
- },
297
- }, queryClient);
298
- hook.trpc = useHookResult({
299
- path: path.join('.'),
300
- });
301
- return hook;
302
- }
303
- /* istanbul ignore next -- @preserve */
304
- function useSubscription(path, input, opts) {
305
- const enabled = opts?.enabled ?? true;
306
- const queryKey = hashKey(getQueryKeyInternal(path, input, 'any'));
307
- const { client } = useContext();
308
- const optsRef = React.useRef(opts);
309
- optsRef.current = opts;
310
- React.useEffect(() => {
311
- if (!enabled) {
312
- return;
313
- }
314
- let isStopped = false;
315
- const subscription = client.subscription(path.join('.'), input ?? undefined, {
316
- onStarted: () => {
317
- if (!isStopped) {
318
- optsRef.current.onStarted?.();
319
- }
320
- },
321
- onData: (data) => {
322
- if (!isStopped) {
323
- opts.onData(data);
324
- }
325
- },
326
- onError: (err) => {
327
- if (!isStopped) {
328
- optsRef.current.onError?.(err);
329
- }
330
- },
331
- });
332
- return () => {
333
- isStopped = true;
334
- subscription.unsubscribe();
335
- };
336
- // eslint-disable-next-line react-hooks/exhaustive-deps
337
- }, [queryKey, enabled]);
338
- }
339
- function useInfiniteQuery$1(path, input, opts) {
340
- const { client, ssrState, prefetchInfiniteQuery, queryClient, abortOnUnmount, } = useContext();
341
- const queryKey = getQueryKeyInternal(path, input, 'infinite');
342
- const defaultOpts = queryClient.getQueryDefaults(queryKey);
343
- if (typeof window === 'undefined' &&
344
- ssrState === 'prepass' &&
345
- opts?.trpc?.ssr !== false &&
346
- (opts?.enabled ?? defaultOpts?.enabled) !== false &&
347
- !queryClient.getQueryCache().find({ queryKey })) {
348
- void prefetchInfiniteQuery(queryKey, { ...defaultOpts, ...opts });
349
- }
350
- const ssrOpts = useSSRQueryOptionsIfNeeded(queryKey, {
351
- ...defaultOpts,
352
- ...opts,
353
- });
354
- // request option should take priority over global
355
- const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? abortOnUnmount;
356
- const hook = useInfiniteQuery({
357
- ...ssrOpts,
358
- initialPageParam: opts.initialCursor ?? null,
359
- persister: opts.persister,
360
- queryKey: queryKey,
361
- queryFn: (queryFunctionContext) => {
362
- const actualOpts = {
363
- ...ssrOpts,
364
- trpc: {
365
- ...ssrOpts?.trpc,
366
- ...(shouldAbortOnUnmount
367
- ? { signal: queryFunctionContext.signal }
368
- : {}),
369
- },
370
- };
371
- return client.query(...getClientArgs(queryKey, actualOpts, queryFunctionContext.pageParam ?? opts.initialCursor));
372
- },
373
- }, queryClient);
374
- hook.trpc = useHookResult({
375
- path: path.join('.'),
376
- });
377
- return hook;
378
- }
379
- function useSuspenseInfiniteQuery$1(path, input, opts) {
380
- const context = useContext();
381
- const queryKey = getQueryKeyInternal(path, input, 'infinite');
382
- const defaultOpts = context.queryClient.getQueryDefaults(queryKey);
383
- const ssrOpts = useSSRQueryOptionsIfNeeded(queryKey, {
384
- ...defaultOpts,
385
- ...opts,
386
- });
387
- // request option should take priority over global
388
- const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? context.abortOnUnmount;
389
- const hook = useSuspenseInfiniteQuery({
390
- ...opts,
391
- initialPageParam: opts.initialCursor ?? null,
392
- queryKey,
393
- queryFn: (queryFunctionContext) => {
394
- const actualOpts = {
395
- ...ssrOpts,
396
- trpc: {
397
- ...ssrOpts?.trpc,
398
- ...(shouldAbortOnUnmount
399
- ? { signal: queryFunctionContext.signal }
400
- : {}),
401
- },
402
- };
403
- return context.client.query(...getClientArgs(queryKey, actualOpts, queryFunctionContext.pageParam ?? opts.initialCursor));
404
- },
405
- }, context.queryClient);
406
- hook.trpc = useHookResult({
407
- path: path.join('.'),
408
- });
409
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
410
- return [hook.data, hook];
411
- }
412
- const useQueries$1 = (queriesCallback) => {
413
- const { ssrState, queryClient, prefetchQuery, client } = useContext();
414
- const proxy = createUseQueries(client);
415
- const queries = queriesCallback(proxy);
416
- if (typeof window === 'undefined' && ssrState === 'prepass') {
417
- for (const query of queries) {
418
- const queryOption = query;
419
- if (queryOption.trpc?.ssr !== false &&
420
- !queryClient.getQueryCache().find({ queryKey: queryOption.queryKey })) {
421
- void prefetchQuery(queryOption.queryKey, queryOption);
422
- }
423
- }
424
- }
425
- return useQueries({
426
- queries: queries.map((query) => ({
427
- ...query,
428
- queryKey: query.queryKey,
429
- })),
430
- }, queryClient);
431
- };
432
- const useSuspenseQueries$1 = (queriesCallback) => {
433
- const { queryClient, client } = useContext();
434
- const proxy = createUseQueries(client);
435
- const queries = queriesCallback(proxy);
436
- const hook = useSuspenseQueries({
437
- queries: queries.map((query) => ({
438
- ...query,
439
- queryKey: query.queryKey,
440
- })),
441
- }, queryClient);
442
- return [hook.map((h) => h.data), hook];
443
- };
444
- const useDehydratedState = (client, trpcState) => {
445
- const transformed = React.useMemo(() => {
446
- if (!trpcState) {
447
- return trpcState;
448
- }
449
- return client.runtime.transformer.deserialize(trpcState);
450
- }, [trpcState, client]);
451
- return transformed;
452
- };
453
- return {
454
- Provider: TRPCProvider,
455
- createClient,
456
- useContext,
457
- useUtils: useContext,
458
- useQuery: useQuery$1,
459
- useSuspenseQuery: useSuspenseQuery$1,
460
- useQueries: useQueries$1,
461
- useSuspenseQueries: useSuspenseQueries$1,
462
- useMutation: useMutation$1,
463
- useSubscription,
464
- useDehydratedState,
465
- useInfiniteQuery: useInfiniteQuery$1,
466
- useSuspenseInfiniteQuery: useSuspenseInfiniteQuery$1,
467
- };
468
- }
469
-
470
- export { createReactDecoration as a, createUtilityFunctions as b, createRootHooks as c, createUseQueries as d, getClientArgs as g };
@@ -1,8 +0,0 @@
1
- import { QueryClient } from '@tanstack/react-query';
2
-
3
- /**
4
- * @internal
5
- */
6
- const getQueryClient = (config) => config.queryClient ?? new QueryClient(config.queryClientConfig);
7
-
8
- export { getQueryClient as g };