Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[node] Update typings to v22.12.0 #71386

Merged
merged 9 commits into from
Jan 28, 2025
Merged
1 change: 1 addition & 0 deletions types/node/dgram.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ declare module "dgram" {
interface SocketOptions extends Abortable {
type: SocketType;
reuseAddr?: boolean | undefined;
reusePort?: boolean | undefined;
/**
* @default false
*/
Expand Down
3 changes: 0 additions & 3 deletions types/node/fs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3845,9 +3845,6 @@ declare module "fs" {
flush?: boolean | undefined;
}
/**
* Unlike the 16 KiB default `highWaterMark` for a `stream.Readable`, the stream
* returned by this method has a default `highWaterMark` of 64 KiB.
*
* `options` can include `start` and `end` values to read a range of bytes from
* the file instead of the entire file. Both `start` and `end` are inclusive and
* start counting at 0, allowed values are in the
Expand Down
11 changes: 6 additions & 5 deletions types/node/net.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,17 +486,18 @@ declare module "net" {
prependOnceListener(event: "timeout", listener: () => void): this;
}
interface ListenOptions extends Abortable {
port?: number | undefined;
host?: string | undefined;
backlog?: number | undefined;
path?: string | undefined;
exclusive?: boolean | undefined;
readableAll?: boolean | undefined;
writableAll?: boolean | undefined;
host?: string | undefined;
/**
* @default false
*/
ipv6Only?: boolean | undefined;
reusePort?: boolean | undefined;
path?: string | undefined;
port?: number | undefined;
readableAll?: boolean | undefined;
writableAll?: boolean | undefined;
}
interface ServerOpts {
/**
Expand Down
2 changes: 1 addition & 1 deletion types/node/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@types/node",
"version": "22.10.9999",
"version": "22.12.9999",
"nonNpm": "conflict",
"nonNpmDescription": "Node.js",
"projects": [
Expand Down
115 changes: 115 additions & 0 deletions types/node/sqlite.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,40 @@ declare module "node:sqlite" {
* @default false
*/
enableDoubleQuotedStringLiterals?: boolean | undefined;
/**
* If `true`, the database is opened in read-only mode.
* If the database does not exist, opening it will fail.
* @since v22.12.0
* @default false
*/
readOnly?: boolean | undefined;
}
interface CreateSessionOptions {
/**
* A specific table to track changes for. By default, changes to all tables are tracked.
* @since v22.12.0
*/
table?: string | undefined;
/**
* Name of the database to track. This is useful when multiple databases have been added using
* [`ATTACH DATABASE`](https://www.sqlite.org/lang_attach.html).
* @since v22.12.0
* @default 'main'
*/
db?: string | undefined;
}
interface ApplyChangesetOptions {
/**
* Skip changes that, when targeted table name is supplied to this function, return a truthy value.
* By default, all changes are attempted.
* @since v22.12.0
*/
filter?: ((tableName: string) => boolean) | undefined;
/**
* Determines how conflicts are handled. **Default**: `SQLITE_CHANGESET_ABORT`.
* @since v22.12.0
*/
onConflict?: number | undefined;
}
/**
* This class represents a single [connection](https://www.sqlite.org/c3ref/sqlite3.html) to a SQLite database. All APIs
Expand Down Expand Up @@ -114,6 +148,72 @@ declare module "node:sqlite" {
* @return The prepared statement.
*/
prepare(sql: string): StatementSync;
/**
* Creates and attaches a session to the database. This method is a wrapper around
* [`sqlite3session_create()`](https://www.sqlite.org/session/sqlite3session_create.html) and
* [`sqlite3session_attach()`](https://www.sqlite.org/session/sqlite3session_attach.html).
* @param options The configuration options for the session.
* @returns A session handle.
* @since v22.12.0
*/
createSession(options?: CreateSessionOptions): Session;
/**
* An exception is thrown if the database is not
* open. This method is a wrapper around
* [`sqlite3changeset_apply()`](https://www.sqlite.org/session/sqlite3changeset_apply.html).
*
* ```js
* const sourceDb = new DatabaseSync(':memory:');
* const targetDb = new DatabaseSync(':memory:');
*
* sourceDb.exec('CREATE TABLE data(key INTEGER PRIMARY KEY, value TEXT)');
* targetDb.exec('CREATE TABLE data(key INTEGER PRIMARY KEY, value TEXT)');
*
* const session = sourceDb.createSession();
*
* const insert = sourceDb.prepare('INSERT INTO data (key, value) VALUES (?, ?)');
* insert.run(1, 'hello');
* insert.run(2, 'world');
*
* const changeset = session.changeset();
* targetDb.applyChangeset(changeset);
* // Now that the changeset has been applied, targetDb contains the same data as sourceDb.
* ```
* @param changeset A binary changeset or patchset.
* @param options The configuration options for how the changes will be applied.
* @returns Whether the changeset was applied succesfully without being aborted.
* @since v22.12.0
*/
applyChangeset(changeset: Uint8Array, options?: ApplyChangesetOptions): boolean;
}
/**
* @since v22.12.0
*/
interface Session {
/**
* Retrieves a changeset containing all changes since the changeset was created. Can be called multiple times.
* An exception is thrown if the database or the session is not open. This method is a wrapper around
* [`sqlite3session_changeset()`](https://www.sqlite.org/session/sqlite3session_changeset.html).
* @returns Binary changeset that can be applied to other databases.
* @since v22.12.0
*/
changeset(): Uint8Array;
/**
* Similar to the method above, but generates a more compact patchset. See
* [Changesets and Patchsets](https://www.sqlite.org/sessionintro.html#changesets_and_patchsets)
* in the documentation of SQLite. An exception is thrown if the database or the session is not open. This method is a
* wrapper around
* [`sqlite3session_patchset()`](https://www.sqlite.org/session/sqlite3session_patchset.html).
* @returns Binary patchset that can be applied to other databases.
* @since v22.12.0
*/
patchset(): Uint8Array;
/**
* Closes the session. An exception is thrown if the database or the session is not open. This method is a
* wrapper around
* [`sqlite3session_delete()`](https://www.sqlite.org/session/sqlite3session_delete.html).
*/
close(): void;
}
type SupportedValueType = null | number | bigint | string | Uint8Array;
interface StatementResultingChanges {
Expand Down Expand Up @@ -231,4 +331,19 @@ declare module "node:sqlite" {
*/
readonly sourceSQL: string;
}
/**
* Conflicting changes are omitted.
* @since v22.12.0
*/
const SQLITE_CHANGESET_OMIT: number;
/**
* Conflicting changes replace existing values.
* @since v22.12.0
*/
const SQLITE_CHANGESET_REPLACE: number;
/**
* Abort when a change encounters a conflict and roll back databsase.
* @since v22.12.0
*/
const SQLITE_CHANGESET_ABORT: number;
}
1 change: 1 addition & 0 deletions types/node/test/dgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as net from "node:net";
ds = dgram.createSocket({
type: "udp4",
reuseAddr: true,
reusePort: true,
recvBufferSize: 1000,
sendBufferSize: 1000,
lookup: dns.lookup,
Expand Down
1 change: 1 addition & 0 deletions types/node/test/net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import * as net from "node:net";

server.listen({
ipv6Only: true,
reusePort: true,
signal: new AbortSignal(),
});

Expand Down
18 changes: 18 additions & 0 deletions types/node/test/sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,21 @@ import { TextEncoder } from "node:util";
statement.expandedSQL; // $ExpectType string
statement.sourceSQL; // $ExpectType string
}

{
const sourceDb = new DatabaseSync(":memory:");
const targetDb = new DatabaseSync(":memory:");

sourceDb.exec("CREATE TABLE data(key INTEGER PRIMARY KEY, value TEXT)");
targetDb.exec("CREATE TABLE data(key INTEGER PRIMARY KEY, value TEXT)");

const session = sourceDb.createSession();

const insert = sourceDb.prepare("INSERT INTO data (key, value) VALUES (?, ?)");
insert.run(1, "hello");
insert.run(2, "world");

const changeset = session.changeset();
targetDb.applyChangeset(changeset);
// Now that the changeset has been applied, targetDb contains the same data as sourceDb.
}
27 changes: 18 additions & 9 deletions types/node/test/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,19 @@ const errorMap: Map<number, [string, string]> = util.getSystemErrorMap();
const foo: string = util.toUSVString("foo");
}

