@abraca/dabra 1.0.11 → 1.0.13

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
 
@@ -7465,12 +7469,16 @@ function txPromise(store, request) {
7465
7469
  request.onerror = () => reject(request.error);
7466
7470
  });
7467
7471
  }
7468
- var FileBlobStore = class extends EventEmitter {
7472
+ var FileBlobStore = class FileBlobStore extends EventEmitter {
7473
+ static {
7474
+ this.NOT_FOUND_TTL = 300 * 1e3;
7475
+ }
7469
7476
  constructor(serverOrigin, client) {
7470
7477
  super();
7471
7478
  this.dbPromise = null;
7472
7479
  this.db = null;
7473
7480
  this.objectUrls = /* @__PURE__ */ new Map();
7481
+ this._notFound = /* @__PURE__ */ new Map();
7474
7482
  this._flushing = false;
7475
7483
  this.origin = serverOrigin;
7476
7484
  this.client = client ?? null;
@@ -7512,10 +7520,13 @@ var FileBlobStore = class extends EventEmitter {
7512
7520
  }
7513
7521
  }
7514
7522
  if (!this.client) return null;
7523
+ const nfTime = this._notFound.get(key);
7524
+ if (nfTime && Date.now() - nfTime < FileBlobStore.NOT_FOUND_TTL) return null;
7515
7525
  let blob;
7516
7526
  try {
7517
7527
  blob = await this.client.getUpload(docId, uploadId);
7518
- } catch {
7528
+ } catch (err) {
7529
+ if (err?.status === 404) this._notFound.set(key, Date.now());
7519
7530
  return null;
7520
7531
  }
7521
7532
  if (db) {
@@ -7539,6 +7550,7 @@ var FileBlobStore = class extends EventEmitter {
7539
7550
  async putBlob(docId, uploadId, blob, filename) {
7540
7551
  if (typeof window === "undefined") return URL.createObjectURL(blob);
7541
7552
  const key = this.blobKey(docId, uploadId);
7553
+ this._notFound.delete(key);
7542
7554
  const existing = this.objectUrls.get(key);
7543
7555
  if (existing) return existing;
7544
7556
  const db = await this.getDb();
@@ -7555,6 +7567,18 @@ var FileBlobStore = class extends EventEmitter {
7555
7567
  this.objectUrls.set(key, url);
7556
7568
  return url;
7557
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
+ }
7558
7582
  /** Revoke the object URL and remove the blob from cache. */
7559
7583
  async evictBlob(docId, uploadId) {
7560
7584
  const key = this.blobKey(docId, uploadId);