@1delta/margin-fetcher 0.0.45 → 0.0.47

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