@electric-sql/client 1.5.10 → 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 +31 -6
- 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 +31 -6
- package/dist/index.legacy-esm.js.map +1 -1
- package/dist/index.mjs +31 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +39 -13
package/dist/index.mjs
CHANGED
|
@@ -1903,6 +1903,9 @@ var RESERVED_PARAMS = /* @__PURE__ */ new Set([
|
|
|
1903
1903
|
CACHE_BUSTER_QUERY_PARAM
|
|
1904
1904
|
]);
|
|
1905
1905
|
var TROUBLESHOOTING_URL = `https://electric-sql.com/docs/guides/troubleshooting`;
|
|
1906
|
+
function createCacheBuster() {
|
|
1907
|
+
return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
1908
|
+
}
|
|
1906
1909
|
async function resolveValue(value) {
|
|
1907
1910
|
if (typeof value === `function`) {
|
|
1908
1911
|
return value();
|
|
@@ -1943,7 +1946,7 @@ function canonicalShapeKey(url) {
|
|
|
1943
1946
|
cleanUrl.searchParams.sort();
|
|
1944
1947
|
return cleanUrl.toString();
|
|
1945
1948
|
}
|
|
1946
|
-
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;
|
|
1949
|
+
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;
|
|
1947
1950
|
var ShapeStream = class {
|
|
1948
1951
|
constructor(options) {
|
|
1949
1952
|
__privateAdd(this, _ShapeStream_instances);
|
|
@@ -1990,6 +1993,7 @@ var ShapeStream = class {
|
|
|
1990
1993
|
__privateAdd(this, _fastLoopBackoffMaxMs, 5e3);
|
|
1991
1994
|
__privateAdd(this, _fastLoopConsecutiveCount, 0);
|
|
1992
1995
|
__privateAdd(this, _fastLoopMaxCount, 5);
|
|
1996
|
+
__privateAdd(this, _refetchCacheBuster);
|
|
1993
1997
|
var _a, _b, _c, _d;
|
|
1994
1998
|
this.options = __spreadValues({ subscribe: true }, options);
|
|
1995
1999
|
validateOptions(this.options);
|
|
@@ -2170,7 +2174,7 @@ var ShapeStream = class {
|
|
|
2170
2174
|
expiredHandle: null,
|
|
2171
2175
|
now: Date.now(),
|
|
2172
2176
|
maxStaleCacheRetries: __privateGet(this, _maxStaleCacheRetries),
|
|
2173
|
-
createCacheBuster
|
|
2177
|
+
createCacheBuster
|
|
2174
2178
|
});
|
|
2175
2179
|
if (transition.action === `accepted`) {
|
|
2176
2180
|
__privateSet(this, _syncState, transition.state);
|
|
@@ -2231,8 +2235,15 @@ var ShapeStream = class {
|
|
|
2231
2235
|
const shapeKey = canonicalShapeKey(fetchUrl);
|
|
2232
2236
|
expiredShapesCache.markExpired(shapeKey, usedHandle);
|
|
2233
2237
|
}
|
|
2234
|
-
const nextHandle = e.headers[SHAPE_HANDLE_HEADER]
|
|
2235
|
-
|
|
2238
|
+
const nextHandle = e.headers[SHAPE_HANDLE_HEADER];
|
|
2239
|
+
if (nextHandle) {
|
|
2240
|
+
__privateSet(this, _syncState, __privateGet(this, _syncState).withHandle(nextHandle));
|
|
2241
|
+
} else {
|
|
2242
|
+
console.warn(
|
|
2243
|
+
`[Electric] Received 409 response without a shape handle header. This likely indicates a proxy or CDN stripping required headers.`
|
|
2244
|
+
);
|
|
2245
|
+
__privateSet(this, _refetchCacheBuster, createCacheBuster());
|
|
2246
|
+
}
|
|
2236
2247
|
return this.fetchSnapshot(opts);
|
|
2237
2248
|
}
|
|
2238
2249
|
throw e;
|
|
@@ -2293,6 +2304,7 @@ _fastLoopBackoffBaseMs = new WeakMap();
|
|
|
2293
2304
|
_fastLoopBackoffMaxMs = new WeakMap();
|
|
2294
2305
|
_fastLoopConsecutiveCount = new WeakMap();
|
|
2295
2306
|
_fastLoopMaxCount = new WeakMap();
|
|
2307
|
+
_refetchCacheBuster = new WeakMap();
|
|
2296
2308
|
start_fn = async function() {
|
|
2297
2309
|
var _a, _b;
|
|
2298
2310
|
__privateSet(this, _started, true);
|
|
@@ -2397,7 +2409,13 @@ requestShape_fn = async function() {
|
|
|
2397
2409
|
const shapeKey = canonicalShapeKey(fetchUrl);
|
|
2398
2410
|
expiredShapesCache.markExpired(shapeKey, __privateGet(this, _syncState).handle);
|
|
2399
2411
|
}
|
|
2400
|
-
const newShapeHandle = e.headers[SHAPE_HANDLE_HEADER]
|
|
2412
|
+
const newShapeHandle = e.headers[SHAPE_HANDLE_HEADER];
|
|
2413
|
+
if (!newShapeHandle) {
|
|
2414
|
+
console.warn(
|
|
2415
|
+
`[Electric] Received 409 response without a shape handle header. This likely indicates a proxy or CDN stripping required headers.`
|
|
2416
|
+
);
|
|
2417
|
+
__privateSet(this, _refetchCacheBuster, createCacheBuster());
|
|
2418
|
+
}
|
|
2401
2419
|
__privateMethod(this, _ShapeStream_instances, reset_fn).call(this, newShapeHandle);
|
|
2402
2420
|
const messages409 = Array.isArray(e.json) ? e.json : e.json != null ? [e.json] : [];
|
|
2403
2421
|
await __privateMethod(this, _ShapeStream_instances, publish_fn).call(this, messages409);
|
|
@@ -2566,6 +2584,13 @@ constructUrl_fn = async function(url, resumingFromPause, subsetParams) {
|
|
|
2566
2584
|
if (expiredHandle) {
|
|
2567
2585
|
fetchUrl.searchParams.set(EXPIRED_HANDLE_QUERY_PARAM, expiredHandle);
|
|
2568
2586
|
}
|
|
2587
|
+
if (__privateGet(this, _refetchCacheBuster)) {
|
|
2588
|
+
fetchUrl.searchParams.set(
|
|
2589
|
+
CACHE_BUSTER_QUERY_PARAM,
|
|
2590
|
+
__privateGet(this, _refetchCacheBuster)
|
|
2591
|
+
);
|
|
2592
|
+
__privateSet(this, _refetchCacheBuster, void 0);
|
|
2593
|
+
}
|
|
2569
2594
|
fetchUrl.searchParams.sort();
|
|
2570
2595
|
return {
|
|
2571
2596
|
fetchUrl,
|
|
@@ -2602,7 +2627,7 @@ onInitialResponse_fn = async function(response) {
|
|
|
2602
2627
|
expiredHandle,
|
|
2603
2628
|
now: Date.now(),
|
|
2604
2629
|
maxStaleCacheRetries: __privateGet(this, _maxStaleCacheRetries),
|
|
2605
|
-
createCacheBuster
|
|
2630
|
+
createCacheBuster
|
|
2606
2631
|
});
|
|
2607
2632
|
__privateSet(this, _syncState, transition.state);
|
|
2608
2633
|
if (transition.action === `stale-retry`) {
|