schema-components 1.28.2 → 2.0.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 (105) hide show
  1. package/README.md +38 -16
  2. package/dist/core/adapter.d.mts +213 -3
  3. package/dist/core/adapter.mjs +21 -2
  4. package/dist/core/constraintHint.d.mts +15 -0
  5. package/dist/core/constraintHint.mjs +24 -0
  6. package/dist/core/constraints.d.mts +34 -2
  7. package/dist/core/constraints.mjs +33 -1
  8. package/dist/core/cssClasses.d.mts +1 -0
  9. package/dist/core/diagnostics.d.mts +1 -1
  10. package/dist/core/errors.d.mts +1 -1
  11. package/dist/core/errors.mjs +22 -12
  12. package/dist/core/fieldOrder.d.mts +1 -1
  13. package/dist/core/formats.d.mts +7 -1
  14. package/dist/core/formats.mjs +6 -0
  15. package/dist/core/idPath.d.mts +35 -5
  16. package/dist/core/idPath.mjs +79 -7
  17. package/dist/core/inferValue.d.mts +2 -0
  18. package/dist/core/inferValue.mjs +1 -0
  19. package/dist/core/limits.d.mts +1 -1
  20. package/dist/core/limits.mjs +6 -0
  21. package/dist/core/merge.d.mts +22 -1
  22. package/dist/core/merge.mjs +66 -3
  23. package/dist/core/normalise.d.mts +17 -2
  24. package/dist/core/normalise.mjs +1 -1
  25. package/dist/core/openapi30.mjs +1 -1
  26. package/dist/core/openapiConstants.d.mts +1 -0
  27. package/dist/core/ref.d.mts +1 -1
  28. package/dist/core/refChain.d.mts +3 -4
  29. package/dist/core/refChain.mjs +2 -3
  30. package/dist/core/renderer.d.mts +199 -2
  31. package/dist/core/renderer.mjs +5 -0
  32. package/dist/core/swagger2.d.mts +1 -1
  33. package/dist/core/swagger2.mjs +1 -1
  34. package/dist/core/typeInference.d.mts +3 -3
  35. package/dist/core/types.d.mts +1 -1
  36. package/dist/core/types.mjs +17 -0
  37. package/dist/core/unionMatch.d.mts +1 -1
  38. package/dist/core/uri.d.mts +12 -4
  39. package/dist/core/uri.mjs +30 -4
  40. package/dist/core/version.d.mts +1 -1
  41. package/dist/core/walkBuilders.d.mts +63 -6
  42. package/dist/core/walkBuilders.mjs +33 -1
  43. package/dist/core/walker.d.mts +14 -1
  44. package/dist/core/walker.mjs +18 -0
  45. package/dist/{diagnostics-Cbwak-ZX.d.mts → diagnostics-BTrm3O6J.d.mts} +9 -1
  46. package/dist/{errors-DQSIK4n1.d.mts → errors-Dki7tji4.d.mts} +23 -13
  47. package/dist/html/a11y.d.mts +3 -7
  48. package/dist/html/a11y.mjs +1 -16
  49. package/dist/html/html.d.mts +11 -0
  50. package/dist/html/html.mjs +11 -0
  51. package/dist/html/renderToHtml.d.mts +45 -12
  52. package/dist/html/renderToHtml.mjs +20 -4
  53. package/dist/html/renderToHtmlStream.d.mts +63 -18
  54. package/dist/html/renderToHtmlStream.mjs +34 -8
  55. package/dist/html/renderers.d.mts +6 -31
  56. package/dist/html/renderers.mjs +45 -91
  57. package/dist/html/streamRenderers.d.mts +31 -3
  58. package/dist/html/streamRenderers.mjs +41 -8
  59. package/dist/inferValue-PPXWJpbN.d.mts +77 -0
  60. package/dist/{limits-DJhgx5Ay.d.mts → limits-x4OiyJxh.d.mts} +6 -0
  61. package/dist/{normalise-Db1xaxgx.mjs → normalise-DB-Xtjmn.mjs} +43 -2
  62. package/dist/openapi/ApiCallbacks.d.mts +13 -1
  63. package/dist/openapi/ApiCallbacks.mjs +7 -0
  64. package/dist/openapi/ApiLinks.d.mts +13 -1
  65. package/dist/openapi/ApiLinks.mjs +7 -0
  66. package/dist/openapi/ApiResponseHeaders.d.mts +13 -1
  67. package/dist/openapi/ApiResponseHeaders.mjs +7 -0
  68. package/dist/openapi/ApiSecurity.d.mts +14 -1
  69. package/dist/openapi/ApiSecurity.mjs +29 -8
  70. package/dist/openapi/bundle.d.mts +31 -0
  71. package/dist/openapi/components.d.mts +135 -20
  72. package/dist/openapi/components.mjs +90 -15
  73. package/dist/openapi/parser.d.mts +140 -13
  74. package/dist/openapi/parser.mjs +84 -12
  75. package/dist/openapi/resolve.d.mts +42 -47
  76. package/dist/openapi/resolve.mjs +62 -56
  77. package/dist/react/SchemaComponent.d.mts +90 -88
  78. package/dist/react/SchemaComponent.mjs +74 -2
  79. package/dist/react/SchemaErrorBoundary.d.mts +18 -1
  80. package/dist/react/SchemaErrorBoundary.mjs +13 -1
  81. package/dist/react/SchemaView.d.mts +39 -11
  82. package/dist/react/SchemaView.mjs +23 -6
  83. package/dist/react/a11y.d.mts +74 -7
  84. package/dist/react/a11y.mjs +67 -6
  85. package/dist/react/fieldPath.d.mts +16 -1
  86. package/dist/react/fieldPath.mjs +25 -1
  87. package/dist/react/fieldShell.d.mts +49 -0
  88. package/dist/react/fieldShell.mjs +37 -0
  89. package/dist/react/headless.d.mts +1 -1
  90. package/dist/react/headlessRenderers.d.mts +13 -2
  91. package/dist/react/headlessRenderers.mjs +134 -54
  92. package/dist/{ref-TdeMfaV_.d.mts → ref-DdsbekXX.d.mts} +33 -1
  93. package/dist/themes/mantine.d.mts +54 -12
  94. package/dist/themes/mantine.mjs +195 -140
  95. package/dist/themes/mui.d.mts +64 -11
  96. package/dist/themes/mui.mjs +277 -213
  97. package/dist/themes/radix.d.mts +67 -15
  98. package/dist/themes/radix.mjs +235 -170
  99. package/dist/themes/shadcn.d.mts +25 -1
  100. package/dist/themes/shadcn.mjs +112 -91
  101. package/dist/{types-BTB73MB8.d.mts → types-BrYbjC7_.d.mts} +30 -0
  102. package/dist/{version-ZzL5R6cS.d.mts → version-DL8U5RuA.d.mts} +6 -0
  103. package/package.json +8 -1
  104. package/dist/adapter-DqlAnZ_w.d.mts +0 -172
  105. package/dist/renderer-Ul9taFYp.d.mts +0 -169
