react-query-kit 2.0.5 → 2.0.6-beta.0

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.
@@ -1 +1,83 @@
1
- import{useQueryClient as e,useQuery as t,useInfiniteQuery as r,useMutation as a}from"@tanstack/react-query";const n=(t,r,a)=>function(n,u){const[i,s]=[e(null!=n&&n.context?n:u).getDefaultOptions()[a],r,n].reduce((([e,t],{use:r=[],...a}={})=>[[...e,...r],{...t,...a}]),[[]]);let y=t;for(let e=i.length;e--;)y=i[e](y);return y(s,u)},u={enabled:!0,suspense:!0,throwOnError:!0,useErrorBoundary:!0},i=(e,t)=>void 0===t?[e]:[e,t],s=(e,t,r)=>{const{primaryKey:a,queryFn:u,queryKeyHashFn:s,getPreviousPageParam:y,getNextPageParam:o,initialPageParam:g}=e,P=e=>i(a,e);return Object.assign(n(((e,a)=>t({...e,...r,queryKey:P(e.variables)},a)),e,"queries"),{getPrimaryKey:()=>a,getKey:P,queryFn:u,queryKeyHashFn:s,getOptions:t=>({...e,queryKey:P(t)}),getFetchOptions:e=>({queryKey:P(e),queryFn:u,queryKeyHashFn:s,getPreviousPageParam:y,getNextPageParam:o,initialPageParam:g})})},y=e=>s(e,t),o=e=>s(e,t,u),g=e=>s(e,r),P=e=>s(e,r,u),m=e=>Object.assign(n(a,e,"mutations"),{getKey:()=>e.mutationKey,mutationFn:e.mutationFn});export{g as createInfiniteQuery,m as createMutation,y as createQuery,P as createSuspenseInfiniteQuery,o as createSuspenseQuery,i as getKey};
1
+ import {
2
+ useInfiniteQuery as a,
3
+ useQueryClient as e,
4
+ useMutation as n,
5
+ useQuery as r,
6
+ useSuspenseQuery as t,
7
+ } from '@tanstack/react-query'
8
+
9
+ const u = (t, r, a) =>
10
+ function (n, u) {
11
+ const [s, i] = [
12
+ e(null != n && n.context ? n : u).getDefaultOptions()[a],
13
+ r,
14
+ n,
15
+ ].reduce(
16
+ ([e, t], { use: r = [], ...a } = {}) => [[...e, ...r], { ...t, ...a }],
17
+ [[]]
18
+ )
19
+ let y = t
20
+ for (let e = s.length; e--; ) y = s[e](y)
21
+ return y(i, u)
22
+ },
23
+ s = (e, t) => (void 0 === t ? [e] : [e, t]),
24
+ i = (e, r) => {
25
+ const {
26
+ primaryKey: a,
27
+ queryFn: n,
28
+ queryKeyHashFn: i,
29
+ getPreviousPageParam: y,
30
+ getNextPageParam: o,
31
+ initialPageParam: g,
32
+ } = e,
33
+ P = e => s(a, e)
34
+ return Object.assign(
35
+ u(
36
+ (e, a) =>
37
+ r(
38
+ {
39
+ ...e,
40
+ ...(e.suspense &&
41
+ !!t && {
42
+ enabled: !0,
43
+ suspense: !0,
44
+ throwOnError: !0,
45
+ useErrorBoundary: !0,
46
+ }),
47
+ queryKey: P(e.variables),
48
+ },
49
+ a
50
+ ),
51
+ e,
52
+ 'queries'
53
+ ),
54
+ {
55
+ getPrimaryKey: () => a,
56
+ getKey: P,
57
+ queryFn: n,
58
+ queryKeyHashFn: i,
59
+ getOptions: t => ({ ...e, queryKey: P(t) }),
60
+ getFetchOptions: e => ({
61
+ queryKey: P(e),
62
+ queryFn: n,
63
+ queryKeyHashFn: i,
64
+ getPreviousPageParam: y,
65
+ getNextPageParam: o,
66
+ initialPageParam: g,
67
+ }),
68
+ }
69
+ )
70
+ },
71
+ y = e => i(e, r),
72
+ o = e => i(e, a),
73
+ g = e =>
74
+ Object.assign(u(n, e, 'mutations'), {
75
+ getKey: () => e.mutationKey,
76
+ mutationFn: e.mutationFn,
77
+ })
78
+ export {
79
+ o as createInfiniteQuery,
80
+ g as createMutation,
81
+ y as createQuery,
82
+ s as getKey,
83
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-query-kit",
3
- "version": "2.0.5",
3
+ "version": "2.0.6-beta.0",
4
4
  "description": "🕊️ A toolkit for ReactQuery that make ReactQuery hooks more reusable and typesafe",
5
5
  "author": "liaoliao666",
6
6
  "repository": "liaoliao666/react-query-kit",
@@ -27,7 +27,7 @@
27
27
  "@rollup/plugin-commonjs": "^22.0.2",
28
28
  "@rollup/plugin-node-resolve": "^13.2.1",
29
29
  "@rollup/plugin-replace": "^4.0.0",
30
- "@tanstack/react-query": "^5.0.0-beta.20",
30
+ "@tanstack/react-query": "^5.0.0-rc.12",
31
31
  "@testing-library/jest-dom": "^5.16.5",
32
32
  "@testing-library/react": "^14.0.0",
33
33
  "@trivago/prettier-plugin-sort-imports": "^4.2.0",
@@ -5,7 +5,7 @@ import type {
5
5
  } from '@tanstack/react-query'
6
6
 
7
7
  import type { AdditionalQueryOptions, Middleware } from './types'
8
- import { getKey as getQueryKey, withMiddleware } from './utils'
8
+ import { getKey as getQueryKey, isV5, withMiddleware } from './utils'
9
9
 
10
10
  interface CreateBaseQueryOptions
11
11
  extends Omit<UseInfiniteQueryOptions, 'queryKey' | 'queryFn'>,
@@ -21,29 +21,11 @@ type QueryBaseHookOptions = Omit<
21
21
  variables?: any
22
22
  }
