Quick Start
Build your first schema registry with doba in under 5 minutes.
Quick Start
Create a registry that transforms user data between database, frontend, and AI representations.
Define your schemas
Each schema represents a different view of the same data:
import { z } from 'zod'
const databaseUser = z.object({
id: z.string(),
email: z.string(),
passwordHash: z.string(),
createdAt: z.string(),
role: z.enum(['admin', 'user']),
})
const frontendUser = z.object({
id: z.string(),
email: z.string(),
createdAt: z.string(),
role: z.enum(['admin', 'user']),
})
const aiUser = z.object({
id: z.string(),
email: z.string(),
isAdmin: z.boolean(),
})Create the registry
Register schemas and define migrations between them:
import { createRegistry } from 'dobajs'
const userRegistry = createRegistry({
schemas: {
database: databaseUser,
frontend: frontendUser,
ai: aiUser,
},
migrations: {
'database->frontend': (user) => ({
id: user.id,
email: user.email,
createdAt: user.createdAt,
role: user.role,
// passwordHash is stripped!
}),
'database->ai': (user) => ({
id: user.id,
email: user.email,
isAdmin: user.role === 'admin',
}),
'frontend->ai': (user) => ({
id: user.id,
email: user.email,
isAdmin: user.role === 'admin',
}),
},
})This creates the following migration graph:
Transform data
const = {
: 'user-123',
: 'alice@example.com',
: 'hashed_xyz',
: '2024-01-15T10:30:00Z',
: 'admin' as ,
}
const = await .(, 'database', 'frontend')
if (.) {
.value ..path}Handle errors
doba returns errors as values. No try/catch:
const result = await userRegistry.transform(invalidData, 'database', 'frontend')
if (!result.ok) {
for (const issue of result.issues) {
console.log(issue.message)
// Typed validation errors
}
}What's next?
Path finding
Learn how doba automatically chains migrations through intermediate schemas.
Validation
Control when and how data is validated during transforms.
Migration context
Track warnings, defaults, and audit trails through your migrations.
Schema identification
Detect which schema unknown data belongs to and transform it in one call.
Migration helpers
Type-safe pipe builder for field renaming, mapping, adding, and dropping.
Examples
Full working examples with Zod, Valibot, ArkType, and more.