@electric-sql/client 1.0.13 → 1.1.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.
@@ -324,26 +324,6 @@ function isVisibleInSnapshot(txid, snapshot) {
324
324
  const xip = snapshot.xip_list.map(BigInt);
325
325
  return xid < xmin || xid < xmax && !xip.includes(xid);
326
326
  }
327
- function generateShardId() {
328
- return Math.floor(Math.random() * 1048575).toString(16).padStart(5, `0`);
329
- }
330
- function isLocalhostUrl(url) {
331
- const hostname = url.hostname.toLowerCase();
332
- return hostname === `localhost` || hostname.endsWith(`.localhost`);
333
- }
334
- function applySubdomainSharding(originalUrl, option = `localhost`) {
335
- if (option === `never` || option === false) {
336
- return originalUrl;
337
- }
338
- const url = new URL(originalUrl);
339
- const shouldShard = option === `always` || option === true || option === `localhost` && isLocalhostUrl(url);
340
- if (!shouldShard) {
341
- return originalUrl;
342
- }
343
- const shardId = generateShardId();
344
- url.hostname = `${shardId}.${url.hostname}`;
345
- return url.toString();
346
- }
347
327
 
348
328
  // src/constants.ts
349
329
  var LIVE_CACHE_BUSTER_HEADER = `electric-cursor`;
@@ -362,6 +342,7 @@ var WHERE_QUERY_PARAM = `where`;
362
342
  var REPLICA_PARAM = `replica`;
363
343
  var WHERE_PARAMS_PARAM = `params`;
364
344
  var EXPERIMENTAL_LIVE_SSE_QUERY_PARAM = `experimental_live_sse`;
345
+ var LIVE_SSE_QUERY_PARAM = `live_sse`;
365
346
  var FORCE_DISCONNECT_AND_REFRESH = `force-disconnect-and-refresh`;
366
347
  var PAUSE_STREAM = `pause-stream`;
367
348
  var LOG_MODE_QUERY_PARAM = `log`;
@@ -432,6 +413,7 @@ function createFetchWithBackoff(fetchClient, backoffOptions = BackoffDefaults) {
432
413
  var NO_BODY_STATUS_CODES = [201, 204, 205];
433
414
  function createFetchWithConsumedMessages(fetchClient) {
434
415
  return (...args) => __async(this, null, function* () {
416
+ var _a, _b;
435
417
  const url = args[0];
436
418
  const res = yield fetchClient(...args);
437
419
  try {
@@ -441,6 +423,9 @@ function createFetchWithConsumedMessages(fetchClient) {
441
423
  const text = yield res.text();
442
424
  return new Response(text, res);
443
425
  } catch (err) {
426
+ if ((_b = (_a = args[1]) == null ? void 0 : _a.signal) == null ? void 0 : _b.aborted) {
427
+ throw new FetchBackoffAbortError();
428
+ }
444
429
  throw new FetchError(
445
430
  res.status,
446
431
  void 0,
@@ -828,10 +813,6 @@ var ShapeStream = class {
828
813
  var _a, _b, _c, _d;
829
814
  this.options = __spreadValues({ subscribe: true }, options);
830
815
  validateOptions(this.options);
831
- this.options.url = applySubdomainSharding(
832
- this.options.url,
833
- this.options.shardSubdomain
834
- );
835
816
  __privateSet(this, _lastOffset, (_a = this.options.offset) != null ? _a : `-1`);
836
817
  __privateSet(this, _liveCacheBuster, ``);
837
818
  __privateSet(this, _shapeHandle, this.options.handle);
@@ -1076,7 +1057,7 @@ requestShape_fn = function() {
1076
1057
  }
1077
1058
  const newShapeHandle = e.headers[SHAPE_HANDLE_HEADER] || `${__privateGet(this, _shapeHandle)}-next`;
1078
1059
  __privateMethod(this, _ShapeStream_instances, reset_fn).call(this, newShapeHandle);
1079
- yield __privateMethod(this, _ShapeStream_instances, publish_fn).call(this, e.json);
1060
+ yield __privateMethod(this, _ShapeStream_instances, publish_fn).call(this, Array.isArray(e.json) ? e.json : [e.json]);
1080
1061
  return __privateMethod(this, _ShapeStream_instances, requestShape_fn).call(this);
1081
1062
  } else {
1082
1063
  __privateMethod(this, _ShapeStream_instances, sendErrorToSubscribers_fn).call(this, e);
@@ -1229,8 +1210,11 @@ onMessages_fn = function(batch, isSseMessage = false) {
1229
1210
  };
1230
1211
  fetchShape_fn = function(opts) {
1231
1212
  return __async(this, null, function* () {
1232
- if (__privateGet(this, _isUpToDate) && this.options.experimentalLiveSse && !__privateGet(this, _isRefreshing) && !opts.resumingFromPause) {
1213
+ var _a;
1214
+ const useSse = (_a = this.options.liveSse) != null ? _a : this.options.experimentalLiveSse;
1215
+ if (__privateGet(this, _isUpToDate) && useSse && !__privateGet(this, _isRefreshing) && !opts.resumingFromPause) {
1233
1216
  opts.fetchUrl.searchParams.set(EXPERIMENTAL_LIVE_SSE_QUERY_PARAM, `true`);
1217
+ opts.fetchUrl.searchParams.set(LIVE_SSE_QUERY_PARAM, `true`);
1234
1218
  return __privateMethod(this, _ShapeStream_instances, requestShapeSSE_fn).call(this, opts);
1235
1219
  }
1236
1220
  return __privateMethod(this, _ShapeStream_instances, requestShapeLongPoll_fn).call(this, opts);