serverless-spy 0.0.8 → 0.0.11

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 (352) hide show
  1. package/.jsii +17 -14
  2. package/cli/cli.ts +1 -1
  3. package/cli/node_modules/ws/LICENSE +19 -0
  4. package/cli/node_modules/ws/README.md +495 -0
  5. package/cli/node_modules/ws/browser.js +8 -0
  6. package/cli/node_modules/ws/index.js +13 -0
  7. package/cli/node_modules/ws/lib/buffer-util.js +127 -0
  8. package/cli/node_modules/ws/lib/constants.js +12 -0
  9. package/cli/node_modules/ws/lib/event-target.js +266 -0
  10. package/cli/node_modules/ws/lib/extension.js +203 -0
  11. package/cli/node_modules/ws/lib/limiter.js +55 -0
  12. package/cli/node_modules/ws/lib/permessage-deflate.js +511 -0
  13. package/cli/node_modules/ws/lib/receiver.js +618 -0
  14. package/cli/node_modules/ws/lib/sender.js +478 -0
  15. package/cli/node_modules/ws/lib/stream.js +159 -0
  16. package/cli/node_modules/ws/lib/subprotocol.js +62 -0
  17. package/cli/node_modules/ws/lib/validation.js +125 -0
  18. package/cli/node_modules/ws/lib/websocket-server.js +535 -0
  19. package/cli/node_modules/ws/lib/websocket.js +1305 -0
  20. package/cli/node_modules/ws/package.json +61 -0
  21. package/cli/node_modules/ws/wrapper.mjs +8 -0
  22. package/cli/ws.ts +1 -1
  23. package/lib/cjs/cli/cli.d.ts +1 -0
  24. package/lib/cjs/cli/cli.js +87 -0
  25. package/lib/cjs/cli/ws.d.ts +1 -0
  26. package/lib/cjs/cli/ws.js +68 -0
  27. package/lib/cjs/common/getWebSocketUrl.d.ts +2 -0
  28. package/lib/cjs/common/getWebSocketUrl.js +57 -0
  29. package/lib/cjs/index.d.ts +2 -0
  30. package/lib/cjs/index.js +19 -0
  31. package/lib/cjs/listener/PrettifyForDisplay.d.ts +3 -0
  32. package/lib/cjs/listener/PrettifyForDisplay.js +3 -0
  33. package/lib/cjs/listener/RecursivePartial.d.ts +4 -0
  34. package/lib/cjs/listener/RecursivePartial.js +3 -0
  35. package/lib/cjs/listener/SpyHandlers.ts.d.ts +109 -0
  36. package/lib/cjs/listener/SpyHandlers.ts.js +3 -0
  37. package/lib/cjs/listener/SpyListener.d.ts +40 -0
  38. package/lib/cjs/listener/SpyListener.js +3 -0
  39. package/lib/cjs/listener/createServerlessSpyListener.d.ts +13 -0
  40. package/lib/cjs/listener/createServerlessSpyListener.js +167 -0
  41. package/lib/cjs/listener/index.d.ts +2 -0
  42. package/lib/cjs/listener/index.js +19 -0
  43. package/lib/cjs/listener/matchers.d.ts +0 -0
  44. package/lib/cjs/listener/matchers.js +55 -0
  45. package/lib/cjs/listener/setup.d.ts +0 -0
  46. package/lib/cjs/listener/setup.js +21 -0
  47. package/lib/{ServerlessSpy.d.ts → cjs/src/ServerlessSpy.d.ts} +0 -0
  48. package/lib/{ServerlessSpy.js → cjs/src/ServerlessSpy.js} +1 -1
  49. package/lib/{index.d.ts → cjs/src/index.d.ts} +0 -0
  50. package/lib/{index.js → cjs/src/index.js} +0 -0
  51. package/lib/mjs/cli/cli.d.ts +1 -0
  52. package/lib/mjs/cli/cli.js +85 -0
  53. package/lib/mjs/cli/ws.d.ts +1 -0
  54. package/lib/mjs/cli/ws.js +66 -0
  55. package/lib/mjs/common/getWebSocketUrl.d.ts +2 -0
  56. package/lib/mjs/common/getWebSocketUrl.js +53 -0
  57. package/lib/mjs/index.d.ts +2 -0
  58. package/lib/mjs/index.js +3 -0
  59. package/lib/mjs/listener/PrettifyForDisplay.d.ts +3 -0
  60. package/lib/mjs/listener/PrettifyForDisplay.js +2 -0
  61. package/lib/mjs/listener/RecursivePartial.d.ts +4 -0
  62. package/lib/mjs/listener/RecursivePartial.js +2 -0
  63. package/lib/mjs/listener/SpyHandlers.ts.d.ts +109 -0
  64. package/lib/mjs/listener/SpyHandlers.ts.js +2 -0
  65. package/lib/mjs/listener/SpyListener.d.ts +40 -0
  66. package/lib/mjs/listener/SpyListener.js +2 -0
  67. package/lib/mjs/listener/createServerlessSpyListener.d.ts +13 -0
  68. package/lib/mjs/listener/createServerlessSpyListener.js +163 -0
  69. package/lib/mjs/listener/index.d.ts +2 -0
  70. package/lib/mjs/listener/index.js +3 -0
  71. package/lib/mjs/listener/matchers.d.ts +0 -0
  72. package/lib/mjs/listener/matchers.js +55 -0
  73. package/lib/mjs/listener/setup.d.ts +0 -0
  74. package/lib/mjs/listener/setup.js +21 -0
  75. package/lib/mjs/src/ServerlessSpy.d.ts +27 -0
  76. package/lib/mjs/src/ServerlessSpy.js +293 -0
  77. package/lib/mjs/src/index.d.ts +1 -0
  78. package/lib/mjs/src/index.js +2 -0
  79. package/listener/node_modules/ws/LICENSE +19 -0
  80. package/listener/node_modules/ws/README.md +495 -0
  81. package/listener/node_modules/ws/browser.js +8 -0
  82. package/listener/node_modules/ws/index.js +13 -0
  83. package/listener/node_modules/ws/lib/buffer-util.js +127 -0
  84. package/listener/node_modules/ws/lib/constants.js +12 -0
  85. package/listener/node_modules/ws/lib/event-target.js +266 -0
  86. package/listener/node_modules/ws/lib/extension.js +203 -0
  87. package/listener/node_modules/ws/lib/limiter.js +55 -0
  88. package/listener/node_modules/ws/lib/permessage-deflate.js +511 -0
  89. package/listener/node_modules/ws/lib/receiver.js +618 -0
  90. package/listener/node_modules/ws/lib/sender.js +478 -0
  91. package/listener/node_modules/ws/lib/stream.js +159 -0
  92. package/listener/node_modules/ws/lib/subprotocol.js +62 -0
  93. package/listener/node_modules/ws/lib/validation.js +125 -0
  94. package/listener/node_modules/ws/lib/websocket-server.js +535 -0
  95. package/listener/node_modules/ws/lib/websocket.js +1305 -0
  96. package/listener/node_modules/ws/package.json +61 -0
  97. package/listener/node_modules/ws/wrapper.mjs +8 -0
  98. package/node_modules/@aws-crypto/crc32/node_modules/tslib/package.json +1 -5
  99. package/node_modules/@aws-crypto/crc32/package.json +1 -5
  100. package/node_modules/@aws-crypto/crc32c/node_modules/tslib/package.json +1 -5
  101. package/node_modules/@aws-crypto/crc32c/package.json +1 -5
  102. package/node_modules/@aws-crypto/ie11-detection/node_modules/tslib/package.json +1 -5
  103. package/node_modules/@aws-crypto/ie11-detection/package.json +1 -5
  104. package/node_modules/@aws-crypto/sha1-browser/node_modules/tslib/package.json +1 -5
  105. package/node_modules/@aws-crypto/sha1-browser/package.json +1 -5
  106. package/node_modules/@aws-crypto/sha256-browser/node_modules/tslib/package.json +1 -5
  107. package/node_modules/@aws-crypto/sha256-browser/package.json +1 -5
  108. package/node_modules/@aws-crypto/sha256-js/node_modules/tslib/package.json +1 -5
  109. package/node_modules/@aws-crypto/sha256-js/package.json +1 -5
  110. package/node_modules/@aws-crypto/supports-web-crypto/node_modules/tslib/package.json +1 -5
  111. package/node_modules/@aws-crypto/supports-web-crypto/package.json +1 -5
  112. package/node_modules/@aws-crypto/util/node_modules/tslib/package.json +1 -5
  113. package/node_modules/@aws-crypto/util/package.json +1 -5
  114. package/node_modules/@aws-sdk/abort-controller/package.json +1 -5
  115. package/node_modules/@aws-sdk/chunked-blob-reader/package.json +1 -5
  116. package/node_modules/@aws-sdk/chunked-blob-reader-native/package.json +1 -5
  117. package/node_modules/@aws-sdk/client-apigatewaymanagementapi/package.json +1 -5
  118. package/node_modules/@aws-sdk/client-cognito-identity/CHANGELOG.md +8 -0
  119. package/node_modules/@aws-sdk/client-cognito-identity/package.json +3 -7
  120. package/node_modules/@aws-sdk/client-dynamodb/package.json +1 -5
  121. package/node_modules/@aws-sdk/client-eventbridge/package.json +1 -5
  122. package/node_modules/@aws-sdk/client-lambda/package.json +1 -5
  123. package/node_modules/@aws-sdk/client-s3/CHANGELOG.md +8 -0
  124. package/node_modules/@aws-sdk/client-s3/node_modules/entities/package.json +1 -5
  125. package/node_modules/@aws-sdk/client-s3/package.json +2 -6
  126. package/node_modules/@aws-sdk/client-sns/node_modules/entities/package.json +1 -5
  127. package/node_modules/@aws-sdk/client-sns/package.json +1 -5
  128. package/node_modules/@aws-sdk/client-sqs/node_modules/entities/package.json +1 -5
  129. package/node_modules/@aws-sdk/client-sqs/package.json +1 -5
  130. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/abort-controller/package.json +1 -5
  131. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/client-sso/package.json +1 -5
  132. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/client-sts/package.json +1 -5
  133. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/config-resolver/package.json +1 -5
  134. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/credential-provider-env/package.json +1 -5
  135. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/credential-provider-imds/package.json +1 -5
  136. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/credential-provider-ini/package.json +1 -5
  137. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/credential-provider-node/package.json +1 -5
  138. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/credential-provider-process/package.json +1 -5
  139. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/credential-provider-sso/package.json +1 -5
  140. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/credential-provider-web-identity/package.json +1 -5
  141. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/fetch-http-handler/package.json +1 -5
  142. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/hash-node/package.json +1 -5
  143. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/invalid-dependency/package.json +1 -5
  144. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/is-array-buffer/package.json +1 -5
  145. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/middleware-content-length/package.json +1 -5
  146. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/middleware-host-header/package.json +1 -5
  147. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/middleware-logger/package.json +1 -5
  148. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/middleware-retry/package.json +1 -5
  149. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/middleware-sdk-sts/package.json +1 -5
  150. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/middleware-serde/package.json +1 -5
  151. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/middleware-signing/package.json +1 -5
  152. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/middleware-stack/package.json +1 -5
  153. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/middleware-user-agent/package.json +1 -5
  154. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/node-config-provider/package.json +1 -5
  155. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/node-http-handler/package.json +1 -5
  156. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/property-provider/package.json +1 -5
  157. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/protocol-http/package.json +1 -5
  158. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/querystring-builder/package.json +1 -5
  159. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/querystring-parser/package.json +1 -5
  160. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/service-error-classification/package.json +1 -5
  161. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/shared-ini-file-loader/package.json +1 -5
  162. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/signature-v4/package.json +1 -5
  163. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/smithy-client/package.json +1 -5
  164. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/types/package.json +1 -5
  165. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/url-parser/package.json +1 -5
  166. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-base64-browser/package.json +1 -5
  167. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-base64-node/package.json +1 -5
  168. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-body-length-browser/package.json +1 -5
  169. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-body-length-node/package.json +1 -5
  170. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-buffer-from/package.json +1 -5
  171. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-config-provider/package.json +1 -5
  172. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-hex-encoding/package.json +1 -5
  173. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-uri-escape/package.json +1 -5
  174. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-user-agent-browser/package.json +1 -5
  175. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-user-agent-node/package.json +1 -5
  176. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-utf8-browser/package.json +1 -5
  177. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-utf8-node/package.json +1 -5
  178. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-waiter/package.json +1 -5
  179. package/node_modules/@aws-sdk/client-ssm/node_modules/entities/package.json +1 -5
  180. package/node_modules/@aws-sdk/client-ssm/package.json +1 -5
  181. package/node_modules/@aws-sdk/client-sso/package.json +1 -5
  182. package/node_modules/@aws-sdk/client-sts/node_modules/entities/package.json +1 -5
  183. package/node_modules/@aws-sdk/client-sts/package.json +1 -5
  184. package/node_modules/@aws-sdk/config-resolver/package.json +1 -5
  185. package/node_modules/@aws-sdk/credential-provider-cognito-identity/CHANGELOG.md +8 -0
  186. package/node_modules/@aws-sdk/credential-provider-cognito-identity/package.json +3 -7
  187. package/node_modules/@aws-sdk/credential-provider-env/package.json +1 -5
  188. package/node_modules/@aws-sdk/credential-provider-imds/package.json +1 -5
  189. package/node_modules/@aws-sdk/credential-provider-ini/package.json +1 -5
  190. package/node_modules/@aws-sdk/credential-provider-node/package.json +1 -5
  191. package/node_modules/@aws-sdk/credential-provider-process/package.json +1 -5
  192. package/node_modules/@aws-sdk/credential-provider-sso/package.json +1 -5
  193. package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +1 -5
  194. package/node_modules/@aws-sdk/credential-providers/CHANGELOG.md +8 -0
  195. package/node_modules/@aws-sdk/credential-providers/package.json +4 -8
  196. package/node_modules/@aws-sdk/endpoint-cache/package.json +1 -5
  197. package/node_modules/@aws-sdk/eventstream-codec/package.json +1 -5
  198. package/node_modules/@aws-sdk/eventstream-serde-browser/package.json +1 -5
  199. package/node_modules/@aws-sdk/eventstream-serde-config-resolver/package.json +1 -5
  200. package/node_modules/@aws-sdk/eventstream-serde-node/package.json +1 -5
  201. package/node_modules/@aws-sdk/eventstream-serde-universal/package.json +1 -5
  202. package/node_modules/@aws-sdk/fetch-http-handler/package.json +1 -5
  203. package/node_modules/@aws-sdk/hash-blob-browser/package.json +1 -5
  204. package/node_modules/@aws-sdk/hash-node/package.json +1 -5
  205. package/node_modules/@aws-sdk/hash-stream-node/package.json +1 -5
  206. package/node_modules/@aws-sdk/invalid-dependency/package.json +1 -5
  207. package/node_modules/@aws-sdk/is-array-buffer/package.json +1 -5
  208. package/node_modules/@aws-sdk/lib-dynamodb/package.json +1 -5
  209. package/node_modules/@aws-sdk/md5-js/package.json +1 -5
  210. package/node_modules/@aws-sdk/middleware-bucket-endpoint/package.json +1 -5
  211. package/node_modules/@aws-sdk/middleware-content-length/package.json +1 -5
  212. package/node_modules/@aws-sdk/middleware-endpoint-discovery/package.json +1 -5
  213. package/node_modules/@aws-sdk/middleware-expect-continue/package.json +1 -5
  214. package/node_modules/@aws-sdk/middleware-flexible-checksums/package.json +1 -5
  215. package/node_modules/@aws-sdk/middleware-host-header/package.json +1 -5
  216. package/node_modules/@aws-sdk/middleware-location-constraint/package.json +1 -5
  217. package/node_modules/@aws-sdk/middleware-logger/package.json +1 -5
  218. package/node_modules/@aws-sdk/middleware-recursion-detection/package.json +1 -5
  219. package/node_modules/@aws-sdk/middleware-retry/package.json +1 -5
  220. package/node_modules/@aws-sdk/middleware-sdk-eventbridge/package.json +1 -5
  221. package/node_modules/@aws-sdk/middleware-sdk-s3/package.json +1 -5
  222. package/node_modules/@aws-sdk/middleware-sdk-sqs/package.json +1 -5
  223. package/node_modules/@aws-sdk/middleware-sdk-sts/package.json +1 -5
  224. package/node_modules/@aws-sdk/middleware-serde/package.json +1 -5
  225. package/node_modules/@aws-sdk/middleware-signing/package.json +1 -5
  226. package/node_modules/@aws-sdk/middleware-ssec/package.json +1 -5
  227. package/node_modules/@aws-sdk/middleware-stack/package.json +1 -5
  228. package/node_modules/@aws-sdk/middleware-user-agent/package.json +1 -5
  229. package/node_modules/@aws-sdk/node-config-provider/package.json +1 -5
  230. package/node_modules/@aws-sdk/node-http-handler/package.json +1 -5
  231. package/node_modules/@aws-sdk/property-provider/package.json +1 -5
  232. package/node_modules/@aws-sdk/protocol-http/package.json +1 -5
  233. package/node_modules/@aws-sdk/querystring-builder/package.json +1 -5
  234. package/node_modules/@aws-sdk/querystring-parser/package.json +1 -5
  235. package/node_modules/@aws-sdk/service-error-classification/package.json +1 -5
  236. package/node_modules/@aws-sdk/shared-ini-file-loader/package.json +1 -5
  237. package/node_modules/@aws-sdk/signature-v4/package.json +1 -5
  238. package/node_modules/@aws-sdk/signature-v4-multi-region/package.json +1 -5
  239. package/node_modules/@aws-sdk/smithy-client/package.json +1 -5
  240. package/node_modules/@aws-sdk/types/package.json +1 -5
  241. package/node_modules/@aws-sdk/url-parser/package.json +1 -5
  242. package/node_modules/@aws-sdk/util-arn-parser/package.json +1 -5
  243. package/node_modules/@aws-sdk/util-base64-browser/package.json +1 -5
  244. package/node_modules/@aws-sdk/util-base64-node/package.json +1 -5
  245. package/node_modules/@aws-sdk/util-body-length-browser/package.json +1 -5
  246. package/node_modules/@aws-sdk/util-body-length-node/package.json +1 -5
  247. package/node_modules/@aws-sdk/util-buffer-from/package.json +1 -5
  248. package/node_modules/@aws-sdk/util-config-provider/package.json +1 -5
  249. package/node_modules/@aws-sdk/util-credentials/node_modules/@aws-sdk/shared-ini-file-loader/package.json +1 -5
  250. package/node_modules/@aws-sdk/util-credentials/package.json +1 -5
  251. package/node_modules/@aws-sdk/util-defaults-mode-browser/package.json +1 -5
  252. package/node_modules/@aws-sdk/util-defaults-mode-node/package.json +1 -5
  253. package/node_modules/@aws-sdk/util-dynamodb/package.json +1 -5
  254. package/node_modules/@aws-sdk/util-hex-encoding/package.json +1 -5
  255. package/node_modules/@aws-sdk/util-locate-window/package.json +1 -5
  256. package/node_modules/@aws-sdk/util-middleware/package.json +1 -5
  257. package/node_modules/@aws-sdk/util-stream-browser/package.json +1 -5
  258. package/node_modules/@aws-sdk/util-stream-node/package.json +1 -5
  259. package/node_modules/@aws-sdk/util-uri-escape/package.json +1 -5
  260. package/node_modules/@aws-sdk/util-user-agent-browser/package.json +1 -5
  261. package/node_modules/@aws-sdk/util-user-agent-node/package.json +1 -5
  262. package/node_modules/@aws-sdk/util-utf8-browser/package.json +1 -5
  263. package/node_modules/@aws-sdk/util-utf8-node/package.json +1 -5
  264. package/node_modules/@aws-sdk/util-waiter/package.json +1 -5
  265. package/node_modules/@aws-sdk/xml-builder/package.json +1 -5
  266. package/node_modules/@graphql-tools/merge/package.json +0 -4
  267. package/node_modules/@graphql-tools/schema/package.json +0 -4
  268. package/node_modules/@graphql-tools/utils/package.json +0 -4
  269. package/node_modules/@serverless-stack/node/.turbo/turbo-build.log +1 -1
  270. package/node_modules/@serverless-stack/node/CHANGELOG.md +2 -0
  271. package/node_modules/@serverless-stack/node/package.json +2 -6
  272. package/node_modules/@tsconfig/node14/package.json +1 -5
  273. package/node_modules/available-typed-arrays/package.json +1 -5
  274. package/node_modules/aws-jwt-verify/package.json +1 -5
  275. package/node_modules/aws-lambda/node_modules/argparse/package.json +1 -5
  276. package/node_modules/aws-lambda/node_modules/commander/package.json +1 -5
  277. package/node_modules/aws-lambda/node_modules/js-yaml/package.json +1 -5
  278. package/node_modules/aws-lambda/package.json +1 -5
  279. package/node_modules/aws-sdk/node_modules/uuid/package.json +1 -5
  280. package/node_modules/aws-sdk/package.json +0 -4
  281. package/node_modules/aws4/package.json +1 -5
  282. package/node_modules/base64-js/package.json +1 -5
  283. package/node_modules/bowser/package.json +1 -5
  284. package/node_modules/buffer/package.json +1 -5
  285. package/node_modules/call-bind/package.json +1 -5
  286. package/node_modules/define-properties/package.json +1 -5
  287. package/node_modules/es-abstract/package.json +1 -5
  288. package/node_modules/es-to-primitive/package.json +1 -5
  289. package/node_modules/esprima/package.json +1 -5
  290. package/node_modules/events/package.json +0 -4
  291. package/node_modules/fast-xml-parser/package.json +1 -5
  292. package/node_modules/for-each/package.json +1 -5
  293. package/node_modules/function-bind/package.json +1 -5
  294. package/node_modules/function.prototype.name/package.json +1 -5
  295. package/node_modules/functions-have-names/package.json +1 -5
  296. package/node_modules/get-intrinsic/package.json +1 -5
  297. package/node_modules/get-symbol-description/package.json +1 -5
  298. package/node_modules/glob-to-regexp/package.json +1 -5
  299. package/node_modules/graceful-fs/package.json +1 -5
  300. package/node_modules/graphql/package.json +1 -5
  301. package/node_modules/graphql-helix/package.json +1 -5
  302. package/node_modules/has/package.json +1 -5
  303. package/node_modules/has-bigints/package.json +1 -5
  304. package/node_modules/has-property-descriptors/package.json +1 -5
  305. package/node_modules/has-symbols/package.json +1 -5
  306. package/node_modules/has-tostringtag/package.json +1 -5
  307. package/node_modules/ieee754/package.json +1 -5
  308. package/node_modules/inherits/package.json +1 -5
  309. package/node_modules/internal-slot/package.json +1 -5
  310. package/node_modules/is-arguments/package.json +1 -5
  311. package/node_modules/is-bigint/package.json +1 -5
  312. package/node_modules/is-boolean-object/package.json +1 -5
  313. package/node_modules/is-callable/package.json +1 -5
  314. package/node_modules/is-date-object/package.json +1 -5
  315. package/node_modules/is-generator-function/package.json +1 -5
  316. package/node_modules/is-negative-zero/package.json +1 -5
  317. package/node_modules/is-number-object/package.json +1 -5
  318. package/node_modules/is-regex/package.json +1 -5
  319. package/node_modules/is-shared-array-buffer/package.json +1 -5
  320. package/node_modules/is-string/package.json +1 -5
  321. package/node_modules/is-symbol/package.json +1 -5
  322. package/node_modules/is-typed-array/package.json +1 -5
  323. package/node_modules/is-weakref/package.json +1 -5
  324. package/node_modules/isarray/package.json +1 -5
  325. package/node_modules/jmespath/package.json +1 -5
  326. package/node_modules/mnemonist/package.json +1 -5
  327. package/node_modules/object-inspect/package.json +1 -5
  328. package/node_modules/object-keys/package.json +1 -5
  329. package/node_modules/object.assign/package.json +1 -5
  330. package/node_modules/obliterator/package.json +1 -5
  331. package/node_modules/querystring/package.json +1 -5
  332. package/node_modules/regexp.prototype.flags/package.json +1 -5
  333. package/node_modules/safe-buffer/package.json +1 -5
  334. package/node_modules/sax/package.json +1 -5
  335. package/node_modules/side-channel/package.json +1 -5
  336. package/node_modules/sprintf-js/package.json +1 -5
  337. package/node_modules/string.prototype.trimend/package.json +1 -5
  338. package/node_modules/string.prototype.trimstart/package.json +1 -5
  339. package/node_modules/tslib/package.json +1 -5
  340. package/node_modules/unbox-primitive/package.json +1 -5
  341. package/node_modules/url/node_modules/punycode/package.json +1 -5
  342. package/node_modules/url/package.json +1 -5
  343. package/node_modules/util/package.json +1 -5
  344. package/node_modules/uuid/package.json +1 -5
  345. package/node_modules/value-or-promise/package.json +1 -5
  346. package/node_modules/watchpack/package.json +1 -5
  347. package/node_modules/which-boxed-primitive/package.json +1 -5
  348. package/node_modules/which-typed-array/package.json +1 -5
  349. package/node_modules/xml2js/node_modules/xmlbuilder/package.json +1 -5
  350. package/node_modules/xml2js/package.json +1 -5
  351. package/package.json +35 -27
  352. package/tsconfig.npm.json +50 -0
