# @varasto/multi-storage

> Combines multiple Varasto storages into one

Latest version **6.0.0** (published 2026-10-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install @varasto/multi-storage
pnpm add @varasto/multi-storage
yarn add @varasto/multi-storage
bun add @varasto/multi-storage
```

## Health

**Score 70/100 (B)** — status: active.

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 6.0.0 |
| Published | 2026-10-04 |
| First published | 2021-10-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22.0 |
| Dependencies | 2 |
| Unpacked size | 12.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Rauli Laine <rauli.laine@iki.fi> |
| Maintainers | rauli |
| Keywords | replication, varasto |

## Links

- npm: https://www.npmjs.com/package/@varasto/multi-storage
- Repository: https://github.com/RauliL/varasto
- Homepage: https://rauli.dev/varasto
- Issues: https://github.com/RauliL/varasto/issues
- npm.io page: https://npm.io/package/@varasto/multi-storage

## Dependencies (2)

- [picomatch](https://npm.io/package/picomatch.md) ^4.0.7
- [@varasto/storage](https://npm.io/package/@varasto/storage.md) ^6.0.0

## Recent versions

- 6.0.0 (latest) — 2026-10-04
- 5.0.1 — 2026-10-04
- 5.0.0 — 2026-10-04
- 4.0.0 — 2026-09-05
- 3.0.0 — 2023-10-05
- 2.0.0 — 2023-09-30
- 1.0.1 — 2021-10-23
- 1.0.0 — 2021-10-08

## README

# @varasto/multi-storage

[![npm][npm-image]][npm-url]

[Storage] implementation which routes namespaces to one or more other storage
instances using [picomatch] patterns.

[npm-image]: https://img.shields.io/npm/v/@varasto/multi-storage.svg
[npm-url]: https://npmjs.org/package/@varasto/multi-storage
[storage]: https://www.npmjs.com/package/@varasto/storage
[picomatch]: https://github.com/micromatch/picomatch

## Installation

```shell
$ npm install --save @varasto/multi-storage
```

## Usage

The package provides a function called `createMultiStorage` which takes a
configuration object that maps namespace patterns to storage instances. Patterns
are matched with [picomatch]; the first matching pattern wins.

```TypeScript
import { createMemoryStorage } from '@varasto/memory-storage';
import { createMultiStorage } from '@varasto/multi-storage';

const usersStorage = createMemoryStorage();
const postsStorage = createMemoryStorage();
const postsReplica = createMemoryStorage();
const fallbackStorage = createMemoryStorage();

const multiStorage = createMultiStorage({
  users: usersStorage,
  'posts-*': [postsStorage, postsReplica],
  '*': fallbackStorage,
});

// Routed to `usersStorage`.
await multiStorage.set('users', '1', { name: 'Alice' });

// Routed to both `postsStorage` and `postsReplica`.
await multiStorage.set('posts-123', '1', { title: 'Hello' });

// Routed to `fallbackStorage`.
await multiStorage.set('other', '1', { value: 5 });
```

When a pattern maps to an array of storages, reads are merged across them and
writes/updates/deletes are applied to all of them. If no pattern matches the
namespace, the operation is a no-op (and `update` rejects with
`ItemDoesNotExistError`).

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