@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/testing.js
CHANGED
|
@@ -782,6 +782,31 @@ var createSyncEngine = (options = {}) => {
|
|
|
782
782
|
const runInTransaction = options.transaction;
|
|
783
783
|
const instanceId = options.instanceId ?? globalThis.crypto?.randomUUID?.() ?? `i${Math.random()}`;
|
|
784
784
|
let clusterBus;
|
|
785
|
+
const importChangeLog = (snapshot) => {
|
|
786
|
+
if (version !== 0) {
|
|
787
|
+
throw new Error(`[sync] importChangeLog: engine already has version ${version}; ` + `restore must happen before any local writes commit.`);
|
|
788
|
+
}
|
|
789
|
+
if (snapshot.instanceId !== instanceId) {
|
|
790
|
+
throw new Error(`[sync] importChangeLog: snapshot instanceId "${snapshot.instanceId}" ` + `does not match this engine's instanceId "${instanceId}". ` + `Pass options.instanceId = "${snapshot.instanceId}" to createSyncEngine.`);
|
|
791
|
+
}
|
|
792
|
+
version = snapshot.version;
|
|
793
|
+
for (const entry of snapshot.entries) {
|
|
794
|
+
changeLog.push(entry);
|
|
795
|
+
}
|
|
796
|
+
while (changeLog.length > changeLogSize) {
|
|
797
|
+
changeLog.shift();
|
|
798
|
+
}
|
|
799
|
+
if (changeLogRetainMs !== null && changeLogRetainMs > 0) {
|
|
800
|
+
const cutoff = Date.now() - changeLogRetainMs;
|
|
801
|
+
while (changeLog.length > 0 && changeLog[0].at < cutoff) {
|
|
802
|
+
changeLog.shift();
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
return snapshot.entries.length;
|
|
806
|
+
};
|
|
807
|
+
if (options.initialChangeLog !== undefined) {
|
|
808
|
+
importChangeLog(options.initialChangeLog);
|
|
809
|
+
}
|
|
785
810
|
const broadcast = (changes, originVersion) => {
|
|
786
811
|
if (clusterBus !== undefined && changes.length > 0) {
|
|
787
812
|
clusterBus.publish({ changes, origin: instanceId, originVersion });
|
|
@@ -2051,6 +2076,13 @@ var createSyncEngine = (options = {}) => {
|
|
|
2051
2076
|
}))
|
|
2052
2077
|
};
|
|
2053
2078
|
},
|
|
2079
|
+
exportChangeLog: () => ({
|
|
2080
|
+
entries: changeLog.slice(),
|
|
2081
|
+
exportedAt: Date.now(),
|
|
2082
|
+
instanceId,
|
|
2083
|
+
version
|
|
2084
|
+
}),
|
|
2085
|
+
importChangeLog,
|
|
2054
2086
|
metrics: () => {
|
|
2055
2087
|
const now = Date.now();
|
|
2056
2088
|
const byCollection = {};
|
|
@@ -2193,5 +2225,5 @@ export {
|
|
|
2193
2225
|
createTestEngine
|
|
2194
2226
|
};
|
|
2195
2227
|
|
|
2196
|
-
//# debugId=
|
|
2228
|
+
//# debugId=D332A9D90117FA7264756E2164756E21
|
|
2197
2229
|
//# sourceMappingURL=testing.js.map
|