schema-components 1.29.0 → 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 (90) hide show
  1. package/README.md +38 -16
  2. package/dist/core/adapter.d.mts +213 -3
  3. package/dist/core/adapter.mjs +1 -1
  4. package/dist/core/constraintHint.d.mts +15 -0
  5. package/dist/core/constraintHint.mjs +24 -0
  6. package/dist/core/constraints.d.mts +2 -2
  7. package/dist/core/constraints.mjs +1 -1
  8. package/dist/core/diagnostics.d.mts +1 -1
  9. package/dist/core/errors.d.mts +1 -1
  10. package/dist/core/fieldOrder.d.mts +1 -1
  11. package/dist/core/formats.d.mts +1 -1
  12. package/dist/core/idPath.d.mts +35 -5
  13. package/dist/core/idPath.mjs +79 -7
  14. package/dist/core/inferValue.d.mts +2 -0
  15. package/dist/core/inferValue.mjs +1 -0
  16. package/dist/core/limits.d.mts +1 -1
  17. package/dist/core/limits.mjs +5 -0
  18. package/dist/core/merge.d.mts +12 -1
  19. package/dist/core/merge.mjs +66 -3
  20. package/dist/core/normalise.d.mts +1 -1
  21. package/dist/core/normalise.mjs +1 -1
  22. package/dist/core/openapi30.mjs +1 -1
  23. package/dist/core/ref.d.mts +1 -1
  24. package/dist/core/refChain.d.mts +3 -4
  25. package/dist/core/refChain.mjs +2 -3
  26. package/dist/core/renderer.d.mts +199 -2
  27. package/dist/core/swagger2.d.mts +1 -1
  28. package/dist/core/swagger2.mjs +1 -1
  29. package/dist/core/typeInference.d.mts +3 -3
  30. package/dist/core/types.d.mts +1 -1
  31. package/dist/core/unionMatch.d.mts +1 -1
  32. package/dist/core/uri.d.mts +12 -4
  33. package/dist/core/uri.mjs +30 -4
  34. package/dist/core/walkBuilders.d.mts +18 -6
  35. package/dist/core/walkBuilders.mjs +3 -1
  36. package/dist/core/walker.d.mts +1 -1
  37. package/dist/core/walker.mjs +5 -0
  38. package/dist/{diagnostics-ByEzkjrA.d.mts → diagnostics-BTrm3O6J.d.mts} +1 -1
  39. package/dist/{errors-D8JndRwI.d.mts → errors-Dki7tji4.d.mts} +1 -1
  40. package/dist/html/a11y.d.mts +3 -7
  41. package/dist/html/a11y.mjs +1 -16
  42. package/dist/html/renderToHtml.d.mts +22 -9
  43. package/dist/html/renderToHtml.mjs +2 -1
  44. package/dist/html/renderToHtmlStream.d.mts +24 -11
  45. package/dist/html/renderToHtmlStream.mjs +2 -1
  46. package/dist/html/renderers.d.mts +2 -33
  47. package/dist/html/renderers.mjs +39 -91
  48. package/dist/html/streamRenderers.d.mts +3 -3
  49. package/dist/html/streamRenderers.mjs +13 -8
  50. package/dist/inferValue-PPXWJpbN.d.mts +77 -0
  51. package/dist/{limits-DswmqWuy.d.mts → limits-x4OiyJxh.d.mts} +5 -0
  52. package/dist/{normalise-Db1xaxgx.mjs → normalise-DB-Xtjmn.mjs} +43 -2
  53. package/dist/openapi/ApiCallbacks.d.mts +1 -1
  54. package/dist/openapi/ApiLinks.d.mts +1 -1
  55. package/dist/openapi/ApiResponseHeaders.d.mts +1 -1
  56. package/dist/openapi/ApiSecurity.d.mts +1 -1
  57. package/dist/openapi/ApiSecurity.mjs +21 -8
  58. package/dist/openapi/bundle.d.mts +31 -0
  59. package/dist/openapi/components.d.mts +41 -10
  60. package/dist/openapi/components.mjs +19 -13
  61. package/dist/openapi/parser.d.mts +13 -13
  62. package/dist/openapi/parser.mjs +12 -12
  63. package/dist/openapi/resolve.d.mts +38 -49
  64. package/dist/openapi/resolve.mjs +62 -56
  65. package/dist/react/SchemaComponent.d.mts +19 -95
  66. package/dist/react/SchemaComponent.mjs +12 -1
  67. package/dist/react/SchemaView.d.mts +11 -7
  68. package/dist/react/SchemaView.mjs +3 -1
  69. package/dist/react/a11y.d.mts +74 -7
  70. package/dist/react/a11y.mjs +67 -6
  71. package/dist/react/fieldPath.d.mts +16 -1
  72. package/dist/react/fieldPath.mjs +25 -1
  73. package/dist/react/fieldShell.d.mts +49 -0
  74. package/dist/react/fieldShell.mjs +37 -0
  75. package/dist/react/headless.d.mts +1 -1
  76. package/dist/react/headlessRenderers.d.mts +2 -2
  77. package/dist/react/headlessRenderers.mjs +123 -54
  78. package/dist/{ref-CPh8rKQ3.d.mts → ref-DdsbekXX.d.mts} +33 -1
  79. package/dist/themes/mantine.d.mts +36 -20
  80. package/dist/themes/mantine.mjs +179 -150
  81. package/dist/themes/mui.d.mts +47 -21
  82. package/dist/themes/mui.mjs +259 -222
  83. package/dist/themes/radix.d.mts +38 -23
  84. package/dist/themes/radix.mjs +208 -180
  85. package/dist/themes/shadcn.d.mts +6 -3
  86. package/dist/themes/shadcn.mjs +93 -93
  87. package/dist/{types-C2Ay1FEh.d.mts → types-BrYbjC7_.d.mts} +7 -0
  88. package/package.json +4 -1
  89. package/dist/adapter-DcWi4XXn.d.mts +0 -223
  90. package/dist/renderer-OaOz-n6-.d.mts +0 -185
