Skip to content

Commit f4c5d1d

Browse files
authored
🤖 Merge PR DefinitelyTyped#74660 node: v25.6 by @Renegade334
1 parent 9edb84e commit f4c5d1d

File tree

14 files changed

+181
-37
lines changed

14 files changed

+181
-37
lines changed

types/node/async_hooks.d.ts

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -123,37 +123,31 @@ declare module "node:async_hooks" {
123123
function triggerAsyncId(): number;
124124
interface HookCallbacks {
125125
/**
126-
* Called when a class is constructed that has the possibility to emit an asynchronous event.
127-
* @param asyncId A unique ID for the async resource
128-
* @param type The type of the async resource
129-
* @param triggerAsyncId The unique ID of the async resource in whose execution context this async resource was created
130-
* @param resource Reference to the resource representing the async operation, needs to be released during destroy
126+
* The [`init` callback](https://nodejs.org/docs/latest-v25.x/api/async_hooks.html#initasyncid-type-triggerasyncid-resource).
131127
*/
132128
init?(asyncId: number, type: string, triggerAsyncId: number, resource: object): void;
133129
/**
134-
* When an asynchronous operation is initiated or completes a callback is called to notify the user.
135-
* The before callback is called just before said callback is executed.
136-
* @param asyncId the unique identifier assigned to the resource about to execute the callback.
130+
* The [`before` callback](https://nodejs.org/docs/latest-v25.x/api/async_hooks.html#beforeasyncid).
137131
*/
138132
before?(asyncId: number): void;
139133
/**
140-
* Called immediately after the callback specified in `before` is completed.
141-
*
142-
* If an uncaught exception occurs during execution of the callback, then `after` will run after the `'uncaughtException'` event is emitted or a `domain`'s handler runs.
143-
* @param asyncId the unique identifier assigned to the resource which has executed the callback.
134+
* The [`after` callback](https://nodejs.org/docs/latest-v25.x/api/async_hooks.html#afterasyncid).
144135
*/
145136
after?(asyncId: number): void;
146137
/**
147-
* Called when a promise has resolve() called. This may not be in the same execution id
148-
* as the promise itself.
149-
* @param asyncId the unique id for the promise that was resolve()d.
138+
* The [`promiseResolve` callback](https://nodejs.org/docs/latest-v25.x/api/async_hooks.html#promiseresolveasyncid).
150139
*/
151140
promiseResolve?(asyncId: number): void;
152141
/**
153-
* Called after the resource corresponding to asyncId is destroyed
154-
* @param asyncId a unique ID for the async resource
142+
* The [`destroy` callback](https://nodejs.org/docs/latest-v25.x/api/async_hooks.html#destroyasyncid).
155143
*/
156144
destroy?(asyncId: number): void;
145+
/**
146+
* Whether the hook should track `Promise`s. Cannot be `false` if
147+
* `promiseResolve` is set.
148+
* @default true
149+
*/
150+
trackPromises?: boolean | undefined;
157151
}
158152
interface AsyncHook {
159153
/**
@@ -174,7 +168,8 @@ declare module "node:async_hooks" {
174168
*
175169
* All callbacks are optional. For example, if only resource cleanup needs to
176170
* be tracked, then only the `destroy` callback needs to be passed. The
177-
* specifics of all functions that can be passed to `callbacks` is in the `Hook Callbacks` section.
171+
* specifics of all functions that can be passed to `callbacks` is in the
172+
* [Hook Callbacks](https://nodejs.org/docs/latest-v25.x/api/async_hooks.html#hook-callbacks) section.
178173
*
179174
* ```js
180175
* import { createHook } from 'node:async_hooks';
@@ -202,12 +197,13 @@ declare module "node:async_hooks" {
202197
* ```
203198
*
204199
* Because promises are asynchronous resources whose lifecycle is tracked
205-
* via the async hooks mechanism, the `init()`, `before()`, `after()`, and`destroy()` callbacks _must not_ be async functions that return promises.
200+
* via the async hooks mechanism, the `init()`, `before()`, `after()`, and
201+
* `destroy()` callbacks _must not_ be async functions that return promises.
206202
* @since v8.1.0
207-
* @param callbacks The `Hook Callbacks` to register
208-
* @return Instance used for disabling and enabling hooks
203+
* @param options The [Hook Callbacks](https://nodejs.org/docs/latest-v25.x/api/async_hooks.html#hook-callbacks) to register
204+
* @returns Instance used for disabling and enabling hooks
209205
*/
210-
function createHook(callbacks: HookCallbacks): AsyncHook;
206+
function createHook(options: HookCallbacks): AsyncHook;
211207
interface AsyncResourceOptions {
212208
/**
213209
* The ID of the execution context that created this async event.

types/node/buffer.buffer.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ declare module "node:buffer" {
174174
* If `totalLength` is not provided, it is calculated from the `Buffer` instances
175175
* in `list` by adding their lengths.
176176
*
177-
* If `totalLength` is provided, it is coerced to an unsigned integer. If the
177+
* If `totalLength` is provided, it must be an unsigned integer. If the
178178
* combined length of the `Buffer`s in `list` exceeds `totalLength`, the result is
179179
* truncated to `totalLength`. If the combined length of the `Buffer`s in `list` is
180180
* less than `totalLength`, the remaining space is filled with zeros.

types/node/net.d.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ declare module "node:net" {
3838
keepAlive?: boolean | undefined;
3939
keepAliveInitialDelay?: number | undefined;
4040
blockList?: BlockList | undefined;
41+
typeOfService?: number | undefined;
4142
}
4243
interface OnReadOpts {
4344
buffer: Uint8Array | (() => Uint8Array);
@@ -231,6 +232,37 @@ declare module "node:net" {
231232
* @return The socket itself.
232233
*/
233234
setKeepAlive(enable?: boolean, initialDelay?: number): this;
235+
/**
236+
* Returns the current Type of Service (TOS) field for IPv4 packets or Traffic
237+
* Class for IPv6 packets for this socket.
238+
*
239+
* `setTypeOfService()` may be called before the socket is connected; the value
240+
* will be cached and applied when the socket establishes a connection.
241+
* `getTypeOfService()` will return the currently set value even before connection.
242+
*
243+
* On some platforms (e.g., Linux), certain TOS/ECN bits may be masked or ignored,
244+
* and behavior can differ between IPv4 and IPv6 or dual-stack sockets. Callers
245+
* should verify platform-specific semantics.
246+
* @since v25.6.0
247+
* @returns The current TOS value.
248+
*/
249+
getTypeOfService(): number;
250+
/**
251+
* Sets the Type of Service (TOS) field for IPv4 packets or Traffic Class for IPv6
252+
* Packets sent from this socket. This can be used to prioritize network traffic.
253+
*
254+
* `setTypeOfService()` may be called before the socket is connected; the value
255+
* will be cached and applied when the socket establishes a connection.
256+
* `getTypeOfService()` will return the currently set value even before connection.
257+
*
258+
* On some platforms (e.g., Linux), certain TOS/ECN bits may be masked or ignored,
259+
* and behavior can differ between IPv4 and IPv6 or dual-stack sockets. Callers
260+
* should verify platform-specific semantics.
261+
* @since v25.6.0
262+
* @param tos The TOS value to set (0-255).
263+
* @returns The socket itself.
264+
*/
265+
setTypeOfService(tos: number): this;
234266
/**
235267
* Returns the bound `address`, the address `family` name and `port` of the
236268
* socket as reported by the operating system:`{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`

types/node/node-tests/async_hooks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
after() {},
1717
destroy() {},
1818
promiseResolve() {},
19+
trackPromises: true,
1920
};
2021

2122
const asyncHook = createHook(hooks);

types/node/node-tests/net.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import * as net from "node:net";
6464
keepAliveInitialDelay: 1000,
6565
noDelay: false,
6666
blockList: new net.BlockList(),
67+
typeOfService: 0b00000111,
6768
});
6869

6970
let bool: boolean;
@@ -451,6 +452,16 @@ import * as net from "node:net";
451452
});
452453
}
453454

455+
{
456+
const socket = new net.Socket();
457+
458+
// $ExpectType number
459+
socket.getTypeOfService();
460+
461+
// $ExpectType Socket
462+
socket.setTypeOfService(0b00000111);
463+
}
464+
454465
{
455466
const sockAddr: net.SocketAddress = new net.SocketAddress({
456467
address: "123.123.123.123",

types/node/node-tests/stream.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,8 @@ async function testConsumers() {
498498
await consumers.blob(consumable);
499499
// $ExpectType NonSharedBuffer
500500
await consumers.buffer(consumable);
501+
// $ExpectType NonSharedUint8Array
502+
await consumers.bytes(consumable);
501503
// $ExpectType unknown
502504
await consumers.json(consumable);
503505
// $ExpectType string

types/node/node-tests/test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ run({
6969
branchCoverage: 50,
7070
functionCoverage: 80,
7171
rerunFailuresFilePath: "/path/to/file.json",
72+
env: {
73+
MY_TEST_PATH: "/path/to/tests",
74+
},
7275
});
7376

7477
// TestsStream should be a NodeJS.ReadableStream

types/node/node-tests/tls.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
psk: Buffer.from("asd"),
4141
};
4242
},
43+
requestOCSP: true,
4344
};
4445
const tlsSocket = connect(connOpts);
4546

types/node/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@types/node",
4-
"version": "25.5.9999",
4+
"version": "25.6.9999",
55
"nonNpm": "conflict",
66
"nonNpmDescription": "Node.js",
77
"projects": [
@@ -18,7 +18,7 @@
1818
}
1919
},
2020
"dependencies": {
21-
"undici-types": "~7.18.0"
21+
"undici-types": "~7.19.0"
2222
},
2323
"devDependencies": {
2424
"@types/node": "workspace:."

types/node/stream/consumers.d.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,108 @@ declare module "node:stream/consumers" {
77
import { Blob, NonSharedBuffer } from "node:buffer";
88
import { ReadableStream } from "node:stream/web";
99
/**
10+
* ```js
11+
* import { arrayBuffer } from 'node:stream/consumers';
12+
* import { Readable } from 'node:stream';
13+
* import { TextEncoder } from 'node:util';
14+
*
15+
* const encoder = new TextEncoder();
16+
* const dataArray = encoder.encode('hello world from consumers!');
17+
*
18+
* const readable = Readable.from(dataArray);
19+
* const data = await arrayBuffer(readable);
20+
* console.log(`from readable: ${data.byteLength}`);
21+
* // Prints: from readable: 76
22+
* ```
1023
* @since v16.7.0
1124
* @returns Fulfills with an `ArrayBuffer` containing the full contents of the stream.
1225
*/
1326
function arrayBuffer(stream: ReadableStream | NodeJS.ReadableStream | AsyncIterable<any>): Promise<ArrayBuffer>;
1427
/**
28+
* ```js
29+
* import { blob } from 'node:stream/consumers';
30+
*
31+
* const dataBlob = new Blob(['hello world from consumers!']);
32+
*
33+
* const readable = dataBlob.stream();
34+
* const data = await blob(readable);
35+
* console.log(`from readable: ${data.size}`);
36+
* // Prints: from readable: 27
37+
* ```
1538
* @since v16.7.0
1639
* @returns Fulfills with a `Blob` containing the full contents of the stream.
1740
*/
1841
function blob(stream: ReadableStream | NodeJS.ReadableStream | AsyncIterable<any>): Promise<Blob>;
1942
/**
43+
* ```js
44+
* import { buffer } from 'node:stream/consumers';
45+
* import { Readable } from 'node:stream';
46+
* import { Buffer } from 'node:buffer';
47+
*
48+
* const dataBuffer = Buffer.from('hello world from consumers!');
49+
*
50+
* const readable = Readable.from(dataBuffer);
51+
* const data = await buffer(readable);
52+
* console.log(`from readable: ${data.length}`);
53+
* // Prints: from readable: 27
54+
* ```
2055
* @since v16.7.0
2156
* @returns Fulfills with a `Buffer` containing the full contents of the stream.
2257
*/
2358
function buffer(stream: ReadableStream | NodeJS.ReadableStream | AsyncIterable<any>): Promise<NonSharedBuffer>;
2459
/**
60+
* ```js
61+
* import { bytes } from 'node:stream/consumers';
62+
* import { Readable } from 'node:stream';
63+
* import { Buffer } from 'node:buffer';
64+
*
65+
* const dataBuffer = Buffer.from('hello world from consumers!');
66+
*
67+
* const readable = Readable.from(dataBuffer);
68+
* const data = await bytes(readable);
69+
* console.log(`from readable: ${data.length}`);
70+
* // Prints: from readable: 27
71+
* ```
72+
* @since v25.6.0
73+
* @returns Fulfills with a `Uint8Array` containing the full contents of the stream.
74+
*/
75+
function bytes(
76+
stream: ReadableStream | NodeJS.ReadableStream | AsyncIterable<any>,
77+
): Promise<NodeJS.NonSharedUint8Array>;
78+
/**
79+
* ```js
80+
* import { json } from 'node:stream/consumers';
81+
* import { Readable } from 'node:stream';
82+
*
83+
* const items = Array.from(
84+
* {
85+
* length: 100,
86+
* },
87+
* () => ({
88+
* message: 'hello world from consumers!',
89+
* }),
90+
* );
91+
*
92+
* const readable = Readable.from(JSON.stringify(items));
93+
* const data = await json(readable);
94+
* console.log(`from readable: ${data.length}`);
95+
* // Prints: from readable: 100
96+
* ```
2597
* @since v16.7.0
2698
* @returns Fulfills with the contents of the stream parsed as a
2799
* UTF-8 encoded string that is then passed through `JSON.parse()`.
28100
*/
29101
function json(stream: ReadableStream | NodeJS.ReadableStream | AsyncIterable<any>): Promise<unknown>;
30102
/**
103+
* ```js
104+
* import { text } from 'node:stream/consumers';
105+
* import { Readable } from 'node:stream';
106+
*
107+
* const readable = Readable.from('Hello world from consumers!');
108+
* const data = await text(readable);
109+
* console.log(`from readable: ${data.length}`);
110+
* // Prints: from readable: 27
111+
* ```
31112
* @since v16.7.0
32113
* @returns Fulfills with the contents of the stream parsed as a UTF-8 encoded string.
33114
*/

0 commit comments

Comments
 (0)