@types/node 18.16.2 → 20.0.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.
Files changed (95) hide show
  1. node/README.md +1 -1
  2. node/assert.d.ts +68 -73
  3. node/async_hooks.d.ts +62 -42
  4. node/buffer.d.ts +123 -95
  5. node/child_process.d.ts +50 -54
  6. node/cluster.d.ts +12 -12
  7. node/console.d.ts +5 -5
  8. node/crypto.d.ts +209 -220
  9. node/dgram.d.ts +15 -15
  10. node/diagnostics_channel.d.ts +25 -26
  11. node/dns/promises.d.ts +6 -6
  12. node/dns.d.ts +16 -16
  13. node/domain.d.ts +3 -3
  14. node/events.d.ts +60 -60
  15. node/fs/promises.d.ts +74 -48
  16. node/fs.d.ts +91 -81
  17. node/http.d.ts +147 -144
  18. node/http2.d.ts +42 -46
  19. node/https.d.ts +52 -153
  20. node/index.d.ts +1 -1
  21. node/inspector.d.ts +10 -3
  22. node/module.d.ts +5 -4
  23. node/net.d.ts +21 -18
  24. node/os.d.ts +22 -18
  25. node/package.json +2 -2
  26. node/path.d.ts +4 -4
  27. node/perf_hooks.d.ts +28 -15
  28. node/process.d.ts +43 -46
  29. node/punycode.d.ts +1 -1
  30. node/querystring.d.ts +5 -5
  31. node/readline/promises.d.ts +6 -4
  32. node/readline.d.ts +15 -15
  33. node/repl.d.ts +9 -9
  34. node/stream/consumers.d.ts +1 -1
  35. node/stream.d.ts +74 -136
  36. node/string_decoder.d.ts +6 -6
  37. node/test.d.ts +0 -76
  38. node/timers/promises.d.ts +3 -3
  39. node/timers.d.ts +2 -2
  40. node/tls.d.ts +29 -15
  41. node/trace_events.d.ts +20 -9
  42. node/ts4.8/assert.d.ts +68 -73
  43. node/ts4.8/async_hooks.d.ts +59 -31
  44. node/ts4.8/buffer.d.ts +123 -95
  45. node/ts4.8/child_process.d.ts +50 -54
  46. node/ts4.8/cluster.d.ts +12 -12
  47. node/ts4.8/console.d.ts +5 -5
  48. node/ts4.8/crypto.d.ts +209 -220
  49. node/ts4.8/dgram.d.ts +15 -15
  50. node/ts4.8/diagnostics_channel.d.ts +25 -26
  51. node/ts4.8/dns/promises.d.ts +6 -6
  52. node/ts4.8/dns.d.ts +16 -16
  53. node/ts4.8/domain.d.ts +3 -3
  54. node/ts4.8/events.d.ts +60 -60
  55. node/ts4.8/fs/promises.d.ts +72 -45
  56. node/ts4.8/fs.d.ts +81 -67
  57. node/ts4.8/http.d.ts +133 -126
  58. node/ts4.8/http2.d.ts +42 -46
  59. node/ts4.8/https.d.ts +52 -153
  60. node/ts4.8/inspector.d.ts +10 -3
  61. node/ts4.8/module.d.ts +5 -4
  62. node/ts4.8/net.d.ts +21 -18
  63. node/ts4.8/os.d.ts +22 -18
  64. node/ts4.8/path.d.ts +4 -4
  65. node/ts4.8/perf_hooks.d.ts +28 -15
  66. node/ts4.8/process.d.ts +43 -46
  67. node/ts4.8/punycode.d.ts +1 -1
  68. node/ts4.8/querystring.d.ts +5 -5
  69. node/ts4.8/readline/promises.d.ts +6 -4
  70. node/ts4.8/readline.d.ts +15 -15
  71. node/ts4.8/repl.d.ts +9 -9
  72. node/ts4.8/stream/consumers.d.ts +1 -1
  73. node/ts4.8/stream.d.ts +77 -139
  74. node/ts4.8/string_decoder.d.ts +6 -6
  75. node/ts4.8/test.d.ts +0 -75
  76. node/ts4.8/timers/promises.d.ts +3 -3
  77. node/ts4.8/timers.d.ts +2 -2
  78. node/ts4.8/tls.d.ts +29 -15
  79. node/ts4.8/trace_events.d.ts +20 -9
  80. node/ts4.8/tty.d.ts +4 -5
  81. node/ts4.8/url.d.ts +26 -36
  82. node/ts4.8/util.d.ts +143 -116
  83. node/ts4.8/v8.d.ts +107 -16
  84. node/ts4.8/vm.d.ts +292 -42
  85. node/ts4.8/wasi.d.ts +8 -14
  86. node/ts4.8/worker_threads.d.ts +32 -34
  87. node/ts4.8/zlib.d.ts +11 -11
  88. node/tty.d.ts +4 -5
  89. node/url.d.ts +26 -36
  90. node/util.d.ts +146 -111
  91. node/v8.d.ts +110 -16
  92. node/vm.d.ts +292 -42
  93. node/wasi.d.ts +8 -14
  94. node/worker_threads.d.ts +32 -34
  95. node/zlib.d.ts +11 -11
