schema-components 1.21.0 → 1.23.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 (91) hide show
  1. package/README.md +3 -1
  2. package/dist/core/adapter.d.mts +115 -4
  3. package/dist/core/adapter.mjs +405 -75
  4. package/dist/core/constraints.d.mts +2 -2
  5. package/dist/core/constraints.mjs +0 -7
  6. package/dist/core/cssClasses.d.mts +52 -0
  7. package/dist/core/cssClasses.mjs +51 -0
  8. package/dist/core/diagnostics.d.mts +1 -1
  9. package/dist/core/errors.d.mts +1 -1
  10. package/dist/core/errors.mjs +5 -13
  11. package/dist/core/fieldOrder.d.mts +1 -1
  12. package/dist/core/formats.d.mts +30 -2
  13. package/dist/core/formats.mjs +33 -1
  14. package/dist/core/idPath.d.mts +54 -0
  15. package/dist/core/idPath.mjs +66 -0
  16. package/dist/core/limits.d.mts +2 -0
  17. package/dist/core/limits.mjs +23 -0
  18. package/dist/core/merge.d.mts +10 -1
  19. package/dist/core/merge.mjs +49 -10
  20. package/dist/core/normalise.d.mts +40 -3
  21. package/dist/core/normalise.mjs +2 -2
  22. package/dist/core/openapi30.d.mts +15 -1
  23. package/dist/core/openapi30.mjs +2 -2
  24. package/dist/core/openapiConstants.d.mts +67 -0
  25. package/dist/core/openapiConstants.mjs +90 -0
  26. package/dist/core/ref.d.mts +2 -2
  27. package/dist/core/ref.mjs +85 -6
  28. package/dist/core/refChain.d.mts +70 -0
  29. package/dist/core/refChain.mjs +44 -0
  30. package/dist/core/renderer.d.mts +1 -1
  31. package/dist/core/renderer.mjs +0 -2
  32. package/dist/core/swagger2.d.mts +1 -1
  33. package/dist/core/swagger2.mjs +1 -1
  34. package/dist/core/typeInference.d.mts +982 -2
  35. package/dist/core/types.d.mts +2 -2
  36. package/dist/core/types.mjs +1 -4
  37. package/dist/core/unionMatch.d.mts +36 -0
  38. package/dist/core/unionMatch.mjs +53 -0
  39. package/dist/core/version.d.mts +1 -1
  40. package/dist/core/version.mjs +29 -17
  41. package/dist/core/walkBuilders.d.mts +23 -4
  42. package/dist/core/walkBuilders.mjs +27 -7
  43. package/dist/core/walker.d.mts +1 -1
  44. package/dist/core/walker.mjs +123 -47
  45. package/dist/{diagnostics-CbBPsxSt.d.mts → diagnostics-BS2kaUyE.d.mts} +1 -1
  46. package/dist/{errors-QEwOtQAA.d.mts → errors-g_MCTQel.d.mts} +10 -16
  47. package/dist/html/a11y.d.mts +9 -4
  48. package/dist/html/a11y.mjs +10 -12
  49. package/dist/html/renderToHtml.d.mts +10 -3
  50. package/dist/html/renderToHtml.mjs +13 -3
  51. package/dist/html/renderToHtmlStream.d.mts +2 -2
  52. package/dist/html/renderToHtmlStream.mjs +12 -1
  53. package/dist/html/renderers.d.mts +43 -8
  54. package/dist/html/renderers.mjs +136 -116
  55. package/dist/html/streamRenderers.d.mts +6 -6
  56. package/dist/html/streamRenderers.mjs +129 -89
  57. package/dist/limits-Cw5QZND8.d.mts +29 -0
  58. package/dist/{normalise-DaSrnr8g.mjs → normalise-DCYp06Sr.mjs} +770 -227
  59. package/dist/openapi/ApiCallbacks.d.mts +1 -1
  60. package/dist/openapi/ApiLinks.d.mts +1 -1
  61. package/dist/openapi/ApiResponseHeaders.d.mts +1 -1
  62. package/dist/openapi/ApiSecurity.d.mts +1 -1
  63. package/dist/openapi/ApiSecurity.mjs +16 -2
  64. package/dist/openapi/components.d.mts +234 -23
  65. package/dist/openapi/components.mjs +183 -52
  66. package/dist/openapi/parser.d.mts +9 -8
  67. package/dist/openapi/parser.mjs +252 -70
  68. package/dist/openapi/resolve.d.mts +31 -15
  69. package/dist/openapi/resolve.mjs +260 -40
  70. package/dist/react/SchemaComponent.d.mts +126 -36
  71. package/dist/react/SchemaComponent.mjs +95 -57
  72. package/dist/react/SchemaView.d.mts +30 -10
  73. package/dist/react/SchemaView.mjs +2 -2
  74. package/dist/react/a11y.d.mts +21 -0
  75. package/dist/react/a11y.mjs +24 -0
  76. package/dist/react/fieldPath.d.mts +1 -1
  77. package/dist/react/headless.d.mts +1 -1
  78. package/dist/react/headless.mjs +1 -2
  79. package/dist/react/headlessRenderers.d.mts +9 -11
  80. package/dist/react/headlessRenderers.mjs +51 -102
  81. package/dist/{ref-si8ViYun.d.mts → ref-DjLEKa_E.d.mts} +38 -3
  82. package/dist/{renderer-DI6ZYf7a.d.mts → renderer-CXJ8y0qw.d.mts} +2 -2
  83. package/dist/themes/mantine.d.mts +1 -1
  84. package/dist/themes/mui.d.mts +1 -1
  85. package/dist/themes/radix.d.mts +1 -1
  86. package/dist/themes/shadcn.d.mts +1 -1
  87. package/dist/themes/shadcn.mjs +2 -1
  88. package/dist/{types-BnxPEElk.d.mts → types-BTB73MB8.d.mts} +35 -14
  89. package/dist/{version-D-u7aMfy.d.mts → version-BFTVLsdb.d.mts} +7 -1
  90. package/package.json +1 -3
  91. package/dist/typeInference-Bxw3NOG1.d.mts +0 -647
