@abraca/dabra 1.0.0 → 1.0.1

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
@@ -1329,6 +1329,12 @@ declare class FileBlobStore extends EventEmitter {
1329
1329
  * URL.createObjectURL is unavailable (e.g. Node.js / SSR).
1330
1330
  */
1331
1331
  getBlobUrl(docId: string, uploadId: string): Promise<string | null>;
1332
+ /**
1333
+ * Store a blob directly into the cache under the given (docId, uploadId) key
1334
+ * and return its object URL. Use this to pre-populate the cache for files
1335
+ * that haven't been uploaded to the server yet (e.g. offline upload queue).
1336
+ */
1337
+ putBlob(docId: string, uploadId: string, blob: Blob, filename: string): Promise<string>;
1332
1338
  /** Revoke the object URL and remove the blob from cache. */
1333
1339
  evictBlob(docId: string, uploadId: string): Promise<void>;
1334
1340
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abraca/dabra",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "abracadabra provider",
5
5
  "keywords": [
6
6
  "abracadabra",
@@ -160,6 +160,42 @@ export class FileBlobStore extends EventEmitter {
160
160
  return url;
161
161
  }
162
162
 
163
+ /**
164
+ * Store a blob directly into the cache under the given (docId, uploadId) key
165
+ * and return its object URL. Use this to pre-populate the cache for files
166
+ * that haven't been uploaded to the server yet (e.g. offline upload queue).
167
+ */
168
+ async putBlob(
169
+ docId: string,
170
+ uploadId: string,
171
+ blob: Blob,
172
+ filename: string,
173
+ ): Promise<string> {
174
+ if (typeof window === "undefined") return URL.createObjectURL(blob);
175
+
176
+ const key = this.blobKey(docId, uploadId);
177
+
178
+ // Return existing URL if already cached in-memory
179
+ const existing = this.objectUrls.get(key);
180
+ if (existing) return existing;
181
+
182
+ const db = await this.getDb();
183
+ if (db) {
184
+ const entry: BlobCacheEntry = {
185
+ blob,
186
+ mime_type: blob.type || "application/octet-stream",
187
+ filename,
188
+ cachedAt: Date.now(),
189
+ };
190
+ const tx = db.transaction("blobs", "readwrite");
191
+ tx.objectStore("blobs").put(entry, key);
192
+ }
193
+
194
+ const url = URL.createObjectURL(blob);
195
+ this.objectUrls.set(key, url);
196
+ return url;
197
+ }
198
+
163
199
  /** Revoke the object URL and remove the blob from cache. */
164
200
  async evictBlob(docId: string, uploadId: string): Promise<void> {
165
201
  const key = this.blobKey(docId, uploadId);