@axiom-lattice/client-sdk 4.3.0 → 4.3.1

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.
@@ -1,10 +1,11 @@
1
- import { parseSseBody, SseParseError } from "../sse-parser";
2
- it("rejects an unterminated line once its UTF-8 bytes exceed the line cap", async () => {
3
- const body = new ReadableStream({
4
- pull(controller) { controller.enqueue(new TextEncoder().encode("x".repeat(70000))); },
5
- });
6
- await expect((async () => { for await (const frame of parseSseBody(body))
7
- void frame; })()).rejects.toBeInstanceOf(SseParseError);
1
+ import { parseSseBody } from "../sse-parser";
2
+ it("accepts a line larger than the previous cap without throwing", async () => {
3
+ const payload = JSON.stringify({ ok: true, value: "x".repeat(70000) });
4
+ const body = new ReadableStream({ start(controller) { controller.enqueue(new TextEncoder().encode(`data: ${payload}\n\n`)); controller.close(); } });
5
+ const frames = [];
6
+ for await (const frame of parseSseBody(body))
7
+ frames.push(frame);
8
+ expect(frames).toEqual([{ event: "", data: { ok: true, value: "x".repeat(70000) } }]);
8
9
  });
9
10
  it("supports a CR delimiter", async () => {
10
11
  const body = new ReadableStream({ start(controller) { controller.enqueue(new TextEncoder().encode("event: x\rdata: {\"ok\":true}\r\r")); controller.close(); } });
@@ -1 +1 @@
1
- {"version":3,"file":"sse-parser.test.js","sourceRoot":"","sources":["../../src/__tests__/sse-parser.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE5D,EAAE,CAAC,uEAAuE,EAAE,KAAK,IAAI,EAAE;IACrF,MAAM,IAAI,GAAG,IAAI,cAAc,CAAa;QAC1C,IAAI,CAAC,UAAU,IAAI,UAAU,CAAC,OAAO,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,KAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KACvF,CAAC,CAAC;IACH,MAAM,MAAM,CAAC,CAAC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AAO,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,SAAS,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACjK,MAAM,MAAM,GAAG,EAAE,CAAC;IAAC,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,YAAY,CAAC,IAAI,CAAC;QAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACpF,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,KAAM,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AACzF,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,yBAAyB,EAAE,KAAK,IAAI,EAAE;IACvC,MAAM,IAAI,GAAG,IAAI,cAAc,CAAa,EAAE,KAAK,CAAC,UAAU,IAAI,UAAU,CAAC,OAAO,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,mCAAmC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC9K,MAAM,MAAM,GAAG,EAAE,CAAC;IAAC,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,YAAY,CAAC,IAAI,CAAC;QAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACpF,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;AAC/D,CAAC,CAAC,CAAC"}
package/dist/index.js CHANGED
@@ -919,8 +919,8 @@ var require_encoding = __commonJS({
919
919
  }
920
920
  return serializeStream.call(this, output);
921
921
  };
922
- function TextEncoder2(label, options) {
923
- if (!(this instanceof TextEncoder2))
922
+ function TextEncoder(label, options) {
923
+ if (!(this instanceof TextEncoder))
924
924
  throw TypeError("Called as a function. Did you forget 'new'?");
925
925
  options = ToDictionary(options);
926
926
  this._encoding = null;
@@ -948,14 +948,14 @@ var require_encoding = __commonJS({
948
948
  return enc;
949
949
  }
950
950
  if (Object.defineProperty) {
951
- Object.defineProperty(TextEncoder2.prototype, "encoding", {
951
+ Object.defineProperty(TextEncoder.prototype, "encoding", {
952
952
  /** @this {TextEncoder} */
953
953
  get: function() {
954
954
  return this._encoding.name.toLowerCase();
955
955
  }
956
956
  });
957
957
  }
958
- TextEncoder2.prototype.encode = function encode2(opt_string, options) {
958
+ TextEncoder.prototype.encode = function encode2(opt_string, options) {
959
959
  opt_string = opt_string === void 0 ? "" : String(opt_string);
960
960
  options = ToDictionary(options);
961
961
  if (!this._do_not_flush)
@@ -1811,7 +1811,7 @@ var require_encoding = __commonJS({
1811
1811
  return new XUserDefinedDecoder(options);
1812
1812
  };
1813
1813
  if (!global["TextEncoder"])
1814
- global["TextEncoder"] = TextEncoder2;
1814
+ global["TextEncoder"] = TextEncoder;
1815
1815
  if (!global["TextDecoder"])
1816
1816
  global["TextDecoder"] = TextDecoder2;
1817
1817
  if (typeof module2 !== "undefined" && module2.exports) {
@@ -3464,9 +3464,6 @@ var SseParseError = class extends Error {
3464
3464
  }
3465
3465
  };
3466
3466
  async function* parseSseBody(body, options = {}) {
3467
- const maxLine = options.maxLineBytes ?? 64 * 1024;
3468
- const maxEvent = options.maxEventBytes ?? 1024 * 1024;
3469
- const maxDataLines = options.maxDataLines ?? 1024;
3470
3467
  const reader = body.getReader();
3471
3468
  const decoder = new TextDecoder();
3472
3469
  let buffer = "";
@@ -3474,13 +3471,11 @@ async function* parseSseBody(body, options = {}) {
3474
3471
  let id;
3475
3472
  let retry;
3476
3473
  let data = [];
3477
- let bytes = 0;
3478
3474
  const dispatch = () => {
3479
3475
  if (data.length === 0) {
3480
3476
  event = "";
3481
3477
  id = void 0;
3482
3478
  retry = void 0;
3483
- bytes = 0;
3484
3479
  return void 0;
3485
3480
  }
3486
3481
  let parsed;
@@ -3496,13 +3491,10 @@ async function* parseSseBody(body, options = {}) {
3496
3491
  id = void 0;
3497
3492
  retry = void 0;
3498
3493
  data = [];
3499
- bytes = 0;
3500
3494
  return result;
3501
3495
  };
3502
3496
  const processLine = (raw) => {
3503
3497
  const line = raw.endsWith("\r") ? raw.slice(0, -1) : raw;
3504
- if (new TextEncoder().encode(line).byteLength > maxLine)
3505
- throw new SseParseError("SSE line is too large");
3506
3498
  if (line === "")
3507
3499
  return dispatch();
3508
3500
  if (line.startsWith(":"))
@@ -3514,14 +3506,9 @@ async function* parseSseBody(body, options = {}) {
3514
3506
  value = value.slice(1);
3515
3507
  if (field === "event")
3516
3508
  event = value;
3517
- else if (field === "data") {
3518
- if (data.length >= maxDataLines)
3519
- throw new SseParseError("Too many SSE data lines");
3509
+ else if (field === "data")
3520
3510
  data.push(value);
3521
- bytes += new TextEncoder().encode(value).byteLength + (data.length === 1 ? 0 : 1);
3522
- if (bytes > maxEvent)
3523
- throw new SseParseError("SSE event is too large");
3524
- } else if (field === "id")
3511
+ else if (field === "id")
3525
3512
  id = value;
3526
3513
  else if (field === "retry") {
3527
3514
  const parsed = Number(value);
@@ -3536,13 +3523,9 @@ async function* parseSseBody(body, options = {}) {
3536
3523
  const chunk = await reader.read();
3537
3524
  if (chunk.done) {
3538
3525
  buffer += decoder.decode();
3539
- if (new TextEncoder().encode(buffer).byteLength > maxLine)
3540
- throw new SseParseError("SSE line is too large");
3541
3526
  break;
3542
3527
  }
3543
3528
  buffer += decoder.decode(chunk.value, { stream: true });
3544
- if (new TextEncoder().encode(buffer.slice(0, Math.max(0, findLineBreak(buffer) < 0 ? buffer.length : findLineBreak(buffer)))).byteLength > maxLine)
3545
- throw new SseParseError("SSE line is too large");
3546
3529
  let index = findLineBreak(buffer);
3547
3530
  while (index >= 0) {
3548
3531
  if (buffer[index] === "\r" && index === buffer.length - 1)