@electric-sql/client 1.2.2 → 1.3.1
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 +533 -575
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +10 -8
- package/dist/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.d.ts +10 -8
- package/dist/index.legacy-esm.js +33 -9
- package/dist/index.legacy-esm.js.map +1 -1
- package/dist/index.mjs +533 -575
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +29 -10
- package/src/fetch.ts +30 -3
- package/src/helpers.ts +2 -4
- package/src/types.ts +9 -0
package/dist/index.mjs
CHANGED
|
@@ -45,26 +45,6 @@ var __privateWrapper = (obj, member, setter, getter) => ({
|
|
|
45
45
|
return __privateGet(obj, member, getter);
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
|
-
var __async = (__this, __arguments, generator) => {
|
|
49
|
-
return new Promise((resolve, reject) => {
|
|
50
|
-
var fulfilled = (value) => {
|
|
51
|
-
try {
|
|
52
|
-
step(generator.next(value));
|
|
53
|
-
} catch (e) {
|
|
54
|
-
reject(e);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
var rejected = (value) => {
|
|
58
|
-
try {
|
|
59
|
-
step(generator.throw(value));
|
|
60
|
-
} catch (e) {
|
|
61
|
-
reject(e);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
65
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
48
|
|
|
69
49
|
// src/error.ts
|
|
70
50
|
var FetchError = class _FetchError extends Error {
|
|
@@ -79,22 +59,20 @@ var FetchError = class _FetchError extends Error {
|
|
|
79
59
|
this.json = json;
|
|
80
60
|
this.headers = headers;
|
|
81
61
|
}
|
|
82
|
-
static fromResponse(response, url) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
text = yield response.text();
|
|
94
|
-
}
|
|
62
|
+
static async fromResponse(response, url) {
|
|
63
|
+
const status = response.status;
|
|
64
|
+
const headers = Object.fromEntries([...response.headers.entries()]);
|
|
65
|
+
let text = void 0;
|
|
66
|
+
let json = void 0;
|
|
67
|
+
const contentType = response.headers.get(`content-type`);
|
|
68
|
+
if (!response.bodyUsed) {
|
|
69
|
+
if (contentType && contentType.includes(`application/json`)) {
|
|
70
|
+
json = await response.json();
|
|
71
|
+
} else {
|
|
72
|
+
text = await response.text();
|
|
95
73
|
}
|
|
96
|
-
|
|
97
|
-
|
|
74
|
+
}
|
|
75
|
+
return new _FetchError(status, text, json, headers, url);
|
|
98
76
|
}
|
|
99
77
|
};
|
|
100
78
|
var FetchBackoffAbortError = class extends Error {
|
|
@@ -451,11 +429,9 @@ function isUpToDateMessage(message) {
|
|
|
451
429
|
return isControlMessage(message) && message.headers.control === `up-to-date`;
|
|
452
430
|
}
|
|
453
431
|
function getOffset(message) {
|
|
432
|
+
if (message.headers.control != `up-to-date`) return;
|
|
454
433
|
const lsn = message.headers.global_last_seen_lsn;
|
|
455
|
-
|
|
456
|
-
return;
|
|
457
|
-
}
|
|
458
|
-
return `${lsn}_0`;
|
|
434
|
+
return lsn ? `${lsn}_0` : void 0;
|
|
459
435
|
}
|
|
460
436
|
function isVisibleInSnapshot(txid, snapshot) {
|
|
461
437
|
const xid = BigInt(txid);
|
|
@@ -538,7 +514,7 @@ function createFetchWithBackoff(fetchClient, backoffOptions = BackoffDefaults) {
|
|
|
538
514
|
onFailedAttempt,
|
|
539
515
|
maxRetries = Infinity
|
|
540
516
|
} = backoffOptions;
|
|
541
|
-
return (...args) =>
|
|
517
|
+
return async (...args) => {
|
|
542
518
|
var _a;
|
|
543
519
|
const url = args[0];
|
|
544
520
|
const options = args[1];
|
|
@@ -546,11 +522,11 @@ function createFetchWithBackoff(fetchClient, backoffOptions = BackoffDefaults) {
|
|
|
546
522
|
let attempt = 0;
|
|
547
523
|
while (true) {
|
|
548
524
|
try {
|
|
549
|
-
const result =
|
|
525
|
+
const result = await fetchClient(...args);
|
|
550
526
|
if (result.ok) {
|
|
551
527
|
return result;
|
|
552
528
|
}
|
|
553
|
-
const err =
|
|
529
|
+
const err = await FetchError.fromResponse(result, url.toString());
|
|
554
530
|
throw err;
|
|
555
531
|
} catch (e) {
|
|
556
532
|
onFailedAttempt == null ? void 0 : onFailedAttempt();
|
|
@@ -578,24 +554,24 @@ function createFetchWithBackoff(fetchClient, backoffOptions = BackoffDefaults) {
|
|
|
578
554
|
`Retry attempt #${attempt} after ${waitMs}ms (${source}, serverMin=${serverMinimumMs}ms, clientBackoff=${clientBackoffMs}ms)`
|
|
579
555
|
);
|
|
580
556
|
}
|
|
581
|
-
|
|
557
|
+
await new Promise((resolve) => setTimeout(resolve, waitMs));
|
|
582
558
|
delay = Math.min(delay * multiplier, maxDelay);
|
|
583
559
|
}
|
|
584
560
|
}
|
|
585
561
|
}
|
|
586
|
-
}
|
|
562
|
+
};
|
|
587
563
|
}
|
|
588
564
|
var NO_BODY_STATUS_CODES = [201, 204, 205];
|
|
589
565
|
function createFetchWithConsumedMessages(fetchClient) {
|
|
590
|
-
return (...args) =>
|
|
566
|
+
return async (...args) => {
|
|
591
567
|
var _a, _b;
|
|
592
568
|
const url = args[0];
|
|
593
|
-
const res =
|
|
569
|
+
const res = await fetchClient(...args);
|
|
594
570
|
try {
|
|
595
571
|
if (res.status < 200 || NO_BODY_STATUS_CODES.includes(res.status)) {
|
|
596
572
|
return res;
|
|
597
573
|
}
|
|
598
|
-
const text =
|
|
574
|
+
const text = await res.text();
|
|
599
575
|
return new Response(text, res);
|
|
600
576
|
} catch (err) {
|
|
601
577
|
if ((_b = (_a = args[1]) == null ? void 0 : _a.signal) == null ? void 0 : _b.aborted) {
|
|
@@ -610,7 +586,7 @@ function createFetchWithConsumedMessages(fetchClient) {
|
|
|
610
586
|
err instanceof Error ? err.message : typeof err === `string` ? err : `failed to read body`
|
|
611
587
|
);
|
|
612
588
|
}
|
|
613
|
-
}
|
|
589
|
+
};
|
|
614
590
|
}
|
|
615
591
|
var ChunkPrefetchDefaults = {
|
|
616
592
|
maxChunksToPrefetch: 2
|
|
@@ -618,14 +594,15 @@ var ChunkPrefetchDefaults = {
|
|
|
618
594
|
function createFetchWithChunkBuffer(fetchClient, prefetchOptions = ChunkPrefetchDefaults) {
|
|
619
595
|
const { maxChunksToPrefetch } = prefetchOptions;
|
|
620
596
|
let prefetchQueue;
|
|
621
|
-
const prefetchClient = (...args) =>
|
|
597
|
+
const prefetchClient = async (...args) => {
|
|
622
598
|
const url = args[0].toString();
|
|
623
599
|
const prefetchedRequest = prefetchQueue == null ? void 0 : prefetchQueue.consume(...args);
|
|
624
600
|
if (prefetchedRequest) {
|
|
625
601
|
return prefetchedRequest;
|
|
626
602
|
}
|
|
627
603
|
prefetchQueue == null ? void 0 : prefetchQueue.abort();
|
|
628
|
-
|
|
604
|
+
prefetchQueue = void 0;
|
|
605
|
+
const response = await fetchClient(...args);
|
|
629
606
|
const nextUrl = getNextChunkUrl(url, response);
|
|
630
607
|
if (nextUrl) {
|
|
631
608
|
prefetchQueue = new PrefetchQueue({
|
|
@@ -636,7 +613,7 @@ function createFetchWithChunkBuffer(fetchClient, prefetchOptions = ChunkPrefetch
|
|
|
636
613
|
});
|
|
637
614
|
}
|
|
638
615
|
return response;
|
|
639
|
-
}
|
|
616
|
+
};
|
|
640
617
|
return prefetchClient;
|
|
641
618
|
}
|
|
642
619
|
var requiredElectricResponseHeaders = [
|
|
@@ -646,8 +623,8 @@ var requiredElectricResponseHeaders = [
|
|
|
646
623
|
var requiredLiveResponseHeaders = [`electric-cursor`];
|
|
647
624
|
var requiredNonLiveResponseHeaders = [`electric-schema`];
|
|
648
625
|
function createFetchWithResponseHeadersCheck(fetchClient) {
|
|
649
|
-
return (...args) =>
|
|
650
|
-
const response =
|
|
626
|
+
return async (...args) => {
|
|
627
|
+
const response = await fetchClient(...args);
|
|
651
628
|
if (response.ok) {
|
|
652
629
|
const headers = response.headers;
|
|
653
630
|
const missingHeaders = [];
|
|
@@ -677,7 +654,7 @@ function createFetchWithResponseHeadersCheck(fetchClient) {
|
|
|
677
654
|
}
|
|
678
655
|
}
|
|
679
656
|
return response;
|
|
680
|
-
}
|
|
657
|
+
};
|
|
681
658
|
}
|
|
682
659
|
var _fetchClient, _maxPrefetchedRequests, _prefetchQueue, _queueHeadUrl, _queueTailUrl, _PrefetchQueue_instances, prefetch_fn;
|
|
683
660
|
var PrefetchQueue = class {
|
|
@@ -697,12 +674,17 @@ var PrefetchQueue = class {
|
|
|
697
674
|
}
|
|
698
675
|
abort() {
|
|
699
676
|
__privateGet(this, _prefetchQueue).forEach(([_, aborter]) => aborter.abort());
|
|
677
|
+
__privateGet(this, _prefetchQueue).clear();
|
|
700
678
|
}
|
|
701
679
|
consume(...args) {
|
|
702
|
-
var _a;
|
|
703
680
|
const url = args[0].toString();
|
|
704
|
-
const
|
|
705
|
-
if (!
|
|
681
|
+
const entry = __privateGet(this, _prefetchQueue).get(url);
|
|
682
|
+
if (!entry || url !== __privateGet(this, _queueHeadUrl)) return;
|
|
683
|
+
const [request, aborter] = entry;
|
|
684
|
+
if (aborter.signal.aborted) {
|
|
685
|
+
__privateGet(this, _prefetchQueue).delete(url);
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
706
688
|
__privateGet(this, _prefetchQueue).delete(url);
|
|
707
689
|
request.then((response) => {
|
|
708
690
|
const nextUrl = getNextChunkUrl(url, response);
|
|
@@ -751,6 +733,13 @@ function getNextChunkUrl(url, res) {
|
|
|
751
733
|
if (!shapeHandle || !lastOffset || isUpToDate) return;
|
|
752
734
|
const nextUrl = new URL(url);
|
|
753
735
|
if (nextUrl.searchParams.has(LIVE_QUERY_PARAM)) return;
|
|
736
|
+
const expiredHandle = nextUrl.searchParams.get(EXPIRED_HANDLE_QUERY_PARAM);
|
|
737
|
+
if (expiredHandle && shapeHandle === expiredHandle) {
|
|
738
|
+
console.warn(
|
|
739
|
+
`[Electric] Received stale cached response with expired shape handle. This should not happen and indicates a proxy/CDN caching misconfiguration. The response contained handle "${shapeHandle}" which was previously marked as expired. Check that your proxy includes all query parameters (especially 'handle' and 'offset') in its cache key. Skipping prefetch to prevent infinite 409 loop.`
|
|
740
|
+
);
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
754
743
|
nextUrl.searchParams.set(SHAPE_HANDLE_QUERY_PARAM, shapeHandle);
|
|
755
744
|
nextUrl.searchParams.set(OFFSET_QUERY_PARAM, lastOffset);
|
|
756
745
|
nextUrl.searchParams.sort();
|
|
@@ -1025,43 +1014,35 @@ var RESERVED_PARAMS = /* @__PURE__ */ new Set([
|
|
|
1025
1014
|
LIVE_QUERY_PARAM,
|
|
1026
1015
|
OFFSET_QUERY_PARAM
|
|
1027
1016
|
]);
|
|
1028
|
-
function resolveValue(value) {
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
return value;
|
|
1034
|
-
});
|
|
1017
|
+
async function resolveValue(value) {
|
|
1018
|
+
if (typeof value === `function`) {
|
|
1019
|
+
return value();
|
|
1020
|
+
}
|
|
1021
|
+
return value;
|
|
1035
1022
|
}
|
|
1036
|
-
function toInternalParams(params) {
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
);
|
|
1052
|
-
});
|
|
1023
|
+
async function toInternalParams(params) {
|
|
1024
|
+
const entries = Object.entries(params);
|
|
1025
|
+
const resolvedEntries = await Promise.all(
|
|
1026
|
+
entries.map(async ([key, value]) => {
|
|
1027
|
+
if (value === void 0) return [key, void 0];
|
|
1028
|
+
const resolvedValue = await resolveValue(value);
|
|
1029
|
+
return [
|
|
1030
|
+
key,
|
|
1031
|
+
Array.isArray(resolvedValue) ? resolvedValue.join(`,`) : resolvedValue
|
|
1032
|
+
];
|
|
1033
|
+
})
|
|
1034
|
+
);
|
|
1035
|
+
return Object.fromEntries(
|
|
1036
|
+
resolvedEntries.filter(([_, value]) => value !== void 0)
|
|
1037
|
+
);
|
|
1053
1038
|
}
|
|
1054
|
-
function resolveHeaders(headers) {
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
}))
|
|
1062
|
-
);
|
|
1063
|
-
return Object.fromEntries(resolvedEntries);
|
|
1064
|
-
});
|
|
1039
|
+
async function resolveHeaders(headers) {
|
|
1040
|
+
if (!headers) return {};
|
|
1041
|
+
const entries = Object.entries(headers);
|
|
1042
|
+
const resolvedEntries = await Promise.all(
|
|
1043
|
+
entries.map(async ([key, value]) => [key, await resolveValue(value)])
|
|
1044
|
+
);
|
|
1045
|
+
return Object.fromEntries(resolvedEntries);
|
|
1065
1046
|
}
|
|
1066
1047
|
function canonicalShapeKey(url) {
|
|
1067
1048
|
const cleanUrl = new URL(url.origin + url.pathname);
|
|
@@ -1223,16 +1204,14 @@ var ShapeStream = class {
|
|
|
1223
1204
|
* long polling, ensuring that the stream receives an up to date message with the
|
|
1224
1205
|
* latest LSN from Postgres at that point in time.
|
|
1225
1206
|
*/
|
|
1226
|
-
forceDisconnectAndRefresh() {
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
__privateSet(this, _isRefreshing, false);
|
|
1235
|
-
});
|
|
1207
|
+
async forceDisconnectAndRefresh() {
|
|
1208
|
+
var _a, _b;
|
|
1209
|
+
__privateSet(this, _isRefreshing, true);
|
|
1210
|
+
if (__privateGet(this, _isUpToDate) && !((_a = __privateGet(this, _requestAbortController)) == null ? void 0 : _a.signal.aborted)) {
|
|
1211
|
+
(_b = __privateGet(this, _requestAbortController)) == null ? void 0 : _b.abort(FORCE_DISCONNECT_AND_REFRESH);
|
|
1212
|
+
}
|
|
1213
|
+
await __privateMethod(this, _ShapeStream_instances, nextTick_fn).call(this);
|
|
1214
|
+
__privateSet(this, _isRefreshing, false);
|
|
1236
1215
|
}
|
|
1237
1216
|
/**
|
|
1238
1217
|
* Request a snapshot for subset of data and inject it into the subscribed data stream.
|
|
@@ -1248,40 +1227,39 @@ var ShapeStream = class {
|
|
|
1248
1227
|
* @param opts - The options for the snapshot request.
|
|
1249
1228
|
* @returns The metadata and the data for the snapshot.
|
|
1250
1229
|
*/
|
|
1251
|
-
requestSnapshot(opts) {
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1230
|
+
async requestSnapshot(opts) {
|
|
1231
|
+
if (__privateGet(this, _mode) === `full`) {
|
|
1232
|
+
throw new Error(
|
|
1233
|
+
`Snapshot requests are not supported in ${__privateGet(this, _mode)} mode, as the consumer is guaranteed to observe all data`
|
|
1234
|
+
);
|
|
1235
|
+
}
|
|
1236
|
+
if (!__privateGet(this, _started)) await __privateMethod(this, _ShapeStream_instances, start_fn).call(this);
|
|
1237
|
+
await __privateMethod(this, _ShapeStream_instances, waitForStreamEnd_fn).call(this);
|
|
1238
|
+
__privateWrapper(this, _activeSnapshotRequests)._++;
|
|
1239
|
+
try {
|
|
1240
|
+
if (__privateGet(this, _activeSnapshotRequests) === 1) {
|
|
1241
|
+
__privateMethod(this, _ShapeStream_instances, pause_fn).call(this);
|
|
1257
1242
|
}
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
data
|
|
1277
|
-
};
|
|
1278
|
-
} finally {
|
|
1279
|
-
__privateWrapper(this, _activeSnapshotRequests)._--;
|
|
1280
|
-
if (__privateGet(this, _activeSnapshotRequests) === 0) {
|
|
1281
|
-
__privateMethod(this, _ShapeStream_instances, resume_fn).call(this);
|
|
1282
|
-
}
|
|
1243
|
+
const { metadata, data } = await this.fetchSnapshot(opts);
|
|
1244
|
+
const dataWithEndBoundary = data.concat([
|
|
1245
|
+
{ headers: __spreadValues({ control: `snapshot-end` }, metadata) },
|
|
1246
|
+
{ headers: __spreadValues({ control: `subset-end` }, opts) }
|
|
1247
|
+
]);
|
|
1248
|
+
__privateGet(this, _snapshotTracker).addSnapshot(
|
|
1249
|
+
metadata,
|
|
1250
|
+
new Set(data.map((message) => message.key))
|
|
1251
|
+
);
|
|
1252
|
+
__privateMethod(this, _ShapeStream_instances, onMessages_fn).call(this, dataWithEndBoundary, false);
|
|
1253
|
+
return {
|
|
1254
|
+
metadata,
|
|
1255
|
+
data
|
|
1256
|
+
};
|
|
1257
|
+
} finally {
|
|
1258
|
+
__privateWrapper(this, _activeSnapshotRequests)._--;
|
|
1259
|
+
if (__privateGet(this, _activeSnapshotRequests) === 0) {
|
|
1260
|
+
__privateMethod(this, _ShapeStream_instances, resume_fn).call(this);
|
|
1283
1261
|
}
|
|
1284
|
-
}
|
|
1262
|
+
}
|
|
1285
1263
|
}
|
|
1286
1264
|
/**
|
|
1287
1265
|
* Fetch a snapshot for subset of data.
|
|
@@ -1290,36 +1268,34 @@ var ShapeStream = class {
|
|
|
1290
1268
|
* @param opts - The options for the snapshot request.
|
|
1291
1269
|
* @returns The metadata and the data for the snapshot.
|
|
1292
1270
|
*/
|
|
1293
|
-
fetchSnapshot(opts) {
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
fetchUrl.toString()
|
|
1307
|
-
);
|
|
1308
|
-
}
|
|
1309
|
-
const schema = (_a = __privateGet(this, _schema)) != null ? _a : getSchemaFromHeaders(response.headers, {
|
|
1310
|
-
required: true,
|
|
1311
|
-
url: fetchUrl.toString()
|
|
1312
|
-
});
|
|
1313
|
-
const { metadata, data: rawData } = yield response.json();
|
|
1314
|
-
const data = __privateGet(this, _messageParser).parseSnapshotData(
|
|
1315
|
-
rawData,
|
|
1316
|
-
schema
|
|
1271
|
+
async fetchSnapshot(opts) {
|
|
1272
|
+
var _a;
|
|
1273
|
+
const { fetchUrl, requestHeaders } = await __privateMethod(this, _ShapeStream_instances, constructUrl_fn).call(this, this.options.url, true, opts);
|
|
1274
|
+
const response = await __privateGet(this, _fetchClient2).call(this, fetchUrl.toString(), {
|
|
1275
|
+
headers: requestHeaders
|
|
1276
|
+
});
|
|
1277
|
+
if (!response.ok) {
|
|
1278
|
+
throw new FetchError(
|
|
1279
|
+
response.status,
|
|
1280
|
+
void 0,
|
|
1281
|
+
void 0,
|
|
1282
|
+
Object.fromEntries([...response.headers.entries()]),
|
|
1283
|
+
fetchUrl.toString()
|
|
1317
1284
|
);
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1285
|
+
}
|
|
1286
|
+
const schema = (_a = __privateGet(this, _schema)) != null ? _a : getSchemaFromHeaders(response.headers, {
|
|
1287
|
+
required: true,
|
|
1288
|
+
url: fetchUrl.toString()
|
|
1322
1289
|
});
|
|
1290
|
+
const { metadata, data: rawData } = await response.json();
|
|
1291
|
+
const data = __privateGet(this, _messageParser).parseSnapshotData(
|
|
1292
|
+
rawData,
|
|
1293
|
+
schema
|
|
1294
|
+
);
|
|
1295
|
+
return {
|
|
1296
|
+
metadata,
|
|
1297
|
+
data
|
|
1298
|
+
};
|
|
1323
1299
|
}
|
|
1324
1300
|
};
|
|
1325
1301
|
_error = new WeakMap();
|
|
@@ -1363,379 +1339,369 @@ _ShapeStream_instances = new WeakSet();
|
|
|
1363
1339
|
replayMode_get = function() {
|
|
1364
1340
|
return __privateGet(this, _lastSeenCursor) !== void 0;
|
|
1365
1341
|
};
|
|
1366
|
-
start_fn = function() {
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
if (retryOpts
|
|
1377
|
-
|
|
1378
|
-
this.options.params = __spreadValues(__spreadValues({}, (_a = this.options.params) != null ? _a : {}), retryOpts.params);
|
|
1379
|
-
}
|
|
1380
|
-
if (retryOpts.headers) {
|
|
1381
|
-
this.options.headers = __spreadValues(__spreadValues({}, (_b = this.options.headers) != null ? _b : {}), retryOpts.headers);
|
|
1382
|
-
}
|
|
1383
|
-
__privateSet(this, _error, null);
|
|
1384
|
-
__privateSet(this, _started, false);
|
|
1385
|
-
yield __privateMethod(this, _ShapeStream_instances, start_fn).call(this);
|
|
1386
|
-
return;
|
|
1342
|
+
start_fn = async function() {
|
|
1343
|
+
var _a, _b, _c, _d, _e;
|
|
1344
|
+
__privateSet(this, _started, true);
|
|
1345
|
+
try {
|
|
1346
|
+
await __privateMethod(this, _ShapeStream_instances, requestShape_fn).call(this);
|
|
1347
|
+
} catch (err) {
|
|
1348
|
+
__privateSet(this, _error, err);
|
|
1349
|
+
if (__privateGet(this, _onError)) {
|
|
1350
|
+
const retryOpts = await __privateGet(this, _onError).call(this, err);
|
|
1351
|
+
if (retryOpts && typeof retryOpts === `object`) {
|
|
1352
|
+
if (retryOpts.params) {
|
|
1353
|
+
this.options.params = __spreadValues(__spreadValues({}, (_a = this.options.params) != null ? _a : {}), retryOpts.params);
|
|
1387
1354
|
}
|
|
1388
|
-
if (
|
|
1389
|
-
|
|
1355
|
+
if (retryOpts.headers) {
|
|
1356
|
+
this.options.headers = __spreadValues(__spreadValues({}, (_b = this.options.headers) != null ? _b : {}), retryOpts.headers);
|
|
1390
1357
|
}
|
|
1391
|
-
__privateSet(this,
|
|
1392
|
-
(
|
|
1358
|
+
__privateSet(this, _error, null);
|
|
1359
|
+
__privateSet(this, _started, false);
|
|
1360
|
+
await __privateMethod(this, _ShapeStream_instances, start_fn).call(this);
|
|
1393
1361
|
return;
|
|
1394
1362
|
}
|
|
1395
1363
|
if (err instanceof Error) {
|
|
1396
1364
|
__privateMethod(this, _ShapeStream_instances, sendErrorToSubscribers_fn).call(this, err);
|
|
1397
1365
|
}
|
|
1398
1366
|
__privateSet(this, _connected, false);
|
|
1399
|
-
(
|
|
1400
|
-
|
|
1367
|
+
(_c = __privateGet(this, _tickPromiseRejecter)) == null ? void 0 : _c.call(this);
|
|
1368
|
+
return;
|
|
1369
|
+
}
|
|
1370
|
+
if (err instanceof Error) {
|
|
1371
|
+
__privateMethod(this, _ShapeStream_instances, sendErrorToSubscribers_fn).call(this, err);
|
|
1401
1372
|
}
|
|
1402
1373
|
__privateSet(this, _connected, false);
|
|
1403
|
-
(
|
|
1404
|
-
|
|
1374
|
+
(_d = __privateGet(this, _tickPromiseRejecter)) == null ? void 0 : _d.call(this);
|
|
1375
|
+
throw err;
|
|
1376
|
+
}
|
|
1377
|
+
__privateSet(this, _connected, false);
|
|
1378
|
+
(_e = __privateGet(this, _tickPromiseRejecter)) == null ? void 0 : _e.call(this);
|
|
1405
1379
|
};
|
|
1406
|
-
requestShape_fn = function() {
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1380
|
+
requestShape_fn = async function() {
|
|
1381
|
+
var _a, _b;
|
|
1382
|
+
if (__privateGet(this, _state) === `pause-requested`) {
|
|
1383
|
+
__privateSet(this, _state, `paused`);
|
|
1384
|
+
return;
|
|
1385
|
+
}
|
|
1386
|
+
if (!this.options.subscribe && (((_a = this.options.signal) == null ? void 0 : _a.aborted) || __privateGet(this, _isUpToDate))) {
|
|
1387
|
+
return;
|
|
1388
|
+
}
|
|
1389
|
+
const resumingFromPause = __privateGet(this, _state) === `paused`;
|
|
1390
|
+
__privateSet(this, _state, `active`);
|
|
1391
|
+
const { url, signal } = this.options;
|
|
1392
|
+
const { fetchUrl, requestHeaders } = await __privateMethod(this, _ShapeStream_instances, constructUrl_fn).call(this, url, resumingFromPause);
|
|
1393
|
+
const abortListener = await __privateMethod(this, _ShapeStream_instances, createAbortListener_fn).call(this, signal);
|
|
1394
|
+
const requestAbortController = __privateGet(this, _requestAbortController);
|
|
1395
|
+
try {
|
|
1396
|
+
await __privateMethod(this, _ShapeStream_instances, fetchShape_fn).call(this, {
|
|
1397
|
+
fetchUrl,
|
|
1398
|
+
requestAbortController,
|
|
1399
|
+
headers: requestHeaders,
|
|
1400
|
+
resumingFromPause
|
|
1401
|
+
});
|
|
1402
|
+
} catch (e) {
|
|
1403
|
+
if ((e instanceof FetchError || e instanceof FetchBackoffAbortError) && requestAbortController.signal.aborted && requestAbortController.signal.reason === FORCE_DISCONNECT_AND_REFRESH) {
|
|
1404
|
+
return __privateMethod(this, _ShapeStream_instances, requestShape_fn).call(this);
|
|
1412
1405
|
}
|
|
1413
|
-
if (
|
|
1406
|
+
if (e instanceof FetchBackoffAbortError) {
|
|
1407
|
+
const currentState = __privateGet(this, _state);
|
|
1408
|
+
if (requestAbortController.signal.aborted && requestAbortController.signal.reason === PAUSE_STREAM && currentState === `pause-requested`) {
|
|
1409
|
+
__privateSet(this, _state, `paused`);
|
|
1410
|
+
}
|
|
1414
1411
|
return;
|
|
1415
1412
|
}
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
const requestAbortController = __privateGet(this, _requestAbortController);
|
|
1422
|
-
try {
|
|
1423
|
-
yield __privateMethod(this, _ShapeStream_instances, fetchShape_fn).call(this, {
|
|
1424
|
-
fetchUrl,
|
|
1425
|
-
requestAbortController,
|
|
1426
|
-
headers: requestHeaders,
|
|
1427
|
-
resumingFromPause
|
|
1428
|
-
});
|
|
1429
|
-
} catch (e) {
|
|
1430
|
-
if ((e instanceof FetchError || e instanceof FetchBackoffAbortError) && requestAbortController.signal.aborted && requestAbortController.signal.reason === FORCE_DISCONNECT_AND_REFRESH) {
|
|
1431
|
-
return __privateMethod(this, _ShapeStream_instances, requestShape_fn).call(this);
|
|
1432
|
-
}
|
|
1433
|
-
if (e instanceof FetchBackoffAbortError) {
|
|
1434
|
-
const currentState = __privateGet(this, _state);
|
|
1435
|
-
if (requestAbortController.signal.aborted && requestAbortController.signal.reason === PAUSE_STREAM && currentState === `pause-requested`) {
|
|
1436
|
-
__privateSet(this, _state, `paused`);
|
|
1437
|
-
}
|
|
1438
|
-
return;
|
|
1439
|
-
}
|
|
1440
|
-
if (!(e instanceof FetchError)) throw e;
|
|
1441
|
-
if (e.status == 409) {
|
|
1442
|
-
if (__privateGet(this, _shapeHandle)) {
|
|
1443
|
-
const shapeKey = canonicalShapeKey(fetchUrl);
|
|
1444
|
-
expiredShapesCache.markExpired(shapeKey, __privateGet(this, _shapeHandle));
|
|
1445
|
-
}
|
|
1446
|
-
const newShapeHandle = e.headers[SHAPE_HANDLE_HEADER] || `${__privateGet(this, _shapeHandle)}-next`;
|
|
1447
|
-
__privateMethod(this, _ShapeStream_instances, reset_fn).call(this, newShapeHandle);
|
|
1448
|
-
yield __privateMethod(this, _ShapeStream_instances, publish_fn).call(this, Array.isArray(e.json) ? e.json : [e.json]);
|
|
1449
|
-
return __privateMethod(this, _ShapeStream_instances, requestShape_fn).call(this);
|
|
1450
|
-
} else {
|
|
1451
|
-
throw e;
|
|
1413
|
+
if (!(e instanceof FetchError)) throw e;
|
|
1414
|
+
if (e.status == 409) {
|
|
1415
|
+
if (__privateGet(this, _shapeHandle)) {
|
|
1416
|
+
const shapeKey = canonicalShapeKey(fetchUrl);
|
|
1417
|
+
expiredShapesCache.markExpired(shapeKey, __privateGet(this, _shapeHandle));
|
|
1452
1418
|
}
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1419
|
+
const newShapeHandle = e.headers[SHAPE_HANDLE_HEADER] || `${__privateGet(this, _shapeHandle)}-next`;
|
|
1420
|
+
__privateMethod(this, _ShapeStream_instances, reset_fn).call(this, newShapeHandle);
|
|
1421
|
+
await __privateMethod(this, _ShapeStream_instances, publish_fn).call(this, Array.isArray(e.json) ? e.json : [e.json]);
|
|
1422
|
+
return __privateMethod(this, _ShapeStream_instances, requestShape_fn).call(this);
|
|
1423
|
+
} else {
|
|
1424
|
+
throw e;
|
|
1458
1425
|
}
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1426
|
+
} finally {
|
|
1427
|
+
if (abortListener && signal) {
|
|
1428
|
+
signal.removeEventListener(`abort`, abortListener);
|
|
1429
|
+
}
|
|
1430
|
+
__privateSet(this, _requestAbortController, void 0);
|
|
1431
|
+
}
|
|
1432
|
+
(_b = __privateGet(this, _tickPromiseResolver)) == null ? void 0 : _b.call(this);
|
|
1433
|
+
return __privateMethod(this, _ShapeStream_instances, requestShape_fn).call(this);
|
|
1462
1434
|
};
|
|
1463
|
-
constructUrl_fn = function(url, resumingFromPause, subsetParams) {
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
if (params)
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
);
|
|
1489
|
-
}
|
|
1490
|
-
const serializedColumns = encodedColumns.map(quoteIdentifier).join(`,`);
|
|
1491
|
-
setQueryParam(fetchUrl, COLUMNS_QUERY_PARAM, serializedColumns);
|
|
1492
|
-
} else {
|
|
1493
|
-
setQueryParam(fetchUrl, COLUMNS_QUERY_PARAM, params.columns);
|
|
1435
|
+
constructUrl_fn = async function(url, resumingFromPause, subsetParams) {
|
|
1436
|
+
var _a, _b, _c, _d;
|
|
1437
|
+
const [requestHeaders, params] = await Promise.all([
|
|
1438
|
+
resolveHeaders(this.options.headers),
|
|
1439
|
+
this.options.params ? toInternalParams(convertWhereParamsToObj(this.options.params)) : void 0
|
|
1440
|
+
]);
|
|
1441
|
+
if (params) validateParams(params);
|
|
1442
|
+
const fetchUrl = new URL(url);
|
|
1443
|
+
if (params) {
|
|
1444
|
+
if (params.table) setQueryParam(fetchUrl, TABLE_QUERY_PARAM, params.table);
|
|
1445
|
+
if (params.where && typeof params.where === `string`) {
|
|
1446
|
+
const encodedWhere = encodeWhereClause(
|
|
1447
|
+
params.where,
|
|
1448
|
+
(_a = this.options.columnMapper) == null ? void 0 : _a.encode
|
|
1449
|
+
);
|
|
1450
|
+
setQueryParam(fetchUrl, WHERE_QUERY_PARAM, encodedWhere);
|
|
1451
|
+
}
|
|
1452
|
+
if (params.columns) {
|
|
1453
|
+
const originalColumns = await resolveValue((_b = this.options.params) == null ? void 0 : _b.columns);
|
|
1454
|
+
if (Array.isArray(originalColumns)) {
|
|
1455
|
+
let encodedColumns = originalColumns.map(String);
|
|
1456
|
+
if (this.options.columnMapper) {
|
|
1457
|
+
encodedColumns = encodedColumns.map(
|
|
1458
|
+
this.options.columnMapper.encode
|
|
1459
|
+
);
|
|
1494
1460
|
}
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
setQueryParam(fetchUrl,
|
|
1499
|
-
const customParams = __spreadValues({}, params);
|
|
1500
|
-
delete customParams.table;
|
|
1501
|
-
delete customParams.where;
|
|
1502
|
-
delete customParams.columns;
|
|
1503
|
-
delete customParams.replica;
|
|
1504
|
-
delete customParams.params;
|
|
1505
|
-
for (const [key, value] of Object.entries(customParams)) {
|
|
1506
|
-
setQueryParam(fetchUrl, key, value);
|
|
1461
|
+
const serializedColumns = encodedColumns.map(quoteIdentifier).join(`,`);
|
|
1462
|
+
setQueryParam(fetchUrl, COLUMNS_QUERY_PARAM, serializedColumns);
|
|
1463
|
+
} else {
|
|
1464
|
+
setQueryParam(fetchUrl, COLUMNS_QUERY_PARAM, params.columns);
|
|
1507
1465
|
}
|
|
1508
1466
|
}
|
|
1509
|
-
if (
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
JSON.stringify(subsetParams.params)
|
|
1521
|
-
);
|
|
1522
|
-
if (subsetParams.limit)
|
|
1523
|
-
setQueryParam(fetchUrl, SUBSET_PARAM_LIMIT, subsetParams.limit);
|
|
1524
|
-
if (subsetParams.offset)
|
|
1525
|
-
setQueryParam(fetchUrl, SUBSET_PARAM_OFFSET, subsetParams.offset);
|
|
1526
|
-
if (subsetParams.orderBy && typeof subsetParams.orderBy === `string`) {
|
|
1527
|
-
const encodedOrderBy = encodeWhereClause(
|
|
1528
|
-
subsetParams.orderBy,
|
|
1529
|
-
(_d = this.options.columnMapper) == null ? void 0 : _d.encode
|
|
1530
|
-
);
|
|
1531
|
-
setQueryParam(fetchUrl, SUBSET_PARAM_ORDER_BY, encodedOrderBy);
|
|
1532
|
-
}
|
|
1467
|
+
if (params.replica) setQueryParam(fetchUrl, REPLICA_PARAM, params.replica);
|
|
1468
|
+
if (params.params)
|
|
1469
|
+
setQueryParam(fetchUrl, WHERE_PARAMS_PARAM, params.params);
|
|
1470
|
+
const customParams = __spreadValues({}, params);
|
|
1471
|
+
delete customParams.table;
|
|
1472
|
+
delete customParams.where;
|
|
1473
|
+
delete customParams.columns;
|
|
1474
|
+
delete customParams.replica;
|
|
1475
|
+
delete customParams.params;
|
|
1476
|
+
for (const [key, value] of Object.entries(customParams)) {
|
|
1477
|
+
setQueryParam(fetchUrl, key, value);
|
|
1533
1478
|
}
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
}
|
|
1541
|
-
fetchUrl.searchParams.set(
|
|
1542
|
-
LIVE_CACHE_BUSTER_QUERY_PARAM,
|
|
1543
|
-
__privateGet(this, _liveCacheBuster)
|
|
1479
|
+
}
|
|
1480
|
+
if (subsetParams) {
|
|
1481
|
+
if (subsetParams.where && typeof subsetParams.where === `string`) {
|
|
1482
|
+
const encodedWhere = encodeWhereClause(
|
|
1483
|
+
subsetParams.where,
|
|
1484
|
+
(_c = this.options.columnMapper) == null ? void 0 : _c.encode
|
|
1544
1485
|
);
|
|
1486
|
+
setQueryParam(fetchUrl, SUBSET_PARAM_WHERE, encodedWhere);
|
|
1545
1487
|
}
|
|
1546
|
-
if (
|
|
1547
|
-
fetchUrl.searchParams.set(
|
|
1488
|
+
if (subsetParams.params)
|
|
1489
|
+
fetchUrl.searchParams.set(
|
|
1490
|
+
SUBSET_PARAM_WHERE_PARAMS,
|
|
1491
|
+
JSON.stringify(subsetParams.params)
|
|
1492
|
+
);
|
|
1493
|
+
if (subsetParams.limit)
|
|
1494
|
+
setQueryParam(fetchUrl, SUBSET_PARAM_LIMIT, subsetParams.limit);
|
|
1495
|
+
if (subsetParams.offset)
|
|
1496
|
+
setQueryParam(fetchUrl, SUBSET_PARAM_OFFSET, subsetParams.offset);
|
|
1497
|
+
if (subsetParams.orderBy && typeof subsetParams.orderBy === `string`) {
|
|
1498
|
+
const encodedOrderBy = encodeWhereClause(
|
|
1499
|
+
subsetParams.orderBy,
|
|
1500
|
+
(_d = this.options.columnMapper) == null ? void 0 : _d.encode
|
|
1501
|
+
);
|
|
1502
|
+
setQueryParam(fetchUrl, SUBSET_PARAM_ORDER_BY, encodedOrderBy);
|
|
1548
1503
|
}
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1504
|
+
}
|
|
1505
|
+
fetchUrl.searchParams.set(OFFSET_QUERY_PARAM, __privateGet(this, _lastOffset));
|
|
1506
|
+
fetchUrl.searchParams.set(LOG_MODE_QUERY_PARAM, __privateGet(this, _mode));
|
|
1507
|
+
const isSnapshotRequest = subsetParams !== void 0;
|
|
1508
|
+
if (__privateGet(this, _isUpToDate) && !isSnapshotRequest) {
|
|
1509
|
+
if (!__privateGet(this, _isRefreshing) && !resumingFromPause) {
|
|
1510
|
+
fetchUrl.searchParams.set(LIVE_QUERY_PARAM, `true`);
|
|
1553
1511
|
}
|
|
1554
|
-
fetchUrl.searchParams.
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1512
|
+
fetchUrl.searchParams.set(
|
|
1513
|
+
LIVE_CACHE_BUSTER_QUERY_PARAM,
|
|
1514
|
+
__privateGet(this, _liveCacheBuster)
|
|
1515
|
+
);
|
|
1516
|
+
}
|
|
1517
|
+
if (__privateGet(this, _shapeHandle)) {
|
|
1518
|
+
fetchUrl.searchParams.set(SHAPE_HANDLE_QUERY_PARAM, __privateGet(this, _shapeHandle));
|
|
1519
|
+
}
|
|
1520
|
+
const shapeKey = canonicalShapeKey(fetchUrl);
|
|
1521
|
+
const expiredHandle = expiredShapesCache.getExpiredHandle(shapeKey);
|
|
1522
|
+
if (expiredHandle) {
|
|
1523
|
+
fetchUrl.searchParams.set(EXPIRED_HANDLE_QUERY_PARAM, expiredHandle);
|
|
1524
|
+
}
|
|
1525
|
+
fetchUrl.searchParams.sort();
|
|
1526
|
+
return {
|
|
1527
|
+
fetchUrl,
|
|
1528
|
+
requestHeaders
|
|
1529
|
+
};
|
|
1560
1530
|
};
|
|
1561
|
-
createAbortListener_fn = function(signal) {
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
(_a = __privateGet(this, _requestAbortController)) == null ? void 0 : _a.abort(signal.reason);
|
|
1573
|
-
}
|
|
1574
|
-
return abortListener;
|
|
1531
|
+
createAbortListener_fn = async function(signal) {
|
|
1532
|
+
var _a;
|
|
1533
|
+
__privateSet(this, _requestAbortController, new AbortController());
|
|
1534
|
+
if (signal) {
|
|
1535
|
+
const abortListener = () => {
|
|
1536
|
+
var _a2;
|
|
1537
|
+
(_a2 = __privateGet(this, _requestAbortController)) == null ? void 0 : _a2.abort(signal.reason);
|
|
1538
|
+
};
|
|
1539
|
+
signal.addEventListener(`abort`, abortListener, { once: true });
|
|
1540
|
+
if (signal.aborted) {
|
|
1541
|
+
(_a = __privateGet(this, _requestAbortController)) == null ? void 0 : _a.abort(signal.reason);
|
|
1575
1542
|
}
|
|
1576
|
-
|
|
1543
|
+
return abortListener;
|
|
1544
|
+
}
|
|
1577
1545
|
};
|
|
1578
|
-
onInitialResponse_fn = function(response) {
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1546
|
+
onInitialResponse_fn = async function(response) {
|
|
1547
|
+
var _a;
|
|
1548
|
+
const { headers, status } = response;
|
|
1549
|
+
const shapeHandle = headers.get(SHAPE_HANDLE_HEADER);
|
|
1550
|
+
if (shapeHandle) {
|
|
1551
|
+
const shapeKey = __privateGet(this, _currentFetchUrl) ? canonicalShapeKey(__privateGet(this, _currentFetchUrl)) : null;
|
|
1552
|
+
const expiredHandle = shapeKey ? expiredShapesCache.getExpiredHandle(shapeKey) : null;
|
|
1553
|
+
if (shapeHandle !== expiredHandle) {
|
|
1584
1554
|
__privateSet(this, _shapeHandle, shapeHandle);
|
|
1555
|
+
} else {
|
|
1556
|
+
console.warn(
|
|
1557
|
+
`[Electric] Received stale cached response with expired shape handle. This should not happen and indicates a proxy/CDN caching misconfiguration. The response contained handle "${shapeHandle}" which was previously marked as expired. Check that your proxy includes all query parameters (especially 'handle' and 'offset') in its cache key. Ignoring the stale handle and continuing with handle "${__privateGet(this, _shapeHandle)}".`
|
|
1558
|
+
);
|
|
1585
1559
|
}
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
}
|
|
1560
|
+
}
|
|
1561
|
+
const lastOffset = headers.get(CHUNK_LAST_OFFSET_HEADER);
|
|
1562
|
+
if (lastOffset) {
|
|
1563
|
+
__privateSet(this, _lastOffset, lastOffset);
|
|
1564
|
+
}
|
|
1565
|
+
const liveCacheBuster = headers.get(LIVE_CACHE_BUSTER_HEADER);
|
|
1566
|
+
if (liveCacheBuster) {
|
|
1567
|
+
__privateSet(this, _liveCacheBuster, liveCacheBuster);
|
|
1568
|
+
}
|
|
1569
|
+
__privateSet(this, _schema, (_a = __privateGet(this, _schema)) != null ? _a : getSchemaFromHeaders(headers));
|
|
1570
|
+
if (status === 204) {
|
|
1571
|
+
__privateSet(this, _lastSyncedAt, Date.now());
|
|
1572
|
+
}
|
|
1599
1573
|
};
|
|
1600
|
-
onMessages_fn = function(batch, isSseMessage = false) {
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
if (
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
__privateSet(this, _lastOffset, offset);
|
|
1611
|
-
}
|
|
1612
|
-
}
|
|
1613
|
-
__privateSet(this, _lastSyncedAt, Date.now());
|
|
1614
|
-
__privateSet(this, _isUpToDate, true);
|
|
1615
|
-
__privateSet(this, _isMidStream, false);
|
|
1616
|
-
(_a = __privateGet(this, _midStreamPromiseResolver)) == null ? void 0 : _a.call(this);
|
|
1617
|
-
if (__privateGet(this, _ShapeStream_instances, replayMode_get) && !isSseMessage) {
|
|
1618
|
-
const currentCursor = __privateGet(this, _liveCacheBuster);
|
|
1619
|
-
if (currentCursor === __privateGet(this, _lastSeenCursor)) {
|
|
1620
|
-
return;
|
|
1621
|
-
}
|
|
1622
|
-
}
|
|
1623
|
-
__privateSet(this, _lastSeenCursor, void 0);
|
|
1624
|
-
if (__privateGet(this, _currentFetchUrl)) {
|
|
1625
|
-
const shapeKey = canonicalShapeKey(__privateGet(this, _currentFetchUrl));
|
|
1626
|
-
upToDateTracker.recordUpToDate(shapeKey, __privateGet(this, _liveCacheBuster));
|
|
1574
|
+
onMessages_fn = async function(batch, isSseMessage = false) {
|
|
1575
|
+
var _a;
|
|
1576
|
+
if (batch.length > 0) {
|
|
1577
|
+
__privateSet(this, _isMidStream, true);
|
|
1578
|
+
const lastMessage = batch[batch.length - 1];
|
|
1579
|
+
if (isUpToDateMessage(lastMessage)) {
|
|
1580
|
+
if (isSseMessage) {
|
|
1581
|
+
const offset = getOffset(lastMessage);
|
|
1582
|
+
if (offset) {
|
|
1583
|
+
__privateSet(this, _lastOffset, offset);
|
|
1627
1584
|
}
|
|
1628
1585
|
}
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1586
|
+
__privateSet(this, _lastSyncedAt, Date.now());
|
|
1587
|
+
__privateSet(this, _isUpToDate, true);
|
|
1588
|
+
__privateSet(this, _isMidStream, false);
|
|
1589
|
+
(_a = __privateGet(this, _midStreamPromiseResolver)) == null ? void 0 : _a.call(this);
|
|
1590
|
+
if (__privateGet(this, _ShapeStream_instances, replayMode_get) && !isSseMessage) {
|
|
1591
|
+
const currentCursor = __privateGet(this, _liveCacheBuster);
|
|
1592
|
+
if (currentCursor === __privateGet(this, _lastSeenCursor)) {
|
|
1593
|
+
return;
|
|
1632
1594
|
}
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
};
|
|
1639
|
-
fetchShape_fn = function(opts) {
|
|
1640
|
-
return __async(this, null, function* () {
|
|
1641
|
-
var _a;
|
|
1642
|
-
__privateSet(this, _currentFetchUrl, opts.fetchUrl);
|
|
1643
|
-
if (!__privateGet(this, _isUpToDate) && !__privateGet(this, _ShapeStream_instances, replayMode_get)) {
|
|
1644
|
-
const shapeKey = canonicalShapeKey(opts.fetchUrl);
|
|
1645
|
-
const lastSeenCursor = upToDateTracker.shouldEnterReplayMode(shapeKey);
|
|
1646
|
-
if (lastSeenCursor) {
|
|
1647
|
-
__privateSet(this, _lastSeenCursor, lastSeenCursor);
|
|
1595
|
+
}
|
|
1596
|
+
__privateSet(this, _lastSeenCursor, void 0);
|
|
1597
|
+
if (__privateGet(this, _currentFetchUrl)) {
|
|
1598
|
+
const shapeKey = canonicalShapeKey(__privateGet(this, _currentFetchUrl));
|
|
1599
|
+
upToDateTracker.recordUpToDate(shapeKey, __privateGet(this, _liveCacheBuster));
|
|
1648
1600
|
}
|
|
1649
1601
|
}
|
|
1650
|
-
const
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
return
|
|
1602
|
+
const messagesToProcess = batch.filter((message) => {
|
|
1603
|
+
if (isChangeMessage(message)) {
|
|
1604
|
+
return !__privateGet(this, _snapshotTracker).shouldRejectMessage(message);
|
|
1605
|
+
}
|
|
1606
|
+
return true;
|
|
1607
|
+
});
|
|
1608
|
+
await __privateMethod(this, _ShapeStream_instances, publish_fn).call(this, messagesToProcess);
|
|
1609
|
+
}
|
|
1610
|
+
};
|
|
1611
|
+
fetchShape_fn = async function(opts) {
|
|
1612
|
+
var _a;
|
|
1613
|
+
__privateSet(this, _currentFetchUrl, opts.fetchUrl);
|
|
1614
|
+
if (!__privateGet(this, _isUpToDate) && !__privateGet(this, _ShapeStream_instances, replayMode_get)) {
|
|
1615
|
+
const shapeKey = canonicalShapeKey(opts.fetchUrl);
|
|
1616
|
+
const lastSeenCursor = upToDateTracker.shouldEnterReplayMode(shapeKey);
|
|
1617
|
+
if (lastSeenCursor) {
|
|
1618
|
+
__privateSet(this, _lastSeenCursor, lastSeenCursor);
|
|
1655
1619
|
}
|
|
1656
|
-
|
|
1657
|
-
|
|
1620
|
+
}
|
|
1621
|
+
const useSse = (_a = this.options.liveSse) != null ? _a : this.options.experimentalLiveSse;
|
|
1622
|
+
if (__privateGet(this, _isUpToDate) && useSse && !__privateGet(this, _isRefreshing) && !opts.resumingFromPause && !__privateGet(this, _sseFallbackToLongPolling)) {
|
|
1623
|
+
opts.fetchUrl.searchParams.set(EXPERIMENTAL_LIVE_SSE_QUERY_PARAM, `true`);
|
|
1624
|
+
opts.fetchUrl.searchParams.set(LIVE_SSE_QUERY_PARAM, `true`);
|
|
1625
|
+
return __privateMethod(this, _ShapeStream_instances, requestShapeSSE_fn).call(this, opts);
|
|
1626
|
+
}
|
|
1627
|
+
return __privateMethod(this, _ShapeStream_instances, requestShapeLongPoll_fn).call(this, opts);
|
|
1658
1628
|
};
|
|
1659
|
-
requestShapeLongPoll_fn = function(opts) {
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
headers
|
|
1665
|
-
});
|
|
1666
|
-
__privateSet(this, _connected, true);
|
|
1667
|
-
yield __privateMethod(this, _ShapeStream_instances, onInitialResponse_fn).call(this, response);
|
|
1668
|
-
const schema = __privateGet(this, _schema);
|
|
1669
|
-
const res = yield response.text();
|
|
1670
|
-
const messages = res || `[]`;
|
|
1671
|
-
const batch = __privateGet(this, _messageParser).parse(messages, schema);
|
|
1672
|
-
yield __privateMethod(this, _ShapeStream_instances, onMessages_fn).call(this, batch);
|
|
1629
|
+
requestShapeLongPoll_fn = async function(opts) {
|
|
1630
|
+
const { fetchUrl, requestAbortController, headers } = opts;
|
|
1631
|
+
const response = await __privateGet(this, _fetchClient2).call(this, fetchUrl.toString(), {
|
|
1632
|
+
signal: requestAbortController.signal,
|
|
1633
|
+
headers
|
|
1673
1634
|
});
|
|
1635
|
+
__privateSet(this, _connected, true);
|
|
1636
|
+
await __privateMethod(this, _ShapeStream_instances, onInitialResponse_fn).call(this, response);
|
|
1637
|
+
const schema = __privateGet(this, _schema);
|
|
1638
|
+
const res = await response.text();
|
|
1639
|
+
const messages = res || `[]`;
|
|
1640
|
+
const batch = __privateGet(this, _messageParser).parse(messages, schema);
|
|
1641
|
+
await __privateMethod(this, _ShapeStream_instances, onMessages_fn).call(this, batch);
|
|
1674
1642
|
};
|
|
1675
|
-
requestShapeSSE_fn = function(opts) {
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
schema
|
|
1698
|
-
);
|
|
1699
|
-
buffer.push(message);
|
|
1700
|
-
if (isUpToDateMessage(message)) {
|
|
1701
|
-
__privateMethod(this, _ShapeStream_instances, onMessages_fn).call(this, buffer, true);
|
|
1702
|
-
buffer = [];
|
|
1703
|
-
}
|
|
1704
|
-
}
|
|
1705
|
-
},
|
|
1706
|
-
onerror: (error) => {
|
|
1707
|
-
throw error;
|
|
1708
|
-
},
|
|
1709
|
-
signal: requestAbortController.signal
|
|
1710
|
-
});
|
|
1711
|
-
} catch (error) {
|
|
1712
|
-
if (requestAbortController.signal.aborted) {
|
|
1713
|
-
throw new FetchBackoffAbortError();
|
|
1714
|
-
}
|
|
1715
|
-
throw error;
|
|
1716
|
-
} finally {
|
|
1717
|
-
const connectionDuration = Date.now() - __privateGet(this, _lastSseConnectionStartTime);
|
|
1718
|
-
const wasAborted = requestAbortController.signal.aborted;
|
|
1719
|
-
if (connectionDuration < __privateGet(this, _minSseConnectionDuration) && !wasAborted) {
|
|
1720
|
-
__privateWrapper(this, _consecutiveShortSseConnections)._++;
|
|
1721
|
-
if (__privateGet(this, _consecutiveShortSseConnections) >= __privateGet(this, _maxShortSseConnections)) {
|
|
1722
|
-
__privateSet(this, _sseFallbackToLongPolling, true);
|
|
1723
|
-
console.warn(
|
|
1724
|
-
`[Electric] SSE connections are closing immediately (possibly due to proxy buffering or misconfiguration). Falling back to long polling. Your proxy must support streaming SSE responses (not buffer the complete response). Configuration: Nginx add 'X-Accel-Buffering: no', Caddy add 'flush_interval -1' to reverse_proxy. Note: Do NOT disable caching entirely - Electric uses cache headers to enable request collapsing for efficiency.`
|
|
1725
|
-
);
|
|
1726
|
-
} else {
|
|
1727
|
-
const maxDelay = Math.min(
|
|
1728
|
-
__privateGet(this, _sseBackoffMaxDelay),
|
|
1729
|
-
__privateGet(this, _sseBackoffBaseDelay) * Math.pow(2, __privateGet(this, _consecutiveShortSseConnections))
|
|
1643
|
+
requestShapeSSE_fn = async function(opts) {
|
|
1644
|
+
const { fetchUrl, requestAbortController, headers } = opts;
|
|
1645
|
+
const fetch2 = __privateGet(this, _sseFetchClient);
|
|
1646
|
+
__privateSet(this, _lastSseConnectionStartTime, Date.now());
|
|
1647
|
+
const sseHeaders = __spreadProps(__spreadValues({}, headers), {
|
|
1648
|
+
Accept: `text/event-stream`
|
|
1649
|
+
});
|
|
1650
|
+
try {
|
|
1651
|
+
let buffer = [];
|
|
1652
|
+
await fetchEventSource(fetchUrl.toString(), {
|
|
1653
|
+
headers: sseHeaders,
|
|
1654
|
+
fetch: fetch2,
|
|
1655
|
+
onopen: async (response) => {
|
|
1656
|
+
__privateSet(this, _connected, true);
|
|
1657
|
+
await __privateMethod(this, _ShapeStream_instances, onInitialResponse_fn).call(this, response);
|
|
1658
|
+
},
|
|
1659
|
+
onmessage: (event) => {
|
|
1660
|
+
if (event.data) {
|
|
1661
|
+
const schema = __privateGet(this, _schema);
|
|
1662
|
+
const message = __privateGet(this, _messageParser).parse(
|
|
1663
|
+
event.data,
|
|
1664
|
+
schema
|
|
1730
1665
|
);
|
|
1731
|
-
|
|
1732
|
-
|
|
1666
|
+
buffer.push(message);
|
|
1667
|
+
if (isUpToDateMessage(message)) {
|
|
1668
|
+
__privateMethod(this, _ShapeStream_instances, onMessages_fn).call(this, buffer, true);
|
|
1669
|
+
buffer = [];
|
|
1670
|
+
}
|
|
1733
1671
|
}
|
|
1734
|
-
}
|
|
1735
|
-
|
|
1672
|
+
},
|
|
1673
|
+
onerror: (error) => {
|
|
1674
|
+
throw error;
|
|
1675
|
+
},
|
|
1676
|
+
signal: requestAbortController.signal
|
|
1677
|
+
});
|
|
1678
|
+
} catch (error) {
|
|
1679
|
+
if (requestAbortController.signal.aborted) {
|
|
1680
|
+
throw new FetchBackoffAbortError();
|
|
1681
|
+
}
|
|
1682
|
+
throw error;
|
|
1683
|
+
} finally {
|
|
1684
|
+
const connectionDuration = Date.now() - __privateGet(this, _lastSseConnectionStartTime);
|
|
1685
|
+
const wasAborted = requestAbortController.signal.aborted;
|
|
1686
|
+
if (connectionDuration < __privateGet(this, _minSseConnectionDuration) && !wasAborted) {
|
|
1687
|
+
__privateWrapper(this, _consecutiveShortSseConnections)._++;
|
|
1688
|
+
if (__privateGet(this, _consecutiveShortSseConnections) >= __privateGet(this, _maxShortSseConnections)) {
|
|
1689
|
+
__privateSet(this, _sseFallbackToLongPolling, true);
|
|
1690
|
+
console.warn(
|
|
1691
|
+
`[Electric] SSE connections are closing immediately (possibly due to proxy buffering or misconfiguration). Falling back to long polling. Your proxy must support streaming SSE responses (not buffer the complete response). Configuration: Nginx add 'X-Accel-Buffering: no', Caddy add 'flush_interval -1' to reverse_proxy. Note: Do NOT disable caching entirely - Electric uses cache headers to enable request collapsing for efficiency.`
|
|
1692
|
+
);
|
|
1693
|
+
} else {
|
|
1694
|
+
const maxDelay = Math.min(
|
|
1695
|
+
__privateGet(this, _sseBackoffMaxDelay),
|
|
1696
|
+
__privateGet(this, _sseBackoffBaseDelay) * Math.pow(2, __privateGet(this, _consecutiveShortSseConnections))
|
|
1697
|
+
);
|
|
1698
|
+
const delayMs = Math.floor(Math.random() * maxDelay);
|
|
1699
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
1736
1700
|
}
|
|
1701
|
+
} else if (connectionDuration >= __privateGet(this, _minSseConnectionDuration)) {
|
|
1702
|
+
__privateSet(this, _consecutiveShortSseConnections, 0);
|
|
1737
1703
|
}
|
|
1738
|
-
}
|
|
1704
|
+
}
|
|
1739
1705
|
};
|
|
1740
1706
|
pause_fn = function() {
|
|
1741
1707
|
var _a;
|
|
@@ -1745,65 +1711,63 @@ pause_fn = function() {
|
|
|
1745
1711
|
}
|
|
1746
1712
|
};
|
|
1747
1713
|
resume_fn = function() {
|
|
1714
|
+
var _a;
|
|
1748
1715
|
if (__privateGet(this, _started) && (__privateGet(this, _state) === `paused` || __privateGet(this, _state) === `pause-requested`)) {
|
|
1716
|
+
if ((_a = this.options.signal) == null ? void 0 : _a.aborted) {
|
|
1717
|
+
return;
|
|
1718
|
+
}
|
|
1749
1719
|
if (__privateGet(this, _state) === `pause-requested`) {
|
|
1750
1720
|
__privateSet(this, _state, `active`);
|
|
1751
1721
|
}
|
|
1752
1722
|
__privateMethod(this, _ShapeStream_instances, start_fn).call(this);
|
|
1753
1723
|
}
|
|
1754
1724
|
};
|
|
1755
|
-
nextTick_fn = function() {
|
|
1756
|
-
|
|
1757
|
-
if (__privateGet(this, _tickPromise)) {
|
|
1758
|
-
return __privateGet(this, _tickPromise);
|
|
1759
|
-
}
|
|
1760
|
-
__privateSet(this, _tickPromise, new Promise((resolve, reject) => {
|
|
1761
|
-
__privateSet(this, _tickPromiseResolver, resolve);
|
|
1762
|
-
__privateSet(this, _tickPromiseRejecter, reject);
|
|
1763
|
-
}));
|
|
1764
|
-
__privateGet(this, _tickPromise).finally(() => {
|
|
1765
|
-
__privateSet(this, _tickPromise, void 0);
|
|
1766
|
-
__privateSet(this, _tickPromiseResolver, void 0);
|
|
1767
|
-
__privateSet(this, _tickPromiseRejecter, void 0);
|
|
1768
|
-
});
|
|
1725
|
+
nextTick_fn = async function() {
|
|
1726
|
+
if (__privateGet(this, _tickPromise)) {
|
|
1769
1727
|
return __privateGet(this, _tickPromise);
|
|
1728
|
+
}
|
|
1729
|
+
__privateSet(this, _tickPromise, new Promise((resolve, reject) => {
|
|
1730
|
+
__privateSet(this, _tickPromiseResolver, resolve);
|
|
1731
|
+
__privateSet(this, _tickPromiseRejecter, reject);
|
|
1732
|
+
}));
|
|
1733
|
+
__privateGet(this, _tickPromise).finally(() => {
|
|
1734
|
+
__privateSet(this, _tickPromise, void 0);
|
|
1735
|
+
__privateSet(this, _tickPromiseResolver, void 0);
|
|
1736
|
+
__privateSet(this, _tickPromiseRejecter, void 0);
|
|
1770
1737
|
});
|
|
1738
|
+
return __privateGet(this, _tickPromise);
|
|
1771
1739
|
};
|
|
1772
|
-
waitForStreamEnd_fn = function() {
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
if (__privateGet(this, _midStreamPromise)) {
|
|
1778
|
-
return __privateGet(this, _midStreamPromise);
|
|
1779
|
-
}
|
|
1780
|
-
__privateSet(this, _midStreamPromise, new Promise((resolve) => {
|
|
1781
|
-
__privateSet(this, _midStreamPromiseResolver, resolve);
|
|
1782
|
-
}));
|
|
1783
|
-
__privateGet(this, _midStreamPromise).finally(() => {
|
|
1784
|
-
__privateSet(this, _midStreamPromise, void 0);
|
|
1785
|
-
__privateSet(this, _midStreamPromiseResolver, void 0);
|
|
1786
|
-
});
|
|
1740
|
+
waitForStreamEnd_fn = async function() {
|
|
1741
|
+
if (!__privateGet(this, _isMidStream)) {
|
|
1742
|
+
return;
|
|
1743
|
+
}
|
|
1744
|
+
if (__privateGet(this, _midStreamPromise)) {
|
|
1787
1745
|
return __privateGet(this, _midStreamPromise);
|
|
1746
|
+
}
|
|
1747
|
+
__privateSet(this, _midStreamPromise, new Promise((resolve) => {
|
|
1748
|
+
__privateSet(this, _midStreamPromiseResolver, resolve);
|
|
1749
|
+
}));
|
|
1750
|
+
__privateGet(this, _midStreamPromise).finally(() => {
|
|
1751
|
+
__privateSet(this, _midStreamPromise, void 0);
|
|
1752
|
+
__privateSet(this, _midStreamPromiseResolver, void 0);
|
|
1788
1753
|
});
|
|
1754
|
+
return __privateGet(this, _midStreamPromise);
|
|
1789
1755
|
};
|
|
1790
|
-
publish_fn = function(messages) {
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
() =>
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
return __privateGet(this, _messageChain);
|
|
1806
|
-
});
|
|
1756
|
+
publish_fn = async function(messages) {
|
|
1757
|
+
__privateSet(this, _messageChain, __privateGet(this, _messageChain).then(
|
|
1758
|
+
() => Promise.all(
|
|
1759
|
+
Array.from(__privateGet(this, _subscribers).values()).map(async ([callback, __]) => {
|
|
1760
|
+
try {
|
|
1761
|
+
await callback(messages);
|
|
1762
|
+
} catch (err) {
|
|
1763
|
+
queueMicrotask(() => {
|
|
1764
|
+
throw err;
|
|
1765
|
+
});
|
|
1766
|
+
}
|
|
1767
|
+
})
|
|
1768
|
+
)
|
|
1769
|
+
));
|
|
1770
|
+
return __privateGet(this, _messageChain);
|
|
1807
1771
|
};
|
|
1808
1772
|
sendErrorToSubscribers_fn = function(error) {
|
|
1809
1773
|
__privateGet(this, _subscribers).forEach(([_, errorFn]) => {
|
|
@@ -1975,13 +1939,11 @@ var Shape = class {
|
|
|
1975
1939
|
* Request a snapshot for subset of data. Only available when mode is changes_only.
|
|
1976
1940
|
* Returns void; data will be emitted via the stream and processed by this Shape.
|
|
1977
1941
|
*/
|
|
1978
|
-
requestSnapshot(params) {
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
yield this.stream.requestSnapshot(params);
|
|
1984
|
-
});
|
|
1942
|
+
async requestSnapshot(params) {
|
|
1943
|
+
const key = JSON.stringify(params);
|
|
1944
|
+
__privateGet(this, _requestedSubSnapshots).add(key);
|
|
1945
|
+
await __privateMethod(this, _Shape_instances, awaitUpToDate_fn).call(this);
|
|
1946
|
+
await this.stream.requestSnapshot(params);
|
|
1985
1947
|
}
|
|
1986
1948
|
subscribe(callback) {
|
|
1987
1949
|
const subscriptionId = Math.random();
|
|
@@ -2063,38 +2025,34 @@ process_fn = function(messages) {
|
|
|
2063
2025
|
});
|
|
2064
2026
|
if (shouldNotify) __privateMethod(this, _Shape_instances, notify_fn).call(this);
|
|
2065
2027
|
};
|
|
2066
|
-
reexecuteSnapshots_fn = function() {
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
);
|
|
2078
|
-
});
|
|
2028
|
+
reexecuteSnapshots_fn = async function() {
|
|
2029
|
+
await __privateMethod(this, _Shape_instances, awaitUpToDate_fn).call(this);
|
|
2030
|
+
await Promise.all(
|
|
2031
|
+
Array.from(__privateGet(this, _requestedSubSnapshots)).map(async (jsonParams) => {
|
|
2032
|
+
try {
|
|
2033
|
+
const snapshot = JSON.parse(jsonParams);
|
|
2034
|
+
await this.stream.requestSnapshot(snapshot);
|
|
2035
|
+
} catch (_) {
|
|
2036
|
+
}
|
|
2037
|
+
})
|
|
2038
|
+
);
|
|
2079
2039
|
};
|
|
2080
|
-
awaitUpToDate_fn = function() {
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
check();
|
|
2097
|
-
});
|
|
2040
|
+
awaitUpToDate_fn = async function() {
|
|
2041
|
+
if (this.stream.isUpToDate) return;
|
|
2042
|
+
await new Promise((resolve) => {
|
|
2043
|
+
const check = () => {
|
|
2044
|
+
if (this.stream.isUpToDate) {
|
|
2045
|
+
clearInterval(interval);
|
|
2046
|
+
unsub();
|
|
2047
|
+
resolve();
|
|
2048
|
+
}
|
|
2049
|
+
};
|
|
2050
|
+
const interval = setInterval(check, 10);
|
|
2051
|
+
const unsub = this.stream.subscribe(
|
|
2052
|
+
() => check(),
|
|
2053
|
+
() => check()
|
|
2054
|
+
);
|
|
2055
|
+
check();
|
|
2098
2056
|
});
|
|
2099
2057
|
};
|
|
2100
2058
|
updateShapeStatus_fn = function(status) {
|