ata-validator 0.18.0 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  All notable changes to ata-validator are documented here. The format follows [Keep a Changelog](https://keepachangelog.com/), and this project adheres to semantic versioning.
4
4
 
5
+ ## 0.18.1 - 2026-05-26
6
+
7
+ ### Added
8
+
9
+ - The browser entry (`index.browser.mjs`) re-exports `toTypeScript`, so the inferred TypeScript type for a schema can be generated client-side (for example in a web playground) alongside `Validator.toStandaloneModule()`. Pure re-export, no runtime change.
10
+
5
11
  ## 0.18.0 - 2026-05-25
6
12
 
7
13
  ### Added
package/README.md CHANGED
@@ -127,40 +127,7 @@ v.countValid(ndjson); // number
127
127
 
128
128
  ### Type-safe schemas
129
129
 
130
- `Validator` is generic. Pair it with any schema authoring tool, or a hand-written type, to get TypeScript narrowing in your handler code.
131
-
132
- ```ts
133
- import { Type, type Static } from '@sinclair/typebox'
134
- import { Validator } from 'ata-validator'
135
-
136
- const UserSchema = Type.Object({
137
- id: Type.Integer({ minimum: 1 }),
138
- name: Type.String({ minLength: 1 }),
139
- email: Type.String({ format: 'email' }),
140
- })
141
-
142
- type User = Static<typeof UserSchema>
143
-
144
- const v = new Validator<User>(UserSchema)
145
-
146
- if (v.isValidObject(data)) {
147
- // data is narrowed to User, no cast needed
148
- console.log(data.name)
149
- }
150
-
151
- const result = v.validate(data)
152
- if (result.valid) {
153
- // result.data is User
154
- } else {
155
- // result.errors: ValidationError[]
156
- }
157
- ```
158
-
159
- The same pattern works with Zod-from-JSON-Schema, Valibot, or a hand-written `type User = {...}` alongside a JSON Schema literal. `Validator<T>` makes no library-specific assumption.
160
-
161
- #### Authoring a schema inline: `defineSchema`
162
-
163
- If you would rather write a plain JSON Schema object than reach for a schema library, wrap it in `defineSchema`. It returns the schema untouched at runtime, but in TypeScript it gives you keyword autocomplete and an error when a value has the wrong shape, with no `as const` needed.
130
+ ata infers TypeScript types straight from plain JSON Schema. Write the schema once with `defineSchema`, and both runtime validation and the static type come from it, with no builder DSL and no second type declaration to keep in sync.
164
131
 
165
132
  ```ts
166
133
  import { defineSchema, Validator } from 'ata-validator'
@@ -174,15 +141,21 @@ const userSchema = defineSchema({
174
141
  required: ['id'],
175
142
  })
176
143
 
177
- // type: 123 or required: 'id' would be a compile error here.
178
144
  const v = new Validator(userSchema)
145
+ const result = v.validate(data)
146
+ if (result.valid) {
147
+ result.data.id // number
148
+ result.data.role // 'admin' | 'user' | undefined
149
+ } else {
150
+ // result.errors: ValidationError[]
151
+ }
179
152
  ```
180
153
 
181
- The exported `JSONSchema` type is also available directly if you want to annotate a schema yourself. Custom and vendor keywords are allowed, so exotic schemas still type-check. Requires TypeScript >= 5.0.
154
+ `defineSchema` returns the schema untouched at runtime; in TypeScript it gives keyword autocomplete and an error when a value has the wrong shape, with no `as const` needed. `new Validator(schema)` carries the inferred type, so a successful `validate` narrows `result.data` with no manual annotation.
182
155
 
183
156
  #### Extracting the type: `Infer`
184
157
 
185
- Because `defineSchema` leaves the schema as a plain object, you can pull a TypeScript type straight out of it with `Infer`, with no second type declaration to keep in sync.
158
+ You can also pull the type out directly with `Infer`, with no second declaration to keep in sync.
186
159
 
187
160
  ```ts
188
161
  import { defineSchema, type Infer } from 'ata-validator'
@@ -208,7 +181,25 @@ type Event = Infer<typeof event>
208
181
  // }
209
182
  ```
210
183
 
211
- `Infer` resolves `const`/`enum` to literals, `anyOf`/`oneOf` to unions, `allOf` to intersections, `prefixItems` to tuples, and local `$ref` into `#/$defs` or `#/definitions`, including recursive references. `new Validator(schema)` carries the same type, so a successful `validate` narrows `result.data` without a manual annotation. An external or unresolvable `$ref` resolves to `unknown` rather than erroring.
184
+ `Infer` resolves `const`/`enum` to literals, `anyOf`/`oneOf` to unions, `allOf` to intersections, `prefixItems` to tuples, and local `$ref` into `#/$defs` or `#/definitions`, including recursive references. An external or unresolvable `$ref` resolves to `unknown` rather than erroring. The exported `JSONSchema` type is available if you want to annotate a schema by hand; custom and vendor keywords are allowed. Requires TypeScript >= 5.0.
185
+
186
+ #### Composes with TypeBox, Zod, or your own types
187
+
188
+ `Validator<T>` is generic, so if you already author schemas with a library, pass the type and ata narrows to it. No library-specific assumption.
189
+
190
+ ```ts
191
+ import { Type, type Static } from '@sinclair/typebox'
192
+ import { Validator } from 'ata-validator'
193
+
194
+ const UserSchema = Type.Object({
195
+ id: Type.Integer({ minimum: 1 }),
196
+ name: Type.String({ minLength: 1 }),
197
+ })
198
+
199
+ const v = new Validator<Static<typeof UserSchema>>(UserSchema)
200
+ ```
201
+
202
+ The same works with Zod-from-JSON-Schema, Valibot, or a hand-written `type User = {...}` alongside a JSON Schema literal.
212
203
 
213
204
  ### Cross-Schema `$ref`
214
205
 
package/index.browser.mjs CHANGED
@@ -1,4 +1,4 @@
1
1
  // Browser ESM entry — same code, native addon stubbed out by bundler via "browser" field.
2
2
  import mod from './index.js';
3
- export const { Validator, validate, version, createPaddedBuffer, SIMDJSON_PADDING, renderPretty, renderCompact, renderJSON } = mod;
3
+ export const { Validator, validate, version, createPaddedBuffer, SIMDJSON_PADDING, renderPretty, renderCompact, renderJSON, toTypeScript } = mod;
4
4
  export default mod;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ata-validator",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "description": "JSON Schema validation with first-class TypeScript and zero runtime cost. AOT compile to per-schema ESM modules with zero validator dependency. Generic Validator<T> for TypeBox/Zod/Valibot composition. Optional runtime API. Standard Schema V1 compatible.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",