@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.
@@ -810,9 +810,8 @@ function canonicalShapeKey(url) {
810
810
  cleanUrl.searchParams.sort();
811
811
  return cleanUrl.toString();
812
812
  }
813
- 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;
813
+ 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;
814
814
  var ShapeStream = class {
815
- // Maximum delay cap (ms)
816
815
  constructor(options) {
817
816
  __privateAdd(this, _ShapeStream_instances);
818
817
  __privateAdd(this, _error, null);
@@ -856,6 +855,8 @@ var ShapeStream = class {
856
855
  __privateAdd(this, _sseBackoffBaseDelay, 100);
857
856
  // Base delay for exponential backoff (ms)
858
857
  __privateAdd(this, _sseBackoffMaxDelay, 5e3);
858
+ // Maximum delay cap (ms)
859
+ __privateAdd(this, _unsubscribeFromVisibilityChanges);
859
860
  var _a, _b, _c, _d;
860
861
  this.options = __spreadValues({ subscribe: true }, options);
861
862
  validateOptions(this.options);
@@ -911,7 +912,9 @@ var ShapeStream = class {
911
912
  };
912
913
  }
913
914
  unsubscribeAll() {
915
+ var _a;
914
916
  __privateGet(this, _subscribers).clear();
917
+ (_a = __privateGet(this, _unsubscribeFromVisibilityChanges)) == null ? void 0 : _a.call(this);
915
918
  }
916
919
  /** Unix time at which we last synced. Undefined when `isLoading` is true. */
917
920
  lastSyncedAt() {
@@ -1038,6 +1041,7 @@ _maxShortSseConnections = new WeakMap();
1038
1041
  _sseFallbackToLongPolling = new WeakMap();
1039
1042
  _sseBackoffBaseDelay = new WeakMap();
1040
1043
  _sseBackoffMaxDelay = new WeakMap();
1044
+ _unsubscribeFromVisibilityChanges = new WeakMap();
1041
1045
  _ShapeStream_instances = new WeakSet();
1042
1046
  start_fn = function() {
1043
1047
  return __async(this, null, function* () {
@@ -1107,7 +1111,8 @@ requestShape_fn = function() {
1107
1111
  return __privateMethod(this, _ShapeStream_instances, requestShape_fn).call(this);
1108
1112
  }
1109
1113
  if (e instanceof FetchBackoffAbortError) {
1110
- if (requestAbortController.signal.aborted && requestAbortController.signal.reason === PAUSE_STREAM) {
1114
+ const currentState = __privateGet(this, _state);
1115
+ if (requestAbortController.signal.aborted && requestAbortController.signal.reason === PAUSE_STREAM && currentState === `pause-requested`) {
1111
1116
  __privateSet(this, _state, `paused`);
1112
1117
  }
1113
1118
  return;
@@ -1368,7 +1373,10 @@ pause_fn = function() {
1368
1373
  }
1369
1374
  };
1370
1375
  resume_fn = function() {
1371
- if (__privateGet(this, _started) && __privateGet(this, _state) === `paused`) {
1376
+ if (__privateGet(this, _started) && (__privateGet(this, _state) === `paused` || __privateGet(this, _state) === `pause-requested`)) {
1377
+ if (__privateGet(this, _state) === `pause-requested`) {
1378
+ __privateSet(this, _state, `active`);
1379
+ }
1372
1380
  __privateMethod(this, _ShapeStream_instances, start_fn).call(this);
1373
1381
  }
1374
1382
  };
@@ -1440,6 +1448,9 @@ subscribeToVisibilityChanges_fn = function() {
1440
1448
  }
1441
1449
  };
1442
1450
  document.addEventListener(`visibilitychange`, visibilityHandler);
1451
+ __privateSet(this, _unsubscribeFromVisibilityChanges, () => {
1452
+ document.removeEventListener(`visibilitychange`, visibilityHandler);
1453
+ });
1443
1454
  }
1444
1455
  };
1445
1456
  /**