cry-synced-db-client 0.1.62 → 0.1.64
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/index.js +16 -5
- package/dist/src/db/types/managers.d.ts +2 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2057,11 +2057,18 @@ class SyncEngine {
|
|
|
2057
2057
|
this.callOnFindNewerManyResult(syncSpecs, {}, findNewerManyStartTime, false, calledFrom, err);
|
|
2058
2058
|
throw err;
|
|
2059
2059
|
}
|
|
2060
|
+
const allUpdatedIds = {};
|
|
2060
2061
|
for (const [collectionName, config] of this.collections) {
|
|
2061
2062
|
const serverData = allServerData[collectionName] || [];
|
|
2062
2063
|
receivedCount += serverData.length;
|
|
2063
2064
|
const stats = await this.processIncomingServerData(collectionName, config, serverData);
|
|
2064
2065
|
conflictsResolved += stats.conflictsResolved;
|
|
2066
|
+
if (stats.updatedIds.length > 0) {
|
|
2067
|
+
allUpdatedIds[collectionName] = stats.updatedIds;
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
if (Object.keys(allUpdatedIds).length > 0) {
|
|
2071
|
+
this.deps.broadcastUpdates(allUpdatedIds);
|
|
2065
2072
|
}
|
|
2066
2073
|
const uploadStats = await this.uploadDirtyItems(calledFrom);
|
|
2067
2074
|
sentCount = uploadStats.sentCount;
|
|
@@ -2274,7 +2281,7 @@ class SyncEngine {
|
|
|
2274
2281
|
}
|
|
2275
2282
|
async processIncomingServerData(collectionName, config, serverData) {
|
|
2276
2283
|
if (serverData.length === 0) {
|
|
2277
|
-
return { conflictsResolved: 0, maxTs: undefined };
|
|
2284
|
+
return { conflictsResolved: 0, maxTs: undefined, updatedIds: [] };
|
|
2278
2285
|
}
|
|
2279
2286
|
let maxTs;
|
|
2280
2287
|
let conflictsResolved = 0;
|
|
@@ -2335,7 +2342,8 @@ class SyncEngine {
|
|
|
2335
2342
|
lastSyncTs: maxTs
|
|
2336
2343
|
});
|
|
2337
2344
|
}
|
|
2338
|
-
|
|
2345
|
+
const updatedIds = serverIds.map((id) => String(id));
|
|
2346
|
+
return { conflictsResolved, maxTs, updatedIds };
|
|
2339
2347
|
}
|
|
2340
2348
|
compareTimestamps(a, b) {
|
|
2341
2349
|
const aT = typeof a === "object" && "t" in a ? a.t : 0;
|
|
@@ -2728,14 +2736,16 @@ class WakeSyncManager {
|
|
|
2728
2736
|
handleWakeEvent(trigger) {
|
|
2729
2737
|
const now = Date.now();
|
|
2730
2738
|
const gap = now - this.lastEventTime;
|
|
2731
|
-
this.
|
|
2732
|
-
|
|
2739
|
+
if (gap < this.gapThresholdMs) {
|
|
2740
|
+
this.lastEventTime = now;
|
|
2733
2741
|
return;
|
|
2742
|
+
}
|
|
2734
2743
|
if (this.debounceTimer) {
|
|
2735
2744
|
clearTimeout(this.debounceTimer);
|
|
2736
2745
|
}
|
|
2737
2746
|
this.debounceTimer = setTimeout(() => {
|
|
2738
2747
|
this.debounceTimer = undefined;
|
|
2748
|
+
this.lastEventTime = Date.now();
|
|
2739
2749
|
this.deps.tryBecomeLeader();
|
|
2740
2750
|
if (!this.deps.isLeader())
|
|
2741
2751
|
return;
|
|
@@ -2931,7 +2941,8 @@ class SyncedDb {
|
|
|
2931
2941
|
goOffline: (reason) => this.connectionManager.goOffline(reason),
|
|
2932
2942
|
flushAllPendingChanges: () => this.pendingChanges.flushAll(),
|
|
2933
2943
|
cancelRestUploadTimer: () => this.pendingChanges.cancelRestUploadTimer(),
|
|
2934
|
-
awaitRestUpload: () => this.pendingChanges.awaitRestUpload()
|
|
2944
|
+
awaitRestUpload: () => this.pendingChanges.awaitRestUpload(),
|
|
2945
|
+
broadcastUpdates: (updates) => this.crossTabSync.broadcastMetaUpdate(updates)
|
|
2935
2946
|
}
|
|
2936
2947
|
});
|
|
2937
2948
|
this.serverUpdateHandler = new ServerUpdateHandler({
|
|
@@ -223,6 +223,8 @@ export interface SyncEngineDeps {
|
|
|
223
223
|
flushAllPendingChanges: () => Promise<void>;
|
|
224
224
|
cancelRestUploadTimer: () => void;
|
|
225
225
|
awaitRestUpload: () => Promise<void>;
|
|
226
|
+
/** Broadcast updated IDs to other tabs */
|
|
227
|
+
broadcastUpdates: (updates: Record<string, string[]>) => void;
|
|
226
228
|
}
|
|
227
229
|
export interface SyncEngineConfig {
|
|
228
230
|
tenant: string;
|