feat(node): v12.7 (#37217)

* feat(node): v12.7

* correct dns.lookup
add http.response.writableFinished
add tests
fix lint

* add events to http.ClientRequest
This commit is contained in:
Simon Schick 2019-08-06 15:34:23 -07:00 committed by Nathan Shively-Sanders
parent 693374319f
commit 3f6627ea70
10 changed files with 1953 additions and 2047 deletions

6
types/node/dns.d.ts vendored
View File

@ -31,9 +31,9 @@ declare module "dns" {
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
namespace lookup {
function __promisify__(hostname: string, options: LookupAllOptions): Promise<{ address: LookupAddress[] }>;
function __promisify__(hostname: string, options?: LookupOneOptions | number): Promise<{ address: string, family: number }>;
function __promisify__(hostname: string, options?: LookupOptions | number): Promise<{ address: string | LookupAddress[], family?: number }>;
function __promisify__(hostname: string, options: LookupAllOptions): Promise<LookupAddress[]>;
function __promisify__(hostname: string, options?: LookupOneOptions | number): Promise<LookupAddress>;
function __promisify__(hostname: string, options: LookupOptions): Promise<LookupAddress | LookupAddress[]>;
}
function lookupService(address: string, port: number, callback: (err: NodeJS.ErrnoException | null, hostname: string, service: string) => void): void;

91
types/node/http.d.ts vendored
View File

@ -146,6 +146,7 @@ declare module "http" {
class ServerResponse extends OutgoingMessage {
statusCode: number;
statusMessage: string;
writableFinished: boolean;
constructor(req: IncomingMessage);
@ -158,6 +159,16 @@ declare module "http" {
writeHead(statusCode: number, headers?: OutgoingHttpHeaders): this;
}
interface InformationEvent {
statusCode: number;
statusMessage: string;
httpVersion: string;
httpVersionMajor: number;
httpVersionMinor: number;
headers: IncomingHttpHeaders;
rawHeaders: string[];
}
// https://github.com/nodejs/node/blob/master/lib/_http_client.js#L77
class ClientRequest extends OutgoingMessage {
connection: Socket;
@ -172,6 +183,86 @@ declare module "http" {
setTimeout(timeout: number, callback?: () => void): this;
setNoDelay(noDelay?: boolean): void;
setSocketKeepAlive(enable?: boolean, initialDelay?: number): void;
addListener(event: 'abort', listener: () => void): this;
addListener(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
addListener(event: 'continue', listener: () => void): this;
addListener(event: 'information', listener: (info: InformationEvent) => void): this;
addListener(event: 'response', listener: (response: IncomingMessage) => void): this;
addListener(event: 'socket', listener: (socket: Socket) => void): this;
addListener(event: 'timeout', listener: () => void): this;
addListener(event: 'upgrade', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
addListener(event: 'close', listener: () => void): this;
addListener(event: 'drain', listener: () => void): this;
addListener(event: 'error', listener: (err: Error) => void): this;
addListener(event: 'finish', listener: () => void): this;
addListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
addListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
on(event: 'abort', listener: () => void): this;
on(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
on(event: 'continue', listener: () => void): this;
on(event: 'information', listener: (info: InformationEvent) => void): this;
on(event: 'response', listener: (response: IncomingMessage) => void): this;
on(event: 'socket', listener: (socket: Socket) => void): this;
on(event: 'timeout', listener: () => void): this;
on(event: 'upgrade', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
on(event: 'close', listener: () => void): this;
on(event: 'drain', listener: () => void): this;
on(event: 'error', listener: (err: Error) => void): this;
on(event: 'finish', listener: () => void): this;
on(event: 'pipe', listener: (src: stream.Readable) => void): this;
on(event: 'unpipe', listener: (src: stream.Readable) => void): this;
on(event: string | symbol, listener: (...args: any[]) => void): this;
once(event: 'abort', listener: () => void): this;
once(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
once(event: 'continue', listener: () => void): this;
once(event: 'information', listener: (info: InformationEvent) => void): this;
once(event: 'response', listener: (response: IncomingMessage) => void): this;
once(event: 'socket', listener: (socket: Socket) => void): this;
once(event: 'timeout', listener: () => void): this;
once(event: 'upgrade', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
once(event: 'close', listener: () => void): this;
once(event: 'drain', listener: () => void): this;
once(event: 'error', listener: (err: Error) => void): this;
once(event: 'finish', listener: () => void): this;
once(event: 'pipe', listener: (src: stream.Readable) => void): this;
once(event: 'unpipe', listener: (src: stream.Readable) => void): this;
once(event: string | symbol, listener: (...args: any[]) => void): this;
prependListener(event: 'abort', listener: () => void): this;
prependListener(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
prependListener(event: 'continue', listener: () => void): this;
prependListener(event: 'information', listener: (info: InformationEvent) => void): this;
prependListener(event: 'response', listener: (response: IncomingMessage) => void): this;
prependListener(event: 'socket', listener: (socket: Socket) => void): this;
prependListener(event: 'timeout', listener: () => void): this;
prependListener(event: 'upgrade', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
prependListener(event: 'close', listener: () => void): this;
prependListener(event: 'drain', listener: () => void): this;
prependListener(event: 'error', listener: (err: Error) => void): this;
prependListener(event: 'finish', listener: () => void): this;
prependListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
prependListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
prependOnceListener(event: 'abort', listener: () => void): this;
prependOnceListener(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
prependOnceListener(event: 'continue', listener: () => void): this;
prependOnceListener(event: 'information', listener: (info: InformationEvent) => void): this;
prependOnceListener(event: 'response', listener: (response: IncomingMessage) => void): this;
prependOnceListener(event: 'socket', listener: (socket: Socket) => void): this;
prependOnceListener(event: 'timeout', listener: () => void): this;
prependOnceListener(event: 'upgrade', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
prependOnceListener(event: 'close', listener: () => void): this;
prependOnceListener(event: 'drain', listener: () => void): this;
prependOnceListener(event: 'error', listener: (err: Error) => void): this;
prependOnceListener(event: 'finish', listener: () => void): this;
prependOnceListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
prependOnceListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
}
class IncomingMessage extends stream.Readable {

View File

@ -1,4 +1,4 @@
// Type definitions for non-npm package Node.js 12.6
// Type definitions for non-npm package Node.js 12.7
// Project: http://nodejs.org/
// Definitions by: Microsoft TypeScript <https://github.com/Microsoft>
// DefinitelyTyped <https://github.com/DefinitelyTyped>

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,6 @@ import * as url from "url";
import * as util from "util";
import * as http from "http";
import * as https from "https";
import * as vm from "vm";
import * as console2 from "console";
import * as timers from "timers";
import * as dns from "dns";

View File

@ -127,10 +127,24 @@ declare module "readline" {
function createInterface(input: NodeJS.ReadableStream, output?: NodeJS.WritableStream, completer?: Completer | AsyncCompleter, terminal?: boolean): Interface;
function createInterface(options: ReadLineOptions): Interface;
function cursorTo(stream: NodeJS.WritableStream, x: number, y?: number): void;
function emitKeypressEvents(stream: NodeJS.ReadableStream, interface?: Interface): void;
function moveCursor(stream: NodeJS.WritableStream, dx: number | string, dy: number | string): void;
function clearLine(stream: NodeJS.WritableStream, dir: number): void;
function clearScreenDown(stream: NodeJS.WritableStream): void;
type Direction = -1 | 0 | 1;
/**
* Clears the current line of this WriteStream in a direction identified by `dir`.
*/
function clearLine(stream: NodeJS.WritableStream, dir: Direction, callback?: () => void): boolean;
/**
* Clears this `WriteStream` from the current cursor down.
*/
function clearScreenDown(stream: NodeJS.WritableStream, callback?: () => void): boolean;
/**
* Moves this WriteStream's cursor to the specified position.
*/
function cursorTo(stream: NodeJS.WritableStream, x: number, y: number, callback?: () => void): boolean;
/**
* Moves this WriteStream's cursor relative to its current position.
*/
function moveCursor(stream: NodeJS.WritableStream, dx: number, dy: number, callback?: () => void): boolean;
}

View File

@ -28,7 +28,7 @@ const httpsGet = (url: string) => new Promise<string>((resolve, reject) => {
// Input arguments
const tag = process.argv[2] || process.version;
const V8_PROTOCOL_URL = `https://raw.githubusercontent.com/nodejs/node/${tag}/deps/v8/src/inspector/js_protocol.json`;
const V8_PROTOCOL_URL = `https://raw.githubusercontent.com/nodejs/node/${tag}/deps/v8/src/inspector/js_protocol-1.3.json`;
const NODE_PROTOCOL_URL = `https://raw.githubusercontent.com/nodejs/node/${tag}/src/inspector/node_protocol.pdl`;
const INSPECTOR_PROTOCOL_REMOTE = `https://chromium.googlesource.com/deps/inspector_protocol`;
const INSPECTOR_PROTOCOL_LOCAL_DIR = "/tmp/inspector_protocol";
@ -51,7 +51,7 @@ function writeProtocolsToFile(jsonProtocols: string[]) {
}
const substituteArgs = generateSubstituteArgs(combinedProtocol);
const template = readFileSync(`${__dirname}/inspector.d.ts.template`, "utf8");
const inspectorDts = substitute(template, substituteArgs).split("\n")
.map(line => trimRight(line))
.join("\n");

View File

@ -5,6 +5,8 @@
// Please see https://github.com/DefinitelyTyped/DefinitelyTyped/pull/19330
// for more information.
// tslint:disable:max-line-length
/**
* The inspector module provides an API for interacting with the V8 inspector.
*/
@ -76,4 +78,11 @@ declare module "inspector" {
* Return the URL of the active inspector, or `undefined` if there is none.
*/
function url(): string | undefined;
/**
* Blocks until a client (existing or connected later) has sent
* `Runtime.runIfWaitingForDebugger` command.
* An exception will be thrown if there is no active inspector.
*/
waitForDebugger();
}

View File

@ -76,8 +76,8 @@ const rl: readline.ReadLine = readline.createInterface(new stream.Readable());
const x = 1;
const y = 1;
readline.cursorTo(strm, x);
readline.cursorTo(strm, x, y);
readline.cursorTo(strm, x, y, () => {}); // $ExpectType boolean
}
{
@ -94,17 +94,20 @@ const rl: readline.ReadLine = readline.createInterface(new stream.Readable());
const dy: number | string = 1;
readline.moveCursor(strm, dx, dy);
readline.moveCursor(strm, dx, dy, () => {}); // $ExpectType boolean
}
{
const strm: NodeJS.WritableStream = new stream.Writable();
readline.clearLine(strm, 1);
readline.clearLine(strm, 1, () => {}); // $ExpectType boolean
}
{
const strm: NodeJS.WritableStream = new stream.Writable();
readline.clearScreenDown(strm);
readline.clearScreenDown(strm, () => {}); // $ExpectType boolean
}
{

19
types/node/tty.d.ts vendored
View File

@ -32,9 +32,22 @@ declare module "tty" {
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
prependOnceListener(event: "resize", listener: () => void): this;
clearLine(dir: Direction): void;
clearScreenDown(): void;
cursorTo(x: number, y: number): void;
/**
* Clears the current line of this WriteStream in a direction identified by `dir`.
*/
clearLine(dir: Direction, callback?: () => void): boolean;
/**
* Clears this `WriteStream` from the current cursor down.
*/
clearScreenDown(callback?: () => void): boolean;
/**
* Moves this WriteStream's cursor to the specified position.
*/
cursorTo(x: number, y: number, callback?: () => void): boolean;
/**
* Moves this WriteStream's cursor relative to its current position.
*/
moveCursor(dx: number, dy: number, callback?: () => void): boolean;
/**
* @default `process.env`
*/