-
Notifications
You must be signed in to change notification settings - Fork 29.8k
/
index.d.ts
222 lines (197 loc) · 5.93 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
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
// Type definitions for node-fetch 2.5
// Project: https://github.com/bitinn/node-fetch
// Definitions by: Torsten Werner <https://github.com/torstenwerner>
// Niklas Lindgren <https://github.com/nikcorg>
// Vinay Bedre <https://github.com/vinaybedre>
// Antonio Román <https://github.com/kyranet>
// Andrew Leedham <https://github.com/AndrewLeedham>
// Jason Li <https://github.com/JasonLi914>
// Brandon Wilson <https://github.com/wilsonianb>
// Steve Faulkner <https://github.com/southpolesteve>
// ExE Boss <https://github.com/ExE-Boss>
// Alex Savin <https://github.com/alexandrusavin>
// Alexis Tyler <https://github.com/OmgImAlexis>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
import FormData = require('form-data');
import { Agent } from "http";
import { URLSearchParams, URL } from "url";
import { AbortSignal } from "./externals";
export class Request extends Body {
constructor(input: RequestInfo, init?: RequestInit);
clone(): Request;
context: RequestContext;
headers: Headers;
method: string;
redirect: RequestRedirect;
referrer: string;
url: string;
// node-fetch extensions to the whatwg/fetch spec
agent?: Agent | ((parsedUrl: URL) => Agent);
compress: boolean;
counter: number;
follow: number;
hostname: string;
port?: number;
protocol: string;
size: number;
timeout: number;
}
export interface RequestInit {
// whatwg/fetch standard options
body?: BodyInit;
headers?: HeadersInit;
method?: string;
redirect?: RequestRedirect;
signal?: AbortSignal | null;
// node-fetch extensions
agent?: Agent | ((parsedUrl: URL) => Agent); // =null http.Agent instance, allows custom proxy, certificate etc.
compress?: boolean; // =true support gzip/deflate content encoding. false to disable
follow?: number; // =20 maximum redirect count. 0 to not follow redirect
size?: number; // =0 maximum response body size in bytes. 0 to disable
timeout?: number; // =0 req/res timeout in ms, it resets on redirect. 0 to disable (OS limit applies)
// node-fetch does not support mode, cache or credentials options
}
export type RequestContext =
"audio"
| "beacon"
| "cspreport"
| "download"
| "embed"
| "eventsource"
| "favicon"
| "fetch"
| "font"
| "form"
| "frame"
| "hyperlink"
| "iframe"
| "image"
| "imageset"
| "import"
| "internal"
| "location"
| "manifest"
| "object"
| "ping"
| "plugin"
| "prefetch"
| "script"
| "serviceworker"
| "sharedworker"
| "style"
| "subresource"
| "track"
| "video"
| "worker"
| "xmlhttprequest"
| "xslt";
export type RequestMode = "cors" | "no-cors" | "same-origin";
export type RequestRedirect = "error" | "follow" | "manual";
export type RequestCredentials = "omit" | "include" | "same-origin";
export type RequestCache =
"default"
| "force-cache"
| "no-cache"
| "no-store"
| "only-if-cached"
| "reload";
export class Headers implements Iterable<[string, string]> {
constructor(init?: HeadersInit);
forEach(callback: (value: string, name: string) => void): void;
append(name: string, value: string): void;
delete(name: string): void;
get(name: string): string | null;
has(name: string): boolean;
raw(): { [k: string]: string[] };
set(name: string, value: string): void;
// Iterator methods
entries(): Iterator<[string, string]>;
keys(): Iterator<string>;
values(): Iterator<[string]>;
[Symbol.iterator](): Iterator<[string, string]>;
}
type BlobPart = ArrayBuffer | ArrayBufferView | Blob | string;
interface BlobOptions {
type?: string;
endings?: "transparent" | "native";
}
export class Blob {
constructor(blobParts?: BlobPart[], options?: BlobOptions);
readonly type: string;
readonly size: number;
slice(start?: number, end?: number): Blob;
}
export class Body {
constructor(body?: any, opts?: { size?: number; timeout?: number });
arrayBuffer(): Promise<ArrayBuffer>;
blob(): Promise<Buffer>;
body: NodeJS.ReadableStream;
bodyUsed: boolean;
buffer(): Promise<Buffer>;
json(): Promise<any>;
size: number;
text(): Promise<string>;
textConverted(): Promise<string>;
timeout: number;
}
interface SystemError extends Error {
code?: string;
}
export class FetchError extends Error {
name: "FetchError";
constructor(message: string, type: string, systemError?: SystemError);
type: string;
code?: string;
errno?: string;
}
export class Response extends Body {
constructor(body?: BodyInit, init?: ResponseInit);
static error(): Response;
static redirect(url: string, status: number): Response;
clone(): Response;
headers: Headers;
ok: boolean;
redirected: boolean;
status: number;
statusText: string;
type: ResponseType;
url: string;
}
export type ResponseType =
"basic"
| "cors"
| "default"
| "error"
| "opaque"
| "opaqueredirect";
export interface ResponseInit {
headers?: HeadersInit;
size?: number;
status?: number;
statusText?: string;
timeout?: number;
url?: string;
}
interface URLLike {
href: string;
}
export type HeadersInit = Headers | string[][] | { [key: string]: string };
// HeaderInit is exported to support backwards compatibility. See PR #34382
export type HeaderInit = HeadersInit;
export type BodyInit =
ArrayBuffer
| ArrayBufferView
| NodeJS.ReadableStream
| string
| URLSearchParams
| FormData;
export type RequestInfo = string | URLLike | Request;
declare function fetch(
url: RequestInfo,
init?: RequestInit
): Promise<Response>;
declare namespace fetch {
function isRedirect(code: number): boolean;
}
export default fetch;