@@ -1,5 +1,5 @@
1
- import { i as DiagnosticsOptions } from "../diagnostics-ByEzkjrA.mjs";
2
- import { OpenApiDocument, OperationInfo, ParameterInfo, ResponseInfo, getRequestBody } from "./parser.mjs";
1
+ import { i as DiagnosticsOptions } from "../diagnostics-BTrm3O6J.mjs";
2
+ import { OpenApiDocument, OperationInfo, ParameterInfo, RequestBodyInfo, ResponseInfo } from "./parser.mjs";
3
3
 
4
4
  //#region src/openapi/resolve.d.ts
5
5
  /**
@@ -11,7 +11,7 @@ import { OpenApiDocument, OperationInfo, ParameterInfo, ResponseInfo, getRequest
11
11
  * keywords (`nullable`, `discriminator`, `example`), OpenAPI 3.1.x
12
12
  * `discriminator`, and Swagger 2.0 documents are all converted to
13
13
  * canonical Draft 2020-12 form. The parser and downstream extractors
14
- * (`getRequestBody`, `getResponses`, etc.) then observe schemas in the
14
+ * (`extractRequestBody`, `extractResponses`, etc.) then observe schemas in the
15
15
  * same form `<SchemaComponent>` does, keeping the OpenAPI components on
16
16
  * the same pipeline as the top-level adapter.
17
17
  *
@@ -61,77 +61,66 @@ interface PathItemInfo {
61
61
  /**
62
62
  * Aggregate view of a single OpenAPI operation: the operation itself,
63
63
  * its Path Item Object context, merged parameters, request body, and
64
- * responses. Produced by {@link resolveOperation} /
65
- * {@link resolveOperationFromParsed} for rendering and inspection.
64
+ * responses. Produced by {@link resolveOperation} for rendering and
65
+ * inspection.
66
66
  */
67
67
  interface ResolvedOperation {
68
68
  operation: OperationInfo;
69
69
  pathItem: PathItemInfo;
70
70
  parameters: ParameterInfo[];
71
- requestBody: ReturnType<typeof getRequestBody>;
71
+ requestBody: RequestBodyInfo | undefined;
72
72
  responses: ResponseInfo[];
73
73
  }
74
- /**
75
- * Resolve an operation against an already-parsed document. Throws if
76
- * the operation is not found.
77
- *
78
- * Used by callers that have already obtained a parsed document via
79
- * {@link getParsed} — most importantly the React components, which
80
- * supply `diagnostics` to `getParsed` and must avoid re-running the
81
- * normalisation pipeline (every re-run would emit each diagnostic
82
- * again into the sink).
83
- */
84
- declare function resolveOperationFromParsed(parsed: OpenApiDocument, path: string, method: string, diagnostics?: DiagnosticsOptions): ResolvedOperation;
85
74
  /**
86
75
  * Resolve an operation from an OpenAPI document by path and method.
87
76
  * Throws if the operation is not found.
88
77
  *
89
- * `diagnostics` is forwarded to {@link getParsed} so normalisation
90
- * events surface to the caller's sink.
91
- */
92
- declare function resolveOperation(doc: Record<string, unknown>, path: string, method: string, diagnostics?: DiagnosticsOptions): ResolvedOperation;
93
- /**
94
- * Resolve parameters against an already-parsed document. See
95
- * {@link resolveOperationFromParsed} for the rationale.
96
- */
97
- declare function resolveParametersFromParsed(parsed: OpenApiDocument, path: string, method: string): ParameterInfo[];
98
- /**
99
- * Resolve parameters for an operation. Returns empty array if none.
78
+ * Accepts either a raw document (parsed lazily via {@link getParsed}'s
79
+ * WeakMap cache) or an already-parsed {@link OpenApiDocument}. Callers
80
+ * that have a parsed document at hand can pass it directly to avoid
81
+ * an extra cache lookup; everyone else trusts the cache.
100
82
  *
101
83
  * `diagnostics` is forwarded to {@link getParsed} so normalisation
102
- * events surface to the caller's sink.
103
- */
104
- declare function resolveParameters(doc: Record<string, unknown>, path: string, method: string, diagnostics?: DiagnosticsOptions): ParameterInfo[];
105
- /**
106
- * Resolve a request body against an already-parsed document. See
107
- * {@link resolveOperationFromParsed} for the rationale.
84
+ * events surface to the caller's sink exactly once per `(doc, sink)`
85
+ * pair, no matter how many times this function is called.
108
86
  */
