@idlebox/stripe-node-types 24.0.14-patch.0 → 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.
Files changed (134) hide show
  1. package/README.md +1 -1
  2. package/assert/strict.d.ts +113 -1
  3. package/assert.d.ts +162 -248
  4. package/async_hooks.d.ts +20 -5
  5. package/buffer.buffer.d.ts +24 -6
  6. package/buffer.d.ts +63 -168
  7. package/child_process.d.ts +117 -223
  8. package/cluster.d.ts +251 -329
  9. package/compatibility/iterators.d.ts +15 -0
  10. package/console.d.ts +60 -346
  11. package/constants.d.ts +15 -1
  12. package/crypto.d.ts +713 -1149
  13. package/dgram.d.ts +30 -50
  14. package/diagnostics_channel.d.ts +16 -3
  15. package/dns/promises.d.ts +15 -0
  16. package/dns.d.ts +150 -131
  17. package/domain.d.ts +25 -14
  18. package/events.d.ts +858 -719
  19. package/fs/promises.d.ts +117 -53
  20. package/fs.d.ts +729 -484
  21. package/globals.d.ts +142 -344
  22. package/globals.typedarray.d.ts +94 -0
  23. package/http.d.ts +358 -246
  24. package/http2.d.ts +578 -711
  25. package/https.d.ts +85 -216
  26. package/index.d.ts +39 -3
  27. package/inspector/promises.d.ts +54 -0
  28. package/inspector.d.ts +180 -3936
  29. package/inspector.generated.d.ts +4242 -0
  30. package/module.d.ts +60 -95
  31. package/my-shim.d.ts +15 -0
  32. package/net.d.ts +102 -186
  33. package/os.d.ts +32 -6
  34. package/package.json +3 -8
  35. package/path/posix.d.ts +20 -0
  36. package/path/win32.d.ts +20 -0
  37. package/path.d.ts +132 -122
  38. package/perf_hooks.d.ts +310 -644
  39. package/process.d.ts +192 -138
  40. package/punycode.d.ts +17 -2
  41. package/querystring.d.ts +16 -1
  42. package/quic.d.ts +926 -0
  43. package/readline/promises.d.ts +16 -1
  44. package/readline.d.ts +80 -118
  45. package/repl.d.ts +98 -96
  46. package/sea.d.ts +25 -1
  47. package/sqlite.d.ts +277 -13
  48. package/stream/consumers.d.ts +22 -7
  49. package/stream/promises.d.ts +148 -12
  50. package/stream/web.d.ts +187 -494
  51. package/stream.d.ts +608 -490
  52. package/string_decoder.d.ts +18 -3
  53. package/test/reporters.d.ts +112 -0
  54. package/test.d.ts +238 -199
  55. package/timers/promises.d.ts +16 -1
  56. package/timers.d.ts +16 -129
  57. package/tls.d.ts +163 -163
  58. package/trace_events.d.ts +21 -6
  59. package/ts5.6/buffer.buffer.d.ts +25 -8
  60. package/ts5.6/compatibility/float16array.d.ts +15 -0
  61. package/ts5.6/globals.typedarray.d.ts +31 -0
  62. package/ts5.6/index.d.ts +39 -3
  63. package/ts5.7/compatibility/float16array.d.ts +15 -0
  64. package/ts5.7/index.d.ts +39 -3
  65. package/tty.d.ts +70 -13
  66. package/undici-types/agent.d.ts +20 -4
  67. package/undici-types/api.d.ts +15 -0
  68. package/undici-types/balanced-pool.d.ts +15 -0
  69. package/undici-types/cache-interceptor.d.ts +15 -0
  70. package/undici-types/cache.d.ts +15 -0
  71. package/undici-types/client-stats.d.ts +31 -0
  72. package/undici-types/client.d.ts +21 -5
  73. package/undici-types/connector.d.ts +15 -0
  74. package/undici-types/content-type.d.ts +15 -0
  75. package/undici-types/cookies.d.ts +15 -0
  76. package/undici-types/diagnostics-channel.d.ts +24 -1
  77. package/undici-types/dispatcher.d.ts +18 -8
  78. package/undici-types/env-http-proxy-agent.d.ts +17 -1
  79. package/undici-types/errors.d.ts +20 -15
  80. package/undici-types/eventsource.d.ts +24 -4
  81. package/undici-types/fetch.d.ts +16 -0
  82. package/undici-types/formdata.d.ts +15 -0
  83. package/undici-types/global-dispatcher.d.ts +15 -0
  84. package/undici-types/global-origin.d.ts +15 -0
  85. package/undici-types/h2c-client.d.ts +15 -2
  86. package/undici-types/handlers.d.ts +16 -1
  87. package/undici-types/header.d.ts +15 -0
  88. package/undici-types/index.d.ts +21 -1
  89. package/undici-types/interceptors.d.ts +20 -0
  90. package/undici-types/mock-agent.d.ts +18 -0
  91. package/undici-types/mock-call-history.d.ts +15 -0
  92. package/undici-types/mock-client.d.ts +17 -0
  93. package/undici-types/mock-errors.d.ts +15 -0
  94. package/undici-types/mock-interceptor.d.ts +17 -1
  95. package/undici-types/mock-pool.d.ts +17 -0
  96. package/undici-types/package.json +1 -1
  97. package/undici-types/patch.d.ts +15 -0
  98. package/undici-types/pool-stats.d.ts +15 -0
  99. package/undici-types/pool.d.ts +17 -0
  100. package/undici-types/proxy-agent.d.ts +16 -0
  101. package/undici-types/readable.d.ts +15 -0
  102. package/undici-types/retry-agent.d.ts +15 -0
  103. package/undici-types/retry-handler.d.ts +24 -0
  104. package/undici-types/snapshot-agent.d.ts +125 -0
  105. package/undici-types/util.d.ts +15 -0
  106. package/undici-types/utility.d.ts +15 -0
  107. package/undici-types/webidl.d.ts +126 -36
  108. package/undici-types/websocket.d.ts +18 -1
  109. package/url.d.ts +107 -587
  110. package/util/types.d.ts +571 -0
  111. package/util.d.ts +158 -792
  112. package/v8.d.ts +82 -7
  113. package/vm.d.ts +267 -108
  114. package/wasi.d.ts +38 -2
  115. package/web-globals/abortcontroller.d.ts +75 -0
  116. package/web-globals/blob.d.ts +39 -0
  117. package/web-globals/console.d.ts +25 -0
  118. package/web-globals/crypto.d.ts +55 -0
  119. package/web-globals/domexception.d.ts +84 -0
  120. package/web-globals/encoding.d.ts +27 -0
  121. package/{dom-events.d.ts → web-globals/events.d.ts} +72 -50
  122. package/web-globals/fetch.d.ts +70 -0
  123. package/web-globals/importmeta.d.ts +29 -0
  124. package/web-globals/messaging.d.ts +39 -0
  125. package/web-globals/navigator.d.ts +41 -0
  126. package/web-globals/performance.d.ts +61 -0
  127. package/web-globals/storage.d.ts +40 -0
  128. package/web-globals/streams.d.ts +131 -0
  129. package/web-globals/timers.d.ts +60 -0
  130. package/web-globals/url.d.ts +40 -0
  131. package/worker_threads.d.ts +306 -349
  132. package/zlib.d.ts +59 -94
  133. package/ts5.1/compatibility/disposable.d.ts +0 -13
  134. package/ts5.1/index.d.ts +0 -100