package/README.md CHANGED
@@ -298,14 +298,20 @@ import { shadcnResolver } from "schema-components/themes/shadcn";
298
298
  ### MUI
299
299
 
300
300
  ```tsx
301
- import { registerMuiComponents } from "schema-components/themes/mui";
302
- import { shadcnResolver } from "schema-components/themes/shadcn";
303
-
304
- // Register MUI components at app startup
305
- registerMuiComponents();
301
+ import { SchemaProvider } from "schema-components/react/SchemaComponent";
302
+ import { createMuiResolver } from "schema-components/themes/mui";
303
+ import TextField from "@mui/material/TextField";
304
+ import Checkbox from "@mui/material/Checkbox";
305
+ import Typography from "@mui/material/Typography";
306
+ import Box from "@mui/material/Box";
307
+ import MenuItem from "@mui/material/MenuItem";
308
+ import FormControlLabel from "@mui/material/FormControlLabel";
309
+
310
+ const muiResolver = createMuiResolver({
311
+ TextField, Checkbox, Typography, Box, MenuItem, FormControlLabel,
312
+ });
306
313
 
307
- // Use via SchemaProvider
308
- <SchemaProvider resolver={shadcnResolver}>
314
+ <SchemaProvider resolver={muiResolver}>
309
315
  <SchemaComponent schema={userSchema} value={user} onChange={setUser} />
310
316
  </SchemaProvider>
311
317
  ```
@@ -313,12 +319,17 @@ registerMuiComponents();
313
319
  ### Mantine
314
320
 
315
321
  ```tsx
316
- import { registerMantineComponents } from "schema-components/themes/mantine";
317
- import { shadcnResolver } from "schema-components/themes/shadcn";
322
+ import { SchemaProvider } from "schema-components/react/SchemaComponent";
323
+ import { createMantineResolver } from "schema-components/themes/mantine";
324
+ import {
325
+ TextInput, NumberInput, Switch, Select, Fieldset, Text,
326
+ } from "@mantine/core";
318
327
 
319
- registerMantineComponents();
328
+ const mantineResolver = createMantineResolver({
329
+ TextInput, NumberInput, Switch, Select, Fieldset, Text,
330
+ });
320
331
 
321
- <SchemaProvider resolver={shadcnResolver}>
332
+ <SchemaProvider resolver={mantineResolver}>
322
333
  <SchemaComponent schema={userSchema} value={user} onChange={setUser} />
323
334
  </SchemaProvider>
324
335
  ```
@@ -326,12 +337,23 @@ registerMantineComponents();
326
337
  ### Radix Themes
327
338
 
328
339
  ```tsx
329
- import { registerRadixComponents } from "schema-components/themes/radix";
330
- import { shadcnResolver } from "schema-components/themes/shadcn";
331
-
332
- registerRadixComponents();
340
+ import { SchemaProvider } from "schema-components/react/SchemaComponent";
341
+ import { createRadixResolver } from "schema-components/themes/radix";
342
+ import { Box, Checkbox, Flex, Select, Text, TextField } from "@radix-ui/themes";
343
+
344
+ const radixResolver = createRadixResolver({
345
+ Box,
346
+ Checkbox,
347
+ Flex,
348
+ SelectRoot: Select.Root,
349
+ SelectTrigger: Select.Trigger,
350
+ SelectContent: Select.Content,
351
+ SelectItem: Select.Item,
352
+ Text,
353
+ TextField: TextField.Root,
354
+ });
333
355
 
334
- <SchemaProvider resolver={shadcnResolver}>
356
+ <SchemaProvider resolver={radixResolver}>
335
357
  <SchemaComponent schema={userSchema} value={user} onChange={setUser} />
336
358
  </SchemaProvider>
337
359
  ```
