@electric-sql/client 1.1.3 → 1.1.4

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.
@@ -751,9 +751,8 @@ function canonicalShapeKey(url) {
751
751
  cleanUrl.searchParams.sort();
752
752
  return cleanUrl.toString();
753
753
  }
754
- var _error, _fetchClient2, _sseFetchClient, _messageParser, _subscribers, _started, _state, _lastOffset, _liveCacheBuster, _lastSyncedAt, _isUpToDate, _isMidStream, _connected, _shapeHandle, _mode, _schema, _onError, _requestAbortController, _isRefreshing, _tickPromise, _tickPromiseResolver, _tickPromiseRejecter, _messageChain, _snapshotTracker, _activeSnapshotRequests, _midStreamPromise, _midStreamPromiseResolver, _lastSseConnectionStartTime, _minSseConnectionDuration, _consecutiveShortSseConnections, _maxShortSseConnections, _sseFallbackToLongPolling, _sseBackoffBaseDelay, _sseBackoffMaxDelay, _ShapeStream_instances, start_fn, requestShape_fn, constructUrl_fn, createAbortListener_fn, onInitialResponse_fn, onMessages_fn, fetchShape_fn, requestShapeLongPoll_fn, requestShapeSSE_fn, pause_fn, resume_fn, nextTick_fn, waitForStreamEnd_fn, publish_fn, sendErrorToSubscribers_fn, subscribeToVisibilityChanges_fn, reset_fn, fetchSnapshot_fn;
754
+ var _error, _fetchClient2, _sseFetchClient, _messageParser, _subscribers, _started, _state, _lastOffset, _liveCacheBuster, _lastSyncedAt, _isUpToDate, _isMidStream, _connected, _shapeHandle, _mode, _schema, _onError, _requestAbortController, _isRefreshing, _tickPromise, _tickPromiseResolver, _tickPromiseRejecter, _messageChain, _snapshotTracker, _activeSnapshotRequests, _midStreamPromise, _midStreamPromiseResolver, _lastSseConnectionStartTime, _minSseConnectionDuration, _consecutiveShortSseConnections, _maxShortSseConnections, _sseFallbackToLongPolling, _sseBackoffBaseDelay, _sseBackoffMaxDelay, _unsubscribeFromVisibilityChanges, _ShapeStream_instances, start_fn, requestShape_fn, constructUrl_fn, createAbortListener_fn, onInitialResponse_fn, onMessages_fn, fetchShape_fn, requestShapeLongPoll_fn, requestShapeSSE_fn, pause_fn, resume_fn, nextTick_fn, waitForStreamEnd_fn, publish_fn, sendErrorToSubscribers_fn, subscribeToVisibilityChanges_fn, reset_fn, fetchSnapshot_fn;
755
755
  var ShapeStream = class {
756
- // Maximum delay cap (ms)
757
756
  constructor(options) {
758
757
  __privateAdd(this, _ShapeStream_instances);
759
758
  __privateAdd(this, _error, null);
@@ -797,6 +796,8 @@ var ShapeStream = class {
797
796
  __privateAdd(this, _sseBackoffBaseDelay, 100);
798
797
  // Base delay for exponential backoff (ms)
799
798
  __privateAdd(this, _sseBackoffMaxDelay, 5e3);
799
+ // Maximum delay cap (ms)
800
+ __privateAdd(this, _unsubscribeFromVisibilityChanges);
800
801
  var _a, _b, _c, _d;
801
802
  this.options = __spreadValues({ subscribe: true }, options);
802
803
  validateOptions(this.options);
@@ -852,7 +853,9 @@ var ShapeStream = class {
852
853
  };
853
854
  }
854
855
  unsubscribeAll() {
856
+ var _a;
855
857
  __privateGet(this, _subscribers).clear();
858
+ (_a = __privateGet(this, _unsubscribeFromVisibilityChanges)) == null ? void 0 : _a.call(this);
856
859
  }
857
860
  /** Unix time at which we last synced. Undefined when `isLoading` is true. */
858
861
  lastSyncedAt() {
@@ -975,6 +978,7 @@ _maxShortSseConnections = new WeakMap();
975
978
  _sseFallbackToLongPolling = new WeakMap();
976
979
  _sseBackoffBaseDelay = new WeakMap();
977
980
  _sseBackoffMaxDelay = new WeakMap();
981
+ _unsubscribeFromVisibilityChanges = new WeakMap();
978
982
  _ShapeStream_instances = new WeakSet();
979
983
  start_fn = async function() {
980
984
  var _a, _b, _c, _d, _e;
@@ -1041,7 +1045,8 @@ requestShape_fn = async function() {
1041
1045
  return __privateMethod(this, _ShapeStream_instances, requestShape_fn).call(this);
1042
1046
  }
1043
1047
  if (e instanceof FetchBackoffAbortError) {
1044
- if (requestAbortController.signal.aborted && requestAbortController.signal.reason === PAUSE_STREAM) {
1048
+ const currentState = __privateGet(this, _state);
1049
+ if (requestAbortController.signal.aborted && requestAbortController.signal.reason === PAUSE_STREAM && currentState === `pause-requested`) {
1045
1050
  __privateSet(this, _state, `paused`);
1046
1051
  }
1047
1052
  return;
@@ -1287,7 +1292,10 @@ pause_fn = function() {
1287
1292
  }
1288
1293
  };
1289
1294
  resume_fn = function() {
1290
- if (__privateGet(this, _started) && __privateGet(this, _state) === `paused`) {
1295
+ if (__privateGet(this, _started) && (__privateGet(this, _state) === `paused` || __privateGet(this, _state) === `pause-requested`)) {
1296
+ if (__privateGet(this, _state) === `pause-requested`) {
1297
+ __privateSet(this, _state, `active`);
1298
+ }
1291
1299
  __privateMethod(this, _ShapeStream_instances, start_fn).call(this);
1292
1300
  }
1293
1301
  };
@@ -1353,6 +1361,9 @@ subscribeToVisibilityChanges_fn = function() {
1353
1361
  }
1354
1362
  };
1355
1363
  document.addEventListener(`visibilitychange`, visibilityHandler);
1364
+ __privateSet(this, _unsubscribeFromVisibilityChanges, () => {
1365
+ document.removeEventListener(`visibilitychange`, visibilityHandler);
1366
+ });
1356
1367
  }
1357
1368
  };
1358
1369
  /**