@@ -0,0 +1,495 @@
1
+ # ws: a Node.js WebSocket library
2
+
3
+ [![Version npm](https://img.shields.io/npm/v/ws.svg?logo=npm)](https://www.npmjs.com/package/ws)
4
+ [![CI](https://img.shields.io/github/workflow/status/websockets/ws/CI/master?label=CI&logo=github)](https://github.com/websockets/ws/actions?query=workflow%3ACI+branch%3Amaster)
5
+ [![Coverage Status](https://img.shields.io/coveralls/websockets/ws/master.svg?logo=coveralls)](https://coveralls.io/github/websockets/ws)
6
+
7
+ ws is a simple to use, blazing fast, and thoroughly tested WebSocket client and
8
+ server implementation.
9
+
10
+ Passes the quite extensive Autobahn test suite: [server][server-report],
11
+ [client][client-report].
12
+
13
+ **Note**: This module does not work in the browser. The client in the docs is a
14
+ reference to a back end with the role of a client in the WebSocket
15
+ communication. Browser clients must use the native
16
+ [`WebSocket`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket)
17
+ object. To make the same code work seamlessly on Node.js and the browser, you
18
+ can use one of the many wrappers available on npm, like
19
+ [isomorphic-ws](https://github.com/heineiuo/isomorphic-ws).
20
+
21
+ ## Table of Contents
22
+
23
+ - [Protocol support](#protocol-support)
24
+ - [Installing](#installing)
25
+ - [Opt-in for performance](#opt-in-for-performance)
26
+ - [API docs](#api-docs)
27
+ - [WebSocket compression](#websocket-compression)
28
+ - [Usage examples](#usage-examples)
29
+ - [Sending and receiving text data](#sending-and-receiving-text-data)
30
+ - [Sending binary data](#sending-binary-data)
31
+ - [Simple server](#simple-server)
32
+ - [External HTTP/S server](#external-https-server)
33
+ - [Multiple servers sharing a single HTTP/S server](#multiple-servers-sharing-a-single-https-server)
34
+ - [Client authentication](#client-authentication)
35
+ - [Server broadcast](#server-broadcast)
36
+ - [Round-trip time](#round-trip-time)
37
+ - [Use the Node.js streams API](#use-the-nodejs-streams-api)
38
+ - [Other examples](#other-examples)
39
+ - [FAQ](#faq)
40
+ - [How to get the IP address of the client?](#how-to-get-the-ip-address-of-the-client)
41
+ - [How to detect and close broken connections?](#how-to-detect-and-close-broken-connections)
42
+ - [How to connect via a proxy?](#how-to-connect-via-a-proxy)
43
+ - [Changelog](#changelog)
44
+ - [License](#license)
45
+
46
+ ## Protocol support
47
+
48
+ - **HyBi drafts 07-12** (Use the option `protocolVersion: 8`)
49
+ - **HyBi drafts 13-17** (Current default, alternatively option
50
+ `protocolVersion: 13`)
51
+
52
+ ## Installing
53
+
54
+ ```
55
+ npm install ws
56
+ ```
57
+
58
+ ### Opt-in for performance
59
+
60
+ There are 2 optional modules that can be installed along side with the ws
61
+ module. These modules are binary addons which improve certain operations.
62
+ Prebuilt binaries are available for the most popular platforms so you don't
63
+ necessarily need to have a C++ compiler installed on your machine.
64
+
65
+ - `npm install --save-optional bufferutil`: Allows to efficiently perform
66
+ operations such as masking and unmasking the data payload of the WebSocket
67
+ frames.
68
+ - `npm install --save-optional utf-8-validate`: Allows to efficiently check if a
69
+ message contains valid UTF-8.
70
+
71
+ To not even try to require and use these modules, use the
72
+ [`WS_NO_BUFFER_UTIL`](./doc/ws.md#ws_no_buffer_util) and
73
+ [`WS_NO_UTF_8_VALIDATE`](./doc/ws.md#ws_no_utf_8_validate) environment
74
+ variables. These might be useful to enhance security in systems where a user can
75
+ put a package in the package search path of an application of another user, due
76
+ to how the Node.js resolver algorithm works.
77
+
78
+ ## API docs
79
+
80
+ See [`/doc/ws.md`](./doc/ws.md) for Node.js-like documentation of ws classes and
81
+ utility functions.
82
+
83
+ ## WebSocket compression
84
+
85
+ ws supports the [permessage-deflate extension][permessage-deflate] which enables
86
+ the client and server to negotiate a compression algorithm and its parameters,
87
+ and then selectively apply it to the data payloads of each WebSocket message.
88
+
89
+ The extension is disabled by default on the server and enabled by default on the
90
+ client. It adds a significant overhead in terms of performance and memory
91
+ consumption so we suggest to enable it only if it is really needed.
92
+
93
+ Note that Node.js has a variety of issues with high-performance compression,
94
+ where increased concurrency, especially on Linux, can lead to [catastrophic
95
+ memory fragmentation][node-zlib-bug] and slow performance. If you intend to use
96
+ permessage-deflate in production, it is worthwhile to set up a test
97
+ representative of your workload and ensure Node.js/zlib will handle it with
98
+ acceptable performance and memory usage.
99
+
100
+ Tuning of permessage-deflate can be done via the options defined below. You can
101
+ also use `zlibDeflateOptions` and `zlibInflateOptions`, which is passed directly
102
+ into the creation of [raw deflate/inflate streams][node-zlib-deflaterawdocs].
103
+
104
+ See [the docs][ws-server-options] for more options.
105
+
106
+ ```js
107
+ import WebSocket, { WebSocketServer } from 'ws';
108
+
109
+ const wss = new WebSocketServer({
110
+ port: 8080,
111
+ perMessageDeflate: {
112
+ zlibDeflateOptions: {
113
+ // See zlib defaults.
114
+ chunkSize: 1024,
115
+ memLevel: 7,
116
+ level: 3
117
+ },
118
+ zlibInflateOptions: {
119
+ chunkSize: 10 * 1024
120
+ },
121
+ // Other options settable:
122
+ clientNoContextTakeover: true, // Defaults to negotiated value.
123
+ serverNoContextTakeover: true, // Defaults to negotiated value.
124
+ serverMaxWindowBits: 10, // Defaults to negotiated value.
125
+ // Below options specified as default values.
126
+ concurrencyLimit: 10, // Limits zlib concurrency for perf.
127
+ threshold: 1024 // Size (in bytes) below which messages
128
+ // should not be compressed if context takeover is disabled.
129
+ }
130
+ });
131
+ ```
132
+
133
+ The client will only use the extension if it is supported and enabled on the
134
+ server. To always disable the extension on the client set the
135
+ `perMessageDeflate` option to `false`.
136
+
137
+ ```js
138
+ import WebSocket from 'ws';
139
+
140
+ const ws = new WebSocket('ws://www.host.com/path', {
141
+ perMessageDeflate: false
142
+ });
143
+ ```
144
+
145
+ ## Usage examples
146
+
147
+ ### Sending and receiving text data
148
+
149
+ ```js
150
+ import WebSocket from 'ws';
151
+
152
+ const ws = new WebSocket('ws://www.host.com/path');
153
+
154
+ ws.on('open', function open() {
155
+ ws.send('something');
156
+ });
157
+
158
+ ws.on('message', function message(data) {
159
+ console.log('received: %s', data);
160
+ });
161
+ ```
162
+
163
+ ### Sending binary data
164
+
165
+ ```js
166
+ import WebSocket from 'ws';
167
+
168
+ const ws = new WebSocket('ws://www.host.com/path');
169
+
170
+ ws.on('open', function open() {
171
+ const array = new Float32Array(5);
172
+
173
+ for (var i = 0; i < array.length; ++i) {
174
+ array[i] = i / 2;
175
+ }
176
+
177
+ ws.send(array);
178
+ });
179
+ ```
180
+
181
+ ### Simple server
182
+
183
+ ```js
184
+ import { WebSocketServer } from 'ws';
185
+
186
+ const wss = new WebSocketServer({ port: 8080 });
187
+
188
+ wss.on('connection', function connection(ws) {
189
+ ws.on('message', function message(data) {
190
+ console.log('received: %s', data);
191
+ });
192
+
193
+ ws.send('something');
194
+ });
195
+ ```
196
+
197
+ ### External HTTP/S server
198
+
199
+ ```js
200
+ import { createServer } from 'https';
201
+ import { readFileSync } from 'fs';
202
+ import { WebSocketServer } from 'ws';
203
+
204
+ const server = createServer({
205
+ cert: readFileSync('/path/to/cert.pem'),
206
+ key: readFileSync('/path/to/key.pem')
207
+ });
208
+ const wss = new WebSocketServer({ server });
209
+
210
+ wss.on('connection', function connection(ws) {
211
+ ws.on('message', function message(data) {
212
+ console.log('received: %s', data);
213
+ });
214
+
215
+ ws.send('something');
216
+ });
217
+
218
+ server.listen(8080);
219
+ ```
220
+
221
+ ### Multiple servers sharing a single HTTP/S server
222
+
223
+ ```js
224
+ import { createServer } from 'http';
225
+ import { parse } from 'url';
226
+ import { WebSocketServer } from 'ws';
227
+
228
+ const server = createServer();
229
+ const wss1 = new WebSocketServer({ noServer: true });
230
+ const wss2 = new WebSocketServer({ noServer: true });
231
+
232
+ wss1.on('connection', function connection(ws) {
233
+ // ...
234
+ });
235
+
236
+ wss2.on('connection', function connection(ws) {
237
+ // ...
238
+ });
239
+
240
+ server.on('upgrade', function upgrade(request, socket, head) {
241
+ const { pathname } = parse(request.url);
242
+
243
+ if (pathname === '/foo') {
244
+ wss1.handleUpgrade(request, socket, head, function done(ws) {
245
+ wss1.emit('connection', ws, request);
246
+ });
247
+ } else if (pathname === '/bar') {
248
+ wss2.handleUpgrade(request, socket, head, function done(ws) {
249
+ wss2.emit('connection', ws, request);
250
+ });
251
+ } else {
252
+ socket.destroy();
253
+ }
254
+ });
255
+
256
+ server.listen(8080);
257
+ ```
258
+
259
+ ### Client authentication
260
+
261
+ ```js
262
+ import { createServer } from 'http';
263
+ import { WebSocketServer } from 'ws';
264
+
265
+ const server = createServer();
266
+ const wss = new WebSocketServer({ noServer: true });
267
+
268
+ wss.on('connection', function connection(ws, request, client) {
269
+ ws.on('message', function message(data) {
270
+ console.log(`Received message ${data} from user ${client}`);
271
+ });
272
+ });
273
+
274
+ server.on('upgrade', function upgrade(request, socket, head) {
275
+ // This function is not defined on purpose. Implement it with your own logic.
276
+ authenticate(request, function next(err, client) {
277
+ if (err || !client) {
278
+ socket.write('HTTP/1.1 401 Unauthorized\r\n\r\n');
279
+ socket.destroy();
280
+ return;
281
+ }
282
+
283
+ wss.handleUpgrade(request, socket, head, function done(ws) {
284
+ wss.emit('connection', ws, request, client);
285
+ });
286
+ });
287
+ });
288
+
289
+ server.listen(8080);
290
+ ```
291
+
292
+ Also see the provided [example][session-parse-example] using `express-session`.
293
+
294
+ ### Server broadcast
295
+
296
+ A client WebSocket broadcasting to all connected WebSocket clients, including
297
+ itself.
298
+
299
+ ```js
300
+ import WebSocket, { WebSocketServer } from 'ws';
301
+
302
+ const wss = new WebSocketServer({ port: 8080 });
303
+
304
+ wss.on('connection', function connection(ws) {
305
+ ws.on('message', function message(data, isBinary) {
306
+ wss.clients.forEach(function each(client) {
307
+ if (client.readyState === WebSocket.OPEN) {
308
+ client.send(data, { binary: isBinary });
309
+ }
310
+ });
311
+ });
312
+ });
313
+ ```
314
+
315
+ A client WebSocket broadcasting to every other connected WebSocket clients,
316
+ excluding itself.
317
+
318
+ ```js
319
+ import WebSocket, { WebSocketServer } from 'ws';
320
+
321
+ const wss = new WebSocketServer({ port: 8080 });
322
+
323
+ wss.on('connection', function connection(ws) {
324
+ ws.on('message', function message(data, isBinary) {
325
+ wss.clients.forEach(function each(client) {
326
+ if (client !== ws && client.readyState === WebSocket.OPEN) {
327
+ client.send(data, { binary: isBinary });
328
+ }
329
+ });
330
+ });
331
+ });
332
+ ```
333
+
334
+ ### Round-trip time
335
+
336
+ ```js
337
+ import WebSocket from 'ws';
338
+
339
+ const ws = new WebSocket('wss://websocket-echo.com/');
340
+
341
+ ws.on('open', function open() {
342
+ console.log('connected');
343
+ ws.send(Date.now());
344
+ });
345
+
346
+ ws.on('close', function close() {
347
+ console.log('disconnected');
348
+ });
349
+
350
+ ws.on('message', function message(data) {
351
+ console.log(`Round-trip time: ${Date.now() - data} ms`);
352
+
353
+ setTimeout(function timeout() {
354
+ ws.send(Date.now());
355
+ }, 500);
356
+ });
357
+ ```
358
+
359
+ ### Use the Node.js streams API
360
+
361
+ ```js
362
+ import WebSocket, { createWebSocketStream } from 'ws';
363
+
364
+ const ws = new WebSocket('wss://websocket-echo.com/');
365
+
366
+ const duplex = createWebSocketStream(ws, { encoding: 'utf8' });
367
+
368
+ duplex.pipe(process.stdout);
369
+ process.stdin.pipe(duplex);
370
+ ```
371
+
372
+ ### Other examples
373
+
374
+ For a full example with a browser client communicating with a ws server, see the
375
+ examples folder.
376
+
377
+ Otherwise, see the test cases.
378
+
379
+ ## FAQ
380
+
381
+ ### How to get the IP address of the client?
382
+
383
+ The remote IP address can be obtained from the raw socket.
384
+
385
+ ```js
386
+ import { WebSocketServer } from 'ws';
387
+
388
+ const wss = new WebSocketServer({ port: 8080 });
389
+
390
+ wss.on('connection', function connection(ws, req) {
391
+ const ip = req.socket.remoteAddress;
392
+ });
393
+ ```
394
+
395
+ When the server runs behind a proxy like NGINX, the de-facto standard is to use
396
+ the `X-Forwarded-For` header.
397
+
398
+ ```js
399
+ wss.on('connection', function connection(ws, req) {
400
+ const ip = req.headers['x-forwarded-for'].split(',')[0].trim();
401
+ });
402
+ ```
403
+
404
+ ### How to detect and close broken connections?
405
+
406
+ Sometimes the link between the server and the client can be interrupted in a way
407
+ that keeps both the server and the client unaware of the broken state of the
408
+ connection (e.g. when pulling the cord).
409
+
410
+ In these cases ping messages can be used as a means to verify that the remote
411
+ endpoint is still responsive.
412
+
413
+ ```js
414
+ import { WebSocketServer } from 'ws';
415
+
416
+ function heartbeat() {
417
+ this.isAlive = true;
418
+ }
419
+
420
+ const wss = new WebSocketServer({ port: 8080 });
421
+
422
+ wss.on('connection', function connection(ws) {
423
+ ws.isAlive = true;
424
+ ws.on('pong', heartbeat);
425
+ });
426
+
427
+ const interval = setInterval(function ping() {
428
+ wss.clients.forEach(function each(ws) {
429
+ if (ws.isAlive === false) return ws.terminate();
430
+
431
+ ws.isAlive = false;
432
+ ws.ping();
433
+ });
434
+ }, 30000);
435
+
436
+ wss.on('close', function close() {
437
+ clearInterval(interval);
438
+ });
439
+ ```
440
+
441
+ Pong messages are automatically sent in response to ping messages as required by
442
+ the spec.
443
+
444
+ Just like the server example above your clients might as well lose connection
445
+ without knowing it. You might want to add a ping listener on your clients to
446
+ prevent that. A simple implementation would be:
447
+
448
+ ```js
449
+ import WebSocket from 'ws';
450
+
451
+ function heartbeat() {
452
+ clearTimeout(this.pingTimeout);
453
+
454
+ // Use `WebSocket#terminate()`, which immediately destroys the connection,
455
+ // instead of `WebSocket#close()`, which waits for the close timer.
456
+ // Delay should be equal to the interval at which your server
457
+ // sends out pings plus a conservative assumption of the latency.
458
+ this.pingTimeout = setTimeout(() => {
459
+ this.terminate();
460
+ }, 30000 + 1000);
461
+ }
462
+
463
+ const client = new WebSocket('wss://websocket-echo.com/');
464
+
465
+ client.on('open', heartbeat);
466
+ client.on('ping', heartbeat);
467
+ client.on('close', function clear() {
468
+ clearTimeout(this.pingTimeout);
469
+ });
470
+ ```
471
+
472
+ ### How to connect via a proxy?
473
+
474
+ Use a custom `http.Agent` implementation like [https-proxy-agent][] or
475
+ [socks-proxy-agent][].
476
+
477
+ ## Changelog
478
+
479
+ We're using the GitHub [releases][changelog] for changelog entries.
480
+
481
+ ## License
482
+
483
+ [MIT](LICENSE)
484
+
485
+ [changelog]: https://github.com/websockets/ws/releases
486
+ [client-report]: http://websockets.github.io/ws/autobahn/clients/
487
+ [https-proxy-agent]: https://github.com/TooTallNate/node-https-proxy-agent
488
+ [node-zlib-bug]: https://github.com/nodejs/node/issues/8871
489
+ [node-zlib-deflaterawdocs]:
490
+ https://nodejs.org/api/zlib.html#zlib_zlib_createdeflateraw_options
491
+ [permessage-deflate]: https://tools.ietf.org/html/rfc7692
492
+ [server-report]: http://websockets.github.io/ws/autobahn/servers/
493
+ [session-parse-example]: ./examples/express-session-parse
494
+ [socks-proxy-agent]: https://github.com/TooTallNate/node-socks-proxy-agent
495
+ [ws-server-options]: ./doc/ws.md#new-websocketserveroptions-callback
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ module.exports = function () {
4
+ throw new Error(
5
+ 'ws does not work in the browser. Browser clients must use the native ' +
6
+ 'WebSocket object'
7
+ );
8
+ };
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ const WebSocket = require('./lib/websocket');
4
+
5
+ WebSocket.createWebSocketStream = require('./lib/stream');
6
+ WebSocket.Server = require('./lib/websocket-server');
7
+ WebSocket.Receiver = require('./lib/receiver');
8
+ WebSocket.Sender = require('./lib/sender');
9
+
10
+ WebSocket.WebSocket = WebSocket;
11
+ WebSocket.WebSocketServer = WebSocket.Server;
12
+
13
+ module.exports = WebSocket;
@@ -0,0 +1,127 @@
1
+ 'use strict';
2
+
3
+ const { EMPTY_BUFFER } = require('./constants');
4
+
5
+ /**
6
+ * Merges an array of buffers into a new buffer.
7
+ *
8
+ * @param {Buffer[]} list The array of buffers to concat
9
+ * @param {Number} totalLength The total length of buffers in the list
10
+ * @return {Buffer} The resulting buffer
11
+ * @public
12
+ */
13
+ function concat(list, totalLength) {
14
+ if (list.length === 0) return EMPTY_BUFFER;
15
+ if (list.length === 1) return list[0];
16
+
17
+ const target = Buffer.allocUnsafe(totalLength);
18
+ let offset = 0;
19
+
20
+ for (let i = 0; i < list.length; i++) {
21
+ const buf = list[i];
22
+ target.set(buf, offset);
23
+ offset += buf.length;
24
+ }
25
+
26
+ if (offset < totalLength) return target.slice(0, offset);
27
+
28
+ return target;
29
+ }
30
+
31
+ /**
32
+ * Masks a buffer using the given mask.
33
+ *
34
+ * @param {Buffer} source The buffer to mask
35
+ * @param {Buffer} mask The mask to use
36
+ * @param {Buffer} output The buffer where to store the result
37
+ * @param {Number} offset The offset at which to start writing
38
+ * @param {Number} length The number of bytes to mask.
39
+ * @public
40
+ */
41
+ function _mask(source, mask, output, offset, length) {
42
+ for (let i = 0; i < length; i++) {
43
+ output[offset + i] = source[i] ^ mask[i & 3];
44
+ }
45
+ }
46
+
47
+ /**
48
+ * Unmasks a buffer using the given mask.
49
+ *
50
+ * @param {Buffer} buffer The buffer to unmask
51
+ * @param {Buffer} mask The mask to use
52
+ * @public
53
+ */
54
+ function _unmask(buffer, mask) {
55
+ for (let i = 0; i < buffer.length; i++) {
56
+ buffer[i] ^= mask[i & 3];
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Converts a buffer to an `ArrayBuffer`.
62
+ *
63
+ * @param {Buffer} buf The buffer to convert
64
+ * @return {ArrayBuffer} Converted buffer
65
+ * @public
66
+ */
67
+ function toArrayBuffer(buf) {
68
+ if (buf.byteLength === buf.buffer.byteLength) {
69
+ return buf.buffer;
70
+ }
71
+
72
+ return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
73
+ }
74
+
75
+ /**
76
+ * Converts `data` to a `Buffer`.
77
+ *
78
+ * @param {*} data The data to convert
79
+ * @return {Buffer} The buffer
80
+ * @throws {TypeError}
81
+ * @public
82
+ */
83
+ function toBuffer(data) {
84
+ toBuffer.readOnly = true;
85
+
86
+ if (Buffer.isBuffer(data)) return data;
87
+
88
+ let buf;
89
+
90
+ if (data instanceof ArrayBuffer) {
91
+ buf = Buffer.from(data);
92
+ } else if (ArrayBuffer.isView(data)) {
93
+ buf = Buffer.from(data.buffer, data.byteOffset, data.byteLength);
94
+ } else {
95
+ buf = Buffer.from(data);
96
+ toBuffer.readOnly = false;
97
+ }
98
+
99
+ return buf;
100
+ }
101
+
102
+ module.exports = {
103
+ concat,
104
+ mask: _mask,
105
+ toArrayBuffer,
106
+ toBuffer,
107
+ unmask: _unmask
108
+ };
109
+
110
+ /* istanbul ignore else */
111
+ if (!process.env.WS_NO_BUFFER_UTIL) {
112
+ try {
113
+ const bufferUtil = require('bufferutil');
114
+
115
+ module.exports.mask = function (source, mask, output, offset, length) {
116
+ if (length < 48) _mask(source, mask, output, offset, length);
117
+ else bufferUtil.mask(source, mask, output, offset, length);
118
+ };
119
+
120
+ module.exports.unmask = function (buffer, mask) {
121
+ if (buffer.length < 32) _unmask(buffer, mask);
122
+ else bufferUtil.unmask(buffer, mask);
123
+ };
124
+ } catch (e) {
125
+ // Continue regardless of the error.
126
+ }
127
+ }
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ BINARY_TYPES: ['nodebuffer', 'arraybuffer', 'fragments'],
5
+ EMPTY_BUFFER: Buffer.alloc(0),
6
+ GUID: '258EAFA5-E914-47DA-95CA-C5AB0DC85B11',
7
+ kForOnEventAttribute: Symbol('kIsForOnEventAttribute'),
8
+ kListener: Symbol('kListener'),
9
+ kStatusCode: Symbol('status-code'),
10
+ kWebSocket: Symbol('websocket'),
11
+ NOOP: () => {}
12
+ };