cry-synced-db-client 0.1.28 → 0.1.29
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/db/SyncedDb.d.ts +5 -0
- package/dist/index.js +19 -0
- package/package.json +1 -1
package/dist/db/SyncedDb.d.ts
CHANGED
|
@@ -187,6 +187,11 @@ export declare class SyncedDb implements I_SyncedDb {
|
|
|
187
187
|
* Normalize timestamp to number for comparison
|
|
188
188
|
*/
|
|
189
189
|
private normalizeTimestamp;
|
|
190
|
+
/**
|
|
191
|
+
* Broadcast metadata update to other tabs.
|
|
192
|
+
* Updates both Dexie sync meta and the in-memory cache.
|
|
193
|
+
*/
|
|
194
|
+
private broadcastMetaUpdate;
|
|
190
195
|
/**
|
|
191
196
|
* Handle cross-tab sync metadata updates from BroadcastChannel
|
|
192
197
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1506,12 +1506,27 @@ class SyncedDb {
|
|
|
1506
1506
|
return ts;
|
|
1507
1507
|
if (ts instanceof Date)
|
|
1508
1508
|
return ts.getTime();
|
|
1509
|
+
if (typeof ts === "object" && "t" in ts)
|
|
1510
|
+
return ts.t;
|
|
1509
1511
|
if (typeof ts.toNumber === "function")
|
|
1510
1512
|
return ts.toNumber();
|
|
1511
1513
|
if (typeof ts.valueOf === "function")
|
|
1512
1514
|
return ts.valueOf();
|
|
1513
1515
|
return 0;
|
|
1514
1516
|
}
|
|
1517
|
+
async broadcastMetaUpdate(collection, timestamp) {
|
|
1518
|
+
const cachedMeta = this.syncMetaCache.get(collection);
|
|
1519
|
+
const cachedTs = this.normalizeTimestamp(cachedMeta?.lastSyncTs);
|
|
1520
|
+
const newTs = this.normalizeTimestamp(timestamp);
|
|
1521
|
+
if (newTs > cachedTs) {
|
|
1522
|
+
await this.dexieDb.setSyncMeta(collection, timestamp);
|
|
1523
|
+
this.syncMetaCache.set(collection, {
|
|
1524
|
+
tenant: this.tenant,
|
|
1525
|
+
collection,
|
|
1526
|
+
lastSyncTs: timestamp
|
|
1527
|
+
});
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1515
1530
|
async handleCrossTabMetaUpdate(payload) {
|
|
1516
1531
|
if (payload.instanceId === this.syncedDbInstanceId) {
|
|
1517
1532
|
return;
|
|
@@ -1588,11 +1603,15 @@ class SyncedDb {
|
|
|
1588
1603
|
const serverItem = items[0];
|
|
1589
1604
|
if (serverItem) {
|
|
1590
1605
|
await this.handleServerItemUpdate(collectionName, serverItem);
|
|
1606
|
+
if (serverItem._ts) {
|
|
1607
|
+
await this.broadcastMetaUpdate(collectionName, serverItem._ts);
|
|
1608
|
+
}
|
|
1591
1609
|
}
|
|
1592
1610
|
break;
|
|
1593
1611
|
}
|
|
1594
1612
|
case "delete": {
|
|
1595
1613
|
await this.handleServerItemDelete(collectionName, payload._id);
|
|
1614
|
+
await this.broadcastMetaUpdate(collectionName, Date.now());
|
|
1596
1615
|
break;
|
|
1597
1616
|
}
|
|
1598
1617
|
case "updateMany":
|