Skip to content
LogoLogo

Store.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 { Store } from 'viem/tempo'
 
const base = Store.memory()
const store = Store.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: Store.Store

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<store extends Store.Store> = store extends Store.Atomic
  ? Store.Atomic
  : Store.Store

A store that prefixes all keys and preserves atomic support from the base store.