@abraca/dabra 1.0.12 → 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.
@@ -1786,6 +1786,7 @@ var AbracadabraWS = class extends EventEmitter {
1786
1786
  this.webSocket?.removeEventListener(name, handlers[name]);
1787
1787
  delete this.webSocketHandlers[identifier];
1788
1788
  });
1789
+ if (this.webSocket.readyState !== 3) this.webSocket.addEventListener("error", () => {});
1789
1790
  try {
1790
1791
  if (this.webSocket.readyState !== 0 && this.webSocket.readyState !== 3) this.webSocket.close();
1791
1792
  } catch (e) {}
@@ -1892,6 +1893,7 @@ var AbracadabraWS = class extends EventEmitter {
1892
1893
  }
1893
1894
  }
1894
1895
  destroy() {
1896
+ this.shouldConnect = false;
1895
1897
  this.emit("destroy");
1896
1898
  clearInterval(this.intervals.connectionChecker);
1897
1899
  this.stopConnectionAttempt();
@@ -2567,10 +2569,11 @@ var OfflineStore = class {
2567
2569
  constructor(docId, serverOrigin) {
2568
2570
  this.db = null;
2569
2571
  this.dbPromise = null;
2572
+ this._destroyed = false;
2570
2573
  this.storeKey = serverOrigin ? `${serverOrigin}/${docId}` : docId;
2571
2574
  }
2572
2575
  getDb() {
2573
- if (!idbAvailable$4()) return Promise.resolve(null);
2576
+ if (this._destroyed || !idbAvailable$4()) return Promise.resolve(null);
2574
2577
  if (!this.dbPromise) this.dbPromise = openDb$5(this.storeKey).catch(() => null).then((db) => {
2575
2578
  this.db = db;
2576
2579
  return db;
@@ -2666,17 +2669,18 @@ var OfflineStore = class {
2666
2669
  const db = await this.getDb();
2667
2670
  if (!db) return null;
2668
2671
  const tx = db.transaction("meta", "readonly");
2669
- return await txPromise$2(tx.objectStore("meta"), tx.objectStore("meta").get(key)) ?? null;
2672
+ return await txPromise$2(tx.objectStore("meta"), tx.objectStore("meta").get(`meta:${key}`)) ?? null;
2670
2673
  }
2671
2674
  async setMeta(key, value) {
2672
2675
  const db = await this.getDb();
2673
2676
  if (!db) return;
2674
2677
  const tx = db.transaction("meta", "readwrite");
2675
- await txPromise$2(tx.objectStore("meta"), tx.objectStore("meta").put(value, key));
2678
+ await txPromise$2(tx.objectStore("meta"), tx.objectStore("meta").put(value, `meta:${key}`));
2676
2679
  }
2677
2680
  destroy() {
2678
- this.db?.close();
2681
+ this._destroyed = true;
2679
2682
  this.db = null;
2683
+ this.dbPromise = null;
2680
2684
  }
2681
2685
  };
2682
2686
 
@@ -7563,6 +7567,60 @@ var FileBlobStore = class FileBlobStore extends EventEmitter {
7563
7567
  this.objectUrls.set(key, url);
7564
7568
  return url;
7565
7569
  }
7570
+ /**
7571
+ * Retrieve the raw Blob from IDB for a previously cached upload.
7572
+ * Returns null if the blob has been evicted or was never stored.
7573
+ * Use this to re-upload a file after a page reload.
7574
+ */
7575
+ async getBlob(docId, uploadId) {
7576
+ const db = await this.getDb();
7577
+ if (!db) return null;
7578
+ const key = this.blobKey(docId, uploadId);
7579
+ const tx = db.transaction("blobs", "readonly");
7580
+ return (await txPromise(tx.objectStore("blobs"), tx.objectStore("blobs").get(key)))?.blob ?? null;
7581
+ }
7582
+ /** Return metadata for all cached blobs (for storage stats). */
7583
+ async getAllCachedEntries() {
7584
+ const db = await this.getDb();
7585
+ if (!db) return [];
7586
+ return new Promise((resolve, reject) => {
7587
+ const tx = db.transaction("blobs", "readonly");
7588
+ const store = tx.objectStore("blobs");
7589
+ const keysReq = store.getAllKeys();
7590
+ const valuesReq = store.getAll();
7591
+ tx.oncomplete = () => {
7592
+ const keys = keysReq.result;
7593
+ const values = valuesReq.result;
7594
+ resolve(keys.map((key, i) => {
7595
+ const slashIdx = key.indexOf("/");
7596
+ const docId = key.slice(0, slashIdx);
7597
+ const uploadId = key.slice(slashIdx + 1);
7598
+ const e = values[i];
7599
+ return {
7600
+ docId,
7601
+ uploadId,
7602
+ filename: e.filename,
7603
+ mimeType: e.mime_type,
7604
+ size: e.blob.size,
7605
+ cachedAt: e.cachedAt
7606
+ };
7607
+ }));
7608
+ };
7609
+ tx.onerror = () => reject(tx.error);
7610
+ });
7611
+ }
7612
+ /** Revoke all object URLs and clear the entire blob cache from IDB. */
7613
+ async clearAllBlobs() {
7614
+ for (const url of this.objectUrls.values()) URL.revokeObjectURL(url);
7615
+ this.objectUrls.clear();
7616
+ const db = await this.getDb();
7617
+ if (!db) return;
7618
+ return new Promise((resolve, reject) => {
7619
+ const req = db.transaction("blobs", "readwrite").objectStore("blobs").clear();
7620
+ req.onsuccess = () => resolve();
7621
+ req.onerror = () => reject(req.error);
7622
+ });
7623
+ }
7566
7624
  /** Revoke the object URL and remove the blob from cache. */
7567
7625
  async evictBlob(docId, uploadId) {
7568
7626
  const key = this.blobKey(docId, uploadId);