@fluixi/storage
v0.1.0-alpha.2
Published
A universal storage abstraction: one typed API across browser, SSR, server and custom environments, with adapters, namespaces, expiry and versioned entries.
Downloads
1,121
Readme
@fluixi/storage
One typed key/value API over any backend: memory, localStorage, sessionStorage, cookies, a request, or your own. No dependency on the rest of Fluixi.
import { createStorage } from '@fluixi/storage';
import { localStorageAdapter } from '@fluixi/storage/browser';
const prefs = createStorage<{ theme: 'light' | 'dark' }>({ adapter: localStorageAdapter(), namespace: 'app' });
prefs.set('theme', 'dark', { ttl: 30 * 24 * 3600_000 });
prefs.get('theme'); // 'dark' | null- Adapters:
memoryStorage(.),localStorageAdapter,sessionStorageAdapteranddocumentCookieAdapter(./browser),cookieStorageandrequestStorage(./server), or your own. - Values: namespaces, expiry, versions and migrations, a strict JSON serializer that refuses what JSON would silently change.
- Management:
search,entries,prune,usage,update,getOrSet,snapshot,restore,copyStorage. - Changes:
subscribe, across every storage over the same adapter and across tabs. - Encryption: per item and opt in, AES-256-GCM through Web Crypto, with a key provider.
- Errors: one
StorageErrorfamily with stable codes.
In a Fluixi app, useStorage, persisted and the theme helpers in @fluixi/core build on it.
Documentation: Storage and Storage in an app.
