@noodleseed/one 0.21.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/dist/commands/author-loop.d.ts.map +1 -1
  2. package/dist/commands/author-loop.js +2 -2
  3. package/dist/commands/author-loop.js.map +1 -1
  4. package/dist/commands/catalog-dispatch.d.ts.map +1 -1
  5. package/dist/commands/catalog-dispatch.js +21 -2
  6. package/dist/commands/catalog-dispatch.js.map +1 -1
  7. package/dist/commands/deploy-ops.d.ts.map +1 -1
  8. package/dist/commands/deploy-ops.js +28 -11
  9. package/dist/commands/deploy-ops.js.map +1 -1
  10. package/dist/first-run.d.ts +11 -0
  11. package/dist/first-run.d.ts.map +1 -1
  12. package/dist/first-run.js +19 -4
  13. package/dist/first-run.js.map +1 -1
  14. package/dist/project-scaffold-templates.d.ts +11 -0
  15. package/dist/project-scaffold-templates.d.ts.map +1 -0
  16. package/dist/project-scaffold-templates.js +359 -0
  17. package/dist/project-scaffold-templates.js.map +1 -0
  18. package/dist/project.d.ts.map +1 -1
  19. package/dist/project.js +1 -323
  20. package/dist/project.js.map +1 -1
  21. package/dist/react.d.ts +2 -2
  22. package/dist/react.d.ts.map +1 -1
  23. package/dist/react.js +1 -1
  24. package/dist/react.js.map +1 -1
  25. package/dist/validate.d.ts +12 -0
  26. package/dist/validate.d.ts.map +1 -1
  27. package/dist/validate.js +11 -0
  28. package/dist/validate.js.map +1 -1
  29. package/node_modules/@noodle-borg/agent-kit/dist/curated/hook-notes.d.ts.map +1 -1
  30. package/node_modules/@noodle-borg/agent-kit/dist/curated/hook-notes.js +2 -1
  31. package/node_modules/@noodle-borg/agent-kit/dist/curated/hook-notes.js.map +1 -1
  32. package/node_modules/@noodle-borg/agent-kit/dist/generated/surface.d.ts.map +1 -1
  33. package/node_modules/@noodle-borg/agent-kit/dist/generated/surface.js +1 -0
  34. package/node_modules/@noodle-borg/agent-kit/dist/generated/surface.js.map +1 -1
  35. package/node_modules/@noodle-borg/agent-kit/dist/skill-content.d.ts.map +1 -1
  36. package/node_modules/@noodle-borg/agent-kit/dist/skill-content.js +6 -9
  37. package/node_modules/@noodle-borg/agent-kit/dist/skill-content.js.map +1 -1
  38. package/node_modules/@noodle-borg/agent-kit/package.json +1 -1
  39. package/node_modules/@noodle-borg/authoring/dist/index.d.ts +3 -3
  40. package/node_modules/@noodle-borg/authoring/dist/index.d.ts.map +1 -1
  41. package/node_modules/@noodle-borg/authoring/dist/index.js +1 -1
  42. package/node_modules/@noodle-borg/authoring/dist/index.js.map +1 -1
  43. package/node_modules/@noodle-borg/authoring/dist/react/bridge.d.ts +9 -1
  44. package/node_modules/@noodle-borg/authoring/dist/react/bridge.d.ts.map +1 -1
  45. package/node_modules/@noodle-borg/authoring/dist/react/bridge.js +11 -1
  46. package/node_modules/@noodle-borg/authoring/dist/react/bridge.js.map +1 -1
  47. package/node_modules/@noodle-borg/authoring/dist/react/components.d.ts +306 -9
  48. package/node_modules/@noodle-borg/authoring/dist/react/components.d.ts.map +1 -1
  49. package/node_modules/@noodle-borg/authoring/dist/react/components.js +63 -11
  50. package/node_modules/@noodle-borg/authoring/dist/react/components.js.map +1 -1
  51. package/node_modules/@noodle-borg/authoring/dist/react/hooks.d.ts +2 -0
  52. package/node_modules/@noodle-borg/authoring/dist/react/hooks.d.ts.map +1 -1
  53. package/node_modules/@noodle-borg/authoring/dist/react/hooks.js +11 -0
  54. package/node_modules/@noodle-borg/authoring/dist/react/hooks.js.map +1 -1
  55. package/node_modules/@noodle-borg/authoring/dist/react/index.d.ts +7 -3
  56. package/node_modules/@noodle-borg/authoring/dist/react/index.d.ts.map +1 -1
  57. package/node_modules/@noodle-borg/authoring/dist/react/index.js +4 -2
  58. package/node_modules/@noodle-borg/authoring/dist/react/index.js.map +1 -1
  59. package/node_modules/@noodle-borg/authoring/dist/react/native-components.d.ts +1159 -0
  60. package/node_modules/@noodle-borg/authoring/dist/react/native-components.d.ts.map +1 -0
  61. package/node_modules/@noodle-borg/authoring/dist/react/native-components.js +66 -0
  62. package/node_modules/@noodle-borg/authoring/dist/react/native-components.js.map +1 -0
  63. package/node_modules/@noodle-borg/authoring/dist/react/semantic-components.d.ts +2618 -0
  64. package/node_modules/@noodle-borg/authoring/dist/react/semantic-components.d.ts.map +1 -0
  65. package/node_modules/@noodle-borg/authoring/dist/react/semantic-components.js +110 -0
  66. package/node_modules/@noodle-borg/authoring/dist/react/semantic-components.js.map +1 -0
  67. package/node_modules/@noodle-borg/authoring/dist/react.d.ts +2 -2
  68. package/node_modules/@noodle-borg/authoring/dist/react.d.ts.map +1 -1
  69. package/node_modules/@noodle-borg/authoring/dist/react.js +1 -1
  70. package/node_modules/@noodle-borg/authoring/dist/react.js.map +1 -1
  71. package/node_modules/@noodle-borg/authoring/dist/recording.d.ts +1 -1
  72. package/node_modules/@noodle-borg/authoring/dist/recording.d.ts.map +1 -1
  73. package/node_modules/@noodle-borg/authoring/dist/recording.js +14 -1
  74. package/node_modules/@noodle-borg/authoring/dist/recording.js.map +1 -1
  75. package/node_modules/@noodle-borg/authoring/dist/server.d.ts +25 -2
  76. package/node_modules/@noodle-borg/authoring/dist/server.d.ts.map +1 -1
  77. package/node_modules/@noodle-borg/authoring/dist/server.js +7 -3
  78. package/node_modules/@noodle-borg/authoring/dist/server.js.map +1 -1
  79. package/node_modules/@noodle-borg/compiler/dist/compile.d.ts.map +1 -1
  80. package/node_modules/@noodle-borg/compiler/dist/compile.js +20 -8
  81. package/node_modules/@noodle-borg/compiler/dist/compile.js.map +1 -1
  82. package/node_modules/@noodle-borg/compiler/dist/manifest/schema.d.ts +2 -0
  83. package/node_modules/@noodle-borg/compiler/dist/manifest/schema.d.ts.map +1 -1
  84. package/node_modules/@noodle-borg/compiler/dist/manifest/schema.js +6 -0
  85. package/node_modules/@noodle-borg/compiler/dist/manifest/schema.js.map +1 -1
  86. package/node_modules/@noodle-borg/connector-http/package.json +1 -1
  87. package/node_modules/@noodle-borg/protocol/dist/mapping.d.ts.map +1 -1
  88. package/node_modules/@noodle-borg/protocol/dist/mapping.js +8 -0
  89. package/node_modules/@noodle-borg/protocol/dist/mapping.js.map +1 -1
  90. package/node_modules/hono/dist/adapter/aws-lambda/handler.js +15 -21
  91. package/node_modules/hono/dist/adapter/bun/websocket.js +3 -1
  92. package/node_modules/hono/dist/adapter/lambda-edge/handler.js +8 -2
  93. package/node_modules/hono/dist/cjs/adapter/aws-lambda/handler.js +15 -21
  94. package/node_modules/hono/dist/cjs/adapter/bun/websocket.js +3 -1
  95. package/node_modules/hono/dist/cjs/adapter/lambda-edge/handler.js +8 -2
  96. package/node_modules/hono/dist/cjs/helper/css/common.js +3 -1
  97. package/node_modules/hono/dist/cjs/helper/css/index.js +9 -1
  98. package/node_modules/hono/dist/cjs/jsx/base.js +8 -14
  99. package/node_modules/hono/dist/cjs/jsx/components.js +41 -21
  100. package/node_modules/hono/dist/cjs/jsx/context.js +131 -5
  101. package/node_modules/hono/dist/cjs/jsx/streaming.js +9 -7
  102. package/node_modules/hono/dist/cjs/middleware/cors/index.js +2 -5
  103. package/node_modules/hono/dist/cjs/middleware/serve-static/index.js +2 -2
  104. package/node_modules/hono/dist/cjs/utils/body.js +12 -4
  105. package/node_modules/hono/dist/cjs/utils/buffer.js +2 -1
  106. package/node_modules/hono/dist/cjs/validator/validator.js +3 -3
  107. package/node_modules/hono/dist/helper/css/common.js +3 -1
  108. package/node_modules/hono/dist/helper/css/index.js +9 -1
  109. package/node_modules/hono/dist/jsx/base.js +15 -15
  110. package/node_modules/hono/dist/jsx/components.js +42 -22
  111. package/node_modules/hono/dist/jsx/context.js +129 -5
  112. package/node_modules/hono/dist/jsx/streaming.js +10 -8
  113. package/node_modules/hono/dist/middleware/cors/index.js +2 -5
  114. package/node_modules/hono/dist/middleware/serve-static/index.js +2 -2
  115. package/node_modules/hono/dist/types/adapter/aws-lambda/handler.d.ts +1 -1
  116. package/node_modules/hono/dist/types/jsx/base.d.ts +1 -3
  117. package/node_modules/hono/dist/types/jsx/context.d.ts +39 -0
  118. package/node_modules/hono/dist/types/middleware/context-storage/index.d.ts +2 -2
  119. package/node_modules/hono/dist/types/utils/body.d.ts +1 -1
  120. package/node_modules/hono/dist/utils/body.js +12 -4
  121. package/node_modules/hono/dist/utils/buffer.js +2 -1
  122. package/node_modules/hono/dist/validator/validator.js +3 -3
  123. package/node_modules/hono/package.json +9 -10
  124. package/node_modules/tailwindcss/dist/chunk-HMCCH6MG.mjs +1 -0
  125. package/node_modules/tailwindcss/dist/default-theme.mjs +1 -1
  126. package/node_modules/tailwindcss/dist/lib.js +13 -13
  127. package/node_modules/tailwindcss/dist/lib.mjs +18 -18
  128. package/node_modules/tailwindcss/package.json +2 -2
  129. package/node_modules/undici/README.md +3 -2
  130. package/node_modules/undici/docs/docs/api/Agent.md +248 -44
  131. package/node_modules/undici/docs/docs/api/BalancedPool.md +246 -48
  132. package/node_modules/undici/docs/docs/api/CacheStorage.md +171 -13
  133. package/node_modules/undici/docs/docs/api/CacheStore.md +294 -98
  134. package/node_modules/undici/docs/docs/api/Client.md +365 -178
  135. package/node_modules/undici/docs/docs/api/ClientStats.md +80 -14
  136. package/node_modules/undici/docs/docs/api/Connector.md +118 -36
  137. package/node_modules/undici/docs/docs/api/ContentType.md +65 -25
  138. package/node_modules/undici/docs/docs/api/Cookies.md +125 -47
  139. package/node_modules/undici/docs/docs/api/Debug.md +34 -18
  140. package/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +364 -164
  141. package/node_modules/undici/docs/docs/api/Dispatcher.md +479 -1093
  142. package/node_modules/undici/docs/docs/api/EnvHttpProxyAgent.md +101 -87
  143. package/node_modules/undici/docs/docs/api/Errors.md +503 -40
  144. package/node_modules/undici/docs/docs/api/EventSource.md +294 -32
  145. package/node_modules/undici/docs/docs/api/Fetch.md +680 -31
  146. package/node_modules/undici/docs/docs/api/GlobalInstallation.md +78 -98
  147. package/node_modules/undici/docs/docs/api/H2CClient.md +298 -176
  148. package/node_modules/undici/docs/docs/api/Interceptors.md +355 -0
  149. package/node_modules/undici/docs/docs/api/MockAgent.md +314 -322
  150. package/node_modules/undici/docs/docs/api/MockCallHistory.md +272 -98
  151. package/node_modules/undici/docs/docs/api/MockCallHistoryLog.md +189 -26
  152. package/node_modules/undici/docs/docs/api/MockClient.md +151 -33
  153. package/node_modules/undici/docs/docs/api/MockErrors.md +56 -5
  154. package/node_modules/undici/docs/docs/api/MockPool.md +299 -263
  155. package/node_modules/undici/docs/docs/api/Pool.md +235 -43
  156. package/node_modules/undici/docs/docs/api/PoolStats.md +119 -13
  157. package/node_modules/undici/docs/docs/api/ProxyAgent.md +179 -160
  158. package/node_modules/undici/docs/docs/api/RedirectHandler.md +238 -63
  159. package/node_modules/undici/docs/docs/api/RetryAgent.md +113 -26
  160. package/node_modules/undici/docs/docs/api/RetryHandler.md +161 -77
  161. package/node_modules/undici/docs/docs/api/RoundRobinPool.md +166 -72
  162. package/node_modules/undici/docs/docs/api/SnapshotAgent.md +264 -542
  163. package/node_modules/undici/docs/docs/api/Socks5ProxyAgent.md +162 -186
  164. package/node_modules/undici/docs/docs/api/Util.md +68 -11
  165. package/node_modules/undici/docs/docs/api/WebSocket.md +475 -80
  166. package/node_modules/undici/docs/docs/api/api-lifecycle.md +100 -32
  167. package/node_modules/undici/docs/docs/best-practices/client-certificate.md +2 -0
  168. package/node_modules/undici/docs/docs/best-practices/crawling.md +3 -1
  169. package/node_modules/undici/docs/docs/best-practices/migrating-from-v7-to-v8.md +6 -4
  170. package/node_modules/undici/docs/docs/best-practices/mocking-request.md +9 -7
  171. package/node_modules/undici/docs/docs/best-practices/proxy.md +3 -1
  172. package/node_modules/undici/docs/docs/best-practices/undici-vs-builtin-fetch.md +10 -8
  173. package/node_modules/undici/docs/docs/best-practices/writing-tests.md +2 -0
  174. package/node_modules/undici/docs/docs/{GettingStarted.md → getting-started.md} +22 -19
  175. package/node_modules/undici/docs/docs/index.md +779 -0
  176. package/node_modules/undici/docs/docs/site.json +125 -0
  177. package/node_modules/undici/docs/docs/type-map.json +79 -0
  178. package/node_modules/undici/lib/api/api-request.js +7 -1
  179. package/node_modules/undici/lib/api/readable.js +47 -2
  180. package/node_modules/undici/lib/core/errors.js +20 -0
  181. package/node_modules/undici/lib/core/request.js +1 -1
  182. package/node_modules/undici/lib/core/util.js +24 -1
  183. package/node_modules/undici/lib/dispatcher/client-h1.js +92 -1
  184. package/node_modules/undici/lib/dispatcher/client-h2.js +322 -118
  185. package/node_modules/undici/lib/dispatcher/client.js +6 -2
  186. package/node_modules/undici/lib/dispatcher/dispatcher-base.js +1 -0
  187. package/node_modules/undici/lib/dispatcher/proxy-agent.js +42 -7
  188. package/node_modules/undici/lib/dispatcher/socks5-proxy-agent.js +4 -2
  189. package/node_modules/undici/lib/handler/redirect-handler.js +1 -0
  190. package/node_modules/undici/lib/handler/retry-handler.js +57 -19
  191. package/node_modules/undici/lib/util/cache.js +8 -2
  192. package/node_modules/undici/lib/web/cookies/parse.js +20 -27
  193. package/node_modules/undici/lib/web/cookies/util.js +1 -1
  194. package/node_modules/undici/lib/web/eventsource/eventsource.js +7 -18
  195. package/node_modules/undici/lib/web/eventsource/util.js +32 -1
  196. package/node_modules/undici/lib/web/fetch/body.js +43 -0
  197. package/node_modules/undici/lib/web/fetch/constants.js +1 -1
  198. package/node_modules/undici/lib/web/fetch/index.js +11 -2
  199. package/node_modules/undici/lib/web/fetch/request.js +1 -0
  200. package/node_modules/undici/lib/web/fetch/util.js +4 -1
  201. package/node_modules/undici/lib/web/websocket/receiver.js +20 -3
  202. package/node_modules/undici/lib/web/websocket/stream/websocketstream.js +8 -1
  203. package/node_modules/undici/lib/web/websocket/websocket.js +3 -1
  204. package/node_modules/undici/package.json +1 -1
  205. package/node_modules/undici/types/client.d.ts +6 -1
  206. package/node_modules/undici/types/cookies.d.ts +1 -1
  207. package/node_modules/undici/types/errors.d.ts +10 -0
  208. package/node_modules/undici/types/fetch.d.ts +1 -0
  209. package/node_modules/undici/types/handlers.d.ts +2 -0
  210. package/node_modules/undici/types/proxy-agent.d.ts +7 -0
  211. package/package.json +8 -6
  212. package/react/styles.css +851 -0
  213. package/react/styles.source.css +850 -0
  214. package/node_modules/hono/dist/tsconfig.build.tsbuildinfo +0 -1
  215. package/node_modules/tailwindcss/dist/chunk-XVOTX5KS.mjs +0 -1
