Skip to content

ValkeyrieType-safe key-value store

Runtime schema validation with pluggable storage drivers for Node.js

Valkeyrie Logo

Quick Start

Install Valkeyrie in your project:

bash
npm install valkeyrie
bash
pnpm add valkeyrie
bash
yarn add valkeyrie

Create a type-safe key-value store with schema validation:

typescript
import { Valkeyrie } from 'valkeyrie'
import { z } from 'zod'

// Define your schema with Zod (or Valibot, ArkType, etc.)
const userSchema = z.object({
  name: z.string(),
  email: z.string().email(),
  age: z.number().min(0)
})

// Register the schema and open the database
const db = await Valkeyrie
  .withSchema(['users', '*'], userSchema)
  .open('./my-data.db')

// Set a value - automatically validated!
await db.set(['users', 'alice'], {
  name: 'Alice',
  email: 'alice@example.com',
  age: 30
})

// Get the value - fully typed!
const user = await db.get(['users', 'alice'])
// user.value type: { name: string, email: string, age: number } | null

// List all users with prefix
for await (const entry of db.list({ prefix: ['users'] })) {
  console.log('User:', entry.value)
}

// Watch for changes
for await (const entries of db.watch([['users', 'alice']])) {
  console.log('User updated:', entries[0].value)
}

Why Valkeyrie?

Valkeyrie brings the best of both worlds: the simplicity of key-value stores and the safety of runtime schema validation.

🔐 Runtime Safety

Never trust input data again. Valkeyrie validates every value against your schema at runtime, catching bugs before they become problems.

💎 Type Inference Magic

Define your schema once, get TypeScript types everywhere. No more maintaining parallel type definitions.

⚡ Atomic Transactions

Modify multiple keys in a single atomic operation with automatic conflict resolution. No more race conditions.

🎨 Flexible Serialization

Choose the serializer that fits your needs:

  • JSON: Maximum compatibility
  • V8: Best performance for Node.js
  • BSON, MessagePack, CBOR: Efficient binary formats

What's Next?

License

MIT © Ducktors

Released under the MIT License.