@ru-code/ru-code 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (323) hide show
  1. package/dist/Mime-CWE7RyvN.mjs +52568 -0
  2. package/dist/NodeHttpServer-S5W3gV7S.mjs +4190 -0
  3. package/dist/bin.mjs +61184 -0
  4. package/dist/client/app-icon-192.png +0 -0
  5. package/dist/client/app-icon-512.png +0 -0
  6. package/dist/client/assets/DiffPanel-_Zh1bdyD.js +127 -0
  7. package/dist/client/assets/abap--vzi7Rxy.js +1 -0
  8. package/dist/client/assets/actionscript-3-CV21uODD.js +1 -0
  9. package/dist/client/assets/ada-DpXSEmbw.js +1 -0
  10. package/dist/client/assets/andromeeda-C1V0Cb0M.js +1 -0
  11. package/dist/client/assets/angular-html-ChCp3ai5.js +1 -0
  12. package/dist/client/assets/angular-ts-C3xt-gof.js +1 -0
  13. package/dist/client/assets/apache-CRmVjs8c.js +1 -0
  14. package/dist/client/assets/apex-DIIc4r7E.js +1 -0
  15. package/dist/client/assets/apl-CHT4ccs5.js +1 -0
  16. package/dist/client/assets/applescript-DMX6NGuU.js +1 -0
  17. package/dist/client/assets/ara-3SArX2Zn.js +1 -0
  18. package/dist/client/assets/asciidoc-CnVFjb7X.js +1 -0
  19. package/dist/client/assets/asm-Cb-CgaBD.js +1 -0
  20. package/dist/client/assets/astro-BAhLRJmT.js +1 -0
  21. package/dist/client/assets/aurora-x-CjvoFyi0.js +1 -0
  22. package/dist/client/assets/awk-BYjsWVhV.js +1 -0
  23. package/dist/client/assets/ayu-dark-C4UVdT_g.js +1 -0
  24. package/dist/client/assets/ayu-light-CFJ-dST-.js +1 -0
  25. package/dist/client/assets/ayu-mirage-BxM9D2Mi.js +1 -0
  26. package/dist/client/assets/ballerina-BsKCUtAm.js +1 -0
  27. package/dist/client/assets/bat-CJlQOahT.js +1 -0
  28. package/dist/client/assets/beancount-Cyf6Xlzd.js +1 -0
  29. package/dist/client/assets/berry-DHYmFnza.js +1 -0
  30. package/dist/client/assets/bibtex-BUB9btZd.js +1 -0
  31. package/dist/client/assets/bicep-CNVX4dQj.js +1 -0
  32. package/dist/client/assets/bird2-LZP25z1s.js +1 -0
  33. package/dist/client/assets/blade-Cf5fRyZt.js +1 -0
  34. package/dist/client/assets/bsl-BODK--Fo.js +1 -0
  35. package/dist/client/assets/c-JcpCn0Mb.js +1 -0
  36. package/dist/client/assets/c3-BI41OB2W.js +1 -0
  37. package/dist/client/assets/cadence-BDnzkZFt.js +1 -0
  38. package/dist/client/assets/cairo-BwpHIzLA.js +1 -0
  39. package/dist/client/assets/catppuccin-frappe-DpT1lCYX.js +1 -0
  40. package/dist/client/assets/catppuccin-latte-qMMse1WJ.js +1 -0
  41. package/dist/client/assets/catppuccin-macchiato-DMu0Ac9B.js +1 -0
  42. package/dist/client/assets/catppuccin-mocha-DicTaD9V.js +1 -0
  43. package/dist/client/assets/clarity-CPz-yzAn.js +1 -0
  44. package/dist/client/assets/clojure-BxJLFKTj.js +1 -0
  45. package/dist/client/assets/cmake-BmC4o4J9.js +1 -0
  46. package/dist/client/assets/cobol-BTJdrQkB.js +1 -0
  47. package/dist/client/assets/codeowners-BPHDuybI.js +1 -0
  48. package/dist/client/assets/codeql-DYWyWzRY.js +1 -0
  49. package/dist/client/assets/coffee-DfgQcCVz.js +1 -0
  50. package/dist/client/assets/common-lisp-CsDdrwfa.js +1 -0
  51. package/dist/client/assets/coq-BZNwxllS.js +1 -0
  52. package/dist/client/assets/cpp-DnXhWnC8.js +1 -0
  53. package/dist/client/assets/crystal-DIUZ4Qep.js +1 -0
  54. package/dist/client/assets/csharp-BLhQzhUA.js +1 -0
  55. package/dist/client/assets/css-C_iboCwd.js +1 -0
  56. package/dist/client/assets/csv-DPc9UZFt.js +1 -0
  57. package/dist/client/assets/cue-Bat8Mt8Y.js +1 -0
  58. package/dist/client/assets/cypher-CTnWkM4Y.js +1 -0
  59. package/dist/client/assets/d-CccbtpLU.js +1 -0
  60. package/dist/client/assets/dark-plus-CKh7uIvz.js +1 -0
  61. package/dist/client/assets/dart-SbRHwU1n.js +1 -0
  62. package/dist/client/assets/dax-vVKSTwd9.js +1 -0
  63. package/dist/client/assets/desktop-rdWGepy4.js +1 -0
  64. package/dist/client/assets/diff-G5H-0DNT.js +1 -0
  65. package/dist/client/assets/docker-CC20slQp.js +1 -0
  66. package/dist/client/assets/dotenv-C36c6TdP.js +1 -0
  67. package/dist/client/assets/dracula-nNMQZYa7.js +1 -0
  68. package/dist/client/assets/dracula-soft-BPmUsSlJ.js +1 -0
  69. package/dist/client/assets/dream-maker-DleGc9Hy.js +1 -0
  70. package/dist/client/assets/edge-CVxt0Jje.js +1 -0
  71. package/dist/client/assets/elixir-DqKPdKvQ.js +1 -0
  72. package/dist/client/assets/elm-DygL8XMy.js +1 -0
  73. package/dist/client/assets/emacs-lisp-D_QlcMHs.js +1 -0
  74. package/dist/client/assets/erb-Dp-8Q-fK.js +1 -0
  75. package/dist/client/assets/erlang-CjZU-VwD.js +1 -0
  76. package/dist/client/assets/everforest-dark-FkVvIMUl.js +1 -0
  77. package/dist/client/assets/everforest-light-d3V1wTAd.js +1 -0
  78. package/dist/client/assets/fennel-BEssPROc.js +1 -0
  79. package/dist/client/assets/fish-Cz5yLEyJ.js +1 -0
  80. package/dist/client/assets/fluent-TGO8KajN.js +1 -0
  81. package/dist/client/assets/fortran-fixed-form-CLgNuKMV.js +1 -0
  82. package/dist/client/assets/fortran-free-form-CHQXX5JB.js +1 -0
  83. package/dist/client/assets/fsharp-kVgJ9XJy.js +1 -0
  84. package/dist/client/assets/gdresource-DDsMuL8p.js +1 -0
  85. package/dist/client/assets/gdscript-DBkVGsC6.js +1 -0
  86. package/dist/client/assets/gdshader-CWQhZP7Q.js +1 -0
  87. package/dist/client/assets/genie-7iw14YxB.js +1 -0
  88. package/dist/client/assets/gherkin-D4AlAQSH.js +1 -0
  89. package/dist/client/assets/git-commit-BKhxSJdF.js +1 -0
  90. package/dist/client/assets/git-rebase-C4ApJ_xl.js +1 -0
  91. package/dist/client/assets/github-dark-CpBni1SQ.js +1 -0
  92. package/dist/client/assets/github-dark-default-Cr5Q59Ad.js +1 -0
  93. package/dist/client/assets/github-dark-dimmed-WEORr92a.js +1 -0
  94. package/dist/client/assets/github-dark-high-contrast-uM2plAzl.js +1 -0
  95. package/dist/client/assets/github-light-BROm54vS.js +1 -0
  96. package/dist/client/assets/github-light-default-jSwgX00f.js +1 -0
  97. package/dist/client/assets/github-light-high-contrast-Bp9ESXtp.js +1 -0
  98. package/dist/client/assets/gleam-D1LXnIj0.js +1 -0
  99. package/dist/client/assets/glimmer-js-Cr1_ytEM.js +1 -0
  100. package/dist/client/assets/glimmer-ts-CvjAzM-N.js +1 -0
  101. package/dist/client/assets/glsl-DzS09rv-.js +1 -0
  102. package/dist/client/assets/gn-CReOiE5m.js +1 -0
  103. package/dist/client/assets/gnuplot-DufViamc.js +1 -0
  104. package/dist/client/assets/go-DC_Zm44P.js +1 -0
  105. package/dist/client/assets/graphql-DQJJUsrn.js +1 -0
  106. package/dist/client/assets/groovy-DEGDVBi0.js +1 -0
  107. package/dist/client/assets/gruvbox-dark-hard-C-zANgxR.js +1 -0
  108. package/dist/client/assets/gruvbox-dark-medium-DY7Z6TBK.js +1 -0
  109. package/dist/client/assets/gruvbox-dark-soft-Bpj6owGh.js +1 -0
  110. package/dist/client/assets/gruvbox-light-hard-DVwTvHam.js +1 -0
  111. package/dist/client/assets/gruvbox-light-medium-98PeoD5Y.js +1 -0
  112. package/dist/client/assets/gruvbox-light-soft-BHI2PZTB.js +1 -0
  113. package/dist/client/assets/hack-BpueDlLv.js +1 -0
  114. package/dist/client/assets/haml-wKqNP3HI.js +1 -0
  115. package/dist/client/assets/handlebars-BbY9wYb6.js +1 -0
  116. package/dist/client/assets/haskell-B-K-GoPf.js +1 -0
  117. package/dist/client/assets/haxe-md5t_Y_E.js +1 -0
  118. package/dist/client/assets/hcl-qSvp9jTg.js +1 -0
  119. package/dist/client/assets/hjson-BNeV6JDA.js +1 -0
  120. package/dist/client/assets/hlsl-CFf5czm3.js +1 -0
  121. package/dist/client/assets/horizon-C4a2pCDo.js +1 -0
  122. package/dist/client/assets/horizon-bright-Bgpx-0aF.js +1 -0
  123. package/dist/client/assets/houston-BZHNDhe5.js +1 -0
  124. package/dist/client/assets/html-X9TVliui.js +1 -0
  125. package/dist/client/assets/html-derivative-M9PDrRmF.js +1 -0
  126. package/dist/client/assets/http-CyfemUM7.js +1 -0
  127. package/dist/client/assets/hurl-CugckyUy.js +1 -0
  128. package/dist/client/assets/hxml-YehGxZ3T.js +1 -0
  129. package/dist/client/assets/hy-hI-CUgFt.js +1 -0
  130. package/dist/client/assets/imba-Dr5pZl3x.js +1 -0
  131. package/dist/client/assets/index-5-Ih3uGX.css +1 -0
  132. package/dist/client/assets/index-C1Qb2KuV.js +298 -0
  133. package/dist/client/assets/ini-KxzJ-qxg.js +1 -0
  134. package/dist/client/assets/java-CIosYouD.js +1 -0
  135. package/dist/client/assets/javascript-DQNtrppK.js +1 -0
  136. package/dist/client/assets/jinja-P_WjBVQb.js +1 -0
  137. package/dist/client/assets/jison-P1CKkbPs.js +1 -0
  138. package/dist/client/assets/json-DnpVzpQN.js +1 -0
  139. package/dist/client/assets/json5-SRM7tKmT.js +1 -0
  140. package/dist/client/assets/jsonc-Cix1XnqC.js +1 -0
  141. package/dist/client/assets/jsonl-BzKwo-fD.js +1 -0
  142. package/dist/client/assets/jsonnet-DaiLv8or.js +1 -0
  143. package/dist/client/assets/jssm-B1pV58QJ.js +1 -0
  144. package/dist/client/assets/jsx-CppRK5ct.js +1 -0
  145. package/dist/client/assets/julia-F1QkpFl6.js +1 -0
  146. package/dist/client/assets/just-Dukhx2il.js +1 -0
  147. package/dist/client/assets/kanagawa-dragon-BihvT_N-.js +1 -0
  148. package/dist/client/assets/kanagawa-lotus-DQN_bzSt.js +1 -0
  149. package/dist/client/assets/kanagawa-wave-Bvz_F3hD.js +1 -0
  150. package/dist/client/assets/kdl-DupMG4Bk.js +1 -0
  151. package/dist/client/assets/kotlin-rOGI_fXV.js +1 -0
  152. package/dist/client/assets/kusto-CHXnQR8L.js +1 -0
  153. package/dist/client/assets/laserwave-CPMyzJF3.js +1 -0
  154. package/dist/client/assets/latex-ioA6_Ihi.js +1 -0
  155. package/dist/client/assets/lean-B76KugVy.js +1 -0
  156. package/dist/client/assets/less-DwUMKQAG.js +1 -0
  157. package/dist/client/assets/light-plus-C6sdUQiS.js +1 -0
  158. package/dist/client/assets/liquid-DWrqX9Am.js +1 -0
  159. package/dist/client/assets/llvm-DumY6MCH.js +1 -0
  160. package/dist/client/assets/log-DdP6k-FU.js +1 -0
  161. package/dist/client/assets/logo-Cx0gX691.js +1 -0
  162. package/dist/client/assets/lua-U9OQ-uaE.js +1 -0
  163. package/dist/client/assets/luau-CI4wJBxI.js +1 -0
  164. package/dist/client/assets/make-BlyBJiAs.js +1 -0
  165. package/dist/client/assets/markdown-BFgBvytj.js +1 -0
  166. package/dist/client/assets/marko-D8gE9bE3.js +1 -0
  167. package/dist/client/assets/material-theme-CyGvAAeY.js +1 -0
  168. package/dist/client/assets/material-theme-darker-DJAOSarR.js +1 -0
  169. package/dist/client/assets/material-theme-lighter-Cb7t96j2.js +1 -0
  170. package/dist/client/assets/material-theme-ocean-EZZ55_HD.js +1 -0
  171. package/dist/client/assets/material-theme-palenight-DtmMSfya.js +1 -0
  172. package/dist/client/assets/matlab-BFLobVcp.js +1 -0
  173. package/dist/client/assets/mdc-IgYKIGhk.js +1 -0
  174. package/dist/client/assets/mdx-Baux4qlv.js +1 -0
  175. package/dist/client/assets/mermaid-DHr7T0Rt.js +1 -0
  176. package/dist/client/assets/min-dark-C9N1U4-e.js +1 -0
  177. package/dist/client/assets/min-light-Ce9oxBvH.js +1 -0
  178. package/dist/client/assets/mipsasm-Cgb1v7yV.js +1 -0
  179. package/dist/client/assets/mojo-BnTBKscO.js +1 -0
  180. package/dist/client/assets/monokai-BGD_YBH-.js +1 -0
  181. package/dist/client/assets/moonbit-HXw0ZM4h.js +1 -0
  182. package/dist/client/assets/move-DG2efXqI.js +1 -0
  183. package/dist/client/assets/narrat-BSasSB5t.js +1 -0
  184. package/dist/client/assets/nextflow-C2lnptGp.js +1 -0
  185. package/dist/client/assets/nextflow-groovy-DXLl8k8E.js +1 -0
  186. package/dist/client/assets/nginx-pll5DKwZ.js +1 -0
  187. package/dist/client/assets/night-owl-DxqNTXDa.js +1 -0
  188. package/dist/client/assets/night-owl-light-MPn8GCyh.js +1 -0
  189. package/dist/client/assets/nim-B6E9KQ37.js +1 -0
  190. package/dist/client/assets/nix-BpnttlWr.js +1 -0
  191. package/dist/client/assets/nord-Mt6M_qHE.js +1 -0
  192. package/dist/client/assets/nushell-CS7Mvg-G.js +1 -0
  193. package/dist/client/assets/objective-c-U4EuJXJs.js +1 -0
  194. package/dist/client/assets/objective-cpp-CE_PrXRW.js +1 -0
  195. package/dist/client/assets/ocaml-ZsxDKzyv.js +1 -0
  196. package/dist/client/assets/odin-CDoDiNYU.js +1 -0
  197. package/dist/client/assets/one-dark-pro-B9P_I1yh.js +1 -0
  198. package/dist/client/assets/one-light-Cv3j6GXq.js +1 -0
  199. package/dist/client/assets/openscad-CfJwW9dY.js +1 -0
  200. package/dist/client/assets/pascal-CjE0UTC7.js +1 -0
  201. package/dist/client/assets/perl-D5Tw2dIy.js +1 -0
  202. package/dist/client/assets/php-DOq25JLm.js +1 -0
  203. package/dist/client/assets/pierre-dark-CZSVFjtj.js +1 -0
  204. package/dist/client/assets/pierre-light-TJcKYd5h.js +1 -0
  205. package/dist/client/assets/pkl-BN6EkHr9.js +1 -0
  206. package/dist/client/assets/plastic-BCnZnfMk.js +1 -0
  207. package/dist/client/assets/plsql-1LW-CqWM.js +1 -0
  208. package/dist/client/assets/po-Cf5hRC9x.js +1 -0
  209. package/dist/client/assets/poimandres-B_zC30Vt.js +1 -0
  210. package/dist/client/assets/polar-S6fWkEw8.js +1 -0
  211. package/dist/client/assets/postcss-cZXfRCsF.js +1 -0
  212. package/dist/client/assets/powerquery-CoRQQdNP.js +1 -0
  213. package/dist/client/assets/powershell-B2VxwRch.js +1 -0
  214. package/dist/client/assets/prisma-sLrt38jj.js +1 -0
  215. package/dist/client/assets/prolog-CL99toUJ.js +1 -0
  216. package/dist/client/assets/proto-CtiBQJNn.js +1 -0
  217. package/dist/client/assets/pug-C20kp5Eb.js +1 -0
  218. package/dist/client/assets/puppet-BlbpxWq2.js +1 -0
  219. package/dist/client/assets/purescript-DPcVkoDV.js +1 -0
  220. package/dist/client/assets/python-BLpCXkJ6.js +1 -0
  221. package/dist/client/assets/qml-B8TtD5Tk.js +1 -0
  222. package/dist/client/assets/qmldir-BcwbwUc8.js +1 -0
  223. package/dist/client/assets/qss-erDfnnzG.js +1 -0
  224. package/dist/client/assets/r-CeIxA-qS.js +1 -0
  225. package/dist/client/assets/racket-Dch6VQku.js +1 -0
  226. package/dist/client/assets/raku-Db8mfsiE.js +1 -0
  227. package/dist/client/assets/razor-Bqxv99FX.js +1 -0
  228. package/dist/client/assets/red-DWyyM82l.js +1 -0
  229. package/dist/client/assets/reg-3F9yjO5J.js +1 -0
  230. package/dist/client/assets/regexp-9rcGRxEv.js +1 -0
  231. package/dist/client/assets/rel-CQq8nxxL.js +1 -0
  232. package/dist/client/assets/riscv-CsUwotvK.js +1 -0
  233. package/dist/client/assets/rolldown-runtime-S-ySWqyJ.js +1 -0
  234. package/dist/client/assets/ron-BwlS4rWu.js +1 -0
  235. package/dist/client/assets/rose-pine-DEj8gOox.js +1 -0
  236. package/dist/client/assets/rose-pine-dawn-DjarqQ2I.js +1 -0
  237. package/dist/client/assets/rose-pine-moon-D7ffkR_D.js +1 -0
  238. package/dist/client/assets/rosmsg-BmwwVMq5.js +1 -0
  239. package/dist/client/assets/rst-BXsAfkkt.js +1 -0
  240. package/dist/client/assets/ruby-DJN2q5Q9.js +1 -0
  241. package/dist/client/assets/rust-DsIgDjpj.js +1 -0
  242. package/dist/client/assets/sas-CyqCpZ0K.js +1 -0
  243. package/dist/client/assets/sass-CkIFK_bT.js +1 -0
  244. package/dist/client/assets/scala-C0TSxhxD.js +1 -0
  245. package/dist/client/assets/scheme-e-5nJ58U.js +1 -0
  246. package/dist/client/assets/scss-BS3XCcAk.js +1 -0
  247. package/dist/client/assets/sdbl-DOe8Nral.js +1 -0
  248. package/dist/client/assets/shaderlab-CCgEvKkt.js +1 -0
  249. package/dist/client/assets/shellscript-61CfPqQ2.js +1 -0
  250. package/dist/client/assets/shellsession-B25Qw7KD.js +1 -0
  251. package/dist/client/assets/slack-dark-CClHvLju.js +1 -0
  252. package/dist/client/assets/slack-ochin-DwCpSVBI.js +1 -0
  253. package/dist/client/assets/smalltalk-fjkC4HKG.js +1 -0
  254. package/dist/client/assets/snazzy-light-2nD216w0.js +1 -0
  255. package/dist/client/assets/solarized-dark-BkxMSETv.js +1 -0
  256. package/dist/client/assets/solarized-light-BScqQ1C4.js +1 -0
  257. package/dist/client/assets/solidity-DbOxJfAY.js +1 -0
  258. package/dist/client/assets/soy-uEX3YyaH.js +1 -0
  259. package/dist/client/assets/sparql-DH0hFmAi.js +1 -0
  260. package/dist/client/assets/splunk-BW0l10cw.js +1 -0
  261. package/dist/client/assets/sql-DSvhSU5b.js +1 -0
  262. package/dist/client/assets/ssh-config-XN7RWvZy.js +1 -0
  263. package/dist/client/assets/stata-BCZ16WIm.js +1 -0
  264. package/dist/client/assets/stylus-D69is74S.js +1 -0
  265. package/dist/client/assets/surrealql-DKo-yuSz.js +1 -0
  266. package/dist/client/assets/svelte-BHd07bA5.js +1 -0
  267. package/dist/client/assets/swift-CqNHAbQB.js +1 -0
  268. package/dist/client/assets/synthwave-84-Ct3Np89a.js +1 -0
  269. package/dist/client/assets/system-verilog-CHbvBf8h.js +1 -0
  270. package/dist/client/assets/systemd-BBC3Z_R4.js +1 -0
  271. package/dist/client/assets/talonscript-DhYQB2ic.js +1 -0
  272. package/dist/client/assets/tasl-CNtai3BH.js +1 -0
  273. package/dist/client/assets/tcl-DFzyQSXW.js +1 -0
  274. package/dist/client/assets/templ-b_nOJUZF.js +1 -0
  275. package/dist/client/assets/terraform-BijD6Khb.js +1 -0
  276. package/dist/client/assets/tex-DM0DPA6B.js +1 -0
  277. package/dist/client/assets/tokyo-night-Dd5BGAxh.js +1 -0
  278. package/dist/client/assets/toml-DZofdujH.js +1 -0
  279. package/dist/client/assets/ts-tags-D3sVhDJE.js +1 -0
  280. package/dist/client/assets/tsv-DOp6g7sz.js +1 -0
  281. package/dist/client/assets/tsx-B3z1x3Uh.js +1 -0
  282. package/dist/client/assets/turtle-BKcRDROw.js +1 -0
  283. package/dist/client/assets/twig-WJHN-q5d.js +1 -0
  284. package/dist/client/assets/typescript-DC_Fy6Wj.js +1 -0
  285. package/dist/client/assets/typespec-Mmt3-2Cw.js +1 -0
  286. package/dist/client/assets/typst-CndOdNo_.js +1 -0
  287. package/dist/client/assets/v-DjlZIA0C.js +1 -0
  288. package/dist/client/assets/vala-C5Nm5NXo.js +1 -0
  289. package/dist/client/assets/vb-zZeWbE2_.js +1 -0
  290. package/dist/client/assets/verilog-CyZIVfoz.js +1 -0
  291. package/dist/client/assets/vesper-B0BMGbco.js +1 -0
  292. package/dist/client/assets/vhdl-DH1mJdjZ.js +1 -0
  293. package/dist/client/assets/viml-e-oP1x-l.js +1 -0
  294. package/dist/client/assets/vitesse-black-BRAUsA4Q.js +1 -0
  295. package/dist/client/assets/vitesse-dark-Dyg71HnT.js +1 -0
  296. package/dist/client/assets/vitesse-light-BJKZKqvd.js +1 -0
  297. package/dist/client/assets/vue-D68Wc1sl.js +1 -0
  298. package/dist/client/assets/vue-html-B23JIrit.js +1 -0
  299. package/dist/client/assets/vue-vine-DTZ7V31n.js +1 -0
  300. package/dist/client/assets/vyper-BRPzCrki.js +1 -0
  301. package/dist/client/assets/wasm-DYMpDie-.js +1 -0
  302. package/dist/client/assets/wasm-Drz0Uqci.js +1 -0
  303. package/dist/client/assets/wenyan-BiJ0NePu.js +1 -0
  304. package/dist/client/assets/wgsl-CNe_V6SG.js +1 -0
  305. package/dist/client/assets/wikitext-DZrjZKWn.js +1 -0
  306. package/dist/client/assets/wit-BUTESHa8.js +1 -0
  307. package/dist/client/assets/wolfram-COEZldPx.js +1 -0
  308. package/dist/client/assets/worker-BIRX47KY.js +160 -0
  309. package/dist/client/assets/xml-CrOYUwB2.js +1 -0
  310. package/dist/client/assets/xsl-BHRFhEOV.js +1 -0
  311. package/dist/client/assets/yaml-Dvn9e6BK.js +1 -0
  312. package/dist/client/assets/zenscript-DThCxjUC.js +1 -0
  313. package/dist/client/assets/zig-Bu6QWpR2.js +1 -0
  314. package/dist/client/icons/dark/apple-touch-icon.png +0 -0
  315. package/dist/client/icons/dark/favicon-32x32.png +0 -0
  316. package/dist/client/icons/light/apple-touch-icon.png +0 -0
  317. package/dist/client/icons/light/favicon-32x32.png +0 -0
  318. package/dist/client/index.html +139 -0
  319. package/dist/client/logo.png +0 -0
  320. package/dist/client/site.webmanifest +24 -0
  321. package/dist/client/sw.js +15 -0
  322. package/dist/open-DeReVUxk.mjs +451 -0
  323. package/package.json +50 -0