@@ -1,141 +1,536 @@
1
- # Class: WebSocket
1
+ # WebSocket
2
2
 
3
- Extends: [`EventTarget`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget)
3
+ <!--introduced_in=v5.15.0-->
4
+ <!--type=module-->
5
+ <!-- source_link=lib/web/websocket/websocket.js -->
4
6
 
5
- The WebSocket object provides a way to manage a WebSocket connection to a server, allowing bidirectional communication. The API follows the [WebSocket spec](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) and [RFC 6455](https://datatracker.ietf.org/doc/html/rfc6455).
7
+ > Stability: 2 - Stable
6
8
 
7
- ## `new WebSocket(url[, protocol])`
9
+ The `WebSocket` API provides a way to manage a WebSocket connection to a
10
+ server, allowing bidirectional communication. It follows the
11
+ [WHATWG WebSocket specification][] and [RFC 6455][], and is intended to be
12
+ interchangeable with the global `WebSocket` available in browsers.
8
13
 
9
- Arguments:
14
+ ```mjs
15
+ import { WebSocket } from 'undici'
10
16
 
11
- * **url** `URL | string`
12
- * **protocol** `string | string[] | WebSocketInit` (optional) - Subprotocol(s) to request the server use, or a [`Dispatcher`](/docs/docs/api/Dispatcher.md).
17
+ const ws = new WebSocket('wss://echo.websocket.events')
13
18
 
14
- ### WebSocketInit
19
+ ws.addEventListener('open', () => {
20
+ ws.send('Hello, world!')
21
+ })
15
22
 
16
- When passing an object as the second argument, the following options are available:
23
+ ws.addEventListener('message', (event) => {
24
+ console.log('received:', event.data)
25
+ })
26
+ ```
17
27
 
18
- * **protocols** `string | string[]` (optional) - Subprotocol(s) to request the server use.
19
- * **dispatcher** `Dispatcher` (optional) - A custom [`Dispatcher`](/docs/docs/api/Dispatcher.md) to use for the connection.
20
- * **headers** `HeadersInit` (optional) - Custom headers to include in the WebSocket handshake request.
28
+ In addition to the standard `WebSocket` interface, this module exports the
29
+ streams-based [`WebSocketStream`][] and [`WebSocketError`][] APIs, as well as a
30
+ [`ping()`][] helper for sending ping frames.
21
31
 
22
- ### Example:
32
+ ## Class: `WebSocket`
23
33
 
24
- This example will not work in browsers or other platforms that don't allow passing an object.
34
+ <!-- YAML
35
+ added: v5.15.0
36
+ -->
25
37
 
26
- ```js
27
- import { WebSocket, ProxyAgent } from 'undici'
38
+ * Extends: {EventTarget}
28
39
 
29
- const proxyAgent = new ProxyAgent('my.proxy.server')
40
+ The `WebSocket` object represents a single WebSocket connection. Constructing a
41
+ `WebSocket` immediately begins the opening handshake; the connection cannot be
42
+ reused once it has been closed.
30
43
 
31
- const ws = new WebSocket('wss://echo.websocket.events', {
32
- dispatcher: proxyAgent,
33
- protocols: ['echo', 'chat']
34
- })
35
- ```
44
+ ### `new WebSocket(url[, protocols])`
45
+
46
+ <!-- YAML
47
+ added: v5.15.0
48
+ -->
49
+
50
+ * `url` {URL|string} The URL of the server to connect to. Must use the `ws:`
51
+ or `wss:` scheme.
52
+ * `protocols` {string|string[]|WebSocketInit} A single subprotocol, a list of
53
+ subprotocols to negotiate with the server, or a `WebSocketInit` object.
54
+ **Default:** `[]`.
55
+ * `protocols` {string|string[]} Subprotocol(s) to request the server use.
56
+ **Default:** `[]`.
57
+ * `dispatcher` {Dispatcher} The dispatcher used to open the connection.
58
+ **Default:** the global dispatcher.
59
+ * `headers` {HeadersInit|null} Additional headers to send with the handshake
60
+ request. (optional)
36
61
 
37
- If you do not need a custom Dispatcher, it's recommended to use the following pattern:
62
+ Creates a new `WebSocket` and begins connecting to `url`. The second argument
63
+ may be a string or array of subprotocols, or a `WebSocketInit` object. The
64
+ object form is an undici extension and is not available in browsers; it allows a
65
+ custom `dispatcher` and additional `headers` to be supplied.
38
66
 
39
- ```js
67
+ If a value in `protocols` is repeated or is not a valid subprotocol name, the
68
+ constructor throws a `SyntaxError` `DOMException`.
69
+
70
+ ```mjs
40
71
  import { WebSocket } from 'undici'
41
72
 
42
73
  const ws = new WebSocket('wss://echo.websocket.events', ['echo', 'chat'])
43
74
  ```
44
75
 
45
- ### Example with HTTP/2:
76
+ To route the connection through a custom dispatcher, such as a
77
+ [`ProxyAgent`][], pass a `WebSocketInit` object:
46
78
 
47
- > ⚠️ Warning: WebSocket over HTTP/2 is experimental, it is likely to change in the future.
79
+ ```mjs
80
+ import { WebSocket, ProxyAgent } from 'undici'
48
81
 
49
- > 🗒️ Note: WebSocket over HTTP/2 may be enabled by default in a future version,
50
- > this will happen by enabling HTTP/2 connections as the default behavior of Undici's Agent as well the global dispatcher.
51
- > Stay tuned to the changelog for more information.
82
+ const dispatcher = new ProxyAgent('http://localhost:8080')
52
83
 
53
- This example will not work in browsers or other platforms that don't allow passing an object.
84
+ const ws = new WebSocket('wss://echo.websocket.events', {
85
+ dispatcher,
86
+ protocols: ['echo', 'chat']
87
+ })
88
+ ```
54
89
 
55
- ```js
56
- import { Agent } from 'undici'
90
+ WebSocket over HTTP/2 is experimental and may change in the future. It can be
91
+ enabled by passing a dispatcher configured with `allowH2`:
57
92
 
58
- const agent = new Agent({ allowH2: true })
93
+ ```mjs
94
+ import { WebSocket, Agent } from 'undici'
95
+
96
+ const dispatcher = new Agent({ allowH2: true })
59
97
 
60
98
  const ws = new WebSocket('wss://echo.websocket.events', {
61
- dispatcher: agent,
99
+ dispatcher,
62
100
  protocols: ['echo', 'chat']
63
101
  })
64
102
  ```
65
103
 
66
- # Class: WebSocketStream
104
+ ### `websocket.close([code[, reason]])`
105
+
106
+ <!-- YAML
107
+ added: v5.15.0
108
+ -->
67
109
 
68
- > ⚠️ Warning: the WebSocketStream API has not been finalized and is likely to change.
110
+ * `code` {number} The status code explaining why the connection is being
111
+ closed. **Default:** `null`.
112
+ * `reason` {string} A human-readable string explaining why the connection is
113
+ being closed. **Default:** `''`.
69
114
 
70
- See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/WebSocketStream) for more information.
115
+ Starts the closing handshake. The `code` is clamped to an unsigned 16-bit
116
+ integer; when omitted, no status code is sent. The `reason` is encoded as
117
+ UTF-8 and must not exceed 123 bytes.
71
118
 
