From df5fcaf4b6ccb0dbf77f363be060a29e9cac0769 Mon Sep 17 00:00:00 2001 From: Adam Thompson-Sharpe Date: Mon, 20 Oct 2025 19:15:33 -0400 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#73830=20[chai]?= =?UTF-8?q?=20Add=20proper=20`AssertionError`=20export=20by=20@MysteryBlok?= =?UTF-8?q?Hed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/bardjs/index.d.ts | 2 +- types/chai/chai-tests.ts | 10 ++++- types/chai/index.d.ts | 88 +++++++++++++++++++--------------------- types/chai/package.json | 3 +- 4 files changed, 54 insertions(+), 49 deletions(-) diff --git a/types/bardjs/index.d.ts b/types/bardjs/index.d.ts index 177a336ab86eb3..f77cb86b9c0cbd 100644 --- a/types/bardjs/index.d.ts +++ b/types/bardjs/index.d.ts @@ -47,7 +47,7 @@ declare namespace bard { /** * Assert a failure in mocha, without condition */ - function assertFail(message: string): Chai.AssertionError; + function assertFail(message: string): Chai.AssertionError; /** * Prepare ngMocked module definition that makes real $http and $q calls diff --git a/types/chai/chai-tests.ts b/types/chai/chai-tests.ts index 013791b40f6c7c..15a46234dc49bc 100644 --- a/types/chai/chai-tests.ts +++ b/types/chai/chai-tests.ts @@ -1,5 +1,5 @@ /// -import { assert, config, expect, Should, use, util } from "chai"; +import { assert, AssertionError, config, expect, Should, use, util } from "chai"; const should = Should(); @@ -2242,3 +2242,11 @@ function configuringDeepEqual() { }); }; } + +function assertionErrorChecks() { + // @ts-expect-error Missing message + new AssertionError(); + new AssertionError("foo"); + new AssertionError("foo", {}); + new AssertionError("foo", {}, () => {}); +} diff --git a/types/chai/index.d.ts b/types/chai/index.d.ts index 67b59e26c38c68..4fed6b906ef0d5 100644 --- a/types/chai/index.d.ts +++ b/types/chai/index.d.ts @@ -1,26 +1,27 @@ import deepEqual = require("deep-eql"); +import { AssertionError as ImportedAssertionError } from "assertion-error"; declare global { namespace Chai { - type Message = string | (() => string); - type ObjectProperty = string | symbol | number; + export type Message = string | (() => string); + export type ObjectProperty = string | symbol | number; - interface PathInfo { + export interface PathInfo { parent: object; name: string; value?: any; exists: boolean; } - interface Constructor { + export interface Constructor { new(...args: any[]): T; } - interface ErrorConstructor { + export interface ErrorConstructor { new(...args: any[]): Error; } - interface ChaiUtils { + export interface ChaiUtils { addChainableMethod( // object to define the method on, e.g. chai.Assertion.prototype ctx: object, @@ -76,9 +77,9 @@ declare global { eql: typeof deepEqual; } - type ChaiPlugin = (chai: ChaiStatic, utils: ChaiUtils) => void; + export type ChaiPlugin = (chai: ChaiStatic, utils: ChaiUtils) => void; - interface ChaiStatic { + export interface ChaiStatic { expect: ExpectStatic; should(): Should; /** @@ -103,7 +104,7 @@ declare global { } // chai.Assertion.prototype.assert arguments - type AssertionArgs = [ + export type AssertionArgs = [ any, // expression to be tested Message, // message or function that returns message to display if expression fails Message, // negatedMessage or function that returns negatedMessage to display if expression fails @@ -147,25 +148,25 @@ declare global { export type OperatorComparable = boolean | null | number | string | undefined | Date; - interface ShouldAssertion { + export interface ShouldAssertion { equal(value1: any, value2: any, message?: string): void; Throw: ShouldThrow; throw: ShouldThrow; exist(value: any, message?: string): void; } - interface Should extends ShouldAssertion { + export interface Should extends ShouldAssertion { not: ShouldAssertion; fail(message?: string): never; fail(actual: any, expected: any, message?: string, operator?: Operator): never; } - interface ShouldThrow { + export interface ShouldThrow { (actual: Function, expected?: string | RegExp, message?: string): void; (actual: Function, constructor: Error | Function, expected?: string | RegExp, message?: string): void; } - interface Assertion extends LanguageChains, NumericComparison, TypeComparison { + export interface Assertion extends LanguageChains, NumericComparison, TypeComparison { not: Assertion; deep: Deep; ordered: Ordered; @@ -231,7 +232,7 @@ declare global { oneOf: OneOf; } - interface LanguageChains { + export interface LanguageChains { to: Assertion; be: Assertion; been: Assertion; @@ -249,7 +250,7 @@ declare global { does: Assertion; } - interface NumericComparison { + export interface NumericComparison { above: NumberComparer; gt: NumberComparer; greaterThan: NumberComparer; @@ -266,25 +267,25 @@ declare global { within(start: Date, finish: Date, message?: string): Assertion; } - interface NumberComparer { + export interface NumberComparer { (value: number | Date, message?: string): Assertion; } - interface TypeComparison { + export interface TypeComparison { (type: string, message?: string): Assertion; instanceof: InstanceOf; instanceOf: InstanceOf; } - interface InstanceOf { + export interface InstanceOf { (constructor: any, message?: string): Assertion; } - interface CloseTo { + export interface CloseTo { (expected: number, delta: number, message?: string): Assertion; } - interface Nested { + export interface Nested { include: Include; includes: Include; contain: Include; @@ -293,7 +294,7 @@ declare global { members: Members; } - interface Own { + export interface Own { include: Include; includes: Include; contain: Include; @@ -301,7 +302,7 @@ declare global { property: Property; } - interface Deep extends KeyFilter { + export interface Deep extends KeyFilter { be: Assertion; equal: Equal; equals: Equal; @@ -317,38 +318,38 @@ declare global { own: Own; } - interface Ordered { + export interface Ordered { members: Members; } - interface KeyFilter { + export interface KeyFilter { keys: Keys; members: Members; } - interface Equal { + export interface Equal { (value: any, message?: string): Assertion; } - interface ContainSubset { + export interface ContainSubset { (expected: any): Assertion; } - interface Property { + export interface Property { (name: string | symbol, value: any, message?: string): Assertion; (name: string | symbol, message?: string): Assertion; } - interface OwnPropertyDescriptor { + export interface OwnPropertyDescriptor { (name: string | symbol, descriptor: PropertyDescriptor, message?: string): Assertion; (name: string | symbol, message?: string): Assertion; } - interface Length extends LanguageChains, NumericComparison { + export interface Length extends LanguageChains, NumericComparison { (length: number, message?: string): Assertion; } - interface Include { + export interface Include { (value: any, message?: string): Assertion; keys: Keys; deep: Deep; @@ -359,41 +360,41 @@ declare global { oneOf: OneOf; } - interface OneOf { + export interface OneOf { (list: readonly unknown[], message?: string): Assertion; } - interface Match { + export interface Match { (regexp: RegExp, message?: string): Assertion; } - interface Keys { + export interface Keys { (...keys: string[]): Assertion; (keys: readonly any[] | Object): Assertion; } - interface Throw { + export interface Throw { (expected?: string | RegExp, message?: string): Assertion; (constructor: Error | Function, expected?: string | RegExp, message?: string): Assertion; } - interface RespondTo { + export interface RespondTo { (method: string, message?: string): Assertion; } - interface Satisfy { + export interface Satisfy { (matcher: Function, message?: string): Assertion; } - interface Members { + export interface Members { (set: readonly any[], message?: string): Assertion; } - interface PropertyChange { + export interface PropertyChange { (object: Object, property?: string, message?: string): DeltaAssertion; } - interface DeltaAssertion extends Assertion { + export interface DeltaAssertion extends Assertion { by(delta: number, msg?: string): Assertion; } @@ -2128,13 +2129,7 @@ declare global { deepEqual: (expected: L, actual: R) => void; } - export class AssertionError { - constructor(message: string, _props?: any, ssf?: Function); - name: string; - message: string; - showDiff: boolean; - stack: string; - } + export type { ImportedAssertionError as AssertionError }; } } @@ -2143,6 +2138,7 @@ export function use(fn: Chai.ChaiPlugin): Chai.ChaiStatic; export const util: Chai.ChaiUtils; export const config: Chai.Config; export const Assertion: Chai.AssertionStatic; +export const AssertionError: typeof ImportedAssertionError; export function should(): Chai.Should; export function Should(): Chai.Should; export const assert: Chai.AssertStatic; diff --git a/types/chai/package.json b/types/chai/package.json index 551dc12c191109..768f6ecbe8953a 100644 --- a/types/chai/package.json +++ b/types/chai/package.json @@ -7,7 +7,8 @@ "http://chaijs.com/" ], "dependencies": { - "@types/deep-eql": "*" + "@types/deep-eql": "*", + "assertion-error": "^2.0.1" }, "devDependencies": { "@types/chai": "workspace:.", From da1e3fcd95c7b758e31fea36cbd00c1d00fd64b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9?= Date: Tue, 21 Oct 2025 00:38:46 +0100 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#73414=20node:?= =?UTF-8?q?=20specify=20non-shared=20array=20buffer=20views=20by=20@Renega?= =?UTF-8?q?de334?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/diffie-hellman/diffie-hellman-tests.ts | 16 +- types/fs-extra/test/fs-extra-tests.ts | 74 ++-- types/mz/test/zlib.test.ts | 18 +- types/node/buffer.buffer.d.ts | 9 + types/node/buffer.d.ts | 12 +- types/node/child_process.d.ts | 83 +++-- types/node/crypto.d.ts | 338 ++++++++++--------- types/node/dgram.d.ts | 17 +- types/node/fs.d.ts | 165 ++++----- types/node/fs/promises.d.ts | 60 ++-- types/node/globals.typedarray.d.ts | 19 ++ types/node/http.d.ts | 63 ++-- types/node/http2.d.ts | 51 +-- types/node/https.d.ts | 132 +++++--- types/node/net.d.ts | 13 +- types/node/os.d.ts | 5 +- types/node/process.d.ts | 3 +- types/node/sqlite.d.ts | 13 +- types/node/stream/consumers.d.ts | 4 +- types/node/string_decoder.d.ts | 4 +- types/node/test/buffer.ts | 4 +- types/node/test/child_process.ts | 90 ++--- types/node/test/crypto.ts | 30 +- types/node/test/dgram.ts | 4 +- types/node/test/fs.ts | 16 +- types/node/test/https.ts | 2 +- types/node/test/stream.ts | 2 +- types/node/test/vm.ts | 2 +- types/node/test/zlib.ts | 74 ++-- types/node/tls.d.ts | 152 +++++---- types/node/ts5.6/buffer.buffer.d.ts | 12 +- types/node/ts5.6/globals.typedarray.d.ts | 16 + types/node/url.d.ts | 4 +- types/node/util.d.ts | 2 +- types/node/v20/buffer.buffer.d.ts | 9 + types/node/v20/buffer.d.ts | 12 +- types/node/v20/child_process.d.ts | 83 +++-- types/node/v20/crypto.d.ts | 282 +++++++++------- types/node/v20/dgram.d.ts | 17 +- types/node/v20/fs.d.ts | 165 ++++----- types/node/v20/fs/promises.d.ts | 60 ++-- types/node/v20/globals.typedarray.d.ts | 17 + types/node/v20/http.d.ts | 63 ++-- types/node/v20/http2.d.ts | 51 +-- types/node/v20/https.d.ts | 132 +++++--- types/node/v20/net.d.ts | 13 +- types/node/v20/os.d.ts | 5 +- types/node/v20/process.d.ts | 3 +- types/node/v20/stream/consumers.d.ts | 4 +- types/node/v20/string_decoder.d.ts | 4 +- types/node/v20/test/buffer.ts | 4 +- types/node/v20/test/child_process.ts | 90 ++--- types/node/v20/test/crypto.ts | 28 +- types/node/v20/test/dgram.ts | 4 +- types/node/v20/test/fs.ts | 10 +- types/node/v20/test/https.ts | 2 +- types/node/v20/test/stream.ts | 2 +- types/node/v20/test/vm.ts | 2 +- types/node/v20/test/zlib.ts | 54 +-- types/node/v20/tls.d.ts | 152 +++++---- types/node/v20/ts5.6/buffer.buffer.d.ts | 12 +- types/node/v20/ts5.6/globals.typedarray.d.ts | 15 + types/node/v20/url.d.ts | 2 +- types/node/v20/util.d.ts | 2 +- types/node/v20/v8.d.ts | 7 +- types/node/v20/vm.d.ts | 7 +- types/node/v20/zlib.d.ts | 41 +-- types/node/v22/buffer.buffer.d.ts | 9 + types/node/v22/buffer.d.ts | 12 +- types/node/v22/child_process.d.ts | 83 +++-- types/node/v22/crypto.d.ts | 282 +++++++++------- types/node/v22/dgram.d.ts | 17 +- types/node/v22/fs.d.ts | 165 ++++----- types/node/v22/fs/promises.d.ts | 60 ++-- types/node/v22/globals.typedarray.d.ts | 17 + types/node/v22/http.d.ts | 63 ++-- types/node/v22/http2.d.ts | 51 +-- types/node/v22/https.d.ts | 132 +++++--- types/node/v22/net.d.ts | 13 +- types/node/v22/os.d.ts | 3 +- types/node/v22/process.d.ts | 3 +- types/node/v22/sqlite.d.ts | 13 +- types/node/v22/stream/consumers.d.ts | 4 +- types/node/v22/string_decoder.d.ts | 4 +- types/node/v22/test/buffer.ts | 4 +- types/node/v22/test/child_process.ts | 90 ++--- types/node/v22/test/crypto.ts | 20 +- types/node/v22/test/dgram.ts | 4 +- types/node/v22/test/fs.ts | 16 +- types/node/v22/test/https.ts | 2 +- types/node/v22/test/stream.ts | 2 +- types/node/v22/test/vm.ts | 2 +- types/node/v22/test/zlib.ts | 74 ++-- types/node/v22/tls.d.ts | 152 +++++---- types/node/v22/ts5.6/buffer.buffer.d.ts | 12 +- types/node/v22/ts5.6/globals.typedarray.d.ts | 15 + types/node/v22/url.d.ts | 4 +- types/node/v22/util.d.ts | 2 +- types/node/v22/v8.d.ts | 7 +- types/node/v22/vm.d.ts | 7 +- types/node/v22/zlib.d.ts | 49 +-- types/node/v8.d.ts | 7 +- types/node/vm.d.ts | 7 +- types/node/zlib.d.ts | 49 +-- types/randombytes/randombytes-tests.ts | 4 +- 105 files changed, 2480 insertions(+), 1843 deletions(-) diff --git a/types/diffie-hellman/diffie-hellman-tests.ts b/types/diffie-hellman/diffie-hellman-tests.ts index b7a8c1b410eca3..ff855a886e3cc6 100644 --- a/types/diffie-hellman/diffie-hellman-tests.ts +++ b/types/diffie-hellman/diffie-hellman-tests.ts @@ -1,32 +1,32 @@ import * as dh from "diffie-hellman"; const dh1 = dh.getDiffieHellman("modp1"); -// $ExpectType DiffieHellmanGroup || Pick +// $ExpectType DiffieHellmanGroup dh1; -// $ExpectType Buffer || Buffer +// $ExpectType Buffer || NonSharedBuffer dh1.generateKeys(); // $ExpectType string dh1.generateKeys("hex"); -// $ExpectType Buffer || Buffer +// $ExpectType Buffer || NonSharedBuffer dh1.getPrime(); // $ExpectType string dh1.getPrime("hex"); -// $ExpectType Buffer || Buffer +// $ExpectType Buffer || NonSharedBuffer dh1.getGenerator(); // $ExpectType string dh1.getGenerator("hex"); const pk = dh1.getPublicKey(); -// $ExpectType Buffer || Buffer +// $ExpectType Buffer || NonSharedBuffer pk; // $ExpectType string dh1.getPublicKey("hex"); -// $ExpectType Buffer || Buffer +// $ExpectType Buffer || NonSharedBuffer dh1.getPrivateKey(); // $ExpectType string dh1.getPrivateKey("hex"); -// $ExpectType Buffer || Buffer +// $ExpectType Buffer || NonSharedBuffer dh1.computeSecret(pk); -// $ExpectType Buffer || Buffer +// $ExpectType Buffer || NonSharedBuffer dh1.computeSecret(pk.toString("hex"), "hex"); // $ExpectType string dh1.computeSecret(pk.toString("hex"), "hex", "hex"); diff --git a/types/fs-extra/test/fs-extra-tests.ts b/types/fs-extra/test/fs-extra-tests.ts index 414db6642f467f..01eb4e4a54ac75 100644 --- a/types/fs-extra/test/fs-extra-tests.ts +++ b/types/fs-extra/test/fs-extra-tests.ts @@ -833,8 +833,8 @@ fs.opendir(path, { encoding: "utf-8" }, (err, dir) => { fs.readdir(path); // $ExpectType Promise fs.readdir(path, "utf-8"); // $ExpectType Promise -fs.readdir(path, "buffer"); // $ExpectType Promise || Promise[]> -fs.readdir(path, { encoding: "buffer" }); // $ExpectType Promise || Promise[]> +fs.readdir(path, "buffer"); // $ExpectType Promise || Promise +fs.readdir(path, { encoding: "buffer" }); // $ExpectType Promise || Promise fs.readdir(path, { encoding: "utf-8" }); // $ExpectType Promise fs.readdir(path, { withFileTypes: true }); // $ExpectType Promise[]> // $ExpectType void @@ -850,12 +850,12 @@ fs.readdir(path, "utf-8", (err, files) => { // $ExpectType void fs.readdir(path, "buffer", (err, files) => { err; // $ExpectType ErrnoException | null - files; // $ExpectType Buffer[] || Buffer[] + files; // $ExpectType Buffer[] || NonSharedBuffer[] }); // $ExpectType void fs.readdir(path, { encoding: "buffer" }, (err, files) => { err; // $ExpectType ErrnoException | null - files; // $ExpectType Buffer[] || Buffer[] + files; // $ExpectType Buffer[] || NonSharedBuffer[] }); // $ExpectType void fs.readdir(path, { encoding: "utf-8" }, (err, files) => { @@ -868,14 +868,14 @@ fs.readdir(path, { withFileTypes: true }, (err, files) => { files; // $ExpectType Dirent[] }); -fs.readFile(path); // $ExpectType Promise || Promise> || Promise +fs.readFile(path); // $ExpectType Promise || Promise fs.readFile(path, "utf-8"); // $ExpectType Promise fs.readFile(path, { encoding: "utf-8" }); // $ExpectType Promise -fs.readFile(path, { flag: "r" }); // $ExpectType Promise || Promise> || Promise +fs.readFile(path, { flag: "r" }); // $ExpectType Promise || Promise // $ExpectType void fs.readFile(path, (err, data) => { err; // $ExpectType ErrnoException | null - data; // $ExpectType Buffer || Buffer || NonSharedBuffer + data; // $ExpectType Buffer || NonSharedBuffer }); // $ExpectType void fs.readFile(path, "utf-8", (err, data) => { @@ -890,19 +890,19 @@ fs.readFile(path, { encoding: "utf-8" }, (err, data) => { // $ExpectType void fs.readFile(path, { flag: "r" }, (err, data) => { err; // $ExpectType ErrnoException | null - data; // $ExpectType Buffer || Buffer || NonSharedBuffer + data; // $ExpectType Buffer || NonSharedBuffer }); // $ExpectType void fs.readFile(path, { signal: new AbortController().signal }, (err, data) => { err; // $ExpectType ErrnoException | null - data; // $ExpectType Buffer || Buffer || NonSharedBuffer + data; // $ExpectType Buffer || NonSharedBuffer }); fs.readlink(path); // $ExpectType Promise fs.readlink(path, "utf-8"); // $ExpectType Promise -fs.readlink(path, "buffer"); // $ExpectType Promise || Promise> +fs.readlink(path, "buffer"); // $ExpectType Promise || Promise fs.readlink(path, { encoding: "utf-8" }); // $ExpectType Promise -fs.readlink(path, { encoding: "buffer" }); // $ExpectType Promise || Promise> +fs.readlink(path, { encoding: "buffer" }); // $ExpectType Promise || Promise // $ExpectType void fs.readlink(path, err => { err; // $ExpectType ErrnoException | null @@ -915,7 +915,7 @@ fs.readlink(path, "utf-8", (err, data) => { // $ExpectType void fs.readlink(path, "buffer", (err, data) => { err; // $ExpectType ErrnoException | null - data; // $ExpectType Buffer || Buffer + data; // $ExpectType Buffer || NonSharedBuffer }); // $ExpectType void fs.readlink(path, { encoding: "utf-8" }, (err, data) => { @@ -925,14 +925,14 @@ fs.readlink(path, { encoding: "utf-8" }, (err, data) => { // $ExpectType void fs.readlink(path, { encoding: "buffer" }, (err, data) => { err; // $ExpectType ErrnoException | null - data; // $ExpectType Buffer || Buffer + data; // $ExpectType Buffer || NonSharedBuffer }); fs.realpath(path); // $ExpectType Promise fs.realpath(path, "utf-8"); // $ExpectType Promise -fs.realpath(path, "buffer"); // $ExpectType Promise || Promise> +fs.realpath(path, "buffer"); // $ExpectType Promise || Promise fs.realpath(path, { encoding: "utf-8" }); // $ExpectType Promise -fs.realpath(path, { encoding: "buffer" }); // $ExpectType Promise || Promise> +fs.realpath(path, { encoding: "buffer" }); // $ExpectType Promise || Promise fs.realpath(path, { encoding: null }); // $ExpectType Promise // $ExpectType void fs.realpath(path, (err, resolved) => { @@ -947,7 +947,7 @@ fs.realpath(path, "utf-8", (err, resolved) => { // $ExpectType void fs.realpath(path, "buffer", (err, resolved) => { err; // $ExpectType ErrnoException | null - resolved; // $ExpectType Buffer || Buffer + resolved; // $ExpectType Buffer || NonSharedBuffer }); // $ExpectType void fs.realpath(path, { encoding: "utf-8" }, (err, resolved) => { @@ -957,7 +957,7 @@ fs.realpath(path, { encoding: "utf-8" }, (err, resolved) => { // $ExpectType void fs.realpath(path, { encoding: "buffer" }, (err, resolved) => { err; // $ExpectType ErrnoException | null - resolved; // $ExpectType Buffer || Buffer + resolved; // $ExpectType Buffer || NonSharedBuffer }); // $ExpectType void fs.realpath(path, { encoding: null }, (err, resolved) => { @@ -983,7 +983,7 @@ fs.realpath.native(path, "utf-8", (err, resolved) => { // $ExpectType void fs.realpath.native(path, "buffer", (err, resolved) => { err; // $ExpectType ErrnoException | null - resolved; // $ExpectType Buffer || Buffer + resolved; // $ExpectType Buffer || NonSharedBuffer }); // $ExpectType void fs.realpath.native(path, { encoding: "utf-8" }, (err, resolved) => { @@ -993,7 +993,7 @@ fs.realpath.native(path, { encoding: "utf-8" }, (err, resolved) => { // $ExpectType void fs.realpath.native(path, { encoding: "buffer" }, (err, resolved) => { err; // $ExpectType ErrnoException | null - resolved; // $ExpectType Buffer || Buffer + resolved; // $ExpectType Buffer || NonSharedBuffer }); // $ExpectType void fs.realpath.native(path, { encoding: null }, (err, resolved) => { @@ -1176,42 +1176,42 @@ fs.writeFile(path, Buffer.from("i am foo"), { signal: new AbortController().sign err; // $ExpectType ErrnoException | null }); -fs.read(fd); // $ExpectType Promise<{ bytesRead: number; buffer: ArrayBufferView; }> || Promise<{ bytesRead: number; buffer: ArrayBufferView; }> -fs.read(fd, { offset: 1 }); // $ExpectType Promise<{ bytesRead: number; buffer: ArrayBufferView; }> || Promise<{ bytesRead: number; buffer: ArrayBufferView; }> -fs.read(fd, { length: 10 }); // $ExpectType Promise<{ bytesRead: number; buffer: ArrayBufferView; }> || Promise<{ bytesRead: number; buffer: ArrayBufferView; }> -fs.read(fd, { position: 1 }); // $ExpectType Promise<{ bytesRead: number; buffer: ArrayBufferView; }> || Promise<{ bytesRead: number; buffer: ArrayBufferView; }> -fs.read(fd, { position: BigInt(1) }); // $ExpectType Promise<{ bytesRead: number; buffer: ArrayBufferView; }> || Promise<{ bytesRead: number; buffer: ArrayBufferView; }> +fs.read(fd); // $ExpectType Promise<{ bytesRead: number; buffer: Buffer; }> || Promise<{ bytesRead: number; buffer: NonSharedBuffer; }> +fs.read(fd, { offset: 1 }); // $ExpectType Promise<{ bytesRead: number; buffer: Buffer; }> || Promise<{ bytesRead: number; buffer: NonSharedBuffer; }> +fs.read(fd, { length: 10 }); // $ExpectType Promise<{ bytesRead: number; buffer: Buffer; }> || Promise<{ bytesRead: number; buffer: NonSharedBuffer; }> +fs.read(fd, { position: 1 }); // $ExpectType Promise<{ bytesRead: number; buffer: Buffer; }> || Promise<{ bytesRead: number; buffer: NonSharedBuffer; }> +fs.read(fd, { position: BigInt(1) }); // $ExpectType Promise<{ bytesRead: number; buffer: Buffer; }> || Promise<{ bytesRead: number; buffer: NonSharedBuffer; }> fs.read(fd, { buffer: Buffer.alloc(10) }); // $ExpectType Promise<{ bytesRead: number; buffer: Buffer; }> || Promise<{ bytesRead: number; buffer: Buffer; }> fs.read(0, Buffer.from(""), 0, 0, null); // $ExpectType Promise<{ bytesRead: number; buffer: Buffer; }> || Promise<{ bytesRead: number; buffer: Buffer; }> // $ExpectType void fs.read(fd, (err, bytesRead, buffer) => { err; // $ExpectType ErrnoException | null bytesRead; // $ExpectType number - buffer; // $ExpectType ArrayBufferView || ArrayBufferView + buffer; // $ExpectType Buffer || NonSharedBuffer }); // $ExpectType void fs.read(fd, { offset: 1 }, (err, bytesRead, buffer) => { err; // $ExpectType ErrnoException | null bytesRead; // $ExpectType number - buffer; // $ExpectType ArrayBufferView || ArrayBufferView + buffer; // $ExpectType Buffer || NonSharedBuffer }); // $ExpectType void fs.read(fd, { length: 10 }, (err, bytesRead, buffer) => { err; // $ExpectType ErrnoException | null bytesRead; // $ExpectType number - buffer; // $ExpectType ArrayBufferView || ArrayBufferView + buffer; // $ExpectType Buffer || NonSharedBuffer }); // $ExpectType void fs.read(fd, { position: 1 }, (err, bytesRead, buffer) => { err; // $ExpectType ErrnoException | null bytesRead; // $ExpectType number - buffer; // $ExpectType ArrayBufferView || ArrayBufferView + buffer; // $ExpectType Buffer || NonSharedBuffer }); // $ExpectType void fs.read(fd, { position: BigInt(1) }, (err, bytesRead, buffer) => { err; // $ExpectType ErrnoException | null bytesRead; // $ExpectType number - buffer; // $ExpectType ArrayBufferView || ArrayBufferView + buffer; // $ExpectType Buffer || NonSharedBuffer }); // $ExpectType void fs.read(fd, { buffer: Buffer.alloc(10) }, (err, bytesRead, buffer) => { @@ -1226,19 +1226,19 @@ fs.read(fd, Buffer.from(""), 0, 0, null, (err, bytesRead, buffer) => { buffer; // $ExpectType Buffer || Buffer }); -fs.readv(fd, [Buffer.alloc(10)] as const); // $ExpectType Promise -fs.readv(fd, [Buffer.alloc(10)] as const, 1); // $ExpectType Promise +fs.readv(fd, [Buffer.alloc(10)] as const); // $ExpectType Promise> || Promise]>> +fs.readv(fd, [Buffer.alloc(10)] as const, 1); // $ExpectType Promise> || Promise]>> // $ExpectType void fs.readv(fd, [Buffer.alloc(10)] as const, (err, bytesRead, buffers) => { err; // $ExpectType ErrnoException | null bytesRead; // $ExpectType number - buffers; // $ExpectType ArrayBufferView[] || ArrayBufferView[] + buffers; // $ExpectType readonly [Buffer] || readonly [Buffer] }); // $ExpectType void fs.readv(fd, [Buffer.alloc(10)] as const, 1, (err, bytesRead, buffers) => { err; // $ExpectType ErrnoException | null bytesRead; // $ExpectType number - buffers; // $ExpectType ArrayBufferView[] || ArrayBufferView[] + buffers; // $ExpectType readonly [Buffer] || readonly [Buffer] }); fs.write(fd, "foo"); // $ExpectType Promise<{ bytesWritten: number; buffer: string; }> @@ -1291,17 +1291,17 @@ fs.write(fd, Buffer.from("foo"), 0, 0, 1, (err, written, buffer) => { buffer; // $ExpectType Buffer || Buffer }); -fs.writev(fd, [Buffer.alloc(10)] as const); // $ExpectType Promise -fs.writev(fd, [Buffer.alloc(10)] as const, 1); // $ExpectType Promise +fs.writev(fd, [Buffer.alloc(10)] as const); // $ExpectType Promise> || Promise]>> +fs.writev(fd, [Buffer.alloc(10)] as const, 1); // $ExpectType Promise> || Promise]>> // $ExpectType void fs.writev(fd, [Buffer.alloc(10)] as const, (err, bytesWritten, buffers) => { err; // $ExpectType ErrnoException | null bytesWritten; // $ExpectType number - buffers; // $ExpectType ArrayBufferView[] || ArrayBufferView[] + buffers; // $ExpectType readonly [Buffer] || readonly [Buffer] }); // $ExpectType void fs.writev(fd, [Buffer.alloc(10)] as const, 1, (err, bytesWritten, buffers) => { err; // $ExpectType ErrnoException | null bytesWritten; // $ExpectType number - buffers; // $ExpectType ArrayBufferView[] || ArrayBufferView[] + buffers; // $ExpectType readonly [Buffer] || readonly [Buffer] }); diff --git a/types/mz/test/zlib.test.ts b/types/mz/test/zlib.test.ts index 8da9373db326fd..c485e4f136f5e3 100644 --- a/types/mz/test/zlib.test.ts +++ b/types/mz/test/zlib.test.ts @@ -5,53 +5,53 @@ const buf = Buffer.alloc(Math.random()); zlib.brotliCompress(buf); // $ExpectType Promise || Promise> zlib.brotliCompress(buf, (err, res) => { err; // $ExpectType Error | null - res; // $ExpectType Buffer || Buffer + res; // $ExpectType Buffer || NonSharedBuffer }); zlib.brotliDecompress(buf); // $ExpectType Promise || Promise> zlib.brotliDecompress(buf, (err, res) => { err; // $ExpectType Error | null - res; // $ExpectType Buffer || Buffer + res; // $ExpectType Buffer || NonSharedBuffer }); zlib.deflate(buf); // $ExpectType Promise || Promise> zlib.deflate(buf, (err, res) => { err; // $ExpectType Error | null - res; // $ExpectType Buffer || Buffer + res; // $ExpectType Buffer || NonSharedBuffer }); zlib.deflateRaw(buf); // $ExpectType Promise || Promise> zlib.deflateRaw(buf, (err, res) => { err; // $ExpectType Error | null - res; // $ExpectType Buffer || Buffer + res; // $ExpectType Buffer || NonSharedBuffer }); zlib.gzip(buf); // $ExpectType Promise || Promise> zlib.gzip(buf, (err, res) => { err; // $ExpectType Error | null - res; // $ExpectType Buffer || Buffer + res; // $ExpectType Buffer || NonSharedBuffer }); zlib.gunzip(buf); // $ExpectType Promise || Promise> zlib.gunzip(buf, (err, res) => { err; // $ExpectType Error | null - res; // $ExpectType Buffer || Buffer + res; // $ExpectType Buffer || NonSharedBuffer }); zlib.inflate(buf); // $ExpectType Promise || Promise> zlib.inflate(buf, (err, res) => { err; // $ExpectType Error | null - res; // $ExpectType Buffer || Buffer + res; // $ExpectType Buffer || NonSharedBuffer }); zlib.inflateRaw(buf); // $ExpectType Promise || Promise> zlib.inflateRaw(buf, (err, res) => { err; // $ExpectType Error | null - res; // $ExpectType Buffer || Buffer + res; // $ExpectType Buffer || NonSharedBuffer }); zlib.unzip(buf); // $ExpectType Promise || Promise> zlib.unzip(buf, (err, res) => { err; // $ExpectType Error | null - res; // $ExpectType Buffer || Buffer + res; // $ExpectType Buffer || NonSharedBuffer }); diff --git a/types/node/buffer.buffer.d.ts b/types/node/buffer.buffer.d.ts index b22f83a291507d..8823deeb4b6754 100644 --- a/types/node/buffer.buffer.d.ts +++ b/types/node/buffer.buffer.d.ts @@ -451,7 +451,16 @@ declare module "buffer" { */ subarray(start?: number, end?: number): Buffer; } + // TODO: remove globals in future version + /** + * @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports + * TypeScript versions earlier than 5.7. + */ type NonSharedBuffer = Buffer; + /** + * @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports + * TypeScript versions earlier than 5.7. + */ type AllowSharedBuffer = Buffer; } /** @deprecated Use `Buffer.allocUnsafeSlow()` instead. */ diff --git a/types/node/buffer.d.ts b/types/node/buffer.d.ts index 49636f3962e25d..9a62ccf97737d6 100644 --- a/types/node/buffer.d.ts +++ b/types/node/buffer.d.ts @@ -59,7 +59,7 @@ declare module "buffer" { * @since v19.4.0, v18.14.0 * @param input The input to validate. */ - export function isUtf8(input: Buffer | ArrayBuffer | NodeJS.TypedArray): boolean; + export function isUtf8(input: ArrayBuffer | NodeJS.TypedArray): boolean; /** * This function returns `true` if `input` contains only valid ASCII-encoded data, * including the case in which `input` is empty. @@ -68,7 +68,7 @@ declare module "buffer" { * @since v19.6.0, v18.15.0 * @param input The input to validate. */ - export function isAscii(input: Buffer | ArrayBuffer | NodeJS.TypedArray): boolean; + export function isAscii(input: ArrayBuffer | NodeJS.TypedArray): boolean; export let INSPECT_MAX_BYTES: number; export const kMaxLength: number; export const kStringMaxLength: number; @@ -113,7 +113,11 @@ declare module "buffer" { * @param fromEnc The current encoding. * @param toEnc To target encoding. */ - export function transcode(source: Uint8Array, fromEnc: TranscodeEncoding, toEnc: TranscodeEncoding): Buffer; + export function transcode( + source: Uint8Array, + fromEnc: TranscodeEncoding, + toEnc: TranscodeEncoding, + ): NonSharedBuffer; /** * Resolves a `'blob:nodedata:...'` an associated `Blob` object registered using * a prior call to `URL.createObjectURL()`. @@ -330,7 +334,7 @@ declare module "buffer" { * @return The number of bytes contained within `string`. */ byteLength( - string: string | Buffer | NodeJS.ArrayBufferView | ArrayBuffer | SharedArrayBuffer, + string: string | NodeJS.ArrayBufferView | ArrayBufferLike, encoding?: BufferEncoding, ): number; /** diff --git a/types/node/child_process.d.ts b/types/node/child_process.d.ts index bf66a081636811..ecad7d8ee45766 100644 --- a/types/node/child_process.d.ts +++ b/types/node/child_process.d.ts @@ -66,6 +66,7 @@ * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/child_process.js) */ declare module "child_process" { + import { NonSharedBuffer } from "node:buffer"; import { Abortable, EventEmitter } from "node:events"; import * as dgram from "node:dgram"; import * as net from "node:net"; @@ -1001,7 +1002,7 @@ declare module "child_process" { function exec( command: string, options: ExecOptionsWithBufferEncoding, - callback?: (error: ExecException | null, stdout: Buffer, stderr: Buffer) => void, + callback?: (error: ExecException | null, stdout: NonSharedBuffer, stderr: NonSharedBuffer) => void, ): ChildProcess; // `options` with well-known or absent `encoding` means stdout/stderr are definitely `string`. function exec( @@ -1013,7 +1014,11 @@ declare module "child_process" { function exec( command: string, options: ExecOptions | undefined | null, - callback?: (error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void, + callback?: ( + error: ExecException | null, + stdout: string | NonSharedBuffer, + stderr: string | NonSharedBuffer, + ) => void, ): ChildProcess; interface PromiseWithChild extends Promise { child: ChildProcess; @@ -1027,8 +1032,8 @@ declare module "child_process" { command: string, options: ExecOptionsWithBufferEncoding, ): PromiseWithChild<{ - stdout: Buffer; - stderr: Buffer; + stdout: NonSharedBuffer; + stderr: NonSharedBuffer; }>; function __promisify__( command: string, @@ -1041,8 +1046,8 @@ declare module "child_process" { command: string, options: ExecOptions | undefined | null, ): PromiseWithChild<{ - stdout: string | Buffer; - stderr: string | Buffer; + stdout: string | NonSharedBuffer; + stderr: string | NonSharedBuffer; }>; } interface ExecFileOptions extends CommonOptions, Abortable { @@ -1144,13 +1149,13 @@ declare module "child_process" { function execFile( file: string, options: ExecFileOptionsWithBufferEncoding, - callback?: (error: ExecFileException | null, stdout: Buffer, stderr: Buffer) => void, + callback?: (error: ExecFileException | null, stdout: NonSharedBuffer, stderr: NonSharedBuffer) => void, ): ChildProcess; function execFile( file: string, args: readonly string[] | undefined | null, options: ExecFileOptionsWithBufferEncoding, - callback?: (error: ExecFileException | null, stdout: Buffer, stderr: Buffer) => void, + callback?: (error: ExecFileException | null, stdout: NonSharedBuffer, stderr: NonSharedBuffer) => void, ): ChildProcess; // `options` with well-known or absent `encoding` means stdout/stderr are definitely `string`. function execFile( @@ -1169,7 +1174,11 @@ declare module "child_process" { file: string, options: ExecFileOptions | undefined | null, callback: - | ((error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void) + | (( + error: ExecFileException | null, + stdout: string | NonSharedBuffer, + stderr: string | NonSharedBuffer, + ) => void) | undefined | null, ): ChildProcess; @@ -1178,7 +1187,11 @@ declare module "child_process" { args: readonly string[] | undefined | null, options: ExecFileOptions | undefined | null, callback: - | ((error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void) + | (( + error: ExecFileException | null, + stdout: string | NonSharedBuffer, + stderr: string | NonSharedBuffer, + ) => void) | undefined | null, ): ChildProcess; @@ -1198,16 +1211,16 @@ declare module "child_process" { file: string, options: ExecFileOptionsWithBufferEncoding, ): PromiseWithChild<{ - stdout: Buffer; - stderr: Buffer; + stdout: NonSharedBuffer; + stderr: NonSharedBuffer; }>; function __promisify__( file: string, args: readonly string[] | undefined | null, options: ExecFileOptionsWithBufferEncoding, ): PromiseWithChild<{ - stdout: Buffer; - stderr: Buffer; + stdout: NonSharedBuffer; + stderr: NonSharedBuffer; }>; function __promisify__( file: string, @@ -1228,16 +1241,16 @@ declare module "child_process" { file: string, options: ExecFileOptions | undefined | null, ): PromiseWithChild<{ - stdout: string | Buffer; - stderr: string | Buffer; + stdout: string | NonSharedBuffer; + stderr: string | NonSharedBuffer; }>; function __promisify__( file: string, args: readonly string[] | undefined | null, options: ExecFileOptions | undefined | null, ): PromiseWithChild<{ - stdout: string | Buffer; - stderr: string | Buffer; + stdout: string | NonSharedBuffer; + stderr: string | NonSharedBuffer; }>; } interface ForkOptions extends ProcessEnvOptions, MessagingOptions, Abortable { @@ -1343,11 +1356,11 @@ declare module "child_process" { * @param command The command to run. * @param args List of string arguments. */ - function spawnSync(command: string): SpawnSyncReturns; + function spawnSync(command: string): SpawnSyncReturns; function spawnSync(command: string, options: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns; - function spawnSync(command: string, options: SpawnSyncOptionsWithBufferEncoding): SpawnSyncReturns; - function spawnSync(command: string, options?: SpawnSyncOptions): SpawnSyncReturns; - function spawnSync(command: string, args: readonly string[]): SpawnSyncReturns; + function spawnSync(command: string, options: SpawnSyncOptionsWithBufferEncoding): SpawnSyncReturns; + function spawnSync(command: string, options?: SpawnSyncOptions): SpawnSyncReturns; + function spawnSync(command: string, args: readonly string[]): SpawnSyncReturns; function spawnSync( command: string, args: readonly string[], @@ -1357,12 +1370,12 @@ declare module "child_process" { command: string, args: readonly string[], options: SpawnSyncOptionsWithBufferEncoding, - ): SpawnSyncReturns; + ): SpawnSyncReturns; function spawnSync( command: string, args?: readonly string[], options?: SpawnSyncOptions, - ): SpawnSyncReturns; + ): SpawnSyncReturns; interface CommonExecOptions extends CommonOptions { input?: string | NodeJS.ArrayBufferView | undefined; /** @@ -1404,10 +1417,10 @@ declare module "child_process" { * @param command The command to run. * @return The stdout from the command. */ - function execSync(command: string): Buffer; + function execSync(command: string): NonSharedBuffer; function execSync(command: string, options: ExecSyncOptionsWithStringEncoding): string; - function execSync(command: string, options: ExecSyncOptionsWithBufferEncoding): Buffer; - function execSync(command: string, options?: ExecSyncOptions): string | Buffer; + function execSync(command: string, options: ExecSyncOptionsWithBufferEncoding): NonSharedBuffer; + function execSync(command: string, options?: ExecSyncOptions): string | NonSharedBuffer; interface ExecFileSyncOptions extends CommonExecOptions { shell?: boolean | string | undefined; } @@ -1437,11 +1450,11 @@ declare module "child_process" { * @param args List of string arguments. * @return The stdout from the command. */ - function execFileSync(file: string): Buffer; + function execFileSync(file: string): NonSharedBuffer; function execFileSync(file: string, options: ExecFileSyncOptionsWithStringEncoding): string; - function execFileSync(file: string, options: ExecFileSyncOptionsWithBufferEncoding): Buffer; - function execFileSync(file: string, options?: ExecFileSyncOptions): string | Buffer; - function execFileSync(file: string, args: readonly string[]): Buffer; + function execFileSync(file: string, options: ExecFileSyncOptionsWithBufferEncoding): NonSharedBuffer; + function execFileSync(file: string, options?: ExecFileSyncOptions): string | NonSharedBuffer; + function execFileSync(file: string, args: readonly string[]): NonSharedBuffer; function execFileSync( file: string, args: readonly string[], @@ -1451,8 +1464,12 @@ declare module "child_process" { file: string, args: readonly string[], options: ExecFileSyncOptionsWithBufferEncoding, - ): Buffer; - function execFileSync(file: string, args?: readonly string[], options?: ExecFileSyncOptions): string | Buffer; + ): NonSharedBuffer; + function execFileSync( + file: string, + args?: readonly string[], + options?: ExecFileSyncOptions, + ): string | NonSharedBuffer; } declare module "node:child_process" { export * from "child_process"; diff --git a/types/node/crypto.d.ts b/types/node/crypto.d.ts index e429849b2fce42..d975cafc383cc1 100644 --- a/types/node/crypto.d.ts +++ b/types/node/crypto.d.ts @@ -17,6 +17,7 @@ * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/crypto.js) */ declare module "crypto" { + import { NonSharedBuffer } from "node:buffer"; import * as stream from "node:stream"; import { PeerCertificate } from "node:tls"; /** @@ -44,7 +45,7 @@ declare module "crypto" { * @param encoding The `encoding` of the `spkac` string. * @return The challenge component of the `spkac` data structure, which includes a public key and a challenge. */ - static exportChallenge(spkac: BinaryLike): Buffer; + static exportChallenge(spkac: BinaryLike): NonSharedBuffer; /** * ```js * const { Certificate } = await import('node:crypto'); @@ -57,7 +58,7 @@ declare module "crypto" { * @param encoding The `encoding` of the `spkac` string. * @return The public key component of the `spkac` data structure, which includes a public key and a challenge. */ - static exportPublicKey(spkac: BinaryLike, encoding?: string): Buffer; + static exportPublicKey(spkac: BinaryLike, encoding?: string): NonSharedBuffer; /** * ```js * import { Buffer } from 'node:buffer'; @@ -78,7 +79,7 @@ declare module "crypto" { * @returns The challenge component of the `spkac` data structure, * which includes a public key and a challenge. */ - exportChallenge(spkac: BinaryLike): Buffer; + exportChallenge(spkac: BinaryLike): NonSharedBuffer; /** * @deprecated * @param spkac @@ -86,7 +87,7 @@ declare module "crypto" { * @returns The public key component of the `spkac` data structure, * which includes a public key and a challenge. */ - exportPublicKey(spkac: BinaryLike, encoding?: string): Buffer; + exportPublicKey(spkac: BinaryLike, encoding?: string): NonSharedBuffer; /** * @deprecated * @param spkac @@ -402,7 +403,7 @@ declare module "crypto" { * @since v0.1.92 * @param encoding The `encoding` of the return value. */ - digest(): Buffer; + digest(): NonSharedBuffer; digest(encoding: BinaryToTextEncoding): string; } /** @@ -496,7 +497,7 @@ declare module "crypto" { * @since v0.1.94 * @param encoding The `encoding` of the return value. */ - digest(): Buffer; + digest(): NonSharedBuffer; digest(encoding: BinaryToTextEncoding): string; } type KeyObjectType = "secret" | "public" | "private"; @@ -636,8 +637,8 @@ declare module "crypto" { * PKCS#1 and SEC1 encryption. * @since v11.6.0 */ - export(options: KeyExportOptions<"pem">): string | Buffer; - export(options?: KeyExportOptions<"der">): Buffer; + export(options: KeyExportOptions<"pem">): string | NonSharedBuffer; + export(options?: KeyExportOptions<"der">): NonSharedBuffer; export(options?: JwkKeyExportOptions): JsonWebKey; /** * Returns `true` or `false` depending on whether the keys have exactly the same @@ -886,8 +887,8 @@ declare module "crypto" { * @param inputEncoding The `encoding` of the data. * @param outputEncoding The `encoding` of the return value. */ - update(data: BinaryLike): Buffer; - update(data: string, inputEncoding: Encoding): Buffer; + update(data: BinaryLike): NonSharedBuffer; + update(data: string, inputEncoding: Encoding): NonSharedBuffer; update(data: NodeJS.ArrayBufferView, inputEncoding: undefined, outputEncoding: Encoding): string; update(data: string, inputEncoding: Encoding | undefined, outputEncoding: Encoding): string; /** @@ -898,7 +899,7 @@ declare module "crypto" { * @param outputEncoding The `encoding` of the return value. * @return Any remaining enciphered contents. If `outputEncoding` is specified, a string is returned. If an `outputEncoding` is not provided, a {@link Buffer} is returned. */ - final(): Buffer; + final(): NonSharedBuffer; final(outputEncoding: BufferEncoding): string; /** * When using block encryption algorithms, the `Cipheriv` class will automatically @@ -924,7 +925,7 @@ declare module "crypto" { plaintextLength: number; }, ): this; - getAuthTag(): Buffer; + getAuthTag(): NonSharedBuffer; } interface CipherGCM extends Cipheriv { setAAD( @@ -933,7 +934,7 @@ declare module "crypto" { plaintextLength: number; }, ): this; - getAuthTag(): Buffer; + getAuthTag(): NonSharedBuffer; } interface CipherOCB extends Cipheriv { setAAD( @@ -942,7 +943,7 @@ declare module "crypto" { plaintextLength: number; }, ): this; - getAuthTag(): Buffer; + getAuthTag(): NonSharedBuffer; } interface CipherChaCha20Poly1305 extends Cipheriv { setAAD( @@ -951,7 +952,7 @@ declare module "crypto" { plaintextLength: number; }, ): this; - getAuthTag(): Buffer; + getAuthTag(): NonSharedBuffer; } /** * Creates and returns a `Decipheriv` object that uses the given `algorithm`, `key` and initialization vector (`iv`). @@ -1136,8 +1137,8 @@ declare module "crypto" { * @param inputEncoding The `encoding` of the `data` string. * @param outputEncoding The `encoding` of the return value. */ - update(data: NodeJS.ArrayBufferView): Buffer; - update(data: string, inputEncoding: Encoding): Buffer; + update(data: NodeJS.ArrayBufferView): NonSharedBuffer; + update(data: string, inputEncoding: Encoding): NonSharedBuffer; update(data: NodeJS.ArrayBufferView, inputEncoding: undefined, outputEncoding: Encoding): string; update(data: string, inputEncoding: Encoding | undefined, outputEncoding: Encoding): string; /** @@ -1148,7 +1149,7 @@ declare module "crypto" { * @param outputEncoding The `encoding` of the return value. * @return Any remaining deciphered contents. If `outputEncoding` is specified, a string is returned. If an `outputEncoding` is not provided, a {@link Buffer} is returned. */ - final(): Buffer; + final(): NonSharedBuffer; final(outputEncoding: BufferEncoding): string; /** * When data has been encrypted without standard block padding, calling `decipher.setAutoPadding(false)` will disable automatic padding to prevent `decipher.final()` from checking for and @@ -1422,7 +1423,7 @@ declare module "crypto" { * called. Multiple calls to `sign.sign()` will result in an error being thrown. * @since v0.1.92 */ - sign(privateKey: KeyLike | SignKeyObjectInput | SignPrivateKeyInput | SignJsonWebKeyInput): Buffer; + sign(privateKey: KeyLike | SignKeyObjectInput | SignPrivateKeyInput | SignJsonWebKeyInput): NonSharedBuffer; sign( privateKey: KeyLike | SignKeyObjectInput | SignPrivateKeyInput | SignJsonWebKeyInput, outputFormat: BinaryToTextEncoding, @@ -1581,7 +1582,7 @@ declare module "crypto" { * @since v0.5.0 * @param encoding The `encoding` of the return value. */ - generateKeys(): Buffer; + generateKeys(): NonSharedBuffer; generateKeys(encoding: BinaryToTextEncoding): string; /** * Computes the shared secret using `otherPublicKey` as the other @@ -1596,8 +1597,16 @@ declare module "crypto" { * @param inputEncoding The `encoding` of an `otherPublicKey` string. * @param outputEncoding The `encoding` of the return value. */ - computeSecret(otherPublicKey: NodeJS.ArrayBufferView, inputEncoding?: null, outputEncoding?: null): Buffer; - computeSecret(otherPublicKey: string, inputEncoding: BinaryToTextEncoding, outputEncoding?: null): Buffer; + computeSecret( + otherPublicKey: NodeJS.ArrayBufferView, + inputEncoding?: null, + outputEncoding?: null, + ): NonSharedBuffer; + computeSecret( + otherPublicKey: string, + inputEncoding: BinaryToTextEncoding, + outputEncoding?: null, + ): NonSharedBuffer; computeSecret( otherPublicKey: NodeJS.ArrayBufferView, inputEncoding: null, @@ -1615,7 +1624,7 @@ declare module "crypto" { * @since v0.5.0 * @param encoding The `encoding` of the return value. */ - getPrime(): Buffer; + getPrime(): NonSharedBuffer; getPrime(encoding: BinaryToTextEncoding): string; /** * Returns the Diffie-Hellman generator in the specified `encoding`. @@ -1624,7 +1633,7 @@ declare module "crypto" { * @since v0.5.0 * @param encoding The `encoding` of the return value. */ - getGenerator(): Buffer; + getGenerator(): NonSharedBuffer; getGenerator(encoding: BinaryToTextEncoding): string; /** * Returns the Diffie-Hellman public key in the specified `encoding`. @@ -1633,7 +1642,7 @@ declare module "crypto" { * @since v0.5.0 * @param encoding The `encoding` of the return value. */ - getPublicKey(): Buffer; + getPublicKey(): NonSharedBuffer; getPublicKey(encoding: BinaryToTextEncoding): string; /** * Returns the Diffie-Hellman private key in the specified `encoding`. @@ -1642,7 +1651,7 @@ declare module "crypto" { * @since v0.5.0 * @param encoding The `encoding` of the return value. */ - getPrivateKey(): Buffer; + getPrivateKey(): NonSharedBuffer; getPrivateKey(encoding: BinaryToTextEncoding): string; /** * Sets the Diffie-Hellman public key. If the `encoding` argument is provided, `publicKey` is expected @@ -1786,7 +1795,7 @@ declare module "crypto" { iterations: number, keylen: number, digest: string, - callback: (err: Error | null, derivedKey: Buffer) => void, + callback: (err: Error | null, derivedKey: NonSharedBuffer) => void, ): void; /** * Provides a synchronous Password-Based Key Derivation Function 2 (PBKDF2) @@ -1823,7 +1832,7 @@ declare module "crypto" { iterations: number, keylen: number, digest: string, - ): Buffer; + ): NonSharedBuffer; /** * Generates cryptographically strong pseudorandom data. The `size` argument * is a number indicating the number of bytes to generate. @@ -1876,10 +1885,10 @@ declare module "crypto" { * @param size The number of bytes to generate. The `size` must not be larger than `2**31 - 1`. * @return if the `callback` function is not provided. */ - function randomBytes(size: number): Buffer; - function randomBytes(size: number, callback: (err: Error | null, buf: Buffer) => void): void; - function pseudoRandomBytes(size: number): Buffer; - function pseudoRandomBytes(size: number, callback: (err: Error | null, buf: Buffer) => void): void; + function randomBytes(size: number): NonSharedBuffer; + function randomBytes(size: number, callback: (err: Error | null, buf: NonSharedBuffer) => void): void; + function pseudoRandomBytes(size: number): NonSharedBuffer; + function pseudoRandomBytes(size: number, callback: (err: Error | null, buf: NonSharedBuffer) => void): void; /** * Return a random integer `n` such that `min <= n < max`. This * implementation avoids [modulo bias](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#Modulo_bias). @@ -2109,14 +2118,14 @@ declare module "crypto" { password: BinaryLike, salt: BinaryLike, keylen: number, - callback: (err: Error | null, derivedKey: Buffer) => void, + callback: (err: Error | null, derivedKey: NonSharedBuffer) => void, ): void; function scrypt( password: BinaryLike, salt: BinaryLike, keylen: number, options: ScryptOptions, - callback: (err: Error | null, derivedKey: Buffer) => void, + callback: (err: Error | null, derivedKey: NonSharedBuffer) => void, ): void; /** * Provides a synchronous [scrypt](https://en.wikipedia.org/wiki/Scrypt) implementation. Scrypt is a password-based @@ -2148,7 +2157,12 @@ declare module "crypto" { * ``` * @since v10.5.0 */ - function scryptSync(password: BinaryLike, salt: BinaryLike, keylen: number, options?: ScryptOptions): Buffer; + function scryptSync( + password: BinaryLike, + salt: BinaryLike, + keylen: number, + options?: ScryptOptions, + ): NonSharedBuffer; interface RsaPublicKey { key: KeyLike; padding?: number | undefined; @@ -2177,7 +2191,7 @@ declare module "crypto" { function publicEncrypt( key: RsaPublicKey | RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView | string, - ): Buffer; + ): NonSharedBuffer; /** * Decrypts `buffer` with `key`.`buffer` was previously encrypted using * the corresponding private key, for example using {@link privateEncrypt}. @@ -2192,7 +2206,7 @@ declare module "crypto" { function publicDecrypt( key: RsaPublicKey | RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView | string, - ): Buffer; + ): NonSharedBuffer; /** * Decrypts `buffer` with `privateKey`. `buffer` was previously encrypted using * the corresponding public key, for example using {@link publicEncrypt}. @@ -2201,7 +2215,10 @@ declare module "crypto" { * object, the `padding` property can be passed. Otherwise, this function uses `RSA_PKCS1_OAEP_PADDING`. * @since v0.11.14 */ - function privateDecrypt(privateKey: RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView | string): Buffer; + function privateDecrypt( + privateKey: RsaPrivateKey | KeyLike, + buffer: NodeJS.ArrayBufferView | string, + ): NonSharedBuffer; /** * Encrypts `buffer` with `privateKey`. The returned data can be decrypted using * the corresponding public key, for example using {@link publicDecrypt}. @@ -2210,7 +2227,10 @@ declare module "crypto" { * object, the `padding` property can be passed. Otherwise, this function uses `RSA_PKCS1_PADDING`. * @since v1.1.0 */ - function privateEncrypt(privateKey: RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView | string): Buffer; + function privateEncrypt( + privateKey: RsaPrivateKey | KeyLike, + buffer: NodeJS.ArrayBufferView | string, + ): NonSharedBuffer; /** * ```js * const { @@ -2339,7 +2359,7 @@ declare module "crypto" { inputEncoding?: BinaryToTextEncoding, outputEncoding?: "latin1" | "hex" | "base64" | "base64url", format?: "uncompressed" | "compressed" | "hybrid", - ): Buffer | string; + ): NonSharedBuffer | string; /** * Generates private and public EC Diffie-Hellman key values, and returns * the public key in the specified `format` and `encoding`. This key should be @@ -2352,7 +2372,7 @@ declare module "crypto" { * @param encoding The `encoding` of the return value. * @param [format='uncompressed'] */ - generateKeys(): Buffer; + generateKeys(): NonSharedBuffer; generateKeys(encoding: BinaryToTextEncoding, format?: ECDHKeyFormat): string; /** * Computes the shared secret using `otherPublicKey` as the other @@ -2371,8 +2391,8 @@ declare module "crypto" { * @param inputEncoding The `encoding` of the `otherPublicKey` string. * @param outputEncoding The `encoding` of the return value. */ - computeSecret(otherPublicKey: NodeJS.ArrayBufferView): Buffer; - computeSecret(otherPublicKey: string, inputEncoding: BinaryToTextEncoding): Buffer; + computeSecret(otherPublicKey: NodeJS.ArrayBufferView): NonSharedBuffer; + computeSecret(otherPublicKey: string, inputEncoding: BinaryToTextEncoding): NonSharedBuffer; computeSecret(otherPublicKey: NodeJS.ArrayBufferView, outputEncoding: BinaryToTextEncoding): string; computeSecret( otherPublicKey: string, @@ -2386,7 +2406,7 @@ declare module "crypto" { * @param encoding The `encoding` of the return value. * @return The EC Diffie-Hellman in the specified `encoding`. */ - getPrivateKey(): Buffer; + getPrivateKey(): NonSharedBuffer; getPrivateKey(encoding: BinaryToTextEncoding): string; /** * The `format` argument specifies point encoding and can be `'compressed'` or `'uncompressed'`. If `format` is not specified the point will be returned in`'uncompressed'` format. @@ -2398,7 +2418,7 @@ declare module "crypto" { * @param [format='uncompressed'] * @return The EC Diffie-Hellman public key in the specified `encoding` and `format`. */ - getPublicKey(encoding?: null, format?: ECDHKeyFormat): Buffer; + getPublicKey(encoding?: null, format?: ECDHKeyFormat): NonSharedBuffer; getPublicKey(encoding: BinaryToTextEncoding, format?: ECDHKeyFormat): string; /** * Sets the EC Diffie-Hellman private key. @@ -2737,15 +2757,15 @@ declare module "crypto" { function generateKeyPairSync( type: "rsa", options: RSAKeyPairOptions<"pem", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "rsa", options: RSAKeyPairOptions<"der", "pem">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "rsa", options: RSAKeyPairOptions<"der", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync(type: "rsa", options: RSAKeyPairKeyObjectOptions): KeyPairKeyObjectResult; function generateKeyPairSync( type: "rsa-pss", @@ -2754,15 +2774,15 @@ declare module "crypto" { function generateKeyPairSync( type: "rsa-pss", options: RSAPSSKeyPairOptions<"pem", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "rsa-pss", options: RSAPSSKeyPairOptions<"der", "pem">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "rsa-pss", options: RSAPSSKeyPairOptions<"der", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync(type: "rsa-pss", options: RSAPSSKeyPairKeyObjectOptions): KeyPairKeyObjectResult; function generateKeyPairSync( type: "dsa", @@ -2771,15 +2791,15 @@ declare module "crypto" { function generateKeyPairSync( type: "dsa", options: DSAKeyPairOptions<"pem", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "dsa", options: DSAKeyPairOptions<"der", "pem">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "dsa", options: DSAKeyPairOptions<"der", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync(type: "dsa", options: DSAKeyPairKeyObjectOptions): KeyPairKeyObjectResult; function generateKeyPairSync( type: "ec", @@ -2788,15 +2808,15 @@ declare module "crypto" { function generateKeyPairSync( type: "ec", options: ECKeyPairOptions<"pem", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "ec", options: ECKeyPairOptions<"der", "pem">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "ec", options: ECKeyPairOptions<"der", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync(type: "ec", options: ECKeyPairKeyObjectOptions): KeyPairKeyObjectResult; function generateKeyPairSync( type: "ed25519", @@ -2805,15 +2825,15 @@ declare module "crypto" { function generateKeyPairSync( type: "ed25519", options: ED25519KeyPairOptions<"pem", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "ed25519", options: ED25519KeyPairOptions<"der", "pem">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "ed25519", options: ED25519KeyPairOptions<"der", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync(type: "ed25519", options?: ED25519KeyPairKeyObjectOptions): KeyPairKeyObjectResult; function generateKeyPairSync( type: "ed448", @@ -2822,15 +2842,15 @@ declare module "crypto" { function generateKeyPairSync( type: "ed448", options: ED448KeyPairOptions<"pem", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "ed448", options: ED448KeyPairOptions<"der", "pem">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "ed448", options: ED448KeyPairOptions<"der", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync(type: "ed448", options?: ED448KeyPairKeyObjectOptions): KeyPairKeyObjectResult; function generateKeyPairSync( type: "x25519", @@ -2839,15 +2859,15 @@ declare module "crypto" { function generateKeyPairSync( type: "x25519", options: X25519KeyPairOptions<"pem", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "x25519", options: X25519KeyPairOptions<"der", "pem">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "x25519", options: X25519KeyPairOptions<"der", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync(type: "x25519", options?: X25519KeyPairKeyObjectOptions): KeyPairKeyObjectResult; function generateKeyPairSync( type: "x448", @@ -2856,15 +2876,15 @@ declare module "crypto" { function generateKeyPairSync( type: "x448", options: X448KeyPairOptions<"pem", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "x448", options: X448KeyPairOptions<"der", "pem">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "x448", options: X448KeyPairOptions<"der", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync(type: "x448", options?: X448KeyPairKeyObjectOptions): KeyPairKeyObjectResult; function generateKeyPairSync( type: "ml-dsa-44" | "ml-dsa-65" | "ml-dsa-87", @@ -2873,15 +2893,15 @@ declare module "crypto" { function generateKeyPairSync( type: "ml-dsa-44" | "ml-dsa-65" | "ml-dsa-87", options: MLDSAKeyPairOptions<"pem", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "ml-dsa-44" | "ml-dsa-65" | "ml-dsa-87", options: MLDSAKeyPairOptions<"der", "pem">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "ml-dsa-44" | "ml-dsa-65" | "ml-dsa-87", options: MLDSAKeyPairOptions<"der", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "ml-dsa-44" | "ml-dsa-65" | "ml-dsa-87", options?: MLDSAKeyPairKeyObjectOptions, @@ -2893,15 +2913,15 @@ declare module "crypto" { function generateKeyPairSync( type: "ml-kem-1024" | "ml-kem-512" | "ml-kem-768", options: MLKEMKeyPairOptions<"pem", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "ml-kem-1024" | "ml-kem-512" | "ml-kem-768", options: MLKEMKeyPairOptions<"der", "pem">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "ml-kem-1024" | "ml-kem-512" | "ml-kem-768", options: MLKEMKeyPairOptions<"der", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "ml-kem-1024" | "ml-kem-512" | "ml-kem-768", options?: MLKEMKeyPairKeyObjectOptions, @@ -3034,17 +3054,17 @@ declare module "crypto" { function generateKeyPair( type: "rsa", options: RSAKeyPairOptions<"pem", "der">, - callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: string, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "rsa", options: RSAKeyPairOptions<"der", "pem">, - callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: string) => void, ): void; function generateKeyPair( type: "rsa", options: RSAKeyPairOptions<"der", "der">, - callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "rsa", @@ -3059,17 +3079,17 @@ declare module "crypto" { function generateKeyPair( type: "rsa-pss", options: RSAPSSKeyPairOptions<"pem", "der">, - callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: string, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "rsa-pss", options: RSAPSSKeyPairOptions<"der", "pem">, - callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: string) => void, ): void; function generateKeyPair( type: "rsa-pss", options: RSAPSSKeyPairOptions<"der", "der">, - callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "rsa-pss", @@ -3084,17 +3104,17 @@ declare module "crypto" { function generateKeyPair( type: "dsa", options: DSAKeyPairOptions<"pem", "der">, - callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: string, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "dsa", options: DSAKeyPairOptions<"der", "pem">, - callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: string) => void, ): void; function generateKeyPair( type: "dsa", options: DSAKeyPairOptions<"der", "der">, - callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "dsa", @@ -3109,17 +3129,17 @@ declare module "crypto" { function generateKeyPair( type: "ec", options: ECKeyPairOptions<"pem", "der">, - callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: string, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "ec", options: ECKeyPairOptions<"der", "pem">, - callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: string) => void, ): void; function generateKeyPair( type: "ec", options: ECKeyPairOptions<"der", "der">, - callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "ec", @@ -3134,17 +3154,17 @@ declare module "crypto" { function generateKeyPair( type: "ed25519", options: ED25519KeyPairOptions<"pem", "der">, - callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: string, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "ed25519", options: ED25519KeyPairOptions<"der", "pem">, - callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: string) => void, ): void; function generateKeyPair( type: "ed25519", options: ED25519KeyPairOptions<"der", "der">, - callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "ed25519", @@ -3159,17 +3179,17 @@ declare module "crypto" { function generateKeyPair( type: "ed448", options: ED448KeyPairOptions<"pem", "der">, - callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: string, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "ed448", options: ED448KeyPairOptions<"der", "pem">, - callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: string) => void, ): void; function generateKeyPair( type: "ed448", options: ED448KeyPairOptions<"der", "der">, - callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "ed448", @@ -3184,17 +3204,17 @@ declare module "crypto" { function generateKeyPair( type: "x25519", options: X25519KeyPairOptions<"pem", "der">, - callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: string, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "x25519", options: X25519KeyPairOptions<"der", "pem">, - callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: string) => void, ): void; function generateKeyPair( type: "x25519", options: X25519KeyPairOptions<"der", "der">, - callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "x25519", @@ -3209,17 +3229,17 @@ declare module "crypto" { function generateKeyPair( type: "x448", options: X448KeyPairOptions<"pem", "der">, - callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: string, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "x448", options: X448KeyPairOptions<"der", "pem">, - callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: string) => void, ): void; function generateKeyPair( type: "x448", options: X448KeyPairOptions<"der", "der">, - callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "x448", @@ -3234,17 +3254,17 @@ declare module "crypto" { function generateKeyPair( type: "ml-dsa-44" | "ml-dsa-65" | "ml-dsa-87", options: MLDSAKeyPairOptions<"pem", "der">, - callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: string, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "ml-dsa-44" | "ml-dsa-65" | "ml-dsa-87", options: MLDSAKeyPairOptions<"der", "pem">, - callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: string) => void, ): void; function generateKeyPair( type: "ml-dsa-44" | "ml-dsa-65" | "ml-dsa-87", options: MLDSAKeyPairOptions<"der", "der">, - callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "ml-dsa-44" | "ml-dsa-65" | "ml-dsa-87", @@ -3259,17 +3279,17 @@ declare module "crypto" { function generateKeyPair( type: "ml-kem-1024" | "ml-kem-512" | "ml-kem-768", options: MLKEMKeyPairOptions<"pem", "der">, - callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: string, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "ml-kem-1024" | "ml-kem-512" | "ml-kem-768", options: MLKEMKeyPairOptions<"der", "pem">, - callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: string) => void, ): void; function generateKeyPair( type: "ml-kem-1024" | "ml-kem-512" | "ml-kem-768", options: MLKEMKeyPairOptions<"der", "der">, - callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "ml-kem-1024" | "ml-kem-512" | "ml-kem-768", @@ -3374,21 +3394,21 @@ declare module "crypto" { options: RSAKeyPairOptions<"pem", "der">, ): Promise<{ publicKey: string; - privateKey: Buffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "rsa", options: RSAKeyPairOptions<"der", "pem">, ): Promise<{ - publicKey: Buffer; + publicKey: NonSharedBuffer; privateKey: string; }>; function __promisify__( type: "rsa", options: RSAKeyPairOptions<"der", "der">, ): Promise<{ - publicKey: Buffer; - privateKey: Buffer; + publicKey: NonSharedBuffer; + privateKey: NonSharedBuffer; }>; function __promisify__(type: "rsa", options: RSAKeyPairKeyObjectOptions): Promise; function __promisify__( @@ -3403,21 +3423,21 @@ declare module "crypto" { options: RSAPSSKeyPairOptions<"pem", "der">, ): Promise<{ publicKey: string; - privateKey: Buffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "rsa-pss", options: RSAPSSKeyPairOptions<"der", "pem">, ): Promise<{ - publicKey: Buffer; + publicKey: NonSharedBuffer; privateKey: string; }>; function __promisify__( type: "rsa-pss", options: RSAPSSKeyPairOptions<"der", "der">, ): Promise<{ - publicKey: Buffer; - privateKey: Buffer; + publicKey: NonSharedBuffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "rsa-pss", @@ -3435,21 +3455,21 @@ declare module "crypto" { options: DSAKeyPairOptions<"pem", "der">, ): Promise<{ publicKey: string; - privateKey: Buffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "dsa", options: DSAKeyPairOptions<"der", "pem">, ): Promise<{ - publicKey: Buffer; + publicKey: NonSharedBuffer; privateKey: string; }>; function __promisify__( type: "dsa", options: DSAKeyPairOptions<"der", "der">, ): Promise<{ - publicKey: Buffer; - privateKey: Buffer; + publicKey: NonSharedBuffer; + privateKey: NonSharedBuffer; }>; function __promisify__(type: "dsa", options: DSAKeyPairKeyObjectOptions): Promise; function __promisify__( @@ -3464,21 +3484,21 @@ declare module "crypto" { options: ECKeyPairOptions<"pem", "der">, ): Promise<{ publicKey: string; - privateKey: Buffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "ec", options: ECKeyPairOptions<"der", "pem">, ): Promise<{ - publicKey: Buffer; + publicKey: NonSharedBuffer; privateKey: string; }>; function __promisify__( type: "ec", options: ECKeyPairOptions<"der", "der">, ): Promise<{ - publicKey: Buffer; - privateKey: Buffer; + publicKey: NonSharedBuffer; + privateKey: NonSharedBuffer; }>; function __promisify__(type: "ec", options: ECKeyPairKeyObjectOptions): Promise; function __promisify__( @@ -3493,21 +3513,21 @@ declare module "crypto" { options: ED25519KeyPairOptions<"pem", "der">, ): Promise<{ publicKey: string; - privateKey: Buffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "ed25519", options: ED25519KeyPairOptions<"der", "pem">, ): Promise<{ - publicKey: Buffer; + publicKey: NonSharedBuffer; privateKey: string; }>; function __promisify__( type: "ed25519", options: ED25519KeyPairOptions<"der", "der">, ): Promise<{ - publicKey: Buffer; - privateKey: Buffer; + publicKey: NonSharedBuffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "ed25519", @@ -3525,21 +3545,21 @@ declare module "crypto" { options: ED448KeyPairOptions<"pem", "der">, ): Promise<{ publicKey: string; - privateKey: Buffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "ed448", options: ED448KeyPairOptions<"der", "pem">, ): Promise<{ - publicKey: Buffer; + publicKey: NonSharedBuffer; privateKey: string; }>; function __promisify__( type: "ed448", options: ED448KeyPairOptions<"der", "der">, ): Promise<{ - publicKey: Buffer; - privateKey: Buffer; + publicKey: NonSharedBuffer; + privateKey: NonSharedBuffer; }>; function __promisify__(type: "ed448", options?: ED448KeyPairKeyObjectOptions): Promise; function __promisify__( @@ -3554,21 +3574,21 @@ declare module "crypto" { options: X25519KeyPairOptions<"pem", "der">, ): Promise<{ publicKey: string; - privateKey: Buffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "x25519", options: X25519KeyPairOptions<"der", "pem">, ): Promise<{ - publicKey: Buffer; + publicKey: NonSharedBuffer; privateKey: string; }>; function __promisify__( type: "x25519", options: X25519KeyPairOptions<"der", "der">, ): Promise<{ - publicKey: Buffer; - privateKey: Buffer; + publicKey: NonSharedBuffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "x25519", @@ -3586,21 +3606,21 @@ declare module "crypto" { options: X448KeyPairOptions<"pem", "der">, ): Promise<{ publicKey: string; - privateKey: Buffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "x448", options: X448KeyPairOptions<"der", "pem">, ): Promise<{ - publicKey: Buffer; + publicKey: NonSharedBuffer; privateKey: string; }>; function __promisify__( type: "x448", options: X448KeyPairOptions<"der", "der">, ): Promise<{ - publicKey: Buffer; - privateKey: Buffer; + publicKey: NonSharedBuffer; + privateKey: NonSharedBuffer; }>; function __promisify__(type: "x448", options?: X448KeyPairKeyObjectOptions): Promise; function __promisify__( @@ -3615,21 +3635,21 @@ declare module "crypto" { options: MLDSAKeyPairOptions<"pem", "der">, ): Promise<{ publicKey: string; - privateKey: Buffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "ml-dsa-44" | "ml-dsa-65" | "ml-dsa-87", options: MLDSAKeyPairOptions<"der", "pem">, ): Promise<{ - publicKey: Buffer; + publicKey: NonSharedBuffer; privateKey: string; }>; function __promisify__( type: "ml-dsa-44" | "ml-dsa-65" | "ml-dsa-87", options: MLDSAKeyPairOptions<"der", "der">, ): Promise<{ - publicKey: Buffer; - privateKey: Buffer; + publicKey: NonSharedBuffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "ml-dsa-44" | "ml-dsa-65" | "ml-dsa-87", @@ -3647,21 +3667,21 @@ declare module "crypto" { options: MLKEMKeyPairOptions<"pem", "der">, ): Promise<{ publicKey: string; - privateKey: Buffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "ml-kem-1024" | "ml-kem-512" | "ml-kem-768", options: MLKEMKeyPairOptions<"der", "pem">, ): Promise<{ - publicKey: Buffer; + publicKey: NonSharedBuffer; privateKey: string; }>; function __promisify__( type: "ml-kem-1024" | "ml-kem-512" | "ml-kem-768", options: MLKEMKeyPairOptions<"der", "der">, ): Promise<{ - publicKey: Buffer; - privateKey: Buffer; + publicKey: NonSharedBuffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "ml-kem-1024" | "ml-kem-512" | "ml-kem-768", @@ -3779,12 +3799,12 @@ declare module "crypto" { algorithm: string | null | undefined, data: NodeJS.ArrayBufferView, key: KeyLike | SignKeyObjectInput | SignPrivateKeyInput | SignJsonWebKeyInput, - ): Buffer; + ): NonSharedBuffer; function sign( algorithm: string | null | undefined, data: NodeJS.ArrayBufferView, key: KeyLike | SignKeyObjectInput | SignPrivateKeyInput | SignJsonWebKeyInput, - callback: (error: Error | null, data: Buffer) => void, + callback: (error: Error | null, data: NonSharedBuffer) => void, ): void; /** * Verifies the given signature for `data` using the given key and algorithm. If @@ -3841,11 +3861,11 @@ declare module "crypto" { function decapsulate( key: KeyLike | PrivateKeyInput | JsonWebKeyInput, ciphertext: ArrayBuffer | NodeJS.ArrayBufferView, - ): Buffer; + ): NonSharedBuffer; function decapsulate( key: KeyLike | PrivateKeyInput | JsonWebKeyInput, ciphertext: ArrayBuffer | NodeJS.ArrayBufferView, - callback: (err: Error, sharedKey: Buffer) => void, + callback: (err: Error, sharedKey: NonSharedBuffer) => void, ): void; /** * Computes the Diffie-Hellman shared secret based on a `privateKey` and a `publicKey`. @@ -3855,10 +3875,10 @@ declare module "crypto" { * If the `callback` function is provided this function uses libuv's threadpool. * @since v13.9.0, v12.17.0 */ - function diffieHellman(options: { privateKey: KeyObject; publicKey: KeyObject }): Buffer; + function diffieHellman(options: { privateKey: KeyObject; publicKey: KeyObject }): NonSharedBuffer; function diffieHellman( options: { privateKey: KeyObject; publicKey: KeyObject }, - callback: (err: Error | null, secret: Buffer) => void, + callback: (err: Error | null, secret: NonSharedBuffer) => void, ): void; /** * Key encapsulation using a KEM algorithm with a public key. @@ -3879,10 +3899,12 @@ declare module "crypto" { * If the `callback` function is provided this function uses libuv's threadpool. * @since v24.7.0 */ - function encapsulate(key: KeyLike | PublicKeyInput | JsonWebKeyInput): { sharedKey: Buffer; ciphertext: Buffer }; function encapsulate( key: KeyLike | PublicKeyInput | JsonWebKeyInput, - callback: (err: Error, result: { sharedKey: Buffer; ciphertext: Buffer }) => void, + ): { sharedKey: NonSharedBuffer; ciphertext: NonSharedBuffer }; + function encapsulate( + key: KeyLike | PublicKeyInput | JsonWebKeyInput, + callback: (err: Error, result: { sharedKey: NonSharedBuffer; ciphertext: NonSharedBuffer }) => void, ): void; interface OneShotDigestOptions { /** @@ -3947,12 +3969,12 @@ declare module "crypto" { algorithm: string, data: BinaryLike, options: OneShotDigestOptionsWithBufferEncoding | "buffer", - ): Buffer; + ): NonSharedBuffer; function hash( algorithm: string, data: BinaryLike, options: OneShotDigestOptions | BinaryToTextEncoding | "buffer", - ): string | Buffer; + ): string | NonSharedBuffer; type CipherMode = "cbc" | "ccm" | "cfb" | "ctr" | "ecb" | "gcm" | "ocb" | "ofb" | "stream" | "wrap" | "xts"; interface CipherInfoOptions { /** @@ -4244,7 +4266,7 @@ declare module "crypto" { * A `Buffer` containing the DER encoding of this certificate. * @since v15.6.0 */ - readonly raw: Buffer; + readonly raw: NonSharedBuffer; /** * The serial number of this certificate. * @@ -4622,7 +4644,7 @@ declare module "crypto" { function argon2( algorithm: Argon2Algorithm, parameters: Argon2Parameters, - callback: (err: Error | null, derivedKey: Buffer) => void, + callback: (err: Error | null, derivedKey: NonSharedBuffer) => void, ): void; /** * Provides a synchronous [Argon2][] implementation. Argon2 is a password-based @@ -4659,7 +4681,7 @@ declare module "crypto" { * @since v24.7.0 * @experimental */ - function argon2Sync(algorithm: Argon2Algorithm, parameters: Argon2Parameters): Buffer; + function argon2Sync(algorithm: Argon2Algorithm, parameters: Argon2Parameters): NonSharedBuffer; /** * A convenient alias for `crypto.webcrypto.subtle`. * @since v17.4.0 diff --git a/types/node/dgram.d.ts b/types/node/dgram.d.ts index 35239f92cc6a49..bc69f0b48e1a5a 100644 --- a/types/node/dgram.d.ts +++ b/types/node/dgram.d.ts @@ -26,6 +26,7 @@ * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/dgram.js) */ declare module "dgram" { + import { NonSharedBuffer } from "node:buffer"; import { AddressInfo, BlockList } from "node:net"; import * as dns from "node:dns"; import { Abortable, EventEmitter } from "node:events"; @@ -85,8 +86,8 @@ declare module "dgram" { * @param options Available options are: * @param callback Attached as a listener for `'message'` events. Optional. */ - function createSocket(type: SocketType, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket; - function createSocket(options: SocketOptions, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket; + function createSocket(type: SocketType, callback?: (msg: NonSharedBuffer, rinfo: RemoteInfo) => void): Socket; + function createSocket(options: SocketOptions, callback?: (msg: NonSharedBuffer, rinfo: RemoteInfo) => void): Socket; /** * Encapsulates the datagram functionality. * @@ -556,37 +557,37 @@ declare module "dgram" { addListener(event: "connect", listener: () => void): this; addListener(event: "error", listener: (err: Error) => void): this; addListener(event: "listening", listener: () => void): this; - addListener(event: "message", listener: (msg: Buffer, rinfo: RemoteInfo) => void): this; + addListener(event: "message", listener: (msg: NonSharedBuffer, rinfo: RemoteInfo) => void): this; emit(event: string | symbol, ...args: any[]): boolean; emit(event: "close"): boolean; emit(event: "connect"): boolean; emit(event: "error", err: Error): boolean; emit(event: "listening"): boolean; - emit(event: "message", msg: Buffer, rinfo: RemoteInfo): boolean; + emit(event: "message", msg: NonSharedBuffer, rinfo: RemoteInfo): boolean; on(event: string, listener: (...args: any[]) => void): this; on(event: "close", listener: () => void): this; on(event: "connect", listener: () => void): this; on(event: "error", listener: (err: Error) => void): this; on(event: "listening", listener: () => void): this; - on(event: "message", listener: (msg: Buffer, rinfo: RemoteInfo) => void): this; + on(event: "message", listener: (msg: NonSharedBuffer, rinfo: RemoteInfo) => void): this; once(event: string, listener: (...args: any[]) => void): this; once(event: "close", listener: () => void): this; once(event: "connect", listener: () => void): this; once(event: "error", listener: (err: Error) => void): this; once(event: "listening", listener: () => void): this; - once(event: "message", listener: (msg: Buffer, rinfo: RemoteInfo) => void): this; + once(event: "message", listener: (msg: NonSharedBuffer, rinfo: RemoteInfo) => void): this; prependListener(event: string, listener: (...args: any[]) => void): this; prependListener(event: "close", listener: () => void): this; prependListener(event: "connect", listener: () => void): this; prependListener(event: "error", listener: (err: Error) => void): this; prependListener(event: "listening", listener: () => void): this; - prependListener(event: "message", listener: (msg: Buffer, rinfo: RemoteInfo) => void): this; + prependListener(event: "message", listener: (msg: NonSharedBuffer, rinfo: RemoteInfo) => void): this; prependOnceListener(event: string, listener: (...args: any[]) => void): this; prependOnceListener(event: "close", listener: () => void): this; prependOnceListener(event: "connect", listener: () => void): this; prependOnceListener(event: "error", listener: (err: Error) => void): this; prependOnceListener(event: "listening", listener: () => void): this; - prependOnceListener(event: "message", listener: (msg: Buffer, rinfo: RemoteInfo) => void): this; + prependOnceListener(event: "message", listener: (msg: NonSharedBuffer, rinfo: RemoteInfo) => void): this; /** * Calls `socket.close()` and returns a promise that fulfills when the socket has closed. * @since v20.5.0 diff --git a/types/node/fs.d.ts b/types/node/fs.d.ts index 0e1330720f261e..b300ca45ae0190 100644 --- a/types/node/fs.d.ts +++ b/types/node/fs.d.ts @@ -19,6 +19,7 @@ * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/fs.js) */ declare module "fs" { + import { NonSharedBuffer } from "node:buffer"; import * as stream from "node:stream"; import { Abortable, EventEmitter } from "node:events"; import { URL } from "node:url"; @@ -394,23 +395,29 @@ declare module "fs" { * 3. error */ addListener(event: string, listener: (...args: any[]) => void): this; - addListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this; + addListener(event: "change", listener: (eventType: string, filename: string | NonSharedBuffer) => void): this; addListener(event: "close", listener: () => void): this; addListener(event: "error", listener: (error: Error) => void): this; on(event: string, listener: (...args: any[]) => void): this; - on(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this; + on(event: "change", listener: (eventType: string, filename: string | NonSharedBuffer) => void): this; on(event: "close", listener: () => void): this; on(event: "error", listener: (error: Error) => void): this; once(event: string, listener: (...args: any[]) => void): this; - once(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this; + once(event: "change", listener: (eventType: string, filename: string | NonSharedBuffer) => void): this; once(event: "close", listener: () => void): this; once(event: "error", listener: (error: Error) => void): this; prependListener(event: string, listener: (...args: any[]) => void): this; - prependListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this; + prependListener( + event: "change", + listener: (eventType: string, filename: string | NonSharedBuffer) => void, + ): this; prependListener(event: "close", listener: () => void): this; prependListener(event: "error", listener: (error: Error) => void): this; prependOnceListener(event: string, listener: (...args: any[]) => void): this; - prependOnceListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this; + prependOnceListener( + event: "change", + listener: (eventType: string, filename: string | NonSharedBuffer) => void, + ): this; prependOnceListener(event: "close", listener: () => void): this; prependOnceListener(event: "error", listener: (error: Error) => void): this; } @@ -1550,7 +1557,7 @@ declare module "fs" { export function readlink( path: PathLike, options: BufferEncodingOption, - callback: (err: NodeJS.ErrnoException | null, linkString: Buffer) => void, + callback: (err: NodeJS.ErrnoException | null, linkString: NonSharedBuffer) => void, ): void; /** * Asynchronous readlink(2) - read value of a symbolic link. @@ -1560,7 +1567,7 @@ declare module "fs" { export function readlink( path: PathLike, options: EncodingOption, - callback: (err: NodeJS.ErrnoException | null, linkString: string | Buffer) => void, + callback: (err: NodeJS.ErrnoException | null, linkString: string | NonSharedBuffer) => void, ): void; /** * Asynchronous readlink(2) - read value of a symbolic link. @@ -1582,13 +1589,13 @@ declare module "fs" { * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function __promisify__(path: PathLike, options: BufferEncodingOption): Promise; + function __promisify__(path: PathLike, options: BufferEncodingOption): Promise; /** * Asynchronous readlink(2) - read value of a symbolic link. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function __promisify__(path: PathLike, options?: EncodingOption): Promise; + function __promisify__(path: PathLike, options?: EncodingOption): Promise; } /** * Returns the symbolic link's string value. @@ -1607,13 +1614,13 @@ declare module "fs" { * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - export function readlinkSync(path: PathLike, options: BufferEncodingOption): Buffer; + export function readlinkSync(path: PathLike, options: BufferEncodingOption): NonSharedBuffer; /** * Synchronous readlink(2) - read value of a symbolic link. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - export function readlinkSync(path: PathLike, options?: EncodingOption): string | Buffer; + export function readlinkSync(path: PathLike, options?: EncodingOption): string | NonSharedBuffer; /** * Asynchronously computes the canonical pathname by resolving `.`, `..`, and * symbolic links. @@ -1653,7 +1660,7 @@ declare module "fs" { export function realpath( path: PathLike, options: BufferEncodingOption, - callback: (err: NodeJS.ErrnoException | null, resolvedPath: Buffer) => void, + callback: (err: NodeJS.ErrnoException | null, resolvedPath: NonSharedBuffer) => void, ): void; /** * Asynchronous realpath(3) - return the canonicalized absolute pathname. @@ -1663,7 +1670,7 @@ declare module "fs" { export function realpath( path: PathLike, options: EncodingOption, - callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | Buffer) => void, + callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | NonSharedBuffer) => void, ): void; /** * Asynchronous realpath(3) - return the canonicalized absolute pathname. @@ -1685,13 +1692,13 @@ declare module "fs" { * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function __promisify__(path: PathLike, options: BufferEncodingOption): Promise; + function __promisify__(path: PathLike, options: BufferEncodingOption): Promise; /** * Asynchronous realpath(3) - return the canonicalized absolute pathname. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function __promisify__(path: PathLike, options?: EncodingOption): Promise; + function __promisify__(path: PathLike, options?: EncodingOption): Promise; /** * Asynchronous [`realpath(3)`](http://man7.org/linux/man-pages/man3/realpath.3.html). * @@ -1717,12 +1724,12 @@ declare module "fs" { function native( path: PathLike, options: BufferEncodingOption, - callback: (err: NodeJS.ErrnoException | null, resolvedPath: Buffer) => void, + callback: (err: NodeJS.ErrnoException | null, resolvedPath: NonSharedBuffer) => void, ): void; function native( path: PathLike, options: EncodingOption, - callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | Buffer) => void, + callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | NonSharedBuffer) => void, ): void; function native( path: PathLike, @@ -1742,17 +1749,17 @@ declare module "fs" { * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - export function realpathSync(path: PathLike, options: BufferEncodingOption): Buffer; + export function realpathSync(path: PathLike, options: BufferEncodingOption): NonSharedBuffer; /** * Synchronous realpath(3) - return the canonicalized absolute pathname. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - export function realpathSync(path: PathLike, options?: EncodingOption): string | Buffer; + export function realpathSync(path: PathLike, options?: EncodingOption): string | NonSharedBuffer; export namespace realpathSync { function native(path: PathLike, options?: EncodingOption): string; - function native(path: PathLike, options: BufferEncodingOption): Buffer; - function native(path: PathLike, options?: EncodingOption): string | Buffer; + function native(path: PathLike, options: BufferEncodingOption): NonSharedBuffer; + function native(path: PathLike, options?: EncodingOption): string | NonSharedBuffer; } /** * Asynchronously removes a file or symbolic link. No arguments other than a @@ -2122,12 +2129,8 @@ declare module "fs" { */ export function mkdtemp( prefix: string, - options: - | "buffer" - | { - encoding: "buffer"; - }, - callback: (err: NodeJS.ErrnoException | null, folder: Buffer) => void, + options: BufferEncodingOption, + callback: (err: NodeJS.ErrnoException | null, folder: NonSharedBuffer) => void, ): void; /** * Asynchronously creates a unique temporary directory. @@ -2137,7 +2140,7 @@ declare module "fs" { export function mkdtemp( prefix: string, options: EncodingOption, - callback: (err: NodeJS.ErrnoException | null, folder: string | Buffer) => void, + callback: (err: NodeJS.ErrnoException | null, folder: string | NonSharedBuffer) => void, ): void; /** * Asynchronously creates a unique temporary directory. @@ -2159,13 +2162,13 @@ declare module "fs" { * Generates six random characters to be appended behind a required prefix to create a unique temporary directory. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function __promisify__(prefix: string, options: BufferEncodingOption): Promise; + function __promisify__(prefix: string, options: BufferEncodingOption): Promise; /** * Asynchronously creates a unique temporary directory. * Generates six random characters to be appended behind a required prefix to create a unique temporary directory. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function __promisify__(prefix: string, options?: EncodingOption): Promise; + function __promisify__(prefix: string, options?: EncodingOption): Promise; } /** * Returns the created directory path. @@ -2183,13 +2186,13 @@ declare module "fs" { * Generates six random characters to be appended behind a required prefix to create a unique temporary directory. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - export function mkdtempSync(prefix: string, options: BufferEncodingOption): Buffer; + export function mkdtempSync(prefix: string, options: BufferEncodingOption): NonSharedBuffer; /** * Synchronously creates a unique temporary directory. * Generates six random characters to be appended behind a required prefix to create a unique temporary directory. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - export function mkdtempSync(prefix: string, options?: EncodingOption): string | Buffer; + export function mkdtempSync(prefix: string, options?: EncodingOption): string | NonSharedBuffer; export interface DisposableTempDir extends AsyncDisposable { /** * The path of the created directory. @@ -2263,7 +2266,7 @@ declare module "fs" { recursive?: boolean | undefined; } | "buffer", - callback: (err: NodeJS.ErrnoException | null, files: Buffer[]) => void, + callback: (err: NodeJS.ErrnoException | null, files: NonSharedBuffer[]) => void, ): void; /** * Asynchronous readdir(3) - read a directory. @@ -2280,7 +2283,7 @@ declare module "fs" { | BufferEncoding | undefined | null, - callback: (err: NodeJS.ErrnoException | null, files: string[] | Buffer[]) => void, + callback: (err: NodeJS.ErrnoException | null, files: string[] | NonSharedBuffer[]) => void, ): void; /** * Asynchronous readdir(3) - read a directory. @@ -2315,7 +2318,7 @@ declare module "fs" { withFileTypes: true; recursive?: boolean | undefined; }, - callback: (err: NodeJS.ErrnoException | null, files: Dirent[]) => void, + callback: (err: NodeJS.ErrnoException | null, files: Dirent[]) => void, ): void; export namespace readdir { /** @@ -2348,7 +2351,7 @@ declare module "fs" { withFileTypes?: false | undefined; recursive?: boolean | undefined; }, - ): Promise; + ): Promise; /** * Asynchronous readdir(3) - read a directory. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. @@ -2363,7 +2366,7 @@ declare module "fs" { }) | BufferEncoding | null, - ): Promise; + ): Promise; /** * Asynchronous readdir(3) - read a directory. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. @@ -2388,7 +2391,7 @@ declare module "fs" { withFileTypes: true; recursive?: boolean | undefined; }, - ): Promise[]>; + ): Promise[]>; } /** * Reads the contents of the directory. @@ -2428,7 +2431,7 @@ declare module "fs" { recursive?: boolean | undefined; } | "buffer", - ): Buffer[]; + ): NonSharedBuffer[]; /** * Synchronous readdir(3) - read a directory. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. @@ -2443,7 +2446,7 @@ declare module "fs" { }) | BufferEncoding | null, - ): string[] | Buffer[]; + ): string[] | NonSharedBuffer[]; /** * Synchronous readdir(3) - read a directory. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. @@ -2468,7 +2471,7 @@ declare module "fs" { withFileTypes: true; recursive?: boolean | undefined; }, - ): Dirent[]; + ): Dirent[]; /** * Closes the file descriptor. No arguments other than a possible exception are * given to the completion callback. @@ -2835,7 +2838,7 @@ declare module "fs" { encoding?: BufferEncoding | null, ): number; export type ReadPosition = number | bigint; - export interface ReadSyncOptions { + export interface ReadOptions { /** * @default 0 */ @@ -2849,9 +2852,15 @@ declare module "fs" { */ position?: ReadPosition | null | undefined; } - export interface ReadAsyncOptions extends ReadSyncOptions { - buffer?: TBuffer; + export interface ReadOptionsWithBuffer extends ReadOptions { + buffer?: T | undefined; } + /** @deprecated Use `ReadOptions` instead. */ + // TODO: remove in future major + export interface ReadSyncOptions extends ReadOptions {} + /** @deprecated Use `ReadOptionsWithBuffer` instead. */ + // TODO: remove in future major + export interface ReadAsyncOptions extends ReadOptionsWithBuffer {} /** * Read data from the file specified by `fd`. * @@ -2886,15 +2895,15 @@ declare module "fs" { * `position` defaults to `null` * @since v12.17.0, 13.11.0 */ - export function read( + export function read( fd: number, - options: ReadAsyncOptions, + options: ReadOptionsWithBuffer, callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void, ): void; export function read( fd: number, buffer: TBuffer, - options: ReadSyncOptions, + options: ReadOptions, callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void, ): void; export function read( @@ -2904,7 +2913,7 @@ declare module "fs" { ): void; export function read( fd: number, - callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: NodeJS.ArrayBufferView) => void, + callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: NonSharedBuffer) => void, ): void; export namespace read { /** @@ -2924,16 +2933,16 @@ declare module "fs" { bytesRead: number; buffer: TBuffer; }>; - function __promisify__( + function __promisify__( fd: number, - options: ReadAsyncOptions, + options: ReadOptionsWithBuffer, ): Promise<{ bytesRead: number; buffer: TBuffer; }>; function __promisify__(fd: number): Promise<{ bytesRead: number; - buffer: NodeJS.ArrayBufferView; + buffer: NonSharedBuffer; }>; } /** @@ -2955,7 +2964,7 @@ declare module "fs" { * Similar to the above `fs.readSync` function, this version takes an optional `options` object. * If no `options` object is specified, it will default with the above values. */ - export function readSync(fd: number, buffer: NodeJS.ArrayBufferView, opts?: ReadSyncOptions): number; + export function readSync(fd: number, buffer: NodeJS.ArrayBufferView, opts?: ReadOptions): number; /** * Asynchronously reads the entire contents of a file. * @@ -3628,12 +3637,12 @@ declare module "fs" { export function watch( filename: PathLike, options: WatchOptionsWithBufferEncoding | "buffer", - listener: WatchListener, + listener: WatchListener, ): FSWatcher; export function watch( filename: PathLike, options: WatchOptions | BufferEncoding | "buffer" | null, - listener: WatchListener, + listener: WatchListener, ): FSWatcher; export function watch(filename: PathLike, listener: WatchListener): FSWatcher; /** @@ -4344,27 +4353,29 @@ declare module "fs" { * @since v12.9.0 * @param [position='null'] */ - export function writev( + export function writev( fd: number, - buffers: readonly NodeJS.ArrayBufferView[], - cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void, + buffers: TBuffers, + cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: TBuffers) => void, ): void; - export function writev( + export function writev( fd: number, - buffers: readonly NodeJS.ArrayBufferView[], + buffers: TBuffers, position: number | null, - cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void, + cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: TBuffers) => void, ): void; - export interface WriteVResult { + // Providing a default type parameter doesn't provide true BC for userland consumers, but at least suppresses TS2314 + // TODO: remove default in future major version + export interface WriteVResult { bytesWritten: number; - buffers: NodeJS.ArrayBufferView[]; + buffers: T; } export namespace writev { - function __promisify__( + function __promisify__( fd: number, - buffers: readonly NodeJS.ArrayBufferView[], + buffers: TBuffers, position?: number, - ): Promise; + ): Promise>; } /** * For detailed information, see the documentation of the asynchronous version of @@ -4389,27 +4400,29 @@ declare module "fs" { * @since v13.13.0, v12.17.0 * @param [position='null'] */ - export function readv( + export function readv( fd: number, - buffers: readonly NodeJS.ArrayBufferView[], - cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => void, + buffers: TBuffers, + cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: TBuffers) => void, ): void; - export function readv( + export function readv( fd: number, - buffers: readonly NodeJS.ArrayBufferView[], + buffers: TBuffers, position: number | null, - cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => void, + cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: TBuffers) => void, ): void; - export interface ReadVResult { + // Providing a default type parameter doesn't provide true BC for userland consumers, but at least suppresses TS2314 + // TODO: remove default in future major version + export interface ReadVResult { bytesRead: number; - buffers: NodeJS.ArrayBufferView[]; + buffers: T; } export namespace readv { - function __promisify__( + function __promisify__( fd: number, - buffers: readonly NodeJS.ArrayBufferView[], + buffers: TBuffers, position?: number, - ): Promise; + ): Promise>; } /** * For detailed information, see the documentation of the asynchronous version of diff --git a/types/node/fs/promises.d.ts b/types/node/fs/promises.d.ts index adddd0985f51b2..986b6da5c6d6aa 100644 --- a/types/node/fs/promises.d.ts +++ b/types/node/fs/promises.d.ts @@ -9,6 +9,7 @@ * @since v10.0.0 */ declare module "fs/promises" { + import { NonSharedBuffer } from "node:buffer"; import { Abortable } from "node:events"; import { Stream } from "node:stream"; import { ReadableStream } from "node:stream/web"; @@ -31,6 +32,8 @@ declare module "fs/promises" { OpenDirOptions, OpenMode, PathLike, + ReadOptions, + ReadOptionsWithBuffer, ReadPosition, ReadStream, ReadVResult, @@ -59,6 +62,7 @@ declare module "fs/promises" { bytesRead: number; buffer: T; } + /** @deprecated This interface will be removed in a future version. Use `import { ReadOptionsWithBuffer } from "node:fs"` instead. */ interface FileReadOptions { /** * @default `Buffer.alloc(0xffff)` @@ -237,11 +241,13 @@ declare module "fs/promises" { length?: number | null, position?: ReadPosition | null, ): Promise>; - read( + read( buffer: T, - options?: FileReadOptions, + options?: ReadOptions, + ): Promise>; + read( + options?: ReadOptionsWithBuffer, ): Promise>; - read(options?: FileReadOptions): Promise>; /** * Returns a byte-oriented `ReadableStream` that may be used to read the file's * contents. @@ -285,7 +291,7 @@ declare module "fs/promises" { options?: | ({ encoding?: null | undefined } & Abortable) | null, - ): Promise; + ): Promise; /** * Asynchronously reads the entire contents of a file. The underlying file will _not_ be closed automatically. * The `FileHandle` must have been opened for reading. @@ -304,7 +310,7 @@ declare module "fs/promises" { | (ObjectEncodingOptions & Abortable) | BufferEncoding | null, - ): Promise; + ): Promise; /** * Convenience method to create a `readline` interface and stream over the file. * See `filehandle.createReadStream()` for the options. @@ -413,7 +419,7 @@ declare module "fs/promises" { * @param [position='null'] The offset from the beginning of the file where the data from `buffer` should be written. If `position` is not a `number`, the data will be written at the current * position. See the POSIX pwrite(2) documentation for more detail. */ - write( + write( buffer: TBuffer, offset?: number | null, length?: number | null, @@ -452,14 +458,20 @@ declare module "fs/promises" { * @param [position='null'] The offset from the beginning of the file where the data from `buffers` should be written. If `position` is not a `number`, the data will be written at the current * position. */ - writev(buffers: readonly NodeJS.ArrayBufferView[], position?: number): Promise; + writev( + buffers: TBuffers, + position?: number, + ): Promise>; /** * Read from a file and write to an array of [ArrayBufferView](https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView) s * @since v13.13.0, v12.17.0 * @param [position='null'] The offset from the beginning of the file where the data should be read from. If `position` is not a `number`, the data will be read from the current position. * @return Fulfills upon success an object containing two properties: */ - readv(buffers: readonly NodeJS.ArrayBufferView[], position?: number): Promise; + readv( + buffers: TBuffers, + position?: number, + ): Promise>; /** * Closes the file handle after waiting for any pending operation on the handle to * complete. @@ -696,7 +708,7 @@ declare module "fs/promises" { recursive?: boolean | undefined; } | "buffer", - ): Promise; + ): Promise; /** * Asynchronous readdir(3) - read a directory. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. @@ -711,7 +723,7 @@ declare module "fs/promises" { }) | BufferEncoding | null, - ): Promise; + ): Promise; /** * Asynchronous readdir(3) - read a directory. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. @@ -736,7 +748,7 @@ declare module "fs/promises" { withFileTypes: true; recursive?: boolean | undefined; }, - ): Promise[]>; + ): Promise[]>; /** * Reads the contents of the symbolic link referred to by `path`. See the POSIX [`readlink(2)`](http://man7.org/linux/man-pages/man2/readlink.2.html) documentation for more detail. The promise is * fulfilled with the`linkString` upon success. @@ -754,13 +766,16 @@ declare module "fs/promises" { * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function readlink(path: PathLike, options: BufferEncodingOption): Promise; + function readlink(path: PathLike, options: BufferEncodingOption): Promise; /** * Asynchronous readlink(2) - read value of a symbolic link. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function readlink(path: PathLike, options?: ObjectEncodingOptions | string | null): Promise; + function readlink( + path: PathLike, + options?: ObjectEncodingOptions | string | null, + ): Promise; /** * Creates a symbolic link. * @@ -911,7 +926,7 @@ declare module "fs/promises" { * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function realpath(path: PathLike, options: BufferEncodingOption): Promise; + function realpath(path: PathLike, options: BufferEncodingOption): Promise; /** * Asynchronous realpath(3) - return the canonicalized absolute pathname. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. @@ -920,7 +935,7 @@ declare module "fs/promises" { function realpath( path: PathLike, options?: ObjectEncodingOptions | BufferEncoding | null, - ): Promise; + ): Promise; /** * Creates a unique temporary directory. A unique directory name is generated by * appending six random characters to the end of the provided `prefix`. Due to @@ -956,13 +971,16 @@ declare module "fs/promises" { * Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function mkdtemp(prefix: string, options: BufferEncodingOption): Promise; + function mkdtemp(prefix: string, options: BufferEncodingOption): Promise; /** * Asynchronously creates a unique temporary directory. * Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function mkdtemp(prefix: string, options?: ObjectEncodingOptions | BufferEncoding | null): Promise; + function mkdtemp( + prefix: string, + options?: ObjectEncodingOptions | BufferEncoding | null, + ): Promise; /** * The resulting Promise holds an async-disposable object whose `path` property * holds the created directory path. When the object is disposed, the directory @@ -1138,7 +1156,7 @@ declare module "fs/promises" { flag?: OpenMode | undefined; } & Abortable) | null, - ): Promise; + ): Promise; /** * Asynchronously reads the entire contents of a file. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. @@ -1174,7 +1192,7 @@ declare module "fs/promises" { ) | BufferEncoding | null, - ): Promise; + ): Promise; /** * Asynchronously open a directory for iterative scanning. See the POSIX [`opendir(3)`](http://man7.org/linux/man-pages/man3/opendir.3.html) documentation for more detail. * @@ -1251,11 +1269,11 @@ declare module "fs/promises" { function watch( filename: PathLike, options: WatchOptionsWithBufferEncoding | "buffer", - ): NodeJS.AsyncIterator>; + ): NodeJS.AsyncIterator>; function watch( filename: PathLike, options: WatchOptions | BufferEncoding | "buffer", - ): NodeJS.AsyncIterator>; + ): NodeJS.AsyncIterator>; /** * Asynchronously copies the entire directory structure from `src` to `dest`, * including subdirectories and files. diff --git a/types/node/globals.typedarray.d.ts b/types/node/globals.typedarray.d.ts index 6d5c9527e847a7..cae4c0b1aad37c 100644 --- a/types/node/globals.typedarray.d.ts +++ b/types/node/globals.typedarray.d.ts @@ -18,5 +18,24 @@ declare global { type ArrayBufferView = | TypedArray | DataView; + + // The following aliases are required to allow use of non-shared ArrayBufferViews in @types/node + // while maintaining compatibility with TS <=5.6. + // TODO: remove once @types/node no longer supports TS 5.6, and replace with native types. + type NonSharedUint8Array = Uint8Array; + type NonSharedUint8ClampedArray = Uint8ClampedArray; + type NonSharedUint16Array = Uint16Array; + type NonSharedUint32Array = Uint32Array; + type NonSharedInt8Array = Int8Array; + type NonSharedInt16Array = Int16Array; + type NonSharedInt32Array = Int32Array; + type NonSharedBigUint64Array = BigUint64Array; + type NonSharedBigInt64Array = BigInt64Array; + type NonSharedFloat16Array = Float16Array; + type NonSharedFloat32Array = Float32Array; + type NonSharedFloat64Array = Float64Array; + type NonSharedDataView = DataView; + type NonSharedTypedArray = TypedArray; + type NonSharedArrayBufferView = ArrayBufferView; } } diff --git a/types/node/http.d.ts b/types/node/http.d.ts index df46bc28e5a43f..771b8b2f407c19 100644 --- a/types/node/http.d.ts +++ b/types/node/http.d.ts @@ -40,6 +40,7 @@ * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/http.js) */ declare module "http" { + import { NonSharedBuffer } from "node:buffer"; import * as stream from "node:stream"; import { URL } from "node:url"; import { LookupOptions } from "node:dns"; @@ -495,13 +496,13 @@ declare module "http" { addListener(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this; addListener( event: "connect", - listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, ): this; addListener(event: "dropRequest", listener: (req: InstanceType, socket: stream.Duplex) => void): this; addListener(event: "request", listener: RequestListener): this; addListener( event: "upgrade", - listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, ): this; emit(event: string, ...args: any[]): boolean; emit(event: "close"): boolean; @@ -519,14 +520,14 @@ declare module "http" { res: InstanceType & { req: InstanceType }, ): boolean; emit(event: "clientError", err: Error, socket: stream.Duplex): boolean; - emit(event: "connect", req: InstanceType, socket: stream.Duplex, head: Buffer): boolean; + emit(event: "connect", req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer): boolean; emit(event: "dropRequest", req: InstanceType, socket: stream.Duplex): boolean; emit( event: "request", req: InstanceType, res: InstanceType & { req: InstanceType }, ): boolean; - emit(event: "upgrade", req: InstanceType, socket: stream.Duplex, head: Buffer): boolean; + emit(event: "upgrade", req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer): boolean; on(event: string, listener: (...args: any[]) => void): this; on(event: "close", listener: () => void): this; on(event: "connection", listener: (socket: Socket) => void): this; @@ -535,10 +536,16 @@ declare module "http" { on(event: "checkContinue", listener: RequestListener): this; on(event: "checkExpectation", listener: RequestListener): this; on(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this; - on(event: "connect", listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void): this; + on( + event: "connect", + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, + ): this; on(event: "dropRequest", listener: (req: InstanceType, socket: stream.Duplex) => void): this; on(event: "request", listener: RequestListener): this; - on(event: "upgrade", listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void): this; + on( + event: "upgrade", + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, + ): this; once(event: string, listener: (...args: any[]) => void): this; once(event: "close", listener: () => void): this; once(event: "connection", listener: (socket: Socket) => void): this; @@ -549,13 +556,13 @@ declare module "http" { once(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this; once( event: "connect", - listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, ): this; once(event: "dropRequest", listener: (req: InstanceType, socket: stream.Duplex) => void): this; once(event: "request", listener: RequestListener): this; once( event: "upgrade", - listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, ): this; prependListener(event: string, listener: (...args: any[]) => void): this; prependListener(event: "close", listener: () => void): this; @@ -567,7 +574,7 @@ declare module "http" { prependListener(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this; prependListener( event: "connect", - listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, ): this; prependListener( event: "dropRequest", @@ -576,7 +583,7 @@ declare module "http" { prependListener(event: "request", listener: RequestListener): this; prependListener( event: "upgrade", - listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, ): this; prependOnceListener(event: string, listener: (...args: any[]) => void): this; prependOnceListener(event: "close", listener: () => void): this; @@ -588,7 +595,7 @@ declare module "http" { prependOnceListener(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this; prependOnceListener( event: "connect", - listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, ): this; prependOnceListener( event: "dropRequest", @@ -597,7 +604,7 @@ declare module "http" { prependOnceListener(event: "request", listener: RequestListener): this; prependOnceListener( event: "upgrade", - listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, ): this; } /** @@ -1117,7 +1124,7 @@ declare module "http" { addListener(event: "abort", listener: () => void): this; addListener( event: "connect", - listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void, + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, ): this; addListener(event: "continue", listener: () => void): this; addListener(event: "information", listener: (info: InformationEvent) => void): this; @@ -1126,7 +1133,7 @@ declare module "http" { addListener(event: "timeout", listener: () => void): this; addListener( event: "upgrade", - listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void, + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, ): this; addListener(event: "close", listener: () => void): this; addListener(event: "drain", listener: () => void): this; @@ -1139,13 +1146,19 @@ declare module "http" { * @deprecated */ on(event: "abort", listener: () => void): this; - on(event: "connect", listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this; + on( + event: "connect", + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, + ): this; on(event: "continue", listener: () => void): this; on(event: "information", listener: (info: InformationEvent) => void): this; on(event: "response", listener: (response: IncomingMessage) => void): this; on(event: "socket", listener: (socket: Socket) => void): this; on(event: "timeout", listener: () => void): this; - on(event: "upgrade", listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this; + on( + event: "upgrade", + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, + ): this; on(event: "close", listener: () => void): this; on(event: "drain", listener: () => void): this; on(event: "error", listener: (err: Error) => void): this; @@ -1157,13 +1170,19 @@ declare module "http" { * @deprecated */ once(event: "abort", listener: () => void): this; - once(event: "connect", listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this; + once( + event: "connect", + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, + ): this; once(event: "continue", listener: () => void): this; once(event: "information", listener: (info: InformationEvent) => void): this; once(event: "response", listener: (response: IncomingMessage) => void): this; once(event: "socket", listener: (socket: Socket) => void): this; once(event: "timeout", listener: () => void): this; - once(event: "upgrade", listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this; + once( + event: "upgrade", + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, + ): this; once(event: "close", listener: () => void): this; once(event: "drain", listener: () => void): this; once(event: "error", listener: (err: Error) => void): this; @@ -1177,7 +1196,7 @@ declare module "http" { prependListener(event: "abort", listener: () => void): this; prependListener( event: "connect", - listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void, + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, ): this; prependListener(event: "continue", listener: () => void): this; prependListener(event: "information", listener: (info: InformationEvent) => void): this; @@ -1186,7 +1205,7 @@ declare module "http" { prependListener(event: "timeout", listener: () => void): this; prependListener( event: "upgrade", - listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void, + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, ): this; prependListener(event: "close", listener: () => void): this; prependListener(event: "drain", listener: () => void): this; @@ -1201,7 +1220,7 @@ declare module "http" { prependOnceListener(event: "abort", listener: () => void): this; prependOnceListener( event: "connect", - listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void, + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, ): this; prependOnceListener(event: "continue", listener: () => void): this; prependOnceListener(event: "information", listener: (info: InformationEvent) => void): this; @@ -1210,7 +1229,7 @@ declare module "http" { prependOnceListener(event: "timeout", listener: () => void): this; prependOnceListener( event: "upgrade", - listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void, + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, ): this; prependOnceListener(event: "close", listener: () => void): this; prependOnceListener(event: "drain", listener: () => void): this; diff --git a/types/node/http2.d.ts b/types/node/http2.d.ts index bfe10cdea6faa6..c90af90537688f 100644 --- a/types/node/http2.d.ts +++ b/types/node/http2.d.ts @@ -9,6 +9,7 @@ * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/http2.js) */ declare module "http2" { + import { NonSharedBuffer } from "node:buffer"; import EventEmitter = require("node:events"); import * as fs from "node:fs"; import * as net from "node:net"; @@ -191,7 +192,7 @@ declare module "http2" { sendTrailers(headers: OutgoingHttpHeaders): void; addListener(event: "aborted", listener: () => void): this; addListener(event: "close", listener: () => void): this; - addListener(event: "data", listener: (chunk: Buffer | string) => void): this; + addListener(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; addListener(event: "drain", listener: () => void): this; addListener(event: "end", listener: () => void): this; addListener(event: "error", listener: (err: Error) => void): this; @@ -206,7 +207,7 @@ declare module "http2" { addListener(event: string | symbol, listener: (...args: any[]) => void): this; emit(event: "aborted"): boolean; emit(event: "close"): boolean; - emit(event: "data", chunk: Buffer | string): boolean; + emit(event: "data", chunk: NonSharedBuffer | string): boolean; emit(event: "drain"): boolean; emit(event: "end"): boolean; emit(event: "error", err: Error): boolean; @@ -221,7 +222,7 @@ declare module "http2" { emit(event: string | symbol, ...args: any[]): boolean; on(event: "aborted", listener: () => void): this; on(event: "close", listener: () => void): this; - on(event: "data", listener: (chunk: Buffer | string) => void): this; + on(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; on(event: "drain", listener: () => void): this; on(event: "end", listener: () => void): this; on(event: "error", listener: (err: Error) => void): this; @@ -236,7 +237,7 @@ declare module "http2" { on(event: string | symbol, listener: (...args: any[]) => void): this; once(event: "aborted", listener: () => void): this; once(event: "close", listener: () => void): this; - once(event: "data", listener: (chunk: Buffer | string) => void): this; + once(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; once(event: "drain", listener: () => void): this; once(event: "end", listener: () => void): this; once(event: "error", listener: (err: Error) => void): this; @@ -251,7 +252,7 @@ declare module "http2" { once(event: string | symbol, listener: (...args: any[]) => void): this; prependListener(event: "aborted", listener: () => void): this; prependListener(event: "close", listener: () => void): this; - prependListener(event: "data", listener: (chunk: Buffer | string) => void): this; + prependListener(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; prependListener(event: "drain", listener: () => void): this; prependListener(event: "end", listener: () => void): this; prependListener(event: "error", listener: (err: Error) => void): this; @@ -266,7 +267,7 @@ declare module "http2" { prependListener(event: string | symbol, listener: (...args: any[]) => void): this; prependOnceListener(event: "aborted", listener: () => void): this; prependOnceListener(event: "close", listener: () => void): this; - prependOnceListener(event: "data", listener: (chunk: Buffer | string) => void): this; + prependOnceListener(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; prependOnceListener(event: "drain", listener: () => void): this; prependOnceListener(event: "end", listener: () => void): this; prependOnceListener(event: "error", listener: (err: Error) => void): this; @@ -834,10 +835,10 @@ declare module "http2" { * @since v8.9.3 * @param payload Optional ping payload. */ - ping(callback: (err: Error | null, duration: number, payload: Buffer) => void): boolean; + ping(callback: (err: Error | null, duration: number, payload: NonSharedBuffer) => void): boolean; ping( payload: NodeJS.ArrayBufferView, - callback: (err: Error | null, duration: number, payload: Buffer) => void, + callback: (err: Error | null, duration: number, payload: NonSharedBuffer) => void, ): boolean; /** * Calls `ref()` on this `Http2Session` instance's underlying `net.Socket`. @@ -899,7 +900,7 @@ declare module "http2" { ): this; addListener( event: "goaway", - listener: (errorCode: number, lastStreamID: number, opaqueData?: Buffer) => void, + listener: (errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer) => void, ): this; addListener(event: "localSettings", listener: (settings: Settings) => void): this; addListener(event: "ping", listener: () => void): this; @@ -909,7 +910,7 @@ declare module "http2" { emit(event: "close"): boolean; emit(event: "error", err: Error): boolean; emit(event: "frameError", frameType: number, errorCode: number, streamID: number): boolean; - emit(event: "goaway", errorCode: number, lastStreamID: number, opaqueData?: Buffer): boolean; + emit(event: "goaway", errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer): boolean; emit(event: "localSettings", settings: Settings): boolean; emit(event: "ping"): boolean; emit(event: "remoteSettings", settings: Settings): boolean; @@ -918,7 +919,10 @@ declare module "http2" { on(event: "close", listener: () => void): this; on(event: "error", listener: (err: Error) => void): this; on(event: "frameError", listener: (frameType: number, errorCode: number, streamID: number) => void): this; - on(event: "goaway", listener: (errorCode: number, lastStreamID: number, opaqueData?: Buffer) => void): this; + on( + event: "goaway", + listener: (errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer) => void, + ): this; on(event: "localSettings", listener: (settings: Settings) => void): this; on(event: "ping", listener: () => void): this; on(event: "remoteSettings", listener: (settings: Settings) => void): this; @@ -927,7 +931,10 @@ declare module "http2" { once(event: "close", listener: () => void): this; once(event: "error", listener: (err: Error) => void): this; once(event: "frameError", listener: (frameType: number, errorCode: number, streamID: number) => void): this; - once(event: "goaway", listener: (errorCode: number, lastStreamID: number, opaqueData?: Buffer) => void): this; + once( + event: "goaway", + listener: (errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer) => void, + ): this; once(event: "localSettings", listener: (settings: Settings) => void): this; once(event: "ping", listener: () => void): this; once(event: "remoteSettings", listener: (settings: Settings) => void): this; @@ -941,7 +948,7 @@ declare module "http2" { ): this; prependListener( event: "goaway", - listener: (errorCode: number, lastStreamID: number, opaqueData?: Buffer) => void, + listener: (errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer) => void, ): this; prependListener(event: "localSettings", listener: (settings: Settings) => void): this; prependListener(event: "ping", listener: () => void): this; @@ -956,7 +963,7 @@ declare module "http2" { ): this; prependOnceListener( event: "goaway", - listener: (errorCode: number, lastStreamID: number, opaqueData?: Buffer) => void, + listener: (errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer) => void, ): this; prependOnceListener(event: "localSettings", listener: (settings: Settings) => void): this; prependOnceListener(event: "ping", listener: () => void): this; @@ -1916,45 +1923,45 @@ declare module "http2" { * @since v8.4.0 */ setTimeout(msecs: number, callback?: () => void): void; - read(size?: number): Buffer | string | null; + read(size?: number): NonSharedBuffer | string | null; addListener(event: "aborted", listener: (hadError: boolean, code: number) => void): this; addListener(event: "close", listener: () => void): this; - addListener(event: "data", listener: (chunk: Buffer | string) => void): this; + addListener(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; addListener(event: "end", listener: () => void): this; addListener(event: "readable", listener: () => void): this; addListener(event: "error", listener: (err: Error) => void): this; addListener(event: string | symbol, listener: (...args: any[]) => void): this; emit(event: "aborted", hadError: boolean, code: number): boolean; emit(event: "close"): boolean; - emit(event: "data", chunk: Buffer | string): boolean; + emit(event: "data", chunk: NonSharedBuffer | string): boolean; emit(event: "end"): boolean; emit(event: "readable"): boolean; emit(event: "error", err: Error): boolean; emit(event: string | symbol, ...args: any[]): boolean; on(event: "aborted", listener: (hadError: boolean, code: number) => void): this; on(event: "close", listener: () => void): this; - on(event: "data", listener: (chunk: Buffer | string) => void): this; + on(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; on(event: "end", listener: () => void): this; on(event: "readable", listener: () => void): this; on(event: "error", listener: (err: Error) => void): this; on(event: string | symbol, listener: (...args: any[]) => void): this; once(event: "aborted", listener: (hadError: boolean, code: number) => void): this; once(event: "close", listener: () => void): this; - once(event: "data", listener: (chunk: Buffer | string) => void): this; + once(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; once(event: "end", listener: () => void): this; once(event: "readable", listener: () => void): this; once(event: "error", listener: (err: Error) => void): this; once(event: string | symbol, listener: (...args: any[]) => void): this; prependListener(event: "aborted", listener: (hadError: boolean, code: number) => void): this; prependListener(event: "close", listener: () => void): this; - prependListener(event: "data", listener: (chunk: Buffer | string) => void): this; + prependListener(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; prependListener(event: "end", listener: () => void): this; prependListener(event: "readable", listener: () => void): this; prependListener(event: "error", listener: (err: Error) => void): this; prependListener(event: string | symbol, listener: (...args: any[]) => void): this; prependOnceListener(event: "aborted", listener: (hadError: boolean, code: number) => void): this; prependOnceListener(event: "close", listener: () => void): this; - prependOnceListener(event: "data", listener: (chunk: Buffer | string) => void): this; + prependOnceListener(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; prependOnceListener(event: "end", listener: () => void): this; prependOnceListener(event: "readable", listener: () => void): this; prependOnceListener(event: "error", listener: (err: Error) => void): this; @@ -2614,7 +2621,7 @@ declare module "http2" { * ``` * @since v8.4.0 */ - export function getPackedSettings(settings: Settings): Buffer; + export function getPackedSettings(settings: Settings): NonSharedBuffer; /** * Returns a `HTTP/2 Settings Object` containing the deserialized settings from * the given `Buffer` as generated by `http2.getPackedSettings()`. diff --git a/types/node/https.d.ts b/types/node/https.d.ts index 1348d59086b282..53de0b9aa9ee97 100644 --- a/types/node/https.d.ts +++ b/types/node/https.d.ts @@ -4,6 +4,7 @@ * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/https.js) */ declare module "https" { + import { NonSharedBuffer } from "node:buffer"; import { Duplex } from "node:stream"; import * as tls from "node:tls"; import * as http from "node:http"; @@ -63,22 +64,25 @@ declare module "https" { */ closeIdleConnections(): void; addListener(event: string, listener: (...args: any[]) => void): this; - addListener(event: "keylog", listener: (line: Buffer, tlsSocket: tls.TLSSocket) => void): this; + addListener(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: tls.TLSSocket) => void): this; addListener( event: "newSession", - listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void, + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, ): this; addListener( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; addListener( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; addListener(event: "secureConnection", listener: (tlsSocket: tls.TLSSocket) => void): this; addListener(event: "tlsClientError", listener: (err: Error, tlsSocket: tls.TLSSocket) => void): this; @@ -91,28 +95,32 @@ declare module "https" { addListener(event: "clientError", listener: (err: Error, socket: Duplex) => void): this; addListener( event: "connect", - listener: (req: InstanceType, socket: Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, ): this; addListener(event: "request", listener: http.RequestListener): this; addListener( event: "upgrade", - listener: (req: InstanceType, socket: Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, ): this; emit(event: string, ...args: any[]): boolean; - emit(event: "keylog", line: Buffer, tlsSocket: tls.TLSSocket): boolean; + emit(event: "keylog", line: NonSharedBuffer, tlsSocket: tls.TLSSocket): boolean; emit( event: "newSession", - sessionId: Buffer, - sessionData: Buffer, - callback: (err: Error, resp: Buffer) => void, + sessionId: NonSharedBuffer, + sessionData: NonSharedBuffer, + callback: () => void, ): boolean; emit( event: "OCSPRequest", - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, + ): boolean; + emit( + event: "resumeSession", + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, ): boolean; - emit(event: "resumeSession", sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void): boolean; emit(event: "secureConnection", tlsSocket: tls.TLSSocket): boolean; emit(event: "tlsClientError", err: Error, tlsSocket: tls.TLSSocket): boolean; emit(event: "close"): boolean; @@ -130,30 +138,33 @@ declare module "https" { res: InstanceType, ): boolean; emit(event: "clientError", err: Error, socket: Duplex): boolean; - emit(event: "connect", req: InstanceType, socket: Duplex, head: Buffer): boolean; + emit(event: "connect", req: InstanceType, socket: Duplex, head: NonSharedBuffer): boolean; emit( event: "request", req: InstanceType, res: InstanceType, ): boolean; - emit(event: "upgrade", req: InstanceType, socket: Duplex, head: Buffer): boolean; + emit(event: "upgrade", req: InstanceType, socket: Duplex, head: NonSharedBuffer): boolean; on(event: string, listener: (...args: any[]) => void): this; - on(event: "keylog", listener: (line: Buffer, tlsSocket: tls.TLSSocket) => void): this; + on(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: tls.TLSSocket) => void): this; on( event: "newSession", - listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void, + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, ): this; on( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; on( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; on(event: "secureConnection", listener: (tlsSocket: tls.TLSSocket) => void): this; on(event: "tlsClientError", listener: (err: Error, tlsSocket: tls.TLSSocket) => void): this; @@ -164,26 +175,35 @@ declare module "https" { on(event: "checkContinue", listener: http.RequestListener): this; on(event: "checkExpectation", listener: http.RequestListener): this; on(event: "clientError", listener: (err: Error, socket: Duplex) => void): this; - on(event: "connect", listener: (req: InstanceType, socket: Duplex, head: Buffer) => void): this; + on( + event: "connect", + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, + ): this; on(event: "request", listener: http.RequestListener): this; - on(event: "upgrade", listener: (req: InstanceType, socket: Duplex, head: Buffer) => void): this; + on( + event: "upgrade", + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, + ): this; once(event: string, listener: (...args: any[]) => void): this; - once(event: "keylog", listener: (line: Buffer, tlsSocket: tls.TLSSocket) => void): this; + once(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: tls.TLSSocket) => void): this; once( event: "newSession", - listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void, + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, ): this; once( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; once( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; once(event: "secureConnection", listener: (tlsSocket: tls.TLSSocket) => void): this; once(event: "tlsClientError", listener: (err: Error, tlsSocket: tls.TLSSocket) => void): this; @@ -194,26 +214,35 @@ declare module "https" { once(event: "checkContinue", listener: http.RequestListener): this; once(event: "checkExpectation", listener: http.RequestListener): this; once(event: "clientError", listener: (err: Error, socket: Duplex) => void): this; - once(event: "connect", listener: (req: InstanceType, socket: Duplex, head: Buffer) => void): this; + once( + event: "connect", + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, + ): this; once(event: "request", listener: http.RequestListener): this; - once(event: "upgrade", listener: (req: InstanceType, socket: Duplex, head: Buffer) => void): this; + once( + event: "upgrade", + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, + ): this; prependListener(event: string, listener: (...args: any[]) => void): this; - prependListener(event: "keylog", listener: (line: Buffer, tlsSocket: tls.TLSSocket) => void): this; + prependListener(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: tls.TLSSocket) => void): this; prependListener( event: "newSession", - listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void, + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, ): this; prependListener( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; prependListener( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; prependListener(event: "secureConnection", listener: (tlsSocket: tls.TLSSocket) => void): this; prependListener(event: "tlsClientError", listener: (err: Error, tlsSocket: tls.TLSSocket) => void): this; @@ -226,30 +255,33 @@ declare module "https" { prependListener(event: "clientError", listener: (err: Error, socket: Duplex) => void): this; prependListener( event: "connect", - listener: (req: InstanceType, socket: Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, ): this; prependListener(event: "request", listener: http.RequestListener): this; prependListener( event: "upgrade", - listener: (req: InstanceType, socket: Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, ): this; prependOnceListener(event: string, listener: (...args: any[]) => void): this; - prependOnceListener(event: "keylog", listener: (line: Buffer, tlsSocket: tls.TLSSocket) => void): this; + prependOnceListener(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: tls.TLSSocket) => void): this; prependOnceListener( event: "newSession", - listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void, + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, ): this; prependOnceListener( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; prependOnceListener( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; prependOnceListener(event: "secureConnection", listener: (tlsSocket: tls.TLSSocket) => void): this; prependOnceListener(event: "tlsClientError", listener: (err: Error, tlsSocket: tls.TLSSocket) => void): this; @@ -262,12 +294,12 @@ declare module "https" { prependOnceListener(event: "clientError", listener: (err: Error, socket: Duplex) => void): this; prependOnceListener( event: "connect", - listener: (req: InstanceType, socket: Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, ): this; prependOnceListener(event: "request", listener: http.RequestListener): this; prependOnceListener( event: "upgrade", - listener: (req: InstanceType, socket: Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, ): this; } /** diff --git a/types/node/net.d.ts b/types/node/net.d.ts index 2e70d909087252..38c1627505dba0 100644 --- a/types/node/net.d.ts +++ b/types/node/net.d.ts @@ -13,6 +13,7 @@ * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/net.js) */ declare module "net" { + import { NonSharedBuffer } from "node:buffer"; import * as stream from "node:stream"; import { Abortable, EventEmitter } from "node:events"; import * as dns from "node:dns"; @@ -380,7 +381,7 @@ declare module "net" { event: "connectionAttemptTimeout", listener: (ip: string, port: number, family: number) => void, ): this; - addListener(event: "data", listener: (data: Buffer) => void): this; + addListener(event: "data", listener: (data: NonSharedBuffer) => void): this; addListener(event: "drain", listener: () => void): this; addListener(event: "end", listener: () => void): this; addListener(event: "error", listener: (err: Error) => void): this; @@ -396,7 +397,7 @@ declare module "net" { emit(event: "connectionAttempt", ip: string, port: number, family: number): boolean; emit(event: "connectionAttemptFailed", ip: string, port: number, family: number, error: Error): boolean; emit(event: "connectionAttemptTimeout", ip: string, port: number, family: number): boolean; - emit(event: "data", data: Buffer): boolean; + emit(event: "data", data: NonSharedBuffer): boolean; emit(event: "drain"): boolean; emit(event: "end"): boolean; emit(event: "error", err: Error): boolean; @@ -412,7 +413,7 @@ declare module "net" { listener: (ip: string, port: number, family: number, error: Error) => void, ): this; on(event: "connectionAttemptTimeout", listener: (ip: string, port: number, family: number) => void): this; - on(event: "data", listener: (data: Buffer) => void): this; + on(event: "data", listener: (data: NonSharedBuffer) => void): this; on(event: "drain", listener: () => void): this; on(event: "end", listener: () => void): this; on(event: "error", listener: (err: Error) => void): this; @@ -431,7 +432,7 @@ declare module "net" { ): this; once(event: "connectionAttemptTimeout", listener: (ip: string, port: number, family: number) => void): this; once(event: "connect", listener: () => void): this; - once(event: "data", listener: (data: Buffer) => void): this; + once(event: "data", listener: (data: NonSharedBuffer) => void): this; once(event: "drain", listener: () => void): this; once(event: "end", listener: () => void): this; once(event: "error", listener: (err: Error) => void): this; @@ -453,7 +454,7 @@ declare module "net" { event: "connectionAttemptTimeout", listener: (ip: string, port: number, family: number) => void, ): this; - prependListener(event: "data", listener: (data: Buffer) => void): this; + prependListener(event: "data", listener: (data: NonSharedBuffer) => void): this; prependListener(event: "drain", listener: () => void): this; prependListener(event: "end", listener: () => void): this; prependListener(event: "error", listener: (err: Error) => void): this; @@ -478,7 +479,7 @@ declare module "net" { event: "connectionAttemptTimeout", listener: (ip: string, port: number, family: number) => void, ): this; - prependOnceListener(event: "data", listener: (data: Buffer) => void): this; + prependOnceListener(event: "data", listener: (data: NonSharedBuffer) => void): this; prependOnceListener(event: "drain", listener: () => void): this; prependOnceListener(event: "end", listener: () => void): this; prependOnceListener(event: "error", listener: (err: Error) => void): this; diff --git a/types/node/os.d.ts b/types/node/os.d.ts index 3ff1c1bc5a5d14..505f5b44d6495f 100644 --- a/types/node/os.d.ts +++ b/types/node/os.d.ts @@ -8,6 +8,7 @@ * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/os.js) */ declare module "os" { + import { NonSharedBuffer } from "buffer"; interface CpuInfo { model: string; speed: number; @@ -253,9 +254,9 @@ declare module "os" { * Throws a [`SystemError`](https://nodejs.org/docs/latest-v24.x/api/errors.html#class-systemerror) if a user has no `username` or `homedir`. * @since v6.0.0 */ - function userInfo(options: UserInfoOptionsWithBufferEncoding): UserInfo; function userInfo(options?: UserInfoOptionsWithStringEncoding): UserInfo; - function userInfo(options: UserInfoOptions): UserInfo; + function userInfo(options: UserInfoOptionsWithBufferEncoding): UserInfo; + function userInfo(options: UserInfoOptions): UserInfo; type SignalConstants = { [key in NodeJS.Signals]: number; }; diff --git a/types/node/process.d.ts b/types/node/process.d.ts index c152531c39b1dd..ba862d56fc405e 100644 --- a/types/node/process.d.ts +++ b/types/node/process.d.ts @@ -1,5 +1,6 @@ declare module "process" { import { Control, MessageOptions } from "node:child_process"; + import { PathLike } from "node:fs"; import * as tty from "node:tty"; import { Worker } from "node:worker_threads"; @@ -1466,7 +1467,7 @@ declare module "process" { * @since v20.12.0 * @param path The path to the .env file */ - loadEnvFile(path?: string | URL | Buffer): void; + loadEnvFile(path?: PathLike): void; /** * The `process.pid` property returns the PID of the process. * diff --git a/types/node/sqlite.d.ts b/types/node/sqlite.d.ts index 4a533758bbca53..d10855b02cf953 100644 --- a/types/node/sqlite.d.ts +++ b/types/node/sqlite.d.ts @@ -43,10 +43,9 @@ * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/sqlite.js) */ declare module "node:sqlite" { + import { PathLike } from "node:fs"; type SQLInputValue = null | number | bigint | string | NodeJS.ArrayBufferView; - type SQLOutputValue = null | number | bigint | string | Uint8Array; - /** @deprecated Use `SQLInputValue` or `SQLOutputValue` instead. */ - type SupportedValueType = SQLOutputValue; + type SQLOutputValue = null | number | bigint | string | NodeJS.NonSharedUint8Array; interface DatabaseSyncOptions { /** * If `true`, the database is opened by the constructor. When @@ -240,7 +239,7 @@ declare module "node:sqlite" { * To use an in-memory database, the path should be the special name `':memory:'`. * @param options Configuration options for the database connection. */ - constructor(path: string | Buffer | URL, options?: DatabaseSyncOptions); + constructor(path: PathLike, options?: DatabaseSyncOptions); /** * Registers a new aggregate function with the SQLite database. This method is a wrapper around * [`sqlite3_create_window_function()`](https://www.sqlite.org/c3ref/create_function.html). @@ -451,7 +450,7 @@ declare module "node:sqlite" { * @returns Binary changeset that can be applied to other databases. * @since v22.12.0 */ - changeset(): Uint8Array; + changeset(): NodeJS.NonSharedUint8Array; /** * Similar to the method above, but generates a more compact patchset. See * [Changesets and Patchsets](https://www.sqlite.org/sessionintro.html#changesets_and_patchsets) @@ -461,7 +460,7 @@ declare module "node:sqlite" { * @returns Binary patchset that can be applied to other databases. * @since v22.12.0 */ - patchset(): Uint8Array; + patchset(): NodeJS.NonSharedUint8Array; /** * Closes the session. An exception is thrown if the database or the session is not open. This method is a * wrapper around @@ -787,7 +786,7 @@ declare module "node:sqlite" { * @returns A promise that fulfills with the total number of backed-up pages upon completion, or rejects if an * error occurs. */ - function backup(sourceDb: DatabaseSync, path: string | Buffer | URL, options?: BackupOptions): Promise; + function backup(sourceDb: DatabaseSync, path: PathLike, options?: BackupOptions): Promise; /** * @since v22.13.0 */ diff --git a/types/node/stream/consumers.d.ts b/types/node/stream/consumers.d.ts index 746d6e508266ac..05db0257d276a5 100644 --- a/types/node/stream/consumers.d.ts +++ b/types/node/stream/consumers.d.ts @@ -4,7 +4,7 @@ * @since v16.7.0 */ declare module "stream/consumers" { - import { Blob as NodeBlob } from "node:buffer"; + import { Blob as NodeBlob, NonSharedBuffer } from "node:buffer"; import { ReadableStream as WebReadableStream } from "node:stream/web"; /** * @since v16.7.0 @@ -20,7 +20,7 @@ declare module "stream/consumers" { * @since v16.7.0 * @returns Fulfills with a `Buffer` containing the full contents of the stream. */ - function buffer(stream: WebReadableStream | NodeJS.ReadableStream | AsyncIterable): Promise; + function buffer(stream: WebReadableStream | NodeJS.ReadableStream | AsyncIterable): Promise; /** * @since v16.7.0 * @returns Fulfills with the contents of the stream parsed as a diff --git a/types/node/string_decoder.d.ts b/types/node/string_decoder.d.ts index 3632c163006ba2..bcd64d5a32fd72 100644 --- a/types/node/string_decoder.d.ts +++ b/types/node/string_decoder.d.ts @@ -48,7 +48,7 @@ declare module "string_decoder" { * @since v0.1.99 * @param buffer The bytes to decode. */ - write(buffer: string | Buffer | NodeJS.ArrayBufferView): string; + write(buffer: string | NodeJS.ArrayBufferView): string; /** * Returns any remaining input stored in the internal buffer as a string. Bytes * representing incomplete UTF-8 and UTF-16 characters will be replaced with @@ -59,7 +59,7 @@ declare module "string_decoder" { * @since v0.9.3 * @param buffer The bytes to decode. */ - end(buffer?: string | Buffer | NodeJS.ArrayBufferView): string; + end(buffer?: string | NodeJS.ArrayBufferView): string; } } declare module "node:string_decoder" { diff --git a/types/node/test/buffer.ts b/types/node/test/buffer.ts index 21993e78a1d245..3356f2d4046bfd 100644 --- a/types/node/test/buffer.ts +++ b/types/node/test/buffer.ts @@ -345,11 +345,11 @@ result = b.write("asd", 123, 123, "hex"); // Buffer module, transcode function { - transcode(Buffer.from("€"), "utf8", "ascii"); // $ExpectType Buffer || Buffer + transcode(Buffer.from("€"), "utf8", "ascii"); // $ExpectType NonSharedBuffer const source: TranscodeEncoding = "utf8"; const target: TranscodeEncoding = "ascii"; - transcode(Buffer.from("€"), source, target); // $ExpectType Buffer || Buffer + transcode(Buffer.from("€"), source, target); // $ExpectType NonSharedBuffer } { diff --git a/types/node/test/child_process.ts b/types/node/test/child_process.ts index 4b480362aacce3..1f83f8b31e402f 100644 --- a/types/node/test/child_process.ts +++ b/types/node/test/child_process.ts @@ -25,15 +25,15 @@ import { promisify } from "node:util"; childProcess.spawnSync("echo test", { encoding: "buffer" }); childProcess.spawnSync("echo test", { cwd: new URL("file://aaaaaaaa") }); - childProcess.spawnSync("echo test").output; // $ExpectType (Buffer | null)[] || (Buffer | null)[] - childProcess.spawnSync("echo test", {}).output; // $ExpectType (Buffer | null)[] || (Buffer | null)[] - childProcess.spawnSync("echo test", { encoding: "buffer" }).output; // $ExpectType (Buffer | null)[] || (Buffer | null)[] + childProcess.spawnSync("echo test").output; // $ExpectType (NonSharedBuffer | null)[] + childProcess.spawnSync("echo test", {}).output; // $ExpectType (NonSharedBuffer | null)[] + childProcess.spawnSync("echo test", { encoding: "buffer" }).output; // $ExpectType (NonSharedBuffer | null)[] childProcess.spawnSync("echo test", { encoding: "utf-8" }).output; // $ExpectType (string | null)[] - childProcess.spawnSync("echo", ["test"]).output; // $ExpectType (Buffer | null)[] || (Buffer | null)[] - childProcess.spawnSync("echo test", ["test"], {}).output; // $ExpectType (Buffer | null)[] || (Buffer | null)[] - childProcess.spawnSync("echo test", ["test"], { encoding: "buffer" }).output; // $ExpectType (Buffer | null)[] || (Buffer | null)[] + childProcess.spawnSync("echo", ["test"]).output; // $ExpectType (NonSharedBuffer | null)[] + childProcess.spawnSync("echo test", ["test"], {}).output; // $ExpectType (NonSharedBuffer | null)[] + childProcess.spawnSync("echo test", ["test"], { encoding: "buffer" }).output; // $ExpectType (NonSharedBuffer | null)[] childProcess.spawnSync("echo test", ["test"], { encoding: "utf-8" }).output; // $ExpectType (string | null)[] - ((opts?: childProcess.SpawnSyncOptions) => childProcess.spawnSync("echo test", opts))().output; // $ExpectType (string | Buffer | null)[] || (string | Buffer | null)[] + ((opts?: childProcess.SpawnSyncOptions) => childProcess.spawnSync("echo test", opts))().output; // $ExpectType (string | NonSharedBuffer | null)[] } { @@ -117,13 +117,13 @@ import { promisify } from "node:util"; (error, stdout, stderr) => { // $ExpectType ExecException | null error; - // $ExpectType Buffer + // $ExpectType NonSharedBuffer stdout; - // $ExpectType Buffer + // $ExpectType NonSharedBuffer stderr; }, ); - // $ExpectType PromiseWithChild<{ stdout: Buffer; stderr: Buffer; }> + // $ExpectType PromiseWithChild<{ stdout: NonSharedBuffer; stderr: NonSharedBuffer; }> promisifiedExec(cmd, { encoding: boolFlag ? "buffer" : null }); // with known encoding @@ -151,13 +151,13 @@ import { promisify } from "node:util"; (error, stdout, stderr) => { // $ExpectType ExecException | null error; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stdout; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stderr; }, ); - // $ExpectType PromiseWithChild<{ stdout: string | Buffer; stderr: string | Buffer; }> + // $ExpectType PromiseWithChild<{ stdout: string | NonSharedBuffer; stderr: string | NonSharedBuffer; }> promisifiedExec(cmd, { encoding: "unknown" }); // with nullish encoding @@ -168,22 +168,22 @@ import { promisify } from "node:util"; (error, stdout, stderr) => { // $ExpectType ExecException | null error; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stdout; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stderr; }, ); - // $ExpectType PromiseWithChild<{ stdout: string | Buffer; stderr: string | Buffer; }> + // $ExpectType PromiseWithChild<{ stdout: string | NonSharedBuffer; stderr: string | NonSharedBuffer; }> promisifiedExec(cmd, boolFlag ? { encoding: "unknown" } : null); } { - childProcess.execSync("echo test"); // $ExpectType Buffer || Buffer - childProcess.execSync("echo test", {}); // $ExpectType Buffer || Buffer - childProcess.execSync("echo test", { encoding: "buffer" }); // $ExpectType Buffer || Buffer + childProcess.execSync("echo test"); // $ExpectType NonSharedBuffer + childProcess.execSync("echo test", {}); // $ExpectType NonSharedBuffer + childProcess.execSync("echo test", { encoding: "buffer" }); // $ExpectType NonSharedBuffer childProcess.execSync("echo test", { encoding: "utf-8" }); // $ExpectType string - ((opts?: childProcess.ExecSyncOptions) => childProcess.execSync("echo test", opts))(); // $ExpectType string | Buffer || string | Buffer + ((opts?: childProcess.ExecSyncOptions) => childProcess.execSync("echo test", opts))(); // $ExpectType string | NonSharedBuffer childProcess.execSync("git status", { // $ExpectType string cwd: "test", input: "test", @@ -346,13 +346,13 @@ import { promisify } from "node:util"; (error, stdout, stderr) => { // $ExpectType ExecFileException | null error; - // $ExpectType Buffer + // $ExpectType NonSharedBuffer stdout; - // $ExpectType Buffer + // $ExpectType NonSharedBuffer stderr; }, ); - // $ExpectType PromiseWithChild<{ stdout: Buffer; stderr: Buffer; }> + // $ExpectType PromiseWithChild<{ stdout: NonSharedBuffer; stderr: NonSharedBuffer; }> promisifiedExecFile(cmd, { encoding: boolFlag ? "buffer" : null }); // $ExpectType ChildProcess childProcess.execFile( @@ -362,13 +362,13 @@ import { promisify } from "node:util"; (error, stdout, stderr) => { // $ExpectType ExecFileException | null error; - // $ExpectType Buffer + // $ExpectType NonSharedBuffer stdout; - // $ExpectType Buffer + // $ExpectType NonSharedBuffer stderr; }, ); - // $ExpectType PromiseWithChild<{ stdout: Buffer; stderr: Buffer; }> + // $ExpectType PromiseWithChild<{ stdout: NonSharedBuffer; stderr: NonSharedBuffer; }> promisifiedExecFile(cmd, args, { encoding: boolFlag ? "buffer" : null }); // with known encoding @@ -413,13 +413,13 @@ import { promisify } from "node:util"; (error, stdout, stderr) => { // $ExpectType ExecFileException | null error; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stdout; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stderr; }, ); - // $ExpectType PromiseWithChild<{ stdout: string | Buffer; stderr: string | Buffer; }> + // $ExpectType PromiseWithChild<{ stdout: string | NonSharedBuffer; stderr: string | NonSharedBuffer; }> promisifiedExecFile(cmd, { encoding: "unknown" }); // $ExpectType ChildProcess childProcess.execFile( @@ -429,13 +429,13 @@ import { promisify } from "node:util"; (error, stdout, stderr) => { // $ExpectType ExecFileException | null error; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stdout; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stderr; }, ); - // $ExpectType PromiseWithChild<{ stdout: string | Buffer; stderr: string | Buffer; }> + // $ExpectType PromiseWithChild<{ stdout: string | NonSharedBuffer; stderr: string | NonSharedBuffer; }> promisifiedExecFile(cmd, args, { encoding: "unknown" }); // with nullish encoding @@ -446,13 +446,13 @@ import { promisify } from "node:util"; (error, stdout, stderr) => { // $ExpectType ExecFileException | null error; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stdout; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stderr; }, ); - // $ExpectType PromiseWithChild<{ stdout: string | Buffer; stderr: string | Buffer; }> + // $ExpectType PromiseWithChild<{ stdout: string | NonSharedBuffer; stderr: string | NonSharedBuffer; }> promisifiedExecFile(cmd, boolFlag ? { encoding: "unknown" } : null); // $ExpectType ChildProcess childProcess.execFile( @@ -462,13 +462,13 @@ import { promisify } from "node:util"; (error, stdout, stderr) => { // $ExpectType ExecFileException | null error; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stdout; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stderr; }, ); - // $ExpectType PromiseWithChild<{ stdout: string | Buffer; stderr: string | Buffer; }> + // $ExpectType PromiseWithChild<{ stdout: string | NonSharedBuffer; stderr: string | NonSharedBuffer; }> promisifiedExecFile(cmd, args, boolFlag ? { encoding: "unknown" } : null); } @@ -481,15 +481,15 @@ import { promisify } from "node:util"; childProcess.execFileSync("echo test", { input: new Uint8Array([]) }); childProcess.execFileSync("echo test", { input: new DataView(new ArrayBuffer(1)) }); - childProcess.execFileSync("echo test"); // $ExpectType Buffer || Buffer - childProcess.execFileSync("echo test", {}); // $ExpectType Buffer || Buffer - childProcess.execFileSync("echo test", { encoding: "buffer" }); // $ExpectType Buffer || Buffer + childProcess.execFileSync("echo test"); // $ExpectType NonSharedBuffer + childProcess.execFileSync("echo test", {}); // $ExpectType NonSharedBuffer + childProcess.execFileSync("echo test", { encoding: "buffer" }); // $ExpectType NonSharedBuffer childProcess.execFileSync("echo test", { encoding: "utf8" }); // $ExpectType string - childProcess.execFileSync("echo test", ["test"]); // $ExpectType Buffer || Buffer - childProcess.execFileSync("echo test", ["test"], {}); // $ExpectType Buffer || Buffer - childProcess.execFileSync("echo test", ["test"], { encoding: "buffer" }); // $ExpectType Buffer || Buffer + childProcess.execFileSync("echo test", ["test"]); // $ExpectType NonSharedBuffer + childProcess.execFileSync("echo test", ["test"], {}); // $ExpectType NonSharedBuffer + childProcess.execFileSync("echo test", ["test"], { encoding: "buffer" }); // $ExpectType NonSharedBuffer childProcess.execFileSync("echo test", ["test"], { encoding: "utf8" }); // $ExpectType string - ((opts?: childProcess.ExecFileSyncOptions) => childProcess.execFileSync("echo test", ["args"], opts))(); // $ExpectType string | Buffer || string | Buffer + ((opts?: childProcess.ExecFileSyncOptions) => childProcess.execFileSync("echo test", ["args"], opts))(); // $ExpectType string | NonSharedBuffer } { diff --git a/types/node/test/crypto.ts b/types/node/test/crypto.ts index bef5920ae5fa66..99205d51865bab 100644 --- a/types/node/test/crypto.ts +++ b/types/node/test/crypto.ts @@ -189,7 +189,7 @@ import { promisify } from "node:util"; const cipher = crypto.createCipheriv("aes-192-cbc", key, nonce); const plaintext = "Hello world"; - // $ExpectType Buffer || Buffer + // $ExpectType NonSharedBuffer const cipherBuf = cipher.update(plaintext, "utf8"); cipher.final(); @@ -206,12 +206,12 @@ import { promisify } from "node:util"; const cipher = crypto.createCipheriv("aes-192-cbc", key, nonce); const plaintext = "Hello world"; - // $ExpectType Buffer || Buffer + // $ExpectType NonSharedBuffer const cipherBuf = cipher.update(plaintext, "utf8"); cipher.final(); const decipher = crypto.createDecipheriv("aes-192-cbc", key, nonce); - // $ExpectType Buffer || Buffer + // $ExpectType NonSharedBuffer const receivedPlaintext = decipher.update(cipherBuf); decipher.final(); } @@ -231,7 +231,7 @@ import { promisify } from "node:util"; }, }); cipher = cipher.setAAD(Buffer.from([]), { plaintextLength: 0 }); - // $ExpectType Buffer + // $ExpectType NonSharedBuffer cipher.getAuthTag(); } @@ -248,7 +248,7 @@ import { promisify } from "node:util"; }, }); cipher = cipher.setAAD(Buffer.from([]), { plaintextLength: 0 }); - // $ExpectType Buffer + // $ExpectType NonSharedBuffer cipher.getAuthTag(); } @@ -264,7 +264,7 @@ import { promisify } from "node:util"; }, }); cipher = cipher.setAAD(Buffer.from([]), { plaintextLength: 0 }); - // $ExpectType Buffer + // $ExpectType NonSharedBuffer cipher.getAuthTag(); } @@ -281,7 +281,7 @@ import { promisify } from "node:util"; }, }); cipher = cipher.setAAD(Buffer.from([]), { plaintextLength: 0 }); - // $ExpectType Buffer + // $ExpectType NonSharedBuffer cipher.getAuthTag(); } @@ -1230,20 +1230,20 @@ import { promisify } from "node:util"; crypto.diffieHellman({ privateKey: privateKeyObject1, publicKey: publicKeyObject1 }, (err, secret) => { err; // $ExpectType Error | null - secret; // $ExpectType Buffer || Buffer + secret; // $ExpectType NonSharedBuffer }); } { // $ExpectType string crypto.hash("sha1", "Node.js"); - // $ExpectType Buffer || Buffer + // $ExpectType NonSharedBuffer crypto.hash("sha1", Buffer.from("Tm9kZS5qcw==", "base64"), "buffer"); // $ExpectType string crypto.hash("shake256", "Node.js", { outputLength: 256 }); // $ExpectType string crypto.hash("shake256", Buffer.allocUnsafe(0), { outputEncoding: "base64" }); - // $ExpectType Buffer || Buffer + // $ExpectType NonSharedBuffer crypto.hash("shake256", "Node.js", { outputEncoding: "buffer", outputLength: 256 }); } @@ -1571,7 +1571,7 @@ import { promisify } from "node:util"; cert.issuerCertificate; // $ExpectType X509Certificate | undefined cert.keyUsage; // $ExpectType string[] cert.publicKey; // $ExpectType KeyObject - cert.raw; // $ExpectType Buffer || Buffer + cert.raw; // $ExpectType NonSharedBuffer cert.serialNumber; // $ExpectType string cert.signatureAlgorithm; // $ExpectType string | undefined cert.signatureAlgorithmOid; // $ExpectType string @@ -1752,7 +1752,7 @@ import { promisify } from "node:util"; alice.generateKeys(); - let alicePublicKey = alice.getPublicKey(); // $ExpectType Buffer || Buffer + let alicePublicKey = alice.getPublicKey(); // $ExpectType NonSharedBuffer alicePublicKey = alice.getPublicKey(null); alicePublicKey = alice.getPublicKey(null, "compressed"); alicePublicKey = alice.getPublicKey(undefined, "hybrid"); @@ -1760,7 +1760,7 @@ import { promisify } from "node:util"; let bobPublicKey = bob.getPublicKey("hex"); // $ExpectType string bobPublicKey = bob.getPublicKey("hex", "compressed"); - let aliceSecret = alice.computeSecret(bobPublicKey, "hex"); // $ExpectType Buffer || Buffer + let aliceSecret = alice.computeSecret(bobPublicKey, "hex"); // $ExpectType NonSharedBuffer aliceSecret = alice.computeSecret(Buffer.from(bobPublicKey, "hex")); let bobSecret = bob.computeSecret(alicePublicKey, "hex"); // $ExpectType string @@ -1882,9 +1882,9 @@ import { promisify } from "node:util"; }; crypto.argon2("argon2i", parameters, (err, derivedKey) => { err; // $ExpectType Error | null - derivedKey; // $ExpectType Buffer || Buffer + derivedKey; // $ExpectType NonSharedBuffer }); - crypto.argon2Sync("argon2i", parameters); // $ExpectType Buffer || Buffer + crypto.argon2Sync("argon2i", parameters); // $ExpectType NonSharedBuffer } { diff --git a/types/node/test/dgram.ts b/types/node/test/dgram.ts index 4b90f9a82dc86b..41cb9c02ae3016 100644 --- a/types/node/test/dgram.ts +++ b/types/node/test/dgram.ts @@ -140,7 +140,7 @@ sock = dgram.createSocket({ lookup: dns.lookup, }); sock = dgram.createSocket("udp6", (msg, rinfo) => { - msg; // $ExpectType Buffer || Buffer + msg; // $ExpectType NonSharedBuffer rinfo; // $ExpectType RemoteInfo }); sock.addMembership("233.252.0.0"); @@ -201,7 +201,7 @@ sock.on("error", (exception) => { }); sock.on("listening", () => undefined); sock.on("message", (msg, rinfo) => { - msg; // $ExpectType Buffer || Buffer + msg; // $ExpectType NonSharedBuffer rinfo.address; // $ExpectType string rinfo.family; // $ExpectType "IPv4" | "IPv6" rinfo.port; // $ExpectType number diff --git a/types/node/test/fs.ts b/types/node/test/fs.ts index 7dde671d155992..1c41788e61ca2f 100644 --- a/types/node/test/fs.ts +++ b/types/node/test/fs.ts @@ -472,21 +472,21 @@ async function testPromisify() { fs.writev( 1, [Buffer.from("123")] as readonly NodeJS.ArrayBufferView[], - (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => { + (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: readonly NodeJS.ArrayBufferView[]) => { }, ); fs.writev( 1, [Buffer.from("123")] as readonly NodeJS.ArrayBufferView[], 123, - (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => { + (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: readonly NodeJS.ArrayBufferView[]) => { }, ); fs.writev( 1, [Buffer.from("123")] as readonly NodeJS.ArrayBufferView[], null, - (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => { + (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: readonly NodeJS.ArrayBufferView[]) => { }, ); const bytesWritten = fs.writevSync(1, [Buffer.from("123")] as readonly NodeJS.ArrayBufferView[]); @@ -625,7 +625,7 @@ async function testPromisify() { const _rom = readStream.readableObjectMode; // $ExpectType boolean - (await handle.read()).buffer; // $ExpectType Buffer || Buffer + (await handle.read()).buffer; // $ExpectType NonSharedBuffer (await handle.read({ buffer: new Uint32Array(), offset: 1, @@ -701,14 +701,14 @@ async function testPromisify() { 123, [Buffer.from("wut")] as readonly NodeJS.ArrayBufferView[], 123, - (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => { + (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: readonly NodeJS.ArrayBufferView[]) => { }, ); fs.readv( 123, [Buffer.from("wut")] as readonly NodeJS.ArrayBufferView[], null, - (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => { + (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: readonly NodeJS.ArrayBufferView[]) => { }, ); } @@ -942,9 +942,9 @@ const anyStatFs: fs.StatsFs | fs.BigIntStatsFs = fs.statfsSync(".", { bigint: Ma { // $ExpectType AsyncIterator, undefined, any> watchAsync("y33t"); - // $ExpectType AsyncIterator, undefined, any> || AsyncIterator>, undefined, any> + // $ExpectType AsyncIterator, undefined, any> watchAsync("y33t", "buffer"); - // $ExpectType AsyncIterator, undefined, any> || AsyncIterator>, undefined, any> + // $ExpectType AsyncIterator, undefined, any> watchAsync("y33t", { encoding: "buffer", signal: new AbortSignal() }); // $ExpectType AsyncIterator, undefined, any> watchAsync("test", { persistent: true, recursive: true, encoding: "utf-8", maxQueue: 2048, overflow: "ignore" }); diff --git a/types/node/test/https.ts b/types/node/test/https.ts index 419f85902eaa64..75d628e9a3f932 100644 --- a/types/node/test/https.ts +++ b/types/node/test/https.ts @@ -324,7 +324,7 @@ import * as url from "node:url"; let _buffer: Buffer = Buffer.from(""); let _err = new Error(); let _boolean = true; - let sessionCallback = (err: Error, resp: Buffer) => {}; + let sessionCallback = (err: Error | null, resp: Buffer) => {}; let ocspRequestCallback = (err: Error | null, resp: Buffer) => {}; server = server.addListener("keylog", (ln, tlsSocket) => { diff --git a/types/node/test/stream.ts b/types/node/test/stream.ts index 5c49fb38725938..54de806f70122a 100644 --- a/types/node/test/stream.ts +++ b/types/node/test/stream.ts @@ -508,7 +508,7 @@ async function testConsumers() { await consumers.arrayBuffer(consumable); // $ExpectType Blob await consumers.blob(consumable); - // $ExpectType Buffer || Buffer + // $ExpectType NonSharedBuffer await consumers.buffer(consumable); // $ExpectType unknown await consumers.json(consumable); diff --git a/types/node/test/vm.ts b/types/node/test/vm.ts index e84b58b6ae9316..4482c8209cadad 100644 --- a/types/node/test/vm.ts +++ b/types/node/test/vm.ts @@ -77,7 +77,7 @@ import { }); fn satisfies Function; - // $ExpectType Buffer | undefined + // $ExpectType NonSharedBuffer | undefined fn.cachedData; // $ExpectType boolean | undefined fn.cachedDataProduced; diff --git a/types/node/test/zlib.ts b/types/node/test/zlib.ts index c9761c80e61b92..29ffa2e273c14d 100644 --- a/types/node/test/zlib.ts +++ b/types/node/test/zlib.ts @@ -163,8 +163,8 @@ createZstdDecompress({ chunkSize: 1024 }); // $ExpectType ZstdDecompress zstdCompress(compressMe, (err: Error | null, result: Buffer) => result); zstdCompress(compressMe, { finishFlush: constants.ZSTD_e_end }, (err: Error | null, result: Buffer) => result); -zstdCompressSync(compressMe); // $ExpectType Buffer || Buffer -zstdCompressSync(compressMe, { finishFlush: constants.ZSTD_e_end }); // $ExpectType Buffer || Buffer +zstdCompressSync(compressMe); // $ExpectType NonSharedBuffer +zstdCompressSync(compressMe, { finishFlush: constants.ZSTD_e_end }); // $ExpectType NonSharedBuffer zstdDecompress(compressMe, (err: Error | null, result: Buffer) => result); zstdDecompress( @@ -172,56 +172,56 @@ zstdDecompress( { params: { [constants.ZSTD_d_windowLogMax]: 100 } }, (err: Error | null, result: Buffer) => result, ); -zstdDecompressSync(compressMe); // $ExpectType Buffer || Buffer -zstdDecompressSync(compressMe, { params: { [constants.ZSTD_d_windowLogMax]: 100 } }); // $ExpectType Buffer || Buffer +zstdDecompressSync(compressMe); // $ExpectType NonSharedBuffer +zstdDecompressSync(compressMe, { params: { [constants.ZSTD_d_windowLogMax]: 100 } }); // $ExpectType NonSharedBuffer { - // $ExpectType (buffer: InputType, options?: BrotliOptions | undefined) => Promise || (buffer: InputType, options?: BrotliOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: BrotliOptions | undefined) => Promise const pBrotliCompress = promisify(brotliCompress); - // $ExpectType (buffer: InputType, options?: BrotliOptions | undefined) => Promise || (buffer: InputType, options?: BrotliOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: BrotliOptions | undefined) => Promise const pBrotliDecompress = promisify(brotliDecompress); - // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise || (buffer: InputType, options?: ZlibOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise const pDeflate = promisify(deflate); - // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise || (buffer: InputType, options?: ZlibOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise const pDeflateRaw = promisify(deflateRaw); - // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise || (buffer: InputType, options?: ZlibOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise const pGzip = promisify(gzip); - // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise || (buffer: InputType, options?: ZlibOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise const pGunzip = promisify(gunzip); - // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise || (buffer: InputType, options?: ZlibOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise const pInflate = promisify(inflate); - // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise || (buffer: InputType, options?: ZlibOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise const pInflateRaw = promisify(inflateRaw); - // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise || (buffer: InputType, options?: ZlibOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise const pUnzip = promisify(unzip); - // $ExpectType (buffer: InputType, options?: ZstdOptions | undefined) => Promise || (buffer: InputType, options?: ZstdOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: ZstdOptions | undefined) => Promise const pZstdCompress = promisify(zstdCompress); - // $ExpectType (buffer: InputType, options?: ZstdOptions | undefined) => Promise || (buffer: InputType, options?: ZstdOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: ZstdOptions | undefined) => Promise const pZstdDecompress = promisify(zstdDecompress); (async () => { - await pBrotliCompress(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pBrotliCompress(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType Buffer || Buffer - await pBrotliDecompress(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pBrotliDecompress(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType Buffer || Buffer - await pDeflate(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pDeflate(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType Buffer || Buffer - await pDeflateRaw(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pDeflateRaw(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType Buffer || Buffer - await pGzip(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pGzip(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType Buffer || Buffer - await pGunzip(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pGunzip(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType Buffer || Buffer - await pInflate(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pInflate(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType Buffer || Buffer - await pInflateRaw(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pInflateRaw(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType Buffer || Buffer - await pUnzip(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pUnzip(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType Buffer || Buffer - await pZstdCompress(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pZstdCompress(Buffer.from("buf"), { flush: constants.ZSTD_e_flush }); // $ExpectType Buffer || Buffer - await pZstdDecompress(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pZstdDecompress(Buffer.from("buf"), { flush: constants.ZSTD_e_flush }); // $ExpectType Buffer || Buffer + await pBrotliCompress(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pBrotliCompress(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType NonSharedBuffer + await pBrotliDecompress(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pBrotliDecompress(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType NonSharedBuffer + await pDeflate(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pDeflate(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType NonSharedBuffer + await pDeflateRaw(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pDeflateRaw(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType NonSharedBuffer + await pGzip(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pGzip(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType NonSharedBuffer + await pGunzip(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pGunzip(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType NonSharedBuffer + await pInflate(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pInflate(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType NonSharedBuffer + await pInflateRaw(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pInflateRaw(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType NonSharedBuffer + await pUnzip(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pUnzip(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType NonSharedBuffer + await pZstdCompress(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pZstdCompress(Buffer.from("buf"), { flush: constants.ZSTD_e_flush }); // $ExpectType NonSharedBuffer + await pZstdDecompress(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pZstdDecompress(Buffer.from("buf"), { flush: constants.ZSTD_e_flush }); // $ExpectType NonSharedBuffer })(); } diff --git a/types/node/tls.d.ts b/types/node/tls.d.ts index 629db522789233..5d52de810c2a58 100644 --- a/types/node/tls.d.ts +++ b/types/node/tls.d.ts @@ -9,6 +9,7 @@ * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/tls.js) */ declare module "tls" { + import { NonSharedBuffer } from "node:buffer"; import { X509Certificate } from "node:crypto"; import * as net from "node:net"; import * as stream from "stream"; @@ -49,7 +50,7 @@ declare module "tls" { /** * The DER encoded X.509 certificate data. */ - raw: Buffer; + raw: NonSharedBuffer; /** * The certificate subject. */ @@ -115,7 +116,7 @@ declare module "tls" { /** * The public key. */ - pubkey?: Buffer; + pubkey?: NonSharedBuffer; /** * The ASN.1 name of the OID of the elliptic curve. * Well-known curves are identified by an OID. @@ -295,7 +296,7 @@ declare module "tls" { * @since v9.9.0 * @return The latest `Finished` message that has been sent to the socket as part of a SSL/TLS handshake, or `undefined` if no `Finished` message has been sent yet. */ - getFinished(): Buffer | undefined; + getFinished(): NonSharedBuffer | undefined; /** * Returns an object representing the peer's certificate. If the peer does not * provide a certificate, an empty object will be returned. If the socket has been @@ -322,7 +323,7 @@ declare module "tls" { * @return The latest `Finished` message that is expected or has actually been received from the socket as part of a SSL/TLS handshake, or `undefined` if there is no `Finished` message so * far. */ - getPeerFinished(): Buffer | undefined; + getPeerFinished(): NonSharedBuffer | undefined; /** * Returns a string containing the negotiated SSL/TLS protocol version of the * current connection. The value `'unknown'` will be returned for connected @@ -352,7 +353,7 @@ declare module "tls" { * must use the `'session'` event (it also works for TLSv1.2 and below). * @since v0.11.4 */ - getSession(): Buffer | undefined; + getSession(): NonSharedBuffer | undefined; /** * See [SSL\_get\_shared\_sigalgs](https://www.openssl.org/docs/man1.1.1/man3/SSL_get_shared_sigalgs.html) for more information. * @since v12.11.0 @@ -367,7 +368,7 @@ declare module "tls" { * See `Session Resumption` for more information. * @since v0.11.4 */ - getTLSTicket(): Buffer | undefined; + getTLSTicket(): NonSharedBuffer | undefined; /** * See `Session Resumption` for more information. * @since v0.5.6 @@ -478,37 +479,37 @@ declare module "tls" { * @param context Optionally provide a context. * @return requested bytes of the keying material */ - exportKeyingMaterial(length: number, label: string, context: Buffer): Buffer; + exportKeyingMaterial(length: number, label: string, context: Buffer): NonSharedBuffer; addListener(event: string, listener: (...args: any[]) => void): this; - addListener(event: "OCSPResponse", listener: (response: Buffer) => void): this; + addListener(event: "OCSPResponse", listener: (response: NonSharedBuffer) => void): this; addListener(event: "secureConnect", listener: () => void): this; - addListener(event: "session", listener: (session: Buffer) => void): this; - addListener(event: "keylog", listener: (line: Buffer) => void): this; + addListener(event: "session", listener: (session: NonSharedBuffer) => void): this; + addListener(event: "keylog", listener: (line: NonSharedBuffer) => void): this; emit(event: string | symbol, ...args: any[]): boolean; - emit(event: "OCSPResponse", response: Buffer): boolean; + emit(event: "OCSPResponse", response: NonSharedBuffer): boolean; emit(event: "secureConnect"): boolean; - emit(event: "session", session: Buffer): boolean; - emit(event: "keylog", line: Buffer): boolean; + emit(event: "session", session: NonSharedBuffer): boolean; + emit(event: "keylog", line: NonSharedBuffer): boolean; on(event: string, listener: (...args: any[]) => void): this; - on(event: "OCSPResponse", listener: (response: Buffer) => void): this; + on(event: "OCSPResponse", listener: (response: NonSharedBuffer) => void): this; on(event: "secureConnect", listener: () => void): this; - on(event: "session", listener: (session: Buffer) => void): this; - on(event: "keylog", listener: (line: Buffer) => void): this; + on(event: "session", listener: (session: NonSharedBuffer) => void): this; + on(event: "keylog", listener: (line: NonSharedBuffer) => void): this; once(event: string, listener: (...args: any[]) => void): this; - once(event: "OCSPResponse", listener: (response: Buffer) => void): this; + once(event: "OCSPResponse", listener: (response: NonSharedBuffer) => void): this; once(event: "secureConnect", listener: () => void): this; - once(event: "session", listener: (session: Buffer) => void): this; - once(event: "keylog", listener: (line: Buffer) => void): this; + once(event: "session", listener: (session: NonSharedBuffer) => void): this; + once(event: "keylog", listener: (line: NonSharedBuffer) => void): this; prependListener(event: string, listener: (...args: any[]) => void): this; - prependListener(event: "OCSPResponse", listener: (response: Buffer) => void): this; + prependListener(event: "OCSPResponse", listener: (response: NonSharedBuffer) => void): this; prependListener(event: "secureConnect", listener: () => void): this; - prependListener(event: "session", listener: (session: Buffer) => void): this; - prependListener(event: "keylog", listener: (line: Buffer) => void): this; + prependListener(event: "session", listener: (session: NonSharedBuffer) => void): this; + prependListener(event: "keylog", listener: (line: NonSharedBuffer) => void): this; prependOnceListener(event: string, listener: (...args: any[]) => void): this; - prependOnceListener(event: "OCSPResponse", listener: (response: Buffer) => void): this; + prependOnceListener(event: "OCSPResponse", listener: (response: NonSharedBuffer) => void): this; prependOnceListener(event: "secureConnect", listener: () => void): this; - prependOnceListener(event: "session", listener: (session: Buffer) => void): this; - prependOnceListener(event: "keylog", listener: (line: Buffer) => void): this; + prependOnceListener(event: "session", listener: (session: NonSharedBuffer) => void): this; + prependOnceListener(event: "keylog", listener: (line: NonSharedBuffer) => void): this; } interface CommonConnectionOptions { /** @@ -531,7 +532,7 @@ declare module "tls" { * An array of strings or a Buffer naming possible ALPN protocols. * (Protocols should be ordered by their priority.) */ - ALPNProtocols?: string[] | Uint8Array[] | Uint8Array | undefined; + ALPNProtocols?: readonly string[] | NodeJS.ArrayBufferView | undefined; /** * SNICallback(servername, cb) A function that will be * called if the client supports SNI TLS extension. Two arguments @@ -596,7 +597,7 @@ declare module "tls" { pskIdentityHint?: string | undefined; } interface PSKCallbackNegotation { - psk: DataView | NodeJS.TypedArray; + psk: NodeJS.ArrayBufferView; identity: string; } interface ConnectionOptions extends SecureContextOptions, CommonConnectionOptions { @@ -655,7 +656,7 @@ declare module "tls" { * @since v3.0.0 * @return A 48-byte buffer containing the session ticket keys. */ - getTicketKeys(): Buffer; + getTicketKeys(): NonSharedBuffer; /** * The `server.setSecureContext()` method replaces the secure context of an * existing server. Existing connections to the server are not interrupted. @@ -687,115 +688,138 @@ declare module "tls" { addListener(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this; addListener( event: "newSession", - listener: (sessionId: Buffer, sessionData: Buffer, callback: () => void) => void, + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, ): this; addListener( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; addListener( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error | null, sessionData: Buffer | null) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; addListener(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this; - addListener(event: "keylog", listener: (line: Buffer, tlsSocket: TLSSocket) => void): this; + addListener(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: TLSSocket) => void): this; emit(event: string | symbol, ...args: any[]): boolean; emit(event: "tlsClientError", err: Error, tlsSocket: TLSSocket): boolean; - emit(event: "newSession", sessionId: Buffer, sessionData: Buffer, callback: () => void): boolean; + emit( + event: "newSession", + sessionId: NonSharedBuffer, + sessionData: NonSharedBuffer, + callback: () => void, + ): boolean; emit( event: "OCSPRequest", - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ): boolean; emit( event: "resumeSession", - sessionId: Buffer, + sessionId: NonSharedBuffer, callback: (err: Error | null, sessionData: Buffer | null) => void, ): boolean; emit(event: "secureConnection", tlsSocket: TLSSocket): boolean; - emit(event: "keylog", line: Buffer, tlsSocket: TLSSocket): boolean; + emit(event: "keylog", line: NonSharedBuffer, tlsSocket: TLSSocket): boolean; on(event: string, listener: (...args: any[]) => void): this; on(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this; - on(event: "newSession", listener: (sessionId: Buffer, sessionData: Buffer, callback: () => void) => void): this; + on( + event: "newSession", + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, + ): this; on( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; on( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error | null, sessionData: Buffer | null) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; on(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this; - on(event: "keylog", listener: (line: Buffer, tlsSocket: TLSSocket) => void): this; + on(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: TLSSocket) => void): this; once(event: string, listener: (...args: any[]) => void): this; once(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this; once( event: "newSession", - listener: (sessionId: Buffer, sessionData: Buffer, callback: () => void) => void, + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, ): this; once( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; once( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error | null, sessionData: Buffer | null) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; once(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this; - once(event: "keylog", listener: (line: Buffer, tlsSocket: TLSSocket) => void): this; + once(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: TLSSocket) => void): this; prependListener(event: string, listener: (...args: any[]) => void): this; prependListener(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this; prependListener( event: "newSession", - listener: (sessionId: Buffer, sessionData: Buffer, callback: () => void) => void, + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, ): this; prependListener( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; prependListener( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error | null, sessionData: Buffer | null) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; prependListener(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this; - prependListener(event: "keylog", listener: (line: Buffer, tlsSocket: TLSSocket) => void): this; + prependListener(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: TLSSocket) => void): this; prependOnceListener(event: string, listener: (...args: any[]) => void): this; prependOnceListener(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this; prependOnceListener( event: "newSession", - listener: (sessionId: Buffer, sessionData: Buffer, callback: () => void) => void, + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, ): this; prependOnceListener( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; prependOnceListener( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error | null, sessionData: Buffer | null) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; prependOnceListener(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this; - prependOnceListener(event: "keylog", listener: (line: Buffer, tlsSocket: TLSSocket) => void): this; + prependOnceListener(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: TLSSocket) => void): this; } type SecureVersion = "TLSv1.3" | "TLSv1.2" | "TLSv1.1" | "TLSv1"; interface SecureContextOptions { diff --git a/types/node/ts5.6/buffer.buffer.d.ts b/types/node/ts5.6/buffer.buffer.d.ts index d19026dc2ff99c..a5f67d7c9306ed 100644 --- a/types/node/ts5.6/buffer.buffer.d.ts +++ b/types/node/ts5.6/buffer.buffer.d.ts @@ -32,7 +32,7 @@ declare module "buffer" { * @param arrayBuffer The ArrayBuffer with which to share memory. * @deprecated since v10.0.0 - Use `Buffer.from(arrayBuffer[, byteOffset[, length]])` instead. */ - new(arrayBuffer: ArrayBuffer | SharedArrayBuffer): Buffer; + new(arrayBuffer: ArrayBufferLike): Buffer; /** * Allocates a new `Buffer` using an `array` of bytes in the range `0` – `255`. * Array entries outside that range will be truncated to fit into it. @@ -126,7 +126,7 @@ declare module "buffer" { * `arrayBuffer.byteLength - byteOffset`. */ from( - arrayBuffer: WithImplicitCoercion, + arrayBuffer: WithImplicitCoercion, byteOffset?: number, length?: number, ): Buffer; @@ -448,7 +448,15 @@ declare module "buffer" { */ subarray(start?: number, end?: number): Buffer; } + /** + * @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports + * TypeScript versions earlier than 5.7. + */ type NonSharedBuffer = Buffer; + /** + * @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports + * TypeScript versions earlier than 5.7. + */ type AllowSharedBuffer = Buffer; } /** @deprecated Use `Buffer.allocUnsafeSlow()` instead. */ diff --git a/types/node/ts5.6/globals.typedarray.d.ts b/types/node/ts5.6/globals.typedarray.d.ts index 255e204813d2bb..57a1ab4f2c9336 100644 --- a/types/node/ts5.6/globals.typedarray.d.ts +++ b/types/node/ts5.6/globals.typedarray.d.ts @@ -16,5 +16,21 @@ declare global { | Float32Array | Float64Array; type ArrayBufferView = TypedArray | DataView; + + type NonSharedUint8Array = Uint8Array; + type NonSharedUint8ClampedArray = Uint8ClampedArray; + type NonSharedUint16Array = Uint16Array; + type NonSharedUint32Array = Uint32Array; + type NonSharedInt8Array = Int8Array; + type NonSharedInt16Array = Int16Array; + type NonSharedInt32Array = Int32Array; + type NonSharedBigUint64Array = BigUint64Array; + type NonSharedBigInt64Array = BigInt64Array; + type NonSharedFloat16Array = Float16Array; + type NonSharedFloat32Array = Float32Array; + type NonSharedFloat64Array = Float64Array; + type NonSharedDataView = DataView; + type NonSharedTypedArray = TypedArray; + type NonSharedArrayBufferView = ArrayBufferView; } } diff --git a/types/node/url.d.ts b/types/node/url.d.ts index ba12c4685f8c08..14319f4257098d 100644 --- a/types/node/url.d.ts +++ b/types/node/url.d.ts @@ -8,7 +8,7 @@ * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/url.js) */ declare module "url" { - import { Blob as NodeBlob } from "node:buffer"; + import { Blob as NodeBlob, NonSharedBuffer } from "node:buffer"; import { ClientRequestArgs } from "node:http"; import { ParsedUrlQuery, ParsedUrlQueryInput } from "node:querystring"; // Input to `url.format` @@ -325,7 +325,7 @@ declare module "url" { * @returns The fully-resolved platform-specific Node.js file path * as a `Buffer`. */ - function fileURLToPathBuffer(url: string | URL, options?: FileUrlToPathOptions): Buffer; + function fileURLToPathBuffer(url: string | URL, options?: FileUrlToPathOptions): NonSharedBuffer; /** * This function ensures that `path` is resolved absolutely, and that the URL * control characters are correctly encoded when converting into a File URL. diff --git a/types/node/util.d.ts b/types/node/util.d.ts index 9a3f5ad8e093bb..c825a79be8db86 100644 --- a/types/node/util.d.ts +++ b/types/node/util.d.ts @@ -1341,7 +1341,7 @@ declare module "util" { * encoded bytes. * @param [input='an empty string'] The text to encode. */ - encode(input?: string): Uint8Array; + encode(input?: string): NodeJS.NonSharedUint8Array; /** * UTF-8 encodes the `src` string to the `dest` Uint8Array and returns an object * containing the read Unicode code units and written UTF-8 bytes. diff --git a/types/node/v20/buffer.buffer.d.ts b/types/node/v20/buffer.buffer.d.ts index e6f977f4293c2e..023bb0fd3f4105 100644 --- a/types/node/v20/buffer.buffer.d.ts +++ b/types/node/v20/buffer.buffer.d.ts @@ -450,7 +450,16 @@ declare module "buffer" { */ subarray(start?: number, end?: number): Buffer; } + // TODO: remove globals in future version + /** + * @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports + * TypeScript versions earlier than 5.7. + */ type NonSharedBuffer = Buffer; + /** + * @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports + * TypeScript versions earlier than 5.7. + */ type AllowSharedBuffer = Buffer; } /** @deprecated Use `Buffer.allocUnsafeSlow()` instead. */ diff --git a/types/node/v20/buffer.d.ts b/types/node/v20/buffer.d.ts index 0902f2af8fdaf8..7c2e87386ee35a 100644 --- a/types/node/v20/buffer.d.ts +++ b/types/node/v20/buffer.d.ts @@ -59,7 +59,7 @@ declare module "buffer" { * @since v19.4.0, v18.14.0 * @param input The input to validate. */ - export function isUtf8(input: Buffer | ArrayBuffer | NodeJS.TypedArray): boolean; + export function isUtf8(input: ArrayBuffer | NodeJS.TypedArray): boolean; /** * This function returns `true` if `input` contains only valid ASCII-encoded data, * including the case in which `input` is empty. @@ -68,7 +68,7 @@ declare module "buffer" { * @since v19.6.0, v18.15.0 * @param input The input to validate. */ - export function isAscii(input: Buffer | ArrayBuffer | NodeJS.TypedArray): boolean; + export function isAscii(input: ArrayBuffer | NodeJS.TypedArray): boolean; export let INSPECT_MAX_BYTES: number; export const kMaxLength: number; export const kStringMaxLength: number; @@ -113,7 +113,11 @@ declare module "buffer" { * @param fromEnc The current encoding. * @param toEnc To target encoding. */ - export function transcode(source: Uint8Array, fromEnc: TranscodeEncoding, toEnc: TranscodeEncoding): Buffer; + export function transcode( + source: Uint8Array, + fromEnc: TranscodeEncoding, + toEnc: TranscodeEncoding, + ): NonSharedBuffer; /** * Resolves a `'blob:nodedata:...'` an associated `Blob` object registered using * a prior call to `URL.createObjectURL()`. @@ -332,7 +336,7 @@ declare module "buffer" { * @return The number of bytes contained within `string`. */ byteLength( - string: string | Buffer | NodeJS.ArrayBufferView | ArrayBuffer | SharedArrayBuffer, + string: string | NodeJS.ArrayBufferView | ArrayBufferLike, encoding?: BufferEncoding, ): number; /** diff --git a/types/node/v20/child_process.d.ts b/types/node/v20/child_process.d.ts index ca57fac9f193bf..50890718343c0f 100644 --- a/types/node/v20/child_process.d.ts +++ b/types/node/v20/child_process.d.ts @@ -66,6 +66,7 @@ * @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/child_process.js) */ declare module "child_process" { + import { NonSharedBuffer } from "node:buffer"; import { Abortable, EventEmitter } from "node:events"; import * as dgram from "node:dgram"; import * as net from "node:net"; @@ -1001,7 +1002,7 @@ declare module "child_process" { function exec( command: string, options: ExecOptionsWithBufferEncoding, - callback?: (error: ExecException | null, stdout: Buffer, stderr: Buffer) => void, + callback?: (error: ExecException | null, stdout: NonSharedBuffer, stderr: NonSharedBuffer) => void, ): ChildProcess; // `options` with well-known or absent `encoding` means stdout/stderr are definitely `string`. function exec( @@ -1013,7 +1014,11 @@ declare module "child_process" { function exec( command: string, options: ExecOptions | undefined | null, - callback?: (error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void, + callback?: ( + error: ExecException | null, + stdout: string | NonSharedBuffer, + stderr: string | NonSharedBuffer, + ) => void, ): ChildProcess; interface PromiseWithChild extends Promise { child: ChildProcess; @@ -1027,8 +1032,8 @@ declare module "child_process" { command: string, options: ExecOptionsWithBufferEncoding, ): PromiseWithChild<{ - stdout: Buffer; - stderr: Buffer; + stdout: NonSharedBuffer; + stderr: NonSharedBuffer; }>; function __promisify__( command: string, @@ -1041,8 +1046,8 @@ declare module "child_process" { command: string, options: ExecOptions | undefined | null, ): PromiseWithChild<{ - stdout: string | Buffer; - stderr: string | Buffer; + stdout: string | NonSharedBuffer; + stderr: string | NonSharedBuffer; }>; } interface ExecFileOptions extends CommonOptions, Abortable { @@ -1143,13 +1148,13 @@ declare module "child_process" { function execFile( file: string, options: ExecFileOptionsWithBufferEncoding, - callback?: (error: ExecFileException | null, stdout: Buffer, stderr: Buffer) => void, + callback?: (error: ExecFileException | null, stdout: NonSharedBuffer, stderr: NonSharedBuffer) => void, ): ChildProcess; function execFile( file: string, args: readonly string[] | undefined | null, options: ExecFileOptionsWithBufferEncoding, - callback?: (error: ExecFileException | null, stdout: Buffer, stderr: Buffer) => void, + callback?: (error: ExecFileException | null, stdout: NonSharedBuffer, stderr: NonSharedBuffer) => void, ): ChildProcess; // `options` with well-known or absent `encoding` means stdout/stderr are definitely `string`. function execFile( @@ -1168,7 +1173,11 @@ declare module "child_process" { file: string, options: ExecFileOptions | undefined | null, callback: - | ((error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void) + | (( + error: ExecFileException | null, + stdout: string | NonSharedBuffer, + stderr: string | NonSharedBuffer, + ) => void) | undefined | null, ): ChildProcess; @@ -1177,7 +1186,11 @@ declare module "child_process" { args: readonly string[] | undefined | null, options: ExecFileOptions | undefined | null, callback: - | ((error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void) + | (( + error: ExecFileException | null, + stdout: string | NonSharedBuffer, + stderr: string | NonSharedBuffer, + ) => void) | undefined | null, ): ChildProcess; @@ -1197,16 +1210,16 @@ declare module "child_process" { file: string, options: ExecFileOptionsWithBufferEncoding, ): PromiseWithChild<{ - stdout: Buffer; - stderr: Buffer; + stdout: NonSharedBuffer; + stderr: NonSharedBuffer; }>; function __promisify__( file: string, args: readonly string[] | undefined | null, options: ExecFileOptionsWithBufferEncoding, ): PromiseWithChild<{ - stdout: Buffer; - stderr: Buffer; + stdout: NonSharedBuffer; + stderr: NonSharedBuffer; }>; function __promisify__( file: string, @@ -1227,16 +1240,16 @@ declare module "child_process" { file: string, options: ExecFileOptions | undefined | null, ): PromiseWithChild<{ - stdout: string | Buffer; - stderr: string | Buffer; + stdout: string | NonSharedBuffer; + stderr: string | NonSharedBuffer; }>; function __promisify__( file: string, args: readonly string[] | undefined | null, options: ExecFileOptions | undefined | null, ): PromiseWithChild<{ - stdout: string | Buffer; - stderr: string | Buffer; + stdout: string | NonSharedBuffer; + stderr: string | NonSharedBuffer; }>; } interface ForkOptions extends ProcessEnvOptions, MessagingOptions, Abortable { @@ -1342,11 +1355,11 @@ declare module "child_process" { * @param command The command to run. * @param args List of string arguments. */ - function spawnSync(command: string): SpawnSyncReturns; + function spawnSync(command: string): SpawnSyncReturns; function spawnSync(command: string, options: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns; - function spawnSync(command: string, options: SpawnSyncOptionsWithBufferEncoding): SpawnSyncReturns; - function spawnSync(command: string, options?: SpawnSyncOptions): SpawnSyncReturns; - function spawnSync(command: string, args: readonly string[]): SpawnSyncReturns; + function spawnSync(command: string, options: SpawnSyncOptionsWithBufferEncoding): SpawnSyncReturns; + function spawnSync(command: string, options?: SpawnSyncOptions): SpawnSyncReturns; + function spawnSync(command: string, args: readonly string[]): SpawnSyncReturns; function spawnSync( command: string, args: readonly string[], @@ -1356,12 +1369,12 @@ declare module "child_process" { command: string, args: readonly string[], options: SpawnSyncOptionsWithBufferEncoding, - ): SpawnSyncReturns; + ): SpawnSyncReturns; function spawnSync( command: string, args?: readonly string[], options?: SpawnSyncOptions, - ): SpawnSyncReturns; + ): SpawnSyncReturns; interface CommonExecOptions extends CommonOptions { input?: string | NodeJS.ArrayBufferView | undefined; /** @@ -1403,10 +1416,10 @@ declare module "child_process" { * @param command The command to run. * @return The stdout from the command. */ - function execSync(command: string): Buffer; + function execSync(command: string): NonSharedBuffer; function execSync(command: string, options: ExecSyncOptionsWithStringEncoding): string; - function execSync(command: string, options: ExecSyncOptionsWithBufferEncoding): Buffer; - function execSync(command: string, options?: ExecSyncOptions): string | Buffer; + function execSync(command: string, options: ExecSyncOptionsWithBufferEncoding): NonSharedBuffer; + function execSync(command: string, options?: ExecSyncOptions): string | NonSharedBuffer; interface ExecFileSyncOptions extends CommonExecOptions { shell?: boolean | string | undefined; } @@ -1436,11 +1449,11 @@ declare module "child_process" { * @param args List of string arguments. * @return The stdout from the command. */ - function execFileSync(file: string): Buffer; + function execFileSync(file: string): NonSharedBuffer; function execFileSync(file: string, options: ExecFileSyncOptionsWithStringEncoding): string; - function execFileSync(file: string, options: ExecFileSyncOptionsWithBufferEncoding): Buffer; - function execFileSync(file: string, options?: ExecFileSyncOptions): string | Buffer; - function execFileSync(file: string, args: readonly string[]): Buffer; + function execFileSync(file: string, options: ExecFileSyncOptionsWithBufferEncoding): NonSharedBuffer; + function execFileSync(file: string, options?: ExecFileSyncOptions): string | NonSharedBuffer; + function execFileSync(file: string, args: readonly string[]): NonSharedBuffer; function execFileSync( file: string, args: readonly string[], @@ -1450,8 +1463,12 @@ declare module "child_process" { file: string, args: readonly string[], options: ExecFileSyncOptionsWithBufferEncoding, - ): Buffer; - function execFileSync(file: string, args?: readonly string[], options?: ExecFileSyncOptions): string | Buffer; + ): NonSharedBuffer; + function execFileSync( + file: string, + args?: readonly string[], + options?: ExecFileSyncOptions, + ): string | NonSharedBuffer; } declare module "node:child_process" { export * from "child_process"; diff --git a/types/node/v20/crypto.d.ts b/types/node/v20/crypto.d.ts index 3021db0baece8d..036cf8c434eddc 100644 --- a/types/node/v20/crypto.d.ts +++ b/types/node/v20/crypto.d.ts @@ -17,6 +17,7 @@ * @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/crypto.js) */ declare module "crypto" { + import { NonSharedBuffer } from "node:buffer"; import * as stream from "node:stream"; import { PeerCertificate } from "node:tls"; /** @@ -44,7 +45,7 @@ declare module "crypto" { * @param encoding The `encoding` of the `spkac` string. * @return The challenge component of the `spkac` data structure, which includes a public key and a challenge. */ - static exportChallenge(spkac: BinaryLike): Buffer; + static exportChallenge(spkac: BinaryLike): NonSharedBuffer; /** * ```js * const { Certificate } = await import('node:crypto'); @@ -57,7 +58,7 @@ declare module "crypto" { * @param encoding The `encoding` of the `spkac` string. * @return The public key component of the `spkac` data structure, which includes a public key and a challenge. */ - static exportPublicKey(spkac: BinaryLike, encoding?: string): Buffer; + static exportPublicKey(spkac: BinaryLike, encoding?: string): NonSharedBuffer; /** * ```js * import { Buffer } from 'node:buffer'; @@ -78,7 +79,7 @@ declare module "crypto" { * @returns The challenge component of the `spkac` data structure, * which includes a public key and a challenge. */ - exportChallenge(spkac: BinaryLike): Buffer; + exportChallenge(spkac: BinaryLike): NonSharedBuffer; /** * @deprecated * @param spkac @@ -86,7 +87,7 @@ declare module "crypto" { * @returns The public key component of the `spkac` data structure, * which includes a public key and a challenge. */ - exportPublicKey(spkac: BinaryLike, encoding?: string): Buffer; + exportPublicKey(spkac: BinaryLike, encoding?: string): NonSharedBuffer; /** * @deprecated * @param spkac @@ -402,7 +403,7 @@ declare module "crypto" { * @since v0.1.92 * @param encoding The `encoding` of the return value. */ - digest(): Buffer; + digest(): NonSharedBuffer; digest(encoding: BinaryToTextEncoding): string; } /** @@ -496,7 +497,7 @@ declare module "crypto" { * @since v0.1.94 * @param encoding The `encoding` of the return value. */ - digest(): Buffer; + digest(): NonSharedBuffer; digest(encoding: BinaryToTextEncoding): string; } type KeyObjectType = "secret" | "public" | "private"; @@ -646,8 +647,8 @@ declare module "crypto" { * PKCS#1 and SEC1 encryption. * @since v11.6.0 */ - export(options: KeyExportOptions<"pem">): string | Buffer; - export(options?: KeyExportOptions<"der">): Buffer; + export(options: KeyExportOptions<"pem">): string | NonSharedBuffer; + export(options?: KeyExportOptions<"der">): NonSharedBuffer; export(options?: JwkKeyExportOptions): JsonWebKey; /** * Returns `true` or `false` depending on whether the keys have exactly the same @@ -933,8 +934,8 @@ declare module "crypto" { * @param inputEncoding The `encoding` of the data. * @param outputEncoding The `encoding` of the return value. */ - update(data: BinaryLike): Buffer; - update(data: string, inputEncoding: Encoding): Buffer; + update(data: BinaryLike): NonSharedBuffer; + update(data: string, inputEncoding: Encoding): NonSharedBuffer; update(data: NodeJS.ArrayBufferView, inputEncoding: undefined, outputEncoding: Encoding): string; update(data: string, inputEncoding: Encoding | undefined, outputEncoding: Encoding): string; /** @@ -945,7 +946,7 @@ declare module "crypto" { * @param outputEncoding The `encoding` of the return value. * @return Any remaining enciphered contents. If `outputEncoding` is specified, a string is returned. If an `outputEncoding` is not provided, a {@link Buffer} is returned. */ - final(): Buffer; + final(): NonSharedBuffer; final(outputEncoding: BufferEncoding): string; /** * When using block encryption algorithms, the `Cipher` class will automatically @@ -971,7 +972,7 @@ declare module "crypto" { plaintextLength: number; }, ): this; - getAuthTag(): Buffer; + getAuthTag(): NonSharedBuffer; } interface CipherGCM extends Cipher { setAAD( @@ -980,7 +981,7 @@ declare module "crypto" { plaintextLength: number; }, ): this; - getAuthTag(): Buffer; + getAuthTag(): NonSharedBuffer; } interface CipherOCB extends Cipher { setAAD( @@ -989,7 +990,7 @@ declare module "crypto" { plaintextLength: number; }, ): this; - getAuthTag(): Buffer; + getAuthTag(): NonSharedBuffer; } interface CipherChaCha20Poly1305 extends Cipher { setAAD( @@ -998,7 +999,7 @@ declare module "crypto" { plaintextLength: number; }, ): this; - getAuthTag(): Buffer; + getAuthTag(): NonSharedBuffer; } /** * Creates and returns a `Decipher` object that uses the given `algorithm` and `password` (key). @@ -1222,8 +1223,8 @@ declare module "crypto" { * @param inputEncoding The `encoding` of the `data` string. * @param outputEncoding The `encoding` of the return value. */ - update(data: NodeJS.ArrayBufferView): Buffer; - update(data: string, inputEncoding: Encoding): Buffer; + update(data: NodeJS.ArrayBufferView): NonSharedBuffer; + update(data: string, inputEncoding: Encoding): NonSharedBuffer; update(data: NodeJS.ArrayBufferView, inputEncoding: undefined, outputEncoding: Encoding): string; update(data: string, inputEncoding: Encoding | undefined, outputEncoding: Encoding): string; /** @@ -1234,7 +1235,7 @@ declare module "crypto" { * @param outputEncoding The `encoding` of the return value. * @return Any remaining deciphered contents. If `outputEncoding` is specified, a string is returned. If an `outputEncoding` is not provided, a {@link Buffer} is returned. */ - final(): Buffer; + final(): NonSharedBuffer; final(outputEncoding: BufferEncoding): string; /** * When data has been encrypted without standard block padding, calling `decipher.setAutoPadding(false)` will disable automatic padding to prevent `decipher.final()` from checking for and @@ -1506,7 +1507,7 @@ declare module "crypto" { * called. Multiple calls to `sign.sign()` will result in an error being thrown. * @since v0.1.92 */ - sign(privateKey: KeyLike | SignKeyObjectInput | SignPrivateKeyInput | SignJsonWebKeyInput): Buffer; + sign(privateKey: KeyLike | SignKeyObjectInput | SignPrivateKeyInput | SignJsonWebKeyInput): NonSharedBuffer; sign( privateKey: KeyLike | SignKeyObjectInput | SignPrivateKeyInput | SignJsonWebKeyInput, outputFormat: BinaryToTextEncoding, @@ -1665,7 +1666,7 @@ declare module "crypto" { * @since v0.5.0 * @param encoding The `encoding` of the return value. */ - generateKeys(): Buffer; + generateKeys(): NonSharedBuffer; generateKeys(encoding: BinaryToTextEncoding): string; /** * Computes the shared secret using `otherPublicKey` as the other @@ -1680,8 +1681,16 @@ declare module "crypto" { * @param inputEncoding The `encoding` of an `otherPublicKey` string. * @param outputEncoding The `encoding` of the return value. */ - computeSecret(otherPublicKey: NodeJS.ArrayBufferView, inputEncoding?: null, outputEncoding?: null): Buffer; - computeSecret(otherPublicKey: string, inputEncoding: BinaryToTextEncoding, outputEncoding?: null): Buffer; + computeSecret( + otherPublicKey: NodeJS.ArrayBufferView, + inputEncoding?: null, + outputEncoding?: null, + ): NonSharedBuffer; + computeSecret( + otherPublicKey: string, + inputEncoding: BinaryToTextEncoding, + outputEncoding?: null, + ): NonSharedBuffer; computeSecret( otherPublicKey: NodeJS.ArrayBufferView, inputEncoding: null, @@ -1699,7 +1708,7 @@ declare module "crypto" { * @since v0.5.0 * @param encoding The `encoding` of the return value. */ - getPrime(): Buffer; + getPrime(): NonSharedBuffer; getPrime(encoding: BinaryToTextEncoding): string; /** * Returns the Diffie-Hellman generator in the specified `encoding`. @@ -1708,7 +1717,7 @@ declare module "crypto" { * @since v0.5.0 * @param encoding The `encoding` of the return value. */ - getGenerator(): Buffer; + getGenerator(): NonSharedBuffer; getGenerator(encoding: BinaryToTextEncoding): string; /** * Returns the Diffie-Hellman public key in the specified `encoding`. @@ -1717,7 +1726,7 @@ declare module "crypto" { * @since v0.5.0 * @param encoding The `encoding` of the return value. */ - getPublicKey(): Buffer; + getPublicKey(): NonSharedBuffer; getPublicKey(encoding: BinaryToTextEncoding): string; /** * Returns the Diffie-Hellman private key in the specified `encoding`. @@ -1726,7 +1735,7 @@ declare module "crypto" { * @since v0.5.0 * @param encoding The `encoding` of the return value. */ - getPrivateKey(): Buffer; + getPrivateKey(): NonSharedBuffer; getPrivateKey(encoding: BinaryToTextEncoding): string; /** * Sets the Diffie-Hellman public key. If the `encoding` argument is provided, `publicKey` is expected @@ -1870,7 +1879,7 @@ declare module "crypto" { iterations: number, keylen: number, digest: string, - callback: (err: Error | null, derivedKey: Buffer) => void, + callback: (err: Error | null, derivedKey: NonSharedBuffer) => void, ): void; /** * Provides a synchronous Password-Based Key Derivation Function 2 (PBKDF2) @@ -1907,7 +1916,7 @@ declare module "crypto" { iterations: number, keylen: number, digest: string, - ): Buffer; + ): NonSharedBuffer; /** * Generates cryptographically strong pseudorandom data. The `size` argument * is a number indicating the number of bytes to generate. @@ -1960,10 +1969,10 @@ declare module "crypto" { * @param size The number of bytes to generate. The `size` must not be larger than `2**31 - 1`. * @return if the `callback` function is not provided. */ - function randomBytes(size: number): Buffer; - function randomBytes(size: number, callback: (err: Error | null, buf: Buffer) => void): void; - function pseudoRandomBytes(size: number): Buffer; - function pseudoRandomBytes(size: number, callback: (err: Error | null, buf: Buffer) => void): void; + function randomBytes(size: number): NonSharedBuffer; + function randomBytes(size: number, callback: (err: Error | null, buf: NonSharedBuffer) => void): void; + function pseudoRandomBytes(size: number): NonSharedBuffer; + function pseudoRandomBytes(size: number, callback: (err: Error | null, buf: NonSharedBuffer) => void): void; /** * Return a random integer `n` such that `min <= n < max`. This * implementation avoids [modulo bias](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#Modulo_bias). @@ -2193,14 +2202,14 @@ declare module "crypto" { password: BinaryLike, salt: BinaryLike, keylen: number, - callback: (err: Error | null, derivedKey: Buffer) => void, + callback: (err: Error | null, derivedKey: NonSharedBuffer) => void, ): void; function scrypt( password: BinaryLike, salt: BinaryLike, keylen: number, options: ScryptOptions, - callback: (err: Error | null, derivedKey: Buffer) => void, + callback: (err: Error | null, derivedKey: NonSharedBuffer) => void, ): void; /** * Provides a synchronous [scrypt](https://en.wikipedia.org/wiki/Scrypt) implementation. Scrypt is a password-based @@ -2232,7 +2241,12 @@ declare module "crypto" { * ``` * @since v10.5.0 */ - function scryptSync(password: BinaryLike, salt: BinaryLike, keylen: number, options?: ScryptOptions): Buffer; + function scryptSync( + password: BinaryLike, + salt: BinaryLike, + keylen: number, + options?: ScryptOptions, + ): NonSharedBuffer; interface RsaPublicKey { key: KeyLike; padding?: number | undefined; @@ -2258,7 +2272,10 @@ declare module "crypto" { * be passed instead of a public key. * @since v0.11.14 */ - function publicEncrypt(key: RsaPublicKey | RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView): Buffer; + function publicEncrypt( + key: RsaPublicKey | RsaPrivateKey | KeyLike, + buffer: NodeJS.ArrayBufferView, + ): NonSharedBuffer; /** * Decrypts `buffer` with `key`.`buffer` was previously encrypted using * the corresponding private key, for example using {@link privateEncrypt}. @@ -2270,7 +2287,10 @@ declare module "crypto" { * be passed instead of a public key. * @since v1.1.0 */ - function publicDecrypt(key: RsaPublicKey | RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView): Buffer; + function publicDecrypt( + key: RsaPublicKey | RsaPrivateKey | KeyLike, + buffer: NodeJS.ArrayBufferView, + ): NonSharedBuffer; /** * Decrypts `buffer` with `privateKey`. `buffer` was previously encrypted using * the corresponding public key, for example using {@link publicEncrypt}. @@ -2279,7 +2299,7 @@ declare module "crypto" { * object, the `padding` property can be passed. Otherwise, this function uses `RSA_PKCS1_OAEP_PADDING`. * @since v0.11.14 */ - function privateDecrypt(privateKey: RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView): Buffer; + function privateDecrypt(privateKey: RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView): NonSharedBuffer; /** * Encrypts `buffer` with `privateKey`. The returned data can be decrypted using * the corresponding public key, for example using {@link publicDecrypt}. @@ -2288,7 +2308,7 @@ declare module "crypto" { * object, the `padding` property can be passed. Otherwise, this function uses `RSA_PKCS1_PADDING`. * @since v1.1.0 */ - function privateEncrypt(privateKey: RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView): Buffer; + function privateEncrypt(privateKey: RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView): NonSharedBuffer; /** * ```js * const { @@ -2417,7 +2437,7 @@ declare module "crypto" { inputEncoding?: BinaryToTextEncoding, outputEncoding?: "latin1" | "hex" | "base64" | "base64url", format?: "uncompressed" | "compressed" | "hybrid", - ): Buffer | string; + ): NonSharedBuffer | string; /** * Generates private and public EC Diffie-Hellman key values, and returns * the public key in the specified `format` and `encoding`. This key should be @@ -2430,7 +2450,7 @@ declare module "crypto" { * @param encoding The `encoding` of the return value. * @param [format='uncompressed'] */ - generateKeys(): Buffer; + generateKeys(): NonSharedBuffer; generateKeys(encoding: BinaryToTextEncoding, format?: ECDHKeyFormat): string; /** * Computes the shared secret using `otherPublicKey` as the other @@ -2449,8 +2469,8 @@ declare module "crypto" { * @param inputEncoding The `encoding` of the `otherPublicKey` string. * @param outputEncoding The `encoding` of the return value. */ - computeSecret(otherPublicKey: NodeJS.ArrayBufferView): Buffer; - computeSecret(otherPublicKey: string, inputEncoding: BinaryToTextEncoding): Buffer; + computeSecret(otherPublicKey: NodeJS.ArrayBufferView): NonSharedBuffer; + computeSecret(otherPublicKey: string, inputEncoding: BinaryToTextEncoding): NonSharedBuffer; computeSecret(otherPublicKey: NodeJS.ArrayBufferView, outputEncoding: BinaryToTextEncoding): string; computeSecret( otherPublicKey: string, @@ -2464,7 +2484,7 @@ declare module "crypto" { * @param encoding The `encoding` of the return value. * @return The EC Diffie-Hellman in the specified `encoding`. */ - getPrivateKey(): Buffer; + getPrivateKey(): NonSharedBuffer; getPrivateKey(encoding: BinaryToTextEncoding): string; /** * The `format` argument specifies point encoding and can be `'compressed'` or `'uncompressed'`. If `format` is not specified the point will be returned in`'uncompressed'` format. @@ -2476,7 +2496,7 @@ declare module "crypto" { * @param [format='uncompressed'] * @return The EC Diffie-Hellman public key in the specified `encoding` and `format`. */ - getPublicKey(encoding?: null, format?: ECDHKeyFormat): Buffer; + getPublicKey(encoding?: null, format?: ECDHKeyFormat): NonSharedBuffer; getPublicKey(encoding: BinaryToTextEncoding, format?: ECDHKeyFormat): string; /** * Sets the EC Diffie-Hellman private key. @@ -2757,15 +2777,15 @@ declare module "crypto" { function generateKeyPairSync( type: "rsa", options: RSAKeyPairOptions<"pem", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "rsa", options: RSAKeyPairOptions<"der", "pem">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "rsa", options: RSAKeyPairOptions<"der", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync(type: "rsa", options: RSAKeyPairKeyObjectOptions): KeyPairKeyObjectResult; function generateKeyPairSync( type: "rsa-pss", @@ -2774,15 +2794,15 @@ declare module "crypto" { function generateKeyPairSync( type: "rsa-pss", options: RSAPSSKeyPairOptions<"pem", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "rsa-pss", options: RSAPSSKeyPairOptions<"der", "pem">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "rsa-pss", options: RSAPSSKeyPairOptions<"der", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync(type: "rsa-pss", options: RSAPSSKeyPairKeyObjectOptions): KeyPairKeyObjectResult; function generateKeyPairSync( type: "dsa", @@ -2791,15 +2811,15 @@ declare module "crypto" { function generateKeyPairSync( type: "dsa", options: DSAKeyPairOptions<"pem", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "dsa", options: DSAKeyPairOptions<"der", "pem">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "dsa", options: DSAKeyPairOptions<"der", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync(type: "dsa", options: DSAKeyPairKeyObjectOptions): KeyPairKeyObjectResult; function generateKeyPairSync( type: "ec", @@ -2808,15 +2828,15 @@ declare module "crypto" { function generateKeyPairSync( type: "ec", options: ECKeyPairOptions<"pem", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "ec", options: ECKeyPairOptions<"der", "pem">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "ec", options: ECKeyPairOptions<"der", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync(type: "ec", options: ECKeyPairKeyObjectOptions): KeyPairKeyObjectResult; function generateKeyPairSync( type: "ed25519", @@ -2825,15 +2845,15 @@ declare module "crypto" { function generateKeyPairSync( type: "ed25519", options: ED25519KeyPairOptions<"pem", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "ed25519", options: ED25519KeyPairOptions<"der", "pem">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "ed25519", options: ED25519KeyPairOptions<"der", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync(type: "ed25519", options?: ED25519KeyPairKeyObjectOptions): KeyPairKeyObjectResult; function generateKeyPairSync( type: "ed448", @@ -2842,15 +2862,15 @@ declare module "crypto" { function generateKeyPairSync( type: "ed448", options: ED448KeyPairOptions<"pem", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "ed448", options: ED448KeyPairOptions<"der", "pem">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "ed448", options: ED448KeyPairOptions<"der", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync(type: "ed448", options?: ED448KeyPairKeyObjectOptions): KeyPairKeyObjectResult; function generateKeyPairSync( type: "x25519", @@ -2859,15 +2879,15 @@ declare module "crypto" { function generateKeyPairSync( type: "x25519", options: X25519KeyPairOptions<"pem", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "x25519", options: X25519KeyPairOptions<"der", "pem">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "x25519", options: X25519KeyPairOptions<"der", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync(type: "x25519", options?: X25519KeyPairKeyObjectOptions): KeyPairKeyObjectResult; function generateKeyPairSync( type: "x448", @@ -2876,15 +2896,15 @@ declare module "crypto" { function generateKeyPairSync( type: "x448", options: X448KeyPairOptions<"pem", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "x448", options: X448KeyPairOptions<"der", "pem">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "x448", options: X448KeyPairOptions<"der", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync(type: "x448", options?: X448KeyPairKeyObjectOptions): KeyPairKeyObjectResult; /** * Generates a new asymmetric key pair of the given `type`. RSA, RSA-PSS, DSA, EC, @@ -2933,17 +2953,17 @@ declare module "crypto" { function generateKeyPair( type: "rsa", options: RSAKeyPairOptions<"pem", "der">, - callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: string, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "rsa", options: RSAKeyPairOptions<"der", "pem">, - callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: string) => void, ): void; function generateKeyPair( type: "rsa", options: RSAKeyPairOptions<"der", "der">, - callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "rsa", @@ -2958,17 +2978,17 @@ declare module "crypto" { function generateKeyPair( type: "rsa-pss", options: RSAPSSKeyPairOptions<"pem", "der">, - callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: string, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "rsa-pss", options: RSAPSSKeyPairOptions<"der", "pem">, - callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: string) => void, ): void; function generateKeyPair( type: "rsa-pss", options: RSAPSSKeyPairOptions<"der", "der">, - callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "rsa-pss", @@ -2983,17 +3003,17 @@ declare module "crypto" { function generateKeyPair( type: "dsa", options: DSAKeyPairOptions<"pem", "der">, - callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: string, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "dsa", options: DSAKeyPairOptions<"der", "pem">, - callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: string) => void, ): void; function generateKeyPair( type: "dsa", options: DSAKeyPairOptions<"der", "der">, - callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "dsa", @@ -3008,17 +3028,17 @@ declare module "crypto" { function generateKeyPair( type: "ec", options: ECKeyPairOptions<"pem", "der">, - callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: string, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "ec", options: ECKeyPairOptions<"der", "pem">, - callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: string) => void, ): void; function generateKeyPair( type: "ec", options: ECKeyPairOptions<"der", "der">, - callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "ec", @@ -3033,17 +3053,17 @@ declare module "crypto" { function generateKeyPair( type: "ed25519", options: ED25519KeyPairOptions<"pem", "der">, - callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: string, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "ed25519", options: ED25519KeyPairOptions<"der", "pem">, - callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: string) => void, ): void; function generateKeyPair( type: "ed25519", options: ED25519KeyPairOptions<"der", "der">, - callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "ed25519", @@ -3058,17 +3078,17 @@ declare module "crypto" { function generateKeyPair( type: "ed448", options: ED448KeyPairOptions<"pem", "der">, - callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: string, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "ed448", options: ED448KeyPairOptions<"der", "pem">, - callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: string) => void, ): void; function generateKeyPair( type: "ed448", options: ED448KeyPairOptions<"der", "der">, - callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "ed448", @@ -3083,17 +3103,17 @@ declare module "crypto" { function generateKeyPair( type: "x25519", options: X25519KeyPairOptions<"pem", "der">, - callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: string, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "x25519", options: X25519KeyPairOptions<"der", "pem">, - callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: string) => void, ): void; function generateKeyPair( type: "x25519", options: X25519KeyPairOptions<"der", "der">, - callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "x25519", @@ -3108,17 +3128,17 @@ declare module "crypto" { function generateKeyPair( type: "x448", options: X448KeyPairOptions<"pem", "der">, - callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: string, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "x448", options: X448KeyPairOptions<"der", "pem">, - callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: string) => void, ): void; function generateKeyPair( type: "x448", options: X448KeyPairOptions<"der", "der">, - callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "x448", @@ -3138,21 +3158,21 @@ declare module "crypto" { options: RSAKeyPairOptions<"pem", "der">, ): Promise<{ publicKey: string; - privateKey: Buffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "rsa", options: RSAKeyPairOptions<"der", "pem">, ): Promise<{ - publicKey: Buffer; + publicKey: NonSharedBuffer; privateKey: string; }>; function __promisify__( type: "rsa", options: RSAKeyPairOptions<"der", "der">, ): Promise<{ - publicKey: Buffer; - privateKey: Buffer; + publicKey: NonSharedBuffer; + privateKey: NonSharedBuffer; }>; function __promisify__(type: "rsa", options: RSAKeyPairKeyObjectOptions): Promise; function __promisify__( @@ -3167,21 +3187,21 @@ declare module "crypto" { options: RSAPSSKeyPairOptions<"pem", "der">, ): Promise<{ publicKey: string; - privateKey: Buffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "rsa-pss", options: RSAPSSKeyPairOptions<"der", "pem">, ): Promise<{ - publicKey: Buffer; + publicKey: NonSharedBuffer; privateKey: string; }>; function __promisify__( type: "rsa-pss", options: RSAPSSKeyPairOptions<"der", "der">, ): Promise<{ - publicKey: Buffer; - privateKey: Buffer; + publicKey: NonSharedBuffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "rsa-pss", @@ -3199,21 +3219,21 @@ declare module "crypto" { options: DSAKeyPairOptions<"pem", "der">, ): Promise<{ publicKey: string; - privateKey: Buffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "dsa", options: DSAKeyPairOptions<"der", "pem">, ): Promise<{ - publicKey: Buffer; + publicKey: NonSharedBuffer; privateKey: string; }>; function __promisify__( type: "dsa", options: DSAKeyPairOptions<"der", "der">, ): Promise<{ - publicKey: Buffer; - privateKey: Buffer; + publicKey: NonSharedBuffer; + privateKey: NonSharedBuffer; }>; function __promisify__(type: "dsa", options: DSAKeyPairKeyObjectOptions): Promise; function __promisify__( @@ -3228,21 +3248,21 @@ declare module "crypto" { options: ECKeyPairOptions<"pem", "der">, ): Promise<{ publicKey: string; - privateKey: Buffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "ec", options: ECKeyPairOptions<"der", "pem">, ): Promise<{ - publicKey: Buffer; + publicKey: NonSharedBuffer; privateKey: string; }>; function __promisify__( type: "ec", options: ECKeyPairOptions<"der", "der">, ): Promise<{ - publicKey: Buffer; - privateKey: Buffer; + publicKey: NonSharedBuffer; + privateKey: NonSharedBuffer; }>; function __promisify__(type: "ec", options: ECKeyPairKeyObjectOptions): Promise; function __promisify__( @@ -3257,21 +3277,21 @@ declare module "crypto" { options: ED25519KeyPairOptions<"pem", "der">, ): Promise<{ publicKey: string; - privateKey: Buffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "ed25519", options: ED25519KeyPairOptions<"der", "pem">, ): Promise<{ - publicKey: Buffer; + publicKey: NonSharedBuffer; privateKey: string; }>; function __promisify__( type: "ed25519", options: ED25519KeyPairOptions<"der", "der">, ): Promise<{ - publicKey: Buffer; - privateKey: Buffer; + publicKey: NonSharedBuffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "ed25519", @@ -3289,21 +3309,21 @@ declare module "crypto" { options: ED448KeyPairOptions<"pem", "der">, ): Promise<{ publicKey: string; - privateKey: Buffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "ed448", options: ED448KeyPairOptions<"der", "pem">, ): Promise<{ - publicKey: Buffer; + publicKey: NonSharedBuffer; privateKey: string; }>; function __promisify__( type: "ed448", options: ED448KeyPairOptions<"der", "der">, ): Promise<{ - publicKey: Buffer; - privateKey: Buffer; + publicKey: NonSharedBuffer; + privateKey: NonSharedBuffer; }>; function __promisify__(type: "ed448", options?: ED448KeyPairKeyObjectOptions): Promise; function __promisify__( @@ -3318,21 +3338,21 @@ declare module "crypto" { options: X25519KeyPairOptions<"pem", "der">, ): Promise<{ publicKey: string; - privateKey: Buffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "x25519", options: X25519KeyPairOptions<"der", "pem">, ): Promise<{ - publicKey: Buffer; + publicKey: NonSharedBuffer; privateKey: string; }>; function __promisify__( type: "x25519", options: X25519KeyPairOptions<"der", "der">, ): Promise<{ - publicKey: Buffer; - privateKey: Buffer; + publicKey: NonSharedBuffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "x25519", @@ -3350,21 +3370,21 @@ declare module "crypto" { options: X448KeyPairOptions<"pem", "der">, ): Promise<{ publicKey: string; - privateKey: Buffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "x448", options: X448KeyPairOptions<"der", "pem">, ): Promise<{ - publicKey: Buffer; + publicKey: NonSharedBuffer; privateKey: string; }>; function __promisify__( type: "x448", options: X448KeyPairOptions<"der", "der">, ): Promise<{ - publicKey: Buffer; - privateKey: Buffer; + publicKey: NonSharedBuffer; + privateKey: NonSharedBuffer; }>; function __promisify__(type: "x448", options?: X448KeyPairKeyObjectOptions): Promise; } @@ -3384,12 +3404,12 @@ declare module "crypto" { algorithm: string | null | undefined, data: NodeJS.ArrayBufferView, key: KeyLike | SignKeyObjectInput | SignPrivateKeyInput | SignJsonWebKeyInput, - ): Buffer; + ): NonSharedBuffer; function sign( algorithm: string | null | undefined, data: NodeJS.ArrayBufferView, key: KeyLike | SignKeyObjectInput | SignPrivateKeyInput | SignJsonWebKeyInput, - callback: (error: Error | null, data: Buffer) => void, + callback: (error: Error | null, data: NonSharedBuffer) => void, ): void; /** * Verifies the given signature for `data` using the given key and algorithm. If `algorithm` is `null` or `undefined`, then the algorithm is dependent upon the @@ -3425,7 +3445,7 @@ declare module "crypto" { * Both keys must have the same `asymmetricKeyType`, which must be one of `'dh'` (for Diffie-Hellman), `'ec'` (for ECDH), `'x448'`, or `'x25519'` (for ECDH-ES). * @since v13.9.0, v12.17.0 */ - function diffieHellman(options: { privateKey: KeyObject; publicKey: KeyObject }): Buffer; + function diffieHellman(options: { privateKey: KeyObject; publicKey: KeyObject }): NonSharedBuffer; /** * A utility for creating one-shot hash digests of data. It can be faster than the object-based `crypto.createHash()` when hashing a smaller amount of data * (<= 5MB) that's readily available. If the data can be big or if it is streamed, it's still recommended to use `crypto.createHash()` instead. The `algorithm` @@ -3455,12 +3475,12 @@ declare module "crypto" { * @param [outputEncoding='hex'] [Encoding](https://nodejs.org/docs/latest-v20.x/api/buffer.html#buffers-and-character-encodings) used to encode the returned digest. */ function hash(algorithm: string, data: BinaryLike, outputEncoding?: BinaryToTextEncoding): string; - function hash(algorithm: string, data: BinaryLike, outputEncoding: "buffer"): Buffer; + function hash(algorithm: string, data: BinaryLike, outputEncoding: "buffer"): NonSharedBuffer; function hash( algorithm: string, data: BinaryLike, outputEncoding?: BinaryToTextEncoding | "buffer", - ): string | Buffer; + ): string | NonSharedBuffer; type CipherMode = "cbc" | "ccm" | "cfb" | "ctr" | "ecb" | "gcm" | "ocb" | "ofb" | "stream" | "wrap" | "xts"; interface CipherInfoOptions { /** @@ -3752,7 +3772,7 @@ declare module "crypto" { * A `Buffer` containing the DER encoding of this certificate. * @since v15.6.0 */ - readonly raw: Buffer; + readonly raw: NonSharedBuffer; /** * The serial number of this certificate. * diff --git a/types/node/v20/dgram.d.ts b/types/node/v20/dgram.d.ts index 625575e2670f47..4c7436729902a5 100644 --- a/types/node/v20/dgram.d.ts +++ b/types/node/v20/dgram.d.ts @@ -26,6 +26,7 @@ * @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/dgram.js) */ declare module "dgram" { + import { NonSharedBuffer } from "node:buffer"; import { AddressInfo } from "node:net"; import * as dns from "node:dns"; import { Abortable, EventEmitter } from "node:events"; @@ -82,8 +83,8 @@ declare module "dgram" { * @param options Available options are: * @param callback Attached as a listener for `'message'` events. Optional. */ - function createSocket(type: SocketType, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket; - function createSocket(options: SocketOptions, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket; + function createSocket(type: SocketType, callback?: (msg: NonSharedBuffer, rinfo: RemoteInfo) => void): Socket; + function createSocket(options: SocketOptions, callback?: (msg: NonSharedBuffer, rinfo: RemoteInfo) => void): Socket; /** * Encapsulates the datagram functionality. * @@ -553,37 +554,37 @@ declare module "dgram" { addListener(event: "connect", listener: () => void): this; addListener(event: "error", listener: (err: Error) => void): this; addListener(event: "listening", listener: () => void): this; - addListener(event: "message", listener: (msg: Buffer, rinfo: RemoteInfo) => void): this; + addListener(event: "message", listener: (msg: NonSharedBuffer, rinfo: RemoteInfo) => void): this; emit(event: string | symbol, ...args: any[]): boolean; emit(event: "close"): boolean; emit(event: "connect"): boolean; emit(event: "error", err: Error): boolean; emit(event: "listening"): boolean; - emit(event: "message", msg: Buffer, rinfo: RemoteInfo): boolean; + emit(event: "message", msg: NonSharedBuffer, rinfo: RemoteInfo): boolean; on(event: string, listener: (...args: any[]) => void): this; on(event: "close", listener: () => void): this; on(event: "connect", listener: () => void): this; on(event: "error", listener: (err: Error) => void): this; on(event: "listening", listener: () => void): this; - on(event: "message", listener: (msg: Buffer, rinfo: RemoteInfo) => void): this; + on(event: "message", listener: (msg: NonSharedBuffer, rinfo: RemoteInfo) => void): this; once(event: string, listener: (...args: any[]) => void): this; once(event: "close", listener: () => void): this; once(event: "connect", listener: () => void): this; once(event: "error", listener: (err: Error) => void): this; once(event: "listening", listener: () => void): this; - once(event: "message", listener: (msg: Buffer, rinfo: RemoteInfo) => void): this; + once(event: "message", listener: (msg: NonSharedBuffer, rinfo: RemoteInfo) => void): this; prependListener(event: string, listener: (...args: any[]) => void): this; prependListener(event: "close", listener: () => void): this; prependListener(event: "connect", listener: () => void): this; prependListener(event: "error", listener: (err: Error) => void): this; prependListener(event: "listening", listener: () => void): this; - prependListener(event: "message", listener: (msg: Buffer, rinfo: RemoteInfo) => void): this; + prependListener(event: "message", listener: (msg: NonSharedBuffer, rinfo: RemoteInfo) => void): this; prependOnceListener(event: string, listener: (...args: any[]) => void): this; prependOnceListener(event: "close", listener: () => void): this; prependOnceListener(event: "connect", listener: () => void): this; prependOnceListener(event: "error", listener: (err: Error) => void): this; prependOnceListener(event: "listening", listener: () => void): this; - prependOnceListener(event: "message", listener: (msg: Buffer, rinfo: RemoteInfo) => void): this; + prependOnceListener(event: "message", listener: (msg: NonSharedBuffer, rinfo: RemoteInfo) => void): this; /** * Calls `socket.close()` and returns a promise that fulfills when the socket has closed. * @since v20.5.0 diff --git a/types/node/v20/fs.d.ts b/types/node/v20/fs.d.ts index cd849a240bf2a2..4115ffe0508a88 100644 --- a/types/node/v20/fs.d.ts +++ b/types/node/v20/fs.d.ts @@ -19,6 +19,7 @@ * @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/fs.js) */ declare module "fs" { + import { NonSharedBuffer } from "node:buffer"; import * as stream from "node:stream"; import { Abortable, EventEmitter } from "node:events"; import { URL } from "node:url"; @@ -386,23 +387,29 @@ declare module "fs" { * 3. error */ addListener(event: string, listener: (...args: any[]) => void): this; - addListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this; + addListener(event: "change", listener: (eventType: string, filename: string | NonSharedBuffer) => void): this; addListener(event: "close", listener: () => void): this; addListener(event: "error", listener: (error: Error) => void): this; on(event: string, listener: (...args: any[]) => void): this; - on(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this; + on(event: "change", listener: (eventType: string, filename: string | NonSharedBuffer) => void): this; on(event: "close", listener: () => void): this; on(event: "error", listener: (error: Error) => void): this; once(event: string, listener: (...args: any[]) => void): this; - once(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this; + once(event: "change", listener: (eventType: string, filename: string | NonSharedBuffer) => void): this; once(event: "close", listener: () => void): this; once(event: "error", listener: (error: Error) => void): this; prependListener(event: string, listener: (...args: any[]) => void): this; - prependListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this; + prependListener( + event: "change", + listener: (eventType: string, filename: string | NonSharedBuffer) => void, + ): this; prependListener(event: "close", listener: () => void): this; prependListener(event: "error", listener: (error: Error) => void): this; prependOnceListener(event: string, listener: (...args: any[]) => void): this; - prependOnceListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this; + prependOnceListener( + event: "change", + listener: (eventType: string, filename: string | NonSharedBuffer) => void, + ): this; prependOnceListener(event: "close", listener: () => void): this; prependOnceListener(event: "error", listener: (error: Error) => void): this; } @@ -1318,7 +1325,7 @@ declare module "fs" { export function readlink( path: PathLike, options: BufferEncodingOption, - callback: (err: NodeJS.ErrnoException | null, linkString: Buffer) => void, + callback: (err: NodeJS.ErrnoException | null, linkString: NonSharedBuffer) => void, ): void; /** * Asynchronous readlink(2) - read value of a symbolic link. @@ -1328,7 +1335,7 @@ declare module "fs" { export function readlink( path: PathLike, options: EncodingOption, - callback: (err: NodeJS.ErrnoException | null, linkString: string | Buffer) => void, + callback: (err: NodeJS.ErrnoException | null, linkString: string | NonSharedBuffer) => void, ): void; /** * Asynchronous readlink(2) - read value of a symbolic link. @@ -1350,13 +1357,13 @@ declare module "fs" { * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function __promisify__(path: PathLike, options: BufferEncodingOption): Promise; + function __promisify__(path: PathLike, options: BufferEncodingOption): Promise; /** * Asynchronous readlink(2) - read value of a symbolic link. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function __promisify__(path: PathLike, options?: EncodingOption): Promise; + function __promisify__(path: PathLike, options?: EncodingOption): Promise; } /** * Returns the symbolic link's string value. @@ -1375,13 +1382,13 @@ declare module "fs" { * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - export function readlinkSync(path: PathLike, options: BufferEncodingOption): Buffer; + export function readlinkSync(path: PathLike, options: BufferEncodingOption): NonSharedBuffer; /** * Synchronous readlink(2) - read value of a symbolic link. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - export function readlinkSync(path: PathLike, options?: EncodingOption): string | Buffer; + export function readlinkSync(path: PathLike, options?: EncodingOption): string | NonSharedBuffer; /** * Asynchronously computes the canonical pathname by resolving `.`, `..`, and * symbolic links. @@ -1421,7 +1428,7 @@ declare module "fs" { export function realpath( path: PathLike, options: BufferEncodingOption, - callback: (err: NodeJS.ErrnoException | null, resolvedPath: Buffer) => void, + callback: (err: NodeJS.ErrnoException | null, resolvedPath: NonSharedBuffer) => void, ): void; /** * Asynchronous realpath(3) - return the canonicalized absolute pathname. @@ -1431,7 +1438,7 @@ declare module "fs" { export function realpath( path: PathLike, options: EncodingOption, - callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | Buffer) => void, + callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | NonSharedBuffer) => void, ): void; /** * Asynchronous realpath(3) - return the canonicalized absolute pathname. @@ -1453,13 +1460,13 @@ declare module "fs" { * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function __promisify__(path: PathLike, options: BufferEncodingOption): Promise; + function __promisify__(path: PathLike, options: BufferEncodingOption): Promise; /** * Asynchronous realpath(3) - return the canonicalized absolute pathname. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function __promisify__(path: PathLike, options?: EncodingOption): Promise; + function __promisify__(path: PathLike, options?: EncodingOption): Promise; /** * Asynchronous [`realpath(3)`](http://man7.org/linux/man-pages/man3/realpath.3.html). * @@ -1485,12 +1492,12 @@ declare module "fs" { function native( path: PathLike, options: BufferEncodingOption, - callback: (err: NodeJS.ErrnoException | null, resolvedPath: Buffer) => void, + callback: (err: NodeJS.ErrnoException | null, resolvedPath: NonSharedBuffer) => void, ): void; function native( path: PathLike, options: EncodingOption, - callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | Buffer) => void, + callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | NonSharedBuffer) => void, ): void; function native( path: PathLike, @@ -1510,17 +1517,17 @@ declare module "fs" { * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - export function realpathSync(path: PathLike, options: BufferEncodingOption): Buffer; + export function realpathSync(path: PathLike, options: BufferEncodingOption): NonSharedBuffer; /** * Synchronous realpath(3) - return the canonicalized absolute pathname. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - export function realpathSync(path: PathLike, options?: EncodingOption): string | Buffer; + export function realpathSync(path: PathLike, options?: EncodingOption): string | NonSharedBuffer; export namespace realpathSync { function native(path: PathLike, options?: EncodingOption): string; - function native(path: PathLike, options: BufferEncodingOption): Buffer; - function native(path: PathLike, options?: EncodingOption): string | Buffer; + function native(path: PathLike, options: BufferEncodingOption): NonSharedBuffer; + function native(path: PathLike, options?: EncodingOption): string | NonSharedBuffer; } /** * Asynchronously removes a file or symbolic link. No arguments other than a @@ -1890,12 +1897,8 @@ declare module "fs" { */ export function mkdtemp( prefix: string, - options: - | "buffer" - | { - encoding: "buffer"; - }, - callback: (err: NodeJS.ErrnoException | null, folder: Buffer) => void, + options: BufferEncodingOption, + callback: (err: NodeJS.ErrnoException | null, folder: NonSharedBuffer) => void, ): void; /** * Asynchronously creates a unique temporary directory. @@ -1905,7 +1908,7 @@ declare module "fs" { export function mkdtemp( prefix: string, options: EncodingOption, - callback: (err: NodeJS.ErrnoException | null, folder: string | Buffer) => void, + callback: (err: NodeJS.ErrnoException | null, folder: string | NonSharedBuffer) => void, ): void; /** * Asynchronously creates a unique temporary directory. @@ -1927,13 +1930,13 @@ declare module "fs" { * Generates six random characters to be appended behind a required prefix to create a unique temporary directory. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function __promisify__(prefix: string, options: BufferEncodingOption): Promise; + function __promisify__(prefix: string, options: BufferEncodingOption): Promise; /** * Asynchronously creates a unique temporary directory. * Generates six random characters to be appended behind a required prefix to create a unique temporary directory. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function __promisify__(prefix: string, options?: EncodingOption): Promise; + function __promisify__(prefix: string, options?: EncodingOption): Promise; } /** * Returns the created directory path. @@ -1951,13 +1954,13 @@ declare module "fs" { * Generates six random characters to be appended behind a required prefix to create a unique temporary directory. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - export function mkdtempSync(prefix: string, options: BufferEncodingOption): Buffer; + export function mkdtempSync(prefix: string, options: BufferEncodingOption): NonSharedBuffer; /** * Synchronously creates a unique temporary directory. * Generates six random characters to be appended behind a required prefix to create a unique temporary directory. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - export function mkdtempSync(prefix: string, options?: EncodingOption): string | Buffer; + export function mkdtempSync(prefix: string, options?: EncodingOption): string | NonSharedBuffer; /** * Reads the contents of a directory. The callback gets two arguments `(err, files)` where `files` is an array of the names of the files in the directory excluding `'.'` and `'..'`. * @@ -1998,7 +2001,7 @@ declare module "fs" { recursive?: boolean | undefined; } | "buffer", - callback: (err: NodeJS.ErrnoException | null, files: Buffer[]) => void, + callback: (err: NodeJS.ErrnoException | null, files: NonSharedBuffer[]) => void, ): void; /** * Asynchronous readdir(3) - read a directory. @@ -2015,7 +2018,7 @@ declare module "fs" { | BufferEncoding | undefined | null, - callback: (err: NodeJS.ErrnoException | null, files: string[] | Buffer[]) => void, + callback: (err: NodeJS.ErrnoException | null, files: string[] | NonSharedBuffer[]) => void, ): void; /** * Asynchronous readdir(3) - read a directory. @@ -2050,7 +2053,7 @@ declare module "fs" { withFileTypes: true; recursive?: boolean | undefined; }, - callback: (err: NodeJS.ErrnoException | null, files: Dirent[]) => void, + callback: (err: NodeJS.ErrnoException | null, files: Dirent[]) => void, ): void; export namespace readdir { /** @@ -2083,7 +2086,7 @@ declare module "fs" { withFileTypes?: false | undefined; recursive?: boolean | undefined; }, - ): Promise; + ): Promise; /** * Asynchronous readdir(3) - read a directory. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. @@ -2098,7 +2101,7 @@ declare module "fs" { }) | BufferEncoding | null, - ): Promise; + ): Promise; /** * Asynchronous readdir(3) - read a directory. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. @@ -2123,7 +2126,7 @@ declare module "fs" { withFileTypes: true; recursive?: boolean | undefined; }, - ): Promise[]>; + ): Promise[]>; } /** * Reads the contents of the directory. @@ -2163,7 +2166,7 @@ declare module "fs" { recursive?: boolean | undefined; } | "buffer", - ): Buffer[]; + ): NonSharedBuffer[]; /** * Synchronous readdir(3) - read a directory. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. @@ -2178,7 +2181,7 @@ declare module "fs" { }) | BufferEncoding | null, - ): string[] | Buffer[]; + ): string[] | NonSharedBuffer[]; /** * Synchronous readdir(3) - read a directory. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. @@ -2203,7 +2206,7 @@ declare module "fs" { withFileTypes: true; recursive?: boolean | undefined; }, - ): Dirent[]; + ): Dirent[]; /** * Closes the file descriptor. No arguments other than a possible exception are * given to the completion callback. @@ -2570,7 +2573,7 @@ declare module "fs" { encoding?: BufferEncoding | null, ): number; export type ReadPosition = number | bigint; - export interface ReadSyncOptions { + export interface ReadOptions { /** * @default 0 */ @@ -2584,9 +2587,15 @@ declare module "fs" { */ position?: ReadPosition | null | undefined; } - export interface ReadAsyncOptions extends ReadSyncOptions { - buffer?: TBuffer; + export interface ReadOptionsWithBuffer extends ReadOptions { + buffer?: T | undefined; } + /** @deprecated Use `ReadOptions` instead. */ + // TODO: remove in future major + export interface ReadSyncOptions extends ReadOptions {} + /** @deprecated Use `ReadOptionsWithBuffer` instead. */ + // TODO: remove in future major + export interface ReadAsyncOptions extends ReadOptionsWithBuffer {} /** * Read data from the file specified by `fd`. * @@ -2621,15 +2630,15 @@ declare module "fs" { * `position` defaults to `null` * @since v12.17.0, 13.11.0 */ - export function read( + export function read( fd: number, - options: ReadAsyncOptions, + options: ReadOptionsWithBuffer, callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void, ): void; export function read( fd: number, buffer: TBuffer, - options: ReadSyncOptions, + options: ReadOptions, callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void, ): void; export function read( @@ -2639,7 +2648,7 @@ declare module "fs" { ): void; export function read( fd: number, - callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: NodeJS.ArrayBufferView) => void, + callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: NonSharedBuffer) => void, ): void; export namespace read { /** @@ -2659,16 +2668,16 @@ declare module "fs" { bytesRead: number; buffer: TBuffer; }>; - function __promisify__( + function __promisify__( fd: number, - options: ReadAsyncOptions, + options: ReadOptionsWithBuffer, ): Promise<{ bytesRead: number; buffer: TBuffer; }>; function __promisify__(fd: number): Promise<{ bytesRead: number; - buffer: NodeJS.ArrayBufferView; + buffer: NonSharedBuffer; }>; } /** @@ -2690,7 +2699,7 @@ declare module "fs" { * Similar to the above `fs.readSync` function, this version takes an optional `options` object. * If no `options` object is specified, it will default with the above values. */ - export function readSync(fd: number, buffer: NodeJS.ArrayBufferView, opts?: ReadSyncOptions): number; + export function readSync(fd: number, buffer: NodeJS.ArrayBufferView, opts?: ReadOptions): number; /** * Asynchronously reads the entire contents of a file. * @@ -3356,7 +3365,7 @@ declare module "fs" { encoding: "buffer"; }) | "buffer", - listener?: WatchListener, + listener?: WatchListener, ): FSWatcher; /** * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`. @@ -3382,7 +3391,7 @@ declare module "fs" { export function watch( filename: PathLike, options: WatchOptions | string, - listener?: WatchListener, + listener?: WatchListener, ): FSWatcher; /** * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`. @@ -4100,27 +4109,29 @@ declare module "fs" { * @since v12.9.0 * @param [position='null'] */ - export function writev( + export function writev( fd: number, - buffers: readonly NodeJS.ArrayBufferView[], - cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void, + buffers: TBuffers, + cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: TBuffers) => void, ): void; - export function writev( + export function writev( fd: number, - buffers: readonly NodeJS.ArrayBufferView[], + buffers: TBuffers, position: number | null, - cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void, + cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: TBuffers) => void, ): void; - export interface WriteVResult { + // Providing a default type parameter doesn't provide true BC for userland consumers, but at least suppresses TS2314 + // TODO: remove default in future major version + export interface WriteVResult { bytesWritten: number; - buffers: NodeJS.ArrayBufferView[]; + buffers: T; } export namespace writev { - function __promisify__( + function __promisify__( fd: number, - buffers: readonly NodeJS.ArrayBufferView[], + buffers: TBuffers, position?: number, - ): Promise; + ): Promise>; } /** * For detailed information, see the documentation of the asynchronous version of @@ -4145,27 +4156,29 @@ declare module "fs" { * @since v13.13.0, v12.17.0 * @param [position='null'] */ - export function readv( + export function readv( fd: number, - buffers: readonly NodeJS.ArrayBufferView[], - cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => void, + buffers: TBuffers, + cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: TBuffers) => void, ): void; - export function readv( + export function readv( fd: number, - buffers: readonly NodeJS.ArrayBufferView[], + buffers: TBuffers, position: number | null, - cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => void, + cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: TBuffers) => void, ): void; - export interface ReadVResult { + // Providing a default type parameter doesn't provide true BC for userland consumers, but at least suppresses TS2314 + // TODO: remove default in future major version + export interface ReadVResult { bytesRead: number; - buffers: NodeJS.ArrayBufferView[]; + buffers: T; } export namespace readv { - function __promisify__( + function __promisify__( fd: number, - buffers: readonly NodeJS.ArrayBufferView[], + buffers: TBuffers, position?: number, - ): Promise; + ): Promise>; } /** * For detailed information, see the documentation of the asynchronous version of diff --git a/types/node/v20/fs/promises.d.ts b/types/node/v20/fs/promises.d.ts index 52f979baccc820..7cc4deed0762c6 100644 --- a/types/node/v20/fs/promises.d.ts +++ b/types/node/v20/fs/promises.d.ts @@ -9,6 +9,7 @@ * @since v10.0.0 */ declare module "fs/promises" { + import { NonSharedBuffer } from "node:buffer"; import { Abortable } from "node:events"; import { Stream } from "node:stream"; import { ReadableStream } from "node:stream/web"; @@ -26,6 +27,8 @@ declare module "fs/promises" { OpenDirOptions, OpenMode, PathLike, + ReadOptions, + ReadOptionsWithBuffer, ReadStream, ReadVResult, RmDirOptions, @@ -53,6 +56,7 @@ declare module "fs/promises" { bytesRead: number; buffer: T; } + /** @deprecated This interface will be removed in a future version. Use `import { ReadOptionsWithBuffer } from "node:fs"` instead. */ interface FileReadOptions { /** * @default `Buffer.alloc(0xffff)` @@ -235,7 +239,13 @@ declare module "fs/promises" { length?: number | null, position?: number | null, ): Promise>; - read(options?: FileReadOptions): Promise>; + read( + buffer: T, + options?: ReadOptions, + ): Promise>; + read( + options?: ReadOptionsWithBuffer, + ): Promise>; /** * Returns a `ReadableStream` that may be used to read the files data. * @@ -279,7 +289,7 @@ declare module "fs/promises" { options?: | ({ encoding?: null | undefined } & Abortable) | null, - ): Promise; + ): Promise; /** * Asynchronously reads the entire contents of a file. The underlying file will _not_ be closed automatically. * The `FileHandle` must have been opened for reading. @@ -298,7 +308,7 @@ declare module "fs/promises" { | (ObjectEncodingOptions & Abortable) | BufferEncoding | null, - ): Promise; + ): Promise; /** * Convenience method to create a `readline` interface and stream over the file. * See `filehandle.createReadStream()` for the options. @@ -407,7 +417,7 @@ declare module "fs/promises" { * @param [position='null'] The offset from the beginning of the file where the data from `buffer` should be written. If `position` is not a `number`, the data will be written at the current * position. See the POSIX pwrite(2) documentation for more detail. */ - write( + write( buffer: TBuffer, offset?: number | null, length?: number | null, @@ -439,14 +449,20 @@ declare module "fs/promises" { * @param [position='null'] The offset from the beginning of the file where the data from `buffers` should be written. If `position` is not a `number`, the data will be written at the current * position. */ - writev(buffers: readonly NodeJS.ArrayBufferView[], position?: number): Promise; + writev( + buffers: TBuffers, + position?: number, + ): Promise>; /** * Read from a file and write to an array of [ArrayBufferView](https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView) s * @since v13.13.0, v12.17.0 * @param [position='null'] The offset from the beginning of the file where the data should be read from. If `position` is not a `number`, the data will be read from the current position. * @return Fulfills upon success an object containing two properties: */ - readv(buffers: readonly NodeJS.ArrayBufferView[], position?: number): Promise; + readv( + buffers: TBuffers, + position?: number, + ): Promise>; /** * Closes the file handle after waiting for any pending operation on the handle to * complete. @@ -682,7 +698,7 @@ declare module "fs/promises" { recursive?: boolean | undefined; } | "buffer", - ): Promise; + ): Promise; /** * Asynchronous readdir(3) - read a directory. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. @@ -697,7 +713,7 @@ declare module "fs/promises" { }) | BufferEncoding | null, - ): Promise; + ): Promise; /** * Asynchronous readdir(3) - read a directory. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. @@ -722,7 +738,7 @@ declare module "fs/promises" { withFileTypes: true; recursive?: boolean | undefined; }, - ): Promise[]>; + ): Promise[]>; /** * Reads the contents of the symbolic link referred to by `path`. See the POSIX [`readlink(2)`](http://man7.org/linux/man-pages/man2/readlink.2.html) documentation for more detail. The promise is * fulfilled with the`linkString` upon success. @@ -740,13 +756,16 @@ declare module "fs/promises" { * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function readlink(path: PathLike, options: BufferEncodingOption): Promise; + function readlink(path: PathLike, options: BufferEncodingOption): Promise; /** * Asynchronous readlink(2) - read value of a symbolic link. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function readlink(path: PathLike, options?: ObjectEncodingOptions | string | null): Promise; + function readlink( + path: PathLike, + options?: ObjectEncodingOptions | string | null, + ): Promise; /** * Creates a symbolic link. * @@ -897,7 +916,7 @@ declare module "fs/promises" { * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function realpath(path: PathLike, options: BufferEncodingOption): Promise; + function realpath(path: PathLike, options: BufferEncodingOption): Promise; /** * Asynchronous realpath(3) - return the canonicalized absolute pathname. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. @@ -906,7 +925,7 @@ declare module "fs/promises" { function realpath( path: PathLike, options?: ObjectEncodingOptions | BufferEncoding | null, - ): Promise; + ): Promise; /** * Creates a unique temporary directory. A unique directory name is generated by * appending six random characters to the end of the provided `prefix`. Due to @@ -942,13 +961,16 @@ declare module "fs/promises" { * Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function mkdtemp(prefix: string, options: BufferEncodingOption): Promise; + function mkdtemp(prefix: string, options: BufferEncodingOption): Promise; /** * Asynchronously creates a unique temporary directory. * Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function mkdtemp(prefix: string, options?: ObjectEncodingOptions | BufferEncoding | null): Promise; + function mkdtemp( + prefix: string, + options?: ObjectEncodingOptions | BufferEncoding | null, + ): Promise; /** * Asynchronously writes data to a file, replacing the file if it already exists. `data` can be a string, a buffer, an * [AsyncIterable](https://tc39.github.io/ecma262/#sec-asynciterable-interface), or an @@ -1104,7 +1126,7 @@ declare module "fs/promises" { flag?: OpenMode | undefined; } & Abortable) | null, - ): Promise; + ): Promise; /** * Asynchronously reads the entire contents of a file. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. @@ -1140,7 +1162,7 @@ declare module "fs/promises" { ) | BufferEncoding | null, - ): Promise; + ): Promise; /** * Asynchronously open a directory for iterative scanning. See the POSIX [`opendir(3)`](http://man7.org/linux/man-pages/man3/opendir.3.html) documentation for more detail. * @@ -1207,7 +1229,7 @@ declare module "fs/promises" { encoding: "buffer"; }) | "buffer", - ): AsyncIterable>; + ): AsyncIterable>; /** * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`. * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol. @@ -1228,7 +1250,7 @@ declare module "fs/promises" { function watch( filename: PathLike, options: WatchOptions | string, - ): AsyncIterable> | AsyncIterable>; + ): AsyncIterable> | AsyncIterable>; /** * Asynchronously copies the entire directory structure from `src` to `dest`, * including subdirectories and files. diff --git a/types/node/v20/globals.typedarray.d.ts b/types/node/v20/globals.typedarray.d.ts index 0c7280c3d8a9a6..8eafc3b464c5ad 100644 --- a/types/node/v20/globals.typedarray.d.ts +++ b/types/node/v20/globals.typedarray.d.ts @@ -17,5 +17,22 @@ declare global { type ArrayBufferView = | TypedArray | DataView; + + // The following aliases are required to allow use of non-shared ArrayBufferViews in @types/node + // while maintaining compatibility with TS <=5.6. + type NonSharedUint8Array = Uint8Array; + type NonSharedUint8ClampedArray = Uint8ClampedArray; + type NonSharedUint16Array = Uint16Array; + type NonSharedUint32Array = Uint32Array; + type NonSharedInt8Array = Int8Array; + type NonSharedInt16Array = Int16Array; + type NonSharedInt32Array = Int32Array; + type NonSharedBigUint64Array = BigUint64Array; + type NonSharedBigInt64Array = BigInt64Array; + type NonSharedFloat32Array = Float32Array; + type NonSharedFloat64Array = Float64Array; + type NonSharedDataView = DataView; + type NonSharedTypedArray = TypedArray; + type NonSharedArrayBufferView = ArrayBufferView; } } diff --git a/types/node/v20/http.d.ts b/types/node/v20/http.d.ts index 595e532adc8ce0..168c549820e421 100644 --- a/types/node/v20/http.d.ts +++ b/types/node/v20/http.d.ts @@ -40,6 +40,7 @@ * @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/http.js) */ declare module "http" { + import { NonSharedBuffer } from "node:buffer"; import * as stream from "node:stream"; import { URL } from "node:url"; import { LookupOptions } from "node:dns"; @@ -457,13 +458,13 @@ declare module "http" { addListener(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this; addListener( event: "connect", - listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, ): this; addListener(event: "dropRequest", listener: (req: InstanceType, socket: stream.Duplex) => void): this; addListener(event: "request", listener: RequestListener): this; addListener( event: "upgrade", - listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, ): this; emit(event: string, ...args: any[]): boolean; emit(event: "close"): boolean; @@ -481,14 +482,14 @@ declare module "http" { res: InstanceType & { req: InstanceType }, ): boolean; emit(event: "clientError", err: Error, socket: stream.Duplex): boolean; - emit(event: "connect", req: InstanceType, socket: stream.Duplex, head: Buffer): boolean; + emit(event: "connect", req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer): boolean; emit(event: "dropRequest", req: InstanceType, socket: stream.Duplex): boolean; emit( event: "request", req: InstanceType, res: InstanceType & { req: InstanceType }, ): boolean; - emit(event: "upgrade", req: InstanceType, socket: stream.Duplex, head: Buffer): boolean; + emit(event: "upgrade", req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer): boolean; on(event: string, listener: (...args: any[]) => void): this; on(event: "close", listener: () => void): this; on(event: "connection", listener: (socket: Socket) => void): this; @@ -497,10 +498,16 @@ declare module "http" { on(event: "checkContinue", listener: RequestListener): this; on(event: "checkExpectation", listener: RequestListener): this; on(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this; - on(event: "connect", listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void): this; + on( + event: "connect", + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, + ): this; on(event: "dropRequest", listener: (req: InstanceType, socket: stream.Duplex) => void): this; on(event: "request", listener: RequestListener): this; - on(event: "upgrade", listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void): this; + on( + event: "upgrade", + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, + ): this; once(event: string, listener: (...args: any[]) => void): this; once(event: "close", listener: () => void): this; once(event: "connection", listener: (socket: Socket) => void): this; @@ -511,13 +518,13 @@ declare module "http" { once(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this; once( event: "connect", - listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, ): this; once(event: "dropRequest", listener: (req: InstanceType, socket: stream.Duplex) => void): this; once(event: "request", listener: RequestListener): this; once( event: "upgrade", - listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, ): this; prependListener(event: string, listener: (...args: any[]) => void): this; prependListener(event: "close", listener: () => void): this; @@ -529,7 +536,7 @@ declare module "http" { prependListener(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this; prependListener( event: "connect", - listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, ): this; prependListener( event: "dropRequest", @@ -538,7 +545,7 @@ declare module "http" { prependListener(event: "request", listener: RequestListener): this; prependListener( event: "upgrade", - listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, ): this; prependOnceListener(event: string, listener: (...args: any[]) => void): this; prependOnceListener(event: "close", listener: () => void): this; @@ -550,7 +557,7 @@ declare module "http" { prependOnceListener(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this; prependOnceListener( event: "connect", - listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, ): this; prependOnceListener( event: "dropRequest", @@ -559,7 +566,7 @@ declare module "http" { prependOnceListener(event: "request", listener: RequestListener): this; prependOnceListener( event: "upgrade", - listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, ): this; } /** @@ -1079,7 +1086,7 @@ declare module "http" { addListener(event: "abort", listener: () => void): this; addListener( event: "connect", - listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void, + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, ): this; addListener(event: "continue", listener: () => void): this; addListener(event: "information", listener: (info: InformationEvent) => void): this; @@ -1088,7 +1095,7 @@ declare module "http" { addListener(event: "timeout", listener: () => void): this; addListener( event: "upgrade", - listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void, + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, ): this; addListener(event: "close", listener: () => void): this; addListener(event: "drain", listener: () => void): this; @@ -1101,13 +1108,19 @@ declare module "http" { * @deprecated */ on(event: "abort", listener: () => void): this; - on(event: "connect", listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this; + on( + event: "connect", + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, + ): this; on(event: "continue", listener: () => void): this; on(event: "information", listener: (info: InformationEvent) => void): this; on(event: "response", listener: (response: IncomingMessage) => void): this; on(event: "socket", listener: (socket: Socket) => void): this; on(event: "timeout", listener: () => void): this; - on(event: "upgrade", listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this; + on( + event: "upgrade", + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, + ): this; on(event: "close", listener: () => void): this; on(event: "drain", listener: () => void): this; on(event: "error", listener: (err: Error) => void): this; @@ -1119,13 +1132,19 @@ declare module "http" { * @deprecated */ once(event: "abort", listener: () => void): this; - once(event: "connect", listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this; + once( + event: "connect", + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, + ): this; once(event: "continue", listener: () => void): this; once(event: "information", listener: (info: InformationEvent) => void): this; once(event: "response", listener: (response: IncomingMessage) => void): this; once(event: "socket", listener: (socket: Socket) => void): this; once(event: "timeout", listener: () => void): this; - once(event: "upgrade", listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this; + once( + event: "upgrade", + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, + ): this; once(event: "close", listener: () => void): this; once(event: "drain", listener: () => void): this; once(event: "error", listener: (err: Error) => void): this; @@ -1139,7 +1158,7 @@ declare module "http" { prependListener(event: "abort", listener: () => void): this; prependListener( event: "connect", - listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void, + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, ): this; prependListener(event: "continue", listener: () => void): this; prependListener(event: "information", listener: (info: InformationEvent) => void): this; @@ -1148,7 +1167,7 @@ declare module "http" { prependListener(event: "timeout", listener: () => void): this; prependListener( event: "upgrade", - listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void, + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, ): this; prependListener(event: "close", listener: () => void): this; prependListener(event: "drain", listener: () => void): this; @@ -1163,7 +1182,7 @@ declare module "http" { prependOnceListener(event: "abort", listener: () => void): this; prependOnceListener( event: "connect", - listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void, + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, ): this; prependOnceListener(event: "continue", listener: () => void): this; prependOnceListener(event: "information", listener: (info: InformationEvent) => void): this; @@ -1172,7 +1191,7 @@ declare module "http" { prependOnceListener(event: "timeout", listener: () => void): this; prependOnceListener( event: "upgrade", - listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void, + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, ): this; prependOnceListener(event: "close", listener: () => void): this; prependOnceListener(event: "drain", listener: () => void): this; diff --git a/types/node/v20/http2.d.ts b/types/node/v20/http2.d.ts index b67734a03cf576..9c69a191c0444e 100644 --- a/types/node/v20/http2.d.ts +++ b/types/node/v20/http2.d.ts @@ -9,6 +9,7 @@ * @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/http2.js) */ declare module "http2" { + import { NonSharedBuffer } from "node:buffer"; import EventEmitter = require("node:events"); import * as fs from "node:fs"; import * as net from "node:net"; @@ -196,7 +197,7 @@ declare module "http2" { sendTrailers(headers: OutgoingHttpHeaders): void; addListener(event: "aborted", listener: () => void): this; addListener(event: "close", listener: () => void): this; - addListener(event: "data", listener: (chunk: Buffer | string) => void): this; + addListener(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; addListener(event: "drain", listener: () => void): this; addListener(event: "end", listener: () => void): this; addListener(event: "error", listener: (err: Error) => void): this; @@ -211,7 +212,7 @@ declare module "http2" { addListener(event: string | symbol, listener: (...args: any[]) => void): this; emit(event: "aborted"): boolean; emit(event: "close"): boolean; - emit(event: "data", chunk: Buffer | string): boolean; + emit(event: "data", chunk: NonSharedBuffer | string): boolean; emit(event: "drain"): boolean; emit(event: "end"): boolean; emit(event: "error", err: Error): boolean; @@ -226,7 +227,7 @@ declare module "http2" { emit(event: string | symbol, ...args: any[]): boolean; on(event: "aborted", listener: () => void): this; on(event: "close", listener: () => void): this; - on(event: "data", listener: (chunk: Buffer | string) => void): this; + on(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; on(event: "drain", listener: () => void): this; on(event: "end", listener: () => void): this; on(event: "error", listener: (err: Error) => void): this; @@ -241,7 +242,7 @@ declare module "http2" { on(event: string | symbol, listener: (...args: any[]) => void): this; once(event: "aborted", listener: () => void): this; once(event: "close", listener: () => void): this; - once(event: "data", listener: (chunk: Buffer | string) => void): this; + once(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; once(event: "drain", listener: () => void): this; once(event: "end", listener: () => void): this; once(event: "error", listener: (err: Error) => void): this; @@ -256,7 +257,7 @@ declare module "http2" { once(event: string | symbol, listener: (...args: any[]) => void): this; prependListener(event: "aborted", listener: () => void): this; prependListener(event: "close", listener: () => void): this; - prependListener(event: "data", listener: (chunk: Buffer | string) => void): this; + prependListener(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; prependListener(event: "drain", listener: () => void): this; prependListener(event: "end", listener: () => void): this; prependListener(event: "error", listener: (err: Error) => void): this; @@ -271,7 +272,7 @@ declare module "http2" { prependListener(event: string | symbol, listener: (...args: any[]) => void): this; prependOnceListener(event: "aborted", listener: () => void): this; prependOnceListener(event: "close", listener: () => void): this; - prependOnceListener(event: "data", listener: (chunk: Buffer | string) => void): this; + prependOnceListener(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; prependOnceListener(event: "drain", listener: () => void): this; prependOnceListener(event: "end", listener: () => void): this; prependOnceListener(event: "error", listener: (err: Error) => void): this; @@ -790,10 +791,10 @@ declare module "http2" { * @since v8.9.3 * @param payload Optional ping payload. */ - ping(callback: (err: Error | null, duration: number, payload: Buffer) => void): boolean; + ping(callback: (err: Error | null, duration: number, payload: NonSharedBuffer) => void): boolean; ping( payload: NodeJS.ArrayBufferView, - callback: (err: Error | null, duration: number, payload: Buffer) => void, + callback: (err: Error | null, duration: number, payload: NonSharedBuffer) => void, ): boolean; /** * Calls `ref()` on this `Http2Session` instance's underlying `net.Socket`. @@ -855,7 +856,7 @@ declare module "http2" { ): this; addListener( event: "goaway", - listener: (errorCode: number, lastStreamID: number, opaqueData?: Buffer) => void, + listener: (errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer) => void, ): this; addListener(event: "localSettings", listener: (settings: Settings) => void): this; addListener(event: "ping", listener: () => void): this; @@ -865,7 +866,7 @@ declare module "http2" { emit(event: "close"): boolean; emit(event: "error", err: Error): boolean; emit(event: "frameError", frameType: number, errorCode: number, streamID: number): boolean; - emit(event: "goaway", errorCode: number, lastStreamID: number, opaqueData?: Buffer): boolean; + emit(event: "goaway", errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer): boolean; emit(event: "localSettings", settings: Settings): boolean; emit(event: "ping"): boolean; emit(event: "remoteSettings", settings: Settings): boolean; @@ -874,7 +875,10 @@ declare module "http2" { on(event: "close", listener: () => void): this; on(event: "error", listener: (err: Error) => void): this; on(event: "frameError", listener: (frameType: number, errorCode: number, streamID: number) => void): this; - on(event: "goaway", listener: (errorCode: number, lastStreamID: number, opaqueData?: Buffer) => void): this; + on( + event: "goaway", + listener: (errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer) => void, + ): this; on(event: "localSettings", listener: (settings: Settings) => void): this; on(event: "ping", listener: () => void): this; on(event: "remoteSettings", listener: (settings: Settings) => void): this; @@ -883,7 +887,10 @@ declare module "http2" { once(event: "close", listener: () => void): this; once(event: "error", listener: (err: Error) => void): this; once(event: "frameError", listener: (frameType: number, errorCode: number, streamID: number) => void): this; - once(event: "goaway", listener: (errorCode: number, lastStreamID: number, opaqueData?: Buffer) => void): this; + once( + event: "goaway", + listener: (errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer) => void, + ): this; once(event: "localSettings", listener: (settings: Settings) => void): this; once(event: "ping", listener: () => void): this; once(event: "remoteSettings", listener: (settings: Settings) => void): this; @@ -897,7 +904,7 @@ declare module "http2" { ): this; prependListener( event: "goaway", - listener: (errorCode: number, lastStreamID: number, opaqueData?: Buffer) => void, + listener: (errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer) => void, ): this; prependListener(event: "localSettings", listener: (settings: Settings) => void): this; prependListener(event: "ping", listener: () => void): this; @@ -912,7 +919,7 @@ declare module "http2" { ): this; prependOnceListener( event: "goaway", - listener: (errorCode: number, lastStreamID: number, opaqueData?: Buffer) => void, + listener: (errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer) => void, ): this; prependOnceListener(event: "localSettings", listener: (settings: Settings) => void): this; prependOnceListener(event: "ping", listener: () => void): this; @@ -1791,45 +1798,45 @@ declare module "http2" { * @since v8.4.0 */ setTimeout(msecs: number, callback?: () => void): void; - read(size?: number): Buffer | string | null; + read(size?: number): NonSharedBuffer | string | null; addListener(event: "aborted", listener: (hadError: boolean, code: number) => void): this; addListener(event: "close", listener: () => void): this; - addListener(event: "data", listener: (chunk: Buffer | string) => void): this; + addListener(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; addListener(event: "end", listener: () => void): this; addListener(event: "readable", listener: () => void): this; addListener(event: "error", listener: (err: Error) => void): this; addListener(event: string | symbol, listener: (...args: any[]) => void): this; emit(event: "aborted", hadError: boolean, code: number): boolean; emit(event: "close"): boolean; - emit(event: "data", chunk: Buffer | string): boolean; + emit(event: "data", chunk: NonSharedBuffer | string): boolean; emit(event: "end"): boolean; emit(event: "readable"): boolean; emit(event: "error", err: Error): boolean; emit(event: string | symbol, ...args: any[]): boolean; on(event: "aborted", listener: (hadError: boolean, code: number) => void): this; on(event: "close", listener: () => void): this; - on(event: "data", listener: (chunk: Buffer | string) => void): this; + on(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; on(event: "end", listener: () => void): this; on(event: "readable", listener: () => void): this; on(event: "error", listener: (err: Error) => void): this; on(event: string | symbol, listener: (...args: any[]) => void): this; once(event: "aborted", listener: (hadError: boolean, code: number) => void): this; once(event: "close", listener: () => void): this; - once(event: "data", listener: (chunk: Buffer | string) => void): this; + once(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; once(event: "end", listener: () => void): this; once(event: "readable", listener: () => void): this; once(event: "error", listener: (err: Error) => void): this; once(event: string | symbol, listener: (...args: any[]) => void): this; prependListener(event: "aborted", listener: (hadError: boolean, code: number) => void): this; prependListener(event: "close", listener: () => void): this; - prependListener(event: "data", listener: (chunk: Buffer | string) => void): this; + prependListener(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; prependListener(event: "end", listener: () => void): this; prependListener(event: "readable", listener: () => void): this; prependListener(event: "error", listener: (err: Error) => void): this; prependListener(event: string | symbol, listener: (...args: any[]) => void): this; prependOnceListener(event: "aborted", listener: (hadError: boolean, code: number) => void): this; prependOnceListener(event: "close", listener: () => void): this; - prependOnceListener(event: "data", listener: (chunk: Buffer | string) => void): this; + prependOnceListener(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; prependOnceListener(event: "end", listener: () => void): this; prependOnceListener(event: "readable", listener: () => void): this; prependOnceListener(event: "error", listener: (err: Error) => void): this; @@ -2489,7 +2496,7 @@ declare module "http2" { * ``` * @since v8.4.0 */ - export function getPackedSettings(settings: Settings): Buffer; + export function getPackedSettings(settings: Settings): NonSharedBuffer; /** * Returns a `HTTP/2 Settings Object` containing the deserialized settings from * the given `Buffer` as generated by `http2.getPackedSettings()`. diff --git a/types/node/v20/https.d.ts b/types/node/v20/https.d.ts index 754c0e65c9b031..5ac45819d93f6b 100644 --- a/types/node/v20/https.d.ts +++ b/types/node/v20/https.d.ts @@ -4,6 +4,7 @@ * @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/https.js) */ declare module "https" { + import { NonSharedBuffer } from "node:buffer"; import { Duplex } from "node:stream"; import * as tls from "node:tls"; import * as http from "node:http"; @@ -62,22 +63,25 @@ declare module "https" { */ closeIdleConnections(): void; addListener(event: string, listener: (...args: any[]) => void): this; - addListener(event: "keylog", listener: (line: Buffer, tlsSocket: tls.TLSSocket) => void): this; + addListener(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: tls.TLSSocket) => void): this; addListener( event: "newSession", - listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void, + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, ): this; addListener( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; addListener( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; addListener(event: "secureConnection", listener: (tlsSocket: tls.TLSSocket) => void): this; addListener(event: "tlsClientError", listener: (err: Error, tlsSocket: tls.TLSSocket) => void): this; @@ -90,28 +94,32 @@ declare module "https" { addListener(event: "clientError", listener: (err: Error, socket: Duplex) => void): this; addListener( event: "connect", - listener: (req: InstanceType, socket: Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, ): this; addListener(event: "request", listener: http.RequestListener): this; addListener( event: "upgrade", - listener: (req: InstanceType, socket: Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, ): this; emit(event: string, ...args: any[]): boolean; - emit(event: "keylog", line: Buffer, tlsSocket: tls.TLSSocket): boolean; + emit(event: "keylog", line: NonSharedBuffer, tlsSocket: tls.TLSSocket): boolean; emit( event: "newSession", - sessionId: Buffer, - sessionData: Buffer, - callback: (err: Error, resp: Buffer) => void, + sessionId: NonSharedBuffer, + sessionData: NonSharedBuffer, + callback: () => void, ): boolean; emit( event: "OCSPRequest", - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, + ): boolean; + emit( + event: "resumeSession", + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, ): boolean; - emit(event: "resumeSession", sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void): boolean; emit(event: "secureConnection", tlsSocket: tls.TLSSocket): boolean; emit(event: "tlsClientError", err: Error, tlsSocket: tls.TLSSocket): boolean; emit(event: "close"): boolean; @@ -129,30 +137,33 @@ declare module "https" { res: InstanceType, ): boolean; emit(event: "clientError", err: Error, socket: Duplex): boolean; - emit(event: "connect", req: InstanceType, socket: Duplex, head: Buffer): boolean; + emit(event: "connect", req: InstanceType, socket: Duplex, head: NonSharedBuffer): boolean; emit( event: "request", req: InstanceType, res: InstanceType, ): boolean; - emit(event: "upgrade", req: InstanceType, socket: Duplex, head: Buffer): boolean; + emit(event: "upgrade", req: InstanceType, socket: Duplex, head: NonSharedBuffer): boolean; on(event: string, listener: (...args: any[]) => void): this; - on(event: "keylog", listener: (line: Buffer, tlsSocket: tls.TLSSocket) => void): this; + on(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: tls.TLSSocket) => void): this; on( event: "newSession", - listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void, + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, ): this; on( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; on( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; on(event: "secureConnection", listener: (tlsSocket: tls.TLSSocket) => void): this; on(event: "tlsClientError", listener: (err: Error, tlsSocket: tls.TLSSocket) => void): this; @@ -163,26 +174,35 @@ declare module "https" { on(event: "checkContinue", listener: http.RequestListener): this; on(event: "checkExpectation", listener: http.RequestListener): this; on(event: "clientError", listener: (err: Error, socket: Duplex) => void): this; - on(event: "connect", listener: (req: InstanceType, socket: Duplex, head: Buffer) => void): this; + on( + event: "connect", + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, + ): this; on(event: "request", listener: http.RequestListener): this; - on(event: "upgrade", listener: (req: InstanceType, socket: Duplex, head: Buffer) => void): this; + on( + event: "upgrade", + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, + ): this; once(event: string, listener: (...args: any[]) => void): this; - once(event: "keylog", listener: (line: Buffer, tlsSocket: tls.TLSSocket) => void): this; + once(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: tls.TLSSocket) => void): this; once( event: "newSession", - listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void, + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, ): this; once( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; once( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; once(event: "secureConnection", listener: (tlsSocket: tls.TLSSocket) => void): this; once(event: "tlsClientError", listener: (err: Error, tlsSocket: tls.TLSSocket) => void): this; @@ -193,26 +213,35 @@ declare module "https" { once(event: "checkContinue", listener: http.RequestListener): this; once(event: "checkExpectation", listener: http.RequestListener): this; once(event: "clientError", listener: (err: Error, socket: Duplex) => void): this; - once(event: "connect", listener: (req: InstanceType, socket: Duplex, head: Buffer) => void): this; + once( + event: "connect", + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, + ): this; once(event: "request", listener: http.RequestListener): this; - once(event: "upgrade", listener: (req: InstanceType, socket: Duplex, head: Buffer) => void): this; + once( + event: "upgrade", + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, + ): this; prependListener(event: string, listener: (...args: any[]) => void): this; - prependListener(event: "keylog", listener: (line: Buffer, tlsSocket: tls.TLSSocket) => void): this; + prependListener(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: tls.TLSSocket) => void): this; prependListener( event: "newSession", - listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void, + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, ): this; prependListener( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; prependListener( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; prependListener(event: "secureConnection", listener: (tlsSocket: tls.TLSSocket) => void): this; prependListener(event: "tlsClientError", listener: (err: Error, tlsSocket: tls.TLSSocket) => void): this; @@ -225,30 +254,33 @@ declare module "https" { prependListener(event: "clientError", listener: (err: Error, socket: Duplex) => void): this; prependListener( event: "connect", - listener: (req: InstanceType, socket: Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, ): this; prependListener(event: "request", listener: http.RequestListener): this; prependListener( event: "upgrade", - listener: (req: InstanceType, socket: Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, ): this; prependOnceListener(event: string, listener: (...args: any[]) => void): this; - prependOnceListener(event: "keylog", listener: (line: Buffer, tlsSocket: tls.TLSSocket) => void): this; + prependOnceListener(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: tls.TLSSocket) => void): this; prependOnceListener( event: "newSession", - listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void, + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, ): this; prependOnceListener( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; prependOnceListener( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; prependOnceListener(event: "secureConnection", listener: (tlsSocket: tls.TLSSocket) => void): this; prependOnceListener(event: "tlsClientError", listener: (err: Error, tlsSocket: tls.TLSSocket) => void): this; @@ -261,12 +293,12 @@ declare module "https" { prependOnceListener(event: "clientError", listener: (err: Error, socket: Duplex) => void): this; prependOnceListener( event: "connect", - listener: (req: InstanceType, socket: Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, ): this; prependOnceListener(event: "request", listener: http.RequestListener): this; prependOnceListener( event: "upgrade", - listener: (req: InstanceType, socket: Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, ): this; } /** diff --git a/types/node/v20/net.d.ts b/types/node/v20/net.d.ts index 2aea753701b6df..06894725445018 100644 --- a/types/node/v20/net.d.ts +++ b/types/node/v20/net.d.ts @@ -13,6 +13,7 @@ * @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/net.js) */ declare module "net" { + import { NonSharedBuffer } from "node:buffer"; import * as stream from "node:stream"; import { Abortable, EventEmitter } from "node:events"; import * as dns from "node:dns"; @@ -386,7 +387,7 @@ declare module "net" { event: "connectionAttemptTimeout", listener: (ip: string, port: number, family: number) => void, ): this; - addListener(event: "data", listener: (data: Buffer) => void): this; + addListener(event: "data", listener: (data: NonSharedBuffer) => void): this; addListener(event: "drain", listener: () => void): this; addListener(event: "end", listener: () => void): this; addListener(event: "error", listener: (err: Error) => void): this; @@ -402,7 +403,7 @@ declare module "net" { emit(event: "connectionAttempt", ip: string, port: number, family: number): boolean; emit(event: "connectionAttemptFailed", ip: string, port: number, family: number, error: Error): boolean; emit(event: "connectionAttemptTimeout", ip: string, port: number, family: number): boolean; - emit(event: "data", data: Buffer): boolean; + emit(event: "data", data: NonSharedBuffer): boolean; emit(event: "drain"): boolean; emit(event: "end"): boolean; emit(event: "error", err: Error): boolean; @@ -418,7 +419,7 @@ declare module "net" { listener: (ip: string, port: number, family: number, error: Error) => void, ): this; on(event: "connectionAttemptTimeout", listener: (ip: string, port: number, family: number) => void): this; - on(event: "data", listener: (data: Buffer) => void): this; + on(event: "data", listener: (data: NonSharedBuffer) => void): this; on(event: "drain", listener: () => void): this; on(event: "end", listener: () => void): this; on(event: "error", listener: (err: Error) => void): this; @@ -437,7 +438,7 @@ declare module "net" { ): this; once(event: "connectionAttemptTimeout", listener: (ip: string, port: number, family: number) => void): this; once(event: "connect", listener: () => void): this; - once(event: "data", listener: (data: Buffer) => void): this; + once(event: "data", listener: (data: NonSharedBuffer) => void): this; once(event: "drain", listener: () => void): this; once(event: "end", listener: () => void): this; once(event: "error", listener: (err: Error) => void): this; @@ -459,7 +460,7 @@ declare module "net" { event: "connectionAttemptTimeout", listener: (ip: string, port: number, family: number) => void, ): this; - prependListener(event: "data", listener: (data: Buffer) => void): this; + prependListener(event: "data", listener: (data: NonSharedBuffer) => void): this; prependListener(event: "drain", listener: () => void): this; prependListener(event: "end", listener: () => void): this; prependListener(event: "error", listener: (err: Error) => void): this; @@ -484,7 +485,7 @@ declare module "net" { event: "connectionAttemptTimeout", listener: (ip: string, port: number, family: number) => void, ): this; - prependOnceListener(event: "data", listener: (data: Buffer) => void): this; + prependOnceListener(event: "data", listener: (data: NonSharedBuffer) => void): this; prependOnceListener(event: "drain", listener: () => void): this; prependOnceListener(event: "end", listener: () => void): this; prependOnceListener(event: "error", listener: (err: Error) => void): this; diff --git a/types/node/v20/os.d.ts b/types/node/v20/os.d.ts index 2f731029ccb82e..331df6eaec1250 100644 --- a/types/node/v20/os.d.ts +++ b/types/node/v20/os.d.ts @@ -8,6 +8,7 @@ * @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/os.js) */ declare module "os" { + import { NonSharedBuffer } from "buffer"; interface CpuInfo { model: string; speed: number; @@ -253,9 +254,9 @@ declare module "os" { * Throws a [`SystemError`](https://nodejs.org/docs/latest-v20.x/api/errors.html#class-systemerror) if a user has no `username` or `homedir`. * @since v6.0.0 */ - function userInfo(options: UserInfoOptionsWithBufferEncoding): UserInfo; function userInfo(options?: UserInfoOptionsWithStringEncoding): UserInfo; - function userInfo(options: UserInfoOptions): UserInfo; + function userInfo(options: UserInfoOptionsWithBufferEncoding): UserInfo; + function userInfo(options: UserInfoOptions): UserInfo; type SignalConstants = { [key in NodeJS.Signals]: number; }; diff --git a/types/node/v20/process.d.ts b/types/node/v20/process.d.ts index 4eb5797ac38bfd..39b60eedbaf57a 100644 --- a/types/node/v20/process.d.ts +++ b/types/node/v20/process.d.ts @@ -1,5 +1,6 @@ declare module "process" { import { Control, MessageOptions } from "node:child_process"; + import { PathLike } from "node:fs"; import * as tty from "node:tty"; import { Worker } from "node:worker_threads"; @@ -1410,7 +1411,7 @@ declare module "process" { * @since v20.12.0 * @param path The path to the .env file */ - loadEnvFile(path?: string | URL | Buffer): void; + loadEnvFile(path?: PathLike): void; /** * The `process.pid` property returns the PID of the process. * diff --git a/types/node/v20/stream/consumers.d.ts b/types/node/v20/stream/consumers.d.ts index 746d6e508266ac..05db0257d276a5 100644 --- a/types/node/v20/stream/consumers.d.ts +++ b/types/node/v20/stream/consumers.d.ts @@ -4,7 +4,7 @@ * @since v16.7.0 */ declare module "stream/consumers" { - import { Blob as NodeBlob } from "node:buffer"; + import { Blob as NodeBlob, NonSharedBuffer } from "node:buffer"; import { ReadableStream as WebReadableStream } from "node:stream/web"; /** * @since v16.7.0 @@ -20,7 +20,7 @@ declare module "stream/consumers" { * @since v16.7.0 * @returns Fulfills with a `Buffer` containing the full contents of the stream. */ - function buffer(stream: WebReadableStream | NodeJS.ReadableStream | AsyncIterable): Promise; + function buffer(stream: WebReadableStream | NodeJS.ReadableStream | AsyncIterable): Promise; /** * @since v16.7.0 * @returns Fulfills with the contents of the stream parsed as a diff --git a/types/node/v20/string_decoder.d.ts b/types/node/v20/string_decoder.d.ts index 4a366eef679e33..d08cbf6c76b0d2 100644 --- a/types/node/v20/string_decoder.d.ts +++ b/types/node/v20/string_decoder.d.ts @@ -48,7 +48,7 @@ declare module "string_decoder" { * @since v0.1.99 * @param buffer The bytes to decode. */ - write(buffer: string | Buffer | NodeJS.ArrayBufferView): string; + write(buffer: string | NodeJS.ArrayBufferView): string; /** * Returns any remaining input stored in the internal buffer as a string. Bytes * representing incomplete UTF-8 and UTF-16 characters will be replaced with @@ -59,7 +59,7 @@ declare module "string_decoder" { * @since v0.9.3 * @param buffer The bytes to decode. */ - end(buffer?: string | Buffer | NodeJS.ArrayBufferView): string; + end(buffer?: string | NodeJS.ArrayBufferView): string; } } declare module "node:string_decoder" { diff --git a/types/node/v20/test/buffer.ts b/types/node/v20/test/buffer.ts index 4faf990e92db20..f2c19f6e0fa409 100644 --- a/types/node/v20/test/buffer.ts +++ b/types/node/v20/test/buffer.ts @@ -345,11 +345,11 @@ result = b.write("asd", 123, 123, "hex"); // Buffer module, transcode function { - transcode(Buffer.from("€"), "utf8", "ascii"); // $ExpectType Buffer || Buffer + transcode(Buffer.from("€"), "utf8", "ascii"); // $ExpectType NonSharedBuffer const source: TranscodeEncoding = "utf8"; const target: TranscodeEncoding = "ascii"; - transcode(Buffer.from("€"), source, target); // $ExpectType Buffer || Buffer + transcode(Buffer.from("€"), source, target); // $ExpectType NonSharedBuffer } { diff --git a/types/node/v20/test/child_process.ts b/types/node/v20/test/child_process.ts index 4b480362aacce3..1f83f8b31e402f 100644 --- a/types/node/v20/test/child_process.ts +++ b/types/node/v20/test/child_process.ts @@ -25,15 +25,15 @@ import { promisify } from "node:util"; childProcess.spawnSync("echo test", { encoding: "buffer" }); childProcess.spawnSync("echo test", { cwd: new URL("file://aaaaaaaa") }); - childProcess.spawnSync("echo test").output; // $ExpectType (Buffer | null)[] || (Buffer | null)[] - childProcess.spawnSync("echo test", {}).output; // $ExpectType (Buffer | null)[] || (Buffer | null)[] - childProcess.spawnSync("echo test", { encoding: "buffer" }).output; // $ExpectType (Buffer | null)[] || (Buffer | null)[] + childProcess.spawnSync("echo test").output; // $ExpectType (NonSharedBuffer | null)[] + childProcess.spawnSync("echo test", {}).output; // $ExpectType (NonSharedBuffer | null)[] + childProcess.spawnSync("echo test", { encoding: "buffer" }).output; // $ExpectType (NonSharedBuffer | null)[] childProcess.spawnSync("echo test", { encoding: "utf-8" }).output; // $ExpectType (string | null)[] - childProcess.spawnSync("echo", ["test"]).output; // $ExpectType (Buffer | null)[] || (Buffer | null)[] - childProcess.spawnSync("echo test", ["test"], {}).output; // $ExpectType (Buffer | null)[] || (Buffer | null)[] - childProcess.spawnSync("echo test", ["test"], { encoding: "buffer" }).output; // $ExpectType (Buffer | null)[] || (Buffer | null)[] + childProcess.spawnSync("echo", ["test"]).output; // $ExpectType (NonSharedBuffer | null)[] + childProcess.spawnSync("echo test", ["test"], {}).output; // $ExpectType (NonSharedBuffer | null)[] + childProcess.spawnSync("echo test", ["test"], { encoding: "buffer" }).output; // $ExpectType (NonSharedBuffer | null)[] childProcess.spawnSync("echo test", ["test"], { encoding: "utf-8" }).output; // $ExpectType (string | null)[] - ((opts?: childProcess.SpawnSyncOptions) => childProcess.spawnSync("echo test", opts))().output; // $ExpectType (string | Buffer | null)[] || (string | Buffer | null)[] + ((opts?: childProcess.SpawnSyncOptions) => childProcess.spawnSync("echo test", opts))().output; // $ExpectType (string | NonSharedBuffer | null)[] } { @@ -117,13 +117,13 @@ import { promisify } from "node:util"; (error, stdout, stderr) => { // $ExpectType ExecException | null error; - // $ExpectType Buffer + // $ExpectType NonSharedBuffer stdout; - // $ExpectType Buffer + // $ExpectType NonSharedBuffer stderr; }, ); - // $ExpectType PromiseWithChild<{ stdout: Buffer; stderr: Buffer; }> + // $ExpectType PromiseWithChild<{ stdout: NonSharedBuffer; stderr: NonSharedBuffer; }> promisifiedExec(cmd, { encoding: boolFlag ? "buffer" : null }); // with known encoding @@ -151,13 +151,13 @@ import { promisify } from "node:util"; (error, stdout, stderr) => { // $ExpectType ExecException | null error; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stdout; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stderr; }, ); - // $ExpectType PromiseWithChild<{ stdout: string | Buffer; stderr: string | Buffer; }> + // $ExpectType PromiseWithChild<{ stdout: string | NonSharedBuffer; stderr: string | NonSharedBuffer; }> promisifiedExec(cmd, { encoding: "unknown" }); // with nullish encoding @@ -168,22 +168,22 @@ import { promisify } from "node:util"; (error, stdout, stderr) => { // $ExpectType ExecException | null error; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stdout; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stderr; }, ); - // $ExpectType PromiseWithChild<{ stdout: string | Buffer; stderr: string | Buffer; }> + // $ExpectType PromiseWithChild<{ stdout: string | NonSharedBuffer; stderr: string | NonSharedBuffer; }> promisifiedExec(cmd, boolFlag ? { encoding: "unknown" } : null); } { - childProcess.execSync("echo test"); // $ExpectType Buffer || Buffer - childProcess.execSync("echo test", {}); // $ExpectType Buffer || Buffer - childProcess.execSync("echo test", { encoding: "buffer" }); // $ExpectType Buffer || Buffer + childProcess.execSync("echo test"); // $ExpectType NonSharedBuffer + childProcess.execSync("echo test", {}); // $ExpectType NonSharedBuffer + childProcess.execSync("echo test", { encoding: "buffer" }); // $ExpectType NonSharedBuffer childProcess.execSync("echo test", { encoding: "utf-8" }); // $ExpectType string - ((opts?: childProcess.ExecSyncOptions) => childProcess.execSync("echo test", opts))(); // $ExpectType string | Buffer || string | Buffer + ((opts?: childProcess.ExecSyncOptions) => childProcess.execSync("echo test", opts))(); // $ExpectType string | NonSharedBuffer childProcess.execSync("git status", { // $ExpectType string cwd: "test", input: "test", @@ -346,13 +346,13 @@ import { promisify } from "node:util"; (error, stdout, stderr) => { // $ExpectType ExecFileException | null error; - // $ExpectType Buffer + // $ExpectType NonSharedBuffer stdout; - // $ExpectType Buffer + // $ExpectType NonSharedBuffer stderr; }, ); - // $ExpectType PromiseWithChild<{ stdout: Buffer; stderr: Buffer; }> + // $ExpectType PromiseWithChild<{ stdout: NonSharedBuffer; stderr: NonSharedBuffer; }> promisifiedExecFile(cmd, { encoding: boolFlag ? "buffer" : null }); // $ExpectType ChildProcess childProcess.execFile( @@ -362,13 +362,13 @@ import { promisify } from "node:util"; (error, stdout, stderr) => { // $ExpectType ExecFileException | null error; - // $ExpectType Buffer + // $ExpectType NonSharedBuffer stdout; - // $ExpectType Buffer + // $ExpectType NonSharedBuffer stderr; }, ); - // $ExpectType PromiseWithChild<{ stdout: Buffer; stderr: Buffer; }> + // $ExpectType PromiseWithChild<{ stdout: NonSharedBuffer; stderr: NonSharedBuffer; }> promisifiedExecFile(cmd, args, { encoding: boolFlag ? "buffer" : null }); // with known encoding @@ -413,13 +413,13 @@ import { promisify } from "node:util"; (error, stdout, stderr) => { // $ExpectType ExecFileException | null error; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stdout; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stderr; }, ); - // $ExpectType PromiseWithChild<{ stdout: string | Buffer; stderr: string | Buffer; }> + // $ExpectType PromiseWithChild<{ stdout: string | NonSharedBuffer; stderr: string | NonSharedBuffer; }> promisifiedExecFile(cmd, { encoding: "unknown" }); // $ExpectType ChildProcess childProcess.execFile( @@ -429,13 +429,13 @@ import { promisify } from "node:util"; (error, stdout, stderr) => { // $ExpectType ExecFileException | null error; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stdout; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stderr; }, ); - // $ExpectType PromiseWithChild<{ stdout: string | Buffer; stderr: string | Buffer; }> + // $ExpectType PromiseWithChild<{ stdout: string | NonSharedBuffer; stderr: string | NonSharedBuffer; }> promisifiedExecFile(cmd, args, { encoding: "unknown" }); // with nullish encoding @@ -446,13 +446,13 @@ import { promisify } from "node:util"; (error, stdout, stderr) => { // $ExpectType ExecFileException | null error; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stdout; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stderr; }, ); - // $ExpectType PromiseWithChild<{ stdout: string | Buffer; stderr: string | Buffer; }> + // $ExpectType PromiseWithChild<{ stdout: string | NonSharedBuffer; stderr: string | NonSharedBuffer; }> promisifiedExecFile(cmd, boolFlag ? { encoding: "unknown" } : null); // $ExpectType ChildProcess childProcess.execFile( @@ -462,13 +462,13 @@ import { promisify } from "node:util"; (error, stdout, stderr) => { // $ExpectType ExecFileException | null error; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stdout; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stderr; }, ); - // $ExpectType PromiseWithChild<{ stdout: string | Buffer; stderr: string | Buffer; }> + // $ExpectType PromiseWithChild<{ stdout: string | NonSharedBuffer; stderr: string | NonSharedBuffer; }> promisifiedExecFile(cmd, args, boolFlag ? { encoding: "unknown" } : null); } @@ -481,15 +481,15 @@ import { promisify } from "node:util"; childProcess.execFileSync("echo test", { input: new Uint8Array([]) }); childProcess.execFileSync("echo test", { input: new DataView(new ArrayBuffer(1)) }); - childProcess.execFileSync("echo test"); // $ExpectType Buffer || Buffer - childProcess.execFileSync("echo test", {}); // $ExpectType Buffer || Buffer - childProcess.execFileSync("echo test", { encoding: "buffer" }); // $ExpectType Buffer || Buffer + childProcess.execFileSync("echo test"); // $ExpectType NonSharedBuffer + childProcess.execFileSync("echo test", {}); // $ExpectType NonSharedBuffer + childProcess.execFileSync("echo test", { encoding: "buffer" }); // $ExpectType NonSharedBuffer childProcess.execFileSync("echo test", { encoding: "utf8" }); // $ExpectType string - childProcess.execFileSync("echo test", ["test"]); // $ExpectType Buffer || Buffer - childProcess.execFileSync("echo test", ["test"], {}); // $ExpectType Buffer || Buffer - childProcess.execFileSync("echo test", ["test"], { encoding: "buffer" }); // $ExpectType Buffer || Buffer + childProcess.execFileSync("echo test", ["test"]); // $ExpectType NonSharedBuffer + childProcess.execFileSync("echo test", ["test"], {}); // $ExpectType NonSharedBuffer + childProcess.execFileSync("echo test", ["test"], { encoding: "buffer" }); // $ExpectType NonSharedBuffer childProcess.execFileSync("echo test", ["test"], { encoding: "utf8" }); // $ExpectType string - ((opts?: childProcess.ExecFileSyncOptions) => childProcess.execFileSync("echo test", ["args"], opts))(); // $ExpectType string | Buffer || string | Buffer + ((opts?: childProcess.ExecFileSyncOptions) => childProcess.execFileSync("echo test", ["args"], opts))(); // $ExpectType string | NonSharedBuffer } { diff --git a/types/node/v20/test/crypto.ts b/types/node/v20/test/crypto.ts index ad7ae2868bb3ac..05b52155fec795 100644 --- a/types/node/v20/test/crypto.ts +++ b/types/node/v20/test/crypto.ts @@ -246,7 +246,7 @@ import { promisify } from "node:util"; const cipher = crypto.createCipheriv("aes-192-cbc", key, nonce); const plaintext = "Hello world"; - // $ExpectType Buffer || Buffer + // $ExpectType NonSharedBuffer const cipherBuf = cipher.update(plaintext, "utf8"); cipher.final(); @@ -263,12 +263,12 @@ import { promisify } from "node:util"; const cipher = crypto.createCipheriv("aes-192-cbc", key, nonce); const plaintext = "Hello world"; - // $ExpectType Buffer || Buffer + // $ExpectType NonSharedBuffer const cipherBuf = cipher.update(plaintext, "utf8"); cipher.final(); const decipher = crypto.createDecipheriv("aes-192-cbc", key, nonce); - // $ExpectType Buffer || Buffer + // $ExpectType NonSharedBuffer const receivedPlaintext = decipher.update(cipherBuf); decipher.final(); } @@ -287,7 +287,7 @@ import { promisify } from "node:util"; }, }); cipher = cipher.setAAD(Buffer.from([]), { plaintextLength: 0 }); - // $ExpectType Buffer + // $ExpectType NonSharedBuffer cipher.getAuthTag(); } @@ -304,7 +304,7 @@ import { promisify } from "node:util"; }, }); cipher = cipher.setAAD(Buffer.from([]), { plaintextLength: 0 }); - // $ExpectType Buffer + // $ExpectType NonSharedBuffer cipher.getAuthTag(); } @@ -320,7 +320,7 @@ import { promisify } from "node:util"; }, }); cipher = cipher.setAAD(Buffer.from([]), { plaintextLength: 0 }); - // $ExpectType Buffer + // $ExpectType NonSharedBuffer cipher.getAuthTag(); } @@ -337,7 +337,7 @@ import { promisify } from "node:util"; }, }); cipher = cipher.setAAD(Buffer.from([]), { plaintextLength: 0 }); - // $ExpectType Buffer + // $ExpectType NonSharedBuffer cipher.getAuthTag(); } @@ -373,7 +373,7 @@ import { promisify } from "node:util"; }, }); cipher = cipher.setAAD(Buffer.from([]), { plaintextLength: 0 }); - // $ExpectType Buffer + // $ExpectType NonSharedBuffer cipher.getAuthTag(); } @@ -390,7 +390,7 @@ import { promisify } from "node:util"; }, }); cipher = cipher.setAAD(Buffer.from([]), { plaintextLength: 0 }); - // $ExpectType Buffer + // $ExpectType NonSharedBuffer cipher.getAuthTag(); } @@ -406,7 +406,7 @@ import { promisify } from "node:util"; }, }); cipher = cipher.setAAD(Buffer.from([]), { plaintextLength: 0 }); - // $ExpectType Buffer + // $ExpectType NonSharedBuffer cipher.getAuthTag(); } @@ -423,7 +423,7 @@ import { promisify } from "node:util"; }, }); cipher = cipher.setAAD(Buffer.from([]), { plaintextLength: 0 }); - // $ExpectType Buffer + // $ExpectType NonSharedBuffer cipher.getAuthTag(); } @@ -1636,7 +1636,7 @@ import { promisify } from "node:util"; cert.issuerCertificate; // $ExpectType X509Certificate | undefined cert.keyUsage; // $ExpectType string[] cert.publicKey; // $ExpectType KeyObject - cert.raw; // $ExpectType Buffer || Buffer + cert.raw; // $ExpectType NonSharedBuffer cert.serialNumber; // $ExpectType string cert.subject; // $ExpectType string cert.subjectAltName; // $ExpectType string | undefined @@ -1813,7 +1813,7 @@ import { promisify } from "node:util"; alice.generateKeys(); - let alicePublicKey = alice.getPublicKey(); // $ExpectType Buffer || Buffer + let alicePublicKey = alice.getPublicKey(); // $ExpectType NonSharedBuffer alicePublicKey = alice.getPublicKey(null); alicePublicKey = alice.getPublicKey(null, "compressed"); alicePublicKey = alice.getPublicKey(undefined, "hybrid"); @@ -1821,7 +1821,7 @@ import { promisify } from "node:util"; let bobPublicKey = bob.getPublicKey("hex"); // $ExpectType string bobPublicKey = bob.getPublicKey("hex", "compressed"); - let aliceSecret = alice.computeSecret(bobPublicKey, "hex"); // $ExpectType Buffer || Buffer + let aliceSecret = alice.computeSecret(bobPublicKey, "hex"); // $ExpectType NonSharedBuffer aliceSecret = alice.computeSecret(Buffer.from(bobPublicKey, "hex")); let bobSecret = bob.computeSecret(alicePublicKey, "hex"); // $ExpectType string diff --git a/types/node/v20/test/dgram.ts b/types/node/v20/test/dgram.ts index 4f92bb72546bab..fe64d2ff75b6ee 100644 --- a/types/node/v20/test/dgram.ts +++ b/types/node/v20/test/dgram.ts @@ -138,7 +138,7 @@ sock = dgram.createSocket({ lookup: dns.lookup, }); sock = dgram.createSocket("udp6", (msg, rinfo) => { - msg; // $ExpectType Buffer || Buffer + msg; // $ExpectType NonSharedBuffer rinfo; // $ExpectType RemoteInfo }); sock.addMembership("233.252.0.0"); @@ -199,7 +199,7 @@ sock.on("error", (exception) => { }); sock.on("listening", () => undefined); sock.on("message", (msg, rinfo) => { - msg; // $ExpectType Buffer || Buffer + msg; // $ExpectType NonSharedBuffer rinfo.address; // $ExpectType string rinfo.family; // $ExpectType "IPv4" | "IPv6" rinfo.port; // $ExpectType number diff --git a/types/node/v20/test/fs.ts b/types/node/v20/test/fs.ts index 0333354bd04b2c..b90833d13fb6cb 100644 --- a/types/node/v20/test/fs.ts +++ b/types/node/v20/test/fs.ts @@ -421,7 +421,7 @@ async function testPromisify() { fs.writev( 1, [Buffer.from("123")] as readonly NodeJS.ArrayBufferView[], - (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => { + (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: readonly NodeJS.ArrayBufferView[]) => { }, ); const bytesWritten = fs.writevSync(1, [Buffer.from("123")] as readonly NodeJS.ArrayBufferView[]); @@ -540,7 +540,7 @@ async function testPromisify() { readStream.addListener("aCustomEvent", () => {}); const _rom = readStream.readableObjectMode; // $ExpectType boolean - (await handle.read()).buffer; // $ExpectType Buffer || Buffer + (await handle.read()).buffer; // $ExpectType NonSharedBuffer (await handle.read({ buffer: new Uint32Array(), offset: 1, @@ -607,7 +607,7 @@ async function testPromisify() { 123, [Buffer.from("wut")] as readonly NodeJS.ArrayBufferView[], 123, - (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => { + (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: readonly NodeJS.ArrayBufferView[]) => { }, ); } @@ -840,8 +840,8 @@ const anyStatFs: fs.StatsFs | fs.BigIntStatsFs = fs.statfsSync(".", { bigint: Ma { watchAsync("y33t"); // $ExpectType AsyncIterable> - watchAsync("y33t", "buffer"); // $ExpectType AsyncIterable> || AsyncIterable>> - watchAsync("y33t", { encoding: "buffer", signal: new AbortSignal() }); // $ExpectType AsyncIterable> || AsyncIterable>> + watchAsync("y33t", "buffer"); // $ExpectType AsyncIterable> + watchAsync("y33t", { encoding: "buffer", signal: new AbortSignal() }); // $ExpectType AsyncIterable> watchAsync("test", { persistent: true, recursive: true, encoding: "utf-8" }); // $ExpectType AsyncIterable> } diff --git a/types/node/v20/test/https.ts b/types/node/v20/test/https.ts index 5cf2d1bf36c270..e537ce0f4f92f6 100644 --- a/types/node/v20/test/https.ts +++ b/types/node/v20/test/https.ts @@ -320,7 +320,7 @@ import * as url from "node:url"; let _buffer: Buffer = Buffer.from(""); let _err = new Error(); let _boolean = true; - let sessionCallback = (err: Error, resp: Buffer) => {}; + let sessionCallback = (err: Error | null, resp: Buffer) => {}; let ocspRequestCallback = (err: Error | null, resp: Buffer) => {}; server = server.addListener("keylog", (ln, tlsSocket) => { diff --git a/types/node/v20/test/stream.ts b/types/node/v20/test/stream.ts index d2c591321c21b6..49291f80180058 100644 --- a/types/node/v20/test/stream.ts +++ b/types/node/v20/test/stream.ts @@ -507,7 +507,7 @@ async function testConsumers() { await consumers.arrayBuffer(consumable); // $ExpectType Blob await consumers.blob(consumable); - // $ExpectType Buffer || Buffer + // $ExpectType NonSharedBuffer await consumers.buffer(consumable); // $ExpectType unknown await consumers.json(consumable); diff --git a/types/node/v20/test/vm.ts b/types/node/v20/test/vm.ts index 3eb8868ffd0b01..6c68b0efe145a1 100644 --- a/types/node/v20/test/vm.ts +++ b/types/node/v20/test/vm.ts @@ -78,7 +78,7 @@ import { }); fn satisfies Function; - // $ExpectType Buffer | undefined + // $ExpectType NonSharedBuffer | undefined fn.cachedData; // $ExpectType boolean | undefined fn.cachedDataProduced; diff --git a/types/node/v20/test/zlib.ts b/types/node/v20/test/zlib.ts index 4cb1c56bc9c05b..8dee71e67be45a 100644 --- a/types/node/v20/test/zlib.ts +++ b/types/node/v20/test/zlib.ts @@ -150,44 +150,44 @@ brotliDecompress( ); { - // $ExpectType (buffer: InputType, options?: BrotliOptions | undefined) => Promise || (buffer: InputType, options?: BrotliOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: BrotliOptions | undefined) => Promise const pBrotliCompress = promisify(brotliCompress); - // $ExpectType (buffer: InputType, options?: BrotliOptions | undefined) => Promise || (buffer: InputType, options?: BrotliOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: BrotliOptions | undefined) => Promise const pBrotliDecompress = promisify(brotliDecompress); - // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise || (buffer: InputType, options?: ZlibOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise const pDeflate = promisify(deflate); - // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise || (buffer: InputType, options?: ZlibOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise const pDeflateRaw = promisify(deflateRaw); - // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise || (buffer: InputType, options?: ZlibOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise const pGzip = promisify(gzip); - // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise || (buffer: InputType, options?: ZlibOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise const pGunzip = promisify(gunzip); - // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise || (buffer: InputType, options?: ZlibOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise const pInflate = promisify(inflate); - // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise || (buffer: InputType, options?: ZlibOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise const pInflateRaw = promisify(inflateRaw); - // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise || (buffer: InputType, options?: ZlibOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise const pUnzip = promisify(unzip); (async () => { - await pBrotliCompress(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pBrotliCompress(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType Buffer || Buffer - await pBrotliDecompress(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pBrotliDecompress(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType Buffer || Buffer - await pDeflate(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pDeflate(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType Buffer || Buffer - await pDeflateRaw(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pDeflateRaw(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType Buffer || Buffer - await pGzip(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pGzip(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType Buffer || Buffer - await pGunzip(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pGunzip(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType Buffer || Buffer - await pInflate(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pInflate(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType Buffer || Buffer - await pInflateRaw(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pInflateRaw(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType Buffer || Buffer - await pUnzip(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pUnzip(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType Buffer || Buffer + await pBrotliCompress(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pBrotliCompress(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType NonSharedBuffer + await pBrotliDecompress(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pBrotliDecompress(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType NonSharedBuffer + await pDeflate(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pDeflate(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType NonSharedBuffer + await pDeflateRaw(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pDeflateRaw(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType NonSharedBuffer + await pGzip(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pGzip(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType NonSharedBuffer + await pGunzip(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pGunzip(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType NonSharedBuffer + await pInflate(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pInflate(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType NonSharedBuffer + await pInflateRaw(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pInflateRaw(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType NonSharedBuffer + await pUnzip(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pUnzip(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType NonSharedBuffer })(); } diff --git a/types/node/v20/tls.d.ts b/types/node/v20/tls.d.ts index 0310aeaa6d2764..948b7371cbd6f0 100644 --- a/types/node/v20/tls.d.ts +++ b/types/node/v20/tls.d.ts @@ -9,6 +9,7 @@ * @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/tls.js) */ declare module "tls" { + import { NonSharedBuffer } from "node:buffer"; import { X509Certificate } from "node:crypto"; import * as net from "node:net"; import * as stream from "stream"; @@ -49,7 +50,7 @@ declare module "tls" { /** * The DER encoded X.509 certificate data. */ - raw: Buffer; + raw: NonSharedBuffer; /** * The certificate subject. */ @@ -115,7 +116,7 @@ declare module "tls" { /** * The public key. */ - pubkey?: Buffer; + pubkey?: NonSharedBuffer; /** * The ASN.1 name of the OID of the elliptic curve. * Well-known curves are identified by an OID. @@ -295,7 +296,7 @@ declare module "tls" { * @since v9.9.0 * @return The latest `Finished` message that has been sent to the socket as part of a SSL/TLS handshake, or `undefined` if no `Finished` message has been sent yet. */ - getFinished(): Buffer | undefined; + getFinished(): NonSharedBuffer | undefined; /** * Returns an object representing the peer's certificate. If the peer does not * provide a certificate, an empty object will be returned. If the socket has been @@ -322,7 +323,7 @@ declare module "tls" { * @return The latest `Finished` message that is expected or has actually been received from the socket as part of a SSL/TLS handshake, or `undefined` if there is no `Finished` message so * far. */ - getPeerFinished(): Buffer | undefined; + getPeerFinished(): NonSharedBuffer | undefined; /** * Returns a string containing the negotiated SSL/TLS protocol version of the * current connection. The value `'unknown'` will be returned for connected @@ -352,7 +353,7 @@ declare module "tls" { * must use the `'session'` event (it also works for TLSv1.2 and below). * @since v0.11.4 */ - getSession(): Buffer | undefined; + getSession(): NonSharedBuffer | undefined; /** * See [SSL\_get\_shared\_sigalgs](https://www.openssl.org/docs/man1.1.1/man3/SSL_get_shared_sigalgs.html) for more information. * @since v12.11.0 @@ -367,7 +368,7 @@ declare module "tls" { * See `Session Resumption` for more information. * @since v0.11.4 */ - getTLSTicket(): Buffer | undefined; + getTLSTicket(): NonSharedBuffer | undefined; /** * See `Session Resumption` for more information. * @since v0.5.6 @@ -478,37 +479,37 @@ declare module "tls" { * @param context Optionally provide a context. * @return requested bytes of the keying material */ - exportKeyingMaterial(length: number, label: string, context: Buffer): Buffer; + exportKeyingMaterial(length: number, label: string, context: Buffer): NonSharedBuffer; addListener(event: string, listener: (...args: any[]) => void): this; - addListener(event: "OCSPResponse", listener: (response: Buffer) => void): this; + addListener(event: "OCSPResponse", listener: (response: NonSharedBuffer) => void): this; addListener(event: "secureConnect", listener: () => void): this; - addListener(event: "session", listener: (session: Buffer) => void): this; - addListener(event: "keylog", listener: (line: Buffer) => void): this; + addListener(event: "session", listener: (session: NonSharedBuffer) => void): this; + addListener(event: "keylog", listener: (line: NonSharedBuffer) => void): this; emit(event: string | symbol, ...args: any[]): boolean; - emit(event: "OCSPResponse", response: Buffer): boolean; + emit(event: "OCSPResponse", response: NonSharedBuffer): boolean; emit(event: "secureConnect"): boolean; - emit(event: "session", session: Buffer): boolean; - emit(event: "keylog", line: Buffer): boolean; + emit(event: "session", session: NonSharedBuffer): boolean; + emit(event: "keylog", line: NonSharedBuffer): boolean; on(event: string, listener: (...args: any[]) => void): this; - on(event: "OCSPResponse", listener: (response: Buffer) => void): this; + on(event: "OCSPResponse", listener: (response: NonSharedBuffer) => void): this; on(event: "secureConnect", listener: () => void): this; - on(event: "session", listener: (session: Buffer) => void): this; - on(event: "keylog", listener: (line: Buffer) => void): this; + on(event: "session", listener: (session: NonSharedBuffer) => void): this; + on(event: "keylog", listener: (line: NonSharedBuffer) => void): this; once(event: string, listener: (...args: any[]) => void): this; - once(event: "OCSPResponse", listener: (response: Buffer) => void): this; + once(event: "OCSPResponse", listener: (response: NonSharedBuffer) => void): this; once(event: "secureConnect", listener: () => void): this; - once(event: "session", listener: (session: Buffer) => void): this; - once(event: "keylog", listener: (line: Buffer) => void): this; + once(event: "session", listener: (session: NonSharedBuffer) => void): this; + once(event: "keylog", listener: (line: NonSharedBuffer) => void): this; prependListener(event: string, listener: (...args: any[]) => void): this; - prependListener(event: "OCSPResponse", listener: (response: Buffer) => void): this; + prependListener(event: "OCSPResponse", listener: (response: NonSharedBuffer) => void): this; prependListener(event: "secureConnect", listener: () => void): this; - prependListener(event: "session", listener: (session: Buffer) => void): this; - prependListener(event: "keylog", listener: (line: Buffer) => void): this; + prependListener(event: "session", listener: (session: NonSharedBuffer) => void): this; + prependListener(event: "keylog", listener: (line: NonSharedBuffer) => void): this; prependOnceListener(event: string, listener: (...args: any[]) => void): this; - prependOnceListener(event: "OCSPResponse", listener: (response: Buffer) => void): this; + prependOnceListener(event: "OCSPResponse", listener: (response: NonSharedBuffer) => void): this; prependOnceListener(event: "secureConnect", listener: () => void): this; - prependOnceListener(event: "session", listener: (session: Buffer) => void): this; - prependOnceListener(event: "keylog", listener: (line: Buffer) => void): this; + prependOnceListener(event: "session", listener: (session: NonSharedBuffer) => void): this; + prependOnceListener(event: "keylog", listener: (line: NonSharedBuffer) => void): this; } interface CommonConnectionOptions { /** @@ -531,7 +532,7 @@ declare module "tls" { * An array of strings or a Buffer naming possible ALPN protocols. * (Protocols should be ordered by their priority.) */ - ALPNProtocols?: string[] | Uint8Array[] | Uint8Array | undefined; + ALPNProtocols?: readonly string[] | NodeJS.ArrayBufferView | undefined; /** * SNICallback(servername, cb) A function that will be * called if the client supports SNI TLS extension. Two arguments @@ -596,7 +597,7 @@ declare module "tls" { pskIdentityHint?: string | undefined; } interface PSKCallbackNegotation { - psk: DataView | NodeJS.TypedArray; + psk: NodeJS.ArrayBufferView; identity: string; } interface ConnectionOptions extends SecureContextOptions, CommonConnectionOptions { @@ -655,7 +656,7 @@ declare module "tls" { * @since v3.0.0 * @return A 48-byte buffer containing the session ticket keys. */ - getTicketKeys(): Buffer; + getTicketKeys(): NonSharedBuffer; /** * The `server.setSecureContext()` method replaces the secure context of an * existing server. Existing connections to the server are not interrupted. @@ -687,115 +688,138 @@ declare module "tls" { addListener(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this; addListener( event: "newSession", - listener: (sessionId: Buffer, sessionData: Buffer, callback: () => void) => void, + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, ): this; addListener( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; addListener( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error | null, sessionData: Buffer | null) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; addListener(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this; - addListener(event: "keylog", listener: (line: Buffer, tlsSocket: TLSSocket) => void): this; + addListener(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: TLSSocket) => void): this; emit(event: string | symbol, ...args: any[]): boolean; emit(event: "tlsClientError", err: Error, tlsSocket: TLSSocket): boolean; - emit(event: "newSession", sessionId: Buffer, sessionData: Buffer, callback: () => void): boolean; + emit( + event: "newSession", + sessionId: NonSharedBuffer, + sessionData: NonSharedBuffer, + callback: () => void, + ): boolean; emit( event: "OCSPRequest", - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ): boolean; emit( event: "resumeSession", - sessionId: Buffer, + sessionId: NonSharedBuffer, callback: (err: Error | null, sessionData: Buffer | null) => void, ): boolean; emit(event: "secureConnection", tlsSocket: TLSSocket): boolean; - emit(event: "keylog", line: Buffer, tlsSocket: TLSSocket): boolean; + emit(event: "keylog", line: NonSharedBuffer, tlsSocket: TLSSocket): boolean; on(event: string, listener: (...args: any[]) => void): this; on(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this; - on(event: "newSession", listener: (sessionId: Buffer, sessionData: Buffer, callback: () => void) => void): this; + on( + event: "newSession", + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, + ): this; on( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; on( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error | null, sessionData: Buffer | null) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; on(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this; - on(event: "keylog", listener: (line: Buffer, tlsSocket: TLSSocket) => void): this; + on(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: TLSSocket) => void): this; once(event: string, listener: (...args: any[]) => void): this; once(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this; once( event: "newSession", - listener: (sessionId: Buffer, sessionData: Buffer, callback: () => void) => void, + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, ): this; once( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; once( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error | null, sessionData: Buffer | null) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; once(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this; - once(event: "keylog", listener: (line: Buffer, tlsSocket: TLSSocket) => void): this; + once(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: TLSSocket) => void): this; prependListener(event: string, listener: (...args: any[]) => void): this; prependListener(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this; prependListener( event: "newSession", - listener: (sessionId: Buffer, sessionData: Buffer, callback: () => void) => void, + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, ): this; prependListener( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; prependListener( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error | null, sessionData: Buffer | null) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; prependListener(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this; - prependListener(event: "keylog", listener: (line: Buffer, tlsSocket: TLSSocket) => void): this; + prependListener(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: TLSSocket) => void): this; prependOnceListener(event: string, listener: (...args: any[]) => void): this; prependOnceListener(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this; prependOnceListener( event: "newSession", - listener: (sessionId: Buffer, sessionData: Buffer, callback: () => void) => void, + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, ): this; prependOnceListener( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; prependOnceListener( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error | null, sessionData: Buffer | null) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; prependOnceListener(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this; - prependOnceListener(event: "keylog", listener: (line: Buffer, tlsSocket: TLSSocket) => void): this; + prependOnceListener(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: TLSSocket) => void): this; } /** * @deprecated since v0.11.3 Use `tls.TLSSocket` instead. diff --git a/types/node/v20/ts5.6/buffer.buffer.d.ts b/types/node/v20/ts5.6/buffer.buffer.d.ts index d19026dc2ff99c..a5f67d7c9306ed 100644 --- a/types/node/v20/ts5.6/buffer.buffer.d.ts +++ b/types/node/v20/ts5.6/buffer.buffer.d.ts @@ -32,7 +32,7 @@ declare module "buffer" { * @param arrayBuffer The ArrayBuffer with which to share memory. * @deprecated since v10.0.0 - Use `Buffer.from(arrayBuffer[, byteOffset[, length]])` instead. */ - new(arrayBuffer: ArrayBuffer | SharedArrayBuffer): Buffer; + new(arrayBuffer: ArrayBufferLike): Buffer; /** * Allocates a new `Buffer` using an `array` of bytes in the range `0` – `255`. * Array entries outside that range will be truncated to fit into it. @@ -126,7 +126,7 @@ declare module "buffer" { * `arrayBuffer.byteLength - byteOffset`. */ from( - arrayBuffer: WithImplicitCoercion, + arrayBuffer: WithImplicitCoercion, byteOffset?: number, length?: number, ): Buffer; @@ -448,7 +448,15 @@ declare module "buffer" { */ subarray(start?: number, end?: number): Buffer; } + /** + * @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports + * TypeScript versions earlier than 5.7. + */ type NonSharedBuffer = Buffer; + /** + * @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports + * TypeScript versions earlier than 5.7. + */ type AllowSharedBuffer = Buffer; } /** @deprecated Use `Buffer.allocUnsafeSlow()` instead. */ diff --git a/types/node/v20/ts5.6/globals.typedarray.d.ts b/types/node/v20/ts5.6/globals.typedarray.d.ts index 0e4633b951b124..f1c444d1fac2da 100644 --- a/types/node/v20/ts5.6/globals.typedarray.d.ts +++ b/types/node/v20/ts5.6/globals.typedarray.d.ts @@ -15,5 +15,20 @@ declare global { | Float32Array | Float64Array; type ArrayBufferView = TypedArray | DataView; + + type NonSharedUint8Array = Uint8Array; + type NonSharedUint8ClampedArray = Uint8ClampedArray; + type NonSharedUint16Array = Uint16Array; + type NonSharedUint32Array = Uint32Array; + type NonSharedInt8Array = Int8Array; + type NonSharedInt16Array = Int16Array; + type NonSharedInt32Array = Int32Array; + type NonSharedBigUint64Array = BigUint64Array; + type NonSharedBigInt64Array = BigInt64Array; + type NonSharedFloat32Array = Float32Array; + type NonSharedFloat64Array = Float64Array; + type NonSharedDataView = DataView; + type NonSharedTypedArray = TypedArray; + type NonSharedArrayBufferView = ArrayBufferView; } } diff --git a/types/node/v20/url.d.ts b/types/node/v20/url.d.ts index 4bbfd6b692a5a8..4d836297d2bda1 100644 --- a/types/node/v20/url.d.ts +++ b/types/node/v20/url.d.ts @@ -8,7 +8,7 @@ * @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/url.js) */ declare module "url" { - import { Blob as NodeBlob } from "node:buffer"; + import { Blob as NodeBlob, NonSharedBuffer } from "node:buffer"; import { ClientRequestArgs } from "node:http"; import { ParsedUrlQuery, ParsedUrlQueryInput } from "node:querystring"; // Input to `url.format` diff --git a/types/node/v20/util.d.ts b/types/node/v20/util.d.ts index 1c564c0af313eb..e5e2cb67bda2f9 100644 --- a/types/node/v20/util.d.ts +++ b/types/node/v20/util.d.ts @@ -1377,7 +1377,7 @@ declare module "util" { * encoded bytes. * @param [input='an empty string'] The text to encode. */ - encode(input?: string): Uint8Array; + encode(input?: string): NodeJS.NonSharedUint8Array; /** * UTF-8 encodes the `src` string to the `dest` Uint8Array and returns an object * containing the read Unicode code units and written UTF-8 bytes. diff --git a/types/node/v20/v8.d.ts b/types/node/v20/v8.d.ts index f27578caae3856..8b0e9656c580dd 100644 --- a/types/node/v20/v8.d.ts +++ b/types/node/v20/v8.d.ts @@ -7,6 +7,7 @@ * @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/v8.js) */ declare module "v8" { + import { NonSharedBuffer } from "node:buffer"; import { Readable } from "node:stream"; interface HeapSpaceInfo { space_name: string; @@ -339,7 +340,7 @@ declare module "v8" { * the buffer is released. Calling this method results in undefined behavior * if a previous write has failed. */ - releaseBuffer(): Buffer; + releaseBuffer(): NonSharedBuffer; /** * Marks an `ArrayBuffer` as having its contents transferred out of band. * Pass the corresponding `ArrayBuffer` in the deserializing context to `deserializer.transferArrayBuffer()`. @@ -367,7 +368,7 @@ declare module "v8" { * will require a way to compute the length of the buffer. * For use inside of a custom `serializer._writeHostObject()`. */ - writeRawBytes(buffer: NodeJS.TypedArray): void; + writeRawBytes(buffer: NodeJS.ArrayBufferView): void; } /** * A subclass of `Serializer` that serializes `TypedArray`(in particular `Buffer`) and `DataView` objects as host objects, and only @@ -438,7 +439,7 @@ declare module "v8" { * larger than `buffer.constants.MAX_LENGTH`. * @since v8.0.0 */ - function serialize(value: any): Buffer; + function serialize(value: any): NonSharedBuffer; /** * Uses a `DefaultDeserializer` with default options to read a JS value * from a buffer. diff --git a/types/node/v20/vm.d.ts b/types/node/v20/vm.d.ts index 2a941de01e7a48..313240af1f550a 100644 --- a/types/node/v20/vm.d.ts +++ b/types/node/v20/vm.d.ts @@ -37,6 +37,7 @@ * @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/vm.js) */ declare module "vm" { + import { NonSharedBuffer } from "node:buffer"; import { ImportAttributes } from "node:module"; interface Context extends NodeJS.Dict {} interface BaseOptions { @@ -65,7 +66,7 @@ declare module "vm" { /** * Provides an optional data with V8's code cache data for the supplied source. */ - cachedData?: Buffer | NodeJS.ArrayBufferView | undefined; + cachedData?: NodeJS.ArrayBufferView | undefined; /** @deprecated in favor of `script.createCachedData()` */ produceCachedData?: boolean | undefined; /** @@ -361,7 +362,7 @@ declare module "vm" { * ``` * @since v10.6.0 */ - createCachedData(): Buffer; + createCachedData(): NonSharedBuffer; /** @deprecated in favor of `script.createCachedData()` */ cachedDataProduced?: boolean; /** @@ -371,7 +372,7 @@ declare module "vm" { * @since v5.7.0 */ cachedDataRejected?: boolean; - cachedData?: Buffer; + cachedData?: NonSharedBuffer; /** * When the script is compiled from a source that contains a source map magic * comment, this property will be set to the URL of the source map. diff --git a/types/node/v20/zlib.d.ts b/types/node/v20/zlib.d.ts index 98d122bdac3606..87af13e7927a71 100644 --- a/types/node/v20/zlib.d.ts +++ b/types/node/v20/zlib.d.ts @@ -92,6 +92,7 @@ * @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/zlib.js) */ declare module "zlib" { + import { NonSharedBuffer } from "node:buffer"; import * as stream from "node:stream"; interface ZlibOptions { /** @@ -180,7 +181,7 @@ declare module "zlib" { * @returns A 32-bit unsigned integer containing the checksum. * @since v20.15.0 */ - function crc32(data: string | Buffer | NodeJS.ArrayBufferView, value?: number): number; + function crc32(data: string | NodeJS.ArrayBufferView, value?: number): number; /** * Creates and returns a new `BrotliCompress` object. * @since v11.7.0, v10.16.0 @@ -234,124 +235,124 @@ declare module "zlib" { */ function createUnzip(options?: ZlibOptions): Unzip; type InputType = string | ArrayBuffer | NodeJS.ArrayBufferView; - type CompressCallback = (error: Error | null, result: Buffer) => void; + type CompressCallback = (error: Error | null, result: NonSharedBuffer) => void; /** * @since v11.7.0, v10.16.0 */ function brotliCompress(buf: InputType, options: BrotliOptions, callback: CompressCallback): void; function brotliCompress(buf: InputType, callback: CompressCallback): void; namespace brotliCompress { - function __promisify__(buffer: InputType, options?: BrotliOptions): Promise; + function __promisify__(buffer: InputType, options?: BrotliOptions): Promise; } /** * Compress a chunk of data with `BrotliCompress`. * @since v11.7.0, v10.16.0 */ - function brotliCompressSync(buf: InputType, options?: BrotliOptions): Buffer; + function brotliCompressSync(buf: InputType, options?: BrotliOptions): NonSharedBuffer; /** * @since v11.7.0, v10.16.0 */ function brotliDecompress(buf: InputType, options: BrotliOptions, callback: CompressCallback): void; function brotliDecompress(buf: InputType, callback: CompressCallback): void; namespace brotliDecompress { - function __promisify__(buffer: InputType, options?: BrotliOptions): Promise; + function __promisify__(buffer: InputType, options?: BrotliOptions): Promise; } /** * Decompress a chunk of data with `BrotliDecompress`. * @since v11.7.0, v10.16.0 */ - function brotliDecompressSync(buf: InputType, options?: BrotliOptions): Buffer; + function brotliDecompressSync(buf: InputType, options?: BrotliOptions): NonSharedBuffer; /** * @since v0.6.0 */ function deflate(buf: InputType, callback: CompressCallback): void; function deflate(buf: InputType, options: ZlibOptions, callback: CompressCallback): void; namespace deflate { - function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; + function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; } /** * Compress a chunk of data with `Deflate`. * @since v0.11.12 */ - function deflateSync(buf: InputType, options?: ZlibOptions): Buffer; + function deflateSync(buf: InputType, options?: ZlibOptions): NonSharedBuffer; /** * @since v0.6.0 */ function deflateRaw(buf: InputType, callback: CompressCallback): void; function deflateRaw(buf: InputType, options: ZlibOptions, callback: CompressCallback): void; namespace deflateRaw { - function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; + function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; } /** * Compress a chunk of data with `DeflateRaw`. * @since v0.11.12 */ - function deflateRawSync(buf: InputType, options?: ZlibOptions): Buffer; + function deflateRawSync(buf: InputType, options?: ZlibOptions): NonSharedBuffer; /** * @since v0.6.0 */ function gzip(buf: InputType, callback: CompressCallback): void; function gzip(buf: InputType, options: ZlibOptions, callback: CompressCallback): void; namespace gzip { - function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; + function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; } /** * Compress a chunk of data with `Gzip`. * @since v0.11.12 */ - function gzipSync(buf: InputType, options?: ZlibOptions): Buffer; + function gzipSync(buf: InputType, options?: ZlibOptions): NonSharedBuffer; /** * @since v0.6.0 */ function gunzip(buf: InputType, callback: CompressCallback): void; function gunzip(buf: InputType, options: ZlibOptions, callback: CompressCallback): void; namespace gunzip { - function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; + function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; } /** * Decompress a chunk of data with `Gunzip`. * @since v0.11.12 */ - function gunzipSync(buf: InputType, options?: ZlibOptions): Buffer; + function gunzipSync(buf: InputType, options?: ZlibOptions): NonSharedBuffer; /** * @since v0.6.0 */ function inflate(buf: InputType, callback: CompressCallback): void; function inflate(buf: InputType, options: ZlibOptions, callback: CompressCallback): void; namespace inflate { - function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; + function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; } /** * Decompress a chunk of data with `Inflate`. * @since v0.11.12 */ - function inflateSync(buf: InputType, options?: ZlibOptions): Buffer; + function inflateSync(buf: InputType, options?: ZlibOptions): NonSharedBuffer; /** * @since v0.6.0 */ function inflateRaw(buf: InputType, callback: CompressCallback): void; function inflateRaw(buf: InputType, options: ZlibOptions, callback: CompressCallback): void; namespace inflateRaw { - function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; + function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; } /** * Decompress a chunk of data with `InflateRaw`. * @since v0.11.12 */ - function inflateRawSync(buf: InputType, options?: ZlibOptions): Buffer; + function inflateRawSync(buf: InputType, options?: ZlibOptions): NonSharedBuffer; /** * @since v0.6.0 */ function unzip(buf: InputType, callback: CompressCallback): void; function unzip(buf: InputType, options: ZlibOptions, callback: CompressCallback): void; namespace unzip { - function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; + function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; } /** * Decompress a chunk of data with `Unzip`. * @since v0.11.12 */ - function unzipSync(buf: InputType, options?: ZlibOptions): Buffer; + function unzipSync(buf: InputType, options?: ZlibOptions): NonSharedBuffer; namespace constants { const BROTLI_DECODE: number; const BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES: number; diff --git a/types/node/v22/buffer.buffer.d.ts b/types/node/v22/buffer.buffer.d.ts index b22f83a291507d..8823deeb4b6754 100644 --- a/types/node/v22/buffer.buffer.d.ts +++ b/types/node/v22/buffer.buffer.d.ts @@ -451,7 +451,16 @@ declare module "buffer" { */ subarray(start?: number, end?: number): Buffer; } + // TODO: remove globals in future version + /** + * @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports + * TypeScript versions earlier than 5.7. + */ type NonSharedBuffer = Buffer; + /** + * @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports + * TypeScript versions earlier than 5.7. + */ type AllowSharedBuffer = Buffer; } /** @deprecated Use `Buffer.allocUnsafeSlow()` instead. */ diff --git a/types/node/v22/buffer.d.ts b/types/node/v22/buffer.d.ts index e5092b4ea6fcd5..354e08aa302b93 100644 --- a/types/node/v22/buffer.d.ts +++ b/types/node/v22/buffer.d.ts @@ -59,7 +59,7 @@ declare module "buffer" { * @since v19.4.0, v18.14.0 * @param input The input to validate. */ - export function isUtf8(input: Buffer | ArrayBuffer | NodeJS.TypedArray): boolean; + export function isUtf8(input: ArrayBuffer | NodeJS.TypedArray): boolean; /** * This function returns `true` if `input` contains only valid ASCII-encoded data, * including the case in which `input` is empty. @@ -68,7 +68,7 @@ declare module "buffer" { * @since v19.6.0, v18.15.0 * @param input The input to validate. */ - export function isAscii(input: Buffer | ArrayBuffer | NodeJS.TypedArray): boolean; + export function isAscii(input: ArrayBuffer | NodeJS.TypedArray): boolean; export let INSPECT_MAX_BYTES: number; export const kMaxLength: number; export const kStringMaxLength: number; @@ -113,7 +113,11 @@ declare module "buffer" { * @param fromEnc The current encoding. * @param toEnc To target encoding. */ - export function transcode(source: Uint8Array, fromEnc: TranscodeEncoding, toEnc: TranscodeEncoding): Buffer; + export function transcode( + source: Uint8Array, + fromEnc: TranscodeEncoding, + toEnc: TranscodeEncoding, + ): NonSharedBuffer; /** * Resolves a `'blob:nodedata:...'` an associated `Blob` object registered using * a prior call to `URL.createObjectURL()`. @@ -330,7 +334,7 @@ declare module "buffer" { * @return The number of bytes contained within `string`. */ byteLength( - string: string | Buffer | NodeJS.ArrayBufferView | ArrayBuffer | SharedArrayBuffer, + string: string | NodeJS.ArrayBufferView | ArrayBufferLike, encoding?: BufferEncoding, ): number; /** diff --git a/types/node/v22/child_process.d.ts b/types/node/v22/child_process.d.ts index d7199dcf847592..313c33c4ecd402 100644 --- a/types/node/v22/child_process.d.ts +++ b/types/node/v22/child_process.d.ts @@ -66,6 +66,7 @@ * @see [source](https://github.com/nodejs/node/blob/v22.x/lib/child_process.js) */ declare module "child_process" { + import { NonSharedBuffer } from "node:buffer"; import { Abortable, EventEmitter } from "node:events"; import * as dgram from "node:dgram"; import * as net from "node:net"; @@ -1001,7 +1002,7 @@ declare module "child_process" { function exec( command: string, options: ExecOptionsWithBufferEncoding, - callback?: (error: ExecException | null, stdout: Buffer, stderr: Buffer) => void, + callback?: (error: ExecException | null, stdout: NonSharedBuffer, stderr: NonSharedBuffer) => void, ): ChildProcess; // `options` with well-known or absent `encoding` means stdout/stderr are definitely `string`. function exec( @@ -1013,7 +1014,11 @@ declare module "child_process" { function exec( command: string, options: ExecOptions | undefined | null, - callback?: (error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void, + callback?: ( + error: ExecException | null, + stdout: string | NonSharedBuffer, + stderr: string | NonSharedBuffer, + ) => void, ): ChildProcess; interface PromiseWithChild extends Promise { child: ChildProcess; @@ -1027,8 +1032,8 @@ declare module "child_process" { command: string, options: ExecOptionsWithBufferEncoding, ): PromiseWithChild<{ - stdout: Buffer; - stderr: Buffer; + stdout: NonSharedBuffer; + stderr: NonSharedBuffer; }>; function __promisify__( command: string, @@ -1041,8 +1046,8 @@ declare module "child_process" { command: string, options: ExecOptions | undefined | null, ): PromiseWithChild<{ - stdout: string | Buffer; - stderr: string | Buffer; + stdout: string | NonSharedBuffer; + stderr: string | NonSharedBuffer; }>; } interface ExecFileOptions extends CommonOptions, Abortable { @@ -1144,13 +1149,13 @@ declare module "child_process" { function execFile( file: string, options: ExecFileOptionsWithBufferEncoding, - callback?: (error: ExecFileException | null, stdout: Buffer, stderr: Buffer) => void, + callback?: (error: ExecFileException | null, stdout: NonSharedBuffer, stderr: NonSharedBuffer) => void, ): ChildProcess; function execFile( file: string, args: readonly string[] | undefined | null, options: ExecFileOptionsWithBufferEncoding, - callback?: (error: ExecFileException | null, stdout: Buffer, stderr: Buffer) => void, + callback?: (error: ExecFileException | null, stdout: NonSharedBuffer, stderr: NonSharedBuffer) => void, ): ChildProcess; // `options` with well-known or absent `encoding` means stdout/stderr are definitely `string`. function execFile( @@ -1169,7 +1174,11 @@ declare module "child_process" { file: string, options: ExecFileOptions | undefined | null, callback: - | ((error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void) + | (( + error: ExecFileException | null, + stdout: string | NonSharedBuffer, + stderr: string | NonSharedBuffer, + ) => void) | undefined | null, ): ChildProcess; @@ -1178,7 +1187,11 @@ declare module "child_process" { args: readonly string[] | undefined | null, options: ExecFileOptions | undefined | null, callback: - | ((error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void) + | (( + error: ExecFileException | null, + stdout: string | NonSharedBuffer, + stderr: string | NonSharedBuffer, + ) => void) | undefined | null, ): ChildProcess; @@ -1198,16 +1211,16 @@ declare module "child_process" { file: string, options: ExecFileOptionsWithBufferEncoding, ): PromiseWithChild<{ - stdout: Buffer; - stderr: Buffer; + stdout: NonSharedBuffer; + stderr: NonSharedBuffer; }>; function __promisify__( file: string, args: readonly string[] | undefined | null, options: ExecFileOptionsWithBufferEncoding, ): PromiseWithChild<{ - stdout: Buffer; - stderr: Buffer; + stdout: NonSharedBuffer; + stderr: NonSharedBuffer; }>; function __promisify__( file: string, @@ -1228,16 +1241,16 @@ declare module "child_process" { file: string, options: ExecFileOptions | undefined | null, ): PromiseWithChild<{ - stdout: string | Buffer; - stderr: string | Buffer; + stdout: string | NonSharedBuffer; + stderr: string | NonSharedBuffer; }>; function __promisify__( file: string, args: readonly string[] | undefined | null, options: ExecFileOptions | undefined | null, ): PromiseWithChild<{ - stdout: string | Buffer; - stderr: string | Buffer; + stdout: string | NonSharedBuffer; + stderr: string | NonSharedBuffer; }>; } interface ForkOptions extends ProcessEnvOptions, MessagingOptions, Abortable { @@ -1343,11 +1356,11 @@ declare module "child_process" { * @param command The command to run. * @param args List of string arguments. */ - function spawnSync(command: string): SpawnSyncReturns; + function spawnSync(command: string): SpawnSyncReturns; function spawnSync(command: string, options: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns; - function spawnSync(command: string, options: SpawnSyncOptionsWithBufferEncoding): SpawnSyncReturns; - function spawnSync(command: string, options?: SpawnSyncOptions): SpawnSyncReturns; - function spawnSync(command: string, args: readonly string[]): SpawnSyncReturns; + function spawnSync(command: string, options: SpawnSyncOptionsWithBufferEncoding): SpawnSyncReturns; + function spawnSync(command: string, options?: SpawnSyncOptions): SpawnSyncReturns; + function spawnSync(command: string, args: readonly string[]): SpawnSyncReturns; function spawnSync( command: string, args: readonly string[], @@ -1357,12 +1370,12 @@ declare module "child_process" { command: string, args: readonly string[], options: SpawnSyncOptionsWithBufferEncoding, - ): SpawnSyncReturns; + ): SpawnSyncReturns; function spawnSync( command: string, args?: readonly string[], options?: SpawnSyncOptions, - ): SpawnSyncReturns; + ): SpawnSyncReturns; interface CommonExecOptions extends CommonOptions { input?: string | NodeJS.ArrayBufferView | undefined; /** @@ -1404,10 +1417,10 @@ declare module "child_process" { * @param command The command to run. * @return The stdout from the command. */ - function execSync(command: string): Buffer; + function execSync(command: string): NonSharedBuffer; function execSync(command: string, options: ExecSyncOptionsWithStringEncoding): string; - function execSync(command: string, options: ExecSyncOptionsWithBufferEncoding): Buffer; - function execSync(command: string, options?: ExecSyncOptions): string | Buffer; + function execSync(command: string, options: ExecSyncOptionsWithBufferEncoding): NonSharedBuffer; + function execSync(command: string, options?: ExecSyncOptions): string | NonSharedBuffer; interface ExecFileSyncOptions extends CommonExecOptions { shell?: boolean | string | undefined; } @@ -1437,11 +1450,11 @@ declare module "child_process" { * @param args List of string arguments. * @return The stdout from the command. */ - function execFileSync(file: string): Buffer; + function execFileSync(file: string): NonSharedBuffer; function execFileSync(file: string, options: ExecFileSyncOptionsWithStringEncoding): string; - function execFileSync(file: string, options: ExecFileSyncOptionsWithBufferEncoding): Buffer; - function execFileSync(file: string, options?: ExecFileSyncOptions): string | Buffer; - function execFileSync(file: string, args: readonly string[]): Buffer; + function execFileSync(file: string, options: ExecFileSyncOptionsWithBufferEncoding): NonSharedBuffer; + function execFileSync(file: string, options?: ExecFileSyncOptions): string | NonSharedBuffer; + function execFileSync(file: string, args: readonly string[]): NonSharedBuffer; function execFileSync( file: string, args: readonly string[], @@ -1451,8 +1464,12 @@ declare module "child_process" { file: string, args: readonly string[], options: ExecFileSyncOptionsWithBufferEncoding, - ): Buffer; - function execFileSync(file: string, args?: readonly string[], options?: ExecFileSyncOptions): string | Buffer; + ): NonSharedBuffer; + function execFileSync( + file: string, + args?: readonly string[], + options?: ExecFileSyncOptions, + ): string | NonSharedBuffer; } declare module "node:child_process" { export * from "child_process"; diff --git a/types/node/v22/crypto.d.ts b/types/node/v22/crypto.d.ts index e4cc705154044d..902380530aaa89 100644 --- a/types/node/v22/crypto.d.ts +++ b/types/node/v22/crypto.d.ts @@ -17,6 +17,7 @@ * @see [source](https://github.com/nodejs/node/blob/v22.x/lib/crypto.js) */ declare module "crypto" { + import { NonSharedBuffer } from "node:buffer"; import * as stream from "node:stream"; import { PeerCertificate } from "node:tls"; /** @@ -44,7 +45,7 @@ declare module "crypto" { * @param encoding The `encoding` of the `spkac` string. * @return The challenge component of the `spkac` data structure, which includes a public key and a challenge. */ - static exportChallenge(spkac: BinaryLike): Buffer; + static exportChallenge(spkac: BinaryLike): NonSharedBuffer; /** * ```js * const { Certificate } = await import('node:crypto'); @@ -57,7 +58,7 @@ declare module "crypto" { * @param encoding The `encoding` of the `spkac` string. * @return The public key component of the `spkac` data structure, which includes a public key and a challenge. */ - static exportPublicKey(spkac: BinaryLike, encoding?: string): Buffer; + static exportPublicKey(spkac: BinaryLike, encoding?: string): NonSharedBuffer; /** * ```js * import { Buffer } from 'node:buffer'; @@ -78,7 +79,7 @@ declare module "crypto" { * @returns The challenge component of the `spkac` data structure, * which includes a public key and a challenge. */ - exportChallenge(spkac: BinaryLike): Buffer; + exportChallenge(spkac: BinaryLike): NonSharedBuffer; /** * @deprecated * @param spkac @@ -86,7 +87,7 @@ declare module "crypto" { * @returns The public key component of the `spkac` data structure, * which includes a public key and a challenge. */ - exportPublicKey(spkac: BinaryLike, encoding?: string): Buffer; + exportPublicKey(spkac: BinaryLike, encoding?: string): NonSharedBuffer; /** * @deprecated * @param spkac @@ -402,7 +403,7 @@ declare module "crypto" { * @since v0.1.92 * @param encoding The `encoding` of the return value. */ - digest(): Buffer; + digest(): NonSharedBuffer; digest(encoding: BinaryToTextEncoding): string; } /** @@ -496,7 +497,7 @@ declare module "crypto" { * @since v0.1.94 * @param encoding The `encoding` of the return value. */ - digest(): Buffer; + digest(): NonSharedBuffer; digest(encoding: BinaryToTextEncoding): string; } type KeyObjectType = "secret" | "public" | "private"; @@ -646,8 +647,8 @@ declare module "crypto" { * PKCS#1 and SEC1 encryption. * @since v11.6.0 */ - export(options: KeyExportOptions<"pem">): string | Buffer; - export(options?: KeyExportOptions<"der">): Buffer; + export(options: KeyExportOptions<"pem">): string | NonSharedBuffer; + export(options?: KeyExportOptions<"der">): NonSharedBuffer; export(options?: JwkKeyExportOptions): JsonWebKey; /** * Returns `true` or `false` depending on whether the keys have exactly the same @@ -896,8 +897,8 @@ declare module "crypto" { * @param inputEncoding The `encoding` of the data. * @param outputEncoding The `encoding` of the return value. */ - update(data: BinaryLike): Buffer; - update(data: string, inputEncoding: Encoding): Buffer; + update(data: BinaryLike): NonSharedBuffer; + update(data: string, inputEncoding: Encoding): NonSharedBuffer; update(data: NodeJS.ArrayBufferView, inputEncoding: undefined, outputEncoding: Encoding): string; update(data: string, inputEncoding: Encoding | undefined, outputEncoding: Encoding): string; /** @@ -908,7 +909,7 @@ declare module "crypto" { * @param outputEncoding The `encoding` of the return value. * @return Any remaining enciphered contents. If `outputEncoding` is specified, a string is returned. If an `outputEncoding` is not provided, a {@link Buffer} is returned. */ - final(): Buffer; + final(): NonSharedBuffer; final(outputEncoding: BufferEncoding): string; /** * When using block encryption algorithms, the `Cipher` class will automatically @@ -934,7 +935,7 @@ declare module "crypto" { plaintextLength: number; }, ): this; - getAuthTag(): Buffer; + getAuthTag(): NonSharedBuffer; } interface CipherGCM extends Cipher { setAAD( @@ -943,7 +944,7 @@ declare module "crypto" { plaintextLength: number; }, ): this; - getAuthTag(): Buffer; + getAuthTag(): NonSharedBuffer; } interface CipherOCB extends Cipher { setAAD( @@ -952,7 +953,7 @@ declare module "crypto" { plaintextLength: number; }, ): this; - getAuthTag(): Buffer; + getAuthTag(): NonSharedBuffer; } interface CipherChaCha20Poly1305 extends Cipher { setAAD( @@ -961,7 +962,7 @@ declare module "crypto" { plaintextLength: number; }, ): this; - getAuthTag(): Buffer; + getAuthTag(): NonSharedBuffer; } /** * Creates and returns a `Decipher` object that uses the given `algorithm`, `key` and initialization vector (`iv`). @@ -1146,8 +1147,8 @@ declare module "crypto" { * @param inputEncoding The `encoding` of the `data` string. * @param outputEncoding The `encoding` of the return value. */ - update(data: NodeJS.ArrayBufferView): Buffer; - update(data: string, inputEncoding: Encoding): Buffer; + update(data: NodeJS.ArrayBufferView): NonSharedBuffer; + update(data: string, inputEncoding: Encoding): NonSharedBuffer; update(data: NodeJS.ArrayBufferView, inputEncoding: undefined, outputEncoding: Encoding): string; update(data: string, inputEncoding: Encoding | undefined, outputEncoding: Encoding): string; /** @@ -1158,7 +1159,7 @@ declare module "crypto" { * @param outputEncoding The `encoding` of the return value. * @return Any remaining deciphered contents. If `outputEncoding` is specified, a string is returned. If an `outputEncoding` is not provided, a {@link Buffer} is returned. */ - final(): Buffer; + final(): NonSharedBuffer; final(outputEncoding: BufferEncoding): string; /** * When data has been encrypted without standard block padding, calling `decipher.setAutoPadding(false)` will disable automatic padding to prevent `decipher.final()` from checking for and @@ -1430,7 +1431,7 @@ declare module "crypto" { * called. Multiple calls to `sign.sign()` will result in an error being thrown. * @since v0.1.92 */ - sign(privateKey: KeyLike | SignKeyObjectInput | SignPrivateKeyInput | SignJsonWebKeyInput): Buffer; + sign(privateKey: KeyLike | SignKeyObjectInput | SignPrivateKeyInput | SignJsonWebKeyInput): NonSharedBuffer; sign( privateKey: KeyLike | SignKeyObjectInput | SignPrivateKeyInput | SignJsonWebKeyInput, outputFormat: BinaryToTextEncoding, @@ -1589,7 +1590,7 @@ declare module "crypto" { * @since v0.5.0 * @param encoding The `encoding` of the return value. */ - generateKeys(): Buffer; + generateKeys(): NonSharedBuffer; generateKeys(encoding: BinaryToTextEncoding): string; /** * Computes the shared secret using `otherPublicKey` as the other @@ -1604,8 +1605,16 @@ declare module "crypto" { * @param inputEncoding The `encoding` of an `otherPublicKey` string. * @param outputEncoding The `encoding` of the return value. */ - computeSecret(otherPublicKey: NodeJS.ArrayBufferView, inputEncoding?: null, outputEncoding?: null): Buffer; - computeSecret(otherPublicKey: string, inputEncoding: BinaryToTextEncoding, outputEncoding?: null): Buffer; + computeSecret( + otherPublicKey: NodeJS.ArrayBufferView, + inputEncoding?: null, + outputEncoding?: null, + ): NonSharedBuffer; + computeSecret( + otherPublicKey: string, + inputEncoding: BinaryToTextEncoding, + outputEncoding?: null, + ): NonSharedBuffer; computeSecret( otherPublicKey: NodeJS.ArrayBufferView, inputEncoding: null, @@ -1623,7 +1632,7 @@ declare module "crypto" { * @since v0.5.0 * @param encoding The `encoding` of the return value. */ - getPrime(): Buffer; + getPrime(): NonSharedBuffer; getPrime(encoding: BinaryToTextEncoding): string; /** * Returns the Diffie-Hellman generator in the specified `encoding`. @@ -1632,7 +1641,7 @@ declare module "crypto" { * @since v0.5.0 * @param encoding The `encoding` of the return value. */ - getGenerator(): Buffer; + getGenerator(): NonSharedBuffer; getGenerator(encoding: BinaryToTextEncoding): string; /** * Returns the Diffie-Hellman public key in the specified `encoding`. @@ -1641,7 +1650,7 @@ declare module "crypto" { * @since v0.5.0 * @param encoding The `encoding` of the return value. */ - getPublicKey(): Buffer; + getPublicKey(): NonSharedBuffer; getPublicKey(encoding: BinaryToTextEncoding): string; /** * Returns the Diffie-Hellman private key in the specified `encoding`. @@ -1650,7 +1659,7 @@ declare module "crypto" { * @since v0.5.0 * @param encoding The `encoding` of the return value. */ - getPrivateKey(): Buffer; + getPrivateKey(): NonSharedBuffer; getPrivateKey(encoding: BinaryToTextEncoding): string; /** * Sets the Diffie-Hellman public key. If the `encoding` argument is provided, `publicKey` is expected @@ -1794,7 +1803,7 @@ declare module "crypto" { iterations: number, keylen: number, digest: string, - callback: (err: Error | null, derivedKey: Buffer) => void, + callback: (err: Error | null, derivedKey: NonSharedBuffer) => void, ): void; /** * Provides a synchronous Password-Based Key Derivation Function 2 (PBKDF2) @@ -1831,7 +1840,7 @@ declare module "crypto" { iterations: number, keylen: number, digest: string, - ): Buffer; + ): NonSharedBuffer; /** * Generates cryptographically strong pseudorandom data. The `size` argument * is a number indicating the number of bytes to generate. @@ -1884,10 +1893,10 @@ declare module "crypto" { * @param size The number of bytes to generate. The `size` must not be larger than `2**31 - 1`. * @return if the `callback` function is not provided. */ - function randomBytes(size: number): Buffer; - function randomBytes(size: number, callback: (err: Error | null, buf: Buffer) => void): void; - function pseudoRandomBytes(size: number): Buffer; - function pseudoRandomBytes(size: number, callback: (err: Error | null, buf: Buffer) => void): void; + function randomBytes(size: number): NonSharedBuffer; + function randomBytes(size: number, callback: (err: Error | null, buf: NonSharedBuffer) => void): void; + function pseudoRandomBytes(size: number): NonSharedBuffer; + function pseudoRandomBytes(size: number, callback: (err: Error | null, buf: NonSharedBuffer) => void): void; /** * Return a random integer `n` such that `min <= n < max`. This * implementation avoids [modulo bias](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#Modulo_bias). @@ -2117,14 +2126,14 @@ declare module "crypto" { password: BinaryLike, salt: BinaryLike, keylen: number, - callback: (err: Error | null, derivedKey: Buffer) => void, + callback: (err: Error | null, derivedKey: NonSharedBuffer) => void, ): void; function scrypt( password: BinaryLike, salt: BinaryLike, keylen: number, options: ScryptOptions, - callback: (err: Error | null, derivedKey: Buffer) => void, + callback: (err: Error | null, derivedKey: NonSharedBuffer) => void, ): void; /** * Provides a synchronous [scrypt](https://en.wikipedia.org/wiki/Scrypt) implementation. Scrypt is a password-based @@ -2156,7 +2165,12 @@ declare module "crypto" { * ``` * @since v10.5.0 */ - function scryptSync(password: BinaryLike, salt: BinaryLike, keylen: number, options?: ScryptOptions): Buffer; + function scryptSync( + password: BinaryLike, + salt: BinaryLike, + keylen: number, + options?: ScryptOptions, + ): NonSharedBuffer; interface RsaPublicKey { key: KeyLike; padding?: number | undefined; @@ -2185,7 +2199,7 @@ declare module "crypto" { function publicEncrypt( key: RsaPublicKey | RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView | string, - ): Buffer; + ): NonSharedBuffer; /** * Decrypts `buffer` with `key`.`buffer` was previously encrypted using * the corresponding private key, for example using {@link privateEncrypt}. @@ -2200,7 +2214,7 @@ declare module "crypto" { function publicDecrypt( key: RsaPublicKey | RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView | string, - ): Buffer; + ): NonSharedBuffer; /** * Decrypts `buffer` with `privateKey`. `buffer` was previously encrypted using * the corresponding public key, for example using {@link publicEncrypt}. @@ -2209,7 +2223,10 @@ declare module "crypto" { * object, the `padding` property can be passed. Otherwise, this function uses `RSA_PKCS1_OAEP_PADDING`. * @since v0.11.14 */ - function privateDecrypt(privateKey: RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView | string): Buffer; + function privateDecrypt( + privateKey: RsaPrivateKey | KeyLike, + buffer: NodeJS.ArrayBufferView | string, + ): NonSharedBuffer; /** * Encrypts `buffer` with `privateKey`. The returned data can be decrypted using * the corresponding public key, for example using {@link publicDecrypt}. @@ -2218,7 +2235,10 @@ declare module "crypto" { * object, the `padding` property can be passed. Otherwise, this function uses `RSA_PKCS1_PADDING`. * @since v1.1.0 */ - function privateEncrypt(privateKey: RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView | string): Buffer; + function privateEncrypt( + privateKey: RsaPrivateKey | KeyLike, + buffer: NodeJS.ArrayBufferView | string, + ): NonSharedBuffer; /** * ```js * const { @@ -2347,7 +2367,7 @@ declare module "crypto" { inputEncoding?: BinaryToTextEncoding, outputEncoding?: "latin1" | "hex" | "base64" | "base64url", format?: "uncompressed" | "compressed" | "hybrid", - ): Buffer | string; + ): NonSharedBuffer | string; /** * Generates private and public EC Diffie-Hellman key values, and returns * the public key in the specified `format` and `encoding`. This key should be @@ -2360,7 +2380,7 @@ declare module "crypto" { * @param encoding The `encoding` of the return value. * @param [format='uncompressed'] */ - generateKeys(): Buffer; + generateKeys(): NonSharedBuffer; generateKeys(encoding: BinaryToTextEncoding, format?: ECDHKeyFormat): string; /** * Computes the shared secret using `otherPublicKey` as the other @@ -2379,8 +2399,8 @@ declare module "crypto" { * @param inputEncoding The `encoding` of the `otherPublicKey` string. * @param outputEncoding The `encoding` of the return value. */ - computeSecret(otherPublicKey: NodeJS.ArrayBufferView): Buffer; - computeSecret(otherPublicKey: string, inputEncoding: BinaryToTextEncoding): Buffer; + computeSecret(otherPublicKey: NodeJS.ArrayBufferView): NonSharedBuffer; + computeSecret(otherPublicKey: string, inputEncoding: BinaryToTextEncoding): NonSharedBuffer; computeSecret(otherPublicKey: NodeJS.ArrayBufferView, outputEncoding: BinaryToTextEncoding): string; computeSecret( otherPublicKey: string, @@ -2394,7 +2414,7 @@ declare module "crypto" { * @param encoding The `encoding` of the return value. * @return The EC Diffie-Hellman in the specified `encoding`. */ - getPrivateKey(): Buffer; + getPrivateKey(): NonSharedBuffer; getPrivateKey(encoding: BinaryToTextEncoding): string; /** * The `format` argument specifies point encoding and can be `'compressed'` or `'uncompressed'`. If `format` is not specified the point will be returned in`'uncompressed'` format. @@ -2406,7 +2426,7 @@ declare module "crypto" { * @param [format='uncompressed'] * @return The EC Diffie-Hellman public key in the specified `encoding` and `format`. */ - getPublicKey(encoding?: null, format?: ECDHKeyFormat): Buffer; + getPublicKey(encoding?: null, format?: ECDHKeyFormat): NonSharedBuffer; getPublicKey(encoding: BinaryToTextEncoding, format?: ECDHKeyFormat): string; /** * Sets the EC Diffie-Hellman private key. @@ -2687,15 +2707,15 @@ declare module "crypto" { function generateKeyPairSync( type: "rsa", options: RSAKeyPairOptions<"pem", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "rsa", options: RSAKeyPairOptions<"der", "pem">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "rsa", options: RSAKeyPairOptions<"der", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync(type: "rsa", options: RSAKeyPairKeyObjectOptions): KeyPairKeyObjectResult; function generateKeyPairSync( type: "rsa-pss", @@ -2704,15 +2724,15 @@ declare module "crypto" { function generateKeyPairSync( type: "rsa-pss", options: RSAPSSKeyPairOptions<"pem", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "rsa-pss", options: RSAPSSKeyPairOptions<"der", "pem">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "rsa-pss", options: RSAPSSKeyPairOptions<"der", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync(type: "rsa-pss", options: RSAPSSKeyPairKeyObjectOptions): KeyPairKeyObjectResult; function generateKeyPairSync( type: "dsa", @@ -2721,15 +2741,15 @@ declare module "crypto" { function generateKeyPairSync( type: "dsa", options: DSAKeyPairOptions<"pem", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "dsa", options: DSAKeyPairOptions<"der", "pem">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "dsa", options: DSAKeyPairOptions<"der", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync(type: "dsa", options: DSAKeyPairKeyObjectOptions): KeyPairKeyObjectResult; function generateKeyPairSync( type: "ec", @@ -2738,15 +2758,15 @@ declare module "crypto" { function generateKeyPairSync( type: "ec", options: ECKeyPairOptions<"pem", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "ec", options: ECKeyPairOptions<"der", "pem">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "ec", options: ECKeyPairOptions<"der", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync(type: "ec", options: ECKeyPairKeyObjectOptions): KeyPairKeyObjectResult; function generateKeyPairSync( type: "ed25519", @@ -2755,15 +2775,15 @@ declare module "crypto" { function generateKeyPairSync( type: "ed25519", options: ED25519KeyPairOptions<"pem", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "ed25519", options: ED25519KeyPairOptions<"der", "pem">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "ed25519", options: ED25519KeyPairOptions<"der", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync(type: "ed25519", options?: ED25519KeyPairKeyObjectOptions): KeyPairKeyObjectResult; function generateKeyPairSync( type: "ed448", @@ -2772,15 +2792,15 @@ declare module "crypto" { function generateKeyPairSync( type: "ed448", options: ED448KeyPairOptions<"pem", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "ed448", options: ED448KeyPairOptions<"der", "pem">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "ed448", options: ED448KeyPairOptions<"der", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync(type: "ed448", options?: ED448KeyPairKeyObjectOptions): KeyPairKeyObjectResult; function generateKeyPairSync( type: "x25519", @@ -2789,15 +2809,15 @@ declare module "crypto" { function generateKeyPairSync( type: "x25519", options: X25519KeyPairOptions<"pem", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "x25519", options: X25519KeyPairOptions<"der", "pem">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "x25519", options: X25519KeyPairOptions<"der", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync(type: "x25519", options?: X25519KeyPairKeyObjectOptions): KeyPairKeyObjectResult; function generateKeyPairSync( type: "x448", @@ -2806,15 +2826,15 @@ declare module "crypto" { function generateKeyPairSync( type: "x448", options: X448KeyPairOptions<"pem", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "x448", options: X448KeyPairOptions<"der", "pem">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync( type: "x448", options: X448KeyPairOptions<"der", "der">, - ): KeyPairSyncResult; + ): KeyPairSyncResult; function generateKeyPairSync(type: "x448", options?: X448KeyPairKeyObjectOptions): KeyPairKeyObjectResult; /** * Generates a new asymmetric key pair of the given `type`. RSA, RSA-PSS, DSA, EC, @@ -2863,17 +2883,17 @@ declare module "crypto" { function generateKeyPair( type: "rsa", options: RSAKeyPairOptions<"pem", "der">, - callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: string, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "rsa", options: RSAKeyPairOptions<"der", "pem">, - callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: string) => void, ): void; function generateKeyPair( type: "rsa", options: RSAKeyPairOptions<"der", "der">, - callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "rsa", @@ -2888,17 +2908,17 @@ declare module "crypto" { function generateKeyPair( type: "rsa-pss", options: RSAPSSKeyPairOptions<"pem", "der">, - callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: string, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "rsa-pss", options: RSAPSSKeyPairOptions<"der", "pem">, - callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: string) => void, ): void; function generateKeyPair( type: "rsa-pss", options: RSAPSSKeyPairOptions<"der", "der">, - callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "rsa-pss", @@ -2913,17 +2933,17 @@ declare module "crypto" { function generateKeyPair( type: "dsa", options: DSAKeyPairOptions<"pem", "der">, - callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: string, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "dsa", options: DSAKeyPairOptions<"der", "pem">, - callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: string) => void, ): void; function generateKeyPair( type: "dsa", options: DSAKeyPairOptions<"der", "der">, - callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "dsa", @@ -2938,17 +2958,17 @@ declare module "crypto" { function generateKeyPair( type: "ec", options: ECKeyPairOptions<"pem", "der">, - callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: string, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "ec", options: ECKeyPairOptions<"der", "pem">, - callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: string) => void, ): void; function generateKeyPair( type: "ec", options: ECKeyPairOptions<"der", "der">, - callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "ec", @@ -2963,17 +2983,17 @@ declare module "crypto" { function generateKeyPair( type: "ed25519", options: ED25519KeyPairOptions<"pem", "der">, - callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: string, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "ed25519", options: ED25519KeyPairOptions<"der", "pem">, - callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: string) => void, ): void; function generateKeyPair( type: "ed25519", options: ED25519KeyPairOptions<"der", "der">, - callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "ed25519", @@ -2988,17 +3008,17 @@ declare module "crypto" { function generateKeyPair( type: "ed448", options: ED448KeyPairOptions<"pem", "der">, - callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: string, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "ed448", options: ED448KeyPairOptions<"der", "pem">, - callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: string) => void, ): void; function generateKeyPair( type: "ed448", options: ED448KeyPairOptions<"der", "der">, - callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "ed448", @@ -3013,17 +3033,17 @@ declare module "crypto" { function generateKeyPair( type: "x25519", options: X25519KeyPairOptions<"pem", "der">, - callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: string, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "x25519", options: X25519KeyPairOptions<"der", "pem">, - callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: string) => void, ): void; function generateKeyPair( type: "x25519", options: X25519KeyPairOptions<"der", "der">, - callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "x25519", @@ -3038,17 +3058,17 @@ declare module "crypto" { function generateKeyPair( type: "x448", options: X448KeyPairOptions<"pem", "der">, - callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: string, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "x448", options: X448KeyPairOptions<"der", "pem">, - callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: string) => void, ): void; function generateKeyPair( type: "x448", options: X448KeyPairOptions<"der", "der">, - callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void, + callback: (err: Error | null, publicKey: NonSharedBuffer, privateKey: NonSharedBuffer) => void, ): void; function generateKeyPair( type: "x448", @@ -3068,21 +3088,21 @@ declare module "crypto" { options: RSAKeyPairOptions<"pem", "der">, ): Promise<{ publicKey: string; - privateKey: Buffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "rsa", options: RSAKeyPairOptions<"der", "pem">, ): Promise<{ - publicKey: Buffer; + publicKey: NonSharedBuffer; privateKey: string; }>; function __promisify__( type: "rsa", options: RSAKeyPairOptions<"der", "der">, ): Promise<{ - publicKey: Buffer; - privateKey: Buffer; + publicKey: NonSharedBuffer; + privateKey: NonSharedBuffer; }>; function __promisify__(type: "rsa", options: RSAKeyPairKeyObjectOptions): Promise; function __promisify__( @@ -3097,21 +3117,21 @@ declare module "crypto" { options: RSAPSSKeyPairOptions<"pem", "der">, ): Promise<{ publicKey: string; - privateKey: Buffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "rsa-pss", options: RSAPSSKeyPairOptions<"der", "pem">, ): Promise<{ - publicKey: Buffer; + publicKey: NonSharedBuffer; privateKey: string; }>; function __promisify__( type: "rsa-pss", options: RSAPSSKeyPairOptions<"der", "der">, ): Promise<{ - publicKey: Buffer; - privateKey: Buffer; + publicKey: NonSharedBuffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "rsa-pss", @@ -3129,21 +3149,21 @@ declare module "crypto" { options: DSAKeyPairOptions<"pem", "der">, ): Promise<{ publicKey: string; - privateKey: Buffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "dsa", options: DSAKeyPairOptions<"der", "pem">, ): Promise<{ - publicKey: Buffer; + publicKey: NonSharedBuffer; privateKey: string; }>; function __promisify__( type: "dsa", options: DSAKeyPairOptions<"der", "der">, ): Promise<{ - publicKey: Buffer; - privateKey: Buffer; + publicKey: NonSharedBuffer; + privateKey: NonSharedBuffer; }>; function __promisify__(type: "dsa", options: DSAKeyPairKeyObjectOptions): Promise; function __promisify__( @@ -3158,21 +3178,21 @@ declare module "crypto" { options: ECKeyPairOptions<"pem", "der">, ): Promise<{ publicKey: string; - privateKey: Buffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "ec", options: ECKeyPairOptions<"der", "pem">, ): Promise<{ - publicKey: Buffer; + publicKey: NonSharedBuffer; privateKey: string; }>; function __promisify__( type: "ec", options: ECKeyPairOptions<"der", "der">, ): Promise<{ - publicKey: Buffer; - privateKey: Buffer; + publicKey: NonSharedBuffer; + privateKey: NonSharedBuffer; }>; function __promisify__(type: "ec", options: ECKeyPairKeyObjectOptions): Promise; function __promisify__( @@ -3187,21 +3207,21 @@ declare module "crypto" { options: ED25519KeyPairOptions<"pem", "der">, ): Promise<{ publicKey: string; - privateKey: Buffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "ed25519", options: ED25519KeyPairOptions<"der", "pem">, ): Promise<{ - publicKey: Buffer; + publicKey: NonSharedBuffer; privateKey: string; }>; function __promisify__( type: "ed25519", options: ED25519KeyPairOptions<"der", "der">, ): Promise<{ - publicKey: Buffer; - privateKey: Buffer; + publicKey: NonSharedBuffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "ed25519", @@ -3219,21 +3239,21 @@ declare module "crypto" { options: ED448KeyPairOptions<"pem", "der">, ): Promise<{ publicKey: string; - privateKey: Buffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "ed448", options: ED448KeyPairOptions<"der", "pem">, ): Promise<{ - publicKey: Buffer; + publicKey: NonSharedBuffer; privateKey: string; }>; function __promisify__( type: "ed448", options: ED448KeyPairOptions<"der", "der">, ): Promise<{ - publicKey: Buffer; - privateKey: Buffer; + publicKey: NonSharedBuffer; + privateKey: NonSharedBuffer; }>; function __promisify__(type: "ed448", options?: ED448KeyPairKeyObjectOptions): Promise; function __promisify__( @@ -3248,21 +3268,21 @@ declare module "crypto" { options: X25519KeyPairOptions<"pem", "der">, ): Promise<{ publicKey: string; - privateKey: Buffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "x25519", options: X25519KeyPairOptions<"der", "pem">, ): Promise<{ - publicKey: Buffer; + publicKey: NonSharedBuffer; privateKey: string; }>; function __promisify__( type: "x25519", options: X25519KeyPairOptions<"der", "der">, ): Promise<{ - publicKey: Buffer; - privateKey: Buffer; + publicKey: NonSharedBuffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "x25519", @@ -3280,21 +3300,21 @@ declare module "crypto" { options: X448KeyPairOptions<"pem", "der">, ): Promise<{ publicKey: string; - privateKey: Buffer; + privateKey: NonSharedBuffer; }>; function __promisify__( type: "x448", options: X448KeyPairOptions<"der", "pem">, ): Promise<{ - publicKey: Buffer; + publicKey: NonSharedBuffer; privateKey: string; }>; function __promisify__( type: "x448", options: X448KeyPairOptions<"der", "der">, ): Promise<{ - publicKey: Buffer; - privateKey: Buffer; + publicKey: NonSharedBuffer; + privateKey: NonSharedBuffer; }>; function __promisify__(type: "x448", options?: X448KeyPairKeyObjectOptions): Promise; } @@ -3314,12 +3334,12 @@ declare module "crypto" { algorithm: string | null | undefined, data: NodeJS.ArrayBufferView, key: KeyLike | SignKeyObjectInput | SignPrivateKeyInput | SignJsonWebKeyInput, - ): Buffer; + ): NonSharedBuffer; function sign( algorithm: string | null | undefined, data: NodeJS.ArrayBufferView, key: KeyLike | SignKeyObjectInput | SignPrivateKeyInput | SignJsonWebKeyInput, - callback: (error: Error | null, data: Buffer) => void, + callback: (error: Error | null, data: NonSharedBuffer) => void, ): void; /** * Verifies the given signature for `data` using the given key and algorithm. If `algorithm` is `null` or `undefined`, then the algorithm is dependent upon the @@ -3355,7 +3375,7 @@ declare module "crypto" { * Both keys must have the same `asymmetricKeyType`, which must be one of `'dh'` (for Diffie-Hellman), `'ec'` (for ECDH), `'x448'`, or `'x25519'` (for ECDH-ES). * @since v13.9.0, v12.17.0 */ - function diffieHellman(options: { privateKey: KeyObject; publicKey: KeyObject }): Buffer; + function diffieHellman(options: { privateKey: KeyObject; publicKey: KeyObject }): NonSharedBuffer; /** * A utility for creating one-shot hash digests of data. It can be faster than the object-based `crypto.createHash()` when hashing a smaller amount of data * (<= 5MB) that's readily available. If the data can be big or if it is streamed, it's still recommended to use `crypto.createHash()` instead. The `algorithm` @@ -3385,12 +3405,12 @@ declare module "crypto" { * @param [outputEncoding='hex'] [Encoding](https://nodejs.org/docs/latest-v22.x/api/buffer.html#buffers-and-character-encodings) used to encode the returned digest. */ function hash(algorithm: string, data: BinaryLike, outputEncoding?: BinaryToTextEncoding): string; - function hash(algorithm: string, data: BinaryLike, outputEncoding: "buffer"): Buffer; + function hash(algorithm: string, data: BinaryLike, outputEncoding: "buffer"): NonSharedBuffer; function hash( algorithm: string, data: BinaryLike, outputEncoding?: BinaryToTextEncoding | "buffer", - ): string | Buffer; + ): string | NonSharedBuffer; type CipherMode = "cbc" | "ccm" | "cfb" | "ctr" | "ecb" | "gcm" | "ocb" | "ofb" | "stream" | "wrap" | "xts"; interface CipherInfoOptions { /** @@ -3682,7 +3702,7 @@ declare module "crypto" { * A `Buffer` containing the DER encoding of this certificate. * @since v15.6.0 */ - readonly raw: Buffer; + readonly raw: NonSharedBuffer; /** * The serial number of this certificate. * diff --git a/types/node/v22/dgram.d.ts b/types/node/v22/dgram.d.ts index 77a851f36ec013..9776de0d5ef68e 100644 --- a/types/node/v22/dgram.d.ts +++ b/types/node/v22/dgram.d.ts @@ -26,6 +26,7 @@ * @see [source](https://github.com/nodejs/node/blob/v22.x/lib/dgram.js) */ declare module "dgram" { + import { NonSharedBuffer } from "node:buffer"; import { AddressInfo, BlockList } from "node:net"; import * as dns from "node:dns"; import { Abortable, EventEmitter } from "node:events"; @@ -85,8 +86,8 @@ declare module "dgram" { * @param options Available options are: * @param callback Attached as a listener for `'message'` events. Optional. */ - function createSocket(type: SocketType, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket; - function createSocket(options: SocketOptions, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket; + function createSocket(type: SocketType, callback?: (msg: NonSharedBuffer, rinfo: RemoteInfo) => void): Socket; + function createSocket(options: SocketOptions, callback?: (msg: NonSharedBuffer, rinfo: RemoteInfo) => void): Socket; /** * Encapsulates the datagram functionality. * @@ -556,37 +557,37 @@ declare module "dgram" { addListener(event: "connect", listener: () => void): this; addListener(event: "error", listener: (err: Error) => void): this; addListener(event: "listening", listener: () => void): this; - addListener(event: "message", listener: (msg: Buffer, rinfo: RemoteInfo) => void): this; + addListener(event: "message", listener: (msg: NonSharedBuffer, rinfo: RemoteInfo) => void): this; emit(event: string | symbol, ...args: any[]): boolean; emit(event: "close"): boolean; emit(event: "connect"): boolean; emit(event: "error", err: Error): boolean; emit(event: "listening"): boolean; - emit(event: "message", msg: Buffer, rinfo: RemoteInfo): boolean; + emit(event: "message", msg: NonSharedBuffer, rinfo: RemoteInfo): boolean; on(event: string, listener: (...args: any[]) => void): this; on(event: "close", listener: () => void): this; on(event: "connect", listener: () => void): this; on(event: "error", listener: (err: Error) => void): this; on(event: "listening", listener: () => void): this; - on(event: "message", listener: (msg: Buffer, rinfo: RemoteInfo) => void): this; + on(event: "message", listener: (msg: NonSharedBuffer, rinfo: RemoteInfo) => void): this; once(event: string, listener: (...args: any[]) => void): this; once(event: "close", listener: () => void): this; once(event: "connect", listener: () => void): this; once(event: "error", listener: (err: Error) => void): this; once(event: "listening", listener: () => void): this; - once(event: "message", listener: (msg: Buffer, rinfo: RemoteInfo) => void): this; + once(event: "message", listener: (msg: NonSharedBuffer, rinfo: RemoteInfo) => void): this; prependListener(event: string, listener: (...args: any[]) => void): this; prependListener(event: "close", listener: () => void): this; prependListener(event: "connect", listener: () => void): this; prependListener(event: "error", listener: (err: Error) => void): this; prependListener(event: "listening", listener: () => void): this; - prependListener(event: "message", listener: (msg: Buffer, rinfo: RemoteInfo) => void): this; + prependListener(event: "message", listener: (msg: NonSharedBuffer, rinfo: RemoteInfo) => void): this; prependOnceListener(event: string, listener: (...args: any[]) => void): this; prependOnceListener(event: "close", listener: () => void): this; prependOnceListener(event: "connect", listener: () => void): this; prependOnceListener(event: "error", listener: (err: Error) => void): this; prependOnceListener(event: "listening", listener: () => void): this; - prependOnceListener(event: "message", listener: (msg: Buffer, rinfo: RemoteInfo) => void): this; + prependOnceListener(event: "message", listener: (msg: NonSharedBuffer, rinfo: RemoteInfo) => void): this; /** * Calls `socket.close()` and returns a promise that fulfills when the socket has closed. * @since v20.5.0 diff --git a/types/node/v22/fs.d.ts b/types/node/v22/fs.d.ts index 693e6289754d57..d40515bfaf02bd 100644 --- a/types/node/v22/fs.d.ts +++ b/types/node/v22/fs.d.ts @@ -19,6 +19,7 @@ * @see [source](https://github.com/nodejs/node/blob/v22.x/lib/fs.js) */ declare module "fs" { + import { NonSharedBuffer } from "node:buffer"; import * as stream from "node:stream"; import { Abortable, EventEmitter } from "node:events"; import { URL } from "node:url"; @@ -402,23 +403,29 @@ declare module "fs" { * 3. error */ addListener(event: string, listener: (...args: any[]) => void): this; - addListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this; + addListener(event: "change", listener: (eventType: string, filename: string | NonSharedBuffer) => void): this; addListener(event: "close", listener: () => void): this; addListener(event: "error", listener: (error: Error) => void): this; on(event: string, listener: (...args: any[]) => void): this; - on(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this; + on(event: "change", listener: (eventType: string, filename: string | NonSharedBuffer) => void): this; on(event: "close", listener: () => void): this; on(event: "error", listener: (error: Error) => void): this; once(event: string, listener: (...args: any[]) => void): this; - once(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this; + once(event: "change", listener: (eventType: string, filename: string | NonSharedBuffer) => void): this; once(event: "close", listener: () => void): this; once(event: "error", listener: (error: Error) => void): this; prependListener(event: string, listener: (...args: any[]) => void): this; - prependListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this; + prependListener( + event: "change", + listener: (eventType: string, filename: string | NonSharedBuffer) => void, + ): this; prependListener(event: "close", listener: () => void): this; prependListener(event: "error", listener: (error: Error) => void): this; prependOnceListener(event: string, listener: (...args: any[]) => void): this; - prependOnceListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this; + prependOnceListener( + event: "change", + listener: (eventType: string, filename: string | NonSharedBuffer) => void, + ): this; prependOnceListener(event: "close", listener: () => void): this; prependOnceListener(event: "error", listener: (error: Error) => void): this; } @@ -1334,7 +1341,7 @@ declare module "fs" { export function readlink( path: PathLike, options: BufferEncodingOption, - callback: (err: NodeJS.ErrnoException | null, linkString: Buffer) => void, + callback: (err: NodeJS.ErrnoException | null, linkString: NonSharedBuffer) => void, ): void; /** * Asynchronous readlink(2) - read value of a symbolic link. @@ -1344,7 +1351,7 @@ declare module "fs" { export function readlink( path: PathLike, options: EncodingOption, - callback: (err: NodeJS.ErrnoException | null, linkString: string | Buffer) => void, + callback: (err: NodeJS.ErrnoException | null, linkString: string | NonSharedBuffer) => void, ): void; /** * Asynchronous readlink(2) - read value of a symbolic link. @@ -1366,13 +1373,13 @@ declare module "fs" { * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function __promisify__(path: PathLike, options: BufferEncodingOption): Promise; + function __promisify__(path: PathLike, options: BufferEncodingOption): Promise; /** * Asynchronous readlink(2) - read value of a symbolic link. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function __promisify__(path: PathLike, options?: EncodingOption): Promise; + function __promisify__(path: PathLike, options?: EncodingOption): Promise; } /** * Returns the symbolic link's string value. @@ -1391,13 +1398,13 @@ declare module "fs" { * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - export function readlinkSync(path: PathLike, options: BufferEncodingOption): Buffer; + export function readlinkSync(path: PathLike, options: BufferEncodingOption): NonSharedBuffer; /** * Synchronous readlink(2) - read value of a symbolic link. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - export function readlinkSync(path: PathLike, options?: EncodingOption): string | Buffer; + export function readlinkSync(path: PathLike, options?: EncodingOption): string | NonSharedBuffer; /** * Asynchronously computes the canonical pathname by resolving `.`, `..`, and * symbolic links. @@ -1437,7 +1444,7 @@ declare module "fs" { export function realpath( path: PathLike, options: BufferEncodingOption, - callback: (err: NodeJS.ErrnoException | null, resolvedPath: Buffer) => void, + callback: (err: NodeJS.ErrnoException | null, resolvedPath: NonSharedBuffer) => void, ): void; /** * Asynchronous realpath(3) - return the canonicalized absolute pathname. @@ -1447,7 +1454,7 @@ declare module "fs" { export function realpath( path: PathLike, options: EncodingOption, - callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | Buffer) => void, + callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | NonSharedBuffer) => void, ): void; /** * Asynchronous realpath(3) - return the canonicalized absolute pathname. @@ -1469,13 +1476,13 @@ declare module "fs" { * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function __promisify__(path: PathLike, options: BufferEncodingOption): Promise; + function __promisify__(path: PathLike, options: BufferEncodingOption): Promise; /** * Asynchronous realpath(3) - return the canonicalized absolute pathname. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function __promisify__(path: PathLike, options?: EncodingOption): Promise; + function __promisify__(path: PathLike, options?: EncodingOption): Promise; /** * Asynchronous [`realpath(3)`](http://man7.org/linux/man-pages/man3/realpath.3.html). * @@ -1501,12 +1508,12 @@ declare module "fs" { function native( path: PathLike, options: BufferEncodingOption, - callback: (err: NodeJS.ErrnoException | null, resolvedPath: Buffer) => void, + callback: (err: NodeJS.ErrnoException | null, resolvedPath: NonSharedBuffer) => void, ): void; function native( path: PathLike, options: EncodingOption, - callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | Buffer) => void, + callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | NonSharedBuffer) => void, ): void; function native( path: PathLike, @@ -1526,17 +1533,17 @@ declare module "fs" { * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - export function realpathSync(path: PathLike, options: BufferEncodingOption): Buffer; + export function realpathSync(path: PathLike, options: BufferEncodingOption): NonSharedBuffer; /** * Synchronous realpath(3) - return the canonicalized absolute pathname. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - export function realpathSync(path: PathLike, options?: EncodingOption): string | Buffer; + export function realpathSync(path: PathLike, options?: EncodingOption): string | NonSharedBuffer; export namespace realpathSync { function native(path: PathLike, options?: EncodingOption): string; - function native(path: PathLike, options: BufferEncodingOption): Buffer; - function native(path: PathLike, options?: EncodingOption): string | Buffer; + function native(path: PathLike, options: BufferEncodingOption): NonSharedBuffer; + function native(path: PathLike, options?: EncodingOption): string | NonSharedBuffer; } /** * Asynchronously removes a file or symbolic link. No arguments other than a @@ -1906,12 +1913,8 @@ declare module "fs" { */ export function mkdtemp( prefix: string, - options: - | "buffer" - | { - encoding: "buffer"; - }, - callback: (err: NodeJS.ErrnoException | null, folder: Buffer) => void, + options: BufferEncodingOption, + callback: (err: NodeJS.ErrnoException | null, folder: NonSharedBuffer) => void, ): void; /** * Asynchronously creates a unique temporary directory. @@ -1921,7 +1924,7 @@ declare module "fs" { export function mkdtemp( prefix: string, options: EncodingOption, - callback: (err: NodeJS.ErrnoException | null, folder: string | Buffer) => void, + callback: (err: NodeJS.ErrnoException | null, folder: string | NonSharedBuffer) => void, ): void; /** * Asynchronously creates a unique temporary directory. @@ -1943,13 +1946,13 @@ declare module "fs" { * Generates six random characters to be appended behind a required prefix to create a unique temporary directory. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function __promisify__(prefix: string, options: BufferEncodingOption): Promise; + function __promisify__(prefix: string, options: BufferEncodingOption): Promise; /** * Asynchronously creates a unique temporary directory. * Generates six random characters to be appended behind a required prefix to create a unique temporary directory. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function __promisify__(prefix: string, options?: EncodingOption): Promise; + function __promisify__(prefix: string, options?: EncodingOption): Promise; } /** * Returns the created directory path. @@ -1967,13 +1970,13 @@ declare module "fs" { * Generates six random characters to be appended behind a required prefix to create a unique temporary directory. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - export function mkdtempSync(prefix: string, options: BufferEncodingOption): Buffer; + export function mkdtempSync(prefix: string, options: BufferEncodingOption): NonSharedBuffer; /** * Synchronously creates a unique temporary directory. * Generates six random characters to be appended behind a required prefix to create a unique temporary directory. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - export function mkdtempSync(prefix: string, options?: EncodingOption): string | Buffer; + export function mkdtempSync(prefix: string, options?: EncodingOption): string | NonSharedBuffer; /** * Reads the contents of a directory. The callback gets two arguments `(err, files)` where `files` is an array of the names of the files in the directory excluding `'.'` and `'..'`. * @@ -2014,7 +2017,7 @@ declare module "fs" { recursive?: boolean | undefined; } | "buffer", - callback: (err: NodeJS.ErrnoException | null, files: Buffer[]) => void, + callback: (err: NodeJS.ErrnoException | null, files: NonSharedBuffer[]) => void, ): void; /** * Asynchronous readdir(3) - read a directory. @@ -2031,7 +2034,7 @@ declare module "fs" { | BufferEncoding | undefined | null, - callback: (err: NodeJS.ErrnoException | null, files: string[] | Buffer[]) => void, + callback: (err: NodeJS.ErrnoException | null, files: string[] | NonSharedBuffer[]) => void, ): void; /** * Asynchronous readdir(3) - read a directory. @@ -2066,7 +2069,7 @@ declare module "fs" { withFileTypes: true; recursive?: boolean | undefined; }, - callback: (err: NodeJS.ErrnoException | null, files: Dirent[]) => void, + callback: (err: NodeJS.ErrnoException | null, files: Dirent[]) => void, ): void; export namespace readdir { /** @@ -2099,7 +2102,7 @@ declare module "fs" { withFileTypes?: false | undefined; recursive?: boolean | undefined; }, - ): Promise; + ): Promise; /** * Asynchronous readdir(3) - read a directory. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. @@ -2114,7 +2117,7 @@ declare module "fs" { }) | BufferEncoding | null, - ): Promise; + ): Promise; /** * Asynchronous readdir(3) - read a directory. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. @@ -2139,7 +2142,7 @@ declare module "fs" { withFileTypes: true; recursive?: boolean | undefined; }, - ): Promise[]>; + ): Promise[]>; } /** * Reads the contents of the directory. @@ -2179,7 +2182,7 @@ declare module "fs" { recursive?: boolean | undefined; } | "buffer", - ): Buffer[]; + ): NonSharedBuffer[]; /** * Synchronous readdir(3) - read a directory. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. @@ -2194,7 +2197,7 @@ declare module "fs" { }) | BufferEncoding | null, - ): string[] | Buffer[]; + ): string[] | NonSharedBuffer[]; /** * Synchronous readdir(3) - read a directory. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. @@ -2219,7 +2222,7 @@ declare module "fs" { withFileTypes: true; recursive?: boolean | undefined; }, - ): Dirent[]; + ): Dirent[]; /** * Closes the file descriptor. No arguments other than a possible exception are * given to the completion callback. @@ -2586,7 +2589,7 @@ declare module "fs" { encoding?: BufferEncoding | null, ): number; export type ReadPosition = number | bigint; - export interface ReadSyncOptions { + export interface ReadOptions { /** * @default 0 */ @@ -2600,9 +2603,15 @@ declare module "fs" { */ position?: ReadPosition | null | undefined; } - export interface ReadAsyncOptions extends ReadSyncOptions { - buffer?: TBuffer; + export interface ReadOptionsWithBuffer extends ReadOptions { + buffer?: T | undefined; } + /** @deprecated Use `ReadOptions` instead. */ + // TODO: remove in future major + export interface ReadSyncOptions extends ReadOptions {} + /** @deprecated Use `ReadOptionsWithBuffer` instead. */ + // TODO: remove in future major + export interface ReadAsyncOptions extends ReadOptionsWithBuffer {} /** * Read data from the file specified by `fd`. * @@ -2637,15 +2646,15 @@ declare module "fs" { * `position` defaults to `null` * @since v12.17.0, 13.11.0 */ - export function read( + export function read( fd: number, - options: ReadAsyncOptions, + options: ReadOptionsWithBuffer, callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void, ): void; export function read( fd: number, buffer: TBuffer, - options: ReadSyncOptions, + options: ReadOptions, callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void, ): void; export function read( @@ -2655,7 +2664,7 @@ declare module "fs" { ): void; export function read( fd: number, - callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: NodeJS.ArrayBufferView) => void, + callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: NonSharedBuffer) => void, ): void; export namespace read { /** @@ -2675,16 +2684,16 @@ declare module "fs" { bytesRead: number; buffer: TBuffer; }>; - function __promisify__( + function __promisify__( fd: number, - options: ReadAsyncOptions, + options: ReadOptionsWithBuffer, ): Promise<{ bytesRead: number; buffer: TBuffer; }>; function __promisify__(fd: number): Promise<{ bytesRead: number; - buffer: NodeJS.ArrayBufferView; + buffer: NonSharedBuffer; }>; } /** @@ -2706,7 +2715,7 @@ declare module "fs" { * Similar to the above `fs.readSync` function, this version takes an optional `options` object. * If no `options` object is specified, it will default with the above values. */ - export function readSync(fd: number, buffer: NodeJS.ArrayBufferView, opts?: ReadSyncOptions): number; + export function readSync(fd: number, buffer: NodeJS.ArrayBufferView, opts?: ReadOptions): number; /** * Asynchronously reads the entire contents of a file. * @@ -3379,12 +3388,12 @@ declare module "fs" { export function watch( filename: PathLike, options: WatchOptionsWithBufferEncoding | "buffer", - listener: WatchListener, + listener: WatchListener, ): FSWatcher; export function watch( filename: PathLike, options: WatchOptions | BufferEncoding | "buffer" | null, - listener: WatchListener, + listener: WatchListener, ): FSWatcher; export function watch(filename: PathLike, listener: WatchListener): FSWatcher; /** @@ -4095,27 +4104,29 @@ declare module "fs" { * @since v12.9.0 * @param [position='null'] */ - export function writev( + export function writev( fd: number, - buffers: readonly NodeJS.ArrayBufferView[], - cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void, + buffers: TBuffers, + cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: TBuffers) => void, ): void; - export function writev( + export function writev( fd: number, - buffers: readonly NodeJS.ArrayBufferView[], + buffers: TBuffers, position: number | null, - cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void, + cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: TBuffers) => void, ): void; - export interface WriteVResult { + // Providing a default type parameter doesn't provide true BC for userland consumers, but at least suppresses TS2314 + // TODO: remove default in future major version + export interface WriteVResult { bytesWritten: number; - buffers: NodeJS.ArrayBufferView[]; + buffers: T; } export namespace writev { - function __promisify__( + function __promisify__( fd: number, - buffers: readonly NodeJS.ArrayBufferView[], + buffers: TBuffers, position?: number, - ): Promise; + ): Promise>; } /** * For detailed information, see the documentation of the asynchronous version of @@ -4140,27 +4151,29 @@ declare module "fs" { * @since v13.13.0, v12.17.0 * @param [position='null'] */ - export function readv( + export function readv( fd: number, - buffers: readonly NodeJS.ArrayBufferView[], - cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => void, + buffers: TBuffers, + cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: TBuffers) => void, ): void; - export function readv( + export function readv( fd: number, - buffers: readonly NodeJS.ArrayBufferView[], + buffers: TBuffers, position: number | null, - cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => void, + cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: TBuffers) => void, ): void; - export interface ReadVResult { + // Providing a default type parameter doesn't provide true BC for userland consumers, but at least suppresses TS2314 + // TODO: remove default in future major version + export interface ReadVResult { bytesRead: number; - buffers: NodeJS.ArrayBufferView[]; + buffers: T; } export namespace readv { - function __promisify__( + function __promisify__( fd: number, - buffers: readonly NodeJS.ArrayBufferView[], + buffers: TBuffers, position?: number, - ): Promise; + ): Promise>; } /** * For detailed information, see the documentation of the asynchronous version of diff --git a/types/node/v22/fs/promises.d.ts b/types/node/v22/fs/promises.d.ts index 9538c8cc1cb591..051ddba4043498 100644 --- a/types/node/v22/fs/promises.d.ts +++ b/types/node/v22/fs/promises.d.ts @@ -9,6 +9,7 @@ * @since v10.0.0 */ declare module "fs/promises" { + import { NonSharedBuffer } from "node:buffer"; import { Abortable } from "node:events"; import { Stream } from "node:stream"; import { ReadableStream } from "node:stream/web"; @@ -29,6 +30,8 @@ declare module "fs/promises" { OpenDirOptions, OpenMode, PathLike, + ReadOptions, + ReadOptionsWithBuffer, ReadPosition, ReadStream, ReadVResult, @@ -57,6 +60,7 @@ declare module "fs/promises" { bytesRead: number; buffer: T; } + /** @deprecated This interface will be removed in a future version. Use `import { ReadOptionsWithBuffer } from "node:fs"` instead. */ interface FileReadOptions { /** * @default `Buffer.alloc(0xffff)` @@ -235,11 +239,13 @@ declare module "fs/promises" { length?: number | null, position?: ReadPosition | null, ): Promise>; - read( + read( buffer: T, - options?: FileReadOptions, + options?: ReadOptions, + ): Promise>; + read( + options?: ReadOptionsWithBuffer, ): Promise>; - read(options?: FileReadOptions): Promise>; /** * Returns a byte-oriented `ReadableStream` that may be used to read the file's * contents. @@ -283,7 +289,7 @@ declare module "fs/promises" { options?: | ({ encoding?: null | undefined } & Abortable) | null, - ): Promise; + ): Promise; /** * Asynchronously reads the entire contents of a file. The underlying file will _not_ be closed automatically. * The `FileHandle` must have been opened for reading. @@ -302,7 +308,7 @@ declare module "fs/promises" { | (ObjectEncodingOptions & Abortable) | BufferEncoding | null, - ): Promise; + ): Promise; /** * Convenience method to create a `readline` interface and stream over the file. * See `filehandle.createReadStream()` for the options. @@ -411,7 +417,7 @@ declare module "fs/promises" { * @param [position='null'] The offset from the beginning of the file where the data from `buffer` should be written. If `position` is not a `number`, the data will be written at the current * position. See the POSIX pwrite(2) documentation for more detail. */ - write( + write( buffer: TBuffer, offset?: number | null, length?: number | null, @@ -450,14 +456,20 @@ declare module "fs/promises" { * @param [position='null'] The offset from the beginning of the file where the data from `buffers` should be written. If `position` is not a `number`, the data will be written at the current * position. */ - writev(buffers: readonly NodeJS.ArrayBufferView[], position?: number): Promise; + writev( + buffers: TBuffers, + position?: number, + ): Promise>; /** * Read from a file and write to an array of [ArrayBufferView](https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView) s * @since v13.13.0, v12.17.0 * @param [position='null'] The offset from the beginning of the file where the data should be read from. If `position` is not a `number`, the data will be read from the current position. * @return Fulfills upon success an object containing two properties: */ - readv(buffers: readonly NodeJS.ArrayBufferView[], position?: number): Promise; + readv( + buffers: TBuffers, + position?: number, + ): Promise>; /** * Closes the file handle after waiting for any pending operation on the handle to * complete. @@ -694,7 +706,7 @@ declare module "fs/promises" { recursive?: boolean | undefined; } | "buffer", - ): Promise; + ): Promise; /** * Asynchronous readdir(3) - read a directory. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. @@ -709,7 +721,7 @@ declare module "fs/promises" { }) | BufferEncoding | null, - ): Promise; + ): Promise; /** * Asynchronous readdir(3) - read a directory. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. @@ -734,7 +746,7 @@ declare module "fs/promises" { withFileTypes: true; recursive?: boolean | undefined; }, - ): Promise[]>; + ): Promise[]>; /** * Reads the contents of the symbolic link referred to by `path`. See the POSIX [`readlink(2)`](http://man7.org/linux/man-pages/man2/readlink.2.html) documentation for more detail. The promise is * fulfilled with the`linkString` upon success. @@ -752,13 +764,16 @@ declare module "fs/promises" { * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function readlink(path: PathLike, options: BufferEncodingOption): Promise; + function readlink(path: PathLike, options: BufferEncodingOption): Promise; /** * Asynchronous readlink(2) - read value of a symbolic link. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function readlink(path: PathLike, options?: ObjectEncodingOptions | string | null): Promise; + function readlink( + path: PathLike, + options?: ObjectEncodingOptions | string | null, + ): Promise; /** * Creates a symbolic link. * @@ -909,7 +924,7 @@ declare module "fs/promises" { * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function realpath(path: PathLike, options: BufferEncodingOption): Promise; + function realpath(path: PathLike, options: BufferEncodingOption): Promise; /** * Asynchronous realpath(3) - return the canonicalized absolute pathname. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. @@ -918,7 +933,7 @@ declare module "fs/promises" { function realpath( path: PathLike, options?: ObjectEncodingOptions | BufferEncoding | null, - ): Promise; + ): Promise; /** * Creates a unique temporary directory. A unique directory name is generated by * appending six random characters to the end of the provided `prefix`. Due to @@ -954,13 +969,16 @@ declare module "fs/promises" { * Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function mkdtemp(prefix: string, options: BufferEncodingOption): Promise; + function mkdtemp(prefix: string, options: BufferEncodingOption): Promise; /** * Asynchronously creates a unique temporary directory. * Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used. */ - function mkdtemp(prefix: string, options?: ObjectEncodingOptions | BufferEncoding | null): Promise; + function mkdtemp( + prefix: string, + options?: ObjectEncodingOptions | BufferEncoding | null, + ): Promise; /** * Asynchronously writes data to a file, replacing the file if it already exists. `data` can be a string, a buffer, an * [AsyncIterable](https://tc39.github.io/ecma262/#sec-asynciterable-interface), or an @@ -1116,7 +1134,7 @@ declare module "fs/promises" { flag?: OpenMode | undefined; } & Abortable) | null, - ): Promise; + ): Promise; /** * Asynchronously reads the entire contents of a file. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. @@ -1152,7 +1170,7 @@ declare module "fs/promises" { ) | BufferEncoding | null, - ): Promise; + ): Promise; /** * Asynchronously open a directory for iterative scanning. See the POSIX [`opendir(3)`](http://man7.org/linux/man-pages/man3/opendir.3.html) documentation for more detail. * @@ -1229,11 +1247,11 @@ declare module "fs/promises" { function watch( filename: PathLike, options: WatchOptionsWithBufferEncoding | "buffer", - ): NodeJS.AsyncIterator>; + ): NodeJS.AsyncIterator>; function watch( filename: PathLike, options: WatchOptions | BufferEncoding | "buffer", - ): NodeJS.AsyncIterator>; + ): NodeJS.AsyncIterator>; /** * Asynchronously copies the entire directory structure from `src` to `dest`, * including subdirectories and files. diff --git a/types/node/v22/globals.typedarray.d.ts b/types/node/v22/globals.typedarray.d.ts index 0c7280c3d8a9a6..8eafc3b464c5ad 100644 --- a/types/node/v22/globals.typedarray.d.ts +++ b/types/node/v22/globals.typedarray.d.ts @@ -17,5 +17,22 @@ declare global { type ArrayBufferView = | TypedArray | DataView; + + // The following aliases are required to allow use of non-shared ArrayBufferViews in @types/node + // while maintaining compatibility with TS <=5.6. + type NonSharedUint8Array = Uint8Array; + type NonSharedUint8ClampedArray = Uint8ClampedArray; + type NonSharedUint16Array = Uint16Array; + type NonSharedUint32Array = Uint32Array; + type NonSharedInt8Array = Int8Array; + type NonSharedInt16Array = Int16Array; + type NonSharedInt32Array = Int32Array; + type NonSharedBigUint64Array = BigUint64Array; + type NonSharedBigInt64Array = BigInt64Array; + type NonSharedFloat32Array = Float32Array; + type NonSharedFloat64Array = Float64Array; + type NonSharedDataView = DataView; + type NonSharedTypedArray = TypedArray; + type NonSharedArrayBufferView = ArrayBufferView; } } diff --git a/types/node/v22/http.d.ts b/types/node/v22/http.d.ts index 7b472ca142e72d..ebc932010a9353 100644 --- a/types/node/v22/http.d.ts +++ b/types/node/v22/http.d.ts @@ -40,6 +40,7 @@ * @see [source](https://github.com/nodejs/node/blob/v22.x/lib/http.js) */ declare module "http" { + import { NonSharedBuffer } from "node:buffer"; import * as stream from "node:stream"; import { URL } from "node:url"; import { LookupOptions } from "node:dns"; @@ -459,13 +460,13 @@ declare module "http" { addListener(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this; addListener( event: "connect", - listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, ): this; addListener(event: "dropRequest", listener: (req: InstanceType, socket: stream.Duplex) => void): this; addListener(event: "request", listener: RequestListener): this; addListener( event: "upgrade", - listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, ): this; emit(event: string, ...args: any[]): boolean; emit(event: "close"): boolean; @@ -483,14 +484,14 @@ declare module "http" { res: InstanceType & { req: InstanceType }, ): boolean; emit(event: "clientError", err: Error, socket: stream.Duplex): boolean; - emit(event: "connect", req: InstanceType, socket: stream.Duplex, head: Buffer): boolean; + emit(event: "connect", req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer): boolean; emit(event: "dropRequest", req: InstanceType, socket: stream.Duplex): boolean; emit( event: "request", req: InstanceType, res: InstanceType & { req: InstanceType }, ): boolean; - emit(event: "upgrade", req: InstanceType, socket: stream.Duplex, head: Buffer): boolean; + emit(event: "upgrade", req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer): boolean; on(event: string, listener: (...args: any[]) => void): this; on(event: "close", listener: () => void): this; on(event: "connection", listener: (socket: Socket) => void): this; @@ -499,10 +500,16 @@ declare module "http" { on(event: "checkContinue", listener: RequestListener): this; on(event: "checkExpectation", listener: RequestListener): this; on(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this; - on(event: "connect", listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void): this; + on( + event: "connect", + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, + ): this; on(event: "dropRequest", listener: (req: InstanceType, socket: stream.Duplex) => void): this; on(event: "request", listener: RequestListener): this; - on(event: "upgrade", listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void): this; + on( + event: "upgrade", + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, + ): this; once(event: string, listener: (...args: any[]) => void): this; once(event: "close", listener: () => void): this; once(event: "connection", listener: (socket: Socket) => void): this; @@ -513,13 +520,13 @@ declare module "http" { once(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this; once( event: "connect", - listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, ): this; once(event: "dropRequest", listener: (req: InstanceType, socket: stream.Duplex) => void): this; once(event: "request", listener: RequestListener): this; once( event: "upgrade", - listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, ): this; prependListener(event: string, listener: (...args: any[]) => void): this; prependListener(event: "close", listener: () => void): this; @@ -531,7 +538,7 @@ declare module "http" { prependListener(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this; prependListener( event: "connect", - listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, ): this; prependListener( event: "dropRequest", @@ -540,7 +547,7 @@ declare module "http" { prependListener(event: "request", listener: RequestListener): this; prependListener( event: "upgrade", - listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, ): this; prependOnceListener(event: string, listener: (...args: any[]) => void): this; prependOnceListener(event: "close", listener: () => void): this; @@ -552,7 +559,7 @@ declare module "http" { prependOnceListener(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this; prependOnceListener( event: "connect", - listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, ): this; prependOnceListener( event: "dropRequest", @@ -561,7 +568,7 @@ declare module "http" { prependOnceListener(event: "request", listener: RequestListener): this; prependOnceListener( event: "upgrade", - listener: (req: InstanceType, socket: stream.Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: stream.Duplex, head: NonSharedBuffer) => void, ): this; } /** @@ -1081,7 +1088,7 @@ declare module "http" { addListener(event: "abort", listener: () => void): this; addListener( event: "connect", - listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void, + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, ): this; addListener(event: "continue", listener: () => void): this; addListener(event: "information", listener: (info: InformationEvent) => void): this; @@ -1090,7 +1097,7 @@ declare module "http" { addListener(event: "timeout", listener: () => void): this; addListener( event: "upgrade", - listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void, + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, ): this; addListener(event: "close", listener: () => void): this; addListener(event: "drain", listener: () => void): this; @@ -1103,13 +1110,19 @@ declare module "http" { * @deprecated */ on(event: "abort", listener: () => void): this; - on(event: "connect", listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this; + on( + event: "connect", + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, + ): this; on(event: "continue", listener: () => void): this; on(event: "information", listener: (info: InformationEvent) => void): this; on(event: "response", listener: (response: IncomingMessage) => void): this; on(event: "socket", listener: (socket: Socket) => void): this; on(event: "timeout", listener: () => void): this; - on(event: "upgrade", listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this; + on( + event: "upgrade", + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, + ): this; on(event: "close", listener: () => void): this; on(event: "drain", listener: () => void): this; on(event: "error", listener: (err: Error) => void): this; @@ -1121,13 +1134,19 @@ declare module "http" { * @deprecated */ once(event: "abort", listener: () => void): this; - once(event: "connect", listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this; + once( + event: "connect", + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, + ): this; once(event: "continue", listener: () => void): this; once(event: "information", listener: (info: InformationEvent) => void): this; once(event: "response", listener: (response: IncomingMessage) => void): this; once(event: "socket", listener: (socket: Socket) => void): this; once(event: "timeout", listener: () => void): this; - once(event: "upgrade", listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this; + once( + event: "upgrade", + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, + ): this; once(event: "close", listener: () => void): this; once(event: "drain", listener: () => void): this; once(event: "error", listener: (err: Error) => void): this; @@ -1141,7 +1160,7 @@ declare module "http" { prependListener(event: "abort", listener: () => void): this; prependListener( event: "connect", - listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void, + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, ): this; prependListener(event: "continue", listener: () => void): this; prependListener(event: "information", listener: (info: InformationEvent) => void): this; @@ -1150,7 +1169,7 @@ declare module "http" { prependListener(event: "timeout", listener: () => void): this; prependListener( event: "upgrade", - listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void, + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, ): this; prependListener(event: "close", listener: () => void): this; prependListener(event: "drain", listener: () => void): this; @@ -1165,7 +1184,7 @@ declare module "http" { prependOnceListener(event: "abort", listener: () => void): this; prependOnceListener( event: "connect", - listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void, + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, ): this; prependOnceListener(event: "continue", listener: () => void): this; prependOnceListener(event: "information", listener: (info: InformationEvent) => void): this; @@ -1174,7 +1193,7 @@ declare module "http" { prependOnceListener(event: "timeout", listener: () => void): this; prependOnceListener( event: "upgrade", - listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void, + listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void, ): this; prependOnceListener(event: "close", listener: () => void): this; prependOnceListener(event: "drain", listener: () => void): this; diff --git a/types/node/v22/http2.d.ts b/types/node/v22/http2.d.ts index 52db4591656c82..0dcc1d90fc7ef8 100644 --- a/types/node/v22/http2.d.ts +++ b/types/node/v22/http2.d.ts @@ -9,6 +9,7 @@ * @see [source](https://github.com/nodejs/node/blob/v22.x/lib/http2.js) */ declare module "http2" { + import { NonSharedBuffer } from "node:buffer"; import EventEmitter = require("node:events"); import * as fs from "node:fs"; import * as net from "node:net"; @@ -196,7 +197,7 @@ declare module "http2" { sendTrailers(headers: OutgoingHttpHeaders): void; addListener(event: "aborted", listener: () => void): this; addListener(event: "close", listener: () => void): this; - addListener(event: "data", listener: (chunk: Buffer | string) => void): this; + addListener(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; addListener(event: "drain", listener: () => void): this; addListener(event: "end", listener: () => void): this; addListener(event: "error", listener: (err: Error) => void): this; @@ -211,7 +212,7 @@ declare module "http2" { addListener(event: string | symbol, listener: (...args: any[]) => void): this; emit(event: "aborted"): boolean; emit(event: "close"): boolean; - emit(event: "data", chunk: Buffer | string): boolean; + emit(event: "data", chunk: NonSharedBuffer | string): boolean; emit(event: "drain"): boolean; emit(event: "end"): boolean; emit(event: "error", err: Error): boolean; @@ -226,7 +227,7 @@ declare module "http2" { emit(event: string | symbol, ...args: any[]): boolean; on(event: "aborted", listener: () => void): this; on(event: "close", listener: () => void): this; - on(event: "data", listener: (chunk: Buffer | string) => void): this; + on(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; on(event: "drain", listener: () => void): this; on(event: "end", listener: () => void): this; on(event: "error", listener: (err: Error) => void): this; @@ -241,7 +242,7 @@ declare module "http2" { on(event: string | symbol, listener: (...args: any[]) => void): this; once(event: "aborted", listener: () => void): this; once(event: "close", listener: () => void): this; - once(event: "data", listener: (chunk: Buffer | string) => void): this; + once(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; once(event: "drain", listener: () => void): this; once(event: "end", listener: () => void): this; once(event: "error", listener: (err: Error) => void): this; @@ -256,7 +257,7 @@ declare module "http2" { once(event: string | symbol, listener: (...args: any[]) => void): this; prependListener(event: "aborted", listener: () => void): this; prependListener(event: "close", listener: () => void): this; - prependListener(event: "data", listener: (chunk: Buffer | string) => void): this; + prependListener(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; prependListener(event: "drain", listener: () => void): this; prependListener(event: "end", listener: () => void): this; prependListener(event: "error", listener: (err: Error) => void): this; @@ -271,7 +272,7 @@ declare module "http2" { prependListener(event: string | symbol, listener: (...args: any[]) => void): this; prependOnceListener(event: "aborted", listener: () => void): this; prependOnceListener(event: "close", listener: () => void): this; - prependOnceListener(event: "data", listener: (chunk: Buffer | string) => void): this; + prependOnceListener(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; prependOnceListener(event: "drain", listener: () => void): this; prependOnceListener(event: "end", listener: () => void): this; prependOnceListener(event: "error", listener: (err: Error) => void): this; @@ -790,10 +791,10 @@ declare module "http2" { * @since v8.9.3 * @param payload Optional ping payload. */ - ping(callback: (err: Error | null, duration: number, payload: Buffer) => void): boolean; + ping(callback: (err: Error | null, duration: number, payload: NonSharedBuffer) => void): boolean; ping( payload: NodeJS.ArrayBufferView, - callback: (err: Error | null, duration: number, payload: Buffer) => void, + callback: (err: Error | null, duration: number, payload: NonSharedBuffer) => void, ): boolean; /** * Calls `ref()` on this `Http2Session` instance's underlying `net.Socket`. @@ -855,7 +856,7 @@ declare module "http2" { ): this; addListener( event: "goaway", - listener: (errorCode: number, lastStreamID: number, opaqueData?: Buffer) => void, + listener: (errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer) => void, ): this; addListener(event: "localSettings", listener: (settings: Settings) => void): this; addListener(event: "ping", listener: () => void): this; @@ -865,7 +866,7 @@ declare module "http2" { emit(event: "close"): boolean; emit(event: "error", err: Error): boolean; emit(event: "frameError", frameType: number, errorCode: number, streamID: number): boolean; - emit(event: "goaway", errorCode: number, lastStreamID: number, opaqueData?: Buffer): boolean; + emit(event: "goaway", errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer): boolean; emit(event: "localSettings", settings: Settings): boolean; emit(event: "ping"): boolean; emit(event: "remoteSettings", settings: Settings): boolean; @@ -874,7 +875,10 @@ declare module "http2" { on(event: "close", listener: () => void): this; on(event: "error", listener: (err: Error) => void): this; on(event: "frameError", listener: (frameType: number, errorCode: number, streamID: number) => void): this; - on(event: "goaway", listener: (errorCode: number, lastStreamID: number, opaqueData?: Buffer) => void): this; + on( + event: "goaway", + listener: (errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer) => void, + ): this; on(event: "localSettings", listener: (settings: Settings) => void): this; on(event: "ping", listener: () => void): this; on(event: "remoteSettings", listener: (settings: Settings) => void): this; @@ -883,7 +887,10 @@ declare module "http2" { once(event: "close", listener: () => void): this; once(event: "error", listener: (err: Error) => void): this; once(event: "frameError", listener: (frameType: number, errorCode: number, streamID: number) => void): this; - once(event: "goaway", listener: (errorCode: number, lastStreamID: number, opaqueData?: Buffer) => void): this; + once( + event: "goaway", + listener: (errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer) => void, + ): this; once(event: "localSettings", listener: (settings: Settings) => void): this; once(event: "ping", listener: () => void): this; once(event: "remoteSettings", listener: (settings: Settings) => void): this; @@ -897,7 +904,7 @@ declare module "http2" { ): this; prependListener( event: "goaway", - listener: (errorCode: number, lastStreamID: number, opaqueData?: Buffer) => void, + listener: (errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer) => void, ): this; prependListener(event: "localSettings", listener: (settings: Settings) => void): this; prependListener(event: "ping", listener: () => void): this; @@ -912,7 +919,7 @@ declare module "http2" { ): this; prependOnceListener( event: "goaway", - listener: (errorCode: number, lastStreamID: number, opaqueData?: Buffer) => void, + listener: (errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer) => void, ): this; prependOnceListener(event: "localSettings", listener: (settings: Settings) => void): this; prependOnceListener(event: "ping", listener: () => void): this; @@ -1804,45 +1811,45 @@ declare module "http2" { * @since v8.4.0 */ setTimeout(msecs: number, callback?: () => void): void; - read(size?: number): Buffer | string | null; + read(size?: number): NonSharedBuffer | string | null; addListener(event: "aborted", listener: (hadError: boolean, code: number) => void): this; addListener(event: "close", listener: () => void): this; - addListener(event: "data", listener: (chunk: Buffer | string) => void): this; + addListener(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; addListener(event: "end", listener: () => void): this; addListener(event: "readable", listener: () => void): this; addListener(event: "error", listener: (err: Error) => void): this; addListener(event: string | symbol, listener: (...args: any[]) => void): this; emit(event: "aborted", hadError: boolean, code: number): boolean; emit(event: "close"): boolean; - emit(event: "data", chunk: Buffer | string): boolean; + emit(event: "data", chunk: NonSharedBuffer | string): boolean; emit(event: "end"): boolean; emit(event: "readable"): boolean; emit(event: "error", err: Error): boolean; emit(event: string | symbol, ...args: any[]): boolean; on(event: "aborted", listener: (hadError: boolean, code: number) => void): this; on(event: "close", listener: () => void): this; - on(event: "data", listener: (chunk: Buffer | string) => void): this; + on(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; on(event: "end", listener: () => void): this; on(event: "readable", listener: () => void): this; on(event: "error", listener: (err: Error) => void): this; on(event: string | symbol, listener: (...args: any[]) => void): this; once(event: "aborted", listener: (hadError: boolean, code: number) => void): this; once(event: "close", listener: () => void): this; - once(event: "data", listener: (chunk: Buffer | string) => void): this; + once(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; once(event: "end", listener: () => void): this; once(event: "readable", listener: () => void): this; once(event: "error", listener: (err: Error) => void): this; once(event: string | symbol, listener: (...args: any[]) => void): this; prependListener(event: "aborted", listener: (hadError: boolean, code: number) => void): this; prependListener(event: "close", listener: () => void): this; - prependListener(event: "data", listener: (chunk: Buffer | string) => void): this; + prependListener(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; prependListener(event: "end", listener: () => void): this; prependListener(event: "readable", listener: () => void): this; prependListener(event: "error", listener: (err: Error) => void): this; prependListener(event: string | symbol, listener: (...args: any[]) => void): this; prependOnceListener(event: "aborted", listener: (hadError: boolean, code: number) => void): this; prependOnceListener(event: "close", listener: () => void): this; - prependOnceListener(event: "data", listener: (chunk: Buffer | string) => void): this; + prependOnceListener(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this; prependOnceListener(event: "end", listener: () => void): this; prependOnceListener(event: "readable", listener: () => void): this; prependOnceListener(event: "error", listener: (err: Error) => void): this; @@ -2502,7 +2509,7 @@ declare module "http2" { * ``` * @since v8.4.0 */ - export function getPackedSettings(settings: Settings): Buffer; + export function getPackedSettings(settings: Settings): NonSharedBuffer; /** * Returns a `HTTP/2 Settings Object` containing the deserialized settings from * the given `Buffer` as generated by `http2.getPackedSettings()`. diff --git a/types/node/v22/https.d.ts b/types/node/v22/https.d.ts index fc550e09faf2ab..e0502558e4097d 100644 --- a/types/node/v22/https.d.ts +++ b/types/node/v22/https.d.ts @@ -4,6 +4,7 @@ * @see [source](https://github.com/nodejs/node/blob/v22.x/lib/https.js) */ declare module "https" { + import { NonSharedBuffer } from "node:buffer"; import { Duplex } from "node:stream"; import * as tls from "node:tls"; import * as http from "node:http"; @@ -63,22 +64,25 @@ declare module "https" { */ closeIdleConnections(): void; addListener(event: string, listener: (...args: any[]) => void): this; - addListener(event: "keylog", listener: (line: Buffer, tlsSocket: tls.TLSSocket) => void): this; + addListener(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: tls.TLSSocket) => void): this; addListener( event: "newSession", - listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void, + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, ): this; addListener( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; addListener( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; addListener(event: "secureConnection", listener: (tlsSocket: tls.TLSSocket) => void): this; addListener(event: "tlsClientError", listener: (err: Error, tlsSocket: tls.TLSSocket) => void): this; @@ -91,28 +95,32 @@ declare module "https" { addListener(event: "clientError", listener: (err: Error, socket: Duplex) => void): this; addListener( event: "connect", - listener: (req: InstanceType, socket: Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, ): this; addListener(event: "request", listener: http.RequestListener): this; addListener( event: "upgrade", - listener: (req: InstanceType, socket: Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, ): this; emit(event: string, ...args: any[]): boolean; - emit(event: "keylog", line: Buffer, tlsSocket: tls.TLSSocket): boolean; + emit(event: "keylog", line: NonSharedBuffer, tlsSocket: tls.TLSSocket): boolean; emit( event: "newSession", - sessionId: Buffer, - sessionData: Buffer, - callback: (err: Error, resp: Buffer) => void, + sessionId: NonSharedBuffer, + sessionData: NonSharedBuffer, + callback: () => void, ): boolean; emit( event: "OCSPRequest", - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, + ): boolean; + emit( + event: "resumeSession", + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, ): boolean; - emit(event: "resumeSession", sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void): boolean; emit(event: "secureConnection", tlsSocket: tls.TLSSocket): boolean; emit(event: "tlsClientError", err: Error, tlsSocket: tls.TLSSocket): boolean; emit(event: "close"): boolean; @@ -130,30 +138,33 @@ declare module "https" { res: InstanceType, ): boolean; emit(event: "clientError", err: Error, socket: Duplex): boolean; - emit(event: "connect", req: InstanceType, socket: Duplex, head: Buffer): boolean; + emit(event: "connect", req: InstanceType, socket: Duplex, head: NonSharedBuffer): boolean; emit( event: "request", req: InstanceType, res: InstanceType, ): boolean; - emit(event: "upgrade", req: InstanceType, socket: Duplex, head: Buffer): boolean; + emit(event: "upgrade", req: InstanceType, socket: Duplex, head: NonSharedBuffer): boolean; on(event: string, listener: (...args: any[]) => void): this; - on(event: "keylog", listener: (line: Buffer, tlsSocket: tls.TLSSocket) => void): this; + on(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: tls.TLSSocket) => void): this; on( event: "newSession", - listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void, + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, ): this; on( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; on( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; on(event: "secureConnection", listener: (tlsSocket: tls.TLSSocket) => void): this; on(event: "tlsClientError", listener: (err: Error, tlsSocket: tls.TLSSocket) => void): this; @@ -164,26 +175,35 @@ declare module "https" { on(event: "checkContinue", listener: http.RequestListener): this; on(event: "checkExpectation", listener: http.RequestListener): this; on(event: "clientError", listener: (err: Error, socket: Duplex) => void): this; - on(event: "connect", listener: (req: InstanceType, socket: Duplex, head: Buffer) => void): this; + on( + event: "connect", + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, + ): this; on(event: "request", listener: http.RequestListener): this; - on(event: "upgrade", listener: (req: InstanceType, socket: Duplex, head: Buffer) => void): this; + on( + event: "upgrade", + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, + ): this; once(event: string, listener: (...args: any[]) => void): this; - once(event: "keylog", listener: (line: Buffer, tlsSocket: tls.TLSSocket) => void): this; + once(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: tls.TLSSocket) => void): this; once( event: "newSession", - listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void, + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, ): this; once( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; once( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; once(event: "secureConnection", listener: (tlsSocket: tls.TLSSocket) => void): this; once(event: "tlsClientError", listener: (err: Error, tlsSocket: tls.TLSSocket) => void): this; @@ -194,26 +214,35 @@ declare module "https" { once(event: "checkContinue", listener: http.RequestListener): this; once(event: "checkExpectation", listener: http.RequestListener): this; once(event: "clientError", listener: (err: Error, socket: Duplex) => void): this; - once(event: "connect", listener: (req: InstanceType, socket: Duplex, head: Buffer) => void): this; + once( + event: "connect", + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, + ): this; once(event: "request", listener: http.RequestListener): this; - once(event: "upgrade", listener: (req: InstanceType, socket: Duplex, head: Buffer) => void): this; + once( + event: "upgrade", + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, + ): this; prependListener(event: string, listener: (...args: any[]) => void): this; - prependListener(event: "keylog", listener: (line: Buffer, tlsSocket: tls.TLSSocket) => void): this; + prependListener(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: tls.TLSSocket) => void): this; prependListener( event: "newSession", - listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void, + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, ): this; prependListener( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; prependListener( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; prependListener(event: "secureConnection", listener: (tlsSocket: tls.TLSSocket) => void): this; prependListener(event: "tlsClientError", listener: (err: Error, tlsSocket: tls.TLSSocket) => void): this; @@ -226,30 +255,33 @@ declare module "https" { prependListener(event: "clientError", listener: (err: Error, socket: Duplex) => void): this; prependListener( event: "connect", - listener: (req: InstanceType, socket: Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, ): this; prependListener(event: "request", listener: http.RequestListener): this; prependListener( event: "upgrade", - listener: (req: InstanceType, socket: Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, ): this; prependOnceListener(event: string, listener: (...args: any[]) => void): this; - prependOnceListener(event: "keylog", listener: (line: Buffer, tlsSocket: tls.TLSSocket) => void): this; + prependOnceListener(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: tls.TLSSocket) => void): this; prependOnceListener( event: "newSession", - listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void, + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, ): this; prependOnceListener( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; prependOnceListener( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; prependOnceListener(event: "secureConnection", listener: (tlsSocket: tls.TLSSocket) => void): this; prependOnceListener(event: "tlsClientError", listener: (err: Error, tlsSocket: tls.TLSSocket) => void): this; @@ -262,12 +294,12 @@ declare module "https" { prependOnceListener(event: "clientError", listener: (err: Error, socket: Duplex) => void): this; prependOnceListener( event: "connect", - listener: (req: InstanceType, socket: Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, ): this; prependOnceListener(event: "request", listener: http.RequestListener): this; prependOnceListener( event: "upgrade", - listener: (req: InstanceType, socket: Duplex, head: Buffer) => void, + listener: (req: InstanceType, socket: Duplex, head: NonSharedBuffer) => void, ): this; } /** diff --git a/types/node/v22/net.d.ts b/types/node/v22/net.d.ts index 01340a8ef7a07d..4901cbf6bbf116 100644 --- a/types/node/v22/net.d.ts +++ b/types/node/v22/net.d.ts @@ -13,6 +13,7 @@ * @see [source](https://github.com/nodejs/node/blob/v22.x/lib/net.js) */ declare module "net" { + import { NonSharedBuffer } from "node:buffer"; import * as stream from "node:stream"; import { Abortable, EventEmitter } from "node:events"; import * as dns from "node:dns"; @@ -383,7 +384,7 @@ declare module "net" { event: "connectionAttemptTimeout", listener: (ip: string, port: number, family: number) => void, ): this; - addListener(event: "data", listener: (data: Buffer) => void): this; + addListener(event: "data", listener: (data: NonSharedBuffer) => void): this; addListener(event: "drain", listener: () => void): this; addListener(event: "end", listener: () => void): this; addListener(event: "error", listener: (err: Error) => void): this; @@ -399,7 +400,7 @@ declare module "net" { emit(event: "connectionAttempt", ip: string, port: number, family: number): boolean; emit(event: "connectionAttemptFailed", ip: string, port: number, family: number, error: Error): boolean; emit(event: "connectionAttemptTimeout", ip: string, port: number, family: number): boolean; - emit(event: "data", data: Buffer): boolean; + emit(event: "data", data: NonSharedBuffer): boolean; emit(event: "drain"): boolean; emit(event: "end"): boolean; emit(event: "error", err: Error): boolean; @@ -415,7 +416,7 @@ declare module "net" { listener: (ip: string, port: number, family: number, error: Error) => void, ): this; on(event: "connectionAttemptTimeout", listener: (ip: string, port: number, family: number) => void): this; - on(event: "data", listener: (data: Buffer) => void): this; + on(event: "data", listener: (data: NonSharedBuffer) => void): this; on(event: "drain", listener: () => void): this; on(event: "end", listener: () => void): this; on(event: "error", listener: (err: Error) => void): this; @@ -434,7 +435,7 @@ declare module "net" { ): this; once(event: "connectionAttemptTimeout", listener: (ip: string, port: number, family: number) => void): this; once(event: "connect", listener: () => void): this; - once(event: "data", listener: (data: Buffer) => void): this; + once(event: "data", listener: (data: NonSharedBuffer) => void): this; once(event: "drain", listener: () => void): this; once(event: "end", listener: () => void): this; once(event: "error", listener: (err: Error) => void): this; @@ -456,7 +457,7 @@ declare module "net" { event: "connectionAttemptTimeout", listener: (ip: string, port: number, family: number) => void, ): this; - prependListener(event: "data", listener: (data: Buffer) => void): this; + prependListener(event: "data", listener: (data: NonSharedBuffer) => void): this; prependListener(event: "drain", listener: () => void): this; prependListener(event: "end", listener: () => void): this; prependListener(event: "error", listener: (err: Error) => void): this; @@ -481,7 +482,7 @@ declare module "net" { event: "connectionAttemptTimeout", listener: (ip: string, port: number, family: number) => void, ): this; - prependOnceListener(event: "data", listener: (data: Buffer) => void): this; + prependOnceListener(event: "data", listener: (data: NonSharedBuffer) => void): this; prependOnceListener(event: "drain", listener: () => void): this; prependOnceListener(event: "end", listener: () => void): this; prependOnceListener(event: "error", listener: (err: Error) => void): this; diff --git a/types/node/v22/os.d.ts b/types/node/v22/os.d.ts index 5e726c0a2ce120..a40bd77b510061 100644 --- a/types/node/v22/os.d.ts +++ b/types/node/v22/os.d.ts @@ -8,6 +8,7 @@ * @see [source](https://github.com/nodejs/node/blob/v22.x/lib/os.js) */ declare module "os" { + import { NonSharedBuffer } from "buffer"; interface CpuInfo { model: string; speed: number; @@ -253,8 +254,8 @@ declare module "os" { * Throws a [`SystemError`](https://nodejs.org/docs/latest-v22.x/api/errors.html#class-systemerror) if a user has no `username` or `homedir`. * @since v6.0.0 */ - function userInfo(options: UserInfoOptionsWithBufferEncoding): UserInfo; function userInfo(options?: UserInfoOptionsWithStringEncoding): UserInfo; + function userInfo(options: UserInfoOptionsWithBufferEncoding): UserInfo; function userInfo(options: UserInfoOptions): UserInfo; type SignalConstants = { [key in NodeJS.Signals]: number; diff --git a/types/node/v22/process.d.ts b/types/node/v22/process.d.ts index 827bbd205cb534..6ce0f3c7da444c 100644 --- a/types/node/v22/process.d.ts +++ b/types/node/v22/process.d.ts @@ -1,5 +1,6 @@ declare module "process" { import { Control, MessageOptions } from "node:child_process"; + import { PathLike } from "node:fs"; import * as tty from "node:tty"; import { Worker } from "node:worker_threads"; @@ -1468,7 +1469,7 @@ declare module "process" { * @since v20.12.0 * @param path The path to the .env file */ - loadEnvFile(path?: string | URL | Buffer): void; + loadEnvFile(path?: PathLike): void; /** * The `process.pid` property returns the PID of the process. * diff --git a/types/node/v22/sqlite.d.ts b/types/node/v22/sqlite.d.ts index a1dcfec53fe1d4..e5ca642e422a94 100644 --- a/types/node/v22/sqlite.d.ts +++ b/types/node/v22/sqlite.d.ts @@ -43,10 +43,9 @@ * @see [source](https://github.com/nodejs/node/blob/v22.x/lib/sqlite.js) */ declare module "node:sqlite" { + import { PathLike } from "node:fs"; type SQLInputValue = null | number | bigint | string | NodeJS.ArrayBufferView; - type SQLOutputValue = null | number | bigint | string | Uint8Array; - /** @deprecated Use `SQLInputValue` or `SQLOutputValue` instead. */ - type SupportedValueType = SQLOutputValue; + type SQLOutputValue = null | number | bigint | string | NodeJS.NonSharedUint8Array; interface DatabaseSyncOptions { /** * If `true`, the database is opened by the constructor. When @@ -240,7 +239,7 @@ declare module "node:sqlite" { * To use an in-memory database, the path should be the special name `':memory:'`. * @param options Configuration options for the database connection. */ - constructor(path: string | Buffer | URL, options?: DatabaseSyncOptions); + constructor(path: PathLike, options?: DatabaseSyncOptions); /** * Registers a new aggregate function with the SQLite database. This method is a wrapper around * [`sqlite3_create_window_function()`](https://www.sqlite.org/c3ref/create_function.html). @@ -411,7 +410,7 @@ declare module "node:sqlite" { * @returns Binary changeset that can be applied to other databases. * @since v22.12.0 */ - changeset(): Uint8Array; + changeset(): NodeJS.NonSharedUint8Array; /** * Similar to the method above, but generates a more compact patchset. See * [Changesets and Patchsets](https://www.sqlite.org/sessionintro.html#changesets_and_patchsets) @@ -421,7 +420,7 @@ declare module "node:sqlite" { * @returns Binary patchset that can be applied to other databases. * @since v22.12.0 */ - patchset(): Uint8Array; + patchset(): NodeJS.NonSharedUint8Array; /** * Closes the session. An exception is thrown if the database or the session is not open. This method is a * wrapper around @@ -671,7 +670,7 @@ declare module "node:sqlite" { * following properties are supported: * @returns A promise that resolves when the backup is completed and rejects if an error occurs. */ - function backup(sourceDb: DatabaseSync, path: string | Buffer | URL, options?: BackupOptions): Promise; + function backup(sourceDb: DatabaseSync, path: PathLike, options?: BackupOptions): Promise; /** * @since v22.13.0 */ diff --git a/types/node/v22/stream/consumers.d.ts b/types/node/v22/stream/consumers.d.ts index 746d6e508266ac..05db0257d276a5 100644 --- a/types/node/v22/stream/consumers.d.ts +++ b/types/node/v22/stream/consumers.d.ts @@ -4,7 +4,7 @@ * @since v16.7.0 */ declare module "stream/consumers" { - import { Blob as NodeBlob } from "node:buffer"; + import { Blob as NodeBlob, NonSharedBuffer } from "node:buffer"; import { ReadableStream as WebReadableStream } from "node:stream/web"; /** * @since v16.7.0 @@ -20,7 +20,7 @@ declare module "stream/consumers" { * @since v16.7.0 * @returns Fulfills with a `Buffer` containing the full contents of the stream. */ - function buffer(stream: WebReadableStream | NodeJS.ReadableStream | AsyncIterable): Promise; + function buffer(stream: WebReadableStream | NodeJS.ReadableStream | AsyncIterable): Promise; /** * @since v16.7.0 * @returns Fulfills with the contents of the stream parsed as a diff --git a/types/node/v22/string_decoder.d.ts b/types/node/v22/string_decoder.d.ts index 350aace2bb3871..d8b9be862fcc0d 100644 --- a/types/node/v22/string_decoder.d.ts +++ b/types/node/v22/string_decoder.d.ts @@ -48,7 +48,7 @@ declare module "string_decoder" { * @since v0.1.99 * @param buffer The bytes to decode. */ - write(buffer: string | Buffer | NodeJS.ArrayBufferView): string; + write(buffer: string | NodeJS.ArrayBufferView): string; /** * Returns any remaining input stored in the internal buffer as a string. Bytes * representing incomplete UTF-8 and UTF-16 characters will be replaced with @@ -59,7 +59,7 @@ declare module "string_decoder" { * @since v0.9.3 * @param buffer The bytes to decode. */ - end(buffer?: string | Buffer | NodeJS.ArrayBufferView): string; + end(buffer?: string | NodeJS.ArrayBufferView): string; } } declare module "node:string_decoder" { diff --git a/types/node/v22/test/buffer.ts b/types/node/v22/test/buffer.ts index 4faf990e92db20..f2c19f6e0fa409 100644 --- a/types/node/v22/test/buffer.ts +++ b/types/node/v22/test/buffer.ts @@ -345,11 +345,11 @@ result = b.write("asd", 123, 123, "hex"); // Buffer module, transcode function { - transcode(Buffer.from("€"), "utf8", "ascii"); // $ExpectType Buffer || Buffer + transcode(Buffer.from("€"), "utf8", "ascii"); // $ExpectType NonSharedBuffer const source: TranscodeEncoding = "utf8"; const target: TranscodeEncoding = "ascii"; - transcode(Buffer.from("€"), source, target); // $ExpectType Buffer || Buffer + transcode(Buffer.from("€"), source, target); // $ExpectType NonSharedBuffer } { diff --git a/types/node/v22/test/child_process.ts b/types/node/v22/test/child_process.ts index 4b480362aacce3..1f83f8b31e402f 100644 --- a/types/node/v22/test/child_process.ts +++ b/types/node/v22/test/child_process.ts @@ -25,15 +25,15 @@ import { promisify } from "node:util"; childProcess.spawnSync("echo test", { encoding: "buffer" }); childProcess.spawnSync("echo test", { cwd: new URL("file://aaaaaaaa") }); - childProcess.spawnSync("echo test").output; // $ExpectType (Buffer | null)[] || (Buffer | null)[] - childProcess.spawnSync("echo test", {}).output; // $ExpectType (Buffer | null)[] || (Buffer | null)[] - childProcess.spawnSync("echo test", { encoding: "buffer" }).output; // $ExpectType (Buffer | null)[] || (Buffer | null)[] + childProcess.spawnSync("echo test").output; // $ExpectType (NonSharedBuffer | null)[] + childProcess.spawnSync("echo test", {}).output; // $ExpectType (NonSharedBuffer | null)[] + childProcess.spawnSync("echo test", { encoding: "buffer" }).output; // $ExpectType (NonSharedBuffer | null)[] childProcess.spawnSync("echo test", { encoding: "utf-8" }).output; // $ExpectType (string | null)[] - childProcess.spawnSync("echo", ["test"]).output; // $ExpectType (Buffer | null)[] || (Buffer | null)[] - childProcess.spawnSync("echo test", ["test"], {}).output; // $ExpectType (Buffer | null)[] || (Buffer | null)[] - childProcess.spawnSync("echo test", ["test"], { encoding: "buffer" }).output; // $ExpectType (Buffer | null)[] || (Buffer | null)[] + childProcess.spawnSync("echo", ["test"]).output; // $ExpectType (NonSharedBuffer | null)[] + childProcess.spawnSync("echo test", ["test"], {}).output; // $ExpectType (NonSharedBuffer | null)[] + childProcess.spawnSync("echo test", ["test"], { encoding: "buffer" }).output; // $ExpectType (NonSharedBuffer | null)[] childProcess.spawnSync("echo test", ["test"], { encoding: "utf-8" }).output; // $ExpectType (string | null)[] - ((opts?: childProcess.SpawnSyncOptions) => childProcess.spawnSync("echo test", opts))().output; // $ExpectType (string | Buffer | null)[] || (string | Buffer | null)[] + ((opts?: childProcess.SpawnSyncOptions) => childProcess.spawnSync("echo test", opts))().output; // $ExpectType (string | NonSharedBuffer | null)[] } { @@ -117,13 +117,13 @@ import { promisify } from "node:util"; (error, stdout, stderr) => { // $ExpectType ExecException | null error; - // $ExpectType Buffer + // $ExpectType NonSharedBuffer stdout; - // $ExpectType Buffer + // $ExpectType NonSharedBuffer stderr; }, ); - // $ExpectType PromiseWithChild<{ stdout: Buffer; stderr: Buffer; }> + // $ExpectType PromiseWithChild<{ stdout: NonSharedBuffer; stderr: NonSharedBuffer; }> promisifiedExec(cmd, { encoding: boolFlag ? "buffer" : null }); // with known encoding @@ -151,13 +151,13 @@ import { promisify } from "node:util"; (error, stdout, stderr) => { // $ExpectType ExecException | null error; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stdout; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stderr; }, ); - // $ExpectType PromiseWithChild<{ stdout: string | Buffer; stderr: string | Buffer; }> + // $ExpectType PromiseWithChild<{ stdout: string | NonSharedBuffer; stderr: string | NonSharedBuffer; }> promisifiedExec(cmd, { encoding: "unknown" }); // with nullish encoding @@ -168,22 +168,22 @@ import { promisify } from "node:util"; (error, stdout, stderr) => { // $ExpectType ExecException | null error; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stdout; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stderr; }, ); - // $ExpectType PromiseWithChild<{ stdout: string | Buffer; stderr: string | Buffer; }> + // $ExpectType PromiseWithChild<{ stdout: string | NonSharedBuffer; stderr: string | NonSharedBuffer; }> promisifiedExec(cmd, boolFlag ? { encoding: "unknown" } : null); } { - childProcess.execSync("echo test"); // $ExpectType Buffer || Buffer - childProcess.execSync("echo test", {}); // $ExpectType Buffer || Buffer - childProcess.execSync("echo test", { encoding: "buffer" }); // $ExpectType Buffer || Buffer + childProcess.execSync("echo test"); // $ExpectType NonSharedBuffer + childProcess.execSync("echo test", {}); // $ExpectType NonSharedBuffer + childProcess.execSync("echo test", { encoding: "buffer" }); // $ExpectType NonSharedBuffer childProcess.execSync("echo test", { encoding: "utf-8" }); // $ExpectType string - ((opts?: childProcess.ExecSyncOptions) => childProcess.execSync("echo test", opts))(); // $ExpectType string | Buffer || string | Buffer + ((opts?: childProcess.ExecSyncOptions) => childProcess.execSync("echo test", opts))(); // $ExpectType string | NonSharedBuffer childProcess.execSync("git status", { // $ExpectType string cwd: "test", input: "test", @@ -346,13 +346,13 @@ import { promisify } from "node:util"; (error, stdout, stderr) => { // $ExpectType ExecFileException | null error; - // $ExpectType Buffer + // $ExpectType NonSharedBuffer stdout; - // $ExpectType Buffer + // $ExpectType NonSharedBuffer stderr; }, ); - // $ExpectType PromiseWithChild<{ stdout: Buffer; stderr: Buffer; }> + // $ExpectType PromiseWithChild<{ stdout: NonSharedBuffer; stderr: NonSharedBuffer; }> promisifiedExecFile(cmd, { encoding: boolFlag ? "buffer" : null }); // $ExpectType ChildProcess childProcess.execFile( @@ -362,13 +362,13 @@ import { promisify } from "node:util"; (error, stdout, stderr) => { // $ExpectType ExecFileException | null error; - // $ExpectType Buffer + // $ExpectType NonSharedBuffer stdout; - // $ExpectType Buffer + // $ExpectType NonSharedBuffer stderr; }, ); - // $ExpectType PromiseWithChild<{ stdout: Buffer; stderr: Buffer; }> + // $ExpectType PromiseWithChild<{ stdout: NonSharedBuffer; stderr: NonSharedBuffer; }> promisifiedExecFile(cmd, args, { encoding: boolFlag ? "buffer" : null }); // with known encoding @@ -413,13 +413,13 @@ import { promisify } from "node:util"; (error, stdout, stderr) => { // $ExpectType ExecFileException | null error; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stdout; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stderr; }, ); - // $ExpectType PromiseWithChild<{ stdout: string | Buffer; stderr: string | Buffer; }> + // $ExpectType PromiseWithChild<{ stdout: string | NonSharedBuffer; stderr: string | NonSharedBuffer; }> promisifiedExecFile(cmd, { encoding: "unknown" }); // $ExpectType ChildProcess childProcess.execFile( @@ -429,13 +429,13 @@ import { promisify } from "node:util"; (error, stdout, stderr) => { // $ExpectType ExecFileException | null error; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stdout; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stderr; }, ); - // $ExpectType PromiseWithChild<{ stdout: string | Buffer; stderr: string | Buffer; }> + // $ExpectType PromiseWithChild<{ stdout: string | NonSharedBuffer; stderr: string | NonSharedBuffer; }> promisifiedExecFile(cmd, args, { encoding: "unknown" }); // with nullish encoding @@ -446,13 +446,13 @@ import { promisify } from "node:util"; (error, stdout, stderr) => { // $ExpectType ExecFileException | null error; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stdout; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stderr; }, ); - // $ExpectType PromiseWithChild<{ stdout: string | Buffer; stderr: string | Buffer; }> + // $ExpectType PromiseWithChild<{ stdout: string | NonSharedBuffer; stderr: string | NonSharedBuffer; }> promisifiedExecFile(cmd, boolFlag ? { encoding: "unknown" } : null); // $ExpectType ChildProcess childProcess.execFile( @@ -462,13 +462,13 @@ import { promisify } from "node:util"; (error, stdout, stderr) => { // $ExpectType ExecFileException | null error; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stdout; - // $ExpectType string | Buffer + // $ExpectType string | NonSharedBuffer stderr; }, ); - // $ExpectType PromiseWithChild<{ stdout: string | Buffer; stderr: string | Buffer; }> + // $ExpectType PromiseWithChild<{ stdout: string | NonSharedBuffer; stderr: string | NonSharedBuffer; }> promisifiedExecFile(cmd, args, boolFlag ? { encoding: "unknown" } : null); } @@ -481,15 +481,15 @@ import { promisify } from "node:util"; childProcess.execFileSync("echo test", { input: new Uint8Array([]) }); childProcess.execFileSync("echo test", { input: new DataView(new ArrayBuffer(1)) }); - childProcess.execFileSync("echo test"); // $ExpectType Buffer || Buffer - childProcess.execFileSync("echo test", {}); // $ExpectType Buffer || Buffer - childProcess.execFileSync("echo test", { encoding: "buffer" }); // $ExpectType Buffer || Buffer + childProcess.execFileSync("echo test"); // $ExpectType NonSharedBuffer + childProcess.execFileSync("echo test", {}); // $ExpectType NonSharedBuffer + childProcess.execFileSync("echo test", { encoding: "buffer" }); // $ExpectType NonSharedBuffer childProcess.execFileSync("echo test", { encoding: "utf8" }); // $ExpectType string - childProcess.execFileSync("echo test", ["test"]); // $ExpectType Buffer || Buffer - childProcess.execFileSync("echo test", ["test"], {}); // $ExpectType Buffer || Buffer - childProcess.execFileSync("echo test", ["test"], { encoding: "buffer" }); // $ExpectType Buffer || Buffer + childProcess.execFileSync("echo test", ["test"]); // $ExpectType NonSharedBuffer + childProcess.execFileSync("echo test", ["test"], {}); // $ExpectType NonSharedBuffer + childProcess.execFileSync("echo test", ["test"], { encoding: "buffer" }); // $ExpectType NonSharedBuffer childProcess.execFileSync("echo test", ["test"], { encoding: "utf8" }); // $ExpectType string - ((opts?: childProcess.ExecFileSyncOptions) => childProcess.execFileSync("echo test", ["args"], opts))(); // $ExpectType string | Buffer || string | Buffer + ((opts?: childProcess.ExecFileSyncOptions) => childProcess.execFileSync("echo test", ["args"], opts))(); // $ExpectType string | NonSharedBuffer } { diff --git a/types/node/v22/test/crypto.ts b/types/node/v22/test/crypto.ts index 9d251ab21cb13e..6272d87c6e7658 100644 --- a/types/node/v22/test/crypto.ts +++ b/types/node/v22/test/crypto.ts @@ -189,7 +189,7 @@ import { promisify } from "node:util"; const cipher = crypto.createCipheriv("aes-192-cbc", key, nonce); const plaintext = "Hello world"; - // $ExpectType Buffer || Buffer + // $ExpectType NonSharedBuffer const cipherBuf = cipher.update(plaintext, "utf8"); cipher.final(); @@ -206,12 +206,12 @@ import { promisify } from "node:util"; const cipher = crypto.createCipheriv("aes-192-cbc", key, nonce); const plaintext = "Hello world"; - // $ExpectType Buffer || Buffer + // $ExpectType NonSharedBuffer const cipherBuf = cipher.update(plaintext, "utf8"); cipher.final(); const decipher = crypto.createDecipheriv("aes-192-cbc", key, nonce); - // $ExpectType Buffer || Buffer + // $ExpectType NonSharedBuffer const receivedPlaintext = decipher.update(cipherBuf); decipher.final(); } @@ -231,7 +231,7 @@ import { promisify } from "node:util"; }, }); cipher = cipher.setAAD(Buffer.from([]), { plaintextLength: 0 }); - // $ExpectType Buffer + // $ExpectType NonSharedBuffer cipher.getAuthTag(); } @@ -248,7 +248,7 @@ import { promisify } from "node:util"; }, }); cipher = cipher.setAAD(Buffer.from([]), { plaintextLength: 0 }); - // $ExpectType Buffer + // $ExpectType NonSharedBuffer cipher.getAuthTag(); } @@ -264,7 +264,7 @@ import { promisify } from "node:util"; }, }); cipher = cipher.setAAD(Buffer.from([]), { plaintextLength: 0 }); - // $ExpectType Buffer + // $ExpectType NonSharedBuffer cipher.getAuthTag(); } @@ -281,7 +281,7 @@ import { promisify } from "node:util"; }, }); cipher = cipher.setAAD(Buffer.from([]), { plaintextLength: 0 }); - // $ExpectType Buffer + // $ExpectType NonSharedBuffer cipher.getAuthTag(); } @@ -1421,7 +1421,7 @@ import { promisify } from "node:util"; cert.issuerCertificate; // $ExpectType X509Certificate | undefined cert.keyUsage; // $ExpectType string[] cert.publicKey; // $ExpectType KeyObject - cert.raw; // $ExpectType Buffer || Buffer + cert.raw; // $ExpectType NonSharedBuffer cert.serialNumber; // $ExpectType string cert.subject; // $ExpectType string cert.subjectAltName; // $ExpectType string | undefined @@ -1600,7 +1600,7 @@ import { promisify } from "node:util"; alice.generateKeys(); - let alicePublicKey = alice.getPublicKey(); // $ExpectType Buffer || Buffer + let alicePublicKey = alice.getPublicKey(); // $ExpectType NonSharedBuffer alicePublicKey = alice.getPublicKey(null); alicePublicKey = alice.getPublicKey(null, "compressed"); alicePublicKey = alice.getPublicKey(undefined, "hybrid"); @@ -1608,7 +1608,7 @@ import { promisify } from "node:util"; let bobPublicKey = bob.getPublicKey("hex"); // $ExpectType string bobPublicKey = bob.getPublicKey("hex", "compressed"); - let aliceSecret = alice.computeSecret(bobPublicKey, "hex"); // $ExpectType Buffer || Buffer + let aliceSecret = alice.computeSecret(bobPublicKey, "hex"); // $ExpectType NonSharedBuffer aliceSecret = alice.computeSecret(Buffer.from(bobPublicKey, "hex")); let bobSecret = bob.computeSecret(alicePublicKey, "hex"); // $ExpectType string diff --git a/types/node/v22/test/dgram.ts b/types/node/v22/test/dgram.ts index 4b90f9a82dc86b..41cb9c02ae3016 100644 --- a/types/node/v22/test/dgram.ts +++ b/types/node/v22/test/dgram.ts @@ -140,7 +140,7 @@ sock = dgram.createSocket({ lookup: dns.lookup, }); sock = dgram.createSocket("udp6", (msg, rinfo) => { - msg; // $ExpectType Buffer || Buffer + msg; // $ExpectType NonSharedBuffer rinfo; // $ExpectType RemoteInfo }); sock.addMembership("233.252.0.0"); @@ -201,7 +201,7 @@ sock.on("error", (exception) => { }); sock.on("listening", () => undefined); sock.on("message", (msg, rinfo) => { - msg; // $ExpectType Buffer || Buffer + msg; // $ExpectType NonSharedBuffer rinfo.address; // $ExpectType string rinfo.family; // $ExpectType "IPv4" | "IPv6" rinfo.port; // $ExpectType number diff --git a/types/node/v22/test/fs.ts b/types/node/v22/test/fs.ts index 9170fa123b692c..ac1b2b18be083a 100644 --- a/types/node/v22/test/fs.ts +++ b/types/node/v22/test/fs.ts @@ -450,21 +450,21 @@ async function testPromisify() { fs.writev( 1, [Buffer.from("123")] as readonly NodeJS.ArrayBufferView[], - (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => { + (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: readonly NodeJS.ArrayBufferView[]) => { }, ); fs.writev( 1, [Buffer.from("123")] as readonly NodeJS.ArrayBufferView[], 123, - (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => { + (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: readonly NodeJS.ArrayBufferView[]) => { }, ); fs.writev( 1, [Buffer.from("123")] as readonly NodeJS.ArrayBufferView[], null, - (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => { + (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: readonly NodeJS.ArrayBufferView[]) => { }, ); const bytesWritten = fs.writevSync(1, [Buffer.from("123")] as readonly NodeJS.ArrayBufferView[]); @@ -604,7 +604,7 @@ async function testPromisify() { const _rom = readStream.readableObjectMode; // $ExpectType boolean - (await handle.read()).buffer; // $ExpectType Buffer || Buffer + (await handle.read()).buffer; // $ExpectType NonSharedBuffer (await handle.read({ buffer: new Uint32Array(), offset: 1, @@ -680,14 +680,14 @@ async function testPromisify() { 123, [Buffer.from("wut")] as readonly NodeJS.ArrayBufferView[], 123, - (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => { + (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: readonly NodeJS.ArrayBufferView[]) => { }, ); fs.readv( 123, [Buffer.from("wut")] as readonly NodeJS.ArrayBufferView[], null, - (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => { + (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: readonly NodeJS.ArrayBufferView[]) => { }, ); } @@ -921,9 +921,9 @@ const anyStatFs: fs.StatsFs | fs.BigIntStatsFs = fs.statfsSync(".", { bigint: Ma { // $ExpectType AsyncIterator, any, any> watchAsync("y33t"); - // $ExpectType AsyncIterator, any, any> || AsyncIterator>, any, any> + // $ExpectType AsyncIterator, any, any> watchAsync("y33t", "buffer"); - // $ExpectType AsyncIterator, any, any> || AsyncIterator>, any, any> + // $ExpectType AsyncIterator, any, any> watchAsync("y33t", { encoding: "buffer", signal: new AbortSignal() }); // $ExpectType AsyncIterator, any, any> watchAsync("test", { persistent: true, recursive: true, encoding: "utf-8", maxQueue: 2048, overflow: "ignore" }); diff --git a/types/node/v22/test/https.ts b/types/node/v22/test/https.ts index f9b37edfd3c1b2..8b71abfc36df9b 100644 --- a/types/node/v22/test/https.ts +++ b/types/node/v22/test/https.ts @@ -320,7 +320,7 @@ import * as url from "node:url"; let _buffer: Buffer = Buffer.from(""); let _err = new Error(); let _boolean = true; - let sessionCallback = (err: Error, resp: Buffer) => {}; + let sessionCallback = (err: Error | null, resp: Buffer) => {}; let ocspRequestCallback = (err: Error | null, resp: Buffer) => {}; server = server.addListener("keylog", (ln, tlsSocket) => { diff --git a/types/node/v22/test/stream.ts b/types/node/v22/test/stream.ts index f26f91758260af..0935601ed71bdc 100644 --- a/types/node/v22/test/stream.ts +++ b/types/node/v22/test/stream.ts @@ -507,7 +507,7 @@ async function testConsumers() { await consumers.arrayBuffer(consumable); // $ExpectType Blob await consumers.blob(consumable); - // $ExpectType Buffer || Buffer + // $ExpectType NonSharedBuffer await consumers.buffer(consumable); // $ExpectType unknown await consumers.json(consumable); diff --git a/types/node/v22/test/vm.ts b/types/node/v22/test/vm.ts index 3eb8868ffd0b01..6c68b0efe145a1 100644 --- a/types/node/v22/test/vm.ts +++ b/types/node/v22/test/vm.ts @@ -78,7 +78,7 @@ import { }); fn satisfies Function; - // $ExpectType Buffer | undefined + // $ExpectType NonSharedBuffer | undefined fn.cachedData; // $ExpectType boolean | undefined fn.cachedDataProduced; diff --git a/types/node/v22/test/zlib.ts b/types/node/v22/test/zlib.ts index c9761c80e61b92..29ffa2e273c14d 100644 --- a/types/node/v22/test/zlib.ts +++ b/types/node/v22/test/zlib.ts @@ -163,8 +163,8 @@ createZstdDecompress({ chunkSize: 1024 }); // $ExpectType ZstdDecompress zstdCompress(compressMe, (err: Error | null, result: Buffer) => result); zstdCompress(compressMe, { finishFlush: constants.ZSTD_e_end }, (err: Error | null, result: Buffer) => result); -zstdCompressSync(compressMe); // $ExpectType Buffer || Buffer -zstdCompressSync(compressMe, { finishFlush: constants.ZSTD_e_end }); // $ExpectType Buffer || Buffer +zstdCompressSync(compressMe); // $ExpectType NonSharedBuffer +zstdCompressSync(compressMe, { finishFlush: constants.ZSTD_e_end }); // $ExpectType NonSharedBuffer zstdDecompress(compressMe, (err: Error | null, result: Buffer) => result); zstdDecompress( @@ -172,56 +172,56 @@ zstdDecompress( { params: { [constants.ZSTD_d_windowLogMax]: 100 } }, (err: Error | null, result: Buffer) => result, ); -zstdDecompressSync(compressMe); // $ExpectType Buffer || Buffer -zstdDecompressSync(compressMe, { params: { [constants.ZSTD_d_windowLogMax]: 100 } }); // $ExpectType Buffer || Buffer +zstdDecompressSync(compressMe); // $ExpectType NonSharedBuffer +zstdDecompressSync(compressMe, { params: { [constants.ZSTD_d_windowLogMax]: 100 } }); // $ExpectType NonSharedBuffer { - // $ExpectType (buffer: InputType, options?: BrotliOptions | undefined) => Promise || (buffer: InputType, options?: BrotliOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: BrotliOptions | undefined) => Promise const pBrotliCompress = promisify(brotliCompress); - // $ExpectType (buffer: InputType, options?: BrotliOptions | undefined) => Promise || (buffer: InputType, options?: BrotliOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: BrotliOptions | undefined) => Promise const pBrotliDecompress = promisify(brotliDecompress); - // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise || (buffer: InputType, options?: ZlibOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise const pDeflate = promisify(deflate); - // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise || (buffer: InputType, options?: ZlibOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise const pDeflateRaw = promisify(deflateRaw); - // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise || (buffer: InputType, options?: ZlibOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise const pGzip = promisify(gzip); - // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise || (buffer: InputType, options?: ZlibOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise const pGunzip = promisify(gunzip); - // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise || (buffer: InputType, options?: ZlibOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise const pInflate = promisify(inflate); - // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise || (buffer: InputType, options?: ZlibOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise const pInflateRaw = promisify(inflateRaw); - // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise || (buffer: InputType, options?: ZlibOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: ZlibOptions | undefined) => Promise const pUnzip = promisify(unzip); - // $ExpectType (buffer: InputType, options?: ZstdOptions | undefined) => Promise || (buffer: InputType, options?: ZstdOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: ZstdOptions | undefined) => Promise const pZstdCompress = promisify(zstdCompress); - // $ExpectType (buffer: InputType, options?: ZstdOptions | undefined) => Promise || (buffer: InputType, options?: ZstdOptions | undefined) => Promise> + // $ExpectType (buffer: InputType, options?: ZstdOptions | undefined) => Promise const pZstdDecompress = promisify(zstdDecompress); (async () => { - await pBrotliCompress(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pBrotliCompress(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType Buffer || Buffer - await pBrotliDecompress(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pBrotliDecompress(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType Buffer || Buffer - await pDeflate(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pDeflate(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType Buffer || Buffer - await pDeflateRaw(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pDeflateRaw(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType Buffer || Buffer - await pGzip(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pGzip(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType Buffer || Buffer - await pGunzip(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pGunzip(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType Buffer || Buffer - await pInflate(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pInflate(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType Buffer || Buffer - await pInflateRaw(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pInflateRaw(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType Buffer || Buffer - await pUnzip(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pUnzip(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType Buffer || Buffer - await pZstdCompress(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pZstdCompress(Buffer.from("buf"), { flush: constants.ZSTD_e_flush }); // $ExpectType Buffer || Buffer - await pZstdDecompress(Buffer.from("buf")); // $ExpectType Buffer || Buffer - await pZstdDecompress(Buffer.from("buf"), { flush: constants.ZSTD_e_flush }); // $ExpectType Buffer || Buffer + await pBrotliCompress(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pBrotliCompress(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType NonSharedBuffer + await pBrotliDecompress(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pBrotliDecompress(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType NonSharedBuffer + await pDeflate(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pDeflate(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType NonSharedBuffer + await pDeflateRaw(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pDeflateRaw(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType NonSharedBuffer + await pGzip(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pGzip(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType NonSharedBuffer + await pGunzip(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pGunzip(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType NonSharedBuffer + await pInflate(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pInflate(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType NonSharedBuffer + await pInflateRaw(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pInflateRaw(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType NonSharedBuffer + await pUnzip(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pUnzip(Buffer.from("buf"), { flush: constants.Z_NO_FLUSH }); // $ExpectType NonSharedBuffer + await pZstdCompress(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pZstdCompress(Buffer.from("buf"), { flush: constants.ZSTD_e_flush }); // $ExpectType NonSharedBuffer + await pZstdDecompress(Buffer.from("buf")); // $ExpectType NonSharedBuffer + await pZstdDecompress(Buffer.from("buf"), { flush: constants.ZSTD_e_flush }); // $ExpectType NonSharedBuffer })(); } diff --git a/types/node/v22/tls.d.ts b/types/node/v22/tls.d.ts index 8e4c88b27b1244..1f90e863ca17e4 100644 --- a/types/node/v22/tls.d.ts +++ b/types/node/v22/tls.d.ts @@ -9,6 +9,7 @@ * @see [source](https://github.com/nodejs/node/blob/v22.x/lib/tls.js) */ declare module "tls" { + import { NonSharedBuffer } from "node:buffer"; import { X509Certificate } from "node:crypto"; import * as net from "node:net"; import * as stream from "stream"; @@ -49,7 +50,7 @@ declare module "tls" { /** * The DER encoded X.509 certificate data. */ - raw: Buffer; + raw: NonSharedBuffer; /** * The certificate subject. */ @@ -115,7 +116,7 @@ declare module "tls" { /** * The public key. */ - pubkey?: Buffer; + pubkey?: NonSharedBuffer; /** * The ASN.1 name of the OID of the elliptic curve. * Well-known curves are identified by an OID. @@ -295,7 +296,7 @@ declare module "tls" { * @since v9.9.0 * @return The latest `Finished` message that has been sent to the socket as part of a SSL/TLS handshake, or `undefined` if no `Finished` message has been sent yet. */ - getFinished(): Buffer | undefined; + getFinished(): NonSharedBuffer | undefined; /** * Returns an object representing the peer's certificate. If the peer does not * provide a certificate, an empty object will be returned. If the socket has been @@ -322,7 +323,7 @@ declare module "tls" { * @return The latest `Finished` message that is expected or has actually been received from the socket as part of a SSL/TLS handshake, or `undefined` if there is no `Finished` message so * far. */ - getPeerFinished(): Buffer | undefined; + getPeerFinished(): NonSharedBuffer | undefined; /** * Returns a string containing the negotiated SSL/TLS protocol version of the * current connection. The value `'unknown'` will be returned for connected @@ -352,7 +353,7 @@ declare module "tls" { * must use the `'session'` event (it also works for TLSv1.2 and below). * @since v0.11.4 */ - getSession(): Buffer | undefined; + getSession(): NonSharedBuffer | undefined; /** * See [SSL\_get\_shared\_sigalgs](https://www.openssl.org/docs/man1.1.1/man3/SSL_get_shared_sigalgs.html) for more information. * @since v12.11.0 @@ -367,7 +368,7 @@ declare module "tls" { * See `Session Resumption` for more information. * @since v0.11.4 */ - getTLSTicket(): Buffer | undefined; + getTLSTicket(): NonSharedBuffer | undefined; /** * See `Session Resumption` for more information. * @since v0.5.6 @@ -478,37 +479,37 @@ declare module "tls" { * @param context Optionally provide a context. * @return requested bytes of the keying material */ - exportKeyingMaterial(length: number, label: string, context: Buffer): Buffer; + exportKeyingMaterial(length: number, label: string, context: Buffer): NonSharedBuffer; addListener(event: string, listener: (...args: any[]) => void): this; - addListener(event: "OCSPResponse", listener: (response: Buffer) => void): this; + addListener(event: "OCSPResponse", listener: (response: NonSharedBuffer) => void): this; addListener(event: "secureConnect", listener: () => void): this; - addListener(event: "session", listener: (session: Buffer) => void): this; - addListener(event: "keylog", listener: (line: Buffer) => void): this; + addListener(event: "session", listener: (session: NonSharedBuffer) => void): this; + addListener(event: "keylog", listener: (line: NonSharedBuffer) => void): this; emit(event: string | symbol, ...args: any[]): boolean; - emit(event: "OCSPResponse", response: Buffer): boolean; + emit(event: "OCSPResponse", response: NonSharedBuffer): boolean; emit(event: "secureConnect"): boolean; - emit(event: "session", session: Buffer): boolean; - emit(event: "keylog", line: Buffer): boolean; + emit(event: "session", session: NonSharedBuffer): boolean; + emit(event: "keylog", line: NonSharedBuffer): boolean; on(event: string, listener: (...args: any[]) => void): this; - on(event: "OCSPResponse", listener: (response: Buffer) => void): this; + on(event: "OCSPResponse", listener: (response: NonSharedBuffer) => void): this; on(event: "secureConnect", listener: () => void): this; - on(event: "session", listener: (session: Buffer) => void): this; - on(event: "keylog", listener: (line: Buffer) => void): this; + on(event: "session", listener: (session: NonSharedBuffer) => void): this; + on(event: "keylog", listener: (line: NonSharedBuffer) => void): this; once(event: string, listener: (...args: any[]) => void): this; - once(event: "OCSPResponse", listener: (response: Buffer) => void): this; + once(event: "OCSPResponse", listener: (response: NonSharedBuffer) => void): this; once(event: "secureConnect", listener: () => void): this; - once(event: "session", listener: (session: Buffer) => void): this; - once(event: "keylog", listener: (line: Buffer) => void): this; + once(event: "session", listener: (session: NonSharedBuffer) => void): this; + once(event: "keylog", listener: (line: NonSharedBuffer) => void): this; prependListener(event: string, listener: (...args: any[]) => void): this; - prependListener(event: "OCSPResponse", listener: (response: Buffer) => void): this; + prependListener(event: "OCSPResponse", listener: (response: NonSharedBuffer) => void): this; prependListener(event: "secureConnect", listener: () => void): this; - prependListener(event: "session", listener: (session: Buffer) => void): this; - prependListener(event: "keylog", listener: (line: Buffer) => void): this; + prependListener(event: "session", listener: (session: NonSharedBuffer) => void): this; + prependListener(event: "keylog", listener: (line: NonSharedBuffer) => void): this; prependOnceListener(event: string, listener: (...args: any[]) => void): this; - prependOnceListener(event: "OCSPResponse", listener: (response: Buffer) => void): this; + prependOnceListener(event: "OCSPResponse", listener: (response: NonSharedBuffer) => void): this; prependOnceListener(event: "secureConnect", listener: () => void): this; - prependOnceListener(event: "session", listener: (session: Buffer) => void): this; - prependOnceListener(event: "keylog", listener: (line: Buffer) => void): this; + prependOnceListener(event: "session", listener: (session: NonSharedBuffer) => void): this; + prependOnceListener(event: "keylog", listener: (line: NonSharedBuffer) => void): this; } interface CommonConnectionOptions { /** @@ -531,7 +532,7 @@ declare module "tls" { * An array of strings or a Buffer naming possible ALPN protocols. * (Protocols should be ordered by their priority.) */ - ALPNProtocols?: string[] | Uint8Array[] | Uint8Array | undefined; + ALPNProtocols?: readonly string[] | NodeJS.ArrayBufferView | undefined; /** * SNICallback(servername, cb) A function that will be * called if the client supports SNI TLS extension. Two arguments @@ -596,7 +597,7 @@ declare module "tls" { pskIdentityHint?: string | undefined; } interface PSKCallbackNegotation { - psk: DataView | NodeJS.TypedArray; + psk: NodeJS.ArrayBufferView; identity: string; } interface ConnectionOptions extends SecureContextOptions, CommonConnectionOptions { @@ -655,7 +656,7 @@ declare module "tls" { * @since v3.0.0 * @return A 48-byte buffer containing the session ticket keys. */ - getTicketKeys(): Buffer; + getTicketKeys(): NonSharedBuffer; /** * The `server.setSecureContext()` method replaces the secure context of an * existing server. Existing connections to the server are not interrupted. @@ -687,115 +688,138 @@ declare module "tls" { addListener(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this; addListener( event: "newSession", - listener: (sessionId: Buffer, sessionData: Buffer, callback: () => void) => void, + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, ): this; addListener( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; addListener( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error | null, sessionData: Buffer | null) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; addListener(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this; - addListener(event: "keylog", listener: (line: Buffer, tlsSocket: TLSSocket) => void): this; + addListener(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: TLSSocket) => void): this; emit(event: string | symbol, ...args: any[]): boolean; emit(event: "tlsClientError", err: Error, tlsSocket: TLSSocket): boolean; - emit(event: "newSession", sessionId: Buffer, sessionData: Buffer, callback: () => void): boolean; + emit( + event: "newSession", + sessionId: NonSharedBuffer, + sessionData: NonSharedBuffer, + callback: () => void, + ): boolean; emit( event: "OCSPRequest", - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ): boolean; emit( event: "resumeSession", - sessionId: Buffer, + sessionId: NonSharedBuffer, callback: (err: Error | null, sessionData: Buffer | null) => void, ): boolean; emit(event: "secureConnection", tlsSocket: TLSSocket): boolean; - emit(event: "keylog", line: Buffer, tlsSocket: TLSSocket): boolean; + emit(event: "keylog", line: NonSharedBuffer, tlsSocket: TLSSocket): boolean; on(event: string, listener: (...args: any[]) => void): this; on(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this; - on(event: "newSession", listener: (sessionId: Buffer, sessionData: Buffer, callback: () => void) => void): this; + on( + event: "newSession", + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, + ): this; on( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; on( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error | null, sessionData: Buffer | null) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; on(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this; - on(event: "keylog", listener: (line: Buffer, tlsSocket: TLSSocket) => void): this; + on(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: TLSSocket) => void): this; once(event: string, listener: (...args: any[]) => void): this; once(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this; once( event: "newSession", - listener: (sessionId: Buffer, sessionData: Buffer, callback: () => void) => void, + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, ): this; once( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; once( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error | null, sessionData: Buffer | null) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; once(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this; - once(event: "keylog", listener: (line: Buffer, tlsSocket: TLSSocket) => void): this; + once(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: TLSSocket) => void): this; prependListener(event: string, listener: (...args: any[]) => void): this; prependListener(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this; prependListener( event: "newSession", - listener: (sessionId: Buffer, sessionData: Buffer, callback: () => void) => void, + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, ): this; prependListener( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; prependListener( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error | null, sessionData: Buffer | null) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; prependListener(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this; - prependListener(event: "keylog", listener: (line: Buffer, tlsSocket: TLSSocket) => void): this; + prependListener(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: TLSSocket) => void): this; prependOnceListener(event: string, listener: (...args: any[]) => void): this; prependOnceListener(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this; prependOnceListener( event: "newSession", - listener: (sessionId: Buffer, sessionData: Buffer, callback: () => void) => void, + listener: (sessionId: NonSharedBuffer, sessionData: NonSharedBuffer, callback: () => void) => void, ): this; prependOnceListener( event: "OCSPRequest", listener: ( - certificate: Buffer, - issuer: Buffer, - callback: (err: Error | null, resp: Buffer) => void, + certificate: NonSharedBuffer, + issuer: NonSharedBuffer, + callback: (err: Error | null, resp: Buffer | null) => void, ) => void, ): this; prependOnceListener( event: "resumeSession", - listener: (sessionId: Buffer, callback: (err: Error | null, sessionData: Buffer | null) => void) => void, + listener: ( + sessionId: NonSharedBuffer, + callback: (err: Error | null, sessionData: Buffer | null) => void, + ) => void, ): this; prependOnceListener(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this; - prependOnceListener(event: "keylog", listener: (line: Buffer, tlsSocket: TLSSocket) => void): this; + prependOnceListener(event: "keylog", listener: (line: NonSharedBuffer, tlsSocket: TLSSocket) => void): this; } /** * @deprecated since v0.11.3 Use `tls.TLSSocket` instead. diff --git a/types/node/v22/ts5.6/buffer.buffer.d.ts b/types/node/v22/ts5.6/buffer.buffer.d.ts index d19026dc2ff99c..a5f67d7c9306ed 100644 --- a/types/node/v22/ts5.6/buffer.buffer.d.ts +++ b/types/node/v22/ts5.6/buffer.buffer.d.ts @@ -32,7 +32,7 @@ declare module "buffer" { * @param arrayBuffer The ArrayBuffer with which to share memory. * @deprecated since v10.0.0 - Use `Buffer.from(arrayBuffer[, byteOffset[, length]])` instead. */ - new(arrayBuffer: ArrayBuffer | SharedArrayBuffer): Buffer; + new(arrayBuffer: ArrayBufferLike): Buffer; /** * Allocates a new `Buffer` using an `array` of bytes in the range `0` – `255`. * Array entries outside that range will be truncated to fit into it. @@ -126,7 +126,7 @@ declare module "buffer" { * `arrayBuffer.byteLength - byteOffset`. */ from( - arrayBuffer: WithImplicitCoercion, + arrayBuffer: WithImplicitCoercion, byteOffset?: number, length?: number, ): Buffer; @@ -448,7 +448,15 @@ declare module "buffer" { */ subarray(start?: number, end?: number): Buffer; } + /** + * @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports + * TypeScript versions earlier than 5.7. + */ type NonSharedBuffer = Buffer; + /** + * @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports + * TypeScript versions earlier than 5.7. + */ type AllowSharedBuffer = Buffer; } /** @deprecated Use `Buffer.allocUnsafeSlow()` instead. */ diff --git a/types/node/v22/ts5.6/globals.typedarray.d.ts b/types/node/v22/ts5.6/globals.typedarray.d.ts index 0e4633b951b124..f1c444d1fac2da 100644 --- a/types/node/v22/ts5.6/globals.typedarray.d.ts +++ b/types/node/v22/ts5.6/globals.typedarray.d.ts @@ -15,5 +15,20 @@ declare global { | Float32Array | Float64Array; type ArrayBufferView = TypedArray | DataView; + + type NonSharedUint8Array = Uint8Array; + type NonSharedUint8ClampedArray = Uint8ClampedArray; + type NonSharedUint16Array = Uint16Array; + type NonSharedUint32Array = Uint32Array; + type NonSharedInt8Array = Int8Array; + type NonSharedInt16Array = Int16Array; + type NonSharedInt32Array = Int32Array; + type NonSharedBigUint64Array = BigUint64Array; + type NonSharedBigInt64Array = BigInt64Array; + type NonSharedFloat32Array = Float32Array; + type NonSharedFloat64Array = Float64Array; + type NonSharedDataView = DataView; + type NonSharedTypedArray = TypedArray; + type NonSharedArrayBufferView = ArrayBufferView; } } diff --git a/types/node/v22/url.d.ts b/types/node/v22/url.d.ts index 33a6addf8bc356..84736e880621bc 100644 --- a/types/node/v22/url.d.ts +++ b/types/node/v22/url.d.ts @@ -8,7 +8,7 @@ * @see [source](https://github.com/nodejs/node/blob/v22.x/lib/url.js) */ declare module "url" { - import { Blob as NodeBlob } from "node:buffer"; + import { Blob as NodeBlob, NonSharedBuffer } from "node:buffer"; import { ClientRequestArgs } from "node:http"; import { ParsedUrlQuery, ParsedUrlQueryInput } from "node:querystring"; // Input to `url.format` @@ -325,7 +325,7 @@ declare module "url" { * @returns The fully-resolved platform-specific Node.js file path * as a `Buffer`. */ - function fileURLToPathBuffer(url: string | URL, options?: FileUrlToPathOptions): Buffer; + function fileURLToPathBuffer(url: string | URL, options?: FileUrlToPathOptions): NonSharedBuffer; /** * This function ensures that `path` is resolved absolutely, and that the URL * control characters are correctly encoded when converting into a File URL. diff --git a/types/node/v22/util.d.ts b/types/node/v22/util.d.ts index b6dedb4ebd3d0c..e535f5c5a48e5a 100644 --- a/types/node/v22/util.d.ts +++ b/types/node/v22/util.d.ts @@ -1616,7 +1616,7 @@ declare module "util" { * encoded bytes. * @param [input='an empty string'] The text to encode. */ - encode(input?: string): Uint8Array; + encode(input?: string): NodeJS.NonSharedUint8Array; /** * UTF-8 encodes the `src` string to the `dest` Uint8Array and returns an object * containing the read Unicode code units and written UTF-8 bytes. diff --git a/types/node/v22/v8.d.ts b/types/node/v22/v8.d.ts index 811af5709c773a..34006cd41b8112 100644 --- a/types/node/v22/v8.d.ts +++ b/types/node/v22/v8.d.ts @@ -7,6 +7,7 @@ * @see [source](https://github.com/nodejs/node/blob/v22.x/lib/v8.js) */ declare module "v8" { + import { NonSharedBuffer } from "node:buffer"; import { Readable } from "node:stream"; interface HeapSpaceInfo { space_name: string; @@ -453,7 +454,7 @@ declare module "v8" { * the buffer is released. Calling this method results in undefined behavior * if a previous write has failed. */ - releaseBuffer(): Buffer; + releaseBuffer(): NonSharedBuffer; /** * Marks an `ArrayBuffer` as having its contents transferred out of band. * Pass the corresponding `ArrayBuffer` in the deserializing context to `deserializer.transferArrayBuffer()`. @@ -481,7 +482,7 @@ declare module "v8" { * will require a way to compute the length of the buffer. * For use inside of a custom `serializer._writeHostObject()`. */ - writeRawBytes(buffer: NodeJS.TypedArray): void; + writeRawBytes(buffer: NodeJS.ArrayBufferView): void; } /** * A subclass of `Serializer` that serializes `TypedArray`(in particular `Buffer`) and `DataView` objects as host objects, and only @@ -552,7 +553,7 @@ declare module "v8" { * larger than `buffer.constants.MAX_LENGTH`. * @since v8.0.0 */ - function serialize(value: any): Buffer; + function serialize(value: any): NonSharedBuffer; /** * Uses a `DefaultDeserializer` with default options to read a JS value * from a buffer. diff --git a/types/node/v22/vm.d.ts b/types/node/v22/vm.d.ts index ec7a2d834440f7..a2609bf2ba2723 100644 --- a/types/node/v22/vm.d.ts +++ b/types/node/v22/vm.d.ts @@ -37,6 +37,7 @@ * @see [source](https://github.com/nodejs/node/blob/v22.x/lib/vm.js) */ declare module "vm" { + import { NonSharedBuffer } from "node:buffer"; import { ImportAttributes } from "node:module"; interface Context extends NodeJS.Dict {} interface BaseOptions { @@ -65,7 +66,7 @@ declare module "vm" { /** * Provides an optional data with V8's code cache data for the supplied source. */ - cachedData?: Buffer | NodeJS.ArrayBufferView | undefined; + cachedData?: NodeJS.ArrayBufferView | undefined; /** @deprecated in favor of `script.createCachedData()` */ produceCachedData?: boolean | undefined; /** @@ -361,7 +362,7 @@ declare module "vm" { * ``` * @since v10.6.0 */ - createCachedData(): Buffer; + createCachedData(): NonSharedBuffer; /** @deprecated in favor of `script.createCachedData()` */ cachedDataProduced?: boolean; /** @@ -371,7 +372,7 @@ declare module "vm" { * @since v5.7.0 */ cachedDataRejected?: boolean; - cachedData?: Buffer; + cachedData?: NonSharedBuffer; /** * When the script is compiled from a source that contains a source map magic * comment, this property will be set to the URL of the source map. diff --git a/types/node/v22/zlib.d.ts b/types/node/v22/zlib.d.ts index 16525553032e15..caeb1ed7c8e26d 100644 --- a/types/node/v22/zlib.d.ts +++ b/types/node/v22/zlib.d.ts @@ -92,6 +92,7 @@ * @see [source](https://github.com/nodejs/node/blob/v22.x/lib/zlib.js) */ declare module "zlib" { + import { NonSharedBuffer } from "node:buffer"; import * as stream from "node:stream"; interface ZlibOptions { /** @@ -223,7 +224,7 @@ declare module "zlib" { * @returns A 32-bit unsigned integer containing the checksum. * @since v22.2.0 */ - function crc32(data: string | Buffer | NodeJS.ArrayBufferView, value?: number): number; + function crc32(data: string | NodeJS.ArrayBufferView, value?: number): number; /** * Creates and returns a new `BrotliCompress` object. * @since v11.7.0, v10.16.0 @@ -287,124 +288,124 @@ declare module "zlib" { */ function createZstdDecompress(options?: ZstdOptions): ZstdDecompress; type InputType = string | ArrayBuffer | NodeJS.ArrayBufferView; - type CompressCallback = (error: Error | null, result: Buffer) => void; + type CompressCallback = (error: Error | null, result: NonSharedBuffer) => void; /** * @since v11.7.0, v10.16.0 */ function brotliCompress(buf: InputType, options: BrotliOptions, callback: CompressCallback): void; function brotliCompress(buf: InputType, callback: CompressCallback): void; namespace brotliCompress { - function __promisify__(buffer: InputType, options?: BrotliOptions): Promise; + function __promisify__(buffer: InputType, options?: BrotliOptions): Promise; } /** * Compress a chunk of data with `BrotliCompress`. * @since v11.7.0, v10.16.0 */ - function brotliCompressSync(buf: InputType, options?: BrotliOptions): Buffer; + function brotliCompressSync(buf: InputType, options?: BrotliOptions): NonSharedBuffer; /** * @since v11.7.0, v10.16.0 */ function brotliDecompress(buf: InputType, options: BrotliOptions, callback: CompressCallback): void; function brotliDecompress(buf: InputType, callback: CompressCallback): void; namespace brotliDecompress { - function __promisify__(buffer: InputType, options?: BrotliOptions): Promise; + function __promisify__(buffer: InputType, options?: BrotliOptions): Promise; } /** * Decompress a chunk of data with `BrotliDecompress`. * @since v11.7.0, v10.16.0 */ - function brotliDecompressSync(buf: InputType, options?: BrotliOptions): Buffer; + function brotliDecompressSync(buf: InputType, options?: BrotliOptions): NonSharedBuffer; /** * @since v0.6.0 */ function deflate(buf: InputType, callback: CompressCallback): void; function deflate(buf: InputType, options: ZlibOptions, callback: CompressCallback): void; namespace deflate { - function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; + function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; } /** * Compress a chunk of data with `Deflate`. * @since v0.11.12 */ - function deflateSync(buf: InputType, options?: ZlibOptions): Buffer; + function deflateSync(buf: InputType, options?: ZlibOptions): NonSharedBuffer; /** * @since v0.6.0 */ function deflateRaw(buf: InputType, callback: CompressCallback): void; function deflateRaw(buf: InputType, options: ZlibOptions, callback: CompressCallback): void; namespace deflateRaw { - function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; + function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; } /** * Compress a chunk of data with `DeflateRaw`. * @since v0.11.12 */ - function deflateRawSync(buf: InputType, options?: ZlibOptions): Buffer; + function deflateRawSync(buf: InputType, options?: ZlibOptions): NonSharedBuffer; /** * @since v0.6.0 */ function gzip(buf: InputType, callback: CompressCallback): void; function gzip(buf: InputType, options: ZlibOptions, callback: CompressCallback): void; namespace gzip { - function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; + function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; } /** * Compress a chunk of data with `Gzip`. * @since v0.11.12 */ - function gzipSync(buf: InputType, options?: ZlibOptions): Buffer; + function gzipSync(buf: InputType, options?: ZlibOptions): NonSharedBuffer; /** * @since v0.6.0 */ function gunzip(buf: InputType, callback: CompressCallback): void; function gunzip(buf: InputType, options: ZlibOptions, callback: CompressCallback): void; namespace gunzip { - function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; + function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; } /** * Decompress a chunk of data with `Gunzip`. * @since v0.11.12 */ - function gunzipSync(buf: InputType, options?: ZlibOptions): Buffer; + function gunzipSync(buf: InputType, options?: ZlibOptions): NonSharedBuffer; /** * @since v0.6.0 */ function inflate(buf: InputType, callback: CompressCallback): void; function inflate(buf: InputType, options: ZlibOptions, callback: CompressCallback): void; namespace inflate { - function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; + function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; } /** * Decompress a chunk of data with `Inflate`. * @since v0.11.12 */ - function inflateSync(buf: InputType, options?: ZlibOptions): Buffer; + function inflateSync(buf: InputType, options?: ZlibOptions): NonSharedBuffer; /** * @since v0.6.0 */ function inflateRaw(buf: InputType, callback: CompressCallback): void; function inflateRaw(buf: InputType, options: ZlibOptions, callback: CompressCallback): void; namespace inflateRaw { - function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; + function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; } /** * Decompress a chunk of data with `InflateRaw`. * @since v0.11.12 */ - function inflateRawSync(buf: InputType, options?: ZlibOptions): Buffer; + function inflateRawSync(buf: InputType, options?: ZlibOptions): NonSharedBuffer; /** * @since v0.6.0 */ function unzip(buf: InputType, callback: CompressCallback): void; function unzip(buf: InputType, options: ZlibOptions, callback: CompressCallback): void; namespace unzip { - function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; + function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; } /** * Decompress a chunk of data with `Unzip`. * @since v0.11.12 */ - function unzipSync(buf: InputType, options?: ZlibOptions): Buffer; + function unzipSync(buf: InputType, options?: ZlibOptions): NonSharedBuffer; /** * @since v22.15.0 * @experimental @@ -412,14 +413,14 @@ declare module "zlib" { function zstdCompress(buf: InputType, callback: CompressCallback): void; function zstdCompress(buf: InputType, options: ZstdOptions, callback: CompressCallback): void; namespace zstdCompress { - function __promisify__(buffer: InputType, options?: ZstdOptions): Promise; + function __promisify__(buffer: InputType, options?: ZstdOptions): Promise; } /** * Compress a chunk of data with `ZstdCompress`. * @since v22.15.0 * @experimental */ - function zstdCompressSync(buf: InputType, options?: ZstdOptions): Buffer; + function zstdCompressSync(buf: InputType, options?: ZstdOptions): NonSharedBuffer; /** * @since v22.15.0 * @experimental @@ -427,14 +428,14 @@ declare module "zlib" { function zstdDecompress(buf: InputType, callback: CompressCallback): void; function zstdDecompress(buf: InputType, options: ZstdOptions, callback: CompressCallback): void; namespace zstdDecompress { - function __promisify__(buffer: InputType, options?: ZstdOptions): Promise; + function __promisify__(buffer: InputType, options?: ZstdOptions): Promise; } /** * Decompress a chunk of data with `ZstdDecompress`. * @since v22.15.0 * @experimental */ - function zstdDecompressSync(buf: InputType, options?: ZstdOptions): Buffer; + function zstdDecompressSync(buf: InputType, options?: ZstdOptions): NonSharedBuffer; namespace constants { const BROTLI_DECODE: number; const BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES: number; diff --git a/types/node/v8.d.ts b/types/node/v8.d.ts index e4d668d2d25982..d509ee13c11998 100644 --- a/types/node/v8.d.ts +++ b/types/node/v8.d.ts @@ -7,6 +7,7 @@ * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/v8.js) */ declare module "v8" { + import { NonSharedBuffer } from "node:buffer"; import { Readable } from "node:stream"; interface HeapSpaceInfo { space_name: string; @@ -485,7 +486,7 @@ declare module "v8" { * the buffer is released. Calling this method results in undefined behavior * if a previous write has failed. */ - releaseBuffer(): Buffer; + releaseBuffer(): NonSharedBuffer; /** * Marks an `ArrayBuffer` as having its contents transferred out of band. * Pass the corresponding `ArrayBuffer` in the deserializing context to `deserializer.transferArrayBuffer()`. @@ -513,7 +514,7 @@ declare module "v8" { * will require a way to compute the length of the buffer. * For use inside of a custom `serializer._writeHostObject()`. */ - writeRawBytes(buffer: NodeJS.TypedArray): void; + writeRawBytes(buffer: NodeJS.ArrayBufferView): void; } /** * A subclass of `Serializer` that serializes `TypedArray`(in particular `Buffer`) and `DataView` objects as host objects, and only @@ -584,7 +585,7 @@ declare module "v8" { * larger than `buffer.constants.MAX_LENGTH`. * @since v8.0.0 */ - function serialize(value: any): Buffer; + function serialize(value: any): NonSharedBuffer; /** * Uses a `DefaultDeserializer` with default options to read a JS value * from a buffer. diff --git a/types/node/vm.d.ts b/types/node/vm.d.ts index e51721e9068791..50b7f09ad54c66 100644 --- a/types/node/vm.d.ts +++ b/types/node/vm.d.ts @@ -37,6 +37,7 @@ * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/vm.js) */ declare module "vm" { + import { NonSharedBuffer } from "node:buffer"; import { ImportAttributes, ImportPhase } from "node:module"; interface Context extends NodeJS.Dict {} interface BaseOptions { @@ -66,7 +67,7 @@ declare module "vm" { /** * Provides an optional data with V8's code cache data for the supplied source. */ - cachedData?: Buffer | NodeJS.ArrayBufferView | undefined; + cachedData?: NodeJS.ArrayBufferView | undefined; /** @deprecated in favor of `script.createCachedData()` */ produceCachedData?: boolean | undefined; /** @@ -367,7 +368,7 @@ declare module "vm" { * ``` * @since v10.6.0 */ - createCachedData(): Buffer; + createCachedData(): NonSharedBuffer; /** @deprecated in favor of `script.createCachedData()` */ cachedDataProduced?: boolean; /** @@ -377,7 +378,7 @@ declare module "vm" { * @since v5.7.0 */ cachedDataRejected?: boolean; - cachedData?: Buffer; + cachedData?: NonSharedBuffer; /** * When the script is compiled from a source that contains a source map magic * comment, this property will be set to the URL of the source map. diff --git a/types/node/zlib.d.ts b/types/node/zlib.d.ts index ebdc232e6c0e40..10f0e60e80e29c 100644 --- a/types/node/zlib.d.ts +++ b/types/node/zlib.d.ts @@ -92,6 +92,7 @@ * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/zlib.js) */ declare module "zlib" { + import { NonSharedBuffer } from "node:buffer"; import * as stream from "node:stream"; interface ZlibOptions { /** @@ -227,7 +228,7 @@ declare module "zlib" { * @returns A 32-bit unsigned integer containing the checksum. * @since v22.2.0 */ - function crc32(data: string | Buffer | NodeJS.ArrayBufferView, value?: number): number; + function crc32(data: string | NodeJS.ArrayBufferView, value?: number): number; /** * Creates and returns a new `BrotliCompress` object. * @since v11.7.0, v10.16.0 @@ -291,124 +292,124 @@ declare module "zlib" { */ function createZstdDecompress(options?: ZstdOptions): ZstdDecompress; type InputType = string | ArrayBuffer | NodeJS.ArrayBufferView; - type CompressCallback = (error: Error | null, result: Buffer) => void; + type CompressCallback = (error: Error | null, result: NonSharedBuffer) => void; /** * @since v11.7.0, v10.16.0 */ function brotliCompress(buf: InputType, options: BrotliOptions, callback: CompressCallback): void; function brotliCompress(buf: InputType, callback: CompressCallback): void; namespace brotliCompress { - function __promisify__(buffer: InputType, options?: BrotliOptions): Promise; + function __promisify__(buffer: InputType, options?: BrotliOptions): Promise; } /** * Compress a chunk of data with `BrotliCompress`. * @since v11.7.0, v10.16.0 */ - function brotliCompressSync(buf: InputType, options?: BrotliOptions): Buffer; + function brotliCompressSync(buf: InputType, options?: BrotliOptions): NonSharedBuffer; /** * @since v11.7.0, v10.16.0 */ function brotliDecompress(buf: InputType, options: BrotliOptions, callback: CompressCallback): void; function brotliDecompress(buf: InputType, callback: CompressCallback): void; namespace brotliDecompress { - function __promisify__(buffer: InputType, options?: BrotliOptions): Promise; + function __promisify__(buffer: InputType, options?: BrotliOptions): Promise; } /** * Decompress a chunk of data with `BrotliDecompress`. * @since v11.7.0, v10.16.0 */ - function brotliDecompressSync(buf: InputType, options?: BrotliOptions): Buffer; + function brotliDecompressSync(buf: InputType, options?: BrotliOptions): NonSharedBuffer; /** * @since v0.6.0 */ function deflate(buf: InputType, callback: CompressCallback): void; function deflate(buf: InputType, options: ZlibOptions, callback: CompressCallback): void; namespace deflate { - function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; + function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; } /** * Compress a chunk of data with `Deflate`. * @since v0.11.12 */ - function deflateSync(buf: InputType, options?: ZlibOptions): Buffer; + function deflateSync(buf: InputType, options?: ZlibOptions): NonSharedBuffer; /** * @since v0.6.0 */ function deflateRaw(buf: InputType, callback: CompressCallback): void; function deflateRaw(buf: InputType, options: ZlibOptions, callback: CompressCallback): void; namespace deflateRaw { - function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; + function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; } /** * Compress a chunk of data with `DeflateRaw`. * @since v0.11.12 */ - function deflateRawSync(buf: InputType, options?: ZlibOptions): Buffer; + function deflateRawSync(buf: InputType, options?: ZlibOptions): NonSharedBuffer; /** * @since v0.6.0 */ function gzip(buf: InputType, callback: CompressCallback): void; function gzip(buf: InputType, options: ZlibOptions, callback: CompressCallback): void; namespace gzip { - function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; + function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; } /** * Compress a chunk of data with `Gzip`. * @since v0.11.12 */ - function gzipSync(buf: InputType, options?: ZlibOptions): Buffer; + function gzipSync(buf: InputType, options?: ZlibOptions): NonSharedBuffer; /** * @since v0.6.0 */ function gunzip(buf: InputType, callback: CompressCallback): void; function gunzip(buf: InputType, options: ZlibOptions, callback: CompressCallback): void; namespace gunzip { - function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; + function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; } /** * Decompress a chunk of data with `Gunzip`. * @since v0.11.12 */ - function gunzipSync(buf: InputType, options?: ZlibOptions): Buffer; + function gunzipSync(buf: InputType, options?: ZlibOptions): NonSharedBuffer; /** * @since v0.6.0 */ function inflate(buf: InputType, callback: CompressCallback): void; function inflate(buf: InputType, options: ZlibOptions, callback: CompressCallback): void; namespace inflate { - function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; + function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; } /** * Decompress a chunk of data with `Inflate`. * @since v0.11.12 */ - function inflateSync(buf: InputType, options?: ZlibOptions): Buffer; + function inflateSync(buf: InputType, options?: ZlibOptions): NonSharedBuffer; /** * @since v0.6.0 */ function inflateRaw(buf: InputType, callback: CompressCallback): void; function inflateRaw(buf: InputType, options: ZlibOptions, callback: CompressCallback): void; namespace inflateRaw { - function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; + function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; } /** * Decompress a chunk of data with `InflateRaw`. * @since v0.11.12 */ - function inflateRawSync(buf: InputType, options?: ZlibOptions): Buffer; + function inflateRawSync(buf: InputType, options?: ZlibOptions): NonSharedBuffer; /** * @since v0.6.0 */ function unzip(buf: InputType, callback: CompressCallback): void; function unzip(buf: InputType, options: ZlibOptions, callback: CompressCallback): void; namespace unzip { - function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; + function __promisify__(buffer: InputType, options?: ZlibOptions): Promise; } /** * Decompress a chunk of data with `Unzip`. * @since v0.11.12 */ - function unzipSync(buf: InputType, options?: ZlibOptions): Buffer; + function unzipSync(buf: InputType, options?: ZlibOptions): NonSharedBuffer; /** * @since v22.15.0 * @experimental @@ -416,14 +417,14 @@ declare module "zlib" { function zstdCompress(buf: InputType, callback: CompressCallback): void; function zstdCompress(buf: InputType, options: ZstdOptions, callback: CompressCallback): void; namespace zstdCompress { - function __promisify__(buffer: InputType, options?: ZstdOptions): Promise; + function __promisify__(buffer: InputType, options?: ZstdOptions): Promise; } /** * Compress a chunk of data with `ZstdCompress`. * @since v22.15.0 * @experimental */ - function zstdCompressSync(buf: InputType, options?: ZstdOptions): Buffer; + function zstdCompressSync(buf: InputType, options?: ZstdOptions): NonSharedBuffer; /** * @since v22.15.0 * @experimental @@ -431,14 +432,14 @@ declare module "zlib" { function zstdDecompress(buf: InputType, callback: CompressCallback): void; function zstdDecompress(buf: InputType, options: ZstdOptions, callback: CompressCallback): void; namespace zstdDecompress { - function __promisify__(buffer: InputType, options?: ZstdOptions): Promise; + function __promisify__(buffer: InputType, options?: ZstdOptions): Promise; } /** * Decompress a chunk of data with `ZstdDecompress`. * @since v22.15.0 * @experimental */ - function zstdDecompressSync(buf: InputType, options?: ZstdOptions): Buffer; + function zstdDecompressSync(buf: InputType, options?: ZstdOptions): NonSharedBuffer; namespace constants { const BROTLI_DECODE: number; const BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES: number; diff --git a/types/randombytes/randombytes-tests.ts b/types/randombytes/randombytes-tests.ts index 61d74c8c5b92f0..c37fdded8b2f07 100644 --- a/types/randombytes/randombytes-tests.ts +++ b/types/randombytes/randombytes-tests.ts @@ -1,11 +1,11 @@ import randomBytes = require("randombytes"); -// $ExpectType Buffer || Buffer +// $ExpectType Buffer || NonSharedBuffer randomBytes(16); // $ExpectType void randomBytes(16, (err, resp) => { // $ExpectType Error | null err; - // $ExpectType Buffer || Buffer + // $ExpectType Buffer || NonSharedBuffer resp; }); From 38fcbaf7cec92d3f43199d5eee5295fff82990d9 Mon Sep 17 00:00:00 2001 From: TheLazySquid <76746384+TheLazySquid@users.noreply.github.com> Date: Mon, 20 Oct 2025 20:00:51 -0400 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#73935=20Gimloa?= =?UTF-8?q?der:=20Document=20stores=20type=20by=20@TheLazySquid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/gimloader/gimloader-tests.ts | 27 + types/gimloader/index.d.ts | 2266 +++++++++++++++++++++++++--- types/gimloader/package.json | 5 +- types/gimloader/tsconfig.json | 2 +- 4 files changed, 2123 insertions(+), 177 deletions(-) diff --git a/types/gimloader/gimloader-tests.ts b/types/gimloader/gimloader-tests.ts index f2fd65962160ab..7a8a083d12354d 100644 --- a/types/gimloader/gimloader-tests.ts +++ b/types/gimloader/gimloader-tests.ts @@ -44,3 +44,30 @@ api.patcher.before({}, "foo", () => true); GL.net.gamemode; // $ExpectType string api.net.gamemode; // $ExpectType string api.net.onLoad((type, gamemode) => {}); + +GL.stores.phaser; // $ExpectType Phaser +window.stores.phaser; // $ExpectType Phaser +let worldManager!: Gimloader.Stores.WorldManager; +worldManager; // $ExpectType WorldManager + +api.stores.me.movementSpeed; // $ExpectType number +api.stores.loading.percentageAssetsLoaded; // $ExpectType number +api.stores.worldOptions.terrainOptions[0].name; // $ExpectType string + +api.stores.phaser.scene.add; // $ExpectType GameObjectFactory +api.stores.phaser.mainCharacter.input; // $ExpectType CharacterInput +api.stores.phaser.mainCharacter.physics.getBody().rigidBody.translation(); // $ExpectType Vector +api.stores.phaser.scene.actionManager; // $ExpectType ActionManager +api.stores.phaser.scene.characterManager; // $ExpectType CharacterManager +api.stores.phaser.scene.inputManager; // $ExpectType InputManager +api.stores.phaser.scene.tileManager; // $ExpectType TileManager +api.stores.phaser.scene.worldManager; // $ExpectType WorldManager + +let character = api.stores.phaser.scene.characterManager.characters.get("...")!; // $ExpectType Character +character.setIsMain(true); +api.stores.phaser.scene.inputManager.getMouseWorldXY(); // $ExpectType Vector +api.stores.phaser.scene.tileManager.layerManager.getActualLayerDepth("..."); // $ExpectType number +let device = api.stores.phaser.scene.worldManager.devices.getDeviceById("...")!; // $ExpectType Device +device.colliders.list; // $ExpectType DeviceCollider[] +device.state; // $ExpectType Record +api.stores.phaser.scene.worldManager.physics.bodies.staticBodies; // $ExpectType Set diff --git a/types/gimloader/index.d.ts b/types/gimloader/index.d.ts index 201c1a1e5f05c4..cbd11b315439be 100644 --- a/types/gimloader/index.d.ts +++ b/types/gimloader/index.d.ts @@ -1,173 +1,2092 @@ declare namespace Gimloader { - type event = symbol | string; - type eventNS = string | event[]; + type EventEmitter2 = import("eventemitter2").EventEmitter2; + namespace Stores { + type Collider = import("@dimforge/rapier2d-compat").Collider; + type ColliderDesc = import("@dimforge/rapier2d-compat").ColliderDesc; + type RigidBody = import("@dimforge/rapier2d-compat").RigidBody; + type RigidBodyDesc = import("@dimforge/rapier2d-compat").RigidBodyDesc; + type Vector = import("@dimforge/rapier2d-compat").Vector; + type BaseScene = import("phaser").Scene; - interface ConstructorOptions { - /** - * @default false - * @description set this to `true` to use wildcards. - */ - wildcard?: boolean; - /** - * @default '.' - * @description the delimiter used to segment namespaces. - */ - delimiter?: string; - /** - * @default false - * @description set this to `true` if you want to emit the newListener events. - */ - newListener?: boolean; - /** - * @default false - * @description set this to `true` if you want to emit the removeListener events. - */ - removeListener?: boolean; - /** - * @default 10 - * @description the maximum amount of listeners that can be assigned to an event. - */ - maxListeners?: number; - /** - * @default false - * @description show event name in memory leak message when more than maximum amount of listeners is assigned, default false - */ - verboseMemoryLeak?: boolean; - /** - * @default false - * @description disable throwing uncaughtException if an error event is emitted and it has no listeners - */ - ignoreErrors?: boolean; - } - interface ListenerFn { - (...values: any[]): void; - } - interface EventAndListener { - (event: string | string[], ...values: any[]): void; - } + interface Team { + characters: Map; + id: string; + name: string; + score: number; + } - interface WaitForFilter { - (...values: any[]): boolean; - } + interface Teams { + teams: Map; + updateCounter: number; + } - interface WaitForOptions { - /** - * @default 0 - */ - timeout: number; - /** - * @default null - */ - filter: WaitForFilter; - /** - * @default false - */ - handleError: boolean; - /** - * @default Promise - */ - Promise: any; - /** - * @default false - */ - overload: boolean; - } + interface SceneStore { + currentScene: string; + gpuTier: number; + isCursorOverCanvas: boolean; + } - interface CancelablePromise extends Promise { - cancel(reason: string): undefined; - } + interface BackgroundLayersManager { + layerManager: LayerManager; + scene: Scene; + createLayer(options: { + layerId: string; + depth: number; + }): void; + fill(terrain: TerrainOption): void; + fillForPlatformer(): void; + fillForTopDown(terrain: TerrainOption): void; + removeLayer(options: { + layerId: string; + }): void; + } - interface OnceOptions { - /** - * @default 0 - */ - timeout: number; - /** - * @default Promise - */ - Promise: any; - /** - * @default false - */ - overload: boolean; - } + interface LayerManager { + backgroundLayersManager: BackgroundLayersManager; + colliders: Map>; + layers: Map; + scene: Scene; + createInitialLayers(): void; + createLayer(id: string): void; + fillBottomLayer(terrain: TerrainOption): void; + getActualLayerDepth(id: string): number; + moveLayersAboveCharacters(): void; + onWorldSizeChange(): void; + } - interface ListenToOptions { - on?: { (event: event | eventNS, handler: ListenerFn): void }; - off?: { (event: event | eventNS, handler: ListenerFn): void }; - reducers: (event: any) => boolean | object; - } + interface TileManager { + cumulTime: number; + scene: Scene; + layerManager: LayerManager; + } - interface GeneralEventEmitter { - addEventListener(event: event, handler: ListenerFn): this; - removeEventListener(event: event, handler: ListenerFn): this; - addListener?(event: event, handler: ListenerFn): this; - removeListener?(event: event, handler: ListenerFn): this; - on?(event: event, handler: ListenerFn): this; - off?(event: event, handler: ListenerFn): this; - } + interface CharacterOptions { + id: string; + x: number; + y: number; + scale: number; + type: string; + } - interface OnOptions { - async?: boolean; - promisify?: boolean; - nextTick?: boolean; - objectify?: boolean; - } + interface Spectating { + findNewCharacter(): void; + onBeginSpectating(): void; + onEndSpectating(): void; + setShuffle(shuffle: boolean, save?: boolean): void; + } - interface Listener { - emitter: EventEmitter2; - event: event | eventNS; - listener: ListenerFn; - off(): this; - } + interface CharacterManager { + characterContainer: import("phaser").GameObjects.Container; + characters: Map; + scene: Scene; + spectating: Spectating; + addCharacter(options: CharacterOptions): Character; + cullCharacters(): void; + removeCharacter(id: string): void; + update(dt: number): void; + } + + interface Removal { + overlay: Overlay; + prevMouseWasDown: boolean; + scene: Scene; + checkForItem(): void; + createStateListeners(): void; + removeSelectedItems(): void; + update(): void; + } + + interface PlatformerEditing { + setTopDownControlsActive(active: boolean): void; + } + + interface SelectedDevicesOverlay { + graphics: import("phaser").GameObjects.Graphics; + scene: Scene; + showing: boolean; + hide(): void; + show(rects: Rect[]): void; + } + + interface MultiSelect { + boundingBoxAroundEverything: Rect | null; + currentlySelectedDevices: Device[]; + currentlySelectedDevicesIds: string[]; + hidingSelectionForDevices: boolean; + isSelecting: boolean; + modifierKeyDown: boolean; + mouseShifts: Vector[]; + movedOrCopiedDevices: Device[]; + overlay: Overlay; + scene: Scene; + selectedDevices: Device[]; + selectedDevicesIds: string[]; + selectedDevicesOverlay: SelectedDevicesOverlay; + selection: Rect | null; + addDeviceToSelection(device: Device): void; + endSelectionRect(): void; + findSelectedDevices(): void; + hasSomeSelection(): boolean; + hideSelection(): void; + multiselectDeleteKeyHandler(): void; + multiselectKeyHandler(down: boolean): void; + onDeviceAdded(device: Device): void; + onDeviceRemoved(id: string): void; + setShiftParams(): void; + startSelectionRect(): void; + unselectAll(): void; + update(): void; + updateSelectedDevicesOverlay(): void; + updateSelectionRect(): void; + } + + interface DepthSort { + overlay: Overlay; + scene: Scene; + update(): void; + } + + interface ActionManager { + depthSort: DepthSort; + multiSelect: MultiSelect; + platformerEditing: PlatformerEditing; + removal: Removal; + update(): void; + } + + interface Projectile { + id: string; + startTime: number; + endTime: number; + start: Vector; + end: Vector; + radius: number; + appearance: string; + ownerId: string; + ownerTeamId: string; + damage: number; + hitPos?: Vector; + hitTime?: number; + } + + interface Projectiles { + damageMarkers: any; + dynamicDevices: Set; + fireSlashes: any; + projectileJSON: Map; + runClientSidePrediction: boolean; + scene: Scene; + addProjectile(projectile: Projectile): void; + fire(pointer: import("phaser").Input.Pointer, snap: boolean): void; + update(): void; + } + + interface WorldBoundsCollider { + body: RigidBody; + collider: Collider; + } + + interface BodyBounds { + minX: number; + minY: number; + maxX: number; + maxY: number; + } + + interface BodyStatic { + bounds: BodyBounds; + cells: Set; + } + + interface Body { + collider?: Collider; + colliderDesc: ColliderDesc; + rigidBody?: RigidBody; + rigidBodyDesc: RigidBodyDesc; + static: BodyStatic; + device?: { + id: string; + }; + terrain?: { + key: string; + }; + } + + interface ActiveBodies { + activeBodies: Set; + bodyManager: BodyManager; + currentCoordinateKeys: Set; + world: World; + disableBody(id: string): void; + enable(keys: Set, setAll: boolean): void; + enableBodiesAlongLine(options: { + start: Vector; + end: Vector; + }): void; + enableBodiesWithinAreas(options: { + areas: Rect[]; + disableActiveBodiesOutsideArea: boolean; + }): void; + enableBody(id: string): void; + setDirty(): void; + } + + interface BodyManager { + activeBodies: ActiveBodies; + bodies: Map; + cells: Map>; + dynamicBodies: Set; + gridSize: number; + staticBodies: Set; + staticSensorBodies: Set; + _idCount: number; + find(id: string): Body | undefined; + findPotentialStaticBodiesWithinArea(area: Rect): Set; + generateId(): void; + insert(body: Body): string; + remove(id: string): void; + } + + interface PhysicsManager { + bodies: BodyManager; + cumulTime: number; + lastTime: number; + physicsStep(dt: number): void; + runPhysicsLoop(dt: number): void; + world: World; + worldBoundsColliders: Set; + } + + interface CreateTileOptions { + x: number; + y: number; + tileIndex: number; + terrainOption: TerrainOption; + } + + interface InGameTerrainBuilder { + afterFailureWithTouch: boolean; + clearConsumeErrorMessage(): void; + clearPreviewLayer(): void; + createPreviewTile(options: CreateTileOptions): void; + overlay: Overlay; + previewingTile?: Vector; + scene: Scene; + update(): void; + wasDown: boolean; + } + + interface WorldInteractives { + scene: Scene; + currentDevice?: Device; + clearCurrentDevice(): void; + setCurrentDevice(device: Device): void; + update(devices: Device[]): void; + } + + interface ShowOverlayOptions { + x: number; + y: number; + width: number; + height: number; + depth: number; + } + + interface Overlay { + scene: Scene; + showing: boolean; + showingDimensions: { + width: number; + height: number; + } | null; + showingPosition: { + x: number; + y: number; + } | null; + hide(): void; + show(options: ShowOverlayOptions): void; + } + + interface DevicesPreview { + devicePreviewOverlay: Overlay; + previousDevices: Device[]; + scene: Scene; + removePreviousDevices(isBeingReplaced: boolean): void; + update(): void; + } + + interface DevicesAction { + inputManager: InputManager; + scene: Scene; + onClick(arg: any): void; + update(): void; + } + + interface DeviceProjectiles { + device: Device; + addToDynamicDevices(): void; + collidesWithProjectile(object: Circle): boolean; + onClientPredictedHit(position: Vector): void; + removeFromDynamicDevices(): void; + setDynamic(dynamic: boolean): void; + } + + interface DeviceTweens { + list: import("phaser").Tweens.Tween[]; + device: Device; + add(config: import("phaser").Types.Tweens.TweenBuilderConfig): import("phaser").Tweens.Tween; + destroy(): void; + } + + interface WirePoints { + device: Device; + end: Vector; + start: Vector; + onPointChange(): void; + setBoth(x: number, y: number): void; + } + + interface Layers { + depth: number; + device: Device; + layer: string; + options: any; + } + + interface ShadowOptions { + x: number; + y: number; + r1: number; + r2: number; + alphaMultip: number; + depth: number; + } + + interface Shadows { + device: Device; + list: ShadowOptions[]; + add(options: ShadowOptions): void; + destroy(): void; + forEach(callback: (shadow: ShadowOptions) => void): void; + hide(): void; + show(): void; + } + + interface Circle { + x: number; + y: number; + radius: number; + } + + interface RotatedCircle extends Circle { + angle: number; + } + + interface VisualEditingCircle { + angle: number; + rotable: boolean; + radius: number; + minRadius: number; + maxRadius: number; + onChange(value: RotatedCircle): void; + } + + interface RotatedRect extends Rect { + angle: number; + } + + interface VisualEditingBox { + width: number; + height: number; + angle: number; + minWidth: number; + maxWidth: number; + minHeight: number; + maxHeight: number; + keepRatio: boolean; + rotable: boolean; + onChange(value: RotatedRect): void; + } + + interface VisualEditing { + add: { + box(options: VisualEditingBox): void; + circle(options: VisualEditingCircle): void; + }; + device: Device; + isActive: boolean; + shapes: (VisualEditingBox | VisualEditingCircle)[]; + clear(): void; + } + + interface InteractiveZones { + add: { + circle(zone: CircleShort): void; + rect(zone: Rect): void; + }; + canInteractThroughColliders: boolean; + device: Device; + forceDisabled: boolean; + zones: (CircleShort | Rect)[]; + contains(x: number, y: number): boolean; + destroy(): void; + getCanInteractThroughColliders(): boolean; + getInfo(): any; + getMaxDistance(x: number, y: number): number; + isInteractive(): boolean; + onPlayerCanInteract(): void; + onPlayerCantInteractAnyMore(): void; + setCanInteractThroughColliders(canInteract: boolean): void; + setForceDisabled(forceDisabled: boolean): void; + setInfo(info: any): void; + } + + interface DeviceInput { + device: Device; + enabled: boolean; + hasKeyListeners: boolean; + isCurrentlyUnderMouse: boolean; + addDeviceToCursorUnderList(): void; + createKeyListeners(): void; + cutCopyHandler(action: string): void; + disable(): void; + dispose(): void; + disposeKeyListeners(): void; + enable(): void; + partIsNoLongerUnderMouse(): void; + partIsUnderMouse(): void; + removeDeviceFromCursorUnderList(): void; + } + + interface DeviceUI { + device: Device; + close(): void; + open(options: Record): void; + update(options: Record): void; + } + + interface VFX { + character: Character; + damageBoostActive: boolean; + phaseActive: boolean; + tintModifierId: string; + transparencyModifierId: string; + setTintModifier(id: string): void; + setTransparencyModifier(id: string): void; + startDamageBoostAnim(): void; + startPhaseAnim(): void; + stopDamageBoostAnim(): void; + stopPhaseAnim(): void; + } + + interface TintParams { + type: string; + fromColor: string; + toColor: string; + duration: number; + tween?: import("phaser").Tweens.Tween; + ease(t: number): number; + } + + interface Tint { + character: Character; + scene: Scene; + phase?: TintParams; + playerAppearanceModifierDevice?: TintParams; + immunity?: TintParams; + damageBoost?: TintParams; + getTintParams(type: string): TintParams | undefined; + setTintParams(type: string, tint?: TintParams): void; + startAnimateTint(params: TintParams): void; + stopAnimateTint(type: string): void; + update(): void; + } + + interface SkinOptions { + id: string; + editStyles: Record; + } + + interface Skin { + character: Character; + editStyles?: Record; + latestSkinId: string; + scene: Scene; + skinId: string; + applyEditStyles(options: SkinOptions): void; + setupSkin(position: Vector): void; + updateSkin(options: SkinOptions): void; + } + + interface Shadow { + character: Character; + image?: import("phaser").GameObjects.Image; + createShadow(): void; + destroy(): void; + update(): void; + } + + interface TweenScaleOptions { + type: string; + scale: number; + duration: number; + } + + interface Scale { + activeScale: number; + baseScale: number; + character: Character; + respawningScale: number; + scaleX: number; + scaleY: number; + scene: Scene; + spectatorScale: number; + dependencyScale: number; + isVisible: boolean; + getCurrentScale(type: number): void; + onSkinChange(): void; + setScale(type: number, scale: number): void; + tweenScale(options: TweenScaleOptions): void; + update(): void; + } + + interface Position { + character: Character; + update(dt: number): void; + } + + interface Network { + lastAngle?: number; + lastAngleUpdate: number; + updateAimAngle(angle: number): void; + } + + interface Nametag { + alpha: number; + character: Character; + creatingTag: boolean; + depth: number; + destroyed: boolean; + followScale: boolean; + fragilityTag?: import("phaser").GameObjects.Text; + healthMode: string; + name: string; + scale: number; + scene: Scene; + tag: import("phaser").GameObjects.Text; + teamState: TeamState; + fontColor: string; + tags: import("phaser").GameObjects.Text[]; + createFragilityTag(): void; + createTag(): void; + destroy(): void; + makeVisibleChanges(force?: boolean): void; + playHideAnimation(): void; + playShowUpAnimation(): void; + setName(name: string): void; + update(update: { + teamState: TeamState; + }): void; + updateFontColor(): void; + updateFragility(fragility: number): void; + updateTagAlpha(force?: boolean): void; + updateTagDepth(force?: boolean): void; + updateTagPosition(force?: boolean): void; + updateTagScale(force?: boolean): void; + } + + interface CharacterInput { + character: Character; + isListeningForInput: boolean; + scene: Scene; + setupInput(): void; + } + + interface TeamState { + status: string; + teamId: string; + } + + interface Indicator extends Updates { + character: Character; + characterHeight: number; + depth: number; + image: import("phaser").GameObjects.Image; + isMain: boolean; + isSpectated: boolean; + lastCharacterAlpha: number; + scene: Scene; + teamState: TeamState; + destroy(): void; + makeIndicator(): void; + } + + interface ImpactAnimation { + animations: Map; + character: Character; + loadedAnimations: Set; + scene: Scene; + _play(animation: string): void; + destroy(): void; + load(animation: string): void; + play(animation: string): void; + } + + interface Immunity { + character: Character; + classImmunityActive: boolean; + spawnImmunityActive: boolean; + activate(): void; + activateClassImmunity(): void; + activateSpawnImmunity(): void; + deactivate(): void; + deactivateClassImmunity(): void; + deactivateSpawnImmunity(): void; + isActive(): boolean; + } + + interface Updates { + update(update: { + delta: number; + }): void; + updateAlpha(): void; + updateDepth(): void; + updatePosition(dt: number): void; + updateScale(): void; + } + + interface Healthbar extends Updates { + character: Character; + depth: number; + isVisible: boolean; + scene: Scene; + destroy(): void; + makeIndicator(): void; + updateValue(): void; + } + + interface Flip { + character: Character; + flipXLastX: number; + isFlipped: boolean; + lastX: number; + lastY: number; + update(): void; + updateFlipForMainCharacter(): void; + updateFlipForOthers(): void; + } + + interface Dimensions { + character: Character; + currentDimensionsId: string; + bottomY: number; + centerX: number; + topY: number; + x: number; + onPotentialDimensionsChange(): void; + } + + interface Depth { + character: Character; + currentDepth: number; + lastY: number; + update(): void; + updateDepth(): void; + } + + interface Culling { + character: Character; + isInCamera: boolean; + needsCullUpdate: boolean; + scene: Scene; + shouldForceUpdate: boolean; + forceUpdate(): void; + hideObject(object: any): void; + onInCamera(): void; + onOutCamera(): void; + showObject(object: any): void; + updateNeedsUpdate(): void; + } + + interface TrailParticles { + frameHeight: number; + frameWidth: number; + imageUrl: string; + numberOfFrames: number; + } + + interface TrailEmitter { + frequency: number; + quantity: number; + blendMode: number; + speed: number; + speedVariation: number; + lifetime: number; + lifetimeVariation: number; + scale: number; + scaleVariation: number; + scaleThreshold: number; + rotationRandomAtStart: boolean; + rotationChange: number; + rotationChangeVariation: number; + rotationAllowNegativeChange: boolean; + alphaThresholdStart: number; + alphaThresholdEnd: number; + gravityY: number; + yOriginChange: number; + emitterZone: Partial; + } + + interface TrailAppearance { + id: string; + emitter: TrailEmitter; + particles: TrailParticles; + } + + interface CharacterTrail { + character: Character; + currentAppearance: TrailAppearance; + currentAppearanceId: string; + isReady: boolean; + lastSetAlpha: number; + destroy(): void; + followCharacter(): void; + setNewAppearance(appearance: TrailAppearance): void; + update(): void; + updateAppearance(id: string): void; + } + + interface TweenAlphaOptions { + alpha: number; + type: string; + duration: number; + ease?: string; + } + + interface Alpha { + character: Character; + cinematicModeAlpha: number; + currentAlpha: number; + immunity: number; + phaseAlpha: number; + playerAppearanceModifierDeviceAlpha: number; + scene: Scene; + getCurrentAlpha(): number; + setAlpha(type: string, alpha: number): void; + tweenAlpha(options: TweenAlphaOptions): void; + update(): void; + } + + interface EndInfo { + end: number; + start: number; + x: number; + y: number; + } + + interface Point { + endTime: number; + endX: number; + endY: number; + startTime: number; + startX: number; + startY: number; + teleported: boolean; + usedTeleported: boolean; + } + + interface Movement { + character: Character; + currentPoint: Point; + currentTime: number; + nonMainCharacterGrounded: boolean; + pointMap: Point[]; + targetIsDirty: boolean; + targetNonMainCharacterGrounded: boolean; + targetX: number; + targetY: number; + teleportCount: number; + teleported: boolean; + getCurrentEndInfo(): EndInfo; + moveToTargetPosition(): void; + onMainCharacterTeleport(): void; + postPhysicsUpdate(dt: number): void; + setNonMainCharacterTargetGrounded(grounded: boolean): void; + setTargetX(x: number): void; + setTargetY(y: number): void; + setTeleportCount(teleportCount: number): void; + update(dt: number): void; + } + + interface NonMainCharacterState { + grounded: boolean; + } + + interface Animation { + availableAnimations: string[]; + blinkTimer: number; + bodyAnimationLocked: boolean; + bodyAnimationStartedAt: number; + character: Character; + currentBodyAnimation: string; + currentEyeAnimation: string; + lastGroundedAnimationAt: number; + nonMainCharacterState: NonMainCharacterState; + prevNonMainCharacterState: NonMainCharacterState; + skinChanged: boolean; + destroy(): void; + onAnimationComplete(options: any): void; + onSkinChanged(): void; + playAnimationOrClearTrack(animations: string[], track: number): void; + playBodyAnimation(animation: string): void; + playBodySupplementalAnimation(animation: string): void; + playEyeAnimation(animation: string): void; + playJumpSupplementalAnimation(animation: string): void; + playMovementSupplementalAnimation(animation: string): void; + setupAnimations(): void; + startBlinkAnimation(): void; + stopBlinkAnimation(): void; + update(dt: number): void; + } + + interface ProjectileAppearance { + imageUrl: string; + rotateToTarget: boolean; + scale: number; + } + + interface WeaponAsset extends BaseAsset { + fireFrames: number[]; + fromCharacterCenterRadius: number; + hideFireSlash: boolean; + idleFrames: number; + originX: number; + originY: number; + } + + interface BaseAsset { + frameHeight: number; + frameRate: number; + frameWidth: number; + imageUrl: string; + scale: number; + } + + interface ImpactAsset extends BaseAsset { + frames: number[]; + hideIfNoHit?: boolean; + } + + interface SoundEffect { + path: string; + volume: number; + } + + interface CurrentAppearance { + id: string; + explosionSfx: SoundEffect[]; + fireSfx: SoundEffect[]; + impact: ImpactAsset; + projectile: ProjectileAppearance; + reloadSfx: SoundEffect; + weapon: WeaponAsset; + } + + interface AimingAndLookingAround { + angleTween?: import("phaser").Tweens.Tween; + character: Character; + currentAngle?: number; + currentAppearance?: CurrentAppearance; + currentWeaponId?: string; + isAiming: boolean; + lastUsedAngle: number; + sprite: import("phaser").GameObjects.Sprite; + targetAngle?: number; + characterShouldFlipX(): boolean; + destroy(): void; + isCurrentlyAiming(): boolean; + onInventoryStateChange(): void; + playFireAnimation(): void; + setImage(appearance: CurrentAppearance): void; + setSpriteParams(skipRecalculateAlpha: boolean): void; + setTargetAngle(angle: number, instant?: boolean): void; + update(): void; + updateAnotherCharacter(): void; + updateMainCharacterMouse(): void; + updateMainCharacterTouch(): void; + } + + interface ServerPosition { + packet: number; + x: number; + y: number; + jsonState: string; + teleport: boolean; + } + + interface Bodies { + character: Character; + collider: Collider; + colliderDesc: ColliderDesc; + rigidBody: RigidBody; + rigidBodyDesc: RigidBodyDesc; + } + + interface PhysicsInput { + _jumpKeyPressed: boolean; + activeClassDeviceId: string; + angle: number; + ignoredStaticBodies: Set; + ignoredTileBodies: Set; + jump: boolean; + projectileHitForcesQueue: Set; + } + + interface MovementState { + accelerationTicks: number; + direction: string; + xVelocity: number; + } + + interface Jump { + actuallyJumped: boolean; + isJumping: boolean; + jumpCounter: number; + jumpTicks: number; + jumpsLeft: number; + xVelocityAtJumpStart: number; + } + + interface PhysicsState { + forces: any[]; + gravity: number; + grounded: boolean; + groundedTicks: number; + jump: Jump; + lastGroundedAngle: number; + movement: MovementState; + velocity: Vector; + } + + interface Physics { + character: Character; + currentPacketId: number; + frameInputsHistory: Map; + justAppliedProjectileHitForces: Set; + lastClassDeviceActivationId: number; + lastPacketSent: number[]; + lastSentClassDeviceActivationId: number; + lastSentTerrainUpdateId: number; + lastTerrainUpdateId: number; + newlyAddedTileBodies: Set; + phase: boolean; + physicsBodyId: string; + prevState: PhysicsState; + projectileHitForcesHistory: Map; + projectileHitForcesQueue: Set; + scene: Scene; + state: PhysicsState; + tickInput: TickInput; + destroy(): void; + getBody(): Bodies; + postUpdate(dt: number): void; + preUpdate(): void; + sendToServer(): void; + setServerPosition(serverPosition: ServerPosition): void; + setupBody(x: number, y: number): void; + updateDebugGraphics(): void; + } + + interface Character { + aimingAndLookingAround: AimingAndLookingAround; + alpha: Alpha; + animation: Animation; + body: Vector; + characterTrail: CharacterTrail; + culling: Culling; + depth: Depth; + dimensions: Dimensions; + flip: Flip; + healthbar: Healthbar; + id: string; + immunity: Immunity; + impactAnimation: ImpactAnimation; + indicator: Indicator; + input: CharacterInput; + isActive: boolean; + isDestroyed: boolean; + isMain: boolean; + movement: Movement; + nametag: Nametag; + network: Network; + physics: Physics; + position: Position; + prevBody: Vector; + scale: Scale; + scene: Scene; + shadow: Shadow; + skin: Skin; + spine: any; + teamId: string; + tint: Tint; + type: string; + vfx: VFX; + destroy(): void; + setIsMain(isMain: boolean): void; + update(dt: number): void; + } + + interface UpdateCullOptions { + mainCharacter: Character; + isPhase: boolean; + insideView: boolean; + } - class EventEmitter2 { - constructor(options?: ConstructorOptions); - emit(event: event | eventNS, ...values: any[]): boolean; - emitAsync(event: event | eventNS, ...values: any[]): Promise; - addListener(event: event | eventNS, listener: ListenerFn): this | Listener; - on(event: event | eventNS, listener: ListenerFn, options?: boolean | OnOptions): this | Listener; - prependListener(event: event | eventNS, listener: ListenerFn, options?: boolean | OnOptions): this | Listener; - once(event: event | eventNS, listener: ListenerFn, options?: true | OnOptions): this | Listener; - prependOnceListener( - event: event | eventNS, - listener: ListenerFn, - options?: boolean | OnOptions, - ): this | Listener; - many( - event: event | eventNS, - timesToListen: number, - listener: ListenerFn, - options?: boolean | OnOptions, - ): this | Listener; - prependMany( - event: event | eventNS, - timesToListen: number, - listener: ListenerFn, - options?: boolean | OnOptions, - ): this | Listener; - onAny(listener: EventAndListener): this; - prependAny(listener: EventAndListener): this; - offAny(listener: ListenerFn): this; - removeListener(event: event | eventNS, listener: ListenerFn): this; - off(event: event | eventNS, listener: ListenerFn): this; - removeAllListeners(event?: event | eventNS): this; - setMaxListeners(n: number): void; - getMaxListeners(): number; - eventNames(nsAsArray?: boolean): (event | eventNS)[]; - listenerCount(event?: event | eventNS): number; - listeners(event?: event | eventNS): ListenerFn[]; - listenersAny(): ListenerFn[]; - waitFor(event: event | eventNS, timeout?: number): CancelablePromise; - waitFor(event: event | eventNS, filter?: WaitForFilter): CancelablePromise; - waitFor(event: event | eventNS, options?: WaitForOptions): CancelablePromise; - listenTo(target: GeneralEventEmitter, events: event | eventNS, options?: ListenToOptions): this; - listenTo(target: GeneralEventEmitter, events: event[], options?: ListenToOptions): this; - listenTo(target: GeneralEventEmitter, events: object, options?: ListenToOptions): this; - stopListeningTo(target?: GeneralEventEmitter, event?: event | eventNS): boolean; - hasListeners(event?: string): boolean; - static once(emitter: EventEmitter2, event: event | eventNS, options?: OnceOptions): CancelablePromise; - static defaultMaxListeners: number; + interface Cull { + device: Device; + ignoresCull: boolean; + isInsideView: boolean; + margin: number; + wasInsideView: boolean; + getMargin(): number; + ignoreCulling(): void; + setMargin(margin: number): void; + setOnEnterViewCallback(callback: () => void): void; + setOnLeaveViewCallback(callback: () => void): void; + onEnterViewCallback?(): void; + onLeaveViewCallback?(): void; + updateCull(options: UpdateCullOptions): void; + } + + type ColliderOptions = { + device: Device; + scene: Scene; + angle: number; + } & DeviceCollider; + + type DeviceCollider = RectShort | CircleShort | Ellipse; + + interface Colliders { + add: { + box(collider: RectShort): void; + circle(collider: CircleShort): void; + ellipse(collider: Ellipse): void; + }; + device: Device; + list: DeviceCollider[]; + createOptions(collider: DeviceCollider): ColliderOptions; + destroy(): void; + forEach(callback: (collider: DeviceCollider) => void): void; + hideDebug(): void; + showDebug(): void; + } + + interface Rect { + x: number; + y: number; + width: number; + height: number; + } + + interface BoundingBox { + cachedBoundingBox: Rect; + device: Device; + hardcodedBoundingBox?: Rect; + clearCached(): void; + clearHardcoded(): void; + getBoundingBox(): Rect; + isHardcoded(): boolean; + isInsideBoundingBox(x: number, y: number): boolean; + setHardcoded(rect: Rect): void; + } + + interface AppearanceVariation { + device: Device; + resetAppearance(): void; + setPreviewAppearance(): void; + setRemovalAppearance(): void; + } + + interface BaseDevice { + isPreview: boolean; + placedByClient: boolean; + isDestroyed: boolean; + x: number; + y: number; + forceUseMyState: boolean; + options: Record; + state: Record; + prevState: Record; + name: string; + id: string; + scene: Scene; + deviceOption: DeviceOption; + visualEditing: VisualEditing; + shadows: Shadows; + input: DeviceInput; + parts: any; + cull: Cull; + boundingBox: BoundingBox; + appearanceVariation: AppearanceVariation; + colliders: Colliders; + interactiveZones: InteractiveZones; + deviceUI: DeviceUI; + layers: Layers; + wirePoints: WirePoints; + tweens: DeviceTweens; + projectiles: DeviceProjectiles; + sensors: any; + onHide: (() => void) | null; + onShow: (() => void) | null; + onUpdate: (() => void) | null; + initialStateProcessing(state: Record): Record; + getMaxDepth(): number; + onStateUpdateFromServer(key: string, value: any): void; + getRealKey(key: string): string; + onPostUpdate(): void; + onInit(): void; + onMessage(message: { + key: string; + data: any; + }): void; + onStateChange(key: string): void; + onDestroy(options: { + isBeingReplaced: boolean; + }): void; + sendToServerDevice(key: string, data: any): void; + openDeviceUI(): void; + checkIfCollidersEnabled(): boolean; + destroy(options: { + isBeingReplaced: boolean; + }): void; + } + + type Device = BaseDevice & { + [key: string]: any; + }; + + interface Cameras { + allCameras: Device[]; + allCamerasNeedsUpdate: boolean; + camerasPlayerIsInside: any[]; + scene: Scene; + wasInPrePhase: boolean; + findNewCameras(allCameras: Device[], x: number, y: number): any; + setCurrentCameraSizeDevice(device: Device): void; + switchToDefaultCameraSize(reset: boolean): void; + update(devices: Device[]): void; + } + + interface Devices { + allDevices: Device[]; + cameras: Cameras; + devicesAction: DevicesAction; + devicesPreview: DevicesPreview; + devicesToPostUpdate: Set; + devicesToUpdate: Set; + interactives: WorldInteractives; + scene: Scene; + visualEditingManager: any; + addDevice(device: Device): void; + cullDevices(): void; + findDeviceUnderMouse(): Device | undefined; + getDeviceById(id: string): Device | undefined; + hasDevice(id: string): boolean; + removeDeviceById(id: string, options: { + isBeingReplaced: boolean; + }): void; + update(dt: number): void; + } + + interface WorldManager { + devices: Devices; + inGameTerrainBuilder: InGameTerrainBuilder; + physics: PhysicsManager; + projectiles: Projectiles; + scene: Scene; + terrain: any; + wires: any; + update(dt: number): void; + } + + interface MovementPointer { + id: string; + x: number; + y: number; + downX: number; + downY: number; + } + + interface Mouse { + clickListeners: Map void>; + downX: number; + downY: number; + isHoldingDown: boolean; + movementPointer?: MovementPointer; + scene: Scene; + stopRunningClickHandlers: boolean; + worldX: number; + worldY: number; + x: number; + y: number; + addClickListener(options: { + callback: (pointer: import("phaser").Input.Pointer) => void; + }): () => void; + pointerUpdate(pointer: import("phaser").Input.Pointer): void; + removeClickListener(id: string): void; + shouldBecomeMovementPointer(pointer: import("phaser").Input.Pointer): boolean; + } + + interface KeyboardState { + isHoldingDown: boolean; + isHoldingLeft: boolean; + isHoldingRight: boolean; + isHoldingUp: boolean; + isHoldingSpace: boolean; + } + + interface Keyboard { + heldKeys: Set; + scene: Scene; + state: KeyboardState; + createListeners(): void; + isKeyDown(key: number): boolean; + } + + interface PressedKeys { + up: boolean; + down: boolean; + left: boolean; + right: boolean; + } + + interface Cursor { + scene: Scene; + createStateListeners(): void; + updateCursor(): void; + } + + interface AimCursor { + aimCursor: import("phaser").GameObjects.Sprite; + aimCursorWorldPos: Vector; + centerShiftX: number; + centerShiftY: number; + scene: Scene; + x: number; + y: number; + update(): void; + } + + interface TickInput { + angle: number | null; + jump: boolean; + _jumpKeyPressed: boolean; + } + + interface InputManager { + aimCursor: AimCursor; + currentInput: TickInput; + cursor: Cursor; + isListeningForInput: boolean; + jumpedSinceLastPhysicsFetch: boolean; + keyboard: Keyboard; + mouse: Mouse; + physicsInputHandledBetweenUpdates: boolean; + scene: Scene; + getAimingDirection(): Vector; + getInputAngle(): number | null; + getKeys(): PressedKeys; + getMouseWorldXY(): Vector; + getPhysicsInput(): TickInput; + refreshInput(): void; + update(): void; + } + + interface Scene extends BaseScene { + actionManager: ActionManager; + cameraHelper: any; + characterManager: CharacterManager; + dt: number; + inputManager: InputManager; + resizeManager: any; + shadowsManager: any; + spine: any; + tileManager: TileManager; + uiManager: any; + worldManager: WorldManager; + create(): void; + } + + interface Phaser { + mainCharacter: Character; + mainCharacterTeleported: boolean; + scene: Scene; + } + + interface NetworkStore { + attemptingToConnect: boolean; + attemptingToReconnect: boolean; + authId: string; + client: any; + clientConnectionString: string; + error: any; + errorFindingServerForGame: boolean; + errorJoiningRoom: boolean; + failedToReconnect: boolean; + findingServerForGame: boolean; + hasJoinedRoom: boolean; + isOffline: boolean; + isUpToDateWithPingPong: boolean; + joinedRoom: boolean; + phaseBeforeReconnect: string | null; + ping: number; + room: any; + roomIntentErrorMessage: string; + syncingAfterReconnection: boolean; + } + + interface Matchmaker { + gameCode: string; + } + + interface Loading { + completedInitialLoad: boolean; + loadedInitialDevices: boolean; + loadedInitialTerrain: boolean; + percentageAssetsLoaded: number; + } + + interface Hooks { + hookJSON: string; + } + + interface EditingStore { + accessPoints: Map; + gridSnap: number; + showMemoryBarAtAllTimes: boolean; + } + + interface Assignment { + hasSavedProgress: boolean; + objective: string; + percentageComplete: number; + } + + interface ActivityFeed { + feedItems: { + id: string; + message: string; + }[]; + } + + interface CustomAssetOption { + id: string; + maxOnMap: number; + memoryCost: number; + minimumRoleLevel?: number; + validate: any; + } + + interface TerrainOption { + id: string; + name: string; + maskTilesUrl: string; + borderTilesUrl: string; + fillUrl: string; + blockedMapStyles?: string[]; + seasonTicketRequired?: boolean; + previewUrl: string; + health?: number; + minimumRoleLevel?: number; + } + + interface SkinOption { + id: string; + name: string; + minimumRoleLevel?: number; + } + + interface CircleShort { + x: number; + y: number; + r: number; + } + + interface RectShort { + x: number; + y: number; + w: number; + h: number; + } + + interface RotatedRectShort extends RectShort { + angle: number; + } + + interface RotatedEllipse extends Ellipse { + angle: number; + } + + interface Ellipse { + x: number; + y: number; + r1: number; + r2: number; + } + + interface PropOption { + id: string; + name: string; + scaleMultip: number; + originX: number; + originY: number; + imageUrl: string; + rectColliders: RotatedRectShort[]; + circleColliders: CircleShort[]; + ellipseColliders: RotatedEllipse[]; + shadows: Ellipse[]; + seasonTicketRequired?: boolean; + minimumRoleLevel?: number; + defaultLayer?: string; + } + + interface WeaponShared { + cooldownBetweenShots: number; + allowAutoFire: boolean; + startingProjectileDistanceFromCharacter: number; + } + + interface Weapon { + type: string; + appearance: string; + shared: WeaponShared; + bullet?: { + ammoItemId: string; + }; + } + + interface ItemOption { + type: string; + id: string; + name: string; + editorName: string; + description: string; + previewImage: string; + rarity?: string; + weapon?: Weapon; + minimumRoleLevel?: number; + useCommand?: string; + consumeType?: string; + terrainId?: string; + maxStackSize?: number; + } + + interface OptionSchema { + options: any[]; + categories?: any[]; + } + + interface DeviceInfo { + id: string; + name: string; + description?: string; + optionSchema: OptionSchema; + defaultState: any; + codeGridSchema: CodeGridSchema; + wireConfig?: any; + minimumRoleLevel?: number; + maxOnMap?: number; + initialMemoryCost?: number; + subsequentMemoryCost?: number; + supportedMapStyles?: string[]; + seasonTicketRequired?: boolean; + maximumRoleLevel?: number; + } + + interface CodeGrids { + blockCategories: string; + customBlocks: string; + customBlocksParsed: any[]; + } + + interface WorldOptions { + codeGrids: CodeGrids; + customAssetsOptions: CustomAssetOption[]; + deviceOptions: DeviceInfo[]; + hasAllProps: boolean; + itemOptions: ItemOption[]; + propsOptions: PropOption[]; + skinOptions: SkinOption[]; + terrainOptions: TerrainOption[]; + } + + interface Limits { + blocksPerCodeGrid: number; + codeGrids: number; + codeGridsPerDevice: number; + collidingTiles: number; + customAssetOnMapDefault: number; + deviceMaxOnMapDefault: number; + nonCollidingTiles: number; + wires: number; + } + + interface Counters { + codeGrids: number; + collidingTiles: number; + customAssets: Map; + devices: Map; + nonCollidingTiles: number; + wires: number; + } + + interface Costs { + codeGrid: number; + collidingTile: number; + customAssetDefault: number; + deviceInitialDefault: number; + deviceSubsequentDefault: number; + nonCollidingTile: number; + wire: number; + } + + interface MemorySystem { + costs: Costs; + counters: Counters; + limits: Limits; + maxUsedMemory: number; + usedMemoryCost: number; + } + + interface CharacterData { + allowWeaponFire: boolean; + existsBeforeReconnect: boolean; + fragility: number; + health: number; + id: string; + isActive: boolean; + lastPlayersTeamId: string; + name: string; + permissions: Permissions; + score: number; + teamId: string; + type: string; + } + + interface Characters { + characters: Map; + } + + interface Scorebar { + teamColors: string[]; + teams: string[]; + } + + interface NoneGui { + addMenu: { + screen: string; + }; + duringGameScreenVisible: boolean; + optionsMenu: { + screen: string; + }; + screen: string; + } + + interface Modals { + closeAllModals: () => void; + cosmosModalOpen: boolean; + switchToRegisterScreenWhenCosmosModalOpens: boolean; + } + + interface KnockoutAlert { + id: string; + name: string; + } + + interface GuiSlot { + id: string; + position: string; + text: string; + trackedItemId: any; + showTrackedItemMaximumAmount: boolean; + type: string; + priority: number; + color: string; + } + + interface DamageIndicator { + show: boolean; + /** `h` for red, `s` for blue, and any other string for yellow. */ + type: string; + } + + interface BottomInGamePrimaryContent { + interactionWantsToBeVisible: boolean; + prioritizeInteraction: boolean; + } + + interface Achievement { + id: string; + key: string; + reset: () => void; + update: () => void; + } + + interface GUI { + achievement: Achievement; + bottomInGamePrimaryContent: BottomInGamePrimaryContent; + damageIndicator: DamageIndicator; + guiSlots: GuiSlot[]; + guiSlotsChangeCounter: number; + knockoutAlerts: KnockoutAlert[]; + modals: Modals; + none: NoneGui; + openInputBlockingUI: string[]; + playersManagerUpdateCounter: number; + scale: number; + scorebar?: Scorebar; + selectedPlayerId: string; + showingGrid: boolean; + } + + interface Permissions { + adding: boolean; + editing: boolean; + manageCodeGrids: boolean; + removing: boolean; + } + + interface GameSession { + callToAction: any; + countdownEnd: number; + phase: string; + resultsEnd: number; + widgets: { + widgets: any[]; + }; + } + + interface Session { + allowGoogleTranslate: boolean; + amIGameOwner: boolean; + canAddGameTime: boolean; + cosmosBlocked: boolean; + customTeams: { + characterToTeamMap: Map; + }; + duringTransition: boolean; + gameClockDuration: string; + gameOwnerId: string; + gameSession: GameSession; + gameTime: number; + gameTimeLastUpdateAt: number; + globalPermissions: Permissions; + loadingPhase: boolean; + mapCreatorRoleLevel: number; + mapStyle: string; + modeType: string; + ownerRole: string; + phase: string; + phaseChangedAt: number; + version: string; + } + + interface ZoneDropOverrides { + allowItemDrop: boolean; + allowResourceDrop: boolean; + allowWeaponDrop: boolean; + } + + interface XPAddition { + amount: number; + reason: string; + xp: number; + } + + interface XP { + additionTimeouts: Map>; + additions: XPAddition[]; + showingLevelUp: boolean; + } + + interface MeSpectating { + id: string; + name: string; + shuffle: boolean; + } + + interface TileToRemove { + depth: number; + id: string; + x: number; + y: number; + } + + interface Removing { + deviceIdToRemove?: string; + removingMode: string; + removingTilesEraserSize: number; + removingTilesLayer: number; + removingTilesMode: string; + tilesToRemove: TileToRemove[]; + wireIdToRemove?: string; + } + + interface NonDismissMessage { + description: string; + title: string; + } + + interface Mood { + activeDeviceId: string; + vignetteActive: boolean; + vignetteStrength: number; + } + + interface MobileControls { + left: boolean; + right: boolean; + up: boolean; + } + + interface InventorySlot { + amount: number; + existsBeforeReconnect: boolean; + } + + interface AlertFeed { + amount: number; + itemId: string; + } + + interface InteractiveSlot { + clipSize: number; + count: number; + currentClip: number; + durability: number; + itemId: string; + waiting: boolean; + waitingEndTime: number; + waitingStartTime: number; + } + + interface Inventory { + activeInteractiveSlot: number; + alertFeed?: AlertFeed; + alertsFeed: AlertFeed[]; + currentWaitingEndTime: number; + infiniteAmmo: boolean; + interactiveSlotErrorMessageTimeouts: Map>; + interactiveSlotErrorMessages: Map; + interactiveSlots: Map; + interactiveSlotsOrder: number[]; + isCurrentWaitingSoundForItem: boolean; + lastShotsTimestamps: Map; + maxSlots: number; + slots: Map; + } + + interface InteractiveInfo { + action: string; + allowedToInteract: boolean; + message: string; + topHeader?: string; + topHeaderColor: string; + } + + interface Interactives { + deviceId: string; + info: InteractiveInfo; + } + + interface Health { + fragility: number; + health: number; + lives: number; + maxHealth: number; + maxShield: number; + shield: number; + } + + interface EditingPreferences { + cameraZoom: number; + movementSpeed: number | null; + phase: boolean | null; + showGrid: boolean | null; + topDownControlsActive: boolean; + } + + interface CurrentlyEditedDevice { + deviceOptionId: string; + id: string; + } + + interface EditingDevice { + currentlyEditedDevice: CurrentlyEditedDevice; + currentlyEditedGridId: string; + currentlySortedDeviceId: string; + screen: string; + sortingState: any[]; + usingMultiselect: boolean; + visualEditing: any; + } + + interface Editing { + device: EditingDevice; + preferences: EditingPreferences; + wire: { + currentlyEditedWireId: string; + }; + } + + interface MeDeviceUI { + current: { + deviceId: string; + props: any; + }; + desiredOpenDeviceId?: string; + serverVersionOpenDeviceId: string; + } + + interface MeCustomAssets { + currentData?: { + shapes: Shapes; + }; + currentIcon: string; + currentId: string; + currentName: string; + currentOptionId: string; + isUIOpen: boolean; + openOptionId: string | null; + pendingDeleteId: string | null; + showDeleteConfirm: boolean; + } + + interface Context { + cursorIsOverCharacterId: string; + __devicesUnderCursor: string[]; + __wiresUnderCursor: Set; + cursorIsOverDevice: boolean; + cursorIsOverWire: boolean; + } + + interface ClassDesigner { + activeClassDeviceId: string; + lastActivatedClassDeviceId: string; + lastClassDeviceActivationId: number; + } + + interface CinematicMode { + charactersVisible: boolean; + enabled: boolean; + followingMainCharacter: boolean; + hidingGUI: boolean; + mainCharacterVisible: boolean; + nameTagsVisible: boolean; + } + + interface AddingWires { + hoveringOverSupportedDevice: boolean; + pointUnderMouseDeviceId?: string; + startDeviceSelected: boolean; + } + + interface AddingTerrain { + brushSize: number; + buildTerrainAsWall: boolean; + currentlySelectedTerrain: string; + currentlySelectedTerrainDepth: number; + } + + interface ExistingDevice { + action: string; + id: string; + shiftX: number; + shiftY: number; + use: boolean; + } + + interface AddingDevices { + currentlySelectedProp: string; + existingDevice: ExistingDevice; + selectedDeviceType: string; + } + + interface Adding { + devices: AddingDevices; + terrain: AddingTerrain; + wires: AddingWires; + mode: string; + } + + interface Me { + adding: Adding; + cinematicMode: CinematicMode; + classDesigner: ClassDesigner; + completedInitialPlacement: boolean; + context: Context; + currentAction: string; + customAssets: MeCustomAssets; + deviceUI: MeDeviceUI; + editing: Editing; + gotKicked: boolean; + health: Health; + interactives: Interactives; + inventory: Inventory; + isRespawning: boolean; + mobileControls: MobileControls; + mood: Mood; + movementSpeed: number; + myTeam: string; + nonDismissMessage: NonDismissMessage; + phase: boolean; + preferences: { + startGameWithMode: string; + }; + properties: Map; + removing: Removing; + roleLevel: number; + spawnPosition: Vector; + spectating: MeSpectating; + teleportCount: number; + unredeemeedXP: number; + xp: XP; + zoneDropOverrides: ZoneDropOverrides; + } + + interface QueuedTile { + timestamp: number; + removedBodyIds: string[]; + } + + interface Tile { + collides: boolean; + depth: number; + terrain: string; + x: number; + y: number; + } + + interface Terrain { + currentTerrainUpdateId: number; + modifiedHealth: Map; + queuedTiles: Map; + teamColorTiles: Map; + tiles: Map; + } + + interface DeviceState { + deviceId: string; + properties: Map; + } + + interface CodeGridItem { + createdAt: number; + existsBeforeReconnect: boolean; + json: string; + triggerType: string; + owner?: string; + triggerValue?: string; + visitors: string[]; + } + + interface CodeGrid { + existsBeforeReconnect: boolean; + items: Map; + } + + interface CodeGridSchema { + allowChannelGrids: boolean; + customBlocks: any[]; + triggers: any[]; + } + + interface DeviceOption { + codeGridSchema: CodeGridSchema; + defaultState: any; + id: string; + optionSchema: { + options: any[]; + }; + wireConfig: any; + } + + interface DeviceData { + depth: number; + deviceOption: DeviceOption; + existsBeforeReconnect: boolean; + hooks: any; + id: string; + isPreview: boolean; + layerId: string; + name: any; + options: Record; + props: any; + x: number; + y: number; + } + + interface WorldDevices { + codeGrids: Map; + devices: Map; + states: Map; + } + + interface Shapes { + circles: number[][]; + lines: number[][]; + paths: number[][]; + rects: number[][]; + } + + interface CustomAsset { + data: { + shapes: Shapes; + }; + icon: string; + id: string; + name: string; + optionId: string; + } + + interface WorldCustomAssets { + customAssets: Map; + isUIOpen: boolean; + updateCounter: number; + } + + interface World { + customAssets: WorldCustomAssets; + devices: WorldDevices; + height: number; + width: number; + mapOptionsJSON: string; + terrain: Terrain; + wires: { + wires: Map; + }; + } + + interface Stores { + activityFeed: ActivityFeed; + assignment: Assignment; + characters: Characters; + editing: EditingStore; + gui: GUI; + hooks: Hooks; + loading: Loading; + matchmaker: Matchmaker; + me: Me; + memorySystem: MemorySystem; + network: NetworkStore; + phaser: Phaser; + scene: SceneStore; + session: Session; + teams: Teams; + world: World; + worldOptions: WorldOptions; + } } class PluginsApi { @@ -298,12 +2217,12 @@ declare namespace Gimloader { instead(object: any, method: string, callback: PatcherInsteadCallback): () => void; } - type PatcherInsteadCallback = (thisVal: any, args: IArguments) => void; + type PatcherAfterCallback = (thisVal: any, args: IArguments, returnVal: any) => any; // eslint-disable-next-line @typescript-eslint/no-invalid-void-type type PatcherBeforeCallback = (thisVal: any, args: IArguments) => boolean | void; - type PatcherAfterCallback = (thisVal: any, args: IArguments, returnVal: any) => any; + type PatcherInsteadCallback = (thisVal: any, args: IArguments) => void; class PatcherApi { /** @@ -403,10 +2322,8 @@ declare namespace Gimloader { removeStyles(id: string): void; } - class ScopedNetApi extends BaseNetApi { - private readonly id; - private readonly defaultGamemode; - constructor(id: string, defaultGamemode: string[]); + interface ScopedNetApi extends BaseNetApi { + new(id: string, defaultGamemode: string[]): this; /** * Runs a callback when the game is loaded, or runs it immediately if the game has already loaded. * If the \@gamemode header is set the callback will only fire if the gamemode matches one of the provided gamemodes. @@ -417,8 +2334,8 @@ declare namespace Gimloader { type ConnectionType = "None" | "Colyseus" | "Blueboat"; - class BaseNetApi extends EventEmitter2 { - constructor(); + interface BaseNetApi extends EventEmitter2 { + new(): this; /** Which type of server the client is currently connected to */ get type(): ConnectionType; /** The id of the gamemode the player is currently playing */ @@ -431,8 +2348,8 @@ declare namespace Gimloader { send(channel: string, message: any): void; } - class NetApi extends BaseNetApi { - constructor(); + interface NetApi extends BaseNetApi { + new(): this; /** * Runs a callback when the game is loaded, or runs it immediately if the game has already loaded * @returns A function to cancel waiting for load @@ -454,8 +2371,7 @@ declare namespace Gimloader { * @hidden */ get blueboat(): this; - /** @hidden */ - private wrappedListeners; + /** * @deprecated use net.on * @hidden @@ -653,7 +2569,7 @@ declare namespace Gimloader { /** Gimkit's internal reactDom instance */ static get ReactDOM(): typeof import("react-dom/client"); /** A variety of Gimkit internal objects available in 2d gamemodes */ - static get stores(): any; + static get stores(): Stores.Stores; /** * Gimkit's notification object, only available when joining or playing a game * @@ -722,7 +2638,7 @@ declare namespace Gimloader { /** Gimkit's internal reactDom instance */ get ReactDOM(): typeof import("react-dom/client"); /** A variety of gimkit internal objects available in 2d gamemodes */ - get stores(): any; + get stores(): Stores.Stores; /** * Gimkit's notification object, only available when joining or playing a game * @@ -743,7 +2659,7 @@ declare namespace Gimloader { declare const api: Gimloader.Api; declare const GL: typeof Gimloader.Api; /** @deprecated Use GL.stores */ -declare const stores: any; +declare const stores: Gimloader.Stores.Stores; /** @deprecated No longer supported */ declare const platformerPhysics: any; @@ -751,7 +2667,7 @@ interface Window { api: Gimloader.Api; GL: typeof Gimloader.Api; /** @deprecated Use GL.stores */ - stores: any; + stores: Gimloader.Stores.Stores; /** @deprecated No longer supported */ platformerPhysics: any; } diff --git a/types/gimloader/package.json b/types/gimloader/package.json index 8991085684f142..332b53d93662d6 100644 --- a/types/gimloader/package.json +++ b/types/gimloader/package.json @@ -9,7 +9,10 @@ ], "dependencies": { "@types/react": "*", - "@types/react-dom": "*" + "@types/react-dom": "*", + "phaser": "~3.90.0", + "@dimforge/rapier2d-compat": "~0.17.2", + "eventemitter2": "~6.4.9" }, "devDependencies": { "@types/gimloader": "workspace:." diff --git a/types/gimloader/tsconfig.json b/types/gimloader/tsconfig.json index b16298e1f1b900..dd0f797f09ec99 100644 --- a/types/gimloader/tsconfig.json +++ b/types/gimloader/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "module": "node16", + "module": "commonjs", "lib": [ "es6", "DOM" From 0097397d3611dbc6a560311c4bcf2147e8c168ba Mon Sep 17 00:00:00 2001 From: Dolan Murvihill Date: Mon, 20 Oct 2025 17:38:43 -0700 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#73938=20[expec?= =?UTF-8?q?t-cookies]=20Add=20co-owner=20@gregl83=20by=20@dmurvihill?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/expect-cookies/package.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/types/expect-cookies/package.json b/types/expect-cookies/package.json index df0394b81e2e98..1ecb85534ab2e8 100644 --- a/types/expect-cookies/package.json +++ b/types/expect-cookies/package.json @@ -14,6 +14,10 @@ { "name": "Dolan Murvihill", "githubUsername": "dmurvihill" + }, + { + "name": "Gregory Langlais", + "githubUsername": "gregl83" } ] }