109
- declare function resolveRequestBodyFromParsed(parsed: OpenApiDocument, path: string, method: string): ReturnType<typeof getRequestBody>;
87
+ declare function resolveOperation(doc: Record<string, unknown> | OpenApiDocument, path: string, method: string, diagnostics?: DiagnosticsOptions): ResolvedOperation;
110
88
  /**
111
- * Resolve request body for an operation. Returns undefined if none.
89
+ * Resolve parameters for an operation. Returns an empty array if none.
112
90
  *
113
- * `diagnostics` is forwarded to {@link getParsed} so normalisation
114
- * events surface to the caller's sink.
91
+ * Accepts either a raw document or an already-parsed
92
+ * {@link OpenApiDocument}. `diagnostics` is forwarded to
93
+ * {@link getParsed} so normalisation events surface to the caller's
94
+ * sink.
115
95
  */
116
- declare function resolveRequestBody(doc: Record<string, unknown>, path: string, method: string, diagnostics?: DiagnosticsOptions): ReturnType<typeof getRequestBody>;
96
+ declare function resolveParameters(doc: Record<string, unknown> | OpenApiDocument, path: string, method: string, diagnostics?: DiagnosticsOptions): ParameterInfo[];
117
97
  /**
118
- * Resolve a specific response against an already-parsed document. See
119
- * {@link resolveOperationFromParsed} for the rationale.
98
+ * Resolve the request body for an operation. Returns `undefined` if
99
+ * the operation declares no request body.
100
+ *
101
+ * Accepts either a raw document or an already-parsed
102
+ * {@link OpenApiDocument}. `diagnostics` is forwarded to
103
+ * {@link getParsed} so normalisation events surface to the caller's
104
+ * sink.
120
105
  */
121
- declare function resolveResponseFromParsed(parsed: OpenApiDocument, path: string, method: string, statusCode: string): ResponseInfo;
106
+ declare function resolveRequestBody(doc: Record<string, unknown> | OpenApiDocument, path: string, method: string, diagnostics?: DiagnosticsOptions): RequestBodyInfo | undefined;
122
107
  /**
123
108
  * Resolve a specific response by status code. Throws if not found.
124
109
  *
125
- * `diagnostics` is forwarded to {@link getParsed} so normalisation
126
- * events surface to the caller's sink.
110
+ * Accepts either a raw document or an already-parsed
111
+ * {@link OpenApiDocument}. `diagnostics` is forwarded to
112
+ * {@link getParsed} so normalisation events surface to the caller's
113
+ * sink.
127
114
  */
128
- declare function resolveResponse(doc: Record<string, unknown>, path: string, method: string, statusCode: string, diagnostics?: DiagnosticsOptions): ResponseInfo;
115
+ declare function resolveResponse(doc: Record<string, unknown> | OpenApiDocument, path: string, method: string, statusCode: string, diagnostics?: DiagnosticsOptions): ResponseInfo;
129
116
  /**
130
117
  * Resolve all responses for an operation.
131
118
  *
132
- * `diagnostics` is forwarded to {@link getParsed} so normalisation
133
- * events surface to the caller's sink.
119
+ * Accepts either a raw document or an already-parsed
120
+ * {@link OpenApiDocument}. `diagnostics` is forwarded to
121
+ * {@link getParsed} so normalisation events surface to the caller's
122
+ * sink.
134
123
  */
135
- declare function resolveResponses(doc: Record<string, unknown>, path: string, method: string, diagnostics?: DiagnosticsOptions): ResponseInfo[];
124
+ declare function resolveResponses(doc: Record<string, unknown> | OpenApiDocument, path: string, method: string, diagnostics?: DiagnosticsOptions): ResponseInfo[];
136
125
  //#endregion
137
- export { PathItemInfo, ResolvedOperation, getParsed, resolveOperation, resolveOperationFromParsed, resolveParameters, resolveParametersFromParsed, resolveRequestBody, resolveRequestBodyFromParsed, resolveResponse, resolveResponseFromParsed, resolveResponses, toDoc };
126
+ export { PathItemInfo, ResolvedOperation, getParsed, resolveOperation, resolveParameters, resolveRequestBody, resolveResponse, resolveResponses, toDoc };
@@ -3,9 +3,9 @@ import "../core/limits.mjs";
3
3
  import { emitDiagnostic } from "../core/diagnostics.mjs";
4
4
  import { isPrototypePollutingKey } from "../core/uri.mjs";
5
5
  import { detectOpenApiVersion } from "../core/version.mjs";
6
- import { o as normaliseOpenApiSchemas, r as documentContainsKeyword } from "../normalise-Db1xaxgx.mjs";
6
+ import { o as normaliseOpenApiSchemas, r as documentContainsKeyword } from "../normalise-DB-Xtjmn.mjs";
7
7
  import { resolveRefChain } from "../core/refChain.mjs";
8
- import { getParameters, getRequestBody, getResponses, listAllOperations, parseOpenApiDocument } from "./parser.mjs";
8
+ import { extractParameters, extractRequestBody, extractResponses, listAllOperations, parseOpenApiDocument } from "./parser.mjs";
9
9
  //#region src/openapi/resolve.ts
10
10
  /**
11
11
  * OpenAPI document resolution and caching.
@@ -24,7 +24,7 @@ const docCache = /* @__PURE__ */ new WeakMap();
24
24
  * keywords (`nullable`, `discriminator`, `example`), OpenAPI 3.1.x
