|
| 1 | +// Type definitions for isomorphic-fetch |
| 2 | +// Project: https://github.com/matthew-andrews/isomorphic-fetch |
| 3 | +// Definitions by: Todd Lucas <https://github.com/toddlucas> |
| 4 | +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped |
| 5 | + |
| 6 | +declare enum RequestContext { |
| 7 | + "audio", "beacon", "cspreport", "download", "embed", "eventsource", |
| 8 | + "favicon", "fetch", "font", "form", "frame", "hyperlink", "iframe", |
| 9 | + "image", "imageset", "import", "internal", "location", "manifest", |
| 10 | + "object", "ping", "plugin", "prefetch", "script", "serviceworker", |
| 11 | + "sharedworker", "subresource", "style", "track", "video", "worker", |
| 12 | + "xmlhttprequest", "xslt" |
| 13 | +} |
| 14 | +declare enum RequestMode { "same-origin", "no-cors", "cors" } |
| 15 | +declare enum RequestCredentials { "omit", "same-origin", "include" } |
| 16 | +declare enum RequestCache { |
| 17 | + "default", "no-store", "reload", "no-cache", "force-cache", |
| 18 | + "only-if-cached" |
| 19 | +} |
| 20 | +declare enum ResponseType { "basic", "cors", "default", "error", "opaque" } |
| 21 | + |
| 22 | +declare type HeaderInit = Headers | Array<string>; |
| 23 | +declare type BodyInit = ArrayBuffer | ArrayBufferView | Blob | FormData | string; |
| 24 | +declare type RequestInfo = Request | string; |
| 25 | + |
| 26 | +interface RequestInit { |
| 27 | + method?: string; |
| 28 | + headers?: HeaderInit | { [index: string]: string }; |
| 29 | + body?: BodyInit; |
| 30 | + mode?: string | RequestMode; |
| 31 | + credentials?: string | RequestCredentials; |
| 32 | + cache?: string | RequestCache; |
| 33 | +} |
| 34 | + |
| 35 | +interface IHeaders { |
| 36 | + get(name: string): string; |
| 37 | + getAll(name: string): Array<string>; |
| 38 | + has(name: string): boolean; |
| 39 | +} |
| 40 | + |
| 41 | +declare class Headers implements IHeaders { |
| 42 | + append(name: string, value: string): void; |
| 43 | + delete(name: string):void; |
| 44 | + get(name: string): string; |
| 45 | + getAll(name: string): Array<string>; |
| 46 | + has(name: string): boolean; |
| 47 | + set(name: string, value: string): void; |
| 48 | +} |
| 49 | + |
| 50 | +interface IBody { |
| 51 | + bodyUsed: boolean; |
| 52 | + arrayBuffer(): Promise<ArrayBuffer>; |
| 53 | + blob(): Promise<Blob>; |
| 54 | + formData(): Promise<FormData>; |
| 55 | + json(): Promise<any>; |
| 56 | + json<T>(): Promise<T>; |
| 57 | + text(): Promise<string>; |
| 58 | +} |
| 59 | + |
| 60 | +declare class Body implements IBody { |
| 61 | + bodyUsed: boolean; |
| 62 | + arrayBuffer(): Promise<ArrayBuffer>; |
| 63 | + blob(): Promise<Blob>; |
| 64 | + formData(): Promise<FormData>; |
| 65 | + json(): Promise<any>; |
| 66 | + json<T>(): Promise<T>; |
| 67 | + text(): Promise<string>; |
| 68 | +} |
| 69 | + |
| 70 | +interface IRequest extends IBody { |
| 71 | + method: string; |
| 72 | + url: string; |
| 73 | + headers: Headers; |
| 74 | + context: string | RequestContext; |
| 75 | + referrer: string; |
| 76 | + mode: string | RequestMode; |
| 77 | + credentials: string | RequestCredentials; |
| 78 | + cache: string | RequestCache; |
| 79 | +} |
| 80 | + |
| 81 | +declare class Request extends Body implements IRequest { |
| 82 | + constructor(input: string | Request, init?: RequestInit); |
| 83 | + method: string; |
| 84 | + url: string; |
| 85 | + headers: Headers; |
| 86 | + context: string | RequestContext; |
| 87 | + referrer: string; |
| 88 | + mode: string | RequestMode; |
| 89 | + credentials: string | RequestCredentials; |
| 90 | + cache: string | RequestCache; |
| 91 | +} |
| 92 | + |
| 93 | +interface IResponse extends IBody { |
| 94 | + url: string; |
| 95 | + status: number; |
| 96 | + statusText: string; |
| 97 | + ok: boolean; |
| 98 | + headers: IHeaders; |
| 99 | + type: string | ResponseType; |
| 100 | + size: number; |
| 101 | + timeout: number; |
| 102 | + redirect(url: string, status: number): IResponse; |
| 103 | + error(): IResponse; |
| 104 | + clone(): IResponse; |
| 105 | +} |
| 106 | + |
| 107 | +interface IFetchStatic { |
| 108 | + Promise: any; |
| 109 | + Headers: IHeaders |
| 110 | + Request: IRequest; |
| 111 | + Response: IResponse; |
| 112 | + (url: string | IRequest, init?: RequestInit): Promise<IResponse>; |
| 113 | +} |
| 114 | + |
| 115 | +declare var fetch: IFetchStatic; |
| 116 | + |
| 117 | +declare module "isomorphic-fetch" { |
| 118 | + export = fetch; |
| 119 | +} |
0 commit comments