Skip to content
LogoLogo

Storage.from

Wraps a base store with a key prefix. All keys are automatically prefixed with {key}:. The wrapper preserves compareAndSet when the base store provides it.

Usage

import { Storage } from 'viem/tempo'
 
const base = Storage.memory()
const store = Storage.from(base, { key: 'tempo' })
 
await store.setItem('foo', 'bar')
 
// Stored under "tempo:foo" in the base store.
const value = await base.getItem('tempo:foo')
'bar'

Parameters

store

  • Type: Storage

The base store to wrap.

options.key (optional)

  • Type: string

Key prefix prepended to all store keys. If omitted, the base store is returned as-is.

Return Type

type ReturnType = Storage

A Storage instance that prefixes all keys.