@aligent/cdk-prerender-proxy 0.2.4 → 0.2.5-beta

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