@trpc/react-query 10.43.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,568 +0,0 @@
1
- import { createRecursiveProxy, createFlatProxy } from '@trpc/server/shared';
2
- import { g as getArrayQueryKey } from './getArrayQueryKey-86134f8b.mjs';
3
- import { createTRPCClientProxy, createTRPCClient } from '@trpc/client';
4
- import { useQuery, useQueryClient, useMutation, hashQueryKey, useInfiniteQuery, useQueries } from '@tanstack/react-query';
5
- import React, { createContext, 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
- */ function getQueryKeyInternal(path, input) {
11
- if (path.length) return input === undefined ? [
12
- path
13
- ] : [
14
- path,
15
- input
16
- ];
17
- return [];
18
- }
19
- /**
20
- * Method to extract the query key for a procedure
21
- * @param procedureOrRouter - procedure or AnyRouter
22
- * @param input - input to procedureOrRouter
23
- * @param type - defaults to `any`
24
- * @link https://trpc.io/docs/getQueryKey
25
- */ function getQueryKey(..._params) {
26
- const [procedureOrRouter, input, type] = _params;
27
- // @ts-expect-error - we don't expose _def on the type layer
28
- const path = procedureOrRouter._def().path;
29
- const dotPath = path.join('.');
30
- const queryKey = getArrayQueryKey(getQueryKeyInternal(dotPath, input), type ?? 'any');
31
- return queryKey;
32
- }
33
-
34
- /**
35
- * Create proxy for decorating procedures
36
- * @internal
37
- */ function createReactProxyDecoration(name, hooks) {
38
- return createRecursiveProxy((opts)=>{
39
- const args = opts.args;
40
- const pathCopy = [
41
- name,
42
- ...opts.path
43
- ];
44
- // The last arg is for instance `.useMutation` or `.useQuery()`
45
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
46
- const lastArg = pathCopy.pop();
47
- // The `path` ends up being something like `post.byId`
48
- const path = pathCopy.join('.');
49
- if (lastArg === 'useMutation') {
50
- return hooks[lastArg](path, ...args);
51
- }
52
- const [input, ...rest] = args;
53
- const queryKey = getQueryKeyInternal(path, input);
54
- // Expose queryKey helper
55
- if (lastArg === 'getQueryKey') {
56
- return getArrayQueryKey(queryKey, rest[0] ?? 'any');
57
- }
58
- if (lastArg === '_def') {
59
- return {
60
- path: pathCopy
61
- };
62
- }
63
- if (lastArg.startsWith('useSuspense')) {
64
- const opts1 = rest[0] || {};
65
- const fn = lastArg === 'useSuspenseQuery' ? 'useQuery' : 'useInfiniteQuery';
66
- const result = hooks[fn](queryKey, {
67
- ...opts1,
68
- suspense: true,
69
- enabled: true
70
- });
71
- return [
72
- result.data,
73
- result
74
- ];
75
- }
76
- return hooks[lastArg](queryKey, ...rest);
77
- });
78
- }
79
-
80
- const contextProps = [
81
- 'client',
82
- 'ssrContext',
83
- 'ssrState',
84
- 'abortOnUnmount'
85
- ];
86
- const TRPCContext = /*#__PURE__*/ createContext(null);
87
-
88
- /**
89
- * @internal
90
- */ function createReactQueryUtilsProxy(context) {
91
- return createFlatProxy((key)=>{
92
- const contextName = key;
93
- if (contextName === 'client') {
94
- return createTRPCClientProxy(context.client);
95
- }
96
- if (contextProps.includes(contextName)) {
97
- return context[contextName];
98
- }
99
- return createRecursiveProxy(({ path , args })=>{
100
- const pathCopy = [
101
- key,
102
- ...path
103
- ];
104
- const utilName = pathCopy.pop();
105
- const fullPath = pathCopy.join('.');
106
- const getOpts = (name)=>{
107
- if ([
108
- 'setData',
109
- 'setInfiniteData'
110
- ].includes(name)) {
111
- const [input, updater, ...rest] = args;
112
- const queryKey = getQueryKeyInternal(fullPath, input);
113
- return {
114
- queryKey,
115
- updater,
116
- rest
117
- };
118
- }
119
- const [input1, ...rest1] = args;
120
- const queryKey1 = getQueryKeyInternal(fullPath, input1);
121
- return {
122
- queryKey: queryKey1,
123
- rest: rest1
124
- };
125
- };
126
- const { queryKey , rest , updater } = getOpts(utilName);
127
- const contextMap = {
128
- fetch: ()=>context.fetchQuery(queryKey, ...rest),
129
- fetchInfinite: ()=>context.fetchInfiniteQuery(queryKey, ...rest),
130
- prefetch: ()=>context.prefetchQuery(queryKey, ...rest),
131
- prefetchInfinite: ()=>context.prefetchInfiniteQuery(queryKey, ...rest),
132
- ensureData: ()=>context.ensureQueryData(queryKey, ...rest),
133
- invalidate: ()=>context.invalidateQueries(queryKey, ...rest),
134
- reset: ()=>context.resetQueries(queryKey, ...rest),
135
- refetch: ()=>context.refetchQueries(queryKey, ...rest),
136
- cancel: ()=>context.cancelQuery(queryKey, ...rest),
137
- setData: ()=>{
138
- context.setQueryData(queryKey, updater, ...rest);
139
- },
140
- setInfiniteData: ()=>{
141
- context.setInfiniteQueryData(queryKey, updater, ...rest);
142
- },
143
- getData: ()=>context.getQueryData(queryKey),
144
- getInfiniteData: ()=>context.getInfiniteQueryData(queryKey)
145
- };
146
- return contextMap[utilName]();
147
- });
148
- });
149
- }
150
-
151
- /**
152
- * Create proxy for `useQueries` options
153
- * @internal
154
- */ function createUseQueriesProxy(client) {
155
- return createRecursiveProxy((opts)=>{
156
- const path = opts.path.join('.');
157
- const [input, _opts] = opts.args;
158
- const queryKey = getQueryKeyInternal(path, input);
159
- const options = {
160
- queryKey,
161
- queryFn: ()=>{
162
- return client.query(path, input, _opts?.trpc);
163
- },
164
- ..._opts
165
- };
166
- return options;
167
- });
168
- }
169
-
170
- function getClientArgs(pathAndInput, opts) {
171
- const [path, input] = pathAndInput;
172
- return [
173
- path,
174
- input,
175
- opts?.trpc
176
- ];
177
- }
178
-
179
- /**
180
- * Makes a stable reference of the `trpc` prop
181
- */ function useHookResult(value) {
182
- const ref = useRef(value);
183
- ref.current.path = value.path;
184
- return ref.current;
185
- }
186
-
187
- /**
188
- * @internal
189
- */ function createRootHooks(config) {
190
- const mutationSuccessOverride = (config?.overrides ?? config?.unstable_overrides)?.useMutation?.onSuccess ?? ((options)=>options.originalFn());
191
- const Context = config?.context ?? TRPCContext;
192
- const ReactQueryContext = config?.reactQueryContext;
193
- const createClient = (opts)=>{
194
- return createTRPCClient(opts);
195
- };
196
- const TRPCProvider = (props)=>{
197
- const { abortOnUnmount =false , client , queryClient , ssrContext } = props;
198
- const [ssrState, setSSRState] = useState(props.ssrState ?? false);
199
- useEffect(()=>{
200
- // Only updating state to `mounted` if we are using SSR.
201
- // This makes it so we don't have an unnecessary re-render when opting out of SSR.
202
- setSSRState((state)=>state ? 'mounted' : false);
203
- }, []);
204
- return /*#__PURE__*/ React.createElement(Context.Provider, {
205
- value: {
206
- abortOnUnmount,
207
- queryClient,
208
- client,
209
- ssrContext: ssrContext ?? null,
210
- ssrState,
211
- fetchQuery: useCallback((pathAndInput, opts)=>{
212
- return queryClient.fetchQuery({
213
- ...opts,
214
- queryKey: getArrayQueryKey(pathAndInput, 'query'),
215
- queryFn: ()=>client.query(...getClientArgs(pathAndInput, opts))
216
- });
217
- }, [
218
- client,
219
- queryClient
220
- ]),
221
- fetchInfiniteQuery: useCallback((pathAndInput, opts)=>{
222
- return queryClient.fetchInfiniteQuery({
223
- ...opts,
224
- queryKey: getArrayQueryKey(pathAndInput, 'infinite'),
225
- queryFn: ({ pageParam })=>{
226
- const [path, input] = pathAndInput;
227
- const actualInput = {
228
- ...input,
229
- cursor: pageParam
230
- };
231
- return client.query(...getClientArgs([
232
- path,
233
- actualInput
234
- ], opts));
235
- }
236
- });
237
- }, [
238
- client,
239
- queryClient
240
- ]),
241
- prefetchQuery: useCallback((pathAndInput, opts)=>{
242
- return queryClient.prefetchQuery({
243
- ...opts,
244
- queryKey: getArrayQueryKey(pathAndInput, 'query'),
245
- queryFn: ()=>client.query(...getClientArgs(pathAndInput, opts))
246
- });
247
- }, [
248
- client,
249
- queryClient
250
- ]),
251
- prefetchInfiniteQuery: useCallback((pathAndInput, opts)=>{
252
- return queryClient.prefetchInfiniteQuery({
253
- ...opts,
254
- queryKey: getArrayQueryKey(pathAndInput, 'infinite'),
255
- queryFn: ({ pageParam })=>{
256
- const [path, input] = pathAndInput;
257
- const actualInput = {
258
- ...input,
259
- cursor: pageParam
260
- };
261
- return client.query(...getClientArgs([
262
- path,
263
- actualInput
264
- ], opts));
265
- }
266
- });
267
- }, [
268
- client,
269
- queryClient
270
- ]),
271
- ensureQueryData: useCallback((pathAndInput, opts)=>{
272
- return queryClient.ensureQueryData({
273
- ...opts,
274
- queryKey: getArrayQueryKey(pathAndInput, 'query'),
275
- queryFn: ()=>client.query(...getClientArgs(pathAndInput, opts))
276
- });
277
- }, [
278
- client,
279
- queryClient
280
- ]),
281
- invalidateQueries: useCallback((queryKey, filters, options)=>{
282
- return queryClient.invalidateQueries({
283
- ...filters,
284
- queryKey: getArrayQueryKey(queryKey, 'any')
285
- }, options);
286
- }, [
287
- queryClient
288
- ]),
289
- resetQueries: useCallback((...args)=>{
290
- const [queryKey, filters, options] = args;
291
- return queryClient.resetQueries({
292
- ...filters,
293
- queryKey: getArrayQueryKey(queryKey, 'any')
294
- }, options);
295
- }, [
296
- queryClient
297
- ]),
298
- refetchQueries: useCallback((...args)=>{
299
- const [queryKey, filters, options] = args;
300
- return queryClient.refetchQueries({
301
- ...filters,
302
- queryKey: getArrayQueryKey(queryKey, 'any')
303
- }, options);
304
- }, [
305
- queryClient
306
- ]),
307
- cancelQuery: useCallback((pathAndInput)=>{
308
- return queryClient.cancelQueries({
309
- queryKey: getArrayQueryKey(pathAndInput, 'any')
310
- });
311
- }, [
312
- queryClient
313
- ]),
314
- setQueryData: useCallback((...args)=>{
315
- const [queryKey, ...rest] = args;
316
- return queryClient.setQueryData(getArrayQueryKey(queryKey, 'query'), ...rest);
317
- }, [
318
- queryClient
319
- ]),
320
- getQueryData: useCallback((...args)=>{
321
- const [queryKey, ...rest] = args;
322
- return queryClient.getQueryData(getArrayQueryKey(queryKey, 'query'), ...rest);
323
- }, [
324
- queryClient
325
- ]),
326
- setInfiniteQueryData: useCallback((...args)=>{
327
- const [queryKey, ...rest] = args;
328
- return queryClient.setQueryData(getArrayQueryKey(queryKey, 'infinite'), ...rest);
329
- }, [
330
- queryClient
331
- ]),
332
- getInfiniteQueryData: useCallback((...args)=>{
333
- const [queryKey, ...rest] = args;
334
- return queryClient.getQueryData(getArrayQueryKey(queryKey, 'infinite'), ...rest);
335
- }, [
336
- queryClient
337
- ])
338
- }
339
- }, props.children);
340
- };
341
- function useContext() {
342
- return React.useContext(Context);
343
- }
344
- /**
345
- * Hack to make sure errors return `status`='error` when doing SSR
346
- * @link https://github.com/trpc/trpc/pull/1645
347
- */ function useSSRQueryOptionsIfNeeded(pathAndInput, type, opts) {
348
- const { queryClient , ssrState } = useContext();
349
- return ssrState && ssrState !== 'mounted' && queryClient.getQueryCache().find(getArrayQueryKey(pathAndInput, type))?.state.status === 'error' ? {
350
- retryOnMount: false,
351
- ...opts
352
- } : opts;
353
- }
354
- function useQuery$1(// FIXME path should be a tuple in next major
355
- pathAndInput, opts) {
356
- const context = useContext();
357
- if (!context) {
358
- throw new Error('Unable to retrieve application context. Did you forget to wrap your App inside `withTRPC` HoC?');
359
- }
360
- const { abortOnUnmount , client , ssrState , queryClient , prefetchQuery } = context;
361
- const defaultOpts = queryClient.getQueryDefaults(getArrayQueryKey(pathAndInput, 'query'));
362
- if (typeof window === 'undefined' && ssrState === 'prepass' && opts?.trpc?.ssr !== false && (opts?.enabled ?? defaultOpts?.enabled) !== false && !queryClient.getQueryCache().find(getArrayQueryKey(pathAndInput, 'query'))) {
363
- void prefetchQuery(pathAndInput, opts);
364
- }
365
- const ssrOpts = useSSRQueryOptionsIfNeeded(pathAndInput, 'query', {
366
- ...defaultOpts,
367
- ...opts
368
- });
369
- const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? config?.abortOnUnmount ?? abortOnUnmount;
370
- const hook = useQuery({
371
- ...ssrOpts,
372
- queryKey: getArrayQueryKey(pathAndInput, 'query'),
373
- queryFn: (queryFunctionContext)=>{
374
- const actualOpts = {
375
- ...ssrOpts,
376
- trpc: {
377
- ...ssrOpts?.trpc,
378
- ...shouldAbortOnUnmount ? {
379
- signal: queryFunctionContext.signal
380
- } : {}
381
- }
382
- };
383
- return client.query(...getClientArgs(pathAndInput, actualOpts));
384
- },
385
- context: ReactQueryContext
386
- });
387
- hook.trpc = useHookResult({
388
- path: pathAndInput[0]
389
- });
390
- return hook;
391
- }
392
- function useMutation$1(// FIXME: this should only be a tuple path in next major
393
- path, opts) {
394
- const { client } = useContext();
395
- const queryClient = useQueryClient({
396
- context: ReactQueryContext
397
- });
398
- const actualPath = Array.isArray(path) ? path[0] : path;
399
- const defaultOpts = queryClient.getMutationDefaults([
400
- actualPath.split('.')
401
- ]);
402
- const hook = useMutation({
403
- ...opts,
404
- mutationKey: [
405
- actualPath.split('.')
406
- ],
407
- mutationFn: (input)=>{
408
- return client.mutation(...getClientArgs([
409
- actualPath,
410
- input
411
- ], opts));
412
- },
413
- context: ReactQueryContext,
414
- onSuccess (...args) {
415
- const originalFn = ()=>opts?.onSuccess?.(...args) ?? defaultOpts?.onSuccess?.(...args);
416
- return mutationSuccessOverride({
417
- originalFn,
418
- queryClient,
419
- meta: opts?.meta ?? defaultOpts?.meta ?? {}
420
- });
421
- }
422
- });
423
- hook.trpc = useHookResult({
424
- path: actualPath
425
- });
426
- return hook;
427
- }
428
- /* istanbul ignore next -- @preserve */ function useSubscription(pathAndInput, opts) {
429
- const enabled = opts?.enabled ?? true;
430
- const queryKey = hashQueryKey(pathAndInput);
431
- const { client } = useContext();
432
- const optsRef = useRef(opts);
433
- optsRef.current = opts;
434
- useEffect(()=>{
435
- if (!enabled) {
436
- return;
437
- }
438
- const [path, input] = pathAndInput;
439
- let isStopped = false;
440
- const subscription = client.subscription(path, input ?? undefined, {
441
- onStarted: ()=>{
442
- if (!isStopped) {
443
- optsRef.current.onStarted?.();
444
- }
445
- },
446
- onData: (data)=>{
447
- if (!isStopped) {
448
- // FIXME this shouldn't be needed as both should be `unknown` in next major
449
- optsRef.current.onData(data);
450
- }
451
- },
452
- onError: (err)=>{
453
- if (!isStopped) {
454
- optsRef.current.onError?.(err);
455
- }
456
- }
457
- });
458
- return ()=>{
459
- isStopped = true;
460
- subscription.unsubscribe();
461
- };
462
- // eslint-disable-next-line react-hooks/exhaustive-deps
463
- }, [
464
- queryKey,
465
- enabled
466
- ]);
467
- }
468
- function useInfiniteQuery$1(pathAndInput, opts) {
469
- const [path, input] = pathAndInput;
470
- const { client , ssrState , prefetchInfiniteQuery , queryClient , abortOnUnmount , } = useContext();
471
- const defaultOpts = queryClient.getQueryDefaults(getArrayQueryKey(pathAndInput, 'infinite'));
472
- if (typeof window === 'undefined' && ssrState === 'prepass' && opts?.trpc?.ssr !== false && (opts?.enabled ?? defaultOpts?.enabled) !== false && !queryClient.getQueryCache().find(getArrayQueryKey(pathAndInput, 'infinite'))) {
473
- void prefetchInfiniteQuery(pathAndInput, {
474
- ...defaultOpts,
475
- ...opts
476
- });
477
- }
478
- const ssrOpts = useSSRQueryOptionsIfNeeded(pathAndInput, 'infinite', {
479
- ...defaultOpts,
480
- ...opts
481
- });
482
- // request option should take priority over global
483
- const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? abortOnUnmount;
484
- const hook = useInfiniteQuery({
485
- ...ssrOpts,
486
- queryKey: getArrayQueryKey(pathAndInput, 'infinite'),
487
- queryFn: (queryFunctionContext)=>{
488
- const actualOpts = {
489
- ...ssrOpts,
490
- trpc: {
491
- ...ssrOpts?.trpc,
492
- ...shouldAbortOnUnmount ? {
493
- signal: queryFunctionContext.signal
494
- } : {}
495
- }
496
- };
497
- const actualInput = {
498
- ...input ?? {},
499
- cursor: queryFunctionContext.pageParam ?? opts?.initialCursor
500
- };
501
- // FIXME as any shouldn't be needed as client should be untyped too
502
- return client.query(...getClientArgs([
503
- path,
504
- actualInput
505
- ], actualOpts));
506
- },
507
- context: ReactQueryContext
508
- });
509
- hook.trpc = useHookResult({
510
- path
511
- });
512
- return hook;
513
- }
514
- const useQueries$1 = (queriesCallback, context)=>{
515
- const { ssrState , queryClient , prefetchQuery , client } = useContext();
516
- const proxy = createUseQueriesProxy(client);
517
- const queries = queriesCallback(proxy);
518
- if (typeof window === 'undefined' && ssrState === 'prepass') {
519
- for (const query of queries){
520
- const queryOption = query;
521
- if (queryOption.trpc?.ssr !== false && !queryClient.getQueryCache().find(getArrayQueryKey(queryOption.queryKey, 'query'))) {
522
- void prefetchQuery(queryOption.queryKey, queryOption);
523
- }
524
- }
525
- }
526
- return useQueries({
527
- queries: queries.map((query)=>({
528
- ...query,
529
- queryKey: getArrayQueryKey(query.queryKey, 'query')
530
- })),
531
- context
532
- });
533
- };
534
- const useDehydratedState = (client, trpcState)=>{
535
- const transformed = useMemo(()=>{
536
- if (!trpcState) {
537
- return trpcState;
538
- }
539
- return client.runtime.transformer.deserialize(trpcState);
540
- }, [
541
- trpcState,
542
- client
543
- ]);
544
- return transformed;
545
- };
546
- return {
547
- Provider: TRPCProvider,
548
- createClient,
549
- useContext,
550
- useUtils: useContext,
551
- useQuery: useQuery$1,
552
- useQueries: useQueries$1,
553
- useMutation: useMutation$1,
554
- useSubscription,
555
- useDehydratedState,
556
- useInfiniteQuery: useInfiniteQuery$1
557
- };
558
- }
559
-
560
- /**
561
- * Create strongly typed react hooks
562
- * @internal
563
- * @deprecated
564
- */ function createHooksInternal(config) {
565
- return createRootHooks(config);
566
- }
567
-
568
- 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 };
@@ -1,36 +0,0 @@
1
- 'use strict';
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
- **/ function getArrayQueryKey(queryKey, type) {
10
- const queryKeyArrayed = Array.isArray(queryKey) ? queryKey : [
11
- queryKey
12
- ];
13
- const [path, input] = queryKeyArrayed;
14
- const arrayPath = typeof path !== 'string' || path === '' ? [] : path.split('.');
15
- // Construct a query key that is easy to destructure and flexible for
16
- // partial selecting etc.
17
- // https://github.com/trpc/trpc/issues/3128
18
- if (!input && (!type || type === 'any')) // 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 ? [
21
- arrayPath
22
- ] : [];
23
- return [
24
- arrayPath,
25
- {
26
- ...typeof input !== 'undefined' && {
27
- input: input
28
- },
29
- ...type && type !== 'any' && {
30
- type: type
31
- }
32
- }
33
- ];
34
- }
35
-
36
- exports.getArrayQueryKey = getArrayQueryKey;
@@ -1,34 +0,0 @@
1
- /**
2
- * To allow easy interactions with groups of related queries, such as
3
- * invalidating all queries of a router, we use an array as the path when
4
- * storing in tanstack query. This function converts from the `.` separated
5
- * path passed around internally by both the legacy and proxy implementation.
6
- * https://github.com/trpc/trpc/issues/2611
7
- **/ function getArrayQueryKey(queryKey, type) {
8
- const queryKeyArrayed = Array.isArray(queryKey) ? queryKey : [
9
- queryKey
10
- ];
11
- const [path, input] = queryKeyArrayed;
12
- const arrayPath = typeof path !== 'string' || path === '' ? [] : path.split('.');
13
- // Construct a query key that is easy to destructure and flexible for
14
- // partial selecting etc.
15
- // https://github.com/trpc/trpc/issues/3128
16
- if (!input && (!type || type === 'any')) // for `utils.invalidate()` to match all queries (including vanilla react-query)
17
- // we don't want nested array if path is empty, i.e. `[]` instead of `[[]]`
18
- return arrayPath.length ? [
19
- arrayPath
20
- ] : [];
21
- return [
22
- arrayPath,
23
- {
24
- ...typeof input !== 'undefined' && {
25
- input: input
26
- },
27
- ...type && type !== 'any' && {
28
- type: type
29
- }
30
- }
31
- ];
32
- }
33
-
34
- export { getArrayQueryKey as g };
@@ -1,25 +0,0 @@
1
- import { GetQueryProcedureInput } from './getQueryKey';
2
- export type QueryType = 'any' | 'infinite' | 'query';
3
- export type QueryKey = [
4
- string[],
5
- {
6
- input?: unknown;
7
- type?: Exclude<QueryType, 'any'>;
8
- }?
9
- ];
10
- export type QueryKeyKnown<TInput, TType extends Exclude<QueryType, 'any'>> = [
11
- string[],
12
- {
13
- input?: GetQueryProcedureInput<TInput>;
14
- type: TType;
15
- }?
16
- ];
17
- /**
18
- * To allow easy interactions with groups of related queries, such as
19
- * invalidating all queries of a router, we use an array as the path when
20
- * storing in tanstack query. This function converts from the `.` separated
21
- * path passed around internally by both the legacy and proxy implementation.
22
- * https://github.com/trpc/trpc/issues/2611
23
- **/
24
- export declare function getArrayQueryKey(queryKey: unknown[] | string | [string, ...unknown[]] | [string], type: QueryType): QueryKey;
25
- //# sourceMappingURL=getArrayQueryKey.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getArrayQueryKey.d.ts","sourceRoot":"","sources":["../../src/internals/getArrayQueryKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAEvD,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,UAAU,GAAG,OAAO,CAAC;AAErD,MAAM,MAAM,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,MAAM,MAAM,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,OAAO,EAAE,GAAG,MAAM,GAAG,CAAC,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,EAChE,IAAI,EAAE,SAAS,GACd,QAAQ,CAqBV"}
package/dist/interop.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import { AnyRouter } from '@trpc/server';
2
- import { CreateTRPCReact } from './createTRPCReact';
3
- import { CreateTRPCReactOptions } from './shared';
4
- import { CreateReactQueryHooks } from './shared/hooks/createRootHooks';
5
- /**
6
- * @deprecated use `createTRPCReact` instead
7
- */
8
- export declare function createReactQueryHooks<TRouter extends AnyRouter, TSSRContext = unknown, TFlags = null>(opts?: CreateTRPCReactOptions<TRouter>): CreateReactQueryHooks<TRouter, TSSRContext> & {
9
- proxy: CreateTRPCReact<TRouter, TSSRContext, TFlags>;
10
- };
11
- //# sourceMappingURL=interop.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"interop.d.ts","sourceRoot":"","sources":["../src/interop.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAA4B,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAEL,qBAAqB,EACtB,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"}