@relative-ci/core 6.0.0 → 6.0.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/lib/cjs/__/content-type/dist/index.js +155 -71
  2. package/lib/cjs/__/content-type/dist/index.js.map +1 -1
  3. package/lib/cjs/__/undici/lib/core/request.js +68 -2
  4. package/lib/cjs/__/undici/lib/core/request.js.map +1 -1
  5. package/lib/cjs/__/undici/lib/dispatcher/agent.js +6 -2
  6. package/lib/cjs/__/undici/lib/dispatcher/agent.js.map +1 -1
  7. package/lib/cjs/__/undici/lib/dispatcher/client-h1.js +18 -9
  8. package/lib/cjs/__/undici/lib/dispatcher/client-h1.js.map +1 -1
  9. package/lib/cjs/__/undici/lib/dispatcher/client-h2.js +73 -23
  10. package/lib/cjs/__/undici/lib/dispatcher/client-h2.js.map +1 -1
  11. package/lib/cjs/__/undici/lib/dispatcher/client.js +3 -2
  12. package/lib/cjs/__/undici/lib/dispatcher/client.js.map +1 -1
  13. package/lib/cjs/__/undici/lib/dispatcher/dispatcher-base.js +14 -0
  14. package/lib/cjs/__/undici/lib/dispatcher/dispatcher-base.js.map +1 -1
  15. package/lib/cjs/__/undici/lib/handler/retry-handler.js +4 -1
  16. package/lib/cjs/__/undici/lib/handler/retry-handler.js.map +1 -1
  17. package/lib/cjs/__/undici/lib/web/eventsource/eventsource-stream.js +93 -10
  18. package/lib/cjs/__/undici/lib/web/eventsource/eventsource-stream.js.map +1 -1
  19. package/lib/cjs/__/undici/lib/web/eventsource/eventsource.js +5 -1
  20. package/lib/cjs/__/undici/lib/web/eventsource/eventsource.js.map +1 -1
  21. package/lib/cjs/__/undici/lib/web/fetch/index.js +7 -9
  22. package/lib/cjs/__/undici/lib/web/fetch/index.js.map +1 -1
  23. package/lib/cjs/__/undici/lib/web/websocket/receiver.js +14 -0
  24. package/lib/cjs/__/undici/lib/web/websocket/receiver.js.map +1 -1
  25. package/lib/cjs/env/load.js +1 -1
  26. package/lib/cjs/env/load.js.map +1 -1
  27. package/lib/esm/__/content-type/dist/index.js +155 -71
  28. package/lib/esm/__/content-type/dist/index.js.map +1 -1
  29. package/lib/esm/__/undici/lib/core/request.js +68 -2
  30. package/lib/esm/__/undici/lib/core/request.js.map +1 -1
  31. package/lib/esm/__/undici/lib/dispatcher/agent.js +6 -2
  32. package/lib/esm/__/undici/lib/dispatcher/agent.js.map +1 -1
  33. package/lib/esm/__/undici/lib/dispatcher/client-h1.js +18 -9
  34. package/lib/esm/__/undici/lib/dispatcher/client-h1.js.map +1 -1
  35. package/lib/esm/__/undici/lib/dispatcher/client-h2.js +72 -23
  36. package/lib/esm/__/undici/lib/dispatcher/client-h2.js.map +1 -1
  37. package/lib/esm/__/undici/lib/dispatcher/client.js +3 -2
  38. package/lib/esm/__/undici/lib/dispatcher/client.js.map +1 -1
  39. package/lib/esm/__/undici/lib/dispatcher/dispatcher-base.js +10 -0
  40. package/lib/esm/__/undici/lib/dispatcher/dispatcher-base.js.map +1 -1
  41. package/lib/esm/__/undici/lib/handler/retry-handler.js +4 -1
  42. package/lib/esm/__/undici/lib/handler/retry-handler.js.map +1 -1
  43. package/lib/esm/__/undici/lib/web/eventsource/eventsource-stream.js +92 -10
  44. package/lib/esm/__/undici/lib/web/eventsource/eventsource-stream.js.map +1 -1
  45. package/lib/esm/__/undici/lib/web/eventsource/eventsource.js +5 -1
  46. package/lib/esm/__/undici/lib/web/eventsource/eventsource.js.map +1 -1
  47. package/lib/esm/__/undici/lib/web/fetch/index.js +7 -9
  48. package/lib/esm/__/undici/lib/web/fetch/index.js.map +1 -1
  49. package/lib/esm/__/undici/lib/web/websocket/receiver.js +14 -0
  50. package/lib/esm/__/undici/lib/web/websocket/receiver.js.map +1 -1
  51. package/lib/esm/env/load.js +1 -1
  52. package/lib/esm/env/load.js.map +1 -1
  53. package/lib/esm/index.js +2 -2
  54. package/package.json +10 -10
@@ -1,3 +1,4 @@
1
+ import require$$0$1 from 'node:buffer';
1
2
  import require$$0 from 'node:stream';
2
3
  import { __require as requireUtil } from './util.js';
3
4
 
