@amritk/adapters 0.3.5 → 0.4.0

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.
Files changed (2) hide show
  1. package/README.md +3 -3
  2. package/package.json +13 -6
package/README.md CHANGED
@@ -145,7 +145,7 @@ const User = Schema.Struct({
145
145
  const jsonSchema = await effectToJsonSchema(User)
146
146
  ```
147
147
 
148
- Requires `effect@>=3`. A top-level `Schema.BigIntFromSelf` / `Schema.DateFromSelf` is rescued into an `x-mjst` hint; everything else goes through `JSONSchema.make`. **Read the [encoded-representation caveat](#effect-encodes-the-wire-representation) before choosing between `Schema.Date` and `Schema.DateFromSelf`** — it changes whether you get a `string` or a runtime `Date`.
148
+ Requires `effect@>=3`. A `Schema.BigIntFromSelf` / `Schema.DateFromSelf` **anywhere in the tree** — top level or nested inside a struct, array, or union — is rescued into an `x-mjst` hint; every subtree `JSONSchema.make` accepts is taken from it verbatim. **Read the [encoded-representation caveat](#effect-encodes-the-wire-representation) before choosing between `Schema.Date` and `Schema.DateFromSelf`** — it changes whether you get a `string` or a runtime `Date`.
149
149
 
150
150
  ---
151
151
 
@@ -213,7 +213,7 @@ Some source types have no faithful JSON Schema representation and are **not** re
213
213
  - **Zod.** These Zod types become "accept anything": `symbol`, `nan`, `void`, `undefined`, `never`, `map`, `set`, `promise`, `function`. When any appear, the adapter logs, e.g.: *"[mjst] Zod adapter: function, symbol have no JSON Schema representation and became 'accept anything'. The generated type will be wider than the Zod schema."*
214
214
  - **Valibot.** The converter runs in `errorMode: 'warn'`: an unsupported construct degrades to an open schema and `@valibot/to-json-schema` logs which one, so the widening is reported by the converter itself.
215
215
  - **TypeBox.** An extended `type` string with no mapping (see below) is left unchanged with a warning: *"[mjst] TypeBox type '…' has no JSON Schema or x-mjst mapping; leaving it unchanged."*
216
- - **Effect.** Effect does not widen — it is stricter. `JSONSchema.make` **throws** on a *nested* unrepresentable type (a `BigIntFromSelf` / `DateFromSelf` below the top level with no `jsonSchema` annotation). The adapter catches that and re-throws an actionable message pointing you at the fix: use the string-encoded `Schema.Date` / `Schema.BigInt`, or add a `jsonSchema` annotation to that field.
216
+ - **Effect.** Effect does not widen — it is stricter. `JSONSchema.make` throws on any unrepresentable type, wherever it sits. The adapter catches that and descends structurally, rebuilding the container (struct, array, union, refinement, …) and rescuing every `BigIntFromSelf` / `DateFromSelf` leaf it reaches into an `x-mjst` hint. Only a leaf it has no rescue for (a raw `symbol`, say) is fatal, and then it throws an actionable message rather than Effect's opaque one: replace the type with a JSON-representable one, or add a `jsonSchema` annotation to that field.
217
217
 
218
218
  If any of these matter to your schema, prefer a representable alternative (e.g. model a set as an array) or add the library's own JSON Schema annotation.
219
219
 
@@ -237,7 +237,7 @@ Any other extended type (`Uint8Array`, `Symbol`, `Undefined`, …) is left untou
237
237
  Effect models a value as a **decode/encode pair**, and `JSONSchema.make` describes the **encoded** (wire) representation — not the runtime type. This is the caveat most likely to surprise you:
238
238
 
239
239
  - `Schema.Date` decodes a `Date` **from a string**, so it converts to a **`string`** schema — not a runtime `Date`. The adapter passes this through unchanged, because it accurately reflects what Effect expects on the wire.
240
- - Only the `*FromSelf` variants — `Schema.DateFromSelf`, `Schema.BigIntFromSelf` — describe the runtime value itself, and those are the ones rescued into `x-mjst` runtime-type hints (see [`src/effect-to-json-schema.ts:63`](./src/effect-to-json-schema.ts#L63)).
240
+ - Only the `*FromSelf` variants — `Schema.DateFromSelf`, `Schema.BigIntFromSelf` — describe the runtime value itself, and those are the ones rescued into `x-mjst` runtime-type hints (see [`src/effect-to-json-schema.ts:121-122`](./src/effect-to-json-schema.ts#L121-L122)).
241
241
 
242
242
  So: want a generated `Date`? Author `Schema.DateFromSelf`. Want a string that Effect parses into a `Date`? Author `Schema.Date` and expect a `string` in the generated output. The same distinction applies to `Schema.BigInt` (→ `string`) vs `Schema.BigIntFromSelf` (→ `bigint`).
243
243
 
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "@amritk/adapters",
3
- "version": "0.3.5",
3
+ "version": "0.4.0",
4
4
  "description": "Convert schemas from external libraries (TypeBox, Zod, ...) into JSON Schema for mjst.",
5
5
  "type": "module",
6
+ "sideEffects": false,
7
+ "engines": {
8
+ "node": ">=20"
9
+ },
6
10
  "license": "MIT",
7
11
  "author": "amritk",
8
12
  "keywords": [
@@ -38,7 +42,7 @@
38
42
  },
39
43
  "dependencies": {
40
44
  "json-schema-typed": "^8.0.1",
41
- "@amritk/helpers": "0.13.5"
45
+ "@amritk/helpers": "^0.15.0"
42
46
  },
43
47
  "exports": {
44
48
  "./package.json": "./package.json",
@@ -71,8 +75,14 @@
71
75
  "default": "./dist/effect-to-json-schema.js"
72
76
  }
73
77
  },
78
+ "typesVersions": {
79
+ "*": {
80
+ "*": [
81
+ "./dist/*.d.ts"
82
+ ]
83
+ }
84
+ },
74
85
  "peerDependencies": {
75
- "@sinclair/typebox": ">=0.34",
76
86
  "zod": ">=3",
77
87
  "zod-to-json-schema": ">=3",
78
88
  "valibot": ">=1",
@@ -80,9 +90,6 @@
80
90
  "effect": ">=3"
81
91
  },
82
92
  "peerDependenciesMeta": {
83
- "@sinclair/typebox": {
84
- "optional": true
85
- },
86
93
  "zod": {
87
94
  "optional": true
88
95
  },