-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.d.ts
147 lines (126 loc) · 3.32 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
export = request;
export as namespace request;
declare function request(url?: RequestURL): Methods
declare function request(options?: Partial<RequestOptions>): Methods
type RequestBody =
| BodyInit
| Document
type ResponseType =
| XMLHttpRequestResponseType
| 'formdata'
| 'moz-chunked-arraybuffer'
| 'moz-chunked-text'
| 'moz-blob'
| 'msxml-document'
type Parameters =
| string
| Record<string, string | string[] | null | undefined>
| URLSearchParams
type RequestURL =
| string
| URL
type RequestHeaders =
| Record<string, string>
| Headers
interface RequestOptions {
url: RequestURL
method: string
headers: RequestHeaders
parameters: Parameters
body: RequestBody
credentials: RequestCredentials
mode: 'cors' | 'no-cors' | 'same-origin'
responseType: ResponseType
responseMediaType: string
timeout: number
username: string
password: string
multipart: boolean
tunneling: boolean
XSLPattern: boolean
}
interface JSONArray extends Array<JSONValue> {}
type JSONValue = string | number | boolean | null | { [name: string]: JSONValue } | JSONArray
type Callback = () => any
type Abort = () => void
interface XDomainRequest {
prototype: XDomainRequest
new(): XDomainRequest
create(): XDomainRequest
onprogress: Callback
onload: Callback
onerror: Callback
ontimeout: Callback
readonly responseText: string
readonly contentType: string
timeout: number
open: (method: 'GET' | 'POST', url: string) => void
send: (body?: string) => void
abort: Abort
}
interface AnonXMLHttpRequest extends XMLHttpRequest {}
interface NormalizedResponse {
body: JSONValue | Blob | Document | FormData | ReadableStream | ArrayBuffer
headers: Record<string, string>
instance: XMLHttpRequest | XDomainRequest | Response | AnonXMLHttpRequest
statusCode: number
statusText: string
url: string
}
interface ProgressEvent {
chunk: string | ArrayBuffer | Blob | Uint8Array | null
aggregate: string | ArrayBuffer | Blob | Uint8Array | null
loaded: number
total: number
lengthComputable: boolean
}
type Complete = (response: NormalizedResponse) => any
interface Done {
(onSuccess?: Complete, onError?: Complete): Abort
(callbacks?: {
success?: Complete
error?: Complete
timeout?: Callback
abort?: (event?: Event) => any
}): Abort
}
interface Pass<T> {
(name: string, value: string): T
(headers: RequestHeaders): T
}
interface Hook<T> {
(
name: 'loadstart',
handler: () => boolean | void
): T
(
name: 'download',
handler: (event: ProgressEvent) => any
): T
(
name: 'loadend',
handler: Callback
): T
}
interface Common {
pass: Pass<this>
hook: Hook<this>
done: Done
}
interface Querier extends Common {
query: (parameters?: Parameters) => Common
}
interface Sender extends Common {
send: (body?: RequestBody) => Common
}
interface Verb<T> {
(url?: RequestURL): T
}
interface Methods extends Common {
get: Verb<Querier>
delete: Verb<Querier>
head: Verb<Querier>
post: Verb<Sender>
put: Verb<Sender>
patch: Verb<Sender>
}