alicezetion 1.9.6 → 1.9.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (292) hide show
  1. package/.cache/replit/modules/nodejs-20.res +1 -0
  2. package/.cache/replit/modules/replit.res +1 -0
  3. package/.cache/typescript/5.4/node_modules/.package-lock.json +137 -0
  4. package/.cache/typescript/5.4/node_modules/@types/bluebird/LICENSE +21 -0
  5. package/.cache/typescript/5.4/node_modules/@types/bluebird/README.md +15 -0
  6. package/.cache/typescript/5.4/node_modules/@types/bluebird/index.d.ts +1365 -0
  7. package/.cache/typescript/5.4/node_modules/@types/bluebird/package.json +25 -0
  8. package/.cache/typescript/5.4/node_modules/@types/caseless/LICENSE +21 -0
  9. package/.cache/typescript/5.4/node_modules/@types/caseless/README.md +48 -0
  10. package/.cache/typescript/5.4/node_modules/@types/caseless/index.d.ts +29 -0
  11. package/.cache/typescript/5.4/node_modules/@types/caseless/package.json +35 -0
  12. package/.cache/typescript/5.4/node_modules/@types/cheerio/LICENSE +21 -0
  13. package/.cache/typescript/5.4/node_modules/@types/cheerio/README.md +15 -0
  14. package/.cache/typescript/5.4/node_modules/@types/cheerio/index.d.ts +318 -0
  15. package/.cache/typescript/5.4/node_modules/@types/cheerio/package.json +71 -0
  16. package/.cache/typescript/5.4/node_modules/@types/node/LICENSE +21 -0
  17. package/.cache/typescript/5.4/node_modules/@types/node/README.md +15 -0
  18. package/.cache/typescript/5.4/node_modules/@types/node/assert/strict.d.ts +8 -0
  19. package/.cache/typescript/5.4/node_modules/@types/node/assert.d.ts +1040 -0
  20. package/.cache/typescript/5.4/node_modules/@types/node/async_hooks.d.ts +541 -0
  21. package/.cache/typescript/5.4/node_modules/@types/node/buffer.d.ts +2363 -0
  22. package/.cache/typescript/5.4/node_modules/@types/node/child_process.d.ts +1544 -0
  23. package/.cache/typescript/5.4/node_modules/@types/node/cluster.d.ts +578 -0
  24. package/.cache/typescript/5.4/node_modules/@types/node/console.d.ts +452 -0
  25. package/.cache/typescript/5.4/node_modules/@types/node/constants.d.ts +19 -0
  26. package/.cache/typescript/5.4/node_modules/@types/node/crypto.d.ts +4523 -0
  27. package/.cache/typescript/5.4/node_modules/@types/node/dgram.d.ts +596 -0
  28. package/.cache/typescript/5.4/node_modules/@types/node/diagnostics_channel.d.ts +554 -0
  29. package/.cache/typescript/5.4/node_modules/@types/node/dns/promises.d.ts +476 -0
  30. package/.cache/typescript/5.4/node_modules/@types/node/dns.d.ts +864 -0
  31. package/.cache/typescript/5.4/node_modules/@types/node/dom-events.d.ts +124 -0
  32. package/.cache/typescript/5.4/node_modules/@types/node/domain.d.ts +170 -0
  33. package/.cache/typescript/5.4/node_modules/@types/node/events.d.ts +931 -0
  34. package/.cache/typescript/5.4/node_modules/@types/node/fs/promises.d.ts +1245 -0
  35. package/.cache/typescript/5.4/node_modules/@types/node/fs.d.ts +4317 -0
  36. package/.cache/typescript/5.4/node_modules/@types/node/globals.d.ts +412 -0
  37. package/.cache/typescript/5.4/node_modules/@types/node/globals.global.d.ts +1 -0
  38. package/.cache/typescript/5.4/node_modules/@types/node/http.d.ts +1908 -0
  39. package/.cache/typescript/5.4/node_modules/@types/node/http2.d.ts +2418 -0
  40. package/.cache/typescript/5.4/node_modules/@types/node/https.d.ts +550 -0
  41. package/.cache/typescript/5.4/node_modules/@types/node/index.d.ts +89 -0
  42. package/.cache/typescript/5.4/node_modules/@types/node/inspector.d.ts +2746 -0
  43. package/.cache/typescript/5.4/node_modules/@types/node/module.d.ts +315 -0
  44. package/.cache/typescript/5.4/node_modules/@types/node/net.d.ts +999 -0
  45. package/.cache/typescript/5.4/node_modules/@types/node/os.d.ts +495 -0
  46. package/.cache/typescript/5.4/node_modules/@types/node/package.json +217 -0
  47. package/.cache/typescript/5.4/node_modules/@types/node/path.d.ts +191 -0
  48. package/.cache/typescript/5.4/node_modules/@types/node/perf_hooks.d.ts +905 -0
  49. package/.cache/typescript/5.4/node_modules/@types/node/process.d.ts +1754 -0
  50. package/.cache/typescript/5.4/node_modules/@types/node/punycode.d.ts +117 -0
  51. package/.cache/typescript/5.4/node_modules/@types/node/querystring.d.ts +153 -0
  52. package/.cache/typescript/5.4/node_modules/@types/node/readline/promises.d.ts +150 -0
  53. package/.cache/typescript/5.4/node_modules/@types/node/readline.d.ts +540 -0
  54. package/.cache/typescript/5.4/node_modules/@types/node/repl.d.ts +430 -0
  55. package/.cache/typescript/5.4/node_modules/@types/node/sea.d.ts +153 -0
  56. package/.cache/typescript/5.4/node_modules/@types/node/stream/consumers.d.ts +12 -0
  57. package/.cache/typescript/5.4/node_modules/@types/node/stream/promises.d.ts +83 -0
  58. package/.cache/typescript/5.4/node_modules/@types/node/stream/web.d.ts +367 -0
  59. package/.cache/typescript/5.4/node_modules/@types/node/stream.d.ts +1707 -0
  60. package/.cache/typescript/5.4/node_modules/@types/node/string_decoder.d.ts +67 -0
  61. package/.cache/typescript/5.4/node_modules/@types/node/test.d.ts +1718 -0
  62. package/.cache/typescript/5.4/node_modules/@types/node/timers/promises.d.ts +97 -0
  63. package/.cache/typescript/5.4/node_modules/@types/node/timers.d.ts +240 -0
  64. package/.cache/typescript/5.4/node_modules/@types/node/tls.d.ts +1217 -0
  65. package/.cache/typescript/5.4/node_modules/@types/node/trace_events.d.ts +197 -0
  66. package/.cache/typescript/5.4/node_modules/@types/node/tty.d.ts +208 -0
  67. package/.cache/typescript/5.4/node_modules/@types/node/url.d.ts +952 -0
  68. package/.cache/typescript/5.4/node_modules/@types/node/util.d.ts +2292 -0
  69. package/.cache/typescript/5.4/node_modules/@types/node/v8.d.ts +808 -0
  70. package/.cache/typescript/5.4/node_modules/@types/node/vm.d.ts +924 -0
  71. package/.cache/typescript/5.4/node_modules/@types/node/wasi.d.ts +181 -0
  72. package/.cache/typescript/5.4/node_modules/@types/node/worker_threads.d.ts +694 -0
  73. package/.cache/typescript/5.4/node_modules/@types/node/zlib.d.ts +530 -0
  74. package/.cache/typescript/5.4/node_modules/@types/npmlog/LICENSE +21 -0
  75. package/.cache/typescript/5.4/node_modules/@types/npmlog/README.md +15 -0
  76. package/.cache/typescript/5.4/node_modules/@types/npmlog/index.d.ts +84 -0
  77. package/.cache/typescript/5.4/node_modules/@types/npmlog/package.json +32 -0
  78. package/.cache/typescript/5.4/node_modules/@types/request/LICENSE +21 -0
  79. package/.cache/typescript/5.4/node_modules/@types/request/README.md +15 -0
  80. package/.cache/typescript/5.4/node_modules/@types/request/index.d.ts +395 -0
  81. package/.cache/typescript/5.4/node_modules/@types/request/package.json +70 -0
  82. package/.cache/typescript/5.4/node_modules/@types/tough-cookie/LICENSE +21 -0
  83. package/.cache/typescript/5.4/node_modules/@types/tough-cookie/README.md +15 -0
  84. package/.cache/typescript/5.4/node_modules/@types/tough-cookie/index.d.ts +321 -0
  85. package/.cache/typescript/5.4/node_modules/@types/tough-cookie/package.json +35 -0
  86. package/.cache/typescript/5.4/node_modules/asynckit/LICENSE +21 -0
  87. package/.cache/typescript/5.4/node_modules/asynckit/README.md +233 -0
  88. package/.cache/typescript/5.4/node_modules/asynckit/bench.js +76 -0
  89. package/.cache/typescript/5.4/node_modules/asynckit/index.js +6 -0
  90. package/.cache/typescript/5.4/node_modules/asynckit/lib/abort.js +29 -0
  91. package/.cache/typescript/5.4/node_modules/asynckit/lib/async.js +34 -0
  92. package/.cache/typescript/5.4/node_modules/asynckit/lib/defer.js +26 -0
  93. package/.cache/typescript/5.4/node_modules/asynckit/lib/iterate.js +75 -0
  94. package/.cache/typescript/5.4/node_modules/asynckit/lib/readable_asynckit.js +91 -0
  95. package/.cache/typescript/5.4/node_modules/asynckit/lib/readable_parallel.js +25 -0
  96. package/.cache/typescript/5.4/node_modules/asynckit/lib/readable_serial.js +25 -0
  97. package/.cache/typescript/5.4/node_modules/asynckit/lib/readable_serial_ordered.js +29 -0
  98. package/.cache/typescript/5.4/node_modules/asynckit/lib/state.js +37 -0
  99. package/.cache/typescript/5.4/node_modules/asynckit/lib/streamify.js +141 -0
  100. package/.cache/typescript/5.4/node_modules/asynckit/lib/terminator.js +29 -0
  101. package/.cache/typescript/5.4/node_modules/asynckit/package.json +63 -0
  102. package/.cache/typescript/5.4/node_modules/asynckit/parallel.js +43 -0
  103. package/.cache/typescript/5.4/node_modules/asynckit/serial.js +17 -0
  104. package/.cache/typescript/5.4/node_modules/asynckit/serialOrdered.js +75 -0
  105. package/.cache/typescript/5.4/node_modules/asynckit/stream.js +21 -0
  106. package/.cache/typescript/5.4/node_modules/combined-stream/License +19 -0
  107. package/.cache/typescript/5.4/node_modules/combined-stream/Readme.md +138 -0
  108. package/.cache/typescript/5.4/node_modules/combined-stream/lib/combined_stream.js +208 -0
  109. package/.cache/typescript/5.4/node_modules/combined-stream/package.json +25 -0
  110. package/.cache/typescript/5.4/node_modules/combined-stream/yarn.lock +17 -0
  111. package/.cache/typescript/5.4/node_modules/delayed-stream/License +19 -0
  112. package/.cache/typescript/5.4/node_modules/delayed-stream/Makefile +7 -0
  113. package/.cache/typescript/5.4/node_modules/delayed-stream/Readme.md +141 -0
  114. package/.cache/typescript/5.4/node_modules/delayed-stream/lib/delayed_stream.js +107 -0
  115. package/.cache/typescript/5.4/node_modules/delayed-stream/package.json +27 -0
  116. package/.cache/typescript/5.4/node_modules/form-data/License +19 -0
  117. package/.cache/typescript/5.4/node_modules/form-data/README.md +350 -0
  118. package/.cache/typescript/5.4/node_modules/form-data/README.md.bak +350 -0
  119. package/.cache/typescript/5.4/node_modules/form-data/index.d.ts +51 -0
  120. package/.cache/typescript/5.4/node_modules/form-data/lib/browser.js +2 -0
  121. package/.cache/typescript/5.4/node_modules/form-data/lib/form_data.js +483 -0
  122. package/.cache/typescript/5.4/node_modules/form-data/lib/populate.js +10 -0
  123. package/.cache/typescript/5.4/node_modules/form-data/package.json +68 -0
  124. package/.cache/typescript/5.4/node_modules/mime-db/HISTORY.md +507 -0
  125. package/.cache/typescript/5.4/node_modules/mime-db/LICENSE +23 -0
  126. package/.cache/typescript/5.4/node_modules/mime-db/README.md +100 -0
  127. package/.cache/typescript/5.4/node_modules/mime-db/db.json +8519 -0
  128. package/.cache/typescript/5.4/node_modules/mime-db/index.js +12 -0
  129. package/.cache/typescript/5.4/node_modules/mime-db/package.json +60 -0
  130. package/.cache/typescript/5.4/node_modules/mime-types/HISTORY.md +397 -0
  131. package/.cache/typescript/5.4/node_modules/mime-types/LICENSE +23 -0
  132. package/.cache/typescript/5.4/node_modules/mime-types/README.md +113 -0
  133. package/.cache/typescript/5.4/node_modules/mime-types/index.js +188 -0
  134. package/.cache/typescript/5.4/node_modules/mime-types/package.json +44 -0
  135. package/.cache/typescript/5.4/node_modules/types-registry/README.md +2 -0
  136. package/.cache/typescript/5.4/node_modules/types-registry/index.json +1 -0
  137. package/.cache/typescript/5.4/node_modules/types-registry/package.json +20 -0
  138. package/.cache/typescript/5.4/node_modules/undici-types/README.md +6 -0
  139. package/.cache/typescript/5.4/node_modules/undici-types/agent.d.ts +31 -0
  140. package/.cache/typescript/5.4/node_modules/undici-types/api.d.ts +43 -0
  141. package/.cache/typescript/5.4/node_modules/undici-types/balanced-pool.d.ts +18 -0
  142. package/.cache/typescript/5.4/node_modules/undici-types/cache.d.ts +36 -0
  143. package/.cache/typescript/5.4/node_modules/undici-types/client.d.ts +97 -0
  144. package/.cache/typescript/5.4/node_modules/undici-types/connector.d.ts +34 -0
  145. package/.cache/typescript/5.4/node_modules/undici-types/content-type.d.ts +21 -0
  146. package/.cache/typescript/5.4/node_modules/undici-types/cookies.d.ts +28 -0
  147. package/.cache/typescript/5.4/node_modules/undici-types/diagnostics-channel.d.ts +67 -0
  148. package/.cache/typescript/5.4/node_modules/undici-types/dispatcher.d.ts +241 -0
  149. package/.cache/typescript/5.4/node_modules/undici-types/errors.d.ts +128 -0
  150. package/.cache/typescript/5.4/node_modules/undici-types/fetch.d.ts +209 -0
  151. package/.cache/typescript/5.4/node_modules/undici-types/file.d.ts +39 -0
  152. package/.cache/typescript/5.4/node_modules/undici-types/filereader.d.ts +54 -0
  153. package/.cache/typescript/5.4/node_modules/undici-types/formdata.d.ts +108 -0
  154. package/.cache/typescript/5.4/node_modules/undici-types/global-dispatcher.d.ts +9 -0
  155. package/.cache/typescript/5.4/node_modules/undici-types/global-origin.d.ts +7 -0
  156. package/.cache/typescript/5.4/node_modules/undici-types/handlers.d.ts +9 -0
  157. package/.cache/typescript/5.4/node_modules/undici-types/header.d.ts +4 -0
  158. package/.cache/typescript/5.4/node_modules/undici-types/index.d.ts +63 -0
  159. package/.cache/typescript/5.4/node_modules/undici-types/interceptors.d.ts +5 -0
  160. package/.cache/typescript/5.4/node_modules/undici-types/mock-agent.d.ts +50 -0
  161. package/.cache/typescript/5.4/node_modules/undici-types/mock-client.d.ts +25 -0
  162. package/.cache/typescript/5.4/node_modules/undici-types/mock-errors.d.ts +12 -0
  163. package/.cache/typescript/5.4/node_modules/undici-types/mock-interceptor.d.ts +93 -0
  164. package/.cache/typescript/5.4/node_modules/undici-types/mock-pool.d.ts +25 -0
  165. package/.cache/typescript/5.4/node_modules/undici-types/package.json +55 -0
  166. package/.cache/typescript/5.4/node_modules/undici-types/patch.d.ts +71 -0
  167. package/.cache/typescript/5.4/node_modules/undici-types/pool-stats.d.ts +19 -0
  168. package/.cache/typescript/5.4/node_modules/undici-types/pool.d.ts +28 -0
  169. package/.cache/typescript/5.4/node_modules/undici-types/proxy-agent.d.ts +30 -0
  170. package/.cache/typescript/5.4/node_modules/undici-types/readable.d.ts +61 -0
  171. package/.cache/typescript/5.4/node_modules/undici-types/webidl.d.ts +220 -0
  172. package/.cache/typescript/5.4/node_modules/undici-types/websocket.d.ts +131 -0
  173. package/.cache/typescript/5.4/package-lock.json +149 -0
  174. package/.cache/typescript/5.4/package.json +1 -0
  175. package/index.js +290 -70
  176. package/leiamnash/addExternalModule.js +15 -0
  177. package/leiamnash/addUserToGroup.js +77 -0
  178. package/leiamnash/changeAdminStatus.js +47 -0
  179. package/leiamnash/changeArchivedStatus.js +41 -0
  180. package/{src → leiamnash}/changeAvatar.js +3 -2
  181. package/leiamnash/changeBio.js +64 -0
  182. package/leiamnash/changeBlockedStatus.js +36 -0
  183. package/leiamnash/changeGroupImage.js +105 -0
  184. package/leiamnash/changeNickname.js +43 -0
  185. package/leiamnash/changeThreadColor.js +61 -0
  186. package/leiamnash/changeThreadEmoji.js +41 -0
  187. package/{src → leiamnash}/chat.js +4 -29
  188. package/leiamnash/createNewGroup.js +70 -0
  189. package/leiamnash/createPoll.js +59 -0
  190. package/leiamnash/deleteMessage.js +44 -0
  191. package/leiamnash/deleteThread.js +42 -0
  192. package/leiamnash/editMessage.js +62 -0
  193. package/leiamnash/forwardAttachment.js +47 -0
  194. package/leiamnash/forwardMessage.js +0 -0
  195. package/leiamnash/getCurrentUserID.js +7 -0
  196. package/leiamnash/getEmojiUrl.js +27 -0
  197. package/leiamnash/getFriendsList.js +73 -0
  198. package/leiamnash/getInfoVideo.js +134 -0
  199. package/leiamnash/getThreadHistory.js +537 -0
  200. package/leiamnash/getThreadHistoryDeprecated.js +71 -0
  201. package/leiamnash/getThreadInfo.js +171 -0
  202. package/leiamnash/getThreadInfoDeprecated.js +56 -0
  203. package/leiamnash/getThreadList.js +213 -0
  204. package/leiamnash/getThreadListDeprecated.js +46 -0
  205. package/leiamnash/getThreadPictures.js +59 -0
  206. package/leiamnash/getUserID.js +61 -0
  207. package/leiamnash/getUserInfo.js +66 -0
  208. package/leiamnash/handleFriendRequest.js +46 -0
  209. package/leiamnash/handleMessageRequest.js +47 -0
  210. package/leiamnash/httpGet.js +47 -0
  211. package/leiamnash/httpPost.js +47 -0
  212. package/leiamnash/httpPostFormData.js +42 -0
  213. package/leiamnash/listenMqtt.js +843 -0
  214. package/leiamnash/logout.js +68 -0
  215. package/leiamnash/markAsDelivered.js +47 -0
  216. package/leiamnash/markAsRead.js +70 -0
  217. package/leiamnash/markAsReadAll.js +40 -0
  218. package/leiamnash/markAsSeen.js +48 -0
  219. package/leiamnash/muteThread.js +45 -0
  220. package/leiamnash/pinMessage.js +58 -0
  221. package/leiamnash/react.js +109 -0
  222. package/{src → leiamnash}/refreshFb_dtsg.js +1 -1
  223. package/leiamnash/removeUserFromGroup.js +45 -0
  224. package/leiamnash/resolvePhotoUrl.js +36 -0
  225. package/leiamnash/searchForThread.js +42 -0
  226. package/leiamnash/seen.js +40 -0
  227. package/leiamnash/sendMessage.js +315 -0
  228. package/leiamnash/sendTypingIndicator.js +70 -0
  229. package/leiamnash/setMessageReaction.js +103 -0
  230. package/leiamnash/setPostReaction.js +63 -0
  231. package/leiamnash/setTitle.js +70 -0
  232. package/leiamnash/threadColors.js +41 -0
  233. package/leiamnash/token.js +112 -0
  234. package/leiamnash/unfriend.js +42 -0
  235. package/leiamnash/unsendMessage.js +39 -0
  236. package/{src → leiamnash}/uploadAttachment.js +2 -1
  237. package/package.json +3 -2
  238. package/utils.js +1345 -1382
  239. package/.cache/replit/modules/nodejs-20:v28-20240213-3f08513.res +0 -1
  240. package/.cache/replit/modules/replit:v5-20240209-9e3a339.res +0 -1
  241. package/.replit +0 -1
  242. package/src/addExternalModule.js +0 -19
  243. package/src/addUserToGroup.js +0 -113
  244. package/src/changeAdminStatus.js +0 -79
  245. package/src/changeArchivedStatus.js +0 -55
  246. package/src/changeBio.js +0 -77
  247. package/src/changeBlockedStatus.js +0 -47
  248. package/src/changeGroupImage.js +0 -132
  249. package/src/changeNickname.js +0 -59
  250. package/src/changeThreadColor.js +0 -65
  251. package/src/changeThreadEmoji.js +0 -55
  252. package/src/createNewGroup.js +0 -86
  253. package/src/createPoll.js +0 -71
  254. package/src/deleteMessage.js +0 -56
  255. package/src/deleteThread.js +0 -56
  256. package/src/edit.js +0 -66
  257. package/src/forwardAttachment.js +0 -60
  258. package/src/getCurrentUserID.js +0 -7
  259. package/src/getEmojiUrl.js +0 -29
  260. package/src/getFriendsList.js +0 -83
  261. package/src/getThreadHistory.js +0 -666
  262. package/src/getThreadInfo.js +0 -232
  263. package/src/getThreadList.js +0 -241
  264. package/src/getThreadPictures.js +0 -79
  265. package/src/getUserID.js +0 -66
  266. package/src/getUserInfo.js +0 -74
  267. package/src/handleFriendRequest.js +0 -61
  268. package/src/handleMessageRequest.js +0 -65
  269. package/src/httpGet.js +0 -57
  270. package/src/httpPost.js +0 -57
  271. package/src/httpPostFormData.js +0 -63
  272. package/src/listenMqtt.js +0 -854
  273. package/src/logout.js +0 -75
  274. package/src/markAsDelivered.js +0 -58
  275. package/src/markAsRead.js +0 -80
  276. package/src/markAsReadAll.js +0 -50
  277. package/src/markAsSeen.js +0 -59
  278. package/src/muteThread.js +0 -52
  279. package/src/react.js +0 -121
  280. package/src/removeUserFromGroup.js +0 -79
  281. package/src/resolvePhotoUrl.js +0 -45
  282. package/src/searchForThread.js +0 -53
  283. package/src/seen.js +0 -50
  284. package/src/sendMessage.js +0 -477
  285. package/src/sendTypingIndicator.js +0 -103
  286. package/src/setMessageReaction.js +0 -121
  287. package/src/setPostReaction.js +0 -109
  288. package/src/setTitle.js +0 -86
  289. package/src/threadColors.js +0 -131
  290. package/src/unfriend.js +0 -52
  291. package/src/unsendMessage.js +0 -49
  292. /package/{src → leiamnash}/getMessage.js +0 -0