@@ -1,3 +1,213 @@
1
- import { m as JsonObject, w as SchemaMeta } from "../types-BTB73MB8.mjs";
2
- import { a as SchemaKind, c as extractRootMetaFromJson, i as SchemaIoSide, l as isCodecSchema, n as NormalisedSchema, o as __CLASSIFIER_RULES_FOR_TEST, r as SchemaInput, s as detectSchemaKind, t as NormaliseOptions, u as normaliseSchema } from "../adapter-DqlAnZ_w.mjs";
3
- export { JsonObject, NormaliseOptions, NormalisedSchema, SchemaInput, SchemaIoSide, SchemaKind, SchemaMeta, __CLASSIFIER_RULES_FOR_TEST, detectSchemaKind, extractRootMetaFromJson, isCodecSchema, normaliseSchema };
1
+ import { m as JsonObject, w as SchemaMeta } from "../types-BrYbjC7_.mjs";
2
+ import { i as DiagnosticsOptions } from "../diagnostics-BTrm3O6J.mjs";
3
+
4
+ //#region src/core/adapter.d.ts
5
+ /**
6
+ * Classification produced by {@link detectSchemaKind} when inspecting a
7
+ * runtime schema input.
8
+ *
9
+ * @group Adapter
10
+ */
11
+ type SchemaKind = "zod4" | "zod3" | "jsonSchema" | "openapi" | "unsupported-schema-lib";
12
+ /**
13
+ * Classify a runtime schema input by structural markers — Zod 4, Zod 3,
14
+ * OpenAPI document, plain JSON Schema, or an unsupported third-party
15
+ * schema library.
16
+ *
17
+ * - `zod4` — has a `_zod` marker (further validation that `_zod.def` is a
18
+ * non-null object happens inside `normaliseZod4`).
19
+ * - `zod3` — has `_def` and no `_zod`. The `typeName` field is no longer
20
+ * required: any `_def` without `_zod` is treated as a probable Zod 3
21
+ * schema. Third-party libraries that expose `_def` without `_zod` are
22
+ * nearly always Zod 3 forks; surfacing the migration message is the
23
+ * correct response.
24
+ * - `openapi` — has `openapi` or `swagger` at the root.
25
+ * - `unsupported-schema-lib` — has `parse` and `safeParse` callables but
26
+ * no `_zod` and no `_def` marker. This catches Standard Schema
27
+ * implementations (valibot, arktype, etc.) that would otherwise flow
28
+ * through as "malformed JSON Schema".
29
+ * - `jsonSchema` — fallback for anything that does not match the above.
30
+ *
31
+ * @group Adapter
32
+ */
33
+ declare function detectSchemaKind(input: unknown): SchemaKind;
34
+ /**
35
+ * Wraps z.toJSONSchema() for a runtime-validated Zod schema.
36
+ *
37
+ * The _zod guard in normaliseZod4 has confirmed this is a valid Zod schema,
38
+ * but TypeScript cannot represent "has _zod.def" as the $ZodType parameter
39
+ * that z.toJSONSchema expects. This is the library boundary equivalent of
40
+ * object → Record<string, unknown> — the type mismatch is genuinely unavoidable.
41
+ *
42
+ * # Options
43
+ *
44
+ * `z.toJSONSchema` is invoked with an explicit options object rather than
45
+ * Zod's defaults so the conversion contract is pinned and stable:
46
+ *
47
+ * - `target: "draft-2020-12"` — matches the walker's draft target.
48
+ * - `unrepresentable: "throw"` — keeps the unrepresentable-type rules in
49
+ * the classifier table firing instead of silently emitting `{}`.
50
+ * - `cycles: "ref"` — converts cyclic graphs into $ref pairs rather than
51
+ * throwing. Cycles in user schemas surface through the walker's $ref
52
+ * resolution rather than the adapter.
53
+ * - `io` — selects which side of every transform / pipe / codec is
54
+ * converted. Defaults to `"output"` (the OUTPUT side); pass `"input"`
55
+ * to render the INPUT side instead. The input side is invisible to
56
+ * the converted schema when `io: "output"` is in force, even though
57
+ * `safeParse` on the same Zod schema consumes the input shape. For
58
+ * transforms this divergence is fatal and the call throws via
59
+ * `Transforms cannot be represented`; for `z.codec(...)` the call
60
+ * succeeds but only the selected side is rendered. Consumers receive
61
+ * a `zod-codec-output-only` diagnostic in the codec case so the
62
+ * asymmetry is visible — see `screenPreConversion`.
63
+ *
64
+ * # Error classification
65
+ *
66
+ * Any exception thrown by z.toJSONSchema is classified into a
67
+ * SchemaNormalisationError so the caller does not have to re-parse error
68
+ * message strings. The classification covers:
69
+ *
70
+ * - Nested Zod 3 schemas inside a Zod 4 tree → zod3-unsupported.
71
+ * Detected structurally (presence of `_def.typeName` markers anywhere
72
+ * in the schema tree) so the check works across V8, JavaScriptCore,
73
+ * and SpiderMonkey, none of which agree on the wording of
74
+ * "Cannot read properties of undefined".
75
+ * - Transforms → zod-transform-unsupported. This also catches `z.codec(…)`
76
+ * because Zod implements codecs as a pipe + transform internally, so
77
+ * they trip the same processor when round-tripping is forced. (Plain
78
+ * `z.toJSONSchema(codec)` itself does NOT throw because Zod picks one
79
+ * side of the codec; the static rejection in `typeInference.ts` is the
80
+ * compile-time guard.)
81
+ * - Dynamic catch values whose handler throws → zod-type-unrepresentable
82
+ * with zodType "dynamic-catch".
83
+ * - Unrepresentable types — bigint, date, map, set, symbol, function, custom,
84
+ * undefined, void, NaN, and the literal-only forms `z.literal(undefined)`
85
+ * ("undefined-literal") and `z.literal(<bigint>)` ("bigint-literal") →
86
+ * zod-type-unrepresentable.
87
+ * - The catch-all "Non-representable type encountered: <type>" fallback Zod
88
+ * emits for any new schema kind without a registered processor →
89
+ * zod-type-unrepresentable with zodType set to the offending def.type.
90
+ * - Cycle detected (`cycles: "throw"`) → zod-cycle-detected.
91
+ * - Duplicate schema id → zod-duplicate-id.
92
+ * - "Unprocessed schema. This is a bug in Zod." → zod-conversion-bug.
93
+ * - "Error converting schema to JSON." → zod-conversion-failed (explicit
94
+ * classification rather than the generic fallback so the contract test
95
+ * protects the prefix from drift).
96
+ * - Anything else → zod-conversion-failed.
97
+ *
98
+ * The original error is preserved on each classified error via the `cause`
99
+ * field so consumers can still inspect the Zod stack trace.
100
+ */
101
+ /**
102
+ * Direction of the Zod transform / pipe / codec that
103
+ * {@link normaliseSchema} should surface to the renderer.
104
+ *
105
+ * - `"output"` (default) — the server-facing side of every transform,
106
+ * matching `z.toJSONSchema`'s default and the historic adapter
107
+ * behaviour.
108
+ * - `"input"` — the client-facing side; flips a `z.codec(...)` chain
109
+ * so consumers can render its input shape.
110
+ *
111
+ * @group Adapter
112
+ */
113
+ type SchemaIoSide = "input" | "output";
114
+ /**
115
+ * True when `value` is a Zod schema implemented as a codec
116
+ * (`z.codec(...)`). Detection looks for the `$ZodCodec` marker on the
117
+ * schema's `_zod.traits` Set — the same structural check used by Zod
118
+ * itself in `to-json-schema.ts`'s `isTransforming` helper.
119
+ *
120
+ * Promoted from a duplicated local helper in `react/SchemaComponent.tsx`
121
+ * so the validation boundary inside `runValidation` can branch on
122
+ * codec-vs-not-codec without re-implementing the trait check. The
123
+ * shared helper anchors a single source of truth for codec detection:
124
+ * any future change to Zod's trait naming flows through here, not
125
+ * through two parallel copies.
126
+ *
127
+ * Returns `false` for non-objects, plain JSON Schema inputs, OpenAPI
128
+ * documents, or Zod schemas of any other kind. This is structural
129
+ * rather than nominal — a Zod 4 codec produced by any path that ends
130
+ * up tagging `_zod.traits` with `$ZodCodec` is recognised, including
131
+ * schemas wrapped by user-defined helpers.
132
+ */
133
+ declare function isCodecSchema(value: unknown): boolean;
134
+ /**
135
+ * Exposed for unit testing — lets the contract test enumerate every rule's
136
+ * `prefix` value and assert mutual non-prefixing.
137
+ */
138
+ declare const __CLASSIFIER_RULES_FOR_TEST: readonly {
139
+ readonly prefix: string;
140
+ }[];
141
+ /**
142
+ * Result of {@link normaliseSchema}. Carries the canonical Draft 2020-12
143
+ * JSON Schema the walker consumes, the optional original Zod schema
144
+ * (used for validation), and the resolved root document so cross-document
145
+ * `$ref`s can be dereferenced downstream.
146
+ *
147
+ * @group Adapter
148
+ */
149
+ interface NormalisedSchema {
150
+ /** JSON Schema object — the authoritative schema for rendering. */
151
+ jsonSchema: JsonObject;
152
+ /** Original Zod schema, if input was Zod. Used for validation. */
153
+ zodSchema?: unknown;
154
+ /** Root-level metadata. */
155
+ rootMeta: SchemaMeta | undefined;
156
+ /** The root document for $ref resolution. */
157
+ rootDocument: JsonObject;
158
+ }
159
+ /**
160
+ * Options accepted by {@link normaliseSchema}.
161
+ *
162
+ * @group Adapter
163
+ */
164
+ interface NormaliseOptions {
165
+ /** Diagnostics channel for surfacing silent fallbacks. */
166
+ diagnostics?: DiagnosticsOptions;
167
+ /**
168
+ * Side of every transform / pipe / codec to render. Defaults to
169
+ * `"output"`, matching `z.toJSONSchema`'s default and the
170
+ * historic behaviour of the adapter. Passing `"input"` flips the
171
+ * conversion so consumers rendering the input shape of a
172
+ * `z.codec(...)` chain receive that side instead of the output
173
+ * side. Only the Zod 4 branch consults this option — JSON Schema
174
+ * and OpenAPI inputs are already a single canonical shape.
175
+ */
176
+ io?: SchemaIoSide;
177
+ }
178
+ /**
179
+ * Normalise any supported schema input — Zod 4 schema, plain JSON
180
+ * Schema (any draft), Swagger 2.0, OpenAPI 3.0 or 3.1 document — into
181
+ * a canonical Draft 2020-12 {@link NormalisedSchema} the walker can
182
+ * consume.
183
+ *
184
+ * Dispatches on {@link detectSchemaKind}, applies the appropriate
185
+ * version normaliser, and returns the JSON Schema alongside the
186
+ * original Zod schema (for validation) and the resolved root document
187
+ * (for cross-document `$ref` resolution). Throws
188
+ * `SchemaNormalisationError` for unsupported inputs (Zod 3, valibot,
189
+ * arktype, codec or other unrepresentable Zod types).
190
+ *
191
+ * @group Adapter
192
+ */
193
+ declare function normaliseSchema(input: unknown, ref?: string, options?: NormaliseOptions): NormalisedSchema;
194
+ /**
195
+ * Surface root-level metadata from the JSON Schema into the `rootMeta`
196
+ * shape consumed by the walker. Pulls `readOnly`, `writeOnly`,
197
+ * `description`, `title`, `deprecated`, `examples`, and `default`
198
+ * directly from the schema root.
199
+ *
200
+ * `examples` is forwarded only when present as an array (per JSON Schema
201
+ * Draft 2020-12 — Draft 04's `example` singular is normalised upstream).
202
+ * `default` is forwarded for any value the schema declares (any JSON
203
+ * value, including `null` and `false`); the presence check uses `in`
204
+ * so a literal `false` or `null` default is preserved.
205
+ *
206
+ * `examples` and `default` ride on the `[key: string]: unknown` index
207
+ * signature of {@link SchemaMeta}. They are not declared as named fields
208
+ * on `SchemaMeta` because that type lives in `types.ts` and is shared
209
+ * with the walker; the index signature is the agreed extension point.
210
+ */
211
+ declare function extractRootMetaFromJson(jsonSchema: JsonObject): SchemaMeta | undefined;
212
+ //#endregion
213
+ export { type JsonObject, NormaliseOptions, NormalisedSchema, SchemaIoSide, SchemaKind, type SchemaMeta, __CLASSIFIER_RULES_FOR_TEST, detectSchemaKind, extractRootMetaFromJson, isCodecSchema, normaliseSchema };
@@ -4,7 +4,7 @@ import { SchemaNormalisationError } from "./errors.mjs";
4
4
  import { appendPointer, emitDiagnostic } from "./diagnostics.mjs";
