diff --git a/types/node/dns.d.ts b/types/node/dns.d.ts index d2b0505648..32cba61184 100644 --- a/types/node/dns.d.ts +++ b/types/node/dns.d.ts @@ -2,6 +2,11 @@ declare module "dns" { // Supported getaddrinfo flags. const ADDRCONFIG: number; const V4MAPPED: number; + /** + * If `dns.V4MAPPED` is specified, return resolved IPv6 addresses as + * well as IPv4 mapped IPv6 addresses. + */ + const ALL: number; interface LookupOptions { family?: number; diff --git a/types/node/fs.d.ts b/types/node/fs.d.ts index ace1e5b958..ce8dbe19a9 100644 --- a/types/node/fs.d.ts +++ b/types/node/fs.d.ts @@ -1404,6 +1404,21 @@ declare module "fs" { ): Promise<{ bytesRead: number, buffer: TBuffer }>; } + interface ReadSyncOptions { + /** + * @default 0 + */ + offset?: number; + /** + * @default `length of buffer` + */ + length?: number; + /** + * @default null + */ + position?: number | null; + } + /** * Synchronously reads data from the file referenced by the supplied file descriptor, returning the number of bytes read. * @param fd A file descriptor. @@ -1414,6 +1429,12 @@ declare module "fs" { */ function readSync(fd: number, buffer: NodeJS.ArrayBufferView, offset: number, length: number, position: number | null): number; + /** + * Similar to the above `fs.readSync` function, this version takes an optional `options` object. + * If no `options` object is specified, it will default with the above values. + */ + function readSync(fd: number, buffer: NodeJS.ArrayBufferView, opts?: ReadSyncOptions): number; + /** * Asynchronously reads the entire contents of a file. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. @@ -2051,6 +2072,32 @@ declare module "fs" { */ function writevSync(fd: number, buffers: NodeJS.ArrayBufferView[], position?: number): number; + function readv( + fd: number, + buffers: NodeJS.ArrayBufferView[], + cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => void + ): void; + function readv( + fd: number, + buffers: NodeJS.ArrayBufferView[], + position: number, + cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => void + ): void; + + interface ReadVResult { + bytesRead: number; + buffers: NodeJS.ArrayBufferView[]; + } + + namespace readv { + function __promisify__(fd: number, buffers: NodeJS.ArrayBufferView[], position?: number): Promise; + } + + /** + * See `readv`. + */ + function readvSync(fd: number, buffers: NodeJS.ArrayBufferView[], position?: number): number; + interface OpenDirOptions { encoding?: BufferEncoding; /** @@ -2202,6 +2249,11 @@ declare module "fs" { */ writev(buffers: NodeJS.ArrayBufferView[], position?: number): Promise; + /** + * See `fs.readv` promisified version. + */ + readv(buffers: NodeJS.ArrayBufferView[], position?: number): Promise; + /** * Asynchronous close(2) - close a `FileHandle`. */ diff --git a/types/node/globals.d.ts b/types/node/globals.d.ts index def669a17c..34764bef38 100644 --- a/types/node/globals.d.ts +++ b/types/node/globals.d.ts @@ -432,6 +432,13 @@ declare namespace NodeJS { customInspect?: boolean; showProxy?: boolean; maxArrayLength?: number | null; + /** + * Specifies the maximum number of characters to + * include when formatting. Set to `null` or `Infinity` to show all elements. + * Set to `0` or negative to show no characters. + * @default Infinity + */ + maxStringLength?: number | null; breakLength?: number; /** * Setting this to `false` causes each object key diff --git a/types/node/http.d.ts b/types/node/http.d.ts index 2c9c1e4e52..f59b3d269d 100644 --- a/types/node/http.d.ts +++ b/types/node/http.d.ts @@ -391,7 +391,7 @@ declare module "http" { /** * Read-only property specifying the maximum allowed size of HTTP headers in bytes. - * Defaults to 8KB. Configurable using the [`--max-http-header-size`][] CLI option. + * Defaults to 16KB. Configurable using the [`--max-http-header-size`][] CLI option. */ const maxHeaderSize: number; } diff --git a/types/node/index.d.ts b/types/node/index.d.ts index a1e1e32fc6..0073973e6c 100644 --- a/types/node/index.d.ts +++ b/types/node/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for non-npm package Node.js 13.11 +// Type definitions for non-npm package Node.js 13.13 // Project: http://nodejs.org/ // Definitions by: Microsoft TypeScript // DefinitelyTyped diff --git a/types/node/node-tests.ts b/types/node/node-tests.ts index aedc7505af..559c7c62d6 100644 --- a/types/node/node-tests.ts +++ b/types/node/node-tests.ts @@ -5,7 +5,6 @@ import * as http from "http"; import * as https from "https"; import * as console2 from "console"; import * as timers from "timers"; -import * as dns from "dns"; import * as inspector from "inspector"; import * as trace_events from "trace_events"; @@ -268,119 +267,6 @@ import * as trace_events from "trace_events"; } } -/////////////////////////////////////////////////// -/// DNS Tests : https://nodejs.org/api/dns.html /// -/////////////////////////////////////////////////// - -{ - dns.lookup("nodejs.org", (err, address, family) => { - const _err: NodeJS.ErrnoException | null = err; - const _address: string = address; - const _family: number = family; - }); - dns.lookup("nodejs.org", 4, (err, address, family) => { - const _err: NodeJS.ErrnoException | null = err; - const _address: string = address; - const _family: number = family; - }); - dns.lookup("nodejs.org", 6, (err, address, family) => { - const _err: NodeJS.ErrnoException | null = err; - const _address: string = address; - const _family: number = family; - }); - dns.lookup("nodejs.org", {}, (err, address, family) => { - const _err: NodeJS.ErrnoException | null = err; - const _address: string = address; - const _family: number = family; - }); - dns.lookup( - "nodejs.org", - { - family: 4, - hints: dns.ADDRCONFIG | dns.V4MAPPED, - all: false - }, - (err, address, family) => { - const _err: NodeJS.ErrnoException | null = err; - const _address: string = address; - const _family: number = family; - } - ); - dns.lookup("nodejs.org", { all: true }, (err, addresses) => { - const _err: NodeJS.ErrnoException | null = err; - const _address: dns.LookupAddress[] = addresses; - }); - dns.lookup("nodejs.org", { all: true, verbatim: true }, (err, addresses) => { - const _err: NodeJS.ErrnoException | null = err; - const _address: dns.LookupAddress[] = addresses; - }); - - function trueOrFalse(): boolean { - return Math.random() > 0.5 ? true : false; - } - dns.lookup("nodejs.org", { all: trueOrFalse() }, (err, addresses, family) => { - const _err: NodeJS.ErrnoException | null = err; - const _addresses: string | dns.LookupAddress[] = addresses; - const _family: number | undefined = family; - }); - - dns.lookupService("127.0.0.1", 0, (err, hostname, service) => { - const _err: NodeJS.ErrnoException | null = err; - const _hostname: string = hostname; - const _service: string = service; - }); - - dns.resolve("nodejs.org", (err, addresses) => { - const _addresses: string[] = addresses; - }); - dns.resolve("nodejs.org", "A", (err, addresses) => { - const _addresses: string[] = addresses; - }); - dns.resolve("nodejs.org", "AAAA", (err, addresses) => { - const _addresses: string[] = addresses; - }); - dns.resolve("nodejs.org", "ANY", (err, addresses) => { - const _addresses: dns.AnyRecord[] = addresses; - }); - dns.resolve("nodejs.org", "MX", (err, addresses) => { - const _addresses: dns.MxRecord[] = addresses; - }); - - dns.resolve4("nodejs.org", (err, addresses) => { - const _addresses: string[] = addresses; - }); - dns.resolve4("nodejs.org", { ttl: true }, (err, addresses) => { - const _addresses: dns.RecordWithTtl[] = addresses; - }); - { - const ttl = false; - dns.resolve4("nodejs.org", { ttl }, (err, addresses) => { - const _addresses: string[] | dns.RecordWithTtl[] = addresses; - }); - } - - dns.resolve6("nodejs.org", (err, addresses) => { - const _addresses: string[] = addresses; - }); - dns.resolve6("nodejs.org", { ttl: true }, (err, addresses) => { - const _addresses: dns.RecordWithTtl[] = addresses; - }); - { - const ttl = false; - dns.resolve6("nodejs.org", { ttl }, (err, addresses) => { - const _addresses: string[] | dns.RecordWithTtl[] = addresses; - }); - } - { - const resolver = new dns.Resolver(); - resolver.setServers(["4.4.4.4"]); - resolver.resolve("nodejs.org", (err, addresses) => { - const _addresses: string[] = addresses; - }); - resolver.cancel(); - } -} - /***************************************************************************** * * * The following tests are the modules not mentioned in document but existed * diff --git a/types/node/test/dns.ts b/types/node/test/dns.ts new file mode 100644 index 0000000000..1af8fa54c7 --- /dev/null +++ b/types/node/test/dns.ts @@ -0,0 +1,108 @@ +import { lookup, ADDRCONFIG, V4MAPPED, LookupAddress, lookupService, resolve, AnyRecord, MxRecord, resolve4, RecordWithTtl, resolve6, Resolver, ALL } from 'dns'; + +lookup("nodejs.org", (err, address, family) => { + const _err: NodeJS.ErrnoException | null = err; + const _address: string = address; + const _family: number = family; +}); +lookup("nodejs.org", 4, (err, address, family) => { + const _err: NodeJS.ErrnoException | null = err; + const _address: string = address; + const _family: number = family; +}); +lookup("nodejs.org", 6, (err, address, family) => { + const _err: NodeJS.ErrnoException | null = err; + const _address: string = address; + const _family: number = family; +}); +lookup("nodejs.org", {}, (err, address, family) => { + const _err: NodeJS.ErrnoException | null = err; + const _address: string = address; + const _family: number = family; +}); +lookup( + "nodejs.org", + { + family: 4, + hints: ADDRCONFIG | V4MAPPED | ALL, + all: false + }, + (err, address, family) => { + const _err: NodeJS.ErrnoException | null = err; + const _address: string = address; + const _family: number = family; + } +); +lookup("nodejs.org", { all: true }, (err, addresses) => { + const _err: NodeJS.ErrnoException | null = err; + const _address: LookupAddress[] = addresses; +}); +lookup("nodejs.org", { all: true, verbatim: true }, (err, addresses) => { + const _err: NodeJS.ErrnoException | null = err; + const _address: LookupAddress[] = addresses; +}); + +function trueOrFalse(): boolean { + return Math.random() > 0.5 ? true : false; +} +lookup("nodejs.org", { all: trueOrFalse() }, (err, addresses, family) => { + const _err: NodeJS.ErrnoException | null = err; + const _addresses: string | LookupAddress[] = addresses; + const _family: number | undefined = family; +}); + +lookupService("127.0.0.1", 0, (err, hostname, service) => { + const _err: NodeJS.ErrnoException | null = err; + const _hostname: string = hostname; + const _service: string = service; +}); + +resolve("nodejs.org", (err, addresses) => { + const _addresses: string[] = addresses; +}); +resolve("nodejs.org", "A", (err, addresses) => { + const _addresses: string[] = addresses; +}); +resolve("nodejs.org", "AAAA", (err, addresses) => { + const _addresses: string[] = addresses; +}); +resolve("nodejs.org", "ANY", (err, addresses) => { + const _addresses: AnyRecord[] = addresses; +}); +resolve("nodejs.org", "MX", (err, addresses) => { + const _addresses: MxRecord[] = addresses; +}); + +resolve4("nodejs.org", (err, addresses) => { + const _addresses: string[] = addresses; +}); +resolve4("nodejs.org", { ttl: true }, (err, addresses) => { + const _addresses: RecordWithTtl[] = addresses; +}); +{ + const ttl = false; + resolve4("nodejs.org", { ttl }, (err, addresses) => { + const _addresses: string[] | RecordWithTtl[] = addresses; + }); +} + +resolve6("nodejs.org", (err, addresses) => { + const _addresses: string[] = addresses; +}); +resolve6("nodejs.org", { ttl: true }, (err, addresses) => { + const _addresses: RecordWithTtl[] = addresses; +}); +{ + const ttl = false; + resolve6("nodejs.org", { ttl }, (err, addresses) => { + const _addresses: string[] | RecordWithTtl[] = addresses; + }); +} +{ + const resolver = new Resolver(); + resolver.setServers(["4.4.4.4"]); + resolver.resolve("nodejs.org", (err, addresses) => { + const _addresses: string[] = addresses; + }); + resolver.cancel(); +} diff --git a/types/node/test/fs.ts b/types/node/test/fs.ts index 4045bc5cea..024ae5fcd5 100644 --- a/types/node/test/fs.ts +++ b/types/node/test/fs.ts @@ -70,6 +70,11 @@ import * as util from 'util'; { fs.readSync(1, new DataView(new ArrayBuffer(1)), 0, 1, 0); + fs.readSync(1, Buffer.from(''), { + length: 123, + offset: 456, + position: null, + }); } { @@ -352,3 +357,9 @@ async function testPromisify() { const readStream = fs.createReadStream('./index.d.ts'); const _rom = readStream.readableObjectMode; // $ExpectType boolean } + +{ + fs.readvSync(123, [Buffer.from('wut')]); + fs.readv(123, [Buffer.from('wut')], 123, (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => { + }); +} diff --git a/types/node/test/util.ts b/types/node/test/util.ts index 92965245d2..2a765b98a7 100644 --- a/types/node/test/util.ts +++ b/types/node/test/util.ts @@ -13,6 +13,7 @@ import { readFile } from 'fs'; showProxy: true, maxArrayLength: 10, breakLength: 20, + maxStringLength: 123, compact: true, sorted(a, b) { return b.localeCompare(a); diff --git a/types/node/test/worker_threads.ts b/types/node/test/worker_threads.ts index 68bbac89d8..0c4923a88f 100644 --- a/types/node/test/worker_threads.ts +++ b/types/node/test/worker_threads.ts @@ -5,6 +5,7 @@ import { Readable } from "stream"; { if (workerThreads.isMainThread) { + const { port1 } = new workerThreads.MessageChannel(); module.exports = async function parseJSAsync(script: string) { return new Promise((resolve, reject) => { const worker = new workerThreads.Worker(__filename, { @@ -12,7 +13,8 @@ import { Readable } from "stream"; codeRangeSizeMb: 123, }, argv: ['asd'], - workerData: script + workerData: script, + transferList: [port1], }); worker.on('message', resolve); worker.on('error', reject); diff --git a/types/node/tsconfig.json b/types/node/tsconfig.json index f5b245a474..138102c082 100644 --- a/types/node/tsconfig.json +++ b/types/node/tsconfig.json @@ -10,6 +10,7 @@ "test/cluster.ts", "test/crypto.ts", "test/dgram.ts", + "test/dns.ts", "test/events.ts", "test/fs.ts", "test/global.ts", diff --git a/types/node/worker_threads.d.ts b/types/node/worker_threads.d.ts index d38a316c0f..2f7cb03124 100644 --- a/types/node/worker_threads.d.ts +++ b/types/node/worker_threads.d.ts @@ -2,6 +2,7 @@ declare module "worker_threads" { import { Context } from "vm"; import { EventEmitter } from "events"; import { Readable, Writable } from "stream"; + import { URL } from "url"; const isMainThread: boolean; const parentPort: null | MessagePort; @@ -70,6 +71,10 @@ declare module "worker_threads" { stderr?: boolean; execArgv?: string[]; resourceLimits?: ResourceLimits; + /** + * Additional data to send in the first worker message. + */ + transferList?: Array; } interface ResourceLimits { @@ -85,7 +90,12 @@ declare module "worker_threads" { readonly threadId: number; readonly resourceLimits?: ResourceLimits; - constructor(filename: string, options?: WorkerOptions); + /** + * @param filename The path to the Worker’s main script or module. + * Must be either an absolute path or a relative path (i.e. relative to the current working directory) starting with ./ or ../, + * or a WHATWG URL object using file: protocol. If options.eval is true, this is a string containing JavaScript code rather than a path. + */ + constructor(filename: string | URL, options?: WorkerOptions); postMessage(value: any, transferList?: Array): void; ref(): void;