72
- ## `new WebSocketStream(url[, protocol])`
119
+ ```mjs
120
+ ws.close(1000, 'Done')
121
+ ```
73
122
 
74
- Arguments:
123
+ ### `websocket.send(data)`
75
124
 
76
- * **url** `URL | string`
77
- * **options** `WebSocketStreamOptions` (optional)
125
+ <!-- YAML
126
+ added: v5.15.0
127
+ -->
78
128
 
79
- ### WebSocketStream Example
129
+ * `data` {string|ArrayBuffer|TypedArray|DataView|Blob} The data to enqueue for
130
+ transmission.
80
131
 
81
- ```js
82
- const stream = new WebSocketStream('https://echo.websocket.org/')
83
- const { readable, writable } = await stream.opened
132
+ Enqueues `data` to be transmitted to the server. String data is sent as a text
133
+ frame; `ArrayBuffer`, any `TypedArray`, `DataView`, and `Blob` values are sent
134
+ as binary frames. The number of bytes queued is added to
135
+ [`websocket.bufferedAmount`][].
84
136
 
85
- async function read () {
86
- /** @type {ReadableStreamReader} */
87
- const reader = readable.getReader()
137
+ If [`websocket.readyState`][] is `CONNECTING`, an `InvalidStateError`
138
+ `DOMException` is thrown. If the connection is closing or already closed, the
139
+ call is silently ignored.
88
140
 
89
- while (true) {
90
- const { done, value } = await reader.read()
91
- if (done) break
141
+ ```mjs
142
+ ws.send('a text message')
143
+ ws.send(new Uint8Array([1, 2, 3]))
144
+ ```
92
145
 
93
- // do something with value
94
- }
95
- }
146
+ ### `websocket.readyState`
96
147
 
97
- async function write () {
98
- /** @type {WritableStreamDefaultWriter} */
99
- const writer = writable.getWriter()
100
- writer.write('Hello, world!')
101
- writer.releaseLock()
102
- }
148
+ <!-- YAML
149
+ added: v5.15.0
150
+ -->
103
151
 
104
- read()
152
+ * Type: {number}
105
153
 
106
- setInterval(() => write(), 5000)
154
+ The current state of the connection. One of the numeric constants
155
+ `WebSocket.CONNECTING` (`0`), `WebSocket.OPEN` (`1`),
156
+ `WebSocket.CLOSING` (`2`), or `WebSocket.CLOSED` (`3`). This property is
157
+ read-only.
107
158
 
108
- ```
159
+ ### `websocket.bufferedAmount`
160
+
161
+ <!-- YAML
162
+ added: v5.15.0
163
+ -->
164
+
165
+ * Type: {number}
166
+
167
+ The number of bytes of data that have been queued using
168
+ [`websocket.send()`][] but not yet transmitted to the network. This value
169
+ resets to `0` once all queued data is sent. This property is read-only.
170
+
171
+ ### `websocket.url`
172
+
173
+ <!-- YAML
174
+ added: v5.15.0
175
+ -->
176
+
177
+ * Type: {string}
178
+
179
+ The absolute URL of the WebSocket as resolved during construction. This
180
+ property is read-only.
181
+
182
+ ### `websocket.extensions`
183
+
184
+ <!-- YAML
185
+ added: v5.15.0
186
+ -->
187
+
188
+ * Type: {string}
189
+
190
+ The extensions negotiated by the server, taken from the
191
+ `Sec-WebSocket-Extensions` response header. Empty until the connection is
192
+ established. This property is read-only.
193
+
194
+ ### `websocket.protocol`
195
+
196
+ <!-- YAML
197
+ added: v5.15.0
198
+ -->
199
+
200
+ * Type: {string}
201
+
202
+ The subprotocol selected by the server, taken from the
203
+ `Sec-WebSocket-Protocol` response header. Empty until the connection is
204
+ established and only set when a subprotocol was negotiated. This property is
205
+ read-only.
206
+
207
+ ### `websocket.binaryType`
208
+
209
+ <!-- YAML
210
+ added: v5.15.0
211
+ -->
212
+
213
+ * Type: {string} **Default:** `'blob'`.
214
+
215
+ Controls the type used to represent binary data delivered by the
216
+ [`'message'`][] event. Must be either `'blob'` (binary frames are exposed as a
217
+ `Blob`) or `'arraybuffer'` (binary frames are exposed as an `ArrayBuffer`).
218
+ Assigning any other value resets it to `'blob'`.
219
+
220
+ ### `websocket.onopen`
221
+
222
+ <!-- YAML
223
+ added: v5.15.0
224
+ -->
225
+
226
+ * Type: {Function|null} **Default:** `null`.
227
+
228
+ An event handler for the [`'open'`][] event. Setting this property replaces any
229
+ previously registered `onopen` handler.
230
+
231
+ ### `websocket.onerror`
232
+
233
+ <!-- YAML
234
+ added: v5.15.0
235
+ -->
236
+
237
+ * Type: {Function|null} **Default:** `null`.
238
+
239
+ An event handler for the [`'error'`][] event. Setting this property replaces any
240
+ previously registered `onerror` handler.
241
+
242
+ ### `websocket.onclose`
243
+
244
+ <!-- YAML
245
+ added: v5.15.0
246
+ -->
247
+
248
+ * Type: {Function|null} **Default:** `null`.
249
+
250
+ An event handler for the [`'close'`][] event. Setting this property replaces any
251
+ previously registered `onclose` handler.
252
+
253
+ ### `websocket.onmessage`
254
+
255
+ <!-- YAML
256
+ added: v5.15.0
257
+ -->
258
+
259
+ * Type: {Function|null} **Default:** `null`.
260
+
261
+ An event handler for the [`'message'`][] event. Setting this property replaces
262
+ any previously registered `onmessage` handler.
263
+
264
+ ### Event: `'open'`
265
+
266
+ <!-- YAML
267
+ added: v5.21.0
268
+ -->
269
+
270
+ Emitted when the WebSocket connection is established. After this event,
271
+ [`websocket.readyState`][] is `OPEN` and data may be sent with
272
+ [`websocket.send()`][]. The listener receives an `Event`.
273
+
274
+ ### Event: `'message'`
275
+
276
+ <!-- YAML
277
+ added: v7.0.0
278
+ -->
279
+
280
+ Emitted when a message is received from the server. The listener receives a
281
+ `MessageEvent` whose `data` property is a `string` for text frames, and either a
282
+ `Blob` or an `ArrayBuffer` for binary frames depending on
283
+ [`websocket.binaryType`][]. The event's `origin` is the origin of
284
+ [`websocket.url`][].
109
285
 
