omegon 0.8.4 → 0.9.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.
Files changed (138) hide show
  1. package/extensions/cleave/dispatcher.ts +213 -20
  2. package/extensions/cleave/rpc-child.ts +269 -0
  3. package/extensions/cleave/types.ts +52 -0
  4. package/node_modules/@types/node/README.md +3 -3
  5. package/node_modules/@types/node/assert/strict.d.ts +11 -5
  6. package/node_modules/@types/node/assert.d.ts +173 -50
  7. package/node_modules/@types/node/async_hooks.d.ts +8 -28
  8. package/node_modules/@types/node/buffer.buffer.d.ts +7 -1
  9. package/node_modules/@types/node/buffer.d.ts +168 -44
  10. package/node_modules/@types/node/child_process.d.ts +70 -27
  11. package/node_modules/@types/node/cluster.d.ts +332 -240
  12. package/node_modules/@types/node/compatibility/disposable.d.ts +14 -0
  13. package/node_modules/@types/node/compatibility/index.d.ts +9 -0
  14. package/node_modules/@types/node/compatibility/indexable.d.ts +20 -0
  15. package/node_modules/@types/node/compatibility/iterators.d.ts +0 -1
  16. package/node_modules/@types/node/console.d.ts +350 -49
  17. package/node_modules/@types/node/constants.d.ts +4 -3
  18. package/node_modules/@types/node/crypto.d.ts +1110 -630
  19. package/node_modules/@types/node/dgram.d.ts +51 -15
  20. package/node_modules/@types/node/diagnostics_channel.d.ts +6 -4
  21. package/node_modules/@types/node/dns/promises.d.ts +4 -4
  22. package/node_modules/@types/node/dns.d.ts +133 -132
  23. package/node_modules/@types/node/domain.d.ts +17 -13
  24. package/node_modules/@types/node/events.d.ts +663 -734
  25. package/node_modules/@types/node/fs/promises.d.ts +9 -43
  26. package/node_modules/@types/node/fs.d.ts +411 -628
  27. package/node_modules/@types/node/globals.d.ts +30 -8
  28. package/node_modules/@types/node/globals.typedarray.d.ts +0 -63
  29. package/node_modules/@types/node/http.d.ts +265 -364
  30. package/node_modules/@types/node/http2.d.ts +715 -551
  31. package/node_modules/@types/node/https.d.ts +239 -65
  32. package/node_modules/@types/node/index.d.ts +6 -24
  33. package/node_modules/@types/node/inspector.d.ts +53 -69
  34. package/node_modules/@types/node/inspector.generated.d.ts +410 -759
  35. package/node_modules/@types/node/module.d.ts +186 -52
  36. package/node_modules/@types/node/net.d.ts +194 -70
  37. package/node_modules/@types/node/os.d.ts +11 -12
  38. package/node_modules/@types/node/package.json +3 -13
  39. package/node_modules/@types/node/path.d.ts +133 -120
  40. package/node_modules/@types/node/perf_hooks.d.ts +643 -318
  41. package/node_modules/@types/node/process.d.ts +132 -223
  42. package/node_modules/@types/node/punycode.d.ts +5 -5
  43. package/node_modules/@types/node/querystring.d.ts +4 -4
  44. package/node_modules/@types/node/readline/promises.d.ts +3 -3
  45. package/node_modules/@types/node/readline.d.ts +120 -68
  46. package/node_modules/@types/node/repl.d.ts +100 -87
  47. package/node_modules/@types/node/sea.d.ts +1 -10
  48. package/node_modules/@types/node/sqlite.d.ts +19 -363
  49. package/node_modules/@types/node/stream/consumers.d.ts +10 -10
  50. package/node_modules/@types/node/stream/promises.d.ts +15 -136
  51. package/node_modules/@types/node/stream/web.d.ts +502 -176
  52. package/node_modules/@types/node/stream.d.ts +475 -581
  53. package/node_modules/@types/node/string_decoder.d.ts +4 -4
  54. package/node_modules/@types/node/test.d.ts +196 -308
  55. package/node_modules/@types/node/timers/promises.d.ts +4 -4
  56. package/node_modules/@types/node/timers.d.ts +132 -4
  57. package/node_modules/@types/node/tls.d.ts +226 -110
  58. package/node_modules/@types/node/trace_events.d.ts +9 -9
  59. package/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +7 -1
  60. package/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +0 -2
  61. package/node_modules/@types/node/ts5.6/index.d.ts +6 -26
  62. package/node_modules/@types/node/tty.d.ts +16 -58
  63. package/node_modules/@types/node/url.d.ts +573 -130
  64. package/node_modules/@types/node/util.d.ts +1100 -181
  65. package/node_modules/@types/node/v8.d.ts +8 -76
  66. package/node_modules/@types/node/vm.d.ts +72 -280
  67. package/node_modules/@types/node/wasi.d.ts +4 -25
  68. package/node_modules/@types/node/web-globals/abortcontroller.d.ts +2 -27
  69. package/node_modules/@types/node/web-globals/events.d.ts +0 -9
  70. package/node_modules/@types/node/web-globals/fetch.d.ts +0 -14
  71. package/node_modules/@types/node/web-globals/navigator.d.ts +0 -3
  72. package/node_modules/@types/node/worker_threads.d.ts +335 -268
  73. package/node_modules/@types/node/zlib.d.ts +74 -9
  74. package/node_modules/undici-types/agent.d.ts +12 -13
  75. package/node_modules/undici-types/api.d.ts +26 -26
  76. package/node_modules/undici-types/balanced-pool.d.ts +12 -13
  77. package/node_modules/undici-types/client.d.ts +19 -19
  78. package/node_modules/undici-types/connector.d.ts +2 -2
  79. package/node_modules/undici-types/cookies.d.ts +0 -2
  80. package/node_modules/undici-types/diagnostics-channel.d.ts +10 -18
  81. package/node_modules/undici-types/dispatcher.d.ts +103 -123
  82. package/node_modules/undici-types/env-http-proxy-agent.d.ts +3 -4
  83. package/node_modules/undici-types/errors.d.ts +54 -66
  84. package/node_modules/undici-types/eventsource.d.ts +4 -9
  85. package/node_modules/undici-types/fetch.d.ts +20 -22
  86. package/node_modules/undici-types/file.d.ts +39 -0
  87. package/node_modules/undici-types/filereader.d.ts +54 -0
  88. package/node_modules/undici-types/formdata.d.ts +7 -7
  89. package/node_modules/undici-types/global-dispatcher.d.ts +4 -4
  90. package/node_modules/undici-types/global-origin.d.ts +5 -5
  91. package/node_modules/undici-types/handlers.d.ts +8 -8
  92. package/node_modules/undici-types/header.d.ts +1 -157
  93. package/node_modules/undici-types/index.d.ts +47 -64
  94. package/node_modules/undici-types/interceptors.d.ts +8 -64
  95. package/node_modules/undici-types/mock-agent.d.ts +18 -36
  96. package/node_modules/undici-types/mock-client.d.ts +4 -6
  97. package/node_modules/undici-types/mock-errors.d.ts +3 -3
  98. package/node_modules/undici-types/mock-interceptor.d.ts +20 -21
  99. package/node_modules/undici-types/mock-pool.d.ts +4 -6
  100. package/node_modules/undici-types/package.json +1 -1
  101. package/node_modules/undici-types/patch.d.ts +4 -0
  102. package/node_modules/undici-types/pool-stats.d.ts +8 -8
  103. package/node_modules/undici-types/pool.d.ts +13 -15
  104. package/node_modules/undici-types/proxy-agent.d.ts +4 -5
  105. package/node_modules/undici-types/readable.d.ts +16 -19
  106. package/node_modules/undici-types/retry-agent.d.ts +1 -1
  107. package/node_modules/undici-types/retry-handler.d.ts +10 -19
  108. package/node_modules/undici-types/util.d.ts +3 -3
  109. package/node_modules/undici-types/webidl.d.ts +29 -142
  110. package/node_modules/undici-types/websocket.d.ts +10 -46
  111. package/package.json +2 -1
  112. package/skills/cleave/SKILL.md +62 -2
  113. package/node_modules/@types/node/inspector/promises.d.ts +0 -41
  114. package/node_modules/@types/node/path/posix.d.ts +0 -8
  115. package/node_modules/@types/node/path/win32.d.ts +0 -8
  116. package/node_modules/@types/node/quic.d.ts +0 -910
  117. package/node_modules/@types/node/test/reporters.d.ts +0 -96
  118. package/node_modules/@types/node/ts5.6/compatibility/float16array.d.ts +0 -71
  119. package/node_modules/@types/node/ts5.7/compatibility/float16array.d.ts +0 -72
  120. package/node_modules/@types/node/ts5.7/index.d.ts +0 -117
  121. package/node_modules/@types/node/util/types.d.ts +0 -558
  122. package/node_modules/@types/node/web-globals/blob.d.ts +0 -23
  123. package/node_modules/@types/node/web-globals/console.d.ts +0 -9
  124. package/node_modules/@types/node/web-globals/crypto.d.ts +0 -39
  125. package/node_modules/@types/node/web-globals/encoding.d.ts +0 -11
  126. package/node_modules/@types/node/web-globals/importmeta.d.ts +0 -13
  127. package/node_modules/@types/node/web-globals/messaging.d.ts +0 -23
  128. package/node_modules/@types/node/web-globals/performance.d.ts +0 -45
  129. package/node_modules/@types/node/web-globals/streams.d.ts +0 -115
  130. package/node_modules/@types/node/web-globals/timers.d.ts +0 -44
  131. package/node_modules/@types/node/web-globals/url.d.ts +0 -24
  132. package/node_modules/undici-types/cache-interceptor.d.ts +0 -173
  133. package/node_modules/undici-types/client-stats.d.ts +0 -15
  134. package/node_modules/undici-types/h2c-client.d.ts +0 -73
  135. package/node_modules/undici-types/mock-call-history.d.ts +0 -111
  136. package/node_modules/undici-types/round-robin-pool.d.ts +0 -41
  137. package/node_modules/undici-types/snapshot-agent.d.ts +0 -109
  138. package/node_modules/undici-types/utility.d.ts +0 -7
