GeezerVison is showing github.com — lib: add EventSource Client · nodejs/node@02b36cb
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .eslintrc.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -348,6 +348,7 @@ module.exports = { | 348 | 348 | Crypto: 'readable', | 349 | 349 | CryptoKey: 'readable', | 350 | 350 | DecompressionStream: 'readable', | | 351 | + EventSource: 'readable', | 351 | 352 | fetch: 'readable', | 352 | 353 | FormData: 'readable', | 353 | 354 | ReadableStream: 'readable', | |
Collapse file Copy file name to clipboardExpand all lines: doc/api/cli.md +10Lines changed: 10 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -898,6 +898,14 @@ CommonJS. This includes the following: | 898 | 898 | * Lexical redeclarations of the CommonJS wrapper variables (`require`, `module`, | 899 | 899 | `exports`, `__dirname`, `__filename`). | 900 | 900 |
| | 901 | +### `--experimental-eventsource` | | 902 | + | | 903 | +<!-- YAML | | 904 | +added: REPLACEME | | 905 | +--> | | 906 | + | | 907 | +Enable exposition of [EventSource Web API][] on the global scope. | | 908 | + | 901 | 909 | ### `--experimental-import-meta-resolve` | 902 | 910 |
| 903 | 911 | <!-- YAML | @@ -2697,6 +2705,7 @@ one is included in the list below. | 2697 | 2705 | * `--experimental-abortcontroller` | 2698 | 2706 | * `--experimental-default-type` | 2699 | 2707 | * `--experimental-detect-module` | | 2708 | +* `--experimental-eventsource` | 2700 | 2709 | * `--experimental-import-meta-resolve` | 2701 | 2710 | * `--experimental-json-modules` | 2702 | 2711 | * `--experimental-loader` | @@ -3172,6 +3181,7 @@ done | 3172 | 3181 | [CustomEvent Web API]: https://dom.spec.whatwg.org/#customevent | 3173 | 3182 | [DEP0025 warning]: deprecations.md#dep0025-requirenodesys | 3174 | 3183 | [ECMAScript module]: esm.md#modules-ecmascript-modules | | 3184 | +[EventSource Web API]: https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events | 3175 | 3185 | [ExperimentalWarning: `vm.measureMemory` is an experimental feature]: vm.md#vmmeasurememoryoptions | 3176 | 3186 | [Fetch API]: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API | 3177 | 3187 | [File System Permissions]: permissions.md#file-system-permissions | |
Collapse file Copy file name to clipboardExpand all lines: doc/node.1 +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -191,6 +191,9 @@ Use this flag to enable ShadowRealm support. | 191 | 191 | .It Fl -experimental-test-coverage | 192 | 192 | Enable code coverage in the test runner. | 193 | 193 | . | | 194 | +.It Fl -experimental-eventsource | | 195 | +Enable experimental support for the EventSource Web API. | | 196 | +. | 194 | 197 | .It Fl -experimental-websocket | 195 | 198 | Enable experimental support for the WebSocket API. | 196 | 199 | . | |
Collapse file Copy file name to clipboardExpand all lines: lib/.eslintrc.yaml +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -152,6 +152,8 @@ rules: | 152 | 152 | message: Use `const { Crypto } = require('internal/crypto/webcrypto');` instead of the global. | 153 | 153 | - name: CryptoKey | 154 | 154 | message: Use `const { CryptoKey } = require('internal/crypto/webcrypto');` instead of the global. | | 155 | + - name: EventSource | | 156 | + message: Use `const { EventSource } = require('internal/deps/undici/undici');` instead of the global. | 155 | 157 | - name: fetch | 156 | 158 | message: Use `const { fetch } = require('internal/deps/undici/undici');` instead of the global. | 157 | 159 | - name: global | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/bootstrap/web/exposed-window-or-worker.js +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -81,6 +81,9 @@ exposeLazyInterfaces(globalThis, 'internal/deps/undici/undici', [ | 81 | 81 | 'FormData', 'Headers', 'Request', 'Response', | 82 | 82 | ]); | 83 | 83 |
| | 84 | +// https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events.org/ | | 85 | +exposeLazyInterfaces(globalThis, 'internal/deps/undici/undici', ['EventSource']); | | 86 | + | 84 | 87 | // The WebAssembly Web API which relies on Response. | 85 | 88 | // https:// webassembly.github.io/spec/web-api/#streaming-modules | 86 | 89 | internalBinding('wasm_web_api').setImplementation((streamState, source) => { | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/process/pre_execution.js +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -109,6 +109,7 @@ function prepareExecution(options) { | 109 | 109 | setupUndici(); | 110 | 110 | setupWebCrypto(); | 111 | 111 | setupCustomEvent(); | | 112 | + setupEventsource(); | 112 | 113 | setupCodeCoverage(); | 113 | 114 | setupDebugEnv(); | 114 | 115 | // Process initial diagnostic reporting configuration, if present. | @@ -328,6 +329,13 @@ function setupUndici() { | 328 | 329 | } | 329 | 330 | } | 330 | 331 |
| | 332 | +// https://html.spec.whatwg.org/multipage/server-sent-events.html | | 333 | +function setupEventsource() { | | 334 | + if (!getOptionValue('--experimental-eventsource')) { | | 335 | + delete globalThis.EventSource; | | 336 | + } | | 337 | +} | | 338 | + | 331 | 339 | // TODO(aduh95): move this to internal/bootstrap/web/* when the CLI flag is | 332 | 340 | // removed. | 333 | 341 | function setupWebCrypto() { | |
Collapse file Copy file name to clipboardExpand all lines: src/node_options.cc +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -406,6 +406,11 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { | 406 | 406 | &EnvironmentOptions::enable_source_maps, | 407 | 407 | kAllowedInEnvvar); | 408 | 408 | AddOption("--experimental-abortcontroller", "", NoOp{}, kAllowedInEnvvar); | | 409 | + AddOption("--experimental-eventsource", | | 410 | + "experimental EventSource API", | | 411 | + &EnvironmentOptions::experimental_eventsource, | | 412 | + kAllowedInEnvvar, | | 413 | + false); | 409 | 414 | AddOption("--experimental-fetch", | 410 | 415 | "experimental Fetch API", | 411 | 416 | &EnvironmentOptions::experimental_fetch, | |
Collapse file Copy file name to clipboardExpand all lines: src/node_options.h +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -115,6 +115,7 @@ class EnvironmentOptions : public Options { | 115 | 115 | bool require_module = false; | 116 | 116 | std::string dns_result_order; | 117 | 117 | bool enable_source_maps = false; | | 118 | + bool experimental_eventsource = false; | 118 | 119 | bool experimental_fetch = true; | 119 | 120 | bool experimental_websocket = false; | 120 | 121 | bool experimental_global_customevent = true; | |
Collapse file Copy file name to clipboardExpand all lines: test/common/globals.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -124,6 +124,7 @@ const webIdlExposedWindow = new Set([ | 124 | 124 | 'Request', | 125 | 125 | 'Response', | 126 | 126 | 'WebSocket', | | 127 | + 'EventSource', | 127 | 128 | ]); | 128 | 129 |
| 129 | 130 | const nodeGlobals = new Set([ | |
Collapse file Copy file name to clipboardExpand all lines: test/common/index.js +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -330,6 +330,10 @@ if (global.structuredClone) { | 330 | 330 | knownGlobals.push(global.structuredClone); | 331 | 331 | } | 332 | 332 |
| | 333 | +if (global.EventSource) { | | 334 | + knownGlobals.push(EventSource); | | 335 | +} | | 336 | + | 333 | 337 | if (global.fetch) { | 334 | 338 | knownGlobals.push(fetch); | 335 | 339 | } | |
|