5
5
  import { dereference } from "./ref.mjs";
6
6
  import { detectOpenApiVersion, inferJsonSchemaDraftWithReason, isSwagger2, matchJsonSchemaDraftUri } from "./version.mjs";
7
- import { a as normaliseJsonSchema$1, o as normaliseOpenApiSchemas } from "../normalise-Db1xaxgx.mjs";
7
+ import { a as normaliseJsonSchema$1, o as normaliseOpenApiSchemas } from "../normalise-DB-Xtjmn.mjs";
8
8
  import { z } from "zod";
9
9
  //#region src/core/adapter.ts
10
10
  /**
@@ -20,7 +20,9 @@ import { z } from "zod";
20
20
  */
21
21
  const schemaCache = /* @__PURE__ */ new WeakMap();
22
22
  /**
23
- * Classify the input schema by its structural markers.
23
+ * Classify a runtime schema input by structural markers — Zod 4, Zod 3,
24
+ * OpenAPI document, plain JSON Schema, or an unsupported third-party
25
+ * schema library.
24
26
  *
25
27
  * - `zod4` — has a `_zod` marker (further validation that `_zod.def` is a
26
28
  * non-null object happens inside `normaliseZod4`).
@@ -35,6 +37,8 @@ const schemaCache = /* @__PURE__ */ new WeakMap();
35
37
  * implementations (valibot, arktype, etc.) that would otherwise flow
