@encody/storage-idb
v1.0.0
Published
Persistent IndexedDB storage adapter for the Encody client SDK — offline-capable upload queue
Readme
@encody/storage-idb
Persistent IndexedDB storage adapter for the Encody client SDK. Plugs into
@encody/vue (and @encody/vue2) to make the upload queue — including the
queued file Blobs — survive page reloads and browser restarts.
Zero dependencies, ~2 KB, raw IndexedDB in an isolated database.
Install
npm install @encody/storage-idbUsage
import { IndexedDBAdapter } from '@encody/storage-idb'
import { createEncody } from '@encody/vue/core'
const encody = createEncody({
token: () => getUploadToken(),
storage: new IndexedDBAdapter()
})Or with the Vue composable:
import { IndexedDBAdapter } from '@encody/storage-idb'
import { useEncody } from '@encody/vue'
const { add, files } = useEncody({
token: () => getUploadToken(),
storage: new IndexedDBAdapter()
})Options
const storage = new IndexedDBAdapter({
dbName: 'encody-uploads', // isolated database name
requestPersistence: true, // request navigator.storage.persist() on init
broadcast: true // live cross-tab sync via BroadcastChannel
})Behavior & caveats
Cross-tab sync: changes (status, progress, removals) broadcast to all tabs on the same database via
BroadcastChannel— blobs are never sent, other tabs read them from IndexedDB. The SDK core elects a leader tab via the Web Locks API so recovery/drain never duplicates uploads.Files are stored as Blobs via structured clone in the adapter's own database (
encody-uploads) — it never shares storage with your app's IndexedDB usage.On WebKit versions with broken Blob cloning, writes transparently fall back to ArrayBuffer storage and rehydrate to a
Fileon read.Storage is best-effort by browser policy:
navigator.storage.persist()is requested but heuristically granted. Safari evicts idle script storage after 7 days of no interaction (installed home-screen PWAs are exempt).Resuming queued uploads after a reload requires the queue recovery pass in the SDK core (
@encody/vue) — see its documentation.
