@types/node 18.19.21 → 18.19.23

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 (56) hide show
  1. node v18.19/README.md +2 -2
  2. node v18.19/package.json +3 -15
  3. node v18.19/ts4.8/assert/strict.d.ts +0 -8
  4. node v18.19/ts4.8/assert.d.ts +0 -985
  5. node v18.19/ts4.8/async_hooks.d.ts +0 -522
  6. node v18.19/ts4.8/buffer.d.ts +0 -2353
  7. node v18.19/ts4.8/child_process.d.ts +0 -1544
  8. node v18.19/ts4.8/cluster.d.ts +0 -432
  9. node v18.19/ts4.8/console.d.ts +0 -412
  10. node v18.19/ts4.8/constants.d.ts +0 -19
  11. node v18.19/ts4.8/crypto.d.ts +0 -4457
  12. node v18.19/ts4.8/dgram.d.ts +0 -596
  13. node v18.19/ts4.8/diagnostics_channel.d.ts +0 -546
  14. node v18.19/ts4.8/dns/promises.d.ts +0 -381
  15. node v18.19/ts4.8/dns.d.ts +0 -809
  16. node v18.19/ts4.8/dom-events.d.ts +0 -122
  17. node v18.19/ts4.8/domain.d.ts +0 -170
  18. node v18.19/ts4.8/events.d.ts +0 -819
  19. node v18.19/ts4.8/fs/promises.d.ts +0 -1205
  20. node v18.19/ts4.8/fs.d.ts +0 -4231
  21. node v18.19/ts4.8/globals.d.ts +0 -377
  22. node v18.19/ts4.8/globals.global.d.ts +0 -1
  23. node v18.19/ts4.8/http.d.ts +0 -1803
  24. node v18.19/ts4.8/http2.d.ts +0 -2386
  25. node v18.19/ts4.8/https.d.ts +0 -544
  26. node v18.19/ts4.8/index.d.ts +0 -88
  27. node v18.19/ts4.8/inspector.d.ts +0 -2739
  28. node v18.19/ts4.8/module.d.ts +0 -298
  29. node v18.19/ts4.8/net.d.ts +0 -918
  30. node v18.19/ts4.8/os.d.ts +0 -473
  31. node v18.19/ts4.8/path.d.ts +0 -191
  32. node v18.19/ts4.8/perf_hooks.d.ts +0 -626
  33. node v18.19/ts4.8/process.d.ts +0 -1548
  34. node v18.19/ts4.8/punycode.d.ts +0 -117
  35. node v18.19/ts4.8/querystring.d.ts +0 -141
  36. node v18.19/ts4.8/readline/promises.d.ts +0 -143
  37. node v18.19/ts4.8/readline.d.ts +0 -666
  38. node v18.19/ts4.8/repl.d.ts +0 -430
  39. node v18.19/ts4.8/stream/consumers.d.ts +0 -12
  40. node v18.19/ts4.8/stream/promises.d.ts +0 -83
  41. node v18.19/ts4.8/stream/web.d.ts +0 -352
  42. node v18.19/ts4.8/stream.d.ts +0 -1731
  43. node v18.19/ts4.8/string_decoder.d.ts +0 -67
  44. node v18.19/ts4.8/test.d.ts +0 -1113
  45. node v18.19/ts4.8/timers/promises.d.ts +0 -93
  46. node v18.19/ts4.8/timers.d.ts +0 -126
  47. node v18.19/ts4.8/tls.d.ts +0 -1203
  48. node v18.19/ts4.8/trace_events.d.ts +0 -171
  49. node v18.19/ts4.8/tty.d.ts +0 -206
  50. node v18.19/ts4.8/url.d.ts +0 -954
  51. node v18.19/ts4.8/util.d.ts +0 -2075
  52. node v18.19/ts4.8/v8.d.ts +0 -753
  53. node v18.19/ts4.8/vm.d.ts +0 -667
  54. node v18.19/ts4.8/wasi.d.ts +0 -158
  55. node v18.19/ts4.8/worker_threads.d.ts +0 -692
  56. node v18.19/ts4.8/zlib.d.ts +0 -517