@@ -33,8 +33,8 @@
33
33
  * workerData: script,
34
34
  * });
35
35
  * worker.on('message', resolve);
36
- * worker.once('error', reject);
37
- * worker.once('exit', (code) => {
36
+ * worker.on('error', reject);
37
+ * worker.on('exit', (code) => {
38
38
  * if (code !== 0)
39
39
  * reject(new Error(`Worker stopped with exit code ${code}`));
40
40
  * });
@@ -52,22 +52,17 @@
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/v25.x/lib/worker_threads.js)
55
+ * @see [source](https://github.com/nodejs/node/blob/v22.x/lib/worker_threads.js)
56
56
  */
57
- declare module "node:worker_threads" {
58
- import {
59
- EventEmitter,
60
- InternalEventEmitter,
61
- InternalEventTargetEventProperties,
62
- NodeEventTarget,
63
- } from "node:events";
57
+ declare module "worker_threads" {
58
+ import { Context } from "node:vm";
59
+ import { EventEmitter, NodeEventTarget } from "node:events";
60
+ import { EventLoopUtilityFunction } from "node:perf_hooks";
64
61
  import { FileHandle } from "node:fs/promises";
65
- import { Performance } from "node:perf_hooks";
66
62
  import { Readable, Writable } from "node:stream";
67
63
  import { ReadableStream, TransformStream, WritableStream } from "node:stream/web";
68
64
  import { URL } from "node:url";
69
- import { CPUProfileHandle, HeapInfo, HeapProfileHandle } from "node:v8";
70
- import { Context } from "node:vm";
65
+ import { HeapInfo } from "node:v8";
71
66
  import { MessageEvent } from "undici-types";
72
67
  const isInternalThread: boolean;
73
68
  const isMainThread: boolean;
@@ -75,12 +70,186 @@ declare module "node:worker_threads" {
75
70
  const resourceLimits: ResourceLimits;
76
71
  const SHARE_ENV: unique symbol;
77
72
  const threadId: number;
78
- const threadName: string | null;
79
73
  const workerData: any;
80
- interface WorkerPerformance extends Pick<Performance, "eventLoopUtilization"> {}
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;
81
104
  /** @deprecated Use `import { Transferable } from "node:worker_threads"` instead. */
82
- // TODO: remove in a future major @types/node version.
83
105
  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 {}
84
253
  interface WorkerOptions {
85
254
  /**
86
255
  * List of arguments which would be stringified and appended to
@@ -131,13 +300,6 @@ declare module "node:worker_threads" {
131
300
  */
132
301
  stackSizeMb?: number | undefined;
133
302
  }
134
- interface WorkerEventMap {
135
- "error": [err: unknown];
136
- "exit": [exitCode: number];
137
- "message": [value: any];
138
- "messageerror": [error: Error];
139
- "online": [];
140
- }
141
303
  /**
142
304
  * The `Worker` class represents an independent JavaScript execution thread.
143
305
  * Most Node.js APIs are available inside of it.
@@ -202,7 +364,7 @@ declare module "node:worker_threads" {
202
364
  * ```
203
365
  * @since v10.5.0
204
366
  */
205
- class Worker implements EventEmitter {
367
+ class Worker extends EventEmitter {
206
368
  /**
207
369
  * If `stdin: true` was passed to the `Worker` constructor, this is a
208
370
  * writable stream. The data written to this stream will be made available in
@@ -229,12 +391,6 @@ declare module "node:worker_threads" {
229
391
  * @since v10.5.0
230
392
  */
231
393
  readonly threadId: number;
232
- /**
233
- * A string identifier for the referenced thread or null if the thread is not running.
234
- * Inside the worker thread, it is available as `require('node:worker_threads').threadName`.
235
- * @since v24.6.0
236
- */
237
- readonly threadName: string | null;
238
394
  /**
239
395
  * Provides the set of JS engine resource constraints for this Worker thread.
240
396
  * If the `resourceLimits` option was passed to the `Worker` constructor,
@@ -285,7 +441,7 @@ declare module "node:worker_threads" {
285
441
  * This method returns a `Promise` that will resolve to an object identical to `process.threadCpuUsage()`,
286
442
  * or reject with an `ERR_WORKER_NOT_RUNNING` error if the worker is no longer running.
287
443
  * This methods allows the statistics to be observed from outside the actual thread.
288
- * @since v24.6.0
444
+ * @since v22.19.0
289
445
  */
290
446
  cpuUsage(prev?: NodeJS.CpuUsage): Promise<NodeJS.CpuUsage>;
291
447
  /**
@@ -302,84 +458,9 @@ declare module "node:worker_threads" {
302
458
  * This method returns a `Promise` that will resolve to an object identical to `v8.getHeapStatistics()`,
303
459
  * or reject with an `ERR_WORKER_NOT_RUNNING` error if the worker is no longer running.
304
460
  * This methods allows the statistics to be observed from outside the actual thread.
305
- * @since v24.0.0
461
+ * @since v22.16.0
306
462
  */
307
463
  getHeapStatistics(): Promise<HeapInfo>;
308
- /**
309
- * Starting a CPU profile then return a Promise that fulfills with an error
310
- * or an `CPUProfileHandle` object. This API supports `await using` syntax.
311
- *
312
- * ```js
313
- * const { Worker } = require('node:worker_threads');
314
- *
315
- * const worker = new Worker(`
316
- * const { parentPort } = require('worker_threads');
317
- * parentPort.on('message', () => {});
318
- * `, { eval: true });
319
- *
320
- * worker.on('online', async () => {
321
- * const handle = await worker.startCpuProfile();
322
- * const profile = await handle.stop();
323
- * console.log(profile);
324
- * worker.terminate();
325
- * });
326
- * ```
327
- *
328
- * `await using` example.
329
- *
330
- * ```js
331
- * const { Worker } = require('node:worker_threads');
332
- *
333
- * const w = new Worker(`
334
- * const { parentPort } = require('node:worker_threads');
335
- * parentPort.on('message', () => {});
336
- * `, { eval: true });
337
- *
338
- * w.on('online', async () => {
339
- * // Stop profile automatically when return and profile will be discarded
340
- * await using handle = await w.startCpuProfile();
341
- * });
342
- * ```
343
- * @since v24.8.0
344
- */
345
- startCpuProfile(): Promise<CPUProfileHandle>;
346
- /**
347
- * Starting a Heap profile then return a Promise that fulfills with an error
348
- * or an `HeapProfileHandle` object. This API supports `await using` syntax.
349
- *
350
- * ```js
351
- * const { Worker } = require('node:worker_threads');
352
- *
353
- * const worker = new Worker(`
354
- * const { parentPort } = require('worker_threads');
355
- * parentPort.on('message', () => {});
356
- * `, { eval: true });
357
- *
358
- * worker.on('online', async () => {
359
- * const handle = await worker.startHeapProfile();
360
- * const profile = await handle.stop();
361
- * console.log(profile);
362
- * worker.terminate();
363
- * });
364
- * ```
365
- *
366
- * `await using` example.
367
- *
368
- * ```js
369
- * const { Worker } = require('node:worker_threads');
370
- *
371
- * const w = new Worker(`
372
- * const { parentPort } = require('node:worker_threads');
373
- * parentPort.on('message', () => {});
374
- * `, { eval: true });
375
- *
376
- * w.on('online', async () => {
377
- * // Stop profile automatically when return and profile will be discarded
378
- * await using handle = await w.startHeapProfile();
379
- * });
380
- * ```
381
- */
382
- startHeapProfile(): Promise<HeapProfileHandle>;
383
464
  /**
384
465
  * Calls `worker.terminate()` when the dispose scope is exited.
385
466
  *
@@ -389,11 +470,113 @@ declare module "node:worker_threads" {
389
470
  * // Worker is automatically terminate when the scope is exited.
390
471
  * }
391
472
  * ```
392
- * @since v24.2.0
473
+ * @since v22.18.0
393
474
  */
394
475
  [Symbol.asyncDispose](): Promise<void>;
476
+ addListener(event: "error", listener: (err: Error) => void): this;
477
+ addListener(event: "exit", listener: (exitCode: number) => void): this;
478
+ addListener(event: "message", listener: (value: any) => void): this;
479
+ addListener(event: "messageerror", listener: (error: Error) => void): this;
480
+ addListener(event: "online", listener: () => void): this;
481
+ addListener(event: string | symbol, listener: (...args: any[]) => void): this;
482
+ emit(event: "error", err: Error): boolean;
483
+ emit(event: "exit", exitCode: number): boolean;
484
+ emit(event: "message", value: any): boolean;
485
+ emit(event: "messageerror", error: Error): boolean;
486
+ emit(event: "online"): boolean;
487
+ emit(event: string | symbol, ...args: any[]): boolean;
488
+ on(event: "error", listener: (err: Error) => void): this;
489
+ on(event: "exit", listener: (exitCode: number) => void): this;
490
+ on(event: "message", listener: (value: any) => void): this;
491
+ on(event: "messageerror", listener: (error: Error) => void): this;
492
+ on(event: "online", listener: () => void): this;
493
+ on(event: string | symbol, listener: (...args: any[]) => void): this;
494
+ once(event: "error", listener: (err: Error) => void): this;
495
+ once(event: "exit", listener: (exitCode: number) => void): this;
496
+ once(event: "message", listener: (value: any) => void): this;
497
+ once(event: "messageerror", listener: (error: Error) => void): this;
498
+ once(event: "online", listener: () => void): this;
499
+ once(event: string | symbol, listener: (...args: any[]) => void): this;
500
+ prependListener(event: "error", listener: (err: Error) => void): this;
501
+ prependListener(event: "exit", listener: (exitCode: number) => void): this;
502
+ prependListener(event: "message", listener: (value: any) => void): this;
503
+ prependListener(event: "messageerror", listener: (error: Error) => void): this;
504
+ prependListener(event: "online", listener: () => void): this;
505
+ prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
506
+ prependOnceListener(event: "error", listener: (err: Error) => void): this;
507
+ prependOnceListener(event: "exit", listener: (exitCode: number) => void): this;
508
+ prependOnceListener(event: "message", listener: (value: any) => void): this;
509
+ prependOnceListener(event: "messageerror", listener: (error: Error) => void): this;
510
+ prependOnceListener(event: "online", listener: () => void): this;
511
+ prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
512
+ removeListener(event: "error", listener: (err: Error) => void): this;
513
+ removeListener(event: "exit", listener: (exitCode: number) => void): this;
514
+ removeListener(event: "message", listener: (value: any) => void): this;
515
+ removeListener(event: "messageerror", listener: (error: Error) => void): this;
516
+ removeListener(event: "online", listener: () => void): this;
517
+ removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
518
+ off(event: "error", listener: (err: Error) => void): this;
519
+ off(event: "exit", listener: (exitCode: number) => void): this;
520
+ off(event: "message", listener: (value: any) => void): this;
521
+ off(event: "messageerror", listener: (error: Error) => void): this;
522
+ off(event: "online", listener: () => void): this;
523
+ off(event: string | symbol, listener: (...args: any[]) => void): this;
524
+ }
525
+ interface BroadcastChannel extends NodeJS.RefCounted {}
526
+ /**
527
+ * Instances of `BroadcastChannel` allow asynchronous one-to-many communication
528
+ * with all other `BroadcastChannel` instances bound to the same channel name.
529
+ *
530
+ * ```js
531
+ * 'use strict';
532
+ *
533
+ * import {
534
+ * isMainThread,
535
+ * BroadcastChannel,
536
+ * Worker,
537
+ * } from 'node:worker_threads';
538
+ *
539
+ * const bc = new BroadcastChannel('hello');
540
+ *
541
+ * if (isMainThread) {
542
+ * let c = 0;
543
+ * bc.onmessage = (event) => {
544
+ * console.log(event.data);
545
+ * if (++c === 10) bc.close();
546
+ * };
547
+ * for (let n = 0; n < 10; n++)
548
+ * new Worker(__filename);
549
+ * } else {
550
+ * bc.postMessage('hello from every worker');
551
+ * bc.close();
552
+ * }
553
+ * ```
554
+ * @since v15.4.0
555
+ */
556
+ class BroadcastChannel extends EventTarget {
557
+ readonly name: string;
558
+ /**
559
+ * Invoked with a single \`MessageEvent\` argument when a message is received.
560
+ * @since v15.4.0
561
+ */
562
+ onmessage: (message: MessageEvent) => void;
563
+ /**
564
+ * Invoked with a received message cannot be deserialized.
565
+ * @since v15.4.0
566
+ */
567
+ onmessageerror: (message: MessageEvent) => void;
568
+ constructor(name: string);
569
+ /**
570
+ * Closes the `BroadcastChannel` connection.
571
+ * @since v15.4.0
572
+ */
573
+ close(): void;
574
+ /**
575
+ * @since v15.4.0
576
+ * @param message Any cloneable JavaScript value.
577
+ */
578
+ postMessage(message: unknown): void;
395
579
  }
396
- interface Worker extends InternalEventEmitter<WorkerEventMap> {}
397
580
  /**
398
581
  * Mark an object as not transferable. If `object` occurs in the transfer list of
399
582
  * a `port.postMessage()` call, it is ignored.
@@ -553,165 +736,49 @@ declare module "node:worker_threads" {
553
736
  transferList: readonly Transferable[],
554
737
  timeout?: number,
555
738
  ): Promise<void>;
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;
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
739
+
740
+ import {
741
+ BroadcastChannel as _BroadcastChannel,
742
+ MessageChannel as _MessageChannel,
743
+ MessagePort as _MessagePort,
744
+ } from "worker_threads";
745
+ global {
746
+ function structuredClone<T>(
747
+ value: T,
748
+ options?: { transfer?: Transferable[] },
749
+ ): T;
750
+ /**
751
+ * `BroadcastChannel` class is a global reference for `import { BroadcastChannel } from 'worker_threads'`
752
+ * https://nodejs.org/api/globals.html#broadcastchannel
753
+ * @since v18.0.0
754
+ */
755
+ var BroadcastChannel: typeof globalThis extends {
756
+ onmessage: any;
757
+ BroadcastChannel: infer T;
758
+ } ? T
759
+ : typeof _BroadcastChannel;
760
+ /**
761
+ * `MessageChannel` class is a global reference for `import { MessageChannel } from 'worker_threads'`
762
+ * https://nodejs.org/api/globals.html#messagechannel
763
+ * @since v15.0.0
764
+ */
765
+ var MessageChannel: typeof globalThis extends {
766
+ onmessage: any;
767
+ MessageChannel: infer T;
768
+ } ? T
769
+ : typeof _MessageChannel;
770
+ /**
771
+ * `MessagePort` class is a global reference for `import { MessagePort } from 'worker_threads'`
772
+ * https://nodejs.org/api/globals.html#messageport
773
+ * @since v15.0.0
774
+ */
775
+ var MessagePort: typeof globalThis extends {
776
+ onmessage: any;
777
+ MessagePort: infer T;
778
+ } ? T
779
+ : typeof _MessagePort;
706
780
  }
707
- var MessagePort: {
708
- prototype: MessagePort;
709
- new(): MessagePort;
710
- };
711
- var locks: LockManager;
712
- export import structuredClone = globalThis.structuredClone;
713
- // #endregion
714
781
  }
715
- declare module "worker_threads" {
716
- export * from "node:worker_threads";
782
+ declare module "node:worker_threads" {
783
+ export * from "worker_threads";
717
784
  }