# @cubux/storage-driver

> Simple storage driver abstraction.

Latest version **0.6.0** (published 2026-08-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install @cubux/storage-driver
pnpm add @cubux/storage-driver
yarn add @cubux/storage-driver
bun add @cubux/storage-driver
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.6.0 |
| Published | 2026-08-14 |
| First published | 2022-09-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=24 |
| Dependencies | 0 |
| Unpacked size | 36.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Vovan-VE |
| Maintainers | vovan-ve |
| Keywords | storage, abstract, abstraction, localStorage, sessionStorage, indexedDB, persist, persistent |

## Links

- npm: https://www.npmjs.com/package/@cubux/storage-driver
- Repository: https://github.com/cubux-net/ts-storage-driver
- Homepage: https://github.com/cubux-net/ts-storage-driver#readme
- Issues: https://github.com/cubux-net/ts-storage-driver/issues
- npm.io page: https://npm.io/package/@cubux/storage-driver

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 0.6.0 (latest) — 2026-08-14
- 0.5.0 — 2023-12-16
- 0.4.0 — 2023-12-11
- 0.3.1 — 2022-09-10
- 0.3.0 — 2022-09-09
- 0.2.0 — 2022-09-07
- 0.1.0 — 2022-09-06

## README

# `@cubux/storage-driver`

[![NPM latest](https://img.shields.io/npm/v/@cubux/storage-driver.svg)](https://www.npmjs.com/package/@cubux/storage-driver)

Simple storage driver abstraction for [`@cubux/effector-persistent`](https://github.com/cubux-net/effector-persistent).
Persist you `effector` Store with `localStorage`/`sessionStorage`, `indexedDB`,
or implement a custom driver.

## Install

```sh
npm i @cubux/storage-driver
```

## API

### `interface StoreDriverSingle<K, V, VOut = V>`

Driver interface to read/write data by single item.

#### Methods

##### `getItem(key: K): Promise<VOut | undefined>`

Get value of specific item with the given key.

##### `removeItem(key: K): Promise<void>`

Remove item with the given key.

##### `setItem(key: K, value: V): Promise<void>`

Store the given value in item with the given key.

### `interface StoreDriverMapped<K, V, VOut = V>`

Driver interface to read/write all items at once.

#### Methods

##### `getAll(): Promise<ReadonlyMap<K, VOut>>`

Get all items.

##### `setAll(items: ReadonlyMap<K, V>): Promise<void>`

Replace all stored items with the given new items. That is keys became missing
will be removed from storage.

### `interface StoreDriver<K, V, VOut = V>`

Generalized interface covering all specific interfaces above.

### `createLocalStorageDriver()`

Create driver to interact with `localStorage`-like storage. Actual storage
can be set in `options`, so it could be `sessionStorage` for example or
another compatible alternative.

```ts
function createLocalStorageDriver<V>(
  options?: LocalStorageOptions<V>,
): StoreDriver<string, V>
```

Options `LocalStorageOptions<V>` to customize driver:

| Option        | Type                   | Default               | Description                                                                          |
|---------------|------------------------|-----------------------|--------------------------------------------------------------------------------------|
| `storage`     | `Storage`              | `window.localStorage` | Actual data storage.                                                                 |
| `prefix`      | `string`               | `"persistent"`        | Key prefix in `storage` to distinguish only related keys.                            |
| `serialize`   | `(value: V) => string` | `JSON.stringify`      | Custom function to serialize input value to string before putting it into `storage`. |
| `unserialize` | `(data: string) => V`  | `JSON.parse`          | Custom function to unserialize data read from `storage`.                                                                                     |

### `createIndexedDBDriver()`

Create driver to interact with `indexedDB`-like storage. Actual storage can be
overridden in `options`.

```ts
function createIndexedDBDriver<K, V, S = V>(
  options: IndexedDBOptions<K, V, S>
): Promise<StoreDriver<K, V>>
```

Options `IndexedDBOptions<K, V, S>` to customize driver:

| Option        | Type                      | Default            | Description                                                                                                                                      |
|---------------|---------------------------|--------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|
| `dbName`      | `string`                  | **Required**       | Database name.                                                                                                                                   |
| `dbVersion`   | `number`                  | `1`                | Database version. Probably, this option should internal.                                                                                         |
| `table`       | `string`                  | **Required**       | Object store name (aka table name).                                                                                                              |
| `indexedDB`   | `IDBFactory`              | `window.indexedDB` | Actual `indexedDB` factory. Default is `window.indexedDB`. Can be used in tests to mock implementation or to use custom polyfill implementation. |
| `serialize`   | `(value: V, key: K) => S` | `(v) => v`         | Custom function to serialize input value before putting it into DB.                                                                              |
| `unserialize` | `(data: S, key: K) => V`  | `(v) => v`         | Custom function to unserialize data read from DB.                                                                                                |

### `createNullDriver()`

Create dummy no-op driver. Can be used for example in test environment to omit
actual driver. This driver always contains nothing in reads and does nothing on
writes.

```ts
function createNullDriver<K = any, V = any>(): StoreDriver<K, V, never>
```

---
_Source: https://npm.io/package/@cubux/storage-driver · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
