@types/node 18.16.3 → 20.1.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/README.md +1 -1
- node/assert.d.ts +71 -75
- node/async_hooks.d.ts +62 -42
- node/buffer.d.ts +127 -99
- node/child_process.d.ts +50 -54
- node/cluster.d.ts +12 -12
- node/console.d.ts +5 -5
- node/crypto.d.ts +209 -220
- node/dgram.d.ts +15 -15
- node/diagnostics_channel.d.ts +25 -26
- node/dns/promises.d.ts +6 -6
- node/dns.d.ts +24 -16
- node/domain.d.ts +4 -4
- node/events.d.ts +60 -60
- node/fs/promises.d.ts +78 -48
- node/fs.d.ts +117 -81
- node/http.d.ts +158 -147
- node/http2.d.ts +42 -46
- node/https.d.ts +52 -153
- node/index.d.ts +1 -1
- node/inspector.d.ts +10 -3
- node/module.d.ts +5 -4
- node/net.d.ts +21 -18
- node/os.d.ts +22 -18
- node/package.json +2 -2
- node/path.d.ts +4 -4
- node/perf_hooks.d.ts +28 -15
- node/process.d.ts +43 -46
- node/punycode.d.ts +1 -1
- node/querystring.d.ts +5 -5
- node/readline/promises.d.ts +6 -4
- node/readline.d.ts +15 -15
- node/repl.d.ts +9 -9
- node/stream/consumers.d.ts +1 -1
- node/stream.d.ts +88 -136
- node/string_decoder.d.ts +6 -6
- node/test.d.ts +423 -186
- node/timers/promises.d.ts +3 -3
- node/timers.d.ts +2 -2
- node/tls.d.ts +24 -16
- node/trace_events.d.ts +20 -9
- node/ts4.8/assert.d.ts +71 -75
- node/ts4.8/async_hooks.d.ts +62 -42
- node/ts4.8/buffer.d.ts +127 -99
- node/ts4.8/child_process.d.ts +50 -54
- node/ts4.8/cluster.d.ts +12 -12
- node/ts4.8/console.d.ts +5 -5
- node/ts4.8/crypto.d.ts +209 -220
- node/ts4.8/dgram.d.ts +15 -15
- node/ts4.8/diagnostics_channel.d.ts +25 -26
- node/ts4.8/dns/promises.d.ts +6 -6
- node/ts4.8/dns.d.ts +24 -16
- node/ts4.8/domain.d.ts +4 -4
- node/ts4.8/events.d.ts +60 -60
- node/ts4.8/fs/promises.d.ts +96 -45
- node/ts4.8/fs.d.ts +203 -67
- node/ts4.8/globals.d.ts +29 -28
- node/ts4.8/http.d.ts +198 -126
- node/ts4.8/http2.d.ts +42 -46
- node/ts4.8/https.d.ts +52 -153
- node/ts4.8/inspector.d.ts +10 -3
- node/ts4.8/module.d.ts +5 -4
- node/ts4.8/net.d.ts +24 -21
- node/ts4.8/os.d.ts +22 -18
- node/ts4.8/path.d.ts +4 -4
- node/ts4.8/perf_hooks.d.ts +28 -15
- node/ts4.8/process.d.ts +43 -46
- node/ts4.8/punycode.d.ts +1 -1
- node/ts4.8/querystring.d.ts +5 -5
- node/ts4.8/readline/promises.d.ts +6 -4
- node/ts4.8/readline.d.ts +15 -15
- node/ts4.8/repl.d.ts +9 -9
- node/ts4.8/stream/consumers.d.ts +1 -1
- node/ts4.8/stream.d.ts +91 -139
- node/ts4.8/string_decoder.d.ts +6 -6
- node/ts4.8/test.d.ts +423 -186
- node/ts4.8/timers/promises.d.ts +3 -3
- node/ts4.8/timers.d.ts +9 -2
- node/ts4.8/tls.d.ts +24 -16
- node/ts4.8/trace_events.d.ts +20 -9
- node/ts4.8/tty.d.ts +4 -5
- node/ts4.8/url.d.ts +26 -36
- node/ts4.8/util.d.ts +143 -116
- node/ts4.8/v8.d.ts +110 -16
- node/ts4.8/vm.d.ts +292 -42
- node/ts4.8/wasi.d.ts +13 -19
- node/ts4.8/worker_threads.d.ts +32 -34
- node/ts4.8/zlib.d.ts +11 -11
- node/tty.d.ts +4 -5
- node/url.d.ts +26 -36
- node/util.d.ts +146 -111
- node/v8.d.ts +110 -16
- node/vm.d.ts +292 -42
- node/wasi.d.ts +13 -19
- node/worker_threads.d.ts +32 -34
- node/zlib.d.ts +11 -11
node/ts4.8/async_hooks.d.ts
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* can
|
|
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/
|
|
15
|
+
* @see [source](https://github.com/nodejs/node/blob/v20.1.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`.
|
|
@@ -274,22 +278,15 @@ declare module 'async_hooks' {
|
|
|
274
278
|
fn: Func,
|
|
275
279
|
type?: string,
|
|
276
280
|
thisArg?: ThisArg
|
|
277
|
-
): Func
|
|
278
|
-
asyncResource: AsyncResource;
|
|
279
|
-
};
|
|
281
|
+
): Func;
|
|
280
282
|
/**
|
|
281
283
|
* 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
284
|
* @since v14.8.0, v12.19.0
|
|
286
285
|
* @param fn The function to bind to the current `AsyncResource`.
|
|
287
286
|
*/
|
|
288
287
|
bind<Func extends (...args: any[]) => any>(
|
|
289
288
|
fn: Func
|
|
290
|
-
): Func
|
|
291
|
-
asyncResource: AsyncResource;
|
|
292
|
-
};
|
|
289
|
+
): Func;
|
|
293
290
|
/**
|
|
294
291
|
* Call the provided function with the provided arguments in the execution context
|
|
295
292
|
* of the async resource. This will establish the context, trigger the AsyncHooks
|
|
@@ -322,17 +319,17 @@ declare module 'async_hooks' {
|
|
|
322
319
|
/**
|
|
323
320
|
* This class creates stores that stay coherent through asynchronous operations.
|
|
324
321
|
*
|
|
325
|
-
* While you can create your own implementation on top of the `async_hooks`
|
|
326
|
-
* implementation that involves significant optimizations that are non-obvious
|
|
327
|
-
* implement.
|
|
322
|
+
* 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
|
|
323
|
+
* safe implementation that involves significant optimizations that are non-obvious
|
|
324
|
+
* to implement.
|
|
328
325
|
*
|
|
329
326
|
* The following example uses `AsyncLocalStorage` to build a simple logger
|
|
330
327
|
* that assigns IDs to incoming HTTP requests and includes them in messages
|
|
331
328
|
* logged within each request.
|
|
332
329
|
*
|
|
333
330
|
* ```js
|
|
334
|
-
* import http from 'http';
|
|
335
|
-
* import { AsyncLocalStorage } from 'async_hooks';
|
|
331
|
+
* import http from 'node:http';
|
|
332
|
+
* import { AsyncLocalStorage } from 'node:async_hooks';
|
|
336
333
|
*
|
|
337
334
|
* const asyncLocalStorage = new AsyncLocalStorage();
|
|
338
335
|
*
|
|
@@ -370,21 +367,44 @@ declare module 'async_hooks' {
|
|
|
370
367
|
class AsyncLocalStorage<T> {
|
|
371
368
|
/**
|
|
372
369
|
* Binds the given function to the current execution context.
|
|
373
|
-
* @since
|
|
370
|
+
* @since v19.8.0
|
|
371
|
+
* @experimental
|
|
374
372
|
* @param fn The function to bind to the current execution context.
|
|
375
|
-
* @
|
|
373
|
+
* @return A new function that calls `fn` within the captured execution context.
|
|
376
374
|
*/
|
|
377
|
-
static bind<Func extends (...args: any[]) => any>(
|
|
378
|
-
|
|
379
|
-
|
|
375
|
+
static bind<Func extends (...args: any[]) => any>(
|
|
376
|
+
fn: Func
|
|
377
|
+
): Func;
|
|
380
378
|
/**
|
|
381
|
-
* Captures the current execution context and returns a function that accepts a
|
|
382
|
-
* Whenever the returned function is called, it
|
|
383
|
-
*
|
|
379
|
+
* Captures the current execution context and returns a function that accepts a
|
|
380
|
+
* function as an argument. Whenever the returned function is called, it
|
|
381
|
+
* calls the function passed to it within the captured context.
|
|
382
|
+
*
|
|
383
|
+
* ```js
|
|
384
|
+
* const asyncLocalStorage = new AsyncLocalStorage();
|
|
385
|
+
* const runInAsyncScope = asyncLocalStorage.run(123, () => AsyncLocalStorage.snapshot());
|
|
386
|
+
* const result = asyncLocalStorage.run(321, () => runInAsyncScope(() => asyncLocalStorage.getStore()));
|
|
387
|
+
* console.log(result); // returns 123
|
|
388
|
+
* ```
|
|
389
|
+
*
|
|
390
|
+
* AsyncLocalStorage.snapshot() can replace the use of AsyncResource for simple
|
|
391
|
+
* async context tracking purposes, for example:
|
|
392
|
+
*
|
|
393
|
+
* ```js
|
|
394
|
+
* class Foo {
|
|
395
|
+
* #runInAsyncScope = AsyncLocalStorage.snapshot();
|
|
396
|
+
*
|
|
397
|
+
* get() { return this.#runInAsyncScope(() => asyncLocalStorage.getStore()); }
|
|
398
|
+
* }
|
|
399
|
+
*
|
|
400
|
+
* const foo = asyncLocalStorage.run(123, () => new Foo());
|
|
401
|
+
* console.log(asyncLocalStorage.run(321, () => foo.get())); // returns 123
|
|
402
|
+
* ```
|
|
403
|
+
* @since v19.8.0
|
|
404
|
+
* @experimental
|
|
405
|
+
* @return A new function with the signature `(fn: (...args) : R, ...args) : R`.
|
|
384
406
|
*/
|
|
385
|
-
static snapshot():
|
|
386
|
-
asyncResource: AsyncResource;
|
|
387
|
-
};
|
|
407
|
+
static snapshot(): <R, TArgs extends any[]>(fn: (...args: TArgs) => R, ...args: TArgs) => R;
|
|
388
408
|
/**
|
|
389
409
|
* Disables the instance of `AsyncLocalStorage`. All subsequent calls
|
|
390
410
|
* to `asyncLocalStorage.getStore()` will return `undefined` until`asyncLocalStorage.run()` or `asyncLocalStorage.enterWith()` is called again.
|