@trpc/react-query 10.42.0 → 11.0.0-next.91

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/dist/bundle-analysis.json +208 -0
  2. package/dist/createHooksInternal-3d8ebfcf.mjs +481 -0
  3. package/dist/createHooksInternal-dce6e141.js +435 -0
  4. package/dist/createHooksInternal-e2034194.js +490 -0
  5. package/dist/createTRPCReact.d.ts +46 -45
  6. package/dist/createTRPCReact.d.ts.map +1 -1
  7. package/dist/index.d.ts +0 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +8 -21
  10. package/dist/index.mjs +9 -21
  11. package/dist/internals/context.d.ts +42 -54
  12. package/dist/internals/context.d.ts.map +1 -1
  13. package/dist/internals/getClientArgs.d.ts +2 -1
  14. package/dist/internals/getClientArgs.d.ts.map +1 -1
  15. package/dist/internals/getQueryKey.d.ts +28 -13
  16. package/dist/internals/getQueryKey.d.ts.map +1 -1
  17. package/dist/internals/useQueries.d.ts +4 -4
  18. package/dist/internals/useQueries.d.ts.map +1 -1
  19. package/dist/server/index.d.ts +0 -6
  20. package/dist/server/index.d.ts.map +1 -1
  21. package/dist/server/index.js +52 -69
  22. package/dist/server/index.mjs +52 -69
  23. package/dist/server/ssgProxy.d.ts +23 -13
  24. package/dist/server/ssgProxy.d.ts.map +1 -1
  25. package/dist/shared/hooks/createHooksInternal.d.ts +35 -12
  26. package/dist/shared/hooks/createHooksInternal.d.ts.map +1 -1
  27. package/dist/shared/hooks/createRootHooks.d.ts +0 -5
  28. package/dist/shared/hooks/createRootHooks.d.ts.map +1 -1
  29. package/dist/shared/hooks/types.d.ts +33 -18
  30. package/dist/shared/hooks/types.d.ts.map +1 -1
  31. package/dist/shared/index.js +9 -9
  32. package/dist/shared/index.mjs +3 -3
  33. package/dist/shared/polymorphism/mutationLike.d.ts +5 -5
  34. package/dist/shared/polymorphism/mutationLike.d.ts.map +1 -1
  35. package/dist/shared/polymorphism/queryLike.d.ts +5 -5
  36. package/dist/shared/polymorphism/queryLike.d.ts.map +1 -1
  37. package/dist/shared/polymorphism/routerLike.d.ts +4 -3
  38. package/dist/shared/polymorphism/routerLike.d.ts.map +1 -1
  39. package/dist/shared/proxy/decorationProxy.d.ts +2 -2
  40. package/dist/shared/proxy/decorationProxy.d.ts.map +1 -1
  41. package/dist/shared/proxy/useQueriesProxy.d.ts +6 -6
  42. package/dist/shared/proxy/useQueriesProxy.d.ts.map +1 -1
  43. package/dist/shared/proxy/utilsProxy.d.ts +34 -31
  44. package/dist/shared/proxy/utilsProxy.d.ts.map +1 -1
  45. package/dist/shared/types.d.ts +0 -12
  46. package/dist/shared/types.d.ts.map +1 -1
  47. package/dist/utils/inferReactQueryProcedure.d.ts +7 -7
  48. package/dist/utils/inferReactQueryProcedure.d.ts.map +1 -1
  49. package/dist/utilsProxy-00894da2.mjs +121 -0
  50. package/dist/utilsProxy-27bd93c1.js +128 -0
  51. package/dist/utilsProxy-7e396600.js +114 -0
  52. package/package.json +8 -14
  53. package/src/createTRPCReact.tsx +156 -135
  54. package/src/index.ts +0 -1
  55. package/src/internals/context.tsx +93 -164
  56. package/src/internals/getClientArgs.ts +9 -4
  57. package/src/internals/getQueryKey.ts +53 -24
  58. package/src/internals/useQueries.ts +7 -10
  59. package/src/server/index.ts +0 -8
  60. package/src/server/ssgProxy.ts +179 -34
  61. package/src/shared/hooks/createHooksInternal.tsx +298 -207
  62. package/src/shared/hooks/createRootHooks.tsx +0 -6
  63. package/src/shared/hooks/types.ts +87 -36
  64. package/src/shared/polymorphism/mutationLike.ts +11 -8
  65. package/src/shared/polymorphism/queryLike.ts +17 -12
  66. package/src/shared/polymorphism/routerLike.ts +15 -9
  67. package/src/shared/proxy/decorationProxy.ts +9 -31
  68. package/src/shared/proxy/useQueriesProxy.ts +23 -37
  69. package/src/shared/proxy/utilsProxy.ts +121 -95
  70. package/src/shared/types.ts +0 -12
  71. package/src/utils/inferReactQueryProcedure.ts +28 -30
  72. package/dist/context-4557b3d3.js +0 -38
  73. package/dist/createHooksInternal-2e69c447.js +0 -582
  74. package/dist/createHooksInternal-37b068e0.js +0 -510
  75. package/dist/createHooksInternal-bdff7171.mjs +0 -568
  76. package/dist/getArrayQueryKey-4bdb5cc2.js +0 -36
  77. package/dist/getArrayQueryKey-86134f8b.mjs +0 -34
  78. package/dist/internals/getArrayQueryKey.d.ts +0 -25
  79. package/dist/internals/getArrayQueryKey.d.ts.map +0 -1
  80. package/dist/interop.d.ts +0 -11
  81. package/dist/interop.d.ts.map +0 -1
  82. package/dist/server/types.d.ts +0 -14
  83. package/dist/server/types.d.ts.map +0 -1
  84. package/dist/shared/hooks/deprecated/createHooksInternal.d.ts +0 -63
  85. package/dist/shared/hooks/deprecated/createHooksInternal.d.ts.map +0 -1
  86. package/dist/ssg/index.d.ts +0 -15
  87. package/dist/ssg/index.d.ts.map +0 -1
  88. package/dist/ssg/ssg.d.ts +0 -16
  89. package/dist/ssg/ssg.d.ts.map +0 -1
  90. package/src/internals/getArrayQueryKey.ts +0 -46
  91. package/src/interop.ts +0 -29
  92. package/src/server/types.ts +0 -29
  93. package/src/shared/hooks/deprecated/createHooksInternal.tsx +0 -641
  94. package/src/ssg/index.tsx +0 -16
  95. package/src/ssg/ssg.ts +0 -139
  96. package/ssg/index.d.ts +0 -1
  97. package/ssg/index.js +0 -1
