1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | type RequestType = "" | "audio" | "font" | "image" | "script" | "style" |
|
7 | "track" | "video";
|
8 | type RequestDestination = "" | "document" | "embed" | "font" | "image" |
|
9 | "manifest" | "media" | "object" | "report" | "script" | "serviceworker" |
|
10 | "sharedworker" | "style" | "worker" | "xslt";
|
11 | type RequestMode = "navigate" | "same-origin" | "no-cors" | "cors";
|
12 | type RequestCredentials = "omit" | "same-origin" | "include";
|
13 | type RequestCache =
|
14 | "default" | "no-store" | "reload" | "no-cache" | "force-cache" |
|
15 | "only-if-cached";
|
16 | type RequestRedirect = "follow" | "error" | "manual";
|
17 |
|
18 | type ResponseType = "basic" | "cors" | "default" | "error" | "opaque" |
|
19 | "opaqueredirect";
|
20 |
|
21 | type ReferrerPolicy = "" | "no-referrer" | "no-referrer-when-downgrade" |
|
22 | "same-origin" | "origin" | "strict-origin" | "origin-when-cross-origin" |
|
23 | "strict-origin-when-cross-origin" | "unsafe-url";
|
24 |
|
25 | interface IHeaders {
|
26 | append(name: string, value: string): void;
|
27 | delete(name: string): void;
|
28 | get(name: string): string;
|
29 | getAll(name: string): Array<string>;
|
30 | has(name: string): boolean;
|
31 | set(name: string, value: string): void;
|
32 |
|
33 |
|
34 | forEach(callback: (value: string, index: number, headers: IHeaders) => void, thisArg?: any): void;
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | }
|
40 |
|
41 | type HeadersInit = Headers | Array<string> | { [index: string]: string };
|
42 |
|
43 | declare class Headers implements IHeaders {
|
44 | constructor(init?: HeadersInit);
|
45 | append(name: string, value: string): void;
|
46 | delete(name: string): void;
|
47 | get(name: string): string;
|
48 | getAll(name: string): Array<string>;
|
49 | has(name: string): boolean;
|
50 | set(name: string, value: string): void;
|
51 |
|
52 | forEach(callback: (value: string, index: number, headers: IHeaders) => void, thisArg?: any): void;
|
53 | }
|
54 |
|
55 | interface IBody {
|
56 | bodyUsed: boolean;
|
57 | arrayBuffer(): Promise<ArrayBuffer>;
|
58 | blob(): Promise<Blob>;
|
59 | formData(): Promise<FormData>;
|
60 | json(): Promise<any>;
|
61 | json<T>(): Promise<T>;
|
62 | text(): Promise<string>;
|
63 | }
|
64 |
|
65 | declare class Body implements IBody {
|
66 | bodyUsed: boolean;
|
67 | arrayBuffer(): Promise<ArrayBuffer>;
|
68 | blob(): Promise<Blob>;
|
69 | formData(): Promise<FormData>;
|
70 | json(): Promise<any>;
|
71 | json<T>(): Promise<T>;
|
72 | text(): Promise<string>;
|
73 | }
|
74 |
|
75 | interface IRequest extends IBody {
|
76 | method: string;
|
77 | url: string;
|
78 | headers: IHeaders;
|
79 |
|
80 | type: RequestType;
|
81 | destination: RequestDestination;
|
82 | referrer?: string;
|
83 | referrerPolicy?: ReferrerPolicy;
|
84 | mode: RequestMode;
|
85 | credentials: RequestCredentials;
|
86 | cache: RequestCache;
|
87 | redirect?: RequestRedirect;
|
88 | integrity?: string;
|
89 |
|
90 | clone(): IRequest;
|
91 | }
|
92 |
|
93 | type BodyInit = Blob | ArrayBufferView | ArrayBuffer | FormData | string;
|
94 |
|
95 | interface RequestInit {
|
96 | method?: string;
|
97 | headers?: HeadersInit;
|
98 | body?: BodyInit;
|
99 | referrer?: string;
|
100 | referrerPolicy?: ReferrerPolicy;
|
101 | mode?: RequestMode;
|
102 | credentials?: RequestCredentials;
|
103 | cache?: RequestCache;
|
104 | redirect?: RequestRedirect;
|
105 | integrity?: string;
|
106 | window?: any;
|
107 | }
|
108 |
|
109 | type RequestInfo = IRequest | string;
|
110 |
|
111 | declare class Request extends Body implements IRequest {
|
112 | constructor(input: RequestInfo, init?: RequestInit);
|
113 |
|
114 | method: string;
|
115 | url: string;
|
116 | headers: IHeaders;
|
117 |
|
118 | type: RequestType
|
119 | destination: RequestDestination;
|
120 | referrer: string;
|
121 | referrerPolicy: ReferrerPolicy;
|
122 | mode: RequestMode;
|
123 | credentials: RequestCredentials;
|
124 | cache: RequestCache;
|
125 | redirect: RequestRedirect;
|
126 | integrity: string;
|
127 |
|
128 | clone(): IRequest;
|
129 | }
|
130 |
|
131 | interface IResponse extends IBody {
|
132 | type: ResponseType;
|
133 |
|
134 | url: string;
|
135 | redirected: boolean;
|
136 | status: number;
|
137 | statusText: string;
|
138 | ok: boolean;
|
139 | headers: IHeaders;
|
140 |
|
141 |
|
142 | body: any;
|
143 | trailer: Promise<IHeaders>;
|
144 |
|
145 | clone(): IResponse;
|
146 | }
|
147 |
|
148 | type ResponseBodyInit = BodyInit;
|
149 |
|
150 | interface ResponseInit {
|
151 | status?: number;
|
152 | statusText?: string;
|
153 | headers?: HeadersInit;
|
154 | }
|
155 |
|
156 | declare class Response extends Body implements IResponse {
|
157 | constructor(body?: ResponseBodyInit, init?: ResponseInit);
|
158 |
|
159 | static redirect(url: string, status?: number): IResponse;
|
160 | static error(): IResponse;
|
161 |
|
162 | type: ResponseType
|
163 |
|
164 | url: string;
|
165 | redirected: boolean;
|
166 | status: number;
|
167 | statusText: string;
|
168 | ok: boolean;
|
169 | headers: IHeaders;
|
170 | body: any;
|
171 | trailer: Promise<IHeaders>;
|
172 |
|
173 | clone(): IResponse;
|
174 | }
|
175 |
|
176 | interface Window {
|
177 | fetch(url: RequestInfo, init?: RequestInit): Promise<IResponse>;
|
178 | }
|
179 |
|
180 | declare var fetch: typeof window.fetch;
|
181 |
|
182 | declare module "isomorphic-fetch" {
|
183 | export = fetch;
|
184 | }
|