-
Notifications
You must be signed in to change notification settings - Fork 546
/
fetch.d.ts
209 lines (173 loc) · 5.33 KB
/
fetch.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
// based on https://github.com/Ethan-Arrowood/undici-fetch/blob/249269714db874351589d2d364a0645d5160ae71/index.d.ts (MIT license)
// and https://github.com/node-fetch/node-fetch/blob/914ce6be5ec67a8bab63d68510aabf07cb818b6d/index.d.ts (MIT license)
/// <reference types="node" />
import { Blob } from 'buffer'
import { URL, URLSearchParams } from 'url'
import { ReadableStream } from 'stream/web'
import { FormData } from './formdata'
import Dispatcher from './dispatcher'
export type RequestInfo = string | URL | Request
export declare function fetch (
input: RequestInfo,
init?: RequestInit
): Promise<Response>
export type BodyInit =
| ArrayBuffer
| AsyncIterable<Uint8Array>
| Blob
| FormData
| Iterable<Uint8Array>
| NodeJS.ArrayBufferView
| URLSearchParams
| null
| string
export interface BodyMixin {
readonly body: ReadableStream | null
readonly bodyUsed: boolean
readonly arrayBuffer: () => Promise<ArrayBuffer>
readonly blob: () => Promise<Blob>
readonly formData: () => Promise<FormData>
readonly json: () => Promise<unknown>
readonly text: () => Promise<string>
}
export interface SpecIterator<T, TReturn = any, TNext = undefined> {
next(...args: [] | [TNext]): IteratorResult<T, TReturn>;
}
export interface SpecIterableIterator<T> extends SpecIterator<T> {
[Symbol.iterator](): SpecIterableIterator<T>;
}
export interface SpecIterable<T> {
[Symbol.iterator](): SpecIterator<T>;
}
export type HeadersInit = string[][] | Record<string, string | ReadonlyArray<string>> | Headers
export declare class Headers implements SpecIterable<[string, string]> {
constructor (init?: HeadersInit)
readonly append: (name: string, value: string) => void
readonly delete: (name: string) => void
readonly get: (name: string) => string | null
readonly has: (name: string) => boolean
readonly set: (name: string, value: string) => void
readonly getSetCookie: () => string[]
readonly forEach: (
callbackfn: (value: string, key: string, iterable: Headers) => void,
thisArg?: unknown
) => void
readonly keys: () => SpecIterableIterator<string>
readonly values: () => SpecIterableIterator<string>
readonly entries: () => SpecIterableIterator<[string, string]>
readonly [Symbol.iterator]: () => SpecIterator<[string, string]>
}
export type RequestCache =
| 'default'
| 'force-cache'
| 'no-cache'
| 'no-store'
| 'only-if-cached'
| 'reload'
export type RequestCredentials = 'omit' | 'include' | 'same-origin'
type RequestDestination =
| ''
| 'audio'
| 'audioworklet'
| 'document'
| 'embed'
| 'font'
| 'image'
| 'manifest'
| 'object'
| 'paintworklet'
| 'report'
| 'script'
| 'sharedworker'
| 'style'
| 'track'
| 'video'
| 'worker'
| 'xslt'
export interface RequestInit {
method?: string
keepalive?: boolean
headers?: HeadersInit
body?: BodyInit
redirect?: RequestRedirect
integrity?: string
signal?: AbortSignal
credentials?: RequestCredentials
mode?: RequestMode
referrer?: string
referrerPolicy?: ReferrerPolicy
window?: null
dispatcher?: Dispatcher
duplex?: RequestDuplex
}
export type ReferrerPolicy =
| ''
| 'no-referrer'
| 'no-referrer-when-downgrade'
| 'origin'
| 'origin-when-cross-origin'
| 'same-origin'
| 'strict-origin'
| 'strict-origin-when-cross-origin'
| 'unsafe-url';
export type RequestMode = 'cors' | 'navigate' | 'no-cors' | 'same-origin'
export type RequestRedirect = 'error' | 'follow' | 'manual'
export type RequestDuplex = 'half'
export declare class Request implements BodyMixin {
constructor (input: RequestInfo, init?: RequestInit)
readonly cache: RequestCache
readonly credentials: RequestCredentials
readonly destination: RequestDestination
readonly headers: Headers
readonly integrity: string
readonly method: string
readonly mode: RequestMode
readonly redirect: RequestRedirect
readonly referrerPolicy: string
readonly url: string
readonly keepalive: boolean
readonly signal: AbortSignal
readonly duplex: RequestDuplex
readonly body: ReadableStream | null
readonly bodyUsed: boolean
readonly arrayBuffer: () => Promise<ArrayBuffer>
readonly blob: () => Promise<Blob>
readonly formData: () => Promise<FormData>
readonly json: () => Promise<unknown>
readonly text: () => Promise<string>
readonly clone: () => Request
}
export interface ResponseInit {
readonly status?: number
readonly statusText?: string
readonly headers?: HeadersInit
}
export type ResponseType =
| 'basic'
| 'cors'
| 'default'
| 'error'
| 'opaque'
| 'opaqueredirect'
export type ResponseRedirectStatus = 301 | 302 | 303 | 307 | 308
export declare class Response implements BodyMixin {
constructor (body?: BodyInit, init?: ResponseInit)
readonly headers: Headers
readonly ok: boolean
readonly status: number
readonly statusText: string
readonly type: ResponseType
readonly url: string
readonly redirected: boolean
readonly body: ReadableStream | null
readonly bodyUsed: boolean
readonly arrayBuffer: () => Promise<ArrayBuffer>
readonly blob: () => Promise<Blob>
readonly formData: () => Promise<FormData>
readonly json: () => Promise<unknown>
readonly text: () => Promise<string>
readonly clone: () => Response
static error (): Response
static json(data: any, init?: ResponseInit): Response
static redirect (url: string | URL, status: ResponseRedirectStatus): Response
}