-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(deps-dev): bump @types/node from 20.3.3 to 20.5.7 #978
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dependabot
bot
added
dependencies
Pull requests that update a dependency file
javascript
Pull requests that update Javascript code
labels
Sep 1, 2023
Diff between @types/node 20.3.3 and 20.5.7diff --git a/README.md b/README.md
index v20.3.3..v20.5.7 100777
--- a/README.md
+++ b/README.md
@@ -9,8 +9,8 @@
### Additional Details
- * Last updated: Fri, 30 Jun 2023 23:02:45 GMT
+ * Last updated: Mon, 28 Aug 2023 00:33:00 GMT
* Dependencies: none
* Global values: `AbortController`, `AbortSignal`, `__dirname`, `__filename`, `console`, `exports`, `gc`, `global`, `module`, `process`, `require`, `structuredClone`
# Credits
-These definitions were written by [Microsoft TypeScript](https://github.com/Microsoft), [DefinitelyTyped](https://github.com/DefinitelyTyped), [Alberto Schiabel](https://github.com/jkomyno), [Alvis HT Tang](https://github.com/alvis), [Andrew Makarov](https://github.com/r3nya), [Benjamin Toueg](https://github.com/btoueg), [Chigozirim C.](https://github.com/smac89), [David Junger](https://github.com/touffy), [Deividas Bakanas](https://github.com/DeividasBakanas), [Eugene Y. Q. Shen](https://github.com/eyqs), [Hannes Magnusson](https://github.com/Hannes-Magnusson-CK), [Huw](https://github.com/hoo29), [Kelvin Jin](https://github.com/kjin), [Klaus Meinhardt](https://github.com/ajafff), [Lishude](https://github.com/islishude), [Mariusz Wiktorczyk](https://github.com/mwiktorczyk), [Mohsen Azimi](https://github.com/mohsen1), [Nicolas Even](https://github.com/n-e), [Nikita Galkin](https://github.com/galkin), [Parambir Singh](https://github.com/parambirs), [Sebastian Silbermann](https://github.com/eps1lon), [Simon Schick](https://github.com/SimonSchick), [Thomas den Hollander](https://github.com/ThomasdenH), [Wilco Bakker](https://github.com/WilcoBakker), [wwwy3y3](https://github.com/wwwy3y3), [Samuel Ainsworth](https://github.com/samuela), [Kyle Uehlein](https://github.com/kuehlein), [Thanik Bhongbhibhat](https://github.com/bhongy), [Marcin Kopacz](https://github.com/chyzwar), [Trivikram Kamat](https://github.com/trivikr), [Junxiao Shi](https://github.com/yoursunny), [Ilia Baryshnikov](https://github.com/qwelias), [ExE Boss](https://github.com/ExE-Boss), [Piotr Błażejewicz](https://github.com/peterblazejewicz), [Anna Henningsen](https://github.com/addaleax), [Victor Perin](https://github.com/victorperin), [Yongsheng Zhang](https://github.com/ZYSzys), [NodeJS Contributors](https://github.com/NodeJS), [Linus Unnebäck](https://github.com/LinusU), [wafuwafu13](https://github.com/wafuwafu13), [Matteo Collina](https://github.com/mcollina), and [Dmitry Semigradsky](https://github.com/Semigradsky).
+These definitions were written by [Microsoft TypeScript](https://github.com/Microsoft), [DefinitelyTyped](https://github.com/DefinitelyTyped), [Alberto Schiabel](https://github.com/jkomyno), [Alvis HT Tang](https://github.com/alvis), [Andrew Makarov](https://github.com/r3nya), [Benjamin Toueg](https://github.com/btoueg), [Chigozirim C.](https://github.com/smac89), [David Junger](https://github.com/touffy), [Deividas Bakanas](https://github.com/DeividasBakanas), [Eugene Y. Q. Shen](https://github.com/eyqs), [Hannes Magnusson](https://github.com/Hannes-Magnusson-CK), [Huw](https://github.com/hoo29), [Kelvin Jin](https://github.com/kjin), [Klaus Meinhardt](https://github.com/ajafff), [Lishude](https://github.com/islishude), [Mariusz Wiktorczyk](https://github.com/mwiktorczyk), [Mohsen Azimi](https://github.com/mohsen1), [Nicolas Even](https://github.com/n-e), [Nikita Galkin](https://github.com/galkin), [Parambir Singh](https://github.com/parambirs), [Sebastian Silbermann](https://github.com/eps1lon), [Thomas den Hollander](https://github.com/ThomasdenH), [Wilco Bakker](https://github.com/WilcoBakker), [wwwy3y3](https://github.com/wwwy3y3), [Samuel Ainsworth](https://github.com/samuela), [Kyle Uehlein](https://github.com/kuehlein), [Thanik Bhongbhibhat](https://github.com/bhongy), [Marcin Kopacz](https://github.com/chyzwar), [Trivikram Kamat](https://github.com/trivikr), [Junxiao Shi](https://github.com/yoursunny), [Ilia Baryshnikov](https://github.com/qwelias), [ExE Boss](https://github.com/ExE-Boss), [Piotr Błażejewicz](https://github.com/peterblazejewicz), [Anna Henningsen](https://github.com/addaleax), [Victor Perin](https://github.com/victorperin), [Yongsheng Zhang](https://github.com/ZYSzys), [NodeJS Contributors](https://github.com/NodeJS), [Linus Unnebäck](https://github.com/LinusU), [wafuwafu13](https://github.com/wafuwafu13), [Matteo Collina](https://github.com/mcollina), and [Dmitry Semigradsky](https://github.com/Semigradsky).
diff --git a/child_process.d.ts b/child_process.d.ts
index v20.3.3..v20.5.7 100777
--- a/child_process.d.ts
+++ b/child_process.d.ts
@@ -304,4 +304,9 @@
kill(signal?: NodeJS.Signals | number): boolean;
/**
+ * Calls {@link ChildProcess.kill} with `'SIGTERM'`.
+ * @since v20.5.0
+ */
+ [Symbol.dispose](): void;
+ /**
* When an IPC channel has been established between the parent and child (
* i.e. when using {@link fork}), the `subprocess.send()` method can
diff --git a/crypto.d.ts b/crypto.d.ts
index v20.3.3..v20.5.7 100777
--- a/crypto.d.ts
+++ b/crypto.d.ts
@@ -1517,8 +1517,13 @@
private constructor();
/**
- * Generates private and public Diffie-Hellman key values, and returns
+ * Generates private and public Diffie-Hellman key values unless they have been
+ * generated or computed already, and returns
* the public key in the specified `encoding`. This key should be
* transferred to the other party.
* If `encoding` is provided a string is returned; otherwise a `Buffer` is returned.
+ *
+ * This function is a thin wrapper around [`DH_generate_key()`](https://www.openssl.org/docs/man3.0/man3/DH_generate_key.html). In particular,
+ * once a private key has been generated or set, calling this function only updates
+ * the public key but does not generate a new private key.
* @since v0.5.0
* @param encoding The `encoding` of the return value.
@@ -1592,4 +1597,7 @@
* to be a string. If no `encoding` is provided, `privateKey` is expected
* to be a `Buffer`, `TypedArray`, or `DataView`.
+ *
+ * This function does not automatically compute the associated public key. Either `diffieHellman.setPublicKey()` or `diffieHellman.generateKeys()` can be
+ * used to manually provide the public key or to automatically derive it.
* @since v0.5.0
* @param encoding The `encoding` of the `privateKey` string.
diff --git a/dgram.d.ts b/dgram.d.ts
index v20.3.3..v20.5.7 100777
--- a/dgram.d.ts
+++ b/dgram.d.ts
@@ -539,4 +539,9 @@
prependOnceListener(event: 'listening', listener: () => void): this;
prependOnceListener(event: 'message', listener: (msg: Buffer, rinfo: RemoteInfo) => void): this;
+ /**
+ * Calls `socket.close()` and returns a promise that fulfills when the socket has closed.
+ * @since v20.5.0
+ */
+ [Symbol.asyncDispose](): Promise<void>;
}
}
diff --git a/events.d.ts b/events.d.ts
index v20.3.3..v20.5.7 100777
--- a/events.d.ts
+++ b/events.d.ts
@@ -296,5 +296,34 @@
static getEventListeners(emitter: _DOMEventTarget | NodeJS.EventEmitter, name: string | symbol): Function[];
/**
+ * Returns the currently set max amount of listeners.
+ *
+ * For `EventEmitter`s this behaves exactly the same as calling `.getMaxListeners` on
+ * the emitter.
+ *
+ * For `EventTarget`s this is the only way to get the max event listeners for the
+ * event target. If the number of event handlers on a single EventTarget exceeds
+ * the max set, the EventTarget will print a warning.
+ *
* ```js
+ * import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events';
+ *
+ * {
+ * const ee = new EventEmitter();
+ * console.log(getMaxListeners(ee)); // 10
+ * setMaxListeners(11, ee);
+ * console.log(getMaxListeners(ee)); // 11
+ * }
+ * {
+ * const et = new EventTarget();
+ * console.log(getMaxListeners(et)); // 10
+ * setMaxListeners(11, et);
+ * console.log(getMaxListeners(et)); // 11
+ * }
+ * ```
+ * @since v19.9.0
+ */
+ static getMaxListeners(emitter: _DOMEventTarget | NodeJS.EventEmitter): number;
+ /**
+ * ```js
* import { setMaxListeners, EventEmitter } from 'node:events';
*
@@ -311,4 +340,39 @@
static setMaxListeners(n?: number, ...eventTargets: Array<_DOMEventTarget | NodeJS.EventEmitter>): void;
/**
+ * Listens once to the `abort` event on the provided `signal`.
+ *
+ * Listening to the `abort` event on abort signals is unsafe and may
+ * lead to resource leaks since another third party with the signal can
+ * call `e.stopImmediatePropagation()`. Unfortunately Node.js cannot change
+ * this since it would violate the web standard. Additionally, the original
+ * API makes it easy to forget to remove listeners.
+ *
+ * This API allows safely using `AbortSignal`s in Node.js APIs by solving these
+ * two issues by listening to the event such that `stopImmediatePropagation` does
+ * not prevent the listener from running.
+ *
+ * Returns a disposable so that it may be unsubscribed from more easily.
+ *
+ * ```js
+ * import { addAbortListener } from 'node:events';
+ *
+ * function example(signal) {
+ * let disposable;
+ * try {
+ * signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
+ * disposable = addAbortListener(signal, (e) => {
+ * // Do something when signal is aborted.
+ * });
+ * } finally {
+ * disposable?.[Symbol.dispose]();
+ * }
+ * }
+ * ```
+ * @since v20.5.0
+ * @experimental
+ * @return that removes the `abort` listener.
+ */
+ static addAbortListener(signal: AbortSignal, resource: (event: Event) => void): Disposable;
+ /**
* 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.
*
diff --git a/fs.d.ts b/fs.d.ts
index v20.3.3..v20.5.7 100777
--- a/fs.d.ts
+++ b/fs.d.ts
@@ -3619,14 +3619,27 @@
mode?: number | undefined;
autoClose?: boolean | undefined;
- /**
- * @default false
- */
emitClose?: boolean | undefined;
start?: number | undefined;
- highWaterMark?: number | undefined;
+ signal?: AbortSignal | null | undefined;
}
+ interface FSImplementation {
+ open?: (...args: any[]) => any;
+ close?: (...args: any[]) => any;
+ }
+ interface CreateReadStreamFSImplementation extends FSImplementation {
+ read: (...args: any[]) => any;
+ }
+ interface CreateWriteStreamFSImplementation extends FSImplementation {
+ write: (...args: any[]) => any;
+ writev?: (...args: any[]) => any;
+ }
interface ReadStreamOptions extends StreamOptions {
+ fs?: CreateReadStreamFSImplementation | null | undefined;
end?: number | undefined;
+ highWaterMark?: number | undefined;
}
+ interface WriteStreamOptions extends StreamOptions {
+ fs?: CreateWriteStreamFSImplementation | null | undefined;
+ }
/**
* Unlike the 16 KiB default `highWaterMark` for a `stream.Readable`, the stream
@@ -3721,5 +3734,5 @@
* @since v0.1.31
*/
- export function createWriteStream(path: PathLike, options?: BufferEncoding | StreamOptions): WriteStream;
+ export function createWriteStream(path: PathLike, options?: BufferEncoding | WriteStreamOptions): WriteStream;
/**
* Forces all currently queued I/O operations associated with the file to the
@@ -3901,4 +3914,29 @@
*/
export function readvSync(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): number;
+
+ export interface OpenAsBlobOptions {
+ /**
+ * An optional mime type for the blob.
+ *
+ * @default 'undefined'
+ */
+ type?: string | undefined;
+ }
+
+ /**
+ * Returns a Blob whose data is backed by the given file.
+ *
+ * The file must not be modified after the `Blob` is created.
+ * Any modifications will cause reading the `Blob` data to fail with a `DOMException` error.
+ * Synchronous stat operations on the file when the `Blob` is created, and before each read in order to detect whether the file data has been modified on disk.
+ *
+ * @param path
+ * @param [options]
+ *
+ * @experimental
+ * @since v19.8.0
+ */
+ export function openAsBlob(path: PathLike, options?: OpenAsBlobOptions): Promise<Blob>;
+
export interface OpenDirOptions {
/**
diff --git a/globals.d.ts b/globals.d.ts
index v20.3.3..v20.5.7 100777
--- a/globals.d.ts
+++ b/globals.d.ts
@@ -85,4 +85,26 @@
//#endregion borrowed
+//#region Disposable
+interface SymbolConstructor {
+ /**
+ * A method that is used to release resources held by an object. Called by the semantics of the `using` statement.
+ */
+ readonly dispose: unique symbol;
+
+ /**
+ * A method that is used to asynchronously release resources held by an object. Called by the semantics of the `await using` statement.
+ */
+ readonly asyncDispose: unique symbol;
+}
+
+interface Disposable {
+ [Symbol.dispose](): void;
+}
+
+interface AsyncDisposable {
+ [Symbol.asyncDispose](): PromiseLike<void>;
+}
+//#endregion Disposable
+
//#region ArrayLike.at()
interface RelativeIndexable<T> {
diff --git a/http2.d.ts b/http2.d.ts
index v20.3.3..v20.5.7 100777
--- a/http2.d.ts
+++ b/http2.d.ts
@@ -129,5 +129,5 @@
* @since v8.4.0
*/
- readonly session: Http2Session;
+ readonly session: Http2Session | undefined;
/**
* Provides miscellaneous information about the current state of the`Http2Stream`.
diff --git a/index.d.ts b/index.d.ts
index v20.3.3..v20.5.7 100777
--- a/index.d.ts
+++ b/index.d.ts
@@ -1,3 +1,3 @@
-// Type definitions for non-npm package Node.js 20.3
+// Type definitions for non-npm package Node.js 20.5
// Project: https://nodejs.org/
// Definitions by: Microsoft TypeScript <https://github.com/Microsoft>
@@ -22,5 +22,4 @@
// Parambir Singh <https://github.com/parambirs>
// Sebastian Silbermann <https://github.com/eps1lon>
-// Simon Schick <https://github.com/SimonSchick>
// Thomas den Hollander <https://github.com/ThomasdenH>
// Wilco Bakker <https://github.com/WilcoBakker>
diff --git a/inspector.d.ts b/inspector.d.ts
index v20.3.3..v20.5.7 100777
--- a/inspector.d.ts
+++ b/inspector.d.ts
@@ -1,3 +1,3 @@
-// eslint-disable-next-line dt-header
+// eslint-disable-next-line @definitelytyped/dt-header
// Type definitions for inspector
diff --git a/module.d.ts b/module.d.ts
index v20.3.3..v20.5.7 100777
--- a/module.d.ts
+++ b/module.d.ts
@@ -4,4 +4,5 @@
declare module 'module' {
import { URL } from 'node:url';
+ import { MessagePort } from 'node:worker_threads';
namespace Module {
/**
@@ -74,10 +75,125 @@
constructor(payload: SourceMapPayload);
/**
- * Given a line number and column number in the generated source file, returns
- * an object representing the position in the original file. The object returned
- * consists of the following keys:
+ * Given a line offset and column offset in the generated source
+ * file, returns an object representing the SourceMap range in the
+ * original file if found, or an empty object if not.
+ *
+ * The object returned contains the following keys:
+ *
+ * The returned value represents the raw range as it appears in the
+ * SourceMap, based on zero-indexed offsets, _not_ 1-indexed line and
+ * column numbers as they appear in Error messages and CallSite
+ * objects.
+ *
+ * To get the corresponding 1-indexed line and column numbers from a
+ * lineNumber and columnNumber as they are reported by Error stacks
+ * and CallSite objects, use `sourceMap.findOrigin(lineNumber, columnNumber)`
+ * @param lineOffset The zero-indexed line number offset in the generated source
+ * @param columnOffset The zero-indexed column number offset in the generated source
*/
- findEntry(line: number, column: number): SourceMapping;
+ findEntry(lineOffset: number, columnOffset: number): SourceMapping;
}
+ interface ImportAssertions extends NodeJS.Dict<string> {
+ type?: string | undefined;
+ }
+ type ModuleFormat = 'builtin' | 'commonjs' | 'json' | 'module' | 'wasm';
+ type ModuleSource = string | ArrayBuffer | NodeJS.TypedArray;
+ interface GlobalPreloadContext {
+ port: MessagePort;
+ }
+ /**
+ * Sometimes it might be necessary to run some code inside of the same global scope that the application runs in.
+ * This hook allows the return of a string that is run as a sloppy-mode script on startup.
+ *
+ * @param context Information to assist the preload code
+ * @return Code to run before application startup
+ */
+ type GlobalPreloadHook = (context: GlobalPreloadContext) => string;
+ interface ResolveHookContext {
+ /**
+ * Export conditions of the relevant `package.json`
+ */
+ conditions: string[];
+ /**
+ * An object whose key-value pairs represent the assertions for the module to import
+ */
+ importAssertions: ImportAssertions;
+ /**
+ * The module importing this one, or undefined if this is the Node.js entry point
+ */
+ parentURL: string | undefined;
+ }
+ interface ResolveFnOutput {
+ /**
+ * A hint to the load hook (it might be ignored)
+ */
+ format?: ModuleFormat | null | undefined;
+ /**
+ * The import assertions to use when caching the module (optional; if excluded the input will be used)
+ */
+ importAssertions?: ImportAssertions | undefined;
+ /**
+ * A signal that this hook intends to terminate the chain of `resolve` hooks.
+ * @default false
+ */
+ shortCircuit?: boolean | undefined;
+ /**
+ * The absolute URL to which this input resolves
+ */
+ url: string;
+ }
+ /**
+ * The `resolve` hook chain is responsible for resolving file URL for a given module specifier and parent URL, and optionally its format (such as `'module'`) as a hint to the `load` hook.
+ * If a format is specified, the load hook is ultimately responsible for providing the final `format` value (and it is free to ignore the hint provided by `resolve`);
+ * if `resolve` provides a format, a custom `load` hook is required even if only to pass the value to the Node.js default `load` hook.
+ *
+ * @param specifier The specified URL path of the module to be resolved
+ * @param context
+ * @param nextResolve The subsequent `resolve` hook in the chain, or the Node.js default `resolve` hook after the last user-supplied resolve hook
+ */
+ type ResolveHook = (
+ specifier: string,
+ context: ResolveHookContext,
+ nextResolve: (specifier: string, context?: ResolveHookContext) => ResolveFnOutput | Promise<ResolveFnOutput>
+ ) => ResolveFnOutput | Promise<ResolveFnOutput>;
+ interface LoadHookContext {
+ /**
+ * Export conditions of the relevant `package.json`
+ */
+ conditions: string[];
+ /**
+ * The format optionally supplied by the `resolve` hook chain
+ */
+ format: ModuleFormat;
+ /**
+ * An object whose key-value pairs represent the assertions for the module to import
+ */
+ importAssertions: ImportAssertions;
+ }
+ interface LoadFnOutput {
+ format: ModuleFormat;
+ /**
+ * A signal that this hook intends to terminate the chain of `resolve` hooks.
+ * @default false
+ */
+ shortCircuit?: boolean | undefined;
+ /**
+ * The source for Node.js to evaluate
+ */
+ source?: ModuleSource;
+ }
+ /**
+ * The `load` hook provides a way to define a custom method of determining how a URL should be interpreted, retrieved, and parsed.
+ * It is also in charge of validating the import assertion.
+ *
+ * @param url The URL/path of the module to be loaded
+ * @param context Metadata about the module
+ * @param nextLoad The subsequent `load` hook in the chain, or the Node.js default `load` hook after the last user-supplied `load` hook
+ */
+ type LoadHook = (
+ url: string,
+ context: LoadHookContext,
+ nextLoad: (url: string, context?: LoadHookContext) => LoadFnOutput | Promise<LoadFnOutput>
+ ) => LoadFnOutput | Promise<LoadFnOutput>;
}
interface Module extends NodeModule {}
diff --git a/net.d.ts b/net.d.ts
index v20.3.3..v20.5.7 100777
--- a/net.d.ts
+++ b/net.d.ts
@@ -17,5 +17,5 @@
import { Abortable, EventEmitter } from 'node:events';
import * as dns from 'node:dns';
- type LookupFunction = (hostname: string, options: dns.LookupOneOptions, callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void) => void;
+ type LookupFunction = (hostname: string, options: dns.LookupAllOptions, callback: (err: NodeJS.ErrnoException | null, addresses: dns.LookupAddress[]) => void) => void;
interface AddressInfo {
address: string;
@@ -640,4 +640,9 @@
prependOnceListener(event: 'listening', listener: () => void): this;
prependOnceListener(event: 'drop', listener: (data?: DropArgument) => void): this;
+ /**
+ * Calls {@link Server.close()} and returns a promise that fulfills when the server has closed.
+ * @since v20.5.0
+ */
+ [Symbol.asyncDispose](): Promise<void>;
}
type IPVersion = 'ipv4' | 'ipv6';
diff --git a/package.json b/package.json
index v20.3.3..v20.5.7 100777
--- a/package.json
+++ b/package.json
@@ -1,5 +1,5 @@
{
"name": "@types/node",
- "version": "20.3.3",
+ "version": "20.5.7",
"description": "TypeScript definitions for Node.js",
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node",
@@ -112,9 +112,4 @@
},
{
- "name": "Simon Schick",
- "url": "https://github.com/SimonSchick",
- "githubUsername": "SimonSchick"
- },
- {
"name": "Thomas den Hollander",
"url": "https://github.com/ThomasdenH",
@@ -233,5 +228,5 @@
"scripts": {},
"dependencies": {},
- "typesPublisherContentHash": "3e39c3e52b68b1f49042fb036058073871b4b113b18668910b0299a06f893177",
+ "typesPublisherContentHash": "3c31754d724881876a0bd7b216ddce3840ec052e1944538329b9271e525d425c",
"typeScriptVersion": "4.3"
}
\ No newline at end of file
diff --git a/perf_hooks.d.ts b/perf_hooks.d.ts
index v20.3.3..v20.5.7 100777
--- a/perf_hooks.d.ts
+++ b/perf_hooks.d.ts
@@ -32,5 +32,5 @@
declare module 'perf_hooks' {
import { AsyncResource } from 'node:async_hooks';
- type EntryType = 'node' | 'mark' | 'measure' | 'gc' | 'function' | 'http2' | 'http';
+ type EntryType = 'node' | 'mark' | 'measure' | 'gc' | 'function' | 'http2' | 'http' | 'dns';
interface NodeGCPerformanceDetail {
/**
diff --git a/stream.d.ts b/stream.d.ts
index v20.3.3..v20.5.7 100777
--- a/stream.d.ts
+++ b/stream.d.ts
@@ -23,4 +23,7 @@
import * as streamConsumers from 'node:stream/consumers';
import * as streamWeb from 'node:stream/web';
+
+ type ComposeFnParam = (source: any) => void;
+
class internal extends EventEmitter {
pipe<T extends NodeJS.WritableStream>(
@@ -30,8 +33,15 @@
}
): T;
+ compose<T extends NodeJS.ReadableStream>(stream: T | ComposeFnParam | Iterable<T> | AsyncIterable<T>, options?: { signal: AbortSignal }): T;
}
import Stream = internal.Stream;
import Readable = internal.Readable;
import ReadableOptions = internal.ReadableOptions;
+ interface ArrayOptions {
+ /** the maximum concurrent invocations of `fn` to call on the stream at once. **Default: 1**. */
+ concurrency?: number;
+ /** allows destroying the stream if the signal is aborted. */
+ signal?: AbortSignal;
+ }
class ReadableBase extends Stream implements NodeJS.ReadableStream {
/**
@@ -393,4 +403,136 @@
wrap(stream: NodeJS.ReadableStream): this;
push(chunk: any, encoding?: BufferEncoding): boolean;
+ /**
+ * The iterator created by this method gives users the option to cancel the destruction
+ * of the stream if the `for await...of` loop is exited by `return`, `break`, or `throw`,
+ * or if the iterator should destroy the stream if the stream emitted an error during iteration.
+ * @since v16.3.0
+ * @param options.destroyOnReturn When set to `false`, calling `return` on the async iterator,
+ * or exiting a `for await...of` iteration using a `break`, `return`, or `throw` will not destroy the stream.
+ * **Default: `true`**.
+ */
+ iterator(options?: {destroyOnReturn?: boolean}): AsyncIterableIterator<any>;
+ /**
+ * This method allows mapping over the stream. The *fn* function will be called for every chunk in the stream.
+ * If the *fn* function returns a promise - that promise will be `await`ed before being passed to the result stream.
+ * @since v17.4.0, v16.14.0
+ * @param fn a function to map over every chunk in the stream. Async or not.
+ * @returns a stream mapped with the function *fn*.
+ */
+ map(fn: (data: any, options?: Pick<ArrayOptions, "signal">) => any, options?: ArrayOptions): Readable;
+ /**
+ * This method allows filtering the stream. For each chunk in the stream the *fn* function will be called
+ * and if it returns a truthy value, the chunk will be passed to the result stream.
+ * If the *fn* function returns a promise - that promise will be `await`ed.
+ * @since v17.4.0, v16.14.0
+ * @param fn a function to filter chunks from the stream. Async or not.
+ * @returns a stream filtered with the predicate *fn*.
+ */
+ filter(fn: (data: any, options?: Pick<ArrayOptions, "signal">) => boolean | Promise<boolean>, options?: ArrayOptions): Readable;
+ /**
+ * This method allows iterating a stream. For each chunk in the stream the *fn* function will be called.
+ * If the *fn* function returns a promise - that promise will be `await`ed.
+ *
+ * This method is different from `for await...of` loops in that it can optionally process chunks concurrently.
+ * In addition, a `forEach` iteration can only be stopped by having passed a `signal` option
+ * and aborting the related AbortController while `for await...of` can be stopped with `break` or `return`.
+ * In either case the stream will be destroyed.
+ *
+ * This method is different from listening to the `'data'` event in that it uses the `readable` event
+ * in the underlying machinary and can limit the number of concurrent *fn* calls.
+ * @since v17.5.0
+ * @param fn a function to call on each chunk of the stream. Async or not.
+ * @returns a promise for when the stream has finished.
+ */
+ forEach(fn: (data: any, options?: Pick<ArrayOptions, "signal">) => void | Promise<void>, options?: ArrayOptions): Promise<void>;
+ /**
+ * This method allows easily obtaining the contents of a stream.
+ *
+ * As this method reads the entire stream into memory, it negates the benefits of streams. It's intended
+ * for interoperability and convenience, not as the primary way to consume streams.
+ * @since v17.5.0
+ * @returns a promise containing an array with the contents of the stream.
+ */
+ toArray(options?: Pick<ArrayOptions, "signal">): Promise<any[]>;
+ /**
+ * This method is similar to `Array.prototype.some` and calls *fn* on each chunk in the stream
+ * until the awaited return value is `true` (or any truthy value). Once an *fn* call on a chunk
+ * `await`ed return value is truthy, the stream is destroyed and the promise is fulfilled with `true`.
+ * If none of the *fn* calls on the chunks return a truthy value, the promise is fulfilled with `false`.
+ * @since v17.5.0
+ * @param fn a function to call on each chunk of the stream. Async or not.
+ * @returns a promise evaluating to `true` if *fn* returned a truthy value for at least one of the chunks.
+ */
+ some(fn: (data: any, options?: Pick<ArrayOptions, "signal">) => boolean | Promise<boolean>, options?: ArrayOptions): Promise<boolean>;
+ /**
+ * This method is similar to `Array.prototype.find` and calls *fn* on each chunk in the stream
+ * to find a chunk with a truthy value for *fn*. Once an *fn* call's awaited return value is truthy,
+ * the stream is destroyed and the promise is fulfilled with value for which *fn* returned a truthy value.
+ * If all of the *fn* calls on the chunks return a falsy value, the promise is fulfilled with `undefined`.
+ * @since v17.5.0
+ * @param fn a function to call on each chunk of the stream. Async or not.
+ * @returns a promise evaluating to the first chunk for which *fn* evaluated with a truthy value,
+ * or `undefined` if no element was found.
+ */
+ find<T>(fn: (data: any, options?: Pick<ArrayOptions, "signal">) => data is T, options?: ArrayOptions): Promise<T | undefined>;
+ find(fn: (data: any, options?: Pick<ArrayOptions, "signal">) => boolean | Promise<boolean>, options?: ArrayOptions): Promise<any>;
+ /**
+ * This method is similar to `Array.prototype.every` and calls *fn* on each chunk in the stream
+ * to check if all awaited return values are truthy value for *fn*. Once an *fn* call on a chunk
+ * `await`ed return value is falsy, the stream is destroyed and the promise is fulfilled with `false`.
+ * If all of the *fn* calls on the chunks return a truthy value, the promise is fulfilled with `true`.
+ * @since v17.5.0
+ * @param fn a function to call on each chunk of the stream. Async or not.
+ * @returns a promise evaluating to `true` if *fn* returned a truthy value for every one of the chunks.
+ */
+ every(fn: (data: any, options?: Pick<ArrayOptions, "signal">) => boolean | Promise<boolean>, options?: ArrayOptions): Promise<boolean>;
+ /**
+ * This method returns a new stream by applying the given callback to each chunk of the stream
+ * and then flattening the result.
+ *
+ * It is possible to return a stream or another iterable or async iterable from *fn* and the result streams
+ * will be merged (flattened) into the returned stream.
+ * @since v17.5.0
+ * @param fn a function to map over every chunk in the stream. May be async. May be a stream or generator.
+ * @returns a stream flat-mapped with the function *fn*.
+ */
+ flatMap(fn: (data: any, options?: Pick<ArrayOptions, "signal">) => any, options?: ArrayOptions): Readable;
+ /**
+ * This method returns a new stream with the first *limit* chunks dropped from the start.
+ * @since v17.5.0
+ * @param limit the number of chunks to drop from the readable.
+ * @returns a stream with *limit* chunks dropped from the start.
+ */
+ drop(limit: number, options?: Pick<ArrayOptions, "signal">): Readable;
+ /**
+ * This method returns a new stream with the first *limit* chunks.
+ * @since v17.5.0
+ * @param limit the number of chunks to take from the readable.
+ * @returns a stream with *limit* chunks taken.
+ */
+ take(limit: number, options?: Pick<ArrayOptions, "signal">): Readable;
+ /**
+ * This method returns a new stream with chunks of the underlying stream paired with a counter
+ * in the form `[index, chunk]`. The first index value is `0` and it increases by 1 for each chunk produced.
+ * @since v17.5.0
+ * @returns a stream of indexed pairs.
+ */
+ asIndexedPairs(options?: Pick<ArrayOptions, "signal">): Readable;
+ /**
+ * This method calls *fn* on each chunk of the stream in order, passing it the result from the calculation
+ * on the previous element. It returns a promise for the final value of the reduction.
+ *
+ * If no *initial* value is supplied the first chunk of the stream is used as the initial value.
+ * If the stream is empty, the promise is rejected with a `TypeError` with the `ERR_INVALID_ARGS` code property.
+ *
+ * The reducer function iterates the stream element-by-element which means that there is no *concurrency* parameter
+ * or parallelism. To perform a reduce concurrently, you can extract the async function to `readable.map` method.
+ * @since v17.5.0
+ * @param fn a reducer function to call over every chunk in the stream. Async or not.
+ * @param initial the initial value to use in the reduction.
+ * @returns a promise for the final value of the reduction.
+ */
+ reduce<T = any>(fn: (previous: any, data: any, options?: Pick<ArrayOptions, "signal">) => T, initial?: undefined, options?: Pick<ArrayOptions, "signal">): Promise<T>;
+ reduce<T = any>(fn: (previous: T, data: any, options?: Pick<ArrayOptions, "signal">) => T, initial: T, options?: Pick<ArrayOptions, "signal">): Promise<T>;
_destroy(error: Error | null, callback: (error?: Error | null) => void): void;
/**
@@ -474,4 +616,9 @@
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
[Symbol.asyncIterator](): AsyncIterableIterator<any>;
+ /**
+ * Calls `readable.destroy()` with an `AbortError` and returns a promise that fulfills when the stream is finished.
+ * @since v20.4.0
+ */
+ [Symbol.asyncDispose](): Promise<void>;
}
import WritableOptions = internal.WritableOptions;
diff --git a/test.d.ts b/test.d.ts
index v20.3.3..v20.5.7 100777
--- a/test.d.ts
+++ b/test.d.ts
@@ -77,8 +77,9 @@
* If any tests fail, the process exit code is set to `1`.
* @since v18.0.0, v16.17.0
- * @see [source](https://github.com/nodejs/node/blob/v20.2.0/lib/test.js)
+ * @see [source](https://github.com/nodejs/node/blob/v20.4.0/lib/test.js)
*/
declare module 'node:test' {
import { Readable } from 'node:stream';
+ import { AsyncResource } from 'node:async_hooks';
/**
* ```js
@@ -160,33 +161,33 @@
* @param options Configuration options for the suite. supports the same options as `test([name][, options][, fn])`.
* @param [fn='A no-op function'] The function under suite declaring all subtests and subsuites. The first argument to this function is a {@link SuiteContext} object.
- * @return `undefined`.
+ * @return Immediately fulfilled with `undefined`.
*/
- function describe(name?: string, options?: TestOptions, fn?: SuiteFn): void;
- function describe(name?: string, fn?: SuiteFn): void;
- function describe(options?: TestOptions, fn?: SuiteFn): void;
- function describe(fn?: SuiteFn): void;
+ function describe(name?: string, options?: TestOptions, fn?: SuiteFn): Promise<void>;
+ function describe(name?: string, fn?: SuiteFn): Promise<void>;
+ function describe(options?: TestOptions, fn?: SuiteFn): Promise<void>;
+ function describe(fn?: SuiteFn): Promise<void>;
namespace describe {
/**
* Shorthand for skipping a suite, same as `describe([name], { skip: true }[, fn])`.
*/
- function skip(name?: string, options?: TestOptions, fn?: SuiteFn): void;
- function skip(name?: string, fn?: SuiteFn): void;
- function skip(options?: TestOptions, fn?: SuiteFn): void;
- function skip(fn?: SuiteFn): void;
+ function skip(name?: string, options?: TestOptions, fn?: SuiteFn): Promise<void>;
+ function skip(name?: string, fn?: SuiteFn): Promise<void>;
+ function skip(options?: TestOptions, fn?: SuiteFn): Promise<void>;
+ function skip(fn?: SuiteFn): Promise<void>;
/**
* Shorthand for marking a suite as `TODO`, same as `describe([name], { todo: true }[, fn])`.
*/
- function todo(name?: string, options?: TestOptions, fn?: SuiteFn): void;
- function todo(name?: string, fn?: SuiteFn): void;
- function todo(options?: TestOptions, fn?: SuiteFn): void;
- function todo(fn?: SuiteFn): void;
+ function todo(name?: string, options?: TestOptions, fn?: SuiteFn): Promise<void>;
+ function todo(name?: string, fn?: SuiteFn): Promise<void>;
+ function todo(options?: TestOptions, fn?: SuiteFn): Promise<void>;
+ function todo(fn?: SuiteFn): Promise<void>;
/**
* Shorthand for marking a suite as `only`, same as `describe([name], { only: true }[, fn])`.
* @since v18.15.0
*/
- function only(name?: string, options?: TestOptions, fn?: SuiteFn): void;
- function only(name?: string, fn?: SuiteFn): void;
- function only(options?: TestOptions, fn?: SuiteFn): void;
- function only(fn?: SuiteFn): void;
+ function only(name?: string, options?: TestOptions, fn?: SuiteFn): Promise<void>;
+ function only(name?: string, fn?: SuiteFn): Promise<void>;
+ function only(options?: TestOptions, fn?: SuiteFn): Promise<void>;
+ function only(fn?: SuiteFn): Promise<void>;
}
/**
@@ -196,31 +197,31 @@
* @since v18.6.0, v16.17.0
*/
- function it(name?: string, options?: TestOptions, fn?: TestFn): void;
- function it(name?: string, fn?: TestFn): void;
- function it(options?: TestOptions, fn?: TestFn): void;
- function it(fn?: TestFn): void;
+ function it(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
+ function it(name?: string, fn?: TestFn): Promise<void>;
+ function it(options?: TestOptions, fn?: TestFn): Promise<void>;
+ function it(fn?: TestFn): Promise<void>;
namespace it {
/**
* Shorthand for skipping a test, same as `it([name], { skip: true }[, fn])`.
*/
- function skip(name?: string, options?: TestOptions, fn?: TestFn): void;
- function skip(name?: string, fn?: TestFn): void;
- function skip(options?: TestOptions, fn?: TestFn): void;
- function skip(fn?: TestFn): void;
+ function skip(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
+ function skip(name?: string, fn?: TestFn): Promise<void>;
+ function skip(options?: TestOptions, fn?: TestFn): Promise<void>;
+ function skip(fn?: TestFn): Promise<void>;
/**
* Shorthand for marking a test as `TODO`, same as `it([name], { todo: true }[, fn])`.
*/
- function todo(name?: string, options?: TestOptions, fn?: TestFn): void;
- function todo(name?: string, fn?: TestFn): void;
- function todo(options?: TestOptions, fn?: TestFn): void;
- function todo(fn?: TestFn): void;
+ function todo(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
+ function todo(name?: string, fn?: TestFn): Promise<void>;
+ function todo(options?: TestOptions, fn?: TestFn): Promise<void>;
+ function todo(fn?: TestFn): Promise<void>;
/**
* Shorthand for marking a test as `only`, same as `it([name], { only: true }[, fn])`.
* @since v18.15.0
*/
- function only(name?: string, options?: TestOptions, fn?: TestFn): void;
- function only(name?: string, fn?: TestFn): void;
- function only(options?: TestOptions, fn?: TestFn): void;
- function only(fn?: TestFn): void;
+ function only(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
+ function only(name?: string, fn?: TestFn): Promise<void>;
+ function only(options?: TestOptions, fn?: TestFn): Promise<void>;
+ function only(fn?: TestFn): Promise<void>;
}
/**
@@ -228,24 +229,24 @@
* @since v20.2.0
*/
- function skip(name?: string, options?: TestOptions, fn?: TestFn): void;
- function skip(name?: string, fn?: TestFn): void;
- function skip(options?: TestOptions, fn?: TestFn): void;
- function skip(fn?: TestFn): void;
+ function skip(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
+ function skip(name?: string, fn?: TestFn): Promise<void>;
+ function skip(options?: TestOptions, fn?: TestFn): Promise<void>;
+ function skip(fn?: TestFn): Promise<void>;
/**
* Shorthand for marking a test as `TODO`, same as `test([name], { todo: true }[, fn])`.
* @since v20.2.0
*/
- function todo(name?: string, options?: TestOptions, fn?: TestFn): void;
- function todo(name?: string, fn?: TestFn): void;
- function todo(options?: TestOptions, fn?: TestFn): void;
- function todo(fn?: TestFn): void;
+ function todo(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
+ function todo(name?: string, fn?: TestFn): Promise<void>;
+ function todo(options?: TestOptions, fn?: TestFn): Promise<void>;
+ function todo(fn?: TestFn): Promise<void>;
/**
* Shorthand for marking a test as `only`, same as `test([name], { only: true }[, fn])`.
* @since v20.2.0
*/
- function only(name?: string, options?: TestOptions, fn?: TestFn): void;
- function only(name?: string, fn?: TestFn): void;
- function only(options?: TestOptions, fn?: TestFn): void;
- function only(fn?: TestFn): void;
+ function only(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
+ function only(name?: string, fn?: TestFn): Promise<void>;
+ function only(options?: TestOptions, fn?: TestFn): Promise<void>;
+ function only(fn?: TestFn): Promise<void>;
/**
* The type of a function under test. The first argument to this function is a
@@ -253,10 +254,19 @@
* the second argument.
*/
- type TestFn = (t: TestContext, done: (result?: any) => void) => any;
+ type TestFn = (t: TestContext, done: (result?: any) => void) => void | Promise<void>;
/**
* The type of a function under Suite.
- * If the test uses callbacks, the callback function is passed as an argument
*/
- type SuiteFn = (done: (result?: any) => void) => void;
+ type SuiteFn = (s: SuiteContext) => void | Promise<void>;
+ interface TestShard {
+ /**
+ * A positive integer between 1 and `<total>` that specifies the index of the shard to run.
+ */
+ index: number;
+ /**
+ * A positive integer that specifies the total number of shards to split the test files to.
+ */
+ total: number;
+ }
interface RunOptions {
/**
@@ -296,5 +306,28 @@
*/
testNamePatterns?: string | RegExp | string[] | RegExp[];
+ /**
+ * A function that accepts the TestsStream instance and can be used to setup listeners before any tests are run.
+ */
+ setup?: (root: Test) => void | Promise<void>;
+ /**
+ * Whether to run in watch mode or not.
+ * @default false
+ */
+ watch?: boolean | undefined;
+ /**
+ * Running tests in a specific shard.
+ * @default undefined
+ */
+ shard?: TestShard | undefined;
}
+ class Test extends AsyncResource {
+ concurrency: number;
+ nesting: number;
+ only: boolean;
+ reporter: TestsStream;
+ runOnlySubtests: boolean;
+ testNumber: number;
+ timeout: number | null;
+ }
/**
* A successful call to `run()` method will return a new `TestsStream` object, streaming a series of events representing the execution of the tests.`TestsStream` will emit events, in the
@@ -487,4 +520,22 @@
readonly mock: MockTracker;
}
+ /**
+ * An instance of `SuiteContext` is passed to each suite function in order to
+ * interact with the test runner. However, the `SuiteContext` constructor is not
+ * exposed as part of the API.
+ * @since v18.7.0, v16.17.0
+ */
+ class SuiteContext {
+ /**
+ * The name of the suite.
+ * @since v18.8.0, v16.18.0
+ */
+ readonly name: string;
+ /**
+ * Can be used to abort test subtasks when the test has been aborted.
+ * @since v18.7.0, v16.17.0
+ */
+ readonly signal: AbortSignal;
+ }
interface TestOptions {
/**
@@ -598,5 +649,5 @@
* second argument.
*/
- type HookFn = (done: (result?: any) => void) => any;
+ type HookFn = (s: SuiteContext, done: (result?: any) => void) => any;
/**
* Configuration options for hooks.
@@ -822,4 +873,5 @@
*/
restoreAll(): void;
+ timers: MockTimers;
}
const mock: MockTracker;
@@ -965,4 +1017,218 @@
restore(): void;
}
+ type Timer = 'setInterval' | 'clearInterval' | 'setTimeout' | 'clearTimeout';
+ /**
+ * Mocking timers is a technique commonly used in software testing to simulate and
+ * control the behavior of timers, such as `setInterval` and `setTimeout`,
+ * without actually waiting for the specified time intervals.
+ *
+ * The `MockTracker` provides a top-level `timers` export
+ * which is a `MockTimers` instance.
+ * @since v20.4.0
+ * @experimental
+ */
+ class MockTimers {
+ /**
+ * Enables timer mocking for the specified timers.
+ *
+ * **Note:** When you enable mocking for a specific timer, its associated
+ * clear function will also be implicitly mocked.
+ *
+ * Example usage:
+ *
+ * ```js
+ * import { mock } from 'node:test';
+ * mock.timers.enable(['setInterval']);
+ * ```
+ *
+ * ```js
+ * const { mock } = require('node:test');
+ * mock.timers.enable(['setInterval']);
+ * ```
+ *
+ * The above example enables mocking for the `setInterval` timer and
+ * implicitly mocks the `clearInterval` function. Only the `setInterval`and `clearInterval` functions from `node:timers`,`node:timers/promises`, and`globalThis` will be mocked.
+ *
+ * Alternatively, if you call `mock.timers.enable()` without any parameters:
+ *
+ * All timers (`'setInterval'`, `'clearInterval'`, `'setTimeout'`, and `'clearTimeout'`)
+ * will be mocked. The `setInterval`, `clearInterval`, `setTimeout`, and `clearTimeout`functions from `node:timers`, `node:timers/promises`,
+ * and `globalThis` will be mocked.
+ * @since v20.4.0
+ */
+ enable(timers?: Timer[]): void;
+ /**
+ * This function restores the default behavior of all mocks that were previously
+ * created by this `MockTimers` instance and disassociates the mocks
+ * from the `MockTracker` instance.
+ *
+ * **Note:** After each test completes, this function is called on
+ * the test context's `MockTracker`.
+ *
+ * ```js
+ * import { mock } from 'node:test';
+ * mock.timers.reset();
+ * ```
+ *
+ * ```js
+ * const { mock } = require('node:test');
+ * mock.timers.reset();
+ * ```
+ * @since v20.4.0
+ */
+ reset(): void;
+ /**
+ * Advances time for all mocked timers.
+ *
+ * **Note:** This diverges from how `setTimeout` in Node.js behaves and accepts
+ * only positive numbers. In Node.js, `setTimeout` with negative numbers is
+ * only supported for web compatibility reasons.
+ *
+ * The following example mocks a `setTimeout` function and
+ * by using `.tick` advances in
+ * time triggering all pending timers.
+ *
+ * ```js
+ * import assert from 'node:assert';
+ * import { test } from 'node:test';
+ *
+ * test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
+ * const fn = context.mock.fn();
+ *
+ * context.mock.timers.enable(['setTimeout']);
+ *
+ * setTimeout(fn, 9999);
+ *
+ * assert.strictEqual(fn.mock.callCount(), 0);
+ *
+ * // Advance in time
+ * context.mock.timers.tick(9999);
+ *
+ * assert.strictEqual(fn.mock.callCount(), 1);
+ * });
+ * ```
+ *
+ * ```js
+ * const assert = require('node:assert');
+ * const { test } = require('node:test');
+ *
+ * test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
+ * const fn = context.mock.fn();
+ * context.mock.timers.enable(['setTimeout']);
+ *
+ * setTimeout(fn, 9999);
+ * assert.strictEqual(fn.mock.callCount(), 0);
+ *
+ * // Advance in time
+ * context.mock.timers.tick(9999);
+ *
+ * assert.strictEqual(fn.mock.callCount(), 1);
+ * });
+ * ```
+ *
+ * Alternativelly, the `.tick` function can be called many times
+ *
+ * ```js
+ * import assert from 'node:assert';
+ * import { test } from 'node:test';
+ *
+ * test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
+ * const fn = context.mock.fn();
+ * context.mock.timers.enable(['setTimeout']);
+ * const nineSecs = 9000;
+ * setTimeout(fn, nineSecs);
+ *
+ * const twoSeconds = 3000;
+ * context.mock.timers.tick(twoSeconds);
+ * context.mock.timers.tick(twoSeconds);
+ * context.mock.timers.tick(twoSeconds);
+ *
+ * assert.strictEqual(fn.mock.callCount(), 1);
+ * });
+ * ```
+ *
+ * ```js
+ * const assert = require('node:assert');
+ * const { test } = require('node:test');
+ *
+ * test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
+ * const fn = context.mock.fn();
+ * context.mock.timers.enable(['setTimeout']);
+ * const nineSecs = 9000;
+ * setTimeout(fn, nineSecs);
+ *
+ * const twoSeconds = 3000;
+ * context.mock.timers.tick(twoSeconds);
+ * context.mock.timers.tick(twoSeconds);
+ * context.mock.timers.tick(twoSeconds);
+ *
+ * assert.strictEqual(fn.mock.callCount(), 1);
+ * });
+ * ```
+ * @since v20.4.0
+ */
+ tick(milliseconds: number): void;
+ /**
+ * Triggers all pending mocked timers immediately.
+ *
+ * The example below triggers all pending timers immediately,
+ * causing them to execute without any delay.
+ *
+ * ```js
+ * import assert from 'node:assert';
+ * import { test } from 'node:test';
+ *
+ * test('runAll functions following the given order', (context) => {
+ * context.mock.timers.enable(['setTimeout']);
+ * const results = [];
+ * setTimeout(() => results.push(1), 9999);
+ *
+ * // Notice that if both timers have the same timeout,
+ * // the order of execution is guaranteed
+ * setTimeout(() => results.push(3), 8888);
+ * setTimeout(() => results.push(2), 8888);
+ *
+ * assert.deepStrictEqual(results, []);
+ *
+ * context.mock.timers.runAll();
+ *
+ * assert.deepStrictEqual(results, [3, 2, 1]);
+ * });
+ * ```
+ *
+ * ```js
+ * const assert = require('node:assert');
+ * const { test } = require('node:test');
+ *
+ * test('runAll functions following the given order', (context) => {
+ * context.mock.timers.enable(['setTimeout']);
+ * const results = [];
+ * setTimeout(() => results.push(1), 9999);
+ *
+ * // Notice that if both timers have the same timeout,
+ * // the order of execution is guaranteed
+ * setTimeout(() => results.push(3), 8888);
+ * setTimeout(() => results.push(2), 8888);
+ *
+ * assert.deepStrictEqual(results, []);
+ *
+ * context.mock.timers.runAll();
+ *
+ * assert.deepStrictEqual(results, [3, 2, 1]);
+ * });
+ * ```
+ *
+ * **Note:** The `runAll()` function is specifically designed for
+ * triggering timers in the context of timer mocking.
+ * It does not have any effect on real-time system
+ * clocks or actual timers outside of the mocking environment.
+ * @since v20.4.0
+ */
+ runAll(): void;
+ /**
+ * Calls {@link MockTimers.reset()}.
+ */
+ [Symbol.dispose](): void;
+ }
export { test as default, run, test, describe, it, before, after, beforeEach, afterEach, mock, skip, only, todo };
}
@@ -990,9 +1256,14 @@
* The duration of the test in milliseconds.
*/
- duration: number;
+ duration_ms: number;
/**
* The error thrown by the test.
*/
error: Error;
+ /**
+ * The type of the test, used to denote whether this is a suite.
+ * @since 20.0.0, 19.9.0, 18.17.0
+ */
+ type?: 'suite';
};
/**
@@ -1029,5 +1300,10 @@
* The duration of the test in milliseconds.
*/
- duration: number;
+ duration_ms: number;
+ /**
+ * The type of the test, used to denote whether this is a suite.
+ * @since 20.0.0, 19.9.0, 18.17.0
+ */
+ type?: 'suite';
};
/**
@@ -1104,4 +1380,32 @@
message: string;
}
+interface TestEnqueue {
+ /**
+ * The test name
+ */
+ name: string;
+ /**
+ * The path of the test file, undefined if test is not ran through a file.
+ */
+ file?: string;
+ /**
+ * The nesting level of the test.
+ */
+ nesting: number;
+}
+interface TestDequeue {
+ /**
+ * The test name
+ */
+ name: string;
+ /**
+ * The path of the test file, undefined if test is not ran through a file.
+ */
+ file?: string;
+ /**
+ * The nesting level of the test.
+ */
+ nesting: number;
+}
/**
@@ -1132,5 +1436,8 @@
| { type: 'test:start', data: TestStart }
| { type: 'test:stderr', data: TestStderr }
- | { type: 'test:stdout', data: TestStdout };
+ | { type: 'test:stdout', data: TestStdout }
+ | { type: 'test:enqueue', data: TestEnqueue }
+ | { type: 'test:dequeue', data: TestDequeue }
+ | { type: 'test:watch:drained' };
type TestEventGenerator = AsyncGenerator<TestEvent, void>;
@@ -1140,5 +1447,5 @@
* and each failing test is represented by a `X`.
*/
- function dot(source: TestEventGenerator): AsyncGenerator<"\n" | "." | "X", void>;
+ function dot(source: TestEventGenerator): AsyncGenerator<'\n' | '.' | 'X', void>;
/**
* The `tap` reporter outputs the test results in the [TAP](https://testanything.org/) format.
@@ -1151,4 +1458,4 @@
constructor();
}
- export { dot, tap, Spec as spec };
+ export { dot, tap, Spec as spec, TestEvent };
}
diff --git a/timers.d.ts b/timers.d.ts
index v20.3.3..v20.5.7 100777
--- a/timers.d.ts
+++ b/timers.d.ts
@@ -69,4 +69,9 @@
hasRef(): boolean;
_onImmediate: Function; // to distinguish it from the Timeout class
+ /**
+ * Cancels the immediate. This is similar to calling `clearImmediate()`.
+ * @since v20.5.0
+ */
+ [Symbol.dispose](): void;
}
/**
@@ -115,4 +120,9 @@
refresh(): this;
[Symbol.toPrimitive](): number;
+ /**
+ * Cancels the timeout.
+ * @since v20.5.0
+ */
+ [Symbol.dispose](): void;
}
}
@@ -164,8 +174,8 @@
* @return for use with {@link clearInterval}
*/
- function setInterval<TArgs extends any[]>(callback: (...args: TArgs) => void, ms?: number, ...args: TArgs): NodeJS.Timer;
+ function setInterval<TArgs extends any[]>(callback: (...args: TArgs) => void, ms?: number, ...args: TArgs): NodeJS.Timeout;
// util.promisify no rest args compability
// tslint:disable-next-line void-return
- function setInterval(callback: (args: void) => void, ms?: number): NodeJS.Timer;
+ function setInterval(callback: (args: void) => void, ms?: number): NodeJS.Timeout;
namespace setInterval {
const __promisify__: typeof setIntervalPromise;
diff --git a/tls.d.ts b/tls.d.ts
index v20.3.3..v20.5.7 100777
--- a/tls.d.ts
+++ b/tls.d.ts
@@ -730,4 +730,15 @@
interface SecureContextOptions {
/**
+ * If set, this will be called when a client opens a connection using the ALPN extension.
+ * One argument will be passed to the callback: an object containing `servername` and `protocols` fields,
+ * respectively containing the server name from the SNI extension (if any) and an array of
+ * ALPN protocol name strings. The callback must return either one of the strings listed in `protocols`,
+ * which will be returned to the client as the selected ALPN protocol, or `undefined`,
+ * to reject the connection with a fatal alert. If a string is returned that does not match one of
+ * the client's ALPN protocols, an error will be thrown.
+ * This option cannot be used with the `ALPNProtocols` option, and setting both options will throw an error.
+ */
+ ALPNCallback?: ((arg: { servername: string; protocols: string[] }) => string | undefined) | undefined;
+ /**
* Optionally override the trusted CA certificates. Default is to trust
* the well-known CAs curated by Mozilla. Mozilla's CAs are completely
diff --git a/url.d.ts b/url.d.ts
index v20.3.3..v20.5.7 100777
--- a/url.d.ts
+++ b/url.d.ts
@@ -395,4 +395,18 @@
*/
static revokeObjectURL(objectUrl: string): void;
+ /**
+ * Checks if an `input` relative to the `base` can be parsed to a `URL`.
+ *
+ * ```js
+ * const isValid = URL.canParse('/foo', 'https://example.org/'); // true
+ *
+ * const isNotValid = URL.canParse('/foo'); // false
+ * ```
+ * @since v19.9.0
+ * @param input The absolute or relative input URL to parse. If `input` is relative, then `base` is required. If `input` is absolute, the `base` is ignored. If `input` is not a string, it is
+ * `converted to a string` first.
+ * @param base The base URL to resolve against if the `input` is not absolute. If `base` is not a string, it is `converted to a string` first.
+ */
+ static canParse(input: string, base?: string): boolean;
constructor(input: string, base?: string | URL);
/**
diff --git a/util.d.ts b/util.d.ts
index v20.3.3..v20.5.7 100777
--- a/util.d.ts
+++ b/util.d.ts
@@ -1461,30 +1461,70 @@
/**
* Gets and sets the type portion of the MIME.
+ *
+ * ```js
+ * import { MIMEType } from 'node:util';
+ *
+ * const myMIME = new MIMEType('text/javascript');
+ * console.log(myMIME.type);
+ * // Prints: text
+ * myMIME.type = 'application';
+ * console.log(myMIME.type);
+ * // Prints: application
+ * console.log(String(myMIME));
+ * // Prints: application/javascript
+ * ```
*/
type: string;
/**
* Gets and sets the subtype portion of the MIME.
+ *
+ * ```js
+ * import { MIMEType } from 'node:util';
+ *
+ * const myMIME = new MIMEType('text/ecmascript');
+ * console.log(myMIME.subtype);
+ * // Prints: ecmascript
+ * myMIME.subtype = 'javascript';
+ * console.log(myMIME.subtype);
+ * // Prints: javascript
+ * console.log(String(myMIME));
+ * // Prints: text/javascript
+ * ```
*/
subtype: string;
/**
- * Gets the essence of the MIME.
+ * Gets the essence of the MIME. This property is read only.
+ * Use `mime.type` or `mime.subtype` to alter the MIME.
*
- * Use `mime.type` or `mime.subtype` to alter the MIME.
+ * ```js
+ * import { MIMEType } from 'node:util';
+ *
+ * const myMIME = new MIMEType('text/javascript;key=value');
+ * console.log(myMIME.essence);
+ * // Prints: text/javascript
+ * myMIME.type = 'application';
+ * console.log(myMIME.essence);
+ * // Prints: application/javascript
+ * console.log(String(myMIME));
+ * // Prints: application/javascript;key=value
+ * ```
*/
readonly essence: string;
/**
- * Gets the `MIMEParams` object representing the parameters of the MIME.
+ * Gets the `MIMEParams` object representing the
+ * parameters of the MIME. This property is read-only. See `MIMEParams` documentation for details.
*/
readonly params: MIMEParams;
/**
- * Returns the serialized MIME.
+ * The `toString()` method on the `MIMEType` object returns the serialized MIME.
*
- * Because of the need for standard compliance, this method
- * does not allow users to customize the serialization process of the MIME.
+ * Because of the need for standard compliance, this method does not allow users
+ * to customize the serialization process of the MIME.
*/
toString(): string;
}
/**
- * @since v18.13.0
+ * The `MIMEParams` API provides read and write access to the parameters of a`MIMEType`.
+ * @since v19.1.0, v18.13.0
*/
export class MIMEParams {
@@ -1495,9 +1535,12 @@
/**
* Returns an iterator over each of the name-value pairs in the parameters.
+ * Each item of the iterator is a JavaScript `Array`. The first item of the array
+ * is the `name`, the second item of the array is the `value`.
*/
entries(): IterableIterator<[name: string, value: string]>;
/**
- * Returns the value of the first name-value pair whose name is `name`.
- * If there are no such pairs, `null` is returned.
+ * Returns the value of the first name-value pair whose name is `name`. If there
+ * are no such pairs, `null` is returned.
+ * @return or `null` if there is no name-value pair with the given `name`.
*/
get(name: string): string | null;
@@ -1508,10 +1551,31 @@
/**
* Returns an iterator over the names of each name-value pair.
+ *
+ * ```js
+ * import { MIMEType } from 'node:util';
+ *
+ * const { params } = new MIMEType('text/plain;foo=0;bar=1');
+ * for (const name of params.keys()) {
+ * console.log(name);
+ * }
+ * // Prints:
+ * // foo
+ * // bar
+ * ```
*/
keys(): IterableIterator<string>;
/**
- * Sets the value in the `MIMEParams` object associated with `name` to `value`.
- * If there are any pre-existing name-value pairs whose names are `name`,
+ * Sets the value in the `MIMEParams` object associated with `name` to`value`. If there are any pre-existing name-value pairs whose names are `name`,
* set the first such pair's value to `value`.
+ *
+ * ```js
+ * import { MIMEType } from 'node:util';
+ *
+ * const { params } = new MIMEType('text/plain;foo=0;bar=1');
+ * params.set('foo', 'def');
+ * params.set('baz', 'xyz');
+ * console.log(params.toString());
+ * // Prints: foo=def&bar=1&baz=xyz
+ * ```
*/
set(name: string, value: string): void;
diff --git a/vm.d.ts b/vm.d.ts
index v20.3.3..v20.5.7 100777
--- a/vm.d.ts
+++ b/vm.d.ts
@@ -38,4 +38,5 @@
*/
declare module 'vm' {
+ import { ImportAssertions } from 'node:module';
interface Context extends NodeJS.Dict<any> {}
interface BaseOptions {
@@ -67,5 +68,5 @@
* If this option is not specified, calls to `import()` will reject with `ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`.
*/
- importModuleDynamically?: ((specifier: string, script: Script, importAssertions: Object) => Module) | undefined;
+ importModuleDynamically?: ((specifier: string, script: Script, importAssertions: ImportAssertions) => Module) | undefined;
}
interface RunningScriptOptions extends BaseOptions {
diff --git a/fs/promises.d.ts b/fs/promises.d.ts
index v20.3.3..v20.5.7 100777
--- a/fs/promises.d.ts
+++ b/fs/promises.d.ts
@@ -83,4 +83,11 @@
start?: number | undefined;
}
+ interface ReadableWebStreamOptions {
+ /**
+ * Whether to open a normal or a `'bytes'` stream.
+ * @since v20.0.0
+ */
+ type?: 'bytes' | undefined;
+ }
// TODO: Add `EventEmitter` close
interface FileHandle {
@@ -241,5 +248,5 @@
* @experimental
*/
- readableWebStream(): ReadableStream;
+ readableWebStream(options?: ReadableWebStreamOptions): ReadableStream;
/**
* Asynchronously reads the entire contents of a file.
@@ -450,4 +457,9 @@
*/
close(): Promise<void>;
+ /**
+ * An alias for {@link FileHandle.close()}.
+ * @since v20.4.0
+ */
+ [Symbol.asyncDispose](): Promise<void>;
}
const constants: typeof fsConstants;
diff --git a/ts4.8/child_process.d.ts b/ts4.8/child_process.d.ts
index v20.3.3..v20.5.7 100777
--- a/ts4.8/child_process.d.ts
+++ b/ts4.8/child_process.d.ts
@@ -304,4 +304,9 @@
kill(signal?: NodeJS.Signals | number): boolean;
/**
+ * Calls {@link ChildProcess.kill} with `'SIGTERM'`.
+ * @since v20.5.0
+ */
+ [Symbol.dispose](): void;
+ /**
* When an IPC channel has been established between the parent and child (
* i.e. when using {@link fork}), the `subprocess.send()` method can
diff --git a/ts4.8/crypto.d.ts b/ts4.8/crypto.d.ts
index v20.3.3..v20.5.7 100777
--- a/ts4.8/crypto.d.ts
+++ b/ts4.8/crypto.d.ts
@@ -1517,8 +1517,13 @@
private constructor();
/**
- * Generates private and public Diffie-Hellman key values, and returns
+ * Generates private and public Diffie-Hellman key values unless they have been
+ * generated or computed already, and returns
* the public key in the specified `encoding`. This key should be
* transferred to the other party.
* If `encoding` is provided a string is returned; otherwise a `Buffer` is returned.
+ *
+ * This function is a thin wrapper around [`DH_generate_key()`](https://www.openssl.org/docs/man3.0/man3/DH_generate_key.html). In particular,
+ * once a private key has been generated or set, calling this function only updates
+ * the public key but does not generate a new private key.
* @since v0.5.0
* @param encoding The `encoding` of the return value.
@@ -1592,4 +1597,7 @@
* to be a string. If no `encoding` is provided, `privateKey` is expected
* to be a `Buffer`, `TypedArray`, or `DataView`.
+ *
+ * This function does not automatically compute the associated public key. Either `diffieHellman.setPublicKey()` or `diffieHellman.generateKeys()` can be
+ * used to manually provide the public key or to automatically derive it.
* @since v0.5.0
* @param encoding The `encoding` of the `privateKey` string.
diff --git a/ts4.8/dgram.d.ts b/ts4.8/dgram.d.ts
index v20.3.3..v20.5.7 100777
--- a/ts4.8/dgram.d.ts
+++ b/ts4.8/dgram.d.ts
@@ -539,4 +539,9 @@
prependOnceListener(event: 'listening', listener: () => void): this;
prependOnceListener(event: 'message', listener: (msg: Buffer, rinfo: RemoteInfo) => void): this;
+ /**
+ * Calls `socket.close()` and returns a promise that fulfills when the socket has closed.
+ * @since v20.5.0
+ */
+ [Symbol.asyncDispose](): Promise<void>;
}
}
diff --git a/ts4.8/events.d.ts b/ts4.8/events.d.ts
index v20.3.3..v20.5.7 100777
--- a/ts4.8/events.d.ts
+++ b/ts4.8/events.d.ts
@@ -296,5 +296,34 @@
static getEventListeners(emitter: _DOMEventTarget | NodeJS.EventEmitter, name: string | symbol): Function[];
/**
+ * Returns the currently set max amount of listeners.
+ *
+ * For `EventEmitter`s this behaves exactly the same as calling `.getMaxListeners` on
+ * the emitter.
+ *
+ * For `EventTarget`s this is the only way to get the max event listeners for the
+ * event target. If the number of event handlers on a single EventTarget exceeds
+ * the max set, the EventTarget will print a warning.
+ *
* ```js
+ * import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events';
+ *
+ * {
+ * const ee = new EventEmitter();
+ * console.log(getMaxListeners(ee)); // 10
+ * setMaxListeners(11, ee);
+ * console.log(getMaxListeners(ee)); // 11
+ * }
+ * {
+ * const et = new EventTarget();
+ * console.log(getMaxListeners(et)); // 10
+ * setMaxListeners(11, et);
+ * console.log(getMaxListeners(et)); // 11
+ * }
+ * ```
+ * @since v19.9.0
+ */
+ static getMaxListeners(emitter: _DOMEventTarget | NodeJS.EventEmitter): number;
+ /**
+ * ```js
* import { setMaxListeners, EventEmitter } from 'node:events';
*
@@ -311,4 +340,39 @@
static setMaxListeners(n?: number, ...eventTargets: Array<_DOMEventTarget | NodeJS.EventEmitter>): void;
/**
+ * Listens once to the `abort` event on the provided `signal`.
+ *
+ * Listening to the `abort` event on abort signals is unsafe and may
+ * lead to resource leaks since another third party with the signal can
+ * call `e.stopImmediatePropagation()`. Unfortunately Node.js cannot change
+ * this since it would violate the web standard. Additionally, the original
+ * API makes it easy to forget to remove listeners.
+ *
+ * This API allows safely using `AbortSignal`s in Node.js APIs by solving these
+ * two issues by listening to the event such that `stopImmediatePropagation` does
+ * not prevent the listener from running.
+ *
+ * Returns a disposable so that it may be unsubscribed from more easily.
+ *
+ * ```js
+ * import { addAbortListener } from 'node:events';
+ *
+ * function example(signal) {
+ * let disposable;
+ * try {
+ * signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
+ * disposable = addAbortListener(signal, (e) => {
+ * // Do something when signal is aborted.
+ * });
+ * } finally {
+ * disposable?.[Symbol.dispose]();
+ * }
+ * }
+ * ```
+ * @since v20.5.0
+ * @experimental
+ * @return that removes the `abort` listener.
+ */
+ static addAbortListener(signal: AbortSignal, resource: (event: Event) => void): Disposable;
+ /**
* 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.
*
diff --git a/ts4.8/fs.d.ts b/ts4.8/fs.d.ts
index v20.3.3..v20.5.7 100777
--- a/ts4.8/fs.d.ts
+++ b/ts4.8/fs.d.ts
@@ -3619,14 +3619,27 @@
mode?: number | undefined;
autoClose?: boolean | undefined;
- /**
- * @default false
- */
emitClose?: boolean | undefined;
start?: number | undefined;
- highWaterMark?: number | undefined;
+ signal?: AbortSignal | null | undefined;
}
+ interface FSImplementation {
+ open?: (...args: any[]) => any;
+ close?: (...args: any[]) => any;
+ }
+ interface CreateReadStreamFSImplementation extends FSImplementation {
+ read: (...args: any[]) => any;
+ }
+ interface CreateWriteStreamFSImplementation extends FSImplementation {
+ write: (...args: any[]) => any;
+ writev?: (...args: any[]) => any;
+ }
interface ReadStreamOptions extends StreamOptions {
+ fs?: CreateReadStreamFSImplementation | null | undefined;
end?: number | undefined;
+ highWaterMark?: number | undefined;
}
+ interface WriteStreamOptions extends StreamOptions {
+ fs?: CreateWriteStreamFSImplementation | null | undefined;
+ }
/**
* Unlike the 16 KiB default `highWaterMark` for a `stream.Readable`, the stream
@@ -3721,5 +3734,5 @@
* @since v0.1.31
*/
- export function createWriteStream(path: PathLike, options?: BufferEncoding | StreamOptions): WriteStream;
+ export function createWriteStream(path: PathLike, options?: BufferEncoding | WriteStreamOptions): WriteStream;
/**
* Forces all currently queued I/O operations associated with the file to the
@@ -3901,4 +3914,29 @@
*/
export function readvSync(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): number;
+
+ export interface OpenAsBlobOptions {
+ /**
+ * An optional mime type for the blob.
+ *
+ * @default 'undefined'
+ */
+ type?: string | undefined;
+ }
+
+ /**
+ * Returns a Blob whose data is backed by the given file.
+ *
+ * The file must not be modified after the `Blob` is created.
+ * Any modifications will cause reading the `Blob` data to fail with a `DOMException` error.
+ * Synchronous stat operations on the file when the `Blob` is created, and before each read in order to detect whether the file data has been modified on disk.
+ *
+ * @param path
+ * @param [options]
+ *
+ * @experimental
+ * @since v19.8.0
+ */
+ export function openAsBlob(path: PathLike, options?: OpenAsBlobOptions): Promise<Blob>;
+
export interface OpenDirOptions {
/**
diff --git a/ts4.8/globals.d.ts b/ts4.8/globals.d.ts
index v20.3.3..v20.5.7 100777
--- a/ts4.8/globals.d.ts
+++ b/ts4.8/globals.d.ts
@@ -85,4 +85,26 @@
//#endregion borrowed
+//#region Disposable
+interface SymbolConstructor {
+ /**
+ * A method that is used to release resources held by an object. Called by the semantics of the `using` statement.
+ */
+ readonly dispose: unique symbol;
+
+ /**
+ * A method that is used to asynchronously release resources held by an object. Called by the semantics of the `await using` statement.
+ */
+ readonly asyncDispose: unique symbol;
+}
+
+interface Disposable {
+ [Symbol.dispose](): void;
+}
+
+interface AsyncDisposable {
+ [Symbol.asyncDispose](): PromiseLike<void>;
+}
+//#endregion Disposable
+
//#region ArrayLike.at()
interface RelativeIndexable<T> {
diff --git a/ts4.8/http2.d.ts b/ts4.8/http2.d.ts
index v20.3.3..v20.5.7 100777
--- a/ts4.8/http2.d.ts
+++ b/ts4.8/http2.d.ts
@@ -129,5 +129,5 @@
* @since v8.4.0
*/
- readonly session: Http2Session;
+ readonly session: Http2Session | undefined;
/**
* Provides miscellaneous information about the current state of the`Http2Stream`.
diff --git a/ts4.8/inspector.d.ts b/ts4.8/inspector.d.ts
index v20.3.3..v20.5.7 100777
--- a/ts4.8/inspector.d.ts
+++ b/ts4.8/inspector.d.ts
@@ -1,3 +1,3 @@
-// eslint-disable-next-line dt-header
+// eslint-disable-next-line @definitelytyped/dt-header
// Type definitions for inspector
diff --git a/ts4.8/module.d.ts b/ts4.8/module.d.ts
index v20.3.3..v20.5.7 100777
--- a/ts4.8/module.d.ts
+++ b/ts4.8/module.d.ts
@@ -4,4 +4,5 @@
declare module 'module' {
import { URL } from 'node:url';
+ import { MessagePort } from 'node:worker_threads';
namespace Module {
/**
@@ -74,10 +75,125 @@
constructor(payload: SourceMapPayload);
/**
- * Given a line number and column number in the generated source file, returns
- * an object representing the position in the original file. The object returned
- * consists of the following keys:
+ * Given a line offset and column offset in the generated source
+ * file, returns an object representing the SourceMap range in the
+ * original file if found, or an empty object if not.
+ *
+ * The object returned contains the following keys:
+ *
+ * The returned value represents the raw range as it appears in the
+ * SourceMap, based on zero-indexed offsets, _not_ 1-indexed line and
+ * column numbers as they appear in Error messages and CallSite
+ * objects.
+ *
+ * To get the corresponding 1-indexed line and column numbers from a
+ * lineNumber and columnNumber as they are reported by Error stacks
+ * and CallSite objects, use `sourceMap.findOrigin(lineNumber, columnNumber)`
+ * @param lineOffset The zero-indexed line number offset in the generated source
+ * @param columnOffset The zero-indexed column number offset in the generated source
*/
- findEntry(line: number, column: number): SourceMapping;
+ findEntry(lineOffset: number, columnOffset: number): SourceMapping;
}
+ interface ImportAssertions extends NodeJS.Dict<string> {
+ type?: string | undefined;
+ }
+ type ModuleFormat = 'builtin' | 'commonjs' | 'json' | 'module' | 'wasm';
+ type ModuleSource = string | ArrayBuffer | NodeJS.TypedArray;
+ interface GlobalPreloadContext {
+ port: MessagePort;
+ }
+ /**
+ * Sometimes it might be necessary to run some code inside of the same global scope that the application runs in.
+ * This hook allows the return of a string that is run as a sloppy-mode script on startup.
+ *
+ * @param context Information to assist the preload code
+ * @return Code to run before application startup
+ */
+ type GlobalPreloadHook = (context: GlobalPreloadContext) => string;
+ interface ResolveHookContext {
+ /**
+ * Export conditions of the relevant `package.json`
+ */
+ conditions: string[];
+ /**
+ * An object whose key-value pairs represent the assertions for the module to import
+ */
+ importAssertions: ImportAssertions;
+ /**
+ * The module importing this one, or undefined if this is the Node.js entry point
+ */
+ parentURL: string | undefined;
+ }
+ interface ResolveFnOutput {
+ /**
+ * A hint to the load hook (it might be ignored)
+ */
+ format?: ModuleFormat | null | undefined;
+ /**
+ * The import assertions to use when caching the module (optional; if excluded the input will be used)
+ */
+ importAssertions?: ImportAssertions | undefined;
+ /**
+ * A signal that this hook intends to terminate the chain of `resolve` hooks.
+ * @default false
+ */
+ shortCircuit?: boolean | undefined;
+ /**
+ * The absolute URL to which this input resolves
+ */
+ url: string;
+ }
+ /**
+ * The `resolve` hook chain is responsible for resolving file URL for a given module specifier and parent URL, and optionally its format (such as `'module'`) as a hint to the `load` hook.
+ * If a format is specified, the load hook is ultimately responsible for providing the final `format` value (and it is free to ignore the hint provided by `resolve`);
+ * if `resolve` provides a format, a custom `load` hook is required even if only to pass the value to the Node.js default `load` hook.
+ *
+ * @param specifier The specified URL path of the module to be resolved
+ * @param context
+ * @param nextResolve The subsequent `resolve` hook in the chain, or the Node.js default `resolve` hook after the last user-supplied resolve hook
+ */
+ type ResolveHook = (
+ specifier: string,
+ context: ResolveHookContext,
+ nextResolve: (specifier: string, context?: ResolveHookContext) => ResolveFnOutput | Promise<ResolveFnOutput>
+ ) => ResolveFnOutput | Promise<ResolveFnOutput>;
+ interface LoadHookContext {
+ /**
+ * Export conditions of the relevant `package.json`
+ */
+ conditions: string[];
+ /**
+ * The format optionally supplied by the `resolve` hook chain
+ */
+ format: ModuleFormat;
+ /**
+ * An object whose key-value pairs represent the assertions for the module to import
+ */
+ importAssertions: ImportAssertions;
+ }
+ interface LoadFnOutput {
+ format: ModuleFormat;
+ /**
+ * A signal that this hook intends to terminate the chain of `resolve` hooks.
+ * @default false
+ */
+ shortCircuit?: boolean | undefined;
+ /**
+ * The source for Node.js to evaluate
+ */
+ source?: ModuleSource;
+ }
+ /**
+ * The `load` hook provides a way to define a custom method of determining how a URL should be interpreted, retrieved, and parsed.
+ * It is also in charge of validating the import assertion.
+ *
+ * @param url The URL/path of the module to be loaded
+ * @param context Metadata about the module
+ * @param nextLoad The subsequent `load` hook in the chain, or the Node.js default `load` hook after the last user-supplied `load` hook
+ */
+ type LoadHook = (
+ url: string,
+ context: LoadHookContext,
+ nextLoad: (url: string, context?: LoadHookContext) => LoadFnOutput | Promise<LoadFnOutput>
+ ) => LoadFnOutput | Promise<LoadFnOutput>;
}
interface Module extends NodeModule {}
diff --git a/ts4.8/net.d.ts b/ts4.8/net.d.ts
index v20.3.3..v20.5.7 100777
--- a/ts4.8/net.d.ts
+++ b/ts4.8/net.d.ts
@@ -17,5 +17,5 @@
import { Abortable, EventEmitter } from 'node:events';
import * as dns from 'node:dns';
- type LookupFunction = (hostname: string, options: dns.LookupOneOptions, callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void) => void;
+ type LookupFunction = (hostname: string, options: dns.LookupAllOptions, callback: (err: NodeJS.ErrnoException | null, addresses: dns.LookupAddress[]) => void) => void;
interface AddressInfo {
address: string;
@@ -640,4 +640,9 @@
prependOnceListener(event: 'listening', listener: () => void): this;
prependOnceListener(event: 'drop', listener: (data?: DropArgument) => void): this;
+ /**
+ * Calls {@link Server.close()} and returns a promise that fulfills when the server has closed.
+ * @since v20.5.0
+ */
+ [Symbol.asyncDispose](): Promise<void>;
}
type IPVersion = 'ipv4' | 'ipv6';
diff --git a/ts4.8/stream.d.ts b/ts4.8/stream.d.ts
index v20.3.3..v20.5.7 100777
--- a/ts4.8/stream.d.ts
+++ b/ts4.8/stream.d.ts
@@ -23,4 +23,7 @@
import * as streamConsumers from 'node:stream/consumers';
import * as streamWeb from 'node:stream/web';
+
+ type ComposeFnParam = (source: any) => void;
+
class internal extends EventEmitter {
pipe<T extends NodeJS.WritableStream>(
@@ -30,5 +33,744 @@
}
): T;
+ compose<T extends NodeJS.ReadableStream>(stream: T | ComposeFnParam | Iterable<T> | AsyncIterable<T>, options?: { signal: AbortSignal }): T;
}
+ import Stream = internal.Stream;
+ import Readable = internal.Readable;
+ import ReadableOptions = internal.ReadableOptions;
+ class ReadableBase extends Stream implements NodeJS.ReadableStream {
+ /**
+ * A utility method for creating Readable Streams out of iterators.
+ */
+ static from(iterable: Iterable<any> | AsyncIterable<any>, options?: ReadableOptions): Readable;
+ /**
+ * Returns whether the stream has been read from or cancelled.
+ * @since v16.8.0
+ */
+ static isDisturbed(stream: Readable | NodeJS.ReadableStream): boolean;
+ /**
+ * Returns whether the stream was destroyed or errored before emitting `'end'`.
+ * @since v16.8.0
+ * @experimental
+ */
+ readonly readableAborted: boolean;
+ /**
+ * Is `true` if it is safe to call `readable.read()`, which means
+ * the stream has not been destroyed or emitted `'error'` or `'end'`.
+ * @since v11.4.0
+ */
+ readable: boolean;
+ /**
+ * Returns whether `'data'` has been emitted.
+ * @since v16.7.0, v14.18.0
+ * @experimental
+ */
+ readonly readableDidRead: boolean;
+ /**
+ * Getter for the property `encoding` of a given `Readable` stream. The `encoding`property can be set using the `readable.setEncoding()` method.
+ * @since v12.7.0
+ */
+ readonly readableEncoding: BufferEncoding | null;
+ /**
+ * Becomes `true` when `'end'` event is emitted.
+ * @since v12.9.0
+ */
+ readonly readableEnded: boolean;
+ /**
+ * This property reflects the current state of a `Readable` stream as described
+ * in the `Three states` section.
+ * @since v9.4.0
+ */
+ readonly readableFlowing: boolean | null;
+ /**
+ * Returns the value of `highWaterMark` passed when creating this `Readable`.
+ * @since v9.3.0
+ */
+ readonly readableHighWaterMark: number;
+ /**
+ * This property contains the number of bytes (or objects) in the queue
+ * ready to be read. The value provides introspection data regarding
+ * the status of the `highWaterMark`.
+ * @since v9.4.0
+ */
+ readonly readableLength: number;
+ /**
+ * Getter for the property `objectMode` of a given `Readable` stream.
+ * @since v12.3.0
+ */
+ readonly readableObjectMode: boolean;
+ /**
+ * Is `true` after `readable.destroy()` has been called.
+ * @since v8.0.0
+ */
+ destroyed: boolean;
+ /**
+ * Is `true` after `'close'` has been emitted.
+ * @since v18.0.0
+ */
+ readonly closed: boolean;
+ /**
+ * Returns error if the stream has been destroyed with an error.
+ * @since v18.0.0
+ */
+ readonly errored: Error | null;
+ constructor(opts?: ReadableOptions);
+ _construct?(callback: (error?: Error | null) => void): void;
+ _read(size: number): void;
+ /**
+ * The `readable.read()` method reads data out of the internal buffer and
+ * returns it. If no data is available to be read, `null` is returned. By default,
+ * the data is returned as a `Buffer` object unless an encoding has been
+ * specified using the `readable.setEncoding()` method or the stream is operating
+ * in object mode.
+ *
+ * The optional `size` argument specifies a specific number of bytes to read. If`size` bytes are not available to be read, `null` will be returned _unless_the stream has ended, in which
+ * case all of the data remaining in the internal
+ * buffer will be returned.
+ *
+ * If the `size` argument is not specified, all of the data contained in the
+ * internal buffer will be returned.
+ *
+ * The `size` argument must be less than or equal to 1 GiB.
+ *
+ * The `readable.read()` method should only be called on `Readable` streams
+ * operating in paused mode. In flowing mode, `readable.read()` is called
+ * automatically until the internal buffer is fully drained.
+ *
+ * ```js
+ * const readable = getReadableStreamSomehow();
+ *
+ * // 'readable' may be triggered multiple times as data is buffered in
+ * readable.on('readable', () => {
+ * let chunk;
+ * console.log('Stream is readable (new data received in buffer)');
+ * // Use a loop to make sure we read all currently available data
+ * while (null !== (chunk = readable.read())) {
+ * console.log(`Read ${chunk.length} bytes of data...`);
+ * }
+ * });
+ *
+ * // 'end' will be triggered once when there is no more data available
+ * readable.on('end', () => {
+ * console.log('Reached end of stream.');
+ * });
+ * ```
+ *
+ * Each call to `readable.read()` returns a chunk of data, or `null`. The chunks
+ * are not concatenated. A `while` loop is necessary to consume all data
+ * currently in the buffer. When reading a large file `.read()` may return `null`,
+ * having consumed all buffered content so far, but there is still more data to
+ * come not yet buffered. In this case a new `'readable'` event will be emitted
+ * when there is more data in the buffer. Finally the `'end'` event will be
+ * emitted when there is no more data to come.
+ *
+ * Therefore to read a file's whole contents from a `readable`, it is necessary
+ * to collect chunks across multiple `'readable'` events:
+ *
+ * ```js
+ * const chunks = [];
+ *
+ * readable.on('readable', () => {
+ * let chunk;
+ * while (null !== (chunk = readable.read())) {
+ * chunks.push(chunk);
+ * }
+ * });
+ *
+ * readable.on('end', () => {
+ * const content = chunks.join('');
+ * });
+ * ```
+ *
+ * A `Readable` stream in object mode will always return a single item from
+ * a call to `readable.read(size)`, regardless of the value of the`size` argument.
+ *
+ * If the `readable.read()` method returns a chunk of data, a `'data'` event will
+ * also be emitted.
+ *
+ * Calling {@link read} after the `'end'` event has
+ * been emitted will return `null`. No runtime error will be raised.
+ * @since v0.9.4
+ * @param size Optional argument to specify how much data to read.
+ */
+ read(size?: number): any;
+ /**
+ * The `readable.setEncoding()` method sets the character encoding for
+ * data read from the `Readable` stream.
+ *
+ * By default, no encoding is assigned and stream data will be returned as`Buffer` objects. Setting an encoding causes the stream data
+ * to be returned as strings of the specified encoding rather than as `Buffer`objects. For instance, calling `readable.setEncoding('utf8')` will cause the
+ * output data to be interpreted as UTF-8 data, and passed as strings. Calling`readable.setEncoding('hex')` will cause the data to be encoded in hexadecimal
+ * string format.
+ *
+ * The `Readable` stream will properly handle multi-byte characters delivered
+ * through the stream that would otherwise become improperly decoded if simply
+ * pulled from the stream as `Buffer` objects.
+ *
+ * ```js
+ * const readable = getReadableStreamSomehow();
+ * readable.setEncoding('utf8');
+ * readable.on('data', (chunk) => {
+ * assert.equal(typeof chunk, 'string');
+ * console.log('Got %d characters of string data:', chunk.length);
+ * });
+ * ```
+ * @since v0.9.4
+ * @param encoding The encoding to use.
+ */
+ setEncoding(encoding: BufferEncoding): this;
+ /**
+ * The `readable.pause()` method will cause a stream in flowing mode to stop
+ * emitting `'data'` events, switching out of flowing mode. Any data that
+ * becomes available will remain in the internal buffer.
+ *
+ * ```js
+ * const readable = getReadableStreamSomehow();
+ * readable.on('data', (chunk) => {
+ * console.log(`Received ${chunk.length} bytes of data.`);
+ * readable.pause();
+ * console.log('There will be no additional data for 1 second.');
+ * setTimeout(() => {
+ * console.log('Now data will start flowing again.');
+ * readable.resume();
+ * }, 1000);
+ * });
+ * ```
+ *
+ * The `readable.pause()` method has no effect if there is a `'readable'`event listener.
+ * @since v0.9.4
+ */
+ pause(): this;
+ /**
+ * The `readable.resume()` method causes an explicitly paused `Readable` stream to
+ * resume emitting `'data'` events, switching the stream into flowing mode.
+ *
+ * The `readable.resume()` method can be used to fully consume the data from a
+ * stream without actually processing any of that data:
+ *
+ * ```js
+ * getReadableStreamSomehow()
+ * .resume()
+ * .on('end', () => {
+ * console.log('Reached the end, but did not read anything.');
+ * });
+ * ```
+ *
+ * The `readable.resume()` method has no effect if there is a `'readable'`event listener.
+ * @since v0.9.4
+ */
+ resume(): this;
+ /**
+ * The `readable.isPaused()` method returns the current operating state of the`Readable`. This is used primarily by the mechanism that underlies the`readable.pipe()` method. In most
+ * typical cases, there will be no reason to
+ * use this method directly.
+ *
+ * ```js
+ * const readable = new stream.Readable();
+ *
+ * readable.isPaused(); // === false
+ * readable.pause();
+ * readable.isPaused(); // === true
+ * readable.resume();
+ * readable.isPaused(); // === false
+ * ```
+ * @since v0.11.14
+ */
+ isPaused(): boolean;
+ /**
+ * The `readable.unpipe()` method detaches a `Writable` stream previously attached
+ * using the {@link pipe} method.
+ *
+ * If the `destination` is not specified, then _all_ pipes are detached.
+ *
+ * If the `destination` is specified, but no pipe is set up for it, then
+ * the method does nothing.
+ *
+ * ```js
+ * const fs = require('node:fs');
+ * const readable = getReadableStreamSomehow();
+ * const writable = fs.createWriteStream('file.txt');
+ * // All the data from readable goes into 'file.txt',
+ * // but only for the first second.
+ * readable.pipe(writable);
+ * setTimeout(() => {
+ * console.log('Stop writing to file.txt.');
+ * readable.unpipe(writable);
+ * console.log('Manually close the file stream.');
+ * writable.end();
+ * }, 1000);
+ * ```
+ * @since v0.9.4
+ * @param destination Optional specific stream to unpipe
+ */
+ unpipe(destination?: NodeJS.WritableStream): this;
+ /**
+ * Passing `chunk` as `null` signals the end of the stream (EOF) and behaves the
+ * same as `readable.push(null)`, after which no more data can be written. The EOF
+ * signal is put at the end of the buffer and any buffered data will still be
+ * flushed.
+ *
+ * The `readable.unshift()` method pushes a chunk of data back into the internal
+ * buffer. This is useful in certain situations where a stream is being consumed by
+ * code that needs to "un-consume" some amount of data that it has optimistically
+ * pulled out of the source, so that the data can be passed on to some other party.
+ *
+ * The `stream.unshift(chunk)` method cannot be called after the `'end'` event
+ * has been emitted or a runtime error will be thrown.
+ *
+ * Developers using `stream.unshift()` often should consider switching to
+ * use of a `Transform` stream instead. See the `API for stream implementers` section for more information.
+ *
+ * ```js
+ * // Pull off a header delimited by \n\n.
+ * // Use unshift() if we get too much.
+ * // Call the callback with (error, header, stream).
+ * const { StringDecoder } = require('node:string_decoder');
+ * function parseHeader(stream, callback) {
+ * stream.on('error', callback);
+ * stream.on('readable', onReadable);
+ * const decoder = new StringDecoder('utf8');
+ * let header = '';
+ * function onReadable() {
+ * let chunk;
+ * while (null !== (chunk = stream.read())) {
+ * const str = decoder.write(chunk);
+ * if (str.includes('\n\n')) {
+ * // Found the header boundary.
+ * const split = str.split(/\n\n/);
+ * header += split.shift();
+ * const remaining = split.join('\n\n');
+ * const buf = Buffer.from(remaining, 'utf8');
+ * stream.removeListener('error', callback);
+ * // Remove the 'readable' listener before unshifting.
+ * stream.removeListener('readable', onReadable);
+ * if (buf.length)
+ * stream.unshift(buf);
+ * // Now the body of the message can be read from the stream.
+ * callback(null, header, stream);
+ * return;
+ * }
+ * // Still reading the header.
+ * header += str;
+ * }
+ * }
+ * }
+ * ```
+ *
+ * Unlike {@link push}, `stream.unshift(chunk)` will not
+ * end the reading process by resetting the internal reading state of the stream.
+ * This can cause unexpected results if `readable.unshift()` is called during a
+ * read (i.e. from within a {@link _read} implementation on a
+ * custom stream). Following the call to `readable.unshift()` with an immediate {@link push} will reset the reading state appropriately,
+ * however it is best to simply avoid calling `readable.unshift()` while in the
+ * process of performing a read.
+ * @since v0.9.11
+ * @param chunk Chunk of data to unshift onto the read queue. For streams not operating in object mode, `chunk` must be a string, `Buffer`, `Uint8Array`, or `null`. For object mode
+ * streams, `chunk` may be any JavaScript value.
+ * @param encoding Encoding of string chunks. Must be a valid `Buffer` encoding, such as `'utf8'` or `'ascii'`.
+ */
+ unshift(chunk: any, encoding?: BufferEncoding): void;
+ /**
+ * Prior to Node.js 0.10, streams did not implement the entire `node:stream`module API as it is currently defined. (See `Compatibility` for more
+ * information.)
+ *
+ * When using an older Node.js library that emits `'data'` events and has a {@link pause} method that is advisory only, the`readable.wrap()` method can be used to create a `Readable`
+ * stream that uses
+ * the old stream as its data source.
+ *
+ * It will rarely be necessary to use `readable.wrap()` but the method has been
+ * provided as a convenience for interacting with older Node.js applications and
+ * libraries.
+ *
+ * ```js
+ * const { OldReader } = require('./old-api-module.js');
+ * const { Readable } = require('node:stream');
+ * const oreader = new OldReader();
+ * const myReader = new Readable().wrap(oreader);
+ *
+ * myReader.on('readable', () => {
+ * myReader.read(); // etc.
+ * });
+ * ```
+ * @since v0.9.4
+ * @param stream An "old style" readable stream
+ */
+ wrap(stream: NodeJS.ReadableStream): this;
+ push(chunk: any, encoding?: BufferEncoding): boolean;
+ _destroy(error: Error | null, callback: (error?: Error | null) => void): void;
+ /**
+ * Destroy the stream. Optionally emit an `'error'` event, and emit a `'close'`event (unless `emitClose` is set to `false`). After this call, the readable
+ * stream will release any internal resources and subsequent calls to `push()`will be ignored.
+ *
+ * Once `destroy()` has been called any further calls will be a no-op and no
+ * further errors except from `_destroy()` may be emitted as `'error'`.
+ *
+ * Implementors should not override this method, but instead implement `readable._destroy()`.
+ * @since v8.0.0
+ * @param error Error which will be passed as payload in `'error'` event
+ */
+ destroy(error?: Error): this;
+ /**
+ * Event emitter
+ * The defined events on documents including:
+ * 1. close
+ * 2. data
+ * 3. end
+ * 4. error
+ * 5. pause
+ * 6. readable
+ * 7. resume
+ */
+ addListener(event: 'close', listener: () => void): this;
+ addListener(event: 'data', listener: (chunk: any) => void): this;
+ addListener(event: 'end', listener: () => void): this;
+ addListener(event: 'error', listener: (err: Error) => void): this;
+ addListener(event: 'pause', listener: () => void): this;
+ addListener(event: 'readable', listener: () => void): this;
+ addListener(event: 'resume', listener: () => void): this;
+ addListener(event: string | symbol, listener: (...args: any[]) => void): this;
+ emit(event: 'close'): boolean;
+ emit(event: 'data', chunk: any): boolean;
+ emit(event: 'end'): boolean;
+ emit(event: 'error', err: Error): boolean;
+ emit(event: 'pause'): boolean;
+ emit(event: 'readable'): boolean;
+ emit(event: 'resume'): boolean;
+ emit(event: string | symbol, ...args: any[]): boolean;
+ on(event: 'close', listener: () => void): this;
+ on(event: 'data', listener: (chunk: any) => void): this;
+ on(event: 'end', listener: () => void): this;
+ on(event: 'error', listener: (err: Error) => void): this;
+ on(event: 'pause', listener: () => void): this;
+ on(event: 'readable', listener: () => void): this;
+ on(event: 'resume', listener: () => void): this;
+ on(event: string | symbol, listener: (...args: any[]) => void): this;
+ once(event: 'close', listener: () => void): this;
+ once(event: 'data', listener: (chunk: any) => void): this;
+ once(event: 'end', listener: () => void): this;
+ once(event: 'error', listener: (err: Error) => void): this;
+ once(event: 'pause', listener: () => void): this;
+ once(event: 'readable', listener: () => void): this;
+ once(event: 'resume', listener: () => void): this;
+ once(event: string | symbol, listener: (...args: any[]) => void): this;
+ prependListener(event: 'close', listener: () => void): this;
+ prependListener(event: 'data', listener: (chunk: any) => void): this;
+ prependListener(event: 'end', listener: () => void): this;
+ prependListener(event: 'error', listener: (err: Error) => void): this;
+ prependListener(event: 'pause', listener: () => void): this;
+ prependListener(event: 'readable', listener: () => void): this;
+ prependListener(event: 'resume', listener: () => void): this;
+ prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
+ prependOnceListener(event: 'close', listener: () => void): this;
+ prependOnceListener(event: 'data', listener: (chunk: any) => void): this;
+ prependOnceListener(event: 'end', listener: () => void): this;
+ prependOnceListener(event: 'error', listener: (err: Error) => void): this;
+ prependOnceListener(event: 'pause', listener: () => void): this;
+ prependOnceListener(event: 'readable', listener: () => void): this;
+ prependOnceListener(event: 'resume', listener: () => void): this;
+ prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
+ removeListener(event: 'close', listener: () => void): this;
+ removeListener(event: 'data', listener: (chunk: any) => void): this;
+ removeListener(event: 'end', listener: () => void): this;
+ removeListener(event: 'error', listener: (err: Error) => void): this;
+ removeListener(event: 'pause', listener: () => void): this;
+ removeListener(event: 'readable', listener: () => void): this;
+ removeListener(event: 'resume', listener: () => void): this;
+ removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
+ [Symbol.asyncIterator](): AsyncIterableIterator<any>;
+ /**
+ * Calls `readable.destroy()` with an `AbortError` and returns a promise that fulfills when the stream is finished.
+ * @since v20.4.0
+ */
+ [Symbol.asyncDispose](): Promise<void>;
+ }
+ import WritableOptions = internal.WritableOptions;
+ class WritableBase extends Stream implements NodeJS.WritableStream {
+ /**
+ * Is `true` if it is safe to call `writable.write()`, which means
+ * the stream has not been destroyed, errored, or ended.
+ * @since v11.4.0
+ */
+ readonly writable: boolean;
+ /**
+ * Is `true` after `writable.end()` has been called. This property
+ * does not indicate whether the data has been flushed, for this use `writable.writableFinished` instead.
+ * @since v12.9.0
+ */
+ readonly writableEnded: boolean;
+ /**
+ * Is set to `true` immediately before the `'finish'` event is emitted.
+ * @since v12.6.0
+ */
+ readonly writableFinished: boolean;
+ /**
+ * Return the value of `highWaterMark` passed when creating this `Writable`.
+ * @since v9.3.0
+ */
+ readonly writableHighWaterMark: number;
+ /**
+ * This property contains the number of bytes (or objects) in the queue
+ * ready to be written. The value provides introspection data regarding
+ * the status of the `highWaterMark`.
+ * @since v9.4.0
+ */
+ readonly writableLength: number;
+ /**
+ * Getter for the property `objectMode` of a given `Writable` stream.
+ * @since v12.3.0
+ */
+ readonly writableObjectMode: boolean;
+ /**
+ * Number of times `writable.uncork()` needs to be
+ * called in order to fully uncork the stream.
+ * @since v13.2.0, v12.16.0
+ */
+ readonly writableCorked: number;
+ /**
+ * Is `true` after `writable.destroy()` has been called.
+ * @since v8.0.0
+ */
+ destroyed: boolean;
+ /**
+ * Is `true` after `'close'` has been emitted.
+ * @since v18.0.0
+ */
+ readonly closed: boolean;
+ /**
+ * Returns error if the stream has been destroyed with an error.
+ * @since v18.0.0
+ */
+ readonly errored: Error | null;
+ /**
+ * Is `true` if the stream's buffer has been full and stream will emit `'drain'`.
+ * @since v15.2.0, v14.17.0
+ */
+ readonly writableNeedDrain: boolean;
+ constructor(opts?: WritableOptions);
+ _write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
+ _writev?(
+ chunks: Array<{
+ chunk: any;
+ encoding: BufferEncoding;
+ }>,
+ callback: (error?: Error | null) => void
+ ): void;
+ _construct?(callback: (error?: Error | null) => void): void;
+ _destroy(error: Error | null, callback: (error?: Error | null) => void): void;
+ _final(callback: (error?: Error | null) => void): void;
+ /**
+ * The `writable.write()` method writes some data to the stream, and calls the
+ * supplied `callback` once the data has been fully handled. If an error
+ * occurs, the `callback` will be called with the error as its
+ * first argument. The `callback` is called asynchronously and before `'error'` is
+ * emitted.
+ *
+ * The return value is `true` if the internal buffer is less than the`highWaterMark` configured when the stream was created after admitting `chunk`.
+ * If `false` is returned, further attempts to write data to the stream should
+ * stop until the `'drain'` event is emitted.
+ *
+ * While a stream is not draining, calls to `write()` will buffer `chunk`, and
+ * return false. Once all currently buffered chunks are drained (accepted for
+ * delivery by the operating system), the `'drain'` event will be emitted.
+ * Once `write()` returns false, do not write more chunks
+ * until the `'drain'` event is emitted. While calling `write()` on a stream that
+ * is not draining is allowed, Node.js will buffer all written chunks until
+ * maximum memory usage occurs, at which point it will abort unconditionally.
+ * Even before it aborts, high memory usage will cause poor garbage collector
+ * performance and high RSS (which is not typically released back to the system,
+ * even after the memory is no longer required). Since TCP sockets may never
+ * drain if the remote peer does not read the data, writing a socket that is
+ * not draining may lead to a remotely exploitable vulnerability.
+ *
+ * Writing data while the stream is not draining is particularly
+ * problematic for a `Transform`, because the `Transform` streams are paused
+ * by default until they are piped or a `'data'` or `'readable'` event handler
+ * is added.
+ *
+ * If the data to be written can be generated or fetched on demand, it is
+ * recommended to encapsulate the logic into a `Readable` and use {@link pipe}. However, if calling `write()` is preferred, it is
+ * possible to respect backpressure and avoid memory issues using the `'drain'` event:
+ *
+ * ```js
+ * function write(data, cb) {
+ * if (!stream.write(data)) {
+ * stream.once('drain', cb);
+ * } else {
+ * process.nextTick(cb);
+ * }
+ * }
+ *
+ * // Wait for cb to be called before doing any other write.
+ * write('hello', () => {
+ * console.log('Write completed, do more writes now.');
+ * });
+ * ```
+ *
+ * A `Writable` stream in object mode will always ignore the `encoding` argument.
+ * @since v0.9.4
+ * @param chunk Optional data to write. For streams not operating in object mode, `chunk` must be a string, `Buffer` or `Uint8Array`. For object mode streams, `chunk` may be any
+ * JavaScript value other than `null`.
+ * @param [encoding='utf8'] The encoding, if `chunk` is a string.
+ * @param callback Callback for when this chunk of data is flushed.
+ * @return `false` if the stream wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`.
+ */
+ write(chunk: any, callback?: (error: Error | null | undefined) => void): boolean;
+ write(chunk: any, encoding: BufferEncoding, callback?: (error: Error | null | undefined) => void): boolean;
+ /**
+ * The `writable.setDefaultEncoding()` method sets the default `encoding` for a `Writable` stream.
+ * @since v0.11.15
+ * @param encoding The new default encoding
+ */
+ setDefaultEncoding(encoding: BufferEncoding): this;
+ /**
+ * Calling the `writable.end()` method signals that no more data will be written
+ * to the `Writable`. The optional `chunk` and `encoding` arguments allow one
+ * final additional chunk of data to be written immediately before closing the
+ * stream.
+ *
+ * Calling the {@link write} method after calling {@link end} will raise an error.
+ *
+ * ```js
+ * // Write 'hello, ' and then end with 'world!'.
+ * const fs = require('node:fs');
+ * const file = fs.createWriteStream('example.txt');
+ * file.write('hello, ');
+ * file.end('world!');
+ * // Writing more now is not allowed!
+ * ```
+ * @since v0.9.4
+ * @param chunk Optional data to write. For streams not operating in object mode, `chunk` must be a string, `Buffer` or `Uint8Array`. For object mode streams, `chunk` may be any
+ * JavaScript value other than `null`.
+ * @param encoding The encoding if `chunk` is a string
+ * @param callback Callback for when the stream is finished.
+ */
+ end(cb?: () => void): this;
+ end(chunk: any, cb?: () => void): this;
+ end(chunk: any, encoding: BufferEncoding, cb?: () => void): this;
+ /**
+ * The `writable.cork()` method forces all written data to be buffered in memory.
+ * The buffered data will be flushed when either the {@link uncork} or {@link end} methods are called.
+ *
+ * The primary intent of `writable.cork()` is to accommodate a situation in which
+ * several small chunks are written to the stream in rapid succession. Instead of
+ * immediately forwarding them to the underlying destination, `writable.cork()`buffers all the chunks until `writable.uncork()` is called, which will pass them
+ * all to `writable._writev()`, if present. This prevents a head-of-line blocking
+ * situation where data is being buffered while waiting for the first small chunk
+ * to be processed. However, use of `writable.cork()` without implementing`writable._writev()` may have an adverse effect on throughput.
+ *
+ * See also: `writable.uncork()`, `writable._writev()`.
+ * @since v0.11.2
+ */
+ cork(): void;
+ /**
+ * The `writable.uncork()` method flushes all data buffered since {@link cork} was called.
+ *
+ * When using `writable.cork()` and `writable.uncork()` to manage the buffering
+ * of writes to a stream, defer calls to `writable.uncork()` using`process.nextTick()`. Doing so allows batching of all`writable.write()` calls that occur within a given Node.js event
+ * loop phase.
+ *
+ * ```js
+ * stream.cork();
+ * stream.write('some ');
+ * stream.write('data ');
+ * process.nextTick(() => stream.uncork());
+ * ```
+ *
+ * If the `writable.cork()` method is called multiple times on a stream, the
+ * same number of calls to `writable.uncork()` must be called to flush the buffered
+ * data.
+ *
+ * ```js
+ * stream.cork();
+ * stream.write('some ');
+ * stream.cork();
+ * stream.write('data ');
+ * process.nextTick(() => {
+ * stream.uncork();
+ * // The data will not be flushed until uncork() is called a second time.
+ * stream.uncork();
+ * });
+ * ```
+ *
+ * See also: `writable.cork()`.
+ * @since v0.11.2
+ */
+ uncork(): void;
+ /**
+ * Destroy the stream. Optionally emit an `'error'` event, and emit a `'close'`event (unless `emitClose` is set to `false`). After this call, the writable
+ * stream has ended and subsequent calls to `write()` or `end()` will result in
+ * an `ERR_STREAM_DESTROYED` error.
+ * This is a destructive and immediate way to destroy a stream. Previous calls to`write()` may not have drained, and may trigger an `ERR_STREAM_DESTROYED` error.
+ * Use `end()` instead of destroy if data should flush before close, or wait for
+ * the `'drain'` event before destroying the stream.
+ *
+ * Once `destroy()` has been called any further calls will be a no-op and no
+ * further errors except from `_destroy()` may be emitted as `'error'`.
+ *
+ * Implementors should not override this method,
+ * but instead implement `writable._destroy()`.
+ * @since v8.0.0
+ * @param error Optional, an error to emit with `'error'` event.
+ */
+ destroy(error?: Error): this;
+ /**
+ * Event emitter
+ * The defined events on documents including:
+ * 1. close
+ * 2. drain
+ * 3. error
+ * 4. finish
+ * 5. pipe
+ * 6. unpipe
+ */
+ 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: Readable) => void): this;
+ addListener(event: 'unpipe', listener: (src: Readable) => void): this;
+ addListener(event: string | symbol, listener: (...args: any[]) => void): this;
+ emit(event: 'close'): boolean;
+ emit(event: 'drain'): boolean;
+ emit(event: 'error', err: Error): boolean;
+ emit(event: 'finish'): boolean;
+ emit(event: 'pipe', src: Readable): boolean;
+ emit(event: 'unpipe', src: Readable): boolean;
+ emit(event: string | symbol, ...args: any[]): boolean;
+ 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: Readable) => void): this;
+ on(event: 'unpipe', listener: (src: Readable) => void): this;
+ on(event: string | symbol, listener: (...args: any[]) => 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: Readable) => void): this;
+ once(event: 'unpipe', listener: (src: Readable) => void): this;
+ once(event: string | symbol, listener: (...args: any[]) => 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: Readable) => void): this;
+ prependListener(event: 'unpipe', listener: (src: Readable) => void): this;
+ prependListener(event: string | symbol, listener: (...args: any[]) => 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: Readable) => void): this;
+ prependOnceListener(event: 'unpipe', listener: (src: Readable) => void): this;
+ prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
+ removeListener(event: 'close', listener: () => void): this;
+ removeListener(event: 'drain', listener: () => void): this;
+ removeListener(event: 'error', listener: (err: Error) => void): this;
+ removeListener(event: 'finish', listener: () => void): this;
+ removeListener(event: 'pipe', listener: (src: Readable) => void): this;
+ removeListener(event: 'unpipe', listener: (src: Readable) => void): this;
+ removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
+ }
namespace internal {
class Stream extends internal {
@@ -50,10 +792,6 @@
* @since v0.9.4
*/
- class Readable extends Stream implements NodeJS.ReadableStream {
+ class Readable extends ReadableBase {
/**
- * A utility method for creating Readable Streams out of iterators.
- */
- static from(iterable: Iterable<any> | AsyncIterable<any>, options?: ReadableOptions): Readable;
- /**
* A utility method for creating a `Readable` from a web `ReadableStream`.
* @since v17.0.0
@@ -62,9 +800,4 @@
static fromWeb(readableStream: streamWeb.ReadableStream, options?: Pick<ReadableOptions, 'encoding' | 'highWaterMark' | 'objectMode' | 'signal'>): Readable;
/**
- * Returns whether the stream has been read from or cancelled.
- * @since v16.8.0
- */
- static isDisturbed(stream: Readable | NodeJS.ReadableStream): boolean;
- /**
* A utility method for creating a web `ReadableStream` from a `Readable`.
* @since v17.0.0
@@ -72,434 +805,4 @@
*/
static toWeb(streamReadable: Readable): streamWeb.ReadableStream;
- /**
- * Returns whether the stream was destroyed or errored before emitting `'end'`.
- * @since v16.8.0
- * @experimental
- */
- readonly readableAborted: boolean;
- /**
- * Is `true` if it is safe to call `readable.read()`, which means
- * the stream has not been destroyed or emitted `'error'` or `'end'`.
- * @since v11.4.0
- */
- readable: boolean;
- /**
- * Returns whether `'data'` has been emitted.
- * @since v16.7.0, v14.18.0
- * @experimental
- */
- readonly readableDidRead: boolean;
- /**
- * Getter for the property `encoding` of a given `Readable` stream. The `encoding`property can be set using the `readable.setEncoding()` method.
- * @since v12.7.0
- */
- readonly readableEncoding: BufferEncoding | null;
- /**
- * Becomes `true` when `'end'` event is emitted.
- * @since v12.9.0
- */
- readonly readableEnded: boolean;
- /**
- * This property reflects the current state of a `Readable` stream as described
- * in the `Three states` section.
- * @since v9.4.0
- */
- readonly readableFlowing: boolean | null;
- /**
- * Returns the value of `highWaterMark` passed when creating this `Readable`.
- * @since v9.3.0
- */
- readonly readableHighWaterMark: number;
- /**
- * This property contains the number of bytes (or objects) in the queue
- * ready to be read. The value provides introspection data regarding
- * the status of the `highWaterMark`.
- * @since v9.4.0
- */
- readonly readableLength: number;
- /**
- * Getter for the property `objectMode` of a given `Readable` stream.
- * @since v12.3.0
- */
- readonly readableObjectMode: boolean;
- /**
- * Is `true` after `readable.destroy()` has been called.
- * @since v8.0.0
- */
- destroyed: boolean;
- /**
- * Is `true` after `'close'` has been emitted.
- * @since v18.0.0
- */
- readonly closed: boolean;
- /**
- * Returns error if the stream has been destroyed with an error.
- * @since v18.0.0
- */
- readonly errored: Error | null;
- constructor(opts?: ReadableOptions);
- _construct?(callback: (error?: Error | null) => void): void;
- _read(size: number): void;
- /**
- * The `readable.read()` method reads data out of the internal buffer and
- * returns it. If no data is available to be read, `null` is returned. By default,
- * the data is returned as a `Buffer` object unless an encoding has been
- * specified using the `readable.setEncoding()` method or the stream is operating
- * in object mode.
- *
- * The optional `size` argument specifies a specific number of bytes to read. If`size` bytes are not available to be read, `null` will be returned _unless_the stream has ended, in which
- * case all of the data remaining in the internal
- * buffer will be returned.
- *
- * If the `size` argument is not specified, all of the data contained in the
- * internal buffer will be returned.
- *
- * The `size` argument must be less than or equal to 1 GiB.
- *
- * The `readable.read()` method should only be called on `Readable` streams
- * operating in paused mode. In flowing mode, `readable.read()` is called
- * automatically until the internal buffer is fully drained.
- *
- * ```js
- * const readable = getReadableStreamSomehow();
- *
- * // 'readable' may be triggered multiple times as data is buffered in
- * readable.on('readable', () => {
- * let chunk;
- * console.log('Stream is readable (new data received in buffer)');
- * // Use a loop to make sure we read all currently available data
- * while (null !== (chunk = readable.read())) {
- * console.log(`Read ${chunk.length} bytes of data...`);
- * }
- * });
- *
- * // 'end' will be triggered once when there is no more data available
- * readable.on('end', () => {
- * console.log('Reached end of stream.');
- * });
- * ```
- *
- * Each call to `readable.read()` returns a chunk of data, or `null`. The chunks
- * are not concatenated. A `while` loop is necessary to consume all data
- * currently in the buffer. When reading a large file `.read()` may return `null`,
- * having consumed all buffered content so far, but there is still more data to
- * come not yet buffered. In this case a new `'readable'` event will be emitted
- * when there is more data in the buffer. Finally the `'end'` event will be
- * emitted when there is no more data to come.
- *
- * Therefore to read a file's whole contents from a `readable`, it is necessary
- * to collect chunks across multiple `'readable'` events:
- *
- * ```js
- * const chunks = [];
- *
- * readable.on('readable', () => {
- * let chunk;
- * while (null !== (chunk = readable.read())) {
- * chunks.push(chunk);
- * }
- * });
- *
- * readable.on('end', () => {
- * const content = chunks.join('');
- * });
- * ```
- *
- * A `Readable` stream in object mode will always return a single item from
- * a call to `readable.read(size)`, regardless of the value of the`size` argument.
- *
- * If the `readable.read()` method returns a chunk of data, a `'data'` event will
- * also be emitted.
- *
- * Calling {@link read} after the `'end'` event has
- * been emitted will return `null`. No runtime error will be raised.
- * @since v0.9.4
- * @param size Optional argument to specify how much data to read.
- */
- read(size?: number): any;
- /**
- * The `readable.setEncoding()` method sets the character encoding for
- * data read from the `Readable` stream.
- *
- * By default, no encoding is assigned and stream data will be returned as`Buffer` objects. Setting an encoding causes the stream data
- * to be returned as strings of the specified encoding rather than as `Buffer`objects. For instance, calling `readable.setEncoding('utf8')` will cause the
- * output data to be interpreted as UTF-8 data, and passed as strings. Calling`readable.setEncoding('hex')` will cause the data to be encoded in hexadecimal
- * string format.
- *
- * The `Readable` stream will properly handle multi-byte characters delivered
- * through the stream that would otherwise become improperly decoded if simply
- * pulled from the stream as `Buffer` objects.
- *
- * ```js
- * const readable = getReadableStreamSomehow();
- * readable.setEncoding('utf8');
- * readable.on('data', (chunk) => {
- * assert.equal(typeof chunk, 'string');
- * console.log('Got %d characters of string data:', chunk.length);
- * });
- * ```
- * @since v0.9.4
- * @param encoding The encoding to use.
- */
- setEncoding(encoding: BufferEncoding): this;
- /**
- * The `readable.pause()` method will cause a stream in flowing mode to stop
- * emitting `'data'` events, switching out of flowing mode. Any data that
- * becomes available will remain in the internal buffer.
- *
- * ```js
- * const readable = getReadableStreamSomehow();
- * readable.on('data', (chunk) => {
- * console.log(`Received ${chunk.length} bytes of data.`);
- * readable.pause();
- * console.log('There will be no additional data for 1 second.');
- * setTimeout(() => {
- * console.log('Now data will start flowing again.');
- * readable.resume();
- * }, 1000);
- * });
- * ```
- *
- * The `readable.pause()` method has no effect if there is a `'readable'`event listener.
- * @since v0.9.4
- */
- pause(): this;
- /**
- * The `readable.resume()` method causes an explicitly paused `Readable` stream to
- * resume emitting `'data'` events, switching the stream into flowing mode.
- *
- * The `readable.resume()` method can be used to fully consume the data from a
- * stream without actually processing any of that data:
- *
- * ```js
- * getReadableStreamSomehow()
- * .resume()
- * .on('end', () => {
- * console.log('Reached the end, but did not read anything.');
- * });
- * ```
- *
- * The `readable.resume()` method has no effect if there is a `'readable'`event listener.
- * @since v0.9.4
- */
- resume(): this;
- /**
- * The `readable.isPaused()` method returns the current operating state of the`Readable`. This is used primarily by the mechanism that underlies the`readable.pipe()` method. In most
- * typical cases, there will be no reason to
- * use this method directly.
- *
- * ```js
- * const readable = new stream.Readable();
- *
- * readable.isPaused(); // === false
- * readable.pause();
- * readable.isPaused(); // === true
- * readable.resume();
- * readable.isPaused(); // === false
- * ```
- * @since v0.11.14
- */
- isPaused(): boolean;
- /**
- * The `readable.unpipe()` method detaches a `Writable` stream previously attached
- * using the {@link pipe} method.
- *
- * If the `destination` is not specified, then _all_ pipes are detached.
- *
- * If the `destination` is specified, but no pipe is set up for it, then
- * the method does nothing.
- *
- * ```js
- * const fs = require('node:fs');
- * const readable = getReadableStreamSomehow();
- * const writable = fs.createWriteStream('file.txt');
- * // All the data from readable goes into 'file.txt',
- * // but only for the first second.
- * readable.pipe(writable);
- * setTimeout(() => {
- * console.log('Stop writing to file.txt.');
- * readable.unpipe(writable);
- * console.log('Manually close the file stream.');
- * writable.end();
- * }, 1000);
- * ```
- * @since v0.9.4
- * @param destination Optional specific stream to unpipe
- */
- unpipe(destination?: NodeJS.WritableStream): this;
- /**
- * Passing `chunk` as `null` signals the end of the stream (EOF) and behaves the
- * same as `readable.push(null)`, after which no more data can be written. The EOF
- * signal is put at the end of the buffer and any buffered data will still be
- * flushed.
- *
- * The `readable.unshift()` method pushes a chunk of data back into the internal
- * buffer. This is useful in certain situations where a stream is being consumed by
- * code that needs to "un-consume" some amount of data that it has optimistically
- * pulled out of the source, so that the data can be passed on to some other party.
- *
- * The `stream.unshift(chunk)` method cannot be called after the `'end'` event
- * has been emitted or a runtime error will be thrown.
- *
- * Developers using `stream.unshift()` often should consider switching to
- * use of a `Transform` stream instead. See the `API for stream implementers` section for more information.
- *
- * ```js
- * // Pull off a header delimited by \n\n.
- * // Use unshift() if we get too much.
- * // Call the callback with (error, header, stream).
- * const { StringDecoder } = require('node:string_decoder');
- * function parseHeader(stream, callback) {
- * stream.on('error', callback);
- * stream.on('readable', onReadable);
- * const decoder = new StringDecoder('utf8');
- * let header = '';
- * function onReadable() {
- * let chunk;
- * while (null !== (chunk = stream.read())) {
- * const str = decoder.write(chunk);
- * if (str.includes('\n\n')) {
- * // Found the header boundary.
- * const split = str.split(/\n\n/);
- * header += split.shift();
- * const remaining = split.join('\n\n');
- * const buf = Buffer.from(remaining, 'utf8');
- * stream.removeListener('error', callback);
- * // Remove the 'readable' listener before unshifting.
- * stream.removeListener('readable', onReadable);
- * if (buf.length)
- * stream.unshift(buf);
- * // Now the body of the message can be read from the stream.
- * callback(null, header, stream);
- * return;
- * }
- * // Still reading the header.
- * header += str;
- * }
- * }
- * }
- * ```
- *
- * Unlike {@link push}, `stream.unshift(chunk)` will not
- * end the reading process by resetting the internal reading state of the stream.
- * This can cause unexpected results if `readable.unshift()` is called during a
- * read (i.e. from within a {@link _read} implementation on a
- * custom stream). Following the call to `readable.unshift()` with an immediate {@link push} will reset the reading state appropriately,
- * however it is best to simply avoid calling `readable.unshift()` while in the
- * process of performing a read.
- * @since v0.9.11
- * @param chunk Chunk of data to unshift onto the read queue. For streams not operating in object mode, `chunk` must be a string, `Buffer`, `Uint8Array`, or `null`. For object mode
- * streams, `chunk` may be any JavaScript value.
- * @param encoding Encoding of string chunks. Must be a valid `Buffer` encoding, such as `'utf8'` or `'ascii'`.
- */
- unshift(chunk: any, encoding?: BufferEncoding): void;
- /**
- * Prior to Node.js 0.10, streams did not implement the entire `node:stream`module API as it is currently defined. (See `Compatibility` for more
- * information.)
- *
- * When using an older Node.js library that emits `'data'` events and has a {@link pause} method that is advisory only, the`readable.wrap()` method can be used to create a `Readable`
- * stream that uses
- * the old stream as its data source.
- *
- * It will rarely be necessary to use `readable.wrap()` but the method has been
- * provided as a convenience for interacting with older Node.js applications and
- * libraries.
- *
- * ```js
- * const { OldReader } = require('./old-api-module.js');
- * const { Readable } = require('node:stream');
- * const oreader = new OldReader();
- * const myReader = new Readable().wrap(oreader);
- *
- * myReader.on('readable', () => {
- * myReader.read(); // etc.
- * });
- * ```
- * @since v0.9.4
- * @param stream An "old style" readable stream
- */
- wrap(stream: NodeJS.ReadableStream): this;
- push(chunk: any, encoding?: BufferEncoding): boolean;
- _destroy(error: Error | null, callback: (error?: Error | null) => void): void;
- /**
- * Destroy the stream. Optionally emit an `'error'` event, and emit a `'close'`event (unless `emitClose` is set to `false`). After this call, the readable
- * stream will release any internal resources and subsequent calls to `push()`will be ignored.
- *
- * Once `destroy()` has been called any further calls will be a no-op and no
- * further errors except from `_destroy()` may be emitted as `'error'`.
- *
- * Implementors should not override this method, but instead implement `readable._destroy()`.
- * @since v8.0.0
- * @param error Error which will be passed as payload in `'error'` event
- */
- destroy(error?: Error): this;
- /**
- * Event emitter
- * The defined events on documents including:
- * 1. close
- * 2. data
- * 3. end
- * 4. error
- * 5. pause
- * 6. readable
- * 7. resume
- */
- addListener(event: 'close', listener: () => void): this;
- addListener(event: 'data', listener: (chunk: any) => void): this;
- addListener(event: 'end', listener: () => void): this;
- addListener(event: 'error', listener: (err: Error) => void): this;
- addListener(event: 'pause', listener: () => void): this;
- addListener(event: 'readable', listener: () => void): this;
- addListener(event: 'resume', listener: () => void): this;
- addListener(event: string | symbol, listener: (...args: any[]) => void): this;
- emit(event: 'close'): boolean;
- emit(event: 'data', chunk: any): boolean;
- emit(event: 'end'): boolean;
- emit(event: 'error', err: Error): boolean;
- emit(event: 'pause'): boolean;
- emit(event: 'readable'): boolean;
- emit(event: 'resume'): boolean;
- emit(event: string | symbol, ...args: any[]): boolean;
- on(event: 'close', listener: () => void): this;
- on(event: 'data', listener: (chunk: any) => void): this;
- on(event: 'end', listener: () => void): this;
- on(event: 'error', listener: (err: Error) => void): this;
- on(event: 'pause', listener: () => void): this;
- on(event: 'readable', listener: () => void): this;
- on(event: 'resume', listener: () => void): this;
- on(event: string | symbol, listener: (...args: any[]) => void): this;
- once(event: 'close', listener: () => void): this;
- once(event: 'data', listener: (chunk: any) => void): this;
- once(event: 'end', listener: () => void): this;
- once(event: 'error', listener: (err: Error) => void): this;
- once(event: 'pause', listener: () => void): this;
- once(event: 'readable', listener: () => void): this;
- once(event: 'resume', listener: () => void): this;
- once(event: string | symbol, listener: (...args: any[]) => void): this;
- prependListener(event: 'close', listener: () => void): this;
- prependListener(event: 'data', listener: (chunk: any) => void): this;
- prependListener(event: 'end', listener: () => void): this;
- prependListener(event: 'error', listener: (err: Error) => void): this;
- prependListener(event: 'pause', listener: () => void): this;
- prependListener(event: 'readable', listener: () => void): this;
- prependListener(event: 'resume', listener: () => void): this;
- prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
- prependOnceListener(event: 'close', listener: () => void): this;
- prependOnceListener(event: 'data', listener: (chunk: any) => void): this;
- prependOnceListener(event: 'end', listener: () => void): this;
- prependOnceListener(event: 'error', listener: (err: Error) => void): this;
- prependOnceListener(event: 'pause', listener: () => void): this;
- prependOnceListener(event: 'readable', listener: () => void): this;
- prependOnceListener(event: 'resume', listener: () => void): this;
- prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
- removeListener(event: 'close', listener: () => void): this;
- removeListener(event: 'data', listener: (chunk: any) => void): this;
- removeListener(event: 'end', listener: () => void): this;
- removeListener(event: 'error', listener: (err: Error) => void): this;
- removeListener(event: 'pause', listener: () => void): this;
- removeListener(event: 'readable', listener: () => void): this;
- removeListener(event: 'resume', listener: () => void): this;
- removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
- [Symbol.asyncIterator](): AsyncIterableIterator<any>;
}
interface WritableOptions extends StreamOptions<Writable> {
@@ -520,5 +823,5 @@
* @since v0.9.4
*/
- class Writable extends Stream implements NodeJS.WritableStream {
+ class Writable extends WritableBase {
/**
* A utility method for creating a `Writable` from a web `WritableStream`.
@@ -533,290 +836,4 @@
*/
static toWeb(streamWritable: Writable): streamWeb.WritableStream;
- /**
- * Is `true` if it is safe to call `writable.write()`, which means
- * the stream has not been destroyed, errored, or ended.
- * @since v11.4.0
- */
- readonly writable: boolean;
- /**
- * Is `true` after `writable.end()` has been called. This property
- * does not indicate whether the data has been flushed, for this use `writable.writableFinished` instead.
- * @since v12.9.0
- */
- readonly writableEnded: boolean;
- /**
- * Is set to `true` immediately before the `'finish'` event is emitted.
- * @since v12.6.0
- */
- readonly writableFinished: boolean;
- /**
- * Return the value of `highWaterMark` passed when creating this `Writable`.
- * @since v9.3.0
- */
- readonly writableHighWaterMark: number;
- /**
- * This property contains the number of bytes (or objects) in the queue
- * ready to be written. The value provides introspection data regarding
- * the status of the `highWaterMark`.
- * @since v9.4.0
- */
- readonly writableLength: number;
- /**
- * Getter for the property `objectMode` of a given `Writable` stream.
- * @since v12.3.0
- */
- readonly writableObjectMode: boolean;
- /**
- * Number of times `writable.uncork()` needs to be
- * called in order to fully uncork the stream.
- * @since v13.2.0, v12.16.0
- */
- readonly writableCorked: number;
- /**
- * Is `true` after `writable.destroy()` has been called.
- * @since v8.0.0
- */
- destroyed: boolean;
- /**
- * Is `true` after `'close'` has been emitted.
- * @since v18.0.0
- */
- readonly closed: boolean;
- /**
- * Returns error if the stream has been destroyed with an error.
- * @since v18.0.0
- */
- readonly errored: Error | null;
- /**
- * Is `true` if the stream's buffer has been full and stream will emit `'drain'`.
- * @since v15.2.0, v14.17.0
- */
- readonly writableNeedDrain: boolean;
- constructor(opts?: WritableOptions);
- _write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
- _writev?(
- chunks: Array<{
- chunk: any;
- encoding: BufferEncoding;
- }>,
- callback: (error?: Error | null) => void
- ): void;
- _construct?(callback: (error?: Error | null) => void): void;
- _destroy(error: Error | null, callback: (error?: Error | null) => void): void;
- _final(callback: (error?: Error | null) => void): void;
- /**
- * The `writable.write()` method writes some data to the stream, and calls the
- * supplied `callback` once the data has been fully handled. If an error
- * occurs, the `callback` will be called with the error as its
- * first argument. The `callback` is called asynchronously and before `'error'` is
- * emitted.
- *
- * The return value is `true` if the internal buffer is less than the`highWaterMark` configured when the stream was created after admitting `chunk`.
- * If `false` is returned, further attempts to write data to the stream should
- * stop until the `'drain'` event is emitted.
- *
- * While a stream is not draining, calls to `write()` will buffer `chunk`, and
- * return false. Once all currently buffered chunks are drained (accepted for
- * delivery by the operating system), the `'drain'` event will be emitted.
- * Once `write()` returns false, do not write more chunks
- * until the `'drain'` event is emitted. While calling `write()` on a stream that
- * is not draining is allowed, Node.js will buffer all written chunks until
- * maximum memory usage occurs, at which point it will abort unconditionally.
- * Even before it aborts, high memory usage will cause poor garbage collector
- * performance and high RSS (which is not typically released back to the system,
- * even after the memory is no longer required). Since TCP sockets may never
- * drain if the remote peer does not read the data, writing a socket that is
- * not draining may lead to a remotely exploitable vulnerability.
- *
- * Writing data while the stream is not draining is particularly
- * problematic for a `Transform`, because the `Transform` streams are paused
- * by default until they are piped or a `'data'` or `'readable'` event handler
- * is added.
- *
- * If the data to be written can be generated or fetched on demand, it is
- * recommended to encapsulate the logic into a `Readable` and use {@link pipe}. However, if calling `write()` is preferred, it is
- * possible to respect backpressure and avoid memory issues using the `'drain'` event:
- *
- * ```js
- * function write(data, cb) {
- * if (!stream.write(data)) {
- * stream.once('drain', cb);
- * } else {
- * process.nextTick(cb);
- * }
- * }
- *
- * // Wait for cb to be called before doing any other write.
- * write('hello', () => {
- * console.log('Write completed, do more writes now.');
- * });
- * ```
- *
- * A `Writable` stream in object mode will always ignore the `encoding` argument.
- * @since v0.9.4
- * @param chunk Optional data to write. For streams not operating in object mode, `chunk` must be a string, `Buffer` or `Uint8Array`. For object mode streams, `chunk` may be any
- * JavaScript value other than `null`.
- * @param [encoding='utf8'] The encoding, if `chunk` is a string.
- * @param callback Callback for when this chunk of data is flushed.
- * @return `false` if the stream wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`.
- */
- write(chunk: any, callback?: (error: Error | null | undefined) => void): boolean;
- write(chunk: any, encoding: BufferEncoding, callback?: (error: Error | null | undefined) => void): boolean;
- /**
- * The `writable.setDefaultEncoding()` method sets the default `encoding` for a `Writable` stream.
- * @since v0.11.15
- * @param encoding The new default encoding
- */
- setDefaultEncoding(encoding: BufferEncoding): this;
- /**
- * Calling the `writable.end()` method signals that no more data will be written
- * to the `Writable`. The optional `chunk` and `encoding` arguments allow one
- * final additional chunk of data to be written immediately before closing the
- * stream.
- *
- * Calling the {@link write} method after calling {@link end} will raise an error.
- *
- * ```js
- * // Write 'hello, ' and then end with 'world!'.
- * const fs = require('node:fs');
- * const file = fs.createWriteStream('example.txt');
- * file.write('hello, ');
- * file.end('world!');
- * // Writing more now is not allowed!
- * ```
- * @since v0.9.4
- * @param chunk Optional data to write. For streams not operating in object mode, `chunk` must be a string, `Buffer` or `Uint8Array`. For object mode streams, `chunk` may be any
- * JavaScript value other than `null`.
- * @param encoding The encoding if `chunk` is a string
- * @param callback Callback for when the stream is finished.
- */
- end(cb?: () => void): this;
- end(chunk: any, cb?: () => void): this;
- end(chunk: any, encoding: BufferEncoding, cb?: () => void): this;
- /**
- * The `writable.cork()` method forces all written data to be buffered in memory.
- * The buffered data will be flushed when either the {@link uncork} or {@link end} methods are called.
- *
- * The primary intent of `writable.cork()` is to accommodate a situation in which
- * several small chunks are written to the stream in rapid succession. Instead of
- * immediately forwarding them to the underlying destination, `writable.cork()`buffers all the chunks until `writable.uncork()` is called, which will pass them
- * all to `writable._writev()`, if present. This prevents a head-of-line blocking
- * situation where data is being buffered while waiting for the first small chunk
- * to be processed. However, use of `writable.cork()` without implementing`writable._writev()` may have an adverse effect on throughput.
- *
- * See also: `writable.uncork()`, `writable._writev()`.
- * @since v0.11.2
- */
- cork(): void;
- /**
- * The `writable.uncork()` method flushes all data buffered since {@link cork} was called.
- *
- * When using `writable.cork()` and `writable.uncork()` to manage the buffering
- * of writes to a stream, defer calls to `writable.uncork()` using`process.nextTick()`. Doing so allows batching of all`writable.write()` calls that occur within a given Node.js event
- * loop phase.
- *
- * ```js
- * stream.cork();
- * stream.write('some ');
- * stream.write('data ');
- * process.nextTick(() => stream.uncork());
- * ```
- *
- * If the `writable.cork()` method is called multiple times on a stream, the
- * same number of calls to `writable.uncork()` must be called to flush the buffered
- * data.
- *
- * ```js
- * stream.cork();
- * stream.write('some ');
- * stream.cork();
- * stream.write('data ');
- * process.nextTick(() => {
- * stream.uncork();
- * // The data will not be flushed until uncork() is called a second time.
- * stream.uncork();
- * });
- * ```
- *
- * See also: `writable.cork()`.
- * @since v0.11.2
- */
- uncork(): void;
- /**
- * Destroy the stream. Optionally emit an `'error'` event, and emit a `'close'`event (unless `emitClose` is set to `false`). After this call, the writable
- * stream has ended and subsequent calls to `write()` or `end()` will result in
- * an `ERR_STREAM_DESTROYED` error.
- * This is a destructive and immediate way to destroy a stream. Previous calls to`write()` may not have drained, and may trigger an `ERR_STREAM_DESTROYED` error.
- * Use `end()` instead of destroy if data should flush before close, or wait for
- * the `'drain'` event before destroying the stream.
- *
- * Once `destroy()` has been called any further calls will be a no-op and no
- * further errors except from `_destroy()` may be emitted as `'error'`.
- *
- * Implementors should not override this method,
- * but instead implement `writable._destroy()`.
- * @since v8.0.0
- * @param error Optional, an error to emit with `'error'` event.
- */
- destroy(error?: Error): this;
- /**
- * Event emitter
- * The defined events on documents including:
- * 1. close
- * 2. drain
- * 3. error
- * 4. finish
- * 5. pipe
- * 6. unpipe
- */
- 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: Readable) => void): this;
- addListener(event: 'unpipe', listener: (src: Readable) => void): this;
- addListener(event: string | symbol, listener: (...args: any[]) => void): this;
- emit(event: 'close'): boolean;
- emit(event: 'drain'): boolean;
- emit(event: 'error', err: Error): boolean;
- emit(event: 'finish'): boolean;
- emit(event: 'pipe', src: Readable): boolean;
- emit(event: 'unpipe', src: Readable): boolean;
- emit(event: string | symbol, ...args: any[]): boolean;
- 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: Readable) => void): this;
- on(event: 'unpipe', listener: (src: Readable) => void): this;
- on(event: string | symbol, listener: (...args: any[]) => 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: Readable) => void): this;
- once(event: 'unpipe', listener: (src: Readable) => void): this;
- once(event: string | symbol, listener: (...args: any[]) => 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: Readable) => void): this;
- prependListener(event: 'unpipe', listener: (src: Readable) => void): this;
- prependListener(event: string | symbol, listener: (...args: any[]) => 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: Readable) => void): this;
- prependOnceListener(event: 'unpipe', listener: (src: Readable) => void): this;
- prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
- removeListener(event: 'close', listener: () => void): this;
- removeListener(event: 'drain', listener: () => void): this;
- removeListener(event: 'error', listener: (err: Error) => void): this;
- removeListener(event: 'finish', listener: () => void): this;
- removeListener(event: 'pipe', listener: (src: Readable) => void): this;
- removeListener(event: 'unpipe', listener: (src: Readable) => void): this;
- removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
}
interface DuplexOptions extends ReadableOptions, WritableOptions {
@@ -851,5 +868,5 @@
* @since v0.9.4
*/
- class Duplex extends Readable implements Writable {
+ class Duplex extends ReadableBase implements WritableBase {
readonly writable: boolean;
readonly writableEnded: boolean;
@@ -914,4 +931,25 @@
uncork(): void;
/**
+ * A utility method for creating a web `ReadableStream` and `WritableStream` from a `Duplex`.
+ * @since v17.0.0
+ * @experimental
+ */
+ static toWeb(streamDuplex: Duplex): {
+ readable: streamWeb.ReadableStream;
+ writable: streamWeb.WritableStream;
+ };
+ /**
+ * A utility method for creating a `Duplex` from a web `ReadableStream` and `WritableStream`.
+ * @since v17.0.0
+ * @experimental
+ */
+ static fromWeb(
+ duplexStream: {
+ readable: streamWeb.ReadableStream;
+ writable: streamWeb.WritableStream;
+ },
+ options?: Pick<DuplexOptions, 'allowHalfOpen' | 'decodeStrings' | 'encoding' | 'highWaterMark' | 'objectMode' | 'signal'>
+ ): Duplex;
+ /**
* Event emitter
* The defined events on documents including:
diff --git a/ts4.8/test.d.ts b/ts4.8/test.d.ts
index v20.3.3..v20.5.7 100777
--- a/ts4.8/test.d.ts
+++ b/ts4.8/test.d.ts
@@ -81,4 +81,5 @@
declare module 'node:test' {
import { Readable } from 'node:stream';
+ import { AsyncResource } from 'node:async_hooks';
/**
* ```js
@@ -160,33 +161,33 @@
* @param options Configuration options for the suite. supports the same options as `test([name][, options][, fn])`.
* @param [fn='A no-op function'] The function under suite declaring all subtests and subsuites. The first argument to this function is a {@link SuiteContext} object.
- * @return `undefined`.
+ * @return Immediately fulfilled with `undefined`.
*/
- function describe(name?: string, options?: TestOptions, fn?: SuiteFn): void;
- function describe(name?: string, fn?: SuiteFn): void;
- function describe(options?: TestOptions, fn?: SuiteFn): void;
- function describe(fn?: SuiteFn): void;
+ function describe(name?: string, options?: TestOptions, fn?: SuiteFn): Promise<void>;
+ function describe(name?: string, fn?: SuiteFn): Promise<void>;
+ function describe(options?: TestOptions, fn?: SuiteFn): Promise<void>;
+ function describe(fn?: SuiteFn): Promise<void>;
namespace describe {
/**
* Shorthand for skipping a suite, same as `describe([name], { skip: true }[, fn])`.
*/
- function skip(name?: string, options?: TestOptions, fn?: SuiteFn): void;
- function skip(name?: string, fn?: SuiteFn): void;
- function skip(options?: TestOptions, fn?: SuiteFn): void;
- function skip(fn?: SuiteFn): void;
+ function skip(name?: string, options?: TestOptions, fn?: SuiteFn): Promise<void>;
+ function skip(name?: string, fn?: SuiteFn): Promise<void>;
+ function skip(options?: TestOptions, fn?: SuiteFn): Promise<void>;
+ function skip(fn?: SuiteFn): Promise<void>;
/**
* Shorthand for marking a suite as `TODO`, same as `describe([name], { todo: true }[, fn])`.
*/
- function todo(name?: string, options?: TestOptions, fn?: SuiteFn): void;
- function todo(name?: string, fn?: SuiteFn): void;
- function todo(options?: TestOptions, fn?: SuiteFn): void;
- function todo(fn?: SuiteFn): void;
+ function todo(name?: string, options?: TestOptions, fn?: SuiteFn): Promise<void>;
+ function todo(name?: string, fn?: SuiteFn): Promise<void>;
+ function todo(options?: TestOptions, fn?: SuiteFn): Promise<void>;
+ function todo(fn?: SuiteFn): Promise<void>;
/**
* Shorthand for marking a suite as `only`, same as `describe([name], { only: true }[, fn])`.
* @since v18.15.0
*/
- function only(name?: string, options?: TestOptions, fn?: SuiteFn): void;
- function only(name?: string, fn?: SuiteFn): void;
- function only(options?: TestOptions, fn?: SuiteFn): void;
- function only(fn?: SuiteFn): void;
+ function only(name?: string, options?: TestOptions, fn?: SuiteFn): Promise<void>;
+ function only(name?: string, fn?: SuiteFn): Promise<void>;
+ function only(options?: TestOptions, fn?: SuiteFn): Promise<void>;
+ function only(fn?: SuiteFn): Promise<void>;
}
/**
@@ -196,31 +197,31 @@
* @since v18.6.0, v16.17.0
*/
- function it(name?: string, options?: TestOptions, fn?: TestFn): void;
- function it(name?: string, fn?: TestFn): void;
- function it(options?: TestOptions, fn?: TestFn): void;
- function it(fn?: TestFn): void;
+ function it(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
+ function it(name?: string, fn?: TestFn): Promise<void>;
+ function it(options?: TestOptions, fn?: TestFn): Promise<void>;
+ function it(fn?: TestFn): Promise<void>;
namespace it {
/**
* Shorthand for skipping a test, same as `it([name], { skip: true }[, fn])`.
*/
- function skip(name?: string, options?: TestOptions, fn?: TestFn): void;
- function skip(name?: string, fn?: TestFn): void;
- function skip(options?: TestOptions, fn?: TestFn): void;
- function skip(fn?: TestFn): void;
+ function skip(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
+ function skip(name?: string, fn?: TestFn): Promise<void>;
+ function skip(options?: TestOptions, fn?: TestFn): Promise<void>;
+ function skip(fn?: TestFn): Promise<void>;
/**
* Shorthand for marking a test as `TODO`, same as `it([name], { todo: true }[, fn])`.
*/
- function todo(name?: string, options?: TestOptions, fn?: TestFn): void;
- function todo(name?: string, fn?: TestFn): void;
- function todo(options?: TestOptions, fn?: TestFn): void;
- function todo(fn?: TestFn): void;
+ function todo(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
+ function todo(name?: string, fn?: TestFn): Promise<void>;
+ function todo(options?: TestOptions, fn?: TestFn): Promise<void>;
+ function todo(fn?: TestFn): Promise<void>;
/**
* Shorthand for marking a test as `only`, same as `it([name], { only: true }[, fn])`.
* @since v18.15.0
*/
- function only(name?: string, options?: TestOptions, fn?: TestFn): void;
- function only(name?: string, fn?: TestFn): void;
- function only(options?: TestOptions, fn?: TestFn): void;
- function only(fn?: TestFn): void;
+ function only(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
+ function only(name?: string, fn?: TestFn): Promise<void>;
+ function only(options?: TestOptions, fn?: TestFn): Promise<void>;
+ function only(fn?: TestFn): Promise<void>;
}
/**
@@ -228,24 +229,24 @@
* @since v20.2.0
*/
- function skip(name?: string, options?: TestOptions, fn?: TestFn): void;
- function skip(name?: string, fn?: TestFn): void;
- function skip(options?: TestOptions, fn?: TestFn): void;
- function skip(fn?: TestFn): void;
+ function skip(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
+ function skip(name?: string, fn?: TestFn): Promise<void>;
+ function skip(options?: TestOptions, fn?: TestFn): Promise<void>;
+ function skip(fn?: TestFn): Promise<void>;
/**
* Shorthand for marking a test as `TODO`, same as `test([name], { todo: true }[, fn])`.
* @since v20.2.0
*/
- function todo(name?: string, options?: TestOptions, fn?: TestFn): void;
- function todo(name?: string, fn?: TestFn): void;
- function todo(options?: TestOptions, fn?: TestFn): void;
- function todo(fn?: TestFn): void;
+ function todo(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
+ function todo(name?: string, fn?: TestFn): Promise<void>;
+ function todo(options?: TestOptions, fn?: TestFn): Promise<void>;
+ function todo(fn?: TestFn): Promise<void>;
/**
* Shorthand for marking a test as `only`, same as `test([name], { only: true }[, fn])`.
* @since v20.2.0
*/
- function only(name?: string, options?: TestOptions, fn?: TestFn): void;
- function only(name?: string, fn?: TestFn): void;
- function only(options?: TestOptions, fn?: TestFn): void;
- function only(fn?: TestFn): void;
+ function only(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
+ function only(name?: string, fn?: TestFn): Promise<void>;
+ function only(options?: TestOptions, fn?: TestFn): Promise<void>;
+ function only(fn?: TestFn): Promise<void>;
/**
* The type of a function under test. The first argument to this function is a
@@ -253,10 +254,19 @@
* the second argument.
*/
- type TestFn = (t: TestContext, done: (result?: any) => void) => any;
+ type TestFn = (t: TestContext, done: (result?: any) => void) => void | Promise<void>;
/**
* The type of a function under Suite.
- * If the test uses callbacks, the callback function is passed as an argument
*/
- type SuiteFn = (done: (result?: any) => void) => void;
+ type SuiteFn = (s: SuiteContext) => void | Promise<void>;
+ interface TestShard {
+ /**
+ * A positive integer between 1 and `<total>` that specifies the index of the shard to run.
+ */
+ index: number;
+ /**
+ * A positive integer that specifies the total number of shards to split the test files to.
+ */
+ total: number;
+ }
interface RunOptions {
/**
@@ -296,5 +306,28 @@
*/
testNamePatterns?: string | RegExp | string[] | RegExp[];
+ /**
+ * A function that accepts the TestsStream instance and can be used to setup listeners before any tests are run.
+ */
+ setup?: (root: unknown) => void | Promise<void>;
+ /**
+ * Whether to run in watch mode or not.
+ * @default false
+ */
+ watch?: boolean | undefined;
+ /**
+ * Running tests in a specific shard.
+ * @default undefined
+ */
+ shard?: TestShard | undefined;
}
+ class Test extends AsyncResource {
+ concurrency: number;
+ nesting: number;
+ only: boolean;
+ reporter: TestsStream;
+ runOnlySubtests: boolean;
+ testNumber: number;
+ timeout: number | null;
+ }
/**
* A successful call to `run()` method will return a new `TestsStream` object, streaming a series of events representing the execution of the tests.`TestsStream` will emit events, in the
@@ -487,4 +520,22 @@
readonly mock: MockTracker;
}
+ /**
+ * An instance of `SuiteContext` is passed to each suite function in order to
+ * interact with the test runner. However, the `SuiteContext` constructor is not
+ * exposed as part of the API.
+ * @since v18.7.0, v16.17.0
+ */
+ class SuiteContext {
+ /**
+ * The name of the suite.
+ * @since v18.8.0, v16.18.0
+ */
+ readonly name: string;
+ /**
+ * Can be used to abort test subtasks when the test has been aborted.
+ * @since v18.7.0, v16.17.0
+ */
+ readonly signal: AbortSignal;
+ }
interface TestOptions {
/**
@@ -598,5 +649,5 @@
* second argument.
*/
- type HookFn = (done: (result?: any) => void) => any;
+ type HookFn = (s: SuiteContext, done: (result?: any) => void) => any;
/**
* Configuration options for hooks.
@@ -822,4 +873,5 @@
*/
restoreAll(): void;
+ timers: MockTimers;
}
const mock: MockTracker;
@@ -965,4 +1017,218 @@
restore(): void;
}
+ type Timer = 'setInterval' | 'clearInterval' | 'setTimeout' | 'clearTimeout';
+ /**
+ * Mocking timers is a technique commonly used in software testing to simulate and
+ * control the behavior of timers, such as `setInterval` and `setTimeout`,
+ * without actually waiting for the specified time intervals.
+ *
+ * The `MockTracker` provides a top-level `timers` export
+ * which is a `MockTimers` instance.
+ * @since v20.4.0
+ * @experimental
+ */
+ class MockTimers {
+ /**
+ * Enables timer mocking for the specified timers.
+ *
+ * **Note:** When you enable mocking for a specific timer, its associated
+ * clear function will also be implicitly mocked.
+ *
+ * Example usage:
+ *
+ * ```js
+ * import { mock } from 'node:test';
+ * mock.timers.enable(['setInterval']);
+ * ```
+ *
+ * ```js
+ * const { mock } = require('node:test');
+ * mock.timers.enable(['setInterval']);
+ * ```
+ *
+ * The above example enables mocking for the `setInterval` timer and
+ * implicitly mocks the `clearInterval` function. Only the `setInterval`and `clearInterval` functions from `node:timers`,`node:timers/promises`, and`globalThis` will be mocked.
+ *
+ * Alternatively, if you call `mock.timers.enable()` without any parameters:
+ *
+ * All timers (`'setInterval'`, `'clearInterval'`, `'setTimeout'`, and `'clearTimeout'`)
+ * will be mocked. The `setInterval`, `clearInterval`, `setTimeout`, and `clearTimeout`functions from `node:timers`, `node:timers/promises`,
+ * and `globalThis` will be mocked.
+ * @since v20.4.0
+ */
+ enable(timers?: Timer[]): void;
+ /**
+ * This function restores the default behavior of all mocks that were previously
+ * created by this `MockTimers` instance and disassociates the mocks
+ * from the `MockTracker` instance.
+ *
+ * **Note:** After each test completes, this function is called on
+ * the test context's `MockTracker`.
+ *
+ * ```js
+ * import { mock } from 'node:test';
+ * mock.timers.reset();
+ * ```
+ *
+ * ```js
+ * const { mock } = require('node:test');
+ * mock.timers.reset();
+ * ```
+ * @since v20.4.0
+ */
+ reset(): void;
+ /**
+ * Advances time for all mocked timers.
+ *
+ * **Note:** This diverges from how `setTimeout` in Node.js behaves and accepts
+ * only positive numbers. In Node.js, `setTimeout` with negative numbers is
+ * only supported for web compatibility reasons.
+ *
+ * The following example mocks a `setTimeout` function and
+ * by using `.tick` advances in
+ * time triggering all pending timers.
+ *
+ * ```js
+ * import assert from 'node:assert';
+ * import { test } from 'node:test';
+ *
+ * test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
+ * const fn = context.mock.fn();
+ *
+ * context.mock.timers.enable(['setTimeout']);
+ *
+ * setTimeout(fn, 9999);
+ *
+ * assert.strictEqual(fn.mock.callCount(), 0);
+ *
+ * // Advance in time
+ * context.mock.timers.tick(9999);
+ *
+ * assert.strictEqual(fn.mock.callCount(), 1);
+ * });
+ * ```
+ *
+ * ```js
+ * const assert = require('node:assert');
+ * const { test } = require('node:test');
+ *
+ * test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
+ * const fn = context.mock.fn();
+ * context.mock.timers.enable(['setTimeout']);
+ *
+ * setTimeout(fn, 9999);
+ * assert.strictEqual(fn.mock.callCount(), 0);
+ *
+ * // Advance in time
+ * context.mock.timers.tick(9999);
+ *
+ * assert.strictEqual(fn.mock.callCount(), 1);
+ * });
+ * ```
+ *
+ * Alternativelly, the `.tick` function can be called many times
+ *
+ * ```js
+ * import assert from 'node:assert';
+ * import { test } from 'node:test';
+ *
+ * test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
+ * const fn = context.mock.fn();
+ * context.mock.timers.enable(['setTimeout']);
+ * const nineSecs = 9000;
+ * setTimeout(fn, nineSecs);
+ *
+ * const twoSeconds = 3000;
+ * context.mock.timers.tick(twoSeconds);
+ * context.mock.timers.tick(twoSeconds);
+ * context.mock.timers.tick(twoSeconds);
+ *
+ * assert.strictEqual(fn.mock.callCount(), 1);
+ * });
+ * ```
+ *
+ * ```js
+ * const assert = require('node:assert');
+ * const { test } = require('node:test');
+ *
+ * test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
+ * const fn = context.mock.fn();
+ * context.mock.timers.enable(['setTimeout']);
+ * const nineSecs = 9000;
+ * setTimeout(fn, nineSecs);
+ *
+ * const twoSeconds = 3000;
+ * context.mock.timers.tick(twoSeconds);
+ * context.mock.timers.tick(twoSeconds);
+ * context.mock.timers.tick(twoSeconds);
+ *
+ * assert.strictEqual(fn.mock.callCount(), 1);
+ * });
+ * ```
+ * @since v20.4.0
+ */
+ tick(milliseconds: number): void;
+ /**
+ * Triggers all pending mocked timers immediately.
+ *
+ * The example below triggers all pending timers immediately,
+ * causing them to execute without any delay.
+ *
+ * ```js
+ * import assert from 'node:assert';
+ * import { test } from 'node:test';
+ *
+ * test('runAll functions following the given order', (context) => {
+ * context.mock.timers.enable(['setTimeout']);
+ * const results = [];
+ * setTimeout(() => results.push(1), 9999);
+ *
+ * // Notice that if both timers have the same timeout,
+ * // the order of execution is guaranteed
+ * setTimeout(() => results.push(3), 8888);
+ * setTimeout(() => results.push(2), 8888);
+ *
+ * assert.deepStrictEqual(results, []);
+ *
+ * context.mock.timers.runAll();
+ *
+ * assert.deepStrictEqual(results, [3, 2, 1]);
+ * });
+ * ```
+ *
+ * ```js
+ * const assert = require('node:assert');
+ * const { test } = require('node:test');
+ *
+ * test('runAll functions following the given order', (context) => {
+ * context.mock.timers.enable(['setTimeout']);
+ * const results = [];
+ * setTimeout(() => results.push(1), 9999);
+ *
+ * // Notice that if both timers have the same timeout,
+ * // the order of execution is guaranteed
+ * setTimeout(() => results.push(3), 8888);
+ * setTimeout(() => results.push(2), 8888);
+ *
+ * assert.deepStrictEqual(results, []);
+ *
+ * context.mock.timers.runAll();
+ *
+ * assert.deepStrictEqual(results, [3, 2, 1]);
+ * });
+ * ```
+ *
+ * **Note:** The `runAll()` function is specifically designed for
+ * triggering timers in the context of timer mocking.
+ * It does not have any effect on real-time system
+ * clocks or actual timers outside of the mocking environment.
+ * @since v20.4.0
+ */
+ runAll(): void;
+ /**
+ * Calls {@link MockTimers.reset()}.
+ */
+ [Symbol.dispose](): void;
+ }
export { test as default, run, test, describe, it, before, after, beforeEach, afterEach, mock, skip, only, todo };
}
@@ -990,9 +1256,14 @@
* The duration of the test in milliseconds.
*/
- duration: number;
+ duration_ms: number;
/**
* The error thrown by the test.
*/
error: Error;
+ /**
+ * The type of the test, used to denote whether this is a suite.
+ * @since 20.0.0, 19.9.0, 18.17.0
+ */
+ type?: 'suite';
};
/**
@@ -1029,5 +1300,10 @@
* The duration of the test in milliseconds.
*/
- duration: number;
+ duration_ms: number;
+ /**
+ * The type of the test, used to denote whether this is a suite.
+ * @since 20.0.0, 19.9.0, 18.17.0
+ */
+ type?: 'suite';
};
/**
@@ -1104,4 +1380,32 @@
message: string;
}
+interface TestEnqueue {
+ /**
+ * The test name
+ */
+ name: string;
+ /**
+ * The path of the test file, undefined if test is not ran through a file.
+ */
+ file?: string;
+ /**
+ * The nesting level of the test.
+ */
+ nesting: number;
+}
+interface TestDequeue {
+ /**
+ * The test name
+ */
+ name: string;
+ /**
+ * The path of the test file, undefined if test is not ran through a file.
+ */
+ file?: string;
+ /**
+ * The nesting level of the test.
+ */
+ nesting: number;
+}
/**
@@ -1132,5 +1436,8 @@
| { type: 'test:start', data: TestStart }
| { type: 'test:stderr', data: TestStderr }
- | { type: 'test:stdout', data: TestStdout };
+ | { type: 'test:stdout', data: TestStdout }
+ | { type: 'test:enqueue', data: TestEnqueue }
+ | { type: 'test:dequeue', data: TestDequeue }
+ | { type: 'test:watch:drained' };
type TestEventGenerator = AsyncGenerator<TestEvent, void>;
@@ -1140,5 +1447,5 @@
* and each failing test is represented by a `X`.
*/
- function dot(source: TestEventGenerator): AsyncGenerator<"\n" | "." | "X", void>;
+ function dot(source: TestEventGenerator): AsyncGenerator<'\n' | '.' | 'X', void>;
/**
* The `tap` reporter outputs the test results in the [TAP](https://testanything.org/) format.
@@ -1151,4 +1458,4 @@
constructor();
}
- export { dot, tap, Spec as spec };
+ export { dot, tap, Spec as spec, TestEvent };
}
diff --git a/ts4.8/timers.d.ts b/ts4.8/timers.d.ts
index v20.3.3..v20.5.7 100777
--- a/ts4.8/timers.d.ts
+++ b/ts4.8/timers.d.ts
@@ -69,4 +69,9 @@
hasRef(): boolean;
_onImmediate: Function; // to distinguish it from the Timeout class
+ /**
+ * Cancels the immediate. This is similar to calling `clearImmediate()`.
+ * @since v20.5.0
+ */
+ [Symbol.dispose](): void;
}
/**
@@ -115,4 +120,9 @@
refresh(): this;
[Symbol.toPrimitive](): number;
+ /**
+ * Cancels the timeout.
+ * @since v20.5.0
+ */
+ [Symbol.dispose](): void;
}
}
@@ -164,8 +174,8 @@
* @return for use with {@link clearInterval}
*/
- function setInterval<TArgs extends any[]>(callback: (...args: TArgs) => void, ms?: number, ...args: TArgs): NodeJS.Timer;
+ function setInterval<TArgs extends any[]>(callback: (...args: TArgs) => void, ms?: number, ...args: TArgs): NodeJS.Timeout;
// util.promisify no rest args compability
// tslint:disable-next-line void-return
- function setInterval(callback: (args: void) => void, ms?: number): NodeJS.Timer;
+ function setInterval(callback: (args: void) => void, ms?: number): NodeJS.Timeout;
namespace setInterval {
const __promisify__: typeof setIntervalPromise;
diff --git a/ts4.8/tls.d.ts b/ts4.8/tls.d.ts
index v20.3.3..v20.5.7 100777
--- a/ts4.8/tls.d.ts
+++ b/ts4.8/tls.d.ts
@@ -730,4 +730,15 @@
interface SecureContextOptions {
/**
+ * If set, this will be called when a client opens a connection using the ALPN extension.
+ * One argument will be passed to the callback: an object containing `servername` and `protocols` fields,
+ * respectively containing the server name from the SNI extension (if any) and an array of
+ * ALPN protocol name strings. The callback must return either one of the strings listed in `protocols`,
+ * which will be returned to the client as the selected ALPN protocol, or `undefined`,
+ * to reject the connection with a fatal alert. If a string is returned that does not match one of
+ * the client's ALPN protocols, an error will be thrown.
+ * This option cannot be used with the `ALPNProtocols` option, and setting both options will throw an error.
+ */
+ ALPNCallback?: ((arg: { servername: string; protocols: string[] }) => string | undefined) | undefined;
+ /**
* Optionally override the trusted CA certificates. Default is to trust
* the well-known CAs curated by Mozilla. Mozilla's CAs are completely
diff --git a/ts4.8/url.d.ts b/ts4.8/url.d.ts
index v20.3.3..v20.5.7 100777
--- a/ts4.8/url.d.ts
+++ b/ts4.8/url.d.ts
@@ -395,4 +395,18 @@
*/
static revokeObjectURL(objectUrl: string): void;
+ /**
+ * Checks if an `input` relative to the `base` can be parsed to a `URL`.
+ *
+ * ```js
+ * const isValid = URL.canParse('/foo', 'https://example.org/'); // true
+ *
+ * const isNotValid = URL.canParse('/foo'); // false
+ * ```
+ * @since v19.9.0
+ * @param input The absolute or relative input URL to parse. If `input` is relative, then `base` is required. If `input` is absolute, the `base` is ignored. If `input` is not a string, it is
+ * `converted to a string` first.
+ * @param base The base URL to resolve against if the `input` is not absolute. If `base` is not a string, it is `converted to a string` first.
+ */
+ static canParse(input: string, base?: string): boolean;
constructor(input: string, base?: string | URL);
/**
diff --git a/ts4.8/util.d.ts b/ts4.8/util.d.ts
index v20.3.3..v20.5.7 100777
--- a/ts4.8/util.d.ts
+++ b/ts4.8/util.d.ts
@@ -1461,30 +1461,70 @@
/**
* Gets and sets the type portion of the MIME.
+ *
+ * ```js
+ * import { MIMEType } from 'node:util';
+ *
+ * const myMIME = new MIMEType('text/javascript');
+ * console.log(myMIME.type);
+ * // Prints: text
+ * myMIME.type = 'application';
+ * console.log(myMIME.type);
+ * // Prints: application
+ * console.log(String(myMIME));
+ * // Prints: application/javascript
+ * ```
*/
type: string;
/**
* Gets and sets the subtype portion of the MIME.
+ *
+ * ```js
+ * import { MIMEType } from 'node:util';
+ *
+ * const myMIME = new MIMEType('text/ecmascript');
+ * console.log(myMIME.subtype);
+ * // Prints: ecmascript
+ * myMIME.subtype = 'javascript';
+ * console.log(myMIME.subtype);
+ * // Prints: javascript
+ * console.log(String(myMIME));
+ * // Prints: text/javascript
+ * ```
*/
subtype: string;
/**
- * Gets the essence of the MIME.
+ * Gets the essence of the MIME. This property is read only.
+ * Use `mime.type` or `mime.subtype` to alter the MIME.
*
- * Use `mime.type` or `mime.subtype` to alter the MIME.
+ * ```js
+ * import { MIMEType } from 'node:util';
+ *
+ * const myMIME = new MIMEType('text/javascript;key=value');
+ * console.log(myMIME.essence);
+ * // Prints: text/javascript
+ * myMIME.type = 'application';
+ * console.log(myMIME.essence);
+ * // Prints: application/javascript
+ * console.log(String(myMIME));
+ * // Prints: application/javascript;key=value
+ * ```
*/
readonly essence: string;
/**
- * Gets the `MIMEParams` object representing the parameters of the MIME.
+ * Gets the `MIMEParams` object representing the
+ * parameters of the MIME. This property is read-only. See `MIMEParams` documentation for details.
*/
readonly params: MIMEParams;
/**
- * Returns the serialized MIME.
+ * The `toString()` method on the `MIMEType` object returns the serialized MIME.
*
- * Because of the need for standard compliance, this method
- * does not allow users to customize the serialization process of the MIME.
+ * Because of the need for standard compliance, this method does not allow users
+ * to customize the serialization process of the MIME.
*/
toString(): string;
}
/**
- * @since v18.13.0
+ * The `MIMEParams` API provides read and write access to the parameters of a`MIMEType`.
+ * @since v19.1.0, v18.13.0
*/
export class MIMEParams {
@@ -1495,9 +1535,12 @@
/**
* Returns an iterator over each of the name-value pairs in the parameters.
+ * Each item of the iterator is a JavaScript `Array`. The first item of the array
+ * is the `name`, the second item of the array is the `value`.
*/
entries(): IterableIterator<[string, string]>;
/**
- * Returns the value of the first name-value pair whose name is `name`.
- * If there are no such pairs, `null` is returned.
+ * Returns the value of the first name-value pair whose name is `name`. If there
+ * are no such pairs, `null` is returned.
+ * @return or `null` if there is no name-value pair with the given `name`.
*/
get(name: string): string | null;
@@ -1508,10 +1551,31 @@
/**
* Returns an iterator over the names of each name-value pair.
+ *
+ * ```js
+ * import { MIMEType } from 'node:util';
+ *
+ * const { params } = new MIMEType('text/plain;foo=0;bar=1');
+ * for (const name of params.keys()) {
+ * console.log(name);
+ * }
+ * // Prints:
+ * // foo
+ * // bar
+ * ```
*/
keys(): IterableIterator<string>;
/**
- * Sets the value in the `MIMEParams` object associated with `name` to `value`.
- * If there are any pre-existing name-value pairs whose names are `name`,
+ * Sets the value in the `MIMEParams` object associated with `name` to`value`. If there are any pre-existing name-value pairs whose names are `name`,
* set the first such pair's value to `value`.
+ *
+ * ```js
+ * import { MIMEType } from 'node:util';
+ *
+ * const { params } = new MIMEType('text/plain;foo=0;bar=1');
+ * params.set('foo', 'def');
+ * params.set('baz', 'xyz');
+ * console.log(params.toString());
+ * // Prints: foo=def&bar=1&baz=xyz
+ * ```
*/
set(name: string, value: string): void;
diff --git a/ts4.8/vm.d.ts b/ts4.8/vm.d.ts
index v20.3.3..v20.5.7 100777
--- a/ts4.8/vm.d.ts
+++ b/ts4.8/vm.d.ts
@@ -38,4 +38,5 @@
*/
declare module 'vm' {
+ import { ImportAssertions } from 'node:module';
interface Context extends NodeJS.Dict<any> {}
interface BaseOptions {
@@ -67,5 +68,5 @@
* If this option is not specified, calls to `import()` will reject with `ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`.
*/
- importModuleDynamically?: ((specifier: string, script: Script, importAssertions: Object) => Module) | undefined;
+ importModuleDynamically?: ((specifier: string, script: Script, importAssertions: ImportAssertions) => Module) | undefined;
}
interface RunningScriptOptions extends BaseOptions {
diff --git a/ts4.8/fs/promises.d.ts b/ts4.8/fs/promises.d.ts
index v20.3.3..v20.5.7 100777
--- a/ts4.8/fs/promises.d.ts
+++ b/ts4.8/fs/promises.d.ts
@@ -83,4 +83,11 @@
start?: number | undefined;
}
+ interface ReadableWebStreamOptions {
+ /**
+ * Whether to open a normal or a `'bytes'` stream.
+ * @since v20.0.0
+ */
+ type?: 'bytes' | undefined;
+ }
// TODO: Add `EventEmitter` close
interface FileHandle {
@@ -241,5 +248,5 @@
* @experimental
*/
- readableWebStream(): ReadableStream;
+ readableWebStream(options?: ReadableWebStreamOptions): ReadableStream;
/**
* Asynchronously reads the entire contents of a file.
@@ -450,4 +457,9 @@
*/
close(): Promise<void>;
+ /**
+ * An alias for {@link FileHandle.close()}.
+ * @since v20.4.0
+ */
+ [Symbol.asyncDispose](): Promise<void>;
}
const constants: typeof fsConstants;
@@ -721,5 +733,6 @@
* exist, `'file'` will be used. Windows junction points require the destination
* path to be absolute. When using `'junction'`, the `target` argument will
- * automatically be normalized to absolute path.
+ * automatically be normalized to absolute path. Junction points on NTFS volumes
+ * can only point to directories.
* @since v10.0.0
* @param [type='null']
Command detailsnpm diff --diff=@types/node@20.3.3 --diff=@types/node@20.5.7 --diff-unified=2 See also the Reported by ybiquitous/npm-diff-action@v1.4.1 (Node.js 18.17.1 and npm 10.0.0) |
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 20.3.3 to 20.5.7. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) --- updated-dependencies: - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
dependabot
bot
force-pushed
the
dependabot/npm_and_yarn/types/node-20.5.7
branch
from
September 1, 2023 06:15
824b5c5
to
5bfa35f
Compare
github-actions
bot
deleted the
dependabot/npm_and_yarn/types/node-20.5.7
branch
September 1, 2023 06:16
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
dependencies
Pull requests that update a dependency file
javascript
Pull requests that update Javascript code
0 participants
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Rebasing might not happen immediately, so don't worry if this takes some time.
Note: if you make any changes to this PR yourself, they will take precedence over the rebase.
Bumps @types/node from 20.3.3 to 20.5.7.
Commits
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebase
will rebase this PR@dependabot recreate
will recreate this PR, overwriting any edits that have been made to it@dependabot merge
will merge this PR after your CI passes on it@dependabot squash and merge
will squash and merge this PR after your CI passes on it@dependabot cancel merge
will cancel a previously requested merge and block automerging@dependabot reopen
will reopen this PR if it is closed@dependabot close
will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually@dependabot show <dependency name> ignore conditions
will show all of the ignore conditions of the specified dependency@dependabot ignore this major version
will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this minor version
will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependency
will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)