Repository navigation
Releases
v0.17.0
A form that validates with react-hook-form and zod can ship without zod, with nothing in the form changed; ataResolver forms ship without the ata runtime again; and a Next.js build applies the plugin's size choices to what the browser gets.
react-hook-form
zodResolver(schema)from@hookform/resolvers/zodis compiled away where the build can read the schema: a constant of the file, at the top or inside the component, a schema written in the call, or one imported by name from another module of the project. The build runs the schema with the application's own zod, writes a check with the same verdict, and records the issue zod reports for each rule, a custom message included, by asking zod. Before a call is replaced, the build holds the written resolver to zod on documents made for that form; a form that differs keeps its call. On a Next.js 16.4.6 page with a five-field form, the scripts the page loads beyond the home page went from 43,450 to 15,411 bytes gzipped under Turbopack and from 37,288 to 15,928 under webpack. In a Vite 7 + React 19 app with the same form, all of the page's JavaScript went from 108,338 to 85,683 bytes gzipped (82,425 with react-hook-form and no validation at all). Carried: strings with their checks and formats,z.email()and the like,url(),trim/toLowerCase/toUpperCase, numbers withint, bounds andz.coerce.number(), booleans, enums, literals, optional fields, nested objects, arrays, andrefinewhose function reads only its argument. Everything else keeps its call and zod. On by default;zodResolver: falseturns it off. An application that sets zod's locale or a global error map gets nothing replaced.ataResolver(schema)is compiled away again. The rewrite waited onataCompiledResolverin @hookform/resolvers, which was declined upstream, so it never ran; the build now writes the resolver itself. Same page: 81,689 to 14,269 bytes under Turbopack.npx @ata-project/unplugin scansays whichzodResolver,ataResolverandnew Validatorcalls a build would compile, and for each of the others why not, naming the field and the cause. Nothing is written. A build prints the same lines.
Fixes
compile()holds each validators file it writes from zod, valibot or TypeBox modules against that library before writing it: documents made from each export (valid ones, ones with one rule broken, both sides of every bound; 50 an export, orverify: <number>) go to the library's own check and to the written validator, and a difference throws with the document. Three things the JSON Schema does not say are now refused by export and path: a check written aftertrim(),toLowerCase(),toUpperCase()ornormalize(),z.coerce.number(), and.catch(value). Up to 0.15.0 these were converted without a word, and the page answered differently from zod on those values.compile({ ..., check: true })writes nothing and returns the files a compile would change, for a CI step. On 17 schemas of 41 fields the check added about 30 ms to a 140 ms compile;verify: falseskips it. (This was released on main as 0.16.0 but never published to npm, so it ships here.)- Under webpack and Rspack (so
next build --webpack), a file could be transformed before the build'stableandsharedErrorschoices were made, and was then written as if neither existed; in Next.js that was every client file. A six-form page: 8,719 to 5,554 bytes. sharedErrors: 'auto'withir: falsewrote compact modules that made a bundle 4 to 8 KB larger for schemas of middling size: the bar was set when ata's error runtime was smaller. It is set from real bundles again, and a test holds it there.verifychecked nothing on the IR path, the default since ata-validator 1.63.1. It now holds the IR's modules to the runtime. With ata-validator 1.63.x it reports real differences on some schemas (references to the official meta-schemas, among others) that 1.64.0 fixes; use it with 1.64.0.- The imports a rewrite adds go after a file's directives, so
'use client'stays first (Next.js failed the build of a client component holding its ownnew Validator). tableandsharedErrorsin their 'auto' form decide for what a page loads together, not for the whole project.
Smaller pages
smallFormats: 'auto': a module written for a browser checksemail,urianduri-referencewith ata-validator's smaller regular expressions (needs ata-validator 1.64.0; an older one keeps the scanners).errorFields: 'auto': a validator whose errors are read only throughkeyword,instancePath,schemaPath,paramsandmessageis written with plain errors. A six-field signup form: 4,529 to 2,128 bytes.
Recommended with ata-validator 1.64.0. Tested: 356 tests, 354 pass, 2 skipped, against ata-validator 1.64.0 as packed from its release branch.
Not covered: Rspack and Rollup were not measured in an application for the zod rewrite; zod 3; schemas re-exported through an index file.
v0.15.0
One change, for projects that call compile() from a script with the zod or from option.
Changed
- Where there are many validators,
compile()writes them as plans for one small interpreter instead of as checks written out one by one, when that makes the smaller bundle. It weighs all the files it writes together, as the plugin does for an application inside a bundler, and chooses plans when they save more than the interpreter costs. Seven flat event schemas in one entry, bundled with esbuild and no plugin: 2.8 KB gzipped as plans (12 KB before compression) against 10.5 KB as written checks (139 KB). The exports, their answers and their errors are the same. - A page that imports one validator from a set written as plans carries the interpreter too. On the same schemas, one file each: a 10-field schema 1,254 bytes gzipped as a plan against 884 as written checks, a 43-field one 1,438 against 3,240, a 60-field one 1,512 against 3,771.
- A plan is slower to run than written checks. On an event of 44 optional fields (Node 25, Apple M4 Pro) a valid document takes about 1.0 µs against 0.6, and a rejected one with its errors read 1.4 µs against 0.1.
table: falsekeeps written checks,table: truetakes plans whatever the sizes. The result ofcompile()carriestable, the choice made.
Not covered
- A schema the table backend does not take stays written checks.
- The sizes are from esbuild; other bundlers were not measured for this change.
v0.14.0
One change, for projects that call compile() from a script with the zod or from option.
Changed
compile()writes each<module>.validators.mjsalready compiled: every export is its schema written out as checks, and the file imports only the helpers those checks use, never the validator runtime. Written asnew Validator(schema), the file was small only in a build that ran the plugin; imported by a build that did not, each validator brought the runtime compiler into the bundle, and nothing in the build output said so. On a page that uses one validator, bundled with esbuild and no plugin: 3.9 KB gzipped compiled against 142.8 KB asnew Validator(ata-validator 1.63.1). The exports, their answers and their errors are the same; a server can import the same file.compiled: falsekeeps thenew Validator(schema)form, for a project whose bundler runs the plugin and should make the choices it makes for a whole application (shared errors, table plans). Inside a bundler the plugin writes that form as before and compiles it in the same build.
Not covered
- The compiled file imports helpers from
ata-validator/kernels, so a server that imports it unbundled still needsata-validatorinstalled. - A file with a validator the build cannot compile is written in the previous form, with a warning that says why.
v0.13.1
One fix. Upgrade if you build with Rspack or webpack.
Fixed
- Under Rspack and webpack a build with the plugin on failed to parse files the plugin has nothing to do with: an application's own JSON import (
JavaScript parse errorin a.jsonfile) or an SVG inlined from a stylesheet. The plugin'sloadhook had noloadInclude, and those two bundlers turn such a hook into a rule over every module that types what it loads as JavaScript. The hook is now kept to the plugin's own virtual modules. Affected 0.11.0 through 0.13.0; the other bundlers were not affected.
Docs
- The README said
ata-validatoris only used at build time. That holds for a page's build. A generated validator file that a server imports without bundling (<module>.validators.mjs, the OpenAPI validators) runs on the runtime there, so that server needsata-validatorin itsdependencies.
0.13.0
One addition. Nothing changes for a build that does not set it.
Added
-
The
zodandfromoptions: modules that export zod, valibot or TypeBox schemas are compiled at build time, so a page keeps the library it writes schemas in and carries neither it nor a validator runtime.ata({ zod: 'src/events/*.ts' })takes zod 4 modules;ata({ from: 'src/schemas/*.ts' })takes modules of any of the three, each export by its own library. The build loads each module (TypeScript through jiti), converts every exported schema (zod's ownz.toJSONSchema, valibot's@valibot/to-json-schema, a TypeBox schema as written), and writes<module>.validators.mjsand.d.mtsbeside it, one{ validate, isValidObject }per export, which the page's build compiles away like any other validator. The page answers as the library does: the schema written is the input schema, so an unknown key passes as it passesz.objectandv.object(the page leaves it in place where the library would drop it;strictObjectstays closed); where zod writes its own regex beside a format name, the regex alone is kept. Errors come in the plain shape (keyword,instancePath,schemaPath,params,message);validatorOptions: { richErrors: true }asks for the rich one. For a TypeScript module the page's type is the library's own:z.input<...>,InferInput<...>orStatic<...>of the exported schema.A
.refine(fn),.transform(fn), valibotcheckortransformwhose function reads nothing but its own parameter is carried: its text is written into the module and run at its place once the compiled check has passed, in the library's order, a check with its message and path, a transform written into the datavalidate()hands back. A zod.pipe()into a second schema is carried as a second compiled check. Of 337 zod refine calls in 195 public TypeScript files, 258 are such functions, 88 of 153 transforms, and 208 of 503 valibot checks and transforms in 185 files.What a page cannot carry stops the build by export and path rather than compile a page that accepts what the schema rejects: a function that closes over an outside name, a
superRefineor a transform that takes a context, apreprocess, a refine inside a union, a valibot validation written after a transform, a TypeBox kind outside the standard set, aTransform, a$refout of the document, or aformatregistered inFormatRegistry, which a page would pass unchecked.dropRefinements: truetakes them out knowingly, and the build reports which.
Measured on three event schemas, one a union of objects, esbuild minified, gzip level 9, ata-validator 1.63.1, zod 4.6.7: the page carries 3.9 KB with the compiled validators and 93.0 KB with zod; one schema alone is 1.1 KB, an Rspack-built fragment importing one validator 1.4 KB, and three carried refines on a signup schema add 0.5 KB. The same event schema in TypeBox 0.34.52 is 1.1 KB compiled against 25.5 KB with Value.Check on the page; in valibot 1.5.0, which is modular and small, 1.1 KB against 1.7 KB, a saving of 0.6 KB on this schema. Converting a module costs the build 4 ms, after a one-time 132 ms to load jiti and the library.
Not covered: zod 3 (z.toJSONSchema is zod 4's), arktype and effect, the stripping of unknown keys, which the page leaves in place, and a carried check's error in a list where the schema's own checks also fail, which appears once those pass; the verdict is the same.
0.12.0
Validators compile through ata-validator/ir by default. Needs ata-validator 1.63.0; with an older one nothing changes.
A validator the file only calls (validate(), isValidObject()) is compiled by the new compiler, whose modules import their helpers from ata-validator/kernels, once per page however many validators it has. Verdicts, errors (every field, in order, rich or plain) and filled defaults are the same as before. Measured with esbuild (minified, gzip level 9) on form schemas with their errors read:
| validators in the bundle | 0.11.3 | 0.12.0 |
|---|---|---|
| 1 | 11.0 KB | 4.3 KB |
| 3 | 12.7 KB | 5.5 KB |
| 10 | 17.6 KB | 5.8 KB |
Across the 654 SchemaStore schemas both paths compile away, the bundle is 0.52 of the previous one at the median and larger on none. Reading the errors of an invalid document takes 0.64 of the previous time at the median and is slower on none of 116 schemas; a valid document's verdict takes 1.03 of it at the median, and 1.9 times as long on the slowest schema measured alone. Loaded fresh with its first ten calls, the new module took 0.49 of the time at the median and was faster on all 48 schemas sampled, mostly because there is less to load.
Many forms as data. table: 'auto', on by default: the build rewrites each file both with written modules and with plans for one interpreter shared across the bundle (ata-validator/ir tableModule), and keeps the plans when the rewritten application comes out smaller, by a threshold set from Vite + React builds of 1 to 10 forms, on which it never took the plans for the larger bundle. In a Vite + React application with ten six-field forms reading plain errors, the validators add 2.02 KB gzipped to the first load, against 5.35 KB as modules; with email and uri fields, 2.70 against 8.24. A single form keeps its module, 1.41 KB. Verdicts, errors and defaults are the same; a plan is slower per call (445 against 22 ns on a valid order form). table: false keeps modules.
One OpenAPI document for the server and the page. openapi: 'openapi.json' writes openapi.validators.mjs and .d.mts beside the document: one validator per operation's JSON request body, plain source a server imports as it is, compiled by the page's build. On a nine-field signup operation the server and the page disagreed on 0 of 50,000 generated documents, every error compared; the page's validation added 3.78 KB gzipped to a Vite + React first load. Needs ata-validator 1.63.0 (ata-validator/openapi).
Next.js, under Turbopack too. withAta(nextConfig, options) from @ata-project/unplugin/next covers both bundlers Next runs: Turbopack, the default since Next.js 16, through a loader (@ata-project/unplugin/turbopack), and webpack through the plugin. Before, the plugin had no way into Turbopack and a Next.js 16 app kept the runtime. On a Next.js 16 page with one order form that reads its errors, the validator adds 4.2 KB gzipped to the first load under Turbopack and 4.6 KB under webpack, against 67.5 and 58.3 KB for the runtime Validator.
ir: false keeps the previous modules. A schema or option the new compiler does not cover (custom keywords or formats, errorMessage, options other than richErrors, useDefaults and assertFormat) takes the previous path on its own, as does a validator handed to other code.
ataResolver(schema) from @hookform/resolvers/ata-validator compiles through the new compiler too, with plain errors (a resolver reads the same fields from them), once the installed resolvers export ataCompiledResolver: 4.8 KB to 2.6 KB on the test fixture.
The ir default and ata-validator 1.63.1. The default compiles with ata-validator/ir only on ata-validator 1.63.1 and later, the release whose module writer was measured: on 1.63.0 the IR's modules were slower than the compiled ones on 129 of 438 SchemaStore schemas by a fifth or more; from 1.63.1 on 51, and faster on 216. On 1.63.0 the plugin keeps the compiled modules unless ir: true is given. The many-forms sizes above (2.02 and 2.70 KB) are the same on both.
0.11.3
A validator handed only to a Standard Schema consumer (Hono's sValidator, hono-openapi, TanStack Form, oRPC, tRPC's .input(), Elysia's hooks) takes the wrapper that carries ~standard alone, on a module that writes plain errors: 733 bytes gzipped. A Hono route bundled for Cloudflare Workers goes from 21.0 to 12.2 KB gzipped against 7.7 for Hono alone, an Elysia route from 120.1 to 110.1 against 106.8, a tRPC procedure from 18.0 to 7.8 against 4.6; the issues are the runtime's on 3,972 answers over 559 suite schemas, and the Hono and Elysia apps answer the same requests with the same responses from both builds. The standardConsumers option names further consumers. The build report counts what each compiled validator carries. Needs ata-validator 1.61.3. (0.11.2 was tagged but never published: its release test job failed on a fixture that lived only in an ignored node_modules.)
0.11.2
A validator handed only to a Standard Schema consumer (Hono's sValidator, hono-openapi, TanStack Form, oRPC, tRPC's .input(), Elysia's hooks) takes the wrapper that carries ~standard alone, on a module that writes plain errors: 733 bytes gzipped. A Hono route bundled for Cloudflare Workers goes from 21.0 to 12.2 KB gzipped against 7.7 for Hono alone, an Elysia route from 120.1 to 110.1 against 106.8, a tRPC procedure from 18.0 to 7.8 against 4.6; the issues are the runtime's on 3,972 answers over 559 suite schemas, and the Hono and Elysia apps answer the same requests with the same responses from both builds. The standardConsumers option names further consumers. The build report counts what each compiled validator carries. Needs ata-validator 1.61.3.
0.11.1
Validators the plugin sees only called, never handed to other code, take the bare wrappers of ata-validator 1.61.1. A form with two validators, one reading errors and one asking for a verdict, bundles to 10.7 KB gzipped, or 3.1 KB with richErrors: false on the one that reads errors, against 16.7 KB on 0.11.0.
Verdict-only validators get modules without the error collector, and inlined modules drop the declarations nothing reads. Answers and error objects are the runtime's.
Needs ata-validator 1.61.1; with an older one the plugin keeps the wrappers it had.
v0.11.0
schemaOf() writes a TypeScript type's JSON Schema in at build time; the build reports every new Validator kept on the runtime with file, line and reason; verify holds every compiled validator to the runtime at the end of the build (default under CI); under Bun.build({ compile: { aot: true } }) the modules take the form made for Bun's compiler and the one-pass error function, and a schema compiled from the globs gets a .bun.ts with its type and a typed parse beside it. Needs ata-validator 1.61.0.