@otonoma/paranet-client 2.18.2 → 2.19.0-rc.12

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 (100) hide show
  1. package/dist/cjs/graphql.d.ts.map +1 -1
  2. package/dist/cjs/{index-AtS3JMf_.cjs → index-eBiJ1Egw.cjs} +161 -295
  3. package/dist/cjs/index-eBiJ1Egw.cjs.map +1 -0
  4. package/dist/cjs/index.cjs +80 -227
  5. package/dist/cjs/index.cjs.map +1 -1
  6. package/dist/cjs/index.d.ts +0 -1
  7. package/dist/cjs/index.d.ts.map +1 -1
  8. package/dist/cjs/pncp.d.ts +0 -10
  9. package/dist/cjs/pncp.d.ts.map +1 -1
  10. package/dist/cjs/proto/broker.grpc.client.d.ts +19 -34
  11. package/dist/cjs/proto/broker.grpc.client.d.ts.map +1 -1
  12. package/dist/cjs/proto/broker.grpc.d.ts.map +1 -1
  13. package/dist/cjs/proto/broker_api.d.ts +59 -25
  14. package/dist/cjs/proto/broker_api.d.ts.map +1 -1
  15. package/dist/cjs/proto/google/protobuf/descriptor.d.ts +177 -177
  16. package/dist/cjs/proto/google/protobuf/descriptor.d.ts.map +1 -1
  17. package/dist/cjs/proto/google/protobuf/timestamp.d.ts +2 -2
  18. package/dist/cjs/proto/grpc/health/v1/health.client.d.ts +4 -4
  19. package/dist/cjs/proto/grpc/health/v1/health.d.ts +2 -2
  20. package/dist/cjs/proto/identifiers.d.ts +4 -4
  21. package/dist/cjs/proto/observation.d.ts +27 -27
  22. package/dist/cjs/proto/otonoma/common/value.d.ts +10 -10
  23. package/dist/cjs/proto/pncp.d.ts +49 -100
  24. package/dist/cjs/proto/pncp.d.ts.map +1 -1
  25. package/dist/cjs/schema/paranet.d.ts +4 -32
  26. package/dist/cjs/schema/paranet.d.ts.map +1 -1
  27. package/dist/client.js +1 -1
  28. package/dist/esm/graphql.d.ts.map +1 -1
  29. package/dist/esm/{index-HCY5Ez1I.mjs → index-PztyZob7.mjs} +161 -295
  30. package/dist/esm/index-PztyZob7.mjs.map +1 -0
  31. package/dist/esm/index.d.ts +0 -1
  32. package/dist/esm/index.d.ts.map +1 -1
  33. package/dist/esm/index.mjs +80 -225
  34. package/dist/esm/index.mjs.map +1 -1
  35. package/dist/esm/pncp.d.ts +0 -10
  36. package/dist/esm/pncp.d.ts.map +1 -1
  37. package/dist/esm/proto/broker.grpc.client.d.ts +19 -34
  38. package/dist/esm/proto/broker.grpc.client.d.ts.map +1 -1
  39. package/dist/esm/proto/broker.grpc.d.ts.map +1 -1
  40. package/dist/esm/proto/broker_api.d.ts +59 -25
  41. package/dist/esm/proto/broker_api.d.ts.map +1 -1
  42. package/dist/esm/proto/google/protobuf/descriptor.d.ts +177 -177
  43. package/dist/esm/proto/google/protobuf/descriptor.d.ts.map +1 -1
  44. package/dist/esm/proto/google/protobuf/timestamp.d.ts +2 -2
  45. package/dist/esm/proto/grpc/health/v1/health.client.d.ts +4 -4
  46. package/dist/esm/proto/grpc/health/v1/health.d.ts +2 -2
  47. package/dist/esm/proto/identifiers.d.ts +4 -4
  48. package/dist/esm/proto/observation.d.ts +27 -27
  49. package/dist/esm/proto/otonoma/common/value.d.ts +10 -10
  50. package/dist/esm/proto/pncp.d.ts +49 -100
  51. package/dist/esm/proto/pncp.d.ts.map +1 -1
  52. package/dist/esm/schema/paranet.d.ts +4 -32
  53. package/dist/esm/schema/paranet.d.ts.map +1 -1
  54. package/dist/graphql.d.ts.map +1 -1
  55. package/dist/graphql.js +0 -2
  56. package/dist/index.d.cts +197 -321
  57. package/dist/index.d.mts +197 -321
  58. package/dist/index.d.ts +0 -1
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +0 -1
  61. package/dist/pncp.d.ts +0 -10
  62. package/dist/pncp.d.ts.map +1 -1
  63. package/dist/pncp.js +0 -3
  64. package/dist/proto/broker.grpc.client.d.ts +19 -34
  65. package/dist/proto/broker.grpc.client.d.ts.map +1 -1
  66. package/dist/proto/broker.grpc.client.js +8 -18
  67. package/dist/proto/broker.grpc.d.ts.map +1 -1
  68. package/dist/proto/broker.grpc.js +4 -6
  69. package/dist/proto/broker_api.d.ts +59 -25
  70. package/dist/proto/broker_api.d.ts.map +1 -1
  71. package/dist/proto/broker_api.js +76 -2
  72. package/dist/proto/google/protobuf/descriptor.d.ts +177 -177
  73. package/dist/proto/google/protobuf/descriptor.d.ts.map +1 -1
  74. package/dist/proto/google/protobuf/descriptor.js +136 -110
  75. package/dist/proto/google/protobuf/timestamp.d.ts +2 -2
  76. package/dist/proto/google/protobuf/timestamp.js +1 -1
  77. package/dist/proto/grpc/health/v1/health.client.d.ts +4 -4
  78. package/dist/proto/grpc/health/v1/health.client.js +2 -2
  79. package/dist/proto/grpc/health/v1/health.d.ts +2 -2
  80. package/dist/proto/grpc/health/v1/health.js +1 -1
  81. package/dist/proto/identifiers.d.ts +4 -4
  82. package/dist/proto/observation.d.ts +27 -27
  83. package/dist/proto/observation.js +1 -1
  84. package/dist/proto/otonoma/common/value.d.ts +10 -10
  85. package/dist/proto/otonoma/common/value.js +2 -2
  86. package/dist/proto/pncp.d.ts +49 -100
  87. package/dist/proto/pncp.d.ts.map +1 -1
  88. package/dist/proto/pncp.js +1 -89
  89. package/dist/schema/paranet.d.ts +4 -32
  90. package/dist/schema/paranet.d.ts.map +1 -1
  91. package/package.json +1 -1
  92. package/dist/cjs/index-AtS3JMf_.cjs.map +0 -1
  93. package/dist/cjs/proto/mediums.d.ts +0 -71
  94. package/dist/cjs/proto/mediums.d.ts.map +0 -1
  95. package/dist/esm/index-HCY5Ez1I.mjs.map +0 -1
  96. package/dist/esm/proto/mediums.d.ts +0 -71
  97. package/dist/esm/proto/mediums.d.ts.map +0 -1
  98. package/dist/proto/mediums.d.ts +0 -71
  99. package/dist/proto/mediums.d.ts.map +0 -1
  100. package/dist/proto/mediums.js +0 -120
