Skip to content

Releases: ata-core/ata-vite

v0.4.0

25 May 21:02

Choose a tag to compare

Adds the .schema.json convention. A <name>.schema.json source compiles to <name>.schema.js (a zero-dependency validator) and <name>.schema.d.ts, so you can:

import validate, { type User, isValid } from './user.schema'

The default export is the validate function; validate, isValid, and the inferred type are also named exports. The type name comes from the schema's title, then $id, then the file name. The default glob is **/*.schema.json, excluding node_modules. Sources without the .schema suffix keep the existing .validator.mjs output.

v0.3.0

23 May 18:29

Choose a tag to compare

  • Resolve path aliases in .ts schema files: tsconfig compilerOptions.paths and Vite resolve.alias are both honored. .js stays on native import, so use relative paths there.
  • Document composing a schema by importing a base .json and extending it from a js/ts file, with a fixture and test. Idea from #1, thanks @SukeshP1995.

v0.1.0

24 Apr 10:24

Choose a tag to compare

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