# @getforma/core/storage

Typed localStorage, sessionStorage and IndexedDB wrappers.

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.

Published declaration: [@getforma/core@3.0.0](https://unpkg.com/@getforma/core@3.0.0/dist/storage.d.ts).

## Values and functions

### createIndexedDB

Function export

```ts
declare function createIndexedDB<T>(dbName: string, storeName?: string): IDBStore<T>;
```

Create a simplified IndexedDB store.

```ts
const store = createIndexedDB<User>('myApp', 'users');
await store.set('u1', { name: 'Alice' });
const user = await store.get('u1'); // { name: 'Alice' }
```

Related declarations: [`IDBStore`](/docs/3.0/api-storage/#symbol-IDBStore)

### createLocalStorage

Function export

```ts
declare function createLocalStorage<T>(key: string, options?: StorageOptions<T>): TypedStorage<T>;
```

Create a typed localStorage wrapper for the given key.

```ts
const store = createLocalStorage<{ name: string }>('user');
store.set({ name: 'Alice' });
store.get(); // { name: 'Alice' }
store.remove();
```

Related declarations: [`StorageOptions`](/docs/3.0/api-storage/#symbol-StorageOptions), [`TypedStorage`](/docs/3.0/api-storage/#symbol-TypedStorage)

### createSessionStorage

Function export

```ts
declare function createSessionStorage<T>(key: string, options?: StorageOptions<T>): TypedStorage<T>;
```

Create a typed sessionStorage wrapper for the given key.

```ts
const store = createSessionStorage<{ token: string }>('auth');
store.set({ token: 'abc123' });
store.get(); // { token: 'abc123' }
store.remove();
```

Related declarations: [`StorageOptions`](/docs/3.0/api-storage/#symbol-StorageOptions), [`TypedStorage`](/docs/3.0/api-storage/#symbol-TypedStorage)

## Exported types

### IDBStore

Interface export

```ts
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 export

```ts
interface StorageOptions<T> {
    serialize?: (v: T) => string;
    deserialize?: (s: string) => T;
    validate?: (v: unknown) => v is T;
}
```



**`validate`**

Optional validator — return true if the deserialized value is valid.

### TypedStorage

Interface export

```ts
interface TypedStorage<T> {
    get(): T | null;
    set(value: T): void;
    remove(): void;
    key: string;
}
```



## Other entry points

[@getforma/core](/docs/3.0/api-core/) · [@getforma/core/runtime](/docs/3.0/api-runtime/) · [@getforma/core/runtime-hardened](/docs/3.0/api-runtime-hardened/) · [@getforma/core/runtime-csp](/docs/3.0/api-runtime-csp/) · [@getforma/core/tc39](/docs/3.0/api-tc39/) · [@getforma/core/http](/docs/3.0/api-http/) · [JSX namespace](/docs/3.0/api-jsx/)