msw 2.11.6 → 2.12.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/lib/core/index.d.mts +1 -0
- package/lib/core/index.d.ts +1 -0
- package/lib/core/index.js +2 -0
- package/lib/core/index.js.map +1 -1
- package/lib/core/index.mjs +4 -0
- package/lib/core/index.mjs.map +1 -1
- package/lib/core/sse.d.mts +116 -0
- package/lib/core/sse.d.ts +116 -0
- package/lib/core/sse.js +599 -0
- package/lib/core/sse.js.map +1 -0
- package/lib/core/sse.mjs +581 -0
- package/lib/core/sse.mjs.map +1 -0
- package/lib/core/utils/internal/isObject.d.mts +1 -1
- package/lib/core/utils/internal/isObject.d.ts +1 -1
- package/lib/core/utils/internal/isObject.js.map +1 -1
- package/lib/core/utils/internal/isObject.mjs.map +1 -1
- package/lib/core/ws/utils/attachWebSocketLogger.d.mts +7 -1
- package/lib/core/ws/utils/attachWebSocketLogger.d.ts +7 -1
- package/lib/core/ws/utils/attachWebSocketLogger.js +1 -0
- package/lib/core/ws/utils/attachWebSocketLogger.js.map +1 -1
- package/lib/core/ws/utils/attachWebSocketLogger.mjs +1 -0
- package/lib/core/ws/utils/attachWebSocketLogger.mjs.map +1 -1
- package/lib/core/ws/utils/getMessageLength.js +2 -1
- package/lib/core/ws/utils/getMessageLength.js.map +1 -1
- package/lib/core/ws/utils/getMessageLength.mjs +2 -1
- package/lib/core/ws/utils/getMessageLength.mjs.map +1 -1
- package/lib/core/ws/utils/getPublicData.js +2 -1
- package/lib/core/ws/utils/getPublicData.js.map +1 -1
- package/lib/core/ws/utils/getPublicData.mjs +2 -1
- package/lib/core/ws/utils/getPublicData.mjs.map +1 -1
- package/lib/iife/index.js +815 -252
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +4 -3
- package/src/browser/tsconfig.browser.json +1 -1
- package/src/core/index.ts +9 -0
- package/src/core/sse.ts +897 -0
- package/src/core/utils/internal/isObject.ts +1 -1
- package/src/core/ws/utils/attachWebSocketLogger.ts +1 -1
- package/src/core/ws/utils/getMessageLength.ts +2 -1
- package/src/core/ws/utils/getPublicData.ts +3 -2
package/lib/core/sse.mjs
ADDED
|
@@ -0,0 +1,581 @@
|
|
|
1
|
+
import { invariant } from "outvariant";
|
|
2
|
+
import { Emitter } from "strict-event-emitter";
|
|
3
|
+
import {
|
|
4
|
+
HttpHandler
|
|
5
|
+
} from './handlers/HttpHandler.mjs';
|
|
6
|
+
import { delay } from './delay.mjs';
|
|
7
|
+
import { getTimestamp } from './utils/logging/getTimestamp.mjs';
|
|
8
|
+
import { devUtils } from './utils/internal/devUtils.mjs';
|
|
9
|
+
import { colors } from './ws/utils/attachWebSocketLogger.mjs';
|
|
10
|
+
import { toPublicUrl } from './utils/request/toPublicUrl.mjs';
|
|
11
|
+
const sse = (path, resolver) => {
|
|
12
|
+
return new ServerSentEventHandler(path, resolver);
|
|
13
|
+
};
|
|
14
|
+
class ServerSentEventHandler extends HttpHandler {
|
|
15
|
+
constructor(path, resolver) {
|
|
16
|
+
invariant(
|
|
17
|
+
typeof EventSource !== "undefined",
|
|
18
|
+
'Failed to construct a Server-Sent Event handler for path "%s": the EventSource API is not supported in this environment',
|
|
19
|
+
path
|
|
20
|
+
);
|
|
21
|
+
const clientEmitter = new Emitter();
|
|
22
|
+
super("GET", path, async (info) => {
|
|
23
|
+
const responseInit = {
|
|
24
|
+
headers: {
|
|
25
|
+
"content-type": "text/event-stream",
|
|
26
|
+
"cache-control": "no-cache",
|
|
27
|
+
connection: "keep-alive"
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
await super.log({
|
|
31
|
+
request: info.request,
|
|
32
|
+
/**
|
|
33
|
+
* @note Construct a placeholder response since SSE response
|
|
34
|
+
* is being streamed and cannot be cloned/consumed for logging.
|
|
35
|
+
*/
|
|
36
|
+
response: new Response("[streaming]", responseInit)
|
|
37
|
+
});
|
|
38
|
+
this.#attachClientLogger(info.request, clientEmitter);
|
|
39
|
+
const stream = new ReadableStream({
|
|
40
|
+
async start(controller) {
|
|
41
|
+
const client = new ServerSentEventClient({
|
|
42
|
+
controller,
|
|
43
|
+
emitter: clientEmitter
|
|
44
|
+
});
|
|
45
|
+
const server = new ServerSentEventServer({
|
|
46
|
+
request: info.request,
|
|
47
|
+
client
|
|
48
|
+
});
|
|
49
|
+
await resolver({
|
|
50
|
+
...info,
|
|
51
|
+
client,
|
|
52
|
+
server
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return new Response(stream, responseInit);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async predicate(args) {
|
|
60
|
+
if (args.request.headers.get("accept") !== "text/event-stream") {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
return super.predicate(args);
|
|
64
|
+
}
|
|
65
|
+
async log(_args) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
#attachClientLogger(request, emitter) {
|
|
69
|
+
const publicUrl = toPublicUrl(request.url);
|
|
70
|
+
emitter.on("message", (payload) => {
|
|
71
|
+
console.groupCollapsed(
|
|
72
|
+
devUtils.formatMessage(
|
|
73
|
+
`${getTimestamp()} SSE %s %c\u21E3%c ${payload.event}`
|
|
74
|
+
),
|
|
75
|
+
publicUrl,
|
|
76
|
+
`color:${colors.mocked}`,
|
|
77
|
+
"color:inherit"
|
|
78
|
+
);
|
|
79
|
+
console.log(payload.frames);
|
|
80
|
+
console.groupEnd();
|
|
81
|
+
});
|
|
82
|
+
emitter.on("error", () => {
|
|
83
|
+
console.groupCollapsed(
|
|
84
|
+
devUtils.formatMessage(`${getTimestamp()} SSE %s %c\xD7%c error`),
|
|
85
|
+
publicUrl,
|
|
86
|
+
`color: ${colors.system}`,
|
|
87
|
+
"color:inherit"
|
|
88
|
+
);
|
|
89
|
+
console.log("Handler:", this);
|
|
90
|
+
console.groupEnd();
|
|
91
|
+
});
|
|
92
|
+
emitter.on("close", () => {
|
|
93
|
+
console.groupCollapsed(
|
|
94
|
+
devUtils.formatMessage(`${getTimestamp()} SSE %s %c\u25A0%c close`),
|
|
95
|
+
publicUrl,
|
|
96
|
+
`colors:${colors.system}`,
|
|
97
|
+
"color:inherit"
|
|
98
|
+
);
|
|
99
|
+
console.log("Handler:", this);
|
|
100
|
+
console.groupEnd();
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
class ServerSentEventClient {
|
|
105
|
+
#encoder;
|
|
106
|
+
#controller;
|
|
107
|
+
#emitter;
|
|
108
|
+
constructor(args) {
|
|
109
|
+
this.#encoder = new TextEncoder();
|
|
110
|
+
this.#controller = args.controller;
|
|
111
|
+
this.#emitter = args.emitter;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Sends the given payload to the intercepted `EventSource`.
|
|
115
|
+
*/
|
|
116
|
+
send(payload) {
|
|
117
|
+
if ("retry" in payload && payload.retry != null) {
|
|
118
|
+
this.#sendRetry(payload.retry);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
this.#sendMessage({
|
|
122
|
+
id: payload.id,
|
|
123
|
+
event: payload.event,
|
|
124
|
+
data: typeof payload.data === "object" ? JSON.stringify(payload.data) : payload.data
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Dispatches the given event on the intercepted `EventSource`.
|
|
129
|
+
*/
|
|
130
|
+
dispatchEvent(event) {
|
|
131
|
+
if (event instanceof MessageEvent) {
|
|
132
|
+
this.#sendMessage({
|
|
133
|
+
id: event.lastEventId || void 0,
|
|
134
|
+
event: event.type === "message" ? void 0 : event.type,
|
|
135
|
+
data: event.data
|
|
136
|
+
});
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (event.type === "error") {
|
|
140
|
+
this.error();
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (event.type === "close") {
|
|
144
|
+
this.close();
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Errors the underlying `EventSource`, closing the connection with an error.
|
|
150
|
+
* This is equivalent to aborting the connection and will produce a `TypeError: Failed to fetch`
|
|
151
|
+
* error.
|
|
152
|
+
*/
|
|
153
|
+
error() {
|
|
154
|
+
this.#controller.error();
|
|
155
|
+
this.#emitter.emit("error");
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Closes the underlying `EventSource`, closing the connection.
|
|
159
|
+
*/
|
|
160
|
+
close() {
|
|
161
|
+
this.#controller.close();
|
|
162
|
+
this.#emitter.emit("close");
|
|
163
|
+
}
|
|
164
|
+
#sendRetry(retry) {
|
|
165
|
+
if (typeof retry === "number") {
|
|
166
|
+
this.#controller.enqueue(this.#encoder.encode(`retry:${retry}
|
|
167
|
+
|
|
168
|
+
`));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
#sendMessage(message) {
|
|
172
|
+
const frames = [];
|
|
173
|
+
if (message.id) {
|
|
174
|
+
frames.push(`id:${message.id}`);
|
|
175
|
+
}
|
|
176
|
+
if (message.event) {
|
|
177
|
+
frames.push(`event:${message.event?.toString()}`);
|
|
178
|
+
}
|
|
179
|
+
frames.push(`data:${message.data}`);
|
|
180
|
+
frames.push("", "");
|
|
181
|
+
this.#controller.enqueue(this.#encoder.encode(frames.join("\n")));
|
|
182
|
+
this.#emitter.emit("message", {
|
|
183
|
+
id: message.id,
|
|
184
|
+
event: message.event?.toString() || "message",
|
|
185
|
+
data: message.data,
|
|
186
|
+
frames
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
class ServerSentEventServer {
|
|
191
|
+
#request;
|
|
192
|
+
#client;
|
|
193
|
+
constructor(args) {
|
|
194
|
+
this.#request = args.request;
|
|
195
|
+
this.#client = args.client;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Establishes the actual connection for this SSE request
|
|
199
|
+
* and returns the `EventSource` instance.
|
|
200
|
+
*/
|
|
201
|
+
connect() {
|
|
202
|
+
const source = new ObservableEventSource(this.#request.url, {
|
|
203
|
+
withCredentials: this.#request.credentials === "include",
|
|
204
|
+
headers: {
|
|
205
|
+
/**
|
|
206
|
+
* @note Mark this request as passthrough so it doesn't trigger
|
|
207
|
+
* an infinite loop matching against the existing request handler.
|
|
208
|
+
*/
|
|
209
|
+
accept: "msw/passthrough"
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
source[kOnAnyMessage] = (event) => {
|
|
213
|
+
Object.defineProperties(event, {
|
|
214
|
+
target: {
|
|
215
|
+
value: this,
|
|
216
|
+
enumerable: true,
|
|
217
|
+
writable: true,
|
|
218
|
+
configurable: true
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
queueMicrotask(() => {
|
|
222
|
+
if (!event.defaultPrevented) {
|
|
223
|
+
this.#client.dispatchEvent(event);
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
source.addEventListener("error", (event) => {
|
|
228
|
+
Object.defineProperties(event, {
|
|
229
|
+
target: {
|
|
230
|
+
value: this,
|
|
231
|
+
enumerable: true,
|
|
232
|
+
writable: true,
|
|
233
|
+
configurable: true
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
queueMicrotask(() => {
|
|
237
|
+
if (!event.defaultPrevented) {
|
|
238
|
+
this.#client.dispatchEvent(event);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
return source;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const kRequest = Symbol("kRequest");
|
|
246
|
+
const kReconnectionTime = Symbol("kReconnectionTime");
|
|
247
|
+
const kLastEventId = Symbol("kLastEventId");
|
|
248
|
+
const kAbortController = Symbol("kAbortController");
|
|
249
|
+
const kOnOpen = Symbol("kOnOpen");
|
|
250
|
+
const kOnMessage = Symbol("kOnMessage");
|
|
251
|
+
const kOnAnyMessage = Symbol("kOnAnyMessage");
|
|
252
|
+
const kOnError = Symbol("kOnError");
|
|
253
|
+
class ObservableEventSource extends EventTarget {
|
|
254
|
+
static CONNECTING = 0;
|
|
255
|
+
static OPEN = 1;
|
|
256
|
+
static CLOSED = 2;
|
|
257
|
+
CONNECTING = ObservableEventSource.CONNECTING;
|
|
258
|
+
OPEN = ObservableEventSource.OPEN;
|
|
259
|
+
CLOSED = ObservableEventSource.CLOSED;
|
|
260
|
+
readyState;
|
|
261
|
+
url;
|
|
262
|
+
withCredentials;
|
|
263
|
+
[kRequest];
|
|
264
|
+
[kReconnectionTime];
|
|
265
|
+
[kLastEventId];
|
|
266
|
+
[kAbortController];
|
|
267
|
+
[kOnOpen] = null;
|
|
268
|
+
[kOnMessage] = null;
|
|
269
|
+
[kOnAnyMessage] = null;
|
|
270
|
+
[kOnError] = null;
|
|
271
|
+
constructor(url, init) {
|
|
272
|
+
super();
|
|
273
|
+
this.url = new URL(url).href;
|
|
274
|
+
this.withCredentials = init?.withCredentials ?? false;
|
|
275
|
+
this.readyState = this.CONNECTING;
|
|
276
|
+
const headers = new Headers(init?.headers || {});
|
|
277
|
+
headers.append("accept", "text/event-stream");
|
|
278
|
+
this[kAbortController] = new AbortController();
|
|
279
|
+
this[kReconnectionTime] = 2e3;
|
|
280
|
+
this[kLastEventId] = "";
|
|
281
|
+
this[kRequest] = new Request(this.url, {
|
|
282
|
+
method: "GET",
|
|
283
|
+
headers,
|
|
284
|
+
credentials: this.withCredentials ? "include" : "omit",
|
|
285
|
+
signal: this[kAbortController].signal
|
|
286
|
+
});
|
|
287
|
+
this.connect();
|
|
288
|
+
}
|
|
289
|
+
get onopen() {
|
|
290
|
+
return this[kOnOpen];
|
|
291
|
+
}
|
|
292
|
+
set onopen(handler) {
|
|
293
|
+
if (this[kOnOpen]) {
|
|
294
|
+
this.removeEventListener("open", this[kOnOpen]);
|
|
295
|
+
}
|
|
296
|
+
this[kOnOpen] = handler.bind(this);
|
|
297
|
+
this.addEventListener("open", this[kOnOpen]);
|
|
298
|
+
}
|
|
299
|
+
get onmessage() {
|
|
300
|
+
return this[kOnMessage];
|
|
301
|
+
}
|
|
302
|
+
set onmessage(handler) {
|
|
303
|
+
if (this[kOnMessage]) {
|
|
304
|
+
this.removeEventListener("message", { handleEvent: this[kOnMessage] });
|
|
305
|
+
}
|
|
306
|
+
this[kOnMessage] = handler.bind(this);
|
|
307
|
+
this.addEventListener("message", { handleEvent: this[kOnMessage] });
|
|
308
|
+
}
|
|
309
|
+
get onerror() {
|
|
310
|
+
return this[kOnError];
|
|
311
|
+
}
|
|
312
|
+
set oneerror(handler) {
|
|
313
|
+
if (this[kOnError]) {
|
|
314
|
+
this.removeEventListener("error", { handleEvent: this[kOnError] });
|
|
315
|
+
}
|
|
316
|
+
this[kOnError] = handler.bind(this);
|
|
317
|
+
this.addEventListener("error", { handleEvent: this[kOnError] });
|
|
318
|
+
}
|
|
319
|
+
addEventListener(type, listener, options) {
|
|
320
|
+
super.addEventListener(
|
|
321
|
+
type,
|
|
322
|
+
listener,
|
|
323
|
+
options
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
removeEventListener(type, listener, options) {
|
|
327
|
+
super.removeEventListener(
|
|
328
|
+
type,
|
|
329
|
+
listener,
|
|
330
|
+
options
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
dispatchEvent(event) {
|
|
334
|
+
return super.dispatchEvent(event);
|
|
335
|
+
}
|
|
336
|
+
close() {
|
|
337
|
+
this[kAbortController].abort();
|
|
338
|
+
this.readyState = this.CLOSED;
|
|
339
|
+
}
|
|
340
|
+
async connect() {
|
|
341
|
+
await fetch(this[kRequest]).then((response) => {
|
|
342
|
+
this.processResponse(response);
|
|
343
|
+
}).catch(() => {
|
|
344
|
+
this.failConnection();
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
processResponse(response) {
|
|
348
|
+
if (!response.body) {
|
|
349
|
+
this.failConnection();
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
if (isNetworkError(response)) {
|
|
353
|
+
this.reestablishConnection();
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
if (response.status !== 200 || response.headers.get("content-type") !== "text/event-stream") {
|
|
357
|
+
this.failConnection();
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
this.announceConnection();
|
|
361
|
+
this.interpretResponseBody(response);
|
|
362
|
+
}
|
|
363
|
+
announceConnection() {
|
|
364
|
+
queueMicrotask(() => {
|
|
365
|
+
if (this.readyState !== this.CLOSED) {
|
|
366
|
+
this.readyState = this.OPEN;
|
|
367
|
+
this.dispatchEvent(new Event("open"));
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
interpretResponseBody(response) {
|
|
372
|
+
const parsingStream = new EventSourceParsingStream({
|
|
373
|
+
message: (message) => {
|
|
374
|
+
if (message.id) {
|
|
375
|
+
this[kLastEventId] = message.id;
|
|
376
|
+
}
|
|
377
|
+
if (message.retry) {
|
|
378
|
+
this[kReconnectionTime] = message.retry;
|
|
379
|
+
}
|
|
380
|
+
const messageEvent = new MessageEvent(
|
|
381
|
+
message.event ? message.event : "message",
|
|
382
|
+
{
|
|
383
|
+
data: message.data,
|
|
384
|
+
origin: this[kRequest].url,
|
|
385
|
+
lastEventId: this[kLastEventId],
|
|
386
|
+
cancelable: true
|
|
387
|
+
}
|
|
388
|
+
);
|
|
389
|
+
this[kOnAnyMessage]?.(messageEvent);
|
|
390
|
+
this.dispatchEvent(messageEvent);
|
|
391
|
+
},
|
|
392
|
+
abort: () => {
|
|
393
|
+
throw new Error("Stream abort is not implemented");
|
|
394
|
+
},
|
|
395
|
+
close: () => {
|
|
396
|
+
this.failConnection();
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
response.body.pipeTo(parsingStream).then(() => {
|
|
400
|
+
this.processResponseEndOfBody(response);
|
|
401
|
+
}).catch(() => {
|
|
402
|
+
this.failConnection();
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
processResponseEndOfBody(response) {
|
|
406
|
+
if (!isNetworkError(response)) {
|
|
407
|
+
this.reestablishConnection();
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
async reestablishConnection() {
|
|
411
|
+
queueMicrotask(() => {
|
|
412
|
+
if (this.readyState === this.CLOSED) {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
this.readyState = this.CONNECTING;
|
|
416
|
+
this.dispatchEvent(new Event("error"));
|
|
417
|
+
});
|
|
418
|
+
await delay(this[kReconnectionTime]);
|
|
419
|
+
queueMicrotask(async () => {
|
|
420
|
+
if (this.readyState !== this.CONNECTING) {
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
if (this[kLastEventId] !== "") {
|
|
424
|
+
this[kRequest].headers.set("last-event-id", this[kLastEventId]);
|
|
425
|
+
}
|
|
426
|
+
await this.connect();
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
failConnection() {
|
|
430
|
+
queueMicrotask(() => {
|
|
431
|
+
if (this.readyState !== this.CLOSED) {
|
|
432
|
+
this.readyState = this.CLOSED;
|
|
433
|
+
this.dispatchEvent(new Event("error"));
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
function isNetworkError(response) {
|
|
439
|
+
return response.type === "error" && response.status === 0 && response.statusText === "" && Array.from(response.headers.entries()).length === 0 && response.body === null;
|
|
440
|
+
}
|
|
441
|
+
var ControlCharacters = /* @__PURE__ */ ((ControlCharacters2) => {
|
|
442
|
+
ControlCharacters2[ControlCharacters2["NewLine"] = 10] = "NewLine";
|
|
443
|
+
ControlCharacters2[ControlCharacters2["CarriageReturn"] = 13] = "CarriageReturn";
|
|
444
|
+
ControlCharacters2[ControlCharacters2["Space"] = 32] = "Space";
|
|
445
|
+
ControlCharacters2[ControlCharacters2["Colon"] = 58] = "Colon";
|
|
446
|
+
return ControlCharacters2;
|
|
447
|
+
})(ControlCharacters || {});
|
|
448
|
+
class EventSourceParsingStream extends WritableStream {
|
|
449
|
+
constructor(underlyingSink) {
|
|
450
|
+
super({
|
|
451
|
+
write: (chunk) => {
|
|
452
|
+
this.processResponseBodyChunk(chunk);
|
|
453
|
+
},
|
|
454
|
+
abort: (reason) => {
|
|
455
|
+
this.underlyingSink.abort?.(reason);
|
|
456
|
+
},
|
|
457
|
+
close: () => {
|
|
458
|
+
this.underlyingSink.close?.();
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
this.underlyingSink = underlyingSink;
|
|
462
|
+
this.decoder = new TextDecoder();
|
|
463
|
+
this.position = 0;
|
|
464
|
+
}
|
|
465
|
+
decoder;
|
|
466
|
+
buffer;
|
|
467
|
+
position;
|
|
468
|
+
fieldLength;
|
|
469
|
+
discardTrailingNewline = false;
|
|
470
|
+
message = {
|
|
471
|
+
id: void 0,
|
|
472
|
+
event: void 0,
|
|
473
|
+
data: void 0,
|
|
474
|
+
retry: void 0
|
|
475
|
+
};
|
|
476
|
+
resetMessage() {
|
|
477
|
+
this.message = {
|
|
478
|
+
id: void 0,
|
|
479
|
+
event: void 0,
|
|
480
|
+
data: void 0,
|
|
481
|
+
retry: void 0
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
processResponseBodyChunk(chunk) {
|
|
485
|
+
if (this.buffer == null) {
|
|
486
|
+
this.buffer = chunk;
|
|
487
|
+
this.position = 0;
|
|
488
|
+
this.fieldLength = -1;
|
|
489
|
+
} else {
|
|
490
|
+
const nextBuffer = new Uint8Array(this.buffer.length + chunk.length);
|
|
491
|
+
nextBuffer.set(this.buffer);
|
|
492
|
+
nextBuffer.set(chunk, this.buffer.length);
|
|
493
|
+
this.buffer = nextBuffer;
|
|
494
|
+
}
|
|
495
|
+
const bufferLength = this.buffer.length;
|
|
496
|
+
let lineStart = 0;
|
|
497
|
+
while (this.position < bufferLength) {
|
|
498
|
+
if (this.discardTrailingNewline) {
|
|
499
|
+
if (this.buffer[this.position] === 10 /* NewLine */) {
|
|
500
|
+
lineStart = ++this.position;
|
|
501
|
+
}
|
|
502
|
+
this.discardTrailingNewline = false;
|
|
503
|
+
}
|
|
504
|
+
let lineEnd = -1;
|
|
505
|
+
for (; this.position < bufferLength && lineEnd === -1; ++this.position) {
|
|
506
|
+
switch (this.buffer[this.position]) {
|
|
507
|
+
case 58 /* Colon */: {
|
|
508
|
+
if (this.fieldLength === -1) {
|
|
509
|
+
this.fieldLength = this.position - lineStart;
|
|
510
|
+
}
|
|
511
|
+
break;
|
|
512
|
+
}
|
|
513
|
+
case 13 /* CarriageReturn */: {
|
|
514
|
+
this.discardTrailingNewline = true;
|
|
515
|
+
break;
|
|
516
|
+
}
|
|
517
|
+
case 10 /* NewLine */: {
|
|
518
|
+
lineEnd = this.position;
|
|
519
|
+
break;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
if (lineEnd === -1) {
|
|
524
|
+
break;
|
|
525
|
+
}
|
|
526
|
+
this.processLine(
|
|
527
|
+
this.buffer.subarray(lineStart, lineEnd),
|
|
528
|
+
this.fieldLength
|
|
529
|
+
);
|
|
530
|
+
lineStart = this.position;
|
|
531
|
+
this.fieldLength = -1;
|
|
532
|
+
}
|
|
533
|
+
if (lineStart === bufferLength) {
|
|
534
|
+
this.buffer = void 0;
|
|
535
|
+
} else if (lineStart !== 0) {
|
|
536
|
+
this.buffer = this.buffer.subarray(lineStart);
|
|
537
|
+
this.position -= lineStart;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
processLine(line, fieldLength) {
|
|
541
|
+
if (line.length === 0) {
|
|
542
|
+
if (this.message.data === void 0) {
|
|
543
|
+
this.message.event = void 0;
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
this.underlyingSink.message(this.message);
|
|
547
|
+
this.resetMessage();
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
if (fieldLength > 0) {
|
|
551
|
+
const field = this.decoder.decode(line.subarray(0, fieldLength));
|
|
552
|
+
const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
|
|
553
|
+
const value = this.decoder.decode(line.subarray(valueOffset));
|
|
554
|
+
switch (field) {
|
|
555
|
+
case "data": {
|
|
556
|
+
this.message.data = this.message.data ? this.message.data + "\n" + value : value;
|
|
557
|
+
break;
|
|
558
|
+
}
|
|
559
|
+
case "event": {
|
|
560
|
+
this.message.event = value;
|
|
561
|
+
break;
|
|
562
|
+
}
|
|
563
|
+
case "id": {
|
|
564
|
+
this.message.id = value;
|
|
565
|
+
break;
|
|
566
|
+
}
|
|
567
|
+
case "retry": {
|
|
568
|
+
const retry = parseInt(value, 10);
|
|
569
|
+
if (!isNaN(retry)) {
|
|
570
|
+
this.message.retry = retry;
|
|
571
|
+
}
|
|
572
|
+
break;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
export {
|
|
579
|
+
sse
|
|
580
|
+
};
|
|
581
|
+
//# sourceMappingURL=sse.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/sse.ts"],"sourcesContent":["import { invariant } from 'outvariant'\nimport { Emitter } from 'strict-event-emitter'\nimport type { ResponseResolver } from './handlers/RequestHandler'\nimport {\n HttpHandler,\n type HttpRequestResolverExtras,\n type HttpRequestParsedResult,\n} from './handlers/HttpHandler'\nimport type { Path, PathParams } from './utils/matching/matchRequestUrl'\nimport { delay } from './delay'\nimport { getTimestamp } from './utils/logging/getTimestamp'\nimport { devUtils } from './utils/internal/devUtils'\nimport { colors } from './ws/utils/attachWebSocketLogger'\nimport { toPublicUrl } from './utils/request/toPublicUrl'\n\ntype EventMapConstraint = {\n message?: unknown\n [key: string]: unknown\n [key: symbol | number]: never\n}\n\nexport type ServerSentEventResolverExtras<\n EventMap extends EventMapConstraint,\n Params extends PathParams,\n> = HttpRequestResolverExtras<Params> & {\n client: ServerSentEventClient<EventMap>\n server: ServerSentEventServer\n}\n\nexport type ServerSentEventResolver<\n EventMap extends EventMapConstraint,\n Params extends PathParams,\n> = ResponseResolver<ServerSentEventResolverExtras<EventMap, Params>, any, any>\n\nexport type ServerSentEventRequestHandler = <\n EventMap extends EventMapConstraint = { message: unknown },\n Params extends PathParams<keyof Params> = PathParams,\n RequestPath extends Path = Path,\n>(\n path: RequestPath,\n resolver: ServerSentEventResolver<EventMap, Params>,\n) => HttpHandler\n\nexport type ServerSentEventMessage<\n EventMap extends EventMapConstraint = { message: unknown },\n> =\n | ToEventDiscriminatedUnion<EventMap & { message: unknown }>\n | {\n id?: never\n event?: never\n data?: never\n retry: number\n }\n\n/**\n * Intercept Server-Sent Events (SSE).\n *\n * @example\n * sse('http://localhost:4321', ({ client }) => {\n * client.send({ data: 'hello world' })\n * })\n *\n * @see {@link https://mswjs.io/docs/sse/ Mocking Server-Sent Events}\n * @see {@link https://mswjs.io/docs/api/sse `sse()` API reference}\n */\nexport const sse: ServerSentEventRequestHandler = (path, resolver) => {\n return new ServerSentEventHandler(path, resolver)\n}\n\nclass ServerSentEventHandler<\n EventMap extends EventMapConstraint,\n> extends HttpHandler {\n constructor(path: Path, resolver: ServerSentEventResolver<EventMap, any>) {\n invariant(\n typeof EventSource !== 'undefined',\n 'Failed to construct a Server-Sent Event handler for path \"%s\": the EventSource API is not supported in this environment',\n path,\n )\n\n const clientEmitter = new Emitter<ServerSentEventClientEventMap>()\n\n super('GET', path, async (info) => {\n const responseInit: ResponseInit = {\n headers: {\n 'content-type': 'text/event-stream',\n 'cache-control': 'no-cache',\n connection: 'keep-alive',\n },\n }\n\n /**\n * @note Log the intercepted request early.\n * Normally, the `this.log()` method is called when the handler returns a response.\n * For SSE, call that method earlier so the logs are in correct order.\n */\n await super.log({\n request: info.request,\n /**\n * @note Construct a placeholder response since SSE response\n * is being streamed and cannot be cloned/consumed for logging.\n */\n response: new Response('[streaming]', responseInit),\n })\n this.#attachClientLogger(info.request, clientEmitter)\n\n const stream = new ReadableStream({\n async start(controller) {\n const client = new ServerSentEventClient<EventMap>({\n controller,\n emitter: clientEmitter,\n })\n const server = new ServerSentEventServer({\n request: info.request,\n client,\n })\n\n await resolver({\n ...info,\n client,\n server,\n })\n },\n })\n\n return new Response(stream, responseInit)\n })\n }\n\n async predicate(args: {\n request: Request\n parsedResult: HttpRequestParsedResult\n }) {\n if (args.request.headers.get('accept') !== 'text/event-stream') {\n return false\n }\n\n return super.predicate(args)\n }\n\n async log(_args: { request: Request; response: Response }): Promise<void> {\n /**\n * @note Skip the default `this.log()` logic so that when this handler is logged\n * upon handling the request, nothing is printed (we log SSE requests early).\n */\n return\n }\n\n #attachClientLogger(\n request: Request,\n emitter: Emitter<ServerSentEventClientEventMap>,\n ): void {\n const publicUrl = toPublicUrl(request.url)\n\n /* eslint-disable no-console */\n emitter.on('message', (payload) => {\n console.groupCollapsed(\n devUtils.formatMessage(\n `${getTimestamp()} SSE %s %c⇣%c ${payload.event}`,\n ),\n publicUrl,\n `color:${colors.mocked}`,\n 'color:inherit',\n )\n console.log(payload.frames)\n console.groupEnd()\n })\n\n emitter.on('error', () => {\n console.groupCollapsed(\n devUtils.formatMessage(`${getTimestamp()} SSE %s %c\\u00D7%c error`),\n publicUrl,\n `color: ${colors.system}`,\n 'color:inherit',\n )\n console.log('Handler:', this)\n console.groupEnd()\n })\n\n emitter.on('close', () => {\n console.groupCollapsed(\n devUtils.formatMessage(`${getTimestamp()} SSE %s %c■%c close`),\n publicUrl,\n `colors:${colors.system}`,\n 'color:inherit',\n )\n console.log('Handler:', this)\n console.groupEnd()\n })\n /* eslint-enable no-console */\n }\n}\n\ntype Values<T> = T[keyof T]\ntype Identity<T> = { [K in keyof T]: T[K] } & unknown\ntype ToEventDiscriminatedUnion<T> = Values<{\n [K in keyof T]: Identity<\n (K extends 'message'\n ? {\n id?: string\n event?: K\n data?: T[K]\n retry?: never\n }\n : {\n id?: string\n event: K\n data?: T[K]\n retry?: never\n }) &\n // Make the `data` field conditionally required through an intersection.\n (undefined extends T[K] ? unknown : { data: unknown })\n >\n}>\n\ntype ServerSentEventClientEventMap = {\n message: [\n payload: {\n id?: string\n event: string\n data?: unknown\n frames: Array<string>\n },\n ]\n error: []\n close: []\n}\n\nclass ServerSentEventClient<\n EventMap extends EventMapConstraint = { message: unknown },\n> {\n #encoder: TextEncoder\n #controller: ReadableStreamDefaultController\n #emitter: Emitter<ServerSentEventClientEventMap>\n\n constructor(args: {\n controller: ReadableStreamDefaultController\n emitter: Emitter<ServerSentEventClientEventMap>\n }) {\n this.#encoder = new TextEncoder()\n this.#controller = args.controller\n this.#emitter = args.emitter\n }\n\n /**\n * Sends the given payload to the intercepted `EventSource`.\n */\n public send(payload: ServerSentEventMessage<EventMap>): void {\n if ('retry' in payload && payload.retry != null) {\n this.#sendRetry(payload.retry)\n return\n }\n\n this.#sendMessage({\n id: payload.id,\n event: payload.event,\n data:\n typeof payload.data === 'object'\n ? JSON.stringify(payload.data)\n : payload.data,\n })\n }\n\n /**\n * Dispatches the given event on the intercepted `EventSource`.\n */\n public dispatchEvent(event: Event) {\n if (event instanceof MessageEvent) {\n /**\n * @note Use the internal send mechanism to skip normalization\n * of the message data (already normalized by the server).\n */\n this.#sendMessage({\n id: event.lastEventId || undefined,\n event: event.type === 'message' ? undefined : event.type,\n data: event.data,\n })\n return\n }\n\n if (event.type === 'error') {\n this.error()\n return\n }\n\n if (event.type === 'close') {\n this.close()\n return\n }\n }\n\n /**\n * Errors the underlying `EventSource`, closing the connection with an error.\n * This is equivalent to aborting the connection and will produce a `TypeError: Failed to fetch`\n * error.\n */\n public error(): void {\n this.#controller.error()\n this.#emitter.emit('error')\n }\n\n /**\n * Closes the underlying `EventSource`, closing the connection.\n */\n public close(): void {\n this.#controller.close()\n this.#emitter.emit('close')\n }\n\n #sendRetry(retry: number): void {\n if (typeof retry === 'number') {\n this.#controller.enqueue(this.#encoder.encode(`retry:${retry}\\n\\n`))\n }\n }\n\n #sendMessage(message: {\n id?: string\n event?: unknown\n data: unknown | undefined\n }): void {\n const frames: Array<string> = []\n\n if (message.id) {\n frames.push(`id:${message.id}`)\n }\n\n if (message.event) {\n frames.push(`event:${message.event?.toString()}`)\n }\n\n frames.push(`data:${message.data}`)\n frames.push('', '')\n\n this.#controller.enqueue(this.#encoder.encode(frames.join('\\n')))\n\n this.#emitter.emit('message', {\n id: message.id,\n event: message.event?.toString() || 'message',\n data: message.data,\n frames,\n })\n }\n}\n\nclass ServerSentEventServer {\n #request: Request\n #client: ServerSentEventClient<ServerSentEventClientEventMap>\n\n constructor(args: { request: Request; client: ServerSentEventClient<any> }) {\n this.#request = args.request\n this.#client = args.client\n }\n\n /**\n * Establishes the actual connection for this SSE request\n * and returns the `EventSource` instance.\n */\n public connect(): EventSource {\n const source = new ObservableEventSource(this.#request.url, {\n withCredentials: this.#request.credentials === 'include',\n headers: {\n /**\n * @note Mark this request as passthrough so it doesn't trigger\n * an infinite loop matching against the existing request handler.\n */\n accept: 'msw/passthrough',\n },\n })\n\n source[kOnAnyMessage] = (event) => {\n Object.defineProperties(event, {\n target: {\n value: this,\n enumerable: true,\n writable: true,\n configurable: true,\n },\n })\n\n // Schedule the server-to-client forwarding for the next tick\n // so the user can prevent the message event.\n queueMicrotask(() => {\n if (!event.defaultPrevented) {\n this.#client.dispatchEvent(event)\n }\n })\n }\n\n // Forward stream errors from the actual server to the client.\n source.addEventListener('error', (event) => {\n Object.defineProperties(event, {\n target: {\n value: this,\n enumerable: true,\n writable: true,\n configurable: true,\n },\n })\n\n queueMicrotask(() => {\n // Allow the user to opt-out from this forwarding.\n if (!event.defaultPrevented) {\n this.#client.dispatchEvent(event)\n }\n })\n })\n\n return source\n }\n}\n\ninterface ObservableEventSourceInit extends EventSourceInit {\n headers?: HeadersInit\n}\n\ntype EventHandler<EventType extends Event> = (\n this: EventSource,\n event: EventType,\n) => any\n\nconst kRequest = Symbol('kRequest')\nconst kReconnectionTime = Symbol('kReconnectionTime')\nconst kLastEventId = Symbol('kLastEventId')\nconst kAbortController = Symbol('kAbortController')\nconst kOnOpen = Symbol('kOnOpen')\nconst kOnMessage = Symbol('kOnMessage')\nconst kOnAnyMessage = Symbol('kOnAnyMessage')\nconst kOnError = Symbol('kOnError')\n\nclass ObservableEventSource extends EventTarget implements EventSource {\n static readonly CONNECTING = 0\n static readonly OPEN = 1\n static readonly CLOSED = 2\n\n public readonly CONNECTING = ObservableEventSource.CONNECTING\n public readonly OPEN = ObservableEventSource.OPEN\n public readonly CLOSED = ObservableEventSource.CLOSED\n\n public readyState: number\n public url: string\n public withCredentials: boolean\n\n private [kRequest]: Request\n private [kReconnectionTime]: number\n private [kLastEventId]: string\n private [kAbortController]: AbortController\n private [kOnOpen]: EventHandler<Event> | null = null\n private [kOnMessage]: EventHandler<MessageEvent> | null = null\n private [kOnAnyMessage]: EventHandler<MessageEvent> | null = null\n private [kOnError]: EventHandler<Event> | null = null\n\n constructor(url: string | URL, init?: ObservableEventSourceInit) {\n super()\n\n this.url = new URL(url).href\n this.withCredentials = init?.withCredentials ?? false\n\n this.readyState = this.CONNECTING\n\n // Support custom request init.\n const headers = new Headers(init?.headers || {})\n headers.append('accept', 'text/event-stream')\n\n this[kAbortController] = new AbortController()\n this[kReconnectionTime] = 2000\n this[kLastEventId] = ''\n this[kRequest] = new Request(this.url, {\n method: 'GET',\n headers,\n credentials: this.withCredentials ? 'include' : 'omit',\n signal: this[kAbortController].signal,\n })\n\n this.connect()\n }\n\n get onopen(): EventHandler<Event> | null {\n return this[kOnOpen]\n }\n\n set onopen(handler: EventHandler<Event>) {\n if (this[kOnOpen]) {\n this.removeEventListener('open', this[kOnOpen])\n }\n this[kOnOpen] = handler.bind(this)\n this.addEventListener('open', this[kOnOpen])\n }\n\n get onmessage(): EventHandler<MessageEvent> | null {\n return this[kOnMessage]\n }\n set onmessage(handler: EventHandler<MessageEvent>) {\n if (this[kOnMessage]) {\n this.removeEventListener('message', { handleEvent: this[kOnMessage] })\n }\n this[kOnMessage] = handler.bind(this)\n this.addEventListener('message', { handleEvent: this[kOnMessage] })\n }\n\n get onerror(): EventHandler<Event> | null {\n return this[kOnError]\n }\n set oneerror(handler: EventHandler<Event>) {\n if (this[kOnError]) {\n this.removeEventListener('error', { handleEvent: this[kOnError] })\n }\n this[kOnError] = handler.bind(this)\n this.addEventListener('error', { handleEvent: this[kOnError] })\n }\n\n public addEventListener<K extends keyof EventSourceEventMap>(\n type: K,\n listener: EventHandler<EventSourceEventMap[K]>,\n options?: boolean | AddEventListenerOptions,\n ): void\n public addEventListener(\n type: string,\n listener: EventHandler<MessageEvent>,\n options?: boolean | AddEventListenerOptions,\n ): void\n public addEventListener(\n type: string,\n listener: EventListenerOrEventListenerObject,\n options?: boolean | AddEventListenerOptions,\n ): void\n\n public addEventListener(\n type: string,\n listener: EventHandler<MessageEvent> | EventListenerOrEventListenerObject,\n options?: boolean | AddEventListenerOptions,\n ): void {\n super.addEventListener(\n type,\n listener as EventListenerOrEventListenerObject,\n options,\n )\n }\n\n public removeEventListener<K extends keyof EventSourceEventMap>(\n type: K,\n listener: (this: EventSource, ev: EventSourceEventMap[K]) => any,\n options?: boolean | EventListenerOptions,\n ): void\n public removeEventListener(\n type: string,\n listener: (this: EventSource, event: MessageEvent) => any,\n options?: boolean | EventListenerOptions,\n ): void\n public removeEventListener(\n type: string,\n listener: EventListenerOrEventListenerObject,\n options?: boolean | EventListenerOptions,\n ): void\n\n public removeEventListener(\n type: string,\n listener: EventHandler<MessageEvent> | EventListenerOrEventListenerObject,\n options?: boolean | AddEventListenerOptions,\n ): void {\n super.removeEventListener(\n type,\n listener as EventListenerOrEventListenerObject,\n options,\n )\n }\n\n public dispatchEvent(event: Event): boolean {\n return super.dispatchEvent(event)\n }\n\n public close(): void {\n this[kAbortController].abort()\n this.readyState = this.CLOSED\n }\n\n private async connect() {\n await fetch(this[kRequest])\n .then((response) => {\n this.processResponse(response)\n })\n .catch(() => {\n // Fail the connection on request errors instead of\n // throwing a generic \"Failed to fetch\" error.\n this.failConnection()\n })\n }\n\n private processResponse(response: Response): void {\n if (!response.body) {\n this.failConnection()\n return\n }\n\n if (isNetworkError(response)) {\n this.reestablishConnection()\n return\n }\n\n if (\n response.status !== 200 ||\n response.headers.get('content-type') !== 'text/event-stream'\n ) {\n this.failConnection()\n return\n }\n\n this.announceConnection()\n this.interpretResponseBody(response)\n }\n\n private announceConnection(): void {\n queueMicrotask(() => {\n if (this.readyState !== this.CLOSED) {\n this.readyState = this.OPEN\n this.dispatchEvent(new Event('open'))\n }\n })\n }\n\n private interpretResponseBody(response: Response): void {\n const parsingStream = new EventSourceParsingStream({\n message: (message) => {\n if (message.id) {\n this[kLastEventId] = message.id\n }\n\n if (message.retry) {\n this[kReconnectionTime] = message.retry\n }\n\n const messageEvent = new MessageEvent(\n message.event ? message.event : 'message',\n {\n data: message.data,\n origin: this[kRequest].url,\n lastEventId: this[kLastEventId],\n cancelable: true,\n },\n )\n\n this[kOnAnyMessage]?.(messageEvent)\n this.dispatchEvent(messageEvent)\n },\n abort: () => {\n throw new Error('Stream abort is not implemented')\n },\n close: () => {\n this.failConnection()\n },\n })\n\n response\n .body!.pipeTo(parsingStream)\n .then(() => {\n this.processResponseEndOfBody(response)\n })\n .catch(() => {\n this.failConnection()\n })\n }\n\n private processResponseEndOfBody(response: Response): void {\n if (!isNetworkError(response)) {\n this.reestablishConnection()\n }\n }\n\n private async reestablishConnection(): Promise<void> {\n queueMicrotask(() => {\n if (this.readyState === this.CLOSED) {\n return\n }\n\n this.readyState = this.CONNECTING\n this.dispatchEvent(new Event('error'))\n })\n\n await delay(this[kReconnectionTime])\n\n queueMicrotask(async () => {\n if (this.readyState !== this.CONNECTING) {\n return\n }\n\n if (this[kLastEventId] !== '') {\n this[kRequest].headers.set('last-event-id', this[kLastEventId])\n }\n\n await this.connect()\n })\n }\n\n private failConnection(): void {\n queueMicrotask(() => {\n if (this.readyState !== this.CLOSED) {\n this.readyState = this.CLOSED\n this.dispatchEvent(new Event('error'))\n }\n })\n }\n}\n\n/**\n * Checks if the given `Response` instance is a network error.\n * @see https://fetch.spec.whatwg.org/#concept-network-error\n */\nfunction isNetworkError(response: Response): boolean {\n return (\n response.type === 'error' &&\n response.status === 0 &&\n response.statusText === '' &&\n Array.from(response.headers.entries()).length === 0 &&\n response.body === null\n )\n}\n\nconst enum ControlCharacters {\n NewLine = 10,\n CarriageReturn = 13,\n Space = 32,\n Colon = 58,\n}\n\ninterface EventSourceMessage {\n id?: string\n event?: string\n data?: string\n retry?: number\n}\n\nclass EventSourceParsingStream extends WritableStream {\n private decoder: TextDecoder\n\n private buffer?: Uint8Array\n private position: number\n private fieldLength?: number\n private discardTrailingNewline = false\n\n private message: EventSourceMessage = {\n id: undefined,\n event: undefined,\n data: undefined,\n retry: undefined,\n }\n\n constructor(\n private underlyingSink: {\n message: (message: EventSourceMessage) => void\n abort?: (reason: any) => void\n close?: () => void\n },\n ) {\n super({\n write: (chunk) => {\n this.processResponseBodyChunk(chunk)\n },\n abort: (reason) => {\n this.underlyingSink.abort?.(reason)\n },\n close: () => {\n this.underlyingSink.close?.()\n },\n })\n\n this.decoder = new TextDecoder()\n this.position = 0\n }\n\n private resetMessage(): void {\n this.message = {\n id: undefined,\n event: undefined,\n data: undefined,\n retry: undefined,\n }\n }\n\n private processResponseBodyChunk(chunk: Uint8Array): void {\n if (this.buffer == null) {\n this.buffer = chunk\n this.position = 0\n this.fieldLength = -1\n } else {\n const nextBuffer = new Uint8Array(this.buffer.length + chunk.length)\n nextBuffer.set(this.buffer)\n nextBuffer.set(chunk, this.buffer.length)\n this.buffer = nextBuffer\n }\n\n const bufferLength = this.buffer.length\n let lineStart = 0\n\n while (this.position < bufferLength) {\n if (this.discardTrailingNewline) {\n if (this.buffer[this.position] === ControlCharacters.NewLine) {\n lineStart = ++this.position\n }\n\n this.discardTrailingNewline = false\n }\n\n let lineEnd = -1\n\n for (; this.position < bufferLength && lineEnd === -1; ++this.position) {\n switch (this.buffer[this.position]) {\n case ControlCharacters.Colon: {\n if (this.fieldLength === -1) {\n this.fieldLength = this.position - lineStart\n }\n break\n }\n\n case ControlCharacters.CarriageReturn: {\n this.discardTrailingNewline = true\n break\n }\n\n case ControlCharacters.NewLine: {\n lineEnd = this.position\n break\n }\n }\n }\n\n if (lineEnd === -1) {\n break\n }\n\n this.processLine(\n this.buffer.subarray(lineStart, lineEnd),\n this.fieldLength!,\n )\n\n lineStart = this.position\n this.fieldLength = -1\n }\n\n if (lineStart === bufferLength) {\n this.buffer = undefined\n } else if (lineStart !== 0) {\n this.buffer = this.buffer.subarray(lineStart)\n this.position -= lineStart\n }\n }\n\n private processLine(line: Uint8Array, fieldLength: number): void {\n // New line indicates the end of the message. Dispatch it.\n if (line.length === 0) {\n // Prevent dispatching the message if the data is an empty string.\n // That is a no-op per spec.\n if (this.message.data === undefined) {\n this.message.event = undefined\n return\n }\n\n this.underlyingSink.message(this.message)\n this.resetMessage()\n return\n }\n\n // Otherwise, keep accumulating message fields until the new line.\n if (fieldLength > 0) {\n const field = this.decoder.decode(line.subarray(0, fieldLength))\n const valueOffset =\n fieldLength +\n (line[fieldLength + 1] === ControlCharacters.Space ? 2 : 1)\n const value = this.decoder.decode(line.subarray(valueOffset))\n\n switch (field) {\n case 'data': {\n this.message.data = this.message.data\n ? this.message.data + '\\n' + value\n : value\n break\n }\n\n case 'event': {\n this.message.event = value\n break\n }\n\n case 'id': {\n this.message.id = value\n break\n }\n\n case 'retry': {\n const retry = parseInt(value, 10)\n\n if (!isNaN(retry)) {\n this.message.retry = retry\n }\n break\n }\n }\n }\n }\n}\n"],"mappings":"AAAA,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AAExB;AAAA,EACE;AAAA,OAGK;AAEP,SAAS,aAAa;AACtB,SAAS,oBAAoB;AAC7B,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,SAAS,mBAAmB;AAoDrB,MAAM,MAAqC,CAAC,MAAM,aAAa;AACpE,SAAO,IAAI,uBAAuB,MAAM,QAAQ;AAClD;AAEA,MAAM,+BAEI,YAAY;AAAA,EACpB,YAAY,MAAY,UAAkD;AACxE;AAAA,MACE,OAAO,gBAAg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K,SAAS;AACZ,gBAAM,QAAQ,SAAS,OAAO,EAAE;AAEhC,cAAI,CAAC,MAAM,KAAK,GAAG;AACjB,iBAAK,QAAQ,QAAQ;AAAA,UACvB;AACA;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":["ControlCharacters"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/utils/internal/isObject.ts"],"sourcesContent":["/**\n * Determines if the given value is an object.\n */\nexport function isObject(value: any):
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/internal/isObject.ts"],"sourcesContent":["/**\n * Determines if the given value is an object.\n */\nexport function isObject(value: any): value is Record<string, any> {\n return value != null && typeof value === 'object' && !Array.isArray(value)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,SAAS,SAAS,OAA0C;AACjE,SAAO,SAAS,QAAQ,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AAC3E;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/utils/internal/isObject.ts"],"sourcesContent":["/**\n * Determines if the given value is an object.\n */\nexport function isObject(value: any):
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/internal/isObject.ts"],"sourcesContent":["/**\n * Determines if the given value is an object.\n */\nexport function isObject(value: any): value is Record<string, any> {\n return value != null && typeof value === 'object' && !Array.isArray(value)\n}\n"],"mappings":"AAGO,SAAS,SAAS,OAA0C;AACjE,SAAO,SAAS,QAAQ,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AAC3E;","names":[]}
|