react-query-kit 2.0.4 → 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.
Files changed (55) hide show
  1. package/README.md +0 -40
  2. package/build/lib/createBaseQuery.d.ts +1 -6
  3. package/build/lib/createBaseQuery.esm.js +16 -17
  4. package/build/lib/createBaseQuery.esm.js.map +1 -1
  5. package/build/lib/createBaseQuery.js +15 -16
  6. package/build/lib/createBaseQuery.js.map +1 -1
  7. package/build/lib/createBaseQuery.mjs +16 -17
  8. package/build/lib/createBaseQuery.mjs.map +1 -1
  9. package/build/lib/createInfiniteQuery.d.ts +1 -1
  10. package/build/lib/createInfiniteQuery.esm.js.map +1 -1
  11. package/build/lib/createInfiniteQuery.js.map +1 -1
  12. package/build/lib/createInfiniteQuery.mjs.map +1 -1
  13. package/build/lib/createQuery.d.ts +1 -1
  14. package/build/lib/createQuery.esm.js.map +1 -1
  15. package/build/lib/createQuery.js.map +1 -1
  16. package/build/lib/createQuery.mjs.map +1 -1
  17. package/build/lib/createSuspenseInfiniteQuery.d.ts +1 -1
  18. package/build/lib/createSuspenseInfiniteQuery.esm.js.map +1 -1
  19. package/build/lib/createSuspenseInfiniteQuery.js.map +1 -1
  20. package/build/lib/createSuspenseInfiniteQuery.mjs.map +1 -1
  21. package/build/lib/createSuspenseQuery.d.ts +1 -1
  22. package/build/lib/createSuspenseQuery.esm.js.map +1 -1
  23. package/build/lib/createSuspenseQuery.js.map +1 -1
  24. package/build/lib/createSuspenseQuery.mjs.map +1 -1
  25. package/build/lib/index.d.ts +0 -2
  26. package/build/lib/index.esm.js +0 -2
  27. package/build/lib/index.esm.js.map +1 -1
  28. package/build/lib/index.js +0 -4
  29. package/build/lib/index.js.map +1 -1
  30. package/build/lib/index.mjs +0 -2
  31. package/build/lib/index.mjs.map +1 -1
  32. package/build/lib/types.d.ts +44 -42
  33. package/build/lib/utils.d.ts +1 -6
  34. package/build/lib/utils.esm.js +3 -8
  35. package/build/lib/utils.esm.js.map +1 -1
  36. package/build/lib/utils.js +2 -7
  37. package/build/lib/utils.js.map +1 -1
  38. package/build/lib/utils.mjs +3 -8
  39. package/build/lib/utils.mjs.map +1 -1
  40. package/build/stats-html.html +1 -1
  41. package/build/stats.json +62 -150
  42. package/build/umd/index.development.js +16 -32
  43. package/build/umd/index.development.js.map +1 -1
  44. package/build/umd/index.production.js +1 -1
  45. package/build/umd/index.production.js.map +1 -1
  46. package/build/zip/zip.esm.js +83 -1
  47. package/package.json +2 -2
  48. package/src/createBaseQuery.ts +19 -21
  49. package/src/createInfiniteQuery.ts +1 -1
  50. package/src/createQuery.tsx +1 -1
  51. package/src/index.ts +0 -2
  52. package/src/types.ts +135 -153
  53. package/src/utils.ts +7 -8
  54. package/src/createSuspenseInfiniteQuery.ts +0 -24
  55. package/src/createSuspenseQuery.ts +0 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-query-kit",
3
- "version": "2.0.4",
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
@@ -5,7 +5,7 @@ import type { CreateInfiniteQueryOptions, InfiniteQueryHook } from './types'
5
5
 
6
6
  export const createInfiniteQuery = <
7
7
  TFnData,
8
- TVariables = any,
8
+ TVariables = void,
9
9
  TError = Error,
10
10
  TPageParam = number
11
11
  >(
@@ -3,7 +3,7 @@ import { useQuery } from '@tanstack/react-query'
3
3
  import { createBaseQuery } from './createBaseQuery'
4
4
  import type { CreateQueryOptions, QueryHook } from './types'
5
5
 
6
- export const createQuery = <TFnData, TVariables = any, TError = Error>(
6
+ export const createQuery = <TFnData, TVariables = void, TError = Error>(
7
7
  options: CreateQueryOptions<TFnData, TVariables, TError>
8
8
  ): QueryHook<TFnData, TVariables, TError> => {
9
9
  return createBaseQuery(options, useQuery)
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> = (
@@ -148,64 +168,33 @@ export type ExposeMethods<TFnData, TVariables, TPageParam = never> = {
148
168
 
149
169
  export interface CreateQueryOptions<
150
170
  TFnData = unknown,
151
- TVariables = any,
171
+ TVariables = void,
152
172
  TError = Error
153
173
  > extends Omit<
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
169
- }
170
-
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>
185
+ suspense?: undefined
179
186
  }
180
187
 
181
- // suspense query hook
182
-
183
- export interface CreateSuspenseQueryOptions<
184
- TFnData = unknown,
185
- TVariables = any,
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 = any,
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> {
230
222
  <TData = TFnData>(
231
- options?: SuspenseQueryHookOptions<TFnData, TError, TData, TVariables>,
223
+ options: DefinedQueryHookOptions<TFnData, TError, TData, TVariables>,
224
+ queryClient?: CompatibleWithV4<QueryClient, void>
225
+ ): DefinedQueryHookResult<TData, TError>
226
+ <TData = TFnData>(
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
  }
@@ -237,7 +237,7 @@ export interface SuspenseQueryHook<
237
237
 
238
238
  export interface CreateInfiniteQueryOptions<
239
239
  TFnData = unknown,
240
- TVariables = any,
240
+ TVariables = void,
241
241
  TError = Error,
242
242
  TPageParam = number
243
243
  > extends Omit<
@@ -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 = any,
290
- TError = Error,
285
+ TVariables,
291
286
  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 = any,
310
- TError = Error,
311
- 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'
@@ -369,7 +327,7 @@ export type SuspenseInfiniteQueryHookResult<TData, TError> = Omit<
369
327
 
370
328
  export interface SuspenseInfiniteQueryHook<
371
329
  TFnData = unknown,
372
- TVariables = any,
330
+ TVariables = void,
373
331
  TError = Error,
374
332
  TPageParam = number
375
333
  > extends ExposeMethods<TFnData, TVariables, TPageParam> {
@@ -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<
@@ -408,13 +404,13 @@ export interface MutationHookOptions<TData, TError, TVariables, TContext>
408
404
  export type MutationHookResult<
409
405
  TData = unknown,
410
406
  TError = Error,
411
- TVariables = unknown,
407
+ TVariables = void,
412
408
  TContext = unknown
413
409
  > = UseMutationResult<TData, TError, TVariables, TContext>
414
410
 
415
411
  export interface MutationHook<
416
412
  TData = unknown,
417
- TVariables = any,
413
+ TVariables = void,
418
414
  TError = unknown
419
415
  > {
420
416
  <TContext>(
@@ -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 = any,
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 = any, TError = Error>(
8
- options: CreateSuspenseQueryOptions<TFnData, TVariables, TError>
9
- ): SuspenseQueryHook<TFnData, TVariables, TError> => {
10
- return createBaseQuery(options, useQuery, suspenseOptions)
11
- }