@electric-sql/client 1.2.2 → 1.3.0
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 +520 -577
- 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 +17 -8
- package/dist/index.legacy-esm.js.map +1 -1
- package/dist/index.mjs +520 -577
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +9 -9
- package/src/fetch.ts +14 -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);
|
|
@@ -1025,43 +1007,35 @@ var RESERVED_PARAMS = /* @__PURE__ */ new Set([
|
|
|
1025
1007
|
LIVE_QUERY_PARAM,
|
|
1026
1008
|
OFFSET_QUERY_PARAM
|
|
1027
1009
|
]);
|
|
1028
|
-
function resolveValue(value) {
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
return value;
|
|
1034
|
-
});
|
|
1010
|
+
async function resolveValue(value) {
|
|
1011
|
+
if (typeof value === `function`) {
|
|
1012
|
+
return value();
|
|
1013
|
+
}
|
|
1014
|
+
return value;
|
|
1035
1015
|
}
|
|
1036
|
-
function toInternalParams(params) {
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
);
|
|
1052
|
-
});
|
|
1016
|
+
async function toInternalParams(params) {
|
|
1017
|
+
const entries = Object.entries(params);
|
|
1018
|
+
const resolvedEntries = await Promise.all(
|
|
1019
|
+
entries.map(async ([key, value]) => {
|
|
1020
|
+
if (value === void 0) return [key, void 0];
|
|
1021
|
+
const resolvedValue = await resolveValue(value);
|
|
1022
|
+
return [
|
|
1023
|
+
key,
|
|
1024
|
+
Array.isArray(resolvedValue) ? resolvedValue.join(`,`) : resolvedValue
|
|
1025
|
+
];
|
|
1026
|
+
})
|
|
1027
|
+
);
|
|
1028
|
+
return Object.fromEntries(
|
|
1029
|
+
resolvedEntries.filter(([_, value]) => value !== void 0)
|
|
1030
|
+
);
|
|
1053
1031
|
}
|
|
1054
|
-
function resolveHeaders(headers) {
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
}))
|
|
1062
|
-
);
|
|
1063
|
-
return Object.fromEntries(resolvedEntries);
|
|
1064
|
-
});
|
|
1032
|
+
async function resolveHeaders(headers) {
|
|
1033
|
+
if (!headers) return {};
|
|
1034
|
+
const entries = Object.entries(headers);
|
|
1035
|
+
const resolvedEntries = await Promise.all(
|
|
1036
|
+
entries.map(async ([key, value]) => [key, await resolveValue(value)])
|
|
1037
|
+
);
|
|
1038
|
+
return Object.fromEntries(resolvedEntries);
|
|
1065
1039
|
}
|
|
1066
1040
|
function canonicalShapeKey(url) {
|
|
1067
1041
|
const cleanUrl = new URL(url.origin + url.pathname);
|
|
@@ -1223,16 +1197,14 @@ var ShapeStream = class {
|
|
|
1223
1197
|
* long polling, ensuring that the stream receives an up to date message with the
|
|
1224
1198
|
* latest LSN from Postgres at that point in time.
|
|
1225
1199
|
*/
|
|
1226
|
-
forceDisconnectAndRefresh() {
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
__privateSet(this, _isRefreshing, false);
|
|
1235
|
-
});
|
|
1200
|
+
async forceDisconnectAndRefresh() {
|
|
1201
|
+
var _a, _b;
|
|
1202
|
+
__privateSet(this, _isRefreshing, true);
|
|
1203
|
+
if (__privateGet(this, _isUpToDate) && !((_a = __privateGet(this, _requestAbortController)) == null ? void 0 : _a.signal.aborted)) {
|
|
1204
|
+
(_b = __privateGet(this, _requestAbortController)) == null ? void 0 : _b.abort(FORCE_DISCONNECT_AND_REFRESH);
|
|
1205
|
+
}
|
|
1206
|
+
await __privateMethod(this, _ShapeStream_instances, nextTick_fn).call(this);
|
|
1207
|
+
__privateSet(this, _isRefreshing, false);
|
|
1236
1208
|
}
|
|
1237
1209
|
/**
|
|
1238
1210
|
* Request a snapshot for subset of data and inject it into the subscribed data stream.
|
|
@@ -1248,40 +1220,39 @@ var ShapeStream = class {
|
|
|
1248
1220
|
* @param opts - The options for the snapshot request.
|
|
1249
1221
|
* @returns The metadata and the data for the snapshot.
|
|
1250
1222
|
*/
|
|
1251
|
-
requestSnapshot(opts) {
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1223
|
+
async requestSnapshot(opts) {
|
|
1224
|
+
if (__privateGet(this, _mode) === `full`) {
|
|
1225
|
+
throw new Error(
|
|
1226
|
+
`Snapshot requests are not supported in ${__privateGet(this, _mode)} mode, as the consumer is guaranteed to observe all data`
|
|
1227
|
+
);
|
|
1228
|
+
}
|
|
1229
|
+
if (!__privateGet(this, _started)) await __privateMethod(this, _ShapeStream_instances, start_fn).call(this);
|
|
1230
|
+
await __privateMethod(this, _ShapeStream_instances, waitForStreamEnd_fn).call(this);
|
|
1231
|
+
__privateWrapper(this, _activeSnapshotRequests)._++;
|
|
1232
|
+
try {
|
|
1233
|
+
if (__privateGet(this, _activeSnapshotRequests) === 1) {
|
|
1234
|
+
__privateMethod(this, _ShapeStream_instances, pause_fn).call(this);
|
|
1257
1235
|
}
|
|
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
|
-
}
|
|
1236
|
+
const { metadata, data } = await this.fetchSnapshot(opts);
|
|
1237
|
+
const dataWithEndBoundary = data.concat([
|
|
1238
|
+
{ headers: __spreadValues({ control: `snapshot-end` }, metadata) },
|
|
1239
|
+
{ headers: __spreadValues({ control: `subset-end` }, opts) }
|
|
1240
|
+
]);
|
|
1241
|
+
__privateGet(this, _snapshotTracker).addSnapshot(
|
|
1242
|
+
metadata,
|
|
1243
|
+
new Set(data.map((message) => message.key))
|
|
1244
|
+
);
|
|
1245
|
+
__privateMethod(this, _ShapeStream_instances, onMessages_fn).call(this, dataWithEndBoundary, false);
|
|
1246
|
+
return {
|
|
1247
|
+
metadata,
|
|
1248
|
+
data
|
|
1249
|
+
};
|
|
1250
|
+
} finally {
|
|
1251
|
+
__privateWrapper(this, _activeSnapshotRequests)._--;
|
|
1252
|
+
if (__privateGet(this, _activeSnapshotRequests) === 0) {
|
|
1253
|
+
__privateMethod(this, _ShapeStream_instances, resume_fn).call(this);
|
|
1283
1254
|
}
|
|
1284
|
-
}
|
|
1255
|
+
}
|
|
1285
1256
|
}
|
|
1286
1257
|
/**
|
|
1287
1258
|
* Fetch a snapshot for subset of data.
|
|
@@ -1290,36 +1261,34 @@ var ShapeStream = class {
|
|
|
1290
1261
|
* @param opts - The options for the snapshot request.
|
|
1291
1262
|
* @returns The metadata and the data for the snapshot.
|
|
1292
1263
|
*/
|
|
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
|
|
1264
|
+
async fetchSnapshot(opts) {
|
|
1265
|
+
var _a;
|
|
1266
|
+
const { fetchUrl, requestHeaders } = await __privateMethod(this, _ShapeStream_instances, constructUrl_fn).call(this, this.options.url, true, opts);
|
|
1267
|
+
const response = await __privateGet(this, _fetchClient2).call(this, fetchUrl.toString(), {
|
|
1268
|
+
headers: requestHeaders
|
|
1269
|
+
});
|
|
1270
|
+
if (!response.ok) {
|
|
1271
|
+
throw new FetchError(
|
|
1272
|
+
response.status,
|
|
1273
|
+
void 0,
|
|
1274
|
+
void 0,
|
|
1275
|
+
Object.fromEntries([...response.headers.entries()]),
|
|
1276
|
+
fetchUrl.toString()
|
|
1317
1277
|
);
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1278
|
+
}
|
|
1279
|
+
const schema = (_a = __privateGet(this, _schema)) != null ? _a : getSchemaFromHeaders(response.headers, {
|
|
1280
|
+
required: true,
|
|
1281
|
+
url: fetchUrl.toString()
|
|
1322
1282
|
});
|
|
1283
|
+
const { metadata, data: rawData } = await response.json();
|
|
1284
|
+
const data = __privateGet(this, _messageParser).parseSnapshotData(
|
|
1285
|
+
rawData,
|
|
1286
|
+
schema
|
|
1287
|
+
);
|
|
1288
|
+
return {
|
|
1289
|
+
metadata,
|
|
1290
|
+
data
|
|
1291
|
+
};
|
|
1323
1292
|
}
|
|
1324
1293
|
};
|
|
1325
1294
|
_error = new WeakMap();
|
|
@@ -1363,379 +1332,361 @@ _ShapeStream_instances = new WeakSet();
|
|
|
1363
1332
|
replayMode_get = function() {
|
|
1364
1333
|
return __privateGet(this, _lastSeenCursor) !== void 0;
|
|
1365
1334
|
};
|
|
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;
|
|
1335
|
+
start_fn = async function() {
|
|
1336
|
+
var _a, _b, _c, _d, _e;
|
|
1337
|
+
__privateSet(this, _started, true);
|
|
1338
|
+
try {
|
|
1339
|
+
await __privateMethod(this, _ShapeStream_instances, requestShape_fn).call(this);
|
|
1340
|
+
} catch (err) {
|
|
1341
|
+
__privateSet(this, _error, err);
|
|
1342
|
+
if (__privateGet(this, _onError)) {
|
|
1343
|
+
const retryOpts = await __privateGet(this, _onError).call(this, err);
|
|
1344
|
+
if (retryOpts && typeof retryOpts === `object`) {
|
|
1345
|
+
if (retryOpts.params) {
|
|
1346
|
+
this.options.params = __spreadValues(__spreadValues({}, (_a = this.options.params) != null ? _a : {}), retryOpts.params);
|
|
1387
1347
|
}
|
|
1388
|
-
if (
|
|
1389
|
-
|
|
1348
|
+
if (retryOpts.headers) {
|
|
1349
|
+
this.options.headers = __spreadValues(__spreadValues({}, (_b = this.options.headers) != null ? _b : {}), retryOpts.headers);
|
|
1390
1350
|
}
|
|
1391
|
-
__privateSet(this,
|
|
1392
|
-
(
|
|
1351
|
+
__privateSet(this, _error, null);
|
|
1352
|
+
__privateSet(this, _started, false);
|
|
1353
|
+
await __privateMethod(this, _ShapeStream_instances, start_fn).call(this);
|
|
1393
1354
|
return;
|
|
1394
1355
|
}
|
|
1395
1356
|
if (err instanceof Error) {
|
|
1396
1357
|
__privateMethod(this, _ShapeStream_instances, sendErrorToSubscribers_fn).call(this, err);
|
|
1397
1358
|
}
|
|
1398
1359
|
__privateSet(this, _connected, false);
|
|
1399
|
-
(
|
|
1400
|
-
|
|
1360
|
+
(_c = __privateGet(this, _tickPromiseRejecter)) == null ? void 0 : _c.call(this);
|
|
1361
|
+
return;
|
|
1362
|
+
}
|
|
1363
|
+
if (err instanceof Error) {
|
|
1364
|
+
__privateMethod(this, _ShapeStream_instances, sendErrorToSubscribers_fn).call(this, err);
|
|
1401
1365
|
}
|
|
1402
1366
|
__privateSet(this, _connected, false);
|
|
1403
|
-
(
|
|
1404
|
-
|
|
1367
|
+
(_d = __privateGet(this, _tickPromiseRejecter)) == null ? void 0 : _d.call(this);
|
|
1368
|
+
throw err;
|
|
1369
|
+
}
|
|
1370
|
+
__privateSet(this, _connected, false);
|
|
1371
|
+
(_e = __privateGet(this, _tickPromiseRejecter)) == null ? void 0 : _e.call(this);
|
|
1405
1372
|
};
|
|
1406
|
-
requestShape_fn = function() {
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1373
|
+
requestShape_fn = async function() {
|
|
1374
|
+
var _a, _b;
|
|
1375
|
+
if (__privateGet(this, _state) === `pause-requested`) {
|
|
1376
|
+
__privateSet(this, _state, `paused`);
|
|
1377
|
+
return;
|
|
1378
|
+
}
|
|
1379
|
+
if (!this.options.subscribe && (((_a = this.options.signal) == null ? void 0 : _a.aborted) || __privateGet(this, _isUpToDate))) {
|
|
1380
|
+
return;
|
|
1381
|
+
}
|
|
1382
|
+
const resumingFromPause = __privateGet(this, _state) === `paused`;
|
|
1383
|
+
__privateSet(this, _state, `active`);
|
|
1384
|
+
const { url, signal } = this.options;
|
|
1385
|
+
const { fetchUrl, requestHeaders } = await __privateMethod(this, _ShapeStream_instances, constructUrl_fn).call(this, url, resumingFromPause);
|
|
1386
|
+
const abortListener = await __privateMethod(this, _ShapeStream_instances, createAbortListener_fn).call(this, signal);
|
|
1387
|
+
const requestAbortController = __privateGet(this, _requestAbortController);
|
|
1388
|
+
try {
|
|
1389
|
+
await __privateMethod(this, _ShapeStream_instances, fetchShape_fn).call(this, {
|
|
1390
|
+
fetchUrl,
|
|
1391
|
+
requestAbortController,
|
|
1392
|
+
headers: requestHeaders,
|
|
1393
|
+
resumingFromPause
|
|
1394
|
+
});
|
|
1395
|
+
} catch (e) {
|
|
1396
|
+
if ((e instanceof FetchError || e instanceof FetchBackoffAbortError) && requestAbortController.signal.aborted && requestAbortController.signal.reason === FORCE_DISCONNECT_AND_REFRESH) {
|
|
1397
|
+
return __privateMethod(this, _ShapeStream_instances, requestShape_fn).call(this);
|
|
1412
1398
|
}
|
|
1413
|
-
if (
|
|
1399
|
+
if (e instanceof FetchBackoffAbortError) {
|
|
1400
|
+
const currentState = __privateGet(this, _state);
|
|
1401
|
+
if (requestAbortController.signal.aborted && requestAbortController.signal.reason === PAUSE_STREAM && currentState === `pause-requested`) {
|
|
1402
|
+
__privateSet(this, _state, `paused`);
|
|
1403
|
+
}
|
|
1414
1404
|
return;
|
|
1415
1405
|
}
|
|
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);
|
|
1406
|
+
if (!(e instanceof FetchError)) throw e;
|
|
1407
|
+
if (e.status == 409) {
|
|
1408
|
+
if (__privateGet(this, _shapeHandle)) {
|
|
1409
|
+
const shapeKey = canonicalShapeKey(fetchUrl);
|
|
1410
|
+
expiredShapesCache.markExpired(shapeKey, __privateGet(this, _shapeHandle));
|
|
1432
1411
|
}
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
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;
|
|
1452
|
-
}
|
|
1453
|
-
} finally {
|
|
1454
|
-
if (abortListener && signal) {
|
|
1455
|
-
signal.removeEventListener(`abort`, abortListener);
|
|
1456
|
-
}
|
|
1457
|
-
__privateSet(this, _requestAbortController, void 0);
|
|
1412
|
+
const newShapeHandle = e.headers[SHAPE_HANDLE_HEADER] || `${__privateGet(this, _shapeHandle)}-next`;
|
|
1413
|
+
__privateMethod(this, _ShapeStream_instances, reset_fn).call(this, newShapeHandle);
|
|
1414
|
+
await __privateMethod(this, _ShapeStream_instances, publish_fn).call(this, Array.isArray(e.json) ? e.json : [e.json]);
|
|
1415
|
+
return __privateMethod(this, _ShapeStream_instances, requestShape_fn).call(this);
|
|
1416
|
+
} else {
|
|
1417
|
+
throw e;
|
|
1458
1418
|
}
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1419
|
+
} finally {
|
|
1420
|
+
if (abortListener && signal) {
|
|
1421
|
+
signal.removeEventListener(`abort`, abortListener);
|
|
1422
|
+
}
|
|
1423
|
+
__privateSet(this, _requestAbortController, void 0);
|
|
1424
|
+
}
|
|
1425
|
+
(_b = __privateGet(this, _tickPromiseResolver)) == null ? void 0 : _b.call(this);
|
|
1426
|
+
return __privateMethod(this, _ShapeStream_instances, requestShape_fn).call(this);
|
|
1462
1427
|
};
|
|
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);
|
|
1428
|
+
constructUrl_fn = async function(url, resumingFromPause, subsetParams) {
|
|
1429
|
+
var _a, _b, _c, _d;
|
|
1430
|
+
const [requestHeaders, params] = await Promise.all([
|
|
1431
|
+
resolveHeaders(this.options.headers),
|
|
1432
|
+
this.options.params ? toInternalParams(convertWhereParamsToObj(this.options.params)) : void 0
|
|
1433
|
+
]);
|
|
1434
|
+
if (params) validateParams(params);
|
|
1435
|
+
const fetchUrl = new URL(url);
|
|
1436
|
+
if (params) {
|
|
1437
|
+
if (params.table) setQueryParam(fetchUrl, TABLE_QUERY_PARAM, params.table);
|
|
1438
|
+
if (params.where && typeof params.where === `string`) {
|
|
1439
|
+
const encodedWhere = encodeWhereClause(
|
|
1440
|
+
params.where,
|
|
1441
|
+
(_a = this.options.columnMapper) == null ? void 0 : _a.encode
|
|
1442
|
+
);
|
|
1443
|
+
setQueryParam(fetchUrl, WHERE_QUERY_PARAM, encodedWhere);
|
|
1444
|
+
}
|
|
1445
|
+
if (params.columns) {
|
|
1446
|
+
const originalColumns = await resolveValue((_b = this.options.params) == null ? void 0 : _b.columns);
|
|
1447
|
+
if (Array.isArray(originalColumns)) {
|
|
1448
|
+
let encodedColumns = originalColumns.map(String);
|
|
1449
|
+
if (this.options.columnMapper) {
|
|
1450
|
+
encodedColumns = encodedColumns.map(
|
|
1451
|
+
this.options.columnMapper.encode
|
|
1452
|
+
);
|
|
1494
1453
|
}
|
|
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);
|
|
1454
|
+
const serializedColumns = encodedColumns.map(quoteIdentifier).join(`,`);
|
|
1455
|
+
setQueryParam(fetchUrl, COLUMNS_QUERY_PARAM, serializedColumns);
|
|
1456
|
+
} else {
|
|
1457
|
+
setQueryParam(fetchUrl, COLUMNS_QUERY_PARAM, params.columns);
|
|
1507
1458
|
}
|
|
1508
1459
|
}
|
|
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
|
-
}
|
|
1460
|
+
if (params.replica) setQueryParam(fetchUrl, REPLICA_PARAM, params.replica);
|
|
1461
|
+
if (params.params)
|
|
1462
|
+
setQueryParam(fetchUrl, WHERE_PARAMS_PARAM, params.params);
|
|
1463
|
+
const customParams = __spreadValues({}, params);
|
|
1464
|
+
delete customParams.table;
|
|
1465
|
+
delete customParams.where;
|
|
1466
|
+
delete customParams.columns;
|
|
1467
|
+
delete customParams.replica;
|
|
1468
|
+
delete customParams.params;
|
|
1469
|
+
for (const [key, value] of Object.entries(customParams)) {
|
|
1470
|
+
setQueryParam(fetchUrl, key, value);
|
|
1533
1471
|
}
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
}
|
|
1541
|
-
fetchUrl.searchParams.set(
|
|
1542
|
-
LIVE_CACHE_BUSTER_QUERY_PARAM,
|
|
1543
|
-
__privateGet(this, _liveCacheBuster)
|
|
1472
|
+
}
|
|
1473
|
+
if (subsetParams) {
|
|
1474
|
+
if (subsetParams.where && typeof subsetParams.where === `string`) {
|
|
1475
|
+
const encodedWhere = encodeWhereClause(
|
|
1476
|
+
subsetParams.where,
|
|
1477
|
+
(_c = this.options.columnMapper) == null ? void 0 : _c.encode
|
|
1544
1478
|
);
|
|
1479
|
+
setQueryParam(fetchUrl, SUBSET_PARAM_WHERE, encodedWhere);
|
|
1545
1480
|
}
|
|
1546
|
-
if (
|
|
1547
|
-
fetchUrl.searchParams.set(
|
|
1481
|
+
if (subsetParams.params)
|
|
1482
|
+
fetchUrl.searchParams.set(
|
|
1483
|
+
SUBSET_PARAM_WHERE_PARAMS,
|
|
1484
|
+
JSON.stringify(subsetParams.params)
|
|
1485
|
+
);
|
|
1486
|
+
if (subsetParams.limit)
|
|
1487
|
+
setQueryParam(fetchUrl, SUBSET_PARAM_LIMIT, subsetParams.limit);
|
|
1488
|
+
if (subsetParams.offset)
|
|
1489
|
+
setQueryParam(fetchUrl, SUBSET_PARAM_OFFSET, subsetParams.offset);
|
|
1490
|
+
if (subsetParams.orderBy && typeof subsetParams.orderBy === `string`) {
|
|
1491
|
+
const encodedOrderBy = encodeWhereClause(
|
|
1492
|
+
subsetParams.orderBy,
|
|
1493
|
+
(_d = this.options.columnMapper) == null ? void 0 : _d.encode
|
|
1494
|
+
);
|
|
1495
|
+
setQueryParam(fetchUrl, SUBSET_PARAM_ORDER_BY, encodedOrderBy);
|
|
1548
1496
|
}
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1497
|
+
}
|
|
1498
|
+
fetchUrl.searchParams.set(OFFSET_QUERY_PARAM, __privateGet(this, _lastOffset));
|
|
1499
|
+
fetchUrl.searchParams.set(LOG_MODE_QUERY_PARAM, __privateGet(this, _mode));
|
|
1500
|
+
const isSnapshotRequest = subsetParams !== void 0;
|
|
1501
|
+
if (__privateGet(this, _isUpToDate) && !isSnapshotRequest) {
|
|
1502
|
+
if (!__privateGet(this, _isRefreshing) && !resumingFromPause) {
|
|
1503
|
+
fetchUrl.searchParams.set(LIVE_QUERY_PARAM, `true`);
|
|
1553
1504
|
}
|
|
1554
|
-
fetchUrl.searchParams.
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1505
|
+
fetchUrl.searchParams.set(
|
|
1506
|
+
LIVE_CACHE_BUSTER_QUERY_PARAM,
|
|
1507
|
+
__privateGet(this, _liveCacheBuster)
|
|
1508
|
+
);
|
|
1509
|
+
}
|
|
1510
|
+
if (__privateGet(this, _shapeHandle)) {
|
|
1511
|
+
fetchUrl.searchParams.set(SHAPE_HANDLE_QUERY_PARAM, __privateGet(this, _shapeHandle));
|
|
1512
|
+
}
|
|
1513
|
+
const shapeKey = canonicalShapeKey(fetchUrl);
|
|
1514
|
+
const expiredHandle = expiredShapesCache.getExpiredHandle(shapeKey);
|
|
1515
|
+
if (expiredHandle) {
|
|
1516
|
+
fetchUrl.searchParams.set(EXPIRED_HANDLE_QUERY_PARAM, expiredHandle);
|
|
1517
|
+
}
|
|
1518
|
+
fetchUrl.searchParams.sort();
|
|
1519
|
+
return {
|
|
1520
|
+
fetchUrl,
|
|
1521
|
+
requestHeaders
|
|
1522
|
+
};
|
|
1560
1523
|
};
|
|
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;
|
|
1524
|
+
createAbortListener_fn = async function(signal) {
|
|
1525
|
+
var _a;
|
|
1526
|
+
__privateSet(this, _requestAbortController, new AbortController());
|
|
1527
|
+
if (signal) {
|
|
1528
|
+
const abortListener = () => {
|
|
1529
|
+
var _a2;
|
|
1530
|
+
(_a2 = __privateGet(this, _requestAbortController)) == null ? void 0 : _a2.abort(signal.reason);
|
|
1531
|
+
};
|
|
1532
|
+
signal.addEventListener(`abort`, abortListener, { once: true });
|
|
1533
|
+
if (signal.aborted) {
|
|
1534
|
+
(_a = __privateGet(this, _requestAbortController)) == null ? void 0 : _a.abort(signal.reason);
|
|
1575
1535
|
}
|
|
1576
|
-
|
|
1536
|
+
return abortListener;
|
|
1537
|
+
}
|
|
1577
1538
|
};
|
|
1578
|
-
onInitialResponse_fn = function(response) {
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
}
|
|
1598
|
-
});
|
|
1539
|
+
onInitialResponse_fn = async function(response) {
|
|
1540
|
+
var _a;
|
|
1541
|
+
const { headers, status } = response;
|
|
1542
|
+
const shapeHandle = headers.get(SHAPE_HANDLE_HEADER);
|
|
1543
|
+
if (shapeHandle) {
|
|
1544
|
+
__privateSet(this, _shapeHandle, shapeHandle);
|
|
1545
|
+
}
|
|
1546
|
+
const lastOffset = headers.get(CHUNK_LAST_OFFSET_HEADER);
|
|
1547
|
+
if (lastOffset) {
|
|
1548
|
+
__privateSet(this, _lastOffset, lastOffset);
|
|
1549
|
+
}
|
|
1550
|
+
const liveCacheBuster = headers.get(LIVE_CACHE_BUSTER_HEADER);
|
|
1551
|
+
if (liveCacheBuster) {
|
|
1552
|
+
__privateSet(this, _liveCacheBuster, liveCacheBuster);
|
|
1553
|
+
}
|
|
1554
|
+
__privateSet(this, _schema, (_a = __privateGet(this, _schema)) != null ? _a : getSchemaFromHeaders(headers));
|
|
1555
|
+
if (status === 204) {
|
|
1556
|
+
__privateSet(this, _lastSyncedAt, Date.now());
|
|
1557
|
+
}
|
|
1599
1558
|
};
|
|
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));
|
|
1559
|
+
onMessages_fn = async function(batch, isSseMessage = false) {
|
|
1560
|
+
var _a;
|
|
1561
|
+
if (batch.length > 0) {
|
|
1562
|
+
__privateSet(this, _isMidStream, true);
|
|
1563
|
+
const lastMessage = batch[batch.length - 1];
|
|
1564
|
+
if (isUpToDateMessage(lastMessage)) {
|
|
1565
|
+
if (isSseMessage) {
|
|
1566
|
+
const offset = getOffset(lastMessage);
|
|
1567
|
+
if (offset) {
|
|
1568
|
+
__privateSet(this, _lastOffset, offset);
|
|
1627
1569
|
}
|
|
1628
1570
|
}
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1571
|
+
__privateSet(this, _lastSyncedAt, Date.now());
|
|
1572
|
+
__privateSet(this, _isUpToDate, true);
|
|
1573
|
+
__privateSet(this, _isMidStream, false);
|
|
1574
|
+
(_a = __privateGet(this, _midStreamPromiseResolver)) == null ? void 0 : _a.call(this);
|
|
1575
|
+
if (__privateGet(this, _ShapeStream_instances, replayMode_get) && !isSseMessage) {
|
|
1576
|
+
const currentCursor = __privateGet(this, _liveCacheBuster);
|
|
1577
|
+
if (currentCursor === __privateGet(this, _lastSeenCursor)) {
|
|
1578
|
+
return;
|
|
1632
1579
|
}
|
|
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);
|
|
1580
|
+
}
|
|
1581
|
+
__privateSet(this, _lastSeenCursor, void 0);
|
|
1582
|
+
if (__privateGet(this, _currentFetchUrl)) {
|
|
1583
|
+
const shapeKey = canonicalShapeKey(__privateGet(this, _currentFetchUrl));
|
|
1584
|
+
upToDateTracker.recordUpToDate(shapeKey, __privateGet(this, _liveCacheBuster));
|
|
1648
1585
|
}
|
|
1649
1586
|
}
|
|
1650
|
-
const
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
return
|
|
1587
|
+
const messagesToProcess = batch.filter((message) => {
|
|
1588
|
+
if (isChangeMessage(message)) {
|
|
1589
|
+
return !__privateGet(this, _snapshotTracker).shouldRejectMessage(message);
|
|
1590
|
+
}
|
|
1591
|
+
return true;
|
|
1592
|
+
});
|
|
1593
|
+
await __privateMethod(this, _ShapeStream_instances, publish_fn).call(this, messagesToProcess);
|
|
1594
|
+
}
|
|
1595
|
+
};
|
|
1596
|
+
fetchShape_fn = async function(opts) {
|
|
1597
|
+
var _a;
|
|
1598
|
+
__privateSet(this, _currentFetchUrl, opts.fetchUrl);
|
|
1599
|
+
if (!__privateGet(this, _isUpToDate) && !__privateGet(this, _ShapeStream_instances, replayMode_get)) {
|
|
1600
|
+
const shapeKey = canonicalShapeKey(opts.fetchUrl);
|
|
1601
|
+
const lastSeenCursor = upToDateTracker.shouldEnterReplayMode(shapeKey);
|
|
1602
|
+
if (lastSeenCursor) {
|
|
1603
|
+
__privateSet(this, _lastSeenCursor, lastSeenCursor);
|
|
1655
1604
|
}
|
|
1656
|
-
|
|
1657
|
-
|
|
1605
|
+
}
|
|
1606
|
+
const useSse = (_a = this.options.liveSse) != null ? _a : this.options.experimentalLiveSse;
|
|
1607
|
+
if (__privateGet(this, _isUpToDate) && useSse && !__privateGet(this, _isRefreshing) && !opts.resumingFromPause && !__privateGet(this, _sseFallbackToLongPolling)) {
|
|
1608
|
+
opts.fetchUrl.searchParams.set(EXPERIMENTAL_LIVE_SSE_QUERY_PARAM, `true`);
|
|
1609
|
+
opts.fetchUrl.searchParams.set(LIVE_SSE_QUERY_PARAM, `true`);
|
|
1610
|
+
return __privateMethod(this, _ShapeStream_instances, requestShapeSSE_fn).call(this, opts);
|
|
1611
|
+
}
|
|
1612
|
+
return __privateMethod(this, _ShapeStream_instances, requestShapeLongPoll_fn).call(this, opts);
|
|
1658
1613
|
};
|
|
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);
|
|
1614
|
+
requestShapeLongPoll_fn = async function(opts) {
|
|
1615
|
+
const { fetchUrl, requestAbortController, headers } = opts;
|
|
1616
|
+
const response = await __privateGet(this, _fetchClient2).call(this, fetchUrl.toString(), {
|
|
1617
|
+
signal: requestAbortController.signal,
|
|
1618
|
+
headers
|
|
1673
1619
|
});
|
|
1620
|
+
__privateSet(this, _connected, true);
|
|
1621
|
+
await __privateMethod(this, _ShapeStream_instances, onInitialResponse_fn).call(this, response);
|
|
1622
|
+
const schema = __privateGet(this, _schema);
|
|
1623
|
+
const res = await response.text();
|
|
1624
|
+
const messages = res || `[]`;
|
|
1625
|
+
const batch = __privateGet(this, _messageParser).parse(messages, schema);
|
|
1626
|
+
await __privateMethod(this, _ShapeStream_instances, onMessages_fn).call(this, batch);
|
|
1674
1627
|
};
|
|
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))
|
|
1628
|
+
requestShapeSSE_fn = async function(opts) {
|
|
1629
|
+
const { fetchUrl, requestAbortController, headers } = opts;
|
|
1630
|
+
const fetch2 = __privateGet(this, _sseFetchClient);
|
|
1631
|
+
__privateSet(this, _lastSseConnectionStartTime, Date.now());
|
|
1632
|
+
const sseHeaders = __spreadProps(__spreadValues({}, headers), {
|
|
1633
|
+
Accept: `text/event-stream`
|
|
1634
|
+
});
|
|
1635
|
+
try {
|
|
1636
|
+
let buffer = [];
|
|
1637
|
+
await fetchEventSource(fetchUrl.toString(), {
|
|
1638
|
+
headers: sseHeaders,
|
|
1639
|
+
fetch: fetch2,
|
|
1640
|
+
onopen: async (response) => {
|
|
1641
|
+
__privateSet(this, _connected, true);
|
|
1642
|
+
await __privateMethod(this, _ShapeStream_instances, onInitialResponse_fn).call(this, response);
|
|
1643
|
+
},
|
|
1644
|
+
onmessage: (event) => {
|
|
1645
|
+
if (event.data) {
|
|
1646
|
+
const schema = __privateGet(this, _schema);
|
|
1647
|
+
const message = __privateGet(this, _messageParser).parse(
|
|
1648
|
+
event.data,
|
|
1649
|
+
schema
|
|
1730
1650
|
);
|
|
1731
|
-
|
|
1732
|
-
|
|
1651
|
+
buffer.push(message);
|
|
1652
|
+
if (isUpToDateMessage(message)) {
|
|
1653
|
+
__privateMethod(this, _ShapeStream_instances, onMessages_fn).call(this, buffer, true);
|
|
1654
|
+
buffer = [];
|
|
1655
|
+
}
|
|
1733
1656
|
}
|
|
1734
|
-
}
|
|
1735
|
-
|
|
1657
|
+
},
|
|
1658
|
+
onerror: (error) => {
|
|
1659
|
+
throw error;
|
|
1660
|
+
},
|
|
1661
|
+
signal: requestAbortController.signal
|
|
1662
|
+
});
|
|
1663
|
+
} catch (error) {
|
|
1664
|
+
if (requestAbortController.signal.aborted) {
|
|
1665
|
+
throw new FetchBackoffAbortError();
|
|
1666
|
+
}
|
|
1667
|
+
throw error;
|
|
1668
|
+
} finally {
|
|
1669
|
+
const connectionDuration = Date.now() - __privateGet(this, _lastSseConnectionStartTime);
|
|
1670
|
+
const wasAborted = requestAbortController.signal.aborted;
|
|
1671
|
+
if (connectionDuration < __privateGet(this, _minSseConnectionDuration) && !wasAborted) {
|
|
1672
|
+
__privateWrapper(this, _consecutiveShortSseConnections)._++;
|
|
1673
|
+
if (__privateGet(this, _consecutiveShortSseConnections) >= __privateGet(this, _maxShortSseConnections)) {
|
|
1674
|
+
__privateSet(this, _sseFallbackToLongPolling, true);
|
|
1675
|
+
console.warn(
|
|
1676
|
+
`[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.`
|
|
1677
|
+
);
|
|
1678
|
+
} else {
|
|
1679
|
+
const maxDelay = Math.min(
|
|
1680
|
+
__privateGet(this, _sseBackoffMaxDelay),
|
|
1681
|
+
__privateGet(this, _sseBackoffBaseDelay) * Math.pow(2, __privateGet(this, _consecutiveShortSseConnections))
|
|
1682
|
+
);
|
|
1683
|
+
const delayMs = Math.floor(Math.random() * maxDelay);
|
|
1684
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
1736
1685
|
}
|
|
1686
|
+
} else if (connectionDuration >= __privateGet(this, _minSseConnectionDuration)) {
|
|
1687
|
+
__privateSet(this, _consecutiveShortSseConnections, 0);
|
|
1737
1688
|
}
|
|
1738
|
-
}
|
|
1689
|
+
}
|
|
1739
1690
|
};
|
|
1740
1691
|
pause_fn = function() {
|
|
1741
1692
|
var _a;
|
|
@@ -1745,65 +1696,63 @@ pause_fn = function() {
|
|
|
1745
1696
|
}
|
|
1746
1697
|
};
|
|
1747
1698
|
resume_fn = function() {
|
|
1699
|
+
var _a;
|
|
1748
1700
|
if (__privateGet(this, _started) && (__privateGet(this, _state) === `paused` || __privateGet(this, _state) === `pause-requested`)) {
|
|
1701
|
+
if ((_a = this.options.signal) == null ? void 0 : _a.aborted) {
|
|
1702
|
+
return;
|
|
1703
|
+
}
|
|
1749
1704
|
if (__privateGet(this, _state) === `pause-requested`) {
|
|
1750
1705
|
__privateSet(this, _state, `active`);
|
|
1751
1706
|
}
|
|
1752
1707
|
__privateMethod(this, _ShapeStream_instances, start_fn).call(this);
|
|
1753
1708
|
}
|
|
1754
1709
|
};
|
|
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
|
-
});
|
|
1710
|
+
nextTick_fn = async function() {
|
|
1711
|
+
if (__privateGet(this, _tickPromise)) {
|
|
1769
1712
|
return __privateGet(this, _tickPromise);
|
|
1713
|
+
}
|
|
1714
|
+
__privateSet(this, _tickPromise, new Promise((resolve, reject) => {
|
|
1715
|
+
__privateSet(this, _tickPromiseResolver, resolve);
|
|
1716
|
+
__privateSet(this, _tickPromiseRejecter, reject);
|
|
1717
|
+
}));
|
|
1718
|
+
__privateGet(this, _tickPromise).finally(() => {
|
|
1719
|
+
__privateSet(this, _tickPromise, void 0);
|
|
1720
|
+
__privateSet(this, _tickPromiseResolver, void 0);
|
|
1721
|
+
__privateSet(this, _tickPromiseRejecter, void 0);
|
|
1770
1722
|
});
|
|
1723
|
+
return __privateGet(this, _tickPromise);
|
|
1771
1724
|
};
|
|
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
|
-
});
|
|
1725
|
+
waitForStreamEnd_fn = async function() {
|
|
1726
|
+
if (!__privateGet(this, _isMidStream)) {
|
|
1727
|
+
return;
|
|
1728
|
+
}
|
|
1729
|
+
if (__privateGet(this, _midStreamPromise)) {
|
|
1787
1730
|
return __privateGet(this, _midStreamPromise);
|
|
1731
|
+
}
|
|
1732
|
+
__privateSet(this, _midStreamPromise, new Promise((resolve) => {
|
|
1733
|
+
__privateSet(this, _midStreamPromiseResolver, resolve);
|
|
1734
|
+
}));
|
|
1735
|
+
__privateGet(this, _midStreamPromise).finally(() => {
|
|
1736
|
+
__privateSet(this, _midStreamPromise, void 0);
|
|
1737
|
+
__privateSet(this, _midStreamPromiseResolver, void 0);
|
|
1788
1738
|
});
|
|
1739
|
+
return __privateGet(this, _midStreamPromise);
|
|
1789
1740
|
};
|
|
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
|
-
});
|
|
1741
|
+
publish_fn = async function(messages) {
|
|
1742
|
+
__privateSet(this, _messageChain, __privateGet(this, _messageChain).then(
|
|
1743
|
+
() => Promise.all(
|
|
1744
|
+
Array.from(__privateGet(this, _subscribers).values()).map(async ([callback, __]) => {
|
|
1745
|
+
try {
|
|
1746
|
+
await callback(messages);
|
|
1747
|
+
} catch (err) {
|
|
1748
|
+
queueMicrotask(() => {
|
|
1749
|
+
throw err;
|
|
1750
|
+
});
|
|
1751
|
+
}
|
|
1752
|
+
})
|
|
1753
|
+
)
|
|
1754
|
+
));
|
|
1755
|
+
return __privateGet(this, _messageChain);
|
|
1807
1756
|
};
|
|
1808
1757
|
sendErrorToSubscribers_fn = function(error) {
|
|
1809
1758
|
__privateGet(this, _subscribers).forEach(([_, errorFn]) => {
|
|
@@ -1975,13 +1924,11 @@ var Shape = class {
|
|
|
1975
1924
|
* Request a snapshot for subset of data. Only available when mode is changes_only.
|
|
1976
1925
|
* Returns void; data will be emitted via the stream and processed by this Shape.
|
|
1977
1926
|
*/
|
|
1978
|
-
requestSnapshot(params) {
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
yield this.stream.requestSnapshot(params);
|
|
1984
|
-
});
|
|
1927
|
+
async requestSnapshot(params) {
|
|
1928
|
+
const key = JSON.stringify(params);
|
|
1929
|
+
__privateGet(this, _requestedSubSnapshots).add(key);
|
|
1930
|
+
await __privateMethod(this, _Shape_instances, awaitUpToDate_fn).call(this);
|
|
1931
|
+
await this.stream.requestSnapshot(params);
|
|
1985
1932
|
}
|
|
1986
1933
|
subscribe(callback) {
|
|
1987
1934
|
const subscriptionId = Math.random();
|
|
@@ -2063,38 +2010,34 @@ process_fn = function(messages) {
|
|
|
2063
2010
|
});
|
|
2064
2011
|
if (shouldNotify) __privateMethod(this, _Shape_instances, notify_fn).call(this);
|
|
2065
2012
|
};
|
|
2066
|
-
reexecuteSnapshots_fn = function() {
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
);
|
|
2078
|
-
});
|
|
2013
|
+
reexecuteSnapshots_fn = async function() {
|
|
2014
|
+
await __privateMethod(this, _Shape_instances, awaitUpToDate_fn).call(this);
|
|
2015
|
+
await Promise.all(
|
|
2016
|
+
Array.from(__privateGet(this, _requestedSubSnapshots)).map(async (jsonParams) => {
|
|
2017
|
+
try {
|
|
2018
|
+
const snapshot = JSON.parse(jsonParams);
|
|
2019
|
+
await this.stream.requestSnapshot(snapshot);
|
|
2020
|
+
} catch (_) {
|
|
2021
|
+
}
|
|
2022
|
+
})
|
|
2023
|
+
);
|
|
2079
2024
|
};
|
|
2080
|
-
awaitUpToDate_fn = function() {
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
check();
|
|
2097
|
-
});
|
|
2025
|
+
awaitUpToDate_fn = async function() {
|
|
2026
|
+
if (this.stream.isUpToDate) return;
|
|
2027
|
+
await new Promise((resolve) => {
|
|
2028
|
+
const check = () => {
|
|
2029
|
+
if (this.stream.isUpToDate) {
|
|
2030
|
+
clearInterval(interval);
|
|
2031
|
+
unsub();
|
|
2032
|
+
resolve();
|
|
2033
|
+
}
|
|
2034
|
+
};
|
|
2035
|
+
const interval = setInterval(check, 10);
|
|
2036
|
+
const unsub = this.stream.subscribe(
|
|
2037
|
+
() => check(),
|
|
2038
|
+
() => check()
|
|
2039
|
+
);
|
|
2040
|
+
check();
|
|
2098
2041
|
});
|
|
2099
2042
|
};
|
|
2100
2043
|
updateShapeStatus_fn = function(status) {
|