@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.
@@ -2696,6 +2696,22 @@ var OfflineStore = class {
2696
2696
  const tx = db.transaction("meta", "readwrite");
2697
2697
  await txPromise$2(tx.objectStore("meta"), tx.objectStore("meta").put(value, `meta:${key}`));
2698
2698
  }
2699
+ /**
2700
+ * Clear all stored data (updates, snapshots, state vectors, subdoc queue).
2701
+ * The database itself is kept but emptied.
2702
+ */
2703
+ async clearAll() {
2704
+ const db = await this.getDb();
2705
+ if (!db) return;
2706
+ const storeNames = Array.from(db.objectStoreNames);
2707
+ if (storeNames.length === 0) return;
2708
+ const tx = db.transaction(storeNames, "readwrite");
2709
+ await Promise.all(storeNames.map((name) => new Promise((resolve, reject) => {
2710
+ const req = tx.objectStore(name).clear();
2711
+ req.onsuccess = () => resolve();
2712
+ req.onerror = () => reject(req.error);
2713
+ })));
2714
+ }
2699
2715
  destroy() {
2700
2716
  this._destroyed = true;
2701
2717
  this.db = null;
@@ -8386,6 +8402,32 @@ var BackgroundSyncManager = class extends EventEmitter {
8386
8402
  }, intervalMs);
8387
8403
  return () => clearInterval(handle);
8388
8404
  }
8405
+ /**
8406
+ * Clear all offline document data and sync state.
8407
+ * Opens each document's OfflineStore and clears its contents, then
8408
+ * resets the background sync persistence. After calling this, all
8409
+ * documents will need to be re-synced.
8410
+ */
8411
+ async clearAllSyncedData() {
8412
+ const docIds = new Set(this.syncStates.keys());
8413
+ const treeMap = this.rootProvider.document.getMap("doc-tree");
8414
+ for (const docId of treeMap.keys()) docIds.add(docId);
8415
+ let serverOrigin;
8416
+ try {
8417
+ serverOrigin = new URL(this.client.baseUrl ?? "").hostname;
8418
+ } catch {}
8419
+ const clearPromises = Array.from(docIds).map(async (docId) => {
8420
+ try {
8421
+ const store = new OfflineStore(docId, serverOrigin);
8422
+ await store.clearAll();
8423
+ store.destroy();
8424
+ } catch {}
8425
+ });
8426
+ await Promise.all(clearPromises);
8427
+ for (const docId of docIds) await this.persistence.deleteState(docId).catch(() => null);
8428
+ this.syncStates.clear();
8429
+ this._initPromise = null;
8430
+ }
8389
8431
  destroy() {
8390
8432
  this._destroyed = true;
8391
8433
  this.removeAllListeners();