@amritk/generate-validators 0.11.9 → 0.11.11
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/AI.md +38 -0
- package/README.md +1 -1
- package/package.json +5 -4
package/AI.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# @amritk/generate-validators — notes for AI coding agents
|
|
2
|
+
|
|
3
|
+
Programmatic API: generate lightweight predicate validators (`validateFoo(input)`)
|
|
4
|
+
plus types from a JSON Schema. Full reference is [README.md](./README.md).
|
|
5
|
+
|
|
6
|
+
> Pre-alpha: APIs and generated output change pre-1.0.
|
|
7
|
+
|
|
8
|
+
## Minimal example
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { buildValidatorSchema } from '@amritk/generate-validators'
|
|
12
|
+
import type { JSONSchema } from 'json-schema-typed/draft-2020-12'
|
|
13
|
+
|
|
14
|
+
const schema: JSONSchema = {
|
|
15
|
+
type: 'object',
|
|
16
|
+
properties: { title: { type: 'string' } },
|
|
17
|
+
required: ['title'],
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const files = await buildValidatorSchema(schema, 'Document')
|
|
21
|
+
// → document.ts, validation-result.ts, index.ts
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Gotchas — where agents fail
|
|
25
|
+
|
|
26
|
+
1. **Success is the literal `true`, not `{ valid: true }`.** A generated
|
|
27
|
+
`validateFoo` returns `true | { valid: false; errors: ValidationError[] }`.
|
|
28
|
+
Check `if (result !== true)` for the failure path — `if (result.valid)` is
|
|
29
|
+
wrong.
|
|
30
|
+
2. **Small signature:** `buildValidatorSchema(rootSchema, rootTypeName, typeSuffix?)`
|
|
31
|
+
— async, no `strict`/`typesOnly`/options. Returns `GeneratedFile[]` in memory
|
|
32
|
+
(you write them).
|
|
33
|
+
3. **Output includes a shared `validation-result.ts`** (`ValidationError`,
|
|
34
|
+
`ValidationResult`, helpers) plus the `index.ts` barrel.
|
|
35
|
+
4. **`NaN` satisfies numeric bounds** (`minimum`/`maximum`/`multipleOf`) — differs
|
|
36
|
+
from Ajv. Draft-07 schemas are auto-upgraded to 2020-12.
|
|
37
|
+
|
|
38
|
+
Only the `.` entry. Install: `bun add @amritk/generate-validators`.
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
**Programmatic API for generating predicate-style TypeScript validators from JSON Schemas.**
|
|
6
6
|
|
|
7
7
|

|
|
8
|
-

|
|
9
9
|

|
|
10
10
|

|
|
11
11
|

|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amritk/generate-validators",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.11",
|
|
4
4
|
"description": "Generate TypeScript validation functions from JSON Schemas.",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"url": "https://github.com/amritk/mjst/issues"
|
|
25
25
|
},
|
|
26
26
|
"files": [
|
|
27
|
-
"dist"
|
|
27
|
+
"dist",
|
|
28
|
+
"AI.md"
|
|
28
29
|
],
|
|
29
30
|
"publishConfig": {
|
|
30
31
|
"access": "public"
|
|
@@ -46,10 +47,10 @@
|
|
|
46
47
|
},
|
|
47
48
|
"dependencies": {
|
|
48
49
|
"json-schema-typed": "^8.0.1",
|
|
49
|
-
"@amritk/helpers": "0.13.
|
|
50
|
+
"@amritk/helpers": "0.13.5"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
|
-
"@amritk/runtime-validators": "0.
|
|
53
|
+
"@amritk/runtime-validators": "0.9.0",
|
|
53
54
|
"@ryoppippi/unplugin-typia": "^2.6.5",
|
|
54
55
|
"@scalar/openapi-parser": "^0.26.1",
|
|
55
56
|
"@sinclair/typebox": "^0.34.49",
|