@types/node 16.11.39 → 18.11.2
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 v16.11 → node}/LICENSE +0 -0
- node v16.11/README.md → node/README.md +4 -4
- {node v16.11 → node}/assert/strict.d.ts +0 -0
- node v16.11/assert.d.ts → node/assert.d.ts +7 -8
- node v16.11/async_hooks.d.ts → node/async_hooks.d.ts +8 -4
- node/buffer.d.ts +2258 -0
- node v16.11/child_process.d.ts → node/child_process.d.ts +6 -3
- node v16.11/cluster.d.ts → node/cluster.d.ts +14 -18
- node v16.11/console.d.ts → node/console.d.ts +1 -1
- {node v16.11 → node}/constants.d.ts +0 -0
- node v16.11/crypto.d.ts → node/crypto.d.ts +679 -53
- node v16.11/dgram.d.ts → node/dgram.d.ts +3 -3
- node v16.11/diagnostics_channel.d.ts → node/diagnostics_channel.d.ts +2 -1
- node v16.11/dns/promises.d.ts → node/dns/promises.d.ts +10 -8
- node v16.11/dns.d.ts → node/dns.d.ts +16 -11
- node/dom-events.d.ts +126 -0
- node v16.11/domain.d.ts → node/domain.d.ts +3 -2
- node v16.11/events.d.ts → node/events.d.ts +65 -10
- node v16.11/fs/promises.d.ts → node/fs/promises.d.ts +86 -39
- node v16.11/fs.d.ts → node/fs.d.ts +149 -67
- node/globals.d.ts +300 -0
- {node v16.11 → node}/globals.global.d.ts +0 -0
- node v16.11/http.d.ts → node/http.d.ts +305 -77
- node v16.11/http2.d.ts → node/http2.d.ts +38 -5
- node v16.11/https.d.ts → node/https.d.ts +209 -59
- node v16.11/index.d.ts → node/index.d.ts +6 -3
- node v16.11/inspector.d.ts → node/inspector.d.ts +11 -15
- {node v16.11 → node}/module.d.ts +0 -0
- node v16.11/net.d.ts → node/net.d.ts +94 -21
- node v16.11/os.d.ts → node/os.d.ts +15 -4
- node v16.11/package.json → node/package.json +15 -8
- node v16.11/path.d.ts → node/path.d.ts +34 -23
- node v16.11/perf_hooks.d.ts → node/perf_hooks.d.ts +76 -8
- node v16.11/process.d.ts → node/process.d.ts +17 -16
- node v16.11/punycode.d.ts → node/punycode.d.ts +1 -1
- node v16.11/querystring.d.ts → node/querystring.d.ts +4 -4
- node/readline/promises.d.ts +143 -0
- node v16.11/readline.d.ts → node/readline.d.ts +140 -30
- node v16.11/repl.d.ts → node/repl.d.ts +2 -2
- node v16.11/stream/consumers.d.ts → node/stream/consumers.d.ts +2 -14
- {node v16.11 → node}/stream/promises.d.ts +0 -0
- node v16.11/stream/web.d.ts → node/stream/web.d.ts +3 -65
- node v16.11/stream.d.ts → node/stream.d.ts +97 -19
- node v16.11/string_decoder.d.ts → node/string_decoder.d.ts +1 -1
- node/test.d.ts +314 -0
- {node v16.11 → node}/timers/promises.d.ts +0 -0
- node v16.11/timers.d.ts → node/timers.d.ts +1 -1
- node v16.11/tls.d.ts → node/tls.d.ts +32 -23
- node v16.11/trace_events.d.ts → node/trace_events.d.ts +11 -1
- node/ts4.8/assert/strict.d.ts +8 -0
- node/ts4.8/assert.d.ts +911 -0
- node/ts4.8/async_hooks.d.ts +501 -0
- node v16.11/buffer.d.ts → node/ts4.8/buffer.d.ts +46 -19
- node/ts4.8/child_process.d.ts +1369 -0
- node/ts4.8/cluster.d.ts +410 -0
- node/ts4.8/console.d.ts +412 -0
- node/ts4.8/constants.d.ts +18 -0
- node/ts4.8/crypto.d.ts +3964 -0
- node/ts4.8/dgram.d.ts +545 -0
- node/ts4.8/diagnostics_channel.d.ts +153 -0
- node/ts4.8/dns/promises.d.ts +370 -0
- node/ts4.8/dns.d.ts +659 -0
- node/ts4.8/dom-events.d.ts +126 -0
- node/ts4.8/domain.d.ts +170 -0
- node/ts4.8/events.d.ts +678 -0
- node/ts4.8/fs/promises.d.ts +1138 -0
- node/ts4.8/fs.d.ts +3872 -0
- node v16.11/globals.d.ts → node/ts4.8/globals.d.ts +14 -4
- node/ts4.8/globals.global.d.ts +1 -0
- node/ts4.8/http.d.ts +1607 -0
- node/ts4.8/http2.d.ts +2134 -0
- node/ts4.8/https.d.ts +541 -0
- node/ts4.8/index.d.ts +88 -0
- node/ts4.8/inspector.d.ts +2741 -0
- node/ts4.8/module.d.ts +114 -0
- node/ts4.8/net.d.ts +869 -0
- node/ts4.8/os.d.ts +466 -0
- node/ts4.8/path.d.ts +191 -0
- node/ts4.8/perf_hooks.d.ts +625 -0
- node/ts4.8/process.d.ts +1482 -0
- node/ts4.8/punycode.d.ts +117 -0
- node/ts4.8/querystring.d.ts +131 -0
- node/ts4.8/readline/promises.d.ts +143 -0
- node/ts4.8/readline.d.ts +653 -0
- node/ts4.8/repl.d.ts +424 -0
- node/ts4.8/stream/consumers.d.ts +12 -0
- node/ts4.8/stream/promises.d.ts +42 -0
- node/ts4.8/stream/web.d.ts +330 -0
- node/ts4.8/stream.d.ts +1340 -0
- node/ts4.8/string_decoder.d.ts +67 -0
- node/ts4.8/test.d.ts +314 -0
- node/ts4.8/timers/promises.d.ts +68 -0
- node/ts4.8/timers.d.ts +94 -0
- node/ts4.8/tls.d.ts +1028 -0
- node/ts4.8/trace_events.d.ts +171 -0
- node v16.11/tty.d.ts → node/ts4.8/tty.d.ts +4 -2
- node v16.11/url.d.ts → node/ts4.8/url.d.ts +85 -39
- node v16.11/util.d.ts → node/ts4.8/util.d.ts +268 -12
- node v16.11/v8.d.ts → node/ts4.8/v8.d.ts +21 -3
- node v16.11/vm.d.ts → node/ts4.8/vm.d.ts +6 -4
- node v16.11/wasi.d.ts → node/ts4.8/wasi.d.ts +1 -1
- node v16.11/worker_threads.d.ts → node/ts4.8/worker_threads.d.ts +50 -10
- node v16.11/zlib.d.ts → node/ts4.8/zlib.d.ts +1 -1
- node/tty.d.ts +206 -0
- node/url.d.ts +897 -0
- node/util.d.ts +1850 -0
- node/v8.d.ts +396 -0
- node/vm.d.ts +509 -0
- node/wasi.d.ts +158 -0
- node/worker_threads.d.ts +689 -0
- node/zlib.d.ts +517 -0
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `async_hooks` module provides an API to track asynchronous resources. It
|
|
3
|
+
* can be accessed using:
|
|
4
|
+
*
|
|
5
|
+
* ```js
|
|
6
|
+
* import async_hooks from 'async_hooks';
|
|
7
|
+
* ```
|
|
8
|
+
* @experimental
|
|
9
|
+
* @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/async_hooks.js)
|
|
10
|
+
*/
|
|
11
|
+
declare module 'async_hooks' {
|
|
12
|
+
/**
|
|
13
|
+
* ```js
|
|
14
|
+
* import { executionAsyncId } from 'async_hooks';
|
|
15
|
+
*
|
|
16
|
+
* console.log(executionAsyncId()); // 1 - bootstrap
|
|
17
|
+
* fs.open(path, 'r', (err, fd) => {
|
|
18
|
+
* console.log(executionAsyncId()); // 6 - open()
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* The ID returned from `executionAsyncId()` is related to execution timing, not
|
|
23
|
+
* causality (which is covered by `triggerAsyncId()`):
|
|
24
|
+
*
|
|
25
|
+
* ```js
|
|
26
|
+
* const server = net.createServer((conn) => {
|
|
27
|
+
* // Returns the ID of the server, not of the new connection, because the
|
|
28
|
+
* // callback runs in the execution scope of the server's MakeCallback().
|
|
29
|
+
* async_hooks.executionAsyncId();
|
|
30
|
+
*
|
|
31
|
+
* }).listen(port, () => {
|
|
32
|
+
* // Returns the ID of a TickObject (process.nextTick()) because all
|
|
33
|
+
* // callbacks passed to .listen() are wrapped in a nextTick().
|
|
34
|
+
* async_hooks.executionAsyncId();
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* Promise contexts may not get precise `executionAsyncIds` by default.
|
|
39
|
+
* See the section on `promise execution tracking`.
|
|
40
|
+
* @since v8.1.0
|
|
41
|
+
* @return The `asyncId` of the current execution context. Useful to track when something calls.
|
|
42
|
+
*/
|
|
43
|
+
function executionAsyncId(): number;
|
|
44
|
+
/**
|
|
45
|
+
* Resource objects returned by `executionAsyncResource()` are most often internal
|
|
46
|
+
* Node.js handle objects with undocumented APIs. Using any functions or properties
|
|
47
|
+
* on the object is likely to crash your application and should be avoided.
|
|
48
|
+
*
|
|
49
|
+
* Using `executionAsyncResource()` in the top-level execution context will
|
|
50
|
+
* return an empty object as there is no handle or request object to use,
|
|
51
|
+
* but having an object representing the top-level can be helpful.
|
|
52
|
+
*
|
|
53
|
+
* ```js
|
|
54
|
+
* import { open } from 'fs';
|
|
55
|
+
* import { executionAsyncId, executionAsyncResource } from 'async_hooks';
|
|
56
|
+
*
|
|
57
|
+
* console.log(executionAsyncId(), executionAsyncResource()); // 1 {}
|
|
58
|
+
* open(new URL(import.meta.url), 'r', (err, fd) => {
|
|
59
|
+
* console.log(executionAsyncId(), executionAsyncResource()); // 7 FSReqWrap
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* This can be used to implement continuation local storage without the
|
|
64
|
+
* use of a tracking `Map` to store the metadata:
|
|
65
|
+
*
|
|
66
|
+
* ```js
|
|
67
|
+
* import { createServer } from 'http';
|
|
68
|
+
* import {
|
|
69
|
+
* executionAsyncId,
|
|
70
|
+
* executionAsyncResource,
|
|
71
|
+
* createHook
|
|
72
|
+
* } from 'async_hooks';
|
|
73
|
+
* const sym = Symbol('state'); // Private symbol to avoid pollution
|
|
74
|
+
*
|
|
75
|
+
* createHook({
|
|
76
|
+
* init(asyncId, type, triggerAsyncId, resource) {
|
|
77
|
+
* const cr = executionAsyncResource();
|
|
78
|
+
* if (cr) {
|
|
79
|
+
* resource[sym] = cr[sym];
|
|
80
|
+
* }
|
|
81
|
+
* }
|
|
82
|
+
* }).enable();
|
|
83
|
+
*
|
|
84
|
+
* const server = createServer((req, res) => {
|
|
85
|
+
* executionAsyncResource()[sym] = { state: req.url };
|
|
86
|
+
* setTimeout(function() {
|
|
87
|
+
* res.end(JSON.stringify(executionAsyncResource()[sym]));
|
|
88
|
+
* }, 100);
|
|
89
|
+
* }).listen(3000);
|
|
90
|
+
* ```
|
|
91
|
+
* @since v13.9.0, v12.17.0
|
|
92
|
+
* @return The resource representing the current execution. Useful to store data within the resource.
|
|
93
|
+
*/
|
|
94
|
+
function executionAsyncResource(): object;
|
|
95
|
+
/**
|
|
96
|
+
* ```js
|
|
97
|
+
* const server = net.createServer((conn) => {
|
|
98
|
+
* // The resource that caused (or triggered) this callback to be called
|
|
99
|
+
* // was that of the new connection. Thus the return value of triggerAsyncId()
|
|
100
|
+
* // is the asyncId of "conn".
|
|
101
|
+
* async_hooks.triggerAsyncId();
|
|
102
|
+
*
|
|
103
|
+
* }).listen(port, () => {
|
|
104
|
+
* // Even though all callbacks passed to .listen() are wrapped in a nextTick()
|
|
105
|
+
* // the callback itself exists because the call to the server's .listen()
|
|
106
|
+
* // was made. So the return value would be the ID of the server.
|
|
107
|
+
* async_hooks.triggerAsyncId();
|
|
108
|
+
* });
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* Promise contexts may not get valid `triggerAsyncId`s by default. See
|
|
112
|
+
* the section on `promise execution tracking`.
|
|
113
|
+
* @return The ID of the resource responsible for calling the callback that is currently being executed.
|
|
114
|
+
*/
|
|
115
|
+
function triggerAsyncId(): number;
|
|
116
|
+
interface HookCallbacks {
|
|
117
|
+
/**
|
|
118
|
+
* Called when a class is constructed that has the possibility to emit an asynchronous event.
|
|
119
|
+
* @param asyncId a unique ID for the async resource
|
|
120
|
+
* @param type the type of the async resource
|
|
121
|
+
* @param triggerAsyncId the unique ID of the async resource in whose execution context this async resource was created
|
|
122
|
+
* @param resource reference to the resource representing the async operation, needs to be released during destroy
|
|
123
|
+
*/
|
|
124
|
+
init?(asyncId: number, type: string, triggerAsyncId: number, resource: object): void;
|
|
125
|
+
/**
|
|
126
|
+
* When an asynchronous operation is initiated or completes a callback is called to notify the user.
|
|
127
|
+
* The before callback is called just before said callback is executed.
|
|
128
|
+
* @param asyncId the unique identifier assigned to the resource about to execute the callback.
|
|
129
|
+
*/
|
|
130
|
+
before?(asyncId: number): void;
|
|
131
|
+
/**
|
|
132
|
+
* Called immediately after the callback specified in before is completed.
|
|
133
|
+
* @param asyncId the unique identifier assigned to the resource which has executed the callback.
|
|
134
|
+
*/
|
|
135
|
+
after?(asyncId: number): void;
|
|
136
|
+
/**
|
|
137
|
+
* Called when a promise has resolve() called. This may not be in the same execution id
|
|
138
|
+
* as the promise itself.
|
|
139
|
+
* @param asyncId the unique id for the promise that was resolve()d.
|
|
140
|
+
*/
|
|
141
|
+
promiseResolve?(asyncId: number): void;
|
|
142
|
+
/**
|
|
143
|
+
* Called after the resource corresponding to asyncId is destroyed
|
|
144
|
+
* @param asyncId a unique ID for the async resource
|
|
145
|
+
*/
|
|
146
|
+
destroy?(asyncId: number): void;
|
|
147
|
+
}
|
|
148
|
+
interface AsyncHook {
|
|
149
|
+
/**
|
|
150
|
+
* Enable the callbacks for a given AsyncHook instance. If no callbacks are provided enabling is a noop.
|
|
151
|
+
*/
|
|
152
|
+
enable(): this;
|
|
153
|
+
/**
|
|
154
|
+
* Disable the callbacks for a given AsyncHook instance from the global pool of AsyncHook callbacks to be executed. Once a hook has been disabled it will not be called again until enabled.
|
|
155
|
+
*/
|
|
156
|
+
disable(): this;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Registers functions to be called for different lifetime events of each async
|
|
160
|
+
* operation.
|
|
161
|
+
*
|
|
162
|
+
* The callbacks `init()`/`before()`/`after()`/`destroy()` are called for the
|
|
163
|
+
* respective asynchronous event during a resource's lifetime.
|
|
164
|
+
*
|
|
165
|
+
* All callbacks are optional. For example, if only resource cleanup needs to
|
|
166
|
+
* be tracked, then only the `destroy` callback needs to be passed. The
|
|
167
|
+
* specifics of all functions that can be passed to `callbacks` is in the `Hook Callbacks` section.
|
|
168
|
+
*
|
|
169
|
+
* ```js
|
|
170
|
+
* import { createHook } from 'async_hooks';
|
|
171
|
+
*
|
|
172
|
+
* const asyncHook = createHook({
|
|
173
|
+
* init(asyncId, type, triggerAsyncId, resource) { },
|
|
174
|
+
* destroy(asyncId) { }
|
|
175
|
+
* });
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* The callbacks will be inherited via the prototype chain:
|
|
179
|
+
*
|
|
180
|
+
* ```js
|
|
181
|
+
* class MyAsyncCallbacks {
|
|
182
|
+
* init(asyncId, type, triggerAsyncId, resource) { }
|
|
183
|
+
* destroy(asyncId) {}
|
|
184
|
+
* }
|
|
185
|
+
*
|
|
186
|
+
* class MyAddedCallbacks extends MyAsyncCallbacks {
|
|
187
|
+
* before(asyncId) { }
|
|
188
|
+
* after(asyncId) { }
|
|
189
|
+
* }
|
|
190
|
+
*
|
|
191
|
+
* const asyncHook = async_hooks.createHook(new MyAddedCallbacks());
|
|
192
|
+
* ```
|
|
193
|
+
*
|
|
194
|
+
* Because promises are asynchronous resources whose lifecycle is tracked
|
|
195
|
+
* via the async hooks mechanism, the `init()`, `before()`, `after()`, and`destroy()` callbacks _must not_ be async functions that return promises.
|
|
196
|
+
* @since v8.1.0
|
|
197
|
+
* @param callbacks The `Hook Callbacks` to register
|
|
198
|
+
* @return Instance used for disabling and enabling hooks
|
|
199
|
+
*/
|
|
200
|
+
function createHook(callbacks: HookCallbacks): AsyncHook;
|
|
201
|
+
interface AsyncResourceOptions {
|
|
202
|
+
/**
|
|
203
|
+
* The ID of the execution context that created this async event.
|
|
204
|
+
* @default executionAsyncId()
|
|
205
|
+
*/
|
|
206
|
+
triggerAsyncId?: number | undefined;
|
|
207
|
+
/**
|
|
208
|
+
* Disables automatic `emitDestroy` when the object is garbage collected.
|
|
209
|
+
* This usually does not need to be set (even if `emitDestroy` is called
|
|
210
|
+
* manually), unless the resource's `asyncId` is retrieved and the
|
|
211
|
+
* sensitive API's `emitDestroy` is called with it.
|
|
212
|
+
* @default false
|
|
213
|
+
*/
|
|
214
|
+
requireManualDestroy?: boolean | undefined;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* The class `AsyncResource` is designed to be extended by the embedder's async
|
|
218
|
+
* resources. Using this, users can easily trigger the lifetime events of their
|
|
219
|
+
* own resources.
|
|
220
|
+
*
|
|
221
|
+
* The `init` hook will trigger when an `AsyncResource` is instantiated.
|
|
222
|
+
*
|
|
223
|
+
* The following is an overview of the `AsyncResource` API.
|
|
224
|
+
*
|
|
225
|
+
* ```js
|
|
226
|
+
* import { AsyncResource, executionAsyncId } from 'async_hooks';
|
|
227
|
+
*
|
|
228
|
+
* // AsyncResource() is meant to be extended. Instantiating a
|
|
229
|
+
* // new AsyncResource() also triggers init. If triggerAsyncId is omitted then
|
|
230
|
+
* // async_hook.executionAsyncId() is used.
|
|
231
|
+
* const asyncResource = new AsyncResource(
|
|
232
|
+
* type, { triggerAsyncId: executionAsyncId(), requireManualDestroy: false }
|
|
233
|
+
* );
|
|
234
|
+
*
|
|
235
|
+
* // Run a function in the execution context of the resource. This will
|
|
236
|
+
* // * establish the context of the resource
|
|
237
|
+
* // * trigger the AsyncHooks before callbacks
|
|
238
|
+
* // * call the provided function `fn` with the supplied arguments
|
|
239
|
+
* // * trigger the AsyncHooks after callbacks
|
|
240
|
+
* // * restore the original execution context
|
|
241
|
+
* asyncResource.runInAsyncScope(fn, thisArg, ...args);
|
|
242
|
+
*
|
|
243
|
+
* // Call AsyncHooks destroy callbacks.
|
|
244
|
+
* asyncResource.emitDestroy();
|
|
245
|
+
*
|
|
246
|
+
* // Return the unique ID assigned to the AsyncResource instance.
|
|
247
|
+
* asyncResource.asyncId();
|
|
248
|
+
*
|
|
249
|
+
* // Return the trigger ID for the AsyncResource instance.
|
|
250
|
+
* asyncResource.triggerAsyncId();
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
class AsyncResource {
|
|
254
|
+
/**
|
|
255
|
+
* AsyncResource() is meant to be extended. Instantiating a
|
|
256
|
+
* new AsyncResource() also triggers init. If triggerAsyncId is omitted then
|
|
257
|
+
* async_hook.executionAsyncId() is used.
|
|
258
|
+
* @param type The type of async event.
|
|
259
|
+
* @param triggerAsyncId The ID of the execution context that created
|
|
260
|
+
* this async event (default: `executionAsyncId()`), or an
|
|
261
|
+
* AsyncResourceOptions object (since v9.3.0)
|
|
262
|
+
*/
|
|
263
|
+
constructor(type: string, triggerAsyncId?: number | AsyncResourceOptions);
|
|
264
|
+
/**
|
|
265
|
+
* 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
|
+
* @since v14.8.0, v12.19.0
|
|
270
|
+
* @param fn The function to bind to the current execution context.
|
|
271
|
+
* @param type An optional name to associate with the underlying `AsyncResource`.
|
|
272
|
+
*/
|
|
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
|
+
};
|
|
280
|
+
/**
|
|
281
|
+
* 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
|
+
* @since v14.8.0, v12.19.0
|
|
286
|
+
* @param fn The function to bind to the current `AsyncResource`.
|
|
287
|
+
*/
|
|
288
|
+
bind<Func extends (...args: any[]) => any>(
|
|
289
|
+
fn: Func
|
|
290
|
+
): Func & {
|
|
291
|
+
asyncResource: AsyncResource;
|
|
292
|
+
};
|
|
293
|
+
/**
|
|
294
|
+
* Call the provided function with the provided arguments in the execution context
|
|
295
|
+
* of the async resource. This will establish the context, trigger the AsyncHooks
|
|
296
|
+
* before callbacks, call the function, trigger the AsyncHooks after callbacks, and
|
|
297
|
+
* then restore the original execution context.
|
|
298
|
+
* @since v9.6.0
|
|
299
|
+
* @param fn The function to call in the execution context of this async resource.
|
|
300
|
+
* @param thisArg The receiver to be used for the function call.
|
|
301
|
+
* @param args Optional arguments to pass to the function.
|
|
302
|
+
*/
|
|
303
|
+
runInAsyncScope<This, Result>(fn: (this: This, ...args: any[]) => Result, thisArg?: This, ...args: any[]): Result;
|
|
304
|
+
/**
|
|
305
|
+
* Call all `destroy` hooks. This should only ever be called once. An error will
|
|
306
|
+
* be thrown if it is called more than once. This **must** be manually called. If
|
|
307
|
+
* the resource is left to be collected by the GC then the `destroy` hooks will
|
|
308
|
+
* never be called.
|
|
309
|
+
* @return A reference to `asyncResource`.
|
|
310
|
+
*/
|
|
311
|
+
emitDestroy(): this;
|
|
312
|
+
/**
|
|
313
|
+
* @return The unique `asyncId` assigned to the resource.
|
|
314
|
+
*/
|
|
315
|
+
asyncId(): number;
|
|
316
|
+
/**
|
|
317
|
+
*
|
|
318
|
+
* @return The same `triggerAsyncId` that is passed to the `AsyncResource` constructor.
|
|
319
|
+
*/
|
|
320
|
+
triggerAsyncId(): number;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* This class creates stores that stay coherent through asynchronous operations.
|
|
324
|
+
*
|
|
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.
|
|
328
|
+
*
|
|
329
|
+
* The following example uses `AsyncLocalStorage` to build a simple logger
|
|
330
|
+
* that assigns IDs to incoming HTTP requests and includes them in messages
|
|
331
|
+
* logged within each request.
|
|
332
|
+
*
|
|
333
|
+
* ```js
|
|
334
|
+
* import http from 'http';
|
|
335
|
+
* import { AsyncLocalStorage } from 'async_hooks';
|
|
336
|
+
*
|
|
337
|
+
* const asyncLocalStorage = new AsyncLocalStorage();
|
|
338
|
+
*
|
|
339
|
+
* function logWithId(msg) {
|
|
340
|
+
* const id = asyncLocalStorage.getStore();
|
|
341
|
+
* console.log(`${id !== undefined ? id : '-'}:`, msg);
|
|
342
|
+
* }
|
|
343
|
+
*
|
|
344
|
+
* let idSeq = 0;
|
|
345
|
+
* http.createServer((req, res) => {
|
|
346
|
+
* asyncLocalStorage.run(idSeq++, () => {
|
|
347
|
+
* logWithId('start');
|
|
348
|
+
* // Imagine any chain of async operations here
|
|
349
|
+
* setImmediate(() => {
|
|
350
|
+
* logWithId('finish');
|
|
351
|
+
* res.end();
|
|
352
|
+
* });
|
|
353
|
+
* });
|
|
354
|
+
* }).listen(8080);
|
|
355
|
+
*
|
|
356
|
+
* http.get('http://localhost:8080');
|
|
357
|
+
* http.get('http://localhost:8080');
|
|
358
|
+
* // Prints:
|
|
359
|
+
* // 0: start
|
|
360
|
+
* // 1: start
|
|
361
|
+
* // 0: finish
|
|
362
|
+
* // 1: finish
|
|
363
|
+
* ```
|
|
364
|
+
*
|
|
365
|
+
* Each instance of `AsyncLocalStorage` maintains an independent storage context.
|
|
366
|
+
* Multiple instances can safely exist simultaneously without risk of interfering
|
|
367
|
+
* with each other's data.
|
|
368
|
+
* @since v13.10.0, v12.17.0
|
|
369
|
+
*/
|
|
370
|
+
class AsyncLocalStorage<T> {
|
|
371
|
+
/**
|
|
372
|
+
* Disables the instance of `AsyncLocalStorage`. All subsequent calls
|
|
373
|
+
* to `asyncLocalStorage.getStore()` will return `undefined` until`asyncLocalStorage.run()` or `asyncLocalStorage.enterWith()` is called again.
|
|
374
|
+
*
|
|
375
|
+
* When calling `asyncLocalStorage.disable()`, all current contexts linked to the
|
|
376
|
+
* instance will be exited.
|
|
377
|
+
*
|
|
378
|
+
* Calling `asyncLocalStorage.disable()` is required before the`asyncLocalStorage` can be garbage collected. This does not apply to stores
|
|
379
|
+
* provided by the `asyncLocalStorage`, as those objects are garbage collected
|
|
380
|
+
* along with the corresponding async resources.
|
|
381
|
+
*
|
|
382
|
+
* Use this method when the `asyncLocalStorage` is not in use anymore
|
|
383
|
+
* in the current process.
|
|
384
|
+
* @since v13.10.0, v12.17.0
|
|
385
|
+
* @experimental
|
|
386
|
+
*/
|
|
387
|
+
disable(): void;
|
|
388
|
+
/**
|
|
389
|
+
* Returns the current store.
|
|
390
|
+
* If called outside of an asynchronous context initialized by
|
|
391
|
+
* calling `asyncLocalStorage.run()` or `asyncLocalStorage.enterWith()`, it
|
|
392
|
+
* returns `undefined`.
|
|
393
|
+
* @since v13.10.0, v12.17.0
|
|
394
|
+
*/
|
|
395
|
+
getStore(): T | undefined;
|
|
396
|
+
/**
|
|
397
|
+
* Runs a function synchronously within a context and returns its
|
|
398
|
+
* return value. The store is not accessible outside of the callback function.
|
|
399
|
+
* The store is accessible to any asynchronous operations created within the
|
|
400
|
+
* callback.
|
|
401
|
+
*
|
|
402
|
+
* The optional `args` are passed to the callback function.
|
|
403
|
+
*
|
|
404
|
+
* If the callback function throws an error, the error is thrown by `run()` too.
|
|
405
|
+
* The stacktrace is not impacted by this call and the context is exited.
|
|
406
|
+
*
|
|
407
|
+
* Example:
|
|
408
|
+
*
|
|
409
|
+
* ```js
|
|
410
|
+
* const store = { id: 2 };
|
|
411
|
+
* try {
|
|
412
|
+
* asyncLocalStorage.run(store, () => {
|
|
413
|
+
* asyncLocalStorage.getStore(); // Returns the store object
|
|
414
|
+
* setTimeout(() => {
|
|
415
|
+
* asyncLocalStorage.getStore(); // Returns the store object
|
|
416
|
+
* }, 200);
|
|
417
|
+
* throw new Error();
|
|
418
|
+
* });
|
|
419
|
+
* } catch (e) {
|
|
420
|
+
* asyncLocalStorage.getStore(); // Returns undefined
|
|
421
|
+
* // The error will be caught here
|
|
422
|
+
* }
|
|
423
|
+
* ```
|
|
424
|
+
* @since v13.10.0, v12.17.0
|
|
425
|
+
*/
|
|
426
|
+
run<R, TArgs extends any[]>(store: T, callback: (...args: TArgs) => R, ...args: TArgs): R;
|
|
427
|
+
/**
|
|
428
|
+
* Runs a function synchronously outside of a context and returns its
|
|
429
|
+
* return value. The store is not accessible within the callback function or
|
|
430
|
+
* the asynchronous operations created within the callback. Any `getStore()`call done within the callback function will always return `undefined`.
|
|
431
|
+
*
|
|
432
|
+
* The optional `args` are passed to the callback function.
|
|
433
|
+
*
|
|
434
|
+
* If the callback function throws an error, the error is thrown by `exit()` too.
|
|
435
|
+
* The stacktrace is not impacted by this call and the context is re-entered.
|
|
436
|
+
*
|
|
437
|
+
* Example:
|
|
438
|
+
*
|
|
439
|
+
* ```js
|
|
440
|
+
* // Within a call to run
|
|
441
|
+
* try {
|
|
442
|
+
* asyncLocalStorage.getStore(); // Returns the store object or value
|
|
443
|
+
* asyncLocalStorage.exit(() => {
|
|
444
|
+
* asyncLocalStorage.getStore(); // Returns undefined
|
|
445
|
+
* throw new Error();
|
|
446
|
+
* });
|
|
447
|
+
* } catch (e) {
|
|
448
|
+
* asyncLocalStorage.getStore(); // Returns the same object or value
|
|
449
|
+
* // The error will be caught here
|
|
450
|
+
* }
|
|
451
|
+
* ```
|
|
452
|
+
* @since v13.10.0, v12.17.0
|
|
453
|
+
* @experimental
|
|
454
|
+
*/
|
|
455
|
+
exit<R, TArgs extends any[]>(callback: (...args: TArgs) => R, ...args: TArgs): R;
|
|
456
|
+
/**
|
|
457
|
+
* Transitions into the context for the remainder of the current
|
|
458
|
+
* synchronous execution and then persists the store through any following
|
|
459
|
+
* asynchronous calls.
|
|
460
|
+
*
|
|
461
|
+
* Example:
|
|
462
|
+
*
|
|
463
|
+
* ```js
|
|
464
|
+
* const store = { id: 1 };
|
|
465
|
+
* // Replaces previous store with the given store object
|
|
466
|
+
* asyncLocalStorage.enterWith(store);
|
|
467
|
+
* asyncLocalStorage.getStore(); // Returns the store object
|
|
468
|
+
* someAsyncOperation(() => {
|
|
469
|
+
* asyncLocalStorage.getStore(); // Returns the same object
|
|
470
|
+
* });
|
|
471
|
+
* ```
|
|
472
|
+
*
|
|
473
|
+
* This transition will continue for the _entire_ synchronous execution.
|
|
474
|
+
* This means that if, for example, the context is entered within an event
|
|
475
|
+
* handler subsequent event handlers will also run within that context unless
|
|
476
|
+
* specifically bound to another context with an `AsyncResource`. That is why`run()` should be preferred over `enterWith()` unless there are strong reasons
|
|
477
|
+
* to use the latter method.
|
|
478
|
+
*
|
|
479
|
+
* ```js
|
|
480
|
+
* const store = { id: 1 };
|
|
481
|
+
*
|
|
482
|
+
* emitter.on('my-event', () => {
|
|
483
|
+
* asyncLocalStorage.enterWith(store);
|
|
484
|
+
* });
|
|
485
|
+
* emitter.on('my-event', () => {
|
|
486
|
+
* asyncLocalStorage.getStore(); // Returns the same object
|
|
487
|
+
* });
|
|
488
|
+
*
|
|
489
|
+
* asyncLocalStorage.getStore(); // Returns undefined
|
|
490
|
+
* emitter.emit('my-event');
|
|
491
|
+
* asyncLocalStorage.getStore(); // Returns the same object
|
|
492
|
+
* ```
|
|
493
|
+
* @since v13.11.0, v12.17.0
|
|
494
|
+
* @experimental
|
|
495
|
+
*/
|
|
496
|
+
enterWith(store: T): void;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
declare module 'node:async_hooks' {
|
|
500
|
+
export * from 'async_hooks';
|
|
501
|
+
}
|
|
@@ -41,10 +41,11 @@
|
|
|
41
41
|
* // Creates a Buffer containing the Latin-1 bytes [0x74, 0xe9, 0x73, 0x74].
|
|
42
42
|
* const buf7 = Buffer.from('tést', 'latin1');
|
|
43
43
|
* ```
|
|
44
|
-
* @see [source](https://github.com/nodejs/node/blob/
|
|
44
|
+
* @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/buffer.js)
|
|
45
45
|
*/
|
|
46
46
|
declare module 'buffer' {
|
|
47
47
|
import { BinaryLike } from 'node:crypto';
|
|
48
|
+
import { ReadableStream as WebReadableStream } from 'node:stream/web';
|
|
48
49
|
export const INSPECT_MAX_BYTES: number;
|
|
49
50
|
export const kMaxLength: number;
|
|
50
51
|
export const kStringMaxLength: number;
|
|
@@ -113,18 +114,17 @@ declare module 'buffer' {
|
|
|
113
114
|
/**
|
|
114
115
|
* A [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) encapsulates immutable, raw data that can be safely shared across
|
|
115
116
|
* multiple worker threads.
|
|
116
|
-
* @since v15.7.0
|
|
117
|
-
* @experimental
|
|
117
|
+
* @since v15.7.0, v14.18.0
|
|
118
118
|
*/
|
|
119
119
|
export class Blob {
|
|
120
120
|
/**
|
|
121
121
|
* The total size of the `Blob` in bytes.
|
|
122
|
-
* @since v15.7.0
|
|
122
|
+
* @since v15.7.0, v14.18.0
|
|
123
123
|
*/
|
|
124
124
|
readonly size: number;
|
|
125
125
|
/**
|
|
126
126
|
* The content-type of the `Blob`.
|
|
127
|
-
* @since v15.7.0
|
|
127
|
+
* @since v15.7.0, v14.18.0
|
|
128
128
|
*/
|
|
129
129
|
readonly type: string;
|
|
130
130
|
/**
|
|
@@ -139,13 +139,13 @@ declare module 'buffer' {
|
|
|
139
139
|
/**
|
|
140
140
|
* Returns a promise that fulfills with an [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) containing a copy of
|
|
141
141
|
* the `Blob` data.
|
|
142
|
-
* @since v15.7.0
|
|
142
|
+
* @since v15.7.0, v14.18.0
|
|
143
143
|
*/
|
|
144
144
|
arrayBuffer(): Promise<ArrayBuffer>;
|
|
145
145
|
/**
|
|
146
146
|
* Creates and returns a new `Blob` containing a subset of this `Blob` objects
|
|
147
147
|
* data. The original `Blob` is not altered.
|
|
148
|
-
* @since v15.7.0
|
|
148
|
+
* @since v15.7.0, v14.18.0
|
|
149
149
|
* @param start The starting index.
|
|
150
150
|
* @param end The ending index.
|
|
151
151
|
* @param type The content-type for the new `Blob`
|
|
@@ -154,17 +154,24 @@ declare module 'buffer' {
|
|
|
154
154
|
/**
|
|
155
155
|
* Returns a promise that fulfills with the contents of the `Blob` decoded as a
|
|
156
156
|
* UTF-8 string.
|
|
157
|
-
* @since v15.7.0
|
|
157
|
+
* @since v15.7.0, v14.18.0
|
|
158
158
|
*/
|
|
159
159
|
text(): Promise<string>;
|
|
160
160
|
/**
|
|
161
|
-
* Returns a new `ReadableStream` that allows the content of the `Blob` to be read.
|
|
161
|
+
* Returns a new (WHATWG) `ReadableStream` that allows the content of the `Blob` to be read.
|
|
162
162
|
* @since v16.7.0
|
|
163
163
|
*/
|
|
164
|
-
stream():
|
|
164
|
+
stream(): WebReadableStream;
|
|
165
165
|
}
|
|
166
166
|
export import atob = globalThis.atob;
|
|
167
167
|
export import btoa = globalThis.btoa;
|
|
168
|
+
|
|
169
|
+
import { Blob as NodeBlob } from 'buffer';
|
|
170
|
+
// This conditional type will be the existing global Blob in a browser, or
|
|
171
|
+
// the copy below in a Node environment.
|
|
172
|
+
type __Blob = typeof globalThis extends { onmessage: any, Blob: any }
|
|
173
|
+
? {} : NodeBlob;
|
|
174
|
+
|
|
168
175
|
global {
|
|
169
176
|
// Buffer class
|
|
170
177
|
type BufferEncoding = 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex';
|
|
@@ -390,7 +397,7 @@ declare module 'buffer' {
|
|
|
390
397
|
* @since v0.11.13
|
|
391
398
|
* @return Either `-1`, `0`, or `1`, depending on the result of the comparison. See `compare` for details.
|
|
392
399
|
*/
|
|
393
|
-
compare(buf1: Uint8Array, buf2: Uint8Array):
|
|
400
|
+
compare(buf1: Uint8Array, buf2: Uint8Array): -1 | 0 | 1;
|
|
394
401
|
/**
|
|
395
402
|
* Allocates a new `Buffer` of `size` bytes. If `fill` is `undefined`, the`Buffer` will be zero-filled.
|
|
396
403
|
*
|
|
@@ -443,7 +450,7 @@ declare module 'buffer' {
|
|
|
443
450
|
* Allocates a new `Buffer` of `size` bytes. If `size` is larger than {@link constants.MAX_LENGTH} or smaller than 0, `ERR_INVALID_ARG_VALUE` is thrown.
|
|
444
451
|
*
|
|
445
452
|
* The underlying memory for `Buffer` instances created in this way is _not_
|
|
446
|
-
* _initialized_. The contents of the newly created `Buffer` are unknown
|
|
453
|
+
* _initialized_. The contents of the newly created `Buffer` are unknown and _may contain sensitive data_. Use `Buffer.alloc()` instead to initialize`Buffer` instances with zeroes.
|
|
447
454
|
*
|
|
448
455
|
* ```js
|
|
449
456
|
* import { Buffer } from 'buffer';
|
|
@@ -481,7 +488,7 @@ declare module 'buffer' {
|
|
|
481
488
|
* if `size` is 0.
|
|
482
489
|
*
|
|
483
490
|
* The underlying memory for `Buffer` instances created in this way is _not_
|
|
484
|
-
* _initialized_. The contents of the newly created `Buffer` are unknown
|
|
491
|
+
* _initialized_. The contents of the newly created `Buffer` are unknown and _may contain sensitive data_. Use `buf.fill(0)` to initialize
|
|
485
492
|
* such `Buffer` instances with zeroes.
|
|
486
493
|
*
|
|
487
494
|
* When using `Buffer.allocUnsafe()` to allocate new `Buffer` instances,
|
|
@@ -704,7 +711,7 @@ declare module 'buffer' {
|
|
|
704
711
|
* @param [sourceStart=0] The offset within `buf` at which to begin comparison.
|
|
705
712
|
* @param [sourceEnd=buf.length] The offset within `buf` at which to end comparison (not inclusive).
|
|
706
713
|
*/
|
|
707
|
-
compare(target: Uint8Array, targetStart?: number, targetEnd?: number, sourceStart?: number, sourceEnd?: number):
|
|
714
|
+
compare(target: Uint8Array, targetStart?: number, targetEnd?: number, sourceStart?: number, sourceEnd?: number): -1 | 0 | 1;
|
|
708
715
|
/**
|
|
709
716
|
* Copies data from a region of `buf` to a region in `target`, even if the `target`memory region overlaps with `buf`.
|
|
710
717
|
*
|
|
@@ -763,8 +770,6 @@ declare module 'buffer' {
|
|
|
763
770
|
* Returns a new `Buffer` that references the same memory as the original, but
|
|
764
771
|
* offset and cropped by the `start` and `end` indices.
|
|
765
772
|
*
|
|
766
|
-
* This is the same behavior as `buf.subarray()`.
|
|
767
|
-
*
|
|
768
773
|
* This method is not compatible with the `Uint8Array.prototype.slice()`,
|
|
769
774
|
* which is a superclass of `Buffer`. To copy the slice, use`Uint8Array.prototype.slice()`.
|
|
770
775
|
*
|
|
@@ -780,8 +785,17 @@ declare module 'buffer' {
|
|
|
780
785
|
*
|
|
781
786
|
* console.log(buf.toString());
|
|
782
787
|
* // Prints: buffer
|
|
788
|
+
*
|
|
789
|
+
* // With buf.slice(), the original buffer is modified.
|
|
790
|
+
* const notReallyCopiedBuf = buf.slice();
|
|
791
|
+
* notReallyCopiedBuf[0]++;
|
|
792
|
+
* console.log(notReallyCopiedBuf.toString());
|
|
793
|
+
* // Prints: cuffer
|
|
794
|
+
* console.log(buf.toString());
|
|
795
|
+
* // Also prints: cuffer (!)
|
|
783
796
|
* ```
|
|
784
797
|
* @since v0.3.0
|
|
798
|
+
* @deprecated Use `subarray` instead.
|
|
785
799
|
* @param [start=0] Where the new `Buffer` will start.
|
|
786
800
|
* @param [end=buf.length] Where the new `Buffer` will end (not inclusive).
|
|
787
801
|
*/
|
|
@@ -1948,7 +1962,7 @@ declare module 'buffer' {
|
|
|
1948
1962
|
*
|
|
1949
1963
|
* * a string, `value` is interpreted according to the character encoding in`encoding`.
|
|
1950
1964
|
* * a `Buffer` or [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array), `value` will be used in its entirety.
|
|
1951
|
-
* To compare a partial `Buffer`, use `buf.
|
|
1965
|
+
* To compare a partial `Buffer`, use `buf.subarray`.
|
|
1952
1966
|
* * a number, `value` will be interpreted as an unsigned 8-bit integer
|
|
1953
1967
|
* value between `0` and `255`.
|
|
1954
1968
|
*
|
|
@@ -2204,7 +2218,7 @@ declare module 'buffer' {
|
|
|
2204
2218
|
* **binary data and predate the introduction of typed arrays in JavaScript.**
|
|
2205
2219
|
* **For code running using Node.js APIs, converting between base64-encoded strings**
|
|
2206
2220
|
* **and binary data should be performed using `Buffer.from(str, 'base64')` and`buf.toString('base64')`.**
|
|
2207
|
-
* @since v15.13.0
|
|
2221
|
+
* @since v15.13.0, v14.17.0
|
|
2208
2222
|
* @deprecated Use `Buffer.from(data, 'base64')` instead.
|
|
2209
2223
|
* @param data The Base64-encoded input string.
|
|
2210
2224
|
*/
|
|
@@ -2220,11 +2234,24 @@ declare module 'buffer' {
|
|
|
2220
2234
|
* **binary data and predate the introduction of typed arrays in JavaScript.**
|
|
2221
2235
|
* **For code running using Node.js APIs, converting between base64-encoded strings**
|
|
2222
2236
|
* **and binary data should be performed using `Buffer.from(str, 'base64')` and`buf.toString('base64')`.**
|
|
2223
|
-
* @since v15.13.0
|
|
2237
|
+
* @since v15.13.0, v14.17.0
|
|
2224
2238
|
* @deprecated Use `buf.toString('base64')` instead.
|
|
2225
2239
|
* @param data An ASCII (Latin1) string.
|
|
2226
2240
|
*/
|
|
2227
2241
|
function btoa(data: string): string;
|
|
2242
|
+
|
|
2243
|
+
interface Blob extends __Blob {}
|
|
2244
|
+
/**
|
|
2245
|
+
* `Blob` class is a global reference for `require('node:buffer').Blob`
|
|
2246
|
+
* https://nodejs.org/api/buffer.html#class-blob
|
|
2247
|
+
* @since v18.0.0
|
|
2248
|
+
*/
|
|
2249
|
+
var Blob: typeof globalThis extends {
|
|
2250
|
+
onmessage: any;
|
|
2251
|
+
Blob: infer T;
|
|
2252
|
+
}
|
|
2253
|
+
? T
|
|
2254
|
+
: typeof NodeBlob;
|
|
2228
2255
|
}
|
|
2229
2256
|
}
|
|
2230
2257
|
declare module 'node:buffer' {
|