access("file/that/does/not/exist", (err) => {
const name = util.getSystemErrorName(err!.errno!);
console.error(name);
});
{
access("file/that/does/not/exist", (err) => {
const name = util.getSystemErrorName(err!.errno!);
console.error(name);
});
}

{
access("file/that/does/not/exist", (err) => {
const name = util.getSystemErrorMessage(err!.errno!);
console.error(name); // no such file or directory
});
}

{
util.stripVTControlCharacters("\u001B[4mvalue\u001B[0m"); // $ExpectType string
Expand Down Expand Up @@ -437,12 +446,12 @@ access("file/that/does/not/exist", (err) => {
}

{
// $ExpectType StacktraceObject[]
util.getCallSite();
// $ExpectType StacktraceObject[]
util.getCallSite(100);
// $ExpectType CallSiteObject[]
util.getCallSites();
// $ExpectType CallSiteObject[]
util.getCallSites(100);

const callSites = util.getCallSite();
const callSites = util.getCallSites();

console.log("Call Sites:");
callSites.forEach((callSite, index) => {
Expand Down
3 changes: 3 additions & 0 deletions types/node/test/util_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ if (types.isArrayBufferView(object)) {
if (types.isBigInt64Array(object)) {
object; // $ExpectType BigInt64Array || BigInt64Array<ArrayBufferLike>
}
if (types.isBigIntObject(object)) {
object; // $ExpectType BigInt
}
if (types.isBigUint64Array(object)) {
object; // $ExpectType BigUint64Array || BigUint64Array<ArrayBufferLike>
}
Expand Down
42 changes: 34 additions & 8 deletions types/node/util.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ declare module "util" {
export interface InspectOptionsStylized extends InspectOptions {
stylize(text: string, styleType: Style): string;
}
export interface StacktraceObject {
export interface CallSiteObject {
/**
* Returns the name of the function associated with this stack frame.
* Returns the name of the function associated with this call site.
*/
functionName: string;
/**
* Returns the name of the resource that contains the script for the
* function for this StackFrame.
* function for this call site.
*/
scriptName: string;
/**
Expand Down Expand Up @@ -186,14 +186,14 @@ declare module "util" {
*/
export function formatWithOptions(inspectOptions: InspectOptions, format?: any, ...param: any[]): string;
/**
* Returns an array of stacktrace objects containing the stack of
* Returns an array of call site objects containing the stack of
* the caller function.
*
* ```js
* const util = require('node:util');
*
* function exampleFunction() {
* const callSites = util.getCallSite();
* const callSites = util.getCallSites();
*
* console.log('Call Sites:');
* callSites.forEach((callSite, index) => {
Expand Down Expand Up @@ -225,12 +225,12 @@ declare module "util" {
*
* anotherFunction();
* ```
* @param frames Number of frames returned in the stacktrace.
* @param frameCount Number of frames to capture as call site objects.
* **Default:** `10`. Allowable range is between 1 and 200.
* @return An array of stacktrace objects
* @return An array of call site objects
* @since v22.9.0
*/
export function getCallSite(frames?: number): StacktraceObject[];
export function getCallSites(frameCount?: number): CallSiteObject[];
/**
* Returns the string name for a numeric error code that comes from a Node.js API.
* The mapping between error codes and error names is platform-dependent.
Expand Down Expand Up @@ -260,6 +260,20 @@ declare module "util" {
* @since v16.0.0, v14.17.0
*/
export function getSystemErrorMap(): Map<number, [string, string]>;
/**
* Returns the string message for a numeric error code that comes from a Node.js
* API.
* The mapping between error codes and string messages is platform-dependent.
*
* ```js
* fs.access('file/that/does/not/exist', (err) => {
* const name = util.getSystemErrorMessage(err.errno);
* console.error(name); // no such file or directory
* });
* ```
* @since v22.12.0
*/
export function getSystemErrorMessage(err: number): string;
/**
* The `util.log()` method prints the given `string` to `stdout` with an included
* timestamp.
Expand Down Expand Up @@ -1917,6 +1931,18 @@ declare module "util/types" {
* @since v10.0.0
*/
function isBigInt64Array(value: unknown): value is BigInt64Array;
/**
* Returns `true` if the value is a BigInt object, e.g. created
* by `Object(BigInt(123))`.
*
* ```js
* util.types.isBigIntObject(Object(BigInt(123))); // Returns true
* util.types.isBigIntObject(BigInt(123)); // Returns false
* util.types.isBigIntObject(123); // Returns false
* ```
* @since v10.4.0
*/
function isBigIntObject(object: unknown): object is BigInt;
/**
* Returns `true` if the value is a `BigUint64Array` instance.
*
Expand Down
Loading