@@ -0,0 +1,4190 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { $o as withFiber, $r as unwrap, A as ResponseError, Bu as flow, C as decodeField, D as ClientAbort, Do as scope, Ds as provide, E as fromWebSocket, Ei as makeUnsafe$1, Es as mergeAll, Fo as suspend, Fs as addFinalizerExit, Go as try_, Gu as __require, Hl as makeUnsafe, Hu as pipe, Io as sync, J as TypeId, Ja as interruptible, Jl as fromNullishOr, Ku as __toESM, La as fnUntraced, Lt as layer$4, M as ServeError, Ma as failCause, Mo as succeed, N as causeResponse, O as HttpServerError, Oa as die, Os as provideMerge, Pa as flatMap, Ps as addFinalizer, Pt as unwrap$1, R as raw, Ro as tapCause, Rs as forkUnsafe, S as toPersisted, To as runSync, U as RequestInit, Uo as timeoutOrElse, Vs as provide$1, W as layer$5, Wo as tryPromise, Wr as orDie, Wu as __commonJSMin, Y as inspect, Zo as void_, Zr as runForEachArray, b as TypeId$1, bs as effect, c as make$3, ct as merge, dc as die$1, dt as isEmpty, fr as layer$2, ft as parseHeader, gr as toUint8Array, h as TypeId$2, ha as callback, hl as seconds, hr as toString, i as make$5, ja as fail, k as RequestParseError, ki as runIn, ks as succeed$1, l as toHandled, lt as layer$3, ma as cached, mr as toArrayBuffer, n as HttpServer, oo as matchCauseEffect, ot as fromInput, p as HttpServerRequest, pr as fromReadable, pt as toSetCookieHeaders, q as MaxBodySize, r as layerTestClient, ra as acquireRelease, ro as map, rt as fromInput$1, s as HttpPlatform, st as fromRecordUnsafe, t as Mime_default, uc as combine, ut as layerWeak, vu as Class, w as make$4, wo as runForkWith, ws as fresh, x as makeConfig, y as MultipartError, zr as map$1 } from "./Mime-CWE7RyvN.mjs";
4
+ import { Duplex, Readable } from "node:stream";
5
+ import * as Fs from "node:fs";
6
+ import * as Http from "node:http";
7
+ import * as NodeStreamP from "node:stream/promises";
8
+ import { pipeline } from "node:stream/promises";
9
+
10
+ //#region ../../node_modules/.pnpm/@effect+platform-node@4.0.0-beta.59_effect@4.0.0-beta.59_ioredis@5.11.0/node_modules/@effect/platform-node/dist/NodeHttpIncomingMessage.js
11
+ /**
12
+ * @since 1.0.0
13
+ */
14
+ /**
15
+ * @since 1.0.0
16
+ * @category Constructors
17
+ */
18
+ var NodeHttpIncomingMessage = class extends Class {
19
+ /**
20
+ * @since 1.0.0
21
+ */
22
+ [TypeId];
23
+ source;
24
+ onError;
25
+ remoteAddressOverride;
26
+ constructor(source, onError, remoteAddressOverride) {
27
+ super();
28
+ this[TypeId] = TypeId;
29
+ this.source = source;
30
+ this.onError = onError;
31
+ this.remoteAddressOverride = remoteAddressOverride;
32
+ }
33
+ get headers() {
34
+ return fromInput(this.source.headers);
35
+ }
36
+ get remoteAddress() {
37
+ return this.remoteAddressOverride ?? fromNullishOr(this.source.socket.remoteAddress);
38
+ }
39
+ textEffect;
40
+ get text() {
41
+ if (this.textEffect) return this.textEffect;
42
+ this.textEffect = runSync(cached(flatMap(MaxBodySize.asEffect(), (maxBodySize) => toString(() => this.source, {
43
+ onError: this.onError,
44
+ maxBytes: maxBodySize
45
+ }))));
46
+ this.arrayBufferEffect = map(this.textEffect, (_) => new TextEncoder().encode(_).buffer);
47
+ return this.textEffect;
48
+ }
49
+ get textUnsafe() {
50
+ return runSync(this.text);
51
+ }
52
+ get json() {
53
+ return flatMap(this.text, (text) => try_({
54
+ try: () => text === "" ? null : JSON.parse(text),
55
+ catch: this.onError
56
+ }));
57
+ }
58
+ get jsonUnsafe() {
59
+ return runSync(this.json);
60
+ }
61
+ get urlParamsBody() {
62
+ return flatMap(this.text, (_) => try_({
63
+ try: () => fromInput$1(new URLSearchParams(_)),
64
+ catch: this.onError
65
+ }));
66
+ }
67
+ get stream() {
68
+ return fromReadable({
69
+ evaluate: () => this.source,
70
+ onError: this.onError
71
+ });
72
+ }
73
+ arrayBufferEffect;
74
+ get arrayBuffer() {
75
+ if (this.arrayBufferEffect) return this.arrayBufferEffect;
76
+ this.arrayBufferEffect = withFiber((fiber) => toArrayBuffer(() => this.source, {
77
+ onError: this.onError,
78
+ maxBytes: fiber.getRef(MaxBodySize)
79
+ })).pipe(cached, runSync);
80
+ this.textEffect = map(this.arrayBufferEffect, (_) => new TextDecoder().decode(_));
81
+ return this.arrayBufferEffect;
82
+ }
83
+ };
84
+
85
+ //#endregion
86
+ //#region ../../node_modules/.pnpm/@effect+platform-node@4.0.0-beta.59_effect@4.0.0-beta.59_ioredis@5.11.0/node_modules/@effect/platform-node/dist/NodeHttpPlatform.js
87
+ /**
88
+ * @since 1.0.0
89
+ */
90
+ /**
91
+ * @since 1.0.0
92
+ * @category Constructors
93
+ */
94
+ const make$2 = /* @__PURE__ */ make$3({
95
+ fileResponse(path, status, statusText, headers, start, end, contentLength) {
96
+ const stream = contentLength === 0 ? Readable.from([]) : Fs.createReadStream(path, {
97
+ start,
98
+ end: end === void 0 ? void 0 : end - 1
99
+ });
100
+ return raw(stream, {
101
+ headers: {
102
+ ...headers,
103
+ "content-type": headers["content-type"] ?? Mime_default.getType(path) ?? "application/octet-stream",
104
+ "content-length": contentLength.toString()
105
+ },
106
+ status,
107
+ statusText
108
+ });
109
+ },
110
+ fileWebResponse(file, status, statusText, headers, _options) {
111
+ return raw(Readable.fromWeb(file.stream()), {
112
+ headers: merge(headers, fromRecordUnsafe({
113
+ "content-type": headers["content-type"] ?? Mime_default.getType(file.name) ?? "application/octet-stream",
114
+ "content-length": file.size.toString()
115
+ })),
116
+ status,
117
+ statusText
118
+ });
119
+ }
120
+ });
121
+ /**
122
+ * @since 1.0.0
123
+ * @category Layers
124
+ */
125
+ const layer$1 = /* @__PURE__ */ pipe(/* @__PURE__ */ effect(HttpPlatform)(make$2), /* @__PURE__ */ provide(layer$2), /* @__PURE__ */ provide(layer$3));
126
+
127
+ //#endregion
128
+ //#region ../../node_modules/.pnpm/multipasta@0.2.7/node_modules/multipasta/dist/esm/node.js
129
+ var MultipastaStream = class extends Duplex {
130
+ _parser;
131
+ _canWrite = true;
132
+ _writeCallback;
133
+ constructor(config) {
134
+ super({ readableObjectMode: true });
135
+ let currentError;
136
+ let currentFile;
137
+ this._parser = make$4({
138
+ ...config,
139
+ onField: (info, value) => {
140
+ if (currentError !== void 0) return;
141
+ const field = {
142
+ _tag: "Field",
143
+ info,
144
+ value
145
+ };
146
+ this.push(field);
147
+ this.emit("field", field);
148
+ },
149
+ onFile: (info) => {
150
+ if (currentError !== void 0) return (_) => {};
151
+ const file = new FileStream(info, this);
152
+ currentFile = file;
153
+ this.push(file);
154
+ this.emit("file", file);
155
+ return (chunk) => {
156
+ this._canWrite = file.push(chunk);
157
+ if (chunk === null && !this._canWrite) {
158
+ currentFile = void 0;
159
+ this._resume();
160
+ }
161
+ };
162
+ },
163
+ onError: (error) => {
164
+ this.emit("error", error);
165
+ currentFile?.emit("error", error);
166
+ currentError = error;
167
+ },
168
+ onDone: () => {
169
+ this.push(null);
170
+ }
171
+ });
172
+ }
173
+ _resume() {
174
+ this._canWrite = true;
175
+ if (this._writeCallback !== void 0) {
176
+ const callback = this._writeCallback;
177
+ this._writeCallback = void 0;
178
+ callback();
179
+ }
180
+ }
181
+ _read(_size) {}
182
+ _write(chunk, encoding, callback) {
183
+ this._parser.write(chunk instanceof Uint8Array ? chunk : Buffer.from(chunk, encoding));
184
+ if (this._canWrite) callback();
185
+ else this._writeCallback = callback;
186
+ }
187
+ _final(callback) {
188
+ this._parser.end();
189
+ callback();
190
+ }
191
+ };
192
+ const make$1 = (config) => new MultipastaStream(config);
193
+ var FileStream = class extends Readable {
194
+ info;
195
+ _parent;
196
+ _tag = "File";
197
+ filename;
198
+ constructor(info, _parent) {
199
+ super();
200
+ this.info = info;
201
+ this._parent = _parent;
202
+ this.filename = info.filename;
203
+ }
204
+ _read(_size) {
205
+ if (this._parent._canWrite === false) this._parent._resume();
206
+ }
207
+ };
208
+
209
+ //#endregion
210
+ //#region ../../node_modules/.pnpm/@effect+platform-node@4.0.0-beta.59_effect@4.0.0-beta.59_ioredis@5.11.0/node_modules/@effect/platform-node/dist/NodeMultipart.js
211
+ /**
212
+ * @since 1.0.0
213
+ */
214
+ /**
215
+ * @since 1.0.0
216
+ * @category constructors
217
+ */
218
+ const stream = (source, headers) => makeConfig(headers).pipe(map((config) => fromReadable({
219
+ evaluate() {
220
+ const parser = make$1(config);
221
+ source.pipe(parser);
222
+ return parser;
223
+ },
224
+ onError: (error) => convertError(error)
225
+ })), unwrap, map$1(convertPart));
226
+ /**
227
+ * @since 1.0.0
228
+ * @category constructors
229
+ */
230
+ const persisted = (source, headers) => toPersisted(stream(source, headers), (path, file) => tryPromise({
231
+ try: (signal) => NodeStreamP.pipeline(file.file, Fs.createWriteStream(path), { signal }),
232
+ catch: (cause) => MultipartError.fromReason("InternalError", cause)
233
+ }));
234
+ const convertPart = (part) => part._tag === "Field" ? new FieldImpl(part.info, part.value) : new FileImpl(part);
235
+ var PartBase = class extends Class {
236
+ [TypeId$1];
237
+ constructor() {
238
+ super();
239
+ this[TypeId$1] = TypeId$1;
240
+ }
241
+ };
242
+ var FieldImpl = class extends PartBase {
243
+ _tag = "Field";
244
+ key;
245
+ contentType;
246
+ value;
247
+ constructor(info, value) {
248
+ super();
249
+ this.key = info.name;
250
+ this.contentType = info.contentType;
251
+ this.value = decodeField(info, value);
252
+ }
253
+ toJSON() {
254
+ return {
255
+ _id: "@effect/platform/Multipart/Part",
256
+ _tag: "Field",
257
+ key: this.key,
258
+ value: this.value,
259
+ contentType: this.contentType
260
+ };
261
+ }
262
+ };
263
+ var FileImpl = class extends PartBase {
264
+ _tag = "File";
265
+ key;
266
+ name;
267
+ contentType;
268
+ content;
269
+ contentEffect;
270
+ file;
271
+ constructor(file) {
272
+ super();
273
+ this.file = file;
274
+ this.key = file.info.name;
275
+ this.name = file.filename ?? file.info.name;
276
+ this.contentType = file.info.contentType;
277
+ this.content = fromReadable({
278
+ evaluate: () => file,
279
+ onError: (cause) => MultipartError.fromReason("InternalError", cause)
280
+ });
281
+ this.contentEffect = toUint8Array(() => file, { onError: (cause) => MultipartError.fromReason("InternalError", cause) });
282
+ }
283
+ toJSON() {
284
+ return {
285
+ _id: "@effect/platform/Multipart/Part",
286
+ _tag: "File",
287
+ key: this.key,
288
+ name: this.name,
289
+ contentType: this.contentType
290
+ };
291
+ }
292
+ };
293
+ function convertError(cause) {
294
+ switch (cause._tag) {
295
+ case "ReachedLimit": switch (cause.limit) {
296
+ case "MaxParts": return MultipartError.fromReason("TooManyParts", cause);
297
+ case "MaxFieldSize": return MultipartError.fromReason("FieldTooLarge", cause);
298
+ case "MaxPartSize": return MultipartError.fromReason("FileTooLarge", cause);
299
+ case "MaxTotalSize": return MultipartError.fromReason("BodyTooLarge", cause);
300
+ }
301
+ default: return MultipartError.fromReason("Parse", cause);
302
+ }
303
+ }
304
+
305
+ //#endregion
306
+ //#region ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/constants.js
307
+ var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
308
+ const BINARY_TYPES = [
309
+ "nodebuffer",
310
+ "arraybuffer",
311
+ "fragments"
312
+ ];
313
+ const hasBlob = typeof Blob !== "undefined";
314
+ if (hasBlob) BINARY_TYPES.push("blob");
315
+ module.exports = {
316
+ BINARY_TYPES,
317
+ CLOSE_TIMEOUT: 3e4,
318
+ EMPTY_BUFFER: Buffer.alloc(0),
319
+ GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
320
+ hasBlob,
321
+ kForOnEventAttribute: Symbol("kIsForOnEventAttribute"),
322
+ kListener: Symbol("kListener"),
323
+ kStatusCode: Symbol("status-code"),
324
+ kWebSocket: Symbol("websocket"),
325
+ NOOP: () => {}
326
+ };
327
+ }));
328
+
329
+ //#endregion
330
+ //#region ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/buffer-util.js
331
+ var require_buffer_util = /* @__PURE__ */ __commonJSMin(((exports, module) => {
332
+ const { EMPTY_BUFFER } = require_constants();
333
+ const FastBuffer = Buffer[Symbol.species];
334
+ /**
335
+ * Merges an array of buffers into a new buffer.
336
+ *
337
+ * @param {Buffer[]} list The array of buffers to concat
338
+ * @param {Number} totalLength The total length of buffers in the list
339
+ * @return {Buffer} The resulting buffer
340
+ * @public
341
+ */
342
+ function concat(list, totalLength) {
343
+ if (list.length === 0) return EMPTY_BUFFER;
344
+ if (list.length === 1) return list[0];
345
+ const target = Buffer.allocUnsafe(totalLength);
346
+ let offset = 0;
347
+ for (let i = 0; i < list.length; i++) {
348
+ const buf = list[i];
349
+ target.set(buf, offset);
350
+ offset += buf.length;
351
+ }
352
+ if (offset < totalLength) return new FastBuffer(target.buffer, target.byteOffset, offset);
353
+ return target;
354
+ }
355
+ /**
356
+ * Masks a buffer using the given mask.
357
+ *
358
+ * @param {Buffer} source The buffer to mask
359
+ * @param {Buffer} mask The mask to use
360
+ * @param {Buffer} output The buffer where to store the result
361
+ * @param {Number} offset The offset at which to start writing
362
+ * @param {Number} length The number of bytes to mask.
363
+ * @public
364
+ */
365
+ function _mask(source, mask, output, offset, length) {
366
+ for (let i = 0; i < length; i++) output[offset + i] = source[i] ^ mask[i & 3];
367
+ }
368
+ /**
369
+ * Unmasks a buffer using the given mask.
370
+ *
371
+ * @param {Buffer} buffer The buffer to unmask
372
+ * @param {Buffer} mask The mask to use
373
+ * @public
374
+ */
375
+ function _unmask(buffer, mask) {
376
+ for (let i = 0; i < buffer.length; i++) buffer[i] ^= mask[i & 3];
377
+ }
378
+ /**
379
+ * Converts a buffer to an `ArrayBuffer`.
380
+ *
381
+ * @param {Buffer} buf The buffer to convert
382
+ * @return {ArrayBuffer} Converted buffer
383
+ * @public
384
+ */
385
+ function toArrayBuffer(buf) {
386
+ if (buf.length === buf.buffer.byteLength) return buf.buffer;
387
+ return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
388
+ }
389
+ /**
390
+ * Converts `data` to a `Buffer`.
391
+ *
392
+ * @param {*} data The data to convert
393
+ * @return {Buffer} The buffer
394
+ * @throws {TypeError}
395
+ * @public
396
+ */
397
+ function toBuffer(data) {
398
+ toBuffer.readOnly = true;
399
+ if (Buffer.isBuffer(data)) return data;
400
+ let buf;
401
+ if (data instanceof ArrayBuffer) buf = new FastBuffer(data);
402
+ else if (ArrayBuffer.isView(data)) buf = new FastBuffer(data.buffer, data.byteOffset, data.byteLength);
403
+ else {
404
+ buf = Buffer.from(data);
405
+ toBuffer.readOnly = false;
406
+ }
407
+ return buf;
408
+ }
409
+ module.exports = {
410
+ concat,
411
+ mask: _mask,
412
+ toArrayBuffer,
413
+ toBuffer,
414
+ unmask: _unmask
415
+ };
416
+ /* istanbul ignore else */
417
+ if (!process.env.WS_NO_BUFFER_UTIL) try {
418
+ const bufferUtil = __require("bufferutil");
419
+ module.exports.mask = function(source, mask, output, offset, length) {
420
+ if (length < 48) _mask(source, mask, output, offset, length);
421
+ else bufferUtil.mask(source, mask, output, offset, length);
422
+ };
423
+ module.exports.unmask = function(buffer, mask) {
424
+ if (buffer.length < 32) _unmask(buffer, mask);
425
+ else bufferUtil.unmask(buffer, mask);
426
+ };
427
+ } catch (e) {}
428
+ }));
429
+
430
+ //#endregion
431
+ //#region ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/limiter.js
432
+ var require_limiter = /* @__PURE__ */ __commonJSMin(((exports, module) => {
433
+ const kDone = Symbol("kDone");
434
+ const kRun = Symbol("kRun");
435
+ /**
436
+ * A very simple job queue with adjustable concurrency. Adapted from
437
+ * https://github.com/STRML/async-limiter
438
+ */
439
+ var Limiter = class {
440
+ /**
441
+ * Creates a new `Limiter`.
442
+ *
443
+ * @param {Number} [concurrency=Infinity] The maximum number of jobs allowed
444
+ * to run concurrently
445
+ */
446
+ constructor(concurrency) {
447
+ this[kDone] = () => {
448
+ this.pending--;
449
+ this[kRun]();
450
+ };
451
+ this.concurrency = concurrency || Infinity;
452
+ this.jobs = [];
453
+ this.pending = 0;
454
+ }
455
+ /**
456
+ * Adds a job to the queue.
457
+ *
458
+ * @param {Function} job The job to run
459
+ * @public
460
+ */
461
+ add(job) {
462
+ this.jobs.push(job);
463
+ this[kRun]();
464
+ }
465
+ /**
466
+ * Removes a job from the queue and runs it if possible.
467
+ *
468
+ * @private
469
+ */
470
+ [kRun]() {
471
+ if (this.pending === this.concurrency) return;
472
+ if (this.jobs.length) {
473
+ const job = this.jobs.shift();
474
+ this.pending++;
475
+ job(this[kDone]);
476
+ }
477
+ }
478
+ };
479
+ module.exports = Limiter;
480
+ }));
481
+
482
+ //#endregion
483
+ //#region ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/permessage-deflate.js
484
+ var require_permessage_deflate = /* @__PURE__ */ __commonJSMin(((exports, module) => {
485
+ const zlib = __require("zlib");
486
+ const bufferUtil = require_buffer_util();
487
+ const Limiter = require_limiter();
488
+ const { kStatusCode } = require_constants();
489
+ const FastBuffer = Buffer[Symbol.species];
490
+ const TRAILER = Buffer.from([
491
+ 0,
492
+ 0,
493
+ 255,
494
+ 255
495
+ ]);
496
+ const kPerMessageDeflate = Symbol("permessage-deflate");
497
+ const kTotalLength = Symbol("total-length");
498
+ const kCallback = Symbol("callback");
499
+ const kBuffers = Symbol("buffers");
500
+ const kError = Symbol("error");
501
+ let zlibLimiter;
502
+ /**
503
+ * permessage-deflate implementation.
504
+ */
505
+ var PerMessageDeflate = class {
506
+ /**
507
+ * Creates a PerMessageDeflate instance.
508
+ *
509
+ * @param {Object} [options] Configuration options
510
+ * @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
511
+ * for, or request, a custom client window size
512
+ * @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
513
+ * acknowledge disabling of client context takeover
514
+ * @param {Number} [options.concurrencyLimit=10] The number of concurrent
515
+ * calls to zlib
516
+ * @param {Boolean} [options.isServer=false] Create the instance in either
517
+ * server or client mode
518
+ * @param {Number} [options.maxPayload=0] The maximum allowed message length
519
+ * @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
520
+ * use of a custom server window size
521
+ * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
522
+ * disabling of server context takeover
523
+ * @param {Number} [options.threshold=1024] Size (in bytes) below which
524
+ * messages should not be compressed if context takeover is disabled
525
+ * @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
526
+ * deflate
527
+ * @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
528
+ * inflate
529
+ */
530
+ constructor(options) {
531
+ this._options = options || {};
532
+ this._threshold = this._options.threshold !== void 0 ? this._options.threshold : 1024;
533
+ this._maxPayload = this._options.maxPayload | 0;
534
+ this._isServer = !!this._options.isServer;
535
+ this._deflate = null;
536
+ this._inflate = null;
537
+ this.params = null;
538
+ if (!zlibLimiter) zlibLimiter = new Limiter(this._options.concurrencyLimit !== void 0 ? this._options.concurrencyLimit : 10);
539
+ }
540
+ /**
541
+ * @type {String}
542
+ */
543
+ static get extensionName() {
544
+ return "permessage-deflate";
545
+ }
546
+ /**
547
+ * Create an extension negotiation offer.
548
+ *
549
+ * @return {Object} Extension parameters
550
+ * @public
551
+ */
552
+ offer() {
553
+ const params = {};
554
+ if (this._options.serverNoContextTakeover) params.server_no_context_takeover = true;
555
+ if (this._options.clientNoContextTakeover) params.client_no_context_takeover = true;
556
+ if (this._options.serverMaxWindowBits) params.server_max_window_bits = this._options.serverMaxWindowBits;
557
+ if (this._options.clientMaxWindowBits) params.client_max_window_bits = this._options.clientMaxWindowBits;
558
+ else if (this._options.clientMaxWindowBits == null) params.client_max_window_bits = true;
559
+ return params;
560
+ }
561
+ /**
562
+ * Accept an extension negotiation offer/response.
563
+ *
564
+ * @param {Array} configurations The extension negotiation offers/reponse
565
+ * @return {Object} Accepted configuration
566
+ * @public
567
+ */
568
+ accept(configurations) {
569
+ configurations = this.normalizeParams(configurations);
570
+ this.params = this._isServer ? this.acceptAsServer(configurations) : this.acceptAsClient(configurations);
571
+ return this.params;
572
+ }
573
+ /**
574
+ * Releases all resources used by the extension.
575
+ *
576
+ * @public
577
+ */
578
+ cleanup() {
579
+ if (this._inflate) {
580
+ this._inflate.close();
581
+ this._inflate = null;
582
+ }
583
+ if (this._deflate) {
584
+ const callback = this._deflate[kCallback];
585
+ this._deflate.close();
586
+ this._deflate = null;
587
+ if (callback) callback(/* @__PURE__ */ new Error("The deflate stream was closed while data was being processed"));
588
+ }
589
+ }
590
+ /**
591
+ * Accept an extension negotiation offer.
592
+ *
593
+ * @param {Array} offers The extension negotiation offers
594
+ * @return {Object} Accepted configuration
595
+ * @private
596
+ */
597
+ acceptAsServer(offers) {
598
+ const opts = this._options;
599
+ const accepted = offers.find((params) => {
600
+ if (opts.serverNoContextTakeover === false && params.server_no_context_takeover || params.server_max_window_bits && (opts.serverMaxWindowBits === false || typeof opts.serverMaxWindowBits === "number" && opts.serverMaxWindowBits > params.server_max_window_bits) || typeof opts.clientMaxWindowBits === "number" && !params.client_max_window_bits) return false;
601
+ return true;
602
+ });
603
+ if (!accepted) throw new Error("None of the extension offers can be accepted");
604
+ if (opts.serverNoContextTakeover) accepted.server_no_context_takeover = true;
605
+ if (opts.clientNoContextTakeover) accepted.client_no_context_takeover = true;
606
+ if (typeof opts.serverMaxWindowBits === "number") accepted.server_max_window_bits = opts.serverMaxWindowBits;
607
+ if (typeof opts.clientMaxWindowBits === "number") accepted.client_max_window_bits = opts.clientMaxWindowBits;
608
+ else if (accepted.client_max_window_bits === true || opts.clientMaxWindowBits === false) delete accepted.client_max_window_bits;
609
+ return accepted;
610
+ }
611
+ /**
612
+ * Accept the extension negotiation response.
613
+ *
614
+ * @param {Array} response The extension negotiation response
615
+ * @return {Object} Accepted configuration
616
+ * @private
617
+ */
618
+ acceptAsClient(response) {
619
+ const params = response[0];
620
+ if (this._options.clientNoContextTakeover === false && params.client_no_context_takeover) throw new Error("Unexpected parameter \"client_no_context_takeover\"");
621
+ if (!params.client_max_window_bits) {
622
+ if (typeof this._options.clientMaxWindowBits === "number") params.client_max_window_bits = this._options.clientMaxWindowBits;
623
+ } else if (this._options.clientMaxWindowBits === false || typeof this._options.clientMaxWindowBits === "number" && params.client_max_window_bits > this._options.clientMaxWindowBits) throw new Error("Unexpected or invalid parameter \"client_max_window_bits\"");
624
+ return params;
625
+ }
626
+ /**
627
+ * Normalize parameters.
628
+ *
629
+ * @param {Array} configurations The extension negotiation offers/reponse
630
+ * @return {Array} The offers/response with normalized parameters
631
+ * @private
632
+ */
633
+ normalizeParams(configurations) {
634
+ configurations.forEach((params) => {
635
+ Object.keys(params).forEach((key) => {
636
+ let value = params[key];
637
+ if (value.length > 1) throw new Error(`Parameter "${key}" must have only a single value`);
638
+ value = value[0];
639
+ if (key === "client_max_window_bits") {
640
+ if (value !== true) {
641
+ const num = +value;
642
+ if (!Number.isInteger(num) || num < 8 || num > 15) throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
643
+ value = num;
644
+ } else if (!this._isServer) throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
645
+ } else if (key === "server_max_window_bits") {
646
+ const num = +value;
647
+ if (!Number.isInteger(num) || num < 8 || num > 15) throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
648
+ value = num;
649
+ } else if (key === "client_no_context_takeover" || key === "server_no_context_takeover") {
650
+ if (value !== true) throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
651
+ } else throw new Error(`Unknown parameter "${key}"`);
652
+ params[key] = value;
653
+ });
654
+ });
655
+ return configurations;
656
+ }
657
+ /**
658
+ * Decompress data. Concurrency limited.
659
+ *
660
+ * @param {Buffer} data Compressed data
661
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
662
+ * @param {Function} callback Callback
663
+ * @public
664
+ */
665
+ decompress(data, fin, callback) {
666
+ zlibLimiter.add((done) => {
667
+ this._decompress(data, fin, (err, result) => {
668
+ done();
669
+ callback(err, result);
670
+ });
671
+ });
672
+ }
673
+ /**
674
+ * Compress data. Concurrency limited.
675
+ *
676
+ * @param {(Buffer|String)} data Data to compress
677
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
678
+ * @param {Function} callback Callback
679
+ * @public
680
+ */
681
+ compress(data, fin, callback) {
682
+ zlibLimiter.add((done) => {
683
+ this._compress(data, fin, (err, result) => {
684
+ done();
685
+ callback(err, result);
686
+ });
687
+ });
688
+ }
689
+ /**
690
+ * Decompress data.
691
+ *
692
+ * @param {Buffer} data Compressed data
693
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
694
+ * @param {Function} callback Callback
695
+ * @private
696
+ */
697
+ _decompress(data, fin, callback) {
698
+ const endpoint = this._isServer ? "client" : "server";
699
+ if (!this._inflate) {
700
+ const key = `${endpoint}_max_window_bits`;
701
+ const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
702
+ this._inflate = zlib.createInflateRaw({
703
+ ...this._options.zlibInflateOptions,
704
+ windowBits
705
+ });
706
+ this._inflate[kPerMessageDeflate] = this;
707
+ this._inflate[kTotalLength] = 0;
708
+ this._inflate[kBuffers] = [];
709
+ this._inflate.on("error", inflateOnError);
710
+ this._inflate.on("data", inflateOnData);
711
+ }
712
+ this._inflate[kCallback] = callback;
713
+ this._inflate.write(data);
714
+ if (fin) this._inflate.write(TRAILER);
715
+ this._inflate.flush(() => {
716
+ const err = this._inflate[kError];
717
+ if (err) {
718
+ this._inflate.close();
719
+ this._inflate = null;
720
+ callback(err);
721
+ return;
722
+ }
723
+ const data = bufferUtil.concat(this._inflate[kBuffers], this._inflate[kTotalLength]);
724
+ if (this._inflate._readableState.endEmitted) {
725
+ this._inflate.close();
726
+ this._inflate = null;
727
+ } else {
728
+ this._inflate[kTotalLength] = 0;
729
+ this._inflate[kBuffers] = [];
730
+ if (fin && this.params[`${endpoint}_no_context_takeover`]) this._inflate.reset();
731
+ }
732
+ callback(null, data);
733
+ });
734
+ }
735
+ /**
736
+ * Compress data.
737
+ *
738
+ * @param {(Buffer|String)} data Data to compress
739
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
740
+ * @param {Function} callback Callback
741
+ * @private
742
+ */
743
+ _compress(data, fin, callback) {
744
+ const endpoint = this._isServer ? "server" : "client";
745
+ if (!this._deflate) {
746
+ const key = `${endpoint}_max_window_bits`;
747
+ const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
748
+ this._deflate = zlib.createDeflateRaw({
749
+ ...this._options.zlibDeflateOptions,
750
+ windowBits
751
+ });
752
+ this._deflate[kTotalLength] = 0;
753
+ this._deflate[kBuffers] = [];
754
+ this._deflate.on("data", deflateOnData);
755
+ }
756
+ this._deflate[kCallback] = callback;
757
+ this._deflate.write(data);
758
+ this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
759
+ if (!this._deflate) return;
760
+ let data = bufferUtil.concat(this._deflate[kBuffers], this._deflate[kTotalLength]);
761
+ if (fin) data = new FastBuffer(data.buffer, data.byteOffset, data.length - 4);
762
+ this._deflate[kCallback] = null;
763
+ this._deflate[kTotalLength] = 0;
764
+ this._deflate[kBuffers] = [];
765
+ if (fin && this.params[`${endpoint}_no_context_takeover`]) this._deflate.reset();
766
+ callback(null, data);
767
+ });
768
+ }
769
+ };
770
+ module.exports = PerMessageDeflate;
771
+ /**
772
+ * The listener of the `zlib.DeflateRaw` stream `'data'` event.
773
+ *
774
+ * @param {Buffer} chunk A chunk of data
775
+ * @private
776
+ */
777
+ function deflateOnData(chunk) {
778
+ this[kBuffers].push(chunk);
779
+ this[kTotalLength] += chunk.length;
780
+ }
781
+ /**
782
+ * The listener of the `zlib.InflateRaw` stream `'data'` event.
783
+ *
784
+ * @param {Buffer} chunk A chunk of data
785
+ * @private
786
+ */
787
+ function inflateOnData(chunk) {
788
+ this[kTotalLength] += chunk.length;
789
+ if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) {
790
+ this[kBuffers].push(chunk);
791
+ return;
792
+ }
793
+ this[kError] = /* @__PURE__ */ new RangeError("Max payload size exceeded");
794
+ this[kError].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH";
795
+ this[kError][kStatusCode] = 1009;
796
+ this.removeListener("data", inflateOnData);
797
+ this.reset();
798
+ }
799
+ /**
800
+ * The listener of the `zlib.InflateRaw` stream `'error'` event.
801
+ *
802
+ * @param {Error} err The emitted error
803
+ * @private
804
+ */
805
+ function inflateOnError(err) {
806
+ this[kPerMessageDeflate]._inflate = null;
807
+ if (this[kError]) {
808
+ this[kCallback](this[kError]);
809
+ return;
810
+ }
811
+ err[kStatusCode] = 1007;
812
+ this[kCallback](err);
813
+ }
814
+ }));
815
+
816
+ //#endregion
817
+ //#region ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/validation.js
818
+ var require_validation = /* @__PURE__ */ __commonJSMin(((exports, module) => {
819
+ const { isUtf8 } = __require("buffer");
820
+ const { hasBlob } = require_constants();
821
+ const tokenChars = [
822
+ 0,
823
+ 0,
824
+ 0,
825
+ 0,
826
+ 0,
827
+ 0,
828
+ 0,
829
+ 0,
830
+ 0,
831
+ 0,
832
+ 0,
833
+ 0,
834
+ 0,
835
+ 0,
836
+ 0,
837
+ 0,
838
+ 0,
839
+ 0,
840
+ 0,
841
+ 0,
842
+ 0,
843
+ 0,
844
+ 0,
845
+ 0,
846
+ 0,
847
+ 0,
848
+ 0,
849
+ 0,
850
+ 0,
851
+ 0,
852
+ 0,
853
+ 0,
854
+ 0,
855
+ 1,
856
+ 0,
857
+ 1,
858
+ 1,
859
+ 1,
860
+ 1,
861
+ 1,
862
+ 0,
863
+ 0,
864
+ 1,
865
+ 1,
866
+ 0,
867
+ 1,
868
+ 1,
869
+ 0,
870
+ 1,
871
+ 1,
872
+ 1,
873
+ 1,
874
+ 1,
875
+ 1,
876
+ 1,
877
+ 1,
878
+ 1,
879
+ 1,
880
+ 0,
881
+ 0,
882
+ 0,
883
+ 0,
884
+ 0,
885
+ 0,
886
+ 0,
887
+ 1,
888
+ 1,
889
+ 1,
890
+ 1,
891
+ 1,
892
+ 1,
893
+ 1,
894
+ 1,
895
+ 1,
896
+ 1,
897
+ 1,
898
+ 1,
899
+ 1,
900
+ 1,
901
+ 1,
902
+ 1,
903
+ 1,
904
+ 1,
905
+ 1,
906
+ 1,
907
+ 1,
908
+ 1,
909
+ 1,
910
+ 1,
911
+ 1,
912
+ 1,
913
+ 0,
914
+ 0,
915
+ 0,
916
+ 1,
917
+ 1,
918
+ 1,
919
+ 1,
920
+ 1,
921
+ 1,
922
+ 1,
923
+ 1,
924
+ 1,
925
+ 1,
926
+ 1,
927
+ 1,
928
+ 1,
929
+ 1,
930
+ 1,
931
+ 1,
932
+ 1,
933
+ 1,
934
+ 1,
935
+ 1,
936
+ 1,
937
+ 1,
938
+ 1,
939
+ 1,
940
+ 1,
941
+ 1,
942
+ 1,
943
+ 1,
944
+ 1,
945
+ 0,
946
+ 1,
947
+ 0,
948
+ 1,
949
+ 0
950
+ ];
951
+ /**
952
+ * Checks if a status code is allowed in a close frame.
953
+ *
954
+ * @param {Number} code The status code
955
+ * @return {Boolean} `true` if the status code is valid, else `false`
956
+ * @public
957
+ */
958
+ function isValidStatusCode(code) {
959
+ return code >= 1e3 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006 || code >= 3e3 && code <= 4999;
960
+ }
961
+ /**
962
+ * Checks if a given buffer contains only correct UTF-8.
963
+ * Ported from https://www.cl.cam.ac.uk/%7Emgk25/ucs/utf8_check.c by
964
+ * Markus Kuhn.
965
+ *
966
+ * @param {Buffer} buf The buffer to check
967
+ * @return {Boolean} `true` if `buf` contains only correct UTF-8, else `false`
968
+ * @public
969
+ */
970
+ function _isValidUTF8(buf) {
971
+ const len = buf.length;
972
+ let i = 0;
973
+ while (i < len) if ((buf[i] & 128) === 0) i++;
974
+ else if ((buf[i] & 224) === 192) {
975
+ if (i + 1 === len || (buf[i + 1] & 192) !== 128 || (buf[i] & 254) === 192) return false;
976
+ i += 2;
977
+ } else if ((buf[i] & 240) === 224) {
978
+ if (i + 2 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || buf[i] === 224 && (buf[i + 1] & 224) === 128 || buf[i] === 237 && (buf[i + 1] & 224) === 160) return false;
979
+ i += 3;
980
+ } else if ((buf[i] & 248) === 240) {
981
+ if (i + 3 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || (buf[i + 3] & 192) !== 128 || buf[i] === 240 && (buf[i + 1] & 240) === 128 || buf[i] === 244 && buf[i + 1] > 143 || buf[i] > 244) return false;
982
+ i += 4;
983
+ } else return false;
984
+ return true;
985
+ }
986
+ /**
987
+ * Determines whether a value is a `Blob`.
988
+ *
989
+ * @param {*} value The value to be tested
990
+ * @return {Boolean} `true` if `value` is a `Blob`, else `false`
991
+ * @private
992
+ */
993
+ function isBlob(value) {
994
+ return hasBlob && typeof value === "object" && typeof value.arrayBuffer === "function" && typeof value.type === "string" && typeof value.stream === "function" && (value[Symbol.toStringTag] === "Blob" || value[Symbol.toStringTag] === "File");
995
+ }
996
+ module.exports = {
997
+ isBlob,
998
+ isValidStatusCode,
999
+ isValidUTF8: _isValidUTF8,
1000
+ tokenChars
1001
+ };
1002
+ if (isUtf8) module.exports.isValidUTF8 = function(buf) {
1003
+ return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
1004
+ };
1005
+ else if (!process.env.WS_NO_UTF_8_VALIDATE) try {
1006
+ const isValidUTF8 = __require("utf-8-validate");
1007
+ module.exports.isValidUTF8 = function(buf) {
1008
+ return buf.length < 32 ? _isValidUTF8(buf) : isValidUTF8(buf);
1009
+ };
1010
+ } catch (e) {}
1011
+ }));
1012
+
1013
+ //#endregion
1014
+ //#region ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/receiver.js
1015
+ var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1016
+ const { Writable } = __require("stream");
1017
+ const PerMessageDeflate = require_permessage_deflate();
1018
+ const { BINARY_TYPES, EMPTY_BUFFER, kStatusCode, kWebSocket } = require_constants();
1019
+ const { concat, toArrayBuffer, unmask } = require_buffer_util();
1020
+ const { isValidStatusCode, isValidUTF8 } = require_validation();
1021
+ const FastBuffer = Buffer[Symbol.species];
1022
+ const GET_INFO = 0;
1023
+ const GET_PAYLOAD_LENGTH_16 = 1;
1024
+ const GET_PAYLOAD_LENGTH_64 = 2;
1025
+ const GET_MASK = 3;
1026
+ const GET_DATA = 4;
1027
+ const INFLATING = 5;
1028
+ const DEFER_EVENT = 6;
1029
+ /**
1030
+ * HyBi Receiver implementation.
1031
+ *
1032
+ * @extends Writable
1033
+ */
1034
+ var Receiver = class extends Writable {
1035
+ /**
1036
+ * Creates a Receiver instance.
1037
+ *
1038
+ * @param {Object} [options] Options object
1039
+ * @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
1040
+ * any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
1041
+ * multiple times in the same tick
1042
+ * @param {String} [options.binaryType=nodebuffer] The type for binary data
1043
+ * @param {Object} [options.extensions] An object containing the negotiated
1044
+ * extensions
1045
+ * @param {Boolean} [options.isServer=false] Specifies whether to operate in
1046
+ * client or server mode
1047
+ * @param {Number} [options.maxBufferedChunks=0] The maximum number of
1048
+ * buffered data chunks
1049
+ * @param {Number} [options.maxFragments=0] The maximum number of message
1050
+ * fragments
1051
+ * @param {Number} [options.maxPayload=0] The maximum allowed message length
1052
+ * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
1053
+ * not to skip UTF-8 validation for text and close messages
1054
+ */
1055
+ constructor(options = {}) {
1056
+ super();
1057
+ this._allowSynchronousEvents = options.allowSynchronousEvents !== void 0 ? options.allowSynchronousEvents : true;
1058
+ this._binaryType = options.binaryType || BINARY_TYPES[0];
1059
+ this._extensions = options.extensions || {};
1060
+ this._isServer = !!options.isServer;
1061
+ this._maxBufferedChunks = options.maxBufferedChunks | 0;
1062
+ this._maxFragments = options.maxFragments | 0;
1063
+ this._maxPayload = options.maxPayload | 0;
1064
+ this._skipUTF8Validation = !!options.skipUTF8Validation;
1065
+ this[kWebSocket] = void 0;
1066
+ this._bufferedBytes = 0;
1067
+ this._buffers = [];
1068
+ this._compressed = false;
1069
+ this._payloadLength = 0;
1070
+ this._mask = void 0;
1071
+ this._fragmented = 0;
1072
+ this._masked = false;
1073
+ this._fin = false;
1074
+ this._opcode = 0;
1075
+ this._totalPayloadLength = 0;
1076
+ this._messageLength = 0;
1077
+ this._fragments = [];
1078
+ this._errored = false;
1079
+ this._loop = false;
1080
+ this._state = GET_INFO;
1081
+ }
1082
+ /**
1083
+ * Implements `Writable.prototype._write()`.
1084
+ *
1085
+ * @param {Buffer} chunk The chunk of data to write
1086
+ * @param {String} encoding The character encoding of `chunk`
1087
+ * @param {Function} cb Callback
1088
+ * @private
1089
+ */
1090
+ _write(chunk, encoding, cb) {
1091
+ if (this._opcode === 8 && this._state == GET_INFO) return cb();
1092
+ if (this._maxBufferedChunks > 0 && this._buffers.length >= this._maxBufferedChunks) {
1093
+ cb(this.createError(RangeError, "Too many buffered chunks", false, 1008, "WS_ERR_TOO_MANY_BUFFERED_PARTS"));
1094
+ return;
1095
+ }
1096
+ this._bufferedBytes += chunk.length;
1097
+ this._buffers.push(chunk);
1098
+ this.startLoop(cb);
1099
+ }
1100
+ /**
1101
+ * Consumes `n` bytes from the buffered data.
1102
+ *
1103
+ * @param {Number} n The number of bytes to consume
1104
+ * @return {Buffer} The consumed bytes
1105
+ * @private
1106
+ */
1107
+ consume(n) {
1108
+ this._bufferedBytes -= n;
1109
+ if (n === this._buffers[0].length) return this._buffers.shift();
1110
+ if (n < this._buffers[0].length) {
1111
+ const buf = this._buffers[0];
1112
+ this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
1113
+ return new FastBuffer(buf.buffer, buf.byteOffset, n);
1114
+ }
1115
+ const dst = Buffer.allocUnsafe(n);
1116
+ do {
1117
+ const buf = this._buffers[0];
1118
+ const offset = dst.length - n;
1119
+ if (n >= buf.length) dst.set(this._buffers.shift(), offset);
1120
+ else {
1121
+ dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
1122
+ this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
1123
+ }
1124
+ n -= buf.length;
1125
+ } while (n > 0);
1126
+ return dst;
1127
+ }
1128
+ /**
1129
+ * Starts the parsing loop.
1130
+ *
1131
+ * @param {Function} cb Callback
1132
+ * @private
1133
+ */
1134
+ startLoop(cb) {
1135
+ this._loop = true;
1136
+ do
1137
+ switch (this._state) {
1138
+ case GET_INFO:
1139
+ this.getInfo(cb);
1140
+ break;
1141
+ case GET_PAYLOAD_LENGTH_16:
1142
+ this.getPayloadLength16(cb);
1143
+ break;
1144
+ case GET_PAYLOAD_LENGTH_64:
1145
+ this.getPayloadLength64(cb);
1146
+ break;
1147
+ case GET_MASK:
1148
+ this.getMask();
1149
+ break;
1150
+ case GET_DATA:
1151
+ this.getData(cb);
1152
+ break;
1153
+ case INFLATING:
1154
+ case DEFER_EVENT:
1155
+ this._loop = false;
1156
+ return;
1157
+ }
1158
+ while (this._loop);
1159
+ if (!this._errored) cb();
1160
+ }
1161
+ /**
1162
+ * Reads the first two bytes of a frame.
1163
+ *
1164
+ * @param {Function} cb Callback
1165
+ * @private
1166
+ */
1167
+ getInfo(cb) {
1168
+ if (this._bufferedBytes < 2) {
1169
+ this._loop = false;
1170
+ return;
1171
+ }
1172
+ const buf = this.consume(2);
1173
+ if ((buf[0] & 48) !== 0) {
1174
+ cb(this.createError(RangeError, "RSV2 and RSV3 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_2_3"));
1175
+ return;
1176
+ }
1177
+ const compressed = (buf[0] & 64) === 64;
1178
+ if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
1179
+ cb(this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1"));
1180
+ return;
1181
+ }
1182
+ this._fin = (buf[0] & 128) === 128;
1183
+ this._opcode = buf[0] & 15;
1184
+ this._payloadLength = buf[1] & 127;
1185
+ if (this._opcode === 0) {
1186
+ if (compressed) {
1187
+ cb(this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1"));
1188
+ return;
1189
+ }
1190
+ if (!this._fragmented) {
1191
+ cb(this.createError(RangeError, "invalid opcode 0", true, 1002, "WS_ERR_INVALID_OPCODE"));
1192
+ return;
1193
+ }
1194
+ this._opcode = this._fragmented;
1195
+ } else if (this._opcode === 1 || this._opcode === 2) {
1196
+ if (this._fragmented) {
1197
+ cb(this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE"));
1198
+ return;
1199
+ }
1200
+ this._compressed = compressed;
1201
+ } else if (this._opcode > 7 && this._opcode < 11) {
1202
+ if (!this._fin) {
1203
+ cb(this.createError(RangeError, "FIN must be set", true, 1002, "WS_ERR_EXPECTED_FIN"));
1204
+ return;
1205
+ }
1206
+ if (compressed) {
1207
+ cb(this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1"));
1208
+ return;
1209
+ }
1210
+ if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1) {
1211
+ cb(this.createError(RangeError, `invalid payload length ${this._payloadLength}`, true, 1002, "WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH"));
1212
+ return;
1213
+ }
1214
+ } else {
1215
+ cb(this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE"));
1216
+ return;
1217
+ }
1218
+ if (!this._fin && !this._fragmented) this._fragmented = this._opcode;
1219
+ this._masked = (buf[1] & 128) === 128;
1220
+ if (this._isServer) {
1221
+ if (!this._masked) {
1222
+ cb(this.createError(RangeError, "MASK must be set", true, 1002, "WS_ERR_EXPECTED_MASK"));
1223
+ return;
1224
+ }
1225
+ } else if (this._masked) {
1226
+ cb(this.createError(RangeError, "MASK must be clear", true, 1002, "WS_ERR_UNEXPECTED_MASK"));
1227
+ return;
1228
+ }
1229
+ if (this._payloadLength === 126) this._state = GET_PAYLOAD_LENGTH_16;
1230
+ else if (this._payloadLength === 127) this._state = GET_PAYLOAD_LENGTH_64;
1231
+ else this.haveLength(cb);
1232
+ }
1233
+ /**
1234
+ * Gets extended payload length (7+16).
1235
+ *
1236
+ * @param {Function} cb Callback
1237
+ * @private
1238
+ */
1239
+ getPayloadLength16(cb) {
1240
+ if (this._bufferedBytes < 2) {
1241
+ this._loop = false;
1242
+ return;
1243
+ }
1244
+ this._payloadLength = this.consume(2).readUInt16BE(0);
1245
+ this.haveLength(cb);
1246
+ }
1247
+ /**
1248
+ * Gets extended payload length (7+64).
1249
+ *
1250
+ * @param {Function} cb Callback
1251
+ * @private
1252
+ */
1253
+ getPayloadLength64(cb) {
1254
+ if (this._bufferedBytes < 8) {
1255
+ this._loop = false;
1256
+ return;
1257
+ }
1258
+ const buf = this.consume(8);
1259
+ const num = buf.readUInt32BE(0);
1260
+ if (num > Math.pow(2, 21) - 1) {
1261
+ cb(this.createError(RangeError, "Unsupported WebSocket frame: payload length > 2^53 - 1", false, 1009, "WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH"));
1262
+ return;
1263
+ }
1264
+ this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
1265
+ this.haveLength(cb);
1266
+ }
1267
+ /**
1268
+ * Payload length has been read.
1269
+ *
1270
+ * @param {Function} cb Callback
1271
+ * @private
1272
+ */
1273
+ haveLength(cb) {
1274
+ if (this._payloadLength && this._opcode < 8) {
1275
+ this._totalPayloadLength += this._payloadLength;
1276
+ if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
1277
+ cb(this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"));
1278
+ return;
1279
+ }
1280
+ }
1281
+ if (this._masked) this._state = GET_MASK;
1282
+ else this._state = GET_DATA;
1283
+ }
1284
+ /**
1285
+ * Reads mask bytes.
1286
+ *
1287
+ * @private
1288
+ */
1289
+ getMask() {
1290
+ if (this._bufferedBytes < 4) {
1291
+ this._loop = false;
1292
+ return;
1293
+ }
1294
+ this._mask = this.consume(4);
1295
+ this._state = GET_DATA;
1296
+ }
1297
+ /**
1298
+ * Reads data bytes.
1299
+ *
1300
+ * @param {Function} cb Callback
1301
+ * @private
1302
+ */
1303
+ getData(cb) {
1304
+ let data = EMPTY_BUFFER;
1305
+ if (this._payloadLength) {
1306
+ if (this._bufferedBytes < this._payloadLength) {
1307
+ this._loop = false;
1308
+ return;
1309
+ }
1310
+ data = this.consume(this._payloadLength);
1311
+ if (this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0) unmask(data, this._mask);
1312
+ }
1313
+ if (this._opcode > 7) {
1314
+ this.controlMessage(data, cb);
1315
+ return;
1316
+ }
1317
+ if (this._compressed) {
1318
+ this._state = INFLATING;
1319
+ this.decompress(data, cb);
1320
+ return;
1321
+ }
1322
+ if (data.length) {
1323
+ if (this._maxFragments > 0 && this._fragments.length >= this._maxFragments) {
1324
+ cb(this.createError(RangeError, "Too many message fragments", false, 1008, "WS_ERR_TOO_MANY_BUFFERED_PARTS"));
1325
+ return;
1326
+ }
1327
+ this._messageLength = this._totalPayloadLength;
1328
+ this._fragments.push(data);
1329
+ }
1330
+ this.dataMessage(cb);
1331
+ }
1332
+ /**
1333
+ * Decompresses data.
1334
+ *
1335
+ * @param {Buffer} data Compressed data
1336
+ * @param {Function} cb Callback
1337
+ * @private
1338
+ */
1339
+ decompress(data, cb) {
1340
+ this._extensions[PerMessageDeflate.extensionName].decompress(data, this._fin, (err, buf) => {
1341
+ if (err) return cb(err);
1342
+ if (buf.length) {
1343
+ this._messageLength += buf.length;
1344
+ if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
1345
+ cb(this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"));
1346
+ return;
1347
+ }
1348
+ if (this._maxFragments > 0 && this._fragments.length >= this._maxFragments) {
1349
+ cb(this.createError(RangeError, "Too many message fragments", false, 1008, "WS_ERR_TOO_MANY_BUFFERED_PARTS"));
1350
+ return;
1351
+ }
1352
+ this._fragments.push(buf);
1353
+ }
1354
+ this.dataMessage(cb);
1355
+ if (this._state === GET_INFO) this.startLoop(cb);
1356
+ });
1357
+ }
1358
+ /**
1359
+ * Handles a data message.
1360
+ *
1361
+ * @param {Function} cb Callback
1362
+ * @private
1363
+ */
1364
+ dataMessage(cb) {
1365
+ if (!this._fin) {
1366
+ this._state = GET_INFO;
1367
+ return;
1368
+ }
1369
+ const messageLength = this._messageLength;
1370
+ const fragments = this._fragments;
1371
+ this._totalPayloadLength = 0;
1372
+ this._messageLength = 0;
1373
+ this._fragmented = 0;
1374
+ this._fragments = [];
1375
+ if (this._opcode === 2) {
1376
+ let data;
1377
+ if (this._binaryType === "nodebuffer") data = concat(fragments, messageLength);
1378
+ else if (this._binaryType === "arraybuffer") data = toArrayBuffer(concat(fragments, messageLength));
1379
+ else if (this._binaryType === "blob") data = new Blob(fragments);
1380
+ else data = fragments;
1381
+ if (this._allowSynchronousEvents) {
1382
+ this.emit("message", data, true);
1383
+ this._state = GET_INFO;
1384
+ } else {
1385
+ this._state = DEFER_EVENT;
1386
+ setImmediate(() => {
1387
+ this.emit("message", data, true);
1388
+ this._state = GET_INFO;
1389
+ this.startLoop(cb);
1390
+ });
1391
+ }
1392
+ } else {
1393
+ const buf = concat(fragments, messageLength);
1394
+ if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
1395
+ cb(this.createError(Error, "invalid UTF-8 sequence", true, 1007, "WS_ERR_INVALID_UTF8"));
1396
+ return;
1397
+ }
1398
+ if (this._state === INFLATING || this._allowSynchronousEvents) {
1399
+ this.emit("message", buf, false);
1400
+ this._state = GET_INFO;
1401
+ } else {
1402
+ this._state = DEFER_EVENT;
1403
+ setImmediate(() => {
1404
+ this.emit("message", buf, false);
1405
+ this._state = GET_INFO;
1406
+ this.startLoop(cb);
1407
+ });
1408
+ }
1409
+ }
1410
+ }
1411
+ /**
1412
+ * Handles a control message.
1413
+ *
1414
+ * @param {Buffer} data Data to handle
1415
+ * @return {(Error|RangeError|undefined)} A possible error
1416
+ * @private
1417
+ */
1418
+ controlMessage(data, cb) {
1419
+ if (this._opcode === 8) {
1420
+ if (data.length === 0) {
1421
+ this._loop = false;
1422
+ this.emit("conclude", 1005, EMPTY_BUFFER);
1423
+ this.end();
1424
+ } else {
1425
+ const code = data.readUInt16BE(0);
1426
+ if (!isValidStatusCode(code)) {
1427
+ cb(this.createError(RangeError, `invalid status code ${code}`, true, 1002, "WS_ERR_INVALID_CLOSE_CODE"));
1428
+ return;
1429
+ }
1430
+ const buf = new FastBuffer(data.buffer, data.byteOffset + 2, data.length - 2);
1431
+ if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
1432
+ cb(this.createError(Error, "invalid UTF-8 sequence", true, 1007, "WS_ERR_INVALID_UTF8"));
1433
+ return;
1434
+ }
1435
+ this._loop = false;
1436
+ this.emit("conclude", code, buf);
1437
+ this.end();
1438
+ }
1439
+ this._state = GET_INFO;
1440
+ return;
1441
+ }
1442
+ if (this._allowSynchronousEvents) {
1443
+ this.emit(this._opcode === 9 ? "ping" : "pong", data);
1444
+ this._state = GET_INFO;
1445
+ } else {
1446
+ this._state = DEFER_EVENT;
1447
+ setImmediate(() => {
1448
+ this.emit(this._opcode === 9 ? "ping" : "pong", data);
1449
+ this._state = GET_INFO;
1450
+ this.startLoop(cb);
1451
+ });
1452
+ }
1453
+ }
1454
+ /**
1455
+ * Builds an error object.
1456
+ *
1457
+ * @param {function(new:Error|RangeError)} ErrorCtor The error constructor
1458
+ * @param {String} message The error message
1459
+ * @param {Boolean} prefix Specifies whether or not to add a default prefix to
1460
+ * `message`
1461
+ * @param {Number} statusCode The status code
1462
+ * @param {String} errorCode The exposed error code
1463
+ * @return {(Error|RangeError)} The error
1464
+ * @private
1465
+ */
1466
+ createError(ErrorCtor, message, prefix, statusCode, errorCode) {
1467
+ this._loop = false;
1468
+ this._errored = true;
1469
+ const err = new ErrorCtor(prefix ? `Invalid WebSocket frame: ${message}` : message);
1470
+ Error.captureStackTrace(err, this.createError);
1471
+ err.code = errorCode;
1472
+ err[kStatusCode] = statusCode;
1473
+ return err;
1474
+ }
1475
+ };
1476
+ module.exports = Receiver;
1477
+ }));
1478
+
1479
+ //#endregion
1480
+ //#region ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/sender.js
1481
+ var require_sender = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1482
+ const { Duplex: Duplex$4 } = __require("stream");
1483
+ const { randomFillSync } = __require("crypto");
1484
+ const { types: { isUint8Array } } = __require("util");
1485
+ const PerMessageDeflate = require_permessage_deflate();
1486
+ const { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants();
1487
+ const { isBlob, isValidStatusCode } = require_validation();
1488
+ const { mask: applyMask, toBuffer } = require_buffer_util();
1489
+ const kByteLength = Symbol("kByteLength");
1490
+ const maskBuffer = Buffer.alloc(4);
1491
+ const RANDOM_POOL_SIZE = 8 * 1024;
1492
+ let randomPool;
1493
+ let randomPoolPointer = RANDOM_POOL_SIZE;
1494
+ const DEFAULT = 0;
1495
+ const DEFLATING = 1;
1496
+ const GET_BLOB_DATA = 2;
1497
+ /**
1498
+ * HyBi Sender implementation.
1499
+ */
1500
+ var Sender = class Sender {
1501
+ /**
1502
+ * Creates a Sender instance.
1503
+ *
1504
+ * @param {Duplex} socket The connection socket
1505
+ * @param {Object} [extensions] An object containing the negotiated extensions
1506
+ * @param {Function} [generateMask] The function used to generate the masking
1507
+ * key
1508
+ */
1509
+ constructor(socket, extensions, generateMask) {
1510
+ this._extensions = extensions || {};
1511
+ if (generateMask) {
1512
+ this._generateMask = generateMask;
1513
+ this._maskBuffer = Buffer.alloc(4);
1514
+ }
1515
+ this._socket = socket;
1516
+ this._firstFragment = true;
1517
+ this._compress = false;
1518
+ this._bufferedBytes = 0;
1519
+ this._queue = [];
1520
+ this._state = DEFAULT;
1521
+ this.onerror = NOOP;
1522
+ this[kWebSocket] = void 0;
1523
+ }
1524
+ /**
1525
+ * Frames a piece of data according to the HyBi WebSocket protocol.
1526
+ *
1527
+ * @param {(Buffer|String)} data The data to frame
1528
+ * @param {Object} options Options object
1529
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1530
+ * FIN bit
1531
+ * @param {Function} [options.generateMask] The function used to generate the
1532
+ * masking key
1533
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1534
+ * `data`
1535
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1536
+ * key
1537
+ * @param {Number} options.opcode The opcode
1538
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1539
+ * modified
1540
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1541
+ * RSV1 bit
1542
+ * @return {(Buffer|String)[]} The framed data
1543
+ * @public
1544
+ */
1545
+ static frame(data, options) {
1546
+ let mask;
1547
+ let merge = false;
1548
+ let offset = 2;
1549
+ let skipMasking = false;
1550
+ if (options.mask) {
1551
+ mask = options.maskBuffer || maskBuffer;
1552
+ if (options.generateMask) options.generateMask(mask);
1553
+ else {
1554
+ if (randomPoolPointer === RANDOM_POOL_SIZE) {
1555
+ /* istanbul ignore else */
1556
+ if (randomPool === void 0) randomPool = Buffer.alloc(RANDOM_POOL_SIZE);
1557
+ randomFillSync(randomPool, 0, RANDOM_POOL_SIZE);
1558
+ randomPoolPointer = 0;
1559
+ }
1560
+ mask[0] = randomPool[randomPoolPointer++];
1561
+ mask[1] = randomPool[randomPoolPointer++];
1562
+ mask[2] = randomPool[randomPoolPointer++];
1563
+ mask[3] = randomPool[randomPoolPointer++];
1564
+ }
1565
+ skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
1566
+ offset = 6;
1567
+ }
1568
+ let dataLength;
1569
+ if (typeof data === "string") if ((!options.mask || skipMasking) && options[kByteLength] !== void 0) dataLength = options[kByteLength];
1570
+ else {
1571
+ data = Buffer.from(data);
1572
+ dataLength = data.length;
1573
+ }
1574
+ else {
1575
+ dataLength = data.length;
1576
+ merge = options.mask && options.readOnly && !skipMasking;
1577
+ }
1578
+ let payloadLength = dataLength;
1579
+ if (dataLength >= 65536) {
1580
+ offset += 8;
1581
+ payloadLength = 127;
1582
+ } else if (dataLength > 125) {
1583
+ offset += 2;
1584
+ payloadLength = 126;
1585
+ }
1586
+ const target = Buffer.allocUnsafe(merge ? dataLength + offset : offset);
1587
+ target[0] = options.fin ? options.opcode | 128 : options.opcode;
1588
+ if (options.rsv1) target[0] |= 64;
1589
+ target[1] = payloadLength;
1590
+ if (payloadLength === 126) target.writeUInt16BE(dataLength, 2);
1591
+ else if (payloadLength === 127) {
1592
+ target[2] = target[3] = 0;
1593
+ target.writeUIntBE(dataLength, 4, 6);
1594
+ }
1595
+ if (!options.mask) return [target, data];
1596
+ target[1] |= 128;
1597
+ target[offset - 4] = mask[0];
1598
+ target[offset - 3] = mask[1];
1599
+ target[offset - 2] = mask[2];
1600
+ target[offset - 1] = mask[3];
1601
+ if (skipMasking) return [target, data];
1602
+ if (merge) {
1603
+ applyMask(data, mask, target, offset, dataLength);
1604
+ return [target];
1605
+ }
1606
+ applyMask(data, mask, data, 0, dataLength);
1607
+ return [target, data];
1608
+ }
1609
+ /**
1610
+ * Sends a close message to the other peer.
1611
+ *
1612
+ * @param {Number} [code] The status code component of the body
1613
+ * @param {(String|Buffer)} [data] The message component of the body
1614
+ * @param {Boolean} [mask=false] Specifies whether or not to mask the message
1615
+ * @param {Function} [cb] Callback
1616
+ * @public
1617
+ */
1618
+ close(code, data, mask, cb) {
1619
+ let buf;
1620
+ if (code === void 0) buf = EMPTY_BUFFER;
1621
+ else if (typeof code !== "number" || !isValidStatusCode(code)) throw new TypeError("First argument must be a valid error code number");
1622
+ else if (data === void 0 || !data.length) {
1623
+ buf = Buffer.allocUnsafe(2);
1624
+ buf.writeUInt16BE(code, 0);
1625
+ } else {
1626
+ const length = Buffer.byteLength(data);
1627
+ if (length > 123) throw new RangeError("The message must not be greater than 123 bytes");
1628
+ buf = Buffer.allocUnsafe(2 + length);
1629
+ buf.writeUInt16BE(code, 0);
1630
+ if (typeof data === "string") buf.write(data, 2);
1631
+ else if (isUint8Array(data)) buf.set(data, 2);
1632
+ else throw new TypeError("Second argument must be a string or a Uint8Array");
1633
+ }
1634
+ const options = {
1635
+ [kByteLength]: buf.length,
1636
+ fin: true,
1637
+ generateMask: this._generateMask,
1638
+ mask,
1639
+ maskBuffer: this._maskBuffer,
1640
+ opcode: 8,
1641
+ readOnly: false,
1642
+ rsv1: false
1643
+ };
1644
+ if (this._state !== DEFAULT) this.enqueue([
1645
+ this.dispatch,
1646
+ buf,
1647
+ false,
1648
+ options,
1649
+ cb
1650
+ ]);
1651
+ else this.sendFrame(Sender.frame(buf, options), cb);
1652
+ }
1653
+ /**
1654
+ * Sends a ping message to the other peer.
1655
+ *
1656
+ * @param {*} data The message to send
1657
+ * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
1658
+ * @param {Function} [cb] Callback
1659
+ * @public
1660
+ */
1661
+ ping(data, mask, cb) {
1662
+ let byteLength;
1663
+ let readOnly;
1664
+ if (typeof data === "string") {
1665
+ byteLength = Buffer.byteLength(data);
1666
+ readOnly = false;
1667
+ } else if (isBlob(data)) {
1668
+ byteLength = data.size;
1669
+ readOnly = false;
1670
+ } else {
1671
+ data = toBuffer(data);
1672
+ byteLength = data.length;
1673
+ readOnly = toBuffer.readOnly;
1674
+ }
1675
+ if (byteLength > 125) throw new RangeError("The data size must not be greater than 125 bytes");
1676
+ const options = {
1677
+ [kByteLength]: byteLength,
1678
+ fin: true,
1679
+ generateMask: this._generateMask,
1680
+ mask,
1681
+ maskBuffer: this._maskBuffer,
1682
+ opcode: 9,
1683
+ readOnly,
1684
+ rsv1: false
1685
+ };
1686
+ if (isBlob(data)) if (this._state !== DEFAULT) this.enqueue([
1687
+ this.getBlobData,
1688
+ data,
1689
+ false,
1690
+ options,
1691
+ cb
1692
+ ]);
1693
+ else this.getBlobData(data, false, options, cb);
1694
+ else if (this._state !== DEFAULT) this.enqueue([
1695
+ this.dispatch,
1696
+ data,
1697
+ false,
1698
+ options,
1699
+ cb
1700
+ ]);
1701
+ else this.sendFrame(Sender.frame(data, options), cb);
1702
+ }
1703
+ /**
1704
+ * Sends a pong message to the other peer.
1705
+ *
1706
+ * @param {*} data The message to send
1707
+ * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
1708
+ * @param {Function} [cb] Callback
1709
+ * @public
1710
+ */
1711
+ pong(data, mask, cb) {
1712
+ let byteLength;
1713
+ let readOnly;
1714
+ if (typeof data === "string") {
1715
+ byteLength = Buffer.byteLength(data);
1716
+ readOnly = false;
1717
+ } else if (isBlob(data)) {
1718
+ byteLength = data.size;
1719
+ readOnly = false;
1720
+ } else {
1721
+ data = toBuffer(data);
1722
+ byteLength = data.length;
1723
+ readOnly = toBuffer.readOnly;
1724
+ }
1725
+ if (byteLength > 125) throw new RangeError("The data size must not be greater than 125 bytes");
1726
+ const options = {
1727
+ [kByteLength]: byteLength,
1728
+ fin: true,
1729
+ generateMask: this._generateMask,
1730
+ mask,
1731
+ maskBuffer: this._maskBuffer,
1732
+ opcode: 10,
1733
+ readOnly,
1734
+ rsv1: false
1735
+ };
1736
+ if (isBlob(data)) if (this._state !== DEFAULT) this.enqueue([
1737
+ this.getBlobData,
1738
+ data,
1739
+ false,
1740
+ options,
1741
+ cb
1742
+ ]);
1743
+ else this.getBlobData(data, false, options, cb);
1744
+ else if (this._state !== DEFAULT) this.enqueue([
1745
+ this.dispatch,
1746
+ data,
1747
+ false,
1748
+ options,
1749
+ cb
1750
+ ]);
1751
+ else this.sendFrame(Sender.frame(data, options), cb);
1752
+ }
1753
+ /**
1754
+ * Sends a data message to the other peer.
1755
+ *
1756
+ * @param {*} data The message to send
1757
+ * @param {Object} options Options object
1758
+ * @param {Boolean} [options.binary=false] Specifies whether `data` is binary
1759
+ * or text
1760
+ * @param {Boolean} [options.compress=false] Specifies whether or not to
1761
+ * compress `data`
1762
+ * @param {Boolean} [options.fin=false] Specifies whether the fragment is the
1763
+ * last one
1764
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1765
+ * `data`
1766
+ * @param {Function} [cb] Callback
1767
+ * @public
1768
+ */
1769
+ send(data, options, cb) {
1770
+ const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
1771
+ let opcode = options.binary ? 2 : 1;
1772
+ let rsv1 = options.compress;
1773
+ let byteLength;
1774
+ let readOnly;
1775
+ if (typeof data === "string") {
1776
+ byteLength = Buffer.byteLength(data);
1777
+ readOnly = false;
1778
+ } else if (isBlob(data)) {
1779
+ byteLength = data.size;
1780
+ readOnly = false;
1781
+ } else {
1782
+ data = toBuffer(data);
1783
+ byteLength = data.length;
1784
+ readOnly = toBuffer.readOnly;
1785
+ }
1786
+ if (this._firstFragment) {
1787
+ this._firstFragment = false;
1788
+ if (rsv1 && perMessageDeflate && perMessageDeflate.params[perMessageDeflate._isServer ? "server_no_context_takeover" : "client_no_context_takeover"]) rsv1 = byteLength >= perMessageDeflate._threshold;
1789
+ this._compress = rsv1;
1790
+ } else {
1791
+ rsv1 = false;
1792
+ opcode = 0;
1793
+ }
1794
+ if (options.fin) this._firstFragment = true;
1795
+ const opts = {
1796
+ [kByteLength]: byteLength,
1797
+ fin: options.fin,
1798
+ generateMask: this._generateMask,
1799
+ mask: options.mask,
1800
+ maskBuffer: this._maskBuffer,
1801
+ opcode,
1802
+ readOnly,
1803
+ rsv1
1804
+ };
1805
+ if (isBlob(data)) if (this._state !== DEFAULT) this.enqueue([
1806
+ this.getBlobData,
1807
+ data,
1808
+ this._compress,
1809
+ opts,
1810
+ cb
1811
+ ]);
1812
+ else this.getBlobData(data, this._compress, opts, cb);
1813
+ else if (this._state !== DEFAULT) this.enqueue([
1814
+ this.dispatch,
1815
+ data,
1816
+ this._compress,
1817
+ opts,
1818
+ cb
1819
+ ]);
1820
+ else this.dispatch(data, this._compress, opts, cb);
1821
+ }
1822
+ /**
1823
+ * Gets the contents of a blob as binary data.
1824
+ *
1825
+ * @param {Blob} blob The blob
1826
+ * @param {Boolean} [compress=false] Specifies whether or not to compress
1827
+ * the data
1828
+ * @param {Object} options Options object
1829
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1830
+ * FIN bit
1831
+ * @param {Function} [options.generateMask] The function used to generate the
1832
+ * masking key
1833
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1834
+ * `data`
1835
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1836
+ * key
1837
+ * @param {Number} options.opcode The opcode
1838
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1839
+ * modified
1840
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1841
+ * RSV1 bit
1842
+ * @param {Function} [cb] Callback
1843
+ * @private
1844
+ */
1845
+ getBlobData(blob, compress, options, cb) {
1846
+ this._bufferedBytes += options[kByteLength];
1847
+ this._state = GET_BLOB_DATA;
1848
+ blob.arrayBuffer().then((arrayBuffer) => {
1849
+ if (this._socket.destroyed) {
1850
+ const err = /* @__PURE__ */ new Error("The socket was closed while the blob was being read");
1851
+ process.nextTick(callCallbacks, this, err, cb);
1852
+ return;
1853
+ }
1854
+ this._bufferedBytes -= options[kByteLength];
1855
+ const data = toBuffer(arrayBuffer);
1856
+ if (!compress) {
1857
+ this._state = DEFAULT;
1858
+ this.sendFrame(Sender.frame(data, options), cb);
1859
+ this.dequeue();
1860
+ } else this.dispatch(data, compress, options, cb);
1861
+ }).catch((err) => {
1862
+ process.nextTick(onError, this, err, cb);
1863
+ });
1864
+ }
1865
+ /**
1866
+ * Dispatches a message.
1867
+ *
1868
+ * @param {(Buffer|String)} data The message to send
1869
+ * @param {Boolean} [compress=false] Specifies whether or not to compress
1870
+ * `data`
1871
+ * @param {Object} options Options object
1872
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1873
+ * FIN bit
1874
+ * @param {Function} [options.generateMask] The function used to generate the
1875
+ * masking key
1876
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1877
+ * `data`
1878
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1879
+ * key
1880
+ * @param {Number} options.opcode The opcode
1881
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1882
+ * modified
1883
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1884
+ * RSV1 bit
1885
+ * @param {Function} [cb] Callback
1886
+ * @private
1887
+ */
1888
+ dispatch(data, compress, options, cb) {
1889
+ if (!compress) {
1890
+ this.sendFrame(Sender.frame(data, options), cb);
1891
+ return;
1892
+ }
1893
+ const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
1894
+ this._bufferedBytes += options[kByteLength];
1895
+ this._state = DEFLATING;
1896
+ perMessageDeflate.compress(data, options.fin, (_, buf) => {
1897
+ if (this._socket.destroyed) {
1898
+ callCallbacks(this, /* @__PURE__ */ new Error("The socket was closed while data was being compressed"), cb);
1899
+ return;
1900
+ }
1901
+ this._bufferedBytes -= options[kByteLength];
1902
+ this._state = DEFAULT;
1903
+ options.readOnly = false;
1904
+ this.sendFrame(Sender.frame(buf, options), cb);
1905
+ this.dequeue();
1906
+ });
1907
+ }
1908
+ /**
1909
+ * Executes queued send operations.
1910
+ *
1911
+ * @private
1912
+ */
1913
+ dequeue() {
1914
+ while (this._state === DEFAULT && this._queue.length) {
1915
+ const params = this._queue.shift();
1916
+ this._bufferedBytes -= params[3][kByteLength];
1917
+ Reflect.apply(params[0], this, params.slice(1));
1918
+ }
1919
+ }
1920
+ /**
1921
+ * Enqueues a send operation.
1922
+ *
1923
+ * @param {Array} params Send operation parameters.
1924
+ * @private
1925
+ */
1926
+ enqueue(params) {
1927
+ this._bufferedBytes += params[3][kByteLength];
1928
+ this._queue.push(params);
1929
+ }
1930
+ /**
1931
+ * Sends a frame.
1932
+ *
1933
+ * @param {(Buffer | String)[]} list The frame to send
1934
+ * @param {Function} [cb] Callback
1935
+ * @private
1936
+ */
1937
+ sendFrame(list, cb) {
1938
+ if (list.length === 2) {
1939
+ this._socket.cork();
1940
+ this._socket.write(list[0]);
1941
+ this._socket.write(list[1], cb);
1942
+ this._socket.uncork();
1943
+ } else this._socket.write(list[0], cb);
1944
+ }
1945
+ };
1946
+ module.exports = Sender;
1947
+ /**
1948
+ * Calls queued callbacks with an error.
1949
+ *
1950
+ * @param {Sender} sender The `Sender` instance
1951
+ * @param {Error} err The error to call the callbacks with
1952
+ * @param {Function} [cb] The first callback
1953
+ * @private
1954
+ */
1955
+ function callCallbacks(sender, err, cb) {
1956
+ if (typeof cb === "function") cb(err);
1957
+ for (let i = 0; i < sender._queue.length; i++) {
1958
+ const params = sender._queue[i];
1959
+ const callback = params[params.length - 1];
1960
+ if (typeof callback === "function") callback(err);
1961
+ }
1962
+ }
1963
+ /**
1964
+ * Handles a `Sender` error.
1965
+ *
1966
+ * @param {Sender} sender The `Sender` instance
1967
+ * @param {Error} err The error
1968
+ * @param {Function} [cb] The first pending callback
1969
+ * @private
1970
+ */
1971
+ function onError(sender, err, cb) {
1972
+ callCallbacks(sender, err, cb);
1973
+ sender.onerror(err);
1974
+ }
1975
+ }));
1976
+
1977
+ //#endregion
1978
+ //#region ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/event-target.js
1979
+ var require_event_target = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1980
+ const { kForOnEventAttribute, kListener } = require_constants();
1981
+ const kCode = Symbol("kCode");
1982
+ const kData = Symbol("kData");
1983
+ const kError = Symbol("kError");
1984
+ const kMessage = Symbol("kMessage");
1985
+ const kReason = Symbol("kReason");
1986
+ const kTarget = Symbol("kTarget");
1987
+ const kType = Symbol("kType");
1988
+ const kWasClean = Symbol("kWasClean");
1989
+ /**
1990
+ * Class representing an event.
1991
+ */
1992
+ var Event = class {
1993
+ /**
1994
+ * Create a new `Event`.
1995
+ *
1996
+ * @param {String} type The name of the event
1997
+ * @throws {TypeError} If the `type` argument is not specified
1998
+ */
1999
+ constructor(type) {
2000
+ this[kTarget] = null;
2001
+ this[kType] = type;
2002
+ }
2003
+ /**
2004
+ * @type {*}
2005
+ */
2006
+ get target() {
2007
+ return this[kTarget];
2008
+ }
2009
+ /**
2010
+ * @type {String}
2011
+ */
2012
+ get type() {
2013
+ return this[kType];
2014
+ }
2015
+ };
2016
+ Object.defineProperty(Event.prototype, "target", { enumerable: true });
2017
+ Object.defineProperty(Event.prototype, "type", { enumerable: true });
2018
+ /**
2019
+ * Class representing a close event.
2020
+ *
2021
+ * @extends Event
2022
+ */
2023
+ var CloseEvent = class extends Event {
2024
+ /**
2025
+ * Create a new `CloseEvent`.
2026
+ *
2027
+ * @param {String} type The name of the event
2028
+ * @param {Object} [options] A dictionary object that allows for setting
2029
+ * attributes via object members of the same name
2030
+ * @param {Number} [options.code=0] The status code explaining why the
2031
+ * connection was closed
2032
+ * @param {String} [options.reason=''] A human-readable string explaining why
2033
+ * the connection was closed
2034
+ * @param {Boolean} [options.wasClean=false] Indicates whether or not the
2035
+ * connection was cleanly closed
2036
+ */
2037
+ constructor(type, options = {}) {
2038
+ super(type);
2039
+ this[kCode] = options.code === void 0 ? 0 : options.code;
2040
+ this[kReason] = options.reason === void 0 ? "" : options.reason;
2041
+ this[kWasClean] = options.wasClean === void 0 ? false : options.wasClean;
2042
+ }
2043
+ /**
2044
+ * @type {Number}
2045
+ */
2046
+ get code() {
2047
+ return this[kCode];
2048
+ }
2049
+ /**
2050
+ * @type {String}
2051
+ */
2052
+ get reason() {
2053
+ return this[kReason];
2054
+ }
2055
+ /**
2056
+ * @type {Boolean}
2057
+ */
2058
+ get wasClean() {
2059
+ return this[kWasClean];
2060
+ }
2061
+ };
2062
+ Object.defineProperty(CloseEvent.prototype, "code", { enumerable: true });
2063
+ Object.defineProperty(CloseEvent.prototype, "reason", { enumerable: true });
2064
+ Object.defineProperty(CloseEvent.prototype, "wasClean", { enumerable: true });
2065
+ /**
2066
+ * Class representing an error event.
2067
+ *
2068
+ * @extends Event
2069
+ */
2070
+ var ErrorEvent = class extends Event {
2071
+ /**
2072
+ * Create a new `ErrorEvent`.
2073
+ *
2074
+ * @param {String} type The name of the event
2075
+ * @param {Object} [options] A dictionary object that allows for setting
2076
+ * attributes via object members of the same name
2077
+ * @param {*} [options.error=null] The error that generated this event
2078
+ * @param {String} [options.message=''] The error message
2079
+ */
2080
+ constructor(type, options = {}) {
2081
+ super(type);
2082
+ this[kError] = options.error === void 0 ? null : options.error;
2083
+ this[kMessage] = options.message === void 0 ? "" : options.message;
2084
+ }
2085
+ /**
2086
+ * @type {*}
2087
+ */
2088
+ get error() {
2089
+ return this[kError];
2090
+ }
2091
+ /**
2092
+ * @type {String}
2093
+ */
2094
+ get message() {
2095
+ return this[kMessage];
2096
+ }
2097
+ };
2098
+ Object.defineProperty(ErrorEvent.prototype, "error", { enumerable: true });
2099
+ Object.defineProperty(ErrorEvent.prototype, "message", { enumerable: true });
2100
+ /**
2101
+ * Class representing a message event.
2102
+ *
2103
+ * @extends Event
2104
+ */
2105
+ var MessageEvent = class extends Event {
2106
+ /**
2107
+ * Create a new `MessageEvent`.
2108
+ *
2109
+ * @param {String} type The name of the event
2110
+ * @param {Object} [options] A dictionary object that allows for setting
2111
+ * attributes via object members of the same name
2112
+ * @param {*} [options.data=null] The message content
2113
+ */
2114
+ constructor(type, options = {}) {
2115
+ super(type);
2116
+ this[kData] = options.data === void 0 ? null : options.data;
2117
+ }
2118
+ /**
2119
+ * @type {*}
2120
+ */
2121
+ get data() {
2122
+ return this[kData];
2123
+ }
2124
+ };
2125
+ Object.defineProperty(MessageEvent.prototype, "data", { enumerable: true });
2126
+ /**
2127
+ * This provides methods for emulating the `EventTarget` interface. It's not
2128
+ * meant to be used directly.
2129
+ *
2130
+ * @mixin
2131
+ */
2132
+ const EventTarget = {
2133
+ addEventListener(type, handler, options = {}) {
2134
+ for (const listener of this.listeners(type)) if (!options[kForOnEventAttribute] && listener[kListener] === handler && !listener[kForOnEventAttribute]) return;
2135
+ let wrapper;
2136
+ if (type === "message") wrapper = function onMessage(data, isBinary) {
2137
+ const event = new MessageEvent("message", { data: isBinary ? data : data.toString() });
2138
+ event[kTarget] = this;
2139
+ callListener(handler, this, event);
2140
+ };
2141
+ else if (type === "close") wrapper = function onClose(code, message) {
2142
+ const event = new CloseEvent("close", {
2143
+ code,
2144
+ reason: message.toString(),
2145
+ wasClean: this._closeFrameReceived && this._closeFrameSent
2146
+ });
2147
+ event[kTarget] = this;
2148
+ callListener(handler, this, event);
2149
+ };
2150
+ else if (type === "error") wrapper = function onError(error) {
2151
+ const event = new ErrorEvent("error", {
2152
+ error,
2153
+ message: error.message
2154
+ });
2155
+ event[kTarget] = this;
2156
+ callListener(handler, this, event);
2157
+ };
2158
+ else if (type === "open") wrapper = function onOpen() {
2159
+ const event = new Event("open");
2160
+ event[kTarget] = this;
2161
+ callListener(handler, this, event);
2162
+ };
2163
+ else return;
2164
+ wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
2165
+ wrapper[kListener] = handler;
2166
+ if (options.once) this.once(type, wrapper);
2167
+ else this.on(type, wrapper);
2168
+ },
2169
+ removeEventListener(type, handler) {
2170
+ for (const listener of this.listeners(type)) if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
2171
+ this.removeListener(type, listener);
2172
+ break;
2173
+ }
2174
+ }
2175
+ };
2176
+ module.exports = {
2177
+ CloseEvent,
2178
+ ErrorEvent,
2179
+ Event,
2180
+ EventTarget,
2181
+ MessageEvent
2182
+ };
2183
+ /**
2184
+ * Call an event listener
2185
+ *
2186
+ * @param {(Function|Object)} listener The listener to call
2187
+ * @param {*} thisArg The value to use as `this`` when calling the listener
2188
+ * @param {Event} event The event to pass to the listener
2189
+ * @private
2190
+ */
2191
+ function callListener(listener, thisArg, event) {
2192
+ if (typeof listener === "object" && listener.handleEvent) listener.handleEvent.call(listener, event);
2193
+ else listener.call(thisArg, event);
2194
+ }
2195
+ }));
2196
+
2197
+ //#endregion
2198
+ //#region ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/extension.js
2199
+ var require_extension = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2200
+ const { tokenChars } = require_validation();
2201
+ /**
2202
+ * Adds an offer to the map of extension offers or a parameter to the map of
2203
+ * parameters.
2204
+ *
2205
+ * @param {Object} dest The map of extension offers or parameters
2206
+ * @param {String} name The extension or parameter name
2207
+ * @param {(Object|Boolean|String)} elem The extension parameters or the
2208
+ * parameter value
2209
+ * @private
2210
+ */
2211
+ function push(dest, name, elem) {
2212
+ if (dest[name] === void 0) dest[name] = [elem];
2213
+ else dest[name].push(elem);
2214
+ }
2215
+ /**
2216
+ * Parses the `Sec-WebSocket-Extensions` header into an object.
2217
+ *
2218
+ * @param {String} header The field value of the header
2219
+ * @return {Object} The parsed object
2220
+ * @public
2221
+ */
2222
+ function parse(header) {
2223
+ const offers = Object.create(null);
2224
+ let params = Object.create(null);
2225
+ let mustUnescape = false;
2226
+ let isEscaping = false;
2227
+ let inQuotes = false;
2228
+ let extensionName;
2229
+ let paramName;
2230
+ let start = -1;
2231
+ let code = -1;
2232
+ let end = -1;
2233
+ let i = 0;
2234
+ for (; i < header.length; i++) {
2235
+ code = header.charCodeAt(i);
2236
+ if (extensionName === void 0) if (end === -1 && tokenChars[code] === 1) {
2237
+ if (start === -1) start = i;
2238
+ } else if (i !== 0 && (code === 32 || code === 9)) {
2239
+ if (end === -1 && start !== -1) end = i;
2240
+ } else if (code === 59 || code === 44) {
2241
+ if (start === -1) throw new SyntaxError(`Unexpected character at index ${i}`);
2242
+ if (end === -1) end = i;
2243
+ const name = header.slice(start, end);
2244
+ if (code === 44) {
2245
+ push(offers, name, params);
2246
+ params = Object.create(null);
2247
+ } else extensionName = name;
2248
+ start = end = -1;
2249
+ } else throw new SyntaxError(`Unexpected character at index ${i}`);
2250
+ else if (paramName === void 0) if (end === -1 && tokenChars[code] === 1) {
2251
+ if (start === -1) start = i;
2252
+ } else if (code === 32 || code === 9) {
2253
+ if (end === -1 && start !== -1) end = i;
2254
+ } else if (code === 59 || code === 44) {
2255
+ if (start === -1) throw new SyntaxError(`Unexpected character at index ${i}`);
2256
+ if (end === -1) end = i;
2257
+ push(params, header.slice(start, end), true);
2258
+ if (code === 44) {
2259
+ push(offers, extensionName, params);
2260
+ params = Object.create(null);
2261
+ extensionName = void 0;
2262
+ }
2263
+ start = end = -1;
2264
+ } else if (code === 61 && start !== -1 && end === -1) {
2265
+ paramName = header.slice(start, i);
2266
+ start = end = -1;
2267
+ } else throw new SyntaxError(`Unexpected character at index ${i}`);
2268
+ else if (isEscaping) {
2269
+ if (tokenChars[code] !== 1) throw new SyntaxError(`Unexpected character at index ${i}`);
2270
+ if (start === -1) start = i;
2271
+ else if (!mustUnescape) mustUnescape = true;
2272
+ isEscaping = false;
2273
+ } else if (inQuotes) if (tokenChars[code] === 1) {
2274
+ if (start === -1) start = i;
2275
+ } else if (code === 34 && start !== -1) {
2276
+ inQuotes = false;
2277
+ end = i;
2278
+ } else if (code === 92) isEscaping = true;
2279
+ else throw new SyntaxError(`Unexpected character at index ${i}`);
2280
+ else if (code === 34 && header.charCodeAt(i - 1) === 61) inQuotes = true;
2281
+ else if (end === -1 && tokenChars[code] === 1) {
2282
+ if (start === -1) start = i;
2283
+ } else if (start !== -1 && (code === 32 || code === 9)) {
2284
+ if (end === -1) end = i;
2285
+ } else if (code === 59 || code === 44) {
2286
+ if (start === -1) throw new SyntaxError(`Unexpected character at index ${i}`);
2287
+ if (end === -1) end = i;
2288
+ let value = header.slice(start, end);
2289
+ if (mustUnescape) {
2290
+ value = value.replace(/\\/g, "");
2291
+ mustUnescape = false;
2292
+ }
2293
+ push(params, paramName, value);
2294
+ if (code === 44) {
2295
+ push(offers, extensionName, params);
2296
+ params = Object.create(null);
2297
+ extensionName = void 0;
2298
+ }
2299
+ paramName = void 0;
2300
+ start = end = -1;
2301
+ } else throw new SyntaxError(`Unexpected character at index ${i}`);
2302
+ }
2303
+ if (start === -1 || inQuotes || code === 32 || code === 9) throw new SyntaxError("Unexpected end of input");
2304
+ if (end === -1) end = i;
2305
+ const token = header.slice(start, end);
2306
+ if (extensionName === void 0) push(offers, token, params);
2307
+ else {
2308
+ if (paramName === void 0) push(params, token, true);
2309
+ else if (mustUnescape) push(params, paramName, token.replace(/\\/g, ""));
2310
+ else push(params, paramName, token);
2311
+ push(offers, extensionName, params);
2312
+ }
2313
+ return offers;
2314
+ }
2315
+ /**
2316
+ * Builds the `Sec-WebSocket-Extensions` header field value.
2317
+ *
2318
+ * @param {Object} extensions The map of extensions and parameters to format
2319
+ * @return {String} A string representing the given object
2320
+ * @public
2321
+ */
2322
+ function format(extensions) {
2323
+ return Object.keys(extensions).map((extension) => {
2324
+ let configurations = extensions[extension];
2325
+ if (!Array.isArray(configurations)) configurations = [configurations];
2326
+ return configurations.map((params) => {
2327
+ return [extension].concat(Object.keys(params).map((k) => {
2328
+ let values = params[k];
2329
+ if (!Array.isArray(values)) values = [values];
2330
+ return values.map((v) => v === true ? k : `${k}=${v}`).join("; ");
2331
+ })).join("; ");
2332
+ }).join(", ");
2333
+ }).join(", ");
2334
+ }
2335
+ module.exports = {
2336
+ format,
2337
+ parse
2338
+ };
2339
+ }));
2340
+
2341
+ //#endregion
2342
+ //#region ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/websocket.js
2343
+ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2344
+ const EventEmitter$1 = __require("events");
2345
+ const https = __require("https");
2346
+ const http$1 = __require("http");
2347
+ const net = __require("net");
2348
+ const tls = __require("tls");
2349
+ const { randomBytes, createHash: createHash$1 } = __require("crypto");
2350
+ const { Duplex: Duplex$3, Readable: Readable$1 } = __require("stream");
2351
+ const { URL } = __require("url");
2352
+ const PerMessageDeflate = require_permessage_deflate();
2353
+ const Receiver = require_receiver();
2354
+ const Sender = require_sender();
2355
+ const { isBlob } = require_validation();
2356
+ const { BINARY_TYPES, CLOSE_TIMEOUT, EMPTY_BUFFER, GUID, kForOnEventAttribute, kListener, kStatusCode, kWebSocket, NOOP } = require_constants();
2357
+ const { EventTarget: { addEventListener, removeEventListener } } = require_event_target();
2358
+ const { format, parse } = require_extension();
2359
+ const { toBuffer } = require_buffer_util();
2360
+ const kAborted = Symbol("kAborted");
2361
+ const protocolVersions = [8, 13];
2362
+ const readyStates = [
2363
+ "CONNECTING",
2364
+ "OPEN",
2365
+ "CLOSING",
2366
+ "CLOSED"
2367
+ ];
2368
+ const subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
2369
+ /**
2370
+ * Class representing a WebSocket.
2371
+ *
2372
+ * @extends EventEmitter
2373
+ */
2374
+ var WebSocket = class WebSocket extends EventEmitter$1 {
2375
+ /**
2376
+ * Create a new `WebSocket`.
2377
+ *
2378
+ * @param {(String|URL)} address The URL to which to connect
2379
+ * @param {(String|String[])} [protocols] The subprotocols
2380
+ * @param {Object} [options] Connection options
2381
+ */
2382
+ constructor(address, protocols, options) {
2383
+ super();
2384
+ this._binaryType = BINARY_TYPES[0];
2385
+ this._closeCode = 1006;
2386
+ this._closeFrameReceived = false;
2387
+ this._closeFrameSent = false;
2388
+ this._closeMessage = EMPTY_BUFFER;
2389
+ this._closeTimer = null;
2390
+ this._errorEmitted = false;
2391
+ this._extensions = {};
2392
+ this._paused = false;
2393
+ this._protocol = "";
2394
+ this._readyState = WebSocket.CONNECTING;
2395
+ this._receiver = null;
2396
+ this._sender = null;
2397
+ this._socket = null;
2398
+ if (address !== null) {
2399
+ this._bufferedAmount = 0;
2400
+ this._isServer = false;
2401
+ this._redirects = 0;
2402
+ if (protocols === void 0) protocols = [];
2403
+ else if (!Array.isArray(protocols)) if (typeof protocols === "object" && protocols !== null) {
2404
+ options = protocols;
2405
+ protocols = [];
2406
+ } else protocols = [protocols];
2407
+ initAsClient(this, address, protocols, options);
2408
+ } else {
2409
+ this._autoPong = options.autoPong;
2410
+ this._closeTimeout = options.closeTimeout;
2411
+ this._isServer = true;
2412
+ }
2413
+ }
2414
+ /**
2415
+ * For historical reasons, the custom "nodebuffer" type is used by the default
2416
+ * instead of "blob".
2417
+ *
2418
+ * @type {String}
2419
+ */
2420
+ get binaryType() {
2421
+ return this._binaryType;
2422
+ }
2423
+ set binaryType(type) {
2424
+ if (!BINARY_TYPES.includes(type)) return;
2425
+ this._binaryType = type;
2426
+ if (this._receiver) this._receiver._binaryType = type;
2427
+ }
2428
+ /**
2429
+ * @type {Number}
2430
+ */
2431
+ get bufferedAmount() {
2432
+ if (!this._socket) return this._bufferedAmount;
2433
+ return this._socket._writableState.length + this._sender._bufferedBytes;
2434
+ }
2435
+ /**
2436
+ * @type {String}
2437
+ */
2438
+ get extensions() {
2439
+ return Object.keys(this._extensions).join();
2440
+ }
2441
+ /**
2442
+ * @type {Boolean}
2443
+ */
2444
+ get isPaused() {
2445
+ return this._paused;
2446
+ }
2447
+ /**
2448
+ * @type {Function}
2449
+ */
2450
+ /* istanbul ignore next */
2451
+ get onclose() {
2452
+ return null;
2453
+ }
2454
+ /**
2455
+ * @type {Function}
2456
+ */
2457
+ /* istanbul ignore next */
2458
+ get onerror() {
2459
+ return null;
2460
+ }
2461
+ /**
2462
+ * @type {Function}
2463
+ */
2464
+ /* istanbul ignore next */
2465
+ get onopen() {
2466
+ return null;
2467
+ }
2468
+ /**
2469
+ * @type {Function}
2470
+ */
2471
+ /* istanbul ignore next */
2472
+ get onmessage() {
2473
+ return null;
2474
+ }
2475
+ /**
2476
+ * @type {String}
2477
+ */
2478
+ get protocol() {
2479
+ return this._protocol;
2480
+ }
2481
+ /**
2482
+ * @type {Number}
2483
+ */
2484
+ get readyState() {
2485
+ return this._readyState;
2486
+ }
2487
+ /**
2488
+ * @type {String}
2489
+ */
2490
+ get url() {
2491
+ return this._url;
2492
+ }
2493
+ /**
2494
+ * Set up the socket and the internal resources.
2495
+ *
2496
+ * @param {Duplex} socket The network socket between the server and client
2497
+ * @param {Buffer} head The first packet of the upgraded stream
2498
+ * @param {Object} options Options object
2499
+ * @param {Boolean} [options.allowSynchronousEvents=false] Specifies whether
2500
+ * any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
2501
+ * multiple times in the same tick
2502
+ * @param {Function} [options.generateMask] The function used to generate the
2503
+ * masking key
2504
+ * @param {Number} [options.maxBufferedChunks=0] The maximum number of
2505
+ * buffered data chunks
2506
+ * @param {Number} [options.maxFragments=0] The maximum number of message
2507
+ * fragments
2508
+ * @param {Number} [options.maxPayload=0] The maximum allowed message size
2509
+ * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
2510
+ * not to skip UTF-8 validation for text and close messages
2511
+ * @private
2512
+ */
2513
+ setSocket(socket, head, options) {
2514
+ const receiver = new Receiver({
2515
+ allowSynchronousEvents: options.allowSynchronousEvents,
2516
+ binaryType: this.binaryType,
2517
+ extensions: this._extensions,
2518
+ isServer: this._isServer,
2519
+ maxBufferedChunks: options.maxBufferedChunks,
2520
+ maxFragments: options.maxFragments,
2521
+ maxPayload: options.maxPayload,
2522
+ skipUTF8Validation: options.skipUTF8Validation
2523
+ });
2524
+ const sender = new Sender(socket, this._extensions, options.generateMask);
2525
+ this._receiver = receiver;
2526
+ this._sender = sender;
2527
+ this._socket = socket;
2528
+ receiver[kWebSocket] = this;
2529
+ sender[kWebSocket] = this;
2530
+ socket[kWebSocket] = this;
2531
+ receiver.on("conclude", receiverOnConclude);
2532
+ receiver.on("drain", receiverOnDrain);
2533
+ receiver.on("error", receiverOnError);
2534
+ receiver.on("message", receiverOnMessage);
2535
+ receiver.on("ping", receiverOnPing);
2536
+ receiver.on("pong", receiverOnPong);
2537
+ sender.onerror = senderOnError;
2538
+ if (socket.setTimeout) socket.setTimeout(0);
2539
+ if (socket.setNoDelay) socket.setNoDelay();
2540
+ if (head.length > 0) socket.unshift(head);
2541
+ socket.on("close", socketOnClose);
2542
+ socket.on("data", socketOnData);
2543
+ socket.on("end", socketOnEnd);
2544
+ socket.on("error", socketOnError);
2545
+ this._readyState = WebSocket.OPEN;
2546
+ this.emit("open");
2547
+ }
2548
+ /**
2549
+ * Emit the `'close'` event.
2550
+ *
2551
+ * @private
2552
+ */
2553
+ emitClose() {
2554
+ if (!this._socket) {
2555
+ this._readyState = WebSocket.CLOSED;
2556
+ this.emit("close", this._closeCode, this._closeMessage);
2557
+ return;
2558
+ }
2559
+ if (this._extensions[PerMessageDeflate.extensionName]) this._extensions[PerMessageDeflate.extensionName].cleanup();
2560
+ this._receiver.removeAllListeners();
2561
+ this._readyState = WebSocket.CLOSED;
2562
+ this.emit("close", this._closeCode, this._closeMessage);
2563
+ }
2564
+ /**
2565
+ * Start a closing handshake.
2566
+ *
2567
+ * +----------+ +-----------+ +----------+
2568
+ * - - -|ws.close()|-->|close frame|-->|ws.close()|- - -
2569
+ * | +----------+ +-----------+ +----------+ |
2570
+ * +----------+ +-----------+ |
2571
+ * CLOSING |ws.close()|<--|close frame|<--+-----+ CLOSING
2572
+ * +----------+ +-----------+ |
2573
+ * | | | +---+ |
2574
+ * +------------------------+-->|fin| - - - -
2575
+ * | +---+ | +---+
2576
+ * - - - - -|fin|<---------------------+
2577
+ * +---+
2578
+ *
2579
+ * @param {Number} [code] Status code explaining why the connection is closing
2580
+ * @param {(String|Buffer)} [data] The reason why the connection is
2581
+ * closing
2582
+ * @public
2583
+ */
2584
+ close(code, data) {
2585
+ if (this.readyState === WebSocket.CLOSED) return;
2586
+ if (this.readyState === WebSocket.CONNECTING) {
2587
+ abortHandshake(this, this._req, "WebSocket was closed before the connection was established");
2588
+ return;
2589
+ }
2590
+ if (this.readyState === WebSocket.CLOSING) {
2591
+ if (this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted)) this._socket.end();
2592
+ return;
2593
+ }
2594
+ this._readyState = WebSocket.CLOSING;
2595
+ this._sender.close(code, data, !this._isServer, (err) => {
2596
+ if (err) return;
2597
+ this._closeFrameSent = true;
2598
+ if (this._closeFrameReceived || this._receiver._writableState.errorEmitted) this._socket.end();
2599
+ });
2600
+ setCloseTimer(this);
2601
+ }
2602
+ /**
2603
+ * Pause the socket.
2604
+ *
2605
+ * @public
2606
+ */
2607
+ pause() {
2608
+ if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) return;
2609
+ this._paused = true;
2610
+ this._socket.pause();
2611
+ }
2612
+ /**
2613
+ * Send a ping.
2614
+ *
2615
+ * @param {*} [data] The data to send
2616
+ * @param {Boolean} [mask] Indicates whether or not to mask `data`
2617
+ * @param {Function} [cb] Callback which is executed when the ping is sent
2618
+ * @public
2619
+ */
2620
+ ping(data, mask, cb) {
2621
+ if (this.readyState === WebSocket.CONNECTING) throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2622
+ if (typeof data === "function") {
2623
+ cb = data;
2624
+ data = mask = void 0;
2625
+ } else if (typeof mask === "function") {
2626
+ cb = mask;
2627
+ mask = void 0;
2628
+ }
2629
+ if (typeof data === "number") data = data.toString();
2630
+ if (this.readyState !== WebSocket.OPEN) {
2631
+ sendAfterClose(this, data, cb);
2632
+ return;
2633
+ }
2634
+ if (mask === void 0) mask = !this._isServer;
2635
+ this._sender.ping(data || EMPTY_BUFFER, mask, cb);
2636
+ }
2637
+ /**
2638
+ * Send a pong.
2639
+ *
2640
+ * @param {*} [data] The data to send
2641
+ * @param {Boolean} [mask] Indicates whether or not to mask `data`
2642
+ * @param {Function} [cb] Callback which is executed when the pong is sent
2643
+ * @public
2644
+ */
2645
+ pong(data, mask, cb) {
2646
+ if (this.readyState === WebSocket.CONNECTING) throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2647
+ if (typeof data === "function") {
2648
+ cb = data;
2649
+ data = mask = void 0;
2650
+ } else if (typeof mask === "function") {
2651
+ cb = mask;
2652
+ mask = void 0;
2653
+ }
2654
+ if (typeof data === "number") data = data.toString();
2655
+ if (this.readyState !== WebSocket.OPEN) {
2656
+ sendAfterClose(this, data, cb);
2657
+ return;
2658
+ }
2659
+ if (mask === void 0) mask = !this._isServer;
2660
+ this._sender.pong(data || EMPTY_BUFFER, mask, cb);
2661
+ }
2662
+ /**
2663
+ * Resume the socket.
2664
+ *
2665
+ * @public
2666
+ */
2667
+ resume() {
2668
+ if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) return;
2669
+ this._paused = false;
2670
+ if (!this._receiver._writableState.needDrain) this._socket.resume();
2671
+ }
2672
+ /**
2673
+ * Send a data message.
2674
+ *
2675
+ * @param {*} data The message to send
2676
+ * @param {Object} [options] Options object
2677
+ * @param {Boolean} [options.binary] Specifies whether `data` is binary or
2678
+ * text
2679
+ * @param {Boolean} [options.compress] Specifies whether or not to compress
2680
+ * `data`
2681
+ * @param {Boolean} [options.fin=true] Specifies whether the fragment is the
2682
+ * last one
2683
+ * @param {Boolean} [options.mask] Specifies whether or not to mask `data`
2684
+ * @param {Function} [cb] Callback which is executed when data is written out
2685
+ * @public
2686
+ */
2687
+ send(data, options, cb) {
2688
+ if (this.readyState === WebSocket.CONNECTING) throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2689
+ if (typeof options === "function") {
2690
+ cb = options;
2691
+ options = {};
2692
+ }
2693
+ if (typeof data === "number") data = data.toString();
2694
+ if (this.readyState !== WebSocket.OPEN) {
2695
+ sendAfterClose(this, data, cb);
2696
+ return;
2697
+ }
2698
+ const opts = {
2699
+ binary: typeof data !== "string",
2700
+ mask: !this._isServer,
2701
+ compress: true,
2702
+ fin: true,
2703
+ ...options
2704
+ };
2705
+ if (!this._extensions[PerMessageDeflate.extensionName]) opts.compress = false;
2706
+ this._sender.send(data || EMPTY_BUFFER, opts, cb);
2707
+ }
2708
+ /**
2709
+ * Forcibly close the connection.
2710
+ *
2711
+ * @public
2712
+ */
2713
+ terminate() {
2714
+ if (this.readyState === WebSocket.CLOSED) return;
2715
+ if (this.readyState === WebSocket.CONNECTING) {
2716
+ abortHandshake(this, this._req, "WebSocket was closed before the connection was established");
2717
+ return;
2718
+ }
2719
+ if (this._socket) {
2720
+ this._readyState = WebSocket.CLOSING;
2721
+ this._socket.destroy();
2722
+ }
2723
+ }
2724
+ };
2725
+ /**
2726
+ * @constant {Number} CONNECTING
2727
+ * @memberof WebSocket
2728
+ */
2729
+ Object.defineProperty(WebSocket, "CONNECTING", {
2730
+ enumerable: true,
2731
+ value: readyStates.indexOf("CONNECTING")
2732
+ });
2733
+ /**
2734
+ * @constant {Number} CONNECTING
2735
+ * @memberof WebSocket.prototype
2736
+ */
2737
+ Object.defineProperty(WebSocket.prototype, "CONNECTING", {
2738
+ enumerable: true,
2739
+ value: readyStates.indexOf("CONNECTING")
2740
+ });
2741
+ /**
2742
+ * @constant {Number} OPEN
2743
+ * @memberof WebSocket
2744
+ */
2745
+ Object.defineProperty(WebSocket, "OPEN", {
2746
+ enumerable: true,
2747
+ value: readyStates.indexOf("OPEN")
2748
+ });
2749
+ /**
2750
+ * @constant {Number} OPEN
2751
+ * @memberof WebSocket.prototype
2752
+ */
2753
+ Object.defineProperty(WebSocket.prototype, "OPEN", {
2754
+ enumerable: true,
2755
+ value: readyStates.indexOf("OPEN")
2756
+ });
2757
+ /**
2758
+ * @constant {Number} CLOSING
2759
+ * @memberof WebSocket
2760
+ */
2761
+ Object.defineProperty(WebSocket, "CLOSING", {
2762
+ enumerable: true,
2763
+ value: readyStates.indexOf("CLOSING")
2764
+ });
2765
+ /**
2766
+ * @constant {Number} CLOSING
2767
+ * @memberof WebSocket.prototype
2768
+ */
2769
+ Object.defineProperty(WebSocket.prototype, "CLOSING", {
2770
+ enumerable: true,
2771
+ value: readyStates.indexOf("CLOSING")
2772
+ });
2773
+ /**
2774
+ * @constant {Number} CLOSED
2775
+ * @memberof WebSocket
2776
+ */
2777
+ Object.defineProperty(WebSocket, "CLOSED", {
2778
+ enumerable: true,
2779
+ value: readyStates.indexOf("CLOSED")
2780
+ });
2781
+ /**
2782
+ * @constant {Number} CLOSED
2783
+ * @memberof WebSocket.prototype
2784
+ */
2785
+ Object.defineProperty(WebSocket.prototype, "CLOSED", {
2786
+ enumerable: true,
2787
+ value: readyStates.indexOf("CLOSED")
2788
+ });
2789
+ [
2790
+ "binaryType",
2791
+ "bufferedAmount",
2792
+ "extensions",
2793
+ "isPaused",
2794
+ "protocol",
2795
+ "readyState",
2796
+ "url"
2797
+ ].forEach((property) => {
2798
+ Object.defineProperty(WebSocket.prototype, property, { enumerable: true });
2799
+ });
2800
+ [
2801
+ "open",
2802
+ "error",
2803
+ "close",
2804
+ "message"
2805
+ ].forEach((method) => {
2806
+ Object.defineProperty(WebSocket.prototype, `on${method}`, {
2807
+ enumerable: true,
2808
+ get() {
2809
+ for (const listener of this.listeners(method)) if (listener[kForOnEventAttribute]) return listener[kListener];
2810
+ return null;
2811
+ },
2812
+ set(handler) {
2813
+ for (const listener of this.listeners(method)) if (listener[kForOnEventAttribute]) {
2814
+ this.removeListener(method, listener);
2815
+ break;
2816
+ }
2817
+ if (typeof handler !== "function") return;
2818
+ this.addEventListener(method, handler, { [kForOnEventAttribute]: true });
2819
+ }
2820
+ });
2821
+ });
2822
+ WebSocket.prototype.addEventListener = addEventListener;
2823
+ WebSocket.prototype.removeEventListener = removeEventListener;
2824
+ module.exports = WebSocket;
2825
+ /**
2826
+ * Initialize a WebSocket client.
2827
+ *
2828
+ * @param {WebSocket} websocket The client to initialize
2829
+ * @param {(String|URL)} address The URL to which to connect
2830
+ * @param {Array} protocols The subprotocols
2831
+ * @param {Object} [options] Connection options
2832
+ * @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether any
2833
+ * of the `'message'`, `'ping'`, and `'pong'` events can be emitted multiple
2834
+ * times in the same tick
2835
+ * @param {Boolean} [options.autoPong=true] Specifies whether or not to
2836
+ * automatically send a pong in response to a ping
2837
+ * @param {Number} [options.closeTimeout=30000] Duration in milliseconds to wait
2838
+ * for the closing handshake to finish after `websocket.close()` is called
2839
+ * @param {Function} [options.finishRequest] A function which can be used to
2840
+ * customize the headers of each http request before it is sent
2841
+ * @param {Boolean} [options.followRedirects=false] Whether or not to follow
2842
+ * redirects
2843
+ * @param {Function} [options.generateMask] The function used to generate the
2844
+ * masking key
2845
+ * @param {Number} [options.handshakeTimeout] Timeout in milliseconds for the
2846
+ * handshake request
2847
+ * @param {Number} [options.maxBufferedChunks=1048576] The maximum number of
2848
+ * buffered data chunks
2849
+ * @param {Number} [options.maxFragments=131072] The maximum number of message
2850
+ * fragments
2851
+ * @param {Number} [options.maxPayload=104857600] The maximum allowed message
2852
+ * size
2853
+ * @param {Number} [options.maxRedirects=10] The maximum number of redirects
2854
+ * allowed
2855
+ * @param {String} [options.origin] Value of the `Origin` or
2856
+ * `Sec-WebSocket-Origin` header
2857
+ * @param {(Boolean|Object)} [options.perMessageDeflate=true] Enable/disable
2858
+ * permessage-deflate
2859
+ * @param {Number} [options.protocolVersion=13] Value of the
2860
+ * `Sec-WebSocket-Version` header
2861
+ * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
2862
+ * not to skip UTF-8 validation for text and close messages
2863
+ * @private
2864
+ */
2865
+ function initAsClient(websocket, address, protocols, options) {
2866
+ const opts = {
2867
+ allowSynchronousEvents: true,
2868
+ autoPong: true,
2869
+ closeTimeout: CLOSE_TIMEOUT,
2870
+ protocolVersion: protocolVersions[1],
2871
+ maxBufferedChunks: 1024 * 1024,
2872
+ maxFragments: 128 * 1024,
2873
+ maxPayload: 100 * 1024 * 1024,
2874
+ skipUTF8Validation: false,
2875
+ perMessageDeflate: true,
2876
+ followRedirects: false,
2877
+ maxRedirects: 10,
2878
+ ...options,
2879
+ socketPath: void 0,
2880
+ hostname: void 0,
2881
+ protocol: void 0,
2882
+ timeout: void 0,
2883
+ method: "GET",
2884
+ host: void 0,
2885
+ path: void 0,
2886
+ port: void 0
2887
+ };
2888
+ websocket._autoPong = opts.autoPong;
2889
+ websocket._closeTimeout = opts.closeTimeout;
2890
+ if (!protocolVersions.includes(opts.protocolVersion)) throw new RangeError(`Unsupported protocol version: ${opts.protocolVersion} (supported versions: ${protocolVersions.join(", ")})`);
2891
+ let parsedUrl;
2892
+ if (address instanceof URL) parsedUrl = address;
2893
+ else try {
2894
+ parsedUrl = new URL(address);
2895
+ } catch {
2896
+ throw new SyntaxError(`Invalid URL: ${address}`);
2897
+ }
2898
+ if (parsedUrl.protocol === "http:") parsedUrl.protocol = "ws:";
2899
+ else if (parsedUrl.protocol === "https:") parsedUrl.protocol = "wss:";
2900
+ websocket._url = parsedUrl.href;
2901
+ const isSecure = parsedUrl.protocol === "wss:";
2902
+ const isIpcUrl = parsedUrl.protocol === "ws+unix:";
2903
+ let invalidUrlMessage;
2904
+ if (parsedUrl.protocol !== "ws:" && !isSecure && !isIpcUrl) invalidUrlMessage = "The URL's protocol must be one of \"ws:\", \"wss:\", \"http:\", \"https:\", or \"ws+unix:\"";
2905
+ else if (isIpcUrl && !parsedUrl.pathname) invalidUrlMessage = "The URL's pathname is empty";
2906
+ else if (parsedUrl.hash) invalidUrlMessage = "The URL contains a fragment identifier";
2907
+ if (invalidUrlMessage) {
2908
+ const err = new SyntaxError(invalidUrlMessage);
2909
+ if (websocket._redirects === 0) throw err;
2910
+ else {
2911
+ emitErrorAndClose(websocket, err);
2912
+ return;
2913
+ }
2914
+ }
2915
+ const defaultPort = isSecure ? 443 : 80;
2916
+ const key = randomBytes(16).toString("base64");
2917
+ const request = isSecure ? https.request : http$1.request;
2918
+ const protocolSet = /* @__PURE__ */ new Set();
2919
+ let perMessageDeflate;
2920
+ opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect);
2921
+ opts.defaultPort = opts.defaultPort || defaultPort;
2922
+ opts.port = parsedUrl.port || defaultPort;
2923
+ opts.host = parsedUrl.hostname.startsWith("[") ? parsedUrl.hostname.slice(1, -1) : parsedUrl.hostname;
2924
+ opts.headers = {
2925
+ ...opts.headers,
2926
+ "Sec-WebSocket-Version": opts.protocolVersion,
2927
+ "Sec-WebSocket-Key": key,
2928
+ Connection: "Upgrade",
2929
+ Upgrade: "websocket"
2930
+ };
2931
+ opts.path = parsedUrl.pathname + parsedUrl.search;
2932
+ opts.timeout = opts.handshakeTimeout;
2933
+ if (opts.perMessageDeflate) {
2934
+ perMessageDeflate = new PerMessageDeflate({
2935
+ ...opts.perMessageDeflate,
2936
+ isServer: false,
2937
+ maxPayload: opts.maxPayload
2938
+ });
2939
+ opts.headers["Sec-WebSocket-Extensions"] = format({ [PerMessageDeflate.extensionName]: perMessageDeflate.offer() });
2940
+ }
2941
+ if (protocols.length) {
2942
+ for (const protocol of protocols) {
2943
+ if (typeof protocol !== "string" || !subprotocolRegex.test(protocol) || protocolSet.has(protocol)) throw new SyntaxError("An invalid or duplicated subprotocol was specified");
2944
+ protocolSet.add(protocol);
2945
+ }
2946
+ opts.headers["Sec-WebSocket-Protocol"] = protocols.join(",");
2947
+ }
2948
+ if (opts.origin) if (opts.protocolVersion < 13) opts.headers["Sec-WebSocket-Origin"] = opts.origin;
2949
+ else opts.headers.Origin = opts.origin;
2950
+ if (parsedUrl.username || parsedUrl.password) opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
2951
+ if (isIpcUrl) {
2952
+ const parts = opts.path.split(":");
2953
+ opts.socketPath = parts[0];
2954
+ opts.path = parts[1];
2955
+ }
2956
+ let req;
2957
+ if (opts.followRedirects) {
2958
+ if (websocket._redirects === 0) {
2959
+ websocket._originalIpc = isIpcUrl;
2960
+ websocket._originalSecure = isSecure;
2961
+ websocket._originalHostOrSocketPath = isIpcUrl ? opts.socketPath : parsedUrl.host;
2962
+ const headers = options && options.headers;
2963
+ options = {
2964
+ ...options,
2965
+ headers: {}
2966
+ };
2967
+ if (headers) for (const [key, value] of Object.entries(headers)) options.headers[key.toLowerCase()] = value;
2968
+ } else if (websocket.listenerCount("redirect") === 0) {
2969
+ const isSameHost = isIpcUrl ? websocket._originalIpc ? opts.socketPath === websocket._originalHostOrSocketPath : false : websocket._originalIpc ? false : parsedUrl.host === websocket._originalHostOrSocketPath;
2970
+ if (!isSameHost || websocket._originalSecure && !isSecure) {
2971
+ delete opts.headers.authorization;
2972
+ delete opts.headers.cookie;
2973
+ if (!isSameHost) delete opts.headers.host;
2974
+ opts.auth = void 0;
2975
+ }
2976
+ }
2977
+ if (opts.auth && !options.headers.authorization) options.headers.authorization = "Basic " + Buffer.from(opts.auth).toString("base64");
2978
+ req = websocket._req = request(opts);
2979
+ if (websocket._redirects) websocket.emit("redirect", websocket.url, req);
2980
+ } else req = websocket._req = request(opts);
2981
+ if (opts.timeout) req.on("timeout", () => {
2982
+ abortHandshake(websocket, req, "Opening handshake has timed out");
2983
+ });
2984
+ req.on("error", (err) => {
2985
+ if (req === null || req[kAborted]) return;
2986
+ req = websocket._req = null;
2987
+ emitErrorAndClose(websocket, err);
2988
+ });
2989
+ req.on("response", (res) => {
2990
+ const location = res.headers.location;
2991
+ const statusCode = res.statusCode;
2992
+ if (location && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
2993
+ if (++websocket._redirects > opts.maxRedirects) {
2994
+ abortHandshake(websocket, req, "Maximum redirects exceeded");
2995
+ return;
2996
+ }
2997
+ req.abort();
2998
+ let addr;
2999
+ try {
3000
+ addr = new URL(location, address);
3001
+ } catch (e) {
3002
+ emitErrorAndClose(websocket, /* @__PURE__ */ new SyntaxError(`Invalid URL: ${location}`));
3003
+ return;
3004
+ }
3005
+ initAsClient(websocket, addr, protocols, options);
3006
+ } else if (!websocket.emit("unexpected-response", req, res)) abortHandshake(websocket, req, `Unexpected server response: ${res.statusCode}`);
3007
+ });
3008
+ req.on("upgrade", (res, socket, head) => {
3009
+ websocket.emit("upgrade", res);
3010
+ if (websocket.readyState !== WebSocket.CONNECTING) return;
3011
+ req = websocket._req = null;
3012
+ const upgrade = res.headers.upgrade;
3013
+ if (upgrade === void 0 || upgrade.toLowerCase() !== "websocket") {
3014
+ abortHandshake(websocket, socket, "Invalid Upgrade header");
3015
+ return;
3016
+ }
3017
+ const digest = createHash$1("sha1").update(key + GUID).digest("base64");
3018
+ if (res.headers["sec-websocket-accept"] !== digest) {
3019
+ abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
3020
+ return;
3021
+ }
3022
+ const serverProt = res.headers["sec-websocket-protocol"];
3023
+ let protError;
3024
+ if (serverProt !== void 0) {
3025
+ if (!protocolSet.size) protError = "Server sent a subprotocol but none was requested";
3026
+ else if (!protocolSet.has(serverProt)) protError = "Server sent an invalid subprotocol";
3027
+ } else if (protocolSet.size) protError = "Server sent no subprotocol";
3028
+ if (protError) {
3029
+ abortHandshake(websocket, socket, protError);
3030
+ return;
3031
+ }
3032
+ if (serverProt) websocket._protocol = serverProt;
3033
+ const secWebSocketExtensions = res.headers["sec-websocket-extensions"];
3034
+ if (secWebSocketExtensions !== void 0) {
3035
+ if (!perMessageDeflate) {
3036
+ abortHandshake(websocket, socket, "Server sent a Sec-WebSocket-Extensions header but no extension was requested");
3037
+ return;
3038
+ }
3039
+ let extensions;
3040
+ try {
3041
+ extensions = parse(secWebSocketExtensions);
3042
+ } catch (err) {
3043
+ abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Extensions header");
3044
+ return;
3045
+ }
3046
+ const extensionNames = Object.keys(extensions);
3047
+ if (extensionNames.length !== 1 || extensionNames[0] !== PerMessageDeflate.extensionName) {
3048
+ abortHandshake(websocket, socket, "Server indicated an extension that was not requested");
3049
+ return;
3050
+ }
3051
+ try {
3052
+ perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
3053
+ } catch (err) {
3054
+ abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Extensions header");
3055
+ return;
3056
+ }
3057
+ websocket._extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
3058
+ }
3059
+ websocket.setSocket(socket, head, {
3060
+ allowSynchronousEvents: opts.allowSynchronousEvents,
3061
+ generateMask: opts.generateMask,
3062
+ maxBufferedChunks: opts.maxBufferedChunks,
3063
+ maxFragments: opts.maxFragments,
3064
+ maxPayload: opts.maxPayload,
3065
+ skipUTF8Validation: opts.skipUTF8Validation
3066
+ });
3067
+ });
3068
+ if (opts.finishRequest) opts.finishRequest(req, websocket);
3069
+ else req.end();
3070
+ }
3071
+ /**
3072
+ * Emit the `'error'` and `'close'` events.
3073
+ *
3074
+ * @param {WebSocket} websocket The WebSocket instance
3075
+ * @param {Error} The error to emit
3076
+ * @private
3077
+ */
3078
+ function emitErrorAndClose(websocket, err) {
3079
+ websocket._readyState = WebSocket.CLOSING;
3080
+ websocket._errorEmitted = true;
3081
+ websocket.emit("error", err);
3082
+ websocket.emitClose();
3083
+ }
3084
+ /**
3085
+ * Create a `net.Socket` and initiate a connection.
3086
+ *
3087
+ * @param {Object} options Connection options
3088
+ * @return {net.Socket} The newly created socket used to start the connection
3089
+ * @private
3090
+ */
3091
+ function netConnect(options) {
3092
+ options.path = options.socketPath;
3093
+ return net.connect(options);
3094
+ }
3095
+ /**
3096
+ * Create a `tls.TLSSocket` and initiate a connection.
3097
+ *
3098
+ * @param {Object} options Connection options
3099
+ * @return {tls.TLSSocket} The newly created socket used to start the connection
3100
+ * @private
3101
+ */
3102
+ function tlsConnect(options) {
3103
+ options.path = void 0;
3104
+ if (!options.servername && options.servername !== "") options.servername = net.isIP(options.host) ? "" : options.host;
3105
+ return tls.connect(options);
3106
+ }
3107
+ /**
3108
+ * Abort the handshake and emit an error.
3109
+ *
3110
+ * @param {WebSocket} websocket The WebSocket instance
3111
+ * @param {(http.ClientRequest|net.Socket|tls.Socket)} stream The request to
3112
+ * abort or the socket to destroy
3113
+ * @param {String} message The error message
3114
+ * @private
3115
+ */
3116
+ function abortHandshake(websocket, stream, message) {
3117
+ websocket._readyState = WebSocket.CLOSING;
3118
+ const err = new Error(message);
3119
+ Error.captureStackTrace(err, abortHandshake);
3120
+ if (stream.setHeader) {
3121
+ stream[kAborted] = true;
3122
+ stream.abort();
3123
+ if (stream.socket && !stream.socket.destroyed) stream.socket.destroy();
3124
+ process.nextTick(emitErrorAndClose, websocket, err);
3125
+ } else {
3126
+ stream.destroy(err);
3127
+ stream.once("error", websocket.emit.bind(websocket, "error"));
3128
+ stream.once("close", websocket.emitClose.bind(websocket));
3129
+ }
3130
+ }
3131
+ /**
3132
+ * Handle cases where the `ping()`, `pong()`, or `send()` methods are called
3133
+ * when the `readyState` attribute is `CLOSING` or `CLOSED`.
3134
+ *
3135
+ * @param {WebSocket} websocket The WebSocket instance
3136
+ * @param {*} [data] The data to send
3137
+ * @param {Function} [cb] Callback
3138
+ * @private
3139
+ */
3140
+ function sendAfterClose(websocket, data, cb) {
3141
+ if (data) {
3142
+ const length = isBlob(data) ? data.size : toBuffer(data).length;
3143
+ if (websocket._socket) websocket._sender._bufferedBytes += length;
3144
+ else websocket._bufferedAmount += length;
3145
+ }
3146
+ if (cb) {
3147
+ const err = /* @__PURE__ */ new Error(`WebSocket is not open: readyState ${websocket.readyState} (${readyStates[websocket.readyState]})`);
3148
+ process.nextTick(cb, err);
3149
+ }
3150
+ }
3151
+ /**
3152
+ * The listener of the `Receiver` `'conclude'` event.
3153
+ *
3154
+ * @param {Number} code The status code
3155
+ * @param {Buffer} reason The reason for closing
3156
+ * @private
3157
+ */
3158
+ function receiverOnConclude(code, reason) {
3159
+ const websocket = this[kWebSocket];
3160
+ websocket._closeFrameReceived = true;
3161
+ websocket._closeMessage = reason;
3162
+ websocket._closeCode = code;
3163
+ if (websocket._socket[kWebSocket] === void 0) return;
3164
+ websocket._socket.removeListener("data", socketOnData);
3165
+ process.nextTick(resume, websocket._socket);
3166
+ if (code === 1005) websocket.close();
3167
+ else websocket.close(code, reason);
3168
+ }
3169
+ /**
3170
+ * The listener of the `Receiver` `'drain'` event.
3171
+ *
3172
+ * @private
3173
+ */
3174
+ function receiverOnDrain() {
3175
+ const websocket = this[kWebSocket];
3176
+ if (!websocket.isPaused) websocket._socket.resume();
3177
+ }
3178
+ /**
3179
+ * The listener of the `Receiver` `'error'` event.
3180
+ *
3181
+ * @param {(RangeError|Error)} err The emitted error
3182
+ * @private
3183
+ */
3184
+ function receiverOnError(err) {
3185
+ const websocket = this[kWebSocket];
3186
+ if (websocket._socket[kWebSocket] !== void 0) {
3187
+ websocket._socket.removeListener("data", socketOnData);
3188
+ process.nextTick(resume, websocket._socket);
3189
+ websocket.close(err[kStatusCode]);
3190
+ }
3191
+ if (!websocket._errorEmitted) {
3192
+ websocket._errorEmitted = true;
3193
+ websocket.emit("error", err);
3194
+ }
3195
+ }
3196
+ /**
3197
+ * The listener of the `Receiver` `'finish'` event.
3198
+ *
3199
+ * @private
3200
+ */
3201
+ function receiverOnFinish() {
3202
+ this[kWebSocket].emitClose();
3203
+ }
3204
+ /**
3205
+ * The listener of the `Receiver` `'message'` event.
3206
+ *
3207
+ * @param {Buffer|ArrayBuffer|Buffer[])} data The message
3208
+ * @param {Boolean} isBinary Specifies whether the message is binary or not
3209
+ * @private
3210
+ */
3211
+ function receiverOnMessage(data, isBinary) {
3212
+ this[kWebSocket].emit("message", data, isBinary);
3213
+ }
3214
+ /**
3215
+ * The listener of the `Receiver` `'ping'` event.
3216
+ *
3217
+ * @param {Buffer} data The data included in the ping frame
3218
+ * @private
3219
+ */
3220
+ function receiverOnPing(data) {
3221
+ const websocket = this[kWebSocket];
3222
+ if (websocket._autoPong) websocket.pong(data, !this._isServer, NOOP);
3223
+ websocket.emit("ping", data);
3224
+ }
3225
+ /**
3226
+ * The listener of the `Receiver` `'pong'` event.
3227
+ *
3228
+ * @param {Buffer} data The data included in the pong frame
3229
+ * @private
3230
+ */
3231
+ function receiverOnPong(data) {
3232
+ this[kWebSocket].emit("pong", data);
3233
+ }
3234
+ /**
3235
+ * Resume a readable stream
3236
+ *
3237
+ * @param {Readable} stream The readable stream
3238
+ * @private
3239
+ */
3240
+ function resume(stream) {
3241
+ stream.resume();
3242
+ }
3243
+ /**
3244
+ * The `Sender` error event handler.
3245
+ *
3246
+ * @param {Error} The error
3247
+ * @private
3248
+ */
3249
+ function senderOnError(err) {
3250
+ const websocket = this[kWebSocket];
3251
+ if (websocket.readyState === WebSocket.CLOSED) return;
3252
+ if (websocket.readyState === WebSocket.OPEN) {
3253
+ websocket._readyState = WebSocket.CLOSING;
3254
+ setCloseTimer(websocket);
3255
+ }
3256
+ this._socket.end();
3257
+ if (!websocket._errorEmitted) {
3258
+ websocket._errorEmitted = true;
3259
+ websocket.emit("error", err);
3260
+ }
3261
+ }
3262
+ /**
3263
+ * Set a timer to destroy the underlying raw socket of a WebSocket.
3264
+ *
3265
+ * @param {WebSocket} websocket The WebSocket instance
3266
+ * @private
3267
+ */
3268
+ function setCloseTimer(websocket) {
3269
+ websocket._closeTimer = setTimeout(websocket._socket.destroy.bind(websocket._socket), websocket._closeTimeout);
3270
+ }
3271
+ /**
3272
+ * The listener of the socket `'close'` event.
3273
+ *
3274
+ * @private
3275
+ */
3276
+ function socketOnClose() {
3277
+ const websocket = this[kWebSocket];
3278
+ this.removeListener("close", socketOnClose);
3279
+ this.removeListener("data", socketOnData);
3280
+ this.removeListener("end", socketOnEnd);
3281
+ websocket._readyState = WebSocket.CLOSING;
3282
+ if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && this._readableState.length !== 0) {
3283
+ const chunk = this.read(this._readableState.length);
3284
+ websocket._receiver.write(chunk);
3285
+ }
3286
+ websocket._receiver.end();
3287
+ this[kWebSocket] = void 0;
3288
+ clearTimeout(websocket._closeTimer);
3289
+ if (websocket._receiver._writableState.finished || websocket._receiver._writableState.errorEmitted) websocket.emitClose();
3290
+ else {
3291
+ websocket._receiver.on("error", receiverOnFinish);
3292
+ websocket._receiver.on("finish", receiverOnFinish);
3293
+ }
3294
+ }
3295
+ /**
3296
+ * The listener of the socket `'data'` event.
3297
+ *
3298
+ * @param {Buffer} chunk A chunk of data
3299
+ * @private
3300
+ */
3301
+ function socketOnData(chunk) {
3302
+ if (!this[kWebSocket]._receiver.write(chunk)) this.pause();
3303
+ }
3304
+ /**
3305
+ * The listener of the socket `'end'` event.
3306
+ *
3307
+ * @private
3308
+ */
3309
+ function socketOnEnd() {
3310
+ const websocket = this[kWebSocket];
3311
+ websocket._readyState = WebSocket.CLOSING;
3312
+ websocket._receiver.end();
3313
+ this.end();
3314
+ }
3315
+ /**
3316
+ * The listener of the socket `'error'` event.
3317
+ *
3318
+ * @private
3319
+ */
3320
+ function socketOnError() {
3321
+ const websocket = this[kWebSocket];
3322
+ this.removeListener("error", socketOnError);
3323
+ this.on("error", NOOP);
3324
+ if (websocket) {
3325
+ websocket._readyState = WebSocket.CLOSING;
3326
+ this.destroy();
3327
+ }
3328
+ }
3329
+ }));
3330
+
3331
+ //#endregion
3332
+ //#region ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/stream.js
3333
+ var require_stream = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3334
+ require_websocket();
3335
+ const { Duplex: Duplex$2 } = __require("stream");
3336
+ /**
3337
+ * Emits the `'close'` event on a stream.
3338
+ *
3339
+ * @param {Duplex} stream The stream.
3340
+ * @private
3341
+ */
3342
+ function emitClose(stream) {
3343
+ stream.emit("close");
3344
+ }
3345
+ /**
3346
+ * The listener of the `'end'` event.
3347
+ *
3348
+ * @private
3349
+ */
3350
+ function duplexOnEnd() {
3351
+ if (!this.destroyed && this._writableState.finished) this.destroy();
3352
+ }
3353
+ /**
3354
+ * The listener of the `'error'` event.
3355
+ *
3356
+ * @param {Error} err The error
3357
+ * @private
3358
+ */
3359
+ function duplexOnError(err) {
3360
+ this.removeListener("error", duplexOnError);
3361
+ this.destroy();
3362
+ if (this.listenerCount("error") === 0) this.emit("error", err);
3363
+ }
3364
+ /**
3365
+ * Wraps a `WebSocket` in a duplex stream.
3366
+ *
3367
+ * @param {WebSocket} ws The `WebSocket` to wrap
3368
+ * @param {Object} [options] The options for the `Duplex` constructor
3369
+ * @return {Duplex} The duplex stream
3370
+ * @public
3371
+ */
3372
+ function createWebSocketStream(ws, options) {
3373
+ let terminateOnDestroy = true;
3374
+ const duplex = new Duplex$2({
3375
+ ...options,
3376
+ autoDestroy: false,
3377
+ emitClose: false,
3378
+ objectMode: false,
3379
+ writableObjectMode: false
3380
+ });
3381
+ ws.on("message", function message(msg, isBinary) {
3382
+ const data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
3383
+ if (!duplex.push(data)) ws.pause();
3384
+ });
3385
+ ws.once("error", function error(err) {
3386
+ if (duplex.destroyed) return;
3387
+ terminateOnDestroy = false;
3388
+ duplex.destroy(err);
3389
+ });
3390
+ ws.once("close", function close() {
3391
+ if (duplex.destroyed) return;
3392
+ duplex.push(null);
3393
+ });
3394
+ duplex._destroy = function(err, callback) {
3395
+ if (ws.readyState === ws.CLOSED) {
3396
+ callback(err);
3397
+ process.nextTick(emitClose, duplex);
3398
+ return;
3399
+ }
3400
+ let called = false;
3401
+ ws.once("error", function error(err) {
3402
+ called = true;
3403
+ callback(err);
3404
+ });
3405
+ ws.once("close", function close() {
3406
+ if (!called) callback(err);
3407
+ process.nextTick(emitClose, duplex);
3408
+ });
3409
+ if (terminateOnDestroy) ws.terminate();
3410
+ };
3411
+ duplex._final = function(callback) {
3412
+ if (ws.readyState === ws.CONNECTING) {
3413
+ ws.once("open", function open() {
3414
+ duplex._final(callback);
3415
+ });
3416
+ return;
3417
+ }
3418
+ if (ws._socket === null) return;
3419
+ if (ws._socket._writableState.finished) {
3420
+ callback();
3421
+ if (duplex._readableState.endEmitted) duplex.destroy();
3422
+ } else {
3423
+ ws._socket.once("finish", function finish() {
3424
+ callback();
3425
+ });
3426
+ ws.close();
3427
+ }
3428
+ };
3429
+ duplex._read = function() {
3430
+ if (ws.isPaused) ws.resume();
3431
+ };
3432
+ duplex._write = function(chunk, encoding, callback) {
3433
+ if (ws.readyState === ws.CONNECTING) {
3434
+ ws.once("open", function open() {
3435
+ duplex._write(chunk, encoding, callback);
3436
+ });
3437
+ return;
3438
+ }
3439
+ ws.send(chunk, callback);
3440
+ };
3441
+ duplex.on("end", duplexOnEnd);
3442
+ duplex.on("error", duplexOnError);
3443
+ return duplex;
3444
+ }
3445
+ module.exports = createWebSocketStream;
3446
+ }));
3447
+
3448
+ //#endregion
3449
+ //#region ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/subprotocol.js
3450
+ var require_subprotocol = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3451
+ const { tokenChars } = require_validation();
3452
+ /**
3453
+ * Parses the `Sec-WebSocket-Protocol` header into a set of subprotocol names.
3454
+ *
3455
+ * @param {String} header The field value of the header
3456
+ * @return {Set} The subprotocol names
3457
+ * @public
3458
+ */
3459
+ function parse(header) {
3460
+ const protocols = /* @__PURE__ */ new Set();
3461
+ let start = -1;
3462
+ let end = -1;
3463
+ let i = 0;
3464
+ for (; i < header.length; i++) {
3465
+ const code = header.charCodeAt(i);
3466
+ if (end === -1 && tokenChars[code] === 1) {
3467
+ if (start === -1) start = i;
3468
+ } else if (i !== 0 && (code === 32 || code === 9)) {
3469
+ if (end === -1 && start !== -1) end = i;
3470
+ } else if (code === 44) {
3471
+ if (start === -1) throw new SyntaxError(`Unexpected character at index ${i}`);
3472
+ if (end === -1) end = i;
3473
+ const protocol = header.slice(start, end);
3474
+ if (protocols.has(protocol)) throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
3475
+ protocols.add(protocol);
3476
+ start = end = -1;
3477
+ } else throw new SyntaxError(`Unexpected character at index ${i}`);
3478
+ }
3479
+ if (start === -1 || end !== -1) throw new SyntaxError("Unexpected end of input");
3480
+ const protocol = header.slice(start, i);
3481
+ if (protocols.has(protocol)) throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
3482
+ protocols.add(protocol);
3483
+ return protocols;
3484
+ }
3485
+ module.exports = { parse };
3486
+ }));
3487
+
3488
+ //#endregion
3489
+ //#region ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/websocket-server.js
3490
+ var require_websocket_server = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3491
+ const EventEmitter = __require("events");
3492
+ const http = __require("http");
3493
+ const { Duplex: Duplex$1 } = __require("stream");
3494
+ const { createHash } = __require("crypto");
3495
+ const extension = require_extension();
3496
+ const PerMessageDeflate = require_permessage_deflate();
3497
+ const subprotocol = require_subprotocol();
3498
+ const WebSocket = require_websocket();
3499
+ const { CLOSE_TIMEOUT, GUID, kWebSocket } = require_constants();
3500
+ const keyRegex = /^[+/0-9A-Za-z]{22}==$/;
3501
+ const RUNNING = 0;
3502
+ const CLOSING = 1;
3503
+ const CLOSED = 2;
3504
+ /**
3505
+ * Class representing a WebSocket server.
3506
+ *
3507
+ * @extends EventEmitter
3508
+ */
3509
+ var WebSocketServer = class extends EventEmitter {
3510
+ /**
3511
+ * Create a `WebSocketServer` instance.
3512
+ *
3513
+ * @param {Object} options Configuration options
3514
+ * @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
3515
+ * any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
3516
+ * multiple times in the same tick
3517
+ * @param {Boolean} [options.autoPong=true] Specifies whether or not to
3518
+ * automatically send a pong in response to a ping
3519
+ * @param {Number} [options.backlog=511] The maximum length of the queue of
3520
+ * pending connections
3521
+ * @param {Boolean} [options.clientTracking=true] Specifies whether or not to
3522
+ * track clients
3523
+ * @param {Number} [options.closeTimeout=30000] Duration in milliseconds to
3524
+ * wait for the closing handshake to finish after `websocket.close()` is
3525
+ * called
3526
+ * @param {Function} [options.handleProtocols] A hook to handle protocols
3527
+ * @param {String} [options.host] The hostname where to bind the server
3528
+ * @param {Number} [options.maxBufferedChunks=1048576] The maximum number of
3529
+ * buffered data chunks
3530
+ * @param {Number} [options.maxFragments=131072] The maximum number of message
3531
+ * fragments
3532
+ * @param {Number} [options.maxPayload=104857600] The maximum allowed message
3533
+ * size
3534
+ * @param {Boolean} [options.noServer=false] Enable no server mode
3535
+ * @param {String} [options.path] Accept only connections matching this path
3536
+ * @param {(Boolean|Object)} [options.perMessageDeflate=false] Enable/disable
3537
+ * permessage-deflate
3538
+ * @param {Number} [options.port] The port where to bind the server
3539
+ * @param {(http.Server|https.Server)} [options.server] A pre-created HTTP/S
3540
+ * server to use
3541
+ * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
3542
+ * not to skip UTF-8 validation for text and close messages
3543
+ * @param {Function} [options.verifyClient] A hook to reject connections
3544
+ * @param {Function} [options.WebSocket=WebSocket] Specifies the `WebSocket`
3545
+ * class to use. It must be the `WebSocket` class or class that extends it
3546
+ * @param {Function} [callback] A listener for the `listening` event
3547
+ */
3548
+ constructor(options, callback) {
3549
+ super();
3550
+ options = {
3551
+ allowSynchronousEvents: true,
3552
+ autoPong: true,
3553
+ maxBufferedChunks: 1024 * 1024,
3554
+ maxFragments: 128 * 1024,
3555
+ maxPayload: 100 * 1024 * 1024,
3556
+ skipUTF8Validation: false,
3557
+ perMessageDeflate: false,
3558
+ handleProtocols: null,
3559
+ clientTracking: true,
3560
+ closeTimeout: CLOSE_TIMEOUT,
3561
+ verifyClient: null,
3562
+ noServer: false,
3563
+ backlog: null,
3564
+ server: null,
3565
+ host: null,
3566
+ path: null,
3567
+ port: null,
3568
+ WebSocket,
3569
+ ...options
3570
+ };
3571
+ if (options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer) throw new TypeError("One and only one of the \"port\", \"server\", or \"noServer\" options must be specified");
3572
+ if (options.port != null) {
3573
+ this._server = http.createServer((req, res) => {
3574
+ const body = http.STATUS_CODES[426];
3575
+ res.writeHead(426, {
3576
+ "Content-Length": body.length,
3577
+ "Content-Type": "text/plain"
3578
+ });
3579
+ res.end(body);
3580
+ });
3581
+ this._server.listen(options.port, options.host, options.backlog, callback);
3582
+ } else if (options.server) this._server = options.server;
3583
+ if (this._server) {
3584
+ const emitConnection = this.emit.bind(this, "connection");
3585
+ this._removeListeners = addListeners(this._server, {
3586
+ listening: this.emit.bind(this, "listening"),
3587
+ error: this.emit.bind(this, "error"),
3588
+ upgrade: (req, socket, head) => {
3589
+ this.handleUpgrade(req, socket, head, emitConnection);
3590
+ }
3591
+ });
3592
+ }
3593
+ if (options.perMessageDeflate === true) options.perMessageDeflate = {};
3594
+ if (options.clientTracking) {
3595
+ this.clients = /* @__PURE__ */ new Set();
3596
+ this._shouldEmitClose = false;
3597
+ }
3598
+ this.options = options;
3599
+ this._state = RUNNING;
3600
+ }
3601
+ /**
3602
+ * Returns the bound address, the address family name, and port of the server
3603
+ * as reported by the operating system if listening on an IP socket.
3604
+ * If the server is listening on a pipe or UNIX domain socket, the name is
3605
+ * returned as a string.
3606
+ *
3607
+ * @return {(Object|String|null)} The address of the server
3608
+ * @public
3609
+ */
3610
+ address() {
3611
+ if (this.options.noServer) throw new Error("The server is operating in \"noServer\" mode");
3612
+ if (!this._server) return null;
3613
+ return this._server.address();
3614
+ }
3615
+ /**
3616
+ * Stop the server from accepting new connections and emit the `'close'` event
3617
+ * when all existing connections are closed.
3618
+ *
3619
+ * @param {Function} [cb] A one-time listener for the `'close'` event
3620
+ * @public
3621
+ */
3622
+ close(cb) {
3623
+ if (this._state === CLOSED) {
3624
+ if (cb) this.once("close", () => {
3625
+ cb(/* @__PURE__ */ new Error("The server is not running"));
3626
+ });
3627
+ process.nextTick(emitClose, this);
3628
+ return;
3629
+ }
3630
+ if (cb) this.once("close", cb);
3631
+ if (this._state === CLOSING) return;
3632
+ this._state = CLOSING;
3633
+ if (this.options.noServer || this.options.server) {
3634
+ if (this._server) {
3635
+ this._removeListeners();
3636
+ this._removeListeners = this._server = null;
3637
+ }
3638
+ if (this.clients) if (!this.clients.size) process.nextTick(emitClose, this);
3639
+ else this._shouldEmitClose = true;
3640
+ else process.nextTick(emitClose, this);
3641
+ } else {
3642
+ const server = this._server;
3643
+ this._removeListeners();
3644
+ this._removeListeners = this._server = null;
3645
+ server.close(() => {
3646
+ emitClose(this);
3647
+ });
3648
+ }
3649
+ }
3650
+ /**
3651
+ * See if a given request should be handled by this server instance.
3652
+ *
3653
+ * @param {http.IncomingMessage} req Request object to inspect
3654
+ * @return {Boolean} `true` if the request is valid, else `false`
3655
+ * @public
3656
+ */
3657
+ shouldHandle(req) {
3658
+ if (this.options.path) {
3659
+ const index = req.url.indexOf("?");
3660
+ if ((index !== -1 ? req.url.slice(0, index) : req.url) !== this.options.path) return false;
3661
+ }
3662
+ return true;
3663
+ }
3664
+ /**
3665
+ * Handle a HTTP Upgrade request.
3666
+ *
3667
+ * @param {http.IncomingMessage} req The request object
3668
+ * @param {Duplex} socket The network socket between the server and client
3669
+ * @param {Buffer} head The first packet of the upgraded stream
3670
+ * @param {Function} cb Callback
3671
+ * @public
3672
+ */
3673
+ handleUpgrade(req, socket, head, cb) {
3674
+ socket.on("error", socketOnError);
3675
+ const key = req.headers["sec-websocket-key"];
3676
+ const upgrade = req.headers.upgrade;
3677
+ const version = +req.headers["sec-websocket-version"];
3678
+ if (req.method !== "GET") {
3679
+ abortHandshakeOrEmitwsClientError(this, req, socket, 405, "Invalid HTTP method");
3680
+ return;
3681
+ }
3682
+ if (upgrade === void 0 || upgrade.toLowerCase() !== "websocket") {
3683
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, "Invalid Upgrade header");
3684
+ return;
3685
+ }
3686
+ if (key === void 0 || !keyRegex.test(key)) {
3687
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, "Missing or invalid Sec-WebSocket-Key header");
3688
+ return;
3689
+ }
3690
+ if (version !== 13 && version !== 8) {
3691
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, "Missing or invalid Sec-WebSocket-Version header", { "Sec-WebSocket-Version": "13, 8" });
3692
+ return;
3693
+ }
3694
+ if (!this.shouldHandle(req)) {
3695
+ abortHandshake(socket, 400);
3696
+ return;
3697
+ }
3698
+ const secWebSocketProtocol = req.headers["sec-websocket-protocol"];
3699
+ let protocols = /* @__PURE__ */ new Set();
3700
+ if (secWebSocketProtocol !== void 0) try {
3701
+ protocols = subprotocol.parse(secWebSocketProtocol);
3702
+ } catch (err) {
3703
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, "Invalid Sec-WebSocket-Protocol header");
3704
+ return;
3705
+ }
3706
+ const secWebSocketExtensions = req.headers["sec-websocket-extensions"];
3707
+ const extensions = {};
3708
+ if (this.options.perMessageDeflate && secWebSocketExtensions !== void 0) {
3709
+ const perMessageDeflate = new PerMessageDeflate({
3710
+ ...this.options.perMessageDeflate,
3711
+ isServer: true,
3712
+ maxPayload: this.options.maxPayload
3713
+ });
3714
+ try {
3715
+ const offers = extension.parse(secWebSocketExtensions);
3716
+ if (offers[PerMessageDeflate.extensionName]) {
3717
+ perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
3718
+ extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
3719
+ }
3720
+ } catch (err) {
3721
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, "Invalid or unacceptable Sec-WebSocket-Extensions header");
3722
+ return;
3723
+ }
3724
+ }
3725
+ if (this.options.verifyClient) {
3726
+ const info = {
3727
+ origin: req.headers[`${version === 8 ? "sec-websocket-origin" : "origin"}`],
3728
+ secure: !!(req.socket.authorized || req.socket.encrypted),
3729
+ req
3730
+ };
3731
+ if (this.options.verifyClient.length === 2) {
3732
+ this.options.verifyClient(info, (verified, code, message, headers) => {
3733
+ if (!verified) return abortHandshake(socket, code || 401, message, headers);
3734
+ this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
3735
+ });
3736
+ return;
3737
+ }
3738
+ if (!this.options.verifyClient(info)) return abortHandshake(socket, 401);
3739
+ }
3740
+ this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
3741
+ }
3742
+ /**
3743
+ * Upgrade the connection to WebSocket.
3744
+ *
3745
+ * @param {Object} extensions The accepted extensions
3746
+ * @param {String} key The value of the `Sec-WebSocket-Key` header
3747
+ * @param {Set} protocols The subprotocols
3748
+ * @param {http.IncomingMessage} req The request object
3749
+ * @param {Duplex} socket The network socket between the server and client
3750
+ * @param {Buffer} head The first packet of the upgraded stream
3751
+ * @param {Function} cb Callback
3752
+ * @throws {Error} If called more than once with the same socket
3753
+ * @private
3754
+ */
3755
+ completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
3756
+ if (!socket.readable || !socket.writable) return socket.destroy();
3757
+ if (socket[kWebSocket]) throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");
3758
+ if (this._state > RUNNING) return abortHandshake(socket, 503);
3759
+ const headers = [
3760
+ "HTTP/1.1 101 Switching Protocols",
3761
+ "Upgrade: websocket",
3762
+ "Connection: Upgrade",
3763
+ `Sec-WebSocket-Accept: ${createHash("sha1").update(key + GUID).digest("base64")}`
3764
+ ];
3765
+ const ws = new this.options.WebSocket(null, void 0, this.options);
3766
+ if (protocols.size) {
3767
+ const protocol = this.options.handleProtocols ? this.options.handleProtocols(protocols, req) : protocols.values().next().value;
3768
+ if (protocol) {
3769
+ headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
3770
+ ws._protocol = protocol;
3771
+ }
3772
+ }
3773
+ if (extensions[PerMessageDeflate.extensionName]) {
3774
+ const params = extensions[PerMessageDeflate.extensionName].params;
3775
+ const value = extension.format({ [PerMessageDeflate.extensionName]: [params] });
3776
+ headers.push(`Sec-WebSocket-Extensions: ${value}`);
3777
+ ws._extensions = extensions;
3778
+ }
3779
+ this.emit("headers", headers, req);
3780
+ socket.write(headers.concat("\r\n").join("\r\n"));
3781
+ socket.removeListener("error", socketOnError);
3782
+ ws.setSocket(socket, head, {
3783
+ allowSynchronousEvents: this.options.allowSynchronousEvents,
3784
+ maxBufferedChunks: this.options.maxBufferedChunks,
3785
+ maxFragments: this.options.maxFragments,
3786
+ maxPayload: this.options.maxPayload,
3787
+ skipUTF8Validation: this.options.skipUTF8Validation
3788
+ });
3789
+ if (this.clients) {
3790
+ this.clients.add(ws);
3791
+ ws.on("close", () => {
3792
+ this.clients.delete(ws);
3793
+ if (this._shouldEmitClose && !this.clients.size) process.nextTick(emitClose, this);
3794
+ });
3795
+ }
3796
+ cb(ws, req);
3797
+ }
3798
+ };
3799
+ module.exports = WebSocketServer;
3800
+ /**
3801
+ * Add event listeners on an `EventEmitter` using a map of <event, listener>
3802
+ * pairs.
3803
+ *
3804
+ * @param {EventEmitter} server The event emitter
3805
+ * @param {Object.<String, Function>} map The listeners to add
3806
+ * @return {Function} A function that will remove the added listeners when
3807
+ * called
3808
+ * @private
3809
+ */
3810
+ function addListeners(server, map) {
3811
+ for (const event of Object.keys(map)) server.on(event, map[event]);
3812
+ return function removeListeners() {
3813
+ for (const event of Object.keys(map)) server.removeListener(event, map[event]);
3814
+ };
3815
+ }
3816
+ /**
3817
+ * Emit a `'close'` event on an `EventEmitter`.
3818
+ *
3819
+ * @param {EventEmitter} server The event emitter
3820
+ * @private
3821
+ */
3822
+ function emitClose(server) {
3823
+ server._state = CLOSED;
3824
+ server.emit("close");
3825
+ }
3826
+ /**
3827
+ * Handle socket errors.
3828
+ *
3829
+ * @private
3830
+ */
3831
+ function socketOnError() {
3832
+ this.destroy();
3833
+ }
3834
+ /**
3835
+ * Close the connection when preconditions are not fulfilled.
3836
+ *
3837
+ * @param {Duplex} socket The socket of the upgrade request
3838
+ * @param {Number} code The HTTP response status code
3839
+ * @param {String} [message] The HTTP response body
3840
+ * @param {Object} [headers] Additional HTTP response headers
3841
+ * @private
3842
+ */
3843
+ function abortHandshake(socket, code, message, headers) {
3844
+ message = message || http.STATUS_CODES[code];
3845
+ headers = {
3846
+ Connection: "close",
3847
+ "Content-Type": "text/html",
3848
+ "Content-Length": Buffer.byteLength(message),
3849
+ ...headers
3850
+ };
3851
+ socket.once("finish", socket.destroy);
3852
+ socket.end(`HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r\n` + Object.keys(headers).map((h) => `${h}: ${headers[h]}`).join("\r\n") + "\r\n\r\n" + message);
3853
+ }
3854
+ /**
3855
+ * Emit a `'wsClientError'` event on a `WebSocketServer` if there is at least
3856
+ * one listener for it, otherwise call `abortHandshake()`.
3857
+ *
3858
+ * @param {WebSocketServer} server The WebSocket server
3859
+ * @param {http.IncomingMessage} req The request object
3860
+ * @param {Duplex} socket The socket of the upgrade request
3861
+ * @param {Number} code The HTTP response status code
3862
+ * @param {String} message The HTTP response body
3863
+ * @param {Object} [headers] The HTTP response headers
3864
+ * @private
3865
+ */
3866
+ function abortHandshakeOrEmitwsClientError(server, req, socket, code, message, headers) {
3867
+ if (server.listenerCount("wsClientError")) {
3868
+ const err = new Error(message);
3869
+ Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
3870
+ server.emit("wsClientError", err, socket, req);
3871
+ } else abortHandshake(socket, code, message, headers);
3872
+ }
3873
+ }));
3874
+
3875
+ //#endregion
3876
+ //#region ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/wrapper.mjs
3877
+ var import_stream = /* @__PURE__ */ __toESM(require_stream(), 1);
3878
+ var import_extension = /* @__PURE__ */ __toESM(require_extension(), 1);
3879
+ var import_permessage_deflate = /* @__PURE__ */ __toESM(require_permessage_deflate(), 1);
3880
+ var import_receiver = /* @__PURE__ */ __toESM(require_receiver(), 1);
3881
+ var import_sender = /* @__PURE__ */ __toESM(require_sender(), 1);
3882
+ var import_subprotocol = /* @__PURE__ */ __toESM(require_subprotocol(), 1);
3883
+ var import_websocket = /* @__PURE__ */ __toESM(require_websocket(), 1);
3884
+ var import_websocket_server = /* @__PURE__ */ __toESM(require_websocket_server(), 1);
3885
+
3886
+ //#endregion
3887
+ //#region ../../node_modules/.pnpm/@effect+platform-node@4.0.0-beta.59_effect@4.0.0-beta.59_ioredis@5.11.0/node_modules/@effect/platform-node/dist/NodeHttpServer.js
3888
+ /**
3889
+ * @since 1.0.0
3890
+ */
3891
+ /**
3892
+ * @since 1.0.0
3893
+ * @category constructors
3894
+ */
3895
+ const make = /* @__PURE__ */ fnUntraced(function* (evaluate, options) {
3896
+ const scope$1 = yield* scope;
3897
+ const server = evaluate();
3898
+ const shutdown = yield* callback((resume) => {
3899
+ if (!server.listening) return resume(void_);
3900
+ server.close((error) => {
3901
+ if (error) resume(die(error));
3902
+ else resume(void_);
3903
+ });
3904
+ }).pipe(cached);
3905
+ const preemptiveShutdown = options.disablePreemptiveShutdown ? void_ : timeoutOrElse(shutdown, {
3906
+ duration: options.gracefulShutdownTimeout ?? seconds(20),
3907
+ orElse: () => void_
3908
+ });
3909
+ yield* addFinalizer(scope$1, shutdown);
3910
+ yield* callback((resume) => {
3911
+ function onError(cause) {
3912
+ resume(fail(new ServeError({ cause })));
3913
+ }
3914
+ server.on("error", onError);
3915
+ server.listen(options, () => {
3916
+ server.off("error", onError);
3917
+ resume(void_);
3918
+ });
3919
+ });
3920
+ const address = server.address();
3921
+ const wss = yield* acquireRelease(sync(() => new import_websocket_server.default({ noServer: true })), (wss) => callback((resume) => {
3922
+ wss.close(() => resume(void_));
3923
+ })).pipe(provide$1(scope$1), cached);
3924
+ return make$5({
3925
+ address: typeof address === "string" ? {
3926
+ _tag: "UnixAddress",
3927
+ path: address
3928
+ } : {
3929
+ _tag: "TcpAddress",
3930
+ hostname: address.address === "::" ? "0.0.0.0" : address.address,
3931
+ port: address.port
3932
+ },
3933
+ serve: fnUntraced(function* (httpApp, middleware) {
3934
+ const serveScope = yield* scope;
3935
+ const scope$2 = forkUnsafe(serveScope, "parallel");
3936
+ const handler = yield* makeHandler(httpApp, {
3937
+ middleware,
3938
+ scope: scope$2
3939
+ });
3940
+ const upgradeHandler = yield* makeUpgradeHandler(wss, httpApp, {
3941
+ middleware,
3942
+ scope: scope$2
3943
+ });
3944
+ yield* addFinalizerExit(serveScope, () => {
3945
+ server.off("request", handler);
3946
+ server.off("upgrade", upgradeHandler);
3947
+ return preemptiveShutdown;
3948
+ });
3949
+ server.on("request", handler);
3950
+ server.on("upgrade", upgradeHandler);
3951
+ })
3952
+ });
3953
+ });
3954
+ /**
3955
+ * @since 1.0.0
3956
+ * @category Handlers
3957
+ */
3958
+ const makeHandler = (httpEffect, options) => {
3959
+ const handled = toHandled(httpEffect, handleResponse, options.middleware);
3960
+ return withFiber((parent) => {
3961
+ const services = parent.context;
3962
+ return succeed(function handler(nodeRequest, nodeResponse) {
3963
+ const map = new Map(services.mapUnsafe);
3964
+ map.set(HttpServerRequest.key, new ServerRequestImpl(nodeRequest, nodeResponse));
3965
+ const fiber = runIn(runForkWith(makeUnsafe(map))(handled), options.scope);
3966
+ nodeResponse.on("close", () => {
3967
+ if (!nodeResponse.writableEnded) fiber.interruptUnsafe(parent.id, ClientAbort.annotation);
3968
+ });
3969
+ });
3970
+ });
3971
+ };
3972
+ /**
3973
+ * @since 1.0.0
3974
+ * @category Handlers
3975
+ */
3976
+ const makeUpgradeHandler = (lazyWss, httpEffect, options) => {
3977
+ const handledApp = toHandled(httpEffect, handleResponse, options.middleware);
3978
+ return withFiber((parent) => {
3979
+ const services = parent.context;
3980
+ return succeed(function handler(nodeRequest, socket, head) {
3981
+ let nodeResponse_ = void 0;
3982
+ const nodeResponse = () => {
3983
+ if (nodeResponse_ === void 0) {
3984
+ nodeResponse_ = new Http.ServerResponse(nodeRequest);
3985
+ nodeResponse_.assignSocket(socket);
3986
+ nodeResponse_.on("finish", () => {
3987
+ socket.end();
3988
+ });
3989
+ }
3990
+ return nodeResponse_;
3991
+ };
3992
+ const upgradeEffect = fromWebSocket(flatMap(lazyWss, (wss) => acquireRelease(callback((resume) => wss.handleUpgrade(nodeRequest, socket, head, (ws) => {
3993
+ resume(succeed(ws));
3994
+ })), (ws) => sync(() => ws.close()))));
3995
+ const map = new Map(services.mapUnsafe);
3996
+ map.set(HttpServerRequest.key, new ServerRequestImpl(nodeRequest, nodeResponse, upgradeEffect));
3997
+ const fiber = runIn(runForkWith(makeUnsafe(map))(handledApp), options.scope);
3998
+ socket.on("close", () => {
3999
+ if (!socket.writableEnded) fiber.interruptUnsafe(parent.id, ClientAbort.annotation);
4000
+ });
4001
+ });
4002
+ });
4003
+ };
4004
+ var ServerRequestImpl = class ServerRequestImpl extends NodeHttpIncomingMessage {
4005
+ [TypeId$2];
4006
+ response;
4007
+ upgradeEffect;
4008
+ url;
4009
+ headersOverride;
4010
+ constructor(source, response, upgradeEffect, url = source.url, headersOverride, remoteAddressOverride) {
4011
+ super(source, (cause) => new HttpServerError({ reason: new RequestParseError({
4012
+ request: this,
4013
+ cause
4014
+ }) }), remoteAddressOverride);
4015
+ this[TypeId$2] = TypeId$2;
4016
+ this.response = response;
4017
+ this.upgradeEffect = upgradeEffect;
4018
+ this.url = url;
4019
+ this.headersOverride = headersOverride;
4020
+ }
4021
+ cachedCookies;
4022
+ get cookies() {
4023
+ if (this.cachedCookies) return this.cachedCookies;
4024
+ return this.cachedCookies = parseHeader(this.headers.cookie ?? "");
4025
+ }
4026
+ get resolvedResponse() {
4027
+ return typeof this.response === "function" ? this.response() : this.response;
4028
+ }
4029
+ modify(options) {
4030
+ return new ServerRequestImpl(this.source, this.response, this.upgradeEffect, options.url ?? this.url, options.headers ?? this.headersOverride, "remoteAddress" in options ? options.remoteAddress : this.remoteAddressOverride);
4031
+ }
4032
+ get originalUrl() {
4033
+ return this.source.url;
4034
+ }
4035
+ get method() {
4036
+ return this.source.method.toUpperCase();
4037
+ }
4038
+ get headers() {
4039
+ this.headersOverride ??= this.source.headers;
4040
+ return this.headersOverride;
4041
+ }
4042
+ multipartEffect;
4043
+ get multipart() {
4044
+ if (this.multipartEffect) return this.multipartEffect;
4045
+ this.multipartEffect = runSync(cached(persisted(this.source, this.source.headers)));
4046
+ return this.multipartEffect;
4047
+ }
4048
+ get multipartStream() {
4049
+ return stream(this.source, this.source.headers);
4050
+ }
4051
+ get upgrade() {
4052
+ return this.upgradeEffect ?? fail(new HttpServerError({ reason: new RequestParseError({
4053
+ request: this,
4054
+ description: "not an upgradeable ServerRequest"
4055
+ }) }));
4056
+ }
4057
+ toString() {
4058
+ return `ServerRequest(${this.method} ${this.url})`;
4059
+ }
4060
+ toJSON() {
4061
+ return inspect(this, {
4062
+ _id: "HttpServerRequest",
4063
+ method: this.method,
4064
+ url: this.originalUrl
4065
+ });
4066
+ }
4067
+ };
4068
+ /**
4069
+ * @since 1.0.0
4070
+ * @category Layers
4071
+ */
4072
+ const layerServer = /* @__PURE__ */ flow(make, /* @__PURE__ */ effect(HttpServer));
4073
+ /**
4074
+ * @since 1.0.0
4075
+ * @category Layers
4076
+ */
4077
+ const layerHttpServices = /* @__PURE__ */ mergeAll(layer$1, layerWeak, layer$4);
4078
+ /**
4079
+ * @since 1.0.0
4080
+ * @category Layers
4081
+ */
4082
+ const layer = (evaluate, options) => mergeAll(layerServer(evaluate, options), layerHttpServices);
4083
+ /**
4084
+ * @since 1.0.0
4085
+ * @category Layers
4086
+ */
4087
+ const layerConfig = (evaluate, options) => mergeAll(effect(HttpServer)(flatMap(unwrap$1(options).asEffect(), (options) => make(evaluate, options))), layerHttpServices);
4088
+ /**
4089
+ * @since 1.0.0
4090
+ * @category Testing
4091
+ */
4092
+ const layerTest = /* @__PURE__ */ layerTestClient.pipe(/* @__PURE__ */ provide(/* @__PURE__ */ fresh(layer$5).pipe(/* @__PURE__ */ provide(/* @__PURE__ */ succeed$1(RequestInit)({ keepalive: false })))), /* @__PURE__ */ provideMerge(/* @__PURE__ */ layer(Http.createServer, { port: 0 })));
4093
+ const handleResponse = (request, response) => {
4094
+ const nodeResponse = request.resolvedResponse;
4095
+ if (nodeResponse.writableEnded) return void_;
4096
+ let headers = response.headers;
4097
+ if (!isEmpty(response.cookies)) {
4098
+ headers = { ...headers };
4099
+ const toSet = toSetCookieHeaders(response.cookies);
4100
+ if (headers["set-cookie"] !== void 0) toSet.push(headers["set-cookie"]);
4101
+ headers["set-cookie"] = toSet;
4102
+ }
4103
+ if (request.method === "HEAD") {
4104
+ nodeResponse.writeHead(response.status, headers);
4105
+ return callback((resume) => {
4106
+ nodeResponse.end(() => resume(void_));
4107
+ });
4108
+ }
4109
+ const body = response.body;
4110
+ switch (body._tag) {
4111
+ case "Empty":
4112
+ nodeResponse.writeHead(response.status, headers);
4113
+ nodeResponse.end();
4114
+ return void_;
4115
+ case "Raw":
4116
+ nodeResponse.writeHead(response.status, headers);
4117
+ if (typeof body.body === "object" && body.body !== null && "pipe" in body.body && typeof body.body.pipe === "function") return tryPromise({
4118
+ try: (signal) => pipeline(body.body, nodeResponse, {
4119
+ signal,
4120
+ end: true
4121
+ }),
4122
+ catch: (cause) => new HttpServerError({ reason: new ResponseError({
4123
+ request,
4124
+ response,
4125
+ description: "Error writing raw response",
4126
+ cause
4127
+ }) })
4128
+ }).pipe(interruptible, tapCause(handleCause(nodeResponse, response)));
4129
+ return callback((resume) => {
4130
+ nodeResponse.end(body.body, () => resume(void_));
4131
+ });
4132
+ case "Uint8Array":
4133
+ nodeResponse.writeHead(response.status, headers);
4134
+ if (body.body.length < 1024 * 1024) {
4135
+ nodeResponse.end(body.body);
4136
+ return void_;
4137
+ }
4138
+ return callback((resume) => {
4139
+ nodeResponse.end(body.body, () => resume(void_));
4140
+ });
4141
+ case "FormData": return suspend(() => {
4142
+ const r = new globalThis.Response(body.formData);
4143
+ nodeResponse.writeHead(response.status, {
4144
+ ...headers,
4145
+ ...Object.fromEntries(r.headers)
4146
+ });
4147
+ return callback((resume, signal) => {
4148
+ Readable.fromWeb(r.body, { signal }).pipe(nodeResponse).on("error", (cause) => {
4149
+ resume(fail(new HttpServerError({ reason: new ResponseError({
4150
+ request,
4151
+ response,
4152
+ description: "Error writing FormData response",
4153
+ cause
4154
+ }) })));
4155
+ }).once("finish", () => {
4156
+ resume(void_);
4157
+ });
4158
+ }).pipe(interruptible, tapCause(handleCause(nodeResponse, response)));
4159
+ });
4160
+ case "Stream": {
4161
+ nodeResponse.writeHead(response.status, headers);
4162
+ const drainLatch = makeUnsafe$1();
4163
+ nodeResponse.on("drain", () => drainLatch.openUnsafe());
4164
+ return body.stream.pipe(orDie, runForEachArray((array) => {
4165
+ let needDrain = false;
4166
+ for (let i = 0; i < array.length; i++) {
4167
+ const written = nodeResponse.write(array[i]);
4168
+ if (!written && !needDrain) {
4169
+ needDrain = true;
4170
+ drainLatch.closeUnsafe();
4171
+ } else if (written && needDrain) needDrain = false;
4172
+ }
4173
+ if (!needDrain) return void_;
4174
+ return drainLatch.await;
4175
+ }), interruptible, matchCauseEffect({
4176
+ onSuccess: () => sync(() => nodeResponse.end()),
4177
+ onFailure: handleCause(nodeResponse, response)
4178
+ }));
4179
+ }
4180
+ }
4181
+ };
4182
+ const handleCause = (nodeResponse, originalResponse) => (originalCause) => flatMap(causeResponse(originalCause), ([response, cause]) => {
4183
+ const headersSent = nodeResponse.headersSent;
4184
+ if (!headersSent) nodeResponse.writeHead(response.status);
4185
+ if (!nodeResponse.writableEnded) nodeResponse.end();
4186
+ return failCause(headersSent ? combine(originalCause, die$1(originalResponse)) : cause);
4187
+ });
4188
+
4189
+ //#endregion
4190
+ export { layer, layerConfig, layerHttpServices, layerServer, layerTest, make, makeHandler, makeUpgradeHandler };