@@ -1,692 +0,0 @@
1
- /**
2
- * The `worker_threads` module enables the use of threads that execute JavaScript
3
- * in parallel. To access it:
4
- *
5
- * ```js
6
- * const worker = require('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
- * const {
18
- * Worker, isMainThread, parentPort, workerData
19
- * } = require('worker_threads');
20
- *
21
- * if (isMainThread) {
22
- * module.exports = function parseJSAsync(script) {
23
- * return new Promise((resolve, reject) => {
24
- * const worker = new Worker(__filename, {
25
- * workerData: script
26
- * });
27
- * worker.on('message', resolve);
28
- * worker.on('error', reject);
29
- * worker.on('exit', (code) => {
30
- * if (code !== 0)
31
- * reject(new Error(`Worker stopped with exit code ${code}`));
32
- * });
33
- * });
34
- * };
35
- * } else {
36
- * const { parse } = require('some-js-parsing-library');
37
- * const script = workerData;
38
- * parentPort.postMessage(parse(script));
39
- * }
40
- * ```
41
- *
42
- * The above example spawns a Worker thread for each `parseJSAsync()` call. In
43
- * practice, use a pool of Workers for these kinds of tasks. Otherwise, the
44
- * overhead of creating Workers would likely exceed their benefit.
45
- *
46
- * When implementing a worker pool, use the `AsyncResource` API to inform
47
- * diagnostic tools (e.g. to provide asynchronous stack traces) about the
48
- * correlation between tasks and their outcomes. See `"Using AsyncResource for a Worker thread pool"` in the `async_hooks` documentation for an example implementation.
49
- *
50
- * Worker threads inherit non-process-specific options by default. Refer to `Worker constructor options` to know how to customize worker thread options,
51
- * specifically `argv` and `execArgv` options.
52
- * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/worker_threads.js)
53
- */
54
- declare module "worker_threads" {
55
- import { Blob } from "node:buffer";
56
- import { Context } from "node:vm";
57
- import { EventEmitter } from "node:events";
58
- import { EventLoopUtilityFunction } from "node:perf_hooks";
59
- import { FileHandle } from "node:fs/promises";
60
- import { Readable, Writable } from "node:stream";
61
- import { URL } from "node:url";
62
- import { X509Certificate } from "node:crypto";
63
- const isMainThread: boolean;
64
- const parentPort: null | MessagePort;
65
- const resourceLimits: ResourceLimits;
66
- const SHARE_ENV: unique symbol;
67
- const threadId: number;
68
- const workerData: any;
69
- /**
70
- * Instances of the `worker.MessageChannel` class represent an asynchronous,
71
- * two-way communications channel.
72
- * The `MessageChannel` has no methods of its own. `new MessageChannel()`yields an object with `port1` and `port2` properties, which refer to linked `MessagePort` instances.
73
- *
74
- * ```js
75
- * const { MessageChannel } = require('worker_threads');
76
- *
77
- * const { port1, port2 } = new MessageChannel();
78
- * port1.on('message', (message) => console.log('received', message));
79
- * port2.postMessage({ foo: 'bar' });
80
- * // Prints: received { foo: 'bar' } from the `port1.on('message')` listener
81
- * ```
82
- * @since v10.5.0
83
- */
84
- class MessageChannel {
85
- readonly port1: MessagePort;
86
- readonly port2: MessagePort;
87
- }
88
- interface WorkerPerformance {
89
- eventLoopUtilization: EventLoopUtilityFunction;
90
- }
91
- type TransferListItem = ArrayBuffer | MessagePort | FileHandle | X509Certificate | Blob;
92
- /**
93
- * Instances of the `worker.MessagePort` class represent one end of an
94
- * asynchronous, two-way communications channel. It can be used to transfer
95
- * structured data, memory regions and other `MessagePort`s between different `Worker` s.
96
- *
97
- * This implementation matches [browser `MessagePort`](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort) s.
98
- * @since v10.5.0
99
- */
100
- class MessagePort extends EventEmitter {
101
- /**
102
- * Disables further sending of messages on either side of the connection.
103
- * This method can be called when no further communication will happen over this`MessagePort`.
104
- *
105
- * The `'close' event` is emitted on both `MessagePort` instances that
106
- * are part of the channel.
107
- * @since v10.5.0
108
- */
109
- close(): void;
110
- /**
111
- * Sends a JavaScript value to the receiving side of this channel.`value` is transferred in a way which is compatible with
112
- * the [HTML structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm).
113
- *
114
- * In particular, the significant differences to `JSON` are:
115
- *
116
- * * `value` may contain circular references.
117
- * * `value` may contain instances of builtin JS types such as `RegExp`s,`BigInt`s, `Map`s, `Set`s, etc.
118
- * * `value` may contain typed arrays, both using `ArrayBuffer`s
119
- * and `SharedArrayBuffer`s.
120
- * * `value` may contain [`WebAssembly.Module`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module) instances.
121
- * * `value` may not contain native (C++-backed) objects other than:
122
- *
123
- * ```js
124
- * const { MessageChannel } = require('worker_threads');
125
- * const { port1, port2 } = new MessageChannel();
126
- *
127
- * port1.on('message', (message) => console.log(message));
128
- *
129
- * const circularData = {};
130
- * circularData.foo = circularData;
131
- * // Prints: { foo: [Circular] }
132
- * port2.postMessage(circularData);
133
- * ```
134
- *
135
- * `transferList` may be a list of [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer), `MessagePort` and `FileHandle` objects.
136
- * After transferring, they are not usable on the sending side of the channel
137
- * anymore (even if they are not contained in `value`). Unlike with `child processes`, transferring handles such as network sockets is currently
138
- * not supported.
139
- *
140
- * If `value` contains [`SharedArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) instances, those are accessible
141
- * from either thread. They cannot be listed in `transferList`.
142
- *
143
- * `value` may still contain `ArrayBuffer` instances that are not in`transferList`; in that case, the underlying memory is copied rather than moved.
144
- *
145
- * ```js
146
- * const { MessageChannel } = require('worker_threads');
147
- * const { port1, port2 } = new MessageChannel();
148
- *
149
- * port1.on('message', (message) => console.log(message));
150
- *
151
- * const uint8Array = new Uint8Array([ 1, 2, 3, 4 ]);
152
- * // This posts a copy of `uint8Array`:
153
- * port2.postMessage(uint8Array);
154
- * // This does not copy data, but renders `uint8Array` unusable:
155
- * port2.postMessage(uint8Array, [ uint8Array.buffer ]);
156
- *
157
- * // The memory for the `sharedUint8Array` is accessible from both the
158
- * // original and the copy received by `.on('message')`:
159
- * const sharedUint8Array = new Uint8Array(new SharedArrayBuffer(4));
160
- * port2.postMessage(sharedUint8Array);
161
- *
162
- * // This transfers a freshly created message port to the receiver.
163
- * // This can be used, for example, to create communication channels between
164
- * // multiple `Worker` threads that are children of the same parent thread.
165
- * const otherChannel = new MessageChannel();
166
- * port2.postMessage({ port: otherChannel.port1 }, [ otherChannel.port1 ]);
167
- * ```
168
- *
169
- * The message object is cloned immediately, and can be modified after
170
- * posting without having side effects.
171
- *
172
- * For more information on the serialization and deserialization mechanisms
173
- * behind this API, see the `serialization API of the v8 module`.
174
- * @since v10.5.0
175
- */
176
- postMessage(value: any, transferList?: readonly TransferListItem[]): void;
177
- /**
178
- * Opposite of `unref()`. Calling `ref()` on a previously `unref()`ed port does _not_ let the program exit if it's the only active handle left (the default
179
- * behavior). If the port is `ref()`ed, calling `ref()` again has no effect.
180
- *
181
- * If listeners are attached or removed using `.on('message')`, the port
182
- * is `ref()`ed and `unref()`ed automatically depending on whether
183
- * listeners for the event exist.
184
- * @since v10.5.0
185
- */
186
- ref(): void;
187
- /**
188
- * Calling `unref()` on a port allows the thread to exit if this is the only
189
- * active handle in the event system. If the port is already `unref()`ed calling`unref()` again has no effect.
190
- *
191
- * If listeners are attached or removed using `.on('message')`, the port is`ref()`ed and `unref()`ed automatically depending on whether
192
- * listeners for the event exist.
193
- * @since v10.5.0
194
- */
195
- unref(): void;
196
- /**
197
- * Starts receiving messages on this `MessagePort`. When using this port
198
- * as an event emitter, this is called automatically once `'message'`listeners are attached.
199
- *
200
- * This method exists for parity with the Web `MessagePort` API. In Node.js,
201
- * it is only useful for ignoring messages when no event listener is present.
202
- * Node.js also diverges in its handling of `.onmessage`. Setting it
203
- * automatically calls `.start()`, but unsetting it lets messages queue up
204
- * until a new handler is set or the port is discarded.
205
- * @since v10.5.0
206
- */
207
- start(): void;
208
- addListener(event: "close", listener: () => void): this;
209
- addListener(event: "message", listener: (value: any) => void): this;
210
- addListener(event: "messageerror", listener: (error: Error) => void): this;
211
- addListener(event: string | symbol, listener: (...args: any[]) => void): this;
212
- emit(event: "close"): boolean;
213
- emit(event: "message", value: any): boolean;
214
- emit(event: "messageerror", error: Error): boolean;
215
- emit(event: string | symbol, ...args: any[]): boolean;
216
- on(event: "close", listener: () => void): this;
217
- on(event: "message", listener: (value: any) => void): this;
218
- on(event: "messageerror", listener: (error: Error) => void): this;
219
- on(event: string | symbol, listener: (...args: any[]) => void): this;
220
- once(event: "close", listener: () => void): this;
221
- once(event: "message", listener: (value: any) => void): this;
222
- once(event: "messageerror", listener: (error: Error) => void): this;
223
- once(event: string | symbol, listener: (...args: any[]) => void): this;
224
- prependListener(event: "close", listener: () => void): this;
225
- prependListener(event: "message", listener: (value: any) => void): this;
226
- prependListener(event: "messageerror", listener: (error: Error) => void): this;
227
- prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
228
- prependOnceListener(event: "close", listener: () => void): this;
229
- prependOnceListener(event: "message", listener: (value: any) => void): this;
230
- prependOnceListener(event: "messageerror", listener: (error: Error) => void): this;
231
- prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
232
- removeListener(event: "close", listener: () => void): this;
233
- removeListener(event: "message", listener: (value: any) => void): this;
234
- removeListener(event: "messageerror", listener: (error: Error) => void): this;
235
- removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
236
- off(event: "close", listener: () => void): this;
237
- off(event: "message", listener: (value: any) => void): this;
238
- off(event: "messageerror", listener: (error: Error) => void): this;
239
- off(event: string | symbol, listener: (...args: any[]) => void): this;
240
- }
241
- interface WorkerOptions {
242
- /**
243
- * List of arguments which would be stringified and appended to
244
- * `process.argv` in the worker. This is mostly similar to the `workerData`
245
- * but the values will be available on the global `process.argv` as if they
246
- * were passed as CLI options to the script.
247
- */
248
- argv?: any[] | undefined;
249
- env?: NodeJS.Dict<string> | typeof SHARE_ENV | undefined;
250
- eval?: boolean | undefined;
251
- workerData?: any;
252
- stdin?: boolean | undefined;
253
- stdout?: boolean | undefined;
254
- stderr?: boolean | undefined;
255
- execArgv?: string[] | undefined;
256
- resourceLimits?: ResourceLimits | undefined;
257
- /**
258
- * Additional data to send in the first worker message.
259
- */
260
- transferList?: TransferListItem[] | undefined;
261
- /**
262
- * @default true
263
- */
264
- trackUnmanagedFds?: boolean | undefined;
265
- /**
266
- * An optional `name` to be appended to the worker title
267
- * for debuggin/identification purposes, making the final title as
268
- * `[worker ${id}] ${name}`.
269
- */
270
- name?: string | undefined;
271
- }
272
- interface ResourceLimits {
273
- /**
274
- * The maximum size of a heap space for recently created objects.
275
- */
276
- maxYoungGenerationSizeMb?: number | undefined;
277
- /**
278
- * The maximum size of the main heap in MB.
279
- */
280
- maxOldGenerationSizeMb?: number | undefined;
281
- /**
282
- * The size of a pre-allocated memory range used for generated code.
283
- */
284
- codeRangeSizeMb?: number | undefined;
285
- /**
286
- * The default maximum stack size for the thread. Small values may lead to unusable Worker instances.
287
- * @default 4
288
- */
289
- stackSizeMb?: number | undefined;
290
- }
291
- /**
292
- * The `Worker` class represents an independent JavaScript execution thread.
293
- * Most Node.js APIs are available inside of it.
294
- *
295
- * Notable differences inside a Worker environment are:
296
- *
297
- * * The `process.stdin`, `process.stdout` and `process.stderr` may be redirected by the parent thread.
298
- * * The `require('worker_threads').isMainThread` property is set to `false`.
299
- * * The `require('worker_threads').parentPort` message port is available.
300
- * * `process.exit()` does not stop the whole program, just the single thread,
301
- * and `process.abort()` is not available.
302
- * * `process.chdir()` and `process` methods that set group or user ids
303
- * are not available.
304
- * * `process.env` is a copy of the parent thread's environment variables,
305
- * unless otherwise specified. Changes to one copy are not visible in other
306
- * threads, and are not visible to native add-ons (unless `worker.SHARE_ENV` is passed as the `env` option to the `Worker` constructor).
307
- * * `process.title` cannot be modified.
308
- * * Signals are not delivered through `process.on('...')`.
309
- * * Execution may stop at any point as a result of `worker.terminate()` being invoked.
310
- * * IPC channels from parent processes are not accessible.
311
- * * The `trace_events` module is not supported.
312
- * * Native add-ons can only be loaded from multiple threads if they fulfill `certain conditions`.
313
- *
314
- * Creating `Worker` instances inside of other `Worker`s is possible.
315
- *
316
- * Like [Web Workers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) and the `cluster module`, two-way communication can be
317
- * achieved through inter-thread message passing. Internally, a `Worker` has a
318
- * built-in pair of `MessagePort` s that are already associated with each other
319
- * when the `Worker` is created. While the `MessagePort` object on the parent side
320
- * is not directly exposed, its functionalities are exposed through `worker.postMessage()` and the `worker.on('message')` event
321
- * on the `Worker` object for the parent thread.
322
- *
323
- * To create custom messaging channels (which is encouraged over using the default
324
- * global channel because it facilitates separation of concerns), users can create
325
- * a `MessageChannel` object on either thread and pass one of the`MessagePort`s on that `MessageChannel` to the other thread through a
326
- * pre-existing channel, such as the global one.
327
- *
328
- * See `port.postMessage()` for more information on how messages are passed,
329
- * and what kind of JavaScript values can be successfully transported through
330
- * the thread barrier.
331
- *
332
- * ```js
333
- * const assert = require('assert');
334
- * const {
335
- * Worker, MessageChannel, MessagePort, isMainThread, parentPort
336
- * } = require('worker_threads');
337
- * if (isMainThread) {
338
- * const worker = new Worker(__filename);
339
- * const subChannel = new MessageChannel();
340
- * worker.postMessage({ hereIsYourPort: subChannel.port1 }, [subChannel.port1]);
341
- * subChannel.port2.on('message', (value) => {
342
- * console.log('received:', value);
343
- * });
344
- * } else {
345
- * parentPort.once('message', (value) => {
346
- * assert(value.hereIsYourPort instanceof MessagePort);
347
- * value.hereIsYourPort.postMessage('the worker is sending this');
348
- * value.hereIsYourPort.close();
349
- * });
350
- * }
351
- * ```
352
- * @since v10.5.0
353
- */
354
- class Worker extends EventEmitter {
355
- /**
356
- * If `stdin: true` was passed to the `Worker` constructor, this is a
357
- * writable stream. The data written to this stream will be made available in
358
- * the worker thread as `process.stdin`.
359
- * @since v10.5.0
360
- */
361
- readonly stdin: Writable | null;
362
- /**
363
- * This is a readable stream which contains data written to `process.stdout` inside the worker thread. If `stdout: true` was not passed to the `Worker` constructor, then data is piped to the
364
- * parent thread's `process.stdout` stream.
365
- * @since v10.5.0
366
- */
367
- readonly stdout: Readable;
368
- /**
369
- * This is a readable stream which contains data written to `process.stderr` inside the worker thread. If `stderr: true` was not passed to the `Worker` constructor, then data is piped to the
370
- * parent thread's `process.stderr` stream.
371
- * @since v10.5.0
372
- */
373
- readonly stderr: Readable;
374
- /**
375
- * An integer identifier for the referenced thread. Inside the worker thread,
376
- * it is available as `require('worker_threads').threadId`.
377
- * This value is unique for each `Worker` instance inside a single process.
378
- * @since v10.5.0
379
- */
380
- readonly threadId: number;
381
- /**
382
- * Provides the set of JS engine resource constraints for this Worker thread.
383
- * If the `resourceLimits` option was passed to the `Worker` constructor,
384
- * this matches its values.
385
- *
386
- * If the worker has stopped, the return value is an empty object.
387
- * @since v13.2.0, v12.16.0
388
- */
389
- readonly resourceLimits?: ResourceLimits | undefined;
390
- /**
391
- * An object that can be used to query performance information from a worker
392
- * instance. Similar to `perf_hooks.performance`.
393
- * @since v15.1.0, v14.17.0, v12.22.0
394
- */
395
- readonly performance: WorkerPerformance;
396
- /**
397
- * @param filename The path to the Worker’s main script or module.
398
- * Must be either an absolute path or a relative path (i.e. relative to the current working directory) starting with ./ or ../,
399
- * or a WHATWG URL object using file: protocol. If options.eval is true, this is a string containing JavaScript code rather than a path.
400
- */
401
- constructor(filename: string | URL, options?: WorkerOptions);
402
- /**
403
- * Send a message to the worker that is received via `require('worker_threads').parentPort.on('message')`.
404
- * See `port.postMessage()` for more details.
405
- * @since v10.5.0
406
- */
407
- postMessage(value: any, transferList?: readonly TransferListItem[]): void;
408
- /**
409
- * Opposite of `unref()`, calling `ref()` on a previously `unref()`ed worker does _not_ let the program exit if it's the only active handle left (the default
410
- * behavior). If the worker is `ref()`ed, calling `ref()` again has
411
- * no effect.
412
- * @since v10.5.0
413
- */
414
- ref(): void;
415
- /**
416
- * Calling `unref()` on a worker allows the thread to exit if this is the only
417
- * active handle in the event system. If the worker is already `unref()`ed calling`unref()` again has no effect.
418
- * @since v10.5.0
419
- */
420
- unref(): void;
421
- /**
422
- * Stop all JavaScript execution in the worker thread as soon as possible.
423
- * Returns a Promise for the exit code that is fulfilled when the `'exit' event` is emitted.
424
- * @since v10.5.0
425
- */
426
- terminate(): Promise<number>;
427
- /**
428
- * Returns a readable stream for a V8 snapshot of the current state of the Worker.
429
- * See `v8.getHeapSnapshot()` for more details.
430
- *
431
- * If the Worker thread is no longer running, which may occur before the `'exit' event` is emitted, the returned `Promise` is rejected
432
- * immediately with an `ERR_WORKER_NOT_RUNNING` error.
433
- * @since v13.9.0, v12.17.0
434
- * @return A promise for a Readable Stream containing a V8 heap snapshot
435
- */
436
- getHeapSnapshot(): Promise<Readable>;
437
- addListener(event: "error", listener: (err: Error) => void): this;
438
- addListener(event: "exit", listener: (exitCode: number) => void): this;
439
- addListener(event: "message", listener: (value: any) => void): this;
440
- addListener(event: "messageerror", listener: (error: Error) => void): this;
441
- addListener(event: "online", listener: () => void): this;
442
- addListener(event: string | symbol, listener: (...args: any[]) => void): this;
443
- emit(event: "error", err: Error): boolean;
444
- emit(event: "exit", exitCode: number): boolean;
445
- emit(event: "message", value: any): boolean;
446
- emit(event: "messageerror", error: Error): boolean;
447
- emit(event: "online"): boolean;
448
- emit(event: string | symbol, ...args: any[]): boolean;
449
- on(event: "error", listener: (err: Error) => void): this;
450
- on(event: "exit", listener: (exitCode: number) => void): this;
451
- on(event: "message", listener: (value: any) => void): this;
452
- on(event: "messageerror", listener: (error: Error) => void): this;
453
- on(event: "online", listener: () => void): this;
454
- on(event: string | symbol, listener: (...args: any[]) => void): this;
455
- once(event: "error", listener: (err: Error) => void): this;
456
- once(event: "exit", listener: (exitCode: number) => void): this;
457
- once(event: "message", listener: (value: any) => void): this;
458
- once(event: "messageerror", listener: (error: Error) => void): this;
459
- once(event: "online", listener: () => void): this;
460
- once(event: string | symbol, listener: (...args: any[]) => void): this;
461
- prependListener(event: "error", listener: (err: Error) => void): this;
462
- prependListener(event: "exit", listener: (exitCode: number) => void): this;
463
- prependListener(event: "message", listener: (value: any) => void): this;
464
- prependListener(event: "messageerror", listener: (error: Error) => void): this;
465
- prependListener(event: "online", listener: () => void): this;
466
- prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
467
- prependOnceListener(event: "error", listener: (err: Error) => void): this;
468
- prependOnceListener(event: "exit", listener: (exitCode: number) => void): this;
469
- prependOnceListener(event: "message", listener: (value: any) => void): this;
470
- prependOnceListener(event: "messageerror", listener: (error: Error) => void): this;
471
- prependOnceListener(event: "online", listener: () => void): this;
472
- prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
473
- removeListener(event: "error", listener: (err: Error) => void): this;
474
- removeListener(event: "exit", listener: (exitCode: number) => void): this;
475
- removeListener(event: "message", listener: (value: any) => void): this;
476
- removeListener(event: "messageerror", listener: (error: Error) => void): this;
477
- removeListener(event: "online", listener: () => void): this;
478
- removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
479
- off(event: "error", listener: (err: Error) => void): this;
480
- off(event: "exit", listener: (exitCode: number) => void): this;
481
- off(event: "message", listener: (value: any) => void): this;
482
- off(event: "messageerror", listener: (error: Error) => void): this;
483
- off(event: "online", listener: () => void): this;
484
- off(event: string | symbol, listener: (...args: any[]) => void): this;
485
- }
486
- interface BroadcastChannel extends NodeJS.RefCounted {}
487
- /**
488
- * Instances of `BroadcastChannel` allow asynchronous one-to-many communication
489
- * with all other `BroadcastChannel` instances bound to the same channel name.
490
- *
491
- * ```js
492
- * 'use strict';
493
- *
494
- * const {
495
- * isMainThread,
496
- * BroadcastChannel,
497
- * Worker
498
- * } = require('worker_threads');
499
- *
500
- * const bc = new BroadcastChannel('hello');
501
- *
502
- * if (isMainThread) {
503
- * let c = 0;
504
- * bc.onmessage = (event) => {
505
- * console.log(event.data);
506
- * if (++c === 10) bc.close();
507
- * };
508
- * for (let n = 0; n < 10; n++)
509
- * new Worker(__filename);
510
- * } else {
511
- * bc.postMessage('hello from every worker');
512
- * bc.close();
513
- * }
514
- * ```
515
- * @since v15.4.0
516
- */
517
- class BroadcastChannel {
518
- readonly name: string;
519
- /**
520
- * Invoked with a single \`MessageEvent\` argument when a message is received.
521
- * @since v15.4.0
522
- */
523
- onmessage: (message: unknown) => void;
524
- /**
525
- * Invoked with a received message cannot be deserialized.
526
- * @since v15.4.0
527
- */
528
- onmessageerror: (message: unknown) => void;
529
- constructor(name: string);
530
- /**
531
- * Closes the `BroadcastChannel` connection.
532
- * @since v15.4.0
533
- */
534
- close(): void;
535
- /**
536
- * @since v15.4.0
537
- * @param message Any cloneable JavaScript value.
538
- */
539
- postMessage(message: unknown): void;
540
- }
541
- /**
542
- * Mark an object as not transferable. If `object` occurs in the transfer list of
543
- * a `port.postMessage()` call, it is ignored.
544
- *
545
- * In particular, this makes sense for objects that can be cloned, rather than
546
- * transferred, and which are used by other objects on the sending side.
547
- * For example, Node.js marks the `ArrayBuffer`s it uses for its `Buffer pool` with this.
548
- *
549
- * This operation cannot be undone.
550
- *
551
- * ```js
552
- * const { MessageChannel, markAsUntransferable } = require('worker_threads');
553
- *
554
- * const pooledBuffer = new ArrayBuffer(8);
555
- * const typedArray1 = new Uint8Array(pooledBuffer);
556
- * const typedArray2 = new Float64Array(pooledBuffer);
557
- *
558
- * markAsUntransferable(pooledBuffer);
559
- *
560
- * const { port1 } = new MessageChannel();
561
- * port1.postMessage(typedArray1, [ typedArray1.buffer ]);
562
- *
563
- * // The following line prints the contents of typedArray1 -- it still owns
564
- * // its memory and has been cloned, not transferred. Without
565
- * // `markAsUntransferable()`, this would print an empty Uint8Array.
566
- * // typedArray2 is intact as well.
567
- * console.log(typedArray1);
568
- * console.log(typedArray2);
569
- * ```
570
- *
571
- * There is no equivalent to this API in browsers.
572
- * @since v14.5.0, v12.19.0
573
- */
574
- function markAsUntransferable(object: object): void;
575
- /**
576
- * Transfer a `MessagePort` to a different `vm` Context. The original `port`object is rendered unusable, and the returned `MessagePort` instance
577
- * takes its place.
578
- *
579
- * The returned `MessagePort` is an object in the target context and
580
- * inherits from its global `Object` class. Objects passed to the [`port.onmessage()`](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/onmessage) listener are also created in the
581
- * target context
582
- * and inherit from its global `Object` class.
583
- *
584
- * However, the created `MessagePort` no longer inherits from [`EventTarget`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget), and only
585
- * [`port.onmessage()`](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/onmessage) can be used to receive
586
- * events using it.
587
- * @since v11.13.0
588
- * @param port The message port to transfer.
589
- * @param contextifiedSandbox A `contextified` object as returned by the `vm.createContext()` method.
590
- */
591
- function moveMessagePortToContext(port: MessagePort, contextifiedSandbox: Context): MessagePort;
592
- /**
593
- * Receive a single message from a given `MessagePort`. If no message is available,`undefined` is returned, otherwise an object with a single `message` property
594
- * that contains the message payload, corresponding to the oldest message in the`MessagePort`’s queue.
595
- *
596
- * ```js
597
- * const { MessageChannel, receiveMessageOnPort } = require('worker_threads');
598
- * const { port1, port2 } = new MessageChannel();
599
- * port1.postMessage({ hello: 'world' });
600
- *
601
- * console.log(receiveMessageOnPort(port2));
602
- * // Prints: { message: { hello: 'world' } }
603
- * console.log(receiveMessageOnPort(port2));
604
- * // Prints: undefined
605
- * ```
606
- *
607
- * When this function is used, no `'message'` event is emitted and the`onmessage` listener is not invoked.
608
- * @since v12.3.0
609
- */
610
- function receiveMessageOnPort(port: MessagePort):
611
- | {
612
- message: any;
613
- }
614
- | undefined;
615
- type Serializable = string | object | number | boolean | bigint;
616
- /**
617
- * Within a worker thread, `worker.getEnvironmentData()` returns a clone
618
- * of data passed to the spawning thread's `worker.setEnvironmentData()`.
619
- * Every new `Worker` receives its own copy of the environment data
620
- * automatically.
621
- *
622
- * ```js
623
- * const {
624
- * Worker,
625
- * isMainThread,
626
- * setEnvironmentData,
627
- * getEnvironmentData,
628
- * } = require('worker_threads');
629
- *
630
- * if (isMainThread) {
631
- * setEnvironmentData('Hello', 'World!');
632
- * const worker = new Worker(__filename);
633
- * } else {
634
- * console.log(getEnvironmentData('Hello')); // Prints 'World!'.
635
- * }
636
- * ```
637
- * @since v15.12.0, v14.18.0
638
- * @param key Any arbitrary, cloneable JavaScript value that can be used as a {Map} key.
639
- */
640
- function getEnvironmentData(key: Serializable): Serializable;
641
- /**
642
- * The `worker.setEnvironmentData()` API sets the content of`worker.getEnvironmentData()` in the current thread and all new `Worker`instances spawned from the current context.
643
- * @since v15.12.0, v14.18.0
644
- * @param key Any arbitrary, cloneable JavaScript value that can be used as a {Map} key.
645
- * @param value Any arbitrary, cloneable JavaScript value that will be cloned and passed automatically to all new `Worker` instances. If `value` is passed as `undefined`, any previously set value
646
- * for the `key` will be deleted.
647
- */
648
- function setEnvironmentData(key: Serializable, value: Serializable): void;
649
-
650
- import {
651
- BroadcastChannel as _BroadcastChannel,
652
- MessageChannel as _MessageChannel,
653
- MessagePort as _MessagePort,
654
- } from "worker_threads";
655
- global {
656
- /**
657
- * `BroadcastChannel` class is a global reference for `require('worker_threads').BroadcastChannel`
658
- * https://nodejs.org/api/globals.html#broadcastchannel
659
- * @since v18.0.0
660
- */
661
- var BroadcastChannel: typeof globalThis extends {
662
- onmessage: any;
663
- BroadcastChannel: infer T;
664
- } ? T
665
- : typeof _BroadcastChannel;
666
-
667
- /**
668
- * `MessageChannel` class is a global reference for `require('worker_threads').MessageChannel`
669
- * https://nodejs.org/api/globals.html#messagechannel
670
- * @since v15.0.0
671
- */
672
- var MessageChannel: typeof globalThis extends {
673
- onmessage: any;
674
- MessageChannel: infer T;
675
- } ? T
676
- : typeof _MessageChannel;
677
-
678
- /**
679
- * `MessagePort` class is a global reference for `require('worker_threads').MessagePort`
680
- * https://nodejs.org/api/globals.html#messageport
681
- * @since v15.0.0
682
- */
683
- var MessagePort: typeof globalThis extends {
684
- onmessage: any;
685
- MessagePort: infer T;
686
- } ? T
687
- : typeof _MessagePort;
688
- }
689
- }
690
- declare module "node:worker_threads" {
691
- export * from "worker_threads";
692
- }