@noodleseed/one 0.22.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.
- package/dist/commands/author-loop.d.ts.map +1 -1
- package/dist/commands/author-loop.js +2 -2
- package/dist/commands/author-loop.js.map +1 -1
- package/dist/commands/catalog-dispatch.d.ts.map +1 -1
- package/dist/commands/catalog-dispatch.js +21 -2
- package/dist/commands/catalog-dispatch.js.map +1 -1
- package/dist/commands/deploy-ops.d.ts.map +1 -1
- package/dist/commands/deploy-ops.js +28 -11
- package/dist/commands/deploy-ops.js.map +1 -1
- package/dist/first-run.d.ts +11 -0
- package/dist/first-run.d.ts.map +1 -1
- package/dist/first-run.js +19 -4
- package/dist/first-run.js.map +1 -1
- package/dist/project-scaffold-templates.d.ts +11 -0
- package/dist/project-scaffold-templates.d.ts.map +1 -0
- package/dist/project-scaffold-templates.js +359 -0
- package/dist/project-scaffold-templates.js.map +1 -0
- package/dist/project.d.ts.map +1 -1
- package/dist/project.js +1 -323
- package/dist/project.js.map +1 -1
- package/dist/react.d.ts +2 -2
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +1 -1
- package/dist/react.js.map +1 -1
- package/dist/validate.d.ts +12 -0
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +11 -0
- package/dist/validate.js.map +1 -1
- package/node_modules/@noodle-borg/agent-kit/dist/skill-content.d.ts.map +1 -1
- package/node_modules/@noodle-borg/agent-kit/dist/skill-content.js +6 -9
- package/node_modules/@noodle-borg/agent-kit/dist/skill-content.js.map +1 -1
- package/node_modules/@noodle-borg/agent-kit/package.json +1 -1
- package/node_modules/@noodle-borg/authoring/dist/index.d.ts +3 -3
- package/node_modules/@noodle-borg/authoring/dist/index.d.ts.map +1 -1
- package/node_modules/@noodle-borg/authoring/dist/index.js +1 -1
- package/node_modules/@noodle-borg/authoring/dist/index.js.map +1 -1
- package/node_modules/@noodle-borg/authoring/dist/react/components.d.ts +302 -7
- package/node_modules/@noodle-borg/authoring/dist/react/components.d.ts.map +1 -1
- package/node_modules/@noodle-borg/authoring/dist/react/components.js +39 -7
- package/node_modules/@noodle-borg/authoring/dist/react/components.js.map +1 -1
- package/node_modules/@noodle-borg/authoring/dist/react/index.d.ts +4 -2
- package/node_modules/@noodle-borg/authoring/dist/react/index.d.ts.map +1 -1
- package/node_modules/@noodle-borg/authoring/dist/react/index.js +2 -1
- package/node_modules/@noodle-borg/authoring/dist/react/index.js.map +1 -1
- package/node_modules/@noodle-borg/authoring/dist/react/semantic-components.d.ts +2618 -0
- package/node_modules/@noodle-borg/authoring/dist/react/semantic-components.d.ts.map +1 -0
- package/node_modules/@noodle-borg/authoring/dist/react/semantic-components.js +110 -0
- package/node_modules/@noodle-borg/authoring/dist/react/semantic-components.js.map +1 -0
- package/node_modules/@noodle-borg/authoring/dist/react.d.ts +2 -2
- package/node_modules/@noodle-borg/authoring/dist/react.d.ts.map +1 -1
- package/node_modules/@noodle-borg/authoring/dist/react.js +1 -1
- package/node_modules/@noodle-borg/authoring/dist/react.js.map +1 -1
- package/node_modules/@noodle-borg/authoring/dist/recording.d.ts +1 -1
- package/node_modules/@noodle-borg/authoring/dist/recording.d.ts.map +1 -1
- package/node_modules/@noodle-borg/authoring/dist/recording.js +14 -1
- package/node_modules/@noodle-borg/authoring/dist/recording.js.map +1 -1
- package/node_modules/@noodle-borg/authoring/dist/server.d.ts +25 -2
- package/node_modules/@noodle-borg/authoring/dist/server.d.ts.map +1 -1
- package/node_modules/@noodle-borg/authoring/dist/server.js +7 -3
- package/node_modules/@noodle-borg/authoring/dist/server.js.map +1 -1
- package/node_modules/@noodle-borg/compiler/dist/compile.d.ts.map +1 -1
- package/node_modules/@noodle-borg/compiler/dist/compile.js +20 -8
- package/node_modules/@noodle-borg/compiler/dist/compile.js.map +1 -1
- package/node_modules/@noodle-borg/compiler/dist/manifest/schema.d.ts +2 -0
- package/node_modules/@noodle-borg/compiler/dist/manifest/schema.d.ts.map +1 -1
- package/node_modules/@noodle-borg/compiler/dist/manifest/schema.js +6 -0
- package/node_modules/@noodle-borg/compiler/dist/manifest/schema.js.map +1 -1
- package/node_modules/@noodle-borg/connector-http/package.json +1 -1
- package/node_modules/@noodle-borg/protocol/dist/mapping.d.ts.map +1 -1
- package/node_modules/@noodle-borg/protocol/dist/mapping.js +8 -0
- package/node_modules/@noodle-borg/protocol/dist/mapping.js.map +1 -1
- package/node_modules/hono/dist/adapter/aws-lambda/handler.js +15 -21
- package/node_modules/hono/dist/adapter/bun/websocket.js +3 -1
- package/node_modules/hono/dist/adapter/lambda-edge/handler.js +8 -2
- package/node_modules/hono/dist/cjs/adapter/aws-lambda/handler.js +15 -21
- package/node_modules/hono/dist/cjs/adapter/bun/websocket.js +3 -1
- package/node_modules/hono/dist/cjs/adapter/lambda-edge/handler.js +8 -2
- package/node_modules/hono/dist/cjs/helper/css/common.js +3 -1
- package/node_modules/hono/dist/cjs/helper/css/index.js +9 -1
- package/node_modules/hono/dist/cjs/jsx/base.js +8 -14
- package/node_modules/hono/dist/cjs/jsx/components.js +41 -21
- package/node_modules/hono/dist/cjs/jsx/context.js +131 -5
- package/node_modules/hono/dist/cjs/jsx/streaming.js +9 -7
- package/node_modules/hono/dist/cjs/middleware/cors/index.js +2 -5
- package/node_modules/hono/dist/cjs/middleware/serve-static/index.js +2 -2
- package/node_modules/hono/dist/cjs/utils/body.js +12 -4
- package/node_modules/hono/dist/cjs/utils/buffer.js +2 -1
- package/node_modules/hono/dist/cjs/validator/validator.js +3 -3
- package/node_modules/hono/dist/helper/css/common.js +3 -1
- package/node_modules/hono/dist/helper/css/index.js +9 -1
- package/node_modules/hono/dist/jsx/base.js +15 -15
- package/node_modules/hono/dist/jsx/components.js +42 -22
- package/node_modules/hono/dist/jsx/context.js +129 -5
- package/node_modules/hono/dist/jsx/streaming.js +10 -8
- package/node_modules/hono/dist/middleware/cors/index.js +2 -5
- package/node_modules/hono/dist/middleware/serve-static/index.js +2 -2
- package/node_modules/hono/dist/types/adapter/aws-lambda/handler.d.ts +1 -1
- package/node_modules/hono/dist/types/jsx/base.d.ts +1 -3
- package/node_modules/hono/dist/types/jsx/context.d.ts +39 -0
- package/node_modules/hono/dist/types/middleware/context-storage/index.d.ts +2 -2
- package/node_modules/hono/dist/types/utils/body.d.ts +1 -1
- package/node_modules/hono/dist/utils/body.js +12 -4
- package/node_modules/hono/dist/utils/buffer.js +2 -1
- package/node_modules/hono/dist/validator/validator.js +3 -3
- package/node_modules/hono/package.json +9 -10
- package/node_modules/tailwindcss/dist/chunk-HMCCH6MG.mjs +1 -0
- package/node_modules/tailwindcss/dist/default-theme.mjs +1 -1
- package/node_modules/tailwindcss/dist/lib.js +13 -13
- package/node_modules/tailwindcss/dist/lib.mjs +18 -18
- package/node_modules/tailwindcss/package.json +2 -2
- package/node_modules/undici/README.md +3 -2
- package/node_modules/undici/docs/docs/api/Agent.md +248 -44
- package/node_modules/undici/docs/docs/api/BalancedPool.md +246 -48
- package/node_modules/undici/docs/docs/api/CacheStorage.md +171 -13
- package/node_modules/undici/docs/docs/api/CacheStore.md +294 -98
- package/node_modules/undici/docs/docs/api/Client.md +365 -178
- package/node_modules/undici/docs/docs/api/ClientStats.md +80 -14
- package/node_modules/undici/docs/docs/api/Connector.md +118 -36
- package/node_modules/undici/docs/docs/api/ContentType.md +65 -25
- package/node_modules/undici/docs/docs/api/Cookies.md +125 -47
- package/node_modules/undici/docs/docs/api/Debug.md +34 -18
- package/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +364 -164
- package/node_modules/undici/docs/docs/api/Dispatcher.md +479 -1093
- package/node_modules/undici/docs/docs/api/EnvHttpProxyAgent.md +101 -87
- package/node_modules/undici/docs/docs/api/Errors.md +503 -40
- package/node_modules/undici/docs/docs/api/EventSource.md +294 -32
- package/node_modules/undici/docs/docs/api/Fetch.md +680 -31
- package/node_modules/undici/docs/docs/api/GlobalInstallation.md +78 -98
- package/node_modules/undici/docs/docs/api/H2CClient.md +298 -176
- package/node_modules/undici/docs/docs/api/Interceptors.md +355 -0
- package/node_modules/undici/docs/docs/api/MockAgent.md +314 -322
- package/node_modules/undici/docs/docs/api/MockCallHistory.md +272 -98
- package/node_modules/undici/docs/docs/api/MockCallHistoryLog.md +189 -26
- package/node_modules/undici/docs/docs/api/MockClient.md +151 -33
- package/node_modules/undici/docs/docs/api/MockErrors.md +56 -5
- package/node_modules/undici/docs/docs/api/MockPool.md +299 -263
- package/node_modules/undici/docs/docs/api/Pool.md +235 -43
- package/node_modules/undici/docs/docs/api/PoolStats.md +119 -13
- package/node_modules/undici/docs/docs/api/ProxyAgent.md +179 -160
- package/node_modules/undici/docs/docs/api/RedirectHandler.md +238 -63
- package/node_modules/undici/docs/docs/api/RetryAgent.md +113 -26
- package/node_modules/undici/docs/docs/api/RetryHandler.md +161 -77
- package/node_modules/undici/docs/docs/api/RoundRobinPool.md +166 -72
- package/node_modules/undici/docs/docs/api/SnapshotAgent.md +264 -542
- package/node_modules/undici/docs/docs/api/Socks5ProxyAgent.md +162 -186
- package/node_modules/undici/docs/docs/api/Util.md +68 -11
- package/node_modules/undici/docs/docs/api/WebSocket.md +475 -80
- package/node_modules/undici/docs/docs/api/api-lifecycle.md +100 -32
- package/node_modules/undici/docs/docs/best-practices/client-certificate.md +2 -0
- package/node_modules/undici/docs/docs/best-practices/crawling.md +3 -1
- package/node_modules/undici/docs/docs/best-practices/migrating-from-v7-to-v8.md +6 -4
- package/node_modules/undici/docs/docs/best-practices/mocking-request.md +9 -7
- package/node_modules/undici/docs/docs/best-practices/proxy.md +3 -1
- package/node_modules/undici/docs/docs/best-practices/undici-vs-builtin-fetch.md +10 -8
- package/node_modules/undici/docs/docs/best-practices/writing-tests.md +2 -0
- package/node_modules/undici/docs/docs/{GettingStarted.md → getting-started.md} +22 -19
- package/node_modules/undici/docs/docs/index.md +779 -0
- package/node_modules/undici/docs/docs/site.json +125 -0
- package/node_modules/undici/docs/docs/type-map.json +79 -0
- package/node_modules/undici/lib/api/api-request.js +7 -1
- package/node_modules/undici/lib/api/readable.js +47 -2
- package/node_modules/undici/lib/core/errors.js +20 -0
- package/node_modules/undici/lib/core/request.js +1 -1
- package/node_modules/undici/lib/core/util.js +24 -1
- package/node_modules/undici/lib/dispatcher/client-h1.js +92 -1
- package/node_modules/undici/lib/dispatcher/client-h2.js +322 -118
- package/node_modules/undici/lib/dispatcher/client.js +6 -2
- package/node_modules/undici/lib/dispatcher/dispatcher-base.js +1 -0
- package/node_modules/undici/lib/dispatcher/proxy-agent.js +42 -7
- package/node_modules/undici/lib/dispatcher/socks5-proxy-agent.js +4 -2
- package/node_modules/undici/lib/handler/redirect-handler.js +1 -0
- package/node_modules/undici/lib/handler/retry-handler.js +57 -19
- package/node_modules/undici/lib/util/cache.js +8 -2
- package/node_modules/undici/lib/web/cookies/parse.js +20 -27
- package/node_modules/undici/lib/web/cookies/util.js +1 -1
- package/node_modules/undici/lib/web/eventsource/eventsource.js +7 -18
- package/node_modules/undici/lib/web/eventsource/util.js +32 -1
- package/node_modules/undici/lib/web/fetch/body.js +43 -0
- package/node_modules/undici/lib/web/fetch/constants.js +1 -1
- package/node_modules/undici/lib/web/fetch/index.js +11 -2
- package/node_modules/undici/lib/web/fetch/request.js +1 -0
- package/node_modules/undici/lib/web/fetch/util.js +4 -1
- package/node_modules/undici/lib/web/websocket/receiver.js +20 -3
- package/node_modules/undici/lib/web/websocket/stream/websocketstream.js +8 -1
- package/node_modules/undici/lib/web/websocket/websocket.js +3 -1
- package/node_modules/undici/package.json +1 -1
- package/node_modules/undici/types/client.d.ts +6 -1
- package/node_modules/undici/types/cookies.d.ts +1 -1
- package/node_modules/undici/types/errors.d.ts +10 -0
- package/node_modules/undici/types/fetch.d.ts +1 -0
- package/node_modules/undici/types/handlers.d.ts +2 -0
- package/node_modules/undici/types/proxy-agent.d.ts +7 -0
- package/package.json +4 -4
- package/react/styles.css +510 -5
- package/react/styles.source.css +850 -0
- package/node_modules/hono/dist/tsconfig.build.tsbuildinfo +0 -1
- package/node_modules/tailwindcss/dist/chunk-XVOTX5KS.mjs +0 -1
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
# EventSource
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<!--introduced_in=v6.5.0-->
|
|
4
|
+
<!--type=module-->
|
|
5
|
+
<!-- source_link=lib/web/eventsource/eventsource.js -->
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
for [Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events).
|
|
7
|
+
> Stability: 1 - Experimental
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
`EventSource` is a [WHATWG-conformant][] implementation of the
|
|
10
|
+
[server-sent events][] interface. It opens a persistent HTTP connection to a
|
|
11
|
+
server that responds with the `text/event-stream` content type and dispatches
|
|
12
|
+
the events it receives without closing the connection.
|
|
12
13
|
|
|
13
14
|
```mjs
|
|
14
15
|
import { EventSource } from 'undici'
|
|
@@ -19,11 +20,266 @@ eventSource.onmessage = (event) => {
|
|
|
19
20
|
}
|
|
20
21
|
```
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
Constructing an `EventSource` for the first time emits a one-time
|
|
24
|
+
`ExperimentalWarning` with the code `'UNDICI-ES'`. The interface is also
|
|
25
|
+
installed onto `globalThis` as `globalThis.EventSource`.
|
|
26
|
+
|
|
27
|
+
## Class: `EventSource`
|
|
28
|
+
|
|
29
|
+
<!-- YAML
|
|
30
|
+
added: v6.5.0
|
|
31
|
+
-->
|
|
32
|
+
|
|
33
|
+
> Stability: 1 - Experimental
|
|
34
|
+
|
|
35
|
+
* Extends: {EventTarget}
|
|
36
|
+
|
|
37
|
+
The `EventSource` interface receives server-sent events over an HTTP
|
|
38
|
+
connection. Instances are created with the [`new EventSource()`](#new-eventsourceurl-eventsourceinitdict)
|
|
39
|
+
constructor and emit [`'open'`](#event-open), [`'message'`](#event-message), and
|
|
40
|
+
[`'error'`](#event-error) events.
|
|
41
|
+
|
|
42
|
+
### `new EventSource(url[, eventSourceInitDict])`
|
|
43
|
+
|
|
44
|
+
<!-- YAML
|
|
45
|
+
added: v6.5.0
|
|
46
|
+
-->
|
|
23
47
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
48
|
+
> Stability: 1 - Experimental
|
|
49
|
+
|
|
50
|
+
* `url` {string|URL} The URL of the event stream. Relative URLs are resolved
|
|
51
|
+
against the environment's base URL.
|
|
52
|
+
* `eventSourceInitDict` {Object} (optional)
|
|
53
|
+
* `withCredentials` {boolean} When `true`, the request is made with the
|
|
54
|
+
credentials mode set to `include` and CORS attribute state set to
|
|
55
|
+
`use-credentials`; otherwise the credentials mode is `same-origin`.
|
|
56
|
+
**Default:** `false`.
|
|
57
|
+
* `dispatcher` {Dispatcher} The dispatcher used for the underlying request.
|
|
58
|
+
**Default:** the global dispatcher.
|
|
59
|
+
|
|
60
|
+
> Stability: 0 - Deprecated. Use `node.dispatcher` instead.
|
|
61
|
+
* `node` {Object} undici-specific extensions to the standard
|
|
62
|
+
`EventSourceInit` dictionary.
|
|
63
|
+
* `dispatcher` {Dispatcher} The dispatcher used for the underlying request.
|
|
64
|
+
**Default:** the global dispatcher.
|
|
65
|
+
* `reconnectionTime` {number} The reconnection time, in milliseconds, to
|
|
66
|
+
wait before re-establishing a dropped connection. The server may override
|
|
67
|
+
this value with a `retry` field. **Default:** `3000`.
|
|
68
|
+
|
|
69
|
+
Creates a new `EventSource` and immediately begins connecting to `url`. The
|
|
70
|
+
request is sent with the `Accept: text/event-stream` header, a cache mode of
|
|
71
|
+
`no-store`, and an initiator type of `other`.
|
|
72
|
+
|
|
73
|
+
If `url` cannot be parsed, a `SyntaxError` `DOMException` is thrown.
|
|
74
|
+
|
|
75
|
+
```mjs
|
|
76
|
+
import { EventSource } from 'undici'
|
|
77
|
+
|
|
78
|
+
const eventSource = new EventSource('http://localhost:3000', {
|
|
79
|
+
withCredentials: true
|
|
80
|
+
})
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
A custom [`Dispatcher`][] can be supplied to control the underlying request, for
|
|
84
|
+
example to add request headers:
|
|
85
|
+
|
|
86
|
+
```mjs
|
|
87
|
+
import { EventSource, Agent } from 'undici'
|
|
88
|
+
|
|
89
|
+
class CustomHeaderAgent extends Agent {
|
|
90
|
+
dispatch (opts) {
|
|
91
|
+
opts.headers['x-custom-header'] = 'hello world'
|
|
92
|
+
return super.dispatch(...arguments)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const eventSource = new EventSource('http://localhost:3000', {
|
|
97
|
+
node: {
|
|
98
|
+
dispatcher: new CustomHeaderAgent()
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### `eventSource.close()`
|
|
104
|
+
|
|
105
|
+
<!-- YAML
|
|
106
|
+
added: v6.5.0
|
|
107
|
+
-->
|
|
108
|
+
|
|
109
|
+
> Stability: 1 - Experimental
|
|
110
|
+
|
|
111
|
+
* Returns: {undefined}
|
|
112
|
+
|
|
113
|
+
Closes the connection, if any, aborts the underlying request, and sets
|
|
114
|
+
[`eventSource.readyState`](#eventsourcereadystate) to `CLOSED`. Once closed, the
|
|
115
|
+
`EventSource` does not attempt to reconnect. Calling `close()` on an already
|
|
116
|
+
closed `EventSource` has no effect.
|
|
117
|
+
|
|
118
|
+
### `eventSource.readyState`
|
|
119
|
+
|
|
120
|
+
<!-- YAML
|
|
121
|
+
added: v6.5.0
|
|
122
|
+
-->
|
|
123
|
+
|
|
124
|
+
> Stability: 1 - Experimental
|
|
125
|
+
|
|
126
|
+
* Type: {number}
|
|
127
|
+
|
|
128
|
+
A read-only number representing the state of the connection. It is one of the
|
|
129
|
+
following constants:
|
|
130
|
+
|
|
131
|
+
* [`EventSource.CONNECTING`](#eventsourceconnecting) (`0`) — the connection has
|
|
132
|
+
not yet been established, or it was closed and is being re-established.
|
|
133
|
+
* [`EventSource.OPEN`](#eventsourceopen) (`1`) — the connection is open and
|
|
134
|
+
events are being dispatched as they are received.
|
|
135
|
+
* [`EventSource.CLOSED`](#eventsourceclosed) (`2`) — the connection is not open
|
|
136
|
+
and is not being re-established.
|
|
137
|
+
|
|
138
|
+
### `eventSource.url`
|
|
139
|
+
|
|
140
|
+
<!-- YAML
|
|
141
|
+
added: v6.5.0
|
|
142
|
+
-->
|
|
143
|
+
|
|
144
|
+
> Stability: 1 - Experimental
|
|
145
|
+
|
|
146
|
+
* Type: {string}
|
|
147
|
+
|
|
148
|
+
A read-only string providing the URL of the event stream, after resolution
|
|
149
|
+
against the environment's base URL.
|
|
150
|
+
|
|
151
|
+
### `eventSource.withCredentials`
|
|
152
|
+
|
|
153
|
+
<!-- YAML
|
|
154
|
+
added: v6.5.0
|
|
155
|
+
-->
|
|
156
|
+
|
|
157
|
+
> Stability: 1 - Experimental
|
|
158
|
+
|
|
159
|
+
* Type: {boolean}
|
|
160
|
+
|
|
161
|
+
A read-only boolean indicating whether the `EventSource` was instantiated with
|
|
162
|
+
CORS credentials (`true`), or not (`false`, the default). It reflects the
|
|
163
|
+
`withCredentials` option passed to the constructor.
|
|
164
|
+
|
|
165
|
+
### `eventSource.onopen`
|
|
166
|
+
|
|
167
|
+
<!-- YAML
|
|
168
|
+
added: v6.5.0
|
|
169
|
+
-->
|
|
170
|
+
|
|
171
|
+
> Stability: 1 - Experimental
|
|
172
|
+
|
|
173
|
+
* Type: {Function|null} **Default:** `null`.
|
|
174
|
+
|
|
175
|
+
An event handler that is invoked when an [`'open'`](#event-open) event is
|
|
176
|
+
dispatched. Assigning a function registers it as the handler; assigning `null`
|
|
177
|
+
removes the current handler.
|
|
178
|
+
|
|
179
|
+
### `eventSource.onmessage`
|
|
180
|
+
|
|
181
|
+
<!-- YAML
|
|
182
|
+
added: v6.5.0
|
|
183
|
+
-->
|
|
184
|
+
|
|
185
|
+
> Stability: 1 - Experimental
|
|
186
|
+
|
|
187
|
+
* Type: {Function|null} **Default:** `null`.
|
|
188
|
+
|
|
189
|
+
An event handler that is invoked when a [`'message'`](#event-message) event is
|
|
190
|
+
dispatched. Assigning a function registers it as the handler; assigning `null`
|
|
191
|
+
removes the current handler.
|
|
192
|
+
|
|
193
|
+
### `eventSource.onerror`
|
|
194
|
+
|
|
195
|
+
<!-- YAML
|
|
196
|
+
added: v6.5.0
|
|
197
|
+
-->
|
|
198
|
+
|
|
199
|
+
> Stability: 1 - Experimental
|
|
200
|
+
|
|
201
|
+
* Type: {Function|null} **Default:** `null`.
|
|
202
|
+
|
|
203
|
+
An event handler that is invoked when an [`'error'`](#event-error) event is
|
|
204
|
+
dispatched. Assigning a function registers it as the handler; assigning `null`
|
|
205
|
+
removes the current handler.
|
|
206
|
+
|
|
207
|
+
### `EventSource.CONNECTING`
|
|
208
|
+
|
|
209
|
+
<!-- YAML
|
|
210
|
+
added: v6.5.0
|
|
211
|
+
-->
|
|
212
|
+
|
|
213
|
+
> Stability: 1 - Experimental
|
|
214
|
+
|
|
215
|
+
* Type: {number}
|
|
216
|
+
|
|
217
|
+
The numeric constant `0`, representing the `CONNECTING`
|
|
218
|
+
[`readyState`](#eventsourcereadystate). It is defined as a read-only,
|
|
219
|
+
non-writable property on both the `EventSource` constructor and instances.
|
|
220
|
+
|
|
221
|
+
### `EventSource.OPEN`
|
|
222
|
+
|
|
223
|
+
<!-- YAML
|
|
224
|
+
added: v6.5.0
|
|
225
|
+
-->
|
|
226
|
+
|
|
227
|
+
> Stability: 1 - Experimental
|
|
228
|
+
|
|
229
|
+
* Type: {number}
|
|
230
|
+
|
|
231
|
+
The numeric constant `1`, representing the `OPEN`
|
|
232
|
+
[`readyState`](#eventsourcereadystate). It is defined as a read-only,
|
|
233
|
+
non-writable property on both the `EventSource` constructor and instances.
|
|
234
|
+
|
|
235
|
+
### `EventSource.CLOSED`
|
|
236
|
+
|
|
237
|
+
<!-- YAML
|
|
238
|
+
added: v6.5.0
|
|
239
|
+
-->
|
|
240
|
+
|
|
241
|
+
> Stability: 1 - Experimental
|
|
242
|
+
|
|
243
|
+
* Type: {number}
|
|
244
|
+
|
|
245
|
+
The numeric constant `2`, representing the `CLOSED`
|
|
246
|
+
[`readyState`](#eventsourcereadystate). It is defined as a read-only,
|
|
247
|
+
non-writable property on both the `EventSource` constructor and instances.
|
|
248
|
+
|
|
249
|
+
### Event: `'open'`
|
|
250
|
+
|
|
251
|
+
<!-- YAML
|
|
252
|
+
added: v6.5.0
|
|
253
|
+
-->
|
|
254
|
+
|
|
255
|
+
> Stability: 1 - Experimental
|
|
256
|
+
|
|
257
|
+
Emitted when the connection is established and the
|
|
258
|
+
[`readyState`](#eventsourcereadystate) becomes `OPEN`. The listener receives an
|
|
259
|
+
{Event}.
|
|
260
|
+
|
|
261
|
+
```mjs
|
|
262
|
+
import { EventSource } from 'undici'
|
|
263
|
+
|
|
264
|
+
const eventSource = new EventSource('http://localhost:3000')
|
|
265
|
+
eventSource.addEventListener('open', () => {
|
|
266
|
+
console.log('connection opened')
|
|
267
|
+
})
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### Event: `'message'`
|
|
271
|
+
|
|
272
|
+
<!-- YAML
|
|
273
|
+
added: v6.15.0
|
|
274
|
+
-->
|
|
275
|
+
|
|
276
|
+
> Stability: 1 - Experimental
|
|
277
|
+
|
|
278
|
+
Emitted when a message that has no explicit `event` field is received. The
|
|
279
|
+
listener receives a {MessageEvent} whose `data`, `lastEventId`, and `origin`
|
|
280
|
+
properties are populated from the server-sent event. Named events (those with an
|
|
281
|
+
`event` field) are dispatched under their own type and must be subscribed to with
|
|
282
|
+
[`addEventListener()`][].
|
|
27
283
|
|
|
28
284
|
```mjs
|
|
29
285
|
import { createServer } from 'node:http'
|
|
@@ -49,44 +305,50 @@ const server = createServer((request, response) => {
|
|
|
49
305
|
server.listen(3000, () => {
|
|
50
306
|
const eventSource = new EventSource('http://localhost:3000')
|
|
51
307
|
|
|
308
|
+
// Named event, delivered under its own type.
|
|
52
309
|
eventSource.addEventListener('ping', (event) => {
|
|
53
310
|
console.log('ping:', event.data)
|
|
54
311
|
})
|
|
55
312
|
|
|
313
|
+
// Unnamed event, delivered as 'message'.
|
|
56
314
|
eventSource.onmessage = (event) => {
|
|
57
315
|
console.log('message:', event.data)
|
|
58
316
|
}
|
|
59
|
-
|
|
60
|
-
eventSource.onerror = () => {
|
|
61
|
-
eventSource.close()
|
|
62
|
-
server.close()
|
|
63
|
-
}
|
|
64
317
|
})
|
|
65
318
|
```
|
|
66
319
|
|
|
67
|
-
|
|
68
|
-
`addEventListener()` to subscribe to named events.
|
|
320
|
+
### Event: `'error'`
|
|
69
321
|
|
|
70
|
-
|
|
322
|
+
<!-- YAML
|
|
323
|
+
added: v6.5.0
|
|
324
|
+
changes:
|
|
325
|
+
- version: v7.11.0
|
|
326
|
+
pr-url: https://github.com/nodejs/undici/pull/4247
|
|
327
|
+
description: The connection is no longer re-established after a network
|
|
328
|
+
error; the `EventSource` is closed instead.
|
|
329
|
+
-->
|
|
71
330
|
|
|
72
|
-
|
|
331
|
+
> Stability: 1 - Experimental
|
|
73
332
|
|
|
74
|
-
|
|
333
|
+
Emitted when the connection fails or is interrupted. The listener receives an
|
|
334
|
+
{Event}. When the failure is recoverable, the `EventSource` transitions back to
|
|
335
|
+
`CONNECTING` and retries after the reconnection time; when it is not, the
|
|
336
|
+
`EventSource` transitions to `CLOSED` and does not reconnect.
|
|
75
337
|
|
|
76
338
|
```mjs
|
|
77
|
-
import { EventSource
|
|
339
|
+
import { EventSource } from 'undici'
|
|
78
340
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
341
|
+
const eventSource = new EventSource('http://localhost:3000')
|
|
342
|
+
eventSource.onerror = () => {
|
|
343
|
+
if (eventSource.readyState === EventSource.CLOSED) {
|
|
344
|
+
console.log('connection closed')
|
|
345
|
+
} else {
|
|
346
|
+
console.log('reconnecting')
|
|
83
347
|
}
|
|
84
348
|
}
|
|
85
|
-
|
|
86
|
-
const eventSource = new EventSource('http://localhost:3000', {
|
|
87
|
-
dispatcher: new CustomHeaderAgent()
|
|
88
|
-
})
|
|
89
349
|
```
|
|
90
350
|
|
|
91
|
-
|
|
92
|
-
[
|
|
351
|
+
[WHATWG-conformant]: https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events
|
|
352
|
+
[`Dispatcher`]: Dispatcher.md#class-dispatcher
|
|
353
|
+
[`addEventListener()`]: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
|
|
354
|
+
[server-sent events]: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events
|