|
1 | 1 | import {
|
2 |
| - Body as NodeBody, |
3 |
| - Headers as NodeHeaders, |
4 |
| - Request as NodeRequest, |
5 |
| - Response as NodeResponse, |
6 |
| - RequestInit as NodeRequestInit |
| 2 | + Body as NodeBody, |
| 3 | + Headers as NodeHeaders, |
| 4 | + Request as NodeRequest, |
| 5 | + Response as NodeResponse, |
| 6 | + RequestInit as NodeRequestInit, |
7 | 7 | } from "node-fetch";
|
8 | 8 |
|
9 |
| -declare namespace unfetch { |
10 |
| - export type IsomorphicHeaders = Headers | NodeHeaders; |
11 |
| - export type IsomorphicBody = Body | NodeBody; |
12 |
| - export type IsomorphicResponse = Response | NodeResponse; |
13 |
| - export type IsomorphicRequest = Request | NodeRequest; |
14 |
| - export type IsomorphicRequestInit = RequestInit | NodeRequestInit; |
| 9 | +/** @augments Headers */ |
| 10 | +export interface UnfetchHeaders { |
| 11 | + keys: () => string[]; |
| 12 | + entries: () => [string, string][]; |
| 13 | + get: (key: string) => string | null; |
| 14 | + has: (key: string) => boolean; |
| 15 | + |
| 16 | + /** @deprecated not supported by unfetch */ |
| 17 | + append: never; |
| 18 | + /** @deprecated not supported by unfetch */ |
| 19 | + delete: never; |
| 20 | + /** @deprecated not supported by unfetch */ |
| 21 | + forEach: never; |
| 22 | + /** @deprecated not supported by unfetch */ |
| 23 | + set: never; |
| 24 | + /** @deprecated not supported by unfetch */ |
| 25 | + values: never; |
| 26 | + /** @deprecated not supported by unfetch */ |
| 27 | + [Symbol.iterator]: never; |
15 | 28 | }
|
16 | 29 |
|
17 |
| -type UnfetchResponse = { |
18 |
| - ok: boolean, |
19 |
| - statusText: string, |
20 |
| - status: number, |
21 |
| - url: string, |
22 |
| - text: () => Promise<string>, |
23 |
| - json: () => Promise<any>, |
24 |
| - blob: () => Promise<Blob>, |
25 |
| - clone: () => UnfetchResponse, |
26 |
| - headers: { |
27 |
| - keys: () => string[], |
28 |
| - entries: () => Array<[string, string]>, |
29 |
| - get: (key: string) => string | undefined, |
30 |
| - has: (key: string) => boolean, |
31 |
| - } |
| 30 | +/** @augments Response */ |
| 31 | +export interface UnfetchResponse { |
| 32 | + ok: boolean; |
| 33 | + statusText: string; |
| 34 | + status: number; |
| 35 | + url: string; |
| 36 | + text: () => Promise<string>; |
| 37 | + json: () => Promise<any>; |
| 38 | + blob: () => Promise<Blob>; |
| 39 | + clone: () => UnfetchResponse; |
| 40 | + headers: UnfetchHeaders; |
| 41 | + |
| 42 | + /** @deprecated not supported by unfetch */ |
| 43 | + arrayBuffer: never; |
| 44 | + /** @deprecated not supported by unfetch */ |
| 45 | + body: never; |
| 46 | + /** @deprecated not supported by unfetch */ |
| 47 | + bodyUsed: never; |
| 48 | + /** @deprecated not supported by unfetch */ |
| 49 | + formData: never; |
| 50 | + /** @deprecated not supported by unfetch */ |
| 51 | + redirected: never; |
| 52 | + /** @deprecated not supported by unfetch */ |
| 53 | + type: never; |
| 54 | +} |
| 55 | + |
| 56 | +/** @augments RequestInit */ |
| 57 | +export interface UnfetchRequestInit { |
| 58 | + method?: string; |
| 59 | + headers?: Record<string, string>; |
| 60 | + credentials?: "include" | "omit"; |
| 61 | + body?: Parameters<XMLHttpRequest["send"]>[0]; |
| 62 | + |
| 63 | + /** @deprecated not supported by unfetch */ |
| 64 | + cache?: never; |
| 65 | + /** @deprecated not supported by unfetch */ |
| 66 | + integrity?: never; |
| 67 | + /** @deprecated not supported by unfetch */ |
| 68 | + keepalive?: never; |
| 69 | + /** @deprecated not supported by unfetch */ |
| 70 | + mode?: never; |
| 71 | + /** @deprecated not supported by unfetch */ |
| 72 | + redirect?: never; |
| 73 | + /** @deprecated not supported by unfetch */ |
| 74 | + referrer?: never; |
| 75 | + /** @deprecated not supported by unfetch */ |
| 76 | + referrerPolicy?: never; |
| 77 | + /** @deprecated not supported by unfetch */ |
| 78 | + signal?: never; |
| 79 | + /** @deprecated not supported by unfetch */ |
| 80 | + window?: never; |
32 | 81 | }
|
33 | 82 |
|
34 |
| -type Unfetch = ( |
35 |
| - url: string, |
36 |
| - options?: { |
37 |
| - method?: string, |
38 |
| - headers?: Record<string, string>, |
39 |
| - credentials?: 'include' | 'omit', |
40 |
| - body?: Parameters<XMLHttpRequest["send"]>[0] |
41 |
| - } |
42 |
| -) => Promise<UnfetchResponse> |
| 83 | +export namespace Unfetch { |
| 84 | + export type IsomorphicHeaders = Headers | NodeHeaders; |
| 85 | + export type IsomorphicBody = Body | NodeBody; |
| 86 | + export type IsomorphicResponse = Response | NodeResponse; |
| 87 | + export type IsomorphicRequest = Request | NodeRequest; |
| 88 | + export type IsomorphicRequestInit = RequestInit | NodeRequestInit; |
| 89 | + |
| 90 | + export type Headers = UnfetchHeaders | globalThis.Headers; |
| 91 | + export type Body = globalThis.Body; |
| 92 | + export type Response = UnfetchResponse | globalThis.Response; |
| 93 | + export type Request = UnfetchRequestInit | globalThis.Request; |
| 94 | + export type RequestInit = UnfetchRequestInit | globalThis.RequestInit; |
| 95 | +} |
| 96 | + |
| 97 | +export interface Unfetch { |
| 98 | + (url: string | URL, options?: UnfetchRequestInit): Promise<UnfetchResponse>; |
| 99 | +} |
43 | 100 |
|
44 | 101 | declare const unfetch: Unfetch;
|
45 | 102 |
|
|
0 commit comments