@dudousxd/nestjs-codegen-valibot
v0.5.1
Published
Valibot validation adapter for @dudousxd/nestjs-codegen — renders the schema IR to valibot source.
Readme
@dudousxd/nestjs-codegen-valibot
Valibot validation adapter for
@dudousxd/nestjs-codegen.
nestjs-codegen translates your @Body()/@Query() DTOs and defineContract schemas
into one neutral schema IR (SchemaNode), then renders that IR with a validation
adapter. This package is the valibot adapter: it renders the IR into valibot
source in the generated forms.ts.
Reach for valibot when bundle size matters — it's a tiny, tree-shakeable validator, so only the actions your forms actually use end up in the client bundle.
Install
pnpm add -D @dudousxd/nestjs-codegen-valibotvalibot itself is the runtime dependency your generated forms.ts imports from
(import * as v from 'valibot'), so install it in your app too:
pnpm add valibotSetup
zod is bundled and used by default. To emit valibot schemas instead, pass
valibotAdapter to the codegen config:
import { defineConfig } from '@dudousxd/nestjs-codegen';
import { valibotAdapter } from '@dudousxd/nestjs-codegen-valibot';
export default defineConfig({
validation: valibotAdapter,
});Given a DTO like:
class CreateUserDto {
@IsEmail() email!: string;
@MinLength(8) password!: string;
}the adapter renders forms.ts in valibot's idiom:
import * as v from 'valibot';
export const CreateBodySchema = v.object({
email: v.pipe(v.string(), v.email()),
password: v.pipe(v.string(), v.minLength(8)),
});
export type CreateBody = v.InferOutput<typeof CreateBodySchema>;How it fits
The codegen builds one neutral schema IR from your DTOs and contracts. A validation adapter renders that IR into a concrete library's source:
- zod — bundled, the default (
validation: 'zod') - valibot — this package (
validation: valibotAdapter) - arktype —
@dudousxd/nestjs-codegen-arktype(validation: arktypeAdapter)
Pick exactly one — it decides which library your generated forms.ts imports and
validates with.
Documentation
License
MIT
