v0.1.0
First release.
Vite plugin that compiles JSON Schema files into self-contained ata-validator modules plus TypeScript declarations at build time.
// vite.config.ts
import ata from 'ata-vite'
export default {
plugins: [
ata({ schemas: 'schemas/**/*.json' }),
],
}For every matched <name>.json the plugin writes:
<name>.validator.mjs— self-contained validator, about 1 KB gzipped on a 10-field schema, no runtime dependency onata-validator<name>.validator.d.mts— TypeScript declaration withisValidas a type predicate, so consumers get narrowing:
import { isValid, type User } from './schemas/user.validator.mjs'
if (isValid(data)) data.role // 'admin' | 'user' | 'guest' | undefinedOptions
| Key | Default | Notes |
|---|---|---|
schemas |
schemas/**/*.json |
glob or array of globs |
outDir |
null |
next to input when null, otherwise mirrored under this folder |
format |
esm |
esm or cjs |
abortEarly |
false |
stub errors, ~0.5 KB gzipped output |
types |
true |
emit paired .d.mts / .d.cts |
nameFromFile |
filename-derived | customize the TS type name |
Hooks
buildStartcompiles every matched schema oncehandleHotUpdaterecompiles a single schema on dev-mode file changewatchChangefor rollup-style watch contexts
Idempotent writes: if the generated content matches what is already on disk, the file is not rewritten.
Programmatic API
import { compile } from 'ata-vite'
await compile({ schemas: 'schemas/**/*.json', outDir: 'src/generated' })Requirements
ata-validator >= 0.11.1vite >= 5.0.0- Node.js
>= 18.0.0
Install
npm install --save-dev ata-vite ata-validator