mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-03 11:41:44 +00:00
Add typings for node-fetch extensions, remove unsupported options (#13114)
This commit is contained in:
committed by
Masahiro Wakame
parent
6cf46289ea
commit
ac6c277232
Vendored
+25
-7
@@ -5,6 +5,8 @@
|
||||
|
||||
///<reference types="node" />
|
||||
|
||||
import { Agent } from "http";
|
||||
|
||||
export class Request extends Body {
|
||||
constructor(input: string | Request, init?: RequestInit);
|
||||
method: string;
|
||||
@@ -12,20 +14,35 @@ export class Request extends Body {
|
||||
headers: Headers;
|
||||
context: RequestContext;
|
||||
referrer: string;
|
||||
mode: RequestMode;
|
||||
redirect: RequestRedirect;
|
||||
credentials: RequestCredentials;
|
||||
cache: RequestCache;
|
||||
|
||||
//node-fetch extensions to the whatwg/fetch spec
|
||||
compress: boolean;
|
||||
agent?: Agent;
|
||||
counter: number;
|
||||
follow: number;
|
||||
hostname: string;
|
||||
protocol: string;
|
||||
port?: number;
|
||||
timeout: number;
|
||||
size: number;
|
||||
}
|
||||
|
||||
interface RequestInit {
|
||||
//whatwg/fetch standard options
|
||||
method?: string;
|
||||
headers?: HeaderInit | { [index: string]: string };
|
||||
body?: BodyInit;
|
||||
mode?: RequestMode;
|
||||
redirect?: RequestRedirect;
|
||||
credentials?: RequestCredentials;
|
||||
cache?: RequestCache;
|
||||
|
||||
//node-fetch extensions
|
||||
timeout?: number; //=0 req/res timeout in ms, it resets on redirect. 0 to disable (OS limit applies)
|
||||
compress?: boolean; //=true support gzip/deflate content encoding. false to disable
|
||||
size?: number; //=0 maximum response body size in bytes. 0 to disable
|
||||
agent?: Agent; //=null http.Agent instance, allows custom proxy, certificate etc.
|
||||
follow?: number; //=20 maximum redirect count. 0 to not follow redirect
|
||||
|
||||
//node-fetch does not support mode, cache or credentials options
|
||||
}
|
||||
|
||||
type RequestContext =
|
||||
@@ -56,7 +73,6 @@ export class Headers {
|
||||
export class Body {
|
||||
bodyUsed: boolean;
|
||||
body: NodeJS.ReadableStream;
|
||||
arrayBuffer(): Promise<ArrayBuffer>;
|
||||
json(): Promise<any>;
|
||||
json<T>(): Promise<T>;
|
||||
text(): Promise<string>;
|
||||
@@ -71,7 +87,9 @@ export class Response extends Body {
|
||||
url: string;
|
||||
status: number;
|
||||
ok: boolean;
|
||||
size: number;
|
||||
statusText: string;
|
||||
timeout: number;
|
||||
headers: Headers;
|
||||
clone(): Response;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import fetch, { Headers, Request, RequestInit, Response } from 'node-fetch';
|
||||
import { Agent } from "http";
|
||||
|
||||
function test_fetchUrlWithOptions() {
|
||||
var headers = new Headers();
|
||||
@@ -6,10 +7,11 @@ function test_fetchUrlWithOptions() {
|
||||
var requestOptions: RequestInit = {
|
||||
method: "POST",
|
||||
headers: headers,
|
||||
mode: 'same-origin',
|
||||
credentials: 'omit',
|
||||
cache: 'default',
|
||||
redirect: 'manual'
|
||||
compress: true,
|
||||
follow: 10,
|
||||
redirect: 'manual',
|
||||
size: 100,
|
||||
timeout: 5000
|
||||
};
|
||||
handlePromise(fetch("http://www.andlabs.net/html5/uCOR.php", requestOptions));
|
||||
}
|
||||
@@ -36,6 +38,11 @@ function test_fetchUrlWithRequestObject() {
|
||||
}
|
||||
};
|
||||
var request: Request = new Request("http://www.andlabs.net/html5/uCOR.php", requestOptions);
|
||||
var timeout: number = request.timeout;
|
||||
var size: number = request.size;
|
||||
var agent: Agent = request.agent;
|
||||
var protocol: string = request.protocol
|
||||
|
||||
handlePromise(fetch(request));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user