Valibot adapter
@xndrjs/domain-valibot integrates Valibot schemas with @xndrjs/domain.
It provides:
valibotToValidator(schema)to produce domain validatorsvalibotFromKit(kit)to use domain kits as Valibot schema fields- full re-export of
@xndrjs/domainfor convenient imports
Install
Section titled “Install”pnpm add @xndrjs/domain-valibot valibotMinimal example
Section titled “Minimal example”import * as v from "valibot";import { domain, valibotToValidator } from "@xndrjs/domain-valibot";
const Email = domain.primitive("Email", valibotToValidator(v.pipe(v.string(), v.email())));
const email = Email.create("dev@example.com");valibotToValidator
Section titled “valibotToValidator”Wrap any compatible Valibot schema into the domain validator contract:
const User = domain.shape( "User", valibotToValidator( v.object({ id: v.pipe(v.string(), v.minLength(1)), email: valibotFromKit(Email), }) ));valibotFromKit
Section titled “valibotFromKit”Use valibotFromKit when a parent Valibot schema should materialize an existing primitive or shape kit.
const Address = domain.shape( "Address", valibotToValidator( v.object({ city: v.pipe(v.string(), v.minLength(1)), country: v.pipe(v.string(), v.length(2)), }) ));
const User = domain.shape( "User", valibotToValidator( v.object({ id: v.string(), address: valibotFromKit(Address), }) ));
const user = User.create({ id: "user_1", address: { city: "Rome", country: "IT" },});When Valibot fits well
Section titled “When Valibot fits well”Valibot is a good match when you want:
- composable function-first schemas
- small boundary parsers
- explicit parser pipelines
- adapter interoperability without changing the domain model