Skip to content
CIVersionSizeTypeScriptDependencies
Deposit logo

Deposit

⚡ Quick Reference

Package: @vielzeug/deposit  ·  Category: Storage

Key exports: createLocalStorage, createSessionStorage, createCookie, createIndexedDB, createMemory, table

When to use: Structured, queryable browser storage with TTL and TypeScript types. Unified API across LocalStorage, IndexedDB, cookies, and in-memory.

Related: Fetchit · Logit · Toolkit

@vielzeug/deposit is a compact, typed browser storage library with five interchangeable adapters:

  • createLocalStorage(dbName, schema) for lightweight browser persistence
  • createSessionStorage(dbName, schema) for tab-scoped persistence
  • createCookie(dbName, schema, options?) for small browser state that should ride with requests
  • createIndexedDB() for transactional storage
  • createMemory(schema) for tests and SSR environments

Installation

sh
pnpm add @vielzeug/deposit
sh
npm install @vielzeug/deposit
sh
yarn add @vielzeug/deposit

Quick Start

ts
import { createIndexedDB, table } from '@vielzeug/deposit';

type User = { id: number; name: string; age: number };

const schema = {
  users: table<User>('id'),
};

const db = createIndexedDB({ dbName: 'app', schemaVersion: 1, schema });

await db.put('users', { id: 1, name: 'Alice', age: 30 });
const first = await db.query('users').between('age', 18, 99).first();

Why Deposit?

Native browser storage APIs are powerful but inconsistent and repetitive to use directly.

  • Typed table schemas via table<T>()
  • Five backends behind one interface (createLocalStorage, createSessionStorage, createCookie, createIndexedDB, createMemory)
  • Compact query builder for common read patterns
  • TTL on writes
  • Atomic multi-table transactions and cross-tab updates (IndexedDB)
ts
import { createLocalStorage, table } from '@vielzeug/deposit';

// Before: direct browser API and manual serialization
localStorage.setItem('users:1', JSON.stringify({ id: 1, name: 'Alice' }));

// After: typed schema + consistent adapter API
const schema = { users: table<User>('id') };
const local = createLocalStorage('app', schema);
await local.put('users', { id: 1, name: 'Alice', age: 30 });
FeatureDepositDexie.jsNative APIs
Bundle size4.5 KB~29 kB0 kB
Typed schema ergonomics✅ (table<T>())
LocalStorage + SessionStorage + Cookie + IndexedDB + Memory under one API❌ (IndexedDB only)
Built-in TTL on writes
Chainable query helpers
Atomic transactions✅ (IndexedDB adapter)⚠️ (manual wiring)

Use Deposit when you want a lightweight typed API that can target multiple browser storage backends with built-in TTL.

Use Dexie.js when you want a feature-rich IndexedDB-first toolkit and don't need LocalStorage parity in the same abstraction.

Use native APIs directly when you need the absolute minimum abstraction and are comfortable handling serialization, keying, migrations, and transaction plumbing yourself.

Features

  • Typed schemastable<T>(key) factory, full type inference, no annotation boilerplate
  • Adapter parity — same Adapter surface for LocalStorage, SessionStorage, Cookie, IndexedDB, and Memory
  • Chainable queriesequals, between, startsWith, orderBy, limit, offset, first
  • TTL support — auto-expire records via ttl.ms/seconds/minutes/hours/days
  • Bulk writesputAll() for atomic batch inserts
  • Existence checkhas() without loading the full record
  • Record utilitiesforEach, getOrPut, update, deleteWhere
  • Reactivityobserve(table, listener, options?) with immediate snapshot and unsubscribe
  • Transactional writestransaction() with rollback on callback failure
  • In-memory adapter — browser-free, zero-setup; ideal for tests and SSR
  • Zero dependencies — small and easy to audit

Compatibility

EnvironmentSupport
Browser
Node.js⚠️ (createMemory works; browser adapters require web APIs)
SSR⚠️ (createMemory works directly; browser adapters require polyfills)

Notes:

  • createLocalStorage requires localStorage.
  • createSessionStorage requires sessionStorage.
  • createCookie requires document and is browser-only.
  • createIndexedDB requires indexedDB.
  • createMemory has no environment requirements.

Documentation

See Also