@@ -1,17 +1,24 @@
1
1
  /**
2
- * The `async_hooks` module provides an API to track asynchronous resources. It
3
- * can be accessed using:
2
+ * We strongly discourage the use of the `async_hooks` API.
3
+ * Other APIs that can cover most of its use cases include:
4
+ *
5
+ * * `AsyncLocalStorage` tracks async context
6
+ * * `process.getActiveResourcesInfo()` tracks active resources
7
+ *
8
+ * The `node:async_hooks` module provides an API to track asynchronous resources.
9
+ * It can be accessed using:
4
10
  *
5
11
  * ```js
6
- * import async_hooks from 'async_hooks';
12
+ * import async_hooks from 'node:async_hooks';
7
13
  * ```
8
14
  * @experimental
9
- * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/async_hooks.js)
15
+ * @see [source](https://github.com/nodejs/node/blob/v20.0.0/lib/async_hooks.js)
10
16
  */
11
17
  declare module 'async_hooks' {
12
18
  /**
13
19
  * ```js
14
- * import { executionAsyncId } from 'async_hooks';
20
+ * import { executionAsyncId } from 'node:async_hooks';
21
+ * import fs from 'node:fs';
15
22
  *
16
23
  * console.log(executionAsyncId()); // 1 - bootstrap
17
24
  * fs.open(path, 'r', (err, fd) => {
@@ -51,8 +58,8 @@ declare module 'async_hooks' {
51
58
  * but having an object representing the top-level can be helpful.
52
59
  *
53
60
  * ```js
54
- * import { open } from 'fs';
55
- * import { executionAsyncId, executionAsyncResource } from 'async_hooks';
61
+ * import { open } from 'node:fs';
62
+ * import { executionAsyncId, executionAsyncResource } from 'node:async_hooks';
56
63
  *
57
64
  * console.log(executionAsyncId(), executionAsyncResource()); // 1 {}
58
65
  * open(new URL(import.meta.url), 'r', (err, fd) => {
@@ -64,11 +71,11 @@ declare module 'async_hooks' {
64
71
  * use of a tracking `Map` to store the metadata:
65
72
  *
66
73
  * ```js
67
- * import { createServer } from 'http';
74
+ * import { createServer } from 'node:http';
68
75
  * import {
69
76
  * executionAsyncId,
70
77
  * executionAsyncResource,
71
- * createHook
78
+ * createHook,
72
79
  * } from 'async_hooks';
73
80
  * const sym = Symbol('state'); // Private symbol to avoid pollution
74
81
  *
@@ -78,7 +85,7 @@ declare module 'async_hooks' {
78
85
  * if (cr) {
79
86
  * resource[sym] = cr[sym];
80
87
  * }
81
- * }
88
+ * },
82
89
  * }).enable();
83
90
  *
84
91
  * const server = createServer((req, res) => {
@@ -167,11 +174,11 @@ declare module 'async_hooks' {
167
174
  * specifics of all functions that can be passed to `callbacks` is in the `Hook Callbacks` section.
168
175
  *
169
176
  * ```js
170
- * import { createHook } from 'async_hooks';
177
+ * import { createHook } from 'node:async_hooks';
171
178
  *
172
179
  * const asyncHook = createHook({
173
180
  * init(asyncId, type, triggerAsyncId, resource) { },
174
- * destroy(asyncId) { }
181
+ * destroy(asyncId) { },
175
182
  * });
176
183
  * ```
177
184
  *
@@ -223,13 +230,13 @@ declare module 'async_hooks' {
223
230
  * The following is an overview of the `AsyncResource` API.
224
231
  *
225
232
  * ```js
226
- * import { AsyncResource, executionAsyncId } from 'async_hooks';
233
+ * import { AsyncResource, executionAsyncId } from 'node:async_hooks';
227
234
  *
228
235
  * // AsyncResource() is meant to be extended. Instantiating a
229
236
  * // new AsyncResource() also triggers init. If triggerAsyncId is omitted then
230
237
  * // async_hook.executionAsyncId() is used.
231
238
  * const asyncResource = new AsyncResource(
232
- * type, { triggerAsyncId: executionAsyncId(), requireManualDestroy: false }
239
+ * type, { triggerAsyncId: executionAsyncId(), requireManualDestroy: false },
233
240
  * );
234
241
  *
235
242
  * // Run a function in the execution context of the resource. This will
@@ -263,9 +270,6 @@ declare module 'async_hooks' {
263
270
  constructor(type: string, triggerAsyncId?: number | AsyncResourceOptions);
264
271
  /**
265
272
  * Binds the given function to the current execution context.
266
- *
267
- * The returned function will have an `asyncResource` property referencing
268
- * the `AsyncResource` to which the function is bound.
269
273
  * @since v14.8.0, v12.19.0
270
274
  * @param fn The function to bind to the current execution context.
271
275
  * @param type An optional name to associate with the underlying `AsyncResource`.
@@ -279,9 +283,6 @@ declare module 'async_hooks' {
279
283
  };
280
284
  /**
281
285
  * Binds the given function to execute to this `AsyncResource`'s scope.
282
- *
283
- * The returned function will have an `asyncResource` property referencing
284
- * the `AsyncResource` to which the function is bound.
285
286
  * @since v14.8.0, v12.19.0
286
287
  * @param fn The function to bind to the current `AsyncResource`.
287
288
  */
@@ -322,17 +323,17 @@ declare module 'async_hooks' {
322
323
  /**
323
324
  * This class creates stores that stay coherent through asynchronous operations.
324
325
  *
325
- * While you can create your own implementation on top of the `async_hooks` module,`AsyncLocalStorage` should be preferred as it is a performant and memory safe
326
- * implementation that involves significant optimizations that are non-obvious to
327
- * implement.
326
+ * While you can create your own implementation on top of the `node:async_hooks`module, `AsyncLocalStorage` should be preferred as it is a performant and memory
327
+ * safe implementation that involves significant optimizations that are non-obvious
328
+ * to implement.
328
329
  *
329
330
  * The following example uses `AsyncLocalStorage` to build a simple logger
330
331
  * that assigns IDs to incoming HTTP requests and includes them in messages
331
332
  * logged within each request.
332
333
  *
333
334
  * ```js
334
- * import http from 'http';
335
- * import { AsyncLocalStorage } from 'async_hooks';
335
+ * import http from 'node:http';
336
+ * import { AsyncLocalStorage } from 'node:async_hooks';
336
337
  *
337
338
  * const asyncLocalStorage = new AsyncLocalStorage();
338
339
  *
@@ -370,17 +371,44 @@ declare module 'async_hooks' {
370
371
  class AsyncLocalStorage<T> {
371
372
  /**
372
373
  * Binds the given function to the current execution context.
373
- * @since v18.16.0
374
+ * @since v19.8.0
375
+ * @experimental
374
376
  * @param fn The function to bind to the current execution context.
375
- * @returns A new function that calls `fn` within the captured execution context.
377
+ * @return A new function that calls `fn` within the captured execution context.
376
378
  */
377
- static bind<Func extends (...args: any[]) => any>(fn: Func): Func & {
379
+ static bind<Func extends (...args: any[]) => any>(
380
+ fn: Func
381
+ ): Func & {
378
382
  asyncResource: AsyncResource;
379
383
  };
380
384
  /**
381
- * Captures the current execution context and returns a function that accepts a function as an argument.
382
- * Whenever the returned function is called, it calls the function passed to it within the captured context.
383
- * @since v18.16.0
385
+ * Captures the current execution context and returns a function that accepts a
386
+ * function as an argument. Whenever the returned function is called, it
387
+ * calls the function passed to it within the captured context.
388
+ *
389
+ * ```js
390
+ * const asyncLocalStorage = new AsyncLocalStorage();
391
+ * const runInAsyncScope = asyncLocalStorage.run(123, () => AsyncLocalStorage.snapshot());
392
+ * const result = asyncLocalStorage.run(321, () => runInAsyncScope(() => asyncLocalStorage.getStore()));
393
+ * console.log(result); // returns 123
394
+ * ```
395
+ *
396
+ * AsyncLocalStorage.snapshot() can replace the use of AsyncResource for simple
397
+ * async context tracking purposes, for example:
398
+ *
399
+ * ```js
400
+ * class Foo {
401
+ * #runInAsyncScope = AsyncLocalStorage.snapshot();
402
+ *
403
+ * get() { return this.#runInAsyncScope(() => asyncLocalStorage.getStore()); }
404
+ * }
405
+ *
406
+ * const foo = asyncLocalStorage.run(123, () => new Foo());
407
+ * console.log(asyncLocalStorage.run(321, () => foo.get())); // returns 123
408
+ * ```
409
+ * @since v19.8.0
410
+ * @experimental
411
+ * @return A new function with the signature `(fn: (...args) : R, ...args) : R`.
384
412
  */
385
413
  static snapshot(): (<R, TArgs extends any[]>(fn: (...args: TArgs) => R, ...args: TArgs) => R) & {
386
414
  asyncResource: AsyncResource;