-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathglobals.d.ts
280 lines (270 loc) · 9.82 KB
/
globals.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/**
* The built in types for Deno do not include the `XMLHttpRequest` and
* associated types, so if you are type checking your code and get errors about
* them not being defined, there are a couple of solutions.
*
* If all you want to do is "polyfill" the types, they are available here under
* `./globals` export. You can either import them like:
*
* ```ts
* import type {} from "jsr:/@kitsonk/xhr/globals";
* ```
*
* Or using the triple slash reference like:
*
* ```ts
* /// <reference types="jsr:/@kitsonk/xhr/globals" />
* ```
*
* @module
*/
// deno-lint-ignore-file no-explicit-any
type XMLHttpRequestResponseType =
| ""
| "arraybuffer"
| "blob"
| "document"
| "json"
| "text";
interface XMLHttpRequestEventTargetEventMap {
"abort": ProgressEvent<XMLHttpRequestEventTarget>;
"error": ProgressEvent<XMLHttpRequestEventTarget>;
"load": ProgressEvent<XMLHttpRequestEventTarget>;
"loadend": ProgressEvent<XMLHttpRequestEventTarget>;
"loadstart": ProgressEvent<XMLHttpRequestEventTarget>;
"progress": ProgressEvent<XMLHttpRequestEventTarget>;
"timeout": ProgressEvent<XMLHttpRequestEventTarget>;
}
interface XMLHttpRequestEventMap extends XMLHttpRequestEventTargetEventMap {
"readystatechange": Event;
}
interface XMLHttpRequestEventTarget extends EventTarget {
onabort: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
onerror: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
onload: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
onloadend: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
onloadstart: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
onprogress: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
ontimeout: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
addEventListener<K extends keyof XMLHttpRequestEventTargetEventMap>(
type: K,
listener: (
this: XMLHttpRequestEventTarget,
ev: XMLHttpRequestEventTargetEventMap[K],
) => any,
options?: boolean | AddEventListenerOptions,
): void;
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions,
): void;
removeEventListener<K extends keyof XMLHttpRequestEventTargetEventMap>(
type: K,
listener: (
this: XMLHttpRequestEventTarget,
ev: XMLHttpRequestEventTargetEventMap[K],
) => any,
options?: boolean | EventListenerOptions,
): void;
removeEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | EventListenerOptions,
): void;
}
/**
* The interface for event handlers for {@linkcode XMLHttpRequest} and
* {@lincode XMLHttpRequestUpload}.
*/
// deno-lint-ignore no-var
declare var XMLHttpRequestEventTarget: {
prototype: XMLHttpRequestEventTarget;
new (): XMLHttpRequestEventTarget;
};
/**
* Use XMLHttpRequest (XHR) objects to interact with servers. You can retrieve
* data from a URL without having to do a full page refresh. This enables a Web
* page to update just part of a page without disrupting what the user is
* doing.
*/
interface XMLHttpRequest extends XMLHttpRequestEventTarget {
onreadystatechange: ((this: XMLHttpRequest, ev: Event) => any) | null;
/**
* Returns client's state.
*/
readonly readyState: number;
/**
* Returns the response's body.
*/
readonly response: any;
/**
* Returns the text response.
*
* Throws an "InvalidStateError" DOMException if responseType is not the empty string or "text".
*/
readonly responseText: string;
/**
* Returns the response type.
*
* Can be set to change the response type. Values are: the empty string (default), "arraybuffer", "blob", "document", "json", and "text".
*
* When set: setting to "document" is ignored if current global object is not a Window object.
*
* When set: throws an "InvalidStateError" DOMException if state is loading or done.
*
* When set: throws an "InvalidAccessError" DOMException if the synchronous flag is set and current global object is a Window object.
*/
responseType: XMLHttpRequestResponseType;
readonly responseURL: string;
/**
* Returns the document response.
*
* Throws an "InvalidStateError" DOMException if responseType is not the empty string or "document".
*/
readonly responseXML: null;
readonly status: number;
readonly statusText: string;
/**
* Can be set to a time in milliseconds. When set to a non-zero value will cause fetching to terminate after the given time has passed. When the time has passed, the request has not yet completed, and the synchronous flag is unset, a timeout event will then be dispatched, or a "TimeoutError" DOMException will be thrown otherwise (for the send() method).
*
* When set: throws an "InvalidAccessError" DOMException if the synchronous flag is set and current global object is a Window object.
*/
timeout: number;
/**
* Returns the associated XMLHttpRequestUpload object. It can be used to gather transmission information when data is transferred to a server.
*/
readonly upload: XMLHttpRequestUpload;
/**
* True when credentials are to be included in a cross-origin request. False when they are to be excluded in a cross-origin request and when cookies are to be ignored in its response. Initially false.
*
* When set: throws an "InvalidStateError" DOMException if state is not unsent or opened, or if the send() flag is set.
*/
withCredentials: boolean;
/**
* Cancels any network activity.
*/
abort(): void;
getAllResponseHeaders(): string;
getResponseHeader(name: string): string | null;
/**
* Sets the request method, request URL, and synchronous flag.
*
* Throws a "SyntaxError" DOMException if either method is not a valid HTTP method or url cannot be parsed.
*
* Throws a "SecurityError" DOMException if method is a case-insensitive match for `CONNECT`, `TRACE`, or `TRACK`.
*
* Throws an "InvalidAccessError" DOMException if async is false, current global object is a Window object, and the timeout attribute is not zero or the responseType attribute is not the empty string.
*/
open(method: string, url: string): void;
open(
method: string,
url: string,
async: boolean,
username?: string | null,
password?: string | null,
): void;
/**
* Acts as if the `Content-Type` header value for response is mime. (It does not actually change the header though.)
*
* Throws an "InvalidStateError" DOMException if state is loading or done.
*/
overrideMimeType(mime: string): void;
/**
* Initiates the request. The body argument provides the request body, if any, and is ignored if the request method is GET or HEAD.
*
* Throws an "InvalidStateError" DOMException if either state is not opened or the send() flag is set.
*/
send(body?: BodyInit | null): void;
/**
* Combines a header in author request headers.
*
* Throws an "InvalidStateError" DOMException if either state is not opened or the send() flag is set.
*
* Throws a "SyntaxError" DOMException if name is not a header name or if value is not a header value.
*/
setRequestHeader(name: string, value: string): void;
readonly DONE: number;
readonly HEADERS_RECEIVED: number;
readonly LOADING: number;
readonly OPENED: number;
readonly UNSENT: number;
addEventListener<K extends keyof XMLHttpRequestEventMap>(
type: K,
listener: (this: XMLHttpRequest, ev: XMLHttpRequestEventMap[K]) => any,
options?: boolean | AddEventListenerOptions,
): void;
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions,
): void;
removeEventListener<K extends keyof XMLHttpRequestEventMap>(
type: K,
listener: (this: XMLHttpRequest, ev: XMLHttpRequestEventMap[K]) => any,
options?: boolean | EventListenerOptions,
): void;
removeEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | EventListenerOptions,
): void;
}
/**
* XMLHttpRequest (XHR) objects are used to interact with servers. You can
* retrieve data from a URL without having to do a full page refresh. This
* enables a Web page to update just part of a page without disrupting what the
* user is doing.
*
* Despite its name, XMLHttpRequest can be used to retrieve any type of data,
* not just XML.
*/
// deno-lint-ignore no-var
declare var XMLHttpRequest: {
prototype: XMLHttpRequest;
new (): XMLHttpRequest;
readonly DONE: number;
readonly HEADERS_RECEIVED: number;
readonly LOADING: number;
readonly OPENED: number;
readonly UNSENT: number;
};
interface XMLHttpRequestUpload extends XMLHttpRequestEventTarget {
addEventListener<K extends keyof XMLHttpRequestEventTargetEventMap>(
type: K,
listener: (
this: XMLHttpRequestUpload,
ev: XMLHttpRequestEventTargetEventMap[K],
) => any,
options?: boolean | AddEventListenerOptions,
): void;
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions,
): void;
removeEventListener<K extends keyof XMLHttpRequestEventTargetEventMap>(
type: K,
listener: (
this: XMLHttpRequestUpload,
ev: XMLHttpRequestEventTargetEventMap[K],
) => any,
options?: boolean | EventListenerOptions,
): void;
removeEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | EventListenerOptions,
): void;
}
/**
* Represents the upload process for a specific {@linkcode XMLHttpRequest}. It
* is an _opaque_ object that represents the underlying, runtime-dependent,
* upload process. It is an {@linkcode XMLHttpRequestEventTarget} and can be
* obtained by calling `XMLHttpRequest.upload`.
*/
// deno-lint-ignore no-var
declare var XMLHttpRequestUpload: {
prototype: XMLHttpRequestUpload;
new (): XMLHttpRequestUpload;
};