@@ -0,0 +1,694 @@
1
+ /**
2
+ * The `node:worker_threads` module enables the use of threads that execute
3
+ * JavaScript in parallel. To access it:
4
+ *
5
+ * ```js
6
+ * const worker = require('node: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('node: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/v20.13.1/lib/worker_threads.js)
53
+ */
54
+ declare module "worker_threads" {
55
+ import { Blob } from "node:buffer";
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";
63
+ const isMainThread: boolean;
64
+ const parentPort: null | MessagePort;
65
+ const resourceLimits: ResourceLimits;
66
+ const SHARE_ENV: unique symbol;
67
+ const threadId: number;
68
+ const workerData: any;
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('node: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
+ */
84
+ class MessageChannel {
85
+ readonly port1: MessagePort;
86
+ readonly port2: MessagePort;
87
+ }
88
+ interface WorkerPerformance {
89
+ eventLoopUtilization: EventLoopUtilityFunction;
90
+ }
91
+ type TransferListItem = ArrayBuffer | MessagePort | FileHandle | X509Certificate | Blob;
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
+ */
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
+ */
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('node: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('node: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 node:v8 module`.
174
+ * @since v10.5.0
175
+ */
176
+ postMessage(value: any, transferList?: readonly 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
+ */
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
+ */
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
+ */
207
+ start(): void;
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;
211
+ addListener(event: string | symbol, listener: (...args: any[]) => void): this;
212
+ emit(event: "close"): boolean;
213
+ emit(event: "message", value: any): boolean;
214
+ emit(event: "messageerror", error: Error): boolean;
215
+ emit(event: string | symbol, ...args: any[]): boolean;
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;
219
+ on(event: string | symbol, listener: (...args: any[]) => 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;
223
+ once(event: string | symbol, listener: (...args: any[]) => 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;
227
+ prependListener(event: string | symbol, listener: (...args: any[]) => 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;
231
+ prependOnceListener(event: string | symbol, listener: (...args: any[]) => 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;
235
+ removeListener(event: string | symbol, listener: (...args: any[]) => 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;
239
+ off(event: string | symbol, listener: (...args: any[]) => void): this;
240
+ addEventListener: EventTarget["addEventListener"];
241
+ dispatchEvent: EventTarget["dispatchEvent"];
242
+ removeEventListener: EventTarget["removeEventListener"];
243
+ }
244
+ interface WorkerOptions {
245
+ /**
246
+ * List of arguments which would be stringified and appended to
247
+ * `process.argv` in the worker. This is mostly similar to the `workerData`
248
+ * but the values will be available on the global `process.argv` as if they
249
+ * were passed as CLI options to the script.
250
+ */
251
+ argv?: any[] | undefined;
252
+ env?: NodeJS.Dict<string> | typeof SHARE_ENV | undefined;
253
+ eval?: boolean | undefined;
254
+ workerData?: any;
255
+ stdin?: boolean | undefined;
256
+ stdout?: boolean | undefined;
257
+ stderr?: boolean | undefined;
258
+ execArgv?: string[] | undefined;
259
+ resourceLimits?: ResourceLimits | undefined;
260
+ /**
261
+ * Additional data to send in the first worker message.
262
+ */
263
+ transferList?: TransferListItem[] | undefined;
264
+ /**
265
+ * @default true
266
+ */
267
+ trackUnmanagedFds?: boolean | undefined;
268
+ /**
269
+ * An optional `name` to be appended to the worker title
270
+ * for debuggin/identification purposes, making the final title as
271
+ * `[worker ${id}] ${name}`.
272
+ */
273
+ name?: string | undefined;
274
+ }
275
+ interface ResourceLimits {
276
+ /**
277
+ * The maximum size of a heap space for recently created objects.
278
+ */
279
+ maxYoungGenerationSizeMb?: number | undefined;
280
+ /**
281
+ * The maximum size of the main heap in MB.
282
+ */
283
+ maxOldGenerationSizeMb?: number | undefined;
284
+ /**
285
+ * The size of a pre-allocated memory range used for generated code.
286
+ */
287
+ codeRangeSizeMb?: number | undefined;
288
+ /**
289
+ * The default maximum stack size for the thread. Small values may lead to unusable Worker instances.
290
+ * @default 4
291
+ */
292
+ stackSizeMb?: number | undefined;
293
+ }
294
+ /**
295
+ * The `Worker` class represents an independent JavaScript execution thread.
296
+ * Most Node.js APIs are available inside of it.
297
+ *
298
+ * Notable differences inside a Worker environment are:
299
+ *
300
+ * * The `process.stdin`, `process.stdout`, and `process.stderr` streams may be redirected by the parent thread.
301
+ * * The `require('node:worker_threads').isMainThread` property is set to `false`.
302
+ * * The `require('node:worker_threads').parentPort` message port is available.
303
+ * * `process.exit()` does not stop the whole program, just the single thread,
304
+ * and `process.abort()` is not available.
305
+ * * `process.chdir()` and `process` methods that set group or user ids
306
+ * are not available.
307
+ * * `process.env` is a copy of the parent thread's environment variables,
308
+ * unless otherwise specified. Changes to one copy are not visible in other
309
+ * threads, and are not visible to native add-ons (unless `worker.SHARE_ENV` is passed as the `env` option to the `Worker` constructor). On Windows, unlike the main thread, a copy of the
310
+ * environment variables operates in a case-sensitive manner.
311
+ * * `process.title` cannot be modified.
312
+ * * Signals are not delivered through `process.on('...')`.
313
+ * * Execution may stop at any point as a result of `worker.terminate()` being invoked.
314
+ * * IPC channels from parent processes are not accessible.
315
+ * * The `trace_events` module is not supported.
316
+ * * Native add-ons can only be loaded from multiple threads if they fulfill `certain conditions`.
317
+ *
318
+ * Creating `Worker` instances inside of other `Worker`s is possible.
319
+ *
320
+ * Like [Web Workers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) and the `node:cluster module`, two-way communication
321
+ * can be achieved through inter-thread message passing. Internally, a `Worker` has
322
+ * a built-in pair of `MessagePort` s that are already associated with each
323
+ * other when the `Worker` is created. While the `MessagePort` object on the parent
324
+ * side is not directly exposed, its functionalities are exposed through `worker.postMessage()` and the `worker.on('message')` event
325
+ * on the `Worker` object for the parent thread.
326
+ *
327
+ * To create custom messaging channels (which is encouraged over using the default
328
+ * global channel because it facilitates separation of concerns), users can create
329
+ * a `MessageChannel` object on either thread and pass one of the`MessagePort`s on that `MessageChannel` to the other thread through a
330
+ * pre-existing channel, such as the global one.
331
+ *
332
+ * See `port.postMessage()` for more information on how messages are passed,
333
+ * and what kind of JavaScript values can be successfully transported through
334
+ * the thread barrier.
335
+ *
336
+ * ```js
337
+ * const assert = require('node:assert');
338
+ * const {
339
+ * Worker, MessageChannel, MessagePort, isMainThread, parentPort,
340
+ * } = require('node:worker_threads');
341
+ * if (isMainThread) {
342
+ * const worker = new Worker(__filename);
343
+ * const subChannel = new MessageChannel();
344
+ * worker.postMessage({ hereIsYourPort: subChannel.port1 }, [subChannel.port1]);
345
+ * subChannel.port2.on('message', (value) => {
346
+ * console.log('received:', value);
347
+ * });
348
+ * } else {
349
+ * parentPort.once('message', (value) => {
350
+ * assert(value.hereIsYourPort instanceof MessagePort);
351
+ * value.hereIsYourPort.postMessage('the worker is sending this');
352
+ * value.hereIsYourPort.close();
353
+ * });
354
+ * }
355
+ * ```
356
+ * @since v10.5.0
357
+ */
358
+ class Worker extends EventEmitter {
359
+ /**
360
+ * If `stdin: true` was passed to the `Worker` constructor, this is a
361
+ * writable stream. The data written to this stream will be made available in
362
+ * the worker thread as `process.stdin`.
363
+ * @since v10.5.0
364
+ */
365
+ readonly stdin: Writable | null;
366
+ /**
367
+ * 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
368
+ * parent thread's `process.stdout` stream.
369
+ * @since v10.5.0
370
+ */
371
+ readonly stdout: Readable;
372
+ /**
373
+ * 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
374
+ * parent thread's `process.stderr` stream.
375
+ * @since v10.5.0
376
+ */
377
+ readonly stderr: Readable;
378
+ /**
379
+ * An integer identifier for the referenced thread. Inside the worker thread,
380
+ * it is available as `require('node:worker_threads').threadId`.
381
+ * This value is unique for each `Worker` instance inside a single process.
382
+ * @since v10.5.0
383
+ */
384
+ readonly threadId: number;
385
+ /**
386
+ * Provides the set of JS engine resource constraints for this Worker thread.
387
+ * If the `resourceLimits` option was passed to the `Worker` constructor,
388
+ * this matches its values.
389
+ *
390
+ * If the worker has stopped, the return value is an empty object.
391
+ * @since v13.2.0, v12.16.0
392
+ */
393
+ readonly resourceLimits?: ResourceLimits | undefined;
394
+ /**
395
+ * An object that can be used to query performance information from a worker
396
+ * instance. Similar to `perf_hooks.performance`.
397
+ * @since v15.1.0, v14.17.0, v12.22.0
398
+ */
399
+ readonly performance: WorkerPerformance;
400
+ /**
401
+ * @param filename The path to the Worker’s main script or module.
402
+ * Must be either an absolute path or a relative path (i.e. relative to the current working directory) starting with ./ or ../,
403
+ * or a WHATWG URL object using file: protocol. If options.eval is true, this is a string containing JavaScript code rather than a path.
404
+ */
405
+ constructor(filename: string | URL, options?: WorkerOptions);
406
+ /**
407
+ * Send a message to the worker that is received via `require('node:worker_threads').parentPort.on('message')`.
408
+ * See `port.postMessage()` for more details.
409
+ * @since v10.5.0
410
+ */
411
+ postMessage(value: any, transferList?: readonly TransferListItem[]): void;
412
+ /**
413
+ * 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
414
+ * behavior). If the worker is `ref()`ed, calling `ref()` again has
415
+ * no effect.
416
+ * @since v10.5.0
417
+ */
418
+ ref(): void;
419
+ /**
420
+ * Calling `unref()` on a worker allows the thread to exit if this is the only
421
+ * active handle in the event system. If the worker is already `unref()`ed calling `unref()` again has no effect.
422
+ * @since v10.5.0
423
+ */
424
+ unref(): void;
425
+ /**
426
+ * Stop all JavaScript execution in the worker thread as soon as possible.
427
+ * Returns a Promise for the exit code that is fulfilled when the `'exit' event` is emitted.
428
+ * @since v10.5.0
429
+ */
430
+ terminate(): Promise<number>;
431
+ /**
432
+ * Returns a readable stream for a V8 snapshot of the current state of the Worker.
433
+ * See `v8.getHeapSnapshot()` for more details.
434
+ *
435
+ * If the Worker thread is no longer running, which may occur before the `'exit' event` is emitted, the returned `Promise` is rejected
436
+ * immediately with an `ERR_WORKER_NOT_RUNNING` error.
437
+ * @since v13.9.0, v12.17.0
438
+ * @return A promise for a Readable Stream containing a V8 heap snapshot
439
+ */
440
+ getHeapSnapshot(): Promise<Readable>;
441
+ addListener(event: "error", listener: (err: Error) => void): this;
442
+ addListener(event: "exit", listener: (exitCode: number) => void): this;
443
+ addListener(event: "message", listener: (value: any) => void): this;
444
+ addListener(event: "messageerror", listener: (error: Error) => void): this;
445
+ addListener(event: "online", listener: () => void): this;
446
+ addListener(event: string | symbol, listener: (...args: any[]) => void): this;
447
+ emit(event: "error", err: Error): boolean;
448
+ emit(event: "exit", exitCode: number): boolean;
449
+ emit(event: "message", value: any): boolean;
450
+ emit(event: "messageerror", error: Error): boolean;
451
+ emit(event: "online"): boolean;
452
+ emit(event: string | symbol, ...args: any[]): boolean;
453
+ on(event: "error", listener: (err: Error) => void): this;
454
+ on(event: "exit", listener: (exitCode: number) => void): this;
455
+ on(event: "message", listener: (value: any) => void): this;
456
+ on(event: "messageerror", listener: (error: Error) => void): this;
457
+ on(event: "online", listener: () => void): this;
458
+ on(event: string | symbol, listener: (...args: any[]) => void): this;
459
+ once(event: "error", listener: (err: Error) => void): this;
460
+ once(event: "exit", listener: (exitCode: number) => void): this;
461
+ once(event: "message", listener: (value: any) => void): this;
462
+ once(event: "messageerror", listener: (error: Error) => void): this;
463
+ once(event: "online", listener: () => void): this;
464
+ once(event: string | symbol, listener: (...args: any[]) => void): this;
465
+ prependListener(event: "error", listener: (err: Error) => void): this;
466
+ prependListener(event: "exit", listener: (exitCode: number) => void): this;
467
+ prependListener(event: "message", listener: (value: any) => void): this;
468
+ prependListener(event: "messageerror", listener: (error: Error) => void): this;
469
+ prependListener(event: "online", listener: () => void): this;
470
+ prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
471
+ prependOnceListener(event: "error", listener: (err: Error) => void): this;
472
+ prependOnceListener(event: "exit", listener: (exitCode: number) => void): this;
473
+ prependOnceListener(event: "message", listener: (value: any) => void): this;
474
+ prependOnceListener(event: "messageerror", listener: (error: Error) => void): this;
475
+ prependOnceListener(event: "online", listener: () => void): this;
476
+ prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
477
+ removeListener(event: "error", listener: (err: Error) => void): this;
478
+ removeListener(event: "exit", listener: (exitCode: number) => void): this;
479
+ removeListener(event: "message", listener: (value: any) => void): this;
480
+ removeListener(event: "messageerror", listener: (error: Error) => void): this;
481
+ removeListener(event: "online", listener: () => void): this;
482
+ removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
483
+ off(event: "error", listener: (err: Error) => void): this;
484
+ off(event: "exit", listener: (exitCode: number) => void): this;
485
+ off(event: "message", listener: (value: any) => void): this;
486
+ off(event: "messageerror", listener: (error: Error) => void): this;
487
+ off(event: "online", listener: () => void): this;
488
+ off(event: string | symbol, listener: (...args: any[]) => void): this;
489
+ }
490
+ interface BroadcastChannel extends NodeJS.RefCounted {}
491
+ /**
492
+ * Instances of `BroadcastChannel` allow asynchronous one-to-many communication
493
+ * with all other `BroadcastChannel` instances bound to the same channel name.
494
+ *
495
+ * ```js
496
+ * 'use strict';
497
+ *
498
+ * const {
499
+ * isMainThread,
500
+ * BroadcastChannel,
501
+ * Worker,
502
+ * } = require('node:worker_threads');
503
+ *
504
+ * const bc = new BroadcastChannel('hello');
505
+ *
506
+ * if (isMainThread) {
507
+ * let c = 0;
508
+ * bc.onmessage = (event) => {
509
+ * console.log(event.data);
510
+ * if (++c === 10) bc.close();
511
+ * };
512
+ * for (let n = 0; n < 10; n++)
513
+ * new Worker(__filename);
514
+ * } else {
515
+ * bc.postMessage('hello from every worker');
516
+ * bc.close();
517
+ * }
518
+ * ```
519
+ * @since v15.4.0
520
+ */
521
+ class BroadcastChannel {
522
+ readonly name: string;
523
+ /**
524
+ * Invoked with a single \`MessageEvent\` argument when a message is received.
525
+ * @since v15.4.0
526
+ */
527
+ onmessage: (message: unknown) => void;
528
+ /**
529
+ * Invoked with a received message cannot be deserialized.
530
+ * @since v15.4.0
531
+ */
532
+ onmessageerror: (message: unknown) => void;
533
+ constructor(name: string);
534
+ /**
535
+ * Closes the `BroadcastChannel` connection.
536
+ * @since v15.4.0
537
+ */
538
+ close(): void;
539
+ /**
540
+ * @since v15.4.0
541
+ * @param message Any cloneable JavaScript value.
542
+ */
543
+ postMessage(message: unknown): void;
544
+ }
545
+ /**
546
+ * Mark an object as not transferable. If `object` occurs in the transfer list of
547
+ * a `port.postMessage()` call, it is ignored.
548
+ *
549
+ * In particular, this makes sense for objects that can be cloned, rather than
550
+ * transferred, and which are used by other objects on the sending side.
551
+ * For example, Node.js marks the `ArrayBuffer`s it uses for its `Buffer pool` with this.
552
+ *
553
+ * This operation cannot be undone.
554
+ *
555
+ * ```js
556
+ * const { MessageChannel, markAsUntransferable } = require('node:worker_threads');
557
+ *
558
+ * const pooledBuffer = new ArrayBuffer(8);
559
+ * const typedArray1 = new Uint8Array(pooledBuffer);
560
+ * const typedArray2 = new Float64Array(pooledBuffer);
561
+ *
562
+ * markAsUntransferable(pooledBuffer);
563
+ *
564
+ * const { port1 } = new MessageChannel();
565
+ * port1.postMessage(typedArray1, [ typedArray1.buffer ]);
566
+ *
567
+ * // The following line prints the contents of typedArray1 -- it still owns
568
+ * // its memory and has been cloned, not transferred. Without
569
+ * // `markAsUntransferable()`, this would print an empty Uint8Array.
570
+ * // typedArray2 is intact as well.
571
+ * console.log(typedArray1);
572
+ * console.log(typedArray2);
573
+ * ```
574
+ *
575
+ * There is no equivalent to this API in browsers.
576
+ * @since v14.5.0, v12.19.0
577
+ */
578
+ function markAsUntransferable(object: object): void;
579
+ /**
580
+ * Transfer a `MessagePort` to a different `vm` Context. The original `port` object is rendered unusable, and the returned `MessagePort` instance
581
+ * takes its place.
582
+ *
583
+ * The returned `MessagePort` is an object in the target context and
584
+ * 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
585
+ * target context
586
+ * and inherit from its global `Object` class.
587
+ *
588
+ * However, the created `MessagePort` no longer inherits from [`EventTarget`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget), and only
589
+ * [`port.onmessage()`](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/onmessage) can be used to receive
590
+ * events using it.
591
+ * @since v11.13.0
592
+ * @param port The message port to transfer.
593
+ * @param contextifiedSandbox A `contextified` object as returned by the `vm.createContext()` method.
594
+ */
595
+ function moveMessagePortToContext(port: MessagePort, contextifiedSandbox: Context): MessagePort;
596
+ /**
597
+ * Receive a single message from a given `MessagePort`. If no message is available,`undefined` is returned, otherwise an object with a single `message` property
598
+ * that contains the message payload, corresponding to the oldest message in the `MessagePort`'s queue.
599
+ *
600
+ * ```js
601
+ * const { MessageChannel, receiveMessageOnPort } = require('node:worker_threads');
602
+ * const { port1, port2 } = new MessageChannel();
603
+ * port1.postMessage({ hello: 'world' });
604
+ *
605
+ * console.log(receiveMessageOnPort(port2));
606
+ * // Prints: { message: { hello: 'world' } }
607
+ * console.log(receiveMessageOnPort(port2));
608
+ * // Prints: undefined
609
+ * ```
610
+ *
611
+ * When this function is used, no `'message'` event is emitted and the `onmessage` listener is not invoked.
612
+ * @since v12.3.0
613
+ */
614
+ function receiveMessageOnPort(port: MessagePort):
615
+ | {
616
+ message: any;
617
+ }
618
+ | undefined;
619
+ type Serializable = string | object | number | boolean | bigint;
620
+ /**
621
+ * Within a worker thread, `worker.getEnvironmentData()` returns a clone
622
+ * of data passed to the spawning thread's `worker.setEnvironmentData()`.
623
+ * Every new `Worker` receives its own copy of the environment data
624
+ * automatically.
625
+ *
626
+ * ```js
627
+ * const {
628
+ * Worker,
629
+ * isMainThread,
630
+ * setEnvironmentData,
631
+ * getEnvironmentData,
632
+ * } = require('node:worker_threads');
633
+ *
634
+ * if (isMainThread) {
635
+ * setEnvironmentData('Hello', 'World!');
636
+ * const worker = new Worker(__filename);
637
+ * } else {
638
+ * console.log(getEnvironmentData('Hello')); // Prints 'World!'.
639
+ * }
640
+ * ```
641
+ * @since v15.12.0, v14.18.0
642
+ * @param key Any arbitrary, cloneable JavaScript value that can be used as a {Map} key.
643
+ */
644
+ function getEnvironmentData(key: Serializable): Serializable;
645
+ /**
646
+ * The `worker.setEnvironmentData()` API sets the content of `worker.getEnvironmentData()` in the current thread and all new `Worker` instances spawned from the current context.
647
+ * @since v15.12.0, v14.18.0
648
+ * @param key Any arbitrary, cloneable JavaScript value that can be used as a {Map} key.
649
+ * @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
650
+ * for the `key` will be deleted.
651
+ */
652
+ function setEnvironmentData(key: Serializable, value: Serializable): void;
653
+
654
+ import {
655
+ BroadcastChannel as _BroadcastChannel,
656
+ MessageChannel as _MessageChannel,
657
+ MessagePort as _MessagePort,
658
+ } from "worker_threads";
659
+ global {
660
+ /**
661
+ * `BroadcastChannel` class is a global reference for `require('worker_threads').BroadcastChannel`
662
+ * https://nodejs.org/api/globals.html#broadcastchannel
663
+ * @since v18.0.0
664
+ */
665
+ var BroadcastChannel: typeof globalThis extends {
666
+ onmessage: any;
667
+ BroadcastChannel: infer T;
668
+ } ? T
669
+ : typeof _BroadcastChannel;
670
+ /**
671
+ * `MessageChannel` class is a global reference for `require('worker_threads').MessageChannel`
672
+ * https://nodejs.org/api/globals.html#messagechannel
673
+ * @since v15.0.0
674
+ */
675
+ var MessageChannel: typeof globalThis extends {
676
+ onmessage: any;
677
+ MessageChannel: infer T;
678
+ } ? T
679
+ : typeof _MessageChannel;
680
+ /**
681
+ * `MessagePort` class is a global reference for `require('worker_threads').MessagePort`
682
+ * https://nodejs.org/api/globals.html#messageport
683
+ * @since v15.0.0
684
+ */
685
+ var MessagePort: typeof globalThis extends {
686
+ onmessage: any;
687
+ MessagePort: infer T;
688
+ } ? T
689
+ : typeof _MessagePort;
690
+ }
691
+ }
692
+ declare module "node:worker_threads" {
693
+ export * from "worker_threads";
694
+ }