@1delta/margin-fetcher 0.0.78 → 0.0.80

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 (269) hide show
  1. package/dist/_esm-32O7VXQT.js +3641 -0
  2. package/dist/_esm-32O7VXQT.js.map +1 -0
  3. package/dist/abis/aave/AaveOracle.d.ts +50 -0
  4. package/dist/abis/aave/AaveOracle.d.ts.map +1 -0
  5. package/dist/abis/aave/AavePoolAndDataProvider.d.ts +1618 -0
  6. package/dist/abis/aave/AavePoolAndDataProvider.d.ts.map +1 -0
  7. package/dist/abis/aave/AavePoolV3Upgraded.d.ts +1134 -0
  8. package/dist/abis/aave/AavePoolV3Upgraded.d.ts.map +1 -0
  9. package/dist/abis/aave/AaveV3ProtocolDataProvider.d.ts +420 -0
  10. package/dist/abis/aave/AaveV3ProtocolDataProvider.d.ts.map +1 -0
  11. package/dist/abis/aave/VariableDebtToken.d.ts +635 -0
  12. package/dist/abis/aave/VariableDebtToken.d.ts.map +1 -0
  13. package/dist/abis/aave-v2/ProtocolDataProvider.d.ts +238 -0
  14. package/dist/abis/aave-v2/ProtocolDataProvider.d.ts.map +1 -0
  15. package/dist/abis/aave-v2/YLDR.d.ts +209 -0
  16. package/dist/abis/aave-v2/YLDR.d.ts.map +1 -0
  17. package/dist/abis/aave-v3/AavePoolDataProviderLegacy.d.ts +406 -0
  18. package/dist/abis/aave-v3/AavePoolDataProviderLegacy.d.ts.map +1 -0
  19. package/dist/abis/aave-v3/AavePoolLegacy.d.ts +819 -0
  20. package/dist/abis/aave-v3/AavePoolLegacy.d.ts.map +1 -0
  21. package/dist/abis/aave-v3/YLDR.d.ts +36 -0
  22. package/dist/abis/aave-v3/YLDR.d.ts.map +1 -0
  23. package/dist/abis/aurelius/Rewarder.d.ts +90 -0
  24. package/dist/abis/aurelius/Rewarder.d.ts.map +1 -0
  25. package/dist/abis/compound-v2/CompoundLens.d.ts +656 -0
  26. package/dist/abis/compound-v2/CompoundLens.d.ts.map +1 -0
  27. package/dist/abis/compound-v2/Comptroller.d.ts +1615 -0
  28. package/dist/abis/compound-v2/Comptroller.d.ts.map +1 -0
  29. package/dist/abis/compound-v3/Comet.d.ts +1382 -0
  30. package/dist/abis/compound-v3/Comet.d.ts.map +1 -0
  31. package/dist/abis/compound-v3/CometExt.d.ts +411 -0
  32. package/dist/abis/compound-v3/CometExt.d.ts.map +1 -0
  33. package/dist/abis/compound-v3/CometLens.d.ts +152 -0
  34. package/dist/abis/compound-v3/CometLens.d.ts.map +1 -0
  35. package/dist/abis/compound-v3/CometRewards.d.ts +253 -0
  36. package/dist/abis/compound-v3/CometRewards.d.ts.map +1 -0
  37. package/dist/abis/compound-v3/IrGetter.d.ts +24 -0
  38. package/dist/abis/compound-v3/IrGetter.d.ts.map +1 -0
  39. package/dist/abis/flashloan-united/flashAbi.d.ts +54 -0
  40. package/dist/abis/flashloan-united/flashAbi.d.ts.map +1 -0
  41. package/dist/abis/init/InitLens.d.ts +158 -0
  42. package/dist/abis/init/InitLens.d.ts.map +1 -0
  43. package/dist/abis/lendle/IncentivesController.d.ts +404 -0
  44. package/dist/abis/lendle/IncentivesController.d.ts.map +1 -0
  45. package/dist/abis/lendle/MultiFeeDistribution.d.ts +624 -0
  46. package/dist/abis/lendle/MultiFeeDistribution.d.ts.map +1 -0
  47. package/dist/abis/meridian/PullRewardsIncentivesController.d.ts +74 -0
  48. package/dist/abis/meridian/PullRewardsIncentivesController.d.ts.map +1 -0
  49. package/dist/abis/morpho/blue.d.ts +76 -0
  50. package/dist/abis/morpho/blue.d.ts.map +1 -0
  51. package/dist/abis/morpho/lens.d.ts +39 -0
  52. package/dist/abis/morpho/lens.d.ts.map +1 -0
  53. package/dist/abis/multicall/Multicall.d.ts +80 -0
  54. package/dist/abis/multicall/Multicall.d.ts.map +1 -0
  55. package/dist/abis/oracle/AaveOracle.d.ts +50 -0
  56. package/dist/abis/oracle/AaveOracle.d.ts.map +1 -0
  57. package/dist/abis/oracle/Api3Oracle.d.ts +48 -0
  58. package/dist/abis/oracle/Api3Oracle.d.ts.map +1 -0
  59. package/dist/abis/oracle/ChainLinkAggregator.d.ts +372 -0
  60. package/dist/abis/oracle/ChainLinkAggregator.d.ts.map +1 -0
  61. package/dist/abis/oracle/ProxyOracle.d.ts +12 -0
  62. package/dist/abis/oracle/ProxyOracle.d.ts.map +1 -0
  63. package/dist/abis/oracle/RWADynamicOracle.d.ts +12 -0
  64. package/dist/abis/oracle/RWADynamicOracle.d.ts.map +1 -0
  65. package/dist/abis/oracle/UniV3.d.ts +50 -0
  66. package/dist/abis/oracle/UniV3.d.ts.map +1 -0
  67. package/dist/abis/oracle/UniswapV2Pair.d.ts +513 -0
  68. package/dist/abis/oracle/UniswapV2Pair.d.ts.map +1 -0
  69. package/dist/assets/index.d.ts +15 -0
  70. package/dist/assets/index.d.ts.map +1 -0
  71. package/dist/assets/liquidityThresholds.d.ts +39 -0
  72. package/dist/assets/liquidityThresholds.d.ts.map +1 -0
  73. package/dist/ccip-DSCWXCSY-ZTHOXJV6.js +4 -0
  74. package/dist/ccip-DSCWXCSY-ZTHOXJV6.js.map +1 -0
  75. package/dist/ccip-V63HKYUC.js +5 -0
  76. package/dist/ccip-V63HKYUC.js.map +1 -0
  77. package/dist/chunk-5R4LXFCO.js +4078 -0
  78. package/dist/chunk-5R4LXFCO.js.map +1 -0
  79. package/dist/chunk-BYTNVMX7.js +369 -0
  80. package/dist/chunk-BYTNVMX7.js.map +1 -0
  81. package/dist/chunk-O4JCFUFK.js +3974 -0
  82. package/dist/chunk-O4JCFUFK.js.map +1 -0
  83. package/dist/chunk-PR4QN5HX.js +39 -0
  84. package/dist/chunk-PR4QN5HX.js.map +1 -0
  85. package/dist/flash-liquidity/assets.d.ts +21 -0
  86. package/dist/flash-liquidity/assets.d.ts.map +1 -0
  87. package/dist/flash-liquidity/fetchLiquidity.d.ts +4 -0
  88. package/dist/flash-liquidity/fetchLiquidity.d.ts.map +1 -0
  89. package/dist/flash-liquidity/index.d.ts +3 -0
  90. package/dist/flash-liquidity/index.d.ts.map +1 -0
  91. package/dist/flash-liquidity/types.d.ts +24 -0
  92. package/dist/flash-liquidity/types.d.ts.map +1 -0
  93. package/dist/flash-liquidity/utils.d.ts +12 -0
  94. package/dist/flash-liquidity/utils.d.ts.map +1 -0
  95. package/dist/index.d.ts +8 -0
  96. package/dist/index.d.ts.map +1 -0
  97. package/dist/index.js +24456 -0
  98. package/dist/index.js.map +1 -0
  99. package/dist/lending/aave-v2-type/misc.d.ts +8 -0
  100. package/dist/lending/aave-v2-type/misc.d.ts.map +1 -0
  101. package/dist/lending/aave-v2-type/publicCallBuild.d.ts +7 -0
  102. package/dist/lending/aave-v2-type/publicCallBuild.d.ts.map +1 -0
  103. package/dist/lending/aave-v2-type/publicCallParse.d.ts +8 -0
  104. package/dist/lending/aave-v2-type/publicCallParse.d.ts.map +1 -0
  105. package/dist/lending/aave-v3-type/publicCallBuild.d.ts +5 -0
  106. package/dist/lending/aave-v3-type/publicCallBuild.d.ts.map +1 -0
  107. package/dist/lending/aave-v3-type/publicCallParse.d.ts +9 -0
  108. package/dist/lending/aave-v3-type/publicCallParse.d.ts.map +1 -0
  109. package/dist/lending/addresses/aave.d.ts +10 -0
  110. package/dist/lending/addresses/aave.d.ts.map +1 -0
  111. package/dist/lending/addresses/aaveV2.d.ts +6 -0
  112. package/dist/lending/addresses/aaveV2.d.ts.map +1 -0
  113. package/dist/lending/addresses/aurelius.d.ts +12 -0
  114. package/dist/lending/addresses/aurelius.d.ts.map +1 -0
  115. package/dist/lending/addresses/compoundV3.d.ts +9 -0
  116. package/dist/lending/addresses/compoundV3.d.ts.map +1 -0
  117. package/dist/lending/addresses/contracts.d.ts +4 -0
  118. package/dist/lending/addresses/contracts.d.ts.map +1 -0
  119. package/dist/lending/addresses/hana.d.ts +6 -0
  120. package/dist/lending/addresses/hana.d.ts.map +1 -0
  121. package/dist/lending/addresses/index.d.ts +2 -0
  122. package/dist/lending/addresses/index.d.ts.map +1 -0
  123. package/dist/lending/addresses/init.d.ts +4 -0
  124. package/dist/lending/addresses/init.d.ts.map +1 -0
  125. package/dist/lending/addresses/lendle.d.ts +12 -0
  126. package/dist/lending/addresses/lendle.d.ts.map +1 -0
  127. package/dist/lending/addresses/meridian.d.ts +15 -0
  128. package/dist/lending/addresses/meridian.d.ts.map +1 -0
  129. package/dist/lending/addresses/takotako.d.ts +12 -0
  130. package/dist/lending/addresses/takotako.d.ts.map +1 -0
  131. package/dist/lending/compound-v3/publicCallBuild.d.ts +3 -0
  132. package/dist/lending/compound-v3/publicCallBuild.d.ts.map +1 -0
  133. package/dist/lending/compound-v3/publicCallParse.d.ts +8 -0
  134. package/dist/lending/compound-v3/publicCallParse.d.ts.map +1 -0
  135. package/dist/lending/fetchLender.d.ts +9 -0
  136. package/dist/lending/fetchLender.d.ts.map +1 -0
  137. package/dist/lending/fetchLenderAll.d.ts +9 -0
  138. package/dist/lending/fetchLenderAll.d.ts.map +1 -0
  139. package/dist/lending/fetchLenderExt.d.ts +9 -0
  140. package/dist/lending/fetchLenderExt.d.ts.map +1 -0
  141. package/dist/lending/index.d.ts +6 -0
  142. package/dist/lending/index.d.ts.map +1 -0
  143. package/dist/lending/init/publicCallBuild.d.ts +7 -0
  144. package/dist/lending/init/publicCallBuild.d.ts.map +1 -0
  145. package/dist/lending/init/publicCallParse.d.ts +11 -0
  146. package/dist/lending/init/publicCallParse.d.ts.map +1 -0
  147. package/dist/lending/meta/index.d.ts +19 -0
  148. package/dist/lending/meta/index.d.ts.map +1 -0
  149. package/dist/lending/morpho/chainsConfigs.d.ts +21 -0
  150. package/dist/lending/morpho/chainsConfigs.d.ts.map +1 -0
  151. package/dist/lending/morpho/constants/markets.d.ts +4 -0
  152. package/dist/lending/morpho/constants/markets.d.ts.map +1 -0
  153. package/dist/lending/morpho/convertPublic.d.ts +7 -0
  154. package/dist/lending/morpho/convertPublic.d.ts.map +1 -0
  155. package/dist/lending/morpho/fetchPublic.d.ts +3 -0
  156. package/dist/lending/morpho/fetchPublic.d.ts.map +1 -0
  157. package/dist/lending/morpho/getMarketsFromChain.d.ts +8 -0
  158. package/dist/lending/morpho/getMarketsFromChain.d.ts.map +1 -0
  159. package/dist/lending/morpho/publicCallBuild.d.ts +10 -0
  160. package/dist/lending/morpho/publicCallBuild.d.ts.map +1 -0
  161. package/dist/lending/morpho/utils/evmParser.d.ts +22 -0
  162. package/dist/lending/morpho/utils/evmParser.d.ts.map +1 -0
  163. package/dist/lending/morpho/utils/mathLib.d.ts +125 -0
  164. package/dist/lending/morpho/utils/mathLib.d.ts.map +1 -0
  165. package/dist/lending/morpho/utils/parsers.d.ts +10 -0
  166. package/dist/lending/morpho/utils/parsers.d.ts.map +1 -0
  167. package/dist/lending/user-data/aave-v2-type/userCallBuild.d.ts +4 -0
  168. package/dist/lending/user-data/aave-v2-type/userCallBuild.d.ts.map +1 -0
  169. package/dist/lending/user-data/aave-v2-type/userCallParse.d.ts +8 -0
  170. package/dist/lending/user-data/aave-v2-type/userCallParse.d.ts.map +1 -0
  171. package/dist/lending/user-data/aave-v3-type/userCallBuild.d.ts +4 -0
  172. package/dist/lending/user-data/aave-v3-type/userCallBuild.d.ts.map +1 -0
  173. package/dist/lending/user-data/aave-v3-type/userCallParse.d.ts +8 -0
  174. package/dist/lending/user-data/aave-v3-type/userCallParse.d.ts.map +1 -0
  175. package/dist/lending/user-data/aave-v3-type/userCallParseYldr.d.ts +9 -0
  176. package/dist/lending/user-data/aave-v3-type/userCallParseYldr.d.ts.map +1 -0
  177. package/dist/lending/user-data/abis.d.ts +9200 -0
  178. package/dist/lending/user-data/abis.d.ts.map +1 -0
  179. package/dist/lending/user-data/compound-v3/index.d.ts +3 -0
  180. package/dist/lending/user-data/compound-v3/index.d.ts.map +1 -0
  181. package/dist/lending/user-data/compound-v3/userCallBuild.d.ts +4 -0
  182. package/dist/lending/user-data/compound-v3/userCallBuild.d.ts.map +1 -0
  183. package/dist/lending/user-data/compound-v3/userCallParse.d.ts +8 -0
  184. package/dist/lending/user-data/compound-v3/userCallParse.d.ts.map +1 -0
  185. package/dist/lending/user-data/fetchUserData.d.ts +28 -0
  186. package/dist/lending/user-data/fetchUserData.d.ts.map +1 -0
  187. package/dist/lending/user-data/index.d.ts +2 -0
  188. package/dist/lending/user-data/index.d.ts.map +1 -0
  189. package/dist/lending/user-data/init/userCallBuild.d.ts +8 -0
  190. package/dist/lending/user-data/init/userCallBuild.d.ts.map +1 -0
  191. package/dist/lending/user-data/init/userCallParse.d.ts +8 -0
  192. package/dist/lending/user-data/init/userCallParse.d.ts.map +1 -0
  193. package/dist/lending/user-data/morpho/decoder.d.ts +21 -0
  194. package/dist/lending/user-data/morpho/decoder.d.ts.map +1 -0
  195. package/dist/lending/user-data/morpho/morphoLib.d.ts +5 -0
  196. package/dist/lending/user-data/morpho/morphoLib.d.ts.map +1 -0
  197. package/dist/lending/user-data/morpho/types.d.ts +12 -0
  198. package/dist/lending/user-data/morpho/types.d.ts.map +1 -0
  199. package/dist/lending/user-data/morpho/userCallBuild.d.ts +8 -0
  200. package/dist/lending/user-data/morpho/userCallBuild.d.ts.map +1 -0
  201. package/dist/lending/user-data/morpho/userCallParse.d.ts +10 -0
  202. package/dist/lending/user-data/morpho/userCallParse.d.ts.map +1 -0
  203. package/dist/lending/user-data/utils/createGeneralUserState.d.ts +45 -0
  204. package/dist/lending/user-data/utils/createGeneralUserState.d.ts.map +1 -0
  205. package/dist/lending/user-data/utils/createMultiAccountStyleUserState.d.ts +16 -0
  206. package/dist/lending/user-data/utils/createMultiAccountStyleUserState.d.ts.map +1 -0
  207. package/dist/lending/user-data/utils/formatting/generalFormatters.d.ts +55 -0
  208. package/dist/lending/user-data/utils/formatting/generalFormatters.d.ts.map +1 -0
  209. package/dist/lending/user-data/utils/formatting/index.d.ts +2 -0
  210. package/dist/lending/user-data/utils/formatting/index.d.ts.map +1 -0
  211. package/dist/lending/user-data/utils/index.d.ts +8 -0
  212. package/dist/lending/user-data/utils/index.d.ts.map +1 -0
  213. package/dist/lending-pairs/computeLendingPairs.d.ts +52 -0
  214. package/dist/lending-pairs/computeLendingPairs.d.ts.map +1 -0
  215. package/dist/lending-pairs/index.d.ts +2 -0
  216. package/dist/lending-pairs/index.d.ts.map +1 -0
  217. package/dist/prices/defillama/index.d.ts +3 -0
  218. package/dist/prices/defillama/index.d.ts.map +1 -0
  219. package/dist/prices/index.d.ts +4 -0
  220. package/dist/prices/index.d.ts.map +1 -0
  221. package/dist/prices/main-prices/addresses/api3.d.ts +6 -0
  222. package/dist/prices/main-prices/addresses/api3.d.ts.map +1 -0
  223. package/dist/prices/main-prices/addresses/chainlink.d.ts +734 -0
  224. package/dist/prices/main-prices/addresses/chainlink.d.ts.map +1 -0
  225. package/dist/prices/main-prices/fetchOracleData.d.ts +17 -0
  226. package/dist/prices/main-prices/fetchOracleData.d.ts.map +1 -0
  227. package/dist/prices/main-prices/index.d.ts +2 -0
  228. package/dist/prices/main-prices/index.d.ts.map +1 -0
  229. package/dist/prices/pendle/fetchPendlePrices.d.ts +47 -0
  230. package/dist/prices/pendle/fetchPendlePrices.d.ts.map +1 -0
  231. package/dist/prices/pendle/index.d.ts +2 -0
  232. package/dist/prices/pendle/index.d.ts.map +1 -0
  233. package/dist/secp256k1-XP7IUONI.js +2208 -0
  234. package/dist/secp256k1-XP7IUONI.js.map +1 -0
  235. package/dist/types/apiReturnType.d.ts +72 -0
  236. package/dist/types/apiReturnType.d.ts.map +1 -0
  237. package/dist/types/general.d.ts +18 -0
  238. package/dist/types/general.d.ts.map +1 -0
  239. package/dist/types/index.d.ts +6 -0
  240. package/dist/types/index.d.ts.map +1 -0
  241. package/dist/types/lender/aave-v2-types.d.ts +80 -0
  242. package/dist/types/lender/aave-v2-types.d.ts.map +1 -0
  243. package/dist/types/lender/aave-v3-types.d.ts +158 -0
  244. package/dist/types/lender/aave-v3-types.d.ts.map +1 -0
  245. package/dist/types/lender/compound-v3-types.d.ts +32 -0
  246. package/dist/types/lender/compound-v3-types.d.ts.map +1 -0
  247. package/dist/types/lender/init-types.d.ts +40 -0
  248. package/dist/types/lender/init-types.d.ts.map +1 -0
  249. package/dist/types/lender/morpho-types.d.ts +110 -0
  250. package/dist/types/lender/morpho-types.d.ts.map +1 -0
  251. package/dist/types/lenderTypes.d.ts +229 -0
  252. package/dist/types/lenderTypes.d.ts.map +1 -0
  253. package/dist/types/misc.d.ts +47 -0
  254. package/dist/types/misc.d.ts.map +1 -0
  255. package/dist/types/providers.d.ts +12 -0
  256. package/dist/types/providers.d.ts.map +1 -0
  257. package/dist/utils/constants.d.ts +7 -0
  258. package/dist/utils/constants.d.ts.map +1 -0
  259. package/dist/utils/index.d.ts +20 -0
  260. package/dist/utils/index.d.ts.map +1 -0
  261. package/dist/utils/multicall.d.ts +6 -0
  262. package/dist/utils/multicall.d.ts.map +1 -0
  263. package/dist/utils/parsing.d.ts +17 -0
  264. package/dist/utils/parsing.d.ts.map +1 -0
  265. package/dist/yields/index.d.ts +21 -0
  266. package/dist/yields/index.d.ts.map +1 -0
  267. package/dist/yields/yieldTypes.d.ts +76 -0
  268. package/dist/yields/yieldTypes.d.ts.map +1 -0
  269. package/package.json +1 -1
