@types/node 25.5.1 → 25.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
node/wasi.d.ts CHANGED
@@ -1,74 +1,3 @@
1
- /**
2
- * **The `node:wasi` module does not currently provide the**
3
- * **comprehensive file system security properties provided by some WASI runtimes.**
4
- * **Full support for secure file system sandboxing may or may not be implemented in**
5
- * **future. In the mean time, do not rely on it to run untrusted code.**
6
- *
7
- * The WASI API provides an implementation of the [WebAssembly System Interface](https://wasi.dev/) specification. WASI gives WebAssembly applications access to the underlying
8
- * operating system via a collection of POSIX-like functions.
9
- *
10
- * ```js
11
- * import { readFile } from 'node:fs/promises';
12
- * import { WASI } from 'node:wasi';
13
- * import { argv, env } from 'node:process';
14
- *
15
- * const wasi = new WASI({
16
- * version: 'preview1',
17
- * args: argv,
18
- * env,
19
- * preopens: {
20
- * '/local': '/some/real/path/that/wasm/can/access',
21
- * },
22
- * });
23
- *
24
- * const wasm = await WebAssembly.compile(
25
- * await readFile(new URL('./demo.wasm', import.meta.url)),
26
- * );
27
- * const instance = await WebAssembly.instantiate(wasm, wasi.getImportObject());
28
- *
29
- * wasi.start(instance);
30
- * ```
31
- *
32
- * To run the above example, create a new WebAssembly text format file named `demo.wat`:
33
- *
34
- * ```text
35
- * (module
36
- * ;; Import the required fd_write WASI function which will write the given io vectors to stdout
37
- * ;; The function signature for fd_write is:
38
- * ;; (File Descriptor, *iovs, iovs_len, nwritten) -> Returns number of bytes written
39
- * (import "wasi_snapshot_preview1" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32)))
40
- *
41
- * (memory 1)
42
- * (export "memory" (memory 0))
43
- *
44
- * ;; Write 'hello world\n' to memory at an offset of 8 bytes
45
- * ;; Note the trailing newline which is required for the text to appear
46
- * (data (i32.const 8) "hello world\n")
47
- *
48
- * (func $main (export "_start")
49
- * ;; Creating a new io vector within linear memory
50
- * (i32.store (i32.const 0) (i32.const 8)) ;; iov.iov_base - This is a pointer to the start of the 'hello world\n' string
51
- * (i32.store (i32.const 4) (i32.const 12)) ;; iov.iov_len - The length of the 'hello world\n' string
52
- *
53
- * (call $fd_write
54
- * (i32.const 1) ;; file_descriptor - 1 for stdout
55
- * (i32.const 0) ;; *iovs - The pointer to the iov array, which is stored at memory location 0
56
- * (i32.const 1) ;; iovs_len - We're printing 1 string stored in an iov - so one.
57
- * (i32.const 20) ;; nwritten - A place in memory to store the number of bytes written
58
- * )
59
- * drop ;; Discard the number of bytes written from the top of the stack
60
- * )
61
- * )
62
- * ```
63
- *
64
- * Use [wabt](https://github.com/WebAssembly/wabt) to compile `.wat` to `.wasm`
65
- *
66
- * ```bash
67
- * wat2wasm demo.wat
68
- * ```
69
- * @experimental
70
- * @see [source](https://github.com/nodejs/node/blob/v25.x/lib/wasi.js)
71
- */
72
1
  declare module "node:wasi" {
73
2
  interface WASIOptions {
74
3
  /**
node/worker_threads.d.ts CHANGED
@@ -1,59 +1,3 @@
1
- /**
2
- * The `node:worker_threads` module enables the use of threads that execute
3
- * JavaScript in parallel. To access it:
4
- *
5
- * ```js
6
- * import worker from 'node:worker_threads';
7
- * ```
8
- *
9
- * Workers (threads) are useful for performing CPU-intensive JavaScript operations.
10
- * They do not help much with I/O-intensive work. The Node.js built-in
11
- * asynchronous I/O operations are more efficient than Workers can be.
12
- *
13
- * Unlike `child_process` or `cluster`, `worker_threads` can share memory. They do
14
- * so by transferring `ArrayBuffer` instances or sharing `SharedArrayBuffer` instances.
15
- *
16
- * ```js
17
- * import {
18
- * Worker,
19
- * isMainThread,
20
- * parentPort,
21
- * workerData,
22
- * } from 'node:worker_threads';
23
- *
24
- * if (!isMainThread) {
25
- * const { parse } = await import('some-js-parsing-library');
26
- * const script = workerData;
27
- * parentPort.postMessage(parse(script));
28
- * }
29
- *
30
- * export default function parseJSAsync(script) {
31
- * return new Promise((resolve, reject) => {
32
- * const worker = new Worker(new URL(import.meta.url), {
33
- * workerData: script,
34
- * });
35
- * worker.on('message', resolve);
36
- * worker.once('error', reject);
37
- * worker.once('exit', (code) => {
38
- * if (code !== 0)
39
- * reject(new Error(`Worker stopped with exit code ${code}`));
40
- * });
41
- * });
42
- * };
43
- * ```
44
- *
45
- * The above example spawns a Worker thread for each `parseJSAsync()` call. In
46
- * practice, use a pool of Workers for these kinds of tasks. Otherwise, the
47
- * overhead of creating Workers would likely exceed their benefit.
48
- *
49
- * When implementing a worker pool, use the `AsyncResource` API to inform
50
- * diagnostic tools (e.g. to provide asynchronous stack traces) about the
51
- * correlation between tasks and their outcomes. See `"Using AsyncResource for a Worker thread pool"` in the `async_hooks` documentation for an example implementation.
52
- *
53
- * Worker threads inherit non-process-specific options by default. Refer to `Worker constructor options` to know how to customize worker thread options,
54
- * specifically `argv` and `execArgv` options.
55
- * @see [source](https://github.com/nodejs/node/blob/v25.x/lib/worker_threads.js)
56
- */
57
1
  declare module "node:worker_threads" {
58
2
  import {
59
3
  EventEmitter,
@@ -396,11 +340,15 @@ declare module "node:worker_threads" {
396
340
  interface Worker extends InternalEventEmitter<WorkerEventMap> {}
397
341
  /**
398
342
  * Mark an object as not transferable. If `object` occurs in the transfer list of
399
- * a `port.postMessage()` call, it is ignored.
343
+ * a [`port.postMessage()`](https://nodejs.org/docs/latest-v25.x/api/worker_threads.html#portpostmessagevalue-transferlist) call, an error is thrown. This is a no-op if
344
+ * `object` is a primitive value.
400
345
  *
401
346
  * In particular, this makes sense for objects that can be cloned, rather than
402
347
  * transferred, and which are used by other objects on the sending side.
403
- * For example, Node.js marks the `ArrayBuffer`s it uses for its `Buffer pool` with this.
348
+ * For example, Node.js marks the `ArrayBuffer`s it uses for its
349
+ * [`Buffer` pool](https://nodejs.org/docs/latest-v25.x/api/buffer.html#static-method-bufferallocunsafesize) with this.
350
+ * `ArrayBuffer.prototype.transfer()` is disallowed on such array buffer
351
+ * instances.
404
352
  *
405
353
  * This operation cannot be undone.
406
354
  *
@@ -414,11 +362,17 @@ declare module "node:worker_threads" {
414
362
  * markAsUntransferable(pooledBuffer);
415
363
  *
416
364
  * const { port1 } = new MessageChannel();
417
- * port1.postMessage(typedArray1, [ typedArray1.buffer ]);
365
+ * try {
366
+ * // This will throw an error, because pooledBuffer is not transferable.
367
+ * port1.postMessage(typedArray1, [ typedArray1.buffer ]);
368
+ * } catch (error) {
369
+ * // error.name === 'DataCloneError'
370
+ * }
418
371
  *
419
372
  * // The following line prints the contents of typedArray1 -- it still owns
420
- * // its memory and has been cloned, not transferred. Without
421
- * // `markAsUntransferable()`, this would print an empty Uint8Array.
373
+ * // its memory and has not been transferred. Without
374
+ * // `markAsUntransferable()`, this would print an empty Uint8Array and the
375
+ * // postMessage call would have succeeded.
422
376
  * // typedArray2 is intact as well.
423
377
  * console.log(typedArray1);
424
378
  * console.log(typedArray2);
node/zlib.d.ts CHANGED
@@ -1,96 +1,3 @@
1
- /**
2
- * The `node:zlib` module provides compression functionality implemented using
3
- * Gzip, Deflate/Inflate, and Brotli.
4
- *
5
- * To access it:
6
- *
7
- * ```js
8
- * import zlib from 'node:zlib';
9
- * ```
10
- *
11
- * Compression and decompression are built around the Node.js
12
- * [Streams API](https://nodejs.org/docs/latest-v25.x/api/stream.html).
13
- *
14
- * Compressing or decompressing a stream (such as a file) can be accomplished by
15
- * piping the source stream through a `zlib` `Transform` stream into a destination
16
- * stream:
17
- *
18
- * ```js
19
- * import { createGzip } from 'node:zlib';
20
- * import { pipeline } from 'node:stream';
21
- * import {
22
- * createReadStream,
23
- * createWriteStream,
24
- * } from 'node:fs';
25
- *
26
- * const gzip = createGzip();
27
- * const source = createReadStream('input.txt');
28
- * const destination = createWriteStream('input.txt.gz');
29
- *
30
- * pipeline(source, gzip, destination, (err) => {
31
- * if (err) {
32
- * console.error('An error occurred:', err);
33
- * process.exitCode = 1;
34
- * }
35
- * });
36
- *
37
- * // Or, Promisified
38
- *
39
- * import { promisify } from 'node:util';
40
- * const pipe = promisify(pipeline);
41
- *
42
- * async function do_gzip(input, output) {
43
- * const gzip = createGzip();
44
- * const source = createReadStream(input);
45
- * const destination = createWriteStream(output);
46
- * await pipe(source, gzip, destination);
47
- * }
48
- *
49
- * do_gzip('input.txt', 'input.txt.gz')
50
- * .catch((err) => {
51
- * console.error('An error occurred:', err);
52
- * process.exitCode = 1;
53
- * });
54
- * ```
55
- *
56
- * It is also possible to compress or decompress data in a single step:
57
- *
58
- * ```js
59
- * import { deflate, unzip } from 'node:zlib';
60
- *
61
- * const input = '.................................';
62
- * deflate(input, (err, buffer) => {
63
- * if (err) {
64
- * console.error('An error occurred:', err);
65
- * process.exitCode = 1;
66
- * }
67
- * console.log(buffer.toString('base64'));
68
- * });
69
- *
70
- * const buffer = Buffer.from('eJzT0yMAAGTvBe8=', 'base64');
71
- * unzip(buffer, (err, buffer) => {
72
- * if (err) {
73
- * console.error('An error occurred:', err);
74
- * process.exitCode = 1;
75
- * }
76
- * console.log(buffer.toString());
77
- * });
78
- *
79
- * // Or, Promisified
80
- *
81
- * import { promisify } from 'node:util';
82
- * const do_unzip = promisify(unzip);
83
- *
84
- * do_unzip(buffer)
85
- * .then((buf) => console.log(buf.toString()))
86
- * .catch((err) => {
87
- * console.error('An error occurred:', err);
88
- * process.exitCode = 1;
89
- * });
90
- * ```
91
- * @since v0.5.8
92
- * @see [source](https://github.com/nodejs/node/blob/v25.x/lib/zlib.js)
93
- */
94
1
  declare module "node:zlib" {
95
2
  import { NonSharedBuffer } from "node:buffer";
96
3
  import * as stream from "node:stream";