@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/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 {
|
|
@@ -292,6 +270,10 @@ function makeNullableParser(parser, columnInfo, columnName) {
|
|
|
292
270
|
}
|
|
293
271
|
|
|
294
272
|
// src/column-mapper.ts
|
|
273
|
+
function quoteIdentifier(identifier) {
|
|
274
|
+
const escaped = identifier.replace(/"/g, `""`);
|
|
275
|
+
return `"${escaped}"`;
|
|
276
|
+
}
|
|
295
277
|
function snakeToCamel(str) {
|
|
296
278
|
var _a, _b, _c, _d;
|
|
297
279
|
const leadingUnderscores = (_b = (_a = str.match(/^_+/)) == null ? void 0 : _a[0]) != null ? _b : ``;
|
|
@@ -447,11 +429,9 @@ function isUpToDateMessage(message) {
|
|
|
447
429
|
return isControlMessage(message) && message.headers.control === `up-to-date`;
|
|
448
430
|
}
|
|
449
431
|
function getOffset(message) {
|
|
432
|
+
if (message.headers.control != `up-to-date`) return;
|
|
450
433
|
const lsn = message.headers.global_last_seen_lsn;
|
|
451
|
-
|
|
452
|
-
return;
|
|
453
|
-
}
|
|
454
|
-
return `${lsn}_0`;
|
|
434
|
+
return lsn ? `${lsn}_0` : void 0;
|
|
455
435
|
}
|
|
456
436
|
function isVisibleInSnapshot(txid, snapshot) {
|
|
457
437
|
const xid = BigInt(txid);
|
|
@@ -534,7 +514,7 @@ function createFetchWithBackoff(fetchClient, backoffOptions = BackoffDefaults) {
|
|
|
534
514
|
onFailedAttempt,
|
|
535
515
|
maxRetries = Infinity
|
|
536
516
|
} = backoffOptions;
|
|
537
|
-
return (...args) =>
|
|
517
|
+
return async (...args) => {
|
|
538
518
|
var _a;
|
|
539
519
|
const url = args[0];
|
|
540
520
|
const options = args[1];
|
|
@@ -542,11 +522,11 @@ function createFetchWithBackoff(fetchClient, backoffOptions = BackoffDefaults) {
|
|
|
542
522
|
let attempt = 0;
|
|
543
523
|
while (true) {
|
|
544
524
|
try {
|
|
545
|
-
const result =
|
|
525
|
+
const result = await fetchClient(...args);
|
|
546
526
|
if (result.ok) {
|
|
547
527
|
return result;
|
|
548
528
|
}
|
|
549
|
-
const err =
|
|
529
|
+
const err = await FetchError.fromResponse(result, url.toString());
|
|
550
530
|
throw err;
|
|
551
531
|
} catch (e) {
|
|
552
532
|
onFailedAttempt == null ? void 0 : onFailedAttempt();
|
|
@@ -574,24 +554,24 @@ function createFetchWithBackoff(fetchClient, backoffOptions = BackoffDefaults) {
|
|
|
574
554
|
`Retry attempt #${attempt} after ${waitMs}ms (${source}, serverMin=${serverMinimumMs}ms, clientBackoff=${clientBackoffMs}ms)`
|
|
575
555
|
);
|
|
576
556
|
}
|
|
577
|
-
|
|
557
|
+
await new Promise((resolve) => setTimeout(resolve, waitMs));
|
|
578
558
|
delay = Math.min(delay * multiplier, maxDelay);
|
|
579
559
|
}
|
|
580
560
|
}
|
|
581
561
|
}
|
|
582
|
-
}
|
|
562
|
+
};
|
|
583
563
|
}
|
|
584
564
|
var NO_BODY_STATUS_CODES = [201, 204, 205];
|
|
585
565
|
function createFetchWithConsumedMessages(fetchClient) {
|
|
586
|
-
return (...args) =>
|
|
566
|
+
return async (...args) => {
|
|
587
567
|
var _a, _b;
|
|
588
568
|
const url = args[0];
|
|
589
|
-
const res =
|
|
569
|
+
const res = await fetchClient(...args);
|
|
590
570
|
try {
|
|
591
571
|
if (res.status < 200 || NO_BODY_STATUS_CODES.includes(res.status)) {
|
|
592
572
|
return res;
|
|
593
573
|
}
|
|
594
|
-
const text =
|
|
574
|
+
const text = await res.text();
|
|
595
575
|
return new Response(text, res);
|
|
596
576
|
} catch (err) {
|
|
597
577
|
if ((_b = (_a = args[1]) == null ? void 0 : _a.signal) == null ? void 0 : _b.aborted) {
|
|
@@ -606,7 +586,7 @@ function createFetchWithConsumedMessages(fetchClient) {
|
|
|
606
586
|
err instanceof Error ? err.message : typeof err === `string` ? err : `failed to read body`
|
|
607
587
|
);
|
|
608
588
|
}
|
|
609
|
-
}
|
|
589
|
+
};
|
|
610
590
|
}
|
|
611
591
|
var ChunkPrefetchDefaults = {
|
|
612
592
|
maxChunksToPrefetch: 2
|
|
@@ -614,14 +594,15 @@ var ChunkPrefetchDefaults = {
|
|
|
614
594
|
function createFetchWithChunkBuffer(fetchClient, prefetchOptions = ChunkPrefetchDefaults) {
|
|
615
595
|
const { maxChunksToPrefetch } = prefetchOptions;
|
|
616
596
|
let prefetchQueue;
|
|
617
|
-
const prefetchClient = (...args) =>
|
|
597
|
+
const prefetchClient = async (...args) => {
|
|
618
598
|
const url = args[0].toString();
|
|
619
599
|
const prefetchedRequest = prefetchQueue == null ? void 0 : prefetchQueue.consume(...args);
|
|
620
600
|
if (prefetchedRequest) {
|
|
621
601
|
return prefetchedRequest;
|
|
622
602
|
}
|
|
623
603
|
prefetchQueue == null ? void 0 : prefetchQueue.abort();
|
|
624
|
-
|
|
604
|
+
prefetchQueue = void 0;
|
|
605
|
+
const response = await fetchClient(...args);
|
|
625
606
|
const nextUrl = getNextChunkUrl(url, response);
|
|
626
607
|
if (nextUrl) {
|
|
627
608
|
prefetchQueue = new PrefetchQueue({
|
|
@@ -632,7 +613,7 @@ function createFetchWithChunkBuffer(fetchClient, prefetchOptions = ChunkPrefetch
|
|
|
632
613
|
});
|
|
633
614
|
}
|
|
634
615
|
return response;
|
|
635
|
-
}
|
|
616
|
+
};
|
|
636
617
|
return prefetchClient;
|
|
637
618
|
}
|
|
638
619
|
var requiredElectricResponseHeaders = [
|
|
@@ -642,8 +623,8 @@ var requiredElectricResponseHeaders = [
|
|
|
642
623
|
var requiredLiveResponseHeaders = [`electric-cursor`];
|
|
643
624
|
var requiredNonLiveResponseHeaders = [`electric-schema`];
|
|
644
625
|
function createFetchWithResponseHeadersCheck(fetchClient) {
|
|
645
|
-
return (...args) =>
|
|
646
|
-
const response =
|
|
626
|
+
return async (...args) => {
|
|
627
|
+
const response = await fetchClient(...args);
|
|
647
628
|
if (response.ok) {
|
|
648
629
|
const headers = response.headers;
|
|
649
630
|
const missingHeaders = [];
|
|
@@ -673,7 +654,7 @@ function createFetchWithResponseHeadersCheck(fetchClient) {
|
|
|
673
654
|
}
|
|
674
655
|
}
|
|
675
656
|
return response;
|
|
676
|
-
}
|
|
657
|
+
};
|
|
677
658
|
}
|
|
678
659
|
var _fetchClient, _maxPrefetchedRequests, _prefetchQueue, _queueHeadUrl, _queueTailUrl, _PrefetchQueue_instances, prefetch_fn;
|
|
679
660
|
var PrefetchQueue = class {
|
|
@@ -693,12 +674,17 @@ var PrefetchQueue = class {
|
|
|
693
674
|
}
|
|
694
675
|
abort() {
|
|
695
676
|
__privateGet(this, _prefetchQueue).forEach(([_, aborter]) => aborter.abort());
|
|
677
|
+
__privateGet(this, _prefetchQueue).clear();
|
|
696
678
|
}
|
|
697
679
|
consume(...args) {
|
|
698
|
-
var _a;
|
|
699
680
|
const url = args[0].toString();
|
|
700
|
-
const
|
|
701
|
-
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
|
+
}
|
|
702
688
|
__privateGet(this, _prefetchQueue).delete(url);
|
|
703
689
|
request.then((response) => {
|
|
704
690
|
const nextUrl = getNextChunkUrl(url, response);
|
|
@@ -1021,43 +1007,35 @@ var RESERVED_PARAMS = /* @__PURE__ */ new Set([
|
|
|
1021
1007
|
LIVE_QUERY_PARAM,
|
|
1022
1008
|
OFFSET_QUERY_PARAM
|
|
1023
1009
|
]);
|
|
1024
|
-
function resolveValue(value) {
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
return value;
|
|
1030
|
-
});
|
|
1010
|
+
async function resolveValue(value) {
|
|
1011
|
+
if (typeof value === `function`) {
|
|
1012
|
+
return value();
|
|
1013
|
+
}
|
|
1014
|
+
return value;
|
|
1031
1015
|
}
|
|
1032
|
-
function toInternalParams(params) {
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
);
|
|
1048
|
-
});
|
|
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
|
+
);
|
|
1049
1031
|
}
|
|
1050
|
-
function resolveHeaders(headers) {
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
}))
|
|
1058
|
-
);
|
|
1059
|
-
return Object.fromEntries(resolvedEntries);
|
|
1060
|
-
});
|
|
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);
|
|
1061
1039
|
}
|
|
1062
1040
|
function canonicalShapeKey(url) {
|
|
1063
1041
|
const cleanUrl = new URL(url.origin + url.pathname);
|
|
@@ -1219,16 +1197,14 @@ var ShapeStream = class {
|
|
|
1219
1197
|
* long polling, ensuring that the stream receives an up to date message with the
|
|
1220
1198
|
* latest LSN from Postgres at that point in time.
|
|
1221
1199
|
*/
|
|
1222
|
-
forceDisconnectAndRefresh() {
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
__privateSet(this, _isRefreshing, false);
|
|
1231
|
-
});
|
|
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);
|
|
1232
1208
|
}
|
|
1233
1209
|
/**
|
|
1234
1210
|
* Request a snapshot for subset of data and inject it into the subscribed data stream.
|
|
@@ -1244,40 +1220,39 @@ var ShapeStream = class {
|
|
|
1244
1220
|
* @param opts - The options for the snapshot request.
|
|
1245
1221
|
* @returns The metadata and the data for the snapshot.
|
|
1246
1222
|
*/
|
|
1247
|
-
requestSnapshot(opts) {
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
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);
|
|
1253
1235
|
}
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
data
|
|
1273
|
-
};
|
|
1274
|
-
} finally {
|
|
1275
|
-
__privateWrapper(this, _activeSnapshotRequests)._--;
|
|
1276
|
-
if (__privateGet(this, _activeSnapshotRequests) === 0) {
|
|
1277
|
-
__privateMethod(this, _ShapeStream_instances, resume_fn).call(this);
|
|
1278
|
-
}
|
|
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);
|
|
1279
1254
|
}
|
|
1280
|
-
}
|
|
1255
|
+
}
|
|
1281
1256
|
}
|
|
1282
1257
|
/**
|
|
1283
1258
|
* Fetch a snapshot for subset of data.
|
|
@@ -1286,36 +1261,34 @@ var ShapeStream = class {
|
|
|
1286
1261
|
* @param opts - The options for the snapshot request.
|
|
1287
1262
|
* @returns The metadata and the data for the snapshot.
|
|
1288
1263
|
*/
|
|
1289
|
-
fetchSnapshot(opts) {
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
fetchUrl.toString()
|
|
1303
|
-
);
|
|
1304
|
-
}
|
|
1305
|
-
const schema = (_a = __privateGet(this, _schema)) != null ? _a : getSchemaFromHeaders(response.headers, {
|
|
1306
|
-
required: true,
|
|
1307
|
-
url: fetchUrl.toString()
|
|
1308
|
-
});
|
|
1309
|
-
const { metadata, data: rawData } = yield response.json();
|
|
1310
|
-
const data = __privateGet(this, _messageParser).parseSnapshotData(
|
|
1311
|
-
rawData,
|
|
1312
|
-
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()
|
|
1313
1277
|
);
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1278
|
+
}
|
|
1279
|
+
const schema = (_a = __privateGet(this, _schema)) != null ? _a : getSchemaFromHeaders(response.headers, {
|
|
1280
|
+
required: true,
|
|
1281
|
+
url: fetchUrl.toString()
|
|
1318
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
|
+
};
|
|
1319
1292
|
}
|
|
1320
1293
|
};
|
|
1321
1294
|
_error = new WeakMap();
|
|
@@ -1359,366 +1332,361 @@ _ShapeStream_instances = new WeakSet();
|
|
|
1359
1332
|
replayMode_get = function() {
|
|
1360
1333
|
return __privateGet(this, _lastSeenCursor) !== void 0;
|
|
1361
1334
|
};
|
|
1362
|
-
start_fn = function() {
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
if (retryOpts
|
|
1373
|
-
|
|
1374
|
-
this.options.params = __spreadValues(__spreadValues({}, (_a = this.options.params) != null ? _a : {}), retryOpts.params);
|
|
1375
|
-
}
|
|
1376
|
-
if (retryOpts.headers) {
|
|
1377
|
-
this.options.headers = __spreadValues(__spreadValues({}, (_b = this.options.headers) != null ? _b : {}), retryOpts.headers);
|
|
1378
|
-
}
|
|
1379
|
-
__privateSet(this, _error, null);
|
|
1380
|
-
__privateSet(this, _started, false);
|
|
1381
|
-
yield __privateMethod(this, _ShapeStream_instances, start_fn).call(this);
|
|
1382
|
-
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);
|
|
1383
1347
|
}
|
|
1384
|
-
if (
|
|
1385
|
-
|
|
1348
|
+
if (retryOpts.headers) {
|
|
1349
|
+
this.options.headers = __spreadValues(__spreadValues({}, (_b = this.options.headers) != null ? _b : {}), retryOpts.headers);
|
|
1386
1350
|
}
|
|
1387
|
-
__privateSet(this,
|
|
1388
|
-
(
|
|
1351
|
+
__privateSet(this, _error, null);
|
|
1352
|
+
__privateSet(this, _started, false);
|
|
1353
|
+
await __privateMethod(this, _ShapeStream_instances, start_fn).call(this);
|
|
1389
1354
|
return;
|
|
1390
1355
|
}
|
|
1391
1356
|
if (err instanceof Error) {
|
|
1392
1357
|
__privateMethod(this, _ShapeStream_instances, sendErrorToSubscribers_fn).call(this, err);
|
|
1393
1358
|
}
|
|
1394
1359
|
__privateSet(this, _connected, false);
|
|
1395
|
-
(
|
|
1396
|
-
|
|
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);
|
|
1397
1365
|
}
|
|
1398
1366
|
__privateSet(this, _connected, false);
|
|
1399
|
-
(
|
|
1400
|
-
|
|
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);
|
|
1401
1372
|
};
|
|
1402
|
-
requestShape_fn = function() {
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
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);
|
|
1408
1398
|
}
|
|
1409
|
-
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
|
+
}
|
|
1410
1404
|
return;
|
|
1411
1405
|
}
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
const requestAbortController = __privateGet(this, _requestAbortController);
|
|
1418
|
-
try {
|
|
1419
|
-
yield __privateMethod(this, _ShapeStream_instances, fetchShape_fn).call(this, {
|
|
1420
|
-
fetchUrl,
|
|
1421
|
-
requestAbortController,
|
|
1422
|
-
headers: requestHeaders,
|
|
1423
|
-
resumingFromPause
|
|
1424
|
-
});
|
|
1425
|
-
} catch (e) {
|
|
1426
|
-
if ((e instanceof FetchError || e instanceof FetchBackoffAbortError) && requestAbortController.signal.aborted && requestAbortController.signal.reason === FORCE_DISCONNECT_AND_REFRESH) {
|
|
1427
|
-
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));
|
|
1428
1411
|
}
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
}
|
|
1436
|
-
if (!(e instanceof FetchError)) throw e;
|
|
1437
|
-
if (e.status == 409) {
|
|
1438
|
-
if (__privateGet(this, _shapeHandle)) {
|
|
1439
|
-
const shapeKey = canonicalShapeKey(fetchUrl);
|
|
1440
|
-
expiredShapesCache.markExpired(shapeKey, __privateGet(this, _shapeHandle));
|
|
1441
|
-
}
|
|
1442
|
-
const newShapeHandle = e.headers[SHAPE_HANDLE_HEADER] || `${__privateGet(this, _shapeHandle)}-next`;
|
|
1443
|
-
__privateMethod(this, _ShapeStream_instances, reset_fn).call(this, newShapeHandle);
|
|
1444
|
-
yield __privateMethod(this, _ShapeStream_instances, publish_fn).call(this, Array.isArray(e.json) ? e.json : [e.json]);
|
|
1445
|
-
return __privateMethod(this, _ShapeStream_instances, requestShape_fn).call(this);
|
|
1446
|
-
} else {
|
|
1447
|
-
throw e;
|
|
1448
|
-
}
|
|
1449
|
-
} finally {
|
|
1450
|
-
if (abortListener && signal) {
|
|
1451
|
-
signal.removeEventListener(`abort`, abortListener);
|
|
1452
|
-
}
|
|
1453
|
-
__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;
|
|
1454
1418
|
}
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
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);
|
|
1458
1427
|
};
|
|
1459
|
-
constructUrl_fn = function(url, resumingFromPause, subsetParams) {
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
if (params)
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
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
|
+
);
|
|
1453
|
+
}
|
|
1454
|
+
const serializedColumns = encodedColumns.map(quoteIdentifier).join(`,`);
|
|
1455
|
+
setQueryParam(fetchUrl, COLUMNS_QUERY_PARAM, serializedColumns);
|
|
1456
|
+
} else {
|
|
1478
1457
|
setQueryParam(fetchUrl, COLUMNS_QUERY_PARAM, params.columns);
|
|
1479
|
-
if (params.replica) setQueryParam(fetchUrl, REPLICA_PARAM, params.replica);
|
|
1480
|
-
if (params.params)
|
|
1481
|
-
setQueryParam(fetchUrl, WHERE_PARAMS_PARAM, params.params);
|
|
1482
|
-
const customParams = __spreadValues({}, params);
|
|
1483
|
-
delete customParams.table;
|
|
1484
|
-
delete customParams.where;
|
|
1485
|
-
delete customParams.columns;
|
|
1486
|
-
delete customParams.replica;
|
|
1487
|
-
delete customParams.params;
|
|
1488
|
-
for (const [key, value] of Object.entries(customParams)) {
|
|
1489
|
-
setQueryParam(fetchUrl, key, value);
|
|
1490
1458
|
}
|
|
1491
1459
|
}
|
|
1492
|
-
if (
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
JSON.stringify(subsetParams.params)
|
|
1504
|
-
);
|
|
1505
|
-
if (subsetParams.limit)
|
|
1506
|
-
setQueryParam(fetchUrl, SUBSET_PARAM_LIMIT, subsetParams.limit);
|
|
1507
|
-
if (subsetParams.offset)
|
|
1508
|
-
setQueryParam(fetchUrl, SUBSET_PARAM_OFFSET, subsetParams.offset);
|
|
1509
|
-
if (subsetParams.orderBy && typeof subsetParams.orderBy === `string`) {
|
|
1510
|
-
const encodedOrderBy = encodeWhereClause(
|
|
1511
|
-
subsetParams.orderBy,
|
|
1512
|
-
(_c = this.options.columnMapper) == null ? void 0 : _c.encode
|
|
1513
|
-
);
|
|
1514
|
-
setQueryParam(fetchUrl, SUBSET_PARAM_ORDER_BY, encodedOrderBy);
|
|
1515
|
-
}
|
|
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);
|
|
1516
1471
|
}
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
}
|
|
1524
|
-
fetchUrl.searchParams.set(
|
|
1525
|
-
LIVE_CACHE_BUSTER_QUERY_PARAM,
|
|
1526
|
-
__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
|
|
1527
1478
|
);
|
|
1479
|
+
setQueryParam(fetchUrl, SUBSET_PARAM_WHERE, encodedWhere);
|
|
1528
1480
|
}
|
|
1529
|
-
if (
|
|
1530
|
-
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);
|
|
1531
1496
|
}
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
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`);
|
|
1536
1504
|
}
|
|
1537
|
-
fetchUrl.searchParams.
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
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
|
+
};
|
|
1543
1523
|
};
|
|
1544
|
-
createAbortListener_fn = function(signal) {
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
(_a = __privateGet(this, _requestAbortController)) == null ? void 0 : _a.abort(signal.reason);
|
|
1556
|
-
}
|
|
1557
|
-
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);
|
|
1558
1535
|
}
|
|
1559
|
-
|
|
1536
|
+
return abortListener;
|
|
1537
|
+
}
|
|
1560
1538
|
};
|
|
1561
|
-
onInitialResponse_fn = function(response) {
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
}
|
|
1581
|
-
});
|
|
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
|
+
}
|
|
1582
1558
|
};
|
|
1583
|
-
onMessages_fn = function(batch, isSseMessage = false) {
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
if (
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
__privateSet(this, _lastOffset, offset);
|
|
1594
|
-
}
|
|
1595
|
-
}
|
|
1596
|
-
__privateSet(this, _lastSyncedAt, Date.now());
|
|
1597
|
-
__privateSet(this, _isUpToDate, true);
|
|
1598
|
-
__privateSet(this, _isMidStream, false);
|
|
1599
|
-
(_a = __privateGet(this, _midStreamPromiseResolver)) == null ? void 0 : _a.call(this);
|
|
1600
|
-
if (__privateGet(this, _ShapeStream_instances, replayMode_get) && !isSseMessage) {
|
|
1601
|
-
const currentCursor = __privateGet(this, _liveCacheBuster);
|
|
1602
|
-
if (currentCursor === __privateGet(this, _lastSeenCursor)) {
|
|
1603
|
-
return;
|
|
1604
|
-
}
|
|
1605
|
-
}
|
|
1606
|
-
__privateSet(this, _lastSeenCursor, void 0);
|
|
1607
|
-
if (__privateGet(this, _currentFetchUrl)) {
|
|
1608
|
-
const shapeKey = canonicalShapeKey(__privateGet(this, _currentFetchUrl));
|
|
1609
|
-
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);
|
|
1610
1569
|
}
|
|
1611
1570
|
}
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
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;
|
|
1615
1579
|
}
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
};
|
|
1622
|
-
fetchShape_fn = function(opts) {
|
|
1623
|
-
return __async(this, null, function* () {
|
|
1624
|
-
var _a;
|
|
1625
|
-
__privateSet(this, _currentFetchUrl, opts.fetchUrl);
|
|
1626
|
-
if (!__privateGet(this, _isUpToDate) && !__privateGet(this, _ShapeStream_instances, replayMode_get)) {
|
|
1627
|
-
const shapeKey = canonicalShapeKey(opts.fetchUrl);
|
|
1628
|
-
const lastSeenCursor = upToDateTracker.shouldEnterReplayMode(shapeKey);
|
|
1629
|
-
if (lastSeenCursor) {
|
|
1630
|
-
__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));
|
|
1631
1585
|
}
|
|
1632
1586
|
}
|
|
1633
|
-
const
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
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);
|
|
1638
1604
|
}
|
|
1639
|
-
|
|
1640
|
-
|
|
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);
|
|
1641
1613
|
};
|
|
1642
|
-
requestShapeLongPoll_fn = function(opts) {
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
headers
|
|
1648
|
-
});
|
|
1649
|
-
__privateSet(this, _connected, true);
|
|
1650
|
-
yield __privateMethod(this, _ShapeStream_instances, onInitialResponse_fn).call(this, response);
|
|
1651
|
-
const schema = __privateGet(this, _schema);
|
|
1652
|
-
const res = yield response.text();
|
|
1653
|
-
const messages = res || `[]`;
|
|
1654
|
-
const batch = __privateGet(this, _messageParser).parse(messages, schema);
|
|
1655
|
-
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
|
|
1656
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);
|
|
1657
1627
|
};
|
|
1658
|
-
requestShapeSSE_fn = function(opts) {
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
schema
|
|
1681
|
-
);
|
|
1682
|
-
buffer.push(message);
|
|
1683
|
-
if (isUpToDateMessage(message)) {
|
|
1684
|
-
__privateMethod(this, _ShapeStream_instances, onMessages_fn).call(this, buffer, true);
|
|
1685
|
-
buffer = [];
|
|
1686
|
-
}
|
|
1687
|
-
}
|
|
1688
|
-
},
|
|
1689
|
-
onerror: (error) => {
|
|
1690
|
-
throw error;
|
|
1691
|
-
},
|
|
1692
|
-
signal: requestAbortController.signal
|
|
1693
|
-
});
|
|
1694
|
-
} catch (error) {
|
|
1695
|
-
if (requestAbortController.signal.aborted) {
|
|
1696
|
-
throw new FetchBackoffAbortError();
|
|
1697
|
-
}
|
|
1698
|
-
throw error;
|
|
1699
|
-
} finally {
|
|
1700
|
-
const connectionDuration = Date.now() - __privateGet(this, _lastSseConnectionStartTime);
|
|
1701
|
-
const wasAborted = requestAbortController.signal.aborted;
|
|
1702
|
-
if (connectionDuration < __privateGet(this, _minSseConnectionDuration) && !wasAborted) {
|
|
1703
|
-
__privateWrapper(this, _consecutiveShortSseConnections)._++;
|
|
1704
|
-
if (__privateGet(this, _consecutiveShortSseConnections) >= __privateGet(this, _maxShortSseConnections)) {
|
|
1705
|
-
__privateSet(this, _sseFallbackToLongPolling, true);
|
|
1706
|
-
console.warn(
|
|
1707
|
-
`[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.`
|
|
1708
|
-
);
|
|
1709
|
-
} else {
|
|
1710
|
-
const maxDelay = Math.min(
|
|
1711
|
-
__privateGet(this, _sseBackoffMaxDelay),
|
|
1712
|
-
__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
|
|
1713
1650
|
);
|
|
1714
|
-
|
|
1715
|
-
|
|
1651
|
+
buffer.push(message);
|
|
1652
|
+
if (isUpToDateMessage(message)) {
|
|
1653
|
+
__privateMethod(this, _ShapeStream_instances, onMessages_fn).call(this, buffer, true);
|
|
1654
|
+
buffer = [];
|
|
1655
|
+
}
|
|
1716
1656
|
}
|
|
1717
|
-
}
|
|
1718
|
-
|
|
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));
|
|
1719
1685
|
}
|
|
1686
|
+
} else if (connectionDuration >= __privateGet(this, _minSseConnectionDuration)) {
|
|
1687
|
+
__privateSet(this, _consecutiveShortSseConnections, 0);
|
|
1720
1688
|
}
|
|
1721
|
-
}
|
|
1689
|
+
}
|
|
1722
1690
|
};
|
|
1723
1691
|
pause_fn = function() {
|
|
1724
1692
|
var _a;
|
|
@@ -1728,65 +1696,63 @@ pause_fn = function() {
|
|
|
1728
1696
|
}
|
|
1729
1697
|
};
|
|
1730
1698
|
resume_fn = function() {
|
|
1699
|
+
var _a;
|
|
1731
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
|
+
}
|
|
1732
1704
|
if (__privateGet(this, _state) === `pause-requested`) {
|
|
1733
1705
|
__privateSet(this, _state, `active`);
|
|
1734
1706
|
}
|
|
1735
1707
|
__privateMethod(this, _ShapeStream_instances, start_fn).call(this);
|
|
1736
1708
|
}
|
|
1737
1709
|
};
|
|
1738
|
-
nextTick_fn = function() {
|
|
1739
|
-
|
|
1740
|
-
if (__privateGet(this, _tickPromise)) {
|
|
1741
|
-
return __privateGet(this, _tickPromise);
|
|
1742
|
-
}
|
|
1743
|
-
__privateSet(this, _tickPromise, new Promise((resolve, reject) => {
|
|
1744
|
-
__privateSet(this, _tickPromiseResolver, resolve);
|
|
1745
|
-
__privateSet(this, _tickPromiseRejecter, reject);
|
|
1746
|
-
}));
|
|
1747
|
-
__privateGet(this, _tickPromise).finally(() => {
|
|
1748
|
-
__privateSet(this, _tickPromise, void 0);
|
|
1749
|
-
__privateSet(this, _tickPromiseResolver, void 0);
|
|
1750
|
-
__privateSet(this, _tickPromiseRejecter, void 0);
|
|
1751
|
-
});
|
|
1710
|
+
nextTick_fn = async function() {
|
|
1711
|
+
if (__privateGet(this, _tickPromise)) {
|
|
1752
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);
|
|
1753
1722
|
});
|
|
1723
|
+
return __privateGet(this, _tickPromise);
|
|
1754
1724
|
};
|
|
1755
|
-
waitForStreamEnd_fn = function() {
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
if (__privateGet(this, _midStreamPromise)) {
|
|
1761
|
-
return __privateGet(this, _midStreamPromise);
|
|
1762
|
-
}
|
|
1763
|
-
__privateSet(this, _midStreamPromise, new Promise((resolve) => {
|
|
1764
|
-
__privateSet(this, _midStreamPromiseResolver, resolve);
|
|
1765
|
-
}));
|
|
1766
|
-
__privateGet(this, _midStreamPromise).finally(() => {
|
|
1767
|
-
__privateSet(this, _midStreamPromise, void 0);
|
|
1768
|
-
__privateSet(this, _midStreamPromiseResolver, void 0);
|
|
1769
|
-
});
|
|
1725
|
+
waitForStreamEnd_fn = async function() {
|
|
1726
|
+
if (!__privateGet(this, _isMidStream)) {
|
|
1727
|
+
return;
|
|
1728
|
+
}
|
|
1729
|
+
if (__privateGet(this, _midStreamPromise)) {
|
|
1770
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);
|
|
1771
1738
|
});
|
|
1739
|
+
return __privateGet(this, _midStreamPromise);
|
|
1772
1740
|
};
|
|
1773
|
-
publish_fn = function(messages) {
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
() =>
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
return __privateGet(this, _messageChain);
|
|
1789
|
-
});
|
|
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);
|
|
1790
1756
|
};
|
|
1791
1757
|
sendErrorToSubscribers_fn = function(error) {
|
|
1792
1758
|
__privateGet(this, _subscribers).forEach(([_, errorFn]) => {
|
|
@@ -1958,13 +1924,11 @@ var Shape = class {
|
|
|
1958
1924
|
* Request a snapshot for subset of data. Only available when mode is changes_only.
|
|
1959
1925
|
* Returns void; data will be emitted via the stream and processed by this Shape.
|
|
1960
1926
|
*/
|
|
1961
|
-
requestSnapshot(params) {
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
yield this.stream.requestSnapshot(params);
|
|
1967
|
-
});
|
|
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);
|
|
1968
1932
|
}
|
|
1969
1933
|
subscribe(callback) {
|
|
1970
1934
|
const subscriptionId = Math.random();
|
|
@@ -2046,38 +2010,34 @@ process_fn = function(messages) {
|
|
|
2046
2010
|
});
|
|
2047
2011
|
if (shouldNotify) __privateMethod(this, _Shape_instances, notify_fn).call(this);
|
|
2048
2012
|
};
|
|
2049
|
-
reexecuteSnapshots_fn = function() {
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
);
|
|
2061
|
-
});
|
|
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
|
+
);
|
|
2062
2024
|
};
|
|
2063
|
-
awaitUpToDate_fn = function() {
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
check();
|
|
2080
|
-
});
|
|
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();
|
|
2081
2041
|
});
|
|
2082
2042
|
};
|
|
2083
2043
|
updateShapeStatus_fn = function(status) {
|