react-query-kit 2.0.6 → 2.0.7
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.
- package/build/lib/createInfiniteQuery.esm.js.map +1 -1
- package/build/lib/createInfiniteQuery.js.map +1 -1
- package/build/lib/createInfiniteQuery.mjs.map +1 -1
- package/build/lib/createMutation.esm.js.map +1 -1
- package/build/lib/createMutation.js.map +1 -1
- package/build/lib/createMutation.mjs.map +1 -1
- package/build/lib/createQuery.esm.js.map +1 -1
- package/build/lib/createQuery.js.map +1 -1
- package/build/lib/createQuery.mjs.map +1 -1
- package/build/lib/createSuspenseInfiniteQuery.esm.js.map +1 -1
- package/build/lib/createSuspenseInfiniteQuery.js.map +1 -1
- package/build/lib/createSuspenseInfiniteQuery.mjs.map +1 -1
- package/build/lib/createSuspenseQuery.esm.js.map +1 -1
- package/build/lib/createSuspenseQuery.js.map +1 -1
- package/build/lib/createSuspenseQuery.mjs.map +1 -1
- package/build/lib/types.d.ts +13 -12
- package/build/lib/utils.d.ts +3 -3
- package/build/lib/utils.esm.js +5 -2
- package/build/lib/utils.esm.js.map +1 -1
- package/build/lib/utils.js +5 -2
- package/build/lib/utils.js.map +1 -1
- package/build/lib/utils.mjs +5 -2
- package/build/lib/utils.mjs.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats.json +86 -86
- package/build/umd/index.development.js +5 -2
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/build/zip/zip.esm.js +1 -1
- package/package.json +6 -1
- package/src/createInfiniteQuery.ts +6 -2
- package/src/createMutation.ts +6 -2
- package/src/createQuery.tsx +6 -2
- package/src/createSuspenseInfiniteQuery.ts +2 -1
- package/src/createSuspenseQuery.ts +10 -2
- package/src/types.ts +21 -14
- package/src/utils.ts +10 -3
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { useQuery } from '@tanstack/react-query'
|
|
2
2
|
|
|
3
3
|
import { createBaseQuery } from './createBaseQuery'
|
|
4
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
CompatibleError,
|
|
6
|
+
CreateSuspenseQueryOptions,
|
|
7
|
+
SuspenseQueryHook,
|
|
8
|
+
} from './types'
|
|
5
9
|
import { suspenseOptions } from './utils'
|
|
6
10
|
|
|
7
|
-
export const createSuspenseQuery = <
|
|
11
|
+
export const createSuspenseQuery = <
|
|
12
|
+
TFnData,
|
|
13
|
+
TVariables = void,
|
|
14
|
+
TError = CompatibleError
|
|
15
|
+
>(
|
|
8
16
|
options: CreateSuspenseQueryOptions<TFnData, TVariables, TError>
|
|
9
17
|
): SuspenseQueryHook<TFnData, TVariables, TError> => {
|
|
10
18
|
return createBaseQuery(options, useQuery, suspenseOptions)
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
DefaultError,
|
|
3
|
+
DefinedUseInfiniteQueryResult,
|
|
2
4
|
DefinedUseQueryResult,
|
|
3
5
|
GetNextPageParamFunction,
|
|
4
6
|
GetPreviousPageParamFunction,
|
|
@@ -90,6 +92,8 @@ type WithRequired<T, K extends keyof T> = T & {
|
|
|
90
92
|
[_ in K]: {}
|
|
91
93
|
}
|
|
92
94
|
|
|
95
|
+
export type CompatibleError = CompatibleWithV4<DefaultError, Error>
|
|
96
|
+
|
|
93
97
|
export type inferQueryKey<TVariables> = TVariables extends void
|
|
94
98
|
? [string]
|
|
95
99
|
: [string, TVariables]
|
|
@@ -161,7 +165,7 @@ export type ExposeMethods<TFnData, TVariables, TPageParam = never> = {
|
|
|
161
165
|
export interface CreateQueryOptions<
|
|
162
166
|
TFnData = unknown,
|
|
163
167
|
TVariables = void,
|
|
164
|
-
TError =
|
|
168
|
+
TError = CompatibleError
|
|
165
169
|
> extends Omit<
|
|
166
170
|
UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TVariables>>,
|
|
167
171
|
'queryKey' | 'queryFn' | 'select'
|
|
@@ -194,8 +198,11 @@ export type DefinedQueryHookResult<TData, TError> = DefinedUseQueryResult<
|
|
|
194
198
|
TError
|
|
195
199
|
>
|
|
196
200
|
|
|
197
|
-
export interface QueryHook<
|
|
198
|
-
|
|
201
|
+
export interface QueryHook<
|
|
202
|
+
TFnData = unknown,
|
|
203
|
+
TVariables = any,
|
|
204
|
+
TError = CompatibleError
|
|
205
|
+
> extends ExposeMethods<TFnData, TVariables> {
|
|
199
206
|
<TData = TFnData>(
|
|
200
207
|
options: DefinedQueryHookOptions<TFnData, TError, TData, TVariables>,
|
|
201
208
|
queryClient?: CompatibleWithV4<QueryClient, void>
|
|
@@ -211,7 +218,7 @@ export interface QueryHook<TFnData = unknown, TVariables = any, TError = Error>
|
|
|
211
218
|
export interface CreateSuspenseQueryOptions<
|
|
212
219
|
TFnData = unknown,
|
|
213
220
|
TVariables = void,
|
|
214
|
-
TError =
|
|
221
|
+
TError = CompatibleError
|
|
215
222
|
> extends Omit<
|
|
216
223
|
UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TVariables>>,
|
|
217
224
|
| 'queryKey'
|
|
@@ -253,7 +260,7 @@ export type SuspenseQueryHookResult<TData, TError> = Omit<
|
|
|
253
260
|
export interface SuspenseQueryHook<
|
|
254
261
|
TFnData = unknown,
|
|
255
262
|
TVariables = void,
|
|
256
|
-
TError =
|
|
263
|
+
TError = CompatibleError
|
|
257
264
|
> extends ExposeMethods<TFnData, TVariables> {
|
|
258
265
|
<TData = TFnData>(
|
|
259
266
|
options?: SuspenseQueryHookOptions<TFnData, TError, TData, TVariables>,
|
|
@@ -266,7 +273,7 @@ export interface SuspenseQueryHook<
|
|
|
266
273
|
export interface CreateInfiniteQueryOptions<
|
|
267
274
|
TFnData = unknown,
|
|
268
275
|
TVariables = void,
|
|
269
|
-
TError =
|
|
276
|
+
TError = CompatibleError,
|
|
270
277
|
TPageParam = number
|
|
271
278
|
> extends Omit<
|
|
272
279
|
CompatibleUseInfiniteQueryOptions<
|
|
@@ -327,15 +334,15 @@ export type InfiniteQueryHookResult<TData, TError> = UseInfiniteQueryResult<
|
|
|
327
334
|
TError
|
|
328
335
|
>
|
|
329
336
|
|
|
330
|
-
export type DefinedInfiniteQueryHookResult<TData, TError> =
|
|
331
|
-
|
|
332
|
-
'data'
|
|
337
|
+
export type DefinedInfiniteQueryHookResult<TData, TError> = CompatibleWithV4<
|
|
338
|
+
DefinedUseInfiniteQueryResult<TData, TError>,
|
|
339
|
+
WithRequired<UseInfiniteQueryResult<TData, TError>, 'data'>
|
|
333
340
|
>
|
|
334
341
|
|
|
335
342
|
export interface InfiniteQueryHook<
|
|
336
343
|
TFnData = unknown,
|
|
337
344
|
TVariables = void,
|
|
338
|
-
TError =
|
|
345
|
+
TError = CompatibleError,
|
|
339
346
|
TPageParam = number
|
|
340
347
|
> extends ExposeMethods<TFnData, TVariables, TPageParam> {
|
|
341
348
|
<TData = CompatibleWithV4<InfiniteData<TFnData, TPageParam>, TFnData>>(
|
|
@@ -365,7 +372,7 @@ export interface InfiniteQueryHook<
|
|
|
365
372
|
export interface CreateSuspenseInfiniteQueryOptions<
|
|
366
373
|
TFnData = unknown,
|
|
367
374
|
TVariables = void,
|
|
368
|
-
TError =
|
|
375
|
+
TError = CompatibleError,
|
|
369
376
|
TPageParam = number
|
|
370
377
|
> extends Omit<
|
|
371
378
|
CompatibleUseInfiniteQueryOptions<
|
|
@@ -428,7 +435,7 @@ export type SuspenseInfiniteQueryHookResult<TData, TError> = Omit<
|
|
|
428
435
|
export interface SuspenseInfiniteQueryHook<
|
|
429
436
|
TFnData = unknown,
|
|
430
437
|
TVariables = void,
|
|
431
|
-
TError =
|
|
438
|
+
TError = CompatibleError,
|
|
432
439
|
TPageParam = number
|
|
433
440
|
> extends ExposeMethods<TFnData, TVariables, TPageParam> {
|
|
434
441
|
<TData = CompatibleWithV4<InfiniteData<TFnData, TPageParam>, TFnData>>(
|
|
@@ -448,7 +455,7 @@ export interface SuspenseInfiniteQueryHook<
|
|
|
448
455
|
export interface CreateMutationOptions<
|
|
449
456
|
TData = unknown,
|
|
450
457
|
TVariables = void,
|
|
451
|
-
TError =
|
|
458
|
+
TError = CompatibleError,
|
|
452
459
|
TContext = unknown
|
|
453
460
|
> extends UseMutationOptions<TData, TError, TVariables, TContext> {
|
|
454
461
|
use?: Middleware<MutationHook<TData, TError, TVariables>>[]
|
|
@@ -465,7 +472,7 @@ export interface MutationHookOptions<TData, TError, TVariables, TContext>
|
|
|
465
472
|
|
|
466
473
|
export type MutationHookResult<
|
|
467
474
|
TData = unknown,
|
|
468
|
-
TError =
|
|
475
|
+
TError = CompatibleError,
|
|
469
476
|
TVariables = void,
|
|
470
477
|
TContext = unknown
|
|
471
478
|
> = UseMutationResult<TData, TError, TVariables, TContext>
|
package/src/utils.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type Query,
|
|
3
|
+
type QueryClient,
|
|
4
|
+
useQueryClient,
|
|
5
|
+
} from '@tanstack/react-query'
|
|
2
6
|
|
|
3
7
|
import type { Middleware, inferQueryKey } from './types'
|
|
4
8
|
|
|
@@ -35,12 +39,15 @@ export const withMiddleware = (
|
|
|
35
39
|
}
|
|
36
40
|
}
|
|
37
41
|
|
|
42
|
+
const defaultThrowOnError = (_error: unknown, query: Query) =>
|
|
43
|
+
query.state.data === undefined
|
|
44
|
+
|
|
38
45
|
export const suspenseOptions = {
|
|
39
46
|
enabled: true,
|
|
40
47
|
suspense: true,
|
|
41
|
-
throwOnError:
|
|
48
|
+
throwOnError: defaultThrowOnError,
|
|
42
49
|
// Compatible with ReactQuery v4
|
|
43
|
-
useErrorBoundary:
|
|
50
|
+
useErrorBoundary: defaultThrowOnError,
|
|
44
51
|
}
|
|
45
52
|
|
|
46
53
|
export const getKey = <TVariables = void>(
|