@electric-sql/client 1.5.4 → 1.5.5

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.
@@ -463,10 +463,10 @@ function snakeCamelMapper(schema) {
463
463
 
464
464
  // src/helpers.ts
465
465
  function isChangeMessage(message) {
466
- return `key` in message;
466
+ return message != null && `key` in message;
467
467
  }
468
468
  function isControlMessage(message) {
469
- return !isChangeMessage(message);
469
+ return message != null && !isChangeMessage(message);
470
470
  }
471
471
  function isUpToDateMessage(message) {
472
472
  return isControlMessage(message) && message.headers.control === `up-to-date`;
@@ -2321,7 +2321,8 @@ requestShape_fn = async function() {
2321
2321
  }
2322
2322
  const newShapeHandle = e.headers[SHAPE_HANDLE_HEADER] || `${__privateGet(this, _syncState).handle}-next`;
2323
2323
  __privateMethod(this, _ShapeStream_instances, reset_fn).call(this, newShapeHandle);
2324
- await __privateMethod(this, _ShapeStream_instances, publish_fn).call(this, Array.isArray(e.json) ? e.json : [e.json]);
2324
+ const messages409 = Array.isArray(e.json) ? e.json : e.json != null ? [e.json] : [];
2325
+ await __privateMethod(this, _ShapeStream_instances, publish_fn).call(this, messages409);
2325
2326
  return __privateMethod(this, _ShapeStream_instances, requestShape_fn).call(this);
2326
2327
  } else {
2327
2328
  throw e;
@@ -2504,6 +2505,12 @@ onInitialResponse_fn = async function(response) {
2504
2505
  return true;
2505
2506
  };
2506
2507
  onMessages_fn = async function(batch, isSseMessage = false) {
2508
+ if (!Array.isArray(batch)) {
2509
+ console.warn(
2510
+ `[Electric] #onMessages called with non-array argument (${typeof batch}). This is a client bug \u2014 please report it.`
2511
+ );
2512
+ return;
2513
+ }
2507
2514
  if (batch.length === 0) return;
2508
2515
  const lastMessage = batch[batch.length - 1];
2509
2516
  const hasUpToDateMessage = isUpToDateMessage(lastMessage);
@@ -2560,6 +2567,7 @@ fetchShape_fn = async function(opts) {
2560
2567
  return __privateMethod(this, _ShapeStream_instances, requestShapeLongPoll_fn).call(this, opts);
2561
2568
  };
2562
2569
  requestShapeLongPoll_fn = async function(opts) {
2570
+ var _a;
2563
2571
  const { fetchUrl, requestAbortController, headers } = opts;
2564
2572
  const response = await __privateGet(this, _fetchClient2).call(this, fetchUrl.toString(), {
2565
2573
  signal: requestAbortController.signal,
@@ -2572,6 +2580,16 @@ requestShapeLongPoll_fn = async function(opts) {
2572
2580
  const res = await response.text();
2573
2581
  const messages = res || `[]`;
2574
2582
  const batch = __privateGet(this, _messageParser).parse(messages, schema);
2583
+ if (!Array.isArray(batch)) {
2584
+ const preview = (_a = JSON.stringify(batch)) == null ? void 0 : _a.slice(0, 200);
2585
+ throw new FetchError(
2586
+ response.status,
2587
+ `Received non-array response body from shape endpoint. This may indicate a proxy or CDN is returning an unexpected response. Expected a JSON array, got ${typeof batch}: ${preview}`,
2588
+ void 0,
2589
+ Object.fromEntries(response.headers.entries()),
2590
+ fetchUrl.toString()
2591
+ );
2592
+ }
2575
2593
  await __privateMethod(this, _ShapeStream_instances, onMessages_fn).call(this, batch);
2576
2594
  };
2577
2595
  requestShapeSSE_fn = async function(opts) {