@trpc/react-query 11.3.1 → 11.3.2-canary.2

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 (129) hide show
  1. package/dist/getQueryKey-CP8onRYT.cjs +104 -0
  2. package/dist/getQueryKey-Dekty44G.mjs +53 -0
  3. package/dist/getQueryKey-Dekty44G.mjs.map +1 -0
  4. package/dist/getQueryKey.d-C_PnqPni.d.cts +892 -0
  5. package/dist/getQueryKey.d-C_PnqPni.d.cts.map +1 -0
  6. package/dist/getQueryKey.d-CruH3ncI.d.mts +892 -0
  7. package/dist/getQueryKey.d-CruH3ncI.d.mts.map +1 -0
  8. package/dist/index.cjs +47 -0
  9. package/dist/index.d.cts +31 -0
  10. package/dist/index.d.cts.map +1 -0
  11. package/dist/index.d.mts +31 -0
  12. package/dist/index.d.mts.map +1 -0
  13. package/dist/index.mjs +40 -4
  14. package/dist/index.mjs.map +1 -0
  15. package/dist/rsc.cjs +69 -0
  16. package/dist/rsc.d.cts +80 -0
  17. package/dist/rsc.d.cts.map +1 -0
  18. package/dist/rsc.d.mts +80 -0
  19. package/dist/rsc.d.mts.map +1 -0
  20. package/dist/rsc.mjs +65 -104
  21. package/dist/rsc.mjs.map +1 -0
  22. package/dist/server/index.cjs +132 -0
  23. package/dist/server/index.d.cts +31 -0
  24. package/dist/server/index.d.cts.map +1 -0
  25. package/dist/server/index.d.mts +31 -0
  26. package/dist/server/index.d.mts.map +1 -0
  27. package/dist/server/index.mjs +133 -1
  28. package/dist/server/index.mjs.map +1 -0
  29. package/dist/shared/index.cjs +13 -0
  30. package/dist/shared/index.d.cts +2 -0
  31. package/dist/shared/index.d.mts +2 -0
  32. package/dist/shared/index.mjs +4 -7
  33. package/dist/shared-CMPBsqju.mjs +784 -0
  34. package/dist/shared-CMPBsqju.mjs.map +1 -0
  35. package/dist/shared-Doe-Gsbv.cjs +846 -0
  36. package/package.json +45 -26
  37. package/rsc/package.json +1 -0
  38. package/server/package.json +1 -0
  39. package/shared/package.json +1 -0
  40. package/dist/createTRPCQueryUtils.d.ts +0 -4
  41. package/dist/createTRPCQueryUtils.d.ts.map +0 -1
  42. package/dist/createTRPCQueryUtils.js +0 -16
  43. package/dist/createTRPCQueryUtils.mjs +0 -14
  44. package/dist/createTRPCReact.d.ts +0 -147
  45. package/dist/createTRPCReact.d.ts.map +0 -1
  46. package/dist/createTRPCReact.js +0 -60
  47. package/dist/createTRPCReact.mjs +0 -38
  48. package/dist/index.d.ts +0 -6
  49. package/dist/index.d.ts.map +0 -1
  50. package/dist/index.js +0 -19
  51. package/dist/internals/context.d.ts +0 -157
  52. package/dist/internals/context.d.ts.map +0 -1
  53. package/dist/internals/context.js +0 -33
  54. package/dist/internals/context.mjs +0 -11
  55. package/dist/internals/getClientArgs.d.ts +0 -9
  56. package/dist/internals/getClientArgs.d.ts.map +0 -1
  57. package/dist/internals/getClientArgs.js +0 -24
  58. package/dist/internals/getClientArgs.mjs +0 -22
  59. package/dist/internals/getQueryKey.d.ts +0 -49
  60. package/dist/internals/getQueryKey.d.ts.map +0 -1
  61. package/dist/internals/getQueryKey.js +0 -75
  62. package/dist/internals/getQueryKey.mjs +0 -70
  63. package/dist/internals/trpcResult.d.ts +0 -18
  64. package/dist/internals/trpcResult.d.ts.map +0 -1
  65. package/dist/internals/trpcResult.js +0 -63
  66. package/dist/internals/trpcResult.mjs +0 -40
  67. package/dist/internals/useQueries.d.ts +0 -58
  68. package/dist/internals/useQueries.d.ts.map +0 -1
  69. package/dist/rsc.d.ts +0 -80
  70. package/dist/rsc.d.ts.map +0 -1
  71. package/dist/rsc.js +0 -130
  72. package/dist/server/index.d.ts +0 -2
  73. package/dist/server/index.d.ts.map +0 -1
  74. package/dist/server/index.js +0 -7
  75. package/dist/server/ssgProxy.d.ts +0 -31
  76. package/dist/server/ssgProxy.d.ts.map +0 -1
  77. package/dist/server/ssgProxy.js +0 -141
  78. package/dist/server/ssgProxy.mjs +0 -139
  79. package/dist/shared/hooks/createHooksInternal.d.ts +0 -31
  80. package/dist/shared/hooks/createHooksInternal.d.ts.map +0 -1
  81. package/dist/shared/hooks/createHooksInternal.js +0 -543
  82. package/dist/shared/hooks/createHooksInternal.mjs +0 -522
  83. package/dist/shared/hooks/createRootHooks.d.ts +0 -2
  84. package/dist/shared/hooks/createRootHooks.d.ts.map +0 -1
  85. package/dist/shared/hooks/types.d.ts +0 -157
  86. package/dist/shared/hooks/types.d.ts.map +0 -1
  87. package/dist/shared/index.d.ts +0 -22
  88. package/dist/shared/index.d.ts.map +0 -1
  89. package/dist/shared/index.js +0 -22
  90. package/dist/shared/polymorphism/index.d.ts +0 -5
  91. package/dist/shared/polymorphism/index.d.ts.map +0 -1
  92. package/dist/shared/polymorphism/mutationLike.d.ts +0 -17
  93. package/dist/shared/polymorphism/mutationLike.d.ts.map +0 -1
  94. package/dist/shared/polymorphism/queryLike.d.ts +0 -21
  95. package/dist/shared/polymorphism/queryLike.d.ts.map +0 -1
  96. package/dist/shared/polymorphism/routerLike.d.ts +0 -11
  97. package/dist/shared/polymorphism/routerLike.d.ts.map +0 -1
  98. package/dist/shared/polymorphism/utilsLike.d.ts +0 -7
  99. package/dist/shared/polymorphism/utilsLike.d.ts.map +0 -1
  100. package/dist/shared/proxy/decorationProxy.d.ts +0 -8
  101. package/dist/shared/proxy/decorationProxy.d.ts.map +0 -1
  102. package/dist/shared/proxy/decorationProxy.js +0 -30
  103. package/dist/shared/proxy/decorationProxy.mjs +0 -28
  104. package/dist/shared/proxy/useQueriesProxy.d.ts +0 -25
  105. package/dist/shared/proxy/useQueriesProxy.d.ts.map +0 -1
  106. package/dist/shared/proxy/useQueriesProxy.js +0 -27
  107. package/dist/shared/proxy/useQueriesProxy.mjs +0 -25
  108. package/dist/shared/proxy/utilsProxy.d.ts +0 -141
  109. package/dist/shared/proxy/utilsProxy.d.ts.map +0 -1
  110. package/dist/shared/proxy/utilsProxy.js +0 -106
  111. package/dist/shared/proxy/utilsProxy.mjs +0 -102
  112. package/dist/shared/queryClient.d.ts +0 -17
  113. package/dist/shared/queryClient.d.ts.map +0 -1
  114. package/dist/shared/queryClient.js +0 -9
  115. package/dist/shared/queryClient.mjs +0 -7
  116. package/dist/shared/types.d.ts +0 -98
  117. package/dist/shared/types.d.ts.map +0 -1
  118. package/dist/utils/createUtilityFunctions.d.ts +0 -23
  119. package/dist/utils/createUtilityFunctions.d.ts.map +0 -1
  120. package/dist/utils/createUtilityFunctions.js +0 -196
  121. package/dist/utils/createUtilityFunctions.mjs +0 -194
  122. package/dist/utils/inferReactQueryProcedure.d.ts +0 -25
  123. package/dist/utils/inferReactQueryProcedure.d.ts.map +0 -1
  124. package/rsc/index.d.ts +0 -1
  125. package/rsc/index.js +0 -1
  126. package/server/index.d.ts +0 -1
  127. package/server/index.js +0 -1
  128. package/shared/index.d.ts +0 -1
  129. package/shared/index.js +0 -1
