@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.
- package/dist/abracadabra-provider.cjs +62 -4
- package/dist/abracadabra-provider.cjs.map +1 -1
- package/dist/abracadabra-provider.esm.js +62 -4
- package/dist/abracadabra-provider.esm.js.map +1 -1
- package/dist/index.d.ts +20 -0
- package/package.json +1 -1
- package/src/AbracadabraClient.ts +1 -1
- package/src/AbracadabraWS.ts +16 -3
- package/src/FileBlobStore.ts +59 -0
- package/src/OfflineStore.ts +11 -4
|
@@ -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.
|
|
2711
|
+
this._destroyed = true;
|
|
2709
2712
|
this.db = null;
|
|
2713
|
+
this.dbPromise = null;
|
|
2710
2714
|
}
|
|
2711
2715
|
};
|
|
2712
2716
|
|
|
@@ -7593,6 +7597,60 @@ var FileBlobStore = class FileBlobStore extends EventEmitter {
|
|
|
7593
7597
|
this.objectUrls.set(key, url);
|
|
7594
7598
|
return url;
|
|
7595
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
|
+
}
|
|
7612
|
+
/** Return metadata for all cached blobs (for storage stats). */
|
|
7613
|
+
async getAllCachedEntries() {
|
|
7614
|
+
const db = await this.getDb();
|
|
7615
|
+
if (!db) return [];
|
|
7616
|
+
return new Promise((resolve, reject) => {
|
|
7617
|
+
const tx = db.transaction("blobs", "readonly");
|
|
7618
|
+
const store = tx.objectStore("blobs");
|
|
7619
|
+
const keysReq = store.getAllKeys();
|
|
7620
|
+
const valuesReq = store.getAll();
|
|
7621
|
+
tx.oncomplete = () => {
|
|
7622
|
+
const keys = keysReq.result;
|
|
7623
|
+
const values = valuesReq.result;
|
|
7624
|
+
resolve(keys.map((key, i) => {
|
|
7625
|
+
const slashIdx = key.indexOf("/");
|
|
7626
|
+
const docId = key.slice(0, slashIdx);
|
|
7627
|
+
const uploadId = key.slice(slashIdx + 1);
|
|
7628
|
+
const e = values[i];
|
|
7629
|
+
return {
|
|
7630
|
+
docId,
|
|
7631
|
+
uploadId,
|
|
7632
|
+
filename: e.filename,
|
|
7633
|
+
mimeType: e.mime_type,
|
|
7634
|
+
size: e.blob.size,
|
|
7635
|
+
cachedAt: e.cachedAt
|
|
7636
|
+
};
|
|
7637
|
+
}));
|
|
7638
|
+
};
|
|
7639
|
+
tx.onerror = () => reject(tx.error);
|
|
7640
|
+
});
|
|
7641
|
+
}
|
|
7642
|
+
/** Revoke all object URLs and clear the entire blob cache from IDB. */
|
|
7643
|
+
async clearAllBlobs() {
|
|
7644
|
+
for (const url of this.objectUrls.values()) URL.revokeObjectURL(url);
|
|
7645
|
+
this.objectUrls.clear();
|
|
7646
|
+
const db = await this.getDb();
|
|
7647
|
+
if (!db) return;
|
|
7648
|
+
return new Promise((resolve, reject) => {
|
|
7649
|
+
const req = db.transaction("blobs", "readwrite").objectStore("blobs").clear();
|
|
7650
|
+
req.onsuccess = () => resolve();
|
|
7651
|
+
req.onerror = () => reject(req.error);
|
|
7652
|
+
});
|
|
7653
|
+
}
|
|
7596
7654
|
/** Revoke the object URL and remove the blob from cache. */
|
|
7597
7655
|
async evictBlob(docId, uploadId) {
|
|
7598
7656
|
const key = this.blobKey(docId, uploadId);
|