25
25
  * `discriminator`, and Swagger 2.0 documents are all converted to
26
26
  * canonical Draft 2020-12 form. The parser and downstream extractors
27
- * (`getRequestBody`, `getResponses`, etc.) then observe schemas in the
27
+ * (`extractRequestBody`, `extractResponses`, etc.) then observe schemas in the
28
28
  * same form `<SchemaComponent>` does, keeping the OpenAPI components on
29
29
  * the same pipeline as the top-level adapter.
30
30
  *
@@ -314,16 +314,20 @@ function extractPathItemInfo(pathItem) {
314
314
  };
315
315
  }
316
316
  /**
317
- * Resolve an operation against an already-parsed document. Throws if
318
- * the operation is not found.
317
+ * Resolve an operation from an OpenAPI document by path and method.
318
+ * Throws if the operation is not found.
319
319
  *
320
- * Used by callers that have already obtained a parsed document via
321
- * {@link getParsed} most importantly the React components, which
322
- * supply `diagnostics` to `getParsed` and must avoid re-running the
323
- * normalisation pipeline (every re-run would emit each diagnostic
324
- * again into the sink).
320
+ * Accepts either a raw document (parsed lazily via {@link getParsed}'s
321
+ * WeakMap cache) or an already-parsed {@link OpenApiDocument}. Callers
322
+ * that have a parsed document at hand can pass it directly to avoid
323
+ * an extra cache lookup; everyone else trusts the cache.
324
+ *
325
+ * `diagnostics` is forwarded to {@link getParsed} so normalisation
326
+ * events surface to the caller's sink exactly once per `(doc, sink)`
327
+ * pair, no matter how many times this function is called.
325
328
  */
