@@ -2,10 +2,10 @@ import { ref, type Ref } from 'vue'
2
2
import { isFunction } from 'rattail'
3
3
import { type AxleInstance , type AxleRequestConfig , type RunnerMethod } from './instance'
4
4
5
- export interface RunOptions < V , P > {
5
+ export interface RunOptions < V , P , D > {
6
6
url ?: string
7
7
params ?: P
8
- config ?: AxleRequestConfig
8
+ config ?: AxleRequestConfig < D >
9
9
resetValue ?: boolean
10
10
cloneResetValue ?: boolean | ( ( value : V ) => V )
11
11
}
@@ -26,19 +26,19 @@ export interface UseAxleRefs<V> {
26
26
downloadProgress : Ref < number >
27
27
}
28
28
29
- export type Run < V , R , P > = {
30
- ( options ?: RunOptions < V , P > ) : Promise < R >
29
+ export type Run < V , R , P , D > = {
30
+ ( options ?: RunOptions < V , P , D > ) : Promise < R >
31
31
} & UseAxleExtra < V >
32
32
33
- export interface UseAxleOptions < V = any , R = any , P = Record < string , any > > {
33
+ export interface UseAxleOptions < V = any , R = any , P = Record < string , any > , D = Record < string , any > > {
34
34
url : string | ( ( ) => string )
35
35
method : RunnerMethod
36
36
value ?: V
37
37
params ?: P | ( ( ) => P )
38
38
resetValue ?: boolean
39
39
cloneResetValue ?: boolean | ( ( value : V ) => V )
40
40
immediate ?: boolean
41
- config ?: AxleRequestConfig | ( ( ) => AxleRequestConfig )
41
+ config ?: AxleRequestConfig < D > | ( ( ) => AxleRequestConfig < D > )
42
42
onBefore ?( refs : UseAxleRefs < V > ) : void
43
43
onAfter ?( refs : UseAxleRefs < V > ) : void
44
44
onTransform ?( response : R , refs : UseAxleRefs < V > ) : V | Promise < V >
@@ -50,17 +50,17 @@ export interface ResetValueOptions<V> {
50
50
cloneResetValue ?: boolean | ( ( value : V ) => V )
51
51
}
52
52
53
- export type UseAxleInstance < V , R , P > = [ value : Ref < V > , run : Run < V , R , P > , extra : UseAxleExtra < V > ]
53
+ export type UseAxleInstance < V , R , P , D > = [ value : Ref < V > , run : Run < V , R , P , D > , extra : UseAxleExtra < V > ]
54
54
55
55
export interface CreateUseAxleOptions {
56
56
axle : AxleInstance
57
57
immediate ?: boolean
58
58
onTransform ?( response : any , refs : any ) : any
59
59
}
60
60
61
- export type UseAxle = < V = any , R = any , P = Record < string , any > > (
62
- options : UseAxleOptions < V , R , P > ,
63
- ) => UseAxleInstance < V , R , P >
61
+ export type UseAxle = < V = any , R = any , P = Record < string , any > , D = Record < string , any > > (
62
+ options : UseAxleOptions < V , R , P , D > ,
63
+ ) => UseAxleInstance < V , R , P , D >
64
64
65
65
export function normalizeValueGetter < T > ( valueGetter : T | ( ( ) => T ) ) {
66
66
return isFunction ( valueGetter ) ? valueGetter ( ) : valueGetter
@@ -69,9 +69,9 @@ export function normalizeValueGetter<T>(valueGetter: T | (() => T)) {
69
69
export function createUseAxle ( options : CreateUseAxleOptions ) {
70
70
const { axle, onTransform : defaultOnTransform , immediate : defaultImmediate = true } = options
71
71
72
- const useAxle : UseAxle = < V = any , R = any , P = Record < string , any > > (
73
- options : UseAxleOptions < V , R , P > ,
74
- ) : UseAxleInstance < V , R , P > => {
72
+ const useAxle : UseAxle = < V = any , R = any , P = Record < string , any > , D = Record < string , any > > (
73
+ options : UseAxleOptions < V , R , P , D > ,
74
+ ) : UseAxleInstance < V , R , P , D > => {
75
75
const {
76
76
url : initialUrlOrGetter ,
77
77
method,
@@ -114,8 +114,8 @@ export function createUseAxle(options: CreateUseAxleOptions) {
114
114
115
115
let controller = new AbortController ( )
116
116
117
- const run : Run < V , R , P > = Object . assign (
118
- async ( options : RunOptions < V , P > = { } ) => {
117
+ const run : Run < V , R , P , D > = Object . assign (
118
+ async ( options : RunOptions < V , P , D > = { } ) => {
119
119
if ( controller . signal . aborted ) {
120
120
controller = new AbortController ( )
121
121
}
0 commit comments