@abraca/dabra 1.0.15 → 1.0.16
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/abracadabra-provider.cjs +42 -0
- package/dist/abracadabra-provider.cjs.map +1 -1
- package/dist/abracadabra-provider.esm.js +42 -0
- package/dist/abracadabra-provider.esm.js.map +1 -1
- package/dist/index.d.ts +12 -0
- package/package.json +1 -1
- package/src/BackgroundSyncManager.ts +43 -0
- package/src/OfflineStore.ts +22 -0
|
@@ -2726,6 +2726,22 @@ var OfflineStore = class {
|
|
|
2726
2726
|
const tx = db.transaction("meta", "readwrite");
|
|
2727
2727
|
await txPromise$2(tx.objectStore("meta"), tx.objectStore("meta").put(value, `meta:${key}`));
|
|
2728
2728
|
}
|
|
2729
|
+
/**
|
|
2730
|
+
* Clear all stored data (updates, snapshots, state vectors, subdoc queue).
|
|
2731
|
+
* The database itself is kept but emptied.
|
|
2732
|
+
*/
|
|
2733
|
+
async clearAll() {
|
|
2734
|
+
const db = await this.getDb();
|
|
2735
|
+
if (!db) return;
|
|
2736
|
+
const storeNames = Array.from(db.objectStoreNames);
|
|
2737
|
+
if (storeNames.length === 0) return;
|
|
2738
|
+
const tx = db.transaction(storeNames, "readwrite");
|
|
2739
|
+
await Promise.all(storeNames.map((name) => new Promise((resolve, reject) => {
|
|
2740
|
+
const req = tx.objectStore(name).clear();
|
|
2741
|
+
req.onsuccess = () => resolve();
|
|
2742
|
+
req.onerror = () => reject(req.error);
|
|
2743
|
+
})));
|
|
2744
|
+
}
|
|
2729
2745
|
destroy() {
|
|
2730
2746
|
this._destroyed = true;
|
|
2731
2747
|
this.db = null;
|
|
@@ -8438,6 +8454,32 @@ var BackgroundSyncManager = class extends EventEmitter {
|
|
|
8438
8454
|
}, intervalMs);
|
|
8439
8455
|
return () => clearInterval(handle);
|
|
8440
8456
|
}
|
|
8457
|
+
/**
|
|
8458
|
+
* Clear all offline document data and sync state.
|
|
8459
|
+
* Opens each document's OfflineStore and clears its contents, then
|
|
8460
|
+
* resets the background sync persistence. After calling this, all
|
|
8461
|
+
* documents will need to be re-synced.
|
|
8462
|
+
*/
|
|
8463
|
+
async clearAllSyncedData() {
|
|
8464
|
+
const docIds = new Set(this.syncStates.keys());
|
|
8465
|
+
const treeMap = this.rootProvider.document.getMap("doc-tree");
|
|
8466
|
+
for (const docId of treeMap.keys()) docIds.add(docId);
|
|
8467
|
+
let serverOrigin;
|
|
8468
|
+
try {
|
|
8469
|
+
serverOrigin = new URL(this.client.baseUrl ?? "").hostname;
|
|
8470
|
+
} catch {}
|
|
8471
|
+
const clearPromises = Array.from(docIds).map(async (docId) => {
|
|
8472
|
+
try {
|
|
8473
|
+
const store = new OfflineStore(docId, serverOrigin);
|
|
8474
|
+
await store.clearAll();
|
|
8475
|
+
store.destroy();
|
|
8476
|
+
} catch {}
|
|
8477
|
+
});
|
|
8478
|
+
await Promise.all(clearPromises);
|
|
8479
|
+
for (const docId of docIds) await this.persistence.deleteState(docId).catch(() => null);
|
|
8480
|
+
this.syncStates.clear();
|
|
8481
|
+
this._initPromise = null;
|
|
8482
|
+
}
|
|
8441
8483
|
destroy() {
|
|
8442
8484
|
this._destroyed = true;
|
|
8443
8485
|
this.removeAllListeners();
|