Introduction
What the plugin generates, and when to use it instead of the protovalidate runtime.
protoc-gen-pvschema-ts is a protoc plugin. It reads protovalidate rules from .proto files and generates Valibot or Zod schemas.
The schemas are for form validation in a frontend. The server still validates each request with protovalidate.
What a schema validates
A generated schema validates the init shape of protobuf-es. You can pass a validated value to create() and send the message.
import { create } from "@bufbuild/protobuf";
import * as v from "valibot";
import { CreateUserRequestSchema } from "./gen/example/v1/user_pb";
import { CreateUserRequestValidationSchema } from "./gen/example/v1/user_pvschema";
const values = v.parse(CreateUserRequestValidationSchema, formValues);
const request = create(CreateUserRequestSchema, values);Why not the protovalidate runtime
@bufbuild/protovalidate runs in the browser and has a Standard Schema adapter. It supports every rule, CEL included. This plugin exists for two cases where a generated schema fits better.
Bundle size. The protovalidate runtime includes a CEL evaluator and an RE2-compatible regex engine. We bundled one message with 12 fields with esbuild and compressed it with gzip.
| Setup | Increase over protobuf-es only |
|---|---|
@bufbuild/protovalidate | +81.1 KB |
zod schema | +28.2 KB |
zod/mini schema | +8.3 KB |
| Valibot schema | +2.6 KB |
The measurement used @bufbuild/protovalidate 1.3.0, valibot 1.5.0, and zod 4.6.7. It covers one message and one run.
Messages. The generated schemas use the standard actions of each library. The locales and the message overrides of Valibot and Zod apply without extra code. Read Messages and languages.
What the plugin does not do
The plugin does not translate CEL rules. It leaves out each rule that has no counterpart in the schema library and lists the rule in a comment. To validate CEL rules in the browser, use @bufbuild/protovalidate.
Read Differences from protovalidate for the cases where a generated schema and protovalidate disagree.