@amritk/generate-parsers 0.17.0 → 0.17.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/AI.md +36 -0
- package/package.json +5 -4
package/AI.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# @amritk/generate-parsers — notes for AI coding agents
|
|
2
|
+
|
|
3
|
+
Programmatic API: turn a JSON Schema (Draft 2020-12) into TypeScript type
|
|
4
|
+
definitions plus optional runtime parser functions. Full reference is
|
|
5
|
+
[README.md](./README.md). (Most users want the [`mjst` CLI](../cli) instead.)
|
|
6
|
+
|
|
7
|
+
> Pre-alpha: APIs and generated output change pre-1.0.
|
|
8
|
+
|
|
9
|
+
## Minimal example
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { buildSchema } from '@amritk/generate-parsers'
|
|
13
|
+
import type { JSONSchema } from 'json-schema-typed/draft-2020-12'
|
|
14
|
+
|
|
15
|
+
const schema: JSONSchema = { type: 'object', properties: { title: { type: 'string' } } }
|
|
16
|
+
|
|
17
|
+
const files = await buildSchema(schema, 'Document')
|
|
18
|
+
// files → [{ filename: 'document.ts', content: '…' }, { filename: 'index.ts', content: '…' }, …]
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Gotchas — where agents fail
|
|
22
|
+
|
|
23
|
+
1. **`buildSchema` is `async` and takes POSITIONAL args, no options object.** The
|
|
24
|
+
full signature is
|
|
25
|
+
`buildSchema(rootSchema, rootTypeName, extensions?, typesOnly?, logWarnings?, strict?, helpersMode?, helpersImportPrefix?, readonly?, stripUnknown?, typeSuffix?, importExt?, caseInsensitive?)`.
|
|
26
|
+
To set a later flag you must pass every intervening positional. (The README's
|
|
27
|
+
short form omits the trailing seven.)
|
|
28
|
+
2. **It returns files in memory — it does NOT write to disk.** You write the
|
|
29
|
+
`GeneratedFile[]` (`{ filename, content }`) yourself.
|
|
30
|
+
3. **Output is more than one file per `$def`:** always an `index.ts` barrel, and
|
|
31
|
+
(unless `typesOnly`) runtime helper files.
|
|
32
|
+
4. **Default parsers COERCE invalid input to defaults** rather than throwing;
|
|
33
|
+
pass `strict: true` (the 6th positional) to make them throw.
|
|
34
|
+
|
|
35
|
+
Only the `.` entry (`buildSchema`, `GeneratedFile`, `ImportExtension`).
|
|
36
|
+
Install: `bun add @amritk/generate-parsers`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amritk/generate-parsers",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.1",
|
|
4
4
|
"description": "Generate TypeScript parsers and type definitions from JSON Schemas.",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"url": "https://github.com/amritk/mjst/issues"
|
|
24
24
|
},
|
|
25
25
|
"files": [
|
|
26
|
-
"dist"
|
|
26
|
+
"dist",
|
|
27
|
+
"AI.md"
|
|
27
28
|
],
|
|
28
29
|
"publishConfig": {
|
|
29
30
|
"access": "public"
|
|
@@ -48,8 +49,8 @@
|
|
|
48
49
|
},
|
|
49
50
|
"dependencies": {
|
|
50
51
|
"json-schema-typed": "^8.0.1",
|
|
51
|
-
"@amritk/helpers": "0.13.
|
|
52
|
-
"@amritk/generate-markdown": "0.4.
|
|
52
|
+
"@amritk/helpers": "0.13.4",
|
|
53
|
+
"@amritk/generate-markdown": "0.4.4"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
56
|
"@sinclair/typebox": "^0.34.49",
|