@electric-sql/client 1.5.9 → 1.5.11
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 +62 -9
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.browser.mjs +4 -4
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.legacy-esm.js +62 -9
- package/dist/index.legacy-esm.js.map +1 -1
- package/dist/index.mjs +62 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +39 -13
- package/src/shape-stream-state.ts +72 -35
package/dist/cjs/index.cjs
CHANGED
|
@@ -1719,7 +1719,7 @@ var PausedState = class _PausedState extends ShapeStreamState {
|
|
|
1719
1719
|
constructor(previousState) {
|
|
1720
1720
|
super();
|
|
1721
1721
|
this.kind = `paused`;
|
|
1722
|
-
this.previousState = previousState;
|
|
1722
|
+
this.previousState = previousState instanceof _PausedState ? previousState.previousState : previousState;
|
|
1723
1723
|
}
|
|
1724
1724
|
get handle() {
|
|
1725
1725
|
return this.previousState.handle;
|
|
@@ -1759,7 +1759,20 @@ var PausedState = class _PausedState extends ShapeStreamState {
|
|
|
1759
1759
|
if (transition.action === `accepted`) {
|
|
1760
1760
|
return { action: `accepted`, state: new _PausedState(transition.state) };
|
|
1761
1761
|
}
|
|
1762
|
-
|
|
1762
|
+
if (transition.action === `ignored`) {
|
|
1763
|
+
return { action: `ignored`, state: this };
|
|
1764
|
+
}
|
|
1765
|
+
if (transition.action === `stale-retry`) {
|
|
1766
|
+
return {
|
|
1767
|
+
action: `stale-retry`,
|
|
1768
|
+
state: new _PausedState(transition.state),
|
|
1769
|
+
exceededMaxRetries: transition.exceededMaxRetries
|
|
1770
|
+
};
|
|
1771
|
+
}
|
|
1772
|
+
const _exhaustive = transition;
|
|
1773
|
+
throw new Error(
|
|
1774
|
+
`PausedState.handleResponseMetadata: unhandled transition action "${_exhaustive.action}"`
|
|
1775
|
+
);
|
|
1763
1776
|
}
|
|
1764
1777
|
withHandle(handle) {
|
|
1765
1778
|
return new _PausedState(this.previousState.withHandle(handle));
|
|
@@ -1778,7 +1791,7 @@ var ErrorState = class _ErrorState extends ShapeStreamState {
|
|
|
1778
1791
|
constructor(previousState, error) {
|
|
1779
1792
|
super();
|
|
1780
1793
|
this.kind = `error`;
|
|
1781
|
-
this.previousState = previousState;
|
|
1794
|
+
this.previousState = previousState instanceof _ErrorState ? previousState.previousState : previousState;
|
|
1782
1795
|
this.error = error;
|
|
1783
1796
|
}
|
|
1784
1797
|
get handle() {
|
|
@@ -1799,6 +1812,21 @@ var ErrorState = class _ErrorState extends ShapeStreamState {
|
|
|
1799
1812
|
get isUpToDate() {
|
|
1800
1813
|
return this.previousState.isUpToDate;
|
|
1801
1814
|
}
|
|
1815
|
+
get staleCacheBuster() {
|
|
1816
|
+
return this.previousState.staleCacheBuster;
|
|
1817
|
+
}
|
|
1818
|
+
get staleCacheRetryCount() {
|
|
1819
|
+
return this.previousState.staleCacheRetryCount;
|
|
1820
|
+
}
|
|
1821
|
+
get sseFallbackToLongPolling() {
|
|
1822
|
+
return this.previousState.sseFallbackToLongPolling;
|
|
1823
|
+
}
|
|
1824
|
+
get consecutiveShortSseConnections() {
|
|
1825
|
+
return this.previousState.consecutiveShortSseConnections;
|
|
1826
|
+
}
|
|
1827
|
+
get replayCursor() {
|
|
1828
|
+
return this.previousState.replayCursor;
|
|
1829
|
+
}
|
|
1802
1830
|
withHandle(handle) {
|
|
1803
1831
|
return new _ErrorState(this.previousState.withHandle(handle), this.error);
|
|
1804
1832
|
}
|
|
@@ -1912,6 +1940,9 @@ var RESERVED_PARAMS = /* @__PURE__ */ new Set([
|
|
|
1912
1940
|
CACHE_BUSTER_QUERY_PARAM
|
|
1913
1941
|
]);
|
|
1914
1942
|
var TROUBLESHOOTING_URL = `https://electric-sql.com/docs/guides/troubleshooting`;
|
|
1943
|
+
function createCacheBuster() {
|
|
1944
|
+
return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
1945
|
+
}
|
|
1915
1946
|
async function resolveValue(value) {
|
|
1916
1947
|
if (typeof value === `function`) {
|
|
1917
1948
|
return value();
|
|
@@ -1952,7 +1983,7 @@ function canonicalShapeKey(url) {
|
|
|
1952
1983
|
cleanUrl.searchParams.sort();
|
|
1953
1984
|
return cleanUrl.toString();
|
|
1954
1985
|
}
|
|
1955
|
-
var _error, _fetchClient2, _sseFetchClient, _messageParser, _subscribers, _started, _syncState, _connected, _mode, _onError, _requestAbortController, _refreshCount, _snapshotCounter, _ShapeStream_instances, isRefreshing_get, _tickPromise, _tickPromiseResolver, _tickPromiseRejecter, _messageChain, _snapshotTracker, _pauseLock, _currentFetchUrl, _lastSseConnectionStartTime, _minSseConnectionDuration, _maxShortSseConnections, _sseBackoffBaseDelay, _sseBackoffMaxDelay, _unsubscribeFromVisibilityChanges, _unsubscribeFromWakeDetection, _maxStaleCacheRetries, _recentRequestEntries, _fastLoopWindowMs, _fastLoopThreshold, _fastLoopBackoffBaseMs, _fastLoopBackoffMaxMs, _fastLoopConsecutiveCount, _fastLoopMaxCount, start_fn, teardown_fn, requestShape_fn, checkFastLoop_fn, constructUrl_fn, createAbortListener_fn, onInitialResponse_fn, onMessages_fn, fetchShape_fn, requestShapeLongPoll_fn, requestShapeSSE_fn, nextTick_fn, publish_fn, sendErrorToSubscribers_fn, hasBrowserVisibilityAPI_fn, subscribeToVisibilityChanges_fn, subscribeToWakeDetection_fn, reset_fn, buildSubsetBody_fn;
|
|
1986
|
+
var _error, _fetchClient2, _sseFetchClient, _messageParser, _subscribers, _started, _syncState, _connected, _mode, _onError, _requestAbortController, _refreshCount, _snapshotCounter, _ShapeStream_instances, isRefreshing_get, _tickPromise, _tickPromiseResolver, _tickPromiseRejecter, _messageChain, _snapshotTracker, _pauseLock, _currentFetchUrl, _lastSseConnectionStartTime, _minSseConnectionDuration, _maxShortSseConnections, _sseBackoffBaseDelay, _sseBackoffMaxDelay, _unsubscribeFromVisibilityChanges, _unsubscribeFromWakeDetection, _maxStaleCacheRetries, _recentRequestEntries, _fastLoopWindowMs, _fastLoopThreshold, _fastLoopBackoffBaseMs, _fastLoopBackoffMaxMs, _fastLoopConsecutiveCount, _fastLoopMaxCount, _refetchCacheBuster, start_fn, teardown_fn, requestShape_fn, checkFastLoop_fn, constructUrl_fn, createAbortListener_fn, onInitialResponse_fn, onMessages_fn, fetchShape_fn, requestShapeLongPoll_fn, requestShapeSSE_fn, nextTick_fn, publish_fn, sendErrorToSubscribers_fn, hasBrowserVisibilityAPI_fn, subscribeToVisibilityChanges_fn, subscribeToWakeDetection_fn, reset_fn, buildSubsetBody_fn;
|
|
1956
1987
|
var ShapeStream = class {
|
|
1957
1988
|
constructor(options) {
|
|
1958
1989
|
__privateAdd(this, _ShapeStream_instances);
|
|
@@ -1999,6 +2030,7 @@ var ShapeStream = class {
|
|
|
1999
2030
|
__privateAdd(this, _fastLoopBackoffMaxMs, 5e3);
|
|
2000
2031
|
__privateAdd(this, _fastLoopConsecutiveCount, 0);
|
|
2001
2032
|
__privateAdd(this, _fastLoopMaxCount, 5);
|
|
2033
|
+
__privateAdd(this, _refetchCacheBuster);
|
|
2002
2034
|
var _a, _b, _c, _d;
|
|
2003
2035
|
this.options = __spreadValues({ subscribe: true }, options);
|
|
2004
2036
|
validateOptions(this.options);
|
|
@@ -2179,7 +2211,7 @@ var ShapeStream = class {
|
|
|
2179
2211
|
expiredHandle: null,
|
|
2180
2212
|
now: Date.now(),
|
|
2181
2213
|
maxStaleCacheRetries: __privateGet(this, _maxStaleCacheRetries),
|
|
2182
|
-
createCacheBuster
|
|
2214
|
+
createCacheBuster
|
|
2183
2215
|
});
|
|
2184
2216
|
if (transition.action === `accepted`) {
|
|
2185
2217
|
__privateSet(this, _syncState, transition.state);
|
|
@@ -2240,8 +2272,15 @@ var ShapeStream = class {
|
|
|
2240
2272
|
const shapeKey = canonicalShapeKey(fetchUrl);
|
|
2241
2273
|
expiredShapesCache.markExpired(shapeKey, usedHandle);
|
|
2242
2274
|
}
|
|
2243
|
-
const nextHandle = e.headers[SHAPE_HANDLE_HEADER]
|
|
2244
|
-
|
|
2275
|
+
const nextHandle = e.headers[SHAPE_HANDLE_HEADER];
|
|
2276
|
+
if (nextHandle) {
|
|
2277
|
+
__privateSet(this, _syncState, __privateGet(this, _syncState).withHandle(nextHandle));
|
|
2278
|
+
} else {
|
|
2279
|
+
console.warn(
|
|
2280
|
+
`[Electric] Received 409 response without a shape handle header. This likely indicates a proxy or CDN stripping required headers.`
|
|
2281
|
+
);
|
|
2282
|
+
__privateSet(this, _refetchCacheBuster, createCacheBuster());
|
|
2283
|
+
}
|
|
2245
2284
|
return this.fetchSnapshot(opts);
|
|
2246
2285
|
}
|
|
2247
2286
|
throw e;
|
|
@@ -2302,6 +2341,7 @@ _fastLoopBackoffBaseMs = new WeakMap();
|
|
|
2302
2341
|
_fastLoopBackoffMaxMs = new WeakMap();
|
|
2303
2342
|
_fastLoopConsecutiveCount = new WeakMap();
|
|
2304
2343
|
_fastLoopMaxCount = new WeakMap();
|
|
2344
|
+
_refetchCacheBuster = new WeakMap();
|
|
2305
2345
|
start_fn = async function() {
|
|
2306
2346
|
var _a, _b;
|
|
2307
2347
|
__privateSet(this, _started, true);
|
|
@@ -2406,7 +2446,13 @@ requestShape_fn = async function() {
|
|
|
2406
2446
|
const shapeKey = canonicalShapeKey(fetchUrl);
|
|
2407
2447
|
expiredShapesCache.markExpired(shapeKey, __privateGet(this, _syncState).handle);
|
|
2408
2448
|
}
|
|
2409
|
-
const newShapeHandle = e.headers[SHAPE_HANDLE_HEADER]
|
|
2449
|
+
const newShapeHandle = e.headers[SHAPE_HANDLE_HEADER];
|
|
2450
|
+
if (!newShapeHandle) {
|
|
2451
|
+
console.warn(
|
|
2452
|
+
`[Electric] Received 409 response without a shape handle header. This likely indicates a proxy or CDN stripping required headers.`
|
|
2453
|
+
);
|
|
2454
|
+
__privateSet(this, _refetchCacheBuster, createCacheBuster());
|
|
2455
|
+
}
|
|
2410
2456
|
__privateMethod(this, _ShapeStream_instances, reset_fn).call(this, newShapeHandle);
|
|
2411
2457
|
const messages409 = Array.isArray(e.json) ? e.json : e.json != null ? [e.json] : [];
|
|
2412
2458
|
await __privateMethod(this, _ShapeStream_instances, publish_fn).call(this, messages409);
|
|
@@ -2575,6 +2621,13 @@ constructUrl_fn = async function(url, resumingFromPause, subsetParams) {
|
|
|
2575
2621
|
if (expiredHandle) {
|
|
2576
2622
|
fetchUrl.searchParams.set(EXPIRED_HANDLE_QUERY_PARAM, expiredHandle);
|
|
2577
2623
|
}
|
|
2624
|
+
if (__privateGet(this, _refetchCacheBuster)) {
|
|
2625
|
+
fetchUrl.searchParams.set(
|
|
2626
|
+
CACHE_BUSTER_QUERY_PARAM,
|
|
2627
|
+
__privateGet(this, _refetchCacheBuster)
|
|
2628
|
+
);
|
|
2629
|
+
__privateSet(this, _refetchCacheBuster, void 0);
|
|
2630
|
+
}
|
|
2578
2631
|
fetchUrl.searchParams.sort();
|
|
2579
2632
|
return {
|
|
2580
2633
|
fetchUrl,
|
|
@@ -2611,7 +2664,7 @@ onInitialResponse_fn = async function(response) {
|
|
|
2611
2664
|
expiredHandle,
|
|
2612
2665
|
now: Date.now(),
|
|
2613
2666
|
maxStaleCacheRetries: __privateGet(this, _maxStaleCacheRetries),
|
|
2614
|
-
createCacheBuster
|
|
2667
|
+
createCacheBuster
|
|
2615
2668
|
});
|
|
2616
2669
|
__privateSet(this, _syncState, transition.state);
|
|
2617
2670
|
if (transition.action === `stale-retry`) {
|