110
- ## ping(websocket, payload)
111
- Arguments:
286
+ ### Event: `'error'`
112
287
 
113
- * **websocket** `WebSocket` - The WebSocket instance to send the ping frame on
114
- * **payload** `Buffer|undefined` (optional) - Optional payload data to include with the ping frame. Must not exceed 125 bytes.
288
+ <!-- YAML
289
+ added: v7.0.0
290
+ -->
115
291
 
116
- Sends a ping frame to the WebSocket server. The server must respond with a pong frame containing the same payload data. This can be used for keepalive purposes or to verify that the connection is still active.
292
+ Emitted when the connection is terminated abnormally, for example when no close
293
+ frame was received before the underlying transport was lost. The listener
294
+ receives an `ErrorEvent`.
117
295
 
118
- ### Example:
296
+ ### Event: `'close'`
119
297
 
120
- ```js
298
+ <!-- YAML
299
+ added: v7.0.0
300
+ -->
301
+
302
+ Emitted when the connection is closed. The listener receives a `CloseEvent`
303
+ whose `code` and `reason` describe why the connection closed, and whose
304
+ `wasClean` property is `true` only when the closing handshake completed in both
305
+ directions.
306
+
307
+ ## `ping(websocket[, payload])`
308
+
309
+ <!-- YAML
310
+ added: v7.12.0
311
+ -->
312
+
313
+ * `websocket` {WebSocket} The WebSocket to send the ping frame on.
314
+ * `payload` {Buffer} Optional payload to include in the ping frame. Must not
315
+ exceed 125 bytes. **Default:** `undefined`.
316
+
317
+ Sends a ping control frame to the server. A conforming server replies with a
318
+ pong frame containing the same payload, which can be used to keep the connection
319
+ alive or to verify that it is still active.
320
+
321
+ The frame is only sent when the connection is open; if it is connecting,
322
+ closing, or closed, the call is a no-op. A `TypeError` is thrown if `payload`
323
+ is not a `Buffer` or is larger than 125 bytes.
324
+
325
+ ```mjs
121
326
  import { WebSocket, ping } from 'undici'
