@electric-sql/client 1.2.1 → 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 +524 -564
- 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 +39 -13
- package/dist/index.legacy-esm.js.map +1 -1
- package/dist/index.mjs +524 -564
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +35 -12
- package/src/column-mapper.ts +25 -0
- package/src/fetch.ts +14 -3
- package/src/helpers.ts +2 -4
- package/src/types.ts +9 -0
package/dist/cjs/index.cjs
CHANGED
|
@@ -61,26 +61,6 @@ var __privateWrapper = (obj, member, setter, getter) => ({
|
|
|
61
61
|
return __privateGet(obj, member, getter);
|
|
62
62
|
}
|
|
63
63
|
});
|
|
64
|
-
var __async = (__this, __arguments, generator) => {
|
|
65
|
-
return new Promise((resolve, reject) => {
|
|
66
|
-
var fulfilled = (value) => {
|
|
67
|
-
try {
|
|
68
|
-
step(generator.next(value));
|
|
69
|
-
} catch (e) {
|
|
70
|
-
reject(e);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
var rejected = (value) => {
|
|
74
|
-
try {
|
|
75
|
-
step(generator.throw(value));
|
|
76
|
-
} catch (e) {
|
|
77
|
-
reject(e);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
81
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
64
|
|
|
85
65
|
// src/index.ts
|
|
86
66
|
var src_exports = {};
|
|
@@ -114,22 +94,20 @@ var FetchError = class _FetchError extends Error {
|
|
|
114
94
|
this.json = json;
|
|
115
95
|
this.headers = headers;
|
|
116
96
|
}
|
|
117
|
-
static fromResponse(response, url) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
text = yield response.text();
|
|
129
|
-
}
|
|
97
|
+
static async fromResponse(response, url) {
|
|
98
|
+
const status = response.status;
|
|
99
|
+
const headers = Object.fromEntries([...response.headers.entries()]);
|
|
100
|
+
let text = void 0;
|
|
101
|
+
let json = void 0;
|
|
102
|
+
const contentType = response.headers.get(`content-type`);
|
|
103
|
+
if (!response.bodyUsed) {
|
|
104
|
+
if (contentType && contentType.includes(`application/json`)) {
|
|
105
|
+
json = await response.json();
|
|
106
|
+
} else {
|
|
107
|
+
text = await response.text();
|
|
130
108
|
}
|
|
131
|
-
|
|
132
|
-
|
|
109
|
+
}
|
|
110
|
+
return new _FetchError(status, text, json, headers, url);
|
|
133
111
|
}
|
|
134
112
|
};
|
|
135
113
|
var FetchBackoffAbortError = class extends Error {
|
|
@@ -327,6 +305,10 @@ function makeNullableParser(parser, columnInfo, columnName) {
|
|
|
327
305
|
}
|
|
328
306
|
|
|
329
307
|
// src/column-mapper.ts
|
|
308
|
+
function quoteIdentifier(identifier) {
|
|
309
|
+
const escaped = identifier.replace(/"/g, `""`);
|
|
310
|
+
return `"${escaped}"`;
|
|
311
|
+
}
|
|
330
312
|
function snakeToCamel(str) {
|
|
331
313
|
var _a, _b, _c, _d;
|
|
332
314
|
const leadingUnderscores = (_b = (_a = str.match(/^_+/)) == null ? void 0 : _a[0]) != null ? _b : ``;
|
|
@@ -482,11 +464,9 @@ function isUpToDateMessage(message) {
|
|
|
482
464
|
return isControlMessage(message) && message.headers.control === `up-to-date`;
|
|
483
465
|
}
|
|
484
466
|
function getOffset(message) {
|
|
467
|
+
if (message.headers.control != `up-to-date`) return;
|
|
485
468
|
const lsn = message.headers.global_last_seen_lsn;
|
|
486
|
-
|
|
487
|
-
return;
|
|
488
|
-
}
|
|
489
|
-
return `${lsn}_0`;
|
|
469
|
+
return lsn ? `${lsn}_0` : void 0;
|
|
490
470
|
}
|
|
491
471
|
function isVisibleInSnapshot(txid, snapshot) {
|
|
492
472
|
const xid = BigInt(txid);
|
|
@@ -569,7 +549,7 @@ function createFetchWithBackoff(fetchClient, backoffOptions = BackoffDefaults) {
|
|
|
569
549
|
onFailedAttempt,
|
|
570
550
|
maxRetries = Infinity
|
|
571
551
|
} = backoffOptions;
|
|
572
|
-
return (...args) =>
|
|
552
|
+
return async (...args) => {
|
|
573
553
|
var _a;
|
|
574
554
|
const url = args[0];
|
|
575
555
|
const options = args[1];
|
|
@@ -577,11 +557,11 @@ function createFetchWithBackoff(fetchClient, backoffOptions = BackoffDefaults) {
|
|
|
577
557
|
let attempt = 0;
|
|
578
558
|
while (true) {
|
|
579
559
|
try {
|
|
580
|
-
const result =
|
|
560
|
+
const result = await fetchClient(...args);
|
|
581
561
|
if (result.ok) {
|
|
582
562
|
return result;
|
|
583
563
|
}
|
|
584
|
-
const err =
|
|
564
|
+
const err = await FetchError.fromResponse(result, url.toString());
|
|
585
565
|
throw err;
|
|
586
566
|
} catch (e) {
|
|
587
567
|
onFailedAttempt == null ? void 0 : onFailedAttempt();
|
|
@@ -609,24 +589,24 @@ function createFetchWithBackoff(fetchClient, backoffOptions = BackoffDefaults) {
|
|
|
609
589
|
`Retry attempt #${attempt} after ${waitMs}ms (${source}, serverMin=${serverMinimumMs}ms, clientBackoff=${clientBackoffMs}ms)`
|
|
610
590
|
);
|
|
611
591
|
}
|
|
612
|
-
|
|
592
|
+
await new Promise((resolve) => setTimeout(resolve, waitMs));
|
|
613
593
|
delay = Math.min(delay * multiplier, maxDelay);
|
|
614
594
|
}
|
|
615
595
|
}
|
|
616
596
|
}
|
|
617
|
-
}
|
|
597
|
+
};
|
|
618
598
|
}
|
|
619
599
|
var NO_BODY_STATUS_CODES = [201, 204, 205];
|
|
620
600
|
function createFetchWithConsumedMessages(fetchClient) {
|
|
621
|
-
return (...args) =>
|
|
601
|
+
return async (...args) => {
|
|
622
602
|
var _a, _b;
|
|
623
603
|
const url = args[0];
|
|
624
|
-
const res =
|
|
604
|
+
const res = await fetchClient(...args);
|
|
625
605
|
try {
|
|
626
606
|
if (res.status < 200 || NO_BODY_STATUS_CODES.includes(res.status)) {
|
|
627
607
|
return res;
|
|
628
608
|
}
|
|
629
|
-
const text =
|
|
609
|
+
const text = await res.text();
|
|
630
610
|
return new Response(text, res);
|
|
631
611
|
} catch (err) {
|
|
632
612
|
if ((_b = (_a = args[1]) == null ? void 0 : _a.signal) == null ? void 0 : _b.aborted) {
|
|
@@ -641,7 +621,7 @@ function createFetchWithConsumedMessages(fetchClient) {
|
|
|
641
621
|
err instanceof Error ? err.message : typeof err === `string` ? err : `failed to read body`
|
|
642
622
|
);
|
|
643
623
|
}
|
|
644
|
-
}
|
|
624
|
+
};
|
|
645
625
|
}
|
|
646
626
|
var ChunkPrefetchDefaults = {
|
|
647
627
|
maxChunksToPrefetch: 2
|
|
@@ -649,14 +629,15 @@ var ChunkPrefetchDefaults = {
|
|
|
649
629
|
function createFetchWithChunkBuffer(fetchClient, prefetchOptions = ChunkPrefetchDefaults) {
|
|
650
630
|
const { maxChunksToPrefetch } = prefetchOptions;
|
|
651
631
|
let prefetchQueue;
|
|
652
|
-
const prefetchClient = (...args) =>
|
|
632
|
+
const prefetchClient = async (...args) => {
|
|
653
633
|
const url = args[0].toString();
|
|
654
634
|
const prefetchedRequest = prefetchQueue == null ? void 0 : prefetchQueue.consume(...args);
|
|
655
635
|
if (prefetchedRequest) {
|
|
656
636
|
return prefetchedRequest;
|
|
657
637
|
}
|
|
658
638
|
prefetchQueue == null ? void 0 : prefetchQueue.abort();
|
|
659
|
-
|
|
639
|
+
prefetchQueue = void 0;
|
|
640
|
+
const response = await fetchClient(...args);
|
|
660
641
|
const nextUrl = getNextChunkUrl(url, response);
|
|
661
642
|
if (nextUrl) {
|
|
662
643
|
prefetchQueue = new PrefetchQueue({
|
|
@@ -667,7 +648,7 @@ function createFetchWithChunkBuffer(fetchClient, prefetchOptions = ChunkPrefetch
|
|
|
667
648
|
});
|
|
668
649
|
}
|
|
669
650
|
return response;
|
|
670
|
-
}
|
|
651
|
+
};
|
|
671
652
|
return prefetchClient;
|
|
672
653
|
}
|
|
673
654
|
var requiredElectricResponseHeaders = [
|
|
@@ -677,8 +658,8 @@ var requiredElectricResponseHeaders = [
|
|
|
677
658
|
var requiredLiveResponseHeaders = [`electric-cursor`];
|
|
678
659
|
var requiredNonLiveResponseHeaders = [`electric-schema`];
|
|
679
660
|
function createFetchWithResponseHeadersCheck(fetchClient) {
|
|
680
|
-
return (...args) =>
|
|
681
|
-
const response =
|
|
661
|
+
return async (...args) => {
|
|
662
|
+
const response = await fetchClient(...args);
|
|
682
663
|
if (response.ok) {
|
|
683
664
|
const headers = response.headers;
|
|
684
665
|
const missingHeaders = [];
|
|
@@ -708,7 +689,7 @@ function createFetchWithResponseHeadersCheck(fetchClient) {
|
|
|
708
689
|
}
|
|
709
690
|
}
|
|
710
691
|
return response;
|
|
711
|
-
}
|
|
692
|
+
};
|
|
712
693
|
}
|
|
713
694
|
var _fetchClient, _maxPrefetchedRequests, _prefetchQueue, _queueHeadUrl, _queueTailUrl, _PrefetchQueue_instances, prefetch_fn;
|
|
714
695
|
var PrefetchQueue = class {
|
|
@@ -728,12 +709,17 @@ var PrefetchQueue = class {
|
|
|
728
709
|
}
|
|
729
710
|
abort() {
|
|
730
711
|
__privateGet(this, _prefetchQueue).forEach(([_, aborter]) => aborter.abort());
|
|
712
|
+
__privateGet(this, _prefetchQueue).clear();
|
|
731
713
|
}
|
|
732
714
|
consume(...args) {
|
|
733
|
-
var _a;
|
|
734
715
|
const url = args[0].toString();
|
|
735
|
-
const
|
|
736
|
-
if (!
|
|
716
|
+
const entry = __privateGet(this, _prefetchQueue).get(url);
|
|
717
|
+
if (!entry || url !== __privateGet(this, _queueHeadUrl)) return;
|
|
718
|
+
const [request, aborter] = entry;
|
|
719
|
+
if (aborter.signal.aborted) {
|
|
720
|
+
__privateGet(this, _prefetchQueue).delete(url);
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
737
723
|
__privateGet(this, _prefetchQueue).delete(url);
|
|
738
724
|
request.then((response) => {
|
|
739
725
|
const nextUrl = getNextChunkUrl(url, response);
|
|
@@ -1054,43 +1040,35 @@ var RESERVED_PARAMS = /* @__PURE__ */ new Set([
|
|
|
1054
1040
|
LIVE_QUERY_PARAM,
|
|
1055
1041
|
OFFSET_QUERY_PARAM
|
|
1056
1042
|
]);
|
|
1057
|
-
function resolveValue(value) {
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
return value;
|
|
1063
|
-
});
|
|
1043
|
+
async function resolveValue(value) {
|
|
1044
|
+
if (typeof value === `function`) {
|
|
1045
|
+
return value();
|
|
1046
|
+
}
|
|
1047
|
+
return value;
|
|
1064
1048
|
}
|
|
1065
|
-
function toInternalParams(params) {
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
);
|
|
1081
|
-
});
|
|
1049
|
+
async function toInternalParams(params) {
|
|
1050
|
+
const entries = Object.entries(params);
|
|
1051
|
+
const resolvedEntries = await Promise.all(
|
|
1052
|
+
entries.map(async ([key, value]) => {
|
|
1053
|
+
if (value === void 0) return [key, void 0];
|
|
1054
|
+
const resolvedValue = await resolveValue(value);
|
|
1055
|
+
return [
|
|
1056
|
+
key,
|
|
1057
|
+
Array.isArray(resolvedValue) ? resolvedValue.join(`,`) : resolvedValue
|
|
1058
|
+
];
|
|
1059
|
+
})
|
|
1060
|
+
);
|
|
1061
|
+
return Object.fromEntries(
|
|
1062
|
+
resolvedEntries.filter(([_, value]) => value !== void 0)
|
|
1063
|
+
);
|
|
1082
1064
|
}
|
|
1083
|
-
function resolveHeaders(headers) {
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
}))
|
|
1091
|
-
);
|
|
1092
|
-
return Object.fromEntries(resolvedEntries);
|
|
1093
|
-
});
|
|
1065
|
+
async function resolveHeaders(headers) {
|
|
1066
|
+
if (!headers) return {};
|
|
1067
|
+
const entries = Object.entries(headers);
|
|
1068
|
+
const resolvedEntries = await Promise.all(
|
|
1069
|
+
entries.map(async ([key, value]) => [key, await resolveValue(value)])
|
|
1070
|
+
);
|
|
1071
|
+
return Object.fromEntries(resolvedEntries);
|
|
1094
1072
|
}
|
|
1095
1073
|
function canonicalShapeKey(url) {
|
|
1096
1074
|
const cleanUrl = new URL(url.origin + url.pathname);
|
|
@@ -1252,16 +1230,14 @@ var ShapeStream = class {
|
|
|
1252
1230
|
* long polling, ensuring that the stream receives an up to date message with the
|
|
1253
1231
|
* latest LSN from Postgres at that point in time.
|
|
1254
1232
|
*/
|
|
1255
|
-
forceDisconnectAndRefresh() {
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
__privateSet(this, _isRefreshing, false);
|
|
1264
|
-
});
|
|
1233
|
+
async forceDisconnectAndRefresh() {
|
|
1234
|
+
var _a, _b;
|
|
1235
|
+
__privateSet(this, _isRefreshing, true);
|
|
1236
|
+
if (__privateGet(this, _isUpToDate) && !((_a = __privateGet(this, _requestAbortController)) == null ? void 0 : _a.signal.aborted)) {
|
|
1237
|
+
(_b = __privateGet(this, _requestAbortController)) == null ? void 0 : _b.abort(FORCE_DISCONNECT_AND_REFRESH);
|
|
1238
|
+
}
|
|
1239
|
+
await __privateMethod(this, _ShapeStream_instances, nextTick_fn).call(this);
|
|
1240
|
+
__privateSet(this, _isRefreshing, false);
|
|
1265
1241
|
}
|
|
1266
1242
|
/**
|
|
1267
1243
|
* Request a snapshot for subset of data and inject it into the subscribed data stream.
|
|
@@ -1277,40 +1253,39 @@ var ShapeStream = class {
|
|
|
1277
1253
|
* @param opts - The options for the snapshot request.
|
|
1278
1254
|
* @returns The metadata and the data for the snapshot.
|
|
1279
1255
|
*/
|
|
1280
|
-
requestSnapshot(opts) {
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1256
|
+
async requestSnapshot(opts) {
|
|
1257
|
+
if (__privateGet(this, _mode) === `full`) {
|
|
1258
|
+
throw new Error(
|
|
1259
|
+
`Snapshot requests are not supported in ${__privateGet(this, _mode)} mode, as the consumer is guaranteed to observe all data`
|
|
1260
|
+
);
|
|
1261
|
+
}
|
|
1262
|
+
if (!__privateGet(this, _started)) await __privateMethod(this, _ShapeStream_instances, start_fn).call(this);
|
|
1263
|
+
await __privateMethod(this, _ShapeStream_instances, waitForStreamEnd_fn).call(this);
|
|
1264
|
+
__privateWrapper(this, _activeSnapshotRequests)._++;
|
|
1265
|
+
try {
|
|
1266
|
+
if (__privateGet(this, _activeSnapshotRequests) === 1) {
|
|
1267
|
+
__privateMethod(this, _ShapeStream_instances, pause_fn).call(this);
|
|
1286
1268
|
}
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
data
|
|
1306
|
-
};
|
|
1307
|
-
} finally {
|
|
1308
|
-
__privateWrapper(this, _activeSnapshotRequests)._--;
|
|
1309
|
-
if (__privateGet(this, _activeSnapshotRequests) === 0) {
|
|
1310
|
-
__privateMethod(this, _ShapeStream_instances, resume_fn).call(this);
|
|
1311
|
-
}
|
|
1269
|
+
const { metadata, data } = await this.fetchSnapshot(opts);
|
|
1270
|
+
const dataWithEndBoundary = data.concat([
|
|
1271
|
+
{ headers: __spreadValues({ control: `snapshot-end` }, metadata) },
|
|
1272
|
+
{ headers: __spreadValues({ control: `subset-end` }, opts) }
|
|
1273
|
+
]);
|
|
1274
|
+
__privateGet(this, _snapshotTracker).addSnapshot(
|
|
1275
|
+
metadata,
|
|
1276
|
+
new Set(data.map((message) => message.key))
|
|
1277
|
+
);
|
|
1278
|
+
__privateMethod(this, _ShapeStream_instances, onMessages_fn).call(this, dataWithEndBoundary, false);
|
|
1279
|
+
return {
|
|
1280
|
+
metadata,
|
|
1281
|
+
data
|
|
1282
|
+
};
|
|
1283
|
+
} finally {
|
|
1284
|
+
__privateWrapper(this, _activeSnapshotRequests)._--;
|
|
1285
|
+
if (__privateGet(this, _activeSnapshotRequests) === 0) {
|
|
1286
|
+
__privateMethod(this, _ShapeStream_instances, resume_fn).call(this);
|
|
1312
1287
|
}
|
|
1313
|
-
}
|
|
1288
|
+
}
|
|
1314
1289
|
}
|
|
1315
1290
|
/**
|
|
1316
1291
|
* Fetch a snapshot for subset of data.
|
|
@@ -1319,36 +1294,34 @@ var ShapeStream = class {
|
|
|
1319
1294
|
* @param opts - The options for the snapshot request.
|
|
1320
1295
|
* @returns The metadata and the data for the snapshot.
|
|
1321
1296
|
*/
|
|
1322
|
-
fetchSnapshot(opts) {
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
fetchUrl.toString()
|
|
1336
|
-
);
|
|
1337
|
-
}
|
|
1338
|
-
const schema = (_a = __privateGet(this, _schema)) != null ? _a : getSchemaFromHeaders(response.headers, {
|
|
1339
|
-
required: true,
|
|
1340
|
-
url: fetchUrl.toString()
|
|
1341
|
-
});
|
|
1342
|
-
const { metadata, data: rawData } = yield response.json();
|
|
1343
|
-
const data = __privateGet(this, _messageParser).parseSnapshotData(
|
|
1344
|
-
rawData,
|
|
1345
|
-
schema
|
|
1297
|
+
async fetchSnapshot(opts) {
|
|
1298
|
+
var _a;
|
|
1299
|
+
const { fetchUrl, requestHeaders } = await __privateMethod(this, _ShapeStream_instances, constructUrl_fn).call(this, this.options.url, true, opts);
|
|
1300
|
+
const response = await __privateGet(this, _fetchClient2).call(this, fetchUrl.toString(), {
|
|
1301
|
+
headers: requestHeaders
|
|
1302
|
+
});
|
|
1303
|
+
if (!response.ok) {
|
|
1304
|
+
throw new FetchError(
|
|
1305
|
+
response.status,
|
|
1306
|
+
void 0,
|
|
1307
|
+
void 0,
|
|
1308
|
+
Object.fromEntries([...response.headers.entries()]),
|
|
1309
|
+
fetchUrl.toString()
|
|
1346
1310
|
);
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1311
|
+
}
|
|
1312
|
+
const schema = (_a = __privateGet(this, _schema)) != null ? _a : getSchemaFromHeaders(response.headers, {
|
|
1313
|
+
required: true,
|
|
1314
|
+
url: fetchUrl.toString()
|
|
1351
1315
|
});
|
|
1316
|
+
const { metadata, data: rawData } = await response.json();
|
|
1317
|
+
const data = __privateGet(this, _messageParser).parseSnapshotData(
|
|
1318
|
+
rawData,
|
|
1319
|
+
schema
|
|
1320
|
+
);
|
|
1321
|
+
return {
|
|
1322
|
+
metadata,
|
|
1323
|
+
data
|
|
1324
|
+
};
|
|
1352
1325
|
}
|
|
1353
1326
|
};
|
|
1354
1327
|
_error = new WeakMap();
|
|
@@ -1392,366 +1365,361 @@ _ShapeStream_instances = new WeakSet();
|
|
|
1392
1365
|
replayMode_get = function() {
|
|
1393
1366
|
return __privateGet(this, _lastSeenCursor) !== void 0;
|
|
1394
1367
|
};
|
|
1395
|
-
start_fn = function() {
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
if (retryOpts
|
|
1406
|
-
|
|
1407
|
-
this.options.params = __spreadValues(__spreadValues({}, (_a = this.options.params) != null ? _a : {}), retryOpts.params);
|
|
1408
|
-
}
|
|
1409
|
-
if (retryOpts.headers) {
|
|
1410
|
-
this.options.headers = __spreadValues(__spreadValues({}, (_b = this.options.headers) != null ? _b : {}), retryOpts.headers);
|
|
1411
|
-
}
|
|
1412
|
-
__privateSet(this, _error, null);
|
|
1413
|
-
__privateSet(this, _started, false);
|
|
1414
|
-
yield __privateMethod(this, _ShapeStream_instances, start_fn).call(this);
|
|
1415
|
-
return;
|
|
1368
|
+
start_fn = async function() {
|
|
1369
|
+
var _a, _b, _c, _d, _e;
|
|
1370
|
+
__privateSet(this, _started, true);
|
|
1371
|
+
try {
|
|
1372
|
+
await __privateMethod(this, _ShapeStream_instances, requestShape_fn).call(this);
|
|
1373
|
+
} catch (err) {
|
|
1374
|
+
__privateSet(this, _error, err);
|
|
1375
|
+
if (__privateGet(this, _onError)) {
|
|
1376
|
+
const retryOpts = await __privateGet(this, _onError).call(this, err);
|
|
1377
|
+
if (retryOpts && typeof retryOpts === `object`) {
|
|
1378
|
+
if (retryOpts.params) {
|
|
1379
|
+
this.options.params = __spreadValues(__spreadValues({}, (_a = this.options.params) != null ? _a : {}), retryOpts.params);
|
|
1416
1380
|
}
|
|
1417
|
-
if (
|
|
1418
|
-
|
|
1381
|
+
if (retryOpts.headers) {
|
|
1382
|
+
this.options.headers = __spreadValues(__spreadValues({}, (_b = this.options.headers) != null ? _b : {}), retryOpts.headers);
|
|
1419
1383
|
}
|
|
1420
|
-
__privateSet(this,
|
|
1421
|
-
(
|
|
1384
|
+
__privateSet(this, _error, null);
|
|
1385
|
+
__privateSet(this, _started, false);
|
|
1386
|
+
await __privateMethod(this, _ShapeStream_instances, start_fn).call(this);
|
|
1422
1387
|
return;
|
|
1423
1388
|
}
|
|
1424
1389
|
if (err instanceof Error) {
|
|
1425
1390
|
__privateMethod(this, _ShapeStream_instances, sendErrorToSubscribers_fn).call(this, err);
|
|
1426
1391
|
}
|
|
1427
1392
|
__privateSet(this, _connected, false);
|
|
1428
|
-
(
|
|
1429
|
-
|
|
1393
|
+
(_c = __privateGet(this, _tickPromiseRejecter)) == null ? void 0 : _c.call(this);
|
|
1394
|
+
return;
|
|
1395
|
+
}
|
|
1396
|
+
if (err instanceof Error) {
|
|
1397
|
+
__privateMethod(this, _ShapeStream_instances, sendErrorToSubscribers_fn).call(this, err);
|
|
1430
1398
|
}
|
|
1431
1399
|
__privateSet(this, _connected, false);
|
|
1432
|
-
(
|
|
1433
|
-
|
|
1400
|
+
(_d = __privateGet(this, _tickPromiseRejecter)) == null ? void 0 : _d.call(this);
|
|
1401
|
+
throw err;
|
|
1402
|
+
}
|
|
1403
|
+
__privateSet(this, _connected, false);
|
|
1404
|
+
(_e = __privateGet(this, _tickPromiseRejecter)) == null ? void 0 : _e.call(this);
|
|
1434
1405
|
};
|
|
1435
|
-
requestShape_fn = function() {
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1406
|
+
requestShape_fn = async function() {
|
|
1407
|
+
var _a, _b;
|
|
1408
|
+
if (__privateGet(this, _state) === `pause-requested`) {
|
|
1409
|
+
__privateSet(this, _state, `paused`);
|
|
1410
|
+
return;
|
|
1411
|
+
}
|
|
1412
|
+
if (!this.options.subscribe && (((_a = this.options.signal) == null ? void 0 : _a.aborted) || __privateGet(this, _isUpToDate))) {
|
|
1413
|
+
return;
|
|
1414
|
+
}
|
|
1415
|
+
const resumingFromPause = __privateGet(this, _state) === `paused`;
|
|
1416
|
+
__privateSet(this, _state, `active`);
|
|
1417
|
+
const { url, signal } = this.options;
|
|
1418
|
+
const { fetchUrl, requestHeaders } = await __privateMethod(this, _ShapeStream_instances, constructUrl_fn).call(this, url, resumingFromPause);
|
|
1419
|
+
const abortListener = await __privateMethod(this, _ShapeStream_instances, createAbortListener_fn).call(this, signal);
|
|
1420
|
+
const requestAbortController = __privateGet(this, _requestAbortController);
|
|
1421
|
+
try {
|
|
1422
|
+
await __privateMethod(this, _ShapeStream_instances, fetchShape_fn).call(this, {
|
|
1423
|
+
fetchUrl,
|
|
1424
|
+
requestAbortController,
|
|
1425
|
+
headers: requestHeaders,
|
|
1426
|
+
resumingFromPause
|
|
1427
|
+
});
|
|
1428
|
+
} catch (e) {
|
|
1429
|
+
if ((e instanceof FetchError || e instanceof FetchBackoffAbortError) && requestAbortController.signal.aborted && requestAbortController.signal.reason === FORCE_DISCONNECT_AND_REFRESH) {
|
|
1430
|
+
return __privateMethod(this, _ShapeStream_instances, requestShape_fn).call(this);
|
|
1441
1431
|
}
|
|
1442
|
-
if (
|
|
1432
|
+
if (e instanceof FetchBackoffAbortError) {
|
|
1433
|
+
const currentState = __privateGet(this, _state);
|
|
1434
|
+
if (requestAbortController.signal.aborted && requestAbortController.signal.reason === PAUSE_STREAM && currentState === `pause-requested`) {
|
|
1435
|
+
__privateSet(this, _state, `paused`);
|
|
1436
|
+
}
|
|
1443
1437
|
return;
|
|
1444
1438
|
}
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
const requestAbortController = __privateGet(this, _requestAbortController);
|
|
1451
|
-
try {
|
|
1452
|
-
yield __privateMethod(this, _ShapeStream_instances, fetchShape_fn).call(this, {
|
|
1453
|
-
fetchUrl,
|
|
1454
|
-
requestAbortController,
|
|
1455
|
-
headers: requestHeaders,
|
|
1456
|
-
resumingFromPause
|
|
1457
|
-
});
|
|
1458
|
-
} catch (e) {
|
|
1459
|
-
if ((e instanceof FetchError || e instanceof FetchBackoffAbortError) && requestAbortController.signal.aborted && requestAbortController.signal.reason === FORCE_DISCONNECT_AND_REFRESH) {
|
|
1460
|
-
return __privateMethod(this, _ShapeStream_instances, requestShape_fn).call(this);
|
|
1439
|
+
if (!(e instanceof FetchError)) throw e;
|
|
1440
|
+
if (e.status == 409) {
|
|
1441
|
+
if (__privateGet(this, _shapeHandle)) {
|
|
1442
|
+
const shapeKey = canonicalShapeKey(fetchUrl);
|
|
1443
|
+
expiredShapesCache.markExpired(shapeKey, __privateGet(this, _shapeHandle));
|
|
1461
1444
|
}
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
}
|
|
1469
|
-
if (!(e instanceof FetchError)) throw e;
|
|
1470
|
-
if (e.status == 409) {
|
|
1471
|
-
if (__privateGet(this, _shapeHandle)) {
|
|
1472
|
-
const shapeKey = canonicalShapeKey(fetchUrl);
|
|
1473
|
-
expiredShapesCache.markExpired(shapeKey, __privateGet(this, _shapeHandle));
|
|
1474
|
-
}
|
|
1475
|
-
const newShapeHandle = e.headers[SHAPE_HANDLE_HEADER] || `${__privateGet(this, _shapeHandle)}-next`;
|
|
1476
|
-
__privateMethod(this, _ShapeStream_instances, reset_fn).call(this, newShapeHandle);
|
|
1477
|
-
yield __privateMethod(this, _ShapeStream_instances, publish_fn).call(this, Array.isArray(e.json) ? e.json : [e.json]);
|
|
1478
|
-
return __privateMethod(this, _ShapeStream_instances, requestShape_fn).call(this);
|
|
1479
|
-
} else {
|
|
1480
|
-
throw e;
|
|
1481
|
-
}
|
|
1482
|
-
} finally {
|
|
1483
|
-
if (abortListener && signal) {
|
|
1484
|
-
signal.removeEventListener(`abort`, abortListener);
|
|
1485
|
-
}
|
|
1486
|
-
__privateSet(this, _requestAbortController, void 0);
|
|
1445
|
+
const newShapeHandle = e.headers[SHAPE_HANDLE_HEADER] || `${__privateGet(this, _shapeHandle)}-next`;
|
|
1446
|
+
__privateMethod(this, _ShapeStream_instances, reset_fn).call(this, newShapeHandle);
|
|
1447
|
+
await __privateMethod(this, _ShapeStream_instances, publish_fn).call(this, Array.isArray(e.json) ? e.json : [e.json]);
|
|
1448
|
+
return __privateMethod(this, _ShapeStream_instances, requestShape_fn).call(this);
|
|
1449
|
+
} else {
|
|
1450
|
+
throw e;
|
|
1487
1451
|
}
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1452
|
+
} finally {
|
|
1453
|
+
if (abortListener && signal) {
|
|
1454
|
+
signal.removeEventListener(`abort`, abortListener);
|
|
1455
|
+
}
|
|
1456
|
+
__privateSet(this, _requestAbortController, void 0);
|
|
1457
|
+
}
|
|
1458
|
+
(_b = __privateGet(this, _tickPromiseResolver)) == null ? void 0 : _b.call(this);
|
|
1459
|
+
return __privateMethod(this, _ShapeStream_instances, requestShape_fn).call(this);
|
|
1491
1460
|
};
|
|
1492
|
-
constructUrl_fn = function(url, resumingFromPause, subsetParams) {
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
if (params)
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1461
|
+
constructUrl_fn = async function(url, resumingFromPause, subsetParams) {
|
|
1462
|
+
var _a, _b, _c, _d;
|
|
1463
|
+
const [requestHeaders, params] = await Promise.all([
|
|
1464
|
+
resolveHeaders(this.options.headers),
|
|
1465
|
+
this.options.params ? toInternalParams(convertWhereParamsToObj(this.options.params)) : void 0
|
|
1466
|
+
]);
|
|
1467
|
+
if (params) validateParams(params);
|
|
1468
|
+
const fetchUrl = new URL(url);
|
|
1469
|
+
if (params) {
|
|
1470
|
+
if (params.table) setQueryParam(fetchUrl, TABLE_QUERY_PARAM, params.table);
|
|
1471
|
+
if (params.where && typeof params.where === `string`) {
|
|
1472
|
+
const encodedWhere = encodeWhereClause(
|
|
1473
|
+
params.where,
|
|
1474
|
+
(_a = this.options.columnMapper) == null ? void 0 : _a.encode
|
|
1475
|
+
);
|
|
1476
|
+
setQueryParam(fetchUrl, WHERE_QUERY_PARAM, encodedWhere);
|
|
1477
|
+
}
|
|
1478
|
+
if (params.columns) {
|
|
1479
|
+
const originalColumns = await resolveValue((_b = this.options.params) == null ? void 0 : _b.columns);
|
|
1480
|
+
if (Array.isArray(originalColumns)) {
|
|
1481
|
+
let encodedColumns = originalColumns.map(String);
|
|
1482
|
+
if (this.options.columnMapper) {
|
|
1483
|
+
encodedColumns = encodedColumns.map(
|
|
1484
|
+
this.options.columnMapper.encode
|
|
1485
|
+
);
|
|
1486
|
+
}
|
|
1487
|
+
const serializedColumns = encodedColumns.map(quoteIdentifier).join(`,`);
|
|
1488
|
+
setQueryParam(fetchUrl, COLUMNS_QUERY_PARAM, serializedColumns);
|
|
1489
|
+
} else {
|
|
1511
1490
|
setQueryParam(fetchUrl, COLUMNS_QUERY_PARAM, params.columns);
|
|
1512
|
-
if (params.replica) setQueryParam(fetchUrl, REPLICA_PARAM, params.replica);
|
|
1513
|
-
if (params.params)
|
|
1514
|
-
setQueryParam(fetchUrl, WHERE_PARAMS_PARAM, params.params);
|
|
1515
|
-
const customParams = __spreadValues({}, params);
|
|
1516
|
-
delete customParams.table;
|
|
1517
|
-
delete customParams.where;
|
|
1518
|
-
delete customParams.columns;
|
|
1519
|
-
delete customParams.replica;
|
|
1520
|
-
delete customParams.params;
|
|
1521
|
-
for (const [key, value] of Object.entries(customParams)) {
|
|
1522
|
-
setQueryParam(fetchUrl, key, value);
|
|
1523
1491
|
}
|
|
1524
1492
|
}
|
|
1525
|
-
if (
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
JSON.stringify(subsetParams.params)
|
|
1537
|
-
);
|
|
1538
|
-
if (subsetParams.limit)
|
|
1539
|
-
setQueryParam(fetchUrl, SUBSET_PARAM_LIMIT, subsetParams.limit);
|
|
1540
|
-
if (subsetParams.offset)
|
|
1541
|
-
setQueryParam(fetchUrl, SUBSET_PARAM_OFFSET, subsetParams.offset);
|
|
1542
|
-
if (subsetParams.orderBy && typeof subsetParams.orderBy === `string`) {
|
|
1543
|
-
const encodedOrderBy = encodeWhereClause(
|
|
1544
|
-
subsetParams.orderBy,
|
|
1545
|
-
(_c = this.options.columnMapper) == null ? void 0 : _c.encode
|
|
1546
|
-
);
|
|
1547
|
-
setQueryParam(fetchUrl, SUBSET_PARAM_ORDER_BY, encodedOrderBy);
|
|
1548
|
-
}
|
|
1493
|
+
if (params.replica) setQueryParam(fetchUrl, REPLICA_PARAM, params.replica);
|
|
1494
|
+
if (params.params)
|
|
1495
|
+
setQueryParam(fetchUrl, WHERE_PARAMS_PARAM, params.params);
|
|
1496
|
+
const customParams = __spreadValues({}, params);
|
|
1497
|
+
delete customParams.table;
|
|
1498
|
+
delete customParams.where;
|
|
1499
|
+
delete customParams.columns;
|
|
1500
|
+
delete customParams.replica;
|
|
1501
|
+
delete customParams.params;
|
|
1502
|
+
for (const [key, value] of Object.entries(customParams)) {
|
|
1503
|
+
setQueryParam(fetchUrl, key, value);
|
|
1549
1504
|
}
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
}
|
|
1557
|
-
fetchUrl.searchParams.set(
|
|
1558
|
-
LIVE_CACHE_BUSTER_QUERY_PARAM,
|
|
1559
|
-
__privateGet(this, _liveCacheBuster)
|
|
1505
|
+
}
|
|
1506
|
+
if (subsetParams) {
|
|
1507
|
+
if (subsetParams.where && typeof subsetParams.where === `string`) {
|
|
1508
|
+
const encodedWhere = encodeWhereClause(
|
|
1509
|
+
subsetParams.where,
|
|
1510
|
+
(_c = this.options.columnMapper) == null ? void 0 : _c.encode
|
|
1560
1511
|
);
|
|
1512
|
+
setQueryParam(fetchUrl, SUBSET_PARAM_WHERE, encodedWhere);
|
|
1561
1513
|
}
|
|
1562
|
-
if (
|
|
1563
|
-
fetchUrl.searchParams.set(
|
|
1514
|
+
if (subsetParams.params)
|
|
1515
|
+
fetchUrl.searchParams.set(
|
|
1516
|
+
SUBSET_PARAM_WHERE_PARAMS,
|
|
1517
|
+
JSON.stringify(subsetParams.params)
|
|
1518
|
+
);
|
|
1519
|
+
if (subsetParams.limit)
|
|
1520
|
+
setQueryParam(fetchUrl, SUBSET_PARAM_LIMIT, subsetParams.limit);
|
|
1521
|
+
if (subsetParams.offset)
|
|
1522
|
+
setQueryParam(fetchUrl, SUBSET_PARAM_OFFSET, subsetParams.offset);
|
|
1523
|
+
if (subsetParams.orderBy && typeof subsetParams.orderBy === `string`) {
|
|
1524
|
+
const encodedOrderBy = encodeWhereClause(
|
|
1525
|
+
subsetParams.orderBy,
|
|
1526
|
+
(_d = this.options.columnMapper) == null ? void 0 : _d.encode
|
|
1527
|
+
);
|
|
1528
|
+
setQueryParam(fetchUrl, SUBSET_PARAM_ORDER_BY, encodedOrderBy);
|
|
1564
1529
|
}
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1530
|
+
}
|
|
1531
|
+
fetchUrl.searchParams.set(OFFSET_QUERY_PARAM, __privateGet(this, _lastOffset));
|
|
1532
|
+
fetchUrl.searchParams.set(LOG_MODE_QUERY_PARAM, __privateGet(this, _mode));
|
|
1533
|
+
const isSnapshotRequest = subsetParams !== void 0;
|
|
1534
|
+
if (__privateGet(this, _isUpToDate) && !isSnapshotRequest) {
|
|
1535
|
+
if (!__privateGet(this, _isRefreshing) && !resumingFromPause) {
|
|
1536
|
+
fetchUrl.searchParams.set(LIVE_QUERY_PARAM, `true`);
|
|
1569
1537
|
}
|
|
1570
|
-
fetchUrl.searchParams.
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1538
|
+
fetchUrl.searchParams.set(
|
|
1539
|
+
LIVE_CACHE_BUSTER_QUERY_PARAM,
|
|
1540
|
+
__privateGet(this, _liveCacheBuster)
|
|
1541
|
+
);
|
|
1542
|
+
}
|
|
1543
|
+
if (__privateGet(this, _shapeHandle)) {
|
|
1544
|
+
fetchUrl.searchParams.set(SHAPE_HANDLE_QUERY_PARAM, __privateGet(this, _shapeHandle));
|
|
1545
|
+
}
|
|
1546
|
+
const shapeKey = canonicalShapeKey(fetchUrl);
|
|
1547
|
+
const expiredHandle = expiredShapesCache.getExpiredHandle(shapeKey);
|
|
1548
|
+
if (expiredHandle) {
|
|
1549
|
+
fetchUrl.searchParams.set(EXPIRED_HANDLE_QUERY_PARAM, expiredHandle);
|
|
1550
|
+
}
|
|
1551
|
+
fetchUrl.searchParams.sort();
|
|
1552
|
+
return {
|
|
1553
|
+
fetchUrl,
|
|
1554
|
+
requestHeaders
|
|
1555
|
+
};
|
|
1576
1556
|
};
|
|
1577
|
-
createAbortListener_fn = function(signal) {
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
(_a = __privateGet(this, _requestAbortController)) == null ? void 0 : _a.abort(signal.reason);
|
|
1589
|
-
}
|
|
1590
|
-
return abortListener;
|
|
1557
|
+
createAbortListener_fn = async function(signal) {
|
|
1558
|
+
var _a;
|
|
1559
|
+
__privateSet(this, _requestAbortController, new AbortController());
|
|
1560
|
+
if (signal) {
|
|
1561
|
+
const abortListener = () => {
|
|
1562
|
+
var _a2;
|
|
1563
|
+
(_a2 = __privateGet(this, _requestAbortController)) == null ? void 0 : _a2.abort(signal.reason);
|
|
1564
|
+
};
|
|
1565
|
+
signal.addEventListener(`abort`, abortListener, { once: true });
|
|
1566
|
+
if (signal.aborted) {
|
|
1567
|
+
(_a = __privateGet(this, _requestAbortController)) == null ? void 0 : _a.abort(signal.reason);
|
|
1591
1568
|
}
|
|
1592
|
-
|
|
1569
|
+
return abortListener;
|
|
1570
|
+
}
|
|
1593
1571
|
};
|
|
1594
|
-
onInitialResponse_fn = function(response) {
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
}
|
|
1614
|
-
});
|
|
1572
|
+
onInitialResponse_fn = async function(response) {
|
|
1573
|
+
var _a;
|
|
1574
|
+
const { headers, status } = response;
|
|
1575
|
+
const shapeHandle = headers.get(SHAPE_HANDLE_HEADER);
|
|
1576
|
+
if (shapeHandle) {
|
|
1577
|
+
__privateSet(this, _shapeHandle, shapeHandle);
|
|
1578
|
+
}
|
|
1579
|
+
const lastOffset = headers.get(CHUNK_LAST_OFFSET_HEADER);
|
|
1580
|
+
if (lastOffset) {
|
|
1581
|
+
__privateSet(this, _lastOffset, lastOffset);
|
|
1582
|
+
}
|
|
1583
|
+
const liveCacheBuster = headers.get(LIVE_CACHE_BUSTER_HEADER);
|
|
1584
|
+
if (liveCacheBuster) {
|
|
1585
|
+
__privateSet(this, _liveCacheBuster, liveCacheBuster);
|
|
1586
|
+
}
|
|
1587
|
+
__privateSet(this, _schema, (_a = __privateGet(this, _schema)) != null ? _a : getSchemaFromHeaders(headers));
|
|
1588
|
+
if (status === 204) {
|
|
1589
|
+
__privateSet(this, _lastSyncedAt, Date.now());
|
|
1590
|
+
}
|
|
1615
1591
|
};
|
|
1616
|
-
onMessages_fn = function(batch, isSseMessage = false) {
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
if (
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
__privateSet(this, _lastOffset, offset);
|
|
1627
|
-
}
|
|
1628
|
-
}
|
|
1629
|
-
__privateSet(this, _lastSyncedAt, Date.now());
|
|
1630
|
-
__privateSet(this, _isUpToDate, true);
|
|
1631
|
-
__privateSet(this, _isMidStream, false);
|
|
1632
|
-
(_a = __privateGet(this, _midStreamPromiseResolver)) == null ? void 0 : _a.call(this);
|
|
1633
|
-
if (__privateGet(this, _ShapeStream_instances, replayMode_get) && !isSseMessage) {
|
|
1634
|
-
const currentCursor = __privateGet(this, _liveCacheBuster);
|
|
1635
|
-
if (currentCursor === __privateGet(this, _lastSeenCursor)) {
|
|
1636
|
-
return;
|
|
1637
|
-
}
|
|
1638
|
-
}
|
|
1639
|
-
__privateSet(this, _lastSeenCursor, void 0);
|
|
1640
|
-
if (__privateGet(this, _currentFetchUrl)) {
|
|
1641
|
-
const shapeKey = canonicalShapeKey(__privateGet(this, _currentFetchUrl));
|
|
1642
|
-
upToDateTracker.recordUpToDate(shapeKey, __privateGet(this, _liveCacheBuster));
|
|
1592
|
+
onMessages_fn = async function(batch, isSseMessage = false) {
|
|
1593
|
+
var _a;
|
|
1594
|
+
if (batch.length > 0) {
|
|
1595
|
+
__privateSet(this, _isMidStream, true);
|
|
1596
|
+
const lastMessage = batch[batch.length - 1];
|
|
1597
|
+
if (isUpToDateMessage(lastMessage)) {
|
|
1598
|
+
if (isSseMessage) {
|
|
1599
|
+
const offset = getOffset(lastMessage);
|
|
1600
|
+
if (offset) {
|
|
1601
|
+
__privateSet(this, _lastOffset, offset);
|
|
1643
1602
|
}
|
|
1644
1603
|
}
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1604
|
+
__privateSet(this, _lastSyncedAt, Date.now());
|
|
1605
|
+
__privateSet(this, _isUpToDate, true);
|
|
1606
|
+
__privateSet(this, _isMidStream, false);
|
|
1607
|
+
(_a = __privateGet(this, _midStreamPromiseResolver)) == null ? void 0 : _a.call(this);
|
|
1608
|
+
if (__privateGet(this, _ShapeStream_instances, replayMode_get) && !isSseMessage) {
|
|
1609
|
+
const currentCursor = __privateGet(this, _liveCacheBuster);
|
|
1610
|
+
if (currentCursor === __privateGet(this, _lastSeenCursor)) {
|
|
1611
|
+
return;
|
|
1648
1612
|
}
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
};
|
|
1655
|
-
fetchShape_fn = function(opts) {
|
|
1656
|
-
return __async(this, null, function* () {
|
|
1657
|
-
var _a;
|
|
1658
|
-
__privateSet(this, _currentFetchUrl, opts.fetchUrl);
|
|
1659
|
-
if (!__privateGet(this, _isUpToDate) && !__privateGet(this, _ShapeStream_instances, replayMode_get)) {
|
|
1660
|
-
const shapeKey = canonicalShapeKey(opts.fetchUrl);
|
|
1661
|
-
const lastSeenCursor = upToDateTracker.shouldEnterReplayMode(shapeKey);
|
|
1662
|
-
if (lastSeenCursor) {
|
|
1663
|
-
__privateSet(this, _lastSeenCursor, lastSeenCursor);
|
|
1613
|
+
}
|
|
1614
|
+
__privateSet(this, _lastSeenCursor, void 0);
|
|
1615
|
+
if (__privateGet(this, _currentFetchUrl)) {
|
|
1616
|
+
const shapeKey = canonicalShapeKey(__privateGet(this, _currentFetchUrl));
|
|
1617
|
+
upToDateTracker.recordUpToDate(shapeKey, __privateGet(this, _liveCacheBuster));
|
|
1664
1618
|
}
|
|
1665
1619
|
}
|
|
1666
|
-
const
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
return
|
|
1620
|
+
const messagesToProcess = batch.filter((message) => {
|
|
1621
|
+
if (isChangeMessage(message)) {
|
|
1622
|
+
return !__privateGet(this, _snapshotTracker).shouldRejectMessage(message);
|
|
1623
|
+
}
|
|
1624
|
+
return true;
|
|
1625
|
+
});
|
|
1626
|
+
await __privateMethod(this, _ShapeStream_instances, publish_fn).call(this, messagesToProcess);
|
|
1627
|
+
}
|
|
1628
|
+
};
|
|
1629
|
+
fetchShape_fn = async function(opts) {
|
|
1630
|
+
var _a;
|
|
1631
|
+
__privateSet(this, _currentFetchUrl, opts.fetchUrl);
|
|
1632
|
+
if (!__privateGet(this, _isUpToDate) && !__privateGet(this, _ShapeStream_instances, replayMode_get)) {
|
|
1633
|
+
const shapeKey = canonicalShapeKey(opts.fetchUrl);
|
|
1634
|
+
const lastSeenCursor = upToDateTracker.shouldEnterReplayMode(shapeKey);
|
|
1635
|
+
if (lastSeenCursor) {
|
|
1636
|
+
__privateSet(this, _lastSeenCursor, lastSeenCursor);
|
|
1671
1637
|
}
|
|
1672
|
-
|
|
1673
|
-
|
|
1638
|
+
}
|
|
1639
|
+
const useSse = (_a = this.options.liveSse) != null ? _a : this.options.experimentalLiveSse;
|
|
1640
|
+
if (__privateGet(this, _isUpToDate) && useSse && !__privateGet(this, _isRefreshing) && !opts.resumingFromPause && !__privateGet(this, _sseFallbackToLongPolling)) {
|
|
1641
|
+
opts.fetchUrl.searchParams.set(EXPERIMENTAL_LIVE_SSE_QUERY_PARAM, `true`);
|
|
1642
|
+
opts.fetchUrl.searchParams.set(LIVE_SSE_QUERY_PARAM, `true`);
|
|
1643
|
+
return __privateMethod(this, _ShapeStream_instances, requestShapeSSE_fn).call(this, opts);
|
|
1644
|
+
}
|
|
1645
|
+
return __privateMethod(this, _ShapeStream_instances, requestShapeLongPoll_fn).call(this, opts);
|
|
1674
1646
|
};
|
|
1675
|
-
requestShapeLongPoll_fn = function(opts) {
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
headers
|
|
1681
|
-
});
|
|
1682
|
-
__privateSet(this, _connected, true);
|
|
1683
|
-
yield __privateMethod(this, _ShapeStream_instances, onInitialResponse_fn).call(this, response);
|
|
1684
|
-
const schema = __privateGet(this, _schema);
|
|
1685
|
-
const res = yield response.text();
|
|
1686
|
-
const messages = res || `[]`;
|
|
1687
|
-
const batch = __privateGet(this, _messageParser).parse(messages, schema);
|
|
1688
|
-
yield __privateMethod(this, _ShapeStream_instances, onMessages_fn).call(this, batch);
|
|
1647
|
+
requestShapeLongPoll_fn = async function(opts) {
|
|
1648
|
+
const { fetchUrl, requestAbortController, headers } = opts;
|
|
1649
|
+
const response = await __privateGet(this, _fetchClient2).call(this, fetchUrl.toString(), {
|
|
1650
|
+
signal: requestAbortController.signal,
|
|
1651
|
+
headers
|
|
1689
1652
|
});
|
|
1653
|
+
__privateSet(this, _connected, true);
|
|
1654
|
+
await __privateMethod(this, _ShapeStream_instances, onInitialResponse_fn).call(this, response);
|
|
1655
|
+
const schema = __privateGet(this, _schema);
|
|
1656
|
+
const res = await response.text();
|
|
1657
|
+
const messages = res || `[]`;
|
|
1658
|
+
const batch = __privateGet(this, _messageParser).parse(messages, schema);
|
|
1659
|
+
await __privateMethod(this, _ShapeStream_instances, onMessages_fn).call(this, batch);
|
|
1690
1660
|
};
|
|
1691
|
-
requestShapeSSE_fn = function(opts) {
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
schema
|
|
1714
|
-
);
|
|
1715
|
-
buffer.push(message);
|
|
1716
|
-
if (isUpToDateMessage(message)) {
|
|
1717
|
-
__privateMethod(this, _ShapeStream_instances, onMessages_fn).call(this, buffer, true);
|
|
1718
|
-
buffer = [];
|
|
1719
|
-
}
|
|
1720
|
-
}
|
|
1721
|
-
},
|
|
1722
|
-
onerror: (error) => {
|
|
1723
|
-
throw error;
|
|
1724
|
-
},
|
|
1725
|
-
signal: requestAbortController.signal
|
|
1726
|
-
});
|
|
1727
|
-
} catch (error) {
|
|
1728
|
-
if (requestAbortController.signal.aborted) {
|
|
1729
|
-
throw new FetchBackoffAbortError();
|
|
1730
|
-
}
|
|
1731
|
-
throw error;
|
|
1732
|
-
} finally {
|
|
1733
|
-
const connectionDuration = Date.now() - __privateGet(this, _lastSseConnectionStartTime);
|
|
1734
|
-
const wasAborted = requestAbortController.signal.aborted;
|
|
1735
|
-
if (connectionDuration < __privateGet(this, _minSseConnectionDuration) && !wasAborted) {
|
|
1736
|
-
__privateWrapper(this, _consecutiveShortSseConnections)._++;
|
|
1737
|
-
if (__privateGet(this, _consecutiveShortSseConnections) >= __privateGet(this, _maxShortSseConnections)) {
|
|
1738
|
-
__privateSet(this, _sseFallbackToLongPolling, true);
|
|
1739
|
-
console.warn(
|
|
1740
|
-
`[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.`
|
|
1741
|
-
);
|
|
1742
|
-
} else {
|
|
1743
|
-
const maxDelay = Math.min(
|
|
1744
|
-
__privateGet(this, _sseBackoffMaxDelay),
|
|
1745
|
-
__privateGet(this, _sseBackoffBaseDelay) * Math.pow(2, __privateGet(this, _consecutiveShortSseConnections))
|
|
1661
|
+
requestShapeSSE_fn = async function(opts) {
|
|
1662
|
+
const { fetchUrl, requestAbortController, headers } = opts;
|
|
1663
|
+
const fetch2 = __privateGet(this, _sseFetchClient);
|
|
1664
|
+
__privateSet(this, _lastSseConnectionStartTime, Date.now());
|
|
1665
|
+
const sseHeaders = __spreadProps(__spreadValues({}, headers), {
|
|
1666
|
+
Accept: `text/event-stream`
|
|
1667
|
+
});
|
|
1668
|
+
try {
|
|
1669
|
+
let buffer = [];
|
|
1670
|
+
await (0, import_fetch_event_source.fetchEventSource)(fetchUrl.toString(), {
|
|
1671
|
+
headers: sseHeaders,
|
|
1672
|
+
fetch: fetch2,
|
|
1673
|
+
onopen: async (response) => {
|
|
1674
|
+
__privateSet(this, _connected, true);
|
|
1675
|
+
await __privateMethod(this, _ShapeStream_instances, onInitialResponse_fn).call(this, response);
|
|
1676
|
+
},
|
|
1677
|
+
onmessage: (event) => {
|
|
1678
|
+
if (event.data) {
|
|
1679
|
+
const schema = __privateGet(this, _schema);
|
|
1680
|
+
const message = __privateGet(this, _messageParser).parse(
|
|
1681
|
+
event.data,
|
|
1682
|
+
schema
|
|
1746
1683
|
);
|
|
1747
|
-
|
|
1748
|
-
|
|
1684
|
+
buffer.push(message);
|
|
1685
|
+
if (isUpToDateMessage(message)) {
|
|
1686
|
+
__privateMethod(this, _ShapeStream_instances, onMessages_fn).call(this, buffer, true);
|
|
1687
|
+
buffer = [];
|
|
1688
|
+
}
|
|
1749
1689
|
}
|
|
1750
|
-
}
|
|
1751
|
-
|
|
1690
|
+
},
|
|
1691
|
+
onerror: (error) => {
|
|
1692
|
+
throw error;
|
|
1693
|
+
},
|
|
1694
|
+
signal: requestAbortController.signal
|
|
1695
|
+
});
|
|
1696
|
+
} catch (error) {
|
|
1697
|
+
if (requestAbortController.signal.aborted) {
|
|
1698
|
+
throw new FetchBackoffAbortError();
|
|
1699
|
+
}
|
|
1700
|
+
throw error;
|
|
1701
|
+
} finally {
|
|
1702
|
+
const connectionDuration = Date.now() - __privateGet(this, _lastSseConnectionStartTime);
|
|
1703
|
+
const wasAborted = requestAbortController.signal.aborted;
|
|
1704
|
+
if (connectionDuration < __privateGet(this, _minSseConnectionDuration) && !wasAborted) {
|
|
1705
|
+
__privateWrapper(this, _consecutiveShortSseConnections)._++;
|
|
1706
|
+
if (__privateGet(this, _consecutiveShortSseConnections) >= __privateGet(this, _maxShortSseConnections)) {
|
|
1707
|
+
__privateSet(this, _sseFallbackToLongPolling, true);
|
|
1708
|
+
console.warn(
|
|
1709
|
+
`[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.`
|
|
1710
|
+
);
|
|
1711
|
+
} else {
|
|
1712
|
+
const maxDelay = Math.min(
|
|
1713
|
+
__privateGet(this, _sseBackoffMaxDelay),
|
|
1714
|
+
__privateGet(this, _sseBackoffBaseDelay) * Math.pow(2, __privateGet(this, _consecutiveShortSseConnections))
|
|
1715
|
+
);
|
|
1716
|
+
const delayMs = Math.floor(Math.random() * maxDelay);
|
|
1717
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
1752
1718
|
}
|
|
1719
|
+
} else if (connectionDuration >= __privateGet(this, _minSseConnectionDuration)) {
|
|
1720
|
+
__privateSet(this, _consecutiveShortSseConnections, 0);
|
|
1753
1721
|
}
|
|
1754
|
-
}
|
|
1722
|
+
}
|
|
1755
1723
|
};
|
|
1756
1724
|
pause_fn = function() {
|
|
1757
1725
|
var _a;
|
|
@@ -1761,65 +1729,63 @@ pause_fn = function() {
|
|
|
1761
1729
|
}
|
|
1762
1730
|
};
|
|
1763
1731
|
resume_fn = function() {
|
|
1732
|
+
var _a;
|
|
1764
1733
|
if (__privateGet(this, _started) && (__privateGet(this, _state) === `paused` || __privateGet(this, _state) === `pause-requested`)) {
|
|
1734
|
+
if ((_a = this.options.signal) == null ? void 0 : _a.aborted) {
|
|
1735
|
+
return;
|
|
1736
|
+
}
|
|
1765
1737
|
if (__privateGet(this, _state) === `pause-requested`) {
|
|
1766
1738
|
__privateSet(this, _state, `active`);
|
|
1767
1739
|
}
|
|
1768
1740
|
__privateMethod(this, _ShapeStream_instances, start_fn).call(this);
|
|
1769
1741
|
}
|
|
1770
1742
|
};
|
|
1771
|
-
nextTick_fn = function() {
|
|
1772
|
-
|
|
1773
|
-
if (__privateGet(this, _tickPromise)) {
|
|
1774
|
-
return __privateGet(this, _tickPromise);
|
|
1775
|
-
}
|
|
1776
|
-
__privateSet(this, _tickPromise, new Promise((resolve, reject) => {
|
|
1777
|
-
__privateSet(this, _tickPromiseResolver, resolve);
|
|
1778
|
-
__privateSet(this, _tickPromiseRejecter, reject);
|
|
1779
|
-
}));
|
|
1780
|
-
__privateGet(this, _tickPromise).finally(() => {
|
|
1781
|
-
__privateSet(this, _tickPromise, void 0);
|
|
1782
|
-
__privateSet(this, _tickPromiseResolver, void 0);
|
|
1783
|
-
__privateSet(this, _tickPromiseRejecter, void 0);
|
|
1784
|
-
});
|
|
1743
|
+
nextTick_fn = async function() {
|
|
1744
|
+
if (__privateGet(this, _tickPromise)) {
|
|
1785
1745
|
return __privateGet(this, _tickPromise);
|
|
1746
|
+
}
|
|
1747
|
+
__privateSet(this, _tickPromise, new Promise((resolve, reject) => {
|
|
1748
|
+
__privateSet(this, _tickPromiseResolver, resolve);
|
|
1749
|
+
__privateSet(this, _tickPromiseRejecter, reject);
|
|
1750
|
+
}));
|
|
1751
|
+
__privateGet(this, _tickPromise).finally(() => {
|
|
1752
|
+
__privateSet(this, _tickPromise, void 0);
|
|
1753
|
+
__privateSet(this, _tickPromiseResolver, void 0);
|
|
1754
|
+
__privateSet(this, _tickPromiseRejecter, void 0);
|
|
1786
1755
|
});
|
|
1756
|
+
return __privateGet(this, _tickPromise);
|
|
1787
1757
|
};
|
|
1788
|
-
waitForStreamEnd_fn = function() {
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
if (__privateGet(this, _midStreamPromise)) {
|
|
1794
|
-
return __privateGet(this, _midStreamPromise);
|
|
1795
|
-
}
|
|
1796
|
-
__privateSet(this, _midStreamPromise, new Promise((resolve) => {
|
|
1797
|
-
__privateSet(this, _midStreamPromiseResolver, resolve);
|
|
1798
|
-
}));
|
|
1799
|
-
__privateGet(this, _midStreamPromise).finally(() => {
|
|
1800
|
-
__privateSet(this, _midStreamPromise, void 0);
|
|
1801
|
-
__privateSet(this, _midStreamPromiseResolver, void 0);
|
|
1802
|
-
});
|
|
1758
|
+
waitForStreamEnd_fn = async function() {
|
|
1759
|
+
if (!__privateGet(this, _isMidStream)) {
|
|
1760
|
+
return;
|
|
1761
|
+
}
|
|
1762
|
+
if (__privateGet(this, _midStreamPromise)) {
|
|
1803
1763
|
return __privateGet(this, _midStreamPromise);
|
|
1764
|
+
}
|
|
1765
|
+
__privateSet(this, _midStreamPromise, new Promise((resolve) => {
|
|
1766
|
+
__privateSet(this, _midStreamPromiseResolver, resolve);
|
|
1767
|
+
}));
|
|
1768
|
+
__privateGet(this, _midStreamPromise).finally(() => {
|
|
1769
|
+
__privateSet(this, _midStreamPromise, void 0);
|
|
1770
|
+
__privateSet(this, _midStreamPromiseResolver, void 0);
|
|
1804
1771
|
});
|
|
1772
|
+
return __privateGet(this, _midStreamPromise);
|
|
1805
1773
|
};
|
|
1806
|
-
publish_fn = function(messages) {
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
() =>
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
return __privateGet(this, _messageChain);
|
|
1822
|
-
});
|
|
1774
|
+
publish_fn = async function(messages) {
|
|
1775
|
+
__privateSet(this, _messageChain, __privateGet(this, _messageChain).then(
|
|
1776
|
+
() => Promise.all(
|
|
1777
|
+
Array.from(__privateGet(this, _subscribers).values()).map(async ([callback, __]) => {
|
|
1778
|
+
try {
|
|
1779
|
+
await callback(messages);
|
|
1780
|
+
} catch (err) {
|
|
1781
|
+
queueMicrotask(() => {
|
|
1782
|
+
throw err;
|
|
1783
|
+
});
|
|
1784
|
+
}
|
|
1785
|
+
})
|
|
1786
|
+
)
|
|
1787
|
+
));
|
|
1788
|
+
return __privateGet(this, _messageChain);
|
|
1823
1789
|
};
|
|
1824
1790
|
sendErrorToSubscribers_fn = function(error) {
|
|
1825
1791
|
__privateGet(this, _subscribers).forEach(([_, errorFn]) => {
|
|
@@ -1991,13 +1957,11 @@ var Shape = class {
|
|
|
1991
1957
|
* Request a snapshot for subset of data. Only available when mode is changes_only.
|
|
1992
1958
|
* Returns void; data will be emitted via the stream and processed by this Shape.
|
|
1993
1959
|
*/
|
|
1994
|
-
requestSnapshot(params) {
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
yield this.stream.requestSnapshot(params);
|
|
2000
|
-
});
|
|
1960
|
+
async requestSnapshot(params) {
|
|
1961
|
+
const key = JSON.stringify(params);
|
|
1962
|
+
__privateGet(this, _requestedSubSnapshots).add(key);
|
|
1963
|
+
await __privateMethod(this, _Shape_instances, awaitUpToDate_fn).call(this);
|
|
1964
|
+
await this.stream.requestSnapshot(params);
|
|
2001
1965
|
}
|
|
2002
1966
|
subscribe(callback) {
|
|
2003
1967
|
const subscriptionId = Math.random();
|
|
@@ -2079,38 +2043,34 @@ process_fn = function(messages) {
|
|
|
2079
2043
|
});
|
|
2080
2044
|
if (shouldNotify) __privateMethod(this, _Shape_instances, notify_fn).call(this);
|
|
2081
2045
|
};
|
|
2082
|
-
reexecuteSnapshots_fn = function() {
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
);
|
|
2094
|
-
});
|
|
2046
|
+
reexecuteSnapshots_fn = async function() {
|
|
2047
|
+
await __privateMethod(this, _Shape_instances, awaitUpToDate_fn).call(this);
|
|
2048
|
+
await Promise.all(
|
|
2049
|
+
Array.from(__privateGet(this, _requestedSubSnapshots)).map(async (jsonParams) => {
|
|
2050
|
+
try {
|
|
2051
|
+
const snapshot = JSON.parse(jsonParams);
|
|
2052
|
+
await this.stream.requestSnapshot(snapshot);
|
|
2053
|
+
} catch (_) {
|
|
2054
|
+
}
|
|
2055
|
+
})
|
|
2056
|
+
);
|
|
2095
2057
|
};
|
|
2096
|
-
awaitUpToDate_fn = function() {
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
check();
|
|
2113
|
-
});
|
|
2058
|
+
awaitUpToDate_fn = async function() {
|
|
2059
|
+
if (this.stream.isUpToDate) return;
|
|
2060
|
+
await new Promise((resolve) => {
|
|
2061
|
+
const check = () => {
|
|
2062
|
+
if (this.stream.isUpToDate) {
|
|
2063
|
+
clearInterval(interval);
|
|
2064
|
+
unsub();
|
|
2065
|
+
resolve();
|
|
2066
|
+
}
|
|
2067
|
+
};
|
|
2068
|
+
const interval = setInterval(check, 10);
|
|
2069
|
+
const unsub = this.stream.subscribe(
|
|
2070
|
+
() => check(),
|
|
2071
|
+
() => check()
|
|
2072
|
+
);
|
|
2073
|
+
check();
|
|
2114
2074
|
});
|
|
2115
2075
|
};
|
|
2116
2076
|
updateShapeStatus_fn = function(status) {
|