@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.
package/dist/index.mjs CHANGED
@@ -293,26 +293,6 @@ function isVisibleInSnapshot(txid, snapshot) {
293
293
  const xip = snapshot.xip_list.map(BigInt);
294
294
  return xid < xmin || xid < xmax && !xip.includes(xid);
295
295
  }
296
- function generateShardId() {
297
- return Math.floor(Math.random() * 1048575).toString(16).padStart(5, `0`);
298
- }
299
- function isLocalhostUrl(url) {
300
- const hostname = url.hostname.toLowerCase();
301
- return hostname === `localhost` || hostname.endsWith(`.localhost`);
302
- }
303
- function applySubdomainSharding(originalUrl, option = `localhost`) {
304
- if (option === `never` || option === false) {
305
- return originalUrl;
306
- }
307
- const url = new URL(originalUrl);
308
- const shouldShard = option === `always` || option === true || option === `localhost` && isLocalhostUrl(url);
309
- if (!shouldShard) {
310
- return originalUrl;
311
- }
312
- const shardId = generateShardId();
313
- url.hostname = `${shardId}.${url.hostname}`;
314
- return url.toString();
315
- }
316
296
 
317
297
  // src/constants.ts
318
298
  var LIVE_CACHE_BUSTER_HEADER = `electric-cursor`;
@@ -331,6 +311,7 @@ var WHERE_QUERY_PARAM = `where`;
331
311
  var REPLICA_PARAM = `replica`;
332
312
  var WHERE_PARAMS_PARAM = `params`;
333
313
  var EXPERIMENTAL_LIVE_SSE_QUERY_PARAM = `experimental_live_sse`;
314
+ var LIVE_SSE_QUERY_PARAM = `live_sse`;
334
315
  var FORCE_DISCONNECT_AND_REFRESH = `force-disconnect-and-refresh`;
335
316
  var PAUSE_STREAM = `pause-stream`;
336
317
  var LOG_MODE_QUERY_PARAM = `log`;
@@ -401,6 +382,7 @@ function createFetchWithBackoff(fetchClient, backoffOptions = BackoffDefaults) {
401
382
  var NO_BODY_STATUS_CODES = [201, 204, 205];
402
383
  function createFetchWithConsumedMessages(fetchClient) {
403
384
  return (...args) => __async(this, null, function* () {
385
+ var _a, _b;
404
386
  const url = args[0];
405
387
  const res = yield fetchClient(...args);
406
388
  try {
@@ -410,6 +392,9 @@ function createFetchWithConsumedMessages(fetchClient) {
410
392
  const text = yield res.text();
411
393
  return new Response(text, res);
412
394
  } catch (err) {
395
+ if ((_b = (_a = args[1]) == null ? void 0 : _a.signal) == null ? void 0 : _b.aborted) {
396
+ throw new FetchBackoffAbortError();
397
+ }
413
398
  throw new FetchError(
414
399
  res.status,
415
400
  void 0,
@@ -799,10 +784,6 @@ var ShapeStream = class {
799
784
  var _a, _b, _c, _d;
800
785
  this.options = __spreadValues({ subscribe: true }, options);
801
786
  validateOptions(this.options);
802
- this.options.url = applySubdomainSharding(
803
- this.options.url,
804
- this.options.shardSubdomain
805
- );
806
787
  __privateSet(this, _lastOffset, (_a = this.options.offset) != null ? _a : `-1`);
807
788
  __privateSet(this, _liveCacheBuster, ``);
808
789
  __privateSet(this, _shapeHandle, this.options.handle);
@@ -1047,7 +1028,7 @@ requestShape_fn = function() {
1047
1028
  }
1048
1029
  const newShapeHandle = e.headers[SHAPE_HANDLE_HEADER] || `${__privateGet(this, _shapeHandle)}-next`;
1049
1030
  __privateMethod(this, _ShapeStream_instances, reset_fn).call(this, newShapeHandle);
1050
- yield __privateMethod(this, _ShapeStream_instances, publish_fn).call(this, e.json);
1031
+ yield __privateMethod(this, _ShapeStream_instances, publish_fn).call(this, Array.isArray(e.json) ? e.json : [e.json]);
1051
1032
  return __privateMethod(this, _ShapeStream_instances, requestShape_fn).call(this);
1052
1033
  } else {
1053
1034
  __privateMethod(this, _ShapeStream_instances, sendErrorToSubscribers_fn).call(this, e);
@@ -1200,8 +1181,11 @@ onMessages_fn = function(batch, isSseMessage = false) {
1200
1181
  };
1201
1182
  fetchShape_fn = function(opts) {
1202
1183
  return __async(this, null, function* () {
1203
- if (__privateGet(this, _isUpToDate) && this.options.experimentalLiveSse && !__privateGet(this, _isRefreshing) && !opts.resumingFromPause) {
1184
+ var _a;
1185
+ const useSse = (_a = this.options.liveSse) != null ? _a : this.options.experimentalLiveSse;
1186
+ if (__privateGet(this, _isUpToDate) && useSse && !__privateGet(this, _isRefreshing) && !opts.resumingFromPause) {
1204
1187
  opts.fetchUrl.searchParams.set(EXPERIMENTAL_LIVE_SSE_QUERY_PARAM, `true`);
1188
+ opts.fetchUrl.searchParams.set(LIVE_SSE_QUERY_PARAM, `true`);
1205
1189
  return __privateMethod(this, _ShapeStream_instances, requestShapeSSE_fn).call(this, opts);
1206
1190
  }
1207
1191
  return __privateMethod(this, _ShapeStream_instances, requestShapeLongPoll_fn).call(this, opts);