@abraca/dabra 1.0.13 → 1.0.14

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.d.ts CHANGED
@@ -1399,6 +1399,17 @@ declare class FileBlobStore extends EventEmitter {
1399
1399
  * Use this to re-upload a file after a page reload.
1400
1400
  */
1401
1401
  getBlob(docId: string, uploadId: string): Promise<Blob | null>;
1402
+ /** Return metadata for all cached blobs (for storage stats). */
1403
+ getAllCachedEntries(): Promise<Array<{
1404
+ docId: string;
1405
+ uploadId: string;
1406
+ filename: string;
1407
+ mimeType: string;
1408
+ size: number;
1409
+ cachedAt: number;
1410
+ }>>;
1411
+ /** Revoke all object URLs and clear the entire blob cache from IDB. */
1412
+ clearAllBlobs(): Promise<void>;
1402
1413
  /** Revoke the object URL and remove the blob from cache. */
1403
1414
  evictBlob(docId: string, uploadId: string): Promise<void>;
1404
1415
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abraca/dabra",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "abracadabra provider",
5
5
  "keywords": [
6
6
  "abracadabra",
@@ -231,6 +231,47 @@ export class FileBlobStore extends EventEmitter {
231
231
  return entry?.blob ?? null;
232
232
  }
233
233
 
234
+ /** Return metadata for all cached blobs (for storage stats). */
235
+ async getAllCachedEntries(): Promise<Array<{
236
+ docId: string; uploadId: string; filename: string;
237
+ mimeType: string; size: number; cachedAt: number;
238
+ }>> {
239
+ const db = await this.getDb();
240
+ if (!db) return [];
241
+ return new Promise((resolve, reject) => {
242
+ const tx = db.transaction("blobs", "readonly");
243
+ const store = tx.objectStore("blobs");
244
+ const keysReq = store.getAllKeys();
245
+ const valuesReq = store.getAll();
246
+ tx.oncomplete = () => {
247
+ const keys = keysReq.result as string[];
248
+ const values = valuesReq.result as BlobCacheEntry[];
249
+ resolve(keys.map((key, i) => {
250
+ const slashIdx = key.indexOf("/");
251
+ const docId = key.slice(0, slashIdx);
252
+ const uploadId = key.slice(slashIdx + 1);
253
+ const e = values[i]!;
254
+ return { docId, uploadId, filename: e.filename, mimeType: e.mime_type, size: e.blob.size, cachedAt: e.cachedAt };
255
+ }));
256
+ };
257
+ tx.onerror = () => reject(tx.error);
258
+ });
259
+ }
260
+
261
+ /** Revoke all object URLs and clear the entire blob cache from IDB. */
262
+ async clearAllBlobs(): Promise<void> {
263
+ for (const url of this.objectUrls.values()) URL.revokeObjectURL(url);
264
+ this.objectUrls.clear();
265
+ const db = await this.getDb();
266
+ if (!db) return;
267
+ return new Promise((resolve, reject) => {
268
+ const tx = db.transaction("blobs", "readwrite");
269
+ const req = tx.objectStore("blobs").clear();
270
+ req.onsuccess = () => resolve();
271
+ req.onerror = () => reject(req.error);
272
+ });
273
+ }
274
+
234
275
  /** Revoke the object URL and remove the blob from cache. */
235
276
  async evictBlob(docId: string, uploadId: string): Promise<void> {
236
277
  const key = this.blobKey(docId, uploadId);