@types/node 18.11.5 → 20.2.5
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 +2 -2
- node/assert.d.ts +86 -75
- node/async_hooks.d.ts +66 -37
- node/buffer.d.ts +193 -100
- node/child_process.d.ts +82 -56
- node/cluster.d.ts +12 -12
- node/console.d.ts +5 -5
- node/crypto.d.ts +233 -235
- node/dgram.d.ts +15 -15
- node/diagnostics_channel.d.ts +59 -21
- node/dns/promises.d.ts +50 -6
- node/dns.d.ts +26 -17
- node/domain.d.ts +4 -4
- node/events.d.ts +111 -65
- node/fs/promises.d.ts +99 -47
- node/fs.d.ts +244 -73
- node/globals.d.ts +6 -3
- node/http.d.ts +265 -148
- node/http2.d.ts +42 -47
- node/https.d.ts +53 -153
- node/index.d.ts +2 -1
- node/inspector.d.ts +10 -3
- node/module.d.ts +6 -4
- node/net.d.ts +32 -15
- node/os.d.ts +27 -16
- node/package.json +9 -4
- node/path.d.ts +4 -4
- node/perf_hooks.d.ts +28 -15
- node/process.d.ts +49 -46
- node/punycode.d.ts +1 -1
- node/querystring.d.ts +5 -5
- node/readline/promises.d.ts +65 -63
- node/readline.d.ts +32 -159
- node/repl.d.ts +20 -20
- node/stream/consumers.d.ts +1 -1
- node/stream.d.ts +950 -869
- node/string_decoder.d.ts +6 -6
- node/test.d.ts +877 -139
- node/timers/promises.d.ts +26 -1
- node/timers.d.ts +125 -4
- node/tls.d.ts +120 -29
- node/trace_events.d.ts +20 -9
- node/ts4.8/assert.d.ts +86 -75
- node/ts4.8/async_hooks.d.ts +66 -37
- node/ts4.8/buffer.d.ts +193 -101
- node/ts4.8/child_process.d.ts +82 -56
- node/ts4.8/cluster.d.ts +12 -12
- node/ts4.8/console.d.ts +5 -5
- node/ts4.8/crypto.d.ts +230 -233
- node/ts4.8/dgram.d.ts +15 -15
- node/ts4.8/diagnostics_channel.d.ts +59 -21
- node/ts4.8/dns/promises.d.ts +50 -6
- node/ts4.8/dns.d.ts +26 -17
- node/ts4.8/domain.d.ts +4 -4
- node/ts4.8/events.d.ts +111 -65
- node/ts4.8/fs/promises.d.ts +97 -46
- node/ts4.8/fs.d.ts +244 -73
- node/ts4.8/globals.d.ts +21 -12
- node/ts4.8/http.d.ts +265 -148
- node/ts4.8/http2.d.ts +42 -47
- node/ts4.8/https.d.ts +53 -153
- node/ts4.8/inspector.d.ts +10 -3
- node/ts4.8/module.d.ts +6 -4
- node/ts4.8/net.d.ts +33 -16
- node/ts4.8/os.d.ts +27 -16
- node/ts4.8/path.d.ts +4 -4
- node/ts4.8/perf_hooks.d.ts +28 -15
- node/ts4.8/process.d.ts +49 -46
- node/ts4.8/punycode.d.ts +1 -1
- node/ts4.8/querystring.d.ts +5 -5
- node/ts4.8/readline/promises.d.ts +65 -63
- node/ts4.8/readline.d.ts +32 -159
- node/ts4.8/repl.d.ts +20 -20
- node/ts4.8/stream/consumers.d.ts +1 -1
- node/ts4.8/stream.d.ts +192 -140
- node/ts4.8/string_decoder.d.ts +6 -6
- node/ts4.8/test.d.ts +877 -139
- node/ts4.8/timers/promises.d.ts +26 -1
- node/ts4.8/timers.d.ts +125 -4
- node/ts4.8/tls.d.ts +120 -29
- node/ts4.8/trace_events.d.ts +20 -9
- node/ts4.8/tty.d.ts +4 -5
- node/ts4.8/url.d.ts +46 -42
- node/ts4.8/util.d.ts +325 -123
- node/ts4.8/v8.d.ts +253 -14
- node/ts4.8/vm.d.ts +417 -32
- node/ts4.8/wasi.d.ts +13 -19
- node/ts4.8/worker_threads.d.ts +38 -34
- node/ts4.8/zlib.d.ts +11 -11
- node/tty.d.ts +4 -5
- node/url.d.ts +46 -42
- node/util.d.ts +325 -123
- node/v8.d.ts +253 -14
- node/vm.d.ts +417 -32
- node/wasi.d.ts +13 -19
- node/worker_threads.d.ts +38 -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.2.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,33 +270,17 @@ 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`.
|
|
272
276
|
*/
|
|
273
|
-
static bind<Func extends (this: ThisArg, ...args: any[]) => any, ThisArg>(
|
|
274
|
-
fn: Func,
|
|
275
|
-
type?: string,
|
|
276
|
-
thisArg?: ThisArg
|
|
277
|
-
): Func & {
|
|
278
|
-
asyncResource: AsyncResource;
|
|
279
|
-
};
|
|
277
|
+
static bind<Func extends (this: ThisArg, ...args: any[]) => any, ThisArg>(fn: Func, type?: string, thisArg?: ThisArg): Func;
|
|
280
278
|
/**
|
|
281
279
|
* 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
280
|
* @since v14.8.0, v12.19.0
|
|
286
281
|
* @param fn The function to bind to the current `AsyncResource`.
|
|
287
282
|
*/
|
|
288
|
-
bind<Func extends (...args: any[]) => any>(
|
|
289
|
-
fn: Func
|
|
290
|
-
): Func & {
|
|
291
|
-
asyncResource: AsyncResource;
|
|
292
|
-
};
|
|
283
|
+
bind<Func extends (...args: any[]) => any>(fn: Func): Func;
|
|
293
284
|
/**
|
|
294
285
|
* Call the provided function with the provided arguments in the execution context
|
|
295
286
|
* of the async resource. This will establish the context, trigger the AsyncHooks
|
|
@@ -322,17 +313,17 @@ declare module 'async_hooks' {
|
|
|
322
313
|
/**
|
|
323
314
|
* This class creates stores that stay coherent through asynchronous operations.
|
|
324
315
|
*
|
|
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.
|
|
316
|
+
* 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
|
|
317
|
+
* safe implementation that involves significant optimizations that are non-obvious
|
|
318
|
+
* to implement.
|
|
328
319
|
*
|
|
329
320
|
* The following example uses `AsyncLocalStorage` to build a simple logger
|
|
330
321
|
* that assigns IDs to incoming HTTP requests and includes them in messages
|
|
331
322
|
* logged within each request.
|
|
332
323
|
*
|
|
333
324
|
* ```js
|
|
334
|
-
* import http from 'http';
|
|
335
|
-
* import { AsyncLocalStorage } from 'async_hooks';
|
|
325
|
+
* import http from 'node:http';
|
|
326
|
+
* import { AsyncLocalStorage } from 'node:async_hooks';
|
|
336
327
|
*
|
|
337
328
|
* const asyncLocalStorage = new AsyncLocalStorage();
|
|
338
329
|
*
|
|
@@ -368,6 +359,44 @@ declare module 'async_hooks' {
|
|
|
368
359
|
* @since v13.10.0, v12.17.0
|
|
369
360
|
*/
|
|
370
361
|
class AsyncLocalStorage<T> {
|
|
362
|
+
/**
|
|
363
|
+
* Binds the given function to the current execution context.
|
|
364
|
+
* @since v19.8.0
|
|
365
|
+
* @experimental
|
|
366
|
+
* @param fn The function to bind to the current execution context.
|
|
367
|
+
* @return A new function that calls `fn` within the captured execution context.
|
|
368
|
+
*/
|
|
369
|
+
static bind<Func extends (...args: any[]) => any>(fn: Func): Func;
|
|
370
|
+
/**
|
|
371
|
+
* Captures the current execution context and returns a function that accepts a
|
|
372
|
+
* function as an argument. Whenever the returned function is called, it
|
|
373
|
+
* calls the function passed to it within the captured context.
|
|
374
|
+
*
|
|
375
|
+
* ```js
|
|
376
|
+
* const asyncLocalStorage = new AsyncLocalStorage();
|
|
377
|
+
* const runInAsyncScope = asyncLocalStorage.run(123, () => AsyncLocalStorage.snapshot());
|
|
378
|
+
* const result = asyncLocalStorage.run(321, () => runInAsyncScope(() => asyncLocalStorage.getStore()));
|
|
379
|
+
* console.log(result); // returns 123
|
|
380
|
+
* ```
|
|
381
|
+
*
|
|
382
|
+
* AsyncLocalStorage.snapshot() can replace the use of AsyncResource for simple
|
|
383
|
+
* async context tracking purposes, for example:
|
|
384
|
+
*
|
|
385
|
+
* ```js
|
|
386
|
+
* class Foo {
|
|
387
|
+
* #runInAsyncScope = AsyncLocalStorage.snapshot();
|
|
388
|
+
*
|
|
389
|
+
* get() { return this.#runInAsyncScope(() => asyncLocalStorage.getStore()); }
|
|
390
|
+
* }
|
|
391
|
+
*
|
|
392
|
+
* const foo = asyncLocalStorage.run(123, () => new Foo());
|
|
393
|
+
* console.log(asyncLocalStorage.run(321, () => foo.get())); // returns 123
|
|
394
|
+
* ```
|
|
395
|
+
* @since v19.8.0
|
|
396
|
+
* @experimental
|
|
397
|
+
* @return A new function with the signature `(fn: (...args) : R, ...args) : R`.
|
|
398
|
+
*/
|
|
399
|
+
static snapshot(): <R, TArgs extends any[]>(fn: (...args: TArgs) => R, ...args: TArgs) => R;
|
|
371
400
|
/**
|
|
372
401
|
* Disables the instance of `AsyncLocalStorage`. All subsequent calls
|
|
373
402
|
* to `asyncLocalStorage.getStore()` will return `undefined` until`asyncLocalStorage.run()` or `asyncLocalStorage.enterWith()` is called again.
|