@@ -1,522 +0,0 @@
1
- import { useSuspenseInfiniteQuery, usePrefetchInfiniteQuery, useInfiniteQuery, skipToken, hashKey, useMutation, useSuspenseQueries, useQueries, useSuspenseQuery, usePrefetchQuery, useQuery } from '@tanstack/react-query';
2
- import { createTRPCClient, TRPCUntypedClient, getUntypedClient } from '@trpc/client';
3
- import { isAsyncIterable } from '@trpc/server/unstable-core-do-not-import';
4
- import * as React from 'react';
5
- import { TRPCContext } from '../../internals/context.mjs';
6
- import { getClientArgs } from '../../internals/getClientArgs.mjs';
7
- import { getQueryKeyInternal, getMutationKeyInternal } from '../../internals/getQueryKey.mjs';
8
- import { useHookResult, buildQueryFromAsyncIterable } from '../../internals/trpcResult.mjs';
9
- import { createUtilityFunctions } from '../../utils/createUtilityFunctions.mjs';
10
- import { createUseQueries } from '../proxy/useQueriesProxy.mjs';
11
-
12
- // TODO: Look into fixing react-compiler support
13
- const trackResult = (result, onTrackResult)=>{
14
- const trackedResult = new Proxy(result, {
15
- get (target, prop) {
16
- onTrackResult(prop);
17
- return target[prop];
18
- }
19
- });
20
- return trackedResult;
21
- };
22
- /**
23
- * @internal
24
- */ function createRootHooks(config) {
25
- const mutationSuccessOverride = config?.overrides?.useMutation?.onSuccess ?? ((options)=>options.originalFn());
26
- const Context = config?.context ?? TRPCContext;
27
- const createClient = createTRPCClient;
28
- const TRPCProvider = (props)=>{
29
- const { abortOnUnmount = false, queryClient, ssrContext } = props;
30
- const [ssrState, setSSRState] = React.useState(props.ssrState ?? false);
31
- const client = props.client instanceof TRPCUntypedClient ? props.client : getUntypedClient(props.client);
32
- const fns = React.useMemo(()=>createUtilityFunctions({
33
- client,
34
- queryClient
35
- }), [
36
- client,
37
- queryClient
38
- ]);
39
- const contextValue = React.useMemo(()=>({
40
- abortOnUnmount,
41
- queryClient,
42
- client,
43
- ssrContext: ssrContext ?? null,
44
- ssrState,
45
- ...fns
46
- }), [
47
- abortOnUnmount,
48
- client,
49
- fns,
50
- queryClient,
51
- ssrContext,
52
- ssrState
53
- ]);
54
- React.useEffect(()=>{
55
- // Only updating state to `mounted` if we are using SSR.
56
- // This makes it so we don't have an unnecessary re-render when opting out of SSR.
57
- setSSRState((state)=>state ? 'mounted' : false);
58
- }, []);
59
- return /*#__PURE__*/ React.createElement(Context.Provider, {
60
- value: contextValue
61
- }, props.children);
62
- };
63
- function useContext() {
64
- const context = React.useContext(Context);
65
- if (!context) {
66
- throw new Error('Unable to find tRPC Context. Did you forget to wrap your App inside `withTRPC` HoC?');
67
- }
68
- return context;
69
- }
70
- /**
71
- * Hack to make sure errors return `status`='error` when doing SSR
72
- * @see https://github.com/trpc/trpc/pull/1645
73
- */ function useSSRQueryOptionsIfNeeded(queryKey, opts) {
74
- const { queryClient, ssrState } = useContext();
75
- return ssrState && ssrState !== 'mounted' && queryClient.getQueryCache().find({
76
- queryKey
77
- })?.state.status === 'error' ? {
78
- retryOnMount: false,
79
- ...opts
80
- } : opts;
81
- }
82
- function useQuery$1(path, input, opts) {
83
- const context = useContext();
84
- const { abortOnUnmount, client, ssrState, queryClient, prefetchQuery } = context;
85
- const queryKey = getQueryKeyInternal(path, input, 'query');
86
- const defaultOpts = queryClient.getQueryDefaults(queryKey);
87
- const isInputSkipToken = input === skipToken;
88
- if (typeof window === 'undefined' && ssrState === 'prepass' && opts?.trpc?.ssr !== false && (opts?.enabled ?? defaultOpts?.enabled) !== false && !isInputSkipToken && !queryClient.getQueryCache().find({
89
- queryKey
90
- })) {
91
- void prefetchQuery(queryKey, opts);
92
- }
93
- const ssrOpts = useSSRQueryOptionsIfNeeded(queryKey, {
94
- ...defaultOpts,
95
- ...opts
96
- });
97
- const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? config?.abortOnUnmount ?? abortOnUnmount;
98
- const hook = useQuery({
99
- ...ssrOpts,
100
- queryKey: queryKey,
101
- queryFn: isInputSkipToken ? input : async (queryFunctionContext)=>{
102
- const actualOpts = {
103
- ...ssrOpts,
104
- trpc: {
105
- ...ssrOpts?.trpc,
106
- ...shouldAbortOnUnmount ? {
107
- signal: queryFunctionContext.signal
108
- } : {
109
- signal: null
110
- }
111
- }
112
- };
113
- const result = await client.query(...getClientArgs(queryKey, actualOpts));
114
- if (isAsyncIterable(result)) {
115
- return buildQueryFromAsyncIterable(result, queryClient, queryKey);
116
- }
117
- return result;
118
- }
119
- }, queryClient);
120
- hook.trpc = useHookResult({
121
- path
122
- });
123
- return hook;
124
- }
125
- function usePrefetchQuery$1(path, input, opts) {
126
- const context = useContext();
127
- const queryKey = getQueryKeyInternal(path, input, 'query');
128
- const isInputSkipToken = input === skipToken;
129
- const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? config?.abortOnUnmount ?? context.abortOnUnmount;
130
- usePrefetchQuery({
131
- ...opts,
132
- queryKey: queryKey,
133
- queryFn: isInputSkipToken ? input : (queryFunctionContext)=>{
134
- const actualOpts = {
135
- trpc: {
136
- ...opts?.trpc,
137
- ...shouldAbortOnUnmount ? {
138
- signal: queryFunctionContext.signal
139
- } : {}
140
- }
141
- };
142
- return context.client.query(...getClientArgs(queryKey, actualOpts));
143
- }
144
- });
145
- }
146
- function useSuspenseQuery$1(path, input, opts) {
147
- const context = useContext();
148
- const queryKey = getQueryKeyInternal(path, input, 'query');
149
- const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? config?.abortOnUnmount ?? context.abortOnUnmount;
150
- const hook = useSuspenseQuery({
151
- ...opts,
152
- queryKey: queryKey,
153
- queryFn: (queryFunctionContext)=>{
154
- const actualOpts = {
155
- ...opts,
156
- trpc: {
157
- ...opts?.trpc,
158
- ...shouldAbortOnUnmount ? {
159
- signal: queryFunctionContext.signal
160
- } : {
161
- signal: null
162
- }
163
- }
164
- };
165
- return context.client.query(...getClientArgs(queryKey, actualOpts));
166
- }
167
- }, context.queryClient);
168
- hook.trpc = useHookResult({
169
- path
170
- });
171
- return [
172
- hook.data,
173
- hook
174
- ];
175
- }
176
- function useMutation$1(path, opts) {
177
- const { client, queryClient } = useContext();
178
- const mutationKey = getMutationKeyInternal(path);
179
- const defaultOpts = queryClient.defaultMutationOptions(queryClient.getMutationDefaults(mutationKey));
180
- const hook = useMutation({
181
- ...opts,
182
- mutationKey: mutationKey,
183
- mutationFn: (input)=>{
184
- return client.mutation(...getClientArgs([
185
- path,
186
- {
187
- input
188
- }
189
- ], opts));
190
- },
191
- onSuccess (...args) {
192
- const originalFn = ()=>opts?.onSuccess?.(...args) ?? defaultOpts?.onSuccess?.(...args);
193
- return mutationSuccessOverride({
194
- originalFn,
195
- queryClient,
196
- meta: opts?.meta ?? defaultOpts?.meta ?? {}
197
- });
198
- }
199
- }, queryClient);
200
- hook.trpc = useHookResult({
201
- path
202
- });
203
- return hook;
204
- }
205
- const initialStateIdle = {
206
- data: undefined,
207
- error: null,
208
- status: 'idle'
209
- };
210
- const initialStateConnecting = {
211
- data: undefined,
212
- error: null,
213
- status: 'connecting'
214
- };
215
- /* istanbul ignore next -- @preserve */ function useSubscription(path, input, opts) {
216
- const enabled = opts?.enabled ?? input !== skipToken;
217
- const queryKey = hashKey(getQueryKeyInternal(path, input, 'any'));
218
- const { client } = useContext();
219
- const optsRef = React.useRef(opts);
220
- React.useEffect(()=>{
221
- optsRef.current = opts;
222
- });
223
- const [trackedProps] = React.useState(new Set([]));
224
- const addTrackedProp = React.useCallback((key)=>{
225
- trackedProps.add(key);
226
- }, [
227
- trackedProps
228
- ]);
229
- const currentSubscriptionRef = React.useRef(null);
230
- const updateState = React.useCallback((callback)=>{
231
- const prev = resultRef.current;
232
- const next = resultRef.current = callback(prev);
233
- let shouldUpdate = false;
234
- for (const key of trackedProps){
235
- if (prev[key] !== next[key]) {
236
- shouldUpdate = true;
237
- break;
238
- }
239
- }
240
- if (shouldUpdate) {
241
- setState(trackResult(next, addTrackedProp));
242
- }
243
- }, [
244
- addTrackedProp,
245
- trackedProps
246
- ]);
247
- const reset = React.useCallback(()=>{
248
- // unsubscribe from the previous subscription
249
- currentSubscriptionRef.current?.unsubscribe();
250
- if (!enabled) {
251
- updateState(()=>({
252
- ...initialStateIdle,
253
- reset
254
- }));
255
- return;
256
- }
257
- updateState(()=>({
258
- ...initialStateConnecting,
259
- reset
260
- }));
261
- const subscription = client.subscription(path.join('.'), input ?? undefined, {
262
- onStarted: ()=>{
263
- optsRef.current.onStarted?.();
264
- updateState((prev)=>({
265
- ...prev,
266
- status: 'pending',
267
- error: null
268
- }));
269
- },
270
- onData: (data)=>{
271
- optsRef.current.onData?.(data);
272
- updateState((prev)=>({
273
- ...prev,
274
- status: 'pending',
275
- data,
276
- error: null
277
- }));
278
- },
279
- onError: (error)=>{
280
- optsRef.current.onError?.(error);
281
- updateState((prev)=>({
282
- ...prev,
283
- status: 'error',
284
- error
285
- }));
286
- },
287
- onConnectionStateChange: (result)=>{
288
- updateState((prev)=>{
289
- switch(result.state){
290
- case 'idle':
291
- return {
292
- ...prev,
293
- status: result.state,
294
- error: null,
295
- data: undefined
296
- };
297
- case 'connecting':
298
- return {
299
- ...prev,
300
- error: result.error,
301
- status: result.state
302
- };
303
- case 'pending':
304
- // handled when data is / onStarted
305
- return prev;
306
- }
307
- });
308
- },
309
- onComplete: ()=>{
310
- optsRef.current.onComplete?.();
311
- // In the case of WebSockets, the connection might not be idle so `onConnectionStateChange` will not be called until the connection is closed.
312
- // In this case, we need to set the state to idle manually.
313
- updateState((prev)=>({
314
- ...prev,
315
- status: 'idle',
316
- error: null,
317
- data: undefined
318
- }));
319
- // (We might want to add a `connectionState` to the state to track the connection state separately)
320
- }
321
- });
322
- currentSubscriptionRef.current = subscription;
323
- // eslint-disable-next-line react-hooks/exhaustive-deps
324
- }, [
325
- client,
326
- queryKey,
327
- enabled,
328
- updateState
329
- ]);
330
- React.useEffect(()=>{
331
- reset();
332
- return ()=>{
333
- currentSubscriptionRef.current?.unsubscribe();
334
- };
335
- }, [
336
- reset
337
- ]);
338
- const resultRef = React.useRef(enabled ? {
339
- ...initialStateConnecting,
340
- reset
341
- } : {
342
- ...initialStateIdle,
343
- reset
344
- });
345
- const [state, setState] = React.useState(trackResult(resultRef.current, addTrackedProp));
346
- return state;
347
- }
348
- function useInfiniteQuery$1(path, input, opts) {
349
- const { client, ssrState, prefetchInfiniteQuery, queryClient, abortOnUnmount } = useContext();
350
- const queryKey = getQueryKeyInternal(path, input, 'infinite');
351
- const defaultOpts = queryClient.getQueryDefaults(queryKey);
352
- const isInputSkipToken = input === skipToken;
353
- if (typeof window === 'undefined' && ssrState === 'prepass' && opts?.trpc?.ssr !== false && (opts?.enabled ?? defaultOpts?.enabled) !== false && !isInputSkipToken && !queryClient.getQueryCache().find({
354
- queryKey
355
- })) {
356
- void prefetchInfiniteQuery(queryKey, {
357
- ...defaultOpts,
358
- ...opts
359
- });
360
- }
361
- const ssrOpts = useSSRQueryOptionsIfNeeded(queryKey, {
362
- ...defaultOpts,
363
- ...opts
364
- });
365
- // request option should take priority over global
366
- const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? abortOnUnmount;
367
- const hook = useInfiniteQuery({
368
- ...ssrOpts,
369
- initialPageParam: opts.initialCursor ?? null,
370
- persister: opts.persister,
371
- queryKey: queryKey,
372
- queryFn: isInputSkipToken ? input : (queryFunctionContext)=>{
373
- const actualOpts = {
374
- ...ssrOpts,
375
- trpc: {
376
- ...ssrOpts?.trpc,
377
- ...shouldAbortOnUnmount ? {
378
- signal: queryFunctionContext.signal
379
- } : {
380
- signal: null
381
- }
382
- }
383
- };
384
- return client.query(...getClientArgs(queryKey, actualOpts, {
385
- pageParam: queryFunctionContext.pageParam ?? opts.initialCursor,
386
- direction: queryFunctionContext.direction
387
- }));
388
- }
389
- }, queryClient);
390
- hook.trpc = useHookResult({
391
- path
392
- });
393
- return hook;
394
- }
395
- function usePrefetchInfiniteQuery$1(path, input, opts) {
396
- const context = useContext();
397
- const queryKey = getQueryKeyInternal(path, input, 'infinite');
398
- const defaultOpts = context.queryClient.getQueryDefaults(queryKey);
399
- const isInputSkipToken = input === skipToken;
400
- const ssrOpts = useSSRQueryOptionsIfNeeded(queryKey, {
401
- ...defaultOpts,
402
- ...opts
403
- });
404
- // request option should take priority over global
405
- const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? context.abortOnUnmount;
406
- usePrefetchInfiniteQuery({
407
- ...opts,
408
- initialPageParam: opts.initialCursor ?? null,
409
- queryKey,
410
- queryFn: isInputSkipToken ? input : (queryFunctionContext)=>{
411
- const actualOpts = {
412
- ...ssrOpts,
413
- trpc: {
414
- ...ssrOpts?.trpc,
415
- ...shouldAbortOnUnmount ? {
416
- signal: queryFunctionContext.signal
417
- } : {}
418
- }
419
- };
420
- return context.client.query(...getClientArgs(queryKey, actualOpts, {
421
- pageParam: queryFunctionContext.pageParam ?? opts.initialCursor,
422
- direction: queryFunctionContext.direction
423
- }));
424
- }
425
- });
426
- }
427
- function useSuspenseInfiniteQuery$1(path, input, opts) {
428
- const context = useContext();
429
- const queryKey = getQueryKeyInternal(path, input, 'infinite');
430
- const defaultOpts = context.queryClient.getQueryDefaults(queryKey);
431
- const ssrOpts = useSSRQueryOptionsIfNeeded(queryKey, {
432
- ...defaultOpts,
433
- ...opts
434
- });
435
- // request option should take priority over global
436
- const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? context.abortOnUnmount;
437
- const hook = useSuspenseInfiniteQuery({
438
- ...opts,
439
- initialPageParam: opts.initialCursor ?? null,
440
- queryKey,
441
- queryFn: (queryFunctionContext)=>{
442
- const actualOpts = {
443
- ...ssrOpts,
444
- trpc: {
445
- ...ssrOpts?.trpc,
446
- ...shouldAbortOnUnmount ? {
447
- signal: queryFunctionContext.signal
448
- } : {}
449
- }
450
- };
451
- return context.client.query(...getClientArgs(queryKey, actualOpts, {
452
- pageParam: queryFunctionContext.pageParam ?? opts.initialCursor,
453
- direction: queryFunctionContext.direction
454
- }));
455
- }
456
- }, context.queryClient);
457
- hook.trpc = useHookResult({
458
- path
459
- });
460
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
461
- return [
462
- hook.data,
463
- hook
464
- ];
465
- }
466
- const useQueries$1 = (queriesCallback, options)=>{
467
- const { ssrState, queryClient, prefetchQuery, client } = useContext();
468
- const proxy = createUseQueries(client);
469
- const queries = queriesCallback(proxy);
470
- if (typeof window === 'undefined' && ssrState === 'prepass') {
471
- for (const query of queries){
472
- const queryOption = query;
473
- if (queryOption.trpc?.ssr !== false && !queryClient.getQueryCache().find({
474
- queryKey: queryOption.queryKey
475
- })) {
476
- void prefetchQuery(queryOption.queryKey, queryOption);
477
- }
478
- }
479
- }
480
- return useQueries({
481
- queries: queries.map((query)=>({
482
- ...query,
483
- queryKey: query.queryKey
484
- })),
485
- combine: options?.combine
486
- }, queryClient);
487
- };
488
- const useSuspenseQueries$1 = (queriesCallback)=>{
489
- const { queryClient, client } = useContext();
490
- const proxy = createUseQueries(client);
491
- const queries = queriesCallback(proxy);
492
- const hook = useSuspenseQueries({
493
- queries: queries.map((query)=>({
494
- ...query,
495
- queryFn: query.queryFn,
496
- queryKey: query.queryKey
497
- }))
498
- }, queryClient);
499
- return [
500
- hook.map((h)=>h.data),
501
- hook
502
- ];
503
- };
504
- return {
505
- Provider: TRPCProvider,
506
- createClient,
507
- useContext,
508
- useUtils: useContext,
509
- useQuery: useQuery$1,
510
- usePrefetchQuery: usePrefetchQuery$1,
511
- useSuspenseQuery: useSuspenseQuery$1,
512
- useQueries: useQueries$1,
513
- useSuspenseQueries: useSuspenseQueries$1,
514
- useMutation: useMutation$1,
515
- useSubscription,
516
- useInfiniteQuery: useInfiniteQuery$1,
517
- usePrefetchInfiniteQuery: usePrefetchInfiniteQuery$1,
518
- useSuspenseInfiniteQuery: useSuspenseInfiniteQuery$1
519
- };
520
- }
521
-
522
- export { createRootHooks };
@@ -1,2 +0,0 @@
1
- export { createRootHooks } from './createHooksInternal';
2
- //# sourceMappingURL=createRootHooks.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createRootHooks.d.ts","sourceRoot":"","sources":["../../../src/shared/hooks/createRootHooks.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC"}
@@ -1,157 +0,0 @@
1
- import type { DefinedUseQueryResult, FetchInfiniteQueryOptions, FetchQueryOptions, InfiniteData, InfiniteQueryObserverSuccessResult, InitialDataFunction, QueryObserverSuccessResult, QueryOptions, UseBaseQueryOptions, UseInfiniteQueryOptions, UseInfiniteQueryResult, UseMutationOptions, UseMutationResult, UseQueryResult, UseSuspenseInfiniteQueryOptions, UseSuspenseInfiniteQueryResult, UseSuspenseQueryOptions, UseSuspenseQueryResult } from '@tanstack/react-query';
2
- import type { CreateTRPCClientOptions, TRPCClient, TRPCRequestOptions, TRPCUntypedClient } from '@trpc/client';
3
- import type { AnyRouter, coerceAsyncIterableToArray, DistributiveOmit } from '@trpc/server/unstable-core-do-not-import';
4
- import type { JSX, ReactNode } from 'react';
5
- import type { TRPCContextProps } from '../../internals/context';
6
- import type { TRPCQueryKey } from '../../internals/getQueryKey';
7
- export type OutputWithCursor<TData, TCursor = any> = {
8
- cursor: TCursor | null;
9
- data: TData;
10
- };
11
- export interface TRPCReactRequestOptions extends Omit<TRPCRequestOptions, 'signal'> {
12
- /**
13
- * Opt out of SSR for this query by passing `ssr: false`
14
- */
15
- ssr?: boolean;
16
- /**
17
- * Opt out or into aborting request on unmount
18
- */
19
- abortOnUnmount?: boolean;
20
- }
21
- export interface TRPCUseQueryBaseOptions {
22
- /**
23
- * tRPC-related options
24
- */
25
- trpc?: TRPCReactRequestOptions;
26
- }
27
- export interface UseTRPCQueryOptions<TOutput, TData, TError, TQueryOptsData = TOutput> extends DistributiveOmit<UseBaseQueryOptions<TOutput, TError, TData, TQueryOptsData, any>, 'queryKey'>, TRPCUseQueryBaseOptions {
28
- }
29
- export interface UseTRPCSuspenseQueryOptions<TOutput, TData, TError> extends DistributiveOmit<UseSuspenseQueryOptions<TOutput, TError, TData, any>, 'queryKey'>, TRPCUseQueryBaseOptions {
30
- }
31
- export interface UseTRPCPrefetchQueryOptions<TOutput, TData, TError> extends DistributiveOmit<FetchQueryOptions<TOutput, TError, TData, any>, 'queryKey'>, TRPCUseQueryBaseOptions {
32
- }
33
- /** @internal **/
34
- export interface DefinedUseTRPCQueryOptions<TOutput, TData, TError, TQueryOptsData = TOutput> extends DistributiveOmit<UseTRPCQueryOptions<TOutput, TData, TError, TQueryOptsData>, 'queryKey'> {
35
- initialData: InitialDataFunction<TQueryOptsData> | TQueryOptsData;
36
- }
37
- export interface TRPCQueryOptions<TData, TError> extends DistributiveOmit<QueryOptions<TData, TError, TData, any>, 'queryKey'>, TRPCUseQueryBaseOptions {
38
- queryKey: TRPCQueryKey;
39
- }
40
- export type ExtractCursorType<TInput> = TInput extends {
41
- cursor?: any;
42
- } ? TInput['cursor'] : unknown;
43
- export interface UseTRPCInfiniteQueryOptions<TInput, TOutput, TError> extends DistributiveOmit<UseInfiniteQueryOptions<TOutput, TError, TOutput, any, ExtractCursorType<TInput>>, 'queryKey' | 'initialPageParam'>, TRPCUseQueryBaseOptions {
44
- initialCursor?: ExtractCursorType<TInput>;
45
- }
46
- export type UseTRPCPrefetchInfiniteQueryOptions<TInput, TOutput, TError> = DistributiveOmit<FetchInfiniteQueryOptions<TOutput, TError, TOutput, any, ExtractCursorType<TInput>>, 'queryKey' | 'initialPageParam'> & TRPCUseQueryBaseOptions & {
47
- initialCursor?: ExtractCursorType<TInput>;
48
- };
49
- export interface UseTRPCSuspenseInfiniteQueryOptions<TInput, TOutput, TError> extends DistributiveOmit<UseSuspenseInfiniteQueryOptions<TOutput, TError, TOutput, any, ExtractCursorType<TInput>>, 'queryKey' | 'initialPageParam'>, TRPCUseQueryBaseOptions {
50
- initialCursor?: ExtractCursorType<TInput>;
51
- }
52
- export interface UseTRPCMutationOptions<TInput, TError, TOutput, TContext = unknown> extends UseMutationOptions<TOutput, TError, TInput, TContext>, TRPCUseQueryBaseOptions {
53
- }
54
- export interface UseTRPCSubscriptionOptions<TOutput, TError> {
55
- /**
56
- * @deprecated
57
- * use a `skipToken` from `@tanstack/react-query` instead
58
- * this will be removed in v12
59
- */
60
- enabled?: boolean;
61
- /**
62
- * Called when the subscription is started
63
- */
64
- onStarted?: () => void;
65
- /**
66
- * Called when new data is received
67
- */
68
- onData?: (data: TOutput) => void;
69
- /**
70
- * Called when an **unrecoverable error** occurs and the subscription is closed
71
- */
72
- onError?: (err: TError) => void;
73
- /**
74
- * Called when the subscription is completed on the server
75
- */
76
- onComplete?: () => void;
77
- }
78
- export interface TRPCSubscriptionBaseResult<TOutput, TError> {
79
- status: 'idle' | 'connecting' | 'pending' | 'error';
80
- data: undefined | TOutput;
81
- error: null | TError;
82
- /**
83
- * Reset the subscription
84
- */
85
- reset: () => void;
86
- }
87
- export interface TRPCSubscriptionIdleResult<TOutput> extends TRPCSubscriptionBaseResult<TOutput, null> {
88
- status: 'idle';
89
- data: undefined;
90
- error: null;
91
- }
92
- export interface TRPCSubscriptionConnectingResult<TOutput, TError> extends TRPCSubscriptionBaseResult<TOutput, TError> {
93
- status: 'connecting';
94
- data: undefined | TOutput;
95
- error: TError | null;
96
- }
97
- export interface TRPCSubscriptionPendingResult<TOutput> extends TRPCSubscriptionBaseResult<TOutput, undefined> {
98
- status: 'pending';
99
- data: TOutput | undefined;
100
- error: null;
101
- }
102
- export interface TRPCSubscriptionErrorResult<TOutput, TError> extends TRPCSubscriptionBaseResult<TOutput, TError> {
103
- status: 'error';
104
- data: TOutput | undefined;
105
- error: TError;
106
- }
107
- export type TRPCSubscriptionResult<TOutput, TError> = TRPCSubscriptionIdleResult<TOutput> | TRPCSubscriptionConnectingResult<TOutput, TError> | TRPCSubscriptionErrorResult<TOutput, TError> | TRPCSubscriptionPendingResult<TOutput>;
108
- export interface TRPCProviderProps<TRouter extends AnyRouter, TSSRContext> extends Omit<TRPCContextProps<TRouter, TSSRContext>, 'client'> {
109
- children: ReactNode;
110
- client: TRPCClient<TRouter> | TRPCUntypedClient<TRouter>;
111
- }
112
- export type TRPCProvider<TRouter extends AnyRouter, TSSRContext> = (props: TRPCProviderProps<TRouter, TSSRContext>) => JSX.Element;
113
- export type CreateClient<TRouter extends AnyRouter> = (opts: CreateTRPCClientOptions<TRouter>) => TRPCUntypedClient<TRouter>;
114
- /**
115
- * @internal
116
- */
117
- export type UseTRPCQueryResult<TData, TError> = TRPCHookResult & UseQueryResult<coerceAsyncIterableToArray<TData>, TError>;
118
- /**
119
- * @internal
120
- */
121
- export type DefinedUseTRPCQueryResult<TData, TError> = DefinedUseQueryResult<TData, TError> & TRPCHookResult;
122
- /**
123
- * @internal
124
- */
125
- export type UseTRPCQuerySuccessResult<TData, TError> = QueryObserverSuccessResult<TData, TError> & TRPCHookResult;
126
- /**
127
- * @internal
128
- */
129
- export type UseTRPCSuspenseQueryResult<TData, TError> = [
130
- TData,
131
- UseSuspenseQueryResult<TData, TError> & TRPCHookResult
132
- ];
133
- /**
134
- * @internal
135
- */
136
- export type UseTRPCInfiniteQueryResult<TData, TError, TInput> = TRPCHookResult & UseInfiniteQueryResult<InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TError>;
137
- /**
138
- * @internal
139
- */
140
- export type UseTRPCInfiniteQuerySuccessResult<TData, TError, TInput> = InfiniteQueryObserverSuccessResult<InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TError> & TRPCHookResult;
141
- /**
142
- * @internal
143
- */
144
- export type UseTRPCSuspenseInfiniteQueryResult<TData, TError, TInput> = [
145
- InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
146
- UseSuspenseInfiniteQueryResult<InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TError> & TRPCHookResult
147
- ];
148
- /**
149
- * @internal
150
- */
151
- export type UseTRPCMutationResult<TData, TError, TVariables, TContext> = TRPCHookResult & UseMutationResult<TData, TError, TVariables, TContext>;
152
- export interface TRPCHookResult {
153
- trpc: {
154
- path: string;
155
- };
156
- }
157
- //# sourceMappingURL=types.d.ts.map