@@ -1 +1 @@
1
- {"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/graphql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,iBAAiB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AACjG,OAAO,KAAK,MAAM,MAAM,kBAAkB,CAAC;AAE3C,OAAO,EAAE,cAAc,EAA0B,MAAM,qBAAqB,CAAC;AAE7E,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,gBAAgB,CAK9E;AAGD,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,CAAC,WAAW,GAAG,iBAAiB,CAejF;AAUD,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,CAAC,WAAW,GAAG,iBAAiB,CAejF;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,CAWlE"}
1
+ {"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/graphql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,iBAAiB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AACjG,OAAO,KAAK,MAAM,MAAM,kBAAkB,CAAC;AAE3C,OAAO,EAAE,cAAc,EAA0B,MAAM,qBAAqB,CAAC;AAE7E,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,gBAAgB,CAK9E;AAGD,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,CAAC,WAAW,GAAG,iBAAiB,CAajF;AAUD,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,CAAC,WAAW,GAAG,iBAAiB,CAejF;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,CAWlE"}
@@ -8949,7 +8949,7 @@ async function connectH1$1 (client, socket) {
8949
8949
 
8950
8950
  function clearIdleSocketValidation (socket) {
8951
8951
  if (socket[kIdleSocketValidationTimeout]) {
8952
- clearImmediate(socket[kIdleSocketValidationTimeout]);
8952
+ clearTimeout(socket[kIdleSocketValidationTimeout]);
8953
8953
  socket[kIdleSocketValidationTimeout] = null;
8954
8954
  }
8955
8955
 
@@ -8958,23 +8958,15 @@ function clearIdleSocketValidation (socket) {
8958
8958
 
8959
8959
  function scheduleIdleSocketValidation (client, socket) {
8960
8960
  socket[kIdleSocketValidation] = 1;
8961
- // Yield to the check phase (after poll) so unsolicited bytes / FIN / RST
8962
- // already pending on this idle keep-alive socket are processed before the
8963
- // next request is written (GHSA-35p6-xmwp-9g52).
8964
- //
8965
- // setTimeout(0) pays Node's ~1ms timer floor on every sequential reuse
8966
- // (#5493). setImmediate avoids that, but an *unref'd* Immediate lets poll
8967
- // block for ~500ms when the event loop is otherwise idle (#5600 / #5606).
8968
- // A ref'd Immediate both keeps the pending request alive and makes poll
8969
- // return immediately — the hybrid those issues asked for.
8970
- socket[kIdleSocketValidationTimeout] = setImmediate(() => {
8961
+ socket[kIdleSocketValidationTimeout] = setTimeout(() => {
8971
8962
  socket[kIdleSocketValidationTimeout] = null;
8972
8963
  socket[kIdleSocketValidation] = 2;
8973
8964
 
8974
8965
  if (client[kSocket$1] === socket && !socket.destroyed) {
8975
8966
  client[kResume$3]();
8976
8967
  }
8977
- });
8968
+ }, 0);
8969
+ socket[kIdleSocketValidationTimeout].unref?.();
8978
8970
  }
8979
8971
 
8980
8972
  /**
@@ -12479,7 +12471,6 @@ let RetryHandler$3 = class RetryHandler {
12479
12471
  this.end = null;
12480
12472
  this.etag = null;
12481
12473
  this.resume = null;
12482
- this.headersSent = false;
12483
12474
 
12484
12475
  // Handle possible onConnect duplication
12485
12476
  this.handler.onConnect(reason => {
@@ -12492,20 +12483,6 @@ let RetryHandler$3 = class RetryHandler {
12492
12483
  });
12493
12484
  }
12494
12485
 
12495
- checkpointResponseEnd (headers, resume) {
12496
- if (this.end == null && this.opts.method !== 'HEAD') {
12497
- const contentLength = headers['content-length'];
12498
- this.end = contentLength != null ? Number(contentLength) - 1 : null;
12499
-
12500
- assert$7(
12501
- this.end == null || Number.isFinite(this.end),
12502
- 'invalid content-length'
12503
- );
12504
- }
12505
-
12506
- this.resume = this.end != null ? resume : null;
12507
- }
12508
-
12509
12486
  onRequestSent () {
12510
12487
  if (this.handler.onRequestSent) {
12511
12488
  this.handler.onRequestSent();
@@ -12595,8 +12572,6 @@ let RetryHandler$3 = class RetryHandler {
12595
12572
 
12596
12573
  if (statusCode >= 300) {
12597
12574
  if (this.retryOpts.statusCodes.includes(statusCode) === false) {
12598
- this.headersSent = true;
12599
- this.checkpointResponseEnd(headers, resume);
12600
12575
  return this.handler.onHeaders(
12601
12576
  statusCode,
12602
12577
  rawHeaders,
@@ -12665,15 +12640,8 @@ let RetryHandler$3 = class RetryHandler {
12665
12640
 
12666
12641
  const { start, size, end = size - 1 } = contentRange;
12667
12642
 
12668
- if (this.start !== start || (this.end != null && this.end !== end)) {
12669
- this.abort(
12670
- new RequestRetryError('Content-Range mismatch', statusCode, {
12671
- headers,
12672
- data: { count: this.retryCount }
12673
- })
12674
- );
12675
- return false
12676
- }
12643
+ assert$7(this.start === start, 'content-range mismatch');
12644
+ assert$7(this.end == null || this.end === end, 'content-range mismatch');
12677
12645
 
12678
12646
  this.resume = resume;
12679
12647
  return true
@@ -12685,7 +12653,6 @@ let RetryHandler$3 = class RetryHandler {
12685
12653
  const range = parseRangeHeader(headers['content-range']);
12686
12654
 
12687
12655
  if (range == null) {
12688
- this.headersSent = true;
12689
12656
  return this.handler.onHeaders(
12690
12657
  statusCode,
12691
12658
  rawHeaders,
@@ -12724,7 +12691,6 @@ let RetryHandler$3 = class RetryHandler {
12724
12691
  );
12725
12692
 
12726
12693
  this.resume = resume;
12727
- this.headersSent = true;
12728
12694
  this.etag = headers.etag != null ? headers.etag : null;
12729
12695
 
12730
12696
  // Weak etags are not useful for comparison nor cache
@@ -12764,7 +12730,7 @@ let RetryHandler$3 = class RetryHandler {
12764
12730
  }
12765
12731
 
12766
12732
  onError (err) {
12767
- if (this.aborted || isDisturbed(this.opts.body) || (this.headersSent && this.resume == null)) {
12733
+ if (this.aborted || isDisturbed(this.opts.body)) {
12768
12734
  return this.handler.onError(err)
12769
12735
  }
12770
12736
 
@@ -24673,7 +24639,7 @@ function requireConnection () {
24673
24639
  // is specified, the server needs to include the same field and one of
24674
24640
  // the selected subprotocol values in its response for the connection to
24675
24641
  // be established.
24676
- if (requestProtocols === null || !requestProtocols.includes(secProtocol)) {
24642
+ if (!requestProtocols.includes(secProtocol)) {
24677
24643
  failWebsocketConnection(ws, 'Protocol was not set in the opening handshake.');
24678
24644
  return
24679
24645
  }
@@ -24920,12 +24886,7 @@ function requirePermessageDeflate () {
24920
24886
 
24921
24887
  if (this.#maxPayloadSize > 0 && this.#inflate[kLength] > this.#maxPayloadSize) {
24922
24888
  callback(new MessageSizeExceededError());
24923
- // The inflater may still hold buffered input that can emit a late
24924
- // zlib error. Remove the data listener, then deterministically stop
24925
- // the stream so a subsequent 'error' cannot fire without a listener
24926
- // (which would terminate the process as an unhandled error event).
24927
24889
  this.#inflate.removeAllListeners();
24928
- this.#inflate.destroy();
24929
24890
  this.#inflate = null;
24930
24891
  return
24931
24892
  }
@@ -26274,49 +26235,6 @@ function requireEventsourceStream () {
26274
26235
  */
26275
26236
  const SPACE = 0x20;
26276
26237
 
26277
- const DATA = Buffer.from('data');
26278
- const EVENT = Buffer.from('event');
26279
- const ID = Buffer.from('id');
26280
- const RETRY = Buffer.from('retry');
26281
-
26282
- function isASCIINumberBytes (buffer, start) {
26283
- if (start >= buffer.length) {
26284
- return false
26285
- }
26286
-
26287
- for (let i = start; i < buffer.length; i++) {
26288
- if (buffer[i] < 0x30 || buffer[i] > 0x39) {
26289
- return false
26290
- }
26291
- }
26292
-
26293
- return true
26294
- }
26295
-
26296
- function isValidLastEventIdBytes (buffer, start) {
26297
- for (let i = start; i < buffer.length; i++) {
26298
- if (buffer[i] === 0x00) {
26299
- return false
26300
- }
26301
- }
26302
-
26303
- return true
26304
- }
26305
-
26306
- function isFieldName (line, length, field) {
26307
- if (length !== field.length) {
26308
- return false
26309
- }
26310
-
26311
- for (let i = 0; i < length; i++) {
26312
- if (line[i] !== field[i]) {
26313
- return false
26314
- }
26315
- }
26316
-
26317
- return true
26318
- }
26319
-
26320
26238
  /**
26321
26239
  * @typedef {object} EventSourceStreamEvent
26322
26240
  * @type {object}
@@ -26357,14 +26275,11 @@ function requireEventsourceStream () {
26357
26275
  eventEndCheck = false
26358
26276
 
26359
26277
  /**
26360
- * @type {Buffer[]}
26278
+ * @type {Buffer}
26361
26279
  */
26362
- chunks = []
26280
+ buffer = null
26363
26281
 
26364
- chunkIndex = 0
26365
26282
  pos = 0
26366
- lineChunkIndex = 0
26367
- linePos = 0
26368
26283
 
26369
26284
  event = {
26370
26285
  data: undefined,
@@ -26403,20 +26318,92 @@ function requireEventsourceStream () {
26403
26318
  return
26404
26319
  }
26405
26320
 
26406
- this.chunks.push(chunk);
26321
+ // Cache the chunk in the buffer, as the data might not be complete while
26322
+ // processing it
26323
+ // TODO: Investigate if there is a more performant way to handle
26324
+ // incoming chunks
26325
+ // see: https://github.com/nodejs/undici/issues/2630
26326
+ if (this.buffer) {
26327
+ this.buffer = Buffer.concat([this.buffer, chunk]);
26328
+ } else {
26329
+ this.buffer = chunk;
26330
+ }
26407
26331
 
26408
26332
  // Strip leading byte-order-mark if we opened the stream and started
26409
26333
  // the processing of the incoming data
26410
26334
  if (this.checkBOM) {
26411
- if (this.handleBOM()) {
26412
- callback();
26413
- return
26335
+ switch (this.buffer.length) {
26336
+ case 1:
26337
+ // Check if the first byte is the same as the first byte of the BOM
26338
+ if (this.buffer[0] === BOM[0]) {
26339
+ // If it is, we need to wait for more data
26340
+ callback();
26341
+ return
26342
+ }
26343
+ // Set the checkBOM flag to false as we don't need to check for the
26344
+ // BOM anymore
26345
+ this.checkBOM = false;
26346
+
26347
+ // The buffer only contains one byte so we need to wait for more data
26348
+ callback();
26349
+ return
26350
+ case 2:
26351
+ // Check if the first two bytes are the same as the first two bytes
26352
+ // of the BOM
26353
+ if (
26354
+ this.buffer[0] === BOM[0] &&
26355
+ this.buffer[1] === BOM[1]
26356
+ ) {
26357
+ // If it is, we need to wait for more data, because the third byte
26358
+ // is needed to determine if it is the BOM or not
26359
+ callback();
26360
+ return
26361
+ }
26362
+
26363
+ // Set the checkBOM flag to false as we don't need to check for the
26364
+ // BOM anymore
26365
+ this.checkBOM = false;
26366
+ break
26367
+ case 3:
26368
+ // Check if the first three bytes are the same as the first three
26369
+ // bytes of the BOM
26370
+ if (
26371
+ this.buffer[0] === BOM[0] &&
26372
+ this.buffer[1] === BOM[1] &&
26373
+ this.buffer[2] === BOM[2]
26374
+ ) {
26375
+ // If it is, we can drop the buffered data, as it is only the BOM
26376
+ this.buffer = Buffer.alloc(0);
26377
+ // Set the checkBOM flag to false as we don't need to check for the
26378
+ // BOM anymore
26379
+ this.checkBOM = false;
26380
+
26381
+ // Await more data
26382
+ callback();
26383
+ return
26384
+ }
26385
+ // If it is not the BOM, we can start processing the data
26386
+ this.checkBOM = false;
26387
+ break
26388
+ default:
26389
+ // The buffer is longer than 3 bytes, so we can drop the BOM if it is
26390
+ // present
26391
+ if (
26392
+ this.buffer[0] === BOM[0] &&
26393
+ this.buffer[1] === BOM[1] &&
26394
+ this.buffer[2] === BOM[2]
26395
+ ) {
26396
+ // Remove the BOM from the buffer
26397
+ this.buffer = this.buffer.subarray(3);
26398
+ }
26399
+
26400
+ // Set the checkBOM flag to false as we don't need to check for the
26401
+ this.checkBOM = false;
26402
+ break
26414
26403
  }
26415
26404
  }
26416
26405
 
26417
- while (this.hasCurrentByte()) {
26418
- const byte = this.currentByte();
26419
-
26406
+ while (this.pos < this.buffer.length) {
26420
26407
  // If the previous line ended with an end-of-line, we need to check
26421
26408
  // if the next character is also an end-of-line.
26422
26409
  if (this.eventEndCheck) {
@@ -26429,9 +26416,10 @@ function requireEventsourceStream () {
26429
26416
  if (this.crlfCheck) {
26430
26417
  // If the current character is a line feed, we can remove it
26431
26418
  // from the buffer and reset the crlfCheck flag
26432
- if (byte === LF) {
26419
+ if (this.buffer[this.pos] === LF) {
26420
+ this.buffer = this.buffer.subarray(this.pos + 1);
26421
+ this.pos = 0;
26433
26422
  this.crlfCheck = false;
26434
- this.consumeCurrentByte();
26435
26423
 
26436
26424
  // It is possible that the line feed is not the end of the
26437
26425
  // event. We need to check if the next character is an
@@ -26447,17 +26435,19 @@ function requireEventsourceStream () {
26447
26435
  this.crlfCheck = false;
26448
26436
  }
26449
26437
 
26450
- if (byte === LF || byte === CR) {
26438
+ if (this.buffer[this.pos] === LF || this.buffer[this.pos] === CR) {
26451
26439
  // If the current character is a carriage return, we need to
26452
26440
  // set the crlfCheck flag to true, as we need to check if the
26453
26441
  // next character is a line feed so we can remove it from the
26454
26442
  // buffer
26455
- if (byte === CR) {
26443
+ if (this.buffer[this.pos] === CR) {
26456
26444
  this.crlfCheck = true;
26457
26445
  }
26458
26446
 
26459
- this.consumeCurrentByte();
26460
- if (this.hasPendingEvent()) {
26447
+ this.buffer = this.buffer.subarray(this.pos + 1);
26448
+ this.pos = 0;
26449
+ if (
26450
+ this.event.data !== undefined || this.event.event || this.event.id || this.event.retry) {
26461
26451
  this.processEvent(this.event);
26462
26452
  }
26463
26453
  this.clearEvent();
@@ -26471,18 +26461,22 @@ function requireEventsourceStream () {
26471
26461
 
26472
26462
  // If the current character is an end-of-line, we can process the
26473
26463
  // line
26474
- if (byte === LF || byte === CR) {
26464
+ if (this.buffer[this.pos] === LF || this.buffer[this.pos] === CR) {
26475
26465
  // If the current character is a carriage return, we need to
26476
26466
  // set the crlfCheck flag to true, as we need to check if the
26477
26467
  // next character is a line feed
26478
- if (byte === CR) {
26468
+ if (this.buffer[this.pos] === CR) {
26479
26469
  this.crlfCheck = true;
26480
26470
  }
26481
26471
 
26482
26472
  // In any case, we can process the line as we reached an
26483
26473
  // end-of-line character
26484
- this.parseLine(this.readLine(), this.event);
26485
- this.consumeCurrentByte();
26474
+ this.parseLine(this.buffer.subarray(0, this.pos), this.event);
26475
+
26476
+ // Remove the processed line from the buffer
26477
+ this.buffer = this.buffer.subarray(this.pos + 1);
26478
+ // Reset the position as we removed the processed line from the buffer
26479
+ this.pos = 0;
26486
26480
  // A line was processed and this could be the end of the event. We need
26487
26481
  // to check if the next line is empty to determine if the event is
26488
26482
  // finished.
@@ -26490,7 +26484,7 @@ function requireEventsourceStream () {
26490
26484
  continue
26491
26485
  }
26492
26486
 
26493
- this.advanceCursor();
26487
+ this.pos++;
26494
26488
  }
26495
26489
 
26496
26490
  callback();
@@ -26515,53 +26509,64 @@ function requireEventsourceStream () {
26515
26509
  return
26516
26510
  }
26517
26511
 
26518
- let fieldLength = line.length;
26519
- let valueStart = line.length;
26512
+ let field = '';
26513
+ let value = '';
26520
26514
 
26521
26515
  // If the line contains a U+003A COLON character (:)
26522
26516
  if (colonPosition !== -1) {
26523
- fieldLength = colonPosition;
26517
+ // Collect the characters on the line before the first U+003A COLON
26518
+ // character (:), and let field be that string.
26519
+ // TODO: Investigate if there is a more performant way to extract the
26520
+ // field
26521
+ // see: https://github.com/nodejs/undici/issues/2630
26522
+ field = line.subarray(0, colonPosition).toString('utf8');
26524
26523
 
26525
26524
  // Collect the characters on the line after the first U+003A COLON
26526
26525
  // character (:), and let value be that string.
26527
26526
  // If value starts with a U+0020 SPACE character, remove it from value.
26528
- valueStart = colonPosition + 1;
26527
+ let valueStart = colonPosition + 1;
26529
26528
  if (line[valueStart] === SPACE) {
26530
26529
  ++valueStart;
26531
26530
  }
26532
- }
26533
-
26534
- if (isFieldName(line, fieldLength, DATA)) {
26535
- const value = line.toString('utf8', valueStart);
26536
-
26537
- if (event.data === undefined) {
26538
- event.data = value;
26539
- } else {
26540
- event.data += `\n${value}`;
26541
- }
26542
- return
26543
- }
26544
-
26545
- if (isFieldName(line, fieldLength, RETRY)) {
26546
- if (isASCIINumberBytes(line, valueStart)) {
26547
- event.retry = line.toString('utf8', valueStart);
26548
- }
26549
- return
26550
- }
26551
-
26552
- if (isFieldName(line, fieldLength, ID)) {
26553
- if (isValidLastEventIdBytes(line, valueStart)) {
26554
- event.id = line.toString('utf8', valueStart);
26555
- }
26556
- return
26557
- }
26531
+ // TODO: Investigate if there is a more performant way to extract the
26532
+ // value
26533
+ // see: https://github.com/nodejs/undici/issues/2630
26534
+ value = line.subarray(valueStart).toString('utf8');
26558
26535
 
26559
- if (isFieldName(line, fieldLength, EVENT)) {
26560
- const value = line.toString('utf8', valueStart);
26561
-
26562
- if (value.length > 0) {
26563
- event.event = value;
26564
- }
26536
+ // Otherwise, the string is not empty but does not contain a U+003A COLON
26537
+ // character (:)
26538
+ } else {
26539
+ // Process the field using the steps described below, using the whole
26540
+ // line as the field name, and the empty string as the field value.
26541
+ field = line.toString('utf8');
26542
+ value = '';
26543
+ }
26544
+
26545
+ // Modify the event with the field name and value. The value is also
26546
+ // decoded as UTF-8
26547
+ switch (field) {
26548
+ case 'data':
26549
+ if (event[field] === undefined) {
26550
+ event[field] = value;
26551
+ } else {
26552
+ event[field] += `\n${value}`;
26553
+ }
26554
+ break
26555
+ case 'retry':
26556
+ if (isASCIINumber(value)) {
26557
+ event[field] = value;
26558
+ }
26559
+ break
26560
+ case 'id':
26561
+ if (isValidLastEventId(value)) {
26562
+ event[field] = value;
26563
+ }
26564
+ break
26565
+ case 'event':
26566
+ if (value.length > 0) {
26567
+ event[field] = value;
26568
+ }
26569
+ break
26565
26570
  }
26566
26571
  }
26567
26572
 
@@ -26591,151 +26596,12 @@ function requireEventsourceStream () {
26591
26596
  }
26592
26597
 
26593
26598
  clearEvent () {
26594
- this.event.data = undefined;
26595
- this.event.event = undefined;
26596
- this.event.id = undefined;
26597
- this.event.retry = undefined;
26598
- }
26599
-
26600
- hasPendingEvent () {
26601
- return this.event.data !== undefined ||
26602
- this.event.event !== undefined ||
26603
- this.event.id !== undefined ||
26604
- this.event.retry !== undefined
26605
- }
26606
-
26607
- hasCurrentByte () {
26608
- return this.chunkIndex < this.chunks.length &&
26609
- this.pos < this.chunks[this.chunkIndex].length
26610
- }
26611
-
26612
- currentByte () {
26613
- return this.chunks[this.chunkIndex][this.pos]
26614
- }
26615
-
26616
- consumeCurrentByte () {
26617
- this.advanceCursor();
26618
- this.syncLineStartToCursor();
26619
- }
26620
-
26621
- advanceCursor () {
26622
- this.pos++;
26623
-
26624
- while (this.chunkIndex < this.chunks.length && this.pos >= this.chunks[this.chunkIndex].length) {
26625
- this.chunkIndex++;
26626
- this.pos = 0;
26627
- }
26628
- }
26629
-
26630
- syncLineStartToCursor () {
26631
- this.lineChunkIndex = this.chunkIndex;
26632
- this.linePos = this.pos;
26633
- this.dropConsumedChunks();
26634
- }
26635
-
26636
- dropConsumedChunks () {
26637
- while (this.lineChunkIndex > 0) {
26638
- this.chunks.shift();
26639
- this.lineChunkIndex--;
26640
- this.chunkIndex--;
26641
- }
26642
-
26643
- if (this.chunkIndex === this.chunks.length) {
26644
- this.chunks.length = 0;
26645
- this.chunkIndex = 0;
26646
- this.pos = 0;
26647
- this.lineChunkIndex = 0;
26648
- this.linePos = 0;
26649
- }
26650
- }
26651
-
26652
- readLine () {
26653
- if (this.lineChunkIndex === this.chunkIndex) {
26654
- return this.chunks[this.chunkIndex].subarray(this.linePos, this.pos)
26655
- }
26656
-
26657
- const chunks = [];
26658
- let length = 0;
26659
-
26660
- for (let i = this.lineChunkIndex; i <= this.chunkIndex; i++) {
26661
- const chunk = this.chunks[i];
26662
- const start = i === this.lineChunkIndex ? this.linePos : 0;
26663
- const end = i === this.chunkIndex ? this.pos : chunk.length;
26664
- const slice = chunk.subarray(start, end);
26665
- length += slice.length;
26666
- chunks.push(slice);
26667
- }
26668
-
26669
- return Buffer.concat(chunks, length)
26670
- }
26671
-
26672
- peekBufferedByte (offset) {
26673
- let chunkIndex = this.lineChunkIndex;
26674
- let pos = this.linePos;
26675
-
26676
- while (chunkIndex < this.chunks.length) {
26677
- const chunk = this.chunks[chunkIndex];
26678
- const remaining = chunk.length - pos;
26679
-
26680
- if (offset < remaining) {
26681
- return chunk[pos + offset]
26682
- }
26683
-
26684
- offset -= remaining;
26685
- chunkIndex++;
26686
- pos = 0;
26687
- }
26688
- }
26689
-
26690
- discardLeadingBytes (count) {
26691
- while (count > 0 && this.lineChunkIndex < this.chunks.length) {
26692
- const chunk = this.chunks[this.lineChunkIndex];
26693
- const remaining = chunk.length - this.linePos;
26694
-
26695
- if (count < remaining) {
26696
- this.linePos += count;
26697
- count = 0;
26698
- } else {
26699
- count -= remaining;
26700
- this.lineChunkIndex++;
26701
- this.linePos = 0;
26702
- }
26703
- }
26704
-
26705
- this.chunkIndex = this.lineChunkIndex;
26706
- this.pos = this.linePos;
26707
- this.dropConsumedChunks();
26708
- }
26709
-
26710
- handleBOM () {
26711
- const first = this.peekBufferedByte(0);
26712
- const second = this.peekBufferedByte(1);
26713
- const third = this.peekBufferedByte(2);
26714
-
26715
- if (second === undefined) {
26716
- if (first === BOM[0]) {
26717
- return true
26718
- }
26719
-
26720
- this.checkBOM = false;
26721
- return true
26722
- }
26723
-
26724
- if (third === undefined) {
26725
- if (first === BOM[0] && second === BOM[1]) {
26726
- return true
26727
- }
26728
-
26729
- this.checkBOM = false;
26730
- return false
26731
- }
26732
-
26733
- if (first === BOM[0] && second === BOM[1] && third === BOM[2]) {
26734
- this.discardLeadingBytes(3);
26735
- }
26736
-
26737
- this.checkBOM = false;
26738
- return !this.hasCurrentByte()
26599
+ this.event = {
26600
+ data: undefined,
26601
+ event: undefined,
26602
+ id: undefined,
26603
+ retry: undefined
26604
+ };
26739
26605
  }
26740
26606
  }
26741
26607
 
@@ -27455,4 +27321,4 @@ var index = /*#__PURE__*/_mergeNamespaces({
27455
27321
  }, [undici]);
27456
27322
 
27457
27323
  exports.index = index;
27458
- //# sourceMappingURL=index-AtS3JMf_.cjs.map
27324
+ //# sourceMappingURL=index-eBiJ1Egw.cjs.map