Skip to content

v0.1.0

Choose a tag to compare

@mertcanaltin mertcanaltin released this 24 Apr 10:24
· 13 commits to main since this release

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 on ata-validator
  • <name>.validator.d.mts — TypeScript declaration with isValid as a type predicate, so consumers get narrowing:
import { isValid, type User } from './schemas/user.validator.mjs'
if (isValid(data)) data.role   // 'admin' | 'user' | 'guest' | undefined

Options

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

  • buildStart compiles every matched schema once
  • handleHotUpdate recompiles a single schema on dev-mode file change
  • watchChange for 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.1
  • vite >= 5.0.0
  • Node.js >= 18.0.0

Install

npm install --save-dev ata-vite ata-validator