@@ -1,3 +1,18 @@
1
+ // biome-ignore-all lint: generated file
2
+ // biome-ignore-all assist: generated file
3
+ /* eslint-disable */
4
+ // @ts-ignore
5
+
6
+ /******************************************************************************
7
+ * GENERATED FILE, DO NOT MODIFY
8
+ * 这是生成的文件,千万不要修改
9
+ *
10
+ * @build-script/codegen - The Simple Code Generater
11
+ * https://github.com/GongT/baobao
12
+ *
13
+ ******************************************************************************/
14
+
15
+
1
16
  /**
2
17
  * The `node:worker_threads` module enables the use of threads that execute
3
18
  * JavaScript in parallel. To access it:
@@ -52,215 +67,36 @@
52
67
  *
53
68
  * Worker threads inherit non-process-specific options by default. Refer to `Worker constructor options` to know how to customize worker thread options,
54
69
  * specifically `argv` and `execArgv` options.
55
- * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/worker_threads.js)
70
+ * @see [source](https://github.com/nodejs/node/blob/v25.x/lib/worker_threads.js)
56
71
  */
57
72
 
58
73
  declare module "node:worker_threads" {
59
- import { Context } from 'node:vm';
60
- import { EventEmitter } from 'node:events';
61
- import { EventLoopUtilityFunction } from 'node:perf_hooks';
74
+ import {
75
+ EventEmitter,
76
+ InternalEventEmitter,
77
+ InternalEventTargetEventProperties,
78
+ NodeEventTarget,
79
+ } from 'node:events';
62
80
  import { FileHandle } from 'node:fs/promises';
81
+ import { Performance } from 'node:perf_hooks';
63
82
  import { Readable, Writable } from 'node:stream';
64
83
  import { ReadableStream, TransformStream, WritableStream } from 'node:stream/web';
65
84
  import { URL } from 'node:url';
66
- 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';
67
88
  const isInternalThread: boolean;
68
89
  const isMainThread: boolean;
69
90
  const parentPort: null | MessagePort;
70
91
  const resourceLimits: ResourceLimits;
71
92
  const SHARE_ENV: unique symbol;
72
93
  const threadId: number;
94
+ const threadName: string | null;
73
95
  const workerData: any;
74
- /**
75
- * Instances of the `worker.MessageChannel` class represent an asynchronous,
76
- * two-way communications channel.
77
- * The `MessageChannel` has no methods of its own. `new MessageChannel()` yields an object with `port1` and `port2` properties, which refer to linked `MessagePort` instances.
78
- *
79
- * ```js
80
- * import { MessageChannel } from 'node:worker_threads';
81
- *
82
- * const { port1, port2 } = new MessageChannel();
83
- * port1.on('message', (message) => console.log('received', message));
84
- * port2.postMessage({ foo: 'bar' });
85
- * // Prints: received { foo: 'bar' } from the `port1.on('message')` listener
86
- * ```
87
- * @since v10.5.0
88
- */
89
- class MessageChannel {
90
- readonly port1: MessagePort;
91
- readonly port2: MessagePort;
92
- }
93
- interface WorkerPerformance {
94
- eventLoopUtilization: EventLoopUtilityFunction;
95
- }
96
- type Transferable =
97
- | ArrayBuffer
98
- | MessagePort
99
- | AbortSignal
100
- | FileHandle
101
- | ReadableStream
102
- | WritableStream
103
- | TransformStream;
96
+ interface WorkerPerformance extends Pick<Performance, "eventLoopUtilization"> {}
104
97
  /** @deprecated Use `import { Transferable } from "node:worker_threads"` instead. */
105
98
  // TODO: remove in a future major @types/node version.
106
99
  type TransferListItem = Transferable;
107
- /**
108
- * Instances of the `worker.MessagePort` class represent one end of an
109
- * asynchronous, two-way communications channel. It can be used to transfer
110
- * structured data, memory regions and other `MessagePort`s between different `Worker`s.
111
- *
112
- * This implementation matches [browser `MessagePort`](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort) s.
113
- * @since v10.5.0
114
- */
115
- class MessagePort extends EventEmitter {
116
- /**
117
- * Disables further sending of messages on either side of the connection.
118
- * This method can be called when no further communication will happen over this `MessagePort`.
119
- *
120
- * The `'close' event` is emitted on both `MessagePort` instances that
121
- * are part of the channel.
122
- * @since v10.5.0
123
- */
124
- close(): void;
125
- /**
126
- * Sends a JavaScript value to the receiving side of this channel. `value` is transferred in a way which is compatible with
127
- * the [HTML structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm).
128
- *
129
- * In particular, the significant differences to `JSON` are:
130
- *
131
- * * `value` may contain circular references.
132
- * * `value` may contain instances of builtin JS types such as `RegExp`s, `BigInt`s, `Map`s, `Set`s, etc.
133
- * * `value` may contain typed arrays, both using `ArrayBuffer`s
134
- * and `SharedArrayBuffer`s.
135
- * * `value` may contain [`WebAssembly.Module`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module) instances.
136
- * * `value` may not contain native (C++-backed) objects other than:
137
- *
138
- * ```js
139
- * import { MessageChannel } from 'node:worker_threads';
140
- * const { port1, port2 } = new MessageChannel();
141
- *
142
- * port1.on('message', (message) => console.log(message));
143
- *
144
- * const circularData = {};
145
- * circularData.foo = circularData;
146
- * // Prints: { foo: [Circular] }
147
- * port2.postMessage(circularData);
148
- * ```
149
- *
150
- * `transferList` may be a list of [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer), `MessagePort`, and `FileHandle` objects.
151
- * After transferring, they are not usable on the sending side of the channel
152
- * anymore (even if they are not contained in `value`). Unlike with `child processes`, transferring handles such as network sockets is currently
153
- * not supported.
154
- *
155
- * If `value` contains [`SharedArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) instances, those are accessible
156
- * from either thread. They cannot be listed in `transferList`.
157
- *
158
- * `value` may still contain `ArrayBuffer` instances that are not in `transferList`; in that case, the underlying memory is copied rather than moved.
159
- *
160
- * ```js
161
- * import { MessageChannel } from 'node:worker_threads';
162
- * const { port1, port2 } = new MessageChannel();
163
- *
164
- * port1.on('message', (message) => console.log(message));
165
- *
166
- * const uint8Array = new Uint8Array([ 1, 2, 3, 4 ]);
167
- * // This posts a copy of `uint8Array`:
168
- * port2.postMessage(uint8Array);
169
- * // This does not copy data, but renders `uint8Array` unusable:
170
- * port2.postMessage(uint8Array, [ uint8Array.buffer ]);
171
- *
172
- * // The memory for the `sharedUint8Array` is accessible from both the
173
- * // original and the copy received by `.on('message')`:
174
- * const sharedUint8Array = new Uint8Array(new SharedArrayBuffer(4));
175
- * port2.postMessage(sharedUint8Array);
176
- *
177
- * // This transfers a freshly created message port to the receiver.
178
- * // This can be used, for example, to create communication channels between
179
- * // multiple `Worker` threads that are children of the same parent thread.
180
- * const otherChannel = new MessageChannel();
181
- * port2.postMessage({ port: otherChannel.port1 }, [ otherChannel.port1 ]);
182
- * ```
183
- *
184
- * The message object is cloned immediately, and can be modified after
185
- * posting without having side effects.
186
- *
187
- * For more information on the serialization and deserialization mechanisms
188
- * behind this API, see the `serialization API of the node:v8 module`.
189
- * @since v10.5.0
190
- */
191
- postMessage(value: any, transferList?: readonly Transferable[]): void;
192
- /**
193
- * If true, the `MessagePort` object will keep the Node.js event loop active.
194
- * @since v18.1.0, v16.17.0
195
- */
196
- hasRef(): boolean;
197
- /**
198
- * 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
199
- * behavior). If the port is `ref()`ed, calling `ref()` again has no effect.
200
- *
201
- * If listeners are attached or removed using `.on('message')`, the port
202
- * is `ref()`ed and `unref()`ed automatically depending on whether
203
- * listeners for the event exist.
204
- * @since v10.5.0
205
- */
206
- ref(): void;
207
- /**
208
- * Calling `unref()` on a port allows the thread to exit if this is the only
209
- * active handle in the event system. If the port is already `unref()`ed calling `unref()` again has no effect.
210
- *
211
- * If listeners are attached or removed using `.on('message')`, the port is `ref()`ed and `unref()`ed automatically depending on whether
212
- * listeners for the event exist.
213
- * @since v10.5.0
214
- */
215
- unref(): void;
216
- /**
217
- * Starts receiving messages on this `MessagePort`. When using this port
218
- * as an event emitter, this is called automatically once `'message'` listeners are attached.
219
- *
220
- * This method exists for parity with the Web `MessagePort` API. In Node.js,
221
- * it is only useful for ignoring messages when no event listener is present.
222
- * Node.js also diverges in its handling of `.onmessage`. Setting it
223
- * automatically calls `.start()`, but unsetting it lets messages queue up
224
- * until a new handler is set or the port is discarded.
225
- * @since v10.5.0
226
- */
227
- start(): void;
228
- addListener(event: "close", listener: () => void): this;
229
- addListener(event: "message", listener: (value: any) => void): this;
230
- addListener(event: "messageerror", listener: (error: Error) => void): this;
231
- addListener(event: string | symbol, listener: (...args: any[]) => void): this;
232
- emit(event: "close"): boolean;
233
- emit(event: "message", value: any): boolean;
234
- emit(event: "messageerror", error: Error): boolean;
235
- emit(event: string | symbol, ...args: any[]): boolean;
236
- on(event: "close", listener: () => void): this;
237
- on(event: "message", listener: (value: any) => void): this;
238
- on(event: "messageerror", listener: (error: Error) => void): this;
239
- on(event: string | symbol, listener: (...args: any[]) => void): this;
240
- once(event: "close", listener: () => void): this;
241
- once(event: "message", listener: (value: any) => void): this;
242
- once(event: "messageerror", listener: (error: Error) => void): this;
243
- once(event: string | symbol, listener: (...args: any[]) => void): this;
244
- prependListener(event: "close", listener: () => void): this;
245
- prependListener(event: "message", listener: (value: any) => void): this;
246
- prependListener(event: "messageerror", listener: (error: Error) => void): this;
247
- prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
248
- prependOnceListener(event: "close", listener: () => void): this;
249
- prependOnceListener(event: "message", listener: (value: any) => void): this;
250
- prependOnceListener(event: "messageerror", listener: (error: Error) => void): this;
251
- prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
252
- removeListener(event: "close", listener: () => void): this;
253
- removeListener(event: "message", listener: (value: any) => void): this;
254
- removeListener(event: "messageerror", listener: (error: Error) => void): this;
255
- removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
256
- off(event: "close", listener: () => void): this;
257
- off(event: "message", listener: (value: any) => void): this;
258
- off(event: "messageerror", listener: (error: Error) => void): this;
259
- off(event: string | symbol, listener: (...args: any[]) => void): this;
260
- addEventListener: EventTarget["addEventListener"];
261
- dispatchEvent: EventTarget["dispatchEvent"];
262
- removeEventListener: EventTarget["removeEventListener"];
263
- }
264
100
  interface WorkerOptions {
265
101
  /**
266
102
  * List of arguments which would be stringified and appended to
@@ -311,6 +147,13 @@ declare module "node:worker_threads" {
311
147
  */
312
148
  stackSizeMb?: number | undefined;
313
149
  }
150
+ interface WorkerEventMap {
151
+ "error": [err: unknown];
152
+ "exit": [exitCode: number];
153
+ "message": [value: any];
154
+ "messageerror": [error: Error];
155
+ "online": [];
156
+ }
314
157
  /**
315
158
  * The `Worker` class represents an independent JavaScript execution thread.
316
159
  * Most Node.js APIs are available inside of it.
@@ -375,7 +218,7 @@ declare module "node:worker_threads" {
375
218
  * ```
376
219
  * @since v10.5.0
377
220
  */
378
- class Worker extends EventEmitter {
221
+ class Worker implements EventEmitter {
379
222
  /**
380
223
  * If `stdin: true` was passed to the `Worker` constructor, this is a
381
224
  * writable stream. The data written to this stream will be made available in
@@ -402,6 +245,12 @@ declare module "node:worker_threads" {
402
245
  * @since v10.5.0
403
246
  */
404
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;
405
254
  /**
406
255
  * Provides the set of JS engine resource constraints for this Worker thread.
407
256
  * If the `resourceLimits` option was passed to the `Worker` constructor,
@@ -429,24 +278,6 @@ declare module "node:worker_threads" {
429
278
  * @since v10.5.0
430
279
  */
431
280
  postMessage(value: any, transferList?: readonly Transferable[]): void;
432
- /**
433
- * Sends a value to another worker, identified by its thread ID.
434
- * @param threadId The target thread ID. If the thread ID is invalid, a `ERR_WORKER_MESSAGING_FAILED` error will be thrown.
435
- * If the target thread ID is the current thread ID, a `ERR_WORKER_MESSAGING_SAME_THREAD` error will be thrown.
436
- * @param value The value to send.
437
- * @param transferList If one or more `MessagePort`-like objects are passed in value, a `transferList` is required for those items
438
- * or `ERR_MISSING_MESSAGE_PORT_IN_TRANSFER_LIST` is thrown. See `port.postMessage()` for more information.
439
- * @param timeout Time to wait for the message to be delivered in milliseconds. By default it's `undefined`, which means wait forever.
440
- * If the operation times out, a `ERR_WORKER_MESSAGING_TIMEOUT` error is thrown.
441
- * @since v22.5.0
442
- */
443
- postMessageToThread(threadId: number, value: any, timeout?: number): Promise<void>;
444
- postMessageToThread(
445
- threadId: number,
446
- value: any,
447
- transferList: readonly Transferable[],
448
- timeout?: number,
449
- ): Promise<void>;
450
281
  /**
451
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
452
283
  * behavior). If the worker is `ref()`ed, calling `ref()` again has
@@ -466,6 +297,13 @@ declare module "node:worker_threads" {
466
297
  * @since v10.5.0
467
298
  */
468
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>;
469
307
  /**
470
308
  * Returns a readable stream for a V8 snapshot of the current state of the Worker.
471
309
  * See `v8.getHeapSnapshot()` for more details.
@@ -483,110 +321,95 @@ declare module "node:worker_threads" {
483
321
  * @since v24.0.0
484
322
  */
485
323
  getHeapStatistics(): Promise<HeapInfo>;
486
- addListener(event: "error", listener: (err: Error) => void): this;
487
- addListener(event: "exit", listener: (exitCode: number) => void): this;
488
- addListener(event: "message", listener: (value: any) => void): this;
489
- addListener(event: "messageerror", listener: (error: Error) => void): this;
490
- addListener(event: "online", listener: () => void): this;
491
- addListener(event: string | symbol, listener: (...args: any[]) => void): this;
492
- emit(event: "error", err: Error): boolean;
493
- emit(event: "exit", exitCode: number): boolean;
494
- emit(event: "message", value: any): boolean;
495
- emit(event: "messageerror", error: Error): boolean;
496
- emit(event: "online"): boolean;
497
- emit(event: string | symbol, ...args: any[]): boolean;
498
- on(event: "error", listener: (err: Error) => void): this;
499
- on(event: "exit", listener: (exitCode: number) => void): this;
500
- on(event: "message", listener: (value: any) => void): this;
501
- on(event: "messageerror", listener: (error: Error) => void): this;
502
- on(event: "online", listener: () => void): this;
503
- on(event: string | symbol, listener: (...args: any[]) => void): this;
504
- once(event: "error", listener: (err: Error) => void): this;
505
- once(event: "exit", listener: (exitCode: number) => void): this;
506
- once(event: "message", listener: (value: any) => void): this;
507
- once(event: "messageerror", listener: (error: Error) => void): this;
508
- once(event: "online", listener: () => void): this;
509
- once(event: string | symbol, listener: (...args: any[]) => void): this;
510
- prependListener(event: "error", listener: (err: Error) => void): this;
511
- prependListener(event: "exit", listener: (exitCode: number) => void): this;
512
- prependListener(event: "message", listener: (value: any) => void): this;
513
- prependListener(event: "messageerror", listener: (error: Error) => void): this;
514
- prependListener(event: "online", listener: () => void): this;
515
- prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
516
- prependOnceListener(event: "error", listener: (err: Error) => void): this;
517
- prependOnceListener(event: "exit", listener: (exitCode: number) => void): this;
518
- prependOnceListener(event: "message", listener: (value: any) => void): this;
519
- prependOnceListener(event: "messageerror", listener: (error: Error) => void): this;
520
- prependOnceListener(event: "online", listener: () => void): this;
521
- prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
522
- removeListener(event: "error", listener: (err: Error) => void): this;
523
- removeListener(event: "exit", listener: (exitCode: number) => void): this;
524
- removeListener(event: "message", listener: (value: any) => void): this;
525
- removeListener(event: "messageerror", listener: (error: Error) => void): this;
526
- removeListener(event: "online", listener: () => void): this;
527
- removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
528
- off(event: "error", listener: (err: Error) => void): this;
529
- off(event: "exit", listener: (exitCode: number) => void): this;
530
- off(event: "message", listener: (value: any) => void): this;
531
- off(event: "messageerror", listener: (error: Error) => void): this;
532
- off(event: "online", listener: () => void): this;
533
- off(event: string | symbol, listener: (...args: any[]) => void): this;
534
- }
535
- interface BroadcastChannel extends NodeJS.RefCounted {}
536
- /**
537
- * Instances of `BroadcastChannel` allow asynchronous one-to-many communication
538
- * with all other `BroadcastChannel` instances bound to the same channel name.
539
- *
540
- * ```js
541
- * 'use strict';
542
- *
543
- * import {
544
- * isMainThread,
545
- * BroadcastChannel,
546
- * Worker,
547
- * } from 'node:worker_threads';
548
- *
549
- * const bc = new BroadcastChannel('hello');
550
- *
551
- * if (isMainThread) {
552
- * let c = 0;
553
- * bc.onmessage = (event) => {
554
- * console.log(event.data);
555
- * if (++c === 10) bc.close();
556
- * };
557
- * for (let n = 0; n < 10; n++)
558
- * new Worker(__filename);
559
- * } else {
560
- * bc.postMessage('hello from every worker');
561
- * bc.close();
562
- * }
563
- * ```
564
- * @since v15.4.0
565
- */
566
- class BroadcastChannel {
567
- readonly name: string;
568
324
  /**
569
- * Invoked with a single \`MessageEvent\` argument when a message is received.
570
- * @since v15.4.0
571
- */
572
- onmessage: (message: unknown) => void;
573
- /**
574
- * Invoked with a received message cannot be deserialized.
575
- * @since v15.4.0
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
576
360
  */
577
- onmessageerror: (message: unknown) => void;
578
- constructor(name: string);
361
+ startCpuProfile(): Promise<CPUProfileHandle>;
579
362
  /**
580
- * Closes the `BroadcastChannel` connection.
581
- * @since v15.4.0
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
+ * ```
582
397
  */
583
- close(): void;
398
+ startHeapProfile(): Promise<HeapProfileHandle>;
584
399
  /**
585
- * @since v15.4.0
586
- * @param message Any cloneable JavaScript value.
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
587
409
  */
588
- postMessage(message: unknown): void;
410
+ [Symbol.asyncDispose](): Promise<void>;
589
411
  }
412
+ interface Worker extends InternalEventEmitter<WorkerEventMap> {}
590
413
  /**
591
414
  * Mark an object as not transferable. If `object` occurs in the transfer list of
592
415
  * a `port.postMessage()` call, it is ignored.
@@ -728,46 +551,180 @@ declare module "node:worker_threads" {
728
551
  * for the `key` will be deleted.
729
552
  */
730
553
  function setEnvironmentData(key: Serializable, value?: Serializable): void;
731
-
732
- import {
733
- BroadcastChannel as _BroadcastChannel,
734
- MessageChannel as _MessageChannel,
735
- MessagePort as _MessagePort,
736
- } from 'node:worker_threads';
737
- global {
738
- function structuredClone<T>(
739
- value: T,
740
- options?: { transfer?: Transferable[] },
741
- ): T;
742
- /**
743
- * `BroadcastChannel` class is a global reference for `import { BroadcastChannel } from 'worker_threads'`
744
- * https://nodejs.org/api/globals.html#broadcastchannel
745
- * @since v18.0.0
746
- */
747
- var BroadcastChannel: typeof globalThis extends {
748
- onmessage: any;
749
- BroadcastChannel: infer T;
750
- } ? T
751
- : typeof _BroadcastChannel;
752
- /**
753
- * `MessageChannel` class is a global reference for `import { MessageChannel } from 'worker_threads'`
754
- * https://nodejs.org/api/globals.html#messagechannel
755
- * @since v15.0.0
756
- */
757
- var MessageChannel: typeof globalThis extends {
758
- onmessage: any;
759
- MessageChannel: infer T;
760
- } ? T
761
- : typeof _MessageChannel;
762
- /**
763
- * `MessagePort` class is a global reference for `import { MessagePort } from 'worker_threads'`
764
- * https://nodejs.org/api/globals.html#messageport
765
- * @since v15.0.0
766
- */
767
- var MessagePort: typeof globalThis extends {
768
- onmessage: any;
769
- MessagePort: infer T;
770
- } ? T
771
- : typeof _MessagePort;
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
772
722
  }
723
+ var MessagePort: {
724
+ prototype: MessagePort;
725
+ new(): MessagePort;
726
+ };
727
+ var locks: LockManager;
728
+ export import structuredClone = globalThis.structuredClone;
729
+ // #endregion
773
730
  }