@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.
- package/dist/cjs/index.cjs +15 -4
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.legacy-esm.js +15 -4
- package/dist/index.legacy-esm.js.map +1 -1
- package/dist/index.mjs +15 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +25 -2
package/dist/index.mjs
CHANGED
|
@@ -781,9 +781,8 @@ function canonicalShapeKey(url) {
|
|
|
781
781
|
cleanUrl.searchParams.sort();
|
|
782
782
|
return cleanUrl.toString();
|
|
783
783
|
}
|
|
784
|
-
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;
|
|
784
|
+
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;
|
|
785
785
|
var ShapeStream = class {
|
|
786
|
-
// Maximum delay cap (ms)
|
|
787
786
|
constructor(options) {
|
|
788
787
|
__privateAdd(this, _ShapeStream_instances);
|
|
789
788
|
__privateAdd(this, _error, null);
|
|
@@ -827,6 +826,8 @@ var ShapeStream = class {
|
|
|
827
826
|
__privateAdd(this, _sseBackoffBaseDelay, 100);
|
|
828
827
|
// Base delay for exponential backoff (ms)
|
|
829
828
|
__privateAdd(this, _sseBackoffMaxDelay, 5e3);
|
|
829
|
+
// Maximum delay cap (ms)
|
|
830
|
+
__privateAdd(this, _unsubscribeFromVisibilityChanges);
|
|
830
831
|
var _a, _b, _c, _d;
|
|
831
832
|
this.options = __spreadValues({ subscribe: true }, options);
|
|
832
833
|
validateOptions(this.options);
|
|
@@ -882,7 +883,9 @@ var ShapeStream = class {
|
|
|
882
883
|
};
|
|
883
884
|
}
|
|
884
885
|
unsubscribeAll() {
|
|
886
|
+
var _a;
|
|
885
887
|
__privateGet(this, _subscribers).clear();
|
|
888
|
+
(_a = __privateGet(this, _unsubscribeFromVisibilityChanges)) == null ? void 0 : _a.call(this);
|
|
886
889
|
}
|
|
887
890
|
/** Unix time at which we last synced. Undefined when `isLoading` is true. */
|
|
888
891
|
lastSyncedAt() {
|
|
@@ -1009,6 +1012,7 @@ _maxShortSseConnections = new WeakMap();
|
|
|
1009
1012
|
_sseFallbackToLongPolling = new WeakMap();
|
|
1010
1013
|
_sseBackoffBaseDelay = new WeakMap();
|
|
1011
1014
|
_sseBackoffMaxDelay = new WeakMap();
|
|
1015
|
+
_unsubscribeFromVisibilityChanges = new WeakMap();
|
|
1012
1016
|
_ShapeStream_instances = new WeakSet();
|
|
1013
1017
|
start_fn = function() {
|
|
1014
1018
|
return __async(this, null, function* () {
|
|
@@ -1078,7 +1082,8 @@ requestShape_fn = function() {
|
|
|
1078
1082
|
return __privateMethod(this, _ShapeStream_instances, requestShape_fn).call(this);
|
|
1079
1083
|
}
|
|
1080
1084
|
if (e instanceof FetchBackoffAbortError) {
|
|
1081
|
-
|
|
1085
|
+
const currentState = __privateGet(this, _state);
|
|
1086
|
+
if (requestAbortController.signal.aborted && requestAbortController.signal.reason === PAUSE_STREAM && currentState === `pause-requested`) {
|
|
1082
1087
|
__privateSet(this, _state, `paused`);
|
|
1083
1088
|
}
|
|
1084
1089
|
return;
|
|
@@ -1339,7 +1344,10 @@ pause_fn = function() {
|
|
|
1339
1344
|
}
|
|
1340
1345
|
};
|
|
1341
1346
|
resume_fn = function() {
|
|
1342
|
-
if (__privateGet(this, _started) && __privateGet(this, _state) === `paused`) {
|
|
1347
|
+
if (__privateGet(this, _started) && (__privateGet(this, _state) === `paused` || __privateGet(this, _state) === `pause-requested`)) {
|
|
1348
|
+
if (__privateGet(this, _state) === `pause-requested`) {
|
|
1349
|
+
__privateSet(this, _state, `active`);
|
|
1350
|
+
}
|
|
1343
1351
|
__privateMethod(this, _ShapeStream_instances, start_fn).call(this);
|
|
1344
1352
|
}
|
|
1345
1353
|
};
|
|
@@ -1411,6 +1419,9 @@ subscribeToVisibilityChanges_fn = function() {
|
|
|
1411
1419
|
}
|
|
1412
1420
|
};
|
|
1413
1421
|
document.addEventListener(`visibilitychange`, visibilityHandler);
|
|
1422
|
+
__privateSet(this, _unsubscribeFromVisibilityChanges, () => {
|
|
1423
|
+
document.removeEventListener(`visibilitychange`, visibilityHandler);
|
|
1424
|
+
});
|
|
1414
1425
|
}
|
|
1415
1426
|
};
|
|
1416
1427
|
/**
|