@@ -1,510 +0,0 @@
1
- import { createRecursiveProxy, createFlatProxy } from '@trpc/server/shared';
2
- import { g as getArrayQueryKey, c as contextProps, T as TRPCContext } from './context-4557b3d3.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
- ensureData: () => context.ensureQueryData(queryKey, ...rest),
113
- invalidate: () => context.invalidateQueries(queryKey, ...rest),
114
- reset: () => context.resetQueries(queryKey, ...rest),
115
- refetch: () => context.refetchQueries(queryKey, ...rest),
116
- cancel: () => context.cancelQuery(queryKey, ...rest),
117
- setData: () => {
118
- context.setQueryData(queryKey, updater, ...rest);
119
- },
120
- setInfiniteData: () => {
121
- context.setInfiniteQueryData(queryKey, updater, ...rest);
122
- },
123
- getData: () => context.getQueryData(queryKey),
124
- getInfiniteData: () => context.getInfiniteQueryData(queryKey),
125
- };
126
- return contextMap[utilName]();
127
- });
128
- });
129
- }
130
-
131
- /**
132
- * Create proxy for `useQueries` options
133
- * @internal
134
- */
135
- function createUseQueriesProxy(client) {
136
- return createRecursiveProxy((opts) => {
137
- const path = opts.path.join('.');
138
- const [input, _opts] = opts.args;
139
- const queryKey = getQueryKeyInternal(path, input);
140
- const options = {
141
- queryKey,
142
- queryFn: () => {
143
- return client.query(path, input, _opts?.trpc);
144
- },
145
- ..._opts,
146
- };
147
- return options;
148
- });
149
- }
150
-
151
- function getClientArgs(pathAndInput, opts) {
152
- const [path, input] = pathAndInput;
153
- return [path, input, opts?.trpc];
154
- }
155
-
156
- /**
157
- * Makes a stable reference of the `trpc` prop
158
- */
159
- function useHookResult(value) {
160
- const ref = useRef(value);
161
- ref.current.path = value.path;
162
- return ref.current;
163
- }
164
-
165
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
166
- /**
167
- * @internal
168
- */
169
- function createRootHooks(config) {
170
- const mutationSuccessOverride = (config?.overrides ?? config?.unstable_overrides)?.useMutation?.onSuccess ??
171
- ((options) => options.originalFn());
172
- const Context = (config?.context ??
173
- TRPCContext);
174
- const ReactQueryContext = config?.reactQueryContext;
175
- const createClient = (opts) => {
176
- return createTRPCClient(opts);
177
- };
178
- const TRPCProvider = (props) => {
179
- const { abortOnUnmount = false, client, queryClient, ssrContext } = props;
180
- const [ssrState, setSSRState] = useState(props.ssrState ?? false);
181
- useEffect(() => {
182
- // Only updating state to `mounted` if we are using SSR.
183
- // This makes it so we don't have an unnecessary re-render when opting out of SSR.
184
- setSSRState((state) => (state ? 'mounted' : false));
185
- }, []);
186
- return (React.createElement(Context.Provider, { value: {
187
- abortOnUnmount,
188
- queryClient,
189
- client,
190
- ssrContext: ssrContext ?? null,
191
- ssrState,
192
- fetchQuery: useCallback((pathAndInput, opts) => {
193
- return queryClient.fetchQuery({
194
- ...opts,
195
- queryKey: getArrayQueryKey(pathAndInput, 'query'),
196
- queryFn: () => client.query(...getClientArgs(pathAndInput, opts)),
197
- });
198
- }, [client, queryClient]),
199
- fetchInfiniteQuery: useCallback((pathAndInput, opts) => {
200
- return queryClient.fetchInfiniteQuery({
201
- ...opts,
202
- queryKey: getArrayQueryKey(pathAndInput, 'infinite'),
203
- queryFn: ({ pageParam }) => {
204
- const [path, input] = pathAndInput;
205
- const actualInput = { ...input, cursor: pageParam };
206
- return client.query(...getClientArgs([path, actualInput], opts));
207
- },
208
- });
209
- }, [client, queryClient]),
210
- prefetchQuery: useCallback((pathAndInput, opts) => {
211
- return queryClient.prefetchQuery({
212
- ...opts,
213
- queryKey: getArrayQueryKey(pathAndInput, 'query'),
214
- queryFn: () => client.query(...getClientArgs(pathAndInput, opts)),
215
- });
216
- }, [client, queryClient]),
217
- prefetchInfiniteQuery: useCallback((pathAndInput, opts) => {
218
- return queryClient.prefetchInfiniteQuery({
219
- ...opts,
220
- queryKey: getArrayQueryKey(pathAndInput, 'infinite'),
221
- queryFn: ({ pageParam }) => {
222
- const [path, input] = pathAndInput;
223
- const actualInput = { ...input, cursor: pageParam };
224
- return client.query(...getClientArgs([path, actualInput], opts));
225
- },
226
- });
227
- }, [client, queryClient]),
228
- ensureQueryData: useCallback((pathAndInput, opts) => {
229
- return queryClient.ensureQueryData({
230
- ...opts,
231
- queryKey: getArrayQueryKey(pathAndInput, 'query'),
232
- queryFn: () => client.query(...getClientArgs(pathAndInput, opts)),
233
- });
234
- }, [client, queryClient]),
235
- invalidateQueries: useCallback((queryKey, filters, options) => {
236
- return queryClient.invalidateQueries({
237
- ...filters,
238
- queryKey: getArrayQueryKey(queryKey, 'any'),
239
- }, options);
240
- }, [queryClient]),
241
- resetQueries: useCallback((...args) => {
242
- const [queryKey, filters, options] = args;
243
- return queryClient.resetQueries({
244
- ...filters,
245
- queryKey: getArrayQueryKey(queryKey, 'any'),
246
- }, options);
247
- }, [queryClient]),
248
- refetchQueries: useCallback((...args) => {
249
- const [queryKey, filters, options] = args;
250
- return queryClient.refetchQueries({
251
- ...filters,
252
- queryKey: getArrayQueryKey(queryKey, 'any'),
253
- }, options);
254
- }, [queryClient]),
255
- cancelQuery: useCallback((pathAndInput) => {
256
- return queryClient.cancelQueries({
257
- queryKey: getArrayQueryKey(pathAndInput, 'any'),
258
- });
259
- }, [queryClient]),
260
- setQueryData: useCallback((...args) => {
261
- const [queryKey, ...rest] = args;
262
- return queryClient.setQueryData(getArrayQueryKey(queryKey, 'query'), ...rest);
263
- }, [queryClient]),
264
- getQueryData: useCallback((...args) => {
265
- const [queryKey, ...rest] = args;
266
- return queryClient.getQueryData(getArrayQueryKey(queryKey, 'query'), ...rest);
267
- }, [queryClient]),
268
- setInfiniteQueryData: useCallback((...args) => {
269
- const [queryKey, ...rest] = args;
270
- return queryClient.setQueryData(getArrayQueryKey(queryKey, 'infinite'), ...rest);
271
- }, [queryClient]),
272
- getInfiniteQueryData: useCallback((...args) => {
273
- const [queryKey, ...rest] = args;
274
- return queryClient.getQueryData(getArrayQueryKey(queryKey, 'infinite'), ...rest);
275
- }, [queryClient]),
276
- } }, props.children));
277
- };
278
- function useContext() {
279
- return React.useContext(Context);
280
- }
281
- /**
282
- * Hack to make sure errors return `status`='error` when doing SSR
283
- * @link https://github.com/trpc/trpc/pull/1645
284
- */
285
- function useSSRQueryOptionsIfNeeded(pathAndInput, type, opts) {
286
- const { queryClient, ssrState } = useContext();
287
- return ssrState &&
288
- ssrState !== 'mounted' &&
289
- queryClient.getQueryCache().find(getArrayQueryKey(pathAndInput, type))
290
- ?.state.status === 'error'
291
- ? {
292
- retryOnMount: false,
293
- ...opts,
294
- }
295
- : opts;
296
- }
297
- function useQuery$1(
298
- // FIXME path should be a tuple in next major
299
- pathAndInput, opts) {
300
- const context = useContext();
301
- if (!context) {
302
- throw new Error('Unable to retrieve application context. Did you forget to wrap your App inside `withTRPC` HoC?');
303
- }
304
- const { abortOnUnmount, client, ssrState, queryClient, prefetchQuery } = context;
305
- const defaultOpts = queryClient.getQueryDefaults(getArrayQueryKey(pathAndInput, 'query'));
306
- if (typeof window === 'undefined' &&
307
- ssrState === 'prepass' &&
308
- opts?.trpc?.ssr !== false &&
309
- (opts?.enabled ?? defaultOpts?.enabled) !== false &&
310
- !queryClient.getQueryCache().find(getArrayQueryKey(pathAndInput, 'query'))) {
311
- void prefetchQuery(pathAndInput, opts);
312
- }
313
- const ssrOpts = useSSRQueryOptionsIfNeeded(pathAndInput, 'query', {
314
- ...defaultOpts,
315
- ...opts,
316
- });
317
- const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? config?.abortOnUnmount ?? abortOnUnmount;
318
- const hook = useQuery({
319
- ...ssrOpts,
320
- queryKey: getArrayQueryKey(pathAndInput, 'query'),
321
- queryFn: (queryFunctionContext) => {
322
- const actualOpts = {
323
- ...ssrOpts,
324
- trpc: {
325
- ...ssrOpts?.trpc,
326
- ...(shouldAbortOnUnmount
327
- ? { signal: queryFunctionContext.signal }
328
- : {}),
329
- },
330
- };
331
- return client.query(...getClientArgs(pathAndInput, actualOpts));
332
- },
333
- context: ReactQueryContext,
334
- });
335
- hook.trpc = useHookResult({
336
- path: pathAndInput[0],
337
- });
338
- return hook;
339
- }
340
- function useMutation$1(
341
- // FIXME: this should only be a tuple path in next major
342
- path, opts) {
343
- const { client } = useContext();
344
- const queryClient = useQueryClient({ context: ReactQueryContext });
345
- const actualPath = Array.isArray(path) ? path[0] : path;
346
- const defaultOpts = queryClient.getMutationDefaults([
347
- actualPath.split('.'),
348
- ]);
349
- const hook = useMutation({
350
- ...opts,
351
- mutationKey: [actualPath.split('.')],
352
- mutationFn: (input) => {
353
- return client.mutation(...getClientArgs([actualPath, input], opts));
354
- },
355
- context: ReactQueryContext,
356
- onSuccess(...args) {
357
- const originalFn = () => opts?.onSuccess?.(...args) ?? defaultOpts?.onSuccess?.(...args);
358
- return mutationSuccessOverride({
359
- originalFn,
360
- queryClient,
361
- meta: opts?.meta ?? defaultOpts?.meta ?? {},
362
- });
363
- },
364
- });
365
- hook.trpc = useHookResult({
366
- path: actualPath,
367
- });
368
- return hook;
369
- }
370
- /* istanbul ignore next -- @preserve */
371
- function useSubscription(pathAndInput, opts) {
372
- const enabled = opts?.enabled ?? true;
373
- const queryKey = hashQueryKey(pathAndInput);
374
- const { client } = useContext();
375
- const optsRef = useRef(opts);
376
- optsRef.current = opts;
377
- useEffect(() => {
378
- if (!enabled) {
379
- return;
380
- }
381
- const [path, input] = pathAndInput;
382
- let isStopped = false;
383
- const subscription = client.subscription(path, (input ?? undefined), {
384
- onStarted: () => {
385
- if (!isStopped) {
386
- optsRef.current.onStarted?.();
387
- }
388
- },
389
- onData: (data) => {
390
- if (!isStopped) {
391
- // FIXME this shouldn't be needed as both should be `unknown` in next major
392
- optsRef.current.onData(data);
393
- }
394
- },
395
- onError: (err) => {
396
- if (!isStopped) {
397
- optsRef.current.onError?.(err);
398
- }
399
- },
400
- });
401
- return () => {
402
- isStopped = true;
403
- subscription.unsubscribe();
404
- };
405
- // eslint-disable-next-line react-hooks/exhaustive-deps
406
- }, [queryKey, enabled]);
407
- }
408
- function useInfiniteQuery$1(pathAndInput, opts) {
409
- const [path, input] = pathAndInput;
410
- const { client, ssrState, prefetchInfiniteQuery, queryClient, abortOnUnmount, } = useContext();
411
- const defaultOpts = queryClient.getQueryDefaults(getArrayQueryKey(pathAndInput, 'infinite'));
412
- if (typeof window === 'undefined' &&
413
- ssrState === 'prepass' &&
414
- opts?.trpc?.ssr !== false &&
415
- (opts?.enabled ?? defaultOpts?.enabled) !== false &&
416
- !queryClient
417
- .getQueryCache()
418
- .find(getArrayQueryKey(pathAndInput, 'infinite'))) {
419
- void prefetchInfiniteQuery(pathAndInput, { ...defaultOpts, ...opts });
420
- }
421
- const ssrOpts = useSSRQueryOptionsIfNeeded(pathAndInput, 'infinite', {
422
- ...defaultOpts,
423
- ...opts,
424
- });
425
- // request option should take priority over global
426
- const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? abortOnUnmount;
427
- const hook = useInfiniteQuery({
428
- ...ssrOpts,
429
- queryKey: getArrayQueryKey(pathAndInput, 'infinite'),
430
- queryFn: (queryFunctionContext) => {
431
- const actualOpts = {
432
- ...ssrOpts,
433
- trpc: {
434
- ...ssrOpts?.trpc,
435
- ...(shouldAbortOnUnmount
436
- ? { signal: queryFunctionContext.signal }
437
- : {}),
438
- },
439
- };
440
- const actualInput = {
441
- ...(input ?? {}),
442
- cursor: queryFunctionContext.pageParam ?? opts?.initialCursor,
443
- };
444
- // FIXME as any shouldn't be needed as client should be untyped too
445
- return client.query(...getClientArgs([path, actualInput], actualOpts));
446
- },
447
- context: ReactQueryContext,
448
- });
449
- hook.trpc = useHookResult({
450
- path,
451
- });
452
- return hook;
453
- }
454
- const useQueries$1 = (queriesCallback, context) => {
455
- const { ssrState, queryClient, prefetchQuery, client } = useContext();
456
- const proxy = createUseQueriesProxy(client);
457
- const queries = queriesCallback(proxy);
458
- if (typeof window === 'undefined' && ssrState === 'prepass') {
459
- for (const query of queries) {
460
- const queryOption = query;
461
- if (queryOption.trpc?.ssr !== false &&
462
- !queryClient
463
- .getQueryCache()
464
- .find(getArrayQueryKey(queryOption.queryKey, 'query'))) {
465
- void prefetchQuery(queryOption.queryKey, queryOption);
466
- }
467
- }
468
- }
469
- return useQueries({
470
- queries: queries.map((query) => ({
471
- ...query,
472
- queryKey: getArrayQueryKey(query.queryKey, 'query'),
473
- })),
474
- context,
475
- });
476
- };
477
- const useDehydratedState = (client, trpcState) => {
478
- const transformed = useMemo(() => {
479
- if (!trpcState) {
480
- return trpcState;
481
- }
482
- return client.runtime.transformer.deserialize(trpcState);
483
- }, [trpcState, client]);
484
- return transformed;
485
- };
486
- return {
487
- Provider: TRPCProvider,
488
- createClient,
489
- useContext,
490
- useUtils: useContext,
491
- useQuery: useQuery$1,
492
- useQueries: useQueries$1,
493
- useMutation: useMutation$1,
494
- useSubscription,
495
- useDehydratedState,
496
- useInfiniteQuery: useInfiniteQuery$1,
497
- };
498
- }
499
-
500
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
501
- /**
502
- * Create strongly typed react hooks
503
- * @internal
504
- * @deprecated
505
- */
506
- function createHooksInternal(config) {
507
- return createRootHooks(config);
508
- }
509
-
510
- export { createReactQueryUtilsProxy as a, createReactProxyDecoration as b, createHooksInternal as c, getClientArgs as d, createUseQueriesProxy as e, createRootHooks as f, getQueryKey as g };