feat(node): v13.6 (#41353)

* feat(node): v13.3

* feat(node): v13.4-5

* Update types/node/wasi.d.ts

Co-Authored-By: Gerhard Stöbich <18708370+Flarna@users.noreply.github.com>

* feat(node): v13.6

Co-authored-by: Gerhard Stöbich <18708370+Flarna@users.noreply.github.com>
This commit is contained in:
Simon Schick 2020-01-23 10:20:52 -08:00 committed by Ben Lichtman
parent fd56e4dd29
commit 19826ba267
31 changed files with 279 additions and 79 deletions

View File

@ -43,6 +43,9 @@ declare module "assert" {
function doesNotReject(block: (() => Promise<any>) | Promise<any>, message?: string | Error): Promise<void>;
function doesNotReject(block: (() => Promise<any>) | Promise<any>, error: RegExp | Function, message?: string | Error): Promise<void>;
function match(value: string, regExp: RegExp, message?: string | Error): void;
function doesNotMatch(value: string, regExp: RegExp, message?: string | Error): void;
const strict: typeof internal;
}

View File

@ -1,6 +1,10 @@
declare module "events" {
interface internal extends NodeJS.EventEmitter {}
class internal { }
interface EventEmitterOptions {
/**
* Enables automatic capturing of promise rejection.
*/
captureRejections?: boolean;
}
interface NodeEventTarget {
once(event: string | symbol, listener: (...args: any[]) => void): this;
@ -10,31 +14,37 @@ declare module "events" {
addEventListener(event: string, listener: (...args: any[]) => void, opts?: { once: boolean }): any;
}
namespace internal {
namespace EventEmitter {
function once(emitter: NodeEventTarget, event: string | symbol): Promise<any[]>;
function once(emitter: DOMEventTarget, event: string): Promise<any[]>;
class EventEmitter extends internal {
function on(emitter: EventEmitter, event: string): AsyncIterableIterator<any>;
const captureRejectionSymbol: unique symbol;
/**
* This symbol shall be used to install a listener for only monitoring `'error'`
* events. Listeners installed using this symbol are called before the regular
* `'error'` listeners are called.
*
* Installing a listener using this symbol does not change the behavior once an
* `'error'` event is emitted, therefore the process will still crash if no
* regular `'error'` listener is installed.
*/
const errorMonitor: unique symbol;
/**
* Sets or gets the default captureRejection value for all emitters.
*/
let captureRejections: boolean;
interface EventEmitter extends NodeJS.EventEmitter {
}
class EventEmitter {
constructor(options?: EventEmitterOptions);
/** @deprecated since v4.0.0 */
static listenerCount(emitter: EventEmitter, event: string | symbol): number;
static defaultMaxListeners: number;
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
on(event: string | symbol, listener: (...args: any[]) => void): this;
once(event: string | symbol, listener: (...args: any[]) => void): this;
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
off(event: string | symbol, listener: (...args: any[]) => void): this;
removeAllListeners(event?: string | symbol): this;
setMaxListeners(n: number): this;
getMaxListeners(): number;
listeners(event: string | symbol): Function[];
rawListeners(event: string | symbol): Function[];
emit(event: string | symbol, ...args: any[]): boolean;
eventNames(): Array<string | symbol>;
listenerCount(type: string | symbol): number;
}
}
export = internal;
export = EventEmitter;
}

23
types/node/fs.d.ts vendored
View File

@ -745,21 +745,20 @@ declare module "fs" {
interface RmDirAsyncOptions extends RmDirOptions {
/**
* If an `EMFILE` error is encountered, Node.js will
* retry the operation with a linear backoff of 1ms longer on each try until the
* timeout duration passes this limit. This option is ignored if the `recursive`
* option is not `true`.
* @default 1000
* The amount of time in milliseconds to wait between retries.
* This option is ignored if the `recursive` option is not `true`.
* @default 100
*/
emfileWait?: number;
retryDelay?: number;
/**
* If an `EBUSY`, `ENOTEMPTY`, or `EPERM` error is
* encountered, Node.js will retry the operation with a linear backoff wait of
* 100ms longer on each try. This option represents the number of retries. This
* option is ignored if the `recursive` option is not `true`.
* @default 3
* If an `EBUSY`, `EMFILE`, `ENFILE`, `ENOTEMPTY`, or
* `EPERM` error is encountered, Node.js will retry the operation with a linear
* backoff wait of `retryDelay` ms longer on each try. This option represents the
* number of retries. This option is ignored if the `recursive` option is not
* `true`.
* @default 0
*/
maxBusyTries?: number;
maxRetries?: number;
}
/**

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

@ -77,6 +77,10 @@ declare module "http" {
defaultPort?: number | string;
localAddress?: string;
socketPath?: string;
/**
* @default 8192
*/
maxHeaderSize?: number;
method?: string;
path?: string | null;
headers?: OutgoingHttpHeaders;
@ -92,14 +96,18 @@ declare module "http" {
interface ServerOptions {
IncomingMessage?: typeof IncomingMessage;
ServerResponse?: typeof ServerResponse;
/**
* Optionally overrides the value of
* [`--max-http-header-size`][] for requests received by this server, i.e.
* the maximum length of request headers in bytes.
* @default 8192
*/
maxHeaderSize?: number;
}
type RequestListener = (req: IncomingMessage, res: ServerResponse) => void;
class Server extends NetServer {
constructor(requestListener?: RequestListener);
constructor(options: ServerOptions, requestListener?: RequestListener);
interface HttpBase {
setTimeout(msecs?: number, callback?: () => void): this;
setTimeout(callback: () => void): this;
/**
@ -111,13 +119,19 @@ declare module "http" {
timeout: number;
/**
* Limit the amount of time the parser will wait to receive the complete HTTP headers.
* @default 40000
* @default 60000
* {@link https://nodejs.org/api/http.html#http_server_headerstimeout}
*/
headersTimeout: number;
keepAliveTimeout: number;
}
interface Server extends HttpBase {}
class Server extends NetServer {
constructor(requestListener?: RequestListener);
constructor(options: ServerOptions, requestListener?: RequestListener);
}
// https://github.com/nodejs/node/blob/master/lib/_http_outgoing.js
class OutgoingMessage extends stream.Writable {
upgrading: boolean;
@ -125,6 +139,9 @@ declare module "http" {
shouldKeepAlive: boolean;
useChunkedEncodingByDefault: boolean;
sendDate: boolean;
/**
* @deprecated Use `writableEnded` instead.
*/
finished: boolean;
headersSent: boolean;
/**
@ -150,7 +167,6 @@ declare module "http" {
class ServerResponse extends OutgoingMessage {
statusCode: number;
statusMessage: string;
writableFinished: boolean;
constructor(req: IncomingMessage);

18
types/node/https.d.ts vendored
View File

@ -21,26 +21,10 @@ declare module "https" {
options: AgentOptions;
}
interface Server extends http.HttpBase {}
class Server extends tls.Server {
constructor(requestListener?: http.RequestListener);
constructor(options: ServerOptions, requestListener?: http.RequestListener);
setTimeout(callback: () => void): this;
setTimeout(msecs?: number, callback?: () => void): this;
/**
* Limits maximum incoming headers count. If set to 0, no limit will be applied.
* @default 2000
* {@link https://nodejs.org/api/http.html#http_server_maxheaderscount}
*/
maxHeadersCount: number | null;
timeout: number;
/**
* Limit the amount of time the parser will wait to receive the complete HTTP headers.
* @default 40000
* {@link https://nodejs.org/api/http.html#http_server_headerstimeout}
*/
headersTimeout: number;
keepAliveTimeout: number;
}
function createServer(requestListener?: http.RequestListener): Server;

12
types/node/index.d.ts vendored
View File

@ -1,4 +1,4 @@
// Type definitions for non-npm package Node.js 13.1
// Type definitions for non-npm package Node.js 13.5
// Project: http://nodejs.org/
// Definitions by: Microsoft TypeScript <https://github.com/Microsoft>
// DefinitelyTyped <https://github.com/DefinitelyTyped>
@ -43,16 +43,16 @@
// Ilia Baryshnikov <https://github.com/qwelias>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// NOTE: These definitions support NodeJS and TypeScript 3.2.
// NOTE: These definitions support NodeJS and TypeScript 3.5.
// NOTE: TypeScript version-specific augmentations can be found in the following paths:
// - ~/base.d.ts - Shared definitions common to all TypeScript versions
// - ~/index.d.ts - Definitions specific to TypeScript 2.8
// - ~/ts3.2/index.d.ts - Definitions specific to TypeScript 3.2
// - ~/ts3.5/index.d.ts - Definitions specific to TypeScript 3.5
// NOTE: Augmentations for TypeScript 3.2 and later should use individual files for overrides
// within the respective ~/ts3.2 (or later) folder. However, this is disallowed for versions
// prior to TypeScript 3.2, so the older definitions will be found here.
// NOTE: Augmentations for TypeScript 3.5 and later should use individual files for overrides
// within the respective ~/ts3.5 (or later) folder. However, this is disallowed for versions
// prior to TypeScript 3.5, so the older definitions will be found here.
// Base definitions for all NodeJS modules that are not specific to any version of TypeScript:
/// <reference path="base.d.ts" />

View File

@ -2,9 +2,9 @@
"private": true,
"types": "index",
"typesVersions": {
">=3.2.0-0": {
">=3.5.0-0": {
"*": [
"ts3.2/*"
"ts3.5/*"
]
}
}

View File

@ -47,6 +47,13 @@ declare module "readline" {
close(): void;
write(data: string | Buffer, key?: Key): void;
/**
* Returns the real position of the cursor in relation to the input
* prompt + string. Long input (wrapping) strings, as well as multiple
* line prompts are included in the calculations.
*/
getCursorPos(): CursorPos;
/**
* events.EventEmitter
* 1. close
@ -138,6 +145,11 @@ declare module "readline" {
type Direction = -1 | 0 | 1;
interface CursorPos {
rows: number;
cols: number;
}
/**
* Clears the current line of this WriteStream in a direction identified by `dir`.
*/

View File

@ -36,6 +36,11 @@ declare module "repl" {
* @see https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_custom_evaluation_functions
*/
eval?: REPLEval;
/**
* Defines if the repl prints output previews or not.
* @default `true` Always `false` in case `terminal` is falsy.
*/
preview?: boolean;
/**
* If `true`, specifies that the default `writer` function should include ANSI color
* styling to REPL output. If a custom `writer` function is provided then this has no

View File

@ -6,7 +6,9 @@ declare module "stream" {
}
namespace internal {
class Stream extends internal { }
class Stream extends internal {
constructor(opts?: ReadableOptions);
}
interface ReadableOptions {
highWaterMark?: number;

View File

@ -13,12 +13,6 @@ assert.doesNotThrow(() => {
assert.equal(3, "3", "uses == comparator");
assert.fail('stuff broke');
assert.fail('actual', 'expected', 'message');
assert.fail(1, 2, undefined, '>');
assert.ifError(0);
assert.notDeepStrictEqual({ x: { y: "3" } }, { x: { y: 3 } }, "uses !== comparator");
@ -42,3 +36,12 @@ assert.doesNotReject(async () => 1);
assert.doesNotReject(Promise.resolve(1));
assert.strict.strict.deepEqual([[[1, 2, 3]], 4, 5], [[[1, 2, '3']], 4, 5]);
assert.match('test', /test/, new Error('yeet'));
assert.match('test', /test/, 'yeet');
assert.fail('stuff broke');
assert.fail('actual', 'expected', 'message');
assert.fail(1, 2, undefined, '>');

View File

@ -78,3 +78,9 @@ const any: any = 1;
}
}, 'name');
}
async function test() {
for await (const e of events.on(new events.EventEmitter(), 'test')) {
console.log(e);
}
}

View File

@ -305,7 +305,7 @@ async function testPromisify() {
(async () => {
try {
await fs.promises.rmdir('some/test/path');
await fs.promises.rmdir('some/test/path', { recursive: true });
await fs.promises.rmdir('some/test/path', { recursive: true, maxRetries: 123, retryDelay: 123 });
} catch (e) {}
})();

View File

@ -198,3 +198,10 @@ const rl: readline.ReadLine = readline.createInterface(new stream.Readable());
// }
});
}
{
const rl = readline.createInterface({
input: process.stdin,
});
const pos: readline.CursorPos = rl.getCursorPos();
}

View File

@ -2,7 +2,9 @@ import { start, Recoverable } from "repl";
import { Context } from "vm";
{
let server = start();
let server = start({
preview: true,
});
let _boolean: boolean;
const _ctx: Context = {};

View File

@ -24,7 +24,16 @@ import * as fs from "fs";
const connOpts: ConnectionOptions = {
host: "127.0.0.1",
port: 55
port: 55,
pskCallback(hint) {
if (hint === 'something??') {
return null;
}
return {
identitty: 'henlo',
psk: Buffer.from('asd'),
};
},
};
const tlsSocket = connect(connOpts);
@ -53,6 +62,12 @@ import * as fs from "fs";
{
const _server = createServer({
enableTrace: true,
pskCallback(socket, ident) {
if (ident === 'something') {
return null;
}
return Buffer.from('asdasd');
}
});
_server.addContext("example", {

View File

@ -39,6 +39,10 @@ import { readFile } from 'fs';
colors: true,
};
util.inspect({
[util.inspect.custom]: <util.CustomInspectFunction> ((depth, opts) => opts.stylize('woop', 'module')),
});
util.formatWithOptions({ colors: true }, 'See object %O', { foo: 42 });
// util.callbackify

View File

@ -10,6 +10,7 @@ import { createContext } from "vm";
resourceLimits: {
codeRangeSizeMb: 123,
},
argv: ['asd'],
workerData: script
});
worker.on('message', resolve);

57
types/node/tls.d.ts vendored
View File

@ -62,6 +62,11 @@ declare module "tls" {
* SSL/TLS protocol version.
*/
version: string;
/**
* IETF name for the cipher suite.
*/
standardName: string;
}
interface EphemeralKeyInfo {
@ -389,6 +394,40 @@ declare module "tls" {
* 48-bytes of cryptographically strong pseudo-random data.
*/
ticketKeys?: Buffer;
/**
*
* @param socket
* @param identity identity parameter sent from the client.
* @return pre-shared key that must either be
* a buffer or `null` to stop the negotiation process. Returned PSK must be
* compatible with the selected cipher's digest.
*
* When negotiating TLS-PSK (pre-shared keys), this function is called
* with the identity provided by the client.
* If the return value is `null` the negotiation process will stop and an
* "unknown_psk_identity" alert message will be sent to the other party.
* If the server wishes to hide the fact that the PSK identity was not known,
* the callback must provide some random data as `psk` to make the connection
* fail with "decrypt_error" before negotiation is finished.
* PSK ciphers are disabled by default, and using TLS-PSK thus
* requires explicitly specifying a cipher suite with the `ciphers` option.
* More information can be found in the RFC 4279.
*/
pskCallback?(socket: TLSSocket, identity: string): DataView | NodeJS.TypedArray | null;
/**
* hint to send to a client to help
* with selecting the identity during TLS-PSK negotiation. Will be ignored
* in TLS 1.3. Upon failing to set pskIdentityHint `tlsClientError` will be
* emitted with `ERR_TLS_PSK_SET_IDENTIY_HINT_FAILED` code.
*/
pskIdentityHint?: string;
}
interface PSKCallbackNegotation {
psk: DataView | NodeJS.TypedArray;
identitty: string;
}
interface ConnectionOptions extends SecureContextOptions, CommonConnectionOptions {
@ -402,6 +441,24 @@ declare module "tls" {
minDHSize?: number;
lookup?: net.LookupFunction;
timeout?: number;
/**
* When negotiating TLS-PSK (pre-shared keys), this function is called
* with optional identity `hint` provided by the server or `null`
* in case of TLS 1.3 where `hint` was removed.
* It will be necessary to provide a custom `tls.checkServerIdentity()`
* for the connection as the default one will try to check hostname/IP
* of the server against the certificate but that's not applicable for PSK
* because there won't be a certificate present.
* More information can be found in the RFC 4279.
*
* @param hint message sent from the server to help client
* decide which identity to use during negotiation.
* Always `null` if TLS 1.3 is used.
* @returns Return `null` to stop the negotiation process. `psk` must be
* compatible with the selected cipher's digest.
* `identity` must use UTF-8 encoding.
*/
pskCallback?(hint: string | null): PSKCallbackNegotation | null;
}
class Server extends net.Server {

View File

@ -1,4 +1,4 @@
// NOTE: These definitions support NodeJS and TypeScript 3.2.
// NOTE: These definitions support NodeJS and TypeScript 3.5.
// Reference required types from the default lib:
/// <reference lib="es2018" />
@ -10,7 +10,8 @@
// tslint:disable-next-line:no-bad-reference
/// <reference path="../base.d.ts" />
// TypeScript 3.2-specific augmentations:
// TypeScript 3.5-specific augmentations:
/// <reference path="fs.d.ts" />
/// <reference path="util.d.ts" />
/// <reference path="globals.d.ts" />
/// <reference path="wasi.d.ts" />

View File

@ -73,3 +73,19 @@ import { BigIntStats, statSync, Stats } from 'fs';
b = a.readBigUInt64LE(123);
b = a.readBigUInt64BE(123);
}
import { WASI } from 'wasi';
const wasi = new WASI({
args: process.argv,
env: process.env,
preopens: {
'/sandbox': '/some/real/path/that/wasm/can/access'
}
});
const importObject = { wasi_unstable: wasi.wasiImport };
(async () => {
const wasm = await WebAssembly.compile(Buffer.from('dummy'));
const instance = await WebAssembly.instantiate(wasm, importObject);
wasi.start(instance);
})();

45
types/node/ts3.5/wasi.d.ts vendored Normal file
View File

@ -0,0 +1,45 @@
declare module 'wasi' {
interface WASIOptions {
/**
* An array of strings that the WebAssembly application will
* see as command line arguments. The first argument is the virtual path to the
* WASI command itself.
*/
args?: string[];
/**
* An object similar to `process.env` that the WebAssembly
* application will see as its environment.
*/
env?: object;
/**
* This object represents the WebAssembly application's
* sandbox directory structure. The string keys of `preopens` are treated as
* directories within the sandbox. The corresponding values in `preopens` are
* the real paths to those directories on the host machine.
*/
preopens?: {
[key: string]: string;
};
}
class WASI {
constructor(options?: WASIOptions);
/**
*
* Attempt to begin execution of `instance` by invoking its `_start()` export.
* If `instance` does not contain a `_start()` export, then `start()` attempts to
* invoke the `__wasi_unstable_reactor_start()` export. If neither of those exports
* is present on `instance`, then `start()` does nothing.
*
* `start()` requires that `instance` exports a [`WebAssembly.Memory`][] named
* `memory`. If `instance` does not have a `memory` export an exception is thrown.
*/
start(instance: object): void; // TODO: avoid DOM dependency until WASM moved to own lib.
/**
* Is an object that implements the WASI system call API. This object
* should be passed as the `wasi_unstable` import during the instantiation of a
* [`WebAssembly.Instance`][].
*/
readonly wasiImport: { [key: string]: any }; // TODO: Narrow to DOM types
}
}

View File

@ -54,4 +54,4 @@
"noEmit": true,
"forceConsistentCasingInFileNames": true
}
}
}

View File

@ -1,5 +1,10 @@
declare module "util" {
interface InspectOptions extends NodeJS.InspectOptions { }
type Style = 'special' | 'number' | 'bigint' | 'boolean' | 'undefined' | 'null' | 'string' | 'symbol' | 'date' | 'regexp' | 'module';
type CustomInspectFunction = (depth: number, options: InspectOptionsStylized) => string;
interface InspectOptionsStylized extends InspectOptions {
stylize(text: string, styleType: Style): string;
}
function format(format: any, ...param: any[]): string;
function formatWithOptions(inspectOptions: InspectOptions, format: string, ...param: any[]): string;
/** @deprecated since v0.11.3 - use a third party module instead. */
@ -11,7 +16,7 @@ declare module "util" {
[color: string]: [number, number] | undefined
};
let styles: {
[style: string]: string | undefined
[K in Style]: string
};
let defaultOptions: InspectOptions;
/**

View File

@ -54,6 +54,13 @@ declare module "worker_threads" {
}
interface WorkerOptions {
/**
* List of arguments which would be stringified and appended to
* `process.argv` in the worker. This is mostly similar to the `workerData`
* but the values will be available on the global `process.argv` as if they
* were passed as CLI options to the script.
*/
argv?: any[];
eval?: boolean;
workerData?: any;
stdin?: boolean;

View File

@ -57,7 +57,7 @@ write(9, "hello", null, "utf-8")
rename("old", "new");
// $ExpectType Promise<void>
rmdir("trash/unwanted", { maxBusyTries: 5 });
rmdir("trash/unwanted", { maxRetries: 5 });
// $ExpectType Promise<void>
mkdir("new/goodies");