-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.d.ts
103 lines (86 loc) · 2.73 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
export type AnyObject = { [x: string]: any }
export type Data = string | AnyObject | ArrayBuffer
export type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'HEAD' | 'OPTIONS' | 'TRACE'
export type DataType = 'json' | 'text' | 'html'
export type ResponseType = 'text' | 'arraybuffer'
export interface RequestTask {
abort: () => void
onHeadersReceived?: (listener: (header: any) => void) => void
offHeadersReceived?: (listener: (header: any) => void) => void
}
export interface FetcherInstance<T = any> {
resolve: (value: T) => void
reject: (reason?: any) => void
source: () => Promise<T>
abort: () => Promise<void>
}
export interface FetcherConstructor {
new <T = RequestTask>(): FetcherInstance<T>
}
export interface CustomConfig {}
export interface AjaxRequestConfig extends CustomConfig {
baseURL?: string
url?: string
data?: Data
query?: AnyObject
params?: AnyObject
header?: any
method?: Method
timeout?: number
dataType?: DataType
responseType?: ResponseType
sslVerify?: boolean
withCredentials?: boolean
firstIpv4?: boolean
fetcher?: FetcherInstance
validateStatus?: ((statusCode?: number) => boolean) | null
adapter?: (config: AjaxRequestConfig) => Promise<any>
}
export type AjaxConfigType =
| AjaxRequestConfig
| (() => AjaxRequestConfig)
| (() => Promise<AjaxRequestConfig>)
| void
export interface AjaxResponse<T = any> {
data: T
statusCode: number
header: any
config: AjaxRequestConfig
errMsg: string
cookies: string[]
}
export interface AjaxInterceptorManager<V> {
use<T = V>(onFulfilled?: (value: V) => T | Promise<T>, onRejected?: (error: any) => any): number
eject(id: number): void
}
export interface CustomResponse<T = any> {}
export type AjaxResult<T> = keyof CustomResponse extends never ? AjaxResponse<T> : CustomResponse<T>
export interface AjaxInvoke {
<T = any, R = AjaxResult<T>>(config?: AjaxRequestConfig): Promise<R>
<T = any, R = AjaxResult<T>>(url?: string, data?: Data, config?: AjaxRequestConfig): Promise<R>
}
export interface AjaxInstance<T extends AjaxConfigType> extends AjaxInvoke {
get: AjaxInvoke
post: AjaxInvoke
put: AjaxInvoke
delete: AjaxInvoke
connect: AjaxInvoke
head: AjaxInvoke
options: AjaxInvoke
trace: AjaxInvoke
getURL(config?: AjaxConfigType): Promise<string>
readonly defaults: AjaxRequestConfig
readonly config: T
interceptors: {
request: AjaxInterceptorManager<AjaxRequestConfig>
response: AjaxInterceptorManager<AjaxResponse>
}
}
export interface AjaxStatic extends AjaxInstance<void> {
create<T extends AjaxConfigType = void>(config?: T): AjaxInstance<T>
Fetcher: FetcherConstructor
}
declare const Ajax: AjaxStatic
declare const Fetcher: FetcherConstructor
export { Fetcher }
export default Ajax