@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.
@@ -1816,6 +1816,7 @@ var AbracadabraWS = class extends EventEmitter {
1816
1816
  this.webSocket?.removeEventListener(name, handlers[name]);
1817
1817
  delete this.webSocketHandlers[identifier];
1818
1818
  });
1819
+ if (this.webSocket.readyState !== 3) this.webSocket.addEventListener("error", () => {});
1819
1820
  try {
1820
1821
  if (this.webSocket.readyState !== 0 && this.webSocket.readyState !== 3) this.webSocket.close();
1821
1822
  } catch (e) {}
@@ -1922,6 +1923,7 @@ var AbracadabraWS = class extends EventEmitter {
1922
1923
  }
1923
1924
  }
1924
1925
  destroy() {
1926
+ this.shouldConnect = false;
1925
1927
  this.emit("destroy");
1926
1928
  clearInterval(this.intervals.connectionChecker);
1927
1929
  this.stopConnectionAttempt();
@@ -2597,10 +2599,11 @@ var OfflineStore = class {
2597
2599
  constructor(docId, serverOrigin) {
2598
2600
  this.db = null;
2599
2601
  this.dbPromise = null;
2602
+ this._destroyed = false;
2600
2603
  this.storeKey = serverOrigin ? `${serverOrigin}/${docId}` : docId;
2601
2604
  }
2602
2605
  getDb() {
2603
- if (!idbAvailable$4()) return Promise.resolve(null);
2606
+ if (this._destroyed || !idbAvailable$4()) return Promise.resolve(null);
2604
2607
  if (!this.dbPromise) this.dbPromise = openDb$5(this.storeKey).catch(() => null).then((db) => {
2605
2608
  this.db = db;
2606
2609
  return db;
@@ -2696,17 +2699,18 @@ var OfflineStore = class {
2696
2699
  const db = await this.getDb();
2697
2700
  if (!db) return null;
2698
2701
  const tx = db.transaction("meta", "readonly");
2699
- return await txPromise$2(tx.objectStore("meta"), tx.objectStore("meta").get(key)) ?? null;
2702
+ return await txPromise$2(tx.objectStore("meta"), tx.objectStore("meta").get(`meta:${key}`)) ?? null;
2700
2703
  }
2701
2704
  async setMeta(key, value) {
2702
2705
  const db = await this.getDb();
2703
2706
  if (!db) return;
2704
2707
  const tx = db.transaction("meta", "readwrite");
2705
- await txPromise$2(tx.objectStore("meta"), tx.objectStore("meta").put(value, key));
2708
+ await txPromise$2(tx.objectStore("meta"), tx.objectStore("meta").put(value, `meta:${key}`));
2706
2709
  }
2707
2710
  destroy() {
2708
- this.db?.close();
2711
+ this._destroyed = true;
2709
2712
  this.db = null;
2713
+ this.dbPromise = null;
2710
2714
  }
2711
2715
  };
2712
2716
 
@@ -7495,12 +7499,16 @@ function txPromise(store, request) {
7495
7499
  request.onerror = () => reject(request.error);
7496
7500
  });
7497
7501
  }
7498
- var FileBlobStore = class extends EventEmitter {
7502
+ var FileBlobStore = class FileBlobStore extends EventEmitter {
7503
+ static {
7504
+ this.NOT_FOUND_TTL = 300 * 1e3;
7505
+ }
7499
7506
  constructor(serverOrigin, client) {
7500
7507
  super();
7501
7508
  this.dbPromise = null;
7502
7509
  this.db = null;
7503
7510
  this.objectUrls = /* @__PURE__ */ new Map();
7511
+ this._notFound = /* @__PURE__ */ new Map();
7504
7512
  this._flushing = false;
7505
7513
  this.origin = serverOrigin;
7506
7514
  this.client = client ?? null;
@@ -7542,10 +7550,13 @@ var FileBlobStore = class extends EventEmitter {
7542
7550
  }
7543
7551
  }
7544
7552
  if (!this.client) return null;
7553
+ const nfTime = this._notFound.get(key);
7554
+ if (nfTime && Date.now() - nfTime < FileBlobStore.NOT_FOUND_TTL) return null;
7545
7555
  let blob;
7546
7556
  try {
7547
7557
  blob = await this.client.getUpload(docId, uploadId);
7548
- } catch {
7558
+ } catch (err) {
7559
+ if (err?.status === 404) this._notFound.set(key, Date.now());
7549
7560
  return null;
7550
7561
  }
7551
7562
  if (db) {
@@ -7569,6 +7580,7 @@ var FileBlobStore = class extends EventEmitter {
7569
7580
  async putBlob(docId, uploadId, blob, filename) {
7570
7581
  if (typeof window === "undefined") return URL.createObjectURL(blob);
7571
7582
  const key = this.blobKey(docId, uploadId);
7583
+ this._notFound.delete(key);
7572
7584
  const existing = this.objectUrls.get(key);
7573
7585
  if (existing) return existing;
7574
7586
  const db = await this.getDb();
@@ -7585,6 +7597,18 @@ var FileBlobStore = class extends EventEmitter {
7585
7597
  this.objectUrls.set(key, url);
7586
7598
  return url;
7587
7599
  }
7600
+ /**
7601
+ * Retrieve the raw Blob from IDB for a previously cached upload.
7602
+ * Returns null if the blob has been evicted or was never stored.
7603
+ * Use this to re-upload a file after a page reload.
7604
+ */
7605
+ async getBlob(docId, uploadId) {
7606
+ const db = await this.getDb();
7607
+ if (!db) return null;
7608
+ const key = this.blobKey(docId, uploadId);
7609
+ const tx = db.transaction("blobs", "readonly");
7610
+ return (await txPromise(tx.objectStore("blobs"), tx.objectStore("blobs").get(key)))?.blob ?? null;
7611
+ }
7588
7612
  /** Revoke the object URL and remove the blob from cache. */
7589
7613
  async evictBlob(docId, uploadId) {
7590
7614
  const key = this.blobKey(docId, uploadId);