package/README.md CHANGED
@@ -16,7 +16,9 @@ Peer dependencies: `zod@^4.0.0`, `react@^18.0.0 || ^19.0.0`.
16
16
 
17
17
  ### Zod version requirement
18
18
 
19
- schema-components requires **Zod 4**. If you are on Zod 3, see the [Zod 4 migration guide](https://zod.dev/v4/migration). The library detects Zod 3 inputs and throws a descriptive error rather than silently misbehaving.
19
+ schema-components requires **Zod 4**. If you are on Zod 3, see the [Zod 4 migration guide](https://zod.dev/v4/migration). Zod 3 schemas are detected structurally — any object exposing `_def` without the Zod 4 `_zod` marker is classified as Zod 3, with or without the historical `_def.typeName` field. (Some third-party Zod-3-style libraries omit `typeName`; the detector keys on the presence of `_def` alone.) A descriptive `SchemaNormalisationError` is raised pointing at the Zod 4 migration guide.
20
+
21
+ Schemas from other libraries that conform to the [Standard Schema](https://standardschema.dev/) spec (valibot, arktype, ...) are also detected and rejected. When the input advertises a `~standard.vendor` field, the error message includes the vendor name so consumers know which library produced the input.
20
22
 
21
23
  ## `SchemaComponent`
22
24
 
@@ -1,10 +1,103 @@
1
- import { T as SchemaMeta, m as JsonObject } from "../types-BnxPEElk.mjs";
2
- import { i as DiagnosticsOptions } from "../diagnostics-CbBPsxSt.mjs";
1
+ import { m as JsonObject, w as SchemaMeta } from "../types-BTB73MB8.mjs";
2
+ import { i as DiagnosticsOptions } from "../diagnostics-BS2kaUyE.mjs";
3
3
 
4
4
  //#region src/core/adapter.d.ts
5
5
  type SchemaInput = Record<string, unknown>;
6
- type SchemaKind = "zod4" | "zod3" | "jsonSchema" | "openapi";
6
+ type SchemaKind = "zod4" | "zod3" | "jsonSchema" | "openapi" | "unsupported-schema-lib";
7
+ /**
8
+ * Classify the input schema by its structural markers.
9
+ *
10
+ * - `zod4` — has a `_zod` marker (further validation that `_zod.def` is a
11
+ * non-null object happens inside `normaliseZod4`).
12
+ * - `zod3` — has `_def` and no `_zod`. The `typeName` field is no longer
13
+ * required: any `_def` without `_zod` is treated as a probable Zod 3
14
+ * schema. Third-party libraries that expose `_def` without `_zod` are
15
+ * nearly always Zod 3 forks; surfacing the migration message is the
16
+ * correct response.
17
+ * - `openapi` — has `openapi` or `swagger` at the root.
18
+ * - `unsupported-schema-lib` — has `parse` and `safeParse` callables but
19
+ * no `_zod` and no `_def` marker. This catches Standard Schema
20
+ * implementations (valibot, arktype, etc.) that would otherwise flow
21
+ * through as "malformed JSON Schema".
22
+ * - `jsonSchema` — fallback for anything that does not match the above.
23
+ */
7
24
  declare function detectSchemaKind(input: unknown): SchemaKind;
25
+ /**
26
+ * Wraps z.toJSONSchema() for a runtime-validated Zod schema.
27
+ *
28
+ * The _zod guard in normaliseZod4 has confirmed this is a valid Zod schema,
29
+ * but TypeScript cannot represent "has _zod.def" as the $ZodType parameter
30
+ * that z.toJSONSchema expects. This is the library boundary equivalent of
31
+ * object → Record<string, unknown> — the type mismatch is genuinely unavoidable.
32
+ *
33
+ * # Options
34
+ *
35
+ * `z.toJSONSchema` is invoked with an explicit options object rather than
36
+ * Zod's defaults so the conversion contract is pinned and stable:
37
+ *
38
+ * - `target: "draft-2020-12"` — matches the walker's draft target.
39
+ * - `unrepresentable: "throw"` — keeps the unrepresentable-type rules in
40
+ * the classifier table firing instead of silently emitting `{}`.
41
+ * - `cycles: "ref"` — converts cyclic graphs into $ref pairs rather than
42
+ * throwing. Cycles in user schemas surface through the walker's $ref
43
+ * resolution rather than the adapter.
44
+ * - `io` — selects which side of every transform / pipe / codec is
45
+ * converted. Defaults to `"output"` (the OUTPUT side); pass `"input"`
46
+ * to render the INPUT side instead. The input side is invisible to
47
+ * the converted schema when `io: "output"` is in force, even though
48
+ * `safeParse` on the same Zod schema consumes the input shape. For
49
+ * transforms this divergence is fatal and the call throws via
50
+ * `Transforms cannot be represented`; for `z.codec(...)` the call
51
+ * succeeds but only the selected side is rendered. Consumers receive
52
+ * a `zod-codec-output-only` diagnostic in the codec case so the
53
+ * asymmetry is visible — see `screenPreConversion`.
54
+ *
55
+ * # Error classification
56
+ *
57
+ * Any exception thrown by z.toJSONSchema is classified into a
58
+ * SchemaNormalisationError so the caller does not have to re-parse error
59
+ * message strings. The classification covers:
60
+ *
61
+ * - Nested Zod 3 schemas inside a Zod 4 tree → zod3-unsupported.
62
+ * Detected structurally (presence of `_def.typeName` markers anywhere
63
+ * in the schema tree) so the check works across V8, JavaScriptCore,
64
+ * and SpiderMonkey, none of which agree on the wording of
65
+ * "Cannot read properties of undefined".
66
+ * - Transforms → zod-transform-unsupported. This also catches `z.codec(…)`
67
+ * because Zod implements codecs as a pipe + transform internally, so
68
+ * they trip the same processor when round-tripping is forced. (Plain
69
+ * `z.toJSONSchema(codec)` itself does NOT throw because Zod picks one
70
+ * side of the codec; the static rejection in `typeInference.ts` is the
71
+ * compile-time guard.)
72
+ * - Dynamic catch values whose handler throws → zod-type-unrepresentable
73
+ * with zodType "dynamic-catch".
74
+ * - Unrepresentable types — bigint, date, map, set, symbol, function, custom,
75
+ * undefined, void, NaN, and the literal-only forms `z.literal(undefined)`
76
+ * ("undefined-literal") and `z.literal(<bigint>)` ("bigint-literal") →
77
+ * zod-type-unrepresentable.
78
+ * - The catch-all "Non-representable type encountered: <type>" fallback Zod
79
+ * emits for any new schema kind without a registered processor →
80
+ * zod-type-unrepresentable with zodType set to the offending def.type.
81
+ * - Cycle detected (`cycles: "throw"`) → zod-cycle-detected.
82
+ * - Duplicate schema id → zod-duplicate-id.
83
+ * - "Unprocessed schema. This is a bug in Zod." → zod-conversion-bug.
84
+ * - "Error converting schema to JSON." → zod-conversion-failed (explicit
85
+ * classification rather than the generic fallback so the contract test
86
+ * protects the prefix from drift).
87
+ * - Anything else → zod-conversion-failed.
88
+ *
89
+ * The original error is preserved on each classified error via the `cause`
90
+ * field so consumers can still inspect the Zod stack trace.
91
+ */
92
+ /**
93
+ * IO side passed to {@link callToJsonSchema}. The Zod runtime accepts
94
+ * `"input" | "output"` for the corresponding `io` option on
95
+ * `z.toJSONSchema`. Defaults to `"output"` everywhere in the adapter
96
+ * pipeline; the parameter exists so a future renderer or component
97
+ * (currently SchemaComponent — see TODO below) can request the input
98
+ * side without forking the helper.
99
+ */
100
+ type SchemaIoSide = "input" | "output";
8
101
  /**
9
102
  * Exposed for unit testing — lets the contract test enumerate every rule's
10
103
  * `prefix` value and assert mutual non-prefixing.
@@ -27,5 +120,23 @@ interface NormaliseOptions {
27
120
  diagnostics?: DiagnosticsOptions;
28
121
  }
29
122
  declare function normaliseSchema(input: unknown, ref?: string, options?: NormaliseOptions): NormalisedSchema;
123
+ /**
124
+ * Surface root-level metadata from the JSON Schema into the `rootMeta`
125
+ * shape consumed by the walker. Pulls `readOnly`, `writeOnly`,
126
+ * `description`, `title`, `deprecated`, `examples`, and `default`
127
+ * directly from the schema root.
128
+ *
129
+ * `examples` is forwarded only when present as an array (per JSON Schema
130
+ * Draft 2020-12 — Draft 04's `example` singular is normalised upstream).
131
+ * `default` is forwarded for any value the schema declares (any JSON
132
+ * value, including `null` and `false`); the presence check uses `in`
133
+ * so a literal `false` or `null` default is preserved.
134
+ *
135
+ * `examples` and `default` ride on the `[key: string]: unknown` index
136
+ * signature of {@link SchemaMeta}. They are not declared as named fields
137
+ * on `SchemaMeta` because that type lives in `types.ts` and is shared
138
+ * with the walker; the index signature is the agreed extension point.
139
+ */
140
+ declare function extractRootMetaFromJson(jsonSchema: JsonObject): SchemaMeta | undefined;
30
141
  //#endregion
31
- export { type JsonObject, NormaliseOptions, NormalisedSchema, SchemaInput, SchemaKind, type SchemaMeta, __CLASSIFIER_RULES_FOR_TEST, detectSchemaKind, normaliseSchema };
142
+ export { type JsonObject, NormaliseOptions, NormalisedSchema, SchemaInput, SchemaIoSide, SchemaKind, type SchemaMeta, __CLASSIFIER_RULES_FOR_TEST, detectSchemaKind, extractRootMetaFromJson, normaliseSchema };