react-query-kit 3.1.0 → 3.1.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.
- package/README.md +50 -10
- package/build/lib/router.d.ts +5 -5
- package/build/lib/router.esm.js +2 -2
- package/build/lib/router.esm.js.map +1 -1
- package/build/lib/router.js +2 -2
- package/build/lib/router.js.map +1 -1
- package/build/lib/router.mjs +2 -2
- package/build/lib/router.mjs.map +1 -1
- package/build/lib/types.d.ts +29 -21
- package/build/stats-html.html +1 -1
- package/build/stats.json +97 -97
- package/build/umd/index.development.js +2 -2
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/router.ts +22 -18
- package/src/types.ts +90 -82
package/src/router.ts
CHANGED
|
@@ -5,14 +5,14 @@ import { createSuspenseInfiniteQuery } from './createSuspenseInfiniteQuery'
|
|
|
5
5
|
import { createSuspenseQuery } from './createSuspenseQuery'
|
|
6
6
|
import type {
|
|
7
7
|
CompatibleError,
|
|
8
|
-
CreateInfiniteQueryOptions,
|
|
9
|
-
CreateMutationOptions,
|
|
10
|
-
CreateQueryOptions,
|
|
11
8
|
CreateRouter,
|
|
12
9
|
RouterConfig,
|
|
13
10
|
RouterInfiniteQuery,
|
|
11
|
+
RouterInfiniteQueryOptions,
|
|
14
12
|
RouterMutation,
|
|
13
|
+
RouterMutationOptions,
|
|
15
14
|
RouterQuery,
|
|
15
|
+
RouterQueryOptions,
|
|
16
16
|
} from './types'
|
|
17
17
|
|
|
18
18
|
const buildRouter = (keys: string[], config: RouterConfig) => {
|
|
@@ -54,19 +54,19 @@ const buildRouter = (keys: string[], config: RouterConfig) => {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
export const router = <TConfig extends RouterConfig>(
|
|
57
|
-
|
|
57
|
+
key: string,
|
|
58
58
|
config: TConfig
|
|
59
59
|
): CreateRouter<TConfig> => {
|
|
60
|
-
return buildRouter([
|
|
60
|
+
return buildRouter([key], config)
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
router.query = <TFnData, TVariables = void, TError = CompatibleError>(
|
|
64
|
-
options:
|
|
65
|
-
)
|
|
64
|
+
options: RouterQueryOptions<TFnData, TVariables, TError>
|
|
65
|
+
) => {
|
|
66
66
|
return {
|
|
67
67
|
...options,
|
|
68
68
|
_type: 'q',
|
|
69
|
-
}
|
|
69
|
+
} as RouterQuery<TFnData, TVariables, TError>
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
router.infiniteQuery = <
|
|
@@ -75,12 +75,14 @@ router.infiniteQuery = <
|
|
|
75
75
|
TError = CompatibleError,
|
|
76
76
|
TPageParam = number
|
|
77
77
|
>(
|
|
78
|
-
options:
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
options: RouterInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>
|
|
79
|
+
) => {
|
|
80
|
+
return { ...options, _type: 'inf' } as RouterInfiniteQuery<
|
|
81
|
+
TFnData,
|
|
82
|
+
TVariables,
|
|
83
|
+
TError,
|
|
84
|
+
TPageParam
|
|
81
85
|
>
|
|
82
|
-
): RouterInfiniteQuery<TFnData, TVariables, TError, TPageParam> => {
|
|
83
|
-
return { ...options, _type: 'inf' }
|
|
84
86
|
}
|
|
85
87
|
|
|
86
88
|
router.mutation = <
|
|
@@ -89,10 +91,12 @@ router.mutation = <
|
|
|
89
91
|
TError = CompatibleError,
|
|
90
92
|
TContext = unknown
|
|
91
93
|
>(
|
|
92
|
-
options:
|
|
93
|
-
|
|
94
|
-
|
|
94
|
+
options: RouterMutationOptions<TFnData, TVariables, TError, TContext>
|
|
95
|
+
) => {
|
|
96
|
+
return { ...options, _type: 'm' } as RouterMutation<
|
|
97
|
+
TFnData,
|
|
98
|
+
TVariables,
|
|
99
|
+
TError,
|
|
100
|
+
TContext
|
|
95
101
|
>
|
|
96
|
-
): RouterMutation<TFnData, TVariables, TError, TContext> => {
|
|
97
|
-
return { ...options, _type: 'm' }
|
|
98
102
|
}
|
package/src/types.ts
CHANGED
|
@@ -60,6 +60,8 @@ type DeepPartial<T> = T extends object
|
|
|
60
60
|
}
|
|
61
61
|
: T
|
|
62
62
|
|
|
63
|
+
type DefaultTo<T, D> = unknown extends T ? D : T
|
|
64
|
+
|
|
63
65
|
export type CompatibleError = CompatibleWithV4<DefaultError, Error>
|
|
64
66
|
|
|
65
67
|
export type Fetcher<TFnData, TVariables = void, TPageParam = never> = (
|
|
@@ -443,15 +445,15 @@ export interface CreateMutationOptions<
|
|
|
443
445
|
TError = CompatibleError,
|
|
444
446
|
TContext = unknown
|
|
445
447
|
> extends UseMutationOptions<TData, TError, TVariables, TContext> {
|
|
446
|
-
use?: Middleware<MutationHook<TData,
|
|
448
|
+
use?: Middleware<MutationHook<TData, TVariables, TError>>[]
|
|
447
449
|
}
|
|
448
450
|
|
|
449
451
|
export interface MutationHookOptions<TData, TError, TVariables, TContext>
|
|
450
452
|
extends Omit<
|
|
451
|
-
UseMutationOptions<TData,
|
|
453
|
+
UseMutationOptions<TData, TVariables, TError, TContext>,
|
|
452
454
|
'mutationFn' | 'mutationKey'
|
|
453
455
|
> {
|
|
454
|
-
use?: Middleware<MutationHook<TData,
|
|
456
|
+
use?: Middleware<MutationHook<TData, TVariables, TError>>[]
|
|
455
457
|
}
|
|
456
458
|
|
|
457
459
|
export type MutationHookResult<
|
|
@@ -464,7 +466,7 @@ export type MutationHookResult<
|
|
|
464
466
|
export interface ExposeMutationMethods<
|
|
465
467
|
TData = unknown,
|
|
466
468
|
TVariables = void,
|
|
467
|
-
TError =
|
|
469
|
+
TError = CompatibleError,
|
|
468
470
|
TDefaultContext = unknown
|
|
469
471
|
> {
|
|
470
472
|
getKey: () => MutationKey | undefined
|
|
@@ -480,7 +482,7 @@ export interface ExposeMutationMethods<
|
|
|
480
482
|
export interface MutationHook<
|
|
481
483
|
TData = unknown,
|
|
482
484
|
TVariables = void,
|
|
483
|
-
TError =
|
|
485
|
+
TError = CompatibleError,
|
|
484
486
|
TDefaultContext = unknown
|
|
485
487
|
> extends ExposeMutationMethods<TData, TVariables, TError, TDefaultContext> {
|
|
486
488
|
<TContext = TDefaultContext>(
|
|
@@ -591,20 +593,35 @@ export type inferCreateOptions<T> = T extends QueryHook<
|
|
|
591
593
|
infer TError,
|
|
592
594
|
infer TContext
|
|
593
595
|
>
|
|
594
|
-
? CreateMutationOptions<TFnData,
|
|
596
|
+
? CreateMutationOptions<TFnData, TVariables, TError, TContext>
|
|
595
597
|
: never
|
|
596
598
|
|
|
597
599
|
// router
|
|
598
600
|
|
|
601
|
+
export type RouterQueryOptions<
|
|
602
|
+
TFnData,
|
|
603
|
+
TVariables = void,
|
|
604
|
+
TError = CompatibleError
|
|
605
|
+
> = Omit<CreateQueryOptions<TFnData, TVariables, TError>, 'queryKey'>
|
|
606
|
+
|
|
599
607
|
export type RouterQuery<
|
|
600
608
|
TFnData,
|
|
601
609
|
TVariables = void,
|
|
602
610
|
TError = CompatibleError
|
|
603
|
-
> =
|
|
611
|
+
> = RouterQueryOptions<TFnData, TVariables, TError> & {
|
|
604
612
|
_type: `q`
|
|
605
613
|
}
|
|
606
614
|
|
|
607
|
-
export type
|
|
615
|
+
export type ResolvedRouterQuery<
|
|
616
|
+
TFnData,
|
|
617
|
+
TVariables = void,
|
|
618
|
+
TError = CompatibleError
|
|
619
|
+
> = {
|
|
620
|
+
useQuery: QueryHook<TFnData, TVariables, TError>
|
|
621
|
+
useSuspenseQuery: SuspenseQueryHook<TFnData, TVariables, TError>
|
|
622
|
+
} & ExposeMethods<TFnData, TVariables, TError>
|
|
623
|
+
|
|
624
|
+
export type RouterInfiniteQueryOptions<
|
|
608
625
|
TFnData,
|
|
609
626
|
TVariables = void,
|
|
610
627
|
TError = CompatibleError,
|
|
@@ -612,11 +629,38 @@ export type RouterInfiniteQuery<
|
|
|
612
629
|
> = Omit<
|
|
613
630
|
CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>,
|
|
614
631
|
'queryKey'
|
|
632
|
+
>
|
|
633
|
+
|
|
634
|
+
export type RouterInfiniteQuery<
|
|
635
|
+
TFnData,
|
|
636
|
+
TVariables = void,
|
|
637
|
+
TError = CompatibleError,
|
|
638
|
+
TPageParam = number
|
|
639
|
+
> = RouterInfiniteQueryOptions<
|
|
640
|
+
TFnData,
|
|
641
|
+
TVariables,
|
|
642
|
+
TError,
|
|
643
|
+
Clone<TPageParam>
|
|
615
644
|
> & {
|
|
616
645
|
_type: `inf`
|
|
617
646
|
}
|
|
618
647
|
|
|
619
|
-
export type
|
|
648
|
+
export type ResolvedRouterInfiniteQuery<
|
|
649
|
+
TFnData,
|
|
650
|
+
TVariables = void,
|
|
651
|
+
TError = CompatibleError,
|
|
652
|
+
TPageParam = number
|
|
653
|
+
> = {
|
|
654
|
+
useInfiniteQuery: InfiniteQueryHook<TFnData, TVariables, TError, TPageParam>
|
|
655
|
+
useSuspenseInfiniteQuery: SuspenseInfiniteQueryHook<
|
|
656
|
+
TFnData,
|
|
657
|
+
TVariables,
|
|
658
|
+
TError,
|
|
659
|
+
TPageParam
|
|
660
|
+
>
|
|
661
|
+
} & ExposeMethods<TFnData, TVariables, TError, TPageParam>
|
|
662
|
+
|
|
663
|
+
export type RouterMutationOptions<
|
|
620
664
|
TData = unknown,
|
|
621
665
|
TVariables = void,
|
|
622
666
|
TError = CompatibleError,
|
|
@@ -624,49 +668,44 @@ export type RouterMutation<
|
|
|
624
668
|
> = Omit<
|
|
625
669
|
CreateMutationOptions<TData, TVariables, TError, TContext>,
|
|
626
670
|
'mutationKey'
|
|
627
|
-
>
|
|
671
|
+
>
|
|
672
|
+
|
|
673
|
+
export type RouterMutation<
|
|
674
|
+
TData = unknown,
|
|
675
|
+
TVariables = void,
|
|
676
|
+
TError = CompatibleError,
|
|
677
|
+
TContext = unknown
|
|
678
|
+
> = RouterMutationOptions<TData, TVariables, TError, TContext> & {
|
|
628
679
|
_type: `m`
|
|
629
680
|
}
|
|
630
681
|
|
|
631
|
-
type
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
| Record<
|
|
649
|
-
string,
|
|
650
|
-
| RouterQuery<any, any, any>
|
|
651
|
-
| RouterInfiniteQuery<any, any, any, any>
|
|
652
|
-
| RouterMutation<any, any, any, any>
|
|
653
|
-
| Record<
|
|
654
|
-
string,
|
|
655
|
-
| RouterQuery<any, any, any>
|
|
656
|
-
| RouterInfiniteQuery<any, any, any, any>
|
|
657
|
-
| RouterMutation<any, any, any, any>
|
|
658
|
-
| Record<
|
|
659
|
-
string,
|
|
660
|
-
| RouterQuery<any, any, any>
|
|
661
|
-
| RouterInfiniteQuery<any, any, any, any>
|
|
662
|
-
| RouterMutation<any, any, any, any>
|
|
663
|
-
>
|
|
664
|
-
>
|
|
665
|
-
>
|
|
666
|
-
>
|
|
667
|
-
>
|
|
682
|
+
export type ResolvedRouterMutation<
|
|
683
|
+
TData = unknown,
|
|
684
|
+
TVariables = void,
|
|
685
|
+
TError = CompatibleError,
|
|
686
|
+
TContext = unknown
|
|
687
|
+
> = {
|
|
688
|
+
useMutation: MutationHook<
|
|
689
|
+
TData,
|
|
690
|
+
DefaultTo<TVariables, void>,
|
|
691
|
+
DefaultTo<TError, CompatibleError>,
|
|
692
|
+
TContext
|
|
693
|
+
>
|
|
694
|
+
} & ExposeMutationMethods<
|
|
695
|
+
TData,
|
|
696
|
+
DefaultTo<TVariables, void>,
|
|
697
|
+
DefaultTo<TError, CompatibleError>,
|
|
698
|
+
TContext
|
|
668
699
|
>
|
|
669
700
|
|
|
701
|
+
export interface RouterConfig {
|
|
702
|
+
[k: string]:
|
|
703
|
+
| RouterQuery<any, any, any>
|
|
704
|
+
| RouterInfiniteQuery<any, any, any, any>
|
|
705
|
+
| RouterMutation<any, any, any, any>
|
|
706
|
+
| RouterConfig
|
|
707
|
+
}
|
|
708
|
+
|
|
670
709
|
export type CreateRouter<TConfig extends RouterConfig> = {
|
|
671
710
|
[K in keyof TConfig]: TConfig[K] extends RouterMutation<
|
|
672
711
|
infer TFnData,
|
|
@@ -674,14 +713,7 @@ export type CreateRouter<TConfig extends RouterConfig> = {
|
|
|
674
713
|
infer TError,
|
|
675
714
|
infer TContext
|
|
676
715
|
>
|
|
677
|
-
?
|
|
678
|
-
useMutation: MutationHook<
|
|
679
|
-
TFnData,
|
|
680
|
-
DefaultTo<TVariables, void>,
|
|
681
|
-
DefaultTo<TError, CompatibleError>,
|
|
682
|
-
TContext
|
|
683
|
-
>
|
|
684
|
-
} & ExposeMutationMethods<
|
|
716
|
+
? ResolvedRouterMutation<
|
|
685
717
|
TFnData,
|
|
686
718
|
DefaultTo<TVariables, void>,
|
|
687
719
|
DefaultTo<TError, CompatibleError>,
|
|
@@ -693,20 +725,7 @@ export type CreateRouter<TConfig extends RouterConfig> = {
|
|
|
693
725
|
infer TError,
|
|
694
726
|
infer TPageParam
|
|
695
727
|
>
|
|
696
|
-
?
|
|
697
|
-
useInfiniteQuery: InfiniteQueryHook<
|
|
698
|
-
TFnData,
|
|
699
|
-
DefaultTo<TVariables, void>,
|
|
700
|
-
DefaultTo<TError, CompatibleError>,
|
|
701
|
-
DefaultTo<TPageParam, number>
|
|
702
|
-
>
|
|
703
|
-
useSuspenseInfiniteQuery: SuspenseInfiniteQueryHook<
|
|
704
|
-
TFnData,
|
|
705
|
-
DefaultTo<TVariables, void>,
|
|
706
|
-
DefaultTo<TError, CompatibleError>,
|
|
707
|
-
DefaultTo<TPageParam, number>
|
|
708
|
-
>
|
|
709
|
-
} & ExposeMethods<
|
|
728
|
+
? ResolvedRouterInfiniteQuery<
|
|
710
729
|
TFnData,
|
|
711
730
|
DefaultTo<TVariables, void>,
|
|
712
731
|
DefaultTo<TError, CompatibleError>,
|
|
@@ -716,18 +735,7 @@ export type CreateRouter<TConfig extends RouterConfig> = {
|
|
|
716
735
|
RouterQuery<infer TFnData, infer TVariables, infer TError>,
|
|
717
736
|
'queryKey'
|
|
718
737
|
>
|
|
719
|
-
?
|
|
720
|
-
useQuery: QueryHook<
|
|
721
|
-
TFnData,
|
|
722
|
-
DefaultTo<TVariables, void>,
|
|
723
|
-
DefaultTo<TError, CompatibleError>
|
|
724
|
-
>
|
|
725
|
-
useSuspenseQuery: SuspenseQueryHook<
|
|
726
|
-
TFnData,
|
|
727
|
-
DefaultTo<TVariables, void>,
|
|
728
|
-
DefaultTo<TError, CompatibleError>
|
|
729
|
-
>
|
|
730
|
-
} & ExposeMethods<
|
|
738
|
+
? ResolvedRouterQuery<
|
|
731
739
|
TFnData,
|
|
732
740
|
DefaultTo<TVariables, void>,
|
|
733
741
|
DefaultTo<TError, CompatibleError>
|
|
@@ -735,4 +743,4 @@ export type CreateRouter<TConfig extends RouterConfig> = {
|
|
|
735
743
|
: TConfig[K] extends RouterConfig
|
|
736
744
|
? CreateRouter<TConfig[K]>
|
|
737
745
|
: never
|
|
738
|
-
} & { getKey: () => [
|
|
746
|
+
} & { getKey: () => string[] }
|