326
- function resolveOperationFromParsed(parsed, path, method, diagnostics) {
329
+ function resolveOperation(doc, path, method, diagnostics) {
330
+ const parsed = ensureParsed(doc, diagnostics);
327
331
  const pathItemNode = lookupPathItemNode(parsed, path, diagnostics);
328
332
  const operation = listAllOperations(parsed).find((op) => op.path === path && op.method === method);
329
333
  if (operation === void 0) throw new Error(`Operation not found: ${method.toUpperCase()} ${path}`);
@@ -331,79 +335,81 @@ function resolveOperationFromParsed(parsed, path, method, diagnostics) {
331
335
  return {
332
336
  operation,
333
337
  pathItem: extractPathItemInfo(pathItemNode),
334
- parameters: getParameters(parsed, path, method),
335
- requestBody: getRequestBody(parsed, path, method),
336
- responses: getResponses(parsed, path, method)
338
+ parameters: extractParameters(parsed, path, method),
339
+ requestBody: extractRequestBody(parsed, path, method),
340
+ responses: extractResponses(parsed, path, method)
337
341
  };
338
342
  }
339
343
  /**
340
- * Resolve an operation from an OpenAPI document by path and method.
341
- * Throws if the operation is not found.
342
- *
343
- * `diagnostics` is forwarded to {@link getParsed} so normalisation
344
- * events surface to the caller's sink.
344
+ * Coerce the first argument of every `resolveX` function either a
345
+ * raw OpenAPI document or an already-parsed {@link OpenApiDocument} —
346
+ * into a parsed view. Distinguishes the two by the presence of the
347
+ * `schemas` map on the parsed shape; falls through to {@link getParsed}
348
+ * for raw documents (which itself short-circuits on a WeakMap cache).
345
349
  */
346
- function resolveOperation(doc, path, method, diagnostics) {
347
- return resolveOperationFromParsed(getParsed(doc, diagnostics), path, method, diagnostics);
350
+ function ensureParsed(doc, diagnostics) {
351
+ if (isParsedDocument(doc)) {
352
+ const cached = docCache.get(doc.doc);
353
+ if (cached !== void 0 && (diagnostics?.diagnostics !== void 0 || diagnostics?.strict === true)) replayCapturedDiagnostics(cached, diagnostics);
354
+ return doc;
355
+ }
356
+ return getParsed(doc, diagnostics);
348
357
  }
349
358
  /**
350
- * Resolve parameters against an already-parsed document. See
351
- * {@link resolveOperationFromParsed} for the rationale.
359
+ * Decide whether `value` is an already-parsed {@link OpenApiDocument}.
360
+ * The parsed shape carries a `schemas` Map alongside the raw `doc`
361
+ * object; a raw OpenAPI document has neither — its keys are
362
+ * `openapi`/`swagger`, `info`, `paths`, etc.
352
363
  */
353
- function resolveParametersFromParsed(parsed, path, method) {
354
- return getParameters(parsed, path, method);
364
+ function isParsedDocument(value) {
365
+ return isObject(value.doc) && value.schemas instanceof Map;
355
366
  }
356
367
  /**
357
- * Resolve parameters for an operation. Returns empty array if none.
368
+ * Resolve parameters for an operation. Returns an empty array if none.
358
369
  *
359
- * `diagnostics` is forwarded to {@link getParsed} so normalisation
360
- * events surface to the caller's sink.
370
+ * Accepts either a raw document or an already-parsed
371
+ * {@link OpenApiDocument}. `diagnostics` is forwarded to
372
+ * {@link getParsed} so normalisation events surface to the caller's
373
+ * sink.
361
374
  */
362
375
  function resolveParameters(doc, path, method, diagnostics) {
363
- return resolveParametersFromParsed(getParsed(doc, diagnostics), path, method);
376
+ return extractParameters(ensureParsed(doc, diagnostics), path, method);
364
377
  }
365
378
  /**
366
- * Resolve a request body against an already-parsed document. See
367
- * {@link resolveOperationFromParsed} for the rationale.
368
- */
369
- function resolveRequestBodyFromParsed(parsed, path, method) {
370
- return getRequestBody(parsed, path, method);
371
- }
372
- /**
373
- * Resolve request body for an operation. Returns undefined if none.
379
+ * Resolve the request body for an operation. Returns `undefined` if
380
+ * the operation declares no request body.
374
381
  *
375
- * `diagnostics` is forwarded to {@link getParsed} so normalisation
376
- * events surface to the caller's sink.
382
+ * Accepts either a raw document or an already-parsed
383
+ * {@link OpenApiDocument}. `diagnostics` is forwarded to
384
+ * {@link getParsed} so normalisation events surface to the caller's
385
+ * sink.
377
386
  */
378
387
  function resolveRequestBody(doc, path, method, diagnostics) {
379
- return resolveRequestBodyFromParsed(getParsed(doc, diagnostics), path, method);
380
- }
381
- /**
382
- * Resolve a specific response against an already-parsed document. See
383
- * {@link resolveOperationFromParsed} for the rationale.
384
- */
385
- function resolveResponseFromParsed(parsed, path, method, statusCode) {
386
- const response = getResponses(parsed, path, method).find((r) => r.statusCode === statusCode);
387
- if (response === void 0) throw new Error(`Response not found: ${statusCode}`);
388
- return response;
388
+ return extractRequestBody(ensureParsed(doc, diagnostics), path, method);
389
389
  }
390
390
  /**
391
391
  * Resolve a specific response by status code. Throws if not found.
392
392
  *
393
- * `diagnostics` is forwarded to {@link getParsed} so normalisation
394
- * events surface to the caller's sink.
393
+ * Accepts either a raw document or an already-parsed
394
+ * {@link OpenApiDocument}. `diagnostics` is forwarded to
395
+ * {@link getParsed} so normalisation events surface to the caller's
396
+ * sink.
395
397
  */
396
398
  function resolveResponse(doc, path, method, statusCode, diagnostics) {
397
- return resolveResponseFromParsed(getParsed(doc, diagnostics), path, method, statusCode);
399
+ const response = extractResponses(ensureParsed(doc, diagnostics), path, method).find((r) => r.statusCode === statusCode);
400
+ if (response === void 0) throw new Error(`Response not found: ${statusCode}`);
401
+ return response;
398
402
  }
399
403
  /**
400
404
  * Resolve all responses for an operation.
401
405
  *
402
- * `diagnostics` is forwarded to {@link getParsed} so normalisation
403
- * events surface to the caller's sink.
406
+ * Accepts either a raw document or an already-parsed
407
+ * {@link OpenApiDocument}. `diagnostics` is forwarded to
408
+ * {@link getParsed} so normalisation events surface to the caller's
409
+ * sink.
404
410
  */
405
411
  function resolveResponses(doc, path, method, diagnostics) {
406
- return getResponses(getParsed(doc, diagnostics), path, method);
412
+ return extractResponses(ensureParsed(doc, diagnostics), path, method);
407
413
  }
408
414
  //#endregion
409
- export { getParsed, resolveOperation, resolveOperationFromParsed, resolveParameters, resolveParametersFromParsed, resolveRequestBody, resolveRequestBodyFromParsed, resolveResponse, resolveResponseFromParsed, resolveResponses, toDoc };
415
+ export { getParsed, resolveOperation, resolveParameters, resolveRequestBody, resolveResponse, resolveResponses, toDoc };
@@ -1,25 +1,15 @@
1
- import { d as FieldOverrides, j as WalkedField, u as FieldOverride, w as SchemaMeta } from "../types-C2Ay1FEh.mjs";
2
- import { t as Diagnostic } from "../diagnostics-ByEzkjrA.mjs";
3
- import { i as SchemaIoSide } from "../adapter-DcWi4XXn.mjs";
4
- import { t as SchemaError } from "../errors-D8JndRwI.mjs";
5
- import { l as RenderProps, r as ComponentResolver } from "../renderer-OaOz-n6-.mjs";
6
- import { FromJSONSchema, FromJSONSchemaMode, IsSwagger2Doc, PathOfType, RejectUnrepresentableZod, ResolveOpenAPIRef, TypeAtPath, __SchemaInferenceFellBack } from "../core/typeInference.mjs";
1
+ import { j as WalkedField, w as SchemaMeta } from "../types-BrYbjC7_.mjs";
2
+ import { t as Diagnostic } from "../diagnostics-BTrm3O6J.mjs";
3
+ import { SchemaIoSide } from "../core/adapter.mjs";
4
+ import { ComponentResolver, RenderProps, WidgetMap } from "../core/renderer.mjs";
5
+ import { t as SchemaError } from "../errors-Dki7tji4.mjs";
6
+ import { FromJSONSchema, PathOfType, RejectUnrepresentableZod } from "../core/typeInference.mjs";
7
+ import { a as InferredValue, i as InferredOutputValue, n as InferSchemaValue, r as InferredInputValue, t as InferFields } from "../inferValue-PPXWJpbN.mjs";
7
8
  import { z } from "zod";
8
9
  import * as _$react_jsx_runtime0 from "react/jsx-runtime";
9
10
  import { ReactNode } from "react";
10
11
 
11
12
  //#region src/react/SchemaComponent.d.ts
12
- /**
13
- * Widget map — maps component hints (from `.meta({ component })`) to render
14
- * functions. Scoped at three levels:
15
- *
16
- * 1. **Per-instance** — `widgets` prop on `<SchemaComponent>`
17
- * 2. **Context-scoped** — `widgets` prop on `<SchemaProvider>`
18
- * 3. **Global** — `registerWidget()` (app-wide defaults)
19
- *
20
- * Resolution order: instance → context → global → resolver → headless.
21
- */
22
- type WidgetMap = ReadonlyMap<string, (props: RenderProps) => unknown>;
23
13
  /**
24
14
  * Provide a theme resolver and scoped widgets to every `<SchemaComponent>`
25
15
  * and `<SchemaView>` rendered inside the subtree.
@@ -58,64 +48,15 @@ declare function SchemaProvider({
58
48
  * or `<SchemaProvider>` instead.
59
49
  */
60
50
  declare function registerWidget(name: string, render: (props: RenderProps) => unknown): void;
61
- type InferFields<T, Ref extends string | undefined> = IsSwagger2Doc<T> extends true ? __SchemaInferenceFellBack : T extends z.ZodType ? FieldOverrides<z.infer<T>> : T extends {
62
- openapi: unknown;
63
- } ? Ref extends string ? FieldOverrides<ResolveOpenAPIRef<T & Record<string, unknown>, Ref>> : Record<string, FieldOverride> : T extends object ? unknown extends FromJSONSchema<T> ? Record<string, FieldOverride> : FieldOverrides<FromJSONSchema<T>> : Record<string, FieldOverride>;
64
- /**
65
- * Infer the data type carried by the schema input.
66
- *
67
- * Mirrors {@link InferFields}'s dispatch order: Zod schema → `z.infer`,
68
- * OpenAPI doc + ref → `ResolveOpenAPIRef`, plain JSON Schema object →
69
- * `FromJSONSchema`, everything else → `unknown`. The `Mode` parameter
70
- * is plumbed through to `FromJSONSchema` / `ResolveOpenAPIRef` so
71
- * `readOnly` / `writeOnly` keywords participate in the inferred
72
- * object shape — `"output"` for the rendered value, `"input"` for the
73
- * `onChange` argument.
74
- *
75
- * When the schema's value type cannot be statically determined (e.g.
76
- * a runtime `Record<string, unknown>` JSON Schema, or an OpenAPI doc
77
- * without a ref), the result falls back to `unknown` so callers can
78
- * still supply arbitrary values.
79
- */
80
- type InferSchemaValue<T, Ref extends string | undefined, Mode extends FromJSONSchemaMode> = IsSwagger2Doc<T> extends true ? __SchemaInferenceFellBack : T extends z.ZodType ? Mode extends "input" ? z.input<T> : z.output<T> : T extends {
81
- openapi: unknown;
82
- } ? Ref extends string ? ResolveOpenAPIRef<T & Record<string, unknown>, Ref, [], Mode> : unknown : T extends object ? FromJSONSchema<T, Record<string, never>, [], Mode> | (unknown extends FromJSONSchema<T> ? unknown : never) extends infer V ? V : unknown : unknown;
83
- /**
84
- * Narrow an inferred value type to the sub-shape at `P`, or return
85
- * the original value type when `P` is `undefined` (no path supplied).
86
- */
87
- type NarrowAtPath<V, P extends string | undefined> = P extends string ? TypeAtPath<V, P> : V;
88
51
  /**
89
- * Public alias mapping a schema input to the rendered value type.
52
+ * Clear every globally registered widget. Intended for test isolation
53
+ * `registerWidget` writes to module-level state and that state otherwise
54
+ * leaks across test cases, making the test suite order-dependent. Tests
55
+ * should call this from an `afterEach` hook.
90
56
  *
91
- * Picks the OUTPUT side (server → client) of every transform / pipe /
92
- * codec. For an `<SchemaComponent io="output">` or `<SchemaView
93
- * io="output">` (both defaults), this is the inferred shape of
94
- * `value` and the parameter of `onChange`.
57
+ * @internal
95
58
  */
96
- type InferredOutputValue<T, Ref extends string | undefined = undefined, P extends string | undefined = undefined> = NarrowAtPath<InferSchemaValue<T, Ref, "output">, P>;
97
- /**
98
- * Companion to {@link InferredOutputValue} for `"input"`-mode shapes.
99
- *
100
- * Picks the INPUT side (client → server) of every transform / pipe /
101
- * codec. Surfaces as the inferred shape of `value` / `onChange` when
102
- * a consumer renders `<SchemaComponent io="input">`. For JSON Schema
103
- * inputs with `readOnly`/`writeOnly` annotations, the INPUT mode
104
- * omits properties marked `readOnly: true`.
105
- */
106
- type InferredInputValue<T, Ref extends string | undefined = undefined, P extends string | undefined = undefined> = NarrowAtPath<InferSchemaValue<T, Ref, "input">, P>;
107
- /**
108
- * Resolve the schema-driven value type for either I/O direction.
109
- *
110
- * Thin convenience over {@link InferredOutputValue} /
111
- * {@link InferredInputValue} so consumers that decide between the
112
- * two at the type level (e.g. a generic wrapper component) can pass
113
- * the chosen direction as a type argument rather than branch on it
114
- * with conditional types. Falls back to `unknown` when the schema's
115
- * value type cannot be statically inferred, identical to the
116
- * underlying helpers.
117
- */
118
- type InferredValue<T, Ref extends string | undefined = undefined, P extends string | undefined = undefined, Mode extends SchemaIoSide = "output"> = NarrowAtPath<InferSchemaValue<T, Ref, Mode>, P>;
59
+ declare function __clearGlobalWidgets(): void;
119
60
  /**
120
61
  * Props accepted by {@link SchemaComponent}.
121
62
  *
@@ -125,7 +66,7 @@ type InferredValue<T, Ref extends string | undefined = undefined, P extends stri
125
66
  *
126
67
  * @group Components
127
68
  */
128
- interface SchemaComponentProps<T = unknown, Ref extends string | undefined = undefined, P extends string | undefined = undefined, Mode extends SchemaIoSide = "output"> {
69
+ interface SchemaComponentProps<T = unknown, Ref extends string | undefined = undefined, Mode extends SchemaIoSide = "output"> {
129
70
  /**
130
71
  * Zod schema, JSON Schema object, or OpenAPI document.
131
72
  *
@@ -139,21 +80,6 @@ interface SchemaComponentProps<T = unknown, Ref extends string | undefined = und
139
80
  schema: RejectUnrepresentableZod<T>;
140
81
  /** For OpenAPI: a ref string like "#/components/schemas/User" or "/users/post". */
141
82
  ref?: Ref;
142
- /**
143
- * Optional dot-separated path used purely for type narrowing.
144
- * When the schema is typed, the path is restricted to the valid
145
- * dot-paths reachable through the schema's inferred value.
146
- *
147
- * RUNTIME CAVEAT: this prop is currently type-level only. The
148
- * render pipeline still operates on the root schema; sub-path
149
- * value resolution is provided by the dedicated `<SchemaField>`
150
- * component, which already implements `resolvePath` /
151
- * `setNestedValue`. The `path` prop here documents intent at the
152
- * type level (and prepares the API surface) so consumers can
153
- * declare narrow typed wrappers without runtime regressions. Use
154
- * `<SchemaField>` when a sub-path render is required at runtime.
155
- */
156
- path?: P;
157
83
  /**
158
84
  * Which side of every transform / pipe / codec to render.
159
85
  *
@@ -178,9 +104,7 @@ interface SchemaComponentProps<T = unknown, Ref extends string | undefined = und
178
104
  /**
179
105
  * Current value to render. Typed against `InferSchemaValue<T,
180
106
  * Ref, Mode>` so the prop tracks the schema's inferred shape for
181
- * the chosen `io` direction. Narrowed further by `P` when a
182
- * `path` is supplied (currently type-level only — see the JSDoc
183
- * on {@link SchemaComponentProps.path}).
107
+ * the chosen `io` direction.
184
108
  *
185
109
  * Falls back to `unknown` when the schema's value type cannot be
186
110
  * statically inferred (runtime `Record<string, unknown>` JSON
@@ -195,7 +119,7 @@ interface SchemaComponentProps<T = unknown, Ref extends string | undefined = und
195
119
  * <SchemaComponent schema={userSchema} value={user} readOnly />
196
120
  * ```
197
121
  */
198
- value?: NarrowAtPath<InferSchemaValue<T, Ref, Mode>, P>;
122
+ value?: InferSchemaValue<T, Ref, Mode>;
199
123
  /**
200
124
  * Called when the value changes (editable fields). The parameter
201
125
  * shares the same shape as {@link SchemaComponentProps.value} so
@@ -205,7 +129,7 @@ interface SchemaComponentProps<T = unknown, Ref extends string | undefined = und
205
129
  * Falls back to `unknown` for schemas whose value type cannot be
206
130
  * statically inferred — see {@link SchemaComponentProps.value}.
207
131
  */
208
- onChange?: (value: NarrowAtPath<InferSchemaValue<T, Ref, Mode>, P>) => void;
132
+ onChange?: (value: InferSchemaValue<T, Ref, Mode>) => void;
209
133
  /** Run schema.safeParse() on change and surface errors via onValidationError. */
210
134
  validate?: boolean;
211
135
  /** Called with the ZodError when validation fails. */
@@ -259,7 +183,7 @@ interface SchemaComponentProps<T = unknown, Ref extends string | undefined = und
259
183
  * <SchemaComponent schema={userSchema} value={user} onChange={setUser} />
260
184
  * ```
261
185
  */
262
- declare function SchemaComponent<T = unknown, Ref extends string | undefined = undefined, P extends string | undefined = undefined, Mode extends SchemaIoSide = "output">(props: SchemaComponentProps<T, Ref, P, Mode>): ReactNode;
186
+ declare function SchemaComponent<T = unknown, Ref extends string | undefined = undefined, Mode extends SchemaIoSide = "output">(props: SchemaComponentProps<T, Ref, Mode>): ReactNode;
263
187
  /**
264
188
  * Append a child path suffix to a parent path. When the suffix is omitted
265
189
  * (e.g. transparent wrappers like union options), the parent path is
@@ -343,4 +267,4 @@ declare function SchemaField<T = unknown, Ref extends string | undefined = undef
343
267
  onValidationError
344
268
  }: SchemaFieldProps<T, Ref, P>): ReactNode;
345
269
  //#endregion
346
- export { InferredInputValue, InferredOutputValue, InferredValue, SchemaComponent, SchemaComponentProps, SchemaField, SchemaFieldProps, SchemaProvider, WidgetMap, joinPath, registerWidget, renderField, sanitisePrefix };
270
+ export { type InferFields, type InferredInputValue, type InferredOutputValue, type InferredValue, SchemaComponent, SchemaComponentProps, SchemaField, SchemaFieldProps, SchemaProvider, __clearGlobalWidgets, joinPath, registerWidget, renderField, sanitisePrefix };
@@ -69,6 +69,17 @@ function registerWidget(name, render) {
69
69
  globalWidgets.set(name, render);
70
70
  }
71
71
  /**
72
+ * Clear every globally registered widget. Intended for test isolation —
73
+ * `registerWidget` writes to module-level state and that state otherwise
74
+ * leaks across test cases, making the test suite order-dependent. Tests
75
+ * should call this from an `afterEach` hook.
76
+ *
77
+ * @internal
78
+ */
79
+ function __clearGlobalWidgets() {
80
+ globalWidgets.clear();
81
+ }
82
+ /**
72
83
  * Render an editable (or read-only) UI from a Zod schema, JSON Schema, or
73
84
  * OpenAPI document.
74
85
  *
@@ -405,4 +416,4 @@ function isCallable(value) {
405
416
  return typeof value === "function";
406
417
  }
407
418
  //#endregion
408
- export { SchemaComponent, SchemaField, SchemaProvider, joinPath, registerWidget, renderField, sanitisePrefix };
419
+ export { SchemaComponent, SchemaField, SchemaProvider, __clearGlobalWidgets, joinPath, registerWidget, renderField, sanitisePrefix };
@@ -1,9 +1,9 @@
1
- import { w as SchemaMeta } from "../types-C2Ay1FEh.mjs";
2
- import { t as Diagnostic } from "../diagnostics-ByEzkjrA.mjs";
3
- import { i as SchemaIoSide } from "../adapter-DcWi4XXn.mjs";
4
- import { r as ComponentResolver } from "../renderer-OaOz-n6-.mjs";
1
+ import { w as SchemaMeta } from "../types-BrYbjC7_.mjs";
2
+ import { t as Diagnostic } from "../diagnostics-BTrm3O6J.mjs";
3
+ import { SchemaIoSide } from "../core/adapter.mjs";
4
+ import { ComponentResolver, WidgetMap } from "../core/renderer.mjs";
5
5
  import { RejectUnrepresentableZod } from "../core/typeInference.mjs";
6
- import { InferredValue, WidgetMap } from "./SchemaComponent.mjs";
6
+ import { a as InferredValue, t as InferFields } from "../inferValue-PPXWJpbN.mjs";
7
7
  import { ReactNode } from "react";
8
8
 
9
9
  //#region src/react/SchemaView.d.ts
@@ -44,8 +44,12 @@ interface SchemaViewProps<T = unknown, Ref extends string | undefined = undefine
44
44
  * schemas where the value type cannot be statically inferred.
45
45
  */
46
46
  value?: InferredValue<T, Ref, undefined, Mode>;
47
- /** Per-field meta overrides. */
48
- fields?: Record<string, unknown>;
47
+ /**
48
+ * Per-field meta overrides — nested object mirroring schema shape.
49
+ * Typed against {@link InferFields} so a typed `schema` prop drives
50
+ * autocomplete on the override map, matching `<SchemaComponent>`.
51
+ */
52
+ fields?: InferFields<T, Ref>;
49
53
  /** Meta overrides applied to the root schema. */
50
54
  meta?: SchemaMeta;
51
55
  /** Convenience: sets description on the root. */
@@ -1,3 +1,4 @@
1
+ import { toRecordOrUndefined } from "../core/guards.mjs";
1
2
  import "../core/limits.mjs";
2
3
  import { SchemaNormalisationError, SchemaRenderError } from "../core/errors.mjs";
3
4
  import { normaliseSchema } from "../core/adapter.mjs";
@@ -84,10 +85,11 @@ function SchemaView({ schema: schemaInput, ref: refInput, io, value, fields, met
84
85
  if (err instanceof SchemaNormalisationError) throw err;
85
86
  throw new SchemaNormalisationError(err instanceof Error ? err.message : "Failed to normalise schema", schemaInput, "unknown");
86
87
  }
88
+ const fieldsRecord = toRecordOrUndefined(fields);
87
89
  const walkOptions = {
88
90
  componentMeta: mergedMeta,
89
91
  rootMeta,
90
- fieldOverrides: fields,
92
+ fieldOverrides: fieldsRecord,
91
93
  rootDocument,
92
94
  ...diagnostics !== void 0 ? { diagnostics } : {}
93
95
  };