1 |
|
2 |
|
3 | import {RequestOptions} from 'http';
|
4 | import {FormData} from 'formdata-polyfill/esm.min.js';
|
5 | import {
|
6 | Blob,
|
7 | blobFrom,
|
8 | blobFromSync,
|
9 | File,
|
10 | fileFrom,
|
11 | fileFromSync
|
12 | } from 'fetch-blob/from.js';
|
13 |
|
14 | type AbortSignal = {
|
15 | readonly aborted: boolean;
|
16 |
|
17 | addEventListener: (type: 'abort', listener: (this: AbortSignal) => void) => void;
|
18 | removeEventListener: (type: 'abort', listener: (this: AbortSignal) => void) => void;
|
19 | };
|
20 |
|
21 | export type HeadersInit = Headers | Record<string, string> | Iterable<readonly [string, string]> | Iterable<Iterable<string>>;
|
22 |
|
23 | export {
|
24 | FormData,
|
25 | Blob,
|
26 | blobFrom,
|
27 | blobFromSync,
|
28 | File,
|
29 | fileFrom,
|
30 | fileFromSync
|
31 | };
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | export class Headers {
|
41 | constructor(init?: HeadersInit);
|
42 |
|
43 | append(name: string, value: string): void;
|
44 | delete(name: string): void;
|
45 | get(name: string): string | null;
|
46 | has(name: string): boolean;
|
47 | set(name: string, value: string): void;
|
48 | forEach(
|
49 | callbackfn: (value: string, key: string, parent: Headers) => void,
|
50 | thisArg?: any
|
51 | ): void;
|
52 |
|
53 | [Symbol.iterator](): IterableIterator<[string, string]>;
|
54 | /**
|
55 | * Returns an iterator allowing to go through all key/value pairs contained in this object.
|
56 | */
|
57 | entries(): IterableIterator<[string, string]>;
|
58 | /**
|
59 | * Returns an iterator allowing to go through all keys of the key/value pairs contained in this object.
|
60 | */
|
61 | keys(): IterableIterator<string>;
|
62 | /**
|
63 | * Returns an iterator allowing to go through all values of the key/value pairs contained in this object.
|
64 | */
|
65 | values(): IterableIterator<string>;
|
66 |
|
67 | /** Node-fetch extension */
|
68 | raw(): Record<string, string[]>;
|
69 | }
|
70 |
|
71 | export interface RequestInit {
|
72 | |
73 |
|
74 |
|
75 | body?: BodyInit | null;
|
76 | |
77 |
|
78 |
|
79 | headers?: HeadersInit;
|
80 | |
81 |
|
82 |
|
83 | method?: string;
|
84 | |
85 |
|
86 |
|
87 | redirect?: RequestRedirect;
|
88 | |
89 |
|
90 |
|
91 | signal?: AbortSignal | null;
|
92 | |
93 |
|
94 |
|
95 | referrer?: string;
|
96 | |
97 |
|
98 |
|
99 | referrerPolicy?: ReferrerPolicy;
|
100 |
|
101 |
|
102 | agent?: RequestOptions['agent'] | ((parsedUrl: URL) => RequestOptions['agent']);
|
103 | compress?: boolean;
|
104 | counter?: number;
|
105 | follow?: number;
|
106 | hostname?: string;
|
107 | port?: number;
|
108 | protocol?: string;
|
109 | size?: number;
|
110 | highWaterMark?: number;
|
111 | insecureHTTPParser?: boolean;
|
112 | }
|
113 |
|
114 | export interface ResponseInit {
|
115 | headers?: HeadersInit;
|
116 | status?: number;
|
117 | statusText?: string;
|
118 | }
|
119 |
|
120 | export type BodyInit =
|
121 | | Blob
|
122 | | Buffer
|
123 | | URLSearchParams
|
124 | | FormData
|
125 | | NodeJS.ReadableStream
|
126 | | string;
|
127 | declare class BodyMixin {
|
128 | constructor(body?: BodyInit, options?: {size?: number});
|
129 |
|
130 | readonly body: NodeJS.ReadableStream | null;
|
131 | readonly bodyUsed: boolean;
|
132 | readonly size: number;
|
133 |
|
134 | /** @deprecated Use `body.arrayBuffer()` instead. */
|
135 | buffer(): Promise<Buffer>;
|
136 | arrayBuffer(): Promise<ArrayBuffer>;
|
137 | formData(): Promise<FormData>;
|
138 | blob(): Promise<Blob>;
|
139 | json(): Promise<unknown>;
|
140 | text(): Promise<string>;
|
141 | }
|
142 |
|
143 | // `Body` must not be exported as a class since it's not exported from the JavaScript code.
|
144 | export interface Body extends Pick<BodyMixin, keyof BodyMixin> {}
|
145 |
|
146 | export type RequestRedirect = 'error' | 'follow' | 'manual';
|
147 | export type ReferrerPolicy = '' | 'no-referrer' | 'no-referrer-when-downgrade' | 'same-origin' | 'origin' | 'strict-origin' | 'origin-when-cross-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url';
|
148 | export type RequestInfo = string | Request;
|
149 | export class Request extends BodyMixin {
|
150 | constructor(input: URL | RequestInfo, init?: RequestInit);
|
151 |
|
152 | /**
|
153 | * Returns a Headers object consisting of the headers associated with request. Note that headers added in the network layer by the user agent will not be accounted for in this object, e.g., the "Host" header.
|
154 | */
|
155 | readonly headers: Headers;
|
156 | /**
|
157 | * Returns request's HTTP method, which is "GET" by default.
|
158 | */
|
159 | readonly method: string;
|
160 | /**
|
161 | * Returns the redirect mode associated with request, which is a string indicating how redirects for the request will be handled during fetching. A request will follow redirects by default.
|
162 | */
|
163 | readonly redirect: RequestRedirect;
|
164 | /**
|
165 | * Returns the signal associated with request, which is an AbortSignal object indicating whether or not request has been aborted, and its abort event handler.
|
166 | */
|
167 | readonly signal: AbortSignal;
|
168 | /**
|
169 | * Returns the URL of request as a string.
|
170 | */
|
171 | readonly url: string;
|
172 | /**
|
173 | * A string whose value is a same-origin URL, "about:client", or the empty string, to set request’s referrer.
|
174 | */
|
175 | readonly referrer: string;
|
176 | /**
|
177 | * A referrer policy to set request’s referrerPolicy.
|
178 | */
|
179 | readonly referrerPolicy: ReferrerPolicy;
|
180 | clone(): Request;
|
181 | }
|
182 |
|
183 | type ResponseType = 'basic' | 'cors' | 'default' | 'error' | 'opaque' | 'opaqueredirect';
|
184 |
|
185 | export class Response extends BodyMixin {
|
186 | constructor(body?: BodyInit | null, init?: ResponseInit);
|
187 |
|
188 | readonly headers: Headers;
|
189 | readonly ok: boolean;
|
190 | readonly redirected: boolean;
|
191 | readonly status: number;
|
192 | readonly statusText: string;
|
193 | readonly type: ResponseType;
|
194 | readonly url: string;
|
195 | clone(): Response;
|
196 |
|
197 | static error(): Response;
|
198 | static redirect(url: string, status?: number): Response;
|
199 | static json(data: any, init?: ResponseInit): Response;
|
200 | }
|
201 |
|
202 | export class FetchError extends Error {
|
203 | constructor(message: string, type: string, systemError?: Record<string, unknown>);
|
204 |
|
205 | name: 'FetchError';
|
206 | [Symbol.toStringTag]: 'FetchError';
|
207 | type: string;
|
208 | code?: string;
|
209 | errno?: string;
|
210 | }
|
211 |
|
212 | export class AbortError extends Error {
|
213 | type: string;
|
214 | name: 'AbortError';
|
215 | [Symbol.toStringTag]: 'AbortError';
|
216 | }
|
217 |
|
218 | export function isRedirect(code: number): boolean;
|
219 | export default function fetch(url: URL | RequestInfo, init?: RequestInit): Promise<Response>;
|
220 |
|
\ | No newline at end of file |