@vielzeug/vault
v1.0.3
Published
Storage adapter for IndexedDB and localStorage with TTL, reactive signals, and schema validation
Downloads
459
Readme
@vielzeug/vault
Typed browser storage with a compact API for LocalStorage, SessionStorage, IndexedDB, and Memory.
Package: @vielzeug/vault · Category: Storage
Key exports: createLocalStorage, createSessionStorage, createIndexedDB, createMemory, table, ttl, scheduleExpiredPrune
When to use: Structured, queryable browser storage with TTL, reactivity, and TypeScript types.
Related: @vielzeug/courier · @vielzeug/rune · @vielzeug/ripple · @vielzeug/spell · @vielzeug/arsenal
@vielzeug/vault is part of Vielzeug and ships as a zero-dependency TypeScript package with ESM+CJS output.
Installation
pnpm add @vielzeug/vault
npm install @vielzeug/vault
yarn add @vielzeug/vaultQuick Start
import { createIndexedDB, table, ttl } from '@vielzeug/vault';
type User = { id: number; name: string; age: number };
const schema = {
users: table<User>('id'),
};
const db = createIndexedDB({ name: 'my-app', schema, version: 1 });
await db.putAll('users', [
{ id: 1, name: 'Alice', age: 30 },
{ id: 2, name: 'Bob', age: 25 },
]);
// TTL — always use the ttl.* helpers
await db.put('users', { id: 3, name: 'Carol', age: 28 }, ttl.hours(1));
const first = await db.query('users').between('age', 18, 99).orderBy('name').first();
// observe always fires immediately with the current snapshot, then on each change
const stop = db.observe('users', (rows) => console.log(rows.length));
// stop from outside via AbortController
const controller = new AbortController();
for await (const users of db.watch('users', { signal: controller.signal })) {
console.log(users.length);
}
(void first, stop);Documentation
License
MIT © Helmuth Saatkamp — part of the Vielzeug monorepo.
