@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
package/dist/index.d.ts
CHANGED
|
@@ -187,6 +187,11 @@ declare class OfflineStore {
|
|
|
187
187
|
removeSubdocFromQueue(childId: string): Promise<void>;
|
|
188
188
|
getMeta(key: string): Promise<string | null>;
|
|
189
189
|
setMeta(key: string, value: string): Promise<void>;
|
|
190
|
+
/**
|
|
191
|
+
* Clear all stored data (updates, snapshots, state vectors, subdoc queue).
|
|
192
|
+
* The database itself is kept but emptied.
|
|
193
|
+
*/
|
|
194
|
+
clearAll(): Promise<void>;
|
|
190
195
|
destroy(): void;
|
|
191
196
|
}
|
|
192
197
|
//#endregion
|
|
@@ -1634,6 +1639,13 @@ declare class BackgroundSyncManager extends EventEmitter {
|
|
|
1634
1639
|
* @returns Cleanup function to stop the periodic sync.
|
|
1635
1640
|
*/
|
|
1636
1641
|
startPeriodicSync(intervalMs?: number): () => void;
|
|
1642
|
+
/**
|
|
1643
|
+
* Clear all offline document data and sync state.
|
|
1644
|
+
* Opens each document's OfflineStore and clears its contents, then
|
|
1645
|
+
* resets the background sync persistence. After calling this, all
|
|
1646
|
+
* documents will need to be re-synced.
|
|
1647
|
+
*/
|
|
1648
|
+
clearAllSyncedData(): Promise<void>;
|
|
1637
1649
|
destroy(): void;
|
|
1638
1650
|
/**
|
|
1639
1651
|
* Build a priority-sorted list of doc IDs:
|
package/package.json
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
BackgroundSyncPersistence,
|
|
28
28
|
type DocSyncState,
|
|
29
29
|
} from "./BackgroundSyncPersistence.ts";
|
|
30
|
+
import { OfflineStore } from "./OfflineStore.ts";
|
|
30
31
|
import EventEmitter from "./EventEmitter.ts";
|
|
31
32
|
import { E2EAbracadabraProvider } from "./E2EAbracadabraProvider.ts";
|
|
32
33
|
|
|
@@ -191,6 +192,48 @@ export class BackgroundSyncManager extends EventEmitter {
|
|
|
191
192
|
return () => clearInterval(handle);
|
|
192
193
|
}
|
|
193
194
|
|
|
195
|
+
/**
|
|
196
|
+
* Clear all offline document data and sync state.
|
|
197
|
+
* Opens each document's OfflineStore and clears its contents, then
|
|
198
|
+
* resets the background sync persistence. After calling this, all
|
|
199
|
+
* documents will need to be re-synced.
|
|
200
|
+
*/
|
|
201
|
+
async clearAllSyncedData(): Promise<void> {
|
|
202
|
+
// Collect doc IDs from both in-memory state and the tree
|
|
203
|
+
const docIds = new Set<string>(this.syncStates.keys());
|
|
204
|
+
const treeMap = this.rootProvider.document.getMap("doc-tree") as Y.Map<any>;
|
|
205
|
+
for (const docId of treeMap.keys()) {
|
|
206
|
+
docIds.add(docId);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Derive server origin the same way the provider does
|
|
210
|
+
let serverOrigin: string | undefined;
|
|
211
|
+
try {
|
|
212
|
+
serverOrigin = new URL((this.client as any).baseUrl ?? "").hostname;
|
|
213
|
+
} catch {}
|
|
214
|
+
|
|
215
|
+
// Clear each document's offline store contents
|
|
216
|
+
const clearPromises = Array.from(docIds).map(async (docId) => {
|
|
217
|
+
try {
|
|
218
|
+
const store = new OfflineStore(docId, serverOrigin);
|
|
219
|
+
await store.clearAll();
|
|
220
|
+
store.destroy();
|
|
221
|
+
} catch {
|
|
222
|
+
// Ignore per-doc failures
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
await Promise.all(clearPromises);
|
|
226
|
+
|
|
227
|
+
// Clear background sync persistence
|
|
228
|
+
for (const docId of docIds) {
|
|
229
|
+
await this.persistence.deleteState(docId).catch(() => null);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Reset in-memory state
|
|
233
|
+
this.syncStates.clear();
|
|
234
|
+
this._initPromise = null;
|
|
235
|
+
}
|
|
236
|
+
|
|
194
237
|
destroy(): void {
|
|
195
238
|
this._destroyed = true;
|
|
196
239
|
this.removeAllListeners();
|
package/src/OfflineStore.ts
CHANGED
|
@@ -251,6 +251,28 @@ export class OfflineStore {
|
|
|
251
251
|
);
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
+
/**
|
|
255
|
+
* Clear all stored data (updates, snapshots, state vectors, subdoc queue).
|
|
256
|
+
* The database itself is kept but emptied.
|
|
257
|
+
*/
|
|
258
|
+
async clearAll(): Promise<void> {
|
|
259
|
+
const db = await this.getDb();
|
|
260
|
+
if (!db) return;
|
|
261
|
+
const storeNames = Array.from(db.objectStoreNames);
|
|
262
|
+
if (storeNames.length === 0) return;
|
|
263
|
+
const tx = db.transaction(storeNames, "readwrite");
|
|
264
|
+
await Promise.all(
|
|
265
|
+
storeNames.map(
|
|
266
|
+
(name) =>
|
|
267
|
+
new Promise<void>((resolve, reject) => {
|
|
268
|
+
const req = tx.objectStore(name).clear();
|
|
269
|
+
req.onsuccess = () => resolve();
|
|
270
|
+
req.onerror = () => reject(req.error);
|
|
271
|
+
}),
|
|
272
|
+
),
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
|
|
254
276
|
// ── Lifecycle ─────────────────────────────────────────────────────────────
|
|
255
277
|
|
|
256
278
|
destroy() {
|