@absolutejs/sync 1.18.2 → 1.19.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/engine/index.js +33 -1
- package/dist/engine/index.js.map +3 -3
- package/dist/engine/syncEngine.d.ts +75 -0
- package/dist/index.js +33 -1
- package/dist/index.js.map +3 -3
- package/dist/testing.js +33 -1
- package/dist/testing.js.map +3 -3
- package/package.json +1 -1
package/dist/engine/index.js
CHANGED
|
@@ -1567,6 +1567,31 @@ var createSyncEngine = (options = {}) => {
|
|
|
1567
1567
|
const runInTransaction = options.transaction;
|
|
1568
1568
|
const instanceId = options.instanceId ?? globalThis.crypto?.randomUUID?.() ?? `i${Math.random()}`;
|
|
1569
1569
|
let clusterBus;
|
|
1570
|
+
const importChangeLog = (snapshot) => {
|
|
1571
|
+
if (version !== 0) {
|
|
1572
|
+
throw new Error(`[sync] importChangeLog: engine already has version ${version}; ` + `restore must happen before any local writes commit.`);
|
|
1573
|
+
}
|
|
1574
|
+
if (snapshot.instanceId !== instanceId) {
|
|
1575
|
+
throw new Error(`[sync] importChangeLog: snapshot instanceId "${snapshot.instanceId}" ` + `does not match this engine's instanceId "${instanceId}". ` + `Pass options.instanceId = "${snapshot.instanceId}" to createSyncEngine.`);
|
|
1576
|
+
}
|
|
1577
|
+
version = snapshot.version;
|
|
1578
|
+
for (const entry of snapshot.entries) {
|
|
1579
|
+
changeLog.push(entry);
|
|
1580
|
+
}
|
|
1581
|
+
while (changeLog.length > changeLogSize) {
|
|
1582
|
+
changeLog.shift();
|
|
1583
|
+
}
|
|
1584
|
+
if (changeLogRetainMs !== null && changeLogRetainMs > 0) {
|
|
1585
|
+
const cutoff = Date.now() - changeLogRetainMs;
|
|
1586
|
+
while (changeLog.length > 0 && changeLog[0].at < cutoff) {
|
|
1587
|
+
changeLog.shift();
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
return snapshot.entries.length;
|
|
1591
|
+
};
|
|
1592
|
+
if (options.initialChangeLog !== undefined) {
|
|
1593
|
+
importChangeLog(options.initialChangeLog);
|
|
1594
|
+
}
|
|
1570
1595
|
const broadcast = (changes, originVersion) => {
|
|
1571
1596
|
if (clusterBus !== undefined && changes.length > 0) {
|
|
1572
1597
|
clusterBus.publish({ changes, origin: instanceId, originVersion });
|
|
@@ -2836,6 +2861,13 @@ var createSyncEngine = (options = {}) => {
|
|
|
2836
2861
|
}))
|
|
2837
2862
|
};
|
|
2838
2863
|
},
|
|
2864
|
+
exportChangeLog: () => ({
|
|
2865
|
+
entries: changeLog.slice(),
|
|
2866
|
+
exportedAt: Date.now(),
|
|
2867
|
+
instanceId,
|
|
2868
|
+
version
|
|
2869
|
+
}),
|
|
2870
|
+
importChangeLog,
|
|
2839
2871
|
metrics: () => {
|
|
2840
2872
|
const now = Date.now();
|
|
2841
2873
|
const byCollection = {};
|
|
@@ -3406,5 +3438,5 @@ export {
|
|
|
3406
3438
|
CdcConsumerSlowError
|
|
3407
3439
|
};
|
|
3408
3440
|
|
|
3409
|
-
//# debugId=
|
|
3441
|
+
//# debugId=079CCC84C9743C1064756E2164756E21
|
|
3410
3442
|
//# sourceMappingURL=index.js.map
|