Prisma → Valibot in one generate. Ship validated, typed data everywhere.
Prisma → Valibot generator: zero‑boilerplate validation for your models.🎯 Type-safe · 🧹 Clean schemas · 🔧 Configurable · 📏 Tree-shakeable
- 🚀 Generate Valibot schemas from your Prisma models automatically
- 📦 Per-model exports:
{Model}Schema(all fields required)Create{Model}Schema(required scalars only)Update{Model}Schema(all fields optional)
- 🎯 Advanced enum support: Dedicated
enums.tswithv.picklist()+ value exports - 🧹 Clean schemas: Relations automatically excluded for focused validation
- 🔧 Full type coverage: String/Int/Float/Boolean/DateTime/Json/Decimal/BigInt/Bytes/Arrays
- ⚙️ Configurable:
enumValueoption supports@mapfor custom enum values - 🛡️ Type-safe: Runtime validation with comprehensive error handling
- 📏 Lightweight: Tree-shakeable exports, minimal runtime overhead
- Node.js 18+
- Prisma 6.12+
- valibot
-
Star this repo 🌟
-
Install
npm i -D prisma-valibot-generator
# pnpm: pnpm add -D prisma-valibot-generator
# yarn: yarn add -D prisma-valibot-generator
# bun: bun add -d prisma-valibot-generator- Add a generator block to your
schema.prisma
generator valibot {
provider = "prisma-valibot-generator"
output = "./src/generated/valibot" // optional
enumValue = "name" // optional: "name" (default) | "dbName" (for @map support)
}- Generate
npx prisma generate- Import and use
import * as v from 'valibot';
import {
UserSchema,
CreateUserSchema,
UpdateUserSchema,
RoleEnum,
RoleValues
} from './src/generated/valibot';
// Validate complete model data
const user = v.parse(UserSchema, {
id: 1,
email: '[email protected]',
name: 'John Doe',
role: 'ADMIN'
});
// Validate creation data (only required fields)
const newUser = v.parse(CreateUserSchema, {
email: '[email protected]',
password: 'secret123'
});
// Validate updates (all fields optional)
const userUpdate = v.parse(UpdateUserSchema, {
name: 'Jane Smith'
});
// Validate enums
const role = v.parse(RoleEnum, 'USER');
// Access enum values for UI components
console.log(RoleValues); // ['USER', 'ADMIN']enum Role {
USER
ADMIN @map("administrator")
MODERATOR @map("mod")
}
generator valibot {
provider = "prisma-valibot-generator"
enumValue = "dbName" // Use @map values
}import { RoleEnum, RoleValues } from './generated/valibot';
// Generated enum values respect @map
console.log(RoleValues); // ['USER', 'administrator', 'mod']
// Validation works with mapped values
v.parse(RoleEnum, 'administrator'); // ✅ Valid
v.parse(RoleEnum, 'ADMIN'); // ❌ InvalidRelations are automatically excluded from generated schemas for clean validation:
model User {
id Int @id
email String
posts Post[] // Excluded from schemas
}
model Post {
id Int @id
title String
author User @relation(fields: [authorId], references: [id]) // Excluded
authorId Int // Included - it's a scalar field
}Arrays are fully supported with proper validation:
model User {
id Int @id
tags String[]
scores Int[]
}const user = v.parse(UserSchema, {
id: 1,
tags: ['developer', 'typescript'],
scores: [95, 87, 92]
});| Option | Values | Default | Description |
|---|---|---|---|
output |
string |
"./generated" |
Output directory for generated files |
enumValue |
"name" | "dbName" |
"name" |
Whether to use enum names or @map values |
The generator provides clear, actionable error messages:
# Invalid enum configuration
❌ Invalid enumValue config: 'invalid'. Must be 'name' or 'dbName'.
# Missing enum definition
❌ Enum 'Status' not found in schema. Available enums: Role, Priority
# Empty enum
❌ Enum 'Status' has no values. Enums must have at least one value.If this saves you time or prevents bugs, please consider sponsoring to support maintenance and new features.
PRs welcome. Keep diffs focused and discuss larger changes in an issue first. See the test suites for expected behavior and coverage.
MIT © Omar Dulaimi