@idlebox/stripe-node-types 24.0.14 → 24.0.15
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.
- package/README.md +1 -1
- package/assert/strict.d.ts +98 -1
- package/assert.d.ts +147 -248
- package/async_hooks.d.ts +5 -5
- package/buffer.buffer.d.ts +9 -6
- package/buffer.d.ts +49 -169
- package/child_process.d.ts +102 -223
- package/cluster.d.ts +236 -329
- package/console.d.ts +45 -346
- package/constants.d.ts +0 -1
- package/crypto.d.ts +698 -1149
- package/dgram.d.ts +15 -50
- package/diagnostics_channel.d.ts +1 -3
- package/dns.d.ts +135 -131
- package/domain.d.ts +10 -14
- package/events.d.ts +846 -722
- package/fs/promises.d.ts +102 -53
- package/fs.d.ts +714 -484
- package/globals.d.ts +130 -347
- package/globals.typedarray.d.ts +79 -0
- package/http.d.ts +343 -246
- package/http2.d.ts +563 -711
- package/https.d.ts +70 -216
- package/index.d.ts +24 -3
- package/inspector/promises.d.ts +54 -0
- package/inspector.d.ts +167 -3938
- package/inspector.generated.d.ts +4242 -0
- package/module.d.ts +45 -95
- package/net.d.ts +87 -186
- package/os.d.ts +17 -6
- package/package.json +3 -8
- package/path/posix.d.ts +20 -0
- package/path/win32.d.ts +20 -0
- package/path.d.ts +117 -122
- package/perf_hooks.d.ts +295 -644
- package/process.d.ts +177 -138
- package/punycode.d.ts +2 -2
- package/querystring.d.ts +1 -1
- package/quic.d.ts +926 -0
- package/readline/promises.d.ts +1 -1
- package/readline.d.ts +65 -118
- package/repl.d.ts +83 -96
- package/sea.d.ts +10 -1
- package/sqlite.d.ts +262 -13
- package/stream/consumers.d.ts +7 -7
- package/stream/promises.d.ts +133 -12
- package/stream/web.d.ts +173 -495
- package/stream.d.ts +593 -490
- package/string_decoder.d.ts +3 -3
- package/test/reporters.d.ts +112 -0
- package/test.d.ts +223 -199
- package/timers/promises.d.ts +1 -1
- package/timers.d.ts +1 -129
- package/tls.d.ts +148 -163
- package/trace_events.d.ts +6 -6
- package/ts5.6/buffer.buffer.d.ts +10 -8
- package/ts5.6/globals.typedarray.d.ts +16 -0
- package/ts5.6/index.d.ts +24 -3
- package/ts5.7/index.d.ts +24 -3
- package/tty.d.ts +55 -13
- package/url.d.ts +92 -587
- package/util/types.d.ts +571 -0
- package/util.d.ts +143 -792
- package/v8.d.ts +67 -7
- package/vm.d.ts +252 -108
- package/wasi.d.ts +23 -2
- package/web-globals/abortcontroller.d.ts +75 -0
- package/web-globals/blob.d.ts +39 -0
- package/{ts5.1/compatibility/disposable.d.ts → web-globals/console.d.ts} +6 -9
- package/web-globals/crypto.d.ts +55 -0
- package/web-globals/domexception.d.ts +84 -0
- package/web-globals/encoding.d.ts +27 -0
- package/{dom-events.d.ts → web-globals/events.d.ts} +57 -50
- package/web-globals/fetch.d.ts +70 -0
- package/web-globals/importmeta.d.ts +29 -0
- package/web-globals/messaging.d.ts +39 -0
- package/web-globals/navigator.d.ts +41 -0
- package/web-globals/performance.d.ts +61 -0
- package/web-globals/storage.d.ts +40 -0
- package/web-globals/streams.d.ts +131 -0
- package/web-globals/timers.d.ts +60 -0
- package/web-globals/url.d.ts +40 -0
- package/worker_threads.d.ts +291 -349
- package/zlib.d.ts +44 -94
- package/ts5.1/index.d.ts +0 -115
package/worker_threads.d.ts
CHANGED
|
@@ -67,215 +67,36 @@
|
|
|
67
67
|
*
|
|
68
68
|
* Worker threads inherit non-process-specific options by default. Refer to `Worker constructor options` to know how to customize worker thread options,
|
|
69
69
|
* specifically `argv` and `execArgv` options.
|
|
70
|
-
* @see [source](https://github.com/nodejs/node/blob/
|
|
70
|
+
* @see [source](https://github.com/nodejs/node/blob/v25.x/lib/worker_threads.js)
|
|
71
71
|
*/
|
|
72
72
|
|
|
73
73
|
declare module "node:worker_threads" {
|
|
74
|
-
import {
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
import {
|
|
75
|
+
EventEmitter,
|
|
76
|
+
InternalEventEmitter,
|
|
77
|
+
InternalEventTargetEventProperties,
|
|
78
|
+
NodeEventTarget,
|
|
79
|
+
} from 'node:events';
|
|
77
80
|
import { FileHandle } from 'node:fs/promises';
|
|
81
|
+
import { Performance } from 'node:perf_hooks';
|
|
78
82
|
import { Readable, Writable } from 'node:stream';
|
|
79
83
|
import { ReadableStream, TransformStream, WritableStream } from 'node:stream/web';
|
|
80
84
|
import { URL } from 'node:url';
|
|
81
|
-
import { HeapInfo } from 'node:v8';
|
|
85
|
+
import { CPUProfileHandle, HeapInfo, HeapProfileHandle } from 'node:v8';
|
|
86
|
+
import { Context } from 'node:vm';
|
|
87
|
+
import { MessageEvent } from './undici-types';
|
|
82
88
|
const isInternalThread: boolean;
|
|
83
89
|
const isMainThread: boolean;
|
|
84
90
|
const parentPort: null | MessagePort;
|
|
85
91
|
const resourceLimits: ResourceLimits;
|
|
86
92
|
const SHARE_ENV: unique symbol;
|
|
87
93
|
const threadId: number;
|
|
94
|
+
const threadName: string | null;
|
|
88
95
|
const workerData: any;
|
|
89
|
-
|
|
90
|
-
* Instances of the `worker.MessageChannel` class represent an asynchronous,
|
|
91
|
-
* two-way communications channel.
|
|
92
|
-
* The `MessageChannel` has no methods of its own. `new MessageChannel()` yields an object with `port1` and `port2` properties, which refer to linked `MessagePort` instances.
|
|
93
|
-
*
|
|
94
|
-
* ```js
|
|
95
|
-
* import { MessageChannel } from 'node:worker_threads';
|
|
96
|
-
*
|
|
97
|
-
* const { port1, port2 } = new MessageChannel();
|
|
98
|
-
* port1.on('message', (message) => console.log('received', message));
|
|
99
|
-
* port2.postMessage({ foo: 'bar' });
|
|
100
|
-
* // Prints: received { foo: 'bar' } from the `port1.on('message')` listener
|
|
101
|
-
* ```
|
|
102
|
-
* @since v10.5.0
|
|
103
|
-
*/
|
|
104
|
-
class MessageChannel {
|
|
105
|
-
readonly port1: MessagePort;
|
|
106
|
-
readonly port2: MessagePort;
|
|
107
|
-
}
|
|
108
|
-
interface WorkerPerformance {
|
|
109
|
-
eventLoopUtilization: EventLoopUtilityFunction;
|
|
110
|
-
}
|
|
111
|
-
type Transferable =
|
|
112
|
-
| ArrayBuffer
|
|
113
|
-
| MessagePort
|
|
114
|
-
| AbortSignal
|
|
115
|
-
| FileHandle
|
|
116
|
-
| ReadableStream
|
|
117
|
-
| WritableStream
|
|
118
|
-
| TransformStream;
|
|
96
|
+
interface WorkerPerformance extends Pick<Performance, "eventLoopUtilization"> {}
|
|
119
97
|
/** @deprecated Use `import { Transferable } from "node:worker_threads"` instead. */
|
|
120
98
|
// TODO: remove in a future major @types/node version.
|
|
121
99
|
type TransferListItem = Transferable;
|
|
122
|
-
/**
|
|
123
|
-
* Instances of the `worker.MessagePort` class represent one end of an
|
|
124
|
-
* asynchronous, two-way communications channel. It can be used to transfer
|
|
125
|
-
* structured data, memory regions and other `MessagePort`s between different `Worker`s.
|
|
126
|
-
*
|
|
127
|
-
* This implementation matches [browser `MessagePort`](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort) s.
|
|
128
|
-
* @since v10.5.0
|
|
129
|
-
*/
|
|
130
|
-
class MessagePort extends EventEmitter {
|
|
131
|
-
/**
|
|
132
|
-
* Disables further sending of messages on either side of the connection.
|
|
133
|
-
* This method can be called when no further communication will happen over this `MessagePort`.
|
|
134
|
-
*
|
|
135
|
-
* The `'close' event` is emitted on both `MessagePort` instances that
|
|
136
|
-
* are part of the channel.
|
|
137
|
-
* @since v10.5.0
|
|
138
|
-
*/
|
|
139
|
-
close(): void;
|
|
140
|
-
/**
|
|
141
|
-
* Sends a JavaScript value to the receiving side of this channel. `value` is transferred in a way which is compatible with
|
|
142
|
-
* the [HTML structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm).
|
|
143
|
-
*
|
|
144
|
-
* In particular, the significant differences to `JSON` are:
|
|
145
|
-
*
|
|
146
|
-
* * `value` may contain circular references.
|
|
147
|
-
* * `value` may contain instances of builtin JS types such as `RegExp`s, `BigInt`s, `Map`s, `Set`s, etc.
|
|
148
|
-
* * `value` may contain typed arrays, both using `ArrayBuffer`s
|
|
149
|
-
* and `SharedArrayBuffer`s.
|
|
150
|
-
* * `value` may contain [`WebAssembly.Module`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module) instances.
|
|
151
|
-
* * `value` may not contain native (C++-backed) objects other than:
|
|
152
|
-
*
|
|
153
|
-
* ```js
|
|
154
|
-
* import { MessageChannel } from 'node:worker_threads';
|
|
155
|
-
* const { port1, port2 } = new MessageChannel();
|
|
156
|
-
*
|
|
157
|
-
* port1.on('message', (message) => console.log(message));
|
|
158
|
-
*
|
|
159
|
-
* const circularData = {};
|
|
160
|
-
* circularData.foo = circularData;
|
|
161
|
-
* // Prints: { foo: [Circular] }
|
|
162
|
-
* port2.postMessage(circularData);
|
|
163
|
-
* ```
|
|
164
|
-
*
|
|
165
|
-
* `transferList` may be a list of [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer), `MessagePort`, and `FileHandle` objects.
|
|
166
|
-
* After transferring, they are not usable on the sending side of the channel
|
|
167
|
-
* anymore (even if they are not contained in `value`). Unlike with `child processes`, transferring handles such as network sockets is currently
|
|
168
|
-
* not supported.
|
|
169
|
-
*
|
|
170
|
-
* If `value` contains [`SharedArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) instances, those are accessible
|
|
171
|
-
* from either thread. They cannot be listed in `transferList`.
|
|
172
|
-
*
|
|
173
|
-
* `value` may still contain `ArrayBuffer` instances that are not in `transferList`; in that case, the underlying memory is copied rather than moved.
|
|
174
|
-
*
|
|
175
|
-
* ```js
|
|
176
|
-
* import { MessageChannel } from 'node:worker_threads';
|
|
177
|
-
* const { port1, port2 } = new MessageChannel();
|
|
178
|
-
*
|
|
179
|
-
* port1.on('message', (message) => console.log(message));
|
|
180
|
-
*
|
|
181
|
-
* const uint8Array = new Uint8Array([ 1, 2, 3, 4 ]);
|
|
182
|
-
* // This posts a copy of `uint8Array`:
|
|
183
|
-
* port2.postMessage(uint8Array);
|
|
184
|
-
* // This does not copy data, but renders `uint8Array` unusable:
|
|
185
|
-
* port2.postMessage(uint8Array, [ uint8Array.buffer ]);
|
|
186
|
-
*
|
|
187
|
-
* // The memory for the `sharedUint8Array` is accessible from both the
|
|
188
|
-
* // original and the copy received by `.on('message')`:
|
|
189
|
-
* const sharedUint8Array = new Uint8Array(new SharedArrayBuffer(4));
|
|
190
|
-
* port2.postMessage(sharedUint8Array);
|
|
191
|
-
*
|
|
192
|
-
* // This transfers a freshly created message port to the receiver.
|
|
193
|
-
* // This can be used, for example, to create communication channels between
|
|
194
|
-
* // multiple `Worker` threads that are children of the same parent thread.
|
|
195
|
-
* const otherChannel = new MessageChannel();
|
|
196
|
-
* port2.postMessage({ port: otherChannel.port1 }, [ otherChannel.port1 ]);
|
|
197
|
-
* ```
|
|
198
|
-
*
|
|
199
|
-
* The message object is cloned immediately, and can be modified after
|
|
200
|
-
* posting without having side effects.
|
|
201
|
-
*
|
|
202
|
-
* For more information on the serialization and deserialization mechanisms
|
|
203
|
-
* behind this API, see the `serialization API of the node:v8 module`.
|
|
204
|
-
* @since v10.5.0
|
|
205
|
-
*/
|
|
206
|
-
postMessage(value: any, transferList?: readonly Transferable[]): void;
|
|
207
|
-
/**
|
|
208
|
-
* If true, the `MessagePort` object will keep the Node.js event loop active.
|
|
209
|
-
* @since v18.1.0, v16.17.0
|
|
210
|
-
*/
|
|
211
|
-
hasRef(): boolean;
|
|
212
|
-
/**
|
|
213
|
-
* 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
|
|
214
|
-
* behavior). If the port is `ref()`ed, calling `ref()` again has no effect.
|
|
215
|
-
*
|
|
216
|
-
* If listeners are attached or removed using `.on('message')`, the port
|
|
217
|
-
* is `ref()`ed and `unref()`ed automatically depending on whether
|
|
218
|
-
* listeners for the event exist.
|
|
219
|
-
* @since v10.5.0
|
|
220
|
-
*/
|
|
221
|
-
ref(): void;
|
|
222
|
-
/**
|
|
223
|
-
* Calling `unref()` on a port allows the thread to exit if this is the only
|
|
224
|
-
* active handle in the event system. If the port is already `unref()`ed calling `unref()` again has no effect.
|
|
225
|
-
*
|
|
226
|
-
* If listeners are attached or removed using `.on('message')`, the port is `ref()`ed and `unref()`ed automatically depending on whether
|
|
227
|
-
* listeners for the event exist.
|
|
228
|
-
* @since v10.5.0
|
|
229
|
-
*/
|
|
230
|
-
unref(): void;
|
|
231
|
-
/**
|
|
232
|
-
* Starts receiving messages on this `MessagePort`. When using this port
|
|
233
|
-
* as an event emitter, this is called automatically once `'message'` listeners are attached.
|
|
234
|
-
*
|
|
235
|
-
* This method exists for parity with the Web `MessagePort` API. In Node.js,
|
|
236
|
-
* it is only useful for ignoring messages when no event listener is present.
|
|
237
|
-
* Node.js also diverges in its handling of `.onmessage`. Setting it
|
|
238
|
-
* automatically calls `.start()`, but unsetting it lets messages queue up
|
|
239
|
-
* until a new handler is set or the port is discarded.
|
|
240
|
-
* @since v10.5.0
|
|
241
|
-
*/
|
|
242
|
-
start(): void;
|
|
243
|
-
addListener(event: "close", listener: () => void): this;
|
|
244
|
-
addListener(event: "message", listener: (value: any) => void): this;
|
|
245
|
-
addListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
246
|
-
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
247
|
-
emit(event: "close"): boolean;
|
|
248
|
-
emit(event: "message", value: any): boolean;
|
|
249
|
-
emit(event: "messageerror", error: Error): boolean;
|
|
250
|
-
emit(event: string | symbol, ...args: any[]): boolean;
|
|
251
|
-
on(event: "close", listener: () => void): this;
|
|
252
|
-
on(event: "message", listener: (value: any) => void): this;
|
|
253
|
-
on(event: "messageerror", listener: (error: Error) => void): this;
|
|
254
|
-
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
255
|
-
once(event: "close", listener: () => void): this;
|
|
256
|
-
once(event: "message", listener: (value: any) => void): this;
|
|
257
|
-
once(event: "messageerror", listener: (error: Error) => void): this;
|
|
258
|
-
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
259
|
-
prependListener(event: "close", listener: () => void): this;
|
|
260
|
-
prependListener(event: "message", listener: (value: any) => void): this;
|
|
261
|
-
prependListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
262
|
-
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
263
|
-
prependOnceListener(event: "close", listener: () => void): this;
|
|
264
|
-
prependOnceListener(event: "message", listener: (value: any) => void): this;
|
|
265
|
-
prependOnceListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
266
|
-
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
267
|
-
removeListener(event: "close", listener: () => void): this;
|
|
268
|
-
removeListener(event: "message", listener: (value: any) => void): this;
|
|
269
|
-
removeListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
270
|
-
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
271
|
-
off(event: "close", listener: () => void): this;
|
|
272
|
-
off(event: "message", listener: (value: any) => void): this;
|
|
273
|
-
off(event: "messageerror", listener: (error: Error) => void): this;
|
|
274
|
-
off(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
275
|
-
addEventListener: EventTarget["addEventListener"];
|
|
276
|
-
dispatchEvent: EventTarget["dispatchEvent"];
|
|
277
|
-
removeEventListener: EventTarget["removeEventListener"];
|
|
278
|
-
}
|
|
279
100
|
interface WorkerOptions {
|
|
280
101
|
/**
|
|
281
102
|
* List of arguments which would be stringified and appended to
|
|
@@ -326,6 +147,13 @@ declare module "node:worker_threads" {
|
|
|
326
147
|
*/
|
|
327
148
|
stackSizeMb?: number | undefined;
|
|
328
149
|
}
|
|
150
|
+
interface WorkerEventMap {
|
|
151
|
+
"error": [err: unknown];
|
|
152
|
+
"exit": [exitCode: number];
|
|
153
|
+
"message": [value: any];
|
|
154
|
+
"messageerror": [error: Error];
|
|
155
|
+
"online": [];
|
|
156
|
+
}
|
|
329
157
|
/**
|
|
330
158
|
* The `Worker` class represents an independent JavaScript execution thread.
|
|
331
159
|
* Most Node.js APIs are available inside of it.
|
|
@@ -390,7 +218,7 @@ declare module "node:worker_threads" {
|
|
|
390
218
|
* ```
|
|
391
219
|
* @since v10.5.0
|
|
392
220
|
*/
|
|
393
|
-
class Worker
|
|
221
|
+
class Worker implements EventEmitter {
|
|
394
222
|
/**
|
|
395
223
|
* If `stdin: true` was passed to the `Worker` constructor, this is a
|
|
396
224
|
* writable stream. The data written to this stream will be made available in
|
|
@@ -417,6 +245,12 @@ declare module "node:worker_threads" {
|
|
|
417
245
|
* @since v10.5.0
|
|
418
246
|
*/
|
|
419
247
|
readonly threadId: number;
|
|
248
|
+
/**
|
|
249
|
+
* A string identifier for the referenced thread or null if the thread is not running.
|
|
250
|
+
* Inside the worker thread, it is available as `require('node:worker_threads').threadName`.
|
|
251
|
+
* @since v24.6.0
|
|
252
|
+
*/
|
|
253
|
+
readonly threadName: string | null;
|
|
420
254
|
/**
|
|
421
255
|
* Provides the set of JS engine resource constraints for this Worker thread.
|
|
422
256
|
* If the `resourceLimits` option was passed to the `Worker` constructor,
|
|
@@ -444,24 +278,6 @@ declare module "node:worker_threads" {
|
|
|
444
278
|
* @since v10.5.0
|
|
445
279
|
*/
|
|
446
280
|
postMessage(value: any, transferList?: readonly Transferable[]): void;
|
|
447
|
-
/**
|
|
448
|
-
* Sends a value to another worker, identified by its thread ID.
|
|
449
|
-
* @param threadId The target thread ID. If the thread ID is invalid, a `ERR_WORKER_MESSAGING_FAILED` error will be thrown.
|
|
450
|
-
* If the target thread ID is the current thread ID, a `ERR_WORKER_MESSAGING_SAME_THREAD` error will be thrown.
|
|
451
|
-
* @param value The value to send.
|
|
452
|
-
* @param transferList If one or more `MessagePort`-like objects are passed in value, a `transferList` is required for those items
|
|
453
|
-
* or `ERR_MISSING_MESSAGE_PORT_IN_TRANSFER_LIST` is thrown. See `port.postMessage()` for more information.
|
|
454
|
-
* @param timeout Time to wait for the message to be delivered in milliseconds. By default it's `undefined`, which means wait forever.
|
|
455
|
-
* If the operation times out, a `ERR_WORKER_MESSAGING_TIMEOUT` error is thrown.
|
|
456
|
-
* @since v22.5.0
|
|
457
|
-
*/
|
|
458
|
-
postMessageToThread(threadId: number, value: any, timeout?: number): Promise<void>;
|
|
459
|
-
postMessageToThread(
|
|
460
|
-
threadId: number,
|
|
461
|
-
value: any,
|
|
462
|
-
transferList: readonly Transferable[],
|
|
463
|
-
timeout?: number,
|
|
464
|
-
): Promise<void>;
|
|
465
281
|
/**
|
|
466
282
|
* 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
|
|
467
283
|
* behavior). If the worker is `ref()`ed, calling `ref()` again has
|
|
@@ -481,6 +297,13 @@ declare module "node:worker_threads" {
|
|
|
481
297
|
* @since v10.5.0
|
|
482
298
|
*/
|
|
483
299
|
terminate(): Promise<number>;
|
|
300
|
+
/**
|
|
301
|
+
* This method returns a `Promise` that will resolve to an object identical to `process.threadCpuUsage()`,
|
|
302
|
+
* or reject with an `ERR_WORKER_NOT_RUNNING` error if the worker is no longer running.
|
|
303
|
+
* This methods allows the statistics to be observed from outside the actual thread.
|
|
304
|
+
* @since v24.6.0
|
|
305
|
+
*/
|
|
306
|
+
cpuUsage(prev?: NodeJS.CpuUsage): Promise<NodeJS.CpuUsage>;
|
|
484
307
|
/**
|
|
485
308
|
* Returns a readable stream for a V8 snapshot of the current state of the Worker.
|
|
486
309
|
* See `v8.getHeapSnapshot()` for more details.
|
|
@@ -498,110 +321,95 @@ declare module "node:worker_threads" {
|
|
|
498
321
|
* @since v24.0.0
|
|
499
322
|
*/
|
|
500
323
|
getHeapStatistics(): Promise<HeapInfo>;
|
|
501
|
-
addListener(event: "error", listener: (err: Error) => void): this;
|
|
502
|
-
addListener(event: "exit", listener: (exitCode: number) => void): this;
|
|
503
|
-
addListener(event: "message", listener: (value: any) => void): this;
|
|
504
|
-
addListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
505
|
-
addListener(event: "online", listener: () => void): this;
|
|
506
|
-
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
507
|
-
emit(event: "error", err: Error): boolean;
|
|
508
|
-
emit(event: "exit", exitCode: number): boolean;
|
|
509
|
-
emit(event: "message", value: any): boolean;
|
|
510
|
-
emit(event: "messageerror", error: Error): boolean;
|
|
511
|
-
emit(event: "online"): boolean;
|
|
512
|
-
emit(event: string | symbol, ...args: any[]): boolean;
|
|
513
|
-
on(event: "error", listener: (err: Error) => void): this;
|
|
514
|
-
on(event: "exit", listener: (exitCode: number) => void): this;
|
|
515
|
-
on(event: "message", listener: (value: any) => void): this;
|
|
516
|
-
on(event: "messageerror", listener: (error: Error) => void): this;
|
|
517
|
-
on(event: "online", listener: () => void): this;
|
|
518
|
-
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
519
|
-
once(event: "error", listener: (err: Error) => void): this;
|
|
520
|
-
once(event: "exit", listener: (exitCode: number) => void): this;
|
|
521
|
-
once(event: "message", listener: (value: any) => void): this;
|
|
522
|
-
once(event: "messageerror", listener: (error: Error) => void): this;
|
|
523
|
-
once(event: "online", listener: () => void): this;
|
|
524
|
-
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
525
|
-
prependListener(event: "error", listener: (err: Error) => void): this;
|
|
526
|
-
prependListener(event: "exit", listener: (exitCode: number) => void): this;
|
|
527
|
-
prependListener(event: "message", listener: (value: any) => void): this;
|
|
528
|
-
prependListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
529
|
-
prependListener(event: "online", listener: () => void): this;
|
|
530
|
-
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
531
|
-
prependOnceListener(event: "error", listener: (err: Error) => void): this;
|
|
532
|
-
prependOnceListener(event: "exit", listener: (exitCode: number) => void): this;
|
|
533
|
-
prependOnceListener(event: "message", listener: (value: any) => void): this;
|
|
534
|
-
prependOnceListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
535
|
-
prependOnceListener(event: "online", listener: () => void): this;
|
|
536
|
-
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
537
|
-
removeListener(event: "error", listener: (err: Error) => void): this;
|
|
538
|
-
removeListener(event: "exit", listener: (exitCode: number) => void): this;
|
|
539
|
-
removeListener(event: "message", listener: (value: any) => void): this;
|
|
540
|
-
removeListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
541
|
-
removeListener(event: "online", listener: () => void): this;
|
|
542
|
-
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
543
|
-
off(event: "error", listener: (err: Error) => void): this;
|
|
544
|
-
off(event: "exit", listener: (exitCode: number) => void): this;
|
|
545
|
-
off(event: "message", listener: (value: any) => void): this;
|
|
546
|
-
off(event: "messageerror", listener: (error: Error) => void): this;
|
|
547
|
-
off(event: "online", listener: () => void): this;
|
|
548
|
-
off(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
549
|
-
}
|
|
550
|
-
interface BroadcastChannel extends NodeJS.RefCounted {}
|
|
551
|
-
/**
|
|
552
|
-
* Instances of `BroadcastChannel` allow asynchronous one-to-many communication
|
|
553
|
-
* with all other `BroadcastChannel` instances bound to the same channel name.
|
|
554
|
-
*
|
|
555
|
-
* ```js
|
|
556
|
-
* 'use strict';
|
|
557
|
-
*
|
|
558
|
-
* import {
|
|
559
|
-
* isMainThread,
|
|
560
|
-
* BroadcastChannel,
|
|
561
|
-
* Worker,
|
|
562
|
-
* } from 'node:worker_threads';
|
|
563
|
-
*
|
|
564
|
-
* const bc = new BroadcastChannel('hello');
|
|
565
|
-
*
|
|
566
|
-
* if (isMainThread) {
|
|
567
|
-
* let c = 0;
|
|
568
|
-
* bc.onmessage = (event) => {
|
|
569
|
-
* console.log(event.data);
|
|
570
|
-
* if (++c === 10) bc.close();
|
|
571
|
-
* };
|
|
572
|
-
* for (let n = 0; n < 10; n++)
|
|
573
|
-
* new Worker(__filename);
|
|
574
|
-
* } else {
|
|
575
|
-
* bc.postMessage('hello from every worker');
|
|
576
|
-
* bc.close();
|
|
577
|
-
* }
|
|
578
|
-
* ```
|
|
579
|
-
* @since v15.4.0
|
|
580
|
-
*/
|
|
581
|
-
class BroadcastChannel {
|
|
582
|
-
readonly name: string;
|
|
583
|
-
/**
|
|
584
|
-
* Invoked with a single \`MessageEvent\` argument when a message is received.
|
|
585
|
-
* @since v15.4.0
|
|
586
|
-
*/
|
|
587
|
-
onmessage: (message: unknown) => void;
|
|
588
324
|
/**
|
|
589
|
-
*
|
|
590
|
-
*
|
|
325
|
+
* Starting a CPU profile then return a Promise that fulfills with an error
|
|
326
|
+
* or an `CPUProfileHandle` object. This API supports `await using` syntax.
|
|
327
|
+
*
|
|
328
|
+
* ```js
|
|
329
|
+
* const { Worker } = require('node:worker_threads');
|
|
330
|
+
*
|
|
331
|
+
* const worker = new Worker(`
|
|
332
|
+
* const { parentPort } = require('worker_threads');
|
|
333
|
+
* parentPort.on('message', () => {});
|
|
334
|
+
* `, { eval: true });
|
|
335
|
+
*
|
|
336
|
+
* worker.on('online', async () => {
|
|
337
|
+
* const handle = await worker.startCpuProfile();
|
|
338
|
+
* const profile = await handle.stop();
|
|
339
|
+
* console.log(profile);
|
|
340
|
+
* worker.terminate();
|
|
341
|
+
* });
|
|
342
|
+
* ```
|
|
343
|
+
*
|
|
344
|
+
* `await using` example.
|
|
345
|
+
*
|
|
346
|
+
* ```js
|
|
347
|
+
* const { Worker } = require('node:worker_threads');
|
|
348
|
+
*
|
|
349
|
+
* const w = new Worker(`
|
|
350
|
+
* const { parentPort } = require('node:worker_threads');
|
|
351
|
+
* parentPort.on('message', () => {});
|
|
352
|
+
* `, { eval: true });
|
|
353
|
+
*
|
|
354
|
+
* w.on('online', async () => {
|
|
355
|
+
* // Stop profile automatically when return and profile will be discarded
|
|
356
|
+
* await using handle = await w.startCpuProfile();
|
|
357
|
+
* });
|
|
358
|
+
* ```
|
|
359
|
+
* @since v24.8.0
|
|
591
360
|
*/
|
|
592
|
-
|
|
593
|
-
constructor(name: string);
|
|
361
|
+
startCpuProfile(): Promise<CPUProfileHandle>;
|
|
594
362
|
/**
|
|
595
|
-
*
|
|
596
|
-
*
|
|
363
|
+
* Starting a Heap profile then return a Promise that fulfills with an error
|
|
364
|
+
* or an `HeapProfileHandle` object. This API supports `await using` syntax.
|
|
365
|
+
*
|
|
366
|
+
* ```js
|
|
367
|
+
* const { Worker } = require('node:worker_threads');
|
|
368
|
+
*
|
|
369
|
+
* const worker = new Worker(`
|
|
370
|
+
* const { parentPort } = require('worker_threads');
|
|
371
|
+
* parentPort.on('message', () => {});
|
|
372
|
+
* `, { eval: true });
|
|
373
|
+
*
|
|
374
|
+
* worker.on('online', async () => {
|
|
375
|
+
* const handle = await worker.startHeapProfile();
|
|
376
|
+
* const profile = await handle.stop();
|
|
377
|
+
* console.log(profile);
|
|
378
|
+
* worker.terminate();
|
|
379
|
+
* });
|
|
380
|
+
* ```
|
|
381
|
+
*
|
|
382
|
+
* `await using` example.
|
|
383
|
+
*
|
|
384
|
+
* ```js
|
|
385
|
+
* const { Worker } = require('node:worker_threads');
|
|
386
|
+
*
|
|
387
|
+
* const w = new Worker(`
|
|
388
|
+
* const { parentPort } = require('node:worker_threads');
|
|
389
|
+
* parentPort.on('message', () => {});
|
|
390
|
+
* `, { eval: true });
|
|
391
|
+
*
|
|
392
|
+
* w.on('online', async () => {
|
|
393
|
+
* // Stop profile automatically when return and profile will be discarded
|
|
394
|
+
* await using handle = await w.startHeapProfile();
|
|
395
|
+
* });
|
|
396
|
+
* ```
|
|
597
397
|
*/
|
|
598
|
-
|
|
398
|
+
startHeapProfile(): Promise<HeapProfileHandle>;
|
|
599
399
|
/**
|
|
600
|
-
*
|
|
601
|
-
*
|
|
400
|
+
* Calls `worker.terminate()` when the dispose scope is exited.
|
|
401
|
+
*
|
|
402
|
+
* ```js
|
|
403
|
+
* async function example() {
|
|
404
|
+
* await using worker = new Worker('for (;;) {}', { eval: true });
|
|
405
|
+
* // Worker is automatically terminate when the scope is exited.
|
|
406
|
+
* }
|
|
407
|
+
* ```
|
|
408
|
+
* @since v24.2.0
|
|
602
409
|
*/
|
|
603
|
-
|
|
410
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
604
411
|
}
|
|
412
|
+
interface Worker extends InternalEventEmitter<WorkerEventMap> {}
|
|
605
413
|
/**
|
|
606
414
|
* Mark an object as not transferable. If `object` occurs in the transfer list of
|
|
607
415
|
* a `port.postMessage()` call, it is ignored.
|
|
@@ -743,46 +551,180 @@ declare module "node:worker_threads" {
|
|
|
743
551
|
* for the `key` will be deleted.
|
|
744
552
|
*/
|
|
745
553
|
function setEnvironmentData(key: Serializable, value?: Serializable): void;
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
554
|
+
/**
|
|
555
|
+
* Sends a value to another worker, identified by its thread ID.
|
|
556
|
+
* @param threadId The target thread ID. If the thread ID is invalid, a `ERR_WORKER_MESSAGING_FAILED` error will be thrown.
|
|
557
|
+
* If the target thread ID is the current thread ID, a `ERR_WORKER_MESSAGING_SAME_THREAD` error will be thrown.
|
|
558
|
+
* @param value The value to send.
|
|
559
|
+
* @param transferList If one or more `MessagePort`-like objects are passed in value, a `transferList` is required for those items
|
|
560
|
+
* or `ERR_MISSING_MESSAGE_PORT_IN_TRANSFER_LIST` is thrown. See `port.postMessage()` for more information.
|
|
561
|
+
* @param timeout Time to wait for the message to be delivered in milliseconds. By default it's `undefined`, which means wait forever.
|
|
562
|
+
* If the operation times out, a `ERR_WORKER_MESSAGING_TIMEOUT` error is thrown.
|
|
563
|
+
* @since v22.5.0
|
|
564
|
+
*/
|
|
565
|
+
function postMessageToThread(threadId: number, value: any, timeout?: number): Promise<void>;
|
|
566
|
+
function postMessageToThread(
|
|
567
|
+
threadId: number,
|
|
568
|
+
value: any,
|
|
569
|
+
transferList: readonly Transferable[],
|
|
570
|
+
timeout?: number,
|
|
571
|
+
): Promise<void>;
|
|
572
|
+
// #region web types
|
|
573
|
+
type LockMode = "exclusive" | "shared";
|
|
574
|
+
type Transferable =
|
|
575
|
+
| ArrayBuffer
|
|
576
|
+
| MessagePort
|
|
577
|
+
| AbortSignal
|
|
578
|
+
| FileHandle
|
|
579
|
+
| ReadableStream
|
|
580
|
+
| WritableStream
|
|
581
|
+
| TransformStream;
|
|
582
|
+
interface LockGrantedCallback<T> {
|
|
583
|
+
(lock: Lock | null): T;
|
|
584
|
+
}
|
|
585
|
+
interface LockInfo {
|
|
586
|
+
clientId: string;
|
|
587
|
+
mode: LockMode;
|
|
588
|
+
name: string;
|
|
589
|
+
}
|
|
590
|
+
interface LockManagerSnapshot {
|
|
591
|
+
held: LockInfo[];
|
|
592
|
+
pending: LockInfo[];
|
|
593
|
+
}
|
|
594
|
+
interface LockOptions {
|
|
595
|
+
ifAvailable?: boolean;
|
|
596
|
+
mode?: LockMode;
|
|
597
|
+
signal?: AbortSignal;
|
|
598
|
+
steal?: boolean;
|
|
599
|
+
}
|
|
600
|
+
interface StructuredSerializeOptions {
|
|
601
|
+
transfer?: Transferable[];
|
|
602
|
+
}
|
|
603
|
+
interface BroadcastChannelEventMap {
|
|
604
|
+
"message": MessageEvent;
|
|
605
|
+
"messageerror": MessageEvent;
|
|
606
|
+
}
|
|
607
|
+
interface BroadcastChannel
|
|
608
|
+
extends EventTarget, InternalEventTargetEventProperties<BroadcastChannelEventMap>, NodeJS.RefCounted
|
|
609
|
+
{
|
|
610
|
+
readonly name: string;
|
|
611
|
+
close(): void;
|
|
612
|
+
postMessage(message: any): void;
|
|
613
|
+
addEventListener<K extends keyof BroadcastChannelEventMap>(
|
|
614
|
+
type: K,
|
|
615
|
+
listener: (ev: BroadcastChannelEventMap[K]) => void,
|
|
616
|
+
options?: AddEventListenerOptions | boolean,
|
|
617
|
+
): void;
|
|
618
|
+
addEventListener(
|
|
619
|
+
type: string,
|
|
620
|
+
listener: EventListener | EventListenerObject,
|
|
621
|
+
options?: AddEventListenerOptions | boolean,
|
|
622
|
+
): void;
|
|
623
|
+
removeEventListener<K extends keyof BroadcastChannelEventMap>(
|
|
624
|
+
type: K,
|
|
625
|
+
listener: (ev: BroadcastChannelEventMap[K]) => void,
|
|
626
|
+
options?: EventListenerOptions | boolean,
|
|
627
|
+
): void;
|
|
628
|
+
removeEventListener(
|
|
629
|
+
type: string,
|
|
630
|
+
listener: EventListener | EventListenerObject,
|
|
631
|
+
options?: EventListenerOptions | boolean,
|
|
632
|
+
): void;
|
|
633
|
+
}
|
|
634
|
+
var BroadcastChannel: {
|
|
635
|
+
prototype: BroadcastChannel;
|
|
636
|
+
new(name: string): BroadcastChannel;
|
|
637
|
+
};
|
|
638
|
+
interface Lock {
|
|
639
|
+
readonly mode: LockMode;
|
|
640
|
+
readonly name: string;
|
|
641
|
+
}
|
|
642
|
+
// var Lock: {
|
|
643
|
+
// prototype: Lock;
|
|
644
|
+
// new(): Lock;
|
|
645
|
+
// };
|
|
646
|
+
interface LockManager {
|
|
647
|
+
query(): Promise<LockManagerSnapshot>;
|
|
648
|
+
request<T>(name: string, callback: LockGrantedCallback<T>): Promise<Awaited<T>>;
|
|
649
|
+
request<T>(name: string, options: LockOptions, callback: LockGrantedCallback<T>): Promise<Awaited<T>>;
|
|
650
|
+
}
|
|
651
|
+
// var LockManager: {
|
|
652
|
+
// prototype: LockManager;
|
|
653
|
+
// new(): LockManager;
|
|
654
|
+
// };
|
|
655
|
+
interface MessageChannel {
|
|
656
|
+
readonly port1: MessagePort;
|
|
657
|
+
readonly port2: MessagePort;
|
|
658
|
+
}
|
|
659
|
+
var MessageChannel: {
|
|
660
|
+
prototype: MessageChannel;
|
|
661
|
+
new(): MessageChannel;
|
|
662
|
+
};
|
|
663
|
+
interface MessagePortEventMap {
|
|
664
|
+
"close": Event;
|
|
665
|
+
"message": MessageEvent;
|
|
666
|
+
"messageerror": MessageEvent;
|
|
667
|
+
}
|
|
668
|
+
interface MessagePort extends NodeEventTarget, InternalEventTargetEventProperties<MessagePortEventMap> {
|
|
669
|
+
close(): void;
|
|
670
|
+
postMessage(message: any, transfer: Transferable[]): void;
|
|
671
|
+
postMessage(message: any, options?: StructuredSerializeOptions): void;
|
|
672
|
+
start(): void;
|
|
673
|
+
hasRef(): boolean;
|
|
674
|
+
ref(): void;
|
|
675
|
+
unref(): void;
|
|
676
|
+
addEventListener<K extends keyof MessagePortEventMap>(
|
|
677
|
+
type: K,
|
|
678
|
+
listener: (ev: MessagePortEventMap[K]) => void,
|
|
679
|
+
options?: AddEventListenerOptions | boolean,
|
|
680
|
+
): void;
|
|
681
|
+
addEventListener(
|
|
682
|
+
type: string,
|
|
683
|
+
listener: EventListener | EventListenerObject,
|
|
684
|
+
options?: AddEventListenerOptions | boolean,
|
|
685
|
+
): void;
|
|
686
|
+
removeEventListener<K extends keyof MessagePortEventMap>(
|
|
687
|
+
type: K,
|
|
688
|
+
listener: (ev: MessagePortEventMap[K]) => void,
|
|
689
|
+
options?: EventListenerOptions | boolean,
|
|
690
|
+
): void;
|
|
691
|
+
removeEventListener(
|
|
692
|
+
type: string,
|
|
693
|
+
listener: EventListener | EventListenerObject,
|
|
694
|
+
options?: EventListenerOptions | boolean,
|
|
695
|
+
): void;
|
|
696
|
+
// #region NodeEventTarget
|
|
697
|
+
addListener(event: "close", listener: (ev: Event) => void): this;
|
|
698
|
+
addListener(event: "message", listener: (value: any) => void): this;
|
|
699
|
+
addListener(event: "messageerror", listener: (error: Error) => void): this;
|
|
700
|
+
addListener(event: string, listener: (arg: any) => void): this;
|
|
701
|
+
emit(event: "close", ev: Event): boolean;
|
|
702
|
+
emit(event: "message", value: any): boolean;
|
|
703
|
+
emit(event: "messageerror", error: Error): boolean;
|
|
704
|
+
emit(event: string, arg: any): boolean;
|
|
705
|
+
off(event: "close", listener: (ev: Event) => void, options?: EventListenerOptions): this;
|
|
706
|
+
off(event: "message", listener: (value: any) => void, options?: EventListenerOptions): this;
|
|
707
|
+
off(event: "messageerror", listener: (error: Error) => void, options?: EventListenerOptions): this;
|
|
708
|
+
off(event: string, listener: (arg: any) => void, options?: EventListenerOptions): this;
|
|
709
|
+
on(event: "close", listener: (ev: Event) => void): this;
|
|
710
|
+
on(event: "message", listener: (value: any) => void): this;
|
|
711
|
+
on(event: "messageerror", listener: (error: Error) => void): this;
|
|
712
|
+
on(event: string, listener: (arg: any) => void): this;
|
|
713
|
+
once(event: "close", listener: (ev: Event) => void): this;
|
|
714
|
+
once(event: "message", listener: (value: any) => void): this;
|
|
715
|
+
once(event: "messageerror", listener: (error: Error) => void): this;
|
|
716
|
+
once(event: string, listener: (arg: any) => void): this;
|
|
717
|
+
removeListener(event: "close", listener: (ev: Event) => void, options?: EventListenerOptions): this;
|
|
718
|
+
removeListener(event: "message", listener: (value: any) => void, options?: EventListenerOptions): this;
|
|
719
|
+
removeListener(event: "messageerror", listener: (error: Error) => void, options?: EventListenerOptions): this;
|
|
720
|
+
removeListener(event: string, listener: (arg: any) => void, options?: EventListenerOptions): this;
|
|
721
|
+
// #endregion
|
|
787
722
|
}
|
|
723
|
+
var MessagePort: {
|
|
724
|
+
prototype: MessagePort;
|
|
725
|
+
new(): MessagePort;
|
|
726
|
+
};
|
|
727
|
+
var locks: LockManager;
|
|
728
|
+
export import structuredClone = globalThis.structuredClone;
|
|
729
|
+
// #endregion
|
|
788
730
|
}
|