@types/node 24.12.0 → 25.5.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 v24.12/README.md → node/README.md +2 -2
- node v24.12/assert/strict.d.ts → node/assert/strict.d.ts +5 -11
- node v24.12/assert.d.ts → node/assert.d.ts +11 -171
- node v24.12/async_hooks.d.ts → node/async_hooks.d.ts +8 -8
- node v24.12/buffer.buffer.d.ts → node/buffer.buffer.d.ts +1 -7
- node v24.12/buffer.d.ts → node/buffer.d.ts +44 -168
- node v24.12/child_process.d.ts → node/child_process.d.ts +21 -64
- node/cluster.d.ts +486 -0
- node/console.d.ts +151 -0
- node v24.12/constants.d.ts → node/constants.d.ts +3 -4
- node v24.12/crypto.d.ts → node/crypto.d.ts +287 -1639
- node v24.12/dgram.d.ts → node/dgram.d.ts +15 -51
- node v24.12/diagnostics_channel.d.ts → node/diagnostics_channel.d.ts +4 -4
- node v24.12/dns/promises.d.ts → node/dns/promises.d.ts +3 -3
- node v24.12/dns.d.ts → node/dns.d.ts +131 -132
- node v24.12/domain.d.ts → node/domain.d.ts +13 -17
- node v24.12/events.d.ts → node/events.d.ts +866 -795
- node v24.12/fs/promises.d.ts → node/fs/promises.d.ts +7 -8
- node v24.12/fs.d.ts → node/fs.d.ts +419 -455
- node v24.12/globals.d.ts → node/globals.d.ts +6 -26
- node/globals.typedarray.d.ts +101 -0
- node v24.12/http.d.ts → node/http.d.ts +310 -276
- node v24.12/http2.d.ts → node/http2.d.ts +528 -804
- node v24.12/https.d.ts → node/https.d.ts +63 -243
- node v24.12/index.d.ts → node/index.d.ts +15 -1
- node/inspector/promises.d.ts +41 -0
- node v24.12/inspector.d.ts → node/inspector.d.ts +42 -50
- node v24.12/inspector.generated.d.ts → node/inspector.generated.d.ts +572 -417
- node v24.12/module.d.ts → node/module.d.ts +47 -195
- node v24.12/net.d.ts → node/net.d.ts +68 -189
- node v24.12/os.d.ts → node/os.d.ts +6 -6
- node v24.12/package.json → node/package.json +3 -3
- node/path/posix.d.ts +8 -0
- node/path/win32.d.ts +8 -0
- node/path.d.ts +187 -0
- node/perf_hooks.d.ts +643 -0
- node v24.12/process.d.ts → node/process.d.ts +219 -127
- node v24.12/punycode.d.ts → node/punycode.d.ts +5 -5
- node v24.12/querystring.d.ts → node/querystring.d.ts +4 -4
- node/quic.d.ts +910 -0
- node v24.12/readline/promises.d.ts → node/readline/promises.d.ts +3 -3
- node v24.12/readline.d.ts → node/readline.d.ts +68 -120
- node v24.12/repl.d.ts → node/repl.d.ts +75 -98
- node v24.12/sea.d.ts → node/sea.d.ts +1 -1
- node v24.12/sqlite.d.ts → node/sqlite.d.ts +137 -30
- node v24.12/stream/consumers.d.ts → node/stream/consumers.d.ts +10 -10
- node/stream/promises.d.ts +211 -0
- node/stream/web.d.ts +296 -0
- node v24.12/stream.d.ts → node/stream.d.ts +565 -478
- node v24.12/string_decoder.d.ts → node/string_decoder.d.ts +4 -4
- node/test/reporters.d.ts +96 -0
- node v24.12/test.d.ts → node/test.d.ts +134 -199
- node v24.12/timers/promises.d.ts → node/timers/promises.d.ts +4 -4
- node v24.12/timers.d.ts → node/timers.d.ts +4 -130
- node v24.12/tls.d.ts → node/tls.d.ts +109 -179
- node v24.12/trace_events.d.ts → node/trace_events.d.ts +9 -9
- node v24.12/ts5.6/buffer.buffer.d.ts → node/ts5.6/buffer.buffer.d.ts +1 -7
- node v24.12/ts5.6/index.d.ts → node/ts5.6/index.d.ts +15 -1
- node v24.12/ts5.7/index.d.ts → node/ts5.7/index.d.ts +15 -1
- node v24.12/tty.d.ts → node/tty.d.ts +58 -16
- node/url.d.ts +541 -0
- node/util/types.d.ts +558 -0
- node v24.12/util.d.ts → node/util.d.ts +150 -796
- node v24.12/v8.d.ts → node/v8.d.ts +31 -21
- node v24.12/vm.d.ts → node/vm.d.ts +43 -30
- node v24.12/wasi.d.ts → node/wasi.d.ts +4 -4
- node v24.12/web-globals/abortcontroller.d.ts → node/web-globals/abortcontroller.d.ts +27 -2
- node/web-globals/blob.d.ts +23 -0
- node/web-globals/console.d.ts +9 -0
- node v24.12/web-globals/crypto.d.ts → node/web-globals/crypto.d.ts +7 -0
- node/web-globals/encoding.d.ts +11 -0
- node v24.12/web-globals/events.d.ts → node/web-globals/events.d.ts +9 -0
- node v24.12/web-globals/fetch.d.ts → node/web-globals/fetch.d.ts +7 -0
- node/web-globals/importmeta.d.ts +13 -0
- node/web-globals/messaging.d.ts +23 -0
- node/web-globals/performance.d.ts +45 -0
- node/web-globals/streams.d.ts +115 -0
- node/web-globals/timers.d.ts +44 -0
- node/web-globals/url.d.ts +24 -0
- node v24.12/worker_threads.d.ts → node/worker_threads.d.ts +186 -363
- node v24.12/zlib.d.ts → node/zlib.d.ts +8 -71
- node v24.12/cluster.d.ts +0 -578
- node v24.12/console.d.ts +0 -453
- node v24.12/globals.typedarray.d.ts +0 -41
- node v24.12/path.d.ts +0 -200
- node v24.12/perf_hooks.d.ts +0 -1042
- node v24.12/stream/promises.d.ts +0 -90
- node v24.12/stream/web.d.ts +0 -573
- node v24.12/url.d.ts +0 -1057
- node v24.12/web-globals/streams.d.ts +0 -22
- {node v24.12 → node}/LICENSE +0 -0
- {node v24.12 → node}/compatibility/iterators.d.ts +0 -0
- {node v24.12 → node}/ts5.6/compatibility/float16array.d.ts +0 -0
- {node v24.12 → node}/ts5.6/globals.typedarray.d.ts +0 -0
- {node v24.12 → node}/ts5.7/compatibility/float16array.d.ts +0 -0
- {node v24.12 → node}/web-globals/domexception.d.ts +0 -0
- {node v24.12 → node}/web-globals/navigator.d.ts +0 -0
- {node v24.12 → node}/web-globals/storage.d.ts +0 -0
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* JavaScript in parallel. To access it:
|
|
4
4
|
*
|
|
5
5
|
* ```js
|
|
6
|
-
* import
|
|
6
|
+
* import worker from 'node:worker_threads';
|
|
7
7
|
* ```
|
|
8
8
|
*
|
|
9
9
|
* Workers (threads) are useful for performing CPU-intensive JavaScript operations.
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
* workerData: script,
|
|
34
34
|
* });
|
|
35
35
|
* worker.on('message', resolve);
|
|
36
|
-
* worker.
|
|
37
|
-
* worker.
|
|
36
|
+
* worker.once('error', reject);
|
|
37
|
+
* worker.once('exit', (code) => {
|
|
38
38
|
* if (code !== 0)
|
|
39
39
|
* reject(new Error(`Worker stopped with exit code ${code}`));
|
|
40
40
|
* });
|
|
@@ -52,17 +52,22 @@
|
|
|
52
52
|
*
|
|
53
53
|
* Worker threads inherit non-process-specific options by default. Refer to `Worker constructor options` to know how to customize worker thread options,
|
|
54
54
|
* specifically `argv` and `execArgv` options.
|
|
55
|
-
* @see [source](https://github.com/nodejs/node/blob/
|
|
55
|
+
* @see [source](https://github.com/nodejs/node/blob/v25.x/lib/worker_threads.js)
|
|
56
56
|
*/
|
|
57
|
-
declare module "worker_threads" {
|
|
58
|
-
import {
|
|
59
|
-
|
|
57
|
+
declare module "node:worker_threads" {
|
|
58
|
+
import {
|
|
59
|
+
EventEmitter,
|
|
60
|
+
InternalEventEmitter,
|
|
61
|
+
InternalEventTargetEventProperties,
|
|
62
|
+
NodeEventTarget,
|
|
63
|
+
} from "node:events";
|
|
60
64
|
import { FileHandle } from "node:fs/promises";
|
|
61
65
|
import { Performance } from "node:perf_hooks";
|
|
62
66
|
import { Readable, Writable } from "node:stream";
|
|
63
67
|
import { ReadableStream, TransformStream, WritableStream } from "node:stream/web";
|
|
64
68
|
import { URL } from "node:url";
|
|
65
69
|
import { CPUProfileHandle, HeapInfo, HeapProfileHandle } from "node:v8";
|
|
70
|
+
import { Context } from "node:vm";
|
|
66
71
|
import { MessageEvent } from "undici-types";
|
|
67
72
|
const isInternalThread: boolean;
|
|
68
73
|
const isMainThread: boolean;
|
|
@@ -72,184 +77,10 @@ declare module "worker_threads" {
|
|
|
72
77
|
const threadId: number;
|
|
73
78
|
const threadName: string | null;
|
|
74
79
|
const workerData: any;
|
|
75
|
-
/**
|
|
76
|
-
* Instances of the `worker.MessageChannel` class represent an asynchronous,
|
|
77
|
-
* two-way communications channel.
|
|
78
|
-
* The `MessageChannel` has no methods of its own. `new MessageChannel()` yields an object with `port1` and `port2` properties, which refer to linked `MessagePort` instances.
|
|
79
|
-
*
|
|
80
|
-
* ```js
|
|
81
|
-
* import { MessageChannel } from 'node:worker_threads';
|
|
82
|
-
*
|
|
83
|
-
* const { port1, port2 } = new MessageChannel();
|
|
84
|
-
* port1.on('message', (message) => console.log('received', message));
|
|
85
|
-
* port2.postMessage({ foo: 'bar' });
|
|
86
|
-
* // Prints: received { foo: 'bar' } from the `port1.on('message')` listener
|
|
87
|
-
* ```
|
|
88
|
-
* @since v10.5.0
|
|
89
|
-
*/
|
|
90
|
-
class MessageChannel {
|
|
91
|
-
readonly port1: MessagePort;
|
|
92
|
-
readonly port2: MessagePort;
|
|
93
|
-
}
|
|
94
80
|
interface WorkerPerformance extends Pick<Performance, "eventLoopUtilization"> {}
|
|
95
|
-
type Transferable =
|
|
96
|
-
| ArrayBuffer
|
|
97
|
-
| MessagePort
|
|
98
|
-
| AbortSignal
|
|
99
|
-
| FileHandle
|
|
100
|
-
| ReadableStream
|
|
101
|
-
| WritableStream
|
|
102
|
-
| TransformStream;
|
|
103
81
|
/** @deprecated Use `import { Transferable } from "node:worker_threads"` instead. */
|
|
104
82
|
// TODO: remove in a future major @types/node version.
|
|
105
83
|
type TransferListItem = Transferable;
|
|
106
|
-
/**
|
|
107
|
-
* Instances of the `worker.MessagePort` class represent one end of an
|
|
108
|
-
* asynchronous, two-way communications channel. It can be used to transfer
|
|
109
|
-
* structured data, memory regions and other `MessagePort`s between different `Worker`s.
|
|
110
|
-
*
|
|
111
|
-
* This implementation matches [browser `MessagePort`](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort) s.
|
|
112
|
-
* @since v10.5.0
|
|
113
|
-
*/
|
|
114
|
-
class MessagePort implements EventTarget {
|
|
115
|
-
/**
|
|
116
|
-
* Disables further sending of messages on either side of the connection.
|
|
117
|
-
* This method can be called when no further communication will happen over this `MessagePort`.
|
|
118
|
-
*
|
|
119
|
-
* The `'close' event` is emitted on both `MessagePort` instances that
|
|
120
|
-
* are part of the channel.
|
|
121
|
-
* @since v10.5.0
|
|
122
|
-
*/
|
|
123
|
-
close(): void;
|
|
124
|
-
/**
|
|
125
|
-
* Sends a JavaScript value to the receiving side of this channel. `value` is transferred in a way which is compatible with
|
|
126
|
-
* the [HTML structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm).
|
|
127
|
-
*
|
|
128
|
-
* In particular, the significant differences to `JSON` are:
|
|
129
|
-
*
|
|
130
|
-
* * `value` may contain circular references.
|
|
131
|
-
* * `value` may contain instances of builtin JS types such as `RegExp`s, `BigInt`s, `Map`s, `Set`s, etc.
|
|
132
|
-
* * `value` may contain typed arrays, both using `ArrayBuffer`s
|
|
133
|
-
* and `SharedArrayBuffer`s.
|
|
134
|
-
* * `value` may contain [`WebAssembly.Module`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module) instances.
|
|
135
|
-
* * `value` may not contain native (C++-backed) objects other than:
|
|
136
|
-
*
|
|
137
|
-
* ```js
|
|
138
|
-
* import { MessageChannel } from 'node:worker_threads';
|
|
139
|
-
* const { port1, port2 } = new MessageChannel();
|
|
140
|
-
*
|
|
141
|
-
* port1.on('message', (message) => console.log(message));
|
|
142
|
-
*
|
|
143
|
-
* const circularData = {};
|
|
144
|
-
* circularData.foo = circularData;
|
|
145
|
-
* // Prints: { foo: [Circular] }
|
|
146
|
-
* port2.postMessage(circularData);
|
|
147
|
-
* ```
|
|
148
|
-
*
|
|
149
|
-
* `transferList` may be a list of [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer), `MessagePort`, and `FileHandle` objects.
|
|
150
|
-
* After transferring, they are not usable on the sending side of the channel
|
|
151
|
-
* anymore (even if they are not contained in `value`). Unlike with `child processes`, transferring handles such as network sockets is currently
|
|
152
|
-
* not supported.
|
|
153
|
-
*
|
|
154
|
-
* If `value` contains [`SharedArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) instances, those are accessible
|
|
155
|
-
* from either thread. They cannot be listed in `transferList`.
|
|
156
|
-
*
|
|
157
|
-
* `value` may still contain `ArrayBuffer` instances that are not in `transferList`; in that case, the underlying memory is copied rather than moved.
|
|
158
|
-
*
|
|
159
|
-
* ```js
|
|
160
|
-
* import { MessageChannel } from 'node:worker_threads';
|
|
161
|
-
* const { port1, port2 } = new MessageChannel();
|
|
162
|
-
*
|
|
163
|
-
* port1.on('message', (message) => console.log(message));
|
|
164
|
-
*
|
|
165
|
-
* const uint8Array = new Uint8Array([ 1, 2, 3, 4 ]);
|
|
166
|
-
* // This posts a copy of `uint8Array`:
|
|
167
|
-
* port2.postMessage(uint8Array);
|
|
168
|
-
* // This does not copy data, but renders `uint8Array` unusable:
|
|
169
|
-
* port2.postMessage(uint8Array, [ uint8Array.buffer ]);
|
|
170
|
-
*
|
|
171
|
-
* // The memory for the `sharedUint8Array` is accessible from both the
|
|
172
|
-
* // original and the copy received by `.on('message')`:
|
|
173
|
-
* const sharedUint8Array = new Uint8Array(new SharedArrayBuffer(4));
|
|
174
|
-
* port2.postMessage(sharedUint8Array);
|
|
175
|
-
*
|
|
176
|
-
* // This transfers a freshly created message port to the receiver.
|
|
177
|
-
* // This can be used, for example, to create communication channels between
|
|
178
|
-
* // multiple `Worker` threads that are children of the same parent thread.
|
|
179
|
-
* const otherChannel = new MessageChannel();
|
|
180
|
-
* port2.postMessage({ port: otherChannel.port1 }, [ otherChannel.port1 ]);
|
|
181
|
-
* ```
|
|
182
|
-
*
|
|
183
|
-
* The message object is cloned immediately, and can be modified after
|
|
184
|
-
* posting without having side effects.
|
|
185
|
-
*
|
|
186
|
-
* For more information on the serialization and deserialization mechanisms
|
|
187
|
-
* behind this API, see the `serialization API of the node:v8 module`.
|
|
188
|
-
* @since v10.5.0
|
|
189
|
-
*/
|
|
190
|
-
postMessage(value: any, transferList?: readonly Transferable[]): void;
|
|
191
|
-
/**
|
|
192
|
-
* If true, the `MessagePort` object will keep the Node.js event loop active.
|
|
193
|
-
* @since v18.1.0, v16.17.0
|
|
194
|
-
*/
|
|
195
|
-
hasRef(): boolean;
|
|
196
|
-
/**
|
|
197
|
-
* 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
|
|
198
|
-
* behavior). If the port is `ref()`ed, calling `ref()` again has no effect.
|
|
199
|
-
*
|
|
200
|
-
* If listeners are attached or removed using `.on('message')`, the port
|
|
201
|
-
* is `ref()`ed and `unref()`ed automatically depending on whether
|
|
202
|
-
* listeners for the event exist.
|
|
203
|
-
* @since v10.5.0
|
|
204
|
-
*/
|
|
205
|
-
ref(): void;
|
|
206
|
-
/**
|
|
207
|
-
* Calling `unref()` on a port allows the thread to exit if this is the only
|
|
208
|
-
* active handle in the event system. If the port is already `unref()`ed calling `unref()` again has no effect.
|
|
209
|
-
*
|
|
210
|
-
* If listeners are attached or removed using `.on('message')`, the port is `ref()`ed and `unref()`ed automatically depending on whether
|
|
211
|
-
* listeners for the event exist.
|
|
212
|
-
* @since v10.5.0
|
|
213
|
-
*/
|
|
214
|
-
unref(): void;
|
|
215
|
-
/**
|
|
216
|
-
* Starts receiving messages on this `MessagePort`. When using this port
|
|
217
|
-
* as an event emitter, this is called automatically once `'message'` listeners are attached.
|
|
218
|
-
*
|
|
219
|
-
* This method exists for parity with the Web `MessagePort` API. In Node.js,
|
|
220
|
-
* it is only useful for ignoring messages when no event listener is present.
|
|
221
|
-
* Node.js also diverges in its handling of `.onmessage`. Setting it
|
|
222
|
-
* automatically calls `.start()`, but unsetting it lets messages queue up
|
|
223
|
-
* until a new handler is set or the port is discarded.
|
|
224
|
-
* @since v10.5.0
|
|
225
|
-
*/
|
|
226
|
-
start(): void;
|
|
227
|
-
addListener(event: "close", listener: (ev: Event) => void): this;
|
|
228
|
-
addListener(event: "message", listener: (value: any) => void): this;
|
|
229
|
-
addListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
230
|
-
addListener(event: string, listener: (arg: any) => void): this;
|
|
231
|
-
emit(event: "close", ev: Event): boolean;
|
|
232
|
-
emit(event: "message", value: any): boolean;
|
|
233
|
-
emit(event: "messageerror", error: Error): boolean;
|
|
234
|
-
emit(event: string, arg: any): boolean;
|
|
235
|
-
off(event: "close", listener: (ev: Event) => void, options?: EventListenerOptions): this;
|
|
236
|
-
off(event: "message", listener: (value: any) => void, options?: EventListenerOptions): this;
|
|
237
|
-
off(event: "messageerror", listener: (error: Error) => void, options?: EventListenerOptions): this;
|
|
238
|
-
off(event: string, listener: (arg: any) => void, options?: EventListenerOptions): this;
|
|
239
|
-
on(event: "close", listener: (ev: Event) => void): this;
|
|
240
|
-
on(event: "message", listener: (value: any) => void): this;
|
|
241
|
-
on(event: "messageerror", listener: (error: Error) => void): this;
|
|
242
|
-
on(event: string, listener: (arg: any) => void): this;
|
|
243
|
-
once(event: "close", listener: (ev: Event) => void): this;
|
|
244
|
-
once(event: "message", listener: (value: any) => void): this;
|
|
245
|
-
once(event: "messageerror", listener: (error: Error) => void): this;
|
|
246
|
-
once(event: string, listener: (arg: any) => void): this;
|
|
247
|
-
removeListener(event: "close", listener: (ev: Event) => void, options?: EventListenerOptions): this;
|
|
248
|
-
removeListener(event: "message", listener: (value: any) => void, options?: EventListenerOptions): this;
|
|
249
|
-
removeListener(event: "messageerror", listener: (error: Error) => void, options?: EventListenerOptions): this;
|
|
250
|
-
removeListener(event: string, listener: (arg: any) => void, options?: EventListenerOptions): this;
|
|
251
|
-
}
|
|
252
|
-
interface MessagePort extends NodeEventTarget {}
|
|
253
84
|
interface WorkerOptions {
|
|
254
85
|
/**
|
|
255
86
|
* List of arguments which would be stringified and appended to
|
|
@@ -300,6 +131,13 @@ declare module "worker_threads" {
|
|
|
300
131
|
*/
|
|
301
132
|
stackSizeMb?: number | undefined;
|
|
302
133
|
}
|
|
134
|
+
interface WorkerEventMap {
|
|
135
|
+
"error": [err: unknown];
|
|
136
|
+
"exit": [exitCode: number];
|
|
137
|
+
"message": [value: any];
|
|
138
|
+
"messageerror": [error: Error];
|
|
139
|
+
"online": [];
|
|
140
|
+
}
|
|
303
141
|
/**
|
|
304
142
|
* The `Worker` class represents an independent JavaScript execution thread.
|
|
305
143
|
* Most Node.js APIs are available inside of it.
|
|
@@ -364,7 +202,7 @@ declare module "worker_threads" {
|
|
|
364
202
|
* ```
|
|
365
203
|
* @since v10.5.0
|
|
366
204
|
*/
|
|
367
|
-
class Worker
|
|
205
|
+
class Worker implements EventEmitter {
|
|
368
206
|
/**
|
|
369
207
|
* If `stdin: true` was passed to the `Worker` constructor, this is a
|
|
370
208
|
* writable stream. The data written to this stream will be made available in
|
|
@@ -408,7 +246,7 @@ declare module "worker_threads" {
|
|
|
408
246
|
readonly resourceLimits?: ResourceLimits | undefined;
|
|
409
247
|
/**
|
|
410
248
|
* An object that can be used to query performance information from a worker
|
|
411
|
-
* instance.
|
|
249
|
+
* instance. Similar to `perf_hooks.performance`.
|
|
412
250
|
* @since v15.1.0, v14.17.0, v12.22.0
|
|
413
251
|
*/
|
|
414
252
|
readonly performance: WorkerPerformance;
|
|
@@ -444,8 +282,8 @@ declare module "worker_threads" {
|
|
|
444
282
|
*/
|
|
445
283
|
terminate(): Promise<number>;
|
|
446
284
|
/**
|
|
447
|
-
* This method returns a `Promise` that will resolve to an object identical to
|
|
448
|
-
* or reject with an
|
|
285
|
+
* This method returns a `Promise` that will resolve to an object identical to `process.threadCpuUsage()`,
|
|
286
|
+
* or reject with an `ERR_WORKER_NOT_RUNNING` error if the worker is no longer running.
|
|
449
287
|
* This methods allows the statistics to be observed from outside the actual thread.
|
|
450
288
|
* @since v24.6.0
|
|
451
289
|
*/
|
|
@@ -554,142 +392,11 @@ declare module "worker_threads" {
|
|
|
554
392
|
* @since v24.2.0
|
|
555
393
|
*/
|
|
556
394
|
[Symbol.asyncDispose](): Promise<void>;
|
|
557
|
-
addListener(event: "error", listener: (err: any) => void): this;
|
|
558
|
-
addListener(event: "exit", listener: (exitCode: number) => void): this;
|
|
559
|
-
addListener(event: "message", listener: (value: any) => void): this;
|
|
560
|
-
addListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
561
|
-
addListener(event: "online", listener: () => void): this;
|
|
562
|
-
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
563
|
-
emit(event: "error", err: any): boolean;
|
|
564
|
-
emit(event: "exit", exitCode: number): boolean;
|
|
565
|
-
emit(event: "message", value: any): boolean;
|
|
566
|
-
emit(event: "messageerror", error: Error): boolean;
|
|
567
|
-
emit(event: "online"): boolean;
|
|
568
|
-
emit(event: string | symbol, ...args: any[]): boolean;
|
|
569
|
-
on(event: "error", listener: (err: any) => void): this;
|
|
570
|
-
on(event: "exit", listener: (exitCode: number) => void): this;
|
|
571
|
-
on(event: "message", listener: (value: any) => void): this;
|
|
572
|
-
on(event: "messageerror", listener: (error: Error) => void): this;
|
|
573
|
-
on(event: "online", listener: () => void): this;
|
|
574
|
-
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
575
|
-
once(event: "error", listener: (err: any) => void): this;
|
|
576
|
-
once(event: "exit", listener: (exitCode: number) => void): this;
|
|
577
|
-
once(event: "message", listener: (value: any) => void): this;
|
|
578
|
-
once(event: "messageerror", listener: (error: Error) => void): this;
|
|
579
|
-
once(event: "online", listener: () => void): this;
|
|
580
|
-
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
581
|
-
prependListener(event: "error", listener: (err: any) => void): this;
|
|
582
|
-
prependListener(event: "exit", listener: (exitCode: number) => void): this;
|
|
583
|
-
prependListener(event: "message", listener: (value: any) => void): this;
|
|
584
|
-
prependListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
585
|
-
prependListener(event: "online", listener: () => void): this;
|
|
586
|
-
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
587
|
-
prependOnceListener(event: "error", listener: (err: any) => void): this;
|
|
588
|
-
prependOnceListener(event: "exit", listener: (exitCode: number) => void): this;
|
|
589
|
-
prependOnceListener(event: "message", listener: (value: any) => void): this;
|
|
590
|
-
prependOnceListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
591
|
-
prependOnceListener(event: "online", listener: () => void): this;
|
|
592
|
-
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
593
|
-
removeListener(event: "error", listener: (err: any) => void): this;
|
|
594
|
-
removeListener(event: "exit", listener: (exitCode: number) => void): this;
|
|
595
|
-
removeListener(event: "message", listener: (value: any) => void): this;
|
|
596
|
-
removeListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
597
|
-
removeListener(event: "online", listener: () => void): this;
|
|
598
|
-
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
599
|
-
off(event: "error", listener: (err: any) => void): this;
|
|
600
|
-
off(event: "exit", listener: (exitCode: number) => void): this;
|
|
601
|
-
off(event: "message", listener: (value: any) => void): this;
|
|
602
|
-
off(event: "messageerror", listener: (error: Error) => void): this;
|
|
603
|
-
off(event: "online", listener: () => void): this;
|
|
604
|
-
off(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
605
|
-
}
|
|
606
|
-
interface BroadcastChannel extends NodeJS.RefCounted {}
|
|
607
|
-
/**
|
|
608
|
-
* Instances of `BroadcastChannel` allow asynchronous one-to-many communication
|
|
609
|
-
* with all other `BroadcastChannel` instances bound to the same channel name.
|
|
610
|
-
*
|
|
611
|
-
* ```js
|
|
612
|
-
* 'use strict';
|
|
613
|
-
*
|
|
614
|
-
* import {
|
|
615
|
-
* isMainThread,
|
|
616
|
-
* BroadcastChannel,
|
|
617
|
-
* Worker,
|
|
618
|
-
* } from 'node:worker_threads';
|
|
619
|
-
*
|
|
620
|
-
* const bc = new BroadcastChannel('hello');
|
|
621
|
-
*
|
|
622
|
-
* if (isMainThread) {
|
|
623
|
-
* let c = 0;
|
|
624
|
-
* bc.onmessage = (event) => {
|
|
625
|
-
* console.log(event.data);
|
|
626
|
-
* if (++c === 10) bc.close();
|
|
627
|
-
* };
|
|
628
|
-
* for (let n = 0; n < 10; n++)
|
|
629
|
-
* new Worker(__filename);
|
|
630
|
-
* } else {
|
|
631
|
-
* bc.postMessage('hello from every worker');
|
|
632
|
-
* bc.close();
|
|
633
|
-
* }
|
|
634
|
-
* ```
|
|
635
|
-
* @since v15.4.0
|
|
636
|
-
*/
|
|
637
|
-
class BroadcastChannel extends EventTarget {
|
|
638
|
-
readonly name: string;
|
|
639
|
-
/**
|
|
640
|
-
* Invoked with a single \`MessageEvent\` argument when a message is received.
|
|
641
|
-
* @since v15.4.0
|
|
642
|
-
*/
|
|
643
|
-
onmessage: (message: MessageEvent) => void;
|
|
644
|
-
/**
|
|
645
|
-
* Invoked with a received message cannot be deserialized.
|
|
646
|
-
* @since v15.4.0
|
|
647
|
-
*/
|
|
648
|
-
onmessageerror: (message: MessageEvent) => void;
|
|
649
|
-
constructor(name: string);
|
|
650
|
-
/**
|
|
651
|
-
* Closes the `BroadcastChannel` connection.
|
|
652
|
-
* @since v15.4.0
|
|
653
|
-
*/
|
|
654
|
-
close(): void;
|
|
655
|
-
/**
|
|
656
|
-
* @since v15.4.0
|
|
657
|
-
* @param message Any cloneable JavaScript value.
|
|
658
|
-
*/
|
|
659
|
-
postMessage(message: unknown): void;
|
|
660
|
-
}
|
|
661
|
-
interface Lock {
|
|
662
|
-
readonly mode: LockMode;
|
|
663
|
-
readonly name: string;
|
|
664
|
-
}
|
|
665
|
-
interface LockGrantedCallback<T> {
|
|
666
|
-
(lock: Lock | null): T;
|
|
667
|
-
}
|
|
668
|
-
interface LockInfo {
|
|
669
|
-
clientId: string;
|
|
670
|
-
mode: LockMode;
|
|
671
|
-
name: string;
|
|
672
|
-
}
|
|
673
|
-
interface LockManager {
|
|
674
|
-
query(): Promise<LockManagerSnapshot>;
|
|
675
|
-
request<T>(name: string, callback: LockGrantedCallback<T>): Promise<Awaited<T>>;
|
|
676
|
-
request<T>(name: string, options: LockOptions, callback: LockGrantedCallback<T>): Promise<Awaited<T>>;
|
|
677
|
-
}
|
|
678
|
-
interface LockManagerSnapshot {
|
|
679
|
-
held: LockInfo[];
|
|
680
|
-
pending: LockInfo[];
|
|
681
395
|
}
|
|
682
|
-
|
|
683
|
-
interface LockOptions {
|
|
684
|
-
ifAvailable?: boolean;
|
|
685
|
-
mode?: LockMode;
|
|
686
|
-
signal?: AbortSignal;
|
|
687
|
-
steal?: boolean;
|
|
688
|
-
}
|
|
689
|
-
var locks: LockManager;
|
|
396
|
+
interface Worker extends InternalEventEmitter<WorkerEventMap> {}
|
|
690
397
|
/**
|
|
691
398
|
* Mark an object as not transferable. If `object` occurs in the transfer list of
|
|
692
|
-
* a
|
|
399
|
+
* a `port.postMessage()` call, it is ignored.
|
|
693
400
|
*
|
|
694
401
|
* In particular, this makes sense for objects that can be cloned, rather than
|
|
695
402
|
* transferred, and which are used by other objects on the sending side.
|
|
@@ -811,13 +518,13 @@ declare module "worker_threads" {
|
|
|
811
518
|
*
|
|
812
519
|
* if (isMainThread) {
|
|
813
520
|
* setEnvironmentData('Hello', 'World!');
|
|
814
|
-
* const worker = new Worker(
|
|
521
|
+
* const worker = new Worker(__filename);
|
|
815
522
|
* } else {
|
|
816
523
|
* console.log(getEnvironmentData('Hello')); // Prints 'World!'.
|
|
817
524
|
* }
|
|
818
525
|
* ```
|
|
819
526
|
* @since v15.12.0, v14.18.0
|
|
820
|
-
* @param key Any arbitrary, cloneable JavaScript value that can be used as a {
|
|
527
|
+
* @param key Any arbitrary, cloneable JavaScript value that can be used as a {Map} key.
|
|
821
528
|
*/
|
|
822
529
|
function getEnvironmentData(key: Serializable): Serializable;
|
|
823
530
|
/**
|
|
@@ -846,49 +553,165 @@ declare module "worker_threads" {
|
|
|
846
553
|
transferList: readonly Transferable[],
|
|
847
554
|
timeout?: number,
|
|
848
555
|
): Promise<void>;
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
MessagePort
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
* `BroadcastChannel` class is a global reference for `import { BroadcastChannel } from 'worker_threads'`
|
|
862
|
-
* https://nodejs.org/api/globals.html#broadcastchannel
|
|
863
|
-
* @since v18.0.0
|
|
864
|
-
*/
|
|
865
|
-
var BroadcastChannel: typeof globalThis extends {
|
|
866
|
-
onmessage: any;
|
|
867
|
-
BroadcastChannel: infer T;
|
|
868
|
-
} ? T
|
|
869
|
-
: typeof _BroadcastChannel;
|
|
870
|
-
/**
|
|
871
|
-
* `MessageChannel` class is a global reference for `import { MessageChannel } from 'worker_threads'`
|
|
872
|
-
* https://nodejs.org/api/globals.html#messagechannel
|
|
873
|
-
* @since v15.0.0
|
|
874
|
-
*/
|
|
875
|
-
var MessageChannel: typeof globalThis extends {
|
|
876
|
-
onmessage: any;
|
|
877
|
-
MessageChannel: infer T;
|
|
878
|
-
} ? T
|
|
879
|
-
: typeof _MessageChannel;
|
|
880
|
-
/**
|
|
881
|
-
* `MessagePort` class is a global reference for `import { MessagePort } from 'worker_threads'`
|
|
882
|
-
* https://nodejs.org/api/globals.html#messageport
|
|
883
|
-
* @since v15.0.0
|
|
884
|
-
*/
|
|
885
|
-
var MessagePort: typeof globalThis extends {
|
|
886
|
-
onmessage: any;
|
|
887
|
-
MessagePort: infer T;
|
|
888
|
-
} ? T
|
|
889
|
-
: typeof _MessagePort;
|
|
556
|
+
// #region web types
|
|
557
|
+
type LockMode = "exclusive" | "shared";
|
|
558
|
+
type Transferable =
|
|
559
|
+
| ArrayBuffer
|
|
560
|
+
| MessagePort
|
|
561
|
+
| AbortSignal
|
|
562
|
+
| FileHandle
|
|
563
|
+
| ReadableStream
|
|
564
|
+
| WritableStream
|
|
565
|
+
| TransformStream;
|
|
566
|
+
interface LockGrantedCallback<T> {
|
|
567
|
+
(lock: Lock | null): T;
|
|
890
568
|
}
|
|
569
|
+
interface LockInfo {
|
|
570
|
+
clientId: string;
|
|
571
|
+
mode: LockMode;
|
|
572
|
+
name: string;
|
|
573
|
+
}
|
|
574
|
+
interface LockManagerSnapshot {
|
|
575
|
+
held: LockInfo[];
|
|
576
|
+
pending: LockInfo[];
|
|
577
|
+
}
|
|
578
|
+
interface LockOptions {
|
|
579
|
+
ifAvailable?: boolean;
|
|
580
|
+
mode?: LockMode;
|
|
581
|
+
signal?: AbortSignal;
|
|
582
|
+
steal?: boolean;
|
|
583
|
+
}
|
|
584
|
+
interface StructuredSerializeOptions {
|
|
585
|
+
transfer?: Transferable[];
|
|
586
|
+
}
|
|
587
|
+
interface BroadcastChannelEventMap {
|
|
588
|
+
"message": MessageEvent;
|
|
589
|
+
"messageerror": MessageEvent;
|
|
590
|
+
}
|
|
591
|
+
interface BroadcastChannel
|
|
592
|
+
extends EventTarget, InternalEventTargetEventProperties<BroadcastChannelEventMap>, NodeJS.RefCounted
|
|
593
|
+
{
|
|
594
|
+
readonly name: string;
|
|
595
|
+
close(): void;
|
|
596
|
+
postMessage(message: any): void;
|
|
597
|
+
addEventListener<K extends keyof BroadcastChannelEventMap>(
|
|
598
|
+
type: K,
|
|
599
|
+
listener: (ev: BroadcastChannelEventMap[K]) => void,
|
|
600
|
+
options?: AddEventListenerOptions | boolean,
|
|
601
|
+
): void;
|
|
602
|
+
addEventListener(
|
|
603
|
+
type: string,
|
|
604
|
+
listener: EventListener | EventListenerObject,
|
|
605
|
+
options?: AddEventListenerOptions | boolean,
|
|
606
|
+
): void;
|
|
607
|
+
removeEventListener<K extends keyof BroadcastChannelEventMap>(
|
|
608
|
+
type: K,
|
|
609
|
+
listener: (ev: BroadcastChannelEventMap[K]) => void,
|
|
610
|
+
options?: EventListenerOptions | boolean,
|
|
611
|
+
): void;
|
|
612
|
+
removeEventListener(
|
|
613
|
+
type: string,
|
|
614
|
+
listener: EventListener | EventListenerObject,
|
|
615
|
+
options?: EventListenerOptions | boolean,
|
|
616
|
+
): void;
|
|
617
|
+
}
|
|
618
|
+
var BroadcastChannel: {
|
|
619
|
+
prototype: BroadcastChannel;
|
|
620
|
+
new(name: string): BroadcastChannel;
|
|
621
|
+
};
|
|
622
|
+
interface Lock {
|
|
623
|
+
readonly mode: LockMode;
|
|
624
|
+
readonly name: string;
|
|
625
|
+
}
|
|
626
|
+
// var Lock: {
|
|
627
|
+
// prototype: Lock;
|
|
628
|
+
// new(): Lock;
|
|
629
|
+
// };
|
|
630
|
+
interface LockManager {
|
|
631
|
+
query(): Promise<LockManagerSnapshot>;
|
|
632
|
+
request<T>(name: string, callback: LockGrantedCallback<T>): Promise<Awaited<T>>;
|
|
633
|
+
request<T>(name: string, options: LockOptions, callback: LockGrantedCallback<T>): Promise<Awaited<T>>;
|
|
634
|
+
}
|
|
635
|
+
// var LockManager: {
|
|
636
|
+
// prototype: LockManager;
|
|
637
|
+
// new(): LockManager;
|
|
638
|
+
// };
|
|
639
|
+
interface MessageChannel {
|
|
640
|
+
readonly port1: MessagePort;
|
|
641
|
+
readonly port2: MessagePort;
|
|
642
|
+
}
|
|
643
|
+
var MessageChannel: {
|
|
644
|
+
prototype: MessageChannel;
|
|
645
|
+
new(): MessageChannel;
|
|
646
|
+
};
|
|
647
|
+
interface MessagePortEventMap {
|
|
648
|
+
"close": Event;
|
|
649
|
+
"message": MessageEvent;
|
|
650
|
+
"messageerror": MessageEvent;
|
|
651
|
+
}
|
|
652
|
+
interface MessagePort extends NodeEventTarget, InternalEventTargetEventProperties<MessagePortEventMap> {
|
|
653
|
+
close(): void;
|
|
654
|
+
postMessage(message: any, transfer: Transferable[]): void;
|
|
655
|
+
postMessage(message: any, options?: StructuredSerializeOptions): void;
|
|
656
|
+
start(): void;
|
|
657
|
+
hasRef(): boolean;
|
|
658
|
+
ref(): void;
|
|
659
|
+
unref(): void;
|
|
660
|
+
addEventListener<K extends keyof MessagePortEventMap>(
|
|
661
|
+
type: K,
|
|
662
|
+
listener: (ev: MessagePortEventMap[K]) => void,
|
|
663
|
+
options?: AddEventListenerOptions | boolean,
|
|
664
|
+
): void;
|
|
665
|
+
addEventListener(
|
|
666
|
+
type: string,
|
|
667
|
+
listener: EventListener | EventListenerObject,
|
|
668
|
+
options?: AddEventListenerOptions | boolean,
|
|
669
|
+
): void;
|
|
670
|
+
removeEventListener<K extends keyof MessagePortEventMap>(
|
|
671
|
+
type: K,
|
|
672
|
+
listener: (ev: MessagePortEventMap[K]) => void,
|
|
673
|
+
options?: EventListenerOptions | boolean,
|
|
674
|
+
): void;
|
|
675
|
+
removeEventListener(
|
|
676
|
+
type: string,
|
|
677
|
+
listener: EventListener | EventListenerObject,
|
|
678
|
+
options?: EventListenerOptions | boolean,
|
|
679
|
+
): void;
|
|
680
|
+
// #region NodeEventTarget
|
|
681
|
+
addListener(event: "close", listener: (ev: Event) => void): this;
|
|
682
|
+
addListener(event: "message", listener: (value: any) => void): this;
|
|
683
|
+
addListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
684
|
+
addListener(event: string, listener: (arg: any) => void): this;
|
|
685
|
+
emit(event: "close", ev: Event): boolean;
|
|
686
|
+
emit(event: "message", value: any): boolean;
|
|
687
|
+
emit(event: "messageerror", error: Error): boolean;
|
|
688
|
+
emit(event: string, arg: any): boolean;
|
|
689
|
+
off(event: "close", listener: (ev: Event) => void, options?: EventListenerOptions): this;
|
|
690
|
+
off(event: "message", listener: (value: any) => void, options?: EventListenerOptions): this;
|
|
691
|
+
off(event: "messageerror", listener: (error: Error) => void, options?: EventListenerOptions): this;
|
|
692
|
+
off(event: string, listener: (arg: any) => void, options?: EventListenerOptions): this;
|
|
693
|
+
on(event: "close", listener: (ev: Event) => void): this;
|
|
694
|
+
on(event: "message", listener: (value: any) => void): this;
|
|
695
|
+
on(event: "messageerror", listener: (error: Error) => void): this;
|
|
696
|
+
on(event: string, listener: (arg: any) => void): this;
|
|
697
|
+
once(event: "close", listener: (ev: Event) => void): this;
|
|
698
|
+
once(event: "message", listener: (value: any) => void): this;
|
|
699
|
+
once(event: "messageerror", listener: (error: Error) => void): this;
|
|
700
|
+
once(event: string, listener: (arg: any) => void): this;
|
|
701
|
+
removeListener(event: "close", listener: (ev: Event) => void, options?: EventListenerOptions): this;
|
|
702
|
+
removeListener(event: "message", listener: (value: any) => void, options?: EventListenerOptions): this;
|
|
703
|
+
removeListener(event: "messageerror", listener: (error: Error) => void, options?: EventListenerOptions): this;
|
|
704
|
+
removeListener(event: string, listener: (arg: any) => void, options?: EventListenerOptions): this;
|
|
705
|
+
// #endregion
|
|
706
|
+
}
|
|
707
|
+
var MessagePort: {
|
|
708
|
+
prototype: MessagePort;
|
|
709
|
+
new(): MessagePort;
|
|
710
|
+
};
|
|
711
|
+
var locks: LockManager;
|
|
712
|
+
export import structuredClone = globalThis.structuredClone;
|
|
713
|
+
// #endregion
|
|
891
714
|
}
|
|
892
|
-
declare module "
|
|
893
|
-
export * from "worker_threads";
|
|
715
|
+
declare module "worker_threads" {
|
|
716
|
+
export * from "node:worker_threads";
|
|
894
717
|
}
|