23
23
 
24
- const existedPrimaryKeys = new Set<string>()
25
-
26
24
  export const createBaseQuery = (
27
25
  defaultOptions: any,
28
- useRQHook: (options: any, queryClient?: any) => any,
29
- overrideOptions?: QueryBaseHookOptions
26
+ useRQHook: (options: any, queryClient?: any) => any
30
27
  ): any => {
31
- const {
32
- primaryKey,
33
- queryFn,
34
- queryKeyHashFn,
35
- getPreviousPageParam,
36
- getNextPageParam,
37
- initialPageParam,
38
- } = defaultOptions as CreateBaseQueryOptions
39
-
40
28
  if (process.env.NODE_ENV !== 'production') {
41
- if (existedPrimaryKeys.has(primaryKey)) {
42
- console.error(`[Bug] Duplicated primaryKey: ${primaryKey}`)
43
- } else {
44
- existedPrimaryKeys.add(primaryKey)
45
- }
46
-
47
29
  // @ts-ignore
48
30
  if (defaultOptions.useDefaultOptions) {
49
31
  console.error(
@@ -52,6 +34,15 @@ export const createBaseQuery = (
52
34
  }
53
35
  }
54
36
 
37
+ const {
38
+ primaryKey,
39
+ queryFn,
40
+ queryKeyHashFn,
41
+ getPreviousPageParam,
42
+ getNextPageParam,
43
+ initialPageParam,
44
+ } = defaultOptions as CreateBaseQueryOptions
45
+
55
46
  const getPrimaryKey = () => primaryKey
56
47
 
57
48
  const getKey = (variables?: any) => getQueryKey(primaryKey, variables)
@@ -81,7 +72,14 @@ export const createBaseQuery = (
81
72
  return useRQHook(
82
73
  {
83
74
  ...options,
84
- ...overrideOptions,
75
+ ...(options.suspense &&
76
+ isV5() && {
77
+ enabled: true,
78
+ suspense: true,
79
+ throwOnError: true,
80
+ // Compatible with ReactQuery v4
81
+ useErrorBoundary: true,
82
+ }),
85
83
  queryKey: getKey(options.variables),
86
84
  },
87
85
  queryClient
package/src/index.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  export * from './createQuery'
2
- export * from './createSuspenseQuery'
3
2
  export * from './createInfiniteQuery'
4
- export * from './createSuspenseInfiniteQuery'
5
3
  export * from './createMutation'
6
4
  export * from './types'
7
5
  export { getKey } from './utils'
package/src/types.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type {
2
+ DefinedUseQueryResult,
2
3
  GetNextPageParamFunction,
3
4
  GetPreviousPageParamFunction,
4
5
  InfiniteData,
@@ -54,6 +55,11 @@ type CompatibleInfiniteQueryPageParamsOptions<
54
55
  }
55
56
  >
56
57
 
58
+ type CompatibleInfiniteData<TFnData, TPageParam> = CompatibleWithV4<
59
+ InfiniteData<TFnData, TPageParam>,
60
+ InfiniteData<TFnData>
61
+ >
62
+
57
63
  type CompatibleUseInfiniteQueryOptions<
58
64
  TFnData,
59
65
  TVariables,
@@ -78,11 +84,22 @@ type CompatibleUseInfiniteQueryOptions<
78
84
  >
79
85
  >
80
86
 
87
+ type NonUndefinedGuard<T> = T extends undefined ? never : T
88
+
89
+ type WithRequired<T, K extends keyof T> = T & {
90
+ [_ in K]: Record<string, never>
91
+ }
92
+
81
93
  export type inferQueryKey<TVariables> = TVariables extends void
82
94
  ? [string]
83
95
  : [string, TVariables]
84
96
 
85
- export type AdditionalQueryOptions<TFnData, TVariables, TPageParam = never> = {
97
+ export type AdditionalQueryOptions<
98
+ TFnData,
99
+ TVariables,
100
+ TError = Error,
101
+ TPageParam = never
102
+ > = {
86
103
  primaryKey: string
87
104
  queryFn: CompatibleQueryFunction<
88
105
  TFnData,
@@ -90,6 +107,9 @@ export type AdditionalQueryOptions<TFnData, TVariables, TPageParam = never> = {
90
107
  TPageParam
91
108
  >
92
109
  variables?: TVariables
110
+ use?: [TPageParam] extends [never]
111
+ ? Middleware<QueryHook<TFnData, TVariables, TError>>[]
112
+ : Middleware<InfiniteQueryHook<TFnData, TVariables, TError, TPageParam>>[]
93
113
  }
94
114
 
95
115
  type inferMiddlewareHook<T extends (...args: any) => any> = (
@@ -154,58 +174,27 @@ export interface CreateQueryOptions<
154
174
  UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TVariables>>,
155
175
  'queryKey' | 'queryFn' | 'select'
156
176
  >,
157
- AdditionalQueryOptions<TFnData, TVariables> {
158
- use?: Middleware<QueryHook<TFnData, TVariables, TError>>[]
159
- variables?: TVariables
160
- }
177
+ AdditionalQueryOptions<TFnData, TVariables> {}
161
178
 
162
179
  export interface QueryHookOptions<TFnData, TError, TData, TVariables>
163
180
  extends Omit<
164
- UseQueryOptions<TFnData, TError, TData, inferQueryKey<TVariables>>,
165
- 'queryKey' | 'queryFn' | 'queryKeyHashFn'
181
+ AdditionalQueryOptions<TFnData, TVariables, TFnData> &
182
+ UseQueryOptions<TFnData, TError, TData, inferQueryKey<TVariables>>,
183
+ 'primaryKey' | 'queryKey' | 'queryFn' | 'queryKeyHashFn'
166
184
  > {
167
- use?: Middleware<QueryHook<TFnData, TVariables, TError>>[]
168
- variables?: TVariables
185
+ suspense?: undefined
169
186
  }
170
187
 
171
- export type QueryHookResult<TData, TError> = UseQueryResult<TData, TError>
172
-
173
- export interface QueryHook<TFnData = unknown, TVariables = any, TError = Error>
174
- extends ExposeMethods<TFnData, TVariables> {
175
- <TData = TFnData>(
176
- options?: QueryHookOptions<TFnData, TError, TData, TVariables>,
177
- queryClient?: CompatibleWithV4<QueryClient, void>
178
- ): QueryHookResult<TData, TError>
179
- }
180
-
181
- // suspense query hook
182
-
183
- export interface CreateSuspenseQueryOptions<
184
- TFnData = unknown,
185
- TVariables = void,
186
- TError = Error
187
- > extends Omit<
188
- UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TVariables>>,
189
- | 'queryKey'
190
- | 'queryFn'
191
- | 'enabled'
192
- | 'select'
193
- | 'suspense'
194
- | 'throwOnError'
195
- | 'placeholderData'
196
- | 'keepPreviousData'
197
- | 'useErrorBoundary'
198
- >,
199
- AdditionalQueryOptions<TFnData, TVariables> {
200
- use?: Middleware<SuspenseQueryHook<TFnData, TVariables, TVariables>>[]
188
+ export type DefinedQueryHookOptions<TFnData, TError, TData, TVariables> = Omit<
189
+ QueryHookOptions<TFnData, TError, TData, TVariables>,
190
+ 'initialData'
191
+ > & {
192
+ initialData: NonUndefinedGuard<TFnData> | (() => NonUndefinedGuard<TFnData>)
201
193
  }
202
194
 
203
195
  export interface SuspenseQueryHookOptions<TFnData, TError, TData, TVariables>
204
196
  extends Omit<
205
- UseQueryOptions<TFnData, TError, TData, inferQueryKey<TVariables>>,
206
- | 'queryKey'
207
- | 'queryFn'
208
- | 'queryKeyHashFn'
197
+ QueryHookOptions<TFnData, TError, TData, TVariables>,
209
198
  | 'enabled'
210
199
  | 'suspense'
211
200
  | 'throwOnError'
@@ -213,22 +202,33 @@ export interface SuspenseQueryHookOptions<TFnData, TError, TData, TVariables>
213
202
  | 'keepPreviousData'
214
203
  | 'useErrorBoundary'
215
204
  > {
216
- use?: Middleware<SuspenseQueryHook<TFnData, TVariables, TVariables>>[]
217
- variables?: TVariables
205
+ suspense: true
218
206
  }
219
207
 
208
+ export type QueryHookResult<TData, TError> = UseQueryResult<TData, TError>
209
+
220
210
  export type SuspenseQueryHookResult<TData, TError> = Omit<
221
211
  QueryObserverSuccessResult<TData, TError>,
222
212
  'isPlaceholderData' | 'isPreviousData'
223
213
  >
224
214
 
225
- export interface SuspenseQueryHook<
226
- TFnData = unknown,
227
- TVariables = void,
228
- TError = Error
229
- > extends ExposeMethods<TFnData, TVariables> {
215
+ export type DefinedQueryHookResult<TData, TError> = DefinedUseQueryResult<
216
+ TData,
217
+ TError
218
+ >
219
+
220
+ export interface QueryHook<TFnData = unknown, TVariables = any, TError = Error>
221
+ extends ExposeMethods<TFnData, TVariables> {
222
+ <TData = TFnData>(
223
+ options: DefinedQueryHookOptions<TFnData, TError, TData, TVariables>,
224
+ queryClient?: CompatibleWithV4<QueryClient, void>
225
+ ): DefinedQueryHookResult<TData, TError>
230
226
  <TData = TFnData>(
231
- options?: SuspenseQueryHookOptions<TFnData, TError, TData, TVariables>,
227
+ options?: QueryHookOptions<TFnData, TError, TData, TVariables>,
228
+ queryClient?: CompatibleWithV4<QueryClient, void>
229
+ ): QueryHookResult<TData, TError>
230
+ <TData = TFnData>(
231
+ options: SuspenseQueryHookOptions<TFnData, TError, TData, TVariables>,
232
232
  queryClient?: CompatibleWithV4<QueryClient, void>
233
233
  ): SuspenseQueryHookResult<TData, TError>
234
234
  }
@@ -250,9 +250,7 @@ export interface CreateInfiniteQueryOptions<
250
250
  >,
251
251
  'queryKey' | 'queryFn' | 'select'
252
252
  >,
253
- AdditionalQueryOptions<TFnData, TVariables, TPageParam> {
254
- use?: Middleware<InfiniteQueryHook<TFnData, TVariables, TError, TPageParam>>[]
255
- }
253
+ AdditionalQueryOptions<TFnData, TVariables, TError, TPageParam> {}
256
254
 
257
255
  export interface InfiniteQueryHookOptions<
258
256
  TFnData,
@@ -267,7 +265,9 @@ export interface InfiniteQueryHookOptions<
267
265
  TData,
268
266
  TError,
269
267
  TPageParam
270
- >,
268
+ > &
269
+ AdditionalQueryOptions<TFnData, TVariables, TError, TPageParam>,
270
+ | 'primaryKey'
271
271
  | 'queryKey'
272
272
  | 'queryFn'
273
273
  | 'queryKeyHashFn'
@@ -275,60 +275,22 @@ export interface InfiniteQueryHookOptions<
275
275
  | 'getPreviousPageParam'
276
276
  | 'getNextPageParam'
277
277
  > {
278
- use?: Middleware<InfiniteQueryHook<TFnData, TVariables, TError, TPageParam>>[]
279
- variables?: TVariables
278
+ suspense?: undefined
280
279
  }
281
280
 
282
- export type InfiniteQueryHookResult<TData, TError> = UseInfiniteQueryResult<
281
+ export type DefinedInfiniteQueryHookOptions<
282
+ TFnData,
283
+ TError,
283
284
  TData,
284
- TError
285
- >
286
-
287
- export interface InfiniteQueryHook<
288
- TFnData = unknown,
289
- TVariables = void,
290
- TError = Error,
291
- TPageParam = number
292
- > extends ExposeMethods<TFnData, TVariables, TPageParam> {
293
- <TData = CompatibleWithV4<InfiniteData<TFnData, TPageParam>, TFnData>>(
294
- options?: InfiniteQueryHookOptions<
295
- TFnData,
296
- TError,
297
- TData,
298
- TVariables,
299
- TPageParam
300
- >,
301
- queryClient?: CompatibleWithV4<QueryClient, void>
302
- ): InfiniteQueryHookResult<TData, TError>
303
- }
304
-
305
- // infinite sususpense query hook
306
-
307
- export interface CreateSuspenseInfiniteQueryOptions<
308
- TFnData = unknown,
309
- TVariables = void,
310
- TError = Error,
285
+ TVariables,
311
286
  TPageParam = number
312
- > extends Omit<
313
- CompatibleUseInfiniteQueryOptions<
314
- TFnData,
315
- TVariables,
316
- TFnData,
317
- TError,
318
- TPageParam
319
- >,
320
- | 'queryKey'
321
- | 'queryFn'
322
- | 'enabled'
323
- | 'select'
324
- | 'suspense'
325
- | 'throwOnError'
326
- | 'placeholderData'
327
- | 'keepPreviousData'
328
- | 'useErrorBoundary'
329
- >,
330
- AdditionalQueryOptions<TFnData, TVariables, TPageParam> {
331
- use?: Middleware<SuspenseInfiniteQueryHook<TFnData, TVariables, TVariables>>[]
287
+ > = Omit<
288
+ InfiniteQueryHookOptions<TFnData, TError, TData, TVariables, TPageParam>,
289
+ 'initialData'
290
+ > & {
291
+ initialData:
292
+ | CompatibleInfiniteData<TFnData, TPageParam>
293
+ | (() => NonUndefinedGuard<CompatibleInfiniteData<TFnData, TPageParam>>)
332
294
  }
333
295
 
334
296
  export interface SuspenseInfiniteQueryHookOptions<
@@ -338,30 +300,26 @@ export interface SuspenseInfiniteQueryHookOptions<
338
300
  TVariables,
339
301
  TPageParam = number
340
302
  > extends Omit<
341
- CompatibleUseInfiniteQueryOptions<
342
- TFnData,
343
- TVariables,
344
- TData,
345
- TError,
346
- TPageParam
347
- >,
348
- | 'queryKey'
349
- | 'queryFn'
350
- | 'queryKeyHashFn'
351
- | 'enabled'
352
- | 'initialPageParam'
353
- | 'getPreviousPageParam'
354
- | 'getNextPageParam'
303
+ InfiniteQueryHookOptions<TFnData, TError, TData, TVariables, TPageParam>,
355
304
  | 'suspense'
356
305
  | 'throwOnError'
357
306
  | 'placeholderData'
358
307
  | 'keepPreviousData'
359
308
  | 'useErrorBoundary'
360
309
  > {
361
- use?: Middleware<SuspenseInfiniteQueryHook<TFnData, TVariables, TVariables>>[]
362
- variables?: TVariables
310
+ suspense: true
363
311
  }
364
312
 
313
+ export type InfiniteQueryHookResult<TData, TError> = UseInfiniteQueryResult<
314
+ TData,
315
+ TError
316
+ >
317
+
318
+ export type DefinedInfiniteQueryHookResult<TData, TError> = WithRequired<
319
+ UseInfiniteQueryResult<TData, TError>,
320
+ 'data'
321
+ >
322
+
365
323
  export type SuspenseInfiniteQueryHookResult<TData, TError> = Omit<
366
324
  InfiniteQueryObserverSuccessResult<TData, TError>,
367
325
  'isPlaceholderData' | 'isPreviousData'
@@ -385,6 +343,44 @@ export interface SuspenseInfiniteQueryHook<
385
343
  ): SuspenseInfiniteQueryHookResult<TData, TError>
386
344
  }
387
345
 
346
+ export interface InfiniteQueryHook<
347
+ TFnData = unknown,
348
+ TVariables = void,
349
+ TError = Error,
350
+ TPageParam = number
351
+ > extends ExposeMethods<TFnData, TVariables, TPageParam> {
352
+ <TData = CompatibleWithV4<InfiniteData<TFnData, TPageParam>, TFnData>>(
353
+ options: DefinedInfiniteQueryHookOptions<
354
+ TFnData,
355
+ TError,
356
+ TData,
357
+ TVariables,
358
+ TPageParam
359
+ >,
360
+ queryClient?: CompatibleWithV4<QueryClient, void>
361
+ ): DefinedInfiniteQueryHookResult<TData, TError>
362
+ <TData = CompatibleWithV4<InfiniteData<TFnData, TPageParam>, TFnData>>(
363
+ options?: InfiniteQueryHookOptions<
364
+ TFnData,
365
+ TError,
366
+ TData,
367
+ TVariables,
368
+ TPageParam
369
+ >,
370
+ queryClient?: CompatibleWithV4<QueryClient, void>
371
+ ): InfiniteQueryHookResult<TData, TError>
372
+ <TData = CompatibleWithV4<InfiniteData<TFnData, TPageParam>, TFnData>>(
373
+ options: SuspenseInfiniteQueryHookOptions<
374
+ TFnData,
375
+ TError,
376
+ TData,
377
+ TVariables,
378
+ TPageParam
379
+ >,
380
+ queryClient?: CompatibleWithV4<QueryClient, void>
381
+ ): SuspenseInfiniteQueryHookResult<TData, TError>
382
+ }
383
+
388
384
  // mutation hook
389
385
 
390
386
  export interface CreateMutationOptions<
@@ -428,8 +424,6 @@ export interface MutationHook<
428
424
  // infer types
429
425
 
430
426
  export type inferVariables<T> = T extends QueryHook<any, infer TVariables, any>
431
- ? TVariables
432
- : T extends SuspenseQueryHook<any, infer TVariables, any>
433
427
  ? TVariables
434
428
  : T extends InfiniteQueryHook<any, infer TVariables, any>
435
429
  ? TVariables
@@ -439,21 +433,22 @@ export type inferVariables<T> = T extends QueryHook<any, infer TVariables, any>
439
433
  ? TVariables
440
434
  : never
441
435
 
442
- export type inferData<T> = T extends QueryHook<infer TData, any, any>
443
- ? TData
444
- : T extends SuspenseQueryHook<infer TData, any, any>
445
- ? TData
446
- : T extends InfiniteQueryHook<infer TData, any, any, infer TPageParam>
447
- ? CompatibleWithV4<InfiniteData<TData, TPageParam>, InfiniteData<TData>>
448
- : T extends SuspenseInfiniteQueryHook<infer TData, any, any, infer TPageParam>
449
- ? CompatibleWithV4<InfiniteData<TData, TPageParam>, InfiniteData<TData>>
450
- : T extends MutationHook<infer TData, any, any>
451
- ? TData
436
+ export type inferData<T> = T extends QueryHook<infer TFnData, any, any>
437
+ ? TFnData
438
+ : T extends InfiniteQueryHook<infer TFnData, any, any, infer TPageParam>
439
+ ? CompatibleInfiniteData<TFnData, TPageParam>
440
+ : T extends SuspenseInfiniteQueryHook<
441
+ infer TFnData,
442
+ any,
443
+ any,
444
+ infer TPageParam
445
+ >
446
+ ? CompatibleInfiniteData<TFnData, TPageParam>
447
+ : T extends MutationHook<infer TFnData, any, any>
448
+ ? TFnData
452
449
  : never
453
450
 
454
451
  export type inferFnData<T> = T extends QueryHook<infer TData, any, any>
455
- ? TData
456
- : T extends SuspenseQueryHook<infer TData, any, any>
457
452
  ? TData
458
453
  : T extends InfiniteQueryHook<infer TData, any, any>
459
454
  ? TData
@@ -464,8 +459,6 @@ export type inferFnData<T> = T extends QueryHook<infer TData, any, any>
464
459
  : never
465
460
 
466
461
  export type inferError<T> = T extends QueryHook<any, any, infer TError>
467
- ? TError
468
- : T extends SuspenseQueryHook<any, any, infer TError>
469
462
  ? TError
470
463
  : T extends InfiniteQueryHook<any, any, infer TError>
471
464
  ? TError
@@ -481,8 +474,6 @@ export type inferOptions<T> = T extends QueryHook<
481
474
  infer TError
482
475
  >
483
476
  ? QueryHookOptions<TFnData, TError, TFnData, TVariables>
484
- : T extends SuspenseQueryHook<infer TFnData, infer TVariables, infer TError>
485
- ? SuspenseQueryHookOptions<TFnData, TError, TFnData, TVariables>
486
477
  : T extends InfiniteQueryHook<
487
478
  infer TFnData,
488
479
  infer TVariables,
@@ -519,8 +510,6 @@ export type inferCreateOptions<T> = T extends QueryHook<
519
510
  infer TError
520
511
  >
521
512
  ? CreateQueryOptions<TFnData, TVariables, TError>
522
- : T extends SuspenseQueryHook<infer TFnData, infer TVariables, infer TError>
523
- ? CreateSuspenseQueryOptions<TFnData, TVariables, TError>
524
513
  : T extends InfiniteQueryHook<
525
514
  infer TFnData,
526
515
  infer TVariables,
@@ -528,13 +517,6 @@ export type inferCreateOptions<T> = T extends QueryHook<
528
517
  infer TPageParam
529
518
  >
530
519
  ? CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>
531
- : T extends SuspenseInfiniteQueryHook<
532
- infer TFnData,
533
- infer TVariables,
534
- infer TError,
535
- infer TPageParam
536
- >
537
- ? CreateSuspenseInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>
538
520
  : T extends MutationHook<infer TFnData, infer TVariables, infer TError>
539
521
  ? CreateMutationOptions<TFnData, TError, TVariables, unknown>
540
522
  : never
package/src/utils.ts CHANGED
@@ -1,4 +1,8 @@
1
- import { type QueryClient, useQueryClient } from '@tanstack/react-query'
1
+ import {
2
+ type QueryClient,
3
+ useQueryClient,
4
+ useSuspenseQuery,
5
+ } from '@tanstack/react-query'
2
6
 
3
7
  import type { Middleware, inferQueryKey } from './types'
4
8
 
@@ -35,13 +39,6 @@ export const withMiddleware = (
35
39
  }
36
40
  }
37
41
 
38
- export const suspenseOptions = {
39
- enabled: true,
40
- suspense: true,
41
- throwOnError: true,
42
- useErrorBoundary: true,
43
- }
44
-
45
42
  export const getKey = <TVariables = void>(
46
43
  primaryKey: string,
47
44
  variables?: TVariables
@@ -50,3 +47,5 @@ export const getKey = <TVariables = void>(
50
47
  variables === undefined ? [primaryKey] : [primaryKey, variables]
51
48
  ) as inferQueryKey<TVariables>
52
49
  }
50
+
51
+ export const isV5 = () => !!useSuspenseQuery
@@ -1,24 +0,0 @@
1
- import { useInfiniteQuery } from '@tanstack/react-query'
2
-
3
- import { createBaseQuery } from './createBaseQuery'
4
- import type {
5
- CreateSuspenseInfiniteQueryOptions,
6
- SuspenseInfiniteQueryHook,
7
- } from './types'
8
- import { suspenseOptions } from './utils'
9
-
10
- export const createSuspenseInfiniteQuery = <
11
- TFnData,
12
- TVariables = void,
13
- TError = Error,
14
- TPageParam = number
15
- >(
16
- options: CreateSuspenseInfiniteQueryOptions<
17
- TFnData,
18
- TVariables,
19
- TError,
20
- TPageParam
21
- >
22
- ): SuspenseInfiniteQueryHook<TFnData, TVariables, TError, TPageParam> => {
23
- return createBaseQuery(options, useInfiniteQuery, suspenseOptions)
24
- }
@@ -1,11 +0,0 @@
1
- import { useQuery } from '@tanstack/react-query'
2
-
3
- import { createBaseQuery } from './createBaseQuery'
4
- import type { CreateSuspenseQueryOptions, SuspenseQueryHook } from './types'
5
- import { suspenseOptions } from './utils'
6
-
7
- export const createSuspenseQuery = <TFnData, TVariables = void, TError = Error>(
8
- options: CreateSuspenseQueryOptions<TFnData, TVariables, TError>
9
- ): SuspenseQueryHook<TFnData, TVariables, TError> => {
10
- return createBaseQuery(options, useQuery, suspenseOptions)
11
- }