122
327
 
123
328
  const ws = new WebSocket('wss://echo.websocket.events')
124
329
 
125
330
  ws.addEventListener('open', () => {
126
- // Send ping with no payload
127
331
  ping(ws)
128
-
129
- // Send ping with payload
130
- const payload = Buffer.from('hello')
131
- ping(ws, payload)
332
+ ping(ws, Buffer.from('hello'))
132
333
  })
133
334
  ```
134
335
 
135
- **Note**: A ping frame cannot have a payload larger than 125 bytes. The ping will only be sent if the WebSocket connection is in the OPEN state.
336
+ ## Class: `WebSocketStream`
337
+
338
+ <!-- YAML
339
+ added: v7.0.0
340
+ -->
341
+
342
+ > Stability: 1 - Experimental
343
+
344
+ `WebSocketStream` is a streams-based alternative to the event-based
345
+ [`WebSocket`][] interface, exposing a connection as a pair of `ReadableStream`
346
+ and `WritableStream` objects. See [MDN][MDN WebSocketStream] for background.
347
+
348
+ Constructing a `WebSocketStream` for the first time emits an
349
+ `ExperimentalWarning` with the code `UNDICI-WSS`.
350
+
351
+ ### `new WebSocketStream(url[, options])`
352
+
353
+ <!-- YAML
354
+ added: v7.0.0
355
+ -->
356
+
357
+ > Stability: 1 - Experimental
358
+
359
+ * `url` {URL|string} The URL of the server to connect to.
360
+ * `options` {WebSocketStreamOptions}
361
+ * `protocols` {string|string[]} Subprotocol(s) to request the server use.
362
+ **Default:** `[]`.
363
+ * `signal` {AbortSignal|null} An `AbortSignal` that aborts the opening
364
+ handshake and rejects [`webSocketStream.opened`][] and
365
+ [`webSocketStream.closed`][] when triggered. **Default:** `null`.
366
+
367
+ Creates a new `WebSocketStream` and begins connecting to `url`. As with
368
+ [`new WebSocket()`][], a repeated or invalid subprotocol causes a `SyntaxError`
369
+ `DOMException` to be thrown.
370
+
371
+ ```mjs
372
+ import { WebSocketStream } from 'undici'
373
+
374
+ const stream = new WebSocketStream('wss://echo.websocket.events')
375
+ const { readable, writable } = await stream.opened
376
+
377
+ const writer = writable.getWriter()
378
+ await writer.write('Hello, world!')
379
+ writer.releaseLock()
380
+
381
+ const reader = readable.getReader()
382
+ const { value } = await reader.read()
383
+ console.log('received:', value)
384
+ ```
385
+
386
+ ### `webSocketStream.url`
387
+
388
+ <!-- YAML
389
+ added: v5.15.0
390
+ -->
391
+
392
+ > Stability: 1 - Experimental
393
+
394
+ * Type: {string}
395
+
396
+ The serialized URL of the WebSocket. This property is read-only.
397
+
398
+ ### `webSocketStream.opened`
399
+
400
+ <!-- YAML
401
+ added: v5.15.0
402
+ -->
403
+
404
+ > Stability: 1 - Experimental
405
+
406
+ * Type: {Promise} Fulfills once the connection is established.
407
+
408
+ A promise that resolves with an object describing the open connection, or
409
+ rejects if the connection could not be established. The fulfillment value has
410
+ the following shape:
411
+
412
+ * `extensions` {string} The negotiated extensions.
413
+ * `protocol` {string} The negotiated subprotocol.
414
+ * `readable` {ReadableStream} A stream of incoming messages. Text frames are
415
+ delivered as strings and binary frames as `Uint8Array` chunks.
416
+ * `writable` {WritableStream} A stream for sending messages. Writing a string
417
+ sends a text frame; writing a `BufferSource` sends a binary frame.
418
+
419
+ ### `webSocketStream.closed`
420
+
421
+ <!-- YAML
422
+ added: v5.15.0
423
+ -->
424
+
425
+ > Stability: 1 - Experimental
426
+
427
+ * Type: {Promise} Fulfills once the connection is closed cleanly.
428
+
429
+ A promise that resolves with a `WebSocketCloseInfo` object when the connection
430
+ closes cleanly, or rejects with a [`WebSocketError`][] when it closes
431
+ abnormally. The fulfillment value has the following shape:
432
+
433
+ * `closeCode` {number} The status code the connection was closed with.
434
+ * `reason` {string} The reason the connection was closed with.
435
+
436
+ ### `webSocketStream.close([closeInfo])`
437
+
438
+ <!-- YAML
439
+ added: v5.15.0
440
+ -->
441
+
442
+ > Stability: 1 - Experimental
443
+
444
+ * `closeInfo` {Object}
445
+ * `closeCode` {number} The status code to close with.
446
+ * `reason` {string} The reason to close with. **Default:** `''`.
447
+
448
+ Starts the closing handshake. When `closeInfo` is omitted, the connection is
449
+ closed without a status code.
450
+
451
+ ## Class: `WebSocketError`
452
+
453
+ <!-- YAML
454
+ added: v7.0.0
455
+ -->
456
+
457
+ > Stability: 1 - Experimental
458
+
459
+ * Extends: {DOMException}
460
+
461
+ An error type used by [`WebSocketStream`][] to report close information. It is
462
+ used to reject [`webSocketStream.closed`][] when the connection closes
463
+ abnormally, and may be passed to a stream's abort or cancel operations to close
464
+ the connection with a specific code and reason.
465
+
466
+ ### `new WebSocketError([message[, init]])`
467
+
468
+ <!-- YAML
469
+ added: v7.0.0
470
+ -->
471
+
472
+ > Stability: 1 - Experimental
473
+
474
+ * `message` {string} A human-readable description of the error.
475
+ **Default:** `''`.
476
+ * `init` {Object}
477
+ * `closeCode` {number} The status code to associate with the error.
478
+ * `reason` {string} The reason to associate with the error.
479
+ **Default:** `''`.
480
+
481
+ Creates a new `WebSocketError`. If `reason` is non-empty but no `closeCode` is
482
+ given, `closeCode` defaults to `1000` ("Normal Closure"). The `closeCode` and
483
+ `reason` are validated, so an out-of-range code or an over-long reason throws.
484
+
485
+ ### `webSocketError.closeCode`
486
+
487
+ <!-- YAML
488
+ added: v5.15.0
489
+ -->
490
+
491
+ > Stability: 1 - Experimental
492
+
493
+ * Type: {number|null}
494
+
495
+ The status code associated with the error, or `null` if none was set. This
496
+ property is read-only.
497
+
498
+ ### `webSocketError.reason`
499
+
500
+ <!-- YAML
501
+ added: v5.15.0
502
+ -->
503
+
504
+ > Stability: 1 - Experimental
505
+
506
+ * Type: {string}
507
+
508
+ The reason associated with the error. This property is read-only.
509
+
510
+ ## Read more
136
511
 
137
- ## Read More
512
+ * [MDN: WebSocket][]
513
+ * [RFC 6455][]
514
+ * [WHATWG WebSocket specification][]
138
515
 
139
- - [MDN - WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket)
140
- - [The WebSocket Specification](https://www.rfc-editor.org/rfc/rfc6455)
141
- - [The WHATWG WebSocket Specification](https://websockets.spec.whatwg.org/)
516
+ [MDN WebSocketStream]: https://developer.mozilla.org/docs/Web/API/WebSocketStream
517
+ [MDN: WebSocket]: https://developer.mozilla.org/docs/Web/API/WebSocket
518
+ [RFC 6455]: https://www.rfc-editor.org/rfc/rfc6455
519
+ [WHATWG WebSocket specification]: https://websockets.spec.whatwg.org/
520
+ [`'close'`]: #event-close
521
+ [`'error'`]: #event-error
522
+ [`'message'`]: #event-message
523
+ [`'open'`]: #event-open
524
+ [`ProxyAgent`]: ProxyAgent.md#class-proxyagent
525
+ [`WebSocket`]: #class-websocket
526
+ [`WebSocketError`]: #class-websocketerror
527
+ [`WebSocketStream`]: #class-websocketstream
528
+ [`new WebSocket()`]: #new-websocketurl-protocols
529
+ [`ping()`]: #pingwebsocket-payload
530
+ [`webSocketStream.closed`]: #websocketstreamclosed
531
+ [`webSocketStream.opened`]: #websocketstreamopened
532
+ [`websocket.bufferedAmount`]: #websocketbufferedamount
533
+ [`websocket.binaryType`]: #websocketbinarytype
534
+ [`websocket.readyState`]: #websocketreadystate
535
+ [`websocket.send()`]: #websocketsenddata
536
+ [`websocket.url`]: #websocketurl