deepv-code 1.0.182 → 1.0.183
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/bundle/dvcode.js +635 -635
- package/package.json +1 -1
- package/bundle/assets/help/README.md +0 -113
- package/bundle/assets/sounds/README.md +0 -74
- package/bundle/node_modules/undici/LICENSE +0 -21
- package/bundle/node_modules/undici/README.md +0 -472
- package/bundle/node_modules/undici/docs/docs/api/Agent.md +0 -83
- package/bundle/node_modules/undici/docs/docs/api/BalancedPool.md +0 -99
- package/bundle/node_modules/undici/docs/docs/api/CacheStorage.md +0 -30
- package/bundle/node_modules/undici/docs/docs/api/CacheStore.md +0 -151
- package/bundle/node_modules/undici/docs/docs/api/Client.md +0 -281
- package/bundle/node_modules/undici/docs/docs/api/ClientStats.md +0 -27
- package/bundle/node_modules/undici/docs/docs/api/Connector.md +0 -115
- package/bundle/node_modules/undici/docs/docs/api/ContentType.md +0 -57
- package/bundle/node_modules/undici/docs/docs/api/Cookies.md +0 -101
- package/bundle/node_modules/undici/docs/docs/api/Debug.md +0 -62
- package/bundle/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +0 -204
- package/bundle/node_modules/undici/docs/docs/api/Dispatcher.md +0 -1200
- package/bundle/node_modules/undici/docs/docs/api/EnvHttpProxyAgent.md +0 -159
- package/bundle/node_modules/undici/docs/docs/api/Errors.md +0 -49
- package/bundle/node_modules/undici/docs/docs/api/EventSource.md +0 -45
- package/bundle/node_modules/undici/docs/docs/api/Fetch.md +0 -52
- package/bundle/node_modules/undici/docs/docs/api/H2CClient.md +0 -262
- package/bundle/node_modules/undici/docs/docs/api/MockAgent.md +0 -603
- package/bundle/node_modules/undici/docs/docs/api/MockCallHistory.md +0 -197
- package/bundle/node_modules/undici/docs/docs/api/MockCallHistoryLog.md +0 -43
- package/bundle/node_modules/undici/docs/docs/api/MockClient.md +0 -77
- package/bundle/node_modules/undici/docs/docs/api/MockErrors.md +0 -12
- package/bundle/node_modules/undici/docs/docs/api/MockPool.md +0 -548
- package/bundle/node_modules/undici/docs/docs/api/Pool.md +0 -84
- package/bundle/node_modules/undici/docs/docs/api/PoolStats.md +0 -35
- package/bundle/node_modules/undici/docs/docs/api/ProxyAgent.md +0 -227
- package/bundle/node_modules/undici/docs/docs/api/RedirectHandler.md +0 -96
- package/bundle/node_modules/undici/docs/docs/api/RetryAgent.md +0 -45
- package/bundle/node_modules/undici/docs/docs/api/RetryHandler.md +0 -117
- package/bundle/node_modules/undici/docs/docs/api/Util.md +0 -25
- package/bundle/node_modules/undici/docs/docs/api/WebSocket.md +0 -85
- package/bundle/node_modules/undici/docs/docs/api/api-lifecycle.md +0 -91
- package/bundle/node_modules/undici/docs/docs/best-practices/client-certificate.md +0 -64
- package/bundle/node_modules/undici/docs/docs/best-practices/mocking-request.md +0 -190
- package/bundle/node_modules/undici/docs/docs/best-practices/proxy.md +0 -127
- package/bundle/node_modules/undici/docs/docs/best-practices/writing-tests.md +0 -20
- package/bundle/node_modules/undici/index-fetch.js +0 -35
- package/bundle/node_modules/undici/index.d.ts +0 -3
- package/bundle/node_modules/undici/index.js +0 -183
- package/bundle/node_modules/undici/lib/api/abort-signal.js +0 -59
- package/bundle/node_modules/undici/lib/api/api-connect.js +0 -110
- package/bundle/node_modules/undici/lib/api/api-pipeline.js +0 -252
- package/bundle/node_modules/undici/lib/api/api-request.js +0 -199
- package/bundle/node_modules/undici/lib/api/api-stream.js +0 -209
- package/bundle/node_modules/undici/lib/api/api-upgrade.js +0 -110
- package/bundle/node_modules/undici/lib/api/index.js +0 -7
- package/bundle/node_modules/undici/lib/api/readable.js +0 -558
- package/bundle/node_modules/undici/lib/api/util.js +0 -95
- package/bundle/node_modules/undici/lib/cache/memory-cache-store.js +0 -234
- package/bundle/node_modules/undici/lib/cache/sqlite-cache-store.js +0 -461
- package/bundle/node_modules/undici/lib/core/connect.js +0 -164
- package/bundle/node_modules/undici/lib/core/constants.js +0 -143
- package/bundle/node_modules/undici/lib/core/diagnostics.js +0 -196
- package/bundle/node_modules/undici/lib/core/errors.js +0 -244
- package/bundle/node_modules/undici/lib/core/request.js +0 -397
- package/bundle/node_modules/undici/lib/core/symbols.js +0 -68
- package/bundle/node_modules/undici/lib/core/tree.js +0 -160
- package/bundle/node_modules/undici/lib/core/util.js +0 -988
- package/bundle/node_modules/undici/lib/dispatcher/agent.js +0 -135
- package/bundle/node_modules/undici/lib/dispatcher/balanced-pool.js +0 -206
- package/bundle/node_modules/undici/lib/dispatcher/client-h1.js +0 -1615
- package/bundle/node_modules/undici/lib/dispatcher/client-h2.js +0 -798
- package/bundle/node_modules/undici/lib/dispatcher/client.js +0 -614
- package/bundle/node_modules/undici/lib/dispatcher/dispatcher-base.js +0 -161
- package/bundle/node_modules/undici/lib/dispatcher/dispatcher.js +0 -48
- package/bundle/node_modules/undici/lib/dispatcher/env-http-proxy-agent.js +0 -151
- package/bundle/node_modules/undici/lib/dispatcher/fixed-queue.js +0 -159
- package/bundle/node_modules/undici/lib/dispatcher/h2c-client.js +0 -122
- package/bundle/node_modules/undici/lib/dispatcher/pool-base.js +0 -191
- package/bundle/node_modules/undici/lib/dispatcher/pool.js +0 -118
- package/bundle/node_modules/undici/lib/dispatcher/proxy-agent.js +0 -275
- package/bundle/node_modules/undici/lib/dispatcher/retry-agent.js +0 -35
- package/bundle/node_modules/undici/lib/global.js +0 -32
- package/bundle/node_modules/undici/lib/handler/cache-handler.js +0 -448
- package/bundle/node_modules/undici/lib/handler/cache-revalidation-handler.js +0 -124
- package/bundle/node_modules/undici/lib/handler/decorator-handler.js +0 -67
- package/bundle/node_modules/undici/lib/handler/redirect-handler.js +0 -227
- package/bundle/node_modules/undici/lib/handler/retry-handler.js +0 -342
- package/bundle/node_modules/undici/lib/handler/unwrap-handler.js +0 -96
- package/bundle/node_modules/undici/lib/handler/wrap-handler.js +0 -95
- package/bundle/node_modules/undici/lib/interceptor/cache.js +0 -372
- package/bundle/node_modules/undici/lib/interceptor/dns.js +0 -432
- package/bundle/node_modules/undici/lib/interceptor/dump.js +0 -111
- package/bundle/node_modules/undici/lib/interceptor/redirect.js +0 -21
- package/bundle/node_modules/undici/lib/interceptor/response-error.js +0 -95
- package/bundle/node_modules/undici/lib/interceptor/retry.js +0 -19
- package/bundle/node_modules/undici/lib/llhttp/.gitkeep +0 -0
- package/bundle/node_modules/undici/lib/llhttp/constants.d.ts +0 -97
- package/bundle/node_modules/undici/lib/llhttp/constants.js +0 -498
- package/bundle/node_modules/undici/lib/llhttp/constants.js.map +0 -1
- package/bundle/node_modules/undici/lib/llhttp/llhttp-wasm.js +0 -15
- package/bundle/node_modules/undici/lib/llhttp/llhttp_simd-wasm.js +0 -15
- package/bundle/node_modules/undici/lib/llhttp/utils.d.ts +0 -2
- package/bundle/node_modules/undici/lib/llhttp/utils.js +0 -15
- package/bundle/node_modules/undici/lib/llhttp/utils.js.map +0 -1
- package/bundle/node_modules/undici/lib/mock/mock-agent.js +0 -224
- package/bundle/node_modules/undici/lib/mock/mock-call-history.js +0 -248
- package/bundle/node_modules/undici/lib/mock/mock-client.js +0 -64
- package/bundle/node_modules/undici/lib/mock/mock-errors.js +0 -19
- package/bundle/node_modules/undici/lib/mock/mock-interceptor.js +0 -209
- package/bundle/node_modules/undici/lib/mock/mock-pool.js +0 -64
- package/bundle/node_modules/undici/lib/mock/mock-symbols.js +0 -31
- package/bundle/node_modules/undici/lib/mock/mock-utils.js +0 -433
- package/bundle/node_modules/undici/lib/mock/pending-interceptors-formatter.js +0 -43
- package/bundle/node_modules/undici/lib/util/cache.js +0 -368
- package/bundle/node_modules/undici/lib/util/date.js +0 -259
- package/bundle/node_modules/undici/lib/util/stats.js +0 -32
- package/bundle/node_modules/undici/lib/util/timers.js +0 -423
- package/bundle/node_modules/undici/lib/web/cache/cache.js +0 -862
- package/bundle/node_modules/undici/lib/web/cache/cachestorage.js +0 -152
- package/bundle/node_modules/undici/lib/web/cache/util.js +0 -45
- package/bundle/node_modules/undici/lib/web/cookies/constants.js +0 -12
- package/bundle/node_modules/undici/lib/web/cookies/index.js +0 -199
- package/bundle/node_modules/undici/lib/web/cookies/parse.js +0 -322
- package/bundle/node_modules/undici/lib/web/cookies/util.js +0 -282
- package/bundle/node_modules/undici/lib/web/eventsource/eventsource-stream.js +0 -399
- package/bundle/node_modules/undici/lib/web/eventsource/eventsource.js +0 -484
- package/bundle/node_modules/undici/lib/web/eventsource/util.js +0 -37
- package/bundle/node_modules/undici/lib/web/fetch/LICENSE +0 -21
- package/bundle/node_modules/undici/lib/web/fetch/body.js +0 -532
- package/bundle/node_modules/undici/lib/web/fetch/constants.js +0 -131
- package/bundle/node_modules/undici/lib/web/fetch/data-url.js +0 -744
- package/bundle/node_modules/undici/lib/web/fetch/dispatcher-weakref.js +0 -46
- package/bundle/node_modules/undici/lib/web/fetch/formdata-parser.js +0 -501
- package/bundle/node_modules/undici/lib/web/fetch/formdata.js +0 -263
- package/bundle/node_modules/undici/lib/web/fetch/global.js +0 -40
- package/bundle/node_modules/undici/lib/web/fetch/headers.js +0 -719
- package/bundle/node_modules/undici/lib/web/fetch/index.js +0 -2258
- package/bundle/node_modules/undici/lib/web/fetch/request.js +0 -1099
- package/bundle/node_modules/undici/lib/web/fetch/response.js +0 -636
- package/bundle/node_modules/undici/lib/web/fetch/util.js +0 -1782
- package/bundle/node_modules/undici/lib/web/fetch/webidl.js +0 -740
- package/bundle/node_modules/undici/lib/web/websocket/connection.js +0 -325
- package/bundle/node_modules/undici/lib/web/websocket/constants.js +0 -126
- package/bundle/node_modules/undici/lib/web/websocket/events.js +0 -331
- package/bundle/node_modules/undici/lib/web/websocket/frame.js +0 -138
- package/bundle/node_modules/undici/lib/web/websocket/permessage-deflate.js +0 -70
- package/bundle/node_modules/undici/lib/web/websocket/receiver.js +0 -454
- package/bundle/node_modules/undici/lib/web/websocket/sender.js +0 -109
- package/bundle/node_modules/undici/lib/web/websocket/stream/websocketerror.js +0 -83
- package/bundle/node_modules/undici/lib/web/websocket/stream/websocketstream.js +0 -485
- package/bundle/node_modules/undici/lib/web/websocket/util.js +0 -338
- package/bundle/node_modules/undici/lib/web/websocket/websocket.js +0 -686
- package/bundle/node_modules/undici/package.json +0 -149
- package/bundle/node_modules/undici/scripts/strip-comments.js +0 -10
- package/bundle/node_modules/undici/types/README.md +0 -6
- package/bundle/node_modules/undici/types/agent.d.ts +0 -35
- package/bundle/node_modules/undici/types/api.d.ts +0 -43
- package/bundle/node_modules/undici/types/balanced-pool.d.ts +0 -29
- package/bundle/node_modules/undici/types/cache-interceptor.d.ts +0 -172
- package/bundle/node_modules/undici/types/cache.d.ts +0 -36
- package/bundle/node_modules/undici/types/client-stats.d.ts +0 -15
- package/bundle/node_modules/undici/types/client.d.ts +0 -110
- package/bundle/node_modules/undici/types/connector.d.ts +0 -34
- package/bundle/node_modules/undici/types/content-type.d.ts +0 -21
- package/bundle/node_modules/undici/types/cookies.d.ts +0 -30
- package/bundle/node_modules/undici/types/diagnostics-channel.d.ts +0 -66
- package/bundle/node_modules/undici/types/dispatcher.d.ts +0 -281
- package/bundle/node_modules/undici/types/env-http-proxy-agent.d.ts +0 -21
- package/bundle/node_modules/undici/types/errors.d.ts +0 -171
- package/bundle/node_modules/undici/types/eventsource.d.ts +0 -61
- package/bundle/node_modules/undici/types/fetch.d.ts +0 -210
- package/bundle/node_modules/undici/types/formdata.d.ts +0 -108
- package/bundle/node_modules/undici/types/global-dispatcher.d.ts +0 -9
- package/bundle/node_modules/undici/types/global-origin.d.ts +0 -7
- package/bundle/node_modules/undici/types/h2c-client.d.ts +0 -75
- package/bundle/node_modules/undici/types/handlers.d.ts +0 -15
- package/bundle/node_modules/undici/types/header.d.ts +0 -160
- package/bundle/node_modules/undici/types/index.d.ts +0 -75
- package/bundle/node_modules/undici/types/interceptors.d.ts +0 -34
- package/bundle/node_modules/undici/types/mock-agent.d.ts +0 -68
- package/bundle/node_modules/undici/types/mock-call-history.d.ts +0 -111
- package/bundle/node_modules/undici/types/mock-client.d.ts +0 -25
- package/bundle/node_modules/undici/types/mock-errors.d.ts +0 -12
- package/bundle/node_modules/undici/types/mock-interceptor.d.ts +0 -93
- package/bundle/node_modules/undici/types/mock-pool.d.ts +0 -25
- package/bundle/node_modules/undici/types/patch.d.ts +0 -29
- package/bundle/node_modules/undici/types/pool-stats.d.ts +0 -19
- package/bundle/node_modules/undici/types/pool.d.ts +0 -41
- package/bundle/node_modules/undici/types/proxy-agent.d.ts +0 -29
- package/bundle/node_modules/undici/types/readable.d.ts +0 -68
- package/bundle/node_modules/undici/types/retry-agent.d.ts +0 -8
- package/bundle/node_modules/undici/types/retry-handler.d.ts +0 -116
- package/bundle/node_modules/undici/types/util.d.ts +0 -18
- package/bundle/node_modules/undici/types/utility.d.ts +0 -7
- package/bundle/node_modules/undici/types/webidl.d.ts +0 -266
- package/bundle/node_modules/undici/types/websocket.d.ts +0 -184
|
@@ -1,484 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { pipeline } = require('node:stream')
|
|
4
|
-
const { fetching } = require('../fetch')
|
|
5
|
-
const { makeRequest } = require('../fetch/request')
|
|
6
|
-
const { webidl } = require('../fetch/webidl')
|
|
7
|
-
const { EventSourceStream } = require('./eventsource-stream')
|
|
8
|
-
const { parseMIMEType } = require('../fetch/data-url')
|
|
9
|
-
const { createFastMessageEvent } = require('../websocket/events')
|
|
10
|
-
const { isNetworkError } = require('../fetch/response')
|
|
11
|
-
const { delay } = require('./util')
|
|
12
|
-
const { kEnumerableProperty } = require('../../core/util')
|
|
13
|
-
const { environmentSettingsObject } = require('../fetch/util')
|
|
14
|
-
|
|
15
|
-
let experimentalWarned = false
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* A reconnection time, in milliseconds. This must initially be an implementation-defined value,
|
|
19
|
-
* probably in the region of a few seconds.
|
|
20
|
-
*
|
|
21
|
-
* In Comparison:
|
|
22
|
-
* - Chrome uses 3000ms.
|
|
23
|
-
* - Deno uses 5000ms.
|
|
24
|
-
*
|
|
25
|
-
* @type {3000}
|
|
26
|
-
*/
|
|
27
|
-
const defaultReconnectionTime = 3000
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* The readyState attribute represents the state of the connection.
|
|
31
|
-
* @typedef ReadyState
|
|
32
|
-
* @type {0|1|2}
|
|
33
|
-
* @readonly
|
|
34
|
-
* @see https://html.spec.whatwg.org/multipage/server-sent-events.html#dom-eventsource-readystate-dev
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* The connection has not yet been established, or it was closed and the user
|
|
39
|
-
* agent is reconnecting.
|
|
40
|
-
* @type {0}
|
|
41
|
-
*/
|
|
42
|
-
const CONNECTING = 0
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* The user agent has an open connection and is dispatching events as it
|
|
46
|
-
* receives them.
|
|
47
|
-
* @type {1}
|
|
48
|
-
*/
|
|
49
|
-
const OPEN = 1
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* The connection is not open, and the user agent is not trying to reconnect.
|
|
53
|
-
* @type {2}
|
|
54
|
-
*/
|
|
55
|
-
const CLOSED = 2
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Requests for the element will have their mode set to "cors" and their credentials mode set to "same-origin".
|
|
59
|
-
* @type {'anonymous'}
|
|
60
|
-
*/
|
|
61
|
-
const ANONYMOUS = 'anonymous'
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Requests for the element will have their mode set to "cors" and their credentials mode set to "include".
|
|
65
|
-
* @type {'use-credentials'}
|
|
66
|
-
*/
|
|
67
|
-
const USE_CREDENTIALS = 'use-credentials'
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* The EventSource interface is used to receive server-sent events. It
|
|
71
|
-
* connects to a server over HTTP and receives events in text/event-stream
|
|
72
|
-
* format without closing the connection.
|
|
73
|
-
* @extends {EventTarget}
|
|
74
|
-
* @see https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events
|
|
75
|
-
* @api public
|
|
76
|
-
*/
|
|
77
|
-
class EventSource extends EventTarget {
|
|
78
|
-
#events = {
|
|
79
|
-
open: null,
|
|
80
|
-
error: null,
|
|
81
|
-
message: null
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
#url
|
|
85
|
-
#withCredentials = false
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* @type {ReadyState}
|
|
89
|
-
*/
|
|
90
|
-
#readyState = CONNECTING
|
|
91
|
-
|
|
92
|
-
#request = null
|
|
93
|
-
#controller = null
|
|
94
|
-
|
|
95
|
-
#dispatcher
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* @type {import('./eventsource-stream').eventSourceSettings}
|
|
99
|
-
*/
|
|
100
|
-
#state
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Creates a new EventSource object.
|
|
104
|
-
* @param {string} url
|
|
105
|
-
* @param {EventSourceInit} [eventSourceInitDict={}]
|
|
106
|
-
* @see https://html.spec.whatwg.org/multipage/server-sent-events.html#the-eventsource-interface
|
|
107
|
-
*/
|
|
108
|
-
constructor (url, eventSourceInitDict = {}) {
|
|
109
|
-
// 1. Let ev be a new EventSource object.
|
|
110
|
-
super()
|
|
111
|
-
|
|
112
|
-
webidl.util.markAsUncloneable(this)
|
|
113
|
-
|
|
114
|
-
const prefix = 'EventSource constructor'
|
|
115
|
-
webidl.argumentLengthCheck(arguments, 1, prefix)
|
|
116
|
-
|
|
117
|
-
if (!experimentalWarned) {
|
|
118
|
-
experimentalWarned = true
|
|
119
|
-
process.emitWarning('EventSource is experimental, expect them to change at any time.', {
|
|
120
|
-
code: 'UNDICI-ES'
|
|
121
|
-
})
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
url = webidl.converters.USVString(url)
|
|
125
|
-
eventSourceInitDict = webidl.converters.EventSourceInitDict(eventSourceInitDict, prefix, 'eventSourceInitDict')
|
|
126
|
-
|
|
127
|
-
this.#dispatcher = eventSourceInitDict.dispatcher
|
|
128
|
-
this.#state = {
|
|
129
|
-
lastEventId: '',
|
|
130
|
-
reconnectionTime: defaultReconnectionTime
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// 2. Let settings be ev's relevant settings object.
|
|
134
|
-
// https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object
|
|
135
|
-
const settings = environmentSettingsObject
|
|
136
|
-
|
|
137
|
-
let urlRecord
|
|
138
|
-
|
|
139
|
-
try {
|
|
140
|
-
// 3. Let urlRecord be the result of encoding-parsing a URL given url, relative to settings.
|
|
141
|
-
urlRecord = new URL(url, settings.settingsObject.baseUrl)
|
|
142
|
-
this.#state.origin = urlRecord.origin
|
|
143
|
-
} catch (e) {
|
|
144
|
-
// 4. If urlRecord is failure, then throw a "SyntaxError" DOMException.
|
|
145
|
-
throw new DOMException(e, 'SyntaxError')
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// 5. Set ev's url to urlRecord.
|
|
149
|
-
this.#url = urlRecord.href
|
|
150
|
-
|
|
151
|
-
// 6. Let corsAttributeState be Anonymous.
|
|
152
|
-
let corsAttributeState = ANONYMOUS
|
|
153
|
-
|
|
154
|
-
// 7. If the value of eventSourceInitDict's withCredentials member is true,
|
|
155
|
-
// then set corsAttributeState to Use Credentials and set ev's
|
|
156
|
-
// withCredentials attribute to true.
|
|
157
|
-
if (eventSourceInitDict.withCredentials === true) {
|
|
158
|
-
corsAttributeState = USE_CREDENTIALS
|
|
159
|
-
this.#withCredentials = true
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// 8. Let request be the result of creating a potential-CORS request given
|
|
163
|
-
// urlRecord, the empty string, and corsAttributeState.
|
|
164
|
-
const initRequest = {
|
|
165
|
-
redirect: 'follow',
|
|
166
|
-
keepalive: true,
|
|
167
|
-
// @see https://html.spec.whatwg.org/multipage/urls-and-fetching.html#cors-settings-attributes
|
|
168
|
-
mode: 'cors',
|
|
169
|
-
credentials: corsAttributeState === 'anonymous'
|
|
170
|
-
? 'same-origin'
|
|
171
|
-
: 'omit',
|
|
172
|
-
referrer: 'no-referrer'
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// 9. Set request's client to settings.
|
|
176
|
-
initRequest.client = environmentSettingsObject.settingsObject
|
|
177
|
-
|
|
178
|
-
// 10. User agents may set (`Accept`, `text/event-stream`) in request's header list.
|
|
179
|
-
initRequest.headersList = [['accept', { name: 'accept', value: 'text/event-stream' }]]
|
|
180
|
-
|
|
181
|
-
// 11. Set request's cache mode to "no-store".
|
|
182
|
-
initRequest.cache = 'no-store'
|
|
183
|
-
|
|
184
|
-
// 12. Set request's initiator type to "other".
|
|
185
|
-
initRequest.initiator = 'other'
|
|
186
|
-
|
|
187
|
-
initRequest.urlList = [new URL(this.#url)]
|
|
188
|
-
|
|
189
|
-
// 13. Set ev's request to request.
|
|
190
|
-
this.#request = makeRequest(initRequest)
|
|
191
|
-
|
|
192
|
-
this.#connect()
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Returns the state of this EventSource object's connection. It can have the
|
|
197
|
-
* values described below.
|
|
198
|
-
* @returns {ReadyState}
|
|
199
|
-
* @readonly
|
|
200
|
-
*/
|
|
201
|
-
get readyState () {
|
|
202
|
-
return this.#readyState
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Returns the URL providing the event stream.
|
|
207
|
-
* @readonly
|
|
208
|
-
* @returns {string}
|
|
209
|
-
*/
|
|
210
|
-
get url () {
|
|
211
|
-
return this.#url
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Returns a boolean indicating whether the EventSource object was
|
|
216
|
-
* instantiated with CORS credentials set (true), or not (false, the default).
|
|
217
|
-
*/
|
|
218
|
-
get withCredentials () {
|
|
219
|
-
return this.#withCredentials
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
#connect () {
|
|
223
|
-
if (this.#readyState === CLOSED) return
|
|
224
|
-
|
|
225
|
-
this.#readyState = CONNECTING
|
|
226
|
-
|
|
227
|
-
const fetchParams = {
|
|
228
|
-
request: this.#request,
|
|
229
|
-
dispatcher: this.#dispatcher
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// 14. Let processEventSourceEndOfBody given response res be the following step: if res is not a network error, then reestablish the connection.
|
|
233
|
-
const processEventSourceEndOfBody = (response) => {
|
|
234
|
-
if (isNetworkError(response)) {
|
|
235
|
-
this.dispatchEvent(new Event('error'))
|
|
236
|
-
this.close()
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
this.#reconnect()
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
// 15. Fetch request, with processResponseEndOfBody set to processEventSourceEndOfBody...
|
|
243
|
-
fetchParams.processResponseEndOfBody = processEventSourceEndOfBody
|
|
244
|
-
|
|
245
|
-
// and processResponse set to the following steps given response res:
|
|
246
|
-
fetchParams.processResponse = (response) => {
|
|
247
|
-
// 1. If res is an aborted network error, then fail the connection.
|
|
248
|
-
|
|
249
|
-
if (isNetworkError(response)) {
|
|
250
|
-
// 1. When a user agent is to fail the connection, the user agent
|
|
251
|
-
// must queue a task which, if the readyState attribute is set to a
|
|
252
|
-
// value other than CLOSED, sets the readyState attribute to CLOSED
|
|
253
|
-
// and fires an event named error at the EventSource object. Once the
|
|
254
|
-
// user agent has failed the connection, it does not attempt to
|
|
255
|
-
// reconnect.
|
|
256
|
-
if (response.aborted) {
|
|
257
|
-
this.close()
|
|
258
|
-
this.dispatchEvent(new Event('error'))
|
|
259
|
-
return
|
|
260
|
-
// 2. Otherwise, if res is a network error, then reestablish the
|
|
261
|
-
// connection, unless the user agent knows that to be futile, in
|
|
262
|
-
// which case the user agent may fail the connection.
|
|
263
|
-
} else {
|
|
264
|
-
this.#reconnect()
|
|
265
|
-
return
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// 3. Otherwise, if res's status is not 200, or if res's `Content-Type`
|
|
270
|
-
// is not `text/event-stream`, then fail the connection.
|
|
271
|
-
const contentType = response.headersList.get('content-type', true)
|
|
272
|
-
const mimeType = contentType !== null ? parseMIMEType(contentType) : 'failure'
|
|
273
|
-
const contentTypeValid = mimeType !== 'failure' && mimeType.essence === 'text/event-stream'
|
|
274
|
-
if (
|
|
275
|
-
response.status !== 200 ||
|
|
276
|
-
contentTypeValid === false
|
|
277
|
-
) {
|
|
278
|
-
this.close()
|
|
279
|
-
this.dispatchEvent(new Event('error'))
|
|
280
|
-
return
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
// 4. Otherwise, announce the connection and interpret res's body
|
|
284
|
-
// line by line.
|
|
285
|
-
|
|
286
|
-
// When a user agent is to announce the connection, the user agent
|
|
287
|
-
// must queue a task which, if the readyState attribute is set to a
|
|
288
|
-
// value other than CLOSED, sets the readyState attribute to OPEN
|
|
289
|
-
// and fires an event named open at the EventSource object.
|
|
290
|
-
// @see https://html.spec.whatwg.org/multipage/server-sent-events.html#sse-processing-model
|
|
291
|
-
this.#readyState = OPEN
|
|
292
|
-
this.dispatchEvent(new Event('open'))
|
|
293
|
-
|
|
294
|
-
// If redirected to a different origin, set the origin to the new origin.
|
|
295
|
-
this.#state.origin = response.urlList[response.urlList.length - 1].origin
|
|
296
|
-
|
|
297
|
-
const eventSourceStream = new EventSourceStream({
|
|
298
|
-
eventSourceSettings: this.#state,
|
|
299
|
-
push: (event) => {
|
|
300
|
-
this.dispatchEvent(createFastMessageEvent(
|
|
301
|
-
event.type,
|
|
302
|
-
event.options
|
|
303
|
-
))
|
|
304
|
-
}
|
|
305
|
-
})
|
|
306
|
-
|
|
307
|
-
pipeline(response.body.stream,
|
|
308
|
-
eventSourceStream,
|
|
309
|
-
(error) => {
|
|
310
|
-
if (
|
|
311
|
-
error?.aborted === false
|
|
312
|
-
) {
|
|
313
|
-
this.close()
|
|
314
|
-
this.dispatchEvent(new Event('error'))
|
|
315
|
-
}
|
|
316
|
-
})
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
this.#controller = fetching(fetchParams)
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* @see https://html.spec.whatwg.org/multipage/server-sent-events.html#sse-processing-model
|
|
324
|
-
* @returns {Promise<void>}
|
|
325
|
-
*/
|
|
326
|
-
async #reconnect () {
|
|
327
|
-
// When a user agent is to reestablish the connection, the user agent must
|
|
328
|
-
// run the following steps. These steps are run in parallel, not as part of
|
|
329
|
-
// a task. (The tasks that it queues, of course, are run like normal tasks
|
|
330
|
-
// and not themselves in parallel.)
|
|
331
|
-
|
|
332
|
-
// 1. Queue a task to run the following steps:
|
|
333
|
-
|
|
334
|
-
// 1. If the readyState attribute is set to CLOSED, abort the task.
|
|
335
|
-
if (this.#readyState === CLOSED) return
|
|
336
|
-
|
|
337
|
-
// 2. Set the readyState attribute to CONNECTING.
|
|
338
|
-
this.#readyState = CONNECTING
|
|
339
|
-
|
|
340
|
-
// 3. Fire an event named error at the EventSource object.
|
|
341
|
-
this.dispatchEvent(new Event('error'))
|
|
342
|
-
|
|
343
|
-
// 2. Wait a delay equal to the reconnection time of the event source.
|
|
344
|
-
await delay(this.#state.reconnectionTime)
|
|
345
|
-
|
|
346
|
-
// 5. Queue a task to run the following steps:
|
|
347
|
-
|
|
348
|
-
// 1. If the EventSource object's readyState attribute is not set to
|
|
349
|
-
// CONNECTING, then return.
|
|
350
|
-
if (this.#readyState !== CONNECTING) return
|
|
351
|
-
|
|
352
|
-
// 2. Let request be the EventSource object's request.
|
|
353
|
-
// 3. If the EventSource object's last event ID string is not the empty
|
|
354
|
-
// string, then:
|
|
355
|
-
// 1. Let lastEventIDValue be the EventSource object's last event ID
|
|
356
|
-
// string, encoded as UTF-8.
|
|
357
|
-
// 2. Set (`Last-Event-ID`, lastEventIDValue) in request's header
|
|
358
|
-
// list.
|
|
359
|
-
if (this.#state.lastEventId.length) {
|
|
360
|
-
this.#request.headersList.set('last-event-id', this.#state.lastEventId, true)
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
// 4. Fetch request and process the response obtained in this fashion, if any, as described earlier in this section.
|
|
364
|
-
this.#connect()
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* Closes the connection, if any, and sets the readyState attribute to
|
|
369
|
-
* CLOSED.
|
|
370
|
-
*/
|
|
371
|
-
close () {
|
|
372
|
-
webidl.brandCheck(this, EventSource)
|
|
373
|
-
|
|
374
|
-
if (this.#readyState === CLOSED) return
|
|
375
|
-
this.#readyState = CLOSED
|
|
376
|
-
this.#controller.abort()
|
|
377
|
-
this.#request = null
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
get onopen () {
|
|
381
|
-
return this.#events.open
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
set onopen (fn) {
|
|
385
|
-
if (this.#events.open) {
|
|
386
|
-
this.removeEventListener('open', this.#events.open)
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
if (typeof fn === 'function') {
|
|
390
|
-
this.#events.open = fn
|
|
391
|
-
this.addEventListener('open', fn)
|
|
392
|
-
} else {
|
|
393
|
-
this.#events.open = null
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
get onmessage () {
|
|
398
|
-
return this.#events.message
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
set onmessage (fn) {
|
|
402
|
-
if (this.#events.message) {
|
|
403
|
-
this.removeEventListener('message', this.#events.message)
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
if (typeof fn === 'function') {
|
|
407
|
-
this.#events.message = fn
|
|
408
|
-
this.addEventListener('message', fn)
|
|
409
|
-
} else {
|
|
410
|
-
this.#events.message = null
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
get onerror () {
|
|
415
|
-
return this.#events.error
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
set onerror (fn) {
|
|
419
|
-
if (this.#events.error) {
|
|
420
|
-
this.removeEventListener('error', this.#events.error)
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
if (typeof fn === 'function') {
|
|
424
|
-
this.#events.error = fn
|
|
425
|
-
this.addEventListener('error', fn)
|
|
426
|
-
} else {
|
|
427
|
-
this.#events.error = null
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
const constantsPropertyDescriptors = {
|
|
433
|
-
CONNECTING: {
|
|
434
|
-
__proto__: null,
|
|
435
|
-
configurable: false,
|
|
436
|
-
enumerable: true,
|
|
437
|
-
value: CONNECTING,
|
|
438
|
-
writable: false
|
|
439
|
-
},
|
|
440
|
-
OPEN: {
|
|
441
|
-
__proto__: null,
|
|
442
|
-
configurable: false,
|
|
443
|
-
enumerable: true,
|
|
444
|
-
value: OPEN,
|
|
445
|
-
writable: false
|
|
446
|
-
},
|
|
447
|
-
CLOSED: {
|
|
448
|
-
__proto__: null,
|
|
449
|
-
configurable: false,
|
|
450
|
-
enumerable: true,
|
|
451
|
-
value: CLOSED,
|
|
452
|
-
writable: false
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
Object.defineProperties(EventSource, constantsPropertyDescriptors)
|
|
457
|
-
Object.defineProperties(EventSource.prototype, constantsPropertyDescriptors)
|
|
458
|
-
|
|
459
|
-
Object.defineProperties(EventSource.prototype, {
|
|
460
|
-
close: kEnumerableProperty,
|
|
461
|
-
onerror: kEnumerableProperty,
|
|
462
|
-
onmessage: kEnumerableProperty,
|
|
463
|
-
onopen: kEnumerableProperty,
|
|
464
|
-
readyState: kEnumerableProperty,
|
|
465
|
-
url: kEnumerableProperty,
|
|
466
|
-
withCredentials: kEnumerableProperty
|
|
467
|
-
})
|
|
468
|
-
|
|
469
|
-
webidl.converters.EventSourceInitDict = webidl.dictionaryConverter([
|
|
470
|
-
{
|
|
471
|
-
key: 'withCredentials',
|
|
472
|
-
converter: webidl.converters.boolean,
|
|
473
|
-
defaultValue: () => false
|
|
474
|
-
},
|
|
475
|
-
{
|
|
476
|
-
key: 'dispatcher', // undici only
|
|
477
|
-
converter: webidl.converters.any
|
|
478
|
-
}
|
|
479
|
-
])
|
|
480
|
-
|
|
481
|
-
module.exports = {
|
|
482
|
-
EventSource,
|
|
483
|
-
defaultReconnectionTime
|
|
484
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Checks if the given value is a valid LastEventId.
|
|
5
|
-
* @param {string} value
|
|
6
|
-
* @returns {boolean}
|
|
7
|
-
*/
|
|
8
|
-
function isValidLastEventId (value) {
|
|
9
|
-
// LastEventId should not contain U+0000 NULL
|
|
10
|
-
return value.indexOf('\u0000') === -1
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Checks if the given value is a base 10 digit.
|
|
15
|
-
* @param {string} value
|
|
16
|
-
* @returns {boolean}
|
|
17
|
-
*/
|
|
18
|
-
function isASCIINumber (value) {
|
|
19
|
-
if (value.length === 0) return false
|
|
20
|
-
for (let i = 0; i < value.length; i++) {
|
|
21
|
-
if (value.charCodeAt(i) < 0x30 || value.charCodeAt(i) > 0x39) return false
|
|
22
|
-
}
|
|
23
|
-
return true
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// https://github.com/nodejs/undici/issues/2664
|
|
27
|
-
function delay (ms) {
|
|
28
|
-
return new Promise((resolve) => {
|
|
29
|
-
setTimeout(resolve, ms).unref()
|
|
30
|
-
})
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
module.exports = {
|
|
34
|
-
isValidLastEventId,
|
|
35
|
-
isASCIINumber,
|
|
36
|
-
delay
|
|
37
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2020 Ethan Arrowood
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|