@amritk/adapters 0.3.3 → 0.3.4
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 +43 -0
- package/dist/get-adapter.d.ts +9 -0
- package/package.json +4 -3
package/AI.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# @amritk/adapters — notes for AI coding agents
|
|
2
|
+
|
|
3
|
+
Convert schemas authored in TypeBox, Zod, Valibot, or Effect into Draft 2020-12
|
|
4
|
+
JSON Schema — the single input shape the mjst generators consume. Full
|
|
5
|
+
reference is [README.md](./README.md).
|
|
6
|
+
|
|
7
|
+
> Pre-alpha: APIs change in **minor** versions.
|
|
8
|
+
|
|
9
|
+
## Minimal example
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { getAdapter } from '@amritk/adapters/get-adapter'
|
|
13
|
+
import { z } from 'zod' // Zod 4+
|
|
14
|
+
|
|
15
|
+
const User = z.object({ id: z.number().int(), name: z.string().min(1) })
|
|
16
|
+
|
|
17
|
+
const adapter = getAdapter('zod')
|
|
18
|
+
const jsonSchema = await adapter.toJSONSchema(User) // always await
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Gotchas — where agents fail
|
|
22
|
+
|
|
23
|
+
1. **No barrel export.** You CANNOT `import { zodToJsonSchema } from '@amritk/adapters'`.
|
|
24
|
+
Import from the specific subpath (`@amritk/adapters/zod-to-json-schema`) or
|
|
25
|
+
use `@amritk/adapters/get-adapter`.
|
|
26
|
+
2. **Adapters take the loaded schema VALUE, not a file path.** Loading the module
|
|
27
|
+
is the caller's job.
|
|
28
|
+
3. **`getAdapter('json')` throws** — `'json'` is a valid `SourceFormat` but has no
|
|
29
|
+
adapter (JSON Schema is read directly). Only `typebox` / `zod` / `valibot` /
|
|
30
|
+
`effect` resolve.
|
|
31
|
+
4. **Source libraries are optional peer deps**, imported dynamically. **Zod must
|
|
32
|
+
be v4+** (`toJSONSchema` doesn't exist earlier). Always `await` — even
|
|
33
|
+
TypeBox's synchronous path is typed to allow a Promise.
|
|
34
|
+
5. **Unrepresentable constructs widen to `{}`** with a stderr `[mjst]` warning
|
|
35
|
+
(Effect throws on nested ones). `date` / `bigint` become `x-mjst` hints. Pass
|
|
36
|
+
`{ strict: true }` to throw instead of widening.
|
|
37
|
+
|
|
38
|
+
## Subpaths
|
|
39
|
+
|
|
40
|
+
`@amritk/adapters/get-adapter`, `.../typebox-to-json-schema`,
|
|
41
|
+
`.../zod-to-json-schema`, `.../valibot-to-json-schema`,
|
|
42
|
+
`.../effect-to-json-schema`, `.../adapter` (types), `.../source-format` (types).
|
|
43
|
+
Install: `bun add @amritk/adapters` (+ your source library).
|
package/dist/get-adapter.d.ts
CHANGED
|
@@ -7,5 +7,14 @@ import type { SourceFormat } from './source-format.js';
|
|
|
7
7
|
* reaches here — the CLI reads JSON Schema files directly without an adapter —
|
|
8
8
|
* and formats that are named but not yet built throw a clear, actionable error
|
|
9
9
|
* so the CLI can fail fast with guidance instead of a cryptic crash.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { z } from 'zod' // Zod 4+
|
|
14
|
+
* const User = z.object({ id: z.number().int(), name: z.string().min(1) })
|
|
15
|
+
* const adapter = getAdapter('zod')
|
|
16
|
+
* const jsonSchema = await adapter.toJSONSchema(User) // always await, even for TypeBox
|
|
17
|
+
* // getAdapter('json') THROWS — JSON Schema is read directly, it has no adapter.
|
|
18
|
+
* ```
|
|
10
19
|
*/
|
|
11
20
|
export declare const getAdapter: (format: SourceFormat) => Adapter;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amritk/adapters",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "Convert schemas from external libraries (TypeBox, Zod, ...) into JSON Schema for mjst.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"url": "https://github.com/amritk/mjst/issues"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
|
-
"dist"
|
|
28
|
+
"dist",
|
|
29
|
+
"AI.md"
|
|
29
30
|
],
|
|
30
31
|
"publishConfig": {
|
|
31
32
|
"access": "public"
|
|
@@ -37,7 +38,7 @@
|
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
39
40
|
"json-schema-typed": "^8.0.1",
|
|
40
|
-
"@amritk/helpers": "0.13.
|
|
41
|
+
"@amritk/helpers": "0.13.4"
|
|
41
42
|
},
|
|
42
43
|
"exports": {
|
|
43
44
|
"./package.json": "./package.json",
|