@@ -0,0 +1,3641 @@
1
+ import { __commonJS, __require, __export, __toESM } from './chunk-PR4QN5HX.js';
2
+
3
+ // ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/constants.js
4
+ var require_constants = __commonJS({
5
+ "../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/constants.js"(exports, module) {
6
+ var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
7
+ var hasBlob = typeof Blob !== "undefined";
8
+ if (hasBlob) BINARY_TYPES.push("blob");
9
+ module.exports = {
10
+ BINARY_TYPES,
11
+ EMPTY_BUFFER: Buffer.alloc(0),
12
+ GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
13
+ hasBlob,
14
+ kForOnEventAttribute: Symbol("kIsForOnEventAttribute"),
15
+ kListener: Symbol("kListener"),
16
+ kStatusCode: Symbol("status-code"),
17
+ kWebSocket: Symbol("websocket"),
18
+ NOOP: () => {
19
+ }
20
+ };
21
+ }
22
+ });
23
+
24
+ // ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/buffer-util.js
25
+ var require_buffer_util = __commonJS({
26
+ "../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/buffer-util.js"(exports, module) {
27
+ var { EMPTY_BUFFER } = require_constants();
28
+ var FastBuffer = Buffer[Symbol.species];
29
+ function concat(list, totalLength) {
30
+ if (list.length === 0) return EMPTY_BUFFER;
31
+ if (list.length === 1) return list[0];
32
+ const target = Buffer.allocUnsafe(totalLength);
33
+ let offset = 0;
34
+ for (let i = 0; i < list.length; i++) {
35
+ const buf = list[i];
36
+ target.set(buf, offset);
37
+ offset += buf.length;
38
+ }
39
+ if (offset < totalLength) {
40
+ return new FastBuffer(target.buffer, target.byteOffset, offset);
41
+ }
42
+ return target;
43
+ }
44
+ function _mask(source, mask, output, offset, length) {
45
+ for (let i = 0; i < length; i++) {
46
+ output[offset + i] = source[i] ^ mask[i & 3];
47
+ }
48
+ }
49
+ function _unmask(buffer, mask) {
50
+ for (let i = 0; i < buffer.length; i++) {
51
+ buffer[i] ^= mask[i & 3];
52
+ }
53
+ }
54
+ function toArrayBuffer(buf) {
55
+ if (buf.length === buf.buffer.byteLength) {
56
+ return buf.buffer;
57
+ }
58
+ return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
59
+ }
60
+ function toBuffer(data) {
61
+ toBuffer.readOnly = true;
62
+ if (Buffer.isBuffer(data)) return data;
63
+ let buf;
64
+ if (data instanceof ArrayBuffer) {
65
+ buf = new FastBuffer(data);
66
+ } else if (ArrayBuffer.isView(data)) {
67
+ buf = new FastBuffer(data.buffer, data.byteOffset, data.byteLength);
68
+ } else {
69
+ buf = Buffer.from(data);
70
+ toBuffer.readOnly = false;
71
+ }
72
+ return buf;
73
+ }
74
+ module.exports = {
75
+ concat,
76
+ mask: _mask,
77
+ toArrayBuffer,
78
+ toBuffer,
79
+ unmask: _unmask
80
+ };
81
+ if (!process.env.WS_NO_BUFFER_UTIL) {
82
+ try {
83
+ const bufferUtil = __require("bufferutil");
84
+ module.exports.mask = function(source, mask, output, offset, length) {
85
+ if (length < 48) _mask(source, mask, output, offset, length);
86
+ else bufferUtil.mask(source, mask, output, offset, length);
87
+ };
88
+ module.exports.unmask = function(buffer, mask) {
89
+ if (buffer.length < 32) _unmask(buffer, mask);
90
+ else bufferUtil.unmask(buffer, mask);
91
+ };
92
+ } catch (e) {
93
+ }
94
+ }
95
+ }
96
+ });
97
+
98
+ // ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/limiter.js
99
+ var require_limiter = __commonJS({
100
+ "../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/limiter.js"(exports, module) {
101
+ var kDone = Symbol("kDone");
102
+ var kRun = Symbol("kRun");
103
+ var Limiter = class {
104
+ /**
105
+ * Creates a new `Limiter`.
106
+ *
107
+ * @param {Number} [concurrency=Infinity] The maximum number of jobs allowed
108
+ * to run concurrently
109
+ */
110
+ constructor(concurrency) {
111
+ this[kDone] = () => {
112
+ this.pending--;
113
+ this[kRun]();
114
+ };
115
+ this.concurrency = concurrency || Infinity;
116
+ this.jobs = [];
117
+ this.pending = 0;
118
+ }
119
+ /**
120
+ * Adds a job to the queue.
121
+ *
122
+ * @param {Function} job The job to run
123
+ * @public
124
+ */
125
+ add(job) {
126
+ this.jobs.push(job);
127
+ this[kRun]();
128
+ }
129
+ /**
130
+ * Removes a job from the queue and runs it if possible.
131
+ *
132
+ * @private
133
+ */
134
+ [kRun]() {
135
+ if (this.pending === this.concurrency) return;
136
+ if (this.jobs.length) {
137
+ const job = this.jobs.shift();
138
+ this.pending++;
139
+ job(this[kDone]);
140
+ }
141
+ }
142
+ };
143
+ module.exports = Limiter;
144
+ }
145
+ });
146
+
147
+ // ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/permessage-deflate.js
148
+ var require_permessage_deflate = __commonJS({
149
+ "../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/permessage-deflate.js"(exports, module) {
150
+ var zlib = __require("zlib");
151
+ var bufferUtil = require_buffer_util();
152
+ var Limiter = require_limiter();
153
+ var { kStatusCode } = require_constants();
154
+ var FastBuffer = Buffer[Symbol.species];
155
+ var TRAILER = Buffer.from([0, 0, 255, 255]);
156
+ var kPerMessageDeflate = Symbol("permessage-deflate");
157
+ var kTotalLength = Symbol("total-length");
158
+ var kCallback = Symbol("callback");
159
+ var kBuffers = Symbol("buffers");
160
+ var kError = Symbol("error");
161
+ var zlibLimiter;
162
+ var PerMessageDeflate = class {
163
+ /**
164
+ * Creates a PerMessageDeflate instance.
165
+ *
166
+ * @param {Object} [options] Configuration options
167
+ * @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
168
+ * for, or request, a custom client window size
169
+ * @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
170
+ * acknowledge disabling of client context takeover
171
+ * @param {Number} [options.concurrencyLimit=10] The number of concurrent
172
+ * calls to zlib
173
+ * @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
174
+ * use of a custom server window size
175
+ * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
176
+ * disabling of server context takeover
177
+ * @param {Number} [options.threshold=1024] Size (in bytes) below which
178
+ * messages should not be compressed if context takeover is disabled
179
+ * @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
180
+ * deflate
181
+ * @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
182
+ * inflate
183
+ * @param {Boolean} [isServer=false] Create the instance in either server or
184
+ * client mode
185
+ * @param {Number} [maxPayload=0] The maximum allowed message length
186
+ */
187
+ constructor(options, isServer, maxPayload) {
188
+ this._maxPayload = maxPayload | 0;
189
+ this._options = options || {};
190
+ this._threshold = this._options.threshold !== void 0 ? this._options.threshold : 1024;
191
+ this._isServer = !!isServer;
192
+ this._deflate = null;
193
+ this._inflate = null;
194
+ this.params = null;
195
+ if (!zlibLimiter) {
196
+ const concurrency = this._options.concurrencyLimit !== void 0 ? this._options.concurrencyLimit : 10;
197
+ zlibLimiter = new Limiter(concurrency);
198
+ }
199
+ }
200
+ /**
201
+ * @type {String}
202
+ */
203
+ static get extensionName() {
204
+ return "permessage-deflate";
205
+ }
206
+ /**
207
+ * Create an extension negotiation offer.
208
+ *
209
+ * @return {Object} Extension parameters
210
+ * @public
211
+ */
212
+ offer() {
213
+ const params = {};
214
+ if (this._options.serverNoContextTakeover) {
215
+ params.server_no_context_takeover = true;
216
+ }
217
+ if (this._options.clientNoContextTakeover) {
218
+ params.client_no_context_takeover = true;
219
+ }
220
+ if (this._options.serverMaxWindowBits) {
221
+ params.server_max_window_bits = this._options.serverMaxWindowBits;
222
+ }
223
+ if (this._options.clientMaxWindowBits) {
224
+ params.client_max_window_bits = this._options.clientMaxWindowBits;
225
+ } else if (this._options.clientMaxWindowBits == null) {
226
+ params.client_max_window_bits = true;
227
+ }
228
+ return params;
229
+ }
230
+ /**
231
+ * Accept an extension negotiation offer/response.
232
+ *
233
+ * @param {Array} configurations The extension negotiation offers/reponse
234
+ * @return {Object} Accepted configuration
235
+ * @public
236
+ */
237
+ accept(configurations) {
238
+ configurations = this.normalizeParams(configurations);
239
+ this.params = this._isServer ? this.acceptAsServer(configurations) : this.acceptAsClient(configurations);
240
+ return this.params;
241
+ }
242
+ /**
243
+ * Releases all resources used by the extension.
244
+ *
245
+ * @public
246
+ */
247
+ cleanup() {
248
+ if (this._inflate) {
249
+ this._inflate.close();
250
+ this._inflate = null;
251
+ }
252
+ if (this._deflate) {
253
+ const callback = this._deflate[kCallback];
254
+ this._deflate.close();
255
+ this._deflate = null;
256
+ if (callback) {
257
+ callback(
258
+ new Error(
259
+ "The deflate stream was closed while data was being processed"
260
+ )
261
+ );
262
+ }
263
+ }
264
+ }
265
+ /**
266
+ * Accept an extension negotiation offer.
267
+ *
268
+ * @param {Array} offers The extension negotiation offers
269
+ * @return {Object} Accepted configuration
270
+ * @private
271
+ */
272
+ acceptAsServer(offers) {
273
+ const opts = this._options;
274
+ const accepted = offers.find((params) => {
275
+ 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) {
276
+ return false;
277
+ }
278
+ return true;
279
+ });
280
+ if (!accepted) {
281
+ throw new Error("None of the extension offers can be accepted");
282
+ }
283
+ if (opts.serverNoContextTakeover) {
284
+ accepted.server_no_context_takeover = true;
285
+ }
286
+ if (opts.clientNoContextTakeover) {
287
+ accepted.client_no_context_takeover = true;
288
+ }
289
+ if (typeof opts.serverMaxWindowBits === "number") {
290
+ accepted.server_max_window_bits = opts.serverMaxWindowBits;
291
+ }
292
+ if (typeof opts.clientMaxWindowBits === "number") {
293
+ accepted.client_max_window_bits = opts.clientMaxWindowBits;
294
+ } else if (accepted.client_max_window_bits === true || opts.clientMaxWindowBits === false) {
295
+ delete accepted.client_max_window_bits;
296
+ }
297
+ return accepted;
298
+ }
299
+ /**
300
+ * Accept the extension negotiation response.
301
+ *
302
+ * @param {Array} response The extension negotiation response
303
+ * @return {Object} Accepted configuration
304
+ * @private
305
+ */
306
+ acceptAsClient(response) {
307
+ const params = response[0];
308
+ if (this._options.clientNoContextTakeover === false && params.client_no_context_takeover) {
309
+ throw new Error('Unexpected parameter "client_no_context_takeover"');
310
+ }
311
+ if (!params.client_max_window_bits) {
312
+ if (typeof this._options.clientMaxWindowBits === "number") {
313
+ params.client_max_window_bits = this._options.clientMaxWindowBits;
314
+ }
315
+ } else if (this._options.clientMaxWindowBits === false || typeof this._options.clientMaxWindowBits === "number" && params.client_max_window_bits > this._options.clientMaxWindowBits) {
316
+ throw new Error(
317
+ 'Unexpected or invalid parameter "client_max_window_bits"'
318
+ );
319
+ }
320
+ return params;
321
+ }
322
+ /**
323
+ * Normalize parameters.
324
+ *
325
+ * @param {Array} configurations The extension negotiation offers/reponse
326
+ * @return {Array} The offers/response with normalized parameters
327
+ * @private
328
+ */
329
+ normalizeParams(configurations) {
330
+ configurations.forEach((params) => {
331
+ Object.keys(params).forEach((key) => {
332
+ let value = params[key];
333
+ if (value.length > 1) {
334
+ throw new Error(`Parameter "${key}" must have only a single value`);
335
+ }
336
+ value = value[0];
337
+ if (key === "client_max_window_bits") {
338
+ if (value !== true) {
339
+ const num = +value;
340
+ if (!Number.isInteger(num) || num < 8 || num > 15) {
341
+ throw new TypeError(
342
+ `Invalid value for parameter "${key}": ${value}`
343
+ );
344
+ }
345
+ value = num;
346
+ } else if (!this._isServer) {
347
+ throw new TypeError(
348
+ `Invalid value for parameter "${key}": ${value}`
349
+ );
350
+ }
351
+ } else if (key === "server_max_window_bits") {
352
+ const num = +value;
353
+ if (!Number.isInteger(num) || num < 8 || num > 15) {
354
+ throw new TypeError(
355
+ `Invalid value for parameter "${key}": ${value}`
356
+ );
357
+ }
358
+ value = num;
359
+ } else if (key === "client_no_context_takeover" || key === "server_no_context_takeover") {
360
+ if (value !== true) {
361
+ throw new TypeError(
362
+ `Invalid value for parameter "${key}": ${value}`
363
+ );
364
+ }
365
+ } else {
366
+ throw new Error(`Unknown parameter "${key}"`);
367
+ }
368
+ params[key] = value;
369
+ });
370
+ });
371
+ return configurations;
372
+ }
373
+ /**
374
+ * Decompress data. Concurrency limited.
375
+ *
376
+ * @param {Buffer} data Compressed data
377
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
378
+ * @param {Function} callback Callback
379
+ * @public
380
+ */
381
+ decompress(data, fin, callback) {
382
+ zlibLimiter.add((done) => {
383
+ this._decompress(data, fin, (err, result) => {
384
+ done();
385
+ callback(err, result);
386
+ });
387
+ });
388
+ }
389
+ /**
390
+ * Compress data. Concurrency limited.
391
+ *
392
+ * @param {(Buffer|String)} data Data to compress
393
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
394
+ * @param {Function} callback Callback
395
+ * @public
396
+ */
397
+ compress(data, fin, callback) {
398
+ zlibLimiter.add((done) => {
399
+ this._compress(data, fin, (err, result) => {
400
+ done();
401
+ callback(err, result);
402
+ });
403
+ });
404
+ }
405
+ /**
406
+ * Decompress data.
407
+ *
408
+ * @param {Buffer} data Compressed data
409
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
410
+ * @param {Function} callback Callback
411
+ * @private
412
+ */
413
+ _decompress(data, fin, callback) {
414
+ const endpoint = this._isServer ? "client" : "server";
415
+ if (!this._inflate) {
416
+ const key = `${endpoint}_max_window_bits`;
417
+ const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
418
+ this._inflate = zlib.createInflateRaw({
419
+ ...this._options.zlibInflateOptions,
420
+ windowBits
421
+ });
422
+ this._inflate[kPerMessageDeflate] = this;
423
+ this._inflate[kTotalLength] = 0;
424
+ this._inflate[kBuffers] = [];
425
+ this._inflate.on("error", inflateOnError);
426
+ this._inflate.on("data", inflateOnData);
427
+ }
428
+ this._inflate[kCallback] = callback;
429
+ this._inflate.write(data);
430
+ if (fin) this._inflate.write(TRAILER);
431
+ this._inflate.flush(() => {
432
+ const err = this._inflate[kError];
433
+ if (err) {
434
+ this._inflate.close();
435
+ this._inflate = null;
436
+ callback(err);
437
+ return;
438
+ }
439
+ const data2 = bufferUtil.concat(
440
+ this._inflate[kBuffers],
441
+ this._inflate[kTotalLength]
442
+ );
443
+ if (this._inflate._readableState.endEmitted) {
444
+ this._inflate.close();
445
+ this._inflate = null;
446
+ } else {
447
+ this._inflate[kTotalLength] = 0;
448
+ this._inflate[kBuffers] = [];
449
+ if (fin && this.params[`${endpoint}_no_context_takeover`]) {
450
+ this._inflate.reset();
451
+ }
452
+ }
453
+ callback(null, data2);
454
+ });
455
+ }
456
+ /**
457
+ * Compress data.
458
+ *
459
+ * @param {(Buffer|String)} data Data to compress
460
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
461
+ * @param {Function} callback Callback
462
+ * @private
463
+ */
464
+ _compress(data, fin, callback) {
465
+ const endpoint = this._isServer ? "server" : "client";
466
+ if (!this._deflate) {
467
+ const key = `${endpoint}_max_window_bits`;
468
+ const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
469
+ this._deflate = zlib.createDeflateRaw({
470
+ ...this._options.zlibDeflateOptions,
471
+ windowBits
472
+ });
473
+ this._deflate[kTotalLength] = 0;
474
+ this._deflate[kBuffers] = [];
475
+ this._deflate.on("data", deflateOnData);
476
+ }
477
+ this._deflate[kCallback] = callback;
478
+ this._deflate.write(data);
479
+ this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
480
+ if (!this._deflate) {
481
+ return;
482
+ }
483
+ let data2 = bufferUtil.concat(
484
+ this._deflate[kBuffers],
485
+ this._deflate[kTotalLength]
486
+ );
487
+ if (fin) {
488
+ data2 = new FastBuffer(data2.buffer, data2.byteOffset, data2.length - 4);
489
+ }
490
+ this._deflate[kCallback] = null;
491
+ this._deflate[kTotalLength] = 0;
492
+ this._deflate[kBuffers] = [];
493
+ if (fin && this.params[`${endpoint}_no_context_takeover`]) {
494
+ this._deflate.reset();
495
+ }
496
+ callback(null, data2);
497
+ });
498
+ }
499
+ };
500
+ module.exports = PerMessageDeflate;
501
+ function deflateOnData(chunk) {
502
+ this[kBuffers].push(chunk);
503
+ this[kTotalLength] += chunk.length;
504
+ }
505
+ function inflateOnData(chunk) {
506
+ this[kTotalLength] += chunk.length;
507
+ if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) {
508
+ this[kBuffers].push(chunk);
509
+ return;
510
+ }
511
+ this[kError] = new RangeError("Max payload size exceeded");
512
+ this[kError].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH";
513
+ this[kError][kStatusCode] = 1009;
514
+ this.removeListener("data", inflateOnData);
515
+ this.reset();
516
+ }
517
+ function inflateOnError(err) {
518
+ this[kPerMessageDeflate]._inflate = null;
519
+ if (this[kError]) {
520
+ this[kCallback](this[kError]);
521
+ return;
522
+ }
523
+ err[kStatusCode] = 1007;
524
+ this[kCallback](err);
525
+ }
526
+ }
527
+ });
528
+
529
+ // ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/validation.js
530
+ var require_validation = __commonJS({
531
+ "../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/validation.js"(exports, module) {
532
+ var { isUtf8 } = __require("buffer");
533
+ var { hasBlob } = require_constants();
534
+ var tokenChars = [
535
+ 0,
536
+ 0,
537
+ 0,
538
+ 0,
539
+ 0,
540
+ 0,
541
+ 0,
542
+ 0,
543
+ 0,
544
+ 0,
545
+ 0,
546
+ 0,
547
+ 0,
548
+ 0,
549
+ 0,
550
+ 0,
551
+ // 0 - 15
552
+ 0,
553
+ 0,
554
+ 0,
555
+ 0,
556
+ 0,
557
+ 0,
558
+ 0,
559
+ 0,
560
+ 0,
561
+ 0,
562
+ 0,
563
+ 0,
564
+ 0,
565
+ 0,
566
+ 0,
567
+ 0,
568
+ // 16 - 31
569
+ 0,
570
+ 1,
571
+ 0,
572
+ 1,
573
+ 1,
574
+ 1,
575
+ 1,
576
+ 1,
577
+ 0,
578
+ 0,
579
+ 1,
580
+ 1,
581
+ 0,
582
+ 1,
583
+ 1,
584
+ 0,
585
+ // 32 - 47
586
+ 1,
587
+ 1,
588
+ 1,
589
+ 1,
590
+ 1,
591
+ 1,
592
+ 1,
593
+ 1,
594
+ 1,
595
+ 1,
596
+ 0,
597
+ 0,
598
+ 0,
599
+ 0,
600
+ 0,
601
+ 0,
602
+ // 48 - 63
603
+ 0,
604
+ 1,
605
+ 1,
606
+ 1,
607
+ 1,
608
+ 1,
609
+ 1,
610
+ 1,
611
+ 1,
612
+ 1,
613
+ 1,
614
+ 1,
615
+ 1,
616
+ 1,
617
+ 1,
618
+ 1,
619
+ // 64 - 79
620
+ 1,
621
+ 1,
622
+ 1,
623
+ 1,
624
+ 1,
625
+ 1,
626
+ 1,
627
+ 1,
628
+ 1,
629
+ 1,
630
+ 1,
631
+ 0,
632
+ 0,
633
+ 0,
634
+ 1,
635
+ 1,
636
+ // 80 - 95
637
+ 1,
638
+ 1,
639
+ 1,
640
+ 1,
641
+ 1,
642
+ 1,
643
+ 1,
644
+ 1,
645
+ 1,
646
+ 1,
647
+ 1,
648
+ 1,
649
+ 1,
650
+ 1,
651
+ 1,
652
+ 1,
653
+ // 96 - 111
654
+ 1,
655
+ 1,
656
+ 1,
657
+ 1,
658
+ 1,
659
+ 1,
660
+ 1,
661
+ 1,
662
+ 1,
663
+ 1,
664
+ 1,
665
+ 0,
666
+ 1,
667
+ 0,
668
+ 1,
669
+ 0
670
+ // 112 - 127
671
+ ];
672
+ function isValidStatusCode(code) {
673
+ return code >= 1e3 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006 || code >= 3e3 && code <= 4999;
674
+ }
675
+ function _isValidUTF8(buf) {
676
+ const len = buf.length;
677
+ let i = 0;
678
+ while (i < len) {
679
+ if ((buf[i] & 128) === 0) {
680
+ i++;
681
+ } else if ((buf[i] & 224) === 192) {
682
+ if (i + 1 === len || (buf[i + 1] & 192) !== 128 || (buf[i] & 254) === 192) {
683
+ return false;
684
+ }
685
+ i += 2;
686
+ } else if ((buf[i] & 240) === 224) {
687
+ if (i + 2 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || buf[i] === 224 && (buf[i + 1] & 224) === 128 || // Overlong
688
+ buf[i] === 237 && (buf[i + 1] & 224) === 160) {
689
+ return false;
690
+ }
691
+ i += 3;
692
+ } else if ((buf[i] & 248) === 240) {
693
+ 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 || // Overlong
694
+ buf[i] === 244 && buf[i + 1] > 143 || buf[i] > 244) {
695
+ return false;
696
+ }
697
+ i += 4;
698
+ } else {
699
+ return false;
700
+ }
701
+ }
702
+ return true;
703
+ }
704
+ function isBlob(value) {
705
+ 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");
706
+ }
707
+ module.exports = {
708
+ isBlob,
709
+ isValidStatusCode,
710
+ isValidUTF8: _isValidUTF8,
711
+ tokenChars
712
+ };
713
+ if (isUtf8) {
714
+ module.exports.isValidUTF8 = function(buf) {
715
+ return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
716
+ };
717
+ } else if (!process.env.WS_NO_UTF_8_VALIDATE) {
718
+ try {
719
+ const isValidUTF8 = __require("utf-8-validate");
720
+ module.exports.isValidUTF8 = function(buf) {
721
+ return buf.length < 32 ? _isValidUTF8(buf) : isValidUTF8(buf);
722
+ };
723
+ } catch (e) {
724
+ }
725
+ }
726
+ }
727
+ });
728
+
729
+ // ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/receiver.js
730
+ var require_receiver = __commonJS({
731
+ "../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/receiver.js"(exports, module) {
732
+ var { Writable } = __require("stream");
733
+ var PerMessageDeflate = require_permessage_deflate();
734
+ var {
735
+ BINARY_TYPES,
736
+ EMPTY_BUFFER,
737
+ kStatusCode,
738
+ kWebSocket
739
+ } = require_constants();
740
+ var { concat, toArrayBuffer, unmask } = require_buffer_util();
741
+ var { isValidStatusCode, isValidUTF8 } = require_validation();
742
+ var FastBuffer = Buffer[Symbol.species];
743
+ var GET_INFO = 0;
744
+ var GET_PAYLOAD_LENGTH_16 = 1;
745
+ var GET_PAYLOAD_LENGTH_64 = 2;
746
+ var GET_MASK = 3;
747
+ var GET_DATA = 4;
748
+ var INFLATING = 5;
749
+ var DEFER_EVENT = 6;
750
+ var Receiver2 = class extends Writable {
751
+ /**
752
+ * Creates a Receiver instance.
753
+ *
754
+ * @param {Object} [options] Options object
755
+ * @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
756
+ * any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
757
+ * multiple times in the same tick
758
+ * @param {String} [options.binaryType=nodebuffer] The type for binary data
759
+ * @param {Object} [options.extensions] An object containing the negotiated
760
+ * extensions
761
+ * @param {Boolean} [options.isServer=false] Specifies whether to operate in
762
+ * client or server mode
763
+ * @param {Number} [options.maxPayload=0] The maximum allowed message length
764
+ * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
765
+ * not to skip UTF-8 validation for text and close messages
766
+ */
767
+ constructor(options = {}) {
768
+ super();
769
+ this._allowSynchronousEvents = options.allowSynchronousEvents !== void 0 ? options.allowSynchronousEvents : true;
770
+ this._binaryType = options.binaryType || BINARY_TYPES[0];
771
+ this._extensions = options.extensions || {};
772
+ this._isServer = !!options.isServer;
773
+ this._maxPayload = options.maxPayload | 0;
774
+ this._skipUTF8Validation = !!options.skipUTF8Validation;
775
+ this[kWebSocket] = void 0;
776
+ this._bufferedBytes = 0;
777
+ this._buffers = [];
778
+ this._compressed = false;
779
+ this._payloadLength = 0;
780
+ this._mask = void 0;
781
+ this._fragmented = 0;
782
+ this._masked = false;
783
+ this._fin = false;
784
+ this._opcode = 0;
785
+ this._totalPayloadLength = 0;
786
+ this._messageLength = 0;
787
+ this._fragments = [];
788
+ this._errored = false;
789
+ this._loop = false;
790
+ this._state = GET_INFO;
791
+ }
792
+ /**
793
+ * Implements `Writable.prototype._write()`.
794
+ *
795
+ * @param {Buffer} chunk The chunk of data to write
796
+ * @param {String} encoding The character encoding of `chunk`
797
+ * @param {Function} cb Callback
798
+ * @private
799
+ */
800
+ _write(chunk, encoding, cb) {
801
+ if (this._opcode === 8 && this._state == GET_INFO) return cb();
802
+ this._bufferedBytes += chunk.length;
803
+ this._buffers.push(chunk);
804
+ this.startLoop(cb);
805
+ }
806
+ /**
807
+ * Consumes `n` bytes from the buffered data.
808
+ *
809
+ * @param {Number} n The number of bytes to consume
810
+ * @return {Buffer} The consumed bytes
811
+ * @private
812
+ */
813
+ consume(n) {
814
+ this._bufferedBytes -= n;
815
+ if (n === this._buffers[0].length) return this._buffers.shift();
816
+ if (n < this._buffers[0].length) {
817
+ const buf = this._buffers[0];
818
+ this._buffers[0] = new FastBuffer(
819
+ buf.buffer,
820
+ buf.byteOffset + n,
821
+ buf.length - n
822
+ );
823
+ return new FastBuffer(buf.buffer, buf.byteOffset, n);
824
+ }
825
+ const dst = Buffer.allocUnsafe(n);
826
+ do {
827
+ const buf = this._buffers[0];
828
+ const offset = dst.length - n;
829
+ if (n >= buf.length) {
830
+ dst.set(this._buffers.shift(), offset);
831
+ } else {
832
+ dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
833
+ this._buffers[0] = new FastBuffer(
834
+ buf.buffer,
835
+ buf.byteOffset + n,
836
+ buf.length - n
837
+ );
838
+ }
839
+ n -= buf.length;
840
+ } while (n > 0);
841
+ return dst;
842
+ }
843
+ /**
844
+ * Starts the parsing loop.
845
+ *
846
+ * @param {Function} cb Callback
847
+ * @private
848
+ */
849
+ startLoop(cb) {
850
+ this._loop = true;
851
+ do {
852
+ switch (this._state) {
853
+ case GET_INFO:
854
+ this.getInfo(cb);
855
+ break;
856
+ case GET_PAYLOAD_LENGTH_16:
857
+ this.getPayloadLength16(cb);
858
+ break;
859
+ case GET_PAYLOAD_LENGTH_64:
860
+ this.getPayloadLength64(cb);
861
+ break;
862
+ case GET_MASK:
863
+ this.getMask();
864
+ break;
865
+ case GET_DATA:
866
+ this.getData(cb);
867
+ break;
868
+ case INFLATING:
869
+ case DEFER_EVENT:
870
+ this._loop = false;
871
+ return;
872
+ }
873
+ } while (this._loop);
874
+ if (!this._errored) cb();
875
+ }
876
+ /**
877
+ * Reads the first two bytes of a frame.
878
+ *
879
+ * @param {Function} cb Callback
880
+ * @private
881
+ */
882
+ getInfo(cb) {
883
+ if (this._bufferedBytes < 2) {
884
+ this._loop = false;
885
+ return;
886
+ }
887
+ const buf = this.consume(2);
888
+ if ((buf[0] & 48) !== 0) {
889
+ const error = this.createError(
890
+ RangeError,
891
+ "RSV2 and RSV3 must be clear",
892
+ true,
893
+ 1002,
894
+ "WS_ERR_UNEXPECTED_RSV_2_3"
895
+ );
896
+ cb(error);
897
+ return;
898
+ }
899
+ const compressed = (buf[0] & 64) === 64;
900
+ if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
901
+ const error = this.createError(
902
+ RangeError,
903
+ "RSV1 must be clear",
904
+ true,
905
+ 1002,
906
+ "WS_ERR_UNEXPECTED_RSV_1"
907
+ );
908
+ cb(error);
909
+ return;
910
+ }
911
+ this._fin = (buf[0] & 128) === 128;
912
+ this._opcode = buf[0] & 15;
913
+ this._payloadLength = buf[1] & 127;
914
+ if (this._opcode === 0) {
915
+ if (compressed) {
916
+ const error = this.createError(
917
+ RangeError,
918
+ "RSV1 must be clear",
919
+ true,
920
+ 1002,
921
+ "WS_ERR_UNEXPECTED_RSV_1"
922
+ );
923
+ cb(error);
924
+ return;
925
+ }
926
+ if (!this._fragmented) {
927
+ const error = this.createError(
928
+ RangeError,
929
+ "invalid opcode 0",
930
+ true,
931
+ 1002,
932
+ "WS_ERR_INVALID_OPCODE"
933
+ );
934
+ cb(error);
935
+ return;
936
+ }
937
+ this._opcode = this._fragmented;
938
+ } else if (this._opcode === 1 || this._opcode === 2) {
939
+ if (this._fragmented) {
940
+ const error = this.createError(
941
+ RangeError,
942
+ `invalid opcode ${this._opcode}`,
943
+ true,
944
+ 1002,
945
+ "WS_ERR_INVALID_OPCODE"
946
+ );
947
+ cb(error);
948
+ return;
949
+ }
950
+ this._compressed = compressed;
951
+ } else if (this._opcode > 7 && this._opcode < 11) {
952
+ if (!this._fin) {
953
+ const error = this.createError(
954
+ RangeError,
955
+ "FIN must be set",
956
+ true,
957
+ 1002,
958
+ "WS_ERR_EXPECTED_FIN"
959
+ );
960
+ cb(error);
961
+ return;
962
+ }
963
+ if (compressed) {
964
+ const error = this.createError(
965
+ RangeError,
966
+ "RSV1 must be clear",
967
+ true,
968
+ 1002,
969
+ "WS_ERR_UNEXPECTED_RSV_1"
970
+ );
971
+ cb(error);
972
+ return;
973
+ }
974
+ if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1) {
975
+ const error = this.createError(
976
+ RangeError,
977
+ `invalid payload length ${this._payloadLength}`,
978
+ true,
979
+ 1002,
980
+ "WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH"
981
+ );
982
+ cb(error);
983
+ return;
984
+ }
985
+ } else {
986
+ const error = this.createError(
987
+ RangeError,
988
+ `invalid opcode ${this._opcode}`,
989
+ true,
990
+ 1002,
991
+ "WS_ERR_INVALID_OPCODE"
992
+ );
993
+ cb(error);
994
+ return;
995
+ }
996
+ if (!this._fin && !this._fragmented) this._fragmented = this._opcode;
997
+ this._masked = (buf[1] & 128) === 128;
998
+ if (this._isServer) {
999
+ if (!this._masked) {
1000
+ const error = this.createError(
1001
+ RangeError,
1002
+ "MASK must be set",
1003
+ true,
1004
+ 1002,
1005
+ "WS_ERR_EXPECTED_MASK"
1006
+ );
1007
+ cb(error);
1008
+ return;
1009
+ }
1010
+ } else if (this._masked) {
1011
+ const error = this.createError(
1012
+ RangeError,
1013
+ "MASK must be clear",
1014
+ true,
1015
+ 1002,
1016
+ "WS_ERR_UNEXPECTED_MASK"
1017
+ );
1018
+ cb(error);
1019
+ return;
1020
+ }
1021
+ if (this._payloadLength === 126) this._state = GET_PAYLOAD_LENGTH_16;
1022
+ else if (this._payloadLength === 127) this._state = GET_PAYLOAD_LENGTH_64;
1023
+ else this.haveLength(cb);
1024
+ }
1025
+ /**
1026
+ * Gets extended payload length (7+16).
1027
+ *
1028
+ * @param {Function} cb Callback
1029
+ * @private
1030
+ */
1031
+ getPayloadLength16(cb) {
1032
+ if (this._bufferedBytes < 2) {
1033
+ this._loop = false;
1034
+ return;
1035
+ }
1036
+ this._payloadLength = this.consume(2).readUInt16BE(0);
1037
+ this.haveLength(cb);
1038
+ }
1039
+ /**
1040
+ * Gets extended payload length (7+64).
1041
+ *
1042
+ * @param {Function} cb Callback
1043
+ * @private
1044
+ */
1045
+ getPayloadLength64(cb) {
1046
+ if (this._bufferedBytes < 8) {
1047
+ this._loop = false;
1048
+ return;
1049
+ }
1050
+ const buf = this.consume(8);
1051
+ const num = buf.readUInt32BE(0);
1052
+ if (num > Math.pow(2, 53 - 32) - 1) {
1053
+ const error = this.createError(
1054
+ RangeError,
1055
+ "Unsupported WebSocket frame: payload length > 2^53 - 1",
1056
+ false,
1057
+ 1009,
1058
+ "WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH"
1059
+ );
1060
+ cb(error);
1061
+ return;
1062
+ }
1063
+ this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
1064
+ this.haveLength(cb);
1065
+ }
1066
+ /**
1067
+ * Payload length has been read.
1068
+ *
1069
+ * @param {Function} cb Callback
1070
+ * @private
1071
+ */
1072
+ haveLength(cb) {
1073
+ if (this._payloadLength && this._opcode < 8) {
1074
+ this._totalPayloadLength += this._payloadLength;
1075
+ if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
1076
+ const error = this.createError(
1077
+ RangeError,
1078
+ "Max payload size exceeded",
1079
+ false,
1080
+ 1009,
1081
+ "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
1082
+ );
1083
+ cb(error);
1084
+ return;
1085
+ }
1086
+ }
1087
+ if (this._masked) this._state = GET_MASK;
1088
+ else this._state = GET_DATA;
1089
+ }
1090
+ /**
1091
+ * Reads mask bytes.
1092
+ *
1093
+ * @private
1094
+ */
1095
+ getMask() {
1096
+ if (this._bufferedBytes < 4) {
1097
+ this._loop = false;
1098
+ return;
1099
+ }
1100
+ this._mask = this.consume(4);
1101
+ this._state = GET_DATA;
1102
+ }
1103
+ /**
1104
+ * Reads data bytes.
1105
+ *
1106
+ * @param {Function} cb Callback
1107
+ * @private
1108
+ */
1109
+ getData(cb) {
1110
+ let data = EMPTY_BUFFER;
1111
+ if (this._payloadLength) {
1112
+ if (this._bufferedBytes < this._payloadLength) {
1113
+ this._loop = false;
1114
+ return;
1115
+ }
1116
+ data = this.consume(this._payloadLength);
1117
+ if (this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0) {
1118
+ unmask(data, this._mask);
1119
+ }
1120
+ }
1121
+ if (this._opcode > 7) {
1122
+ this.controlMessage(data, cb);
1123
+ return;
1124
+ }
1125
+ if (this._compressed) {
1126
+ this._state = INFLATING;
1127
+ this.decompress(data, cb);
1128
+ return;
1129
+ }
1130
+ if (data.length) {
1131
+ this._messageLength = this._totalPayloadLength;
1132
+ this._fragments.push(data);
1133
+ }
1134
+ this.dataMessage(cb);
1135
+ }
1136
+ /**
1137
+ * Decompresses data.
1138
+ *
1139
+ * @param {Buffer} data Compressed data
1140
+ * @param {Function} cb Callback
1141
+ * @private
1142
+ */
1143
+ decompress(data, cb) {
1144
+ const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
1145
+ perMessageDeflate.decompress(data, this._fin, (err, buf) => {
1146
+ if (err) return cb(err);
1147
+ if (buf.length) {
1148
+ this._messageLength += buf.length;
1149
+ if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
1150
+ const error = this.createError(
1151
+ RangeError,
1152
+ "Max payload size exceeded",
1153
+ false,
1154
+ 1009,
1155
+ "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
1156
+ );
1157
+ cb(error);
1158
+ return;
1159
+ }
1160
+ this._fragments.push(buf);
1161
+ }
1162
+ this.dataMessage(cb);
1163
+ if (this._state === GET_INFO) this.startLoop(cb);
1164
+ });
1165
+ }
1166
+ /**
1167
+ * Handles a data message.
1168
+ *
1169
+ * @param {Function} cb Callback
1170
+ * @private
1171
+ */
1172
+ dataMessage(cb) {
1173
+ if (!this._fin) {
1174
+ this._state = GET_INFO;
1175
+ return;
1176
+ }
1177
+ const messageLength = this._messageLength;
1178
+ const fragments = this._fragments;
1179
+ this._totalPayloadLength = 0;
1180
+ this._messageLength = 0;
1181
+ this._fragmented = 0;
1182
+ this._fragments = [];
1183
+ if (this._opcode === 2) {
1184
+ let data;
1185
+ if (this._binaryType === "nodebuffer") {
1186
+ data = concat(fragments, messageLength);
1187
+ } else if (this._binaryType === "arraybuffer") {
1188
+ data = toArrayBuffer(concat(fragments, messageLength));
1189
+ } else if (this._binaryType === "blob") {
1190
+ data = new Blob(fragments);
1191
+ } else {
1192
+ data = fragments;
1193
+ }
1194
+ if (this._allowSynchronousEvents) {
1195
+ this.emit("message", data, true);
1196
+ this._state = GET_INFO;
1197
+ } else {
1198
+ this._state = DEFER_EVENT;
1199
+ setImmediate(() => {
1200
+ this.emit("message", data, true);
1201
+ this._state = GET_INFO;
1202
+ this.startLoop(cb);
1203
+ });
1204
+ }
1205
+ } else {
1206
+ const buf = concat(fragments, messageLength);
1207
+ if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
1208
+ const error = this.createError(
1209
+ Error,
1210
+ "invalid UTF-8 sequence",
1211
+ true,
1212
+ 1007,
1213
+ "WS_ERR_INVALID_UTF8"
1214
+ );
1215
+ cb(error);
1216
+ return;
1217
+ }
1218
+ if (this._state === INFLATING || this._allowSynchronousEvents) {
1219
+ this.emit("message", buf, false);
1220
+ this._state = GET_INFO;
1221
+ } else {
1222
+ this._state = DEFER_EVENT;
1223
+ setImmediate(() => {
1224
+ this.emit("message", buf, false);
1225
+ this._state = GET_INFO;
1226
+ this.startLoop(cb);
1227
+ });
1228
+ }
1229
+ }
1230
+ }
1231
+ /**
1232
+ * Handles a control message.
1233
+ *
1234
+ * @param {Buffer} data Data to handle
1235
+ * @return {(Error|RangeError|undefined)} A possible error
1236
+ * @private
1237
+ */
1238
+ controlMessage(data, cb) {
1239
+ if (this._opcode === 8) {
1240
+ if (data.length === 0) {
1241
+ this._loop = false;
1242
+ this.emit("conclude", 1005, EMPTY_BUFFER);
1243
+ this.end();
1244
+ } else {
1245
+ const code = data.readUInt16BE(0);
1246
+ if (!isValidStatusCode(code)) {
1247
+ const error = this.createError(
1248
+ RangeError,
1249
+ `invalid status code ${code}`,
1250
+ true,
1251
+ 1002,
1252
+ "WS_ERR_INVALID_CLOSE_CODE"
1253
+ );
1254
+ cb(error);
1255
+ return;
1256
+ }
1257
+ const buf = new FastBuffer(
1258
+ data.buffer,
1259
+ data.byteOffset + 2,
1260
+ data.length - 2
1261
+ );
1262
+ if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
1263
+ const error = this.createError(
1264
+ Error,
1265
+ "invalid UTF-8 sequence",
1266
+ true,
1267
+ 1007,
1268
+ "WS_ERR_INVALID_UTF8"
1269
+ );
1270
+ cb(error);
1271
+ return;
1272
+ }
1273
+ this._loop = false;
1274
+ this.emit("conclude", code, buf);
1275
+ this.end();
1276
+ }
1277
+ this._state = GET_INFO;
1278
+ return;
1279
+ }
1280
+ if (this._allowSynchronousEvents) {
1281
+ this.emit(this._opcode === 9 ? "ping" : "pong", data);
1282
+ this._state = GET_INFO;
1283
+ } else {
1284
+ this._state = DEFER_EVENT;
1285
+ setImmediate(() => {
1286
+ this.emit(this._opcode === 9 ? "ping" : "pong", data);
1287
+ this._state = GET_INFO;
1288
+ this.startLoop(cb);
1289
+ });
1290
+ }
1291
+ }
1292
+ /**
1293
+ * Builds an error object.
1294
+ *
1295
+ * @param {function(new:Error|RangeError)} ErrorCtor The error constructor
1296
+ * @param {String} message The error message
1297
+ * @param {Boolean} prefix Specifies whether or not to add a default prefix to
1298
+ * `message`
1299
+ * @param {Number} statusCode The status code
1300
+ * @param {String} errorCode The exposed error code
1301
+ * @return {(Error|RangeError)} The error
1302
+ * @private
1303
+ */
1304
+ createError(ErrorCtor, message, prefix, statusCode, errorCode) {
1305
+ this._loop = false;
1306
+ this._errored = true;
1307
+ const err = new ErrorCtor(
1308
+ prefix ? `Invalid WebSocket frame: ${message}` : message
1309
+ );
1310
+ Error.captureStackTrace(err, this.createError);
1311
+ err.code = errorCode;
1312
+ err[kStatusCode] = statusCode;
1313
+ return err;
1314
+ }
1315
+ };
1316
+ module.exports = Receiver2;
1317
+ }
1318
+ });
1319
+
1320
+ // ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/sender.js
1321
+ var require_sender = __commonJS({
1322
+ "../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/sender.js"(exports, module) {
1323
+ var { Duplex } = __require("stream");
1324
+ var { randomFillSync } = __require("crypto");
1325
+ var PerMessageDeflate = require_permessage_deflate();
1326
+ var { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants();
1327
+ var { isBlob, isValidStatusCode } = require_validation();
1328
+ var { mask: applyMask, toBuffer } = require_buffer_util();
1329
+ var kByteLength = Symbol("kByteLength");
1330
+ var maskBuffer = Buffer.alloc(4);
1331
+ var RANDOM_POOL_SIZE = 8 * 1024;
1332
+ var randomPool;
1333
+ var randomPoolPointer = RANDOM_POOL_SIZE;
1334
+ var DEFAULT = 0;
1335
+ var DEFLATING = 1;
1336
+ var GET_BLOB_DATA = 2;
1337
+ var Sender2 = class _Sender {
1338
+ /**
1339
+ * Creates a Sender instance.
1340
+ *
1341
+ * @param {Duplex} socket The connection socket
1342
+ * @param {Object} [extensions] An object containing the negotiated extensions
1343
+ * @param {Function} [generateMask] The function used to generate the masking
1344
+ * key
1345
+ */
1346
+ constructor(socket, extensions, generateMask) {
1347
+ this._extensions = extensions || {};
1348
+ if (generateMask) {
1349
+ this._generateMask = generateMask;
1350
+ this._maskBuffer = Buffer.alloc(4);
1351
+ }
1352
+ this._socket = socket;
1353
+ this._firstFragment = true;
1354
+ this._compress = false;
1355
+ this._bufferedBytes = 0;
1356
+ this._queue = [];
1357
+ this._state = DEFAULT;
1358
+ this.onerror = NOOP;
1359
+ this[kWebSocket] = void 0;
1360
+ }
1361
+ /**
1362
+ * Frames a piece of data according to the HyBi WebSocket protocol.
1363
+ *
1364
+ * @param {(Buffer|String)} data The data to frame
1365
+ * @param {Object} options Options object
1366
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1367
+ * FIN bit
1368
+ * @param {Function} [options.generateMask] The function used to generate the
1369
+ * masking key
1370
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1371
+ * `data`
1372
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1373
+ * key
1374
+ * @param {Number} options.opcode The opcode
1375
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1376
+ * modified
1377
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1378
+ * RSV1 bit
1379
+ * @return {(Buffer|String)[]} The framed data
1380
+ * @public
1381
+ */
1382
+ static frame(data, options) {
1383
+ let mask;
1384
+ let merge = false;
1385
+ let offset = 2;
1386
+ let skipMasking = false;
1387
+ if (options.mask) {
1388
+ mask = options.maskBuffer || maskBuffer;
1389
+ if (options.generateMask) {
1390
+ options.generateMask(mask);
1391
+ } else {
1392
+ if (randomPoolPointer === RANDOM_POOL_SIZE) {
1393
+ if (randomPool === void 0) {
1394
+ randomPool = Buffer.alloc(RANDOM_POOL_SIZE);
1395
+ }
1396
+ randomFillSync(randomPool, 0, RANDOM_POOL_SIZE);
1397
+ randomPoolPointer = 0;
1398
+ }
1399
+ mask[0] = randomPool[randomPoolPointer++];
1400
+ mask[1] = randomPool[randomPoolPointer++];
1401
+ mask[2] = randomPool[randomPoolPointer++];
1402
+ mask[3] = randomPool[randomPoolPointer++];
1403
+ }
1404
+ skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
1405
+ offset = 6;
1406
+ }
1407
+ let dataLength;
1408
+ if (typeof data === "string") {
1409
+ if ((!options.mask || skipMasking) && options[kByteLength] !== void 0) {
1410
+ dataLength = options[kByteLength];
1411
+ } else {
1412
+ data = Buffer.from(data);
1413
+ dataLength = data.length;
1414
+ }
1415
+ } else {
1416
+ dataLength = data.length;
1417
+ merge = options.mask && options.readOnly && !skipMasking;
1418
+ }
1419
+ let payloadLength = dataLength;
1420
+ if (dataLength >= 65536) {
1421
+ offset += 8;
1422
+ payloadLength = 127;
1423
+ } else if (dataLength > 125) {
1424
+ offset += 2;
1425
+ payloadLength = 126;
1426
+ }
1427
+ const target = Buffer.allocUnsafe(merge ? dataLength + offset : offset);
1428
+ target[0] = options.fin ? options.opcode | 128 : options.opcode;
1429
+ if (options.rsv1) target[0] |= 64;
1430
+ target[1] = payloadLength;
1431
+ if (payloadLength === 126) {
1432
+ target.writeUInt16BE(dataLength, 2);
1433
+ } else if (payloadLength === 127) {
1434
+ target[2] = target[3] = 0;
1435
+ target.writeUIntBE(dataLength, 4, 6);
1436
+ }
1437
+ if (!options.mask) return [target, data];
1438
+ target[1] |= 128;
1439
+ target[offset - 4] = mask[0];
1440
+ target[offset - 3] = mask[1];
1441
+ target[offset - 2] = mask[2];
1442
+ target[offset - 1] = mask[3];
1443
+ if (skipMasking) return [target, data];
1444
+ if (merge) {
1445
+ applyMask(data, mask, target, offset, dataLength);
1446
+ return [target];
1447
+ }
1448
+ applyMask(data, mask, data, 0, dataLength);
1449
+ return [target, data];
1450
+ }
1451
+ /**
1452
+ * Sends a close message to the other peer.
1453
+ *
1454
+ * @param {Number} [code] The status code component of the body
1455
+ * @param {(String|Buffer)} [data] The message component of the body
1456
+ * @param {Boolean} [mask=false] Specifies whether or not to mask the message
1457
+ * @param {Function} [cb] Callback
1458
+ * @public
1459
+ */
1460
+ close(code, data, mask, cb) {
1461
+ let buf;
1462
+ if (code === void 0) {
1463
+ buf = EMPTY_BUFFER;
1464
+ } else if (typeof code !== "number" || !isValidStatusCode(code)) {
1465
+ throw new TypeError("First argument must be a valid error code number");
1466
+ } else if (data === void 0 || !data.length) {
1467
+ buf = Buffer.allocUnsafe(2);
1468
+ buf.writeUInt16BE(code, 0);
1469
+ } else {
1470
+ const length = Buffer.byteLength(data);
1471
+ if (length > 123) {
1472
+ throw new RangeError("The message must not be greater than 123 bytes");
1473
+ }
1474
+ buf = Buffer.allocUnsafe(2 + length);
1475
+ buf.writeUInt16BE(code, 0);
1476
+ if (typeof data === "string") {
1477
+ buf.write(data, 2);
1478
+ } else {
1479
+ buf.set(data, 2);
1480
+ }
1481
+ }
1482
+ const options = {
1483
+ [kByteLength]: buf.length,
1484
+ fin: true,
1485
+ generateMask: this._generateMask,
1486
+ mask,
1487
+ maskBuffer: this._maskBuffer,
1488
+ opcode: 8,
1489
+ readOnly: false,
1490
+ rsv1: false
1491
+ };
1492
+ if (this._state !== DEFAULT) {
1493
+ this.enqueue([this.dispatch, buf, false, options, cb]);
1494
+ } else {
1495
+ this.sendFrame(_Sender.frame(buf, options), cb);
1496
+ }
1497
+ }
1498
+ /**
1499
+ * Sends a ping message to the other peer.
1500
+ *
1501
+ * @param {*} data The message to send
1502
+ * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
1503
+ * @param {Function} [cb] Callback
1504
+ * @public
1505
+ */
1506
+ ping(data, mask, cb) {
1507
+ let byteLength;
1508
+ let readOnly;
1509
+ if (typeof data === "string") {
1510
+ byteLength = Buffer.byteLength(data);
1511
+ readOnly = false;
1512
+ } else if (isBlob(data)) {
1513
+ byteLength = data.size;
1514
+ readOnly = false;
1515
+ } else {
1516
+ data = toBuffer(data);
1517
+ byteLength = data.length;
1518
+ readOnly = toBuffer.readOnly;
1519
+ }
1520
+ if (byteLength > 125) {
1521
+ throw new RangeError("The data size must not be greater than 125 bytes");
1522
+ }
1523
+ const options = {
1524
+ [kByteLength]: byteLength,
1525
+ fin: true,
1526
+ generateMask: this._generateMask,
1527
+ mask,
1528
+ maskBuffer: this._maskBuffer,
1529
+ opcode: 9,
1530
+ readOnly,
1531
+ rsv1: false
1532
+ };
1533
+ if (isBlob(data)) {
1534
+ if (this._state !== DEFAULT) {
1535
+ this.enqueue([this.getBlobData, data, false, options, cb]);
1536
+ } else {
1537
+ this.getBlobData(data, false, options, cb);
1538
+ }
1539
+ } else if (this._state !== DEFAULT) {
1540
+ this.enqueue([this.dispatch, data, false, options, cb]);
1541
+ } else {
1542
+ this.sendFrame(_Sender.frame(data, options), cb);
1543
+ }
1544
+ }
1545
+ /**
1546
+ * Sends a pong message to the other peer.
1547
+ *
1548
+ * @param {*} data The message to send
1549
+ * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
1550
+ * @param {Function} [cb] Callback
1551
+ * @public
1552
+ */
1553
+ pong(data, mask, cb) {
1554
+ let byteLength;
1555
+ let readOnly;
1556
+ if (typeof data === "string") {
1557
+ byteLength = Buffer.byteLength(data);
1558
+ readOnly = false;
1559
+ } else if (isBlob(data)) {
1560
+ byteLength = data.size;
1561
+ readOnly = false;
1562
+ } else {
1563
+ data = toBuffer(data);
1564
+ byteLength = data.length;
1565
+ readOnly = toBuffer.readOnly;
1566
+ }
1567
+ if (byteLength > 125) {
1568
+ throw new RangeError("The data size must not be greater than 125 bytes");
1569
+ }
1570
+ const options = {
1571
+ [kByteLength]: byteLength,
1572
+ fin: true,
1573
+ generateMask: this._generateMask,
1574
+ mask,
1575
+ maskBuffer: this._maskBuffer,
1576
+ opcode: 10,
1577
+ readOnly,
1578
+ rsv1: false
1579
+ };
1580
+ if (isBlob(data)) {
1581
+ if (this._state !== DEFAULT) {
1582
+ this.enqueue([this.getBlobData, data, false, options, cb]);
1583
+ } else {
1584
+ this.getBlobData(data, false, options, cb);
1585
+ }
1586
+ } else if (this._state !== DEFAULT) {
1587
+ this.enqueue([this.dispatch, data, false, options, cb]);
1588
+ } else {
1589
+ this.sendFrame(_Sender.frame(data, options), cb);
1590
+ }
1591
+ }
1592
+ /**
1593
+ * Sends a data message to the other peer.
1594
+ *
1595
+ * @param {*} data The message to send
1596
+ * @param {Object} options Options object
1597
+ * @param {Boolean} [options.binary=false] Specifies whether `data` is binary
1598
+ * or text
1599
+ * @param {Boolean} [options.compress=false] Specifies whether or not to
1600
+ * compress `data`
1601
+ * @param {Boolean} [options.fin=false] Specifies whether the fragment is the
1602
+ * last one
1603
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1604
+ * `data`
1605
+ * @param {Function} [cb] Callback
1606
+ * @public
1607
+ */
1608
+ send(data, options, cb) {
1609
+ const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
1610
+ let opcode = options.binary ? 2 : 1;
1611
+ let rsv1 = options.compress;
1612
+ let byteLength;
1613
+ let readOnly;
1614
+ if (typeof data === "string") {
1615
+ byteLength = Buffer.byteLength(data);
1616
+ readOnly = false;
1617
+ } else if (isBlob(data)) {
1618
+ byteLength = data.size;
1619
+ readOnly = false;
1620
+ } else {
1621
+ data = toBuffer(data);
1622
+ byteLength = data.length;
1623
+ readOnly = toBuffer.readOnly;
1624
+ }
1625
+ if (this._firstFragment) {
1626
+ this._firstFragment = false;
1627
+ if (rsv1 && perMessageDeflate && perMessageDeflate.params[perMessageDeflate._isServer ? "server_no_context_takeover" : "client_no_context_takeover"]) {
1628
+ rsv1 = byteLength >= perMessageDeflate._threshold;
1629
+ }
1630
+ this._compress = rsv1;
1631
+ } else {
1632
+ rsv1 = false;
1633
+ opcode = 0;
1634
+ }
1635
+ if (options.fin) this._firstFragment = true;
1636
+ const opts = {
1637
+ [kByteLength]: byteLength,
1638
+ fin: options.fin,
1639
+ generateMask: this._generateMask,
1640
+ mask: options.mask,
1641
+ maskBuffer: this._maskBuffer,
1642
+ opcode,
1643
+ readOnly,
1644
+ rsv1
1645
+ };
1646
+ if (isBlob(data)) {
1647
+ if (this._state !== DEFAULT) {
1648
+ this.enqueue([this.getBlobData, data, this._compress, opts, cb]);
1649
+ } else {
1650
+ this.getBlobData(data, this._compress, opts, cb);
1651
+ }
1652
+ } else if (this._state !== DEFAULT) {
1653
+ this.enqueue([this.dispatch, data, this._compress, opts, cb]);
1654
+ } else {
1655
+ this.dispatch(data, this._compress, opts, cb);
1656
+ }
1657
+ }
1658
+ /**
1659
+ * Gets the contents of a blob as binary data.
1660
+ *
1661
+ * @param {Blob} blob The blob
1662
+ * @param {Boolean} [compress=false] Specifies whether or not to compress
1663
+ * the data
1664
+ * @param {Object} options Options object
1665
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1666
+ * FIN bit
1667
+ * @param {Function} [options.generateMask] The function used to generate the
1668
+ * masking key
1669
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1670
+ * `data`
1671
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1672
+ * key
1673
+ * @param {Number} options.opcode The opcode
1674
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1675
+ * modified
1676
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1677
+ * RSV1 bit
1678
+ * @param {Function} [cb] Callback
1679
+ * @private
1680
+ */
1681
+ getBlobData(blob, compress, options, cb) {
1682
+ this._bufferedBytes += options[kByteLength];
1683
+ this._state = GET_BLOB_DATA;
1684
+ blob.arrayBuffer().then((arrayBuffer) => {
1685
+ if (this._socket.destroyed) {
1686
+ const err = new Error(
1687
+ "The socket was closed while the blob was being read"
1688
+ );
1689
+ process.nextTick(callCallbacks, this, err, cb);
1690
+ return;
1691
+ }
1692
+ this._bufferedBytes -= options[kByteLength];
1693
+ const data = toBuffer(arrayBuffer);
1694
+ if (!compress) {
1695
+ this._state = DEFAULT;
1696
+ this.sendFrame(_Sender.frame(data, options), cb);
1697
+ this.dequeue();
1698
+ } else {
1699
+ this.dispatch(data, compress, options, cb);
1700
+ }
1701
+ }).catch((err) => {
1702
+ process.nextTick(onError, this, err, cb);
1703
+ });
1704
+ }
1705
+ /**
1706
+ * Dispatches a message.
1707
+ *
1708
+ * @param {(Buffer|String)} data The message to send
1709
+ * @param {Boolean} [compress=false] Specifies whether or not to compress
1710
+ * `data`
1711
+ * @param {Object} options Options object
1712
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1713
+ * FIN bit
1714
+ * @param {Function} [options.generateMask] The function used to generate the
1715
+ * masking key
1716
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1717
+ * `data`
1718
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1719
+ * key
1720
+ * @param {Number} options.opcode The opcode
1721
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1722
+ * modified
1723
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1724
+ * RSV1 bit
1725
+ * @param {Function} [cb] Callback
1726
+ * @private
1727
+ */
1728
+ dispatch(data, compress, options, cb) {
1729
+ if (!compress) {
1730
+ this.sendFrame(_Sender.frame(data, options), cb);
1731
+ return;
1732
+ }
1733
+ const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
1734
+ this._bufferedBytes += options[kByteLength];
1735
+ this._state = DEFLATING;
1736
+ perMessageDeflate.compress(data, options.fin, (_, buf) => {
1737
+ if (this._socket.destroyed) {
1738
+ const err = new Error(
1739
+ "The socket was closed while data was being compressed"
1740
+ );
1741
+ callCallbacks(this, err, cb);
1742
+ return;
1743
+ }
1744
+ this._bufferedBytes -= options[kByteLength];
1745
+ this._state = DEFAULT;
1746
+ options.readOnly = false;
1747
+ this.sendFrame(_Sender.frame(buf, options), cb);
1748
+ this.dequeue();
1749
+ });
1750
+ }
1751
+ /**
1752
+ * Executes queued send operations.
1753
+ *
1754
+ * @private
1755
+ */
1756
+ dequeue() {
1757
+ while (this._state === DEFAULT && this._queue.length) {
1758
+ const params = this._queue.shift();
1759
+ this._bufferedBytes -= params[3][kByteLength];
1760
+ Reflect.apply(params[0], this, params.slice(1));
1761
+ }
1762
+ }
1763
+ /**
1764
+ * Enqueues a send operation.
1765
+ *
1766
+ * @param {Array} params Send operation parameters.
1767
+ * @private
1768
+ */
1769
+ enqueue(params) {
1770
+ this._bufferedBytes += params[3][kByteLength];
1771
+ this._queue.push(params);
1772
+ }
1773
+ /**
1774
+ * Sends a frame.
1775
+ *
1776
+ * @param {(Buffer | String)[]} list The frame to send
1777
+ * @param {Function} [cb] Callback
1778
+ * @private
1779
+ */
1780
+ sendFrame(list, cb) {
1781
+ if (list.length === 2) {
1782
+ this._socket.cork();
1783
+ this._socket.write(list[0]);
1784
+ this._socket.write(list[1], cb);
1785
+ this._socket.uncork();
1786
+ } else {
1787
+ this._socket.write(list[0], cb);
1788
+ }
1789
+ }
1790
+ };
1791
+ module.exports = Sender2;
1792
+ function callCallbacks(sender, err, cb) {
1793
+ if (typeof cb === "function") cb(err);
1794
+ for (let i = 0; i < sender._queue.length; i++) {
1795
+ const params = sender._queue[i];
1796
+ const callback = params[params.length - 1];
1797
+ if (typeof callback === "function") callback(err);
1798
+ }
1799
+ }
1800
+ function onError(sender, err, cb) {
1801
+ callCallbacks(sender, err, cb);
1802
+ sender.onerror(err);
1803
+ }
1804
+ }
1805
+ });
1806
+
1807
+ // ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/event-target.js
1808
+ var require_event_target = __commonJS({
1809
+ "../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/event-target.js"(exports, module) {
1810
+ var { kForOnEventAttribute, kListener } = require_constants();
1811
+ var kCode = Symbol("kCode");
1812
+ var kData = Symbol("kData");
1813
+ var kError = Symbol("kError");
1814
+ var kMessage = Symbol("kMessage");
1815
+ var kReason = Symbol("kReason");
1816
+ var kTarget = Symbol("kTarget");
1817
+ var kType = Symbol("kType");
1818
+ var kWasClean = Symbol("kWasClean");
1819
+ var Event = class {
1820
+ /**
1821
+ * Create a new `Event`.
1822
+ *
1823
+ * @param {String} type The name of the event
1824
+ * @throws {TypeError} If the `type` argument is not specified
1825
+ */
1826
+ constructor(type) {
1827
+ this[kTarget] = null;
1828
+ this[kType] = type;
1829
+ }
1830
+ /**
1831
+ * @type {*}
1832
+ */
1833
+ get target() {
1834
+ return this[kTarget];
1835
+ }
1836
+ /**
1837
+ * @type {String}
1838
+ */
1839
+ get type() {
1840
+ return this[kType];
1841
+ }
1842
+ };
1843
+ Object.defineProperty(Event.prototype, "target", { enumerable: true });
1844
+ Object.defineProperty(Event.prototype, "type", { enumerable: true });
1845
+ var CloseEvent = class extends Event {
1846
+ /**
1847
+ * Create a new `CloseEvent`.
1848
+ *
1849
+ * @param {String} type The name of the event
1850
+ * @param {Object} [options] A dictionary object that allows for setting
1851
+ * attributes via object members of the same name
1852
+ * @param {Number} [options.code=0] The status code explaining why the
1853
+ * connection was closed
1854
+ * @param {String} [options.reason=''] A human-readable string explaining why
1855
+ * the connection was closed
1856
+ * @param {Boolean} [options.wasClean=false] Indicates whether or not the
1857
+ * connection was cleanly closed
1858
+ */
1859
+ constructor(type, options = {}) {
1860
+ super(type);
1861
+ this[kCode] = options.code === void 0 ? 0 : options.code;
1862
+ this[kReason] = options.reason === void 0 ? "" : options.reason;
1863
+ this[kWasClean] = options.wasClean === void 0 ? false : options.wasClean;
1864
+ }
1865
+ /**
1866
+ * @type {Number}
1867
+ */
1868
+ get code() {
1869
+ return this[kCode];
1870
+ }
1871
+ /**
1872
+ * @type {String}
1873
+ */
1874
+ get reason() {
1875
+ return this[kReason];
1876
+ }
1877
+ /**
1878
+ * @type {Boolean}
1879
+ */
1880
+ get wasClean() {
1881
+ return this[kWasClean];
1882
+ }
1883
+ };
1884
+ Object.defineProperty(CloseEvent.prototype, "code", { enumerable: true });
1885
+ Object.defineProperty(CloseEvent.prototype, "reason", { enumerable: true });
1886
+ Object.defineProperty(CloseEvent.prototype, "wasClean", { enumerable: true });
1887
+ var ErrorEvent = class extends Event {
1888
+ /**
1889
+ * Create a new `ErrorEvent`.
1890
+ *
1891
+ * @param {String} type The name of the event
1892
+ * @param {Object} [options] A dictionary object that allows for setting
1893
+ * attributes via object members of the same name
1894
+ * @param {*} [options.error=null] The error that generated this event
1895
+ * @param {String} [options.message=''] The error message
1896
+ */
1897
+ constructor(type, options = {}) {
1898
+ super(type);
1899
+ this[kError] = options.error === void 0 ? null : options.error;
1900
+ this[kMessage] = options.message === void 0 ? "" : options.message;
1901
+ }
1902
+ /**
1903
+ * @type {*}
1904
+ */
1905
+ get error() {
1906
+ return this[kError];
1907
+ }
1908
+ /**
1909
+ * @type {String}
1910
+ */
1911
+ get message() {
1912
+ return this[kMessage];
1913
+ }
1914
+ };
1915
+ Object.defineProperty(ErrorEvent.prototype, "error", { enumerable: true });
1916
+ Object.defineProperty(ErrorEvent.prototype, "message", { enumerable: true });
1917
+ var MessageEvent = class extends Event {
1918
+ /**
1919
+ * Create a new `MessageEvent`.
1920
+ *
1921
+ * @param {String} type The name of the event
1922
+ * @param {Object} [options] A dictionary object that allows for setting
1923
+ * attributes via object members of the same name
1924
+ * @param {*} [options.data=null] The message content
1925
+ */
1926
+ constructor(type, options = {}) {
1927
+ super(type);
1928
+ this[kData] = options.data === void 0 ? null : options.data;
1929
+ }
1930
+ /**
1931
+ * @type {*}
1932
+ */
1933
+ get data() {
1934
+ return this[kData];
1935
+ }
1936
+ };
1937
+ Object.defineProperty(MessageEvent.prototype, "data", { enumerable: true });
1938
+ var EventTarget = {
1939
+ /**
1940
+ * Register an event listener.
1941
+ *
1942
+ * @param {String} type A string representing the event type to listen for
1943
+ * @param {(Function|Object)} handler The listener to add
1944
+ * @param {Object} [options] An options object specifies characteristics about
1945
+ * the event listener
1946
+ * @param {Boolean} [options.once=false] A `Boolean` indicating that the
1947
+ * listener should be invoked at most once after being added. If `true`,
1948
+ * the listener would be automatically removed when invoked.
1949
+ * @public
1950
+ */
1951
+ addEventListener(type, handler, options = {}) {
1952
+ for (const listener of this.listeners(type)) {
1953
+ if (!options[kForOnEventAttribute] && listener[kListener] === handler && !listener[kForOnEventAttribute]) {
1954
+ return;
1955
+ }
1956
+ }
1957
+ let wrapper;
1958
+ if (type === "message") {
1959
+ wrapper = function onMessage(data, isBinary) {
1960
+ const event = new MessageEvent("message", {
1961
+ data: isBinary ? data : data.toString()
1962
+ });
1963
+ event[kTarget] = this;
1964
+ callListener(handler, this, event);
1965
+ };
1966
+ } else if (type === "close") {
1967
+ wrapper = function onClose(code, message) {
1968
+ const event = new CloseEvent("close", {
1969
+ code,
1970
+ reason: message.toString(),
1971
+ wasClean: this._closeFrameReceived && this._closeFrameSent
1972
+ });
1973
+ event[kTarget] = this;
1974
+ callListener(handler, this, event);
1975
+ };
1976
+ } else if (type === "error") {
1977
+ wrapper = function onError(error) {
1978
+ const event = new ErrorEvent("error", {
1979
+ error,
1980
+ message: error.message
1981
+ });
1982
+ event[kTarget] = this;
1983
+ callListener(handler, this, event);
1984
+ };
1985
+ } else if (type === "open") {
1986
+ wrapper = function onOpen() {
1987
+ const event = new Event("open");
1988
+ event[kTarget] = this;
1989
+ callListener(handler, this, event);
1990
+ };
1991
+ } else {
1992
+ return;
1993
+ }
1994
+ wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
1995
+ wrapper[kListener] = handler;
1996
+ if (options.once) {
1997
+ this.once(type, wrapper);
1998
+ } else {
1999
+ this.on(type, wrapper);
2000
+ }
2001
+ },
2002
+ /**
2003
+ * Remove an event listener.
2004
+ *
2005
+ * @param {String} type A string representing the event type to remove
2006
+ * @param {(Function|Object)} handler The listener to remove
2007
+ * @public
2008
+ */
2009
+ removeEventListener(type, handler) {
2010
+ for (const listener of this.listeners(type)) {
2011
+ if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
2012
+ this.removeListener(type, listener);
2013
+ break;
2014
+ }
2015
+ }
2016
+ }
2017
+ };
2018
+ module.exports = {
2019
+ CloseEvent,
2020
+ ErrorEvent,
2021
+ Event,
2022
+ EventTarget,
2023
+ MessageEvent
2024
+ };
2025
+ function callListener(listener, thisArg, event) {
2026
+ if (typeof listener === "object" && listener.handleEvent) {
2027
+ listener.handleEvent.call(listener, event);
2028
+ } else {
2029
+ listener.call(thisArg, event);
2030
+ }
2031
+ }
2032
+ }
2033
+ });
2034
+
2035
+ // ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/extension.js
2036
+ var require_extension = __commonJS({
2037
+ "../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/extension.js"(exports, module) {
2038
+ var { tokenChars } = require_validation();
2039
+ function push(dest, name, elem) {
2040
+ if (dest[name] === void 0) dest[name] = [elem];
2041
+ else dest[name].push(elem);
2042
+ }
2043
+ function parse(header) {
2044
+ const offers = /* @__PURE__ */ Object.create(null);
2045
+ let params = /* @__PURE__ */ Object.create(null);
2046
+ let mustUnescape = false;
2047
+ let isEscaping = false;
2048
+ let inQuotes = false;
2049
+ let extensionName;
2050
+ let paramName;
2051
+ let start = -1;
2052
+ let code = -1;
2053
+ let end = -1;
2054
+ let i = 0;
2055
+ for (; i < header.length; i++) {
2056
+ code = header.charCodeAt(i);
2057
+ if (extensionName === void 0) {
2058
+ if (end === -1 && tokenChars[code] === 1) {
2059
+ if (start === -1) start = i;
2060
+ } else if (i !== 0 && (code === 32 || code === 9)) {
2061
+ if (end === -1 && start !== -1) end = i;
2062
+ } else if (code === 59 || code === 44) {
2063
+ if (start === -1) {
2064
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2065
+ }
2066
+ if (end === -1) end = i;
2067
+ const name = header.slice(start, end);
2068
+ if (code === 44) {
2069
+ push(offers, name, params);
2070
+ params = /* @__PURE__ */ Object.create(null);
2071
+ } else {
2072
+ extensionName = name;
2073
+ }
2074
+ start = end = -1;
2075
+ } else {
2076
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2077
+ }
2078
+ } else if (paramName === void 0) {
2079
+ if (end === -1 && tokenChars[code] === 1) {
2080
+ if (start === -1) start = i;
2081
+ } else if (code === 32 || code === 9) {
2082
+ if (end === -1 && start !== -1) end = i;
2083
+ } else if (code === 59 || code === 44) {
2084
+ if (start === -1) {
2085
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2086
+ }
2087
+ if (end === -1) end = i;
2088
+ push(params, header.slice(start, end), true);
2089
+ if (code === 44) {
2090
+ push(offers, extensionName, params);
2091
+ params = /* @__PURE__ */ Object.create(null);
2092
+ extensionName = void 0;
2093
+ }
2094
+ start = end = -1;
2095
+ } else if (code === 61 && start !== -1 && end === -1) {
2096
+ paramName = header.slice(start, i);
2097
+ start = end = -1;
2098
+ } else {
2099
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2100
+ }
2101
+ } else {
2102
+ if (isEscaping) {
2103
+ if (tokenChars[code] !== 1) {
2104
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2105
+ }
2106
+ if (start === -1) start = i;
2107
+ else if (!mustUnescape) mustUnescape = true;
2108
+ isEscaping = false;
2109
+ } else if (inQuotes) {
2110
+ if (tokenChars[code] === 1) {
2111
+ if (start === -1) start = i;
2112
+ } else if (code === 34 && start !== -1) {
2113
+ inQuotes = false;
2114
+ end = i;
2115
+ } else if (code === 92) {
2116
+ isEscaping = true;
2117
+ } else {
2118
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2119
+ }
2120
+ } else if (code === 34 && header.charCodeAt(i - 1) === 61) {
2121
+ inQuotes = true;
2122
+ } else if (end === -1 && tokenChars[code] === 1) {
2123
+ if (start === -1) start = i;
2124
+ } else if (start !== -1 && (code === 32 || code === 9)) {
2125
+ if (end === -1) end = i;
2126
+ } else if (code === 59 || code === 44) {
2127
+ if (start === -1) {
2128
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2129
+ }
2130
+ if (end === -1) end = i;
2131
+ let value = header.slice(start, end);
2132
+ if (mustUnescape) {
2133
+ value = value.replace(/\\/g, "");
2134
+ mustUnescape = false;
2135
+ }
2136
+ push(params, paramName, value);
2137
+ if (code === 44) {
2138
+ push(offers, extensionName, params);
2139
+ params = /* @__PURE__ */ Object.create(null);
2140
+ extensionName = void 0;
2141
+ }
2142
+ paramName = void 0;
2143
+ start = end = -1;
2144
+ } else {
2145
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2146
+ }
2147
+ }
2148
+ }
2149
+ if (start === -1 || inQuotes || code === 32 || code === 9) {
2150
+ throw new SyntaxError("Unexpected end of input");
2151
+ }
2152
+ if (end === -1) end = i;
2153
+ const token = header.slice(start, end);
2154
+ if (extensionName === void 0) {
2155
+ push(offers, token, params);
2156
+ } else {
2157
+ if (paramName === void 0) {
2158
+ push(params, token, true);
2159
+ } else if (mustUnescape) {
2160
+ push(params, paramName, token.replace(/\\/g, ""));
2161
+ } else {
2162
+ push(params, paramName, token);
2163
+ }
2164
+ push(offers, extensionName, params);
2165
+ }
2166
+ return offers;
2167
+ }
2168
+ function format(extensions) {
2169
+ return Object.keys(extensions).map((extension) => {
2170
+ let configurations = extensions[extension];
2171
+ if (!Array.isArray(configurations)) configurations = [configurations];
2172
+ return configurations.map((params) => {
2173
+ return [extension].concat(
2174
+ Object.keys(params).map((k) => {
2175
+ let values = params[k];
2176
+ if (!Array.isArray(values)) values = [values];
2177
+ return values.map((v) => v === true ? k : `${k}=${v}`).join("; ");
2178
+ })
2179
+ ).join("; ");
2180
+ }).join(", ");
2181
+ }).join(", ");
2182
+ }
2183
+ module.exports = { format, parse };
2184
+ }
2185
+ });
2186
+
2187
+ // ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/websocket.js
2188
+ var require_websocket = __commonJS({
2189
+ "../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/websocket.js"(exports, module) {
2190
+ var EventEmitter = __require("events");
2191
+ var https = __require("https");
2192
+ var http = __require("http");
2193
+ var net = __require("net");
2194
+ var tls = __require("tls");
2195
+ var { randomBytes, createHash } = __require("crypto");
2196
+ var { Duplex, Readable } = __require("stream");
2197
+ var { URL } = __require("url");
2198
+ var PerMessageDeflate = require_permessage_deflate();
2199
+ var Receiver2 = require_receiver();
2200
+ var Sender2 = require_sender();
2201
+ var { isBlob } = require_validation();
2202
+ var {
2203
+ BINARY_TYPES,
2204
+ EMPTY_BUFFER,
2205
+ GUID,
2206
+ kForOnEventAttribute,
2207
+ kListener,
2208
+ kStatusCode,
2209
+ kWebSocket,
2210
+ NOOP
2211
+ } = require_constants();
2212
+ var {
2213
+ EventTarget: { addEventListener, removeEventListener }
2214
+ } = require_event_target();
2215
+ var { format, parse } = require_extension();
2216
+ var { toBuffer } = require_buffer_util();
2217
+ var closeTimeout = 30 * 1e3;
2218
+ var kAborted = Symbol("kAborted");
2219
+ var protocolVersions = [8, 13];
2220
+ var readyStates = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
2221
+ var subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
2222
+ var WebSocket4 = class _WebSocket extends EventEmitter {
2223
+ /**
2224
+ * Create a new `WebSocket`.
2225
+ *
2226
+ * @param {(String|URL)} address The URL to which to connect
2227
+ * @param {(String|String[])} [protocols] The subprotocols
2228
+ * @param {Object} [options] Connection options
2229
+ */
2230
+ constructor(address, protocols, options) {
2231
+ super();
2232
+ this._binaryType = BINARY_TYPES[0];
2233
+ this._closeCode = 1006;
2234
+ this._closeFrameReceived = false;
2235
+ this._closeFrameSent = false;
2236
+ this._closeMessage = EMPTY_BUFFER;
2237
+ this._closeTimer = null;
2238
+ this._errorEmitted = false;
2239
+ this._extensions = {};
2240
+ this._paused = false;
2241
+ this._protocol = "";
2242
+ this._readyState = _WebSocket.CONNECTING;
2243
+ this._receiver = null;
2244
+ this._sender = null;
2245
+ this._socket = null;
2246
+ if (address !== null) {
2247
+ this._bufferedAmount = 0;
2248
+ this._isServer = false;
2249
+ this._redirects = 0;
2250
+ if (protocols === void 0) {
2251
+ protocols = [];
2252
+ } else if (!Array.isArray(protocols)) {
2253
+ if (typeof protocols === "object" && protocols !== null) {
2254
+ options = protocols;
2255
+ protocols = [];
2256
+ } else {
2257
+ protocols = [protocols];
2258
+ }
2259
+ }
2260
+ initAsClient(this, address, protocols, options);
2261
+ } else {
2262
+ this._autoPong = options.autoPong;
2263
+ this._isServer = true;
2264
+ }
2265
+ }
2266
+ /**
2267
+ * For historical reasons, the custom "nodebuffer" type is used by the default
2268
+ * instead of "blob".
2269
+ *
2270
+ * @type {String}
2271
+ */
2272
+ get binaryType() {
2273
+ return this._binaryType;
2274
+ }
2275
+ set binaryType(type) {
2276
+ if (!BINARY_TYPES.includes(type)) return;
2277
+ this._binaryType = type;
2278
+ if (this._receiver) this._receiver._binaryType = type;
2279
+ }
2280
+ /**
2281
+ * @type {Number}
2282
+ */
2283
+ get bufferedAmount() {
2284
+ if (!this._socket) return this._bufferedAmount;
2285
+ return this._socket._writableState.length + this._sender._bufferedBytes;
2286
+ }
2287
+ /**
2288
+ * @type {String}
2289
+ */
2290
+ get extensions() {
2291
+ return Object.keys(this._extensions).join();
2292
+ }
2293
+ /**
2294
+ * @type {Boolean}
2295
+ */
2296
+ get isPaused() {
2297
+ return this._paused;
2298
+ }
2299
+ /**
2300
+ * @type {Function}
2301
+ */
2302
+ /* istanbul ignore next */
2303
+ get onclose() {
2304
+ return null;
2305
+ }
2306
+ /**
2307
+ * @type {Function}
2308
+ */
2309
+ /* istanbul ignore next */
2310
+ get onerror() {
2311
+ return null;
2312
+ }
2313
+ /**
2314
+ * @type {Function}
2315
+ */
2316
+ /* istanbul ignore next */
2317
+ get onopen() {
2318
+ return null;
2319
+ }
2320
+ /**
2321
+ * @type {Function}
2322
+ */
2323
+ /* istanbul ignore next */
2324
+ get onmessage() {
2325
+ return null;
2326
+ }
2327
+ /**
2328
+ * @type {String}
2329
+ */
2330
+ get protocol() {
2331
+ return this._protocol;
2332
+ }
2333
+ /**
2334
+ * @type {Number}
2335
+ */
2336
+ get readyState() {
2337
+ return this._readyState;
2338
+ }
2339
+ /**
2340
+ * @type {String}
2341
+ */
2342
+ get url() {
2343
+ return this._url;
2344
+ }
2345
+ /**
2346
+ * Set up the socket and the internal resources.
2347
+ *
2348
+ * @param {Duplex} socket The network socket between the server and client
2349
+ * @param {Buffer} head The first packet of the upgraded stream
2350
+ * @param {Object} options Options object
2351
+ * @param {Boolean} [options.allowSynchronousEvents=false] Specifies whether
2352
+ * any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
2353
+ * multiple times in the same tick
2354
+ * @param {Function} [options.generateMask] The function used to generate the
2355
+ * masking key
2356
+ * @param {Number} [options.maxPayload=0] The maximum allowed message size
2357
+ * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
2358
+ * not to skip UTF-8 validation for text and close messages
2359
+ * @private
2360
+ */
2361
+ setSocket(socket, head, options) {
2362
+ const receiver = new Receiver2({
2363
+ allowSynchronousEvents: options.allowSynchronousEvents,
2364
+ binaryType: this.binaryType,
2365
+ extensions: this._extensions,
2366
+ isServer: this._isServer,
2367
+ maxPayload: options.maxPayload,
2368
+ skipUTF8Validation: options.skipUTF8Validation
2369
+ });
2370
+ const sender = new Sender2(socket, this._extensions, options.generateMask);
2371
+ this._receiver = receiver;
2372
+ this._sender = sender;
2373
+ this._socket = socket;
2374
+ receiver[kWebSocket] = this;
2375
+ sender[kWebSocket] = this;
2376
+ socket[kWebSocket] = this;
2377
+ receiver.on("conclude", receiverOnConclude);
2378
+ receiver.on("drain", receiverOnDrain);
2379
+ receiver.on("error", receiverOnError);
2380
+ receiver.on("message", receiverOnMessage);
2381
+ receiver.on("ping", receiverOnPing);
2382
+ receiver.on("pong", receiverOnPong);
2383
+ sender.onerror = senderOnError;
2384
+ if (socket.setTimeout) socket.setTimeout(0);
2385
+ if (socket.setNoDelay) socket.setNoDelay();
2386
+ if (head.length > 0) socket.unshift(head);
2387
+ socket.on("close", socketOnClose);
2388
+ socket.on("data", socketOnData);
2389
+ socket.on("end", socketOnEnd);
2390
+ socket.on("error", socketOnError);
2391
+ this._readyState = _WebSocket.OPEN;
2392
+ this.emit("open");
2393
+ }
2394
+ /**
2395
+ * Emit the `'close'` event.
2396
+ *
2397
+ * @private
2398
+ */
2399
+ emitClose() {
2400
+ if (!this._socket) {
2401
+ this._readyState = _WebSocket.CLOSED;
2402
+ this.emit("close", this._closeCode, this._closeMessage);
2403
+ return;
2404
+ }
2405
+ if (this._extensions[PerMessageDeflate.extensionName]) {
2406
+ this._extensions[PerMessageDeflate.extensionName].cleanup();
2407
+ }
2408
+ this._receiver.removeAllListeners();
2409
+ this._readyState = _WebSocket.CLOSED;
2410
+ this.emit("close", this._closeCode, this._closeMessage);
2411
+ }
2412
+ /**
2413
+ * Start a closing handshake.
2414
+ *
2415
+ * +----------+ +-----------+ +----------+
2416
+ * - - -|ws.close()|-->|close frame|-->|ws.close()|- - -
2417
+ * | +----------+ +-----------+ +----------+ |
2418
+ * +----------+ +-----------+ |
2419
+ * CLOSING |ws.close()|<--|close frame|<--+-----+ CLOSING
2420
+ * +----------+ +-----------+ |
2421
+ * | | | +---+ |
2422
+ * +------------------------+-->|fin| - - - -
2423
+ * | +---+ | +---+
2424
+ * - - - - -|fin|<---------------------+
2425
+ * +---+
2426
+ *
2427
+ * @param {Number} [code] Status code explaining why the connection is closing
2428
+ * @param {(String|Buffer)} [data] The reason why the connection is
2429
+ * closing
2430
+ * @public
2431
+ */
2432
+ close(code, data) {
2433
+ if (this.readyState === _WebSocket.CLOSED) return;
2434
+ if (this.readyState === _WebSocket.CONNECTING) {
2435
+ const msg = "WebSocket was closed before the connection was established";
2436
+ abortHandshake(this, this._req, msg);
2437
+ return;
2438
+ }
2439
+ if (this.readyState === _WebSocket.CLOSING) {
2440
+ if (this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted)) {
2441
+ this._socket.end();
2442
+ }
2443
+ return;
2444
+ }
2445
+ this._readyState = _WebSocket.CLOSING;
2446
+ this._sender.close(code, data, !this._isServer, (err) => {
2447
+ if (err) return;
2448
+ this._closeFrameSent = true;
2449
+ if (this._closeFrameReceived || this._receiver._writableState.errorEmitted) {
2450
+ this._socket.end();
2451
+ }
2452
+ });
2453
+ setCloseTimer(this);
2454
+ }
2455
+ /**
2456
+ * Pause the socket.
2457
+ *
2458
+ * @public
2459
+ */
2460
+ pause() {
2461
+ if (this.readyState === _WebSocket.CONNECTING || this.readyState === _WebSocket.CLOSED) {
2462
+ return;
2463
+ }
2464
+ this._paused = true;
2465
+ this._socket.pause();
2466
+ }
2467
+ /**
2468
+ * Send a ping.
2469
+ *
2470
+ * @param {*} [data] The data to send
2471
+ * @param {Boolean} [mask] Indicates whether or not to mask `data`
2472
+ * @param {Function} [cb] Callback which is executed when the ping is sent
2473
+ * @public
2474
+ */
2475
+ ping(data, mask, cb) {
2476
+ if (this.readyState === _WebSocket.CONNECTING) {
2477
+ throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2478
+ }
2479
+ if (typeof data === "function") {
2480
+ cb = data;
2481
+ data = mask = void 0;
2482
+ } else if (typeof mask === "function") {
2483
+ cb = mask;
2484
+ mask = void 0;
2485
+ }
2486
+ if (typeof data === "number") data = data.toString();
2487
+ if (this.readyState !== _WebSocket.OPEN) {
2488
+ sendAfterClose(this, data, cb);
2489
+ return;
2490
+ }
2491
+ if (mask === void 0) mask = !this._isServer;
2492
+ this._sender.ping(data || EMPTY_BUFFER, mask, cb);
2493
+ }
2494
+ /**
2495
+ * Send a pong.
2496
+ *
2497
+ * @param {*} [data] The data to send
2498
+ * @param {Boolean} [mask] Indicates whether or not to mask `data`
2499
+ * @param {Function} [cb] Callback which is executed when the pong is sent
2500
+ * @public
2501
+ */
2502
+ pong(data, mask, cb) {
2503
+ if (this.readyState === _WebSocket.CONNECTING) {
2504
+ throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2505
+ }
2506
+ if (typeof data === "function") {
2507
+ cb = data;
2508
+ data = mask = void 0;
2509
+ } else if (typeof mask === "function") {
2510
+ cb = mask;
2511
+ mask = void 0;
2512
+ }
2513
+ if (typeof data === "number") data = data.toString();
2514
+ if (this.readyState !== _WebSocket.OPEN) {
2515
+ sendAfterClose(this, data, cb);
2516
+ return;
2517
+ }
2518
+ if (mask === void 0) mask = !this._isServer;
2519
+ this._sender.pong(data || EMPTY_BUFFER, mask, cb);
2520
+ }
2521
+ /**
2522
+ * Resume the socket.
2523
+ *
2524
+ * @public
2525
+ */
2526
+ resume() {
2527
+ if (this.readyState === _WebSocket.CONNECTING || this.readyState === _WebSocket.CLOSED) {
2528
+ return;
2529
+ }
2530
+ this._paused = false;
2531
+ if (!this._receiver._writableState.needDrain) this._socket.resume();
2532
+ }
2533
+ /**
2534
+ * Send a data message.
2535
+ *
2536
+ * @param {*} data The message to send
2537
+ * @param {Object} [options] Options object
2538
+ * @param {Boolean} [options.binary] Specifies whether `data` is binary or
2539
+ * text
2540
+ * @param {Boolean} [options.compress] Specifies whether or not to compress
2541
+ * `data`
2542
+ * @param {Boolean} [options.fin=true] Specifies whether the fragment is the
2543
+ * last one
2544
+ * @param {Boolean} [options.mask] Specifies whether or not to mask `data`
2545
+ * @param {Function} [cb] Callback which is executed when data is written out
2546
+ * @public
2547
+ */
2548
+ send(data, options, cb) {
2549
+ if (this.readyState === _WebSocket.CONNECTING) {
2550
+ throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2551
+ }
2552
+ if (typeof options === "function") {
2553
+ cb = options;
2554
+ options = {};
2555
+ }
2556
+ if (typeof data === "number") data = data.toString();
2557
+ if (this.readyState !== _WebSocket.OPEN) {
2558
+ sendAfterClose(this, data, cb);
2559
+ return;
2560
+ }
2561
+ const opts = {
2562
+ binary: typeof data !== "string",
2563
+ mask: !this._isServer,
2564
+ compress: true,
2565
+ fin: true,
2566
+ ...options
2567
+ };
2568
+ if (!this._extensions[PerMessageDeflate.extensionName]) {
2569
+ opts.compress = false;
2570
+ }
2571
+ this._sender.send(data || EMPTY_BUFFER, opts, cb);
2572
+ }
2573
+ /**
2574
+ * Forcibly close the connection.
2575
+ *
2576
+ * @public
2577
+ */
2578
+ terminate() {
2579
+ if (this.readyState === _WebSocket.CLOSED) return;
2580
+ if (this.readyState === _WebSocket.CONNECTING) {
2581
+ const msg = "WebSocket was closed before the connection was established";
2582
+ abortHandshake(this, this._req, msg);
2583
+ return;
2584
+ }
2585
+ if (this._socket) {
2586
+ this._readyState = _WebSocket.CLOSING;
2587
+ this._socket.destroy();
2588
+ }
2589
+ }
2590
+ };
2591
+ Object.defineProperty(WebSocket4, "CONNECTING", {
2592
+ enumerable: true,
2593
+ value: readyStates.indexOf("CONNECTING")
2594
+ });
2595
+ Object.defineProperty(WebSocket4.prototype, "CONNECTING", {
2596
+ enumerable: true,
2597
+ value: readyStates.indexOf("CONNECTING")
2598
+ });
2599
+ Object.defineProperty(WebSocket4, "OPEN", {
2600
+ enumerable: true,
2601
+ value: readyStates.indexOf("OPEN")
2602
+ });
2603
+ Object.defineProperty(WebSocket4.prototype, "OPEN", {
2604
+ enumerable: true,
2605
+ value: readyStates.indexOf("OPEN")
2606
+ });
2607
+ Object.defineProperty(WebSocket4, "CLOSING", {
2608
+ enumerable: true,
2609
+ value: readyStates.indexOf("CLOSING")
2610
+ });
2611
+ Object.defineProperty(WebSocket4.prototype, "CLOSING", {
2612
+ enumerable: true,
2613
+ value: readyStates.indexOf("CLOSING")
2614
+ });
2615
+ Object.defineProperty(WebSocket4, "CLOSED", {
2616
+ enumerable: true,
2617
+ value: readyStates.indexOf("CLOSED")
2618
+ });
2619
+ Object.defineProperty(WebSocket4.prototype, "CLOSED", {
2620
+ enumerable: true,
2621
+ value: readyStates.indexOf("CLOSED")
2622
+ });
2623
+ [
2624
+ "binaryType",
2625
+ "bufferedAmount",
2626
+ "extensions",
2627
+ "isPaused",
2628
+ "protocol",
2629
+ "readyState",
2630
+ "url"
2631
+ ].forEach((property) => {
2632
+ Object.defineProperty(WebSocket4.prototype, property, { enumerable: true });
2633
+ });
2634
+ ["open", "error", "close", "message"].forEach((method) => {
2635
+ Object.defineProperty(WebSocket4.prototype, `on${method}`, {
2636
+ enumerable: true,
2637
+ get() {
2638
+ for (const listener of this.listeners(method)) {
2639
+ if (listener[kForOnEventAttribute]) return listener[kListener];
2640
+ }
2641
+ return null;
2642
+ },
2643
+ set(handler) {
2644
+ for (const listener of this.listeners(method)) {
2645
+ if (listener[kForOnEventAttribute]) {
2646
+ this.removeListener(method, listener);
2647
+ break;
2648
+ }
2649
+ }
2650
+ if (typeof handler !== "function") return;
2651
+ this.addEventListener(method, handler, {
2652
+ [kForOnEventAttribute]: true
2653
+ });
2654
+ }
2655
+ });
2656
+ });
2657
+ WebSocket4.prototype.addEventListener = addEventListener;
2658
+ WebSocket4.prototype.removeEventListener = removeEventListener;
2659
+ module.exports = WebSocket4;
2660
+ function initAsClient(websocket, address, protocols, options) {
2661
+ const opts = {
2662
+ allowSynchronousEvents: true,
2663
+ autoPong: true,
2664
+ protocolVersion: protocolVersions[1],
2665
+ maxPayload: 100 * 1024 * 1024,
2666
+ skipUTF8Validation: false,
2667
+ perMessageDeflate: true,
2668
+ followRedirects: false,
2669
+ maxRedirects: 10,
2670
+ ...options,
2671
+ socketPath: void 0,
2672
+ hostname: void 0,
2673
+ protocol: void 0,
2674
+ timeout: void 0,
2675
+ method: "GET",
2676
+ host: void 0,
2677
+ path: void 0,
2678
+ port: void 0
2679
+ };
2680
+ websocket._autoPong = opts.autoPong;
2681
+ if (!protocolVersions.includes(opts.protocolVersion)) {
2682
+ throw new RangeError(
2683
+ `Unsupported protocol version: ${opts.protocolVersion} (supported versions: ${protocolVersions.join(", ")})`
2684
+ );
2685
+ }
2686
+ let parsedUrl;
2687
+ if (address instanceof URL) {
2688
+ parsedUrl = address;
2689
+ } else {
2690
+ try {
2691
+ parsedUrl = new URL(address);
2692
+ } catch (e) {
2693
+ throw new SyntaxError(`Invalid URL: ${address}`);
2694
+ }
2695
+ }
2696
+ if (parsedUrl.protocol === "http:") {
2697
+ parsedUrl.protocol = "ws:";
2698
+ } else if (parsedUrl.protocol === "https:") {
2699
+ parsedUrl.protocol = "wss:";
2700
+ }
2701
+ websocket._url = parsedUrl.href;
2702
+ const isSecure = parsedUrl.protocol === "wss:";
2703
+ const isIpcUrl = parsedUrl.protocol === "ws+unix:";
2704
+ let invalidUrlMessage;
2705
+ if (parsedUrl.protocol !== "ws:" && !isSecure && !isIpcUrl) {
2706
+ invalidUrlMessage = `The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`;
2707
+ } else if (isIpcUrl && !parsedUrl.pathname) {
2708
+ invalidUrlMessage = "The URL's pathname is empty";
2709
+ } else if (parsedUrl.hash) {
2710
+ invalidUrlMessage = "The URL contains a fragment identifier";
2711
+ }
2712
+ if (invalidUrlMessage) {
2713
+ const err = new SyntaxError(invalidUrlMessage);
2714
+ if (websocket._redirects === 0) {
2715
+ throw err;
2716
+ } else {
2717
+ emitErrorAndClose(websocket, err);
2718
+ return;
2719
+ }
2720
+ }
2721
+ const defaultPort = isSecure ? 443 : 80;
2722
+ const key = randomBytes(16).toString("base64");
2723
+ const request = isSecure ? https.request : http.request;
2724
+ const protocolSet = /* @__PURE__ */ new Set();
2725
+ let perMessageDeflate;
2726
+ opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect);
2727
+ opts.defaultPort = opts.defaultPort || defaultPort;
2728
+ opts.port = parsedUrl.port || defaultPort;
2729
+ opts.host = parsedUrl.hostname.startsWith("[") ? parsedUrl.hostname.slice(1, -1) : parsedUrl.hostname;
2730
+ opts.headers = {
2731
+ ...opts.headers,
2732
+ "Sec-WebSocket-Version": opts.protocolVersion,
2733
+ "Sec-WebSocket-Key": key,
2734
+ Connection: "Upgrade",
2735
+ Upgrade: "websocket"
2736
+ };
2737
+ opts.path = parsedUrl.pathname + parsedUrl.search;
2738
+ opts.timeout = opts.handshakeTimeout;
2739
+ if (opts.perMessageDeflate) {
2740
+ perMessageDeflate = new PerMessageDeflate(
2741
+ opts.perMessageDeflate !== true ? opts.perMessageDeflate : {},
2742
+ false,
2743
+ opts.maxPayload
2744
+ );
2745
+ opts.headers["Sec-WebSocket-Extensions"] = format({
2746
+ [PerMessageDeflate.extensionName]: perMessageDeflate.offer()
2747
+ });
2748
+ }
2749
+ if (protocols.length) {
2750
+ for (const protocol of protocols) {
2751
+ if (typeof protocol !== "string" || !subprotocolRegex.test(protocol) || protocolSet.has(protocol)) {
2752
+ throw new SyntaxError(
2753
+ "An invalid or duplicated subprotocol was specified"
2754
+ );
2755
+ }
2756
+ protocolSet.add(protocol);
2757
+ }
2758
+ opts.headers["Sec-WebSocket-Protocol"] = protocols.join(",");
2759
+ }
2760
+ if (opts.origin) {
2761
+ if (opts.protocolVersion < 13) {
2762
+ opts.headers["Sec-WebSocket-Origin"] = opts.origin;
2763
+ } else {
2764
+ opts.headers.Origin = opts.origin;
2765
+ }
2766
+ }
2767
+ if (parsedUrl.username || parsedUrl.password) {
2768
+ opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
2769
+ }
2770
+ if (isIpcUrl) {
2771
+ const parts = opts.path.split(":");
2772
+ opts.socketPath = parts[0];
2773
+ opts.path = parts[1];
2774
+ }
2775
+ let req;
2776
+ if (opts.followRedirects) {
2777
+ if (websocket._redirects === 0) {
2778
+ websocket._originalIpc = isIpcUrl;
2779
+ websocket._originalSecure = isSecure;
2780
+ websocket._originalHostOrSocketPath = isIpcUrl ? opts.socketPath : parsedUrl.host;
2781
+ const headers = options && options.headers;
2782
+ options = { ...options, headers: {} };
2783
+ if (headers) {
2784
+ for (const [key2, value] of Object.entries(headers)) {
2785
+ options.headers[key2.toLowerCase()] = value;
2786
+ }
2787
+ }
2788
+ } else if (websocket.listenerCount("redirect") === 0) {
2789
+ const isSameHost = isIpcUrl ? websocket._originalIpc ? opts.socketPath === websocket._originalHostOrSocketPath : false : websocket._originalIpc ? false : parsedUrl.host === websocket._originalHostOrSocketPath;
2790
+ if (!isSameHost || websocket._originalSecure && !isSecure) {
2791
+ delete opts.headers.authorization;
2792
+ delete opts.headers.cookie;
2793
+ if (!isSameHost) delete opts.headers.host;
2794
+ opts.auth = void 0;
2795
+ }
2796
+ }
2797
+ if (opts.auth && !options.headers.authorization) {
2798
+ options.headers.authorization = "Basic " + Buffer.from(opts.auth).toString("base64");
2799
+ }
2800
+ req = websocket._req = request(opts);
2801
+ if (websocket._redirects) {
2802
+ websocket.emit("redirect", websocket.url, req);
2803
+ }
2804
+ } else {
2805
+ req = websocket._req = request(opts);
2806
+ }
2807
+ if (opts.timeout) {
2808
+ req.on("timeout", () => {
2809
+ abortHandshake(websocket, req, "Opening handshake has timed out");
2810
+ });
2811
+ }
2812
+ req.on("error", (err) => {
2813
+ if (req === null || req[kAborted]) return;
2814
+ req = websocket._req = null;
2815
+ emitErrorAndClose(websocket, err);
2816
+ });
2817
+ req.on("response", (res) => {
2818
+ const location = res.headers.location;
2819
+ const statusCode = res.statusCode;
2820
+ if (location && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
2821
+ if (++websocket._redirects > opts.maxRedirects) {
2822
+ abortHandshake(websocket, req, "Maximum redirects exceeded");
2823
+ return;
2824
+ }
2825
+ req.abort();
2826
+ let addr;
2827
+ try {
2828
+ addr = new URL(location, address);
2829
+ } catch (e) {
2830
+ const err = new SyntaxError(`Invalid URL: ${location}`);
2831
+ emitErrorAndClose(websocket, err);
2832
+ return;
2833
+ }
2834
+ initAsClient(websocket, addr, protocols, options);
2835
+ } else if (!websocket.emit("unexpected-response", req, res)) {
2836
+ abortHandshake(
2837
+ websocket,
2838
+ req,
2839
+ `Unexpected server response: ${res.statusCode}`
2840
+ );
2841
+ }
2842
+ });
2843
+ req.on("upgrade", (res, socket, head) => {
2844
+ websocket.emit("upgrade", res);
2845
+ if (websocket.readyState !== WebSocket4.CONNECTING) return;
2846
+ req = websocket._req = null;
2847
+ const upgrade = res.headers.upgrade;
2848
+ if (upgrade === void 0 || upgrade.toLowerCase() !== "websocket") {
2849
+ abortHandshake(websocket, socket, "Invalid Upgrade header");
2850
+ return;
2851
+ }
2852
+ const digest = createHash("sha1").update(key + GUID).digest("base64");
2853
+ if (res.headers["sec-websocket-accept"] !== digest) {
2854
+ abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
2855
+ return;
2856
+ }
2857
+ const serverProt = res.headers["sec-websocket-protocol"];
2858
+ let protError;
2859
+ if (serverProt !== void 0) {
2860
+ if (!protocolSet.size) {
2861
+ protError = "Server sent a subprotocol but none was requested";
2862
+ } else if (!protocolSet.has(serverProt)) {
2863
+ protError = "Server sent an invalid subprotocol";
2864
+ }
2865
+ } else if (protocolSet.size) {
2866
+ protError = "Server sent no subprotocol";
2867
+ }
2868
+ if (protError) {
2869
+ abortHandshake(websocket, socket, protError);
2870
+ return;
2871
+ }
2872
+ if (serverProt) websocket._protocol = serverProt;
2873
+ const secWebSocketExtensions = res.headers["sec-websocket-extensions"];
2874
+ if (secWebSocketExtensions !== void 0) {
2875
+ if (!perMessageDeflate) {
2876
+ const message = "Server sent a Sec-WebSocket-Extensions header but no extension was requested";
2877
+ abortHandshake(websocket, socket, message);
2878
+ return;
2879
+ }
2880
+ let extensions;
2881
+ try {
2882
+ extensions = parse(secWebSocketExtensions);
2883
+ } catch (err) {
2884
+ const message = "Invalid Sec-WebSocket-Extensions header";
2885
+ abortHandshake(websocket, socket, message);
2886
+ return;
2887
+ }
2888
+ const extensionNames = Object.keys(extensions);
2889
+ if (extensionNames.length !== 1 || extensionNames[0] !== PerMessageDeflate.extensionName) {
2890
+ const message = "Server indicated an extension that was not requested";
2891
+ abortHandshake(websocket, socket, message);
2892
+ return;
2893
+ }
2894
+ try {
2895
+ perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
2896
+ } catch (err) {
2897
+ const message = "Invalid Sec-WebSocket-Extensions header";
2898
+ abortHandshake(websocket, socket, message);
2899
+ return;
2900
+ }
2901
+ websocket._extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
2902
+ }
2903
+ websocket.setSocket(socket, head, {
2904
+ allowSynchronousEvents: opts.allowSynchronousEvents,
2905
+ generateMask: opts.generateMask,
2906
+ maxPayload: opts.maxPayload,
2907
+ skipUTF8Validation: opts.skipUTF8Validation
2908
+ });
2909
+ });
2910
+ if (opts.finishRequest) {
2911
+ opts.finishRequest(req, websocket);
2912
+ } else {
2913
+ req.end();
2914
+ }
2915
+ }
2916
+ function emitErrorAndClose(websocket, err) {
2917
+ websocket._readyState = WebSocket4.CLOSING;
2918
+ websocket._errorEmitted = true;
2919
+ websocket.emit("error", err);
2920
+ websocket.emitClose();
2921
+ }
2922
+ function netConnect(options) {
2923
+ options.path = options.socketPath;
2924
+ return net.connect(options);
2925
+ }
2926
+ function tlsConnect(options) {
2927
+ options.path = void 0;
2928
+ if (!options.servername && options.servername !== "") {
2929
+ options.servername = net.isIP(options.host) ? "" : options.host;
2930
+ }
2931
+ return tls.connect(options);
2932
+ }
2933
+ function abortHandshake(websocket, stream, message) {
2934
+ websocket._readyState = WebSocket4.CLOSING;
2935
+ const err = new Error(message);
2936
+ Error.captureStackTrace(err, abortHandshake);
2937
+ if (stream.setHeader) {
2938
+ stream[kAborted] = true;
2939
+ stream.abort();
2940
+ if (stream.socket && !stream.socket.destroyed) {
2941
+ stream.socket.destroy();
2942
+ }
2943
+ process.nextTick(emitErrorAndClose, websocket, err);
2944
+ } else {
2945
+ stream.destroy(err);
2946
+ stream.once("error", websocket.emit.bind(websocket, "error"));
2947
+ stream.once("close", websocket.emitClose.bind(websocket));
2948
+ }
2949
+ }
2950
+ function sendAfterClose(websocket, data, cb) {
2951
+ if (data) {
2952
+ const length = isBlob(data) ? data.size : toBuffer(data).length;
2953
+ if (websocket._socket) websocket._sender._bufferedBytes += length;
2954
+ else websocket._bufferedAmount += length;
2955
+ }
2956
+ if (cb) {
2957
+ const err = new Error(
2958
+ `WebSocket is not open: readyState ${websocket.readyState} (${readyStates[websocket.readyState]})`
2959
+ );
2960
+ process.nextTick(cb, err);
2961
+ }
2962
+ }
2963
+ function receiverOnConclude(code, reason) {
2964
+ const websocket = this[kWebSocket];
2965
+ websocket._closeFrameReceived = true;
2966
+ websocket._closeMessage = reason;
2967
+ websocket._closeCode = code;
2968
+ if (websocket._socket[kWebSocket] === void 0) return;
2969
+ websocket._socket.removeListener("data", socketOnData);
2970
+ process.nextTick(resume, websocket._socket);
2971
+ if (code === 1005) websocket.close();
2972
+ else websocket.close(code, reason);
2973
+ }
2974
+ function receiverOnDrain() {
2975
+ const websocket = this[kWebSocket];
2976
+ if (!websocket.isPaused) websocket._socket.resume();
2977
+ }
2978
+ function receiverOnError(err) {
2979
+ const websocket = this[kWebSocket];
2980
+ if (websocket._socket[kWebSocket] !== void 0) {
2981
+ websocket._socket.removeListener("data", socketOnData);
2982
+ process.nextTick(resume, websocket._socket);
2983
+ websocket.close(err[kStatusCode]);
2984
+ }
2985
+ if (!websocket._errorEmitted) {
2986
+ websocket._errorEmitted = true;
2987
+ websocket.emit("error", err);
2988
+ }
2989
+ }
2990
+ function receiverOnFinish() {
2991
+ this[kWebSocket].emitClose();
2992
+ }
2993
+ function receiverOnMessage(data, isBinary) {
2994
+ this[kWebSocket].emit("message", data, isBinary);
2995
+ }
2996
+ function receiverOnPing(data) {
2997
+ const websocket = this[kWebSocket];
2998
+ if (websocket._autoPong) websocket.pong(data, !this._isServer, NOOP);
2999
+ websocket.emit("ping", data);
3000
+ }
3001
+ function receiverOnPong(data) {
3002
+ this[kWebSocket].emit("pong", data);
3003
+ }
3004
+ function resume(stream) {
3005
+ stream.resume();
3006
+ }
3007
+ function senderOnError(err) {
3008
+ const websocket = this[kWebSocket];
3009
+ if (websocket.readyState === WebSocket4.CLOSED) return;
3010
+ if (websocket.readyState === WebSocket4.OPEN) {
3011
+ websocket._readyState = WebSocket4.CLOSING;
3012
+ setCloseTimer(websocket);
3013
+ }
3014
+ this._socket.end();
3015
+ if (!websocket._errorEmitted) {
3016
+ websocket._errorEmitted = true;
3017
+ websocket.emit("error", err);
3018
+ }
3019
+ }
3020
+ function setCloseTimer(websocket) {
3021
+ websocket._closeTimer = setTimeout(
3022
+ websocket._socket.destroy.bind(websocket._socket),
3023
+ closeTimeout
3024
+ );
3025
+ }
3026
+ function socketOnClose() {
3027
+ const websocket = this[kWebSocket];
3028
+ this.removeListener("close", socketOnClose);
3029
+ this.removeListener("data", socketOnData);
3030
+ this.removeListener("end", socketOnEnd);
3031
+ websocket._readyState = WebSocket4.CLOSING;
3032
+ let chunk;
3033
+ if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && (chunk = websocket._socket.read()) !== null) {
3034
+ websocket._receiver.write(chunk);
3035
+ }
3036
+ websocket._receiver.end();
3037
+ this[kWebSocket] = void 0;
3038
+ clearTimeout(websocket._closeTimer);
3039
+ if (websocket._receiver._writableState.finished || websocket._receiver._writableState.errorEmitted) {
3040
+ websocket.emitClose();
3041
+ } else {
3042
+ websocket._receiver.on("error", receiverOnFinish);
3043
+ websocket._receiver.on("finish", receiverOnFinish);
3044
+ }
3045
+ }
3046
+ function socketOnData(chunk) {
3047
+ if (!this[kWebSocket]._receiver.write(chunk)) {
3048
+ this.pause();
3049
+ }
3050
+ }
3051
+ function socketOnEnd() {
3052
+ const websocket = this[kWebSocket];
3053
+ websocket._readyState = WebSocket4.CLOSING;
3054
+ websocket._receiver.end();
3055
+ this.end();
3056
+ }
3057
+ function socketOnError() {
3058
+ const websocket = this[kWebSocket];
3059
+ this.removeListener("error", socketOnError);
3060
+ this.on("error", NOOP);
3061
+ if (websocket) {
3062
+ websocket._readyState = WebSocket4.CLOSING;
3063
+ this.destroy();
3064
+ }
3065
+ }
3066
+ }
3067
+ });
3068
+
3069
+ // ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/stream.js
3070
+ var require_stream = __commonJS({
3071
+ "../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/stream.js"(exports, module) {
3072
+ require_websocket();
3073
+ var { Duplex } = __require("stream");
3074
+ function emitClose(stream) {
3075
+ stream.emit("close");
3076
+ }
3077
+ function duplexOnEnd() {
3078
+ if (!this.destroyed && this._writableState.finished) {
3079
+ this.destroy();
3080
+ }
3081
+ }
3082
+ function duplexOnError(err) {
3083
+ this.removeListener("error", duplexOnError);
3084
+ this.destroy();
3085
+ if (this.listenerCount("error") === 0) {
3086
+ this.emit("error", err);
3087
+ }
3088
+ }
3089
+ function createWebSocketStream2(ws, options) {
3090
+ let terminateOnDestroy = true;
3091
+ const duplex = new Duplex({
3092
+ ...options,
3093
+ autoDestroy: false,
3094
+ emitClose: false,
3095
+ objectMode: false,
3096
+ writableObjectMode: false
3097
+ });
3098
+ ws.on("message", function message(msg, isBinary) {
3099
+ const data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
3100
+ if (!duplex.push(data)) ws.pause();
3101
+ });
3102
+ ws.once("error", function error(err) {
3103
+ if (duplex.destroyed) return;
3104
+ terminateOnDestroy = false;
3105
+ duplex.destroy(err);
3106
+ });
3107
+ ws.once("close", function close() {
3108
+ if (duplex.destroyed) return;
3109
+ duplex.push(null);
3110
+ });
3111
+ duplex._destroy = function(err, callback) {
3112
+ if (ws.readyState === ws.CLOSED) {
3113
+ callback(err);
3114
+ process.nextTick(emitClose, duplex);
3115
+ return;
3116
+ }
3117
+ let called = false;
3118
+ ws.once("error", function error(err2) {
3119
+ called = true;
3120
+ callback(err2);
3121
+ });
3122
+ ws.once("close", function close() {
3123
+ if (!called) callback(err);
3124
+ process.nextTick(emitClose, duplex);
3125
+ });
3126
+ if (terminateOnDestroy) ws.terminate();
3127
+ };
3128
+ duplex._final = function(callback) {
3129
+ if (ws.readyState === ws.CONNECTING) {
3130
+ ws.once("open", function open() {
3131
+ duplex._final(callback);
3132
+ });
3133
+ return;
3134
+ }
3135
+ if (ws._socket === null) return;
3136
+ if (ws._socket._writableState.finished) {
3137
+ callback();
3138
+ if (duplex._readableState.endEmitted) duplex.destroy();
3139
+ } else {
3140
+ ws._socket.once("finish", function finish() {
3141
+ callback();
3142
+ });
3143
+ ws.close();
3144
+ }
3145
+ };
3146
+ duplex._read = function() {
3147
+ if (ws.isPaused) ws.resume();
3148
+ };
3149
+ duplex._write = function(chunk, encoding, callback) {
3150
+ if (ws.readyState === ws.CONNECTING) {
3151
+ ws.once("open", function open() {
3152
+ duplex._write(chunk, encoding, callback);
3153
+ });
3154
+ return;
3155
+ }
3156
+ ws.send(chunk, callback);
3157
+ };
3158
+ duplex.on("end", duplexOnEnd);
3159
+ duplex.on("error", duplexOnError);
3160
+ return duplex;
3161
+ }
3162
+ module.exports = createWebSocketStream2;
3163
+ }
3164
+ });
3165
+
3166
+ // ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/subprotocol.js
3167
+ var require_subprotocol = __commonJS({
3168
+ "../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/subprotocol.js"(exports, module) {
3169
+ var { tokenChars } = require_validation();
3170
+ function parse(header) {
3171
+ const protocols = /* @__PURE__ */ new Set();
3172
+ let start = -1;
3173
+ let end = -1;
3174
+ let i = 0;
3175
+ for (i; i < header.length; i++) {
3176
+ const code = header.charCodeAt(i);
3177
+ if (end === -1 && tokenChars[code] === 1) {
3178
+ if (start === -1) start = i;
3179
+ } else if (i !== 0 && (code === 32 || code === 9)) {
3180
+ if (end === -1 && start !== -1) end = i;
3181
+ } else if (code === 44) {
3182
+ if (start === -1) {
3183
+ throw new SyntaxError(`Unexpected character at index ${i}`);
3184
+ }
3185
+ if (end === -1) end = i;
3186
+ const protocol2 = header.slice(start, end);
3187
+ if (protocols.has(protocol2)) {
3188
+ throw new SyntaxError(`The "${protocol2}" subprotocol is duplicated`);
3189
+ }
3190
+ protocols.add(protocol2);
3191
+ start = end = -1;
3192
+ } else {
3193
+ throw new SyntaxError(`Unexpected character at index ${i}`);
3194
+ }
3195
+ }
3196
+ if (start === -1 || end !== -1) {
3197
+ throw new SyntaxError("Unexpected end of input");
3198
+ }
3199
+ const protocol = header.slice(start, i);
3200
+ if (protocols.has(protocol)) {
3201
+ throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
3202
+ }
3203
+ protocols.add(protocol);
3204
+ return protocols;
3205
+ }
3206
+ module.exports = { parse };
3207
+ }
3208
+ });
3209
+
3210
+ // ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/websocket-server.js
3211
+ var require_websocket_server = __commonJS({
3212
+ "../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/websocket-server.js"(exports, module) {
3213
+ var EventEmitter = __require("events");
3214
+ var http = __require("http");
3215
+ var { Duplex } = __require("stream");
3216
+ var { createHash } = __require("crypto");
3217
+ var extension = require_extension();
3218
+ var PerMessageDeflate = require_permessage_deflate();
3219
+ var subprotocol = require_subprotocol();
3220
+ var WebSocket4 = require_websocket();
3221
+ var { GUID, kWebSocket } = require_constants();
3222
+ var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
3223
+ var RUNNING = 0;
3224
+ var CLOSING = 1;
3225
+ var CLOSED = 2;
3226
+ var WebSocketServer2 = class extends EventEmitter {
3227
+ /**
3228
+ * Create a `WebSocketServer` instance.
3229
+ *
3230
+ * @param {Object} options Configuration options
3231
+ * @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
3232
+ * any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
3233
+ * multiple times in the same tick
3234
+ * @param {Boolean} [options.autoPong=true] Specifies whether or not to
3235
+ * automatically send a pong in response to a ping
3236
+ * @param {Number} [options.backlog=511] The maximum length of the queue of
3237
+ * pending connections
3238
+ * @param {Boolean} [options.clientTracking=true] Specifies whether or not to
3239
+ * track clients
3240
+ * @param {Function} [options.handleProtocols] A hook to handle protocols
3241
+ * @param {String} [options.host] The hostname where to bind the server
3242
+ * @param {Number} [options.maxPayload=104857600] The maximum allowed message
3243
+ * size
3244
+ * @param {Boolean} [options.noServer=false] Enable no server mode
3245
+ * @param {String} [options.path] Accept only connections matching this path
3246
+ * @param {(Boolean|Object)} [options.perMessageDeflate=false] Enable/disable
3247
+ * permessage-deflate
3248
+ * @param {Number} [options.port] The port where to bind the server
3249
+ * @param {(http.Server|https.Server)} [options.server] A pre-created HTTP/S
3250
+ * server to use
3251
+ * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
3252
+ * not to skip UTF-8 validation for text and close messages
3253
+ * @param {Function} [options.verifyClient] A hook to reject connections
3254
+ * @param {Function} [options.WebSocket=WebSocket] Specifies the `WebSocket`
3255
+ * class to use. It must be the `WebSocket` class or class that extends it
3256
+ * @param {Function} [callback] A listener for the `listening` event
3257
+ */
3258
+ constructor(options, callback) {
3259
+ super();
3260
+ options = {
3261
+ allowSynchronousEvents: true,
3262
+ autoPong: true,
3263
+ maxPayload: 100 * 1024 * 1024,
3264
+ skipUTF8Validation: false,
3265
+ perMessageDeflate: false,
3266
+ handleProtocols: null,
3267
+ clientTracking: true,
3268
+ verifyClient: null,
3269
+ noServer: false,
3270
+ backlog: null,
3271
+ // use default (511 as implemented in net.js)
3272
+ server: null,
3273
+ host: null,
3274
+ path: null,
3275
+ port: null,
3276
+ WebSocket: WebSocket4,
3277
+ ...options
3278
+ };
3279
+ if (options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer) {
3280
+ throw new TypeError(
3281
+ 'One and only one of the "port", "server", or "noServer" options must be specified'
3282
+ );
3283
+ }
3284
+ if (options.port != null) {
3285
+ this._server = http.createServer((req, res) => {
3286
+ const body = http.STATUS_CODES[426];
3287
+ res.writeHead(426, {
3288
+ "Content-Length": body.length,
3289
+ "Content-Type": "text/plain"
3290
+ });
3291
+ res.end(body);
3292
+ });
3293
+ this._server.listen(
3294
+ options.port,
3295
+ options.host,
3296
+ options.backlog,
3297
+ callback
3298
+ );
3299
+ } else if (options.server) {
3300
+ this._server = options.server;
3301
+ }
3302
+ if (this._server) {
3303
+ const emitConnection = this.emit.bind(this, "connection");
3304
+ this._removeListeners = addListeners(this._server, {
3305
+ listening: this.emit.bind(this, "listening"),
3306
+ error: this.emit.bind(this, "error"),
3307
+ upgrade: (req, socket, head) => {
3308
+ this.handleUpgrade(req, socket, head, emitConnection);
3309
+ }
3310
+ });
3311
+ }
3312
+ if (options.perMessageDeflate === true) options.perMessageDeflate = {};
3313
+ if (options.clientTracking) {
3314
+ this.clients = /* @__PURE__ */ new Set();
3315
+ this._shouldEmitClose = false;
3316
+ }
3317
+ this.options = options;
3318
+ this._state = RUNNING;
3319
+ }
3320
+ /**
3321
+ * Returns the bound address, the address family name, and port of the server
3322
+ * as reported by the operating system if listening on an IP socket.
3323
+ * If the server is listening on a pipe or UNIX domain socket, the name is
3324
+ * returned as a string.
3325
+ *
3326
+ * @return {(Object|String|null)} The address of the server
3327
+ * @public
3328
+ */
3329
+ address() {
3330
+ if (this.options.noServer) {
3331
+ throw new Error('The server is operating in "noServer" mode');
3332
+ }
3333
+ if (!this._server) return null;
3334
+ return this._server.address();
3335
+ }
3336
+ /**
3337
+ * Stop the server from accepting new connections and emit the `'close'` event
3338
+ * when all existing connections are closed.
3339
+ *
3340
+ * @param {Function} [cb] A one-time listener for the `'close'` event
3341
+ * @public
3342
+ */
3343
+ close(cb) {
3344
+ if (this._state === CLOSED) {
3345
+ if (cb) {
3346
+ this.once("close", () => {
3347
+ cb(new Error("The server is not running"));
3348
+ });
3349
+ }
3350
+ process.nextTick(emitClose, this);
3351
+ return;
3352
+ }
3353
+ if (cb) this.once("close", cb);
3354
+ if (this._state === CLOSING) return;
3355
+ this._state = CLOSING;
3356
+ if (this.options.noServer || this.options.server) {
3357
+ if (this._server) {
3358
+ this._removeListeners();
3359
+ this._removeListeners = this._server = null;
3360
+ }
3361
+ if (this.clients) {
3362
+ if (!this.clients.size) {
3363
+ process.nextTick(emitClose, this);
3364
+ } else {
3365
+ this._shouldEmitClose = true;
3366
+ }
3367
+ } else {
3368
+ process.nextTick(emitClose, this);
3369
+ }
3370
+ } else {
3371
+ const server = this._server;
3372
+ this._removeListeners();
3373
+ this._removeListeners = this._server = null;
3374
+ server.close(() => {
3375
+ emitClose(this);
3376
+ });
3377
+ }
3378
+ }
3379
+ /**
3380
+ * See if a given request should be handled by this server instance.
3381
+ *
3382
+ * @param {http.IncomingMessage} req Request object to inspect
3383
+ * @return {Boolean} `true` if the request is valid, else `false`
3384
+ * @public
3385
+ */
3386
+ shouldHandle(req) {
3387
+ if (this.options.path) {
3388
+ const index = req.url.indexOf("?");
3389
+ const pathname = index !== -1 ? req.url.slice(0, index) : req.url;
3390
+ if (pathname !== this.options.path) return false;
3391
+ }
3392
+ return true;
3393
+ }
3394
+ /**
3395
+ * Handle a HTTP Upgrade request.
3396
+ *
3397
+ * @param {http.IncomingMessage} req The request object
3398
+ * @param {Duplex} socket The network socket between the server and client
3399
+ * @param {Buffer} head The first packet of the upgraded stream
3400
+ * @param {Function} cb Callback
3401
+ * @public
3402
+ */
3403
+ handleUpgrade(req, socket, head, cb) {
3404
+ socket.on("error", socketOnError);
3405
+ const key = req.headers["sec-websocket-key"];
3406
+ const upgrade = req.headers.upgrade;
3407
+ const version = +req.headers["sec-websocket-version"];
3408
+ if (req.method !== "GET") {
3409
+ const message = "Invalid HTTP method";
3410
+ abortHandshakeOrEmitwsClientError(this, req, socket, 405, message);
3411
+ return;
3412
+ }
3413
+ if (upgrade === void 0 || upgrade.toLowerCase() !== "websocket") {
3414
+ const message = "Invalid Upgrade header";
3415
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3416
+ return;
3417
+ }
3418
+ if (key === void 0 || !keyRegex.test(key)) {
3419
+ const message = "Missing or invalid Sec-WebSocket-Key header";
3420
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3421
+ return;
3422
+ }
3423
+ if (version !== 13 && version !== 8) {
3424
+ const message = "Missing or invalid Sec-WebSocket-Version header";
3425
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message, {
3426
+ "Sec-WebSocket-Version": "13, 8"
3427
+ });
3428
+ return;
3429
+ }
3430
+ if (!this.shouldHandle(req)) {
3431
+ abortHandshake(socket, 400);
3432
+ return;
3433
+ }
3434
+ const secWebSocketProtocol = req.headers["sec-websocket-protocol"];
3435
+ let protocols = /* @__PURE__ */ new Set();
3436
+ if (secWebSocketProtocol !== void 0) {
3437
+ try {
3438
+ protocols = subprotocol.parse(secWebSocketProtocol);
3439
+ } catch (err) {
3440
+ const message = "Invalid Sec-WebSocket-Protocol header";
3441
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3442
+ return;
3443
+ }
3444
+ }
3445
+ const secWebSocketExtensions = req.headers["sec-websocket-extensions"];
3446
+ const extensions = {};
3447
+ if (this.options.perMessageDeflate && secWebSocketExtensions !== void 0) {
3448
+ const perMessageDeflate = new PerMessageDeflate(
3449
+ this.options.perMessageDeflate,
3450
+ true,
3451
+ this.options.maxPayload
3452
+ );
3453
+ try {
3454
+ const offers = extension.parse(secWebSocketExtensions);
3455
+ if (offers[PerMessageDeflate.extensionName]) {
3456
+ perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
3457
+ extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
3458
+ }
3459
+ } catch (err) {
3460
+ const message = "Invalid or unacceptable Sec-WebSocket-Extensions header";
3461
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3462
+ return;
3463
+ }
3464
+ }
3465
+ if (this.options.verifyClient) {
3466
+ const info = {
3467
+ origin: req.headers[`${version === 8 ? "sec-websocket-origin" : "origin"}`],
3468
+ secure: !!(req.socket.authorized || req.socket.encrypted),
3469
+ req
3470
+ };
3471
+ if (this.options.verifyClient.length === 2) {
3472
+ this.options.verifyClient(info, (verified, code, message, headers) => {
3473
+ if (!verified) {
3474
+ return abortHandshake(socket, code || 401, message, headers);
3475
+ }
3476
+ this.completeUpgrade(
3477
+ extensions,
3478
+ key,
3479
+ protocols,
3480
+ req,
3481
+ socket,
3482
+ head,
3483
+ cb
3484
+ );
3485
+ });
3486
+ return;
3487
+ }
3488
+ if (!this.options.verifyClient(info)) return abortHandshake(socket, 401);
3489
+ }
3490
+ this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
3491
+ }
3492
+ /**
3493
+ * Upgrade the connection to WebSocket.
3494
+ *
3495
+ * @param {Object} extensions The accepted extensions
3496
+ * @param {String} key The value of the `Sec-WebSocket-Key` header
3497
+ * @param {Set} protocols The subprotocols
3498
+ * @param {http.IncomingMessage} req The request object
3499
+ * @param {Duplex} socket The network socket between the server and client
3500
+ * @param {Buffer} head The first packet of the upgraded stream
3501
+ * @param {Function} cb Callback
3502
+ * @throws {Error} If called more than once with the same socket
3503
+ * @private
3504
+ */
3505
+ completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
3506
+ if (!socket.readable || !socket.writable) return socket.destroy();
3507
+ if (socket[kWebSocket]) {
3508
+ throw new Error(
3509
+ "server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration"
3510
+ );
3511
+ }
3512
+ if (this._state > RUNNING) return abortHandshake(socket, 503);
3513
+ const digest = createHash("sha1").update(key + GUID).digest("base64");
3514
+ const headers = [
3515
+ "HTTP/1.1 101 Switching Protocols",
3516
+ "Upgrade: websocket",
3517
+ "Connection: Upgrade",
3518
+ `Sec-WebSocket-Accept: ${digest}`
3519
+ ];
3520
+ const ws = new this.options.WebSocket(null, void 0, this.options);
3521
+ if (protocols.size) {
3522
+ const protocol = this.options.handleProtocols ? this.options.handleProtocols(protocols, req) : protocols.values().next().value;
3523
+ if (protocol) {
3524
+ headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
3525
+ ws._protocol = protocol;
3526
+ }
3527
+ }
3528
+ if (extensions[PerMessageDeflate.extensionName]) {
3529
+ const params = extensions[PerMessageDeflate.extensionName].params;
3530
+ const value = extension.format({
3531
+ [PerMessageDeflate.extensionName]: [params]
3532
+ });
3533
+ headers.push(`Sec-WebSocket-Extensions: ${value}`);
3534
+ ws._extensions = extensions;
3535
+ }
3536
+ this.emit("headers", headers, req);
3537
+ socket.write(headers.concat("\r\n").join("\r\n"));
3538
+ socket.removeListener("error", socketOnError);
3539
+ ws.setSocket(socket, head, {
3540
+ allowSynchronousEvents: this.options.allowSynchronousEvents,
3541
+ maxPayload: this.options.maxPayload,
3542
+ skipUTF8Validation: this.options.skipUTF8Validation
3543
+ });
3544
+ if (this.clients) {
3545
+ this.clients.add(ws);
3546
+ ws.on("close", () => {
3547
+ this.clients.delete(ws);
3548
+ if (this._shouldEmitClose && !this.clients.size) {
3549
+ process.nextTick(emitClose, this);
3550
+ }
3551
+ });
3552
+ }
3553
+ cb(ws, req);
3554
+ }
3555
+ };
3556
+ module.exports = WebSocketServer2;
3557
+ function addListeners(server, map) {
3558
+ for (const event of Object.keys(map)) server.on(event, map[event]);
3559
+ return function removeListeners() {
3560
+ for (const event of Object.keys(map)) {
3561
+ server.removeListener(event, map[event]);
3562
+ }
3563
+ };
3564
+ }
3565
+ function emitClose(server) {
3566
+ server._state = CLOSED;
3567
+ server.emit("close");
3568
+ }
3569
+ function socketOnError() {
3570
+ this.destroy();
3571
+ }
3572
+ function abortHandshake(socket, code, message, headers) {
3573
+ message = message || http.STATUS_CODES[code];
3574
+ headers = {
3575
+ Connection: "close",
3576
+ "Content-Type": "text/html",
3577
+ "Content-Length": Buffer.byteLength(message),
3578
+ ...headers
3579
+ };
3580
+ socket.once("finish", socket.destroy);
3581
+ socket.end(
3582
+ `HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r
3583
+ ` + Object.keys(headers).map((h) => `${h}: ${headers[h]}`).join("\r\n") + "\r\n\r\n" + message
3584
+ );
3585
+ }
3586
+ function abortHandshakeOrEmitwsClientError(server, req, socket, code, message, headers) {
3587
+ if (server.listenerCount("wsClientError")) {
3588
+ const err = new Error(message);
3589
+ Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
3590
+ server.emit("wsClientError", err, socket, req);
3591
+ } else {
3592
+ abortHandshake(socket, code, message, headers);
3593
+ }
3594
+ }
3595
+ }
3596
+ });
3597
+
3598
+ // ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/wrapper.mjs
3599
+ var wrapper_exports = {};
3600
+ __export(wrapper_exports, {
3601
+ Receiver: () => import_receiver.default,
3602
+ Sender: () => import_sender.default,
3603
+ WebSocket: () => import_websocket.default,
3604
+ WebSocketServer: () => import_websocket_server.default,
3605
+ createWebSocketStream: () => import_stream.default,
3606
+ default: () => wrapper_default
3607
+ });
3608
+ var import_stream = __toESM(require_stream(), 1);
3609
+ var import_receiver = __toESM(require_receiver(), 1);
3610
+ var import_sender = __toESM(require_sender(), 1);
3611
+ var import_websocket = __toESM(require_websocket(), 1);
3612
+ var import_websocket_server = __toESM(require_websocket_server(), 1);
3613
+ var wrapper_default = import_websocket.default;
3614
+
3615
+ // ../../node_modules/.pnpm/isows@1.0.7_ws@8.18.3/node_modules/isows/_esm/utils.js
3616
+ function getNativeWebSocket() {
3617
+ if (typeof WebSocket !== "undefined")
3618
+ return WebSocket;
3619
+ if (typeof global.WebSocket !== "undefined")
3620
+ return global.WebSocket;
3621
+ if (typeof window.WebSocket !== "undefined")
3622
+ return window.WebSocket;
3623
+ if (typeof self.WebSocket !== "undefined")
3624
+ return self.WebSocket;
3625
+ throw new Error("`WebSocket` is not supported in this environment");
3626
+ }
3627
+
3628
+ // ../../node_modules/.pnpm/isows@1.0.7_ws@8.18.3/node_modules/isows/_esm/index.js
3629
+ var WebSocket3 = (() => {
3630
+ try {
3631
+ return getNativeWebSocket();
3632
+ } catch {
3633
+ if (import_websocket.default)
3634
+ return import_websocket.default;
3635
+ return wrapper_exports;
3636
+ }
3637
+ })();
3638
+
3639
+ export { WebSocket3 as WebSocket };
3640
+ //# sourceMappingURL=_esm-32O7VXQT.js.map
3641
+ //# sourceMappingURL=_esm-32O7VXQT.js.map