These wrappers store data in the browser. They do not supply server persistence. StorageOptions can validate a deserialized value; a generic type alone does not validate stored data.
Read the usage guide or all entry points.
6 exports · published 3.0.0 declarations
import { createIndexedDB } from '@getforma/core/storage';Values and functions
createIndexedDB#
declare function createIndexedDB<T>(dbName: string, storeName?: string): IDBStore<T>;Create a simplified IndexedDB store.
const store = createIndexedDB<User>('myApp', 'users');
await store.set('u1', { name: 'Alice' });
const user = await store.get('u1'); // { name: 'Alice' }Related declarations: IDBStore
createLocalStorage#
declare function createLocalStorage<T>(key: string, options?: StorageOptions<T>): TypedStorage<T>;Create a typed localStorage wrapper for the given key.
const store = createLocalStorage<{ name: string }>('user');
store.set({ name: 'Alice' });
store.get(); // { name: 'Alice' }
store.remove();Related declarations: StorageOptions, TypedStorage
createSessionStorage#
declare function createSessionStorage<T>(key: string, options?: StorageOptions<T>): TypedStorage<T>;Create a typed sessionStorage wrapper for the given key.
const store = createSessionStorage<{ token: string }>('auth');
store.set({ token: 'abc123' });
store.get(); // { token: 'abc123' }
store.remove();Related declarations: StorageOptions, TypedStorage
Exported types
IDBStore#
interface IDBStore<T> {
get(key: string): Promise<T | undefined>;
set(key: string, value: T): Promise<void>;
delete(key: string): Promise<void>;
getAll(): Promise<T[]>;
keys(): Promise<string[]>;
clear(): Promise<void>;
}Forma Storage - IndexedDB
Simplified IndexedDB wrapper with lazy connection and promise-based API. Zero dependencies — native browser APIs only.
StorageOptions#
interface StorageOptions<T> {
serialize?: (v: T) => string;
deserialize?: (s: string) => T;
validate?: (v: unknown) => v is T;
}Member notes
validate
Optional validator — return true if the deserialized value is valid.
TypedStorage#
interface TypedStorage<T> {
get(): T | null;
set(value: T): void;
remove(): void;
key: string;
}Other entry points
@getforma/core · @getforma/core/runtime · @getforma/core/runtime-hardened · @getforma/core/runtime-csp · @getforma/core/tc39 · @getforma/core/http · JSX namespace