36
38
  * through as "malformed JSON Schema".
37
39
  * - `jsonSchema` — fallback for anything that does not match the above.
40
+ *
41
+ * @group Adapter
38
42
  */
39
43
  function detectSchemaKind(input) {
40
44
  if (hasProperty(input, "_zod")) return "zod4";
@@ -624,6 +628,21 @@ function classifyZodConversionError(err, schema) {
624
628
  * `prefix` value and assert mutual non-prefixing.
625
629
  */
626
630
  const __CLASSIFIER_RULES_FOR_TEST = CLASSIFIER_RULES;
631
+ /**
632
+ * Normalise any supported schema input — Zod 4 schema, plain JSON
633
+ * Schema (any draft), Swagger 2.0, OpenAPI 3.0 or 3.1 document — into
634
+ * a canonical Draft 2020-12 {@link NormalisedSchema} the walker can
635
+ * consume.
636
+ *
637
+ * Dispatches on {@link detectSchemaKind}, applies the appropriate
638
+ * version normaliser, and returns the JSON Schema alongside the
639
+ * original Zod schema (for validation) and the resolved root document
640
+ * (for cross-document `$ref` resolution). Throws
641
+ * `SchemaNormalisationError` for unsupported inputs (Zod 3, valibot,
642
+ * arktype, codec or other unrepresentable Zod types).
643
+ *
644
+ * @group Adapter
645
+ */
627
646
  function normaliseSchema(input, ref, options) {
628
647
  const usesDiagnostics = options?.diagnostics !== void 0;
629
648
  const nonDefaultIo = options?.io !== void 0 && options.io !== "output";
@@ -0,0 +1,15 @@
1
+ import { AllConstraints } from "./renderer.mjs";
2
+
3
+ //#region src/core/constraintHint.d.ts
4
+ /**
5
+ * Build a human-readable constraint description string.
6
+ *
7
+ * Returns `undefined` when no constraint worth announcing is present.
8
+ * Pattern hints are suppressed when a `format` is set because the
9
+ * format already implies the pattern and the resulting copy would be
10
+ * misleading ("Must match pattern" alongside a `format: "email"` field
11
+ * would read as if the schema required a non-email regex).
12
+ */
13
+ declare function constraintHint(c: AllConstraints): string | undefined;
14
+ //#endregion
15
+ export { constraintHint };
@@ -0,0 +1,24 @@
1
+ //#region src/core/constraintHint.ts
2
+ /**
3
+ * Build a human-readable constraint description string.
4
+ *
5
+ * Returns `undefined` when no constraint worth announcing is present.
6
+ * Pattern hints are suppressed when a `format` is set because the
7
+ * format already implies the pattern and the resulting copy would be
8
+ * misleading ("Must match pattern" alongside a `format: "email"` field
9
+ * would read as if the schema required a non-email regex).
10
+ */
11
+ function constraintHint(c) {
12
+ const parts = [];
13
+ if (c.minLength !== void 0) parts.push(`Minimum ${String(c.minLength)} characters`);
14
+ if (c.maxLength !== void 0) parts.push(`Maximum ${String(c.maxLength)} characters`);
15
+ if (c.minimum !== void 0) parts.push(`Minimum ${String(c.minimum)}`);
16
+ if (c.maximum !== void 0) parts.push(`Maximum ${String(c.maximum)}`);
17
+ if (c.pattern !== void 0 && c.format === void 0) parts.push("Must match pattern");
18
+ if (c.minItems !== void 0) parts.push(`Minimum ${String(c.minItems)} items`);
19
+ if (c.maxItems !== void 0) parts.push(`Maximum ${String(c.maxItems)} items`);
20
+ if (parts.length === 0) return void 0;
21
+ return parts.join(". ");
22
+ }
23
+ //#endregion
24
+ export { constraintHint };
@@ -1,11 +1,43 @@
1
- import { E as StringConstraints, f as FileConstraints, t as ArrayConstraints, x as ObjectConstraints, y as NumberConstraints } from "../types-BTB73MB8.mjs";
2
- import { i as DiagnosticsOptions } from "../diagnostics-Cbwak-ZX.mjs";
1
+ import { E as StringConstraints, f as FileConstraints, t as ArrayConstraints, x as ObjectConstraints, y as NumberConstraints } from "../types-BrYbjC7_.mjs";
2
+ import { i as DiagnosticsOptions } from "../diagnostics-BTrm3O6J.mjs";
3
3
 
4
4
  //#region src/core/constraints.d.ts
5
+ /**
6
+ * Read the JSON Schema string constraint keywords (`minLength`,
7
+ * `maxLength`, `pattern`, `format`, `contentEncoding`,
8
+ * `contentMediaType`) from a schema node and return them in the
9
+ * `StringConstraints` shape consumed by string field renderers.
10
+ * Emits an `unknown-format` diagnostic for unrecognised `format`
11
+ * values.
12
+ */
5
13
  declare function extractStringConstraints(schema: Record<string, unknown>, diagnostics?: DiagnosticsOptions, pointer?: string): StringConstraints;
14
+ /**
15
+ * Read the JSON Schema number constraint keywords (`minimum`,
16
+ * `maximum`, `exclusiveMinimum`, `exclusiveMaximum`, `multipleOf`)
17
+ * from a schema node and return them in the `NumberConstraints` shape
18
+ * consumed by number field renderers.
19
+ */
6
20
  declare function extractNumberConstraints(schema: Record<string, unknown>): NumberConstraints;
21
+ /**
22
+ * Read the JSON Schema array constraint keywords (`minItems`,
23
+ * `maxItems`, `uniqueItems`, `minContains`, `maxContains`) from a
24
+ * schema node and return them in the `ArrayConstraints` shape. The
25
+ * `contains` and `unevaluatedItems` sub-schemas are walked separately
26
+ * and surfaced on the `ArrayField` / `TupleField` directly rather
27
+ * than as raw constraints.
28
+ */
7
29
  declare function extractArrayConstraints(schema: Record<string, unknown>): ArrayConstraints;
30
+ /**
31
+ * Read the JSON Schema object constraint keywords (`minProperties`,
32
+ * `maxProperties`) from a schema node and return them in the
33
+ * `ObjectConstraints` shape.
34
+ */
8
35
  declare function extractObjectConstraints(schema: Record<string, unknown>): ObjectConstraints;
36
+ /**
37
+ * Read the JSON Schema file constraints from a schema node — currently
38
+ * just `contentMediaType`, which surfaces as the single-entry
39
+ * `mimeTypes` array on `FileConstraints`.
40
+ */
9
41
  declare function extractFileConstraints(schema: Record<string, unknown>): FileConstraints;
10
42
  /**
11
43
  * Return a copy of the schema with constraint keywords that don't apply
@@ -9,6 +9,14 @@ function getNumber(obj, key) {
9
9
  const value = obj[key];
10
10
  return typeof value === "number" ? value : void 0;
11
11
  }
12
+ /**
13
+ * Read the JSON Schema string constraint keywords (`minLength`,
14
+ * `maxLength`, `pattern`, `format`, `contentEncoding`,
15
+ * `contentMediaType`) from a schema node and return them in the
16
+ * `StringConstraints` shape consumed by string field renderers.
17
+ * Emits an `unknown-format` diagnostic for unrecognised `format`
18
+ * values.
19
+ */
12
20
  function extractStringConstraints(schema, diagnostics, pointer = "") {
13
21
  const c = {};
14
22
  const minLength = getNumber(schema, "minLength");
@@ -22,7 +30,7 @@ function extractStringConstraints(schema, diagnostics, pointer = "") {
22
30
  c.format = format;
23
31
  const pattern = FORMAT_PATTERNS[format];
24
32
  if (pattern !== void 0) c.formatPattern = pattern;
25
- else if (format !== "binary") emitDiagnostic(diagnostics, {
33
+ else if (format !== "binary" && format !== "password") emitDiagnostic(diagnostics, {
26
34
  code: "unknown-format",
27
35
  message: `Unknown format: ${format}`,
28
36
  pointer,
@@ -35,6 +43,12 @@ function extractStringConstraints(schema, diagnostics, pointer = "") {
35
43
  if (contentMediaType !== void 0) c.contentMediaType = contentMediaType;
36
44
  return c;
37
45
  }
46
+ /**
47
+ * Read the JSON Schema number constraint keywords (`minimum`,
48
+ * `maximum`, `exclusiveMinimum`, `exclusiveMaximum`, `multipleOf`)
49
+ * from a schema node and return them in the `NumberConstraints` shape
50
+ * consumed by number field renderers.
51
+ */
38
52
  function extractNumberConstraints(schema) {
39
53
  const c = {};
40
54
  const minimum = getNumber(schema, "minimum");
@@ -49,6 +63,14 @@ function extractNumberConstraints(schema) {
49
63
  if (multipleOf !== void 0) c.multipleOf = multipleOf;
50
64
  return c;
51
65
  }
66
+ /**
67
+ * Read the JSON Schema array constraint keywords (`minItems`,
68
+ * `maxItems`, `uniqueItems`, `minContains`, `maxContains`) from a
69
+ * schema node and return them in the `ArrayConstraints` shape. The
70
+ * `contains` and `unevaluatedItems` sub-schemas are walked separately
71
+ * and surfaced on the `ArrayField` / `TupleField` directly rather
72
+ * than as raw constraints.
73
+ */
52
74
  function extractArrayConstraints(schema) {
53
75
  const c = {};
54
76
  const minItems = getNumber(schema, "minItems");
@@ -62,6 +84,11 @@ function extractArrayConstraints(schema) {
62
84
  if (maxContains !== void 0) c.maxContains = maxContains;
63
85
  return c;
64
86
  }
87
+ /**
88
+ * Read the JSON Schema object constraint keywords (`minProperties`,
89
+ * `maxProperties`) from a schema node and return them in the
90
+ * `ObjectConstraints` shape.
91
+ */
65
92
  function extractObjectConstraints(schema) {
66
93
  const c = {};
67
94
  const minProperties = getNumber(schema, "minProperties");
@@ -70,6 +97,11 @@ function extractObjectConstraints(schema) {
70
97
  if (maxProperties !== void 0) c.maxProperties = maxProperties;
71
98
  return c;
72
99
  }
100
+ /**
101
+ * Read the JSON Schema file constraints from a schema node — currently
102
+ * just `contentMediaType`, which surfaces as the single-entry
103
+ * `mimeTypes` array on `FileConstraints`.
104
+ */
73
105
  function extractFileConstraints(schema) {
74
106
  const c = {};
75
107
  const contentMediaType = getString(schema, "contentMediaType");
@@ -47,6 +47,7 @@ declare const SC_CLASSES: {
47
47
  readonly never: "sc-never";
48
48
  readonly recursive: "sc-recursive";
49
49
  };
50
+ /** Stable string-literal key into the canonical {@link SC_CLASSES} map. */
50
51
  type ScClassKey = keyof typeof SC_CLASSES;
51
52
  //#endregion
52
53
  export { ELLIPSIS, EM_DASH, SC_CLASSES, SC_ID_PREFIX, ScClassKey };
@@ -1,2 +1,2 @@
1
- import { a as appendPointer, i as DiagnosticsOptions, n as DiagnosticCode, o as emitDiagnostic, r as DiagnosticSink, t as Diagnostic } from "../diagnostics-Cbwak-ZX.mjs";
1
+ import { a as appendPointer, i as DiagnosticsOptions, n as DiagnosticCode, o as emitDiagnostic, r as DiagnosticSink, t as Diagnostic } from "../diagnostics-BTrm3O6J.mjs";
2
2
  export { Diagnostic, DiagnosticCode, DiagnosticSink, DiagnosticsOptions, appendPointer, emitDiagnostic };
@@ -1,2 +1,2 @@
1
- import { i as SchemaRenderError, n as SchemaFieldError, r as SchemaNormalisationError, t as SchemaError } from "../errors-DQSIK4n1.mjs";
1
+ import { i as SchemaRenderError, n as SchemaFieldError, r as SchemaNormalisationError, t as SchemaError } from "../errors-Dki7tji4.mjs";
2
2
  export { SchemaError, SchemaFieldError, SchemaNormalisationError, SchemaRenderError };
@@ -1,12 +1,15 @@
1
1
  //#region src/core/errors.ts
2
2
  /**
3
- * Base class for all schema-components errors.
4
- * Catch this to handle any library error uniformly.
3
+ * Base class for every schema-components error. Catch this to handle
4
+ * any library error uniformly.
5
5
  *
6
- * Forwards the optional `cause` to the native ES2022 `Error` constructor so
7
- * `error.cause` is wired up by the runtime and rendered correctly by
8
- * `util.inspect` ("Caused by: ..."). Subclasses that need a typed `cause`
9
- * field still get it via the platform's own `Error.cause` getter.
6
+ * Forwards the optional `cause` to the native ES2022 `Error` constructor
7
+ * so `error.cause` is wired up by the runtime and rendered correctly by
8
+ * `util.inspect` ("Caused by: ..."). Subclasses that need a typed
9
+ * `cause` field still get it via the platform's own `Error.cause`
10
+ * getter.
11
+ *
12
+ * @group Errors
10
13
  */
11
14
  var SchemaError = class extends Error {
12
15
  /** The schema input that caused the error. */
@@ -21,7 +24,12 @@ var SchemaError = class extends Error {
21
24
  * The adapter failed to convert the input schema to JSON Schema.
22
25
  *
23
26
  * Causes: invalid Zod schema, Zod 3 schema (unsupported), malformed
24
- * JSON Schema, missing OpenAPI ref, unsupported ref format.
27
+ * JSON Schema, missing OpenAPI ref, unsupported ref format,
28
+ * unrepresentable Zod types, conversion bugs, cycles, and duplicate
29
+ * ids. The `kind` field carries the precise classification — see the
30
+ * union declaration below.
31
+ *
32
+ * @group Errors
25
33
  */
26
34
  var SchemaNormalisationError = class extends SchemaError {
27
35
  kind;
@@ -38,9 +46,10 @@ var SchemaNormalisationError = class extends SchemaError {
38
46
  }
39
47
  };
40
48
  /**
41
- * A theme adapter's render function threw during rendering.
49
+ * A theme adapter's render function threw during rendering. The
50
+ * original error is preserved on `cause`.
42
51
  *
43
- * The `cause` is the original error from the render function.
52
+ * @group Errors
44
53
  */
45
54
  var SchemaRenderError = class extends SchemaError {
46
55
  /**
@@ -56,10 +65,11 @@ var SchemaRenderError = class extends SchemaError {
56
65
  }
57
66
  };
58
67
  /**
59
- * A field path couldn't be resolved against the walked schema tree.
68
+ * A field path could not be resolved against the walked schema tree.
69
+ * Produced by `<SchemaField>` when the `path` prop does not match any
70
+ * field in the schema.
60
71
  *
61
- * This is produced by `<SchemaField>` when the `path` prop doesn't
62
- * match any field in the schema.
72
+ * @group Errors
63
73
  */
64
74
  var SchemaFieldError = class extends SchemaError {
65
75
  /** The unresolvable dot-separated path. */
@@ -1,4 +1,4 @@
1
- import { j as WalkedField } from "../types-BTB73MB8.mjs";
1
+ import { j as WalkedField } from "../types-BrYbjC7_.mjs";
2
2
 
3
3
  //#region src/core/fieldOrder.d.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { i as DiagnosticsOptions } from "../diagnostics-Cbwak-ZX.mjs";
1
+ import { i as DiagnosticsOptions } from "../diagnostics-BTrm3O6J.mjs";
2
2
 
3
3
  //#region src/core/formats.d.ts
4
4
  /**
@@ -52,6 +52,12 @@ type FormatValidator = RegExp | ((value: string) => boolean);
52
52
  * directly. Used by the URI safety helpers for mailto address checks.
53
53
  */
54
54
  declare const EMAIL_FORMAT_PATTERN: RegExp;
55
+ /**
56
+ * Map of recognised JSON Schema string `format` values to RegExp
57
+ * patterns. Consumed by `extractStringConstraints` to derive a
58
+ * client-side `formatPattern` for renderers, and by
59
+ * {@link validateFormat} for runtime checks.
60
+ */
55
61
  declare const FORMAT_PATTERNS: Readonly<Record<string, RegExp>>;
56
62
  /**
57
63
  * Validate a string value against format constraints.
@@ -51,6 +51,12 @@ function dateInputType(format) {
51
51
  * directly. Used by the URI safety helpers for mailto address checks.
52
52
  */
53
53
  const EMAIL_FORMAT_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
54
+ /**
55
+ * Map of recognised JSON Schema string `format` values to RegExp
56
+ * patterns. Consumed by `extractStringConstraints` to derive a
57
+ * client-side `formatPattern` for renderers, and by
58
+ * {@link validateFormat} for runtime checks.
59
+ */
54
60
  const FORMAT_PATTERNS = {
55
61
  uuid: /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,
56
62
  email: EMAIL_FORMAT_PATTERN,