@@ -7,6 +8,7 @@ var hasRequiredEventsourceStream;
7
8
  function requireEventsourceStream () {
8
9
  if (hasRequiredEventsourceStream) return eventsourceStream;
9
10
  hasRequiredEventsourceStream = 1;
11
+ const buffer = require$$0$1;
10
12
  const { Transform } = require$$0;
11
13
  const { isASCIINumber, isValidLastEventId } = requireUtil();
12
14
 
@@ -31,11 +33,19 @@ function requireEventsourceStream () {
31
33
  */
32
34
  const SPACE = 0x20;
33
35
 
36
+ const defaultMaxEventSize = buffer.kStringMaxLength;
37
+
34
38
  const DATA = Buffer.from('data');
35
39
  const EVENT = Buffer.from('event');
36
40
  const ID = Buffer.from('id');
37
41
  const RETRY = Buffer.from('retry');
38
42
 
43
+ // Each data field creates a string node, and each unconsumed input chunk keeps
44
+ // a Buffer wrapper. The absolute ceiling protects the large default byte limit.
45
+ const minParserItems = 1024;
46
+ const maxParserItems = 131072;
47
+ const bytesPerParserItem = 128;
48
+
39
49
  function isASCIINumberBytes (buffer, start) {
40
50
  if (start >= buffer.length) {
41
51
  return false
@@ -74,6 +84,12 @@ function requireEventsourceStream () {
74
84
  return true
75
85
  }
76
86
 
87
+ function createMaxEventSizeExceededError () {
88
+ const error = new Error('EventSource message size exceeded');
89
+ error.aborted = false;
90
+ return error
91
+ }
92
+
77
93
  /**
78
94
  * @typedef {object} EventSourceStreamEvent
79
95
  * @type {object}
@@ -122,6 +138,13 @@ function requireEventsourceStream () {
122
138
  pos = 0
123
139
  lineChunkIndex = 0
124
140
  linePos = 0
141
+ lineLength = 0
142
+ eventSize = 0
143
+ eventFieldSizes = { data: 0, event: 0, id: 0, retry: 0 }
144
+ dataLineCount = 0
145
+ maxEventSize
146
+ maxDataLines
147
+ maxBufferedChunks
125
148
 
126
149
  event = {
127
150
  data: undefined,
@@ -132,6 +155,7 @@ function requireEventsourceStream () {
132
155
 
133
156
  /**
134
157
  * @param {object} options
158
+ * @param {number} [options.maxEventSize]
135
159
  * @param {eventSourceSettings} options.eventSourceSettings
136
160
  * @param {Function} [options.push]
137
161
  */
@@ -143,6 +167,12 @@ function requireEventsourceStream () {
143
167
  super(options);
144
168
 
145
169
  this.state = options.eventSourceSettings || {};
170
+ this.maxEventSize = options.maxEventSize ?? defaultMaxEventSize;
171
+ const parserItemLimit = this.maxEventSize > 0
172
+ ? Math.min(maxParserItems, Math.max(minParserItems, Math.floor(this.maxEventSize / bytesPerParserItem)))
173
+ : 0;
174
+ this.maxDataLines = parserItemLimit;
175
+ this.maxBufferedChunks = parserItemLimit;
146
176
  if (options.push) {
147
177
  this.push = options.push;
148
178
  }
@@ -160,6 +190,14 @@ function requireEventsourceStream () {
160
190
  return
161
191
  }
162
192
 
193
+ // A leading line ending can immediately release the currently buffered
194
+ // line, even when it uses the final allowed chunk slot.
195
+ if (this.maxEventSize > 0 &&
196
+ this.chunks.length >= this.maxBufferedChunks &&
197
+ chunk[0] !== LF && chunk[0] !== CR) {
198
+ callback(createMaxEventSizeExceededError());
199
+ return
200
+ }
163
201
  this.chunks.push(chunk);
164
202
 
165
203
  // Strip leading byte-order-mark if we opened the stream and started
@@ -238,7 +276,12 @@ function requireEventsourceStream () {
238
276
 
239
277
  // In any case, we can process the line as we reached an
240
278
  // end-of-line character
241
- this.parseLine(this.readLine(), this.event);
279
+ try {
280
+ this.parseLine(this.readLine(), this.event);
281
+ } catch (error) {
282
+ callback(error);
283
+ return
284
+ }
242
285
  this.consumeCurrentByte();
243
286
  // A line was processed and this could be the end of the event. We need
244
287
  // to check if the next line is empty to determine if the event is
@@ -247,15 +290,28 @@ function requireEventsourceStream () {
247
290
  continue
248
291
  }
249
292
 
293
+ // readLine() is only called after CR or LF. Reject an unfinished line
294
+ // before it can retain an unbounded number of decoded chunks. The seven
295
+ // extra bytes allow the longest field prefix ("event: " or "retry: ").
296
+ if (this.maxEventSize > 0 && ++this.lineLength > this.maxEventSize + 7) {
297
+ callback(createMaxEventSizeExceededError());
298
+ return
299
+ }
250
300
  this.advanceCursor();
251
301
  }
252
302
 
253
303
  callback();
254
304
  }
255
305
 
306
+ _destroy (error, callback) {
307
+ this.chunks.length = 0;
308
+ this.clearEvent();
309
+ super._destroy(error, callback);
310
+ }
311
+
256
312
  /**
257
313
  * @param {Buffer} line
258
- * @param {EventStreamEvent} event
314
+ * @param {EventSourceStreamEvent} event
259
315
  */
260
316
  parseLine (line, event) {
261
317
  // If the line is empty (a blank line)
@@ -289,6 +345,13 @@ function requireEventsourceStream () {
289
345
  }
290
346
 
291
347
  if (isFieldName(line, fieldLength, DATA)) {
348
+ if (this.maxEventSize > 0 && this.dataLineCount >= this.maxDataLines) {
349
+ throw createMaxEventSizeExceededError()
350
+ }
351
+ const valueBytes = line.length - valueStart;
352
+ const dataSize = this.eventFieldSizes.data + (event.data === undefined ? 0 : 1) + valueBytes;
353
+ this.setEventFieldSize('data', dataSize);
354
+
292
355
  const value = line.toString('utf8', valueStart);
293
356
 
294
357
  if (event.data === undefined) {
@@ -296,11 +359,13 @@ function requireEventsourceStream () {
296
359
  } else {
297
360
  event.data += `\n${value}`;
298
361
  }
362
+ this.dataLineCount++;
299
363
  return
300
364
  }
301
365
 
302
366
  if (isFieldName(line, fieldLength, RETRY)) {
303
367
  if (isASCIINumberBytes(line, valueStart)) {
368
+ this.setEventFieldSize('retry', line.length - valueStart);
304
369
  event.retry = line.toString('utf8', valueStart);
305
370
  }
306
371
  return
@@ -308,20 +373,29 @@ function requireEventsourceStream () {
308
373
 
309
374
  if (isFieldName(line, fieldLength, ID)) {
310
375
  if (isValidLastEventIdBytes(line, valueStart)) {
376
+ this.setEventFieldSize('id', line.length - valueStart);
311
377
  event.id = line.toString('utf8', valueStart);
312
378
  }
313
379
  return
314
380
  }
315
381
 
316
382
  if (isFieldName(line, fieldLength, EVENT)) {
317
- const value = line.toString('utf8', valueStart);
318
-
319
- if (value.length > 0) {
320
- event.event = value;
383
+ if (valueStart < line.length) {
384
+ this.setEventFieldSize('event', line.length - valueStart);
385
+ event.event = line.toString('utf8', valueStart);
321
386
  }
322
387
  }
323
388
  }
324
389
 
390
+ setEventFieldSize (field, size) {
391
+ const eventSize = this.eventSize - this.eventFieldSizes[field] + size;
392
+ if (this.maxEventSize > 0 && eventSize > this.maxEventSize) {
393
+ throw createMaxEventSizeExceededError()
394
+ }
395
+ this.eventSize = eventSize;
396
+ this.eventFieldSizes[field] = size;
397
+ }
398
+
325
399
  /**
326
400
  * @param {EventSourceStreamEvent} event
327
401
  */
@@ -352,6 +426,12 @@ function requireEventsourceStream () {
352
426
  this.event.event = undefined;
353
427
  this.event.id = undefined;
354
428
  this.event.retry = undefined;
429
+ this.eventSize = 0;
430
+ this.dataLineCount = 0;
431
+ this.eventFieldSizes.data = 0;
432
+ this.eventFieldSizes.event = 0;
433
+ this.eventFieldSizes.id = 0;
434
+ this.eventFieldSizes.retry = 0;
355
435
  }
356
436
 
357
437
  hasPendingEvent () {
@@ -387,14 +467,16 @@ function requireEventsourceStream () {
387
467
  syncLineStartToCursor () {
388
468
  this.lineChunkIndex = this.chunkIndex;
389
469
  this.linePos = this.pos;
470
+ this.lineLength = 0;
390
471
  this.dropConsumedChunks();
391
472
  }
392
473
 
393
474
  dropConsumedChunks () {
394
- while (this.lineChunkIndex > 0) {
395
- this.chunks.shift();
396
- this.lineChunkIndex--;
397
- this.chunkIndex--;
475
+ if (this.lineChunkIndex > 0) {
476
+ const consumed = this.lineChunkIndex;
477
+ this.chunks.splice(0, consumed);
478
+ this.lineChunkIndex = 0;
479
+ this.chunkIndex -= consumed;
398
480
  }
399
481
 
400
482
  if (this.chunkIndex === this.chunks.length) {
@@ -1 +1 @@
1
- {"version":3,"file":"eventsource-stream.js","sources":["../../../../../../../../../node_modules/undici/lib/web/eventsource/eventsource-stream.js"],"sourcesContent":["'use strict'\nconst { Transform } = require('node:stream')\nconst { isASCIINumber, isValidLastEventId } = require('./util')\n\n/**\n * @type {number[]} BOM\n */\nconst BOM = [0xEF, 0xBB, 0xBF]\n/**\n * @type {10} LF\n */\nconst LF = 0x0A\n/**\n * @type {13} CR\n */\nconst CR = 0x0D\n/**\n * @type {58} COLON\n */\nconst COLON = 0x3A\n/**\n * @type {32} SPACE\n */\nconst SPACE = 0x20\n\nconst DATA = Buffer.from('data')\nconst EVENT = Buffer.from('event')\nconst ID = Buffer.from('id')\nconst RETRY = Buffer.from('retry')\n\nfunction isASCIINumberBytes (buffer, start) {\n if (start >= buffer.length) {\n return false\n }\n\n for (let i = start; i < buffer.length; i++) {\n if (buffer[i] < 0x30 || buffer[i] > 0x39) {\n return false\n }\n }\n\n return true\n}\n\nfunction isValidLastEventIdBytes (buffer, start) {\n for (let i = start; i < buffer.length; i++) {\n if (buffer[i] === 0x00) {\n return false\n }\n }\n\n return true\n}\n\nfunction isFieldName (line, length, field) {\n if (length !== field.length) {\n return false\n }\n\n for (let i = 0; i < length; i++) {\n if (line[i] !== field[i]) {\n return false\n }\n }\n\n return true\n}\n\n/**\n * @typedef {object} EventSourceStreamEvent\n * @type {object}\n * @property {string} [event] The event type.\n * @property {string} [data] The data of the message.\n * @property {string} [id] A unique ID for the event.\n * @property {string} [retry] The reconnection time, in milliseconds.\n */\n\n/**\n * @typedef eventSourceSettings\n * @type {object}\n * @property {string} lastEventId The last event ID received from the server.\n * @property {string} origin The origin of the event source.\n * @property {number} reconnectionTime The reconnection time, in milliseconds.\n */\n\nclass EventSourceStream extends Transform {\n /**\n * @type {eventSourceSettings}\n */\n state = null\n\n /**\n * Leading byte-order-mark check.\n * @type {boolean}\n */\n checkBOM = true\n\n /**\n * @type {boolean}\n */\n crlfCheck = false\n\n /**\n * @type {boolean}\n */\n eventEndCheck = false\n\n /**\n * @type {Buffer[]}\n */\n chunks = []\n\n chunkIndex = 0\n pos = 0\n lineChunkIndex = 0\n linePos = 0\n\n event = {\n data: undefined,\n event: undefined,\n id: undefined,\n retry: undefined\n }\n\n /**\n * @param {object} options\n * @param {eventSourceSettings} options.eventSourceSettings\n * @param {Function} [options.push]\n */\n constructor (options = {}) {\n // Enable object mode as EventSourceStream emits objects of shape\n // EventSourceStreamEvent\n options.readableObjectMode = true\n\n super(options)\n\n this.state = options.eventSourceSettings || {}\n if (options.push) {\n this.push = options.push\n }\n }\n\n /**\n * @param {Buffer} chunk\n * @param {string} _encoding\n * @param {Function} callback\n * @returns {void}\n */\n _transform (chunk, _encoding, callback) {\n if (chunk.length === 0) {\n callback()\n return\n }\n\n this.chunks.push(chunk)\n\n // Strip leading byte-order-mark if we opened the stream and started\n // the processing of the incoming data\n if (this.checkBOM) {\n if (this.handleBOM()) {\n callback()\n return\n }\n }\n\n while (this.hasCurrentByte()) {\n const byte = this.currentByte()\n\n // If the previous line ended with an end-of-line, we need to check\n // if the next character is also an end-of-line.\n if (this.eventEndCheck) {\n // If the the current character is an end-of-line, then the event\n // is finished and we can process it\n\n // If the previous line ended with a carriage return, we need to\n // check if the current character is a line feed and remove it\n // from the buffer.\n if (this.crlfCheck) {\n // If the current character is a line feed, we can remove it\n // from the buffer and reset the crlfCheck flag\n if (byte === LF) {\n this.crlfCheck = false\n this.consumeCurrentByte()\n\n // It is possible that the line feed is not the end of the\n // event. We need to check if the next character is an\n // end-of-line character to determine if the event is\n // finished. We simply continue the loop to check the next\n // character.\n\n // As we removed the line feed from the buffer and set the\n // crlfCheck flag to false, we basically don't make any\n // distinction between a line feed and a carriage return.\n continue\n }\n this.crlfCheck = false\n }\n\n if (byte === LF || byte === CR) {\n // If the current character is a carriage return, we need to\n // set the crlfCheck flag to true, as we need to check if the\n // next character is a line feed so we can remove it from the\n // buffer\n if (byte === CR) {\n this.crlfCheck = true\n }\n\n this.consumeCurrentByte()\n if (this.hasPendingEvent()) {\n this.processEvent(this.event)\n }\n this.clearEvent()\n continue\n }\n // If the current character is not an end-of-line, then the event\n // is not finished and we have to reset the eventEndCheck flag\n this.eventEndCheck = false\n continue\n }\n\n // If the current character is an end-of-line, we can process the\n // line\n if (byte === LF || byte === CR) {\n // If the current character is a carriage return, we need to\n // set the crlfCheck flag to true, as we need to check if the\n // next character is a line feed\n if (byte === CR) {\n this.crlfCheck = true\n }\n\n // In any case, we can process the line as we reached an\n // end-of-line character\n this.parseLine(this.readLine(), this.event)\n this.consumeCurrentByte()\n // A line was processed and this could be the end of the event. We need\n // to check if the next line is empty to determine if the event is\n // finished.\n this.eventEndCheck = true\n continue\n }\n\n this.advanceCursor()\n }\n\n callback()\n }\n\n /**\n * @param {Buffer} line\n * @param {EventStreamEvent} event\n */\n parseLine (line, event) {\n // If the line is empty (a blank line)\n // Dispatch the event, as defined below.\n // This will be handled in the _transform method\n if (line.length === 0) {\n return\n }\n\n // If the line starts with a U+003A COLON character (:)\n // Ignore the line.\n const colonPosition = line.indexOf(COLON)\n if (colonPosition === 0) {\n return\n }\n\n let fieldLength = line.length\n let valueStart = line.length\n\n // If the line contains a U+003A COLON character (:)\n if (colonPosition !== -1) {\n fieldLength = colonPosition\n\n // Collect the characters on the line after the first U+003A COLON\n // character (:), and let value be that string.\n // If value starts with a U+0020 SPACE character, remove it from value.\n valueStart = colonPosition + 1\n if (line[valueStart] === SPACE) {\n ++valueStart\n }\n }\n\n if (isFieldName(line, fieldLength, DATA)) {\n const value = line.toString('utf8', valueStart)\n\n if (event.data === undefined) {\n event.data = value\n } else {\n event.data += `\\n${value}`\n }\n return\n }\n\n if (isFieldName(line, fieldLength, RETRY)) {\n if (isASCIINumberBytes(line, valueStart)) {\n event.retry = line.toString('utf8', valueStart)\n }\n return\n }\n\n if (isFieldName(line, fieldLength, ID)) {\n if (isValidLastEventIdBytes(line, valueStart)) {\n event.id = line.toString('utf8', valueStart)\n }\n return\n }\n\n if (isFieldName(line, fieldLength, EVENT)) {\n const value = line.toString('utf8', valueStart)\n\n if (value.length > 0) {\n event.event = value\n }\n }\n }\n\n /**\n * @param {EventSourceStreamEvent} event\n */\n processEvent (event) {\n if (event.retry && isASCIINumber(event.retry)) {\n this.state.reconnectionTime = parseInt(event.retry, 10)\n }\n\n if (event.id && isValidLastEventId(event.id)) {\n this.state.lastEventId = event.id\n }\n\n // only dispatch event, when data is provided\n if (event.data !== undefined) {\n this.push({\n type: event.event || 'message',\n options: {\n data: event.data,\n lastEventId: this.state.lastEventId,\n origin: this.state.origin\n }\n })\n }\n }\n\n clearEvent () {\n this.event.data = undefined\n this.event.event = undefined\n this.event.id = undefined\n this.event.retry = undefined\n }\n\n hasPendingEvent () {\n return this.event.data !== undefined ||\n this.event.event !== undefined ||\n this.event.id !== undefined ||\n this.event.retry !== undefined\n }\n\n hasCurrentByte () {\n return this.chunkIndex < this.chunks.length &&\n this.pos < this.chunks[this.chunkIndex].length\n }\n\n currentByte () {\n return this.chunks[this.chunkIndex][this.pos]\n }\n\n consumeCurrentByte () {\n this.advanceCursor()\n this.syncLineStartToCursor()\n }\n\n advanceCursor () {\n this.pos++\n\n while (this.chunkIndex < this.chunks.length && this.pos >= this.chunks[this.chunkIndex].length) {\n this.chunkIndex++\n this.pos = 0\n }\n }\n\n syncLineStartToCursor () {\n this.lineChunkIndex = this.chunkIndex\n this.linePos = this.pos\n this.dropConsumedChunks()\n }\n\n dropConsumedChunks () {\n while (this.lineChunkIndex > 0) {\n this.chunks.shift()\n this.lineChunkIndex--\n this.chunkIndex--\n }\n\n if (this.chunkIndex === this.chunks.length) {\n this.chunks.length = 0\n this.chunkIndex = 0\n this.pos = 0\n this.lineChunkIndex = 0\n this.linePos = 0\n }\n }\n\n readLine () {\n if (this.lineChunkIndex === this.chunkIndex) {\n return this.chunks[this.chunkIndex].subarray(this.linePos, this.pos)\n }\n\n const chunks = []\n let length = 0\n\n for (let i = this.lineChunkIndex; i <= this.chunkIndex; i++) {\n const chunk = this.chunks[i]\n const start = i === this.lineChunkIndex ? this.linePos : 0\n const end = i === this.chunkIndex ? this.pos : chunk.length\n const slice = chunk.subarray(start, end)\n length += slice.length\n chunks.push(slice)\n }\n\n return Buffer.concat(chunks, length)\n }\n\n peekBufferedByte (offset) {\n let chunkIndex = this.lineChunkIndex\n let pos = this.linePos\n\n while (chunkIndex < this.chunks.length) {\n const chunk = this.chunks[chunkIndex]\n const remaining = chunk.length - pos\n\n if (offset < remaining) {\n return chunk[pos + offset]\n }\n\n offset -= remaining\n chunkIndex++\n pos = 0\n }\n }\n\n discardLeadingBytes (count) {\n while (count > 0 && this.lineChunkIndex < this.chunks.length) {\n const chunk = this.chunks[this.lineChunkIndex]\n const remaining = chunk.length - this.linePos\n\n if (count < remaining) {\n this.linePos += count\n count = 0\n } else {\n count -= remaining\n this.lineChunkIndex++\n this.linePos = 0\n }\n }\n\n this.chunkIndex = this.lineChunkIndex\n this.pos = this.linePos\n this.dropConsumedChunks()\n }\n\n handleBOM () {\n const first = this.peekBufferedByte(0)\n const second = this.peekBufferedByte(1)\n const third = this.peekBufferedByte(2)\n\n if (second === undefined) {\n if (first === BOM[0]) {\n return true\n }\n\n this.checkBOM = false\n return true\n }\n\n if (third === undefined) {\n if (first === BOM[0] && second === BOM[1]) {\n return true\n }\n\n this.checkBOM = false\n return false\n }\n\n if (first === BOM[0] && second === BOM[1] && third === BOM[2]) {\n this.discardLeadingBytes(3)\n }\n\n this.checkBOM = false\n return !this.hasCurrentByte()\n }\n}\n\nmodule.exports = {\n EventSourceStream\n}\n"],"names":["require$$1"],"mappings":";;;;;;;;;CACA,MAAM,EAAE,SAAS,EAAE,GAAG;AACtB,CAAA,MAAM,EAAE,aAAa,EAAE,kBAAkB,EAAE,GAAGA,WAAA;;AAE9C;AACA;AACA;AACA,CAAA,MAAM,GAAG,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI;AAC7B;AACA;AACA;AACA,CAAA,MAAM,EAAE,GAAG;AACX;AACA;AACA;AACA,CAAA,MAAM,EAAE,GAAG;AACX;AACA;AACA;AACA,CAAA,MAAM,KAAK,GAAG;AACd;AACA;AACA;AACA,CAAA,MAAM,KAAK,GAAG;;AAEd,CAAA,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM;AAC/B,CAAA,MAAM,KAAK,GAAG,MAAM,CAAC,IA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I,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;AAC3B,KAAI,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC;KAChB,IAAI,CAAC,kBAAkB;AAC3B,GAAA;;GAEE,SAAS,CAAC,GAAG;AACf,KAAI,MAAM,KAAK,GAAG,IAAI,CAAC,gBAAgB,CAAC,CAAC;AACzC,KAAI,MAAM,MAAM,GAAG,IAAI,CAAC,gBAAgB,CAAC,CAAC;AAC1C,KAAI,MAAM,KAAK,GAAG,IAAI,CAAC,gBAAgB,CAAC,CAAC;;AAEzC,KAAI,IAAI,MAAM,KAAK,SAAS,EAAE;AAC9B,OAAM,IAAI,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE;AAC5B,SAAQ,OAAO;AACf,OAAA;;OAEM,IAAI,CAAC,QAAQ,GAAG;AACtB,OAAM,OAAO;AACb,KAAA;;AAEA,KAAI,IAAI,KAAK,KAAK,SAAS,EAAE;AAC7B,OAAM,IAAI,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE;AACjD,SAAQ,OAAO;AACf,OAAA;;OAEM,IAAI,CAAC,QAAQ,GAAG;AACtB,OAAM,OAAO;AACb,KAAA;;KAEI,IAAI,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE;AACnE,OAAM,IAAI,CAAC,mBAAmB,CAAC,CAAC;AAChC,KAAA;;KAEI,IAAI,CAAC,QAAQ,GAAG;AACpB,KAAI,OAAO,CAAC,IAAI,CAAC,cAAc;AAC/B,GAAA;AACA;;AAEA,CAAA,iBAAc,GAAG;GACf;AACF;;;;","x_google_ignoreList":[0]}
1
+ {"version":3,"file":"eventsource-stream.js","sources":["../../../../../../../../../node_modules/undici/lib/web/eventsource/eventsource-stream.js"],"sourcesContent":["'use strict'\nconst buffer = require('node:buffer')\nconst { Transform } = require('node:stream')\nconst { isASCIINumber, isValidLastEventId } = require('./util')\n\n/**\n * @type {number[]} BOM\n */\nconst BOM = [0xEF, 0xBB, 0xBF]\n/**\n * @type {10} LF\n */\nconst LF = 0x0A\n/**\n * @type {13} CR\n */\nconst CR = 0x0D\n/**\n * @type {58} COLON\n */\nconst COLON = 0x3A\n/**\n * @type {32} SPACE\n */\nconst SPACE = 0x20\n\nconst defaultMaxEventSize = buffer.kStringMaxLength\n\nconst DATA = Buffer.from('data')\nconst EVENT = Buffer.from('event')\nconst ID = Buffer.from('id')\nconst RETRY = Buffer.from('retry')\n\n// Each data field creates a string node, and each unconsumed input chunk keeps\n// a Buffer wrapper. The absolute ceiling protects the large default byte limit.\nconst minParserItems = 1024\nconst maxParserItems = 131072\nconst bytesPerParserItem = 128\n\nfunction isASCIINumberBytes (buffer, start) {\n if (start >= buffer.length) {\n return false\n }\n\n for (let i = start; i < buffer.length; i++) {\n if (buffer[i] < 0x30 || buffer[i] > 0x39) {\n return false\n }\n }\n\n return true\n}\n\nfunction isValidLastEventIdBytes (buffer, start) {\n for (let i = start; i < buffer.length; i++) {\n if (buffer[i] === 0x00) {\n return false\n }\n }\n\n return true\n}\n\nfunction isFieldName (line, length, field) {\n if (length !== field.length) {\n return false\n }\n\n for (let i = 0; i < length; i++) {\n if (line[i] !== field[i]) {\n return false\n }\n }\n\n return true\n}\n\nfunction createMaxEventSizeExceededError () {\n const error = new Error('EventSource message size exceeded')\n error.aborted = false\n return error\n}\n\n/**\n * @typedef {object} EventSourceStreamEvent\n * @type {object}\n * @property {string} [event] The event type.\n * @property {string} [data] The data of the message.\n * @property {string} [id] A unique ID for the event.\n * @property {string} [retry] The reconnection time, in milliseconds.\n */\n\n/**\n * @typedef eventSourceSettings\n * @type {object}\n * @property {string} lastEventId The last event ID received from the server.\n * @property {string} origin The origin of the event source.\n * @property {number} reconnectionTime The reconnection time, in milliseconds.\n */\n\nclass EventSourceStream extends Transform {\n /**\n * @type {eventSourceSettings}\n */\n state = null\n\n /**\n * Leading byte-order-mark check.\n * @type {boolean}\n */\n checkBOM = true\n\n /**\n * @type {boolean}\n */\n crlfCheck = false\n\n /**\n * @type {boolean}\n */\n eventEndCheck = false\n\n /**\n * @type {Buffer[]}\n */\n chunks = []\n\n chunkIndex = 0\n pos = 0\n lineChunkIndex = 0\n linePos = 0\n lineLength = 0\n eventSize = 0\n eventFieldSizes = { data: 0, event: 0, id: 0, retry: 0 }\n dataLineCount = 0\n maxEventSize\n maxDataLines\n maxBufferedChunks\n\n event = {\n data: undefined,\n event: undefined,\n id: undefined,\n retry: undefined\n }\n\n /**\n * @param {object} options\n * @param {number} [options.maxEventSize]\n * @param {eventSourceSettings} options.eventSourceSettings\n * @param {Function} [options.push]\n */\n constructor (options = {}) {\n // Enable object mode as EventSourceStream emits objects of shape\n // EventSourceStreamEvent\n options.readableObjectMode = true\n\n super(options)\n\n this.state = options.eventSourceSettings || {}\n this.maxEventSize = options.maxEventSize ?? defaultMaxEventSize\n const parserItemLimit = this.maxEventSize > 0\n ? Math.min(maxParserItems, Math.max(minParserItems, Math.floor(this.maxEventSize / bytesPerParserItem)))\n : 0\n this.maxDataLines = parserItemLimit\n this.maxBufferedChunks = parserItemLimit\n if (options.push) {\n this.push = options.push\n }\n }\n\n /**\n * @param {Buffer} chunk\n * @param {string} _encoding\n * @param {Function} callback\n * @returns {void}\n */\n _transform (chunk, _encoding, callback) {\n if (chunk.length === 0) {\n callback()\n return\n }\n\n // A leading line ending can immediately release the currently buffered\n // line, even when it uses the final allowed chunk slot.\n if (this.maxEventSize > 0 &&\n this.chunks.length >= this.maxBufferedChunks &&\n chunk[0] !== LF && chunk[0] !== CR) {\n callback(createMaxEventSizeExceededError())\n return\n }\n this.chunks.push(chunk)\n\n // Strip leading byte-order-mark if we opened the stream and started\n // the processing of the incoming data\n if (this.checkBOM) {\n if (this.handleBOM()) {\n callback()\n return\n }\n }\n\n while (this.hasCurrentByte()) {\n const byte = this.currentByte()\n\n // If the previous line ended with an end-of-line, we need to check\n // if the next character is also an end-of-line.\n if (this.eventEndCheck) {\n // If the the current character is an end-of-line, then the event\n // is finished and we can process it\n\n // If the previous line ended with a carriage return, we need to\n // check if the current character is a line feed and remove it\n // from the buffer.\n if (this.crlfCheck) {\n // If the current character is a line feed, we can remove it\n // from the buffer and reset the crlfCheck flag\n if (byte === LF) {\n this.crlfCheck = false\n this.consumeCurrentByte()\n\n // It is possible that the line feed is not the end of the\n // event. We need to check if the next character is an\n // end-of-line character to determine if the event is\n // finished. We simply continue the loop to check the next\n // character.\n\n // As we removed the line feed from the buffer and set the\n // crlfCheck flag to false, we basically don't make any\n // distinction between a line feed and a carriage return.\n continue\n }\n this.crlfCheck = false\n }\n\n if (byte === LF || byte === CR) {\n // If the current character is a carriage return, we need to\n // set the crlfCheck flag to true, as we need to check if the\n // next character is a line feed so we can remove it from the\n // buffer\n if (byte === CR) {\n this.crlfCheck = true\n }\n\n this.consumeCurrentByte()\n if (this.hasPendingEvent()) {\n this.processEvent(this.event)\n }\n this.clearEvent()\n continue\n }\n // If the current character is not an end-of-line, then the event\n // is not finished and we have to reset the eventEndCheck flag\n this.eventEndCheck = false\n continue\n }\n\n // If the current character is an end-of-line, we can process the\n // line\n if (byte === LF || byte === CR) {\n // If the current character is a carriage return, we need to\n // set the crlfCheck flag to true, as we need to check if the\n // next character is a line feed\n if (byte === CR) {\n this.crlfCheck = true\n }\n\n // In any case, we can process the line as we reached an\n // end-of-line character\n try {\n this.parseLine(this.readLine(), this.event)\n } catch (error) {\n callback(error)\n return\n }\n this.consumeCurrentByte()\n // A line was processed and this could be the end of the event. We need\n // to check if the next line is empty to determine if the event is\n // finished.\n this.eventEndCheck = true\n continue\n }\n\n // readLine() is only called after CR or LF. Reject an unfinished line\n // before it can retain an unbounded number of decoded chunks. The seven\n // extra bytes allow the longest field prefix (\"event: \" or \"retry: \").\n if (this.maxEventSize > 0 && ++this.lineLength > this.maxEventSize + 7) {\n callback(createMaxEventSizeExceededError())\n return\n }\n this.advanceCursor()\n }\n\n callback()\n }\n\n _destroy (error, callback) {\n this.chunks.length = 0\n this.clearEvent()\n super._destroy(error, callback)\n }\n\n /**\n * @param {Buffer} line\n * @param {EventSourceStreamEvent} event\n */\n parseLine (line, event) {\n // If the line is empty (a blank line)\n // Dispatch the event, as defined below.\n // This will be handled in the _transform method\n if (line.length === 0) {\n return\n }\n\n // If the line starts with a U+003A COLON character (:)\n // Ignore the line.\n const colonPosition = line.indexOf(COLON)\n if (colonPosition === 0) {\n return\n }\n\n let fieldLength = line.length\n let valueStart = line.length\n\n // If the line contains a U+003A COLON character (:)\n if (colonPosition !== -1) {\n fieldLength = colonPosition\n\n // Collect the characters on the line after the first U+003A COLON\n // character (:), and let value be that string.\n // If value starts with a U+0020 SPACE character, remove it from value.\n valueStart = colonPosition + 1\n if (line[valueStart] === SPACE) {\n ++valueStart\n }\n }\n\n if (isFieldName(line, fieldLength, DATA)) {\n if (this.maxEventSize > 0 && this.dataLineCount >= this.maxDataLines) {\n throw createMaxEventSizeExceededError()\n }\n const valueBytes = line.length - valueStart\n const dataSize = this.eventFieldSizes.data + (event.data === undefined ? 0 : 1) + valueBytes\n this.setEventFieldSize('data', dataSize)\n\n const value = line.toString('utf8', valueStart)\n\n if (event.data === undefined) {\n event.data = value\n } else {\n event.data += `\\n${value}`\n }\n this.dataLineCount++\n return\n }\n\n if (isFieldName(line, fieldLength, RETRY)) {\n if (isASCIINumberBytes(line, valueStart)) {\n this.setEventFieldSize('retry', line.length - valueStart)\n event.retry = line.toString('utf8', valueStart)\n }\n return\n }\n\n if (isFieldName(line, fieldLength, ID)) {\n if (isValidLastEventIdBytes(line, valueStart)) {\n this.setEventFieldSize('id', line.length - valueStart)\n event.id = line.toString('utf8', valueStart)\n }\n return\n }\n\n if (isFieldName(line, fieldLength, EVENT)) {\n if (valueStart < line.length) {\n this.setEventFieldSize('event', line.length - valueStart)\n event.event = line.toString('utf8', valueStart)\n }\n }\n }\n\n setEventFieldSize (field, size) {\n const eventSize = this.eventSize - this.eventFieldSizes[field] + size\n if (this.maxEventSize > 0 && eventSize > this.maxEventSize) {\n throw createMaxEventSizeExceededError()\n }\n this.eventSize = eventSize\n this.eventFieldSizes[field] = size\n }\n\n /**\n * @param {EventSourceStreamEvent} event\n */\n processEvent (event) {\n if (event.retry && isASCIINumber(event.retry)) {\n this.state.reconnectionTime = parseInt(event.retry, 10)\n }\n\n if (event.id && isValidLastEventId(event.id)) {\n this.state.lastEventId = event.id\n }\n\n // only dispatch event, when data is provided\n if (event.data !== undefined) {\n this.push({\n type: event.event || 'message',\n options: {\n data: event.data,\n lastEventId: this.state.lastEventId,\n origin: this.state.origin\n }\n })\n }\n }\n\n clearEvent () {\n this.event.data = undefined\n this.event.event = undefined\n this.event.id = undefined\n this.event.retry = undefined\n this.eventSize = 0\n this.dataLineCount = 0\n this.eventFieldSizes.data = 0\n this.eventFieldSizes.event = 0\n this.eventFieldSizes.id = 0\n this.eventFieldSizes.retry = 0\n }\n\n hasPendingEvent () {\n return this.event.data !== undefined ||\n this.event.event !== undefined ||\n this.event.id !== undefined ||\n this.event.retry !== undefined\n }\n\n hasCurrentByte () {\n return this.chunkIndex < this.chunks.length &&\n this.pos < this.chunks[this.chunkIndex].length\n }\n\n currentByte () {\n return this.chunks[this.chunkIndex][this.pos]\n }\n\n consumeCurrentByte () {\n this.advanceCursor()\n this.syncLineStartToCursor()\n }\n\n advanceCursor () {\n this.pos++\n\n while (this.chunkIndex < this.chunks.length && this.pos >= this.chunks[this.chunkIndex].length) {\n this.chunkIndex++\n this.pos = 0\n }\n }\n\n syncLineStartToCursor () {\n this.lineChunkIndex = this.chunkIndex\n this.linePos = this.pos\n this.lineLength = 0\n this.dropConsumedChunks()\n }\n\n dropConsumedChunks () {\n if (this.lineChunkIndex > 0) {\n const consumed = this.lineChunkIndex\n this.chunks.splice(0, consumed)\n this.lineChunkIndex = 0\n this.chunkIndex -= consumed\n }\n\n if (this.chunkIndex === this.chunks.length) {\n this.chunks.length = 0\n this.chunkIndex = 0\n this.pos = 0\n this.lineChunkIndex = 0\n this.linePos = 0\n }\n }\n\n readLine () {\n if (this.lineChunkIndex === this.chunkIndex) {\n return this.chunks[this.chunkIndex].subarray(this.linePos, this.pos)\n }\n\n const chunks = []\n let length = 0\n\n for (let i = this.lineChunkIndex; i <= this.chunkIndex; i++) {\n const chunk = this.chunks[i]\n const start = i === this.lineChunkIndex ? this.linePos : 0\n const end = i === this.chunkIndex ? this.pos : chunk.length\n const slice = chunk.subarray(start, end)\n length += slice.length\n chunks.push(slice)\n }\n\n return Buffer.concat(chunks, length)\n }\n\n peekBufferedByte (offset) {\n let chunkIndex = this.lineChunkIndex\n let pos = this.linePos\n\n while (chunkIndex < this.chunks.length) {\n const chunk = this.chunks[chunkIndex]\n const remaining = chunk.length - pos\n\n if (offset < remaining) {\n return chunk[pos + offset]\n }\n\n offset -= remaining\n chunkIndex++\n pos = 0\n }\n }\n\n discardLeadingBytes (count) {\n while (count > 0 && this.lineChunkIndex < this.chunks.length) {\n const chunk = this.chunks[this.lineChunkIndex]\n const remaining = chunk.length - this.linePos\n\n if (count < remaining) {\n this.linePos += count\n count = 0\n } else {\n count -= remaining\n this.lineChunkIndex++\n this.linePos = 0\n }\n }\n\n this.chunkIndex = this.lineChunkIndex\n this.pos = this.linePos\n this.dropConsumedChunks()\n }\n\n handleBOM () {\n const first = this.peekBufferedByte(0)\n const second = this.peekBufferedByte(1)\n const third = this.peekBufferedByte(2)\n\n if (second === undefined) {\n if (first === BOM[0]) {\n return true\n }\n\n this.checkBOM = false\n return true\n }\n\n if (third === undefined) {\n if (first === BOM[0] && second === BOM[1]) {\n return true\n }\n\n this.checkBOM = false\n return false\n }\n\n if (first === BOM[0] && second === BOM[1] && third === BOM[2]) {\n this.discardLeadingBytes(3)\n }\n\n this.checkBOM = false\n return !this.hasCurrentByte()\n }\n}\n\nmodule.exports = {\n EventSourceStream\n}\n"],"names":["require$$0","require$$1","require$$2"],"mappings":";;;;;;;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AgB,CAAC,CAAC;AAC1C,KAAI,MAAM,KAAK,GAAG,IAAI,CAAC,gBAAgB,CAAC,CAAC;;AAEzC,KAAI,IAAI,MAAM,KAAK,SAAS,EAAE;AAC9B,OAAM,IAAI,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE;AAC5B,SAAQ,OAAO;AACf,OAAA;;OAEM,IAAI,CAAC,QAAQ,GAAG;AACtB,OAAM,OAAO;AACb,KAAA;;AAEA,KAAI,IAAI,KAAK,KAAK,SAAS,EAAE;AAC7B,OAAM,IAAI,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE;AACjD,SAAQ,OAAO;AACf,OAAA;;OAEM,IAAI,CAAC,QAAQ,GAAG;AACtB,OAAM,OAAO;AACb,KAAA;;KAEI,IAAI,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE;AACnE,OAAM,IAAI,CAAC,mBAAmB,CAAC,CAAC;AAChC,KAAA;;KAEI,IAAI,CAAC,QAAQ,GAAG;AACpB,KAAI,OAAO,CAAC,IAAI,CAAC,cAAc;AAC/B,GAAA;AACA;;AAEA,CAAA,iBAAc,GAAG;GACf;AACF;;;;","x_google_ignoreList":[0]}
@@ -9,6 +9,7 @@ import { __require as requireResponse } from '../fetch/response.js';
9
9
  import { __require as requireUtil } from './util.js';
10
10
  import { __require as requireUtil$1 } from '../../core/util.js';
11
11
  import { __require as requireUtil$2 } from '../fetch/util.js';
12
+ import { __require as requireGlobal } from '../../global.js';
12
13
 
13
14
  var eventsource;
14
15
  var hasRequiredEventsource;
@@ -28,6 +29,7 @@ function requireEventsource () {
28
29
  const { delay } = requireUtil();
29
30
  const { kEnumerableProperty } = requireUtil$1();
30
31
  const { environmentSettingsObject } = requireUtil$2();
32
+ const { getGlobalDispatcher } = requireGlobal();
31
33
 
32
34
  let experimentalWarned = false;
33
35
 
@@ -309,6 +311,7 @@ function requireEventsource () {
309
311
 
310
312
  const eventSourceStream = new EventSourceStream({
311
313
  eventSourceSettings: this.#state,
314
+ maxEventSize: this.#dispatcher.eventSourceOptions?.maxEventSize,
312
315
  push: (event) => {
313
316
  this.dispatchEvent(createFastMessageEvent(
314
317
  event.type,
@@ -487,7 +490,8 @@ function requireEventsource () {
487
490
  },
488
491
  {
489
492
  key: 'dispatcher', // undici only
490
- converter: webidl.converters.any
493
+ converter: webidl.converters.any,
494
+ defaultValue: () => getGlobalDispatcher()
491
495
  }
492
496
  ]);
493
497
 
@@ -1 +1 @@
1
- {"version":3,"file":"eventsource.js","sources":["../../../../../../../../../node_modules/undici/lib/web/eventsource/eventsource.js"],"sourcesContent":["'use strict'\n\nconst { pipeline } = require('node:stream')\nconst { fetching } = require('../fetch')\nconst { makeRequest } = require('../fetch/request')\nconst { webidl } = require('../fetch/webidl')\nconst { EventSourceStream } = require('./eventsource-stream')\nconst { parseMIMEType } = require('../fetch/data-url')\nconst { createFastMessageEvent } = require('../websocket/events')\nconst { isNetworkError } = require('../fetch/response')\nconst { delay } = require('./util')\nconst { kEnumerableProperty } = require('../../core/util')\nconst { environmentSettingsObject } = require('../fetch/util')\n\nlet experimentalWarned = false\n\n/**\n * A reconnection time, in milliseconds. This must initially be an implementation-defined value,\n * probably in the region of a few seconds.\n *\n * In Comparison:\n * - Chrome uses 3000ms.\n * - Deno uses 5000ms.\n *\n * @type {3000}\n */\nconst defaultReconnectionTime = 3000\n\n/**\n * The readyState attribute represents the state of the connection.\n * @enum\n * @readonly\n * @see https://html.spec.whatwg.org/multipage/server-sent-events.html#dom-eventsource-readystate-dev\n */\n\n/**\n * The connection has not yet been established, or it was closed and the user\n * agent is reconnecting.\n * @type {0}\n */\nconst CONNECTING = 0\n\n/**\n * The user agent has an open connection and is dispatching events as it\n * receives them.\n * @type {1}\n */\nconst OPEN = 1\n\n/**\n * The connection is not open, and the user agent is not trying to reconnect.\n * @type {2}\n */\nconst CLOSED = 2\n\n/**\n * Requests for the element will have their mode set to \"cors\" and their credentials mode set to \"same-origin\".\n * @type {'anonymous'}\n */\nconst ANONYMOUS = 'anonymous'\n\n/**\n * Requests for the element will have their mode set to \"cors\" and their credentials mode set to \"include\".\n * @type {'use-credentials'}\n */\nconst USE_CREDENTIALS = 'use-credentials'\n\n/**\n * The EventSource interface is used to receive server-sent events. It\n * connects to a server over HTTP and receives events in text/event-stream\n * format without closing the connection.\n * @extends {EventTarget}\n * @see https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events\n * @api public\n */\nclass EventSource extends EventTarget {\n #events = {\n open: null,\n error: null,\n message: null\n }\n\n #url = null\n #withCredentials = false\n\n #readyState = CONNECTING\n\n #request = null\n #controller = null\n\n #dispatcher\n\n /**\n * @type {import('./eventsource-stream').eventSourceSettings}\n */\n #state\n\n /**\n * Creates a new EventSource object.\n * @param {string} url\n * @param {EventSourceInit} [eventSourceInitDict]\n * @see https://html.spec.whatwg.org/multipage/server-sent-events.html#the-eventsource-interface\n */\n constructor (url, eventSourceInitDict = {}) {\n // 1. Let ev be a new EventSource object.\n super()\n\n webidl.util.markAsUncloneable(this)\n\n const prefix = 'EventSource constructor'\n webidl.argumentLengthCheck(arguments, 1, prefix)\n\n if (!experimentalWarned) {\n experimentalWarned = true\n process.emitWarning('EventSource is experimental, expect them to change at any time.', {\n code: 'UNDICI-ES'\n })\n }\n\n url = webidl.converters.USVString(url, prefix, 'url')\n eventSourceInitDict = webidl.converters.EventSourceInitDict(eventSourceInitDict, prefix, 'eventSourceInitDict')\n\n this.#dispatcher = eventSourceInitDict.dispatcher\n this.#state = {\n lastEventId: '',\n reconnectionTime: defaultReconnectionTime\n }\n\n // 2. Let settings be ev's relevant settings object.\n // https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object\n const settings = environmentSettingsObject\n\n let urlRecord\n\n try {\n // 3. Let urlRecord be the result of encoding-parsing a URL given url, relative to settings.\n urlRecord = new URL(url, settings.settingsObject.baseUrl)\n this.#state.origin = urlRecord.origin\n } catch (e) {\n // 4. If urlRecord is failure, then throw a \"SyntaxError\" DOMException.\n throw new DOMException(e, 'SyntaxError')\n }\n\n // 5. Set ev's url to urlRecord.\n this.#url = urlRecord.href\n\n // 6. Let corsAttributeState be Anonymous.\n let corsAttributeState = ANONYMOUS\n\n // 7. If the value of eventSourceInitDict's withCredentials member is true,\n // then set corsAttributeState to Use Credentials and set ev's\n // withCredentials attribute to true.\n if (eventSourceInitDict.withCredentials) {\n corsAttributeState = USE_CREDENTIALS\n this.#withCredentials = true\n }\n\n // 8. Let request be the result of creating a potential-CORS request given\n // urlRecord, the empty string, and corsAttributeState.\n const initRequest = {\n redirect: 'follow',\n keepalive: true,\n // @see https://html.spec.whatwg.org/multipage/urls-and-fetching.html#cors-settings-attributes\n mode: 'cors',\n credentials: corsAttributeState === 'anonymous'\n ? 'same-origin'\n : 'omit',\n referrer: 'no-referrer'\n }\n\n // 9. Set request's client to settings.\n initRequest.client = environmentSettingsObject.settingsObject\n\n // 10. User agents may set (`Accept`, `text/event-stream`) in request's header list.\n initRequest.headersList = [['accept', { name: 'accept', value: 'text/event-stream' }]]\n\n // 11. Set request's cache mode to \"no-store\".\n initRequest.cache = 'no-store'\n\n // 12. Set request's initiator type to \"other\".\n initRequest.initiator = 'other'\n\n initRequest.urlList = [new URL(this.#url)]\n\n // 13. Set ev's request to request.\n this.#request = makeRequest(initRequest)\n\n this.#connect()\n }\n\n /**\n * Returns the state of this EventSource object's connection. It can have the\n * values described below.\n * @returns {0|1|2}\n * @readonly\n */\n get readyState () {\n return this.#readyState\n }\n\n /**\n * Returns the URL providing the event stream.\n * @readonly\n * @returns {string}\n */\n get url () {\n return this.#url\n }\n\n /**\n * Returns a boolean indicating whether the EventSource object was\n * instantiated with CORS credentials set (true), or not (false, the default).\n */\n get withCredentials () {\n return this.#withCredentials\n }\n\n #connect () {\n if (this.#readyState === CLOSED) return\n\n this.#readyState = CONNECTING\n\n const fetchParams = {\n request: this.#request,\n dispatcher: this.#dispatcher\n }\n\n // 14. Let processEventSourceEndOfBody given response res be the following step: if res is not a network error, then reestablish the connection.\n const processEventSourceEndOfBody = (response) => {\n if (isNetworkError(response)) {\n this.dispatchEvent(new Event('error'))\n this.close()\n }\n\n this.#reconnect()\n }\n\n // 15. Fetch request, with processResponseEndOfBody set to processEventSourceEndOfBody...\n fetchParams.processResponseEndOfBody = processEventSourceEndOfBody\n\n // and processResponse set to the following steps given response res:\n fetchParams.processResponse = (response) => {\n // 1. If res is an aborted network error, then fail the connection.\n\n if (isNetworkError(response)) {\n // 1. When a user agent is to fail the connection, the user agent\n // must queue a task which, if the readyState attribute is set to a\n // value other than CLOSED, sets the readyState attribute to CLOSED\n // and fires an event named error at the EventSource object. Once the\n // user agent has failed the connection, it does not attempt to\n // reconnect.\n if (response.aborted) {\n this.close()\n this.dispatchEvent(new Event('error'))\n return\n // 2. Otherwise, if res is a network error, then reestablish the\n // connection, unless the user agent knows that to be futile, in\n // which case the user agent may fail the connection.\n } else {\n this.#reconnect()\n return\n }\n }\n\n // 3. Otherwise, if res's status is not 200, or if res's `Content-Type`\n // is not `text/event-stream`, then fail the connection.\n const contentType = response.headersList.get('content-type', true)\n const mimeType = contentType !== null ? parseMIMEType(contentType) : 'failure'\n const contentTypeValid = mimeType !== 'failure' && mimeType.essence === 'text/event-stream'\n if (\n response.status !== 200 ||\n contentTypeValid === false\n ) {\n this.close()\n this.dispatchEvent(new Event('error'))\n return\n }\n\n // 4. Otherwise, announce the connection and interpret res's body\n // line by line.\n\n // When a user agent is to announce the connection, the user agent\n // must queue a task which, if the readyState attribute is set to a\n // value other than CLOSED, sets the readyState attribute to OPEN\n // and fires an event named open at the EventSource object.\n // @see https://html.spec.whatwg.org/multipage/server-sent-events.html#sse-processing-model\n this.#readyState = OPEN\n this.dispatchEvent(new Event('open'))\n\n // If redirected to a different origin, set the origin to the new origin.\n this.#state.origin = response.urlList[response.urlList.length - 1].origin\n\n const eventSourceStream = new EventSourceStream({\n eventSourceSettings: this.#state,\n push: (event) => {\n this.dispatchEvent(createFastMessageEvent(\n event.type,\n event.options\n ))\n }\n })\n\n pipeline(response.body.stream,\n eventSourceStream,\n (error) => {\n if (\n error?.aborted === false\n ) {\n this.close()\n this.dispatchEvent(new Event('error'))\n }\n })\n }\n\n this.#controller = fetching(fetchParams)\n }\n\n /**\n * @see https://html.spec.whatwg.org/multipage/server-sent-events.html#sse-processing-model\n * @returns {Promise<void>}\n */\n async #reconnect () {\n // When a user agent is to reestablish the connection, the user agent must\n // run the following steps. These steps are run in parallel, not as part of\n // a task. (The tasks that it queues, of course, are run like normal tasks\n // and not themselves in parallel.)\n\n // 1. Queue a task to run the following steps:\n\n // 1. If the readyState attribute is set to CLOSED, abort the task.\n if (this.#readyState === CLOSED) return\n\n // 2. Set the readyState attribute to CONNECTING.\n this.#readyState = CONNECTING\n\n // 3. Fire an event named error at the EventSource object.\n this.dispatchEvent(new Event('error'))\n\n // 2. Wait a delay equal to the reconnection time of the event source.\n await delay(this.#state.reconnectionTime)\n\n // 5. Queue a task to run the following steps:\n\n // 1. If the EventSource object's readyState attribute is not set to\n // CONNECTING, then return.\n if (this.#readyState !== CONNECTING) return\n\n // 2. Let request be the EventSource object's request.\n // 3. If the EventSource object's last event ID string is not the empty\n // string, then:\n // 1. Let lastEventIDValue be the EventSource object's last event ID\n // string, encoded as UTF-8.\n // 2. Set (`Last-Event-ID`, lastEventIDValue) in request's header\n // list.\n if (this.#state.lastEventId.length) {\n this.#request.headersList.set('last-event-id', this.#state.lastEventId, true)\n }\n\n // 4. Fetch request and process the response obtained in this fashion, if any, as described earlier in this section.\n this.#connect()\n }\n\n /**\n * Closes the connection, if any, and sets the readyState attribute to\n * CLOSED.\n */\n close () {\n webidl.brandCheck(this, EventSource)\n\n if (this.#readyState === CLOSED) return\n this.#readyState = CLOSED\n this.#controller.abort()\n this.#request = null\n }\n\n get onopen () {\n return this.#events.open\n }\n\n set onopen (fn) {\n if (this.#events.open) {\n this.removeEventListener('open', this.#events.open)\n }\n\n if (typeof fn === 'function') {\n this.#events.open = fn\n this.addEventListener('open', fn)\n } else {\n this.#events.open = null\n }\n }\n\n get onmessage () {\n return this.#events.message\n }\n\n set onmessage (fn) {\n if (this.#events.message) {\n this.removeEventListener('message', this.#events.message)\n }\n\n if (typeof fn === 'function') {\n this.#events.message = fn\n this.addEventListener('message', fn)\n } else {\n this.#events.message = null\n }\n }\n\n get onerror () {\n return this.#events.error\n }\n\n set onerror (fn) {\n if (this.#events.error) {\n this.removeEventListener('error', this.#events.error)\n }\n\n if (typeof fn === 'function') {\n this.#events.error = fn\n this.addEventListener('error', fn)\n } else {\n this.#events.error = null\n }\n }\n}\n\nconst constantsPropertyDescriptors = {\n CONNECTING: {\n __proto__: null,\n configurable: false,\n enumerable: true,\n value: CONNECTING,\n writable: false\n },\n OPEN: {\n __proto__: null,\n configurable: false,\n enumerable: true,\n value: OPEN,\n writable: false\n },\n CLOSED: {\n __proto__: null,\n configurable: false,\n enumerable: true,\n value: CLOSED,\n writable: false\n }\n}\n\nObject.defineProperties(EventSource, constantsPropertyDescriptors)\nObject.defineProperties(EventSource.prototype, constantsPropertyDescriptors)\n\nObject.defineProperties(EventSource.prototype, {\n close: kEnumerableProperty,\n onerror: kEnumerableProperty,\n onmessage: kEnumerableProperty,\n onopen: kEnumerableProperty,\n readyState: kEnumerableProperty,\n url: kEnumerableProperty,\n withCredentials: kEnumerableProperty\n})\n\nwebidl.converters.EventSourceInitDict = webidl.dictionaryConverter([\n {\n key: 'withCredentials',\n converter: webidl.converters.boolean,\n defaultValue: () => false\n },\n {\n key: 'dispatcher', // undici only\n converter: webidl.converters.any\n }\n])\n\nmodule.exports = {\n EventSource,\n defaultReconnectionTime\n}\n"],"names":["require$$1","require$$2","require$$3","require$$4","require$$5","require$$6","require$$7","require$$8","require$$9","require$$10"],"mappings":";;;;;;;;;;;;;;;;;;;CAEA,MAAM,EAAE,QAAQ,EAAE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C,gBAAgB,CAAC,WAAW,CAAC,SAAS,EAAE,4BAA4B;;AAE3E,CAAA,MAAM,CAAC,gBAAgB,CAAC,WAAW,CAAC,SAAS,EAAE;GAC7C,KAAK,EAAE,mBAAmB;GAC1B,OAAO,EAAE,mBAAmB;GAC5B,SAAS,EAAE,mBAAmB;GAC9B,MAAM,EAAE,mBAAmB;GAC3B,UAAU,EAAE,mBAAmB;GAC/B,GAAG,EAAE,mBAAmB;AAC1B,GAAE,eAAe,EAAE;EAClB;;CAED,MAAM,CAAC,UAAU,CAAC,mBAAmB,GAAG,MAAM,CAAC,mBAAmB,CAAC;GACjE;KACE,GAAG,EAAE,iBAAiB;AAC1B,KAAI,SAAS,EAAE,MAAM,CAAC,UAAU,CAAC,OAAO;KACpC,YAAY,EAAE,MAAM;IACrB;GACD;KACE,GAAG,EAAE,YAAY;AACrB,KAAI,SAAS,EAAE,MAAM,CAAC,UAAU,CAAC;AACjC;EACC;;AAED,CAAA,WAAc,GAAG;AACjB,GAAE,WAAW;GACX;AACF;;;;","x_google_ignoreList":[0]}
1
+ {"version":3,"file":"eventsource.js","sources":["../../../../../../../../../node_modules/undici/lib/web/eventsource/eventsource.js"],"sourcesContent":["'use strict'\n\nconst { pipeline } = require('node:stream')\nconst { fetching } = require('../fetch')\nconst { makeRequest } = require('../fetch/request')\nconst { webidl } = require('../fetch/webidl')\nconst { EventSourceStream } = require('./eventsource-stream')\nconst { parseMIMEType } = require('../fetch/data-url')\nconst { createFastMessageEvent } = require('../websocket/events')\nconst { isNetworkError } = require('../fetch/response')\nconst { delay } = require('./util')\nconst { kEnumerableProperty } = require('../../core/util')\nconst { environmentSettingsObject } = require('../fetch/util')\nconst { getGlobalDispatcher } = require('../../global')\n\nlet experimentalWarned = false\n\n/**\n * A reconnection time, in milliseconds. This must initially be an implementation-defined value,\n * probably in the region of a few seconds.\n *\n * In Comparison:\n * - Chrome uses 3000ms.\n * - Deno uses 5000ms.\n *\n * @type {3000}\n */\nconst defaultReconnectionTime = 3000\n\n/**\n * The readyState attribute represents the state of the connection.\n * @enum\n * @readonly\n * @see https://html.spec.whatwg.org/multipage/server-sent-events.html#dom-eventsource-readystate-dev\n */\n\n/**\n * The connection has not yet been established, or it was closed and the user\n * agent is reconnecting.\n * @type {0}\n */\nconst CONNECTING = 0\n\n/**\n * The user agent has an open connection and is dispatching events as it\n * receives them.\n * @type {1}\n */\nconst OPEN = 1\n\n/**\n * The connection is not open, and the user agent is not trying to reconnect.\n * @type {2}\n */\nconst CLOSED = 2\n\n/**\n * Requests for the element will have their mode set to \"cors\" and their credentials mode set to \"same-origin\".\n * @type {'anonymous'}\n */\nconst ANONYMOUS = 'anonymous'\n\n/**\n * Requests for the element will have their mode set to \"cors\" and their credentials mode set to \"include\".\n * @type {'use-credentials'}\n */\nconst USE_CREDENTIALS = 'use-credentials'\n\n/**\n * The EventSource interface is used to receive server-sent events. It\n * connects to a server over HTTP and receives events in text/event-stream\n * format without closing the connection.\n * @extends {EventTarget}\n * @see https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events\n * @api public\n */\nclass EventSource extends EventTarget {\n #events = {\n open: null,\n error: null,\n message: null\n }\n\n #url = null\n #withCredentials = false\n\n #readyState = CONNECTING\n\n #request = null\n #controller = null\n\n #dispatcher\n\n /**\n * @type {import('./eventsource-stream').eventSourceSettings}\n */\n #state\n\n /**\n * Creates a new EventSource object.\n * @param {string} url\n * @param {EventSourceInit} [eventSourceInitDict]\n * @see https://html.spec.whatwg.org/multipage/server-sent-events.html#the-eventsource-interface\n */\n constructor (url, eventSourceInitDict = {}) {\n // 1. Let ev be a new EventSource object.\n super()\n\n webidl.util.markAsUncloneable(this)\n\n const prefix = 'EventSource constructor'\n webidl.argumentLengthCheck(arguments, 1, prefix)\n\n if (!experimentalWarned) {\n experimentalWarned = true\n process.emitWarning('EventSource is experimental, expect them to change at any time.', {\n code: 'UNDICI-ES'\n })\n }\n\n url = webidl.converters.USVString(url, prefix, 'url')\n eventSourceInitDict = webidl.converters.EventSourceInitDict(eventSourceInitDict, prefix, 'eventSourceInitDict')\n\n this.#dispatcher = eventSourceInitDict.dispatcher\n this.#state = {\n lastEventId: '',\n reconnectionTime: defaultReconnectionTime\n }\n\n // 2. Let settings be ev's relevant settings object.\n // https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object\n const settings = environmentSettingsObject\n\n let urlRecord\n\n try {\n // 3. Let urlRecord be the result of encoding-parsing a URL given url, relative to settings.\n urlRecord = new URL(url, settings.settingsObject.baseUrl)\n this.#state.origin = urlRecord.origin\n } catch (e) {\n // 4. If urlRecord is failure, then throw a \"SyntaxError\" DOMException.\n throw new DOMException(e, 'SyntaxError')\n }\n\n // 5. Set ev's url to urlRecord.\n this.#url = urlRecord.href\n\n // 6. Let corsAttributeState be Anonymous.\n let corsAttributeState = ANONYMOUS\n\n // 7. If the value of eventSourceInitDict's withCredentials member is true,\n // then set corsAttributeState to Use Credentials and set ev's\n // withCredentials attribute to true.\n if (eventSourceInitDict.withCredentials) {\n corsAttributeState = USE_CREDENTIALS\n this.#withCredentials = true\n }\n\n // 8. Let request be the result of creating a potential-CORS request given\n // urlRecord, the empty string, and corsAttributeState.\n const initRequest = {\n redirect: 'follow',\n keepalive: true,\n // @see https://html.spec.whatwg.org/multipage/urls-and-fetching.html#cors-settings-attributes\n mode: 'cors',\n credentials: corsAttributeState === 'anonymous'\n ? 'same-origin'\n : 'omit',\n referrer: 'no-referrer'\n }\n\n // 9. Set request's client to settings.\n initRequest.client = environmentSettingsObject.settingsObject\n\n // 10. User agents may set (`Accept`, `text/event-stream`) in request's header list.\n initRequest.headersList = [['accept', { name: 'accept', value: 'text/event-stream' }]]\n\n // 11. Set request's cache mode to \"no-store\".\n initRequest.cache = 'no-store'\n\n // 12. Set request's initiator type to \"other\".\n initRequest.initiator = 'other'\n\n initRequest.urlList = [new URL(this.#url)]\n\n // 13. Set ev's request to request.\n this.#request = makeRequest(initRequest)\n\n this.#connect()\n }\n\n /**\n * Returns the state of this EventSource object's connection. It can have the\n * values described below.\n * @returns {0|1|2}\n * @readonly\n */\n get readyState () {\n return this.#readyState\n }\n\n /**\n * Returns the URL providing the event stream.\n * @readonly\n * @returns {string}\n */\n get url () {\n return this.#url\n }\n\n /**\n * Returns a boolean indicating whether the EventSource object was\n * instantiated with CORS credentials set (true), or not (false, the default).\n */\n get withCredentials () {\n return this.#withCredentials\n }\n\n #connect () {\n if (this.#readyState === CLOSED) return\n\n this.#readyState = CONNECTING\n\n const fetchParams = {\n request: this.#request,\n dispatcher: this.#dispatcher\n }\n\n // 14. Let processEventSourceEndOfBody given response res be the following step: if res is not a network error, then reestablish the connection.\n const processEventSourceEndOfBody = (response) => {\n if (isNetworkError(response)) {\n this.dispatchEvent(new Event('error'))\n this.close()\n }\n\n this.#reconnect()\n }\n\n // 15. Fetch request, with processResponseEndOfBody set to processEventSourceEndOfBody...\n fetchParams.processResponseEndOfBody = processEventSourceEndOfBody\n\n // and processResponse set to the following steps given response res:\n fetchParams.processResponse = (response) => {\n // 1. If res is an aborted network error, then fail the connection.\n\n if (isNetworkError(response)) {\n // 1. When a user agent is to fail the connection, the user agent\n // must queue a task which, if the readyState attribute is set to a\n // value other than CLOSED, sets the readyState attribute to CLOSED\n // and fires an event named error at the EventSource object. Once the\n // user agent has failed the connection, it does not attempt to\n // reconnect.\n if (response.aborted) {\n this.close()\n this.dispatchEvent(new Event('error'))\n return\n // 2. Otherwise, if res is a network error, then reestablish the\n // connection, unless the user agent knows that to be futile, in\n // which case the user agent may fail the connection.\n } else {\n this.#reconnect()\n return\n }\n }\n\n // 3. Otherwise, if res's status is not 200, or if res's `Content-Type`\n // is not `text/event-stream`, then fail the connection.\n const contentType = response.headersList.get('content-type', true)\n const mimeType = contentType !== null ? parseMIMEType(contentType) : 'failure'\n const contentTypeValid = mimeType !== 'failure' && mimeType.essence === 'text/event-stream'\n if (\n response.status !== 200 ||\n contentTypeValid === false\n ) {\n this.close()\n this.dispatchEvent(new Event('error'))\n return\n }\n\n // 4. Otherwise, announce the connection and interpret res's body\n // line by line.\n\n // When a user agent is to announce the connection, the user agent\n // must queue a task which, if the readyState attribute is set to a\n // value other than CLOSED, sets the readyState attribute to OPEN\n // and fires an event named open at the EventSource object.\n // @see https://html.spec.whatwg.org/multipage/server-sent-events.html#sse-processing-model\n this.#readyState = OPEN\n this.dispatchEvent(new Event('open'))\n\n // If redirected to a different origin, set the origin to the new origin.\n this.#state.origin = response.urlList[response.urlList.length - 1].origin\n\n const eventSourceStream = new EventSourceStream({\n eventSourceSettings: this.#state,\n maxEventSize: this.#dispatcher.eventSourceOptions?.maxEventSize,\n push: (event) => {\n this.dispatchEvent(createFastMessageEvent(\n event.type,\n event.options\n ))\n }\n })\n\n pipeline(response.body.stream,\n eventSourceStream,\n (error) => {\n if (\n error?.aborted === false\n ) {\n this.close()\n this.dispatchEvent(new Event('error'))\n }\n })\n }\n\n this.#controller = fetching(fetchParams)\n }\n\n /**\n * @see https://html.spec.whatwg.org/multipage/server-sent-events.html#sse-processing-model\n * @returns {Promise<void>}\n */\n async #reconnect () {\n // When a user agent is to reestablish the connection, the user agent must\n // run the following steps. These steps are run in parallel, not as part of\n // a task. (The tasks that it queues, of course, are run like normal tasks\n // and not themselves in parallel.)\n\n // 1. Queue a task to run the following steps:\n\n // 1. If the readyState attribute is set to CLOSED, abort the task.\n if (this.#readyState === CLOSED) return\n\n // 2. Set the readyState attribute to CONNECTING.\n this.#readyState = CONNECTING\n\n // 3. Fire an event named error at the EventSource object.\n this.dispatchEvent(new Event('error'))\n\n // 2. Wait a delay equal to the reconnection time of the event source.\n await delay(this.#state.reconnectionTime)\n\n // 5. Queue a task to run the following steps:\n\n // 1. If the EventSource object's readyState attribute is not set to\n // CONNECTING, then return.\n if (this.#readyState !== CONNECTING) return\n\n // 2. Let request be the EventSource object's request.\n // 3. If the EventSource object's last event ID string is not the empty\n // string, then:\n // 1. Let lastEventIDValue be the EventSource object's last event ID\n // string, encoded as UTF-8.\n // 2. Set (`Last-Event-ID`, lastEventIDValue) in request's header\n // list.\n if (this.#state.lastEventId.length) {\n this.#request.headersList.set('last-event-id', this.#state.lastEventId, true)\n }\n\n // 4. Fetch request and process the response obtained in this fashion, if any, as described earlier in this section.\n this.#connect()\n }\n\n /**\n * Closes the connection, if any, and sets the readyState attribute to\n * CLOSED.\n */\n close () {\n webidl.brandCheck(this, EventSource)\n\n if (this.#readyState === CLOSED) return\n this.#readyState = CLOSED\n this.#controller.abort()\n this.#request = null\n }\n\n get onopen () {\n return this.#events.open\n }\n\n set onopen (fn) {\n if (this.#events.open) {\n this.removeEventListener('open', this.#events.open)\n }\n\n if (typeof fn === 'function') {\n this.#events.open = fn\n this.addEventListener('open', fn)\n } else {\n this.#events.open = null\n }\n }\n\n get onmessage () {\n return this.#events.message\n }\n\n set onmessage (fn) {\n if (this.#events.message) {\n this.removeEventListener('message', this.#events.message)\n }\n\n if (typeof fn === 'function') {\n this.#events.message = fn\n this.addEventListener('message', fn)\n } else {\n this.#events.message = null\n }\n }\n\n get onerror () {\n return this.#events.error\n }\n\n set onerror (fn) {\n if (this.#events.error) {\n this.removeEventListener('error', this.#events.error)\n }\n\n if (typeof fn === 'function') {\n this.#events.error = fn\n this.addEventListener('error', fn)\n } else {\n this.#events.error = null\n }\n }\n}\n\nconst constantsPropertyDescriptors = {\n CONNECTING: {\n __proto__: null,\n configurable: false,\n enumerable: true,\n value: CONNECTING,\n writable: false\n },\n OPEN: {\n __proto__: null,\n configurable: false,\n enumerable: true,\n value: OPEN,\n writable: false\n },\n CLOSED: {\n __proto__: null,\n configurable: false,\n enumerable: true,\n value: CLOSED,\n writable: false\n }\n}\n\nObject.defineProperties(EventSource, constantsPropertyDescriptors)\nObject.defineProperties(EventSource.prototype, constantsPropertyDescriptors)\n\nObject.defineProperties(EventSource.prototype, {\n close: kEnumerableProperty,\n onerror: kEnumerableProperty,\n onmessage: kEnumerableProperty,\n onopen: kEnumerableProperty,\n readyState: kEnumerableProperty,\n url: kEnumerableProperty,\n withCredentials: kEnumerableProperty\n})\n\nwebidl.converters.EventSourceInitDict = webidl.dictionaryConverter([\n {\n key: 'withCredentials',\n converter: webidl.converters.boolean,\n defaultValue: () => false\n },\n {\n key: 'dispatcher', // undici only\n converter: webidl.converters.any,\n defaultValue: () => getGlobalDispatcher()\n }\n])\n\nmodule.exports = {\n EventSource,\n defaultReconnectionTime\n}\n"],"names":["require$$1","require$$2","require$$3","require$$4","require$$5","require$$6","require$$7","require$$8","require$$9","require$$10","require$$11"],"mappings":";;;;;;;;;;;;;;;;;;;;CAEA,MAAM,EAAE,QAAQ,EAAE,GAAG;CACrB,MAAM,EAAE,QAAQ,EAAE,GAAGA,YAAA;CACrB,MAAM,EAAE,WAAW,EAAE,GAAGC,cAAA;CACxB,MAAM,EAAE,MAAM,EAAE,GAAGC,aAAA;CACnB,MAAM,EAAE,iBAAiB,EAAE,GAAGC,wBAAA;CAC9B,MAAM,EAAE,aAAa,EAAE,GAAGC,cAAA;CAC1B,MAAM,EAAE,sBAAsB,EAAE,GAAGC,aAAA;CACnC,MAAM,EAAE,cAAc,EAAE,GAAGC,eAAA;CAC3B,MAAM,EAAE,KAAK,EAAE,GAAGC,WAAA;CAClB,MAAM,EAAE,mBAAmB,EAAE,GAAGC,aAAA;CAChC,MAAM,EAAE,yBAAyB,EAAE,GAAGC,aAAA;CACtC,MAAM,EAAE,mBAAmB,EAAE,GAAGC,aAAA;;AAEhC,CAAA,IAAI,kBAAkB,GAAG;;AAEzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAA,MAAM,uBAAuB,GAAG;;AAEhC;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,CAAA,MAAM,UAAU,GAAG;;AAEnB;AACA;AACA;AACA;AACA;AACA,CAAA,MAAM,IAAI,GAAG;;AAEb;AACA;AACA;AACA;AACA,CAAA,MAAM,MAAM,GAAG;;AAEf;AACA;AACA;AACA;AACA,CAAA,MAAM,SAAS,GAAG;;AAElB;AACA;AACA;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899
  // 1. Run these steps, but abort when fetchParams is canceled:
1900
- fetchParams.controller.onAborted = onAborted;
1901
- fetchParams.controller.on('terminated', onAborted);
1900
+ if (!fetchParams.controller.resume) {
1901
+ fetchParams.controller.on('terminated', onAborted);
1902
+ }
1903
+
1902
1904
  fetchParams.controller.resume = async () => {
1903
1905
  // 1. While true
1904
1906
  while (true) {
@@ -2067,8 +2069,6 @@ function requireFetch () {
2067
2069
  }
2068
2070
  location = headersList.get('location', true);
2069
2071
 
2070
- this.body = new Readable({ read: resume });
2071
-
2072
2072
  const decoders = [];
2073
2073
 
2074
2074
  const willFollow = location && request.redirect === 'follow' &&
@@ -2086,7 +2086,7 @@ function requireFetch () {
2086
2086
  // CVE fix similar to urllib3 (GHSA-gm62-xv2j-4w53) and curl (CVE-2022-32206).
2087
2087
  const maxContentEncodings = 5;
2088
2088
  if (codings.length > maxContentEncodings) {
2089
- reject(new Error(`too many content-encodings in response: ${codings.length}, maximum allowed is ${maxContentEncodings}`));
2089
+ this.abort(new Error(`too many content-encodings in response: ${codings.length}, maximum allowed is ${maxContentEncodings}`));
2090
2090
  return true
2091
2091
  }
2092
2092
 
@@ -2119,6 +2119,8 @@ function requireFetch () {
2119
2119
  }
2120
2120
  }
2121
2121
 
2122
+ this.body = new Readable({ read: resume });
2123
+
2122
2124
  const onError = this.onError.bind(this);
2123
2125
 
2124
2126
  resolve({
@@ -2165,10 +2167,6 @@ function requireFetch () {
2165
2167
  fetchParams.controller.off('terminated', this.abort);
2166
2168
  }
2167
2169
 
2168
- if (fetchParams.controller.onAborted) {
2169
- fetchParams.controller.off('terminated', fetchParams.controller.onAborted);
2170
- }
2171
-
2172
2170
  fetchParams.controller.ended = true;
2173
2171
 
2174
2172
  this.body.push(null);