1// based on https://github.com/Ethan-Arrowood/undici-fetch/blob/249269714db874351589d2d364a0645d5160ae71/index.d.ts (MIT license) 2// and https://github.com/node-fetch/node-fetch/blob/914ce6be5ec67a8bab63d68510aabf07cb818b6d/index.d.ts (MIT license) 3/// <reference types="node" /> 4 5import { Blob } from 'buffer' 6import { URL, URLSearchParams } from 'url' 7import { ReadableStream } from 'stream/web' 8import { FormData } from './formdata' 9 10import Dispatcher from './dispatcher' 11 12export type RequestInfo = string | URL | Request 13 14export declare function fetch ( 15 input: RequestInfo, 16 init?: RequestInit 17): Promise<Response> 18 19export type BodyInit = 20 | ArrayBuffer 21 | AsyncIterable<Uint8Array> 22 | Blob 23 | FormData 24 | Iterable<Uint8Array> 25 | NodeJS.ArrayBufferView 26 | URLSearchParams 27 | null 28 | string 29 30export interface BodyMixin { 31 readonly body: ReadableStream | null 32 readonly bodyUsed: boolean 33 34 readonly arrayBuffer: () => Promise<ArrayBuffer> 35 readonly blob: () => Promise<Blob> 36 readonly formData: () => Promise<FormData> 37 readonly json: () => Promise<unknown> 38 readonly text: () => Promise<string> 39} 40 41export interface SpecIterator<T, TReturn = any, TNext = undefined> { 42 next(...args: [] | [TNext]): IteratorResult<T, TReturn>; 43} 44 45export interface SpecIterableIterator<T> extends SpecIterator<T> { 46 [Symbol.iterator](): SpecIterableIterator<T>; 47} 48 49export interface SpecIterable<T> { 50 [Symbol.iterator](): SpecIterator<T>; 51} 52 53export type HeadersInit = string[][] | Record<string, string | ReadonlyArray<string>> | Headers 54 55export declare class Headers implements SpecIterable<[string, string]> { 56 constructor (init?: HeadersInit) 57 readonly append: (name: string, value: string) => void 58 readonly delete: (name: string) => void 59 readonly get: (name: string) => string | null 60 readonly has: (name: string) => boolean 61 readonly set: (name: string, value: string) => void 62 readonly getSetCookie: () => string[] 63 readonly forEach: ( 64 callbackfn: (value: string, key: string, iterable: Headers) => void, 65 thisArg?: unknown 66 ) => void 67 68 readonly keys: () => SpecIterableIterator<string> 69 readonly values: () => SpecIterableIterator<string> 70 readonly entries: () => SpecIterableIterator<[string, string]> 71 readonly [Symbol.iterator]: () => SpecIterator<[string, string]> 72} 73 74export type RequestCache = 75 | 'default' 76 | 'force-cache' 77 | 'no-cache' 78 | 'no-store' 79 | 'only-if-cached' 80 | 'reload' 81 82export type RequestCredentials = 'omit' | 'include' | 'same-origin' 83 84type RequestDestination = 85 | '' 86 | 'audio' 87 | 'audioworklet' 88 | 'document' 89 | 'embed' 90 | 'font' 91 | 'image' 92 | 'manifest' 93 | 'object' 94 | 'paintworklet' 95 | 'report' 96 | 'script' 97 | 'sharedworker' 98 | 'style' 99 | 'track' 100 | 'video' 101 | 'worker' 102 | 'xslt' 103 104export interface RequestInit { 105 method?: string 106 keepalive?: boolean 107 headers?: HeadersInit 108 body?: BodyInit 109 redirect?: RequestRedirect 110 integrity?: string 111 signal?: AbortSignal | null 112 credentials?: RequestCredentials 113 mode?: RequestMode 114 referrer?: string 115 referrerPolicy?: ReferrerPolicy 116 window?: null 117 dispatcher?: Dispatcher 118 duplex?: RequestDuplex 119} 120 121export type ReferrerPolicy = 122 | '' 123 | 'no-referrer' 124 | 'no-referrer-when-downgrade' 125 | 'origin' 126 | 'origin-when-cross-origin' 127 | 'same-origin' 128 | 'strict-origin' 129 | 'strict-origin-when-cross-origin' 130 | 'unsafe-url'; 131 132export type RequestMode = 'cors' | 'navigate' | 'no-cors' | 'same-origin' 133 134export type RequestRedirect = 'error' | 'follow' | 'manual' 135 136export type RequestDuplex = 'half' 137 138export declare class Request implements BodyMixin { 139 constructor (input: RequestInfo, init?: RequestInit) 140 141 readonly cache: RequestCache 142 readonly credentials: RequestCredentials 143 readonly destination: RequestDestination 144 readonly headers: Headers 145 readonly integrity: string 146 readonly method: string 147 readonly mode: RequestMode 148 readonly redirect: RequestRedirect 149 readonly referrerPolicy: string 150 readonly url: string 151 152 readonly keepalive: boolean 153 readonly signal: AbortSignal 154 readonly duplex: RequestDuplex 155 156 readonly body: ReadableStream | null 157 readonly bodyUsed: boolean 158 159 readonly arrayBuffer: () => Promise<ArrayBuffer> 160 readonly blob: () => Promise<Blob> 161 readonly formData: () => Promise<FormData> 162 readonly json: () => Promise<unknown> 163 readonly text: () => Promise<string> 164 165 readonly clone: () => Request 166} 167 168export interface ResponseInit { 169 readonly status?: number 170 readonly statusText?: string 171 readonly headers?: HeadersInit 172} 173 174export type ResponseType = 175 | 'basic' 176 | 'cors' 177 | 'default' 178 | 'error' 179 | 'opaque' 180 | 'opaqueredirect' 181 182export type ResponseRedirectStatus = 301 | 302 | 303 | 307 | 308 183 184export declare class Response implements BodyMixin { 185 constructor (body?: BodyInit, init?: ResponseInit) 186 187 readonly headers: Headers 188 readonly ok: boolean 189 readonly status: number 190 readonly statusText: string 191 readonly type: ResponseType 192 readonly url: string 193 readonly redirected: boolean 194 195 readonly body: ReadableStream | null 196 readonly bodyUsed: boolean 197 198 readonly arrayBuffer: () => Promise<ArrayBuffer> 199 readonly blob: () => Promise<Blob> 200 readonly formData: () => Promise<FormData> 201 readonly json: () => Promise<unknown> 202 readonly text: () => Promise<string> 203 204 readonly clone: () => Response 205 206 static error (): Response 207 static json(data: any, init?: ResponseInit): Response 208 static redirect (url: string | URL, status: ResponseRedirectStatus): Response 209} 210