@formspec/build 0.1.0-alpha.2 → 0.1.0-alpha.20

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 (177) hide show
  1. package/README.md +120 -0
  2. package/dist/__tests__/alias-chain-propagation.test.d.ts +9 -0
  3. package/dist/__tests__/alias-chain-propagation.test.d.ts.map +1 -0
  4. package/dist/__tests__/chain-dsl-canonicalizer.test.d.ts +2 -0
  5. package/dist/__tests__/chain-dsl-canonicalizer.test.d.ts.map +1 -0
  6. package/dist/__tests__/class-schema.test.d.ts +2 -0
  7. package/dist/__tests__/class-schema.test.d.ts.map +1 -0
  8. package/dist/__tests__/constraint-validator.test.d.ts +2 -0
  9. package/dist/__tests__/constraint-validator.test.d.ts.map +1 -0
  10. package/dist/__tests__/date-extension.integration.test.d.ts +2 -0
  11. package/dist/__tests__/date-extension.integration.test.d.ts.map +1 -0
  12. package/dist/__tests__/extension-api.test.d.ts +2 -0
  13. package/dist/__tests__/extension-api.test.d.ts.map +1 -0
  14. package/dist/__tests__/extension-runtime.integration.test.d.ts +2 -0
  15. package/dist/__tests__/extension-runtime.integration.test.d.ts.map +1 -0
  16. package/dist/__tests__/fixtures/alias-chains.d.ts +37 -0
  17. package/dist/__tests__/fixtures/alias-chains.d.ts.map +1 -0
  18. package/dist/__tests__/fixtures/class-schema-regressions.d.ts +87 -0
  19. package/dist/__tests__/fixtures/class-schema-regressions.d.ts.map +1 -0
  20. package/dist/__tests__/fixtures/edge-cases.d.ts +132 -0
  21. package/dist/__tests__/fixtures/edge-cases.d.ts.map +1 -0
  22. package/dist/__tests__/fixtures/example-a-builtins.d.ts +30 -0
  23. package/dist/__tests__/fixtures/example-a-builtins.d.ts.map +1 -0
  24. package/dist/__tests__/fixtures/example-date-extension.d.ts +12 -0
  25. package/dist/__tests__/fixtures/example-date-extension.d.ts.map +1 -0
  26. package/dist/__tests__/fixtures/example-interface-types.d.ts +102 -0
  27. package/dist/__tests__/fixtures/example-interface-types.d.ts.map +1 -0
  28. package/dist/__tests__/fixtures/example-numeric-extension.d.ts +20 -0
  29. package/dist/__tests__/fixtures/example-numeric-extension.d.ts.map +1 -0
  30. package/dist/__tests__/fixtures/extension-forms.d.ts +7 -0
  31. package/dist/__tests__/fixtures/extension-forms.d.ts.map +1 -0
  32. package/dist/__tests__/fixtures/mixed-authoring-shipping-address.d.ts +31 -0
  33. package/dist/__tests__/fixtures/mixed-authoring-shipping-address.d.ts.map +1 -0
  34. package/dist/__tests__/fixtures/named-primitive-aliases.d.ts +15 -0
  35. package/dist/__tests__/fixtures/named-primitive-aliases.d.ts.map +1 -0
  36. package/dist/__tests__/fixtures/nested-array-path-constraints.d.ts +14 -0
  37. package/dist/__tests__/fixtures/nested-array-path-constraints.d.ts.map +1 -0
  38. package/dist/__tests__/fixtures/sample-forms.d.ts +65 -0
  39. package/dist/__tests__/fixtures/sample-forms.d.ts.map +1 -0
  40. package/dist/__tests__/generate-schemas.test.d.ts +2 -0
  41. package/dist/__tests__/generate-schemas.test.d.ts.map +1 -0
  42. package/dist/__tests__/guards.test.d.ts +2 -0
  43. package/dist/__tests__/guards.test.d.ts.map +1 -0
  44. package/dist/__tests__/ir-analyzer.test.d.ts +11 -0
  45. package/dist/__tests__/ir-analyzer.test.d.ts.map +1 -0
  46. package/dist/__tests__/ir-jsdoc-constraints.test.d.ts +12 -0
  47. package/dist/__tests__/ir-jsdoc-constraints.test.d.ts.map +1 -0
  48. package/dist/__tests__/ir-json-schema-generator.test.d.ts +11 -0
  49. package/dist/__tests__/ir-json-schema-generator.test.d.ts.map +1 -0
  50. package/dist/__tests__/ir-ui-schema-generator.test.d.ts +2 -0
  51. package/dist/__tests__/ir-ui-schema-generator.test.d.ts.map +1 -0
  52. package/dist/__tests__/mixed-authoring.test.d.ts +2 -0
  53. package/dist/__tests__/mixed-authoring.test.d.ts.map +1 -0
  54. package/dist/__tests__/numeric-extension.integration.test.d.ts +2 -0
  55. package/dist/__tests__/numeric-extension.integration.test.d.ts.map +1 -0
  56. package/dist/__tests__/parity/fixtures/address/chain-dsl.d.ts +9 -0
  57. package/dist/__tests__/parity/fixtures/address/chain-dsl.d.ts.map +1 -0
  58. package/dist/__tests__/parity/fixtures/address/expected-ir.d.ts +9 -0
  59. package/dist/__tests__/parity/fixtures/address/expected-ir.d.ts.map +1 -0
  60. package/dist/__tests__/parity/fixtures/address/tsdoc.d.ts +19 -0
  61. package/dist/__tests__/parity/fixtures/address/tsdoc.d.ts.map +1 -0
  62. package/dist/__tests__/parity/fixtures/plan-status/chain-dsl.d.ts +19 -0
  63. package/dist/__tests__/parity/fixtures/plan-status/chain-dsl.d.ts.map +1 -0
  64. package/dist/__tests__/parity/fixtures/plan-status/expected-ir.d.ts +6 -0
  65. package/dist/__tests__/parity/fixtures/plan-status/expected-ir.d.ts.map +1 -0
  66. package/dist/__tests__/parity/fixtures/plan-status/tsdoc.d.ts +17 -0
  67. package/dist/__tests__/parity/fixtures/plan-status/tsdoc.d.ts.map +1 -0
  68. package/dist/__tests__/parity/fixtures/product-config/chain-dsl.d.ts +13 -0
  69. package/dist/__tests__/parity/fixtures/product-config/chain-dsl.d.ts.map +1 -0
  70. package/dist/__tests__/parity/fixtures/product-config/expected-ir.d.ts +9 -0
  71. package/dist/__tests__/parity/fixtures/product-config/expected-ir.d.ts.map +1 -0
  72. package/dist/__tests__/parity/fixtures/product-config/tsdoc.d.ts +28 -0
  73. package/dist/__tests__/parity/fixtures/product-config/tsdoc.d.ts.map +1 -0
  74. package/dist/__tests__/parity/fixtures/usd-cents/chain-dsl.d.ts +9 -0
  75. package/dist/__tests__/parity/fixtures/usd-cents/chain-dsl.d.ts.map +1 -0
  76. package/dist/__tests__/parity/fixtures/usd-cents/expected-ir.d.ts +6 -0
  77. package/dist/__tests__/parity/fixtures/usd-cents/expected-ir.d.ts.map +1 -0
  78. package/dist/__tests__/parity/fixtures/usd-cents/tsdoc.d.ts +19 -0
  79. package/dist/__tests__/parity/fixtures/usd-cents/tsdoc.d.ts.map +1 -0
  80. package/dist/__tests__/parity/fixtures/user-registration/chain-dsl.d.ts +12 -0
  81. package/dist/__tests__/parity/fixtures/user-registration/chain-dsl.d.ts.map +1 -0
  82. package/dist/__tests__/parity/fixtures/user-registration/expected-ir.d.ts +9 -0
  83. package/dist/__tests__/parity/fixtures/user-registration/expected-ir.d.ts.map +1 -0
  84. package/dist/__tests__/parity/fixtures/user-registration/tsdoc.d.ts +19 -0
  85. package/dist/__tests__/parity/fixtures/user-registration/tsdoc.d.ts.map +1 -0
  86. package/dist/__tests__/parity/parity.test.d.ts +18 -0
  87. package/dist/__tests__/parity/parity.test.d.ts.map +1 -0
  88. package/dist/__tests__/parity/utils.d.ts +151 -0
  89. package/dist/__tests__/parity/utils.d.ts.map +1 -0
  90. package/dist/__tests__/path-target-parser.test.d.ts +9 -0
  91. package/dist/__tests__/path-target-parser.test.d.ts.map +1 -0
  92. package/dist/analyzer/class-analyzer.d.ts +100 -0
  93. package/dist/analyzer/class-analyzer.d.ts.map +1 -0
  94. package/dist/analyzer/jsdoc-constraints.d.ts +53 -0
  95. package/dist/analyzer/jsdoc-constraints.d.ts.map +1 -0
  96. package/dist/analyzer/program.d.ts +68 -0
  97. package/dist/analyzer/program.d.ts.map +1 -0
  98. package/dist/analyzer/tsdoc-parser.d.ts +122 -0
  99. package/dist/analyzer/tsdoc-parser.d.ts.map +1 -0
  100. package/dist/browser.cjs +1291 -0
  101. package/dist/browser.cjs.map +1 -0
  102. package/dist/browser.d.ts +73 -0
  103. package/dist/browser.d.ts.map +1 -0
  104. package/dist/browser.js +1242 -0
  105. package/dist/browser.js.map +1 -0
  106. package/dist/build.d.ts +996 -0
  107. package/dist/canonicalize/chain-dsl-canonicalizer.d.ts +18 -0
  108. package/dist/canonicalize/chain-dsl-canonicalizer.d.ts.map +1 -0
  109. package/dist/canonicalize/index.d.ts +8 -0
  110. package/dist/canonicalize/index.d.ts.map +1 -0
  111. package/dist/canonicalize/tsdoc-canonicalizer.d.ts +34 -0
  112. package/dist/canonicalize/tsdoc-canonicalizer.d.ts.map +1 -0
  113. package/dist/cli.cjs +3862 -0
  114. package/dist/cli.cjs.map +1 -0
  115. package/dist/cli.js +3826 -103
  116. package/dist/cli.js.map +1 -1
  117. package/dist/extensions/index.d.ts +8 -0
  118. package/dist/extensions/index.d.ts.map +1 -0
  119. package/dist/extensions/registry.d.ts +79 -0
  120. package/dist/extensions/registry.d.ts.map +1 -0
  121. package/dist/generators/class-schema.d.ts +99 -0
  122. package/dist/generators/class-schema.d.ts.map +1 -0
  123. package/dist/generators/method-schema.d.ts +65 -0
  124. package/dist/generators/method-schema.d.ts.map +1 -0
  125. package/dist/generators/mixed-authoring.d.ts +45 -0
  126. package/dist/generators/mixed-authoring.d.ts.map +1 -0
  127. package/dist/index.cjs +3627 -0
  128. package/dist/index.cjs.map +1 -0
  129. package/dist/index.d.ts +33 -8
  130. package/dist/index.d.ts.map +1 -1
  131. package/dist/index.js +3587 -106
  132. package/dist/index.js.map +1 -1
  133. package/dist/internals.cjs +3371 -0
  134. package/dist/internals.cjs.map +1 -0
  135. package/dist/internals.d.ts +30 -0
  136. package/dist/internals.d.ts.map +1 -0
  137. package/dist/internals.js +3345 -0
  138. package/dist/internals.js.map +1 -0
  139. package/dist/json-schema/generator.d.ts +16 -5
  140. package/dist/json-schema/generator.d.ts.map +1 -1
  141. package/dist/json-schema/ir-generator.d.ts +108 -0
  142. package/dist/json-schema/ir-generator.d.ts.map +1 -0
  143. package/dist/json-schema/schema.d.ts +16 -0
  144. package/dist/json-schema/schema.d.ts.map +1 -0
  145. package/dist/json-schema/types.d.ts +29 -2
  146. package/dist/json-schema/types.d.ts.map +1 -1
  147. package/dist/ui-schema/generator.d.ts +5 -0
  148. package/dist/ui-schema/generator.d.ts.map +1 -1
  149. package/dist/ui-schema/ir-generator.d.ts +53 -0
  150. package/dist/ui-schema/ir-generator.d.ts.map +1 -0
  151. package/dist/ui-schema/schema.d.ts +357 -0
  152. package/dist/ui-schema/schema.d.ts.map +1 -0
  153. package/dist/ui-schema/types.d.ts +8 -73
  154. package/dist/ui-schema/types.d.ts.map +1 -1
  155. package/dist/validate/constraint-validator.d.ts +23 -0
  156. package/dist/validate/constraint-validator.d.ts.map +1 -0
  157. package/dist/validate/index.d.ts +9 -0
  158. package/dist/validate/index.d.ts.map +1 -0
  159. package/package.json +27 -7
  160. package/dist/__tests__/cli.test.js +0 -178
  161. package/dist/__tests__/cli.test.js.map +0 -1
  162. package/dist/__tests__/edge-cases.test.js +0 -217
  163. package/dist/__tests__/edge-cases.test.js.map +0 -1
  164. package/dist/__tests__/generator.test.js +0 -225
  165. package/dist/__tests__/generator.test.js.map +0 -1
  166. package/dist/__tests__/integration.test.js +0 -163
  167. package/dist/__tests__/integration.test.js.map +0 -1
  168. package/dist/__tests__/write-schemas.test.js +0 -196
  169. package/dist/__tests__/write-schemas.test.js.map +0 -1
  170. package/dist/json-schema/generator.js +0 -161
  171. package/dist/json-schema/generator.js.map +0 -1
  172. package/dist/json-schema/types.js +0 -7
  173. package/dist/json-schema/types.js.map +0 -1
  174. package/dist/ui-schema/generator.js +0 -150
  175. package/dist/ui-schema/generator.js.map +0 -1
  176. package/dist/ui-schema/types.js +0 -8
  177. package/dist/ui-schema/types.js.map +0 -1
@@ -1,10 +1,21 @@
1
1
  /**
2
2
  * JSON Schema generator for FormSpec forms.
3
+ *
4
+ * Routes through the canonical IR pipeline: Chain DSL → FormIR → JSON Schema 2020-12.
3
5
  */
4
6
  import type { FormElement, FormSpec } from "@formspec/core";
5
- import type { JSONSchema7 } from "./types.js";
7
+ import { type GenerateJsonSchemaFromIROptions, type JsonSchema2020 } from "./ir-generator.js";
6
8
  /**
7
- * Generates a JSON Schema from a FormSpec.
9
+ * Options for generating JSON Schema from a Chain DSL form.
10
+ *
11
+ * These options are forwarded to the IR-based JSON Schema generator.
12
+ */
13
+ export type GenerateJsonSchemaOptions = GenerateJsonSchemaFromIROptions;
14
+ /**
15
+ * Generates a JSON Schema 2020-12 from a FormSpec.
16
+ *
17
+ * All generation routes through the canonical IR. The chain DSL is first
18
+ * canonicalized to a FormIR, then the IR-based generator produces the schema.
8
19
  *
9
20
  * @example
10
21
  * ```typescript
@@ -15,7 +26,7 @@ import type { JSONSchema7 } from "./types.js";
15
26
  *
16
27
  * const schema = generateJsonSchema(form);
17
28
  * // {
18
- * // $schema: "https://json-schema.org/draft-07/schema#",
29
+ * // $schema: "https://json-schema.org/draft/2020-12/schema",
19
30
  * // type: "object",
20
31
  * // properties: {
21
32
  * // name: { type: "string", title: "Name" },
@@ -26,7 +37,7 @@ import type { JSONSchema7 } from "./types.js";
26
37
  * ```
27
38
  *
28
39
  * @param form - The FormSpec to convert
29
- * @returns A JSON Schema object
40
+ * @returns A JSON Schema 2020-12 object
30
41
  */
31
- export declare function generateJsonSchema<E extends readonly FormElement[]>(form: FormSpec<E>): JSONSchema7;
42
+ export declare function generateJsonSchema<E extends readonly FormElement[]>(form: FormSpec<E>, options?: GenerateJsonSchemaOptions): JsonSchema2020;
32
43
  //# sourceMappingURL=generator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/json-schema/generator.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,QAAQ,EAMT,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AA4J9C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,SAAS,WAAW,EAAE,EACjE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,GAChB,WAAW,CAYb"}
1
+ {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/json-schema/generator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE5D,OAAO,EAEL,KAAK,+BAA+B,EACpC,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAC;AAE3B;;;;GAIG;AACH,MAAM,MAAM,yBAAyB,GAAG,+BAA+B,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,SAAS,WAAW,EAAE,EACjE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,EACjB,OAAO,CAAC,EAAE,yBAAyB,GAClC,cAAc,CAGhB"}
@@ -0,0 +1,108 @@
1
+ /**
2
+ * JSON Schema 2020-12 generator that consumes the canonical FormIR.
3
+ *
4
+ * This generator is a pure function of the IR. It never consults the TypeScript
5
+ * AST or surface syntax directly — only the IR (per the JSON Schema vocabulary spec §1.2).
6
+ *
7
+ * @see https://json-schema.org/draft/2020-12/schema
8
+ * @see https://json-schema.org/draft/2020-12/schema
9
+ */
10
+ import type { FormIR, JsonValue } from "@formspec/core";
11
+ import type { ExtensionRegistry } from "../extensions/index.js";
12
+ /**
13
+ * A JSON Schema 2020-12 document, sub-schema, or keyword collection.
14
+ *
15
+ * This interface covers the subset of JSON Schema 2020-12 that this generator
16
+ * emits, plus an index signature for custom `x-formspec-*` extension keywords.
17
+ */
18
+ export interface JsonSchema2020 {
19
+ $schema?: string;
20
+ $ref?: string;
21
+ $defs?: Record<string, JsonSchema2020>;
22
+ type?: string;
23
+ properties?: Record<string, JsonSchema2020>;
24
+ required?: string[];
25
+ items?: JsonSchema2020;
26
+ additionalProperties?: boolean | JsonSchema2020;
27
+ enum?: readonly (string | number)[];
28
+ const?: JsonValue;
29
+ allOf?: readonly JsonSchema2020[];
30
+ oneOf?: readonly JsonSchema2020[];
31
+ anyOf?: readonly JsonSchema2020[];
32
+ minimum?: number;
33
+ maximum?: number;
34
+ exclusiveMinimum?: number;
35
+ exclusiveMaximum?: number;
36
+ multipleOf?: number;
37
+ minLength?: number;
38
+ maxLength?: number;
39
+ minItems?: number;
40
+ maxItems?: number;
41
+ pattern?: string;
42
+ uniqueItems?: boolean;
43
+ format?: string;
44
+ title?: string;
45
+ description?: string;
46
+ default?: unknown;
47
+ deprecated?: boolean;
48
+ [key: `x-${string}`]: unknown;
49
+ }
50
+ /**
51
+ * Options for generating JSON Schema from a canonical FormIR.
52
+ */
53
+ export interface GenerateJsonSchemaFromIROptions {
54
+ /**
55
+ * Registry used to resolve custom types, constraints, and annotations.
56
+ *
57
+ * JSON Schema generation throws when custom IR nodes are present without a
58
+ * matching registration in this registry.
59
+ */
60
+ readonly extensionRegistry?: ExtensionRegistry | undefined;
61
+ /**
62
+ * Vendor prefix passed to extension `toJsonSchema` hooks.
63
+ * @defaultValue "x-formspec"
64
+ */
65
+ readonly vendorPrefix?: string | undefined;
66
+ }
67
+ /**
68
+ * Generates a JSON Schema 2020-12 object from a canonical FormIR.
69
+ *
70
+ * Groups and conditionals are flattened — they influence UI layout but do not
71
+ * affect the data schema. All fields appear at the level they would occupy in
72
+ * the output data.
73
+ *
74
+ * Named types in the `typeRegistry` are emitted as `$defs` entries and
75
+ * referenced via `$ref` (per PP7 — high-fidelity output).
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * import { canonicalizeDSL } from "./canonicalize/index.js";
80
+ * import { generateJsonSchemaFromIR } from "./json-schema/ir-generator.js";
81
+ * import { formspec, field } from "@formspec/dsl";
82
+ *
83
+ * const form = formspec(
84
+ * field.text("name", { label: "Name", required: true }),
85
+ * field.number("age", { min: 0 }),
86
+ * );
87
+ * const ir = canonicalizeDSL(form);
88
+ * const schema = generateJsonSchemaFromIR(ir);
89
+ * // {
90
+ * // $schema: "https://json-schema.org/draft/2020-12/schema",
91
+ * // type: "object",
92
+ * // properties: {
93
+ * // name: { type: "string", title: "Name" },
94
+ * // age: { type: "number", minimum: 0 }
95
+ * // },
96
+ * // required: ["name"]
97
+ * // }
98
+ * ```
99
+ *
100
+ * Advanced API — most consumers should use `generateJsonSchema()` or
101
+ * `buildFormSchemas()`, which canonicalize form definitions automatically.
102
+ * Callers of this function are responsible for providing pre-canonicalized IR.
103
+ *
104
+ * @param ir - The canonical FormIR produced by a canonicalizer
105
+ * @returns A plain JSON-serializable JSON Schema 2020-12 object
106
+ */
107
+ export declare function generateJsonSchemaFromIR(ir: FormIR, options?: GenerateJsonSchemaFromIROptions): JsonSchema2020;
108
+ //# sourceMappingURL=ir-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ir-generator.d.ts","sourceRoot":"","sources":["../../src/json-schema/ir-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,MAAM,EAgBN,SAAS,EACV,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAMhE;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACvC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC5C,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,oBAAoB,CAAC,EAAE,OAAO,GAAG,cAAc,CAAC;IAChD,IAAI,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IACpC,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,KAAK,CAAC,EAAE,SAAS,cAAc,EAAE,CAAC;IAClC,KAAK,CAAC,EAAE,SAAS,cAAc,EAAE,CAAC;IAClC,KAAK,CAAC,EAAE,SAAS,cAAc,EAAE,CAAC;IAElC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;IAGrB,CAAC,GAAG,EAAE,KAAK,MAAM,EAAE,GAAG,OAAO,CAAC;CAC/B;AAqBD;;GAEG;AACH,MAAM,WAAW,+BAA+B;IAC9C;;;;;OAKG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAC3D;;;OAGG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5C;AAqBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,wBAAwB,CACtC,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,+BAA+B,GACxC,cAAc,CAwChB"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Zod schemas for JSON Schema output validation.
3
+ *
4
+ * These schemas cover the subset of JSON Schema that FormSpec generates,
5
+ * plus the FormSpec-specific `x-formspec-*` extension properties.
6
+ *
7
+ * @see https://json-schema.org/draft/2020-12/schema
8
+ */
9
+ import { z } from "zod";
10
+ import type { JSONSchema7 } from "./types.js";
11
+ /**
12
+ * Zod schema for JSON Schema primitive type strings.
13
+ */
14
+ export declare const jsonSchemaTypeSchema: z.ZodEnum<["string", "number", "integer", "boolean", "object", "array", "null"]>;
15
+ export declare const jsonSchema7Schema: z.ZodType<JSONSchema7>;
16
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/json-schema/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAM9C;;GAEG;AACH,eAAO,MAAM,oBAAoB,kFAQ/B,CAAC;AAeH,eAAO,MAAM,iBAAiB,EAAE,CAAC,CAAC,OAAO,CAAC,WAAW,CAoEpD,CAAC"}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * JSON Schema Draft-07 type definitions.
2
+ * JSON Schema type definitions.
3
3
  *
4
4
  * These types are a subset of JSON Schema sufficient for form generation.
5
5
  */
@@ -8,7 +8,7 @@
8
8
  */
9
9
  export type JSONSchemaType = "string" | "number" | "integer" | "boolean" | "object" | "array" | "null";
10
10
  /**
11
- * A JSON Schema definition (draft-07 subset).
11
+ * A JSON Schema definition (legacy subset used by Zod validator and types.ts).
12
12
  */
13
13
  export interface JSONSchema7 {
14
14
  $schema?: string;
@@ -16,6 +16,7 @@ export interface JSONSchema7 {
16
16
  $ref?: string;
17
17
  title?: string;
18
18
  description?: string;
19
+ deprecated?: boolean;
19
20
  type?: JSONSchemaType | JSONSchemaType[];
20
21
  minLength?: number;
21
22
  maxLength?: number;
@@ -57,4 +58,30 @@ export interface JSONSchema7 {
57
58
  */
58
59
  "x-formspec-schemaSource"?: string;
59
60
  }
61
+ /** Extension properties for custom FormSpec constraint tags. */
62
+ export type FormSpecSchemaExtensions = Record<`x-formspec-${string}`, unknown>;
63
+ /** JSON Schema with FormSpec extension properties for arbitrary x-formspec-* keys. */
64
+ export type ExtendedJSONSchema7 = JSONSchema7 & FormSpecSchemaExtensions;
65
+ /**
66
+ * Sets a FormSpec extension property on a JSON Schema node.
67
+ *
68
+ * Use this to safely add `x-formspec-*` properties to any schema,
69
+ * including nested schemas typed as `JSONSchema7` (which don't carry
70
+ * the extension index signature).
71
+ *
72
+ * @param schema - Any JSON Schema node
73
+ * @param key - Extension key (must start with `x-formspec-`)
74
+ * @param value - Extension value
75
+ */
76
+ export declare function setSchemaExtension(schema: object, key: `x-formspec-${string}`, value: unknown): void;
77
+ /**
78
+ * Reads a FormSpec extension property from a JSON Schema node.
79
+ *
80
+ * Accepts any schema object — `JSONSchema7`, `JsonSchema2020`, `ExtendedJSONSchema7`, etc.
81
+ *
82
+ * @param schema - Any JSON Schema node
83
+ * @param key - Extension key (must start with `x-formspec-`)
84
+ * @returns The extension value, or `undefined` if not present
85
+ */
86
+ export declare function getSchemaExtension(schema: object, key: `x-formspec-${string}`): unknown;
60
87
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/json-schema/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,SAAS,GACT,QAAQ,GACR,OAAO,GACP,MAAM,CAAC;AAEX;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IAGd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IAGrB,IAAI,CAAC,EAAE,cAAc,GAAG,cAAc,EAAE,CAAC;IAGzC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IAGjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,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GlB,EAAE,CAAC,EAAE,WAAW,CAAC;IACjB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,IAAI,CAAC,EAAE,WAAW,CAAC;IAGnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAGhB,OAAO,CAAC,EAAE,OAAO,CAAC;IAMlB;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B;;;OAGG;IACH,mBAAmB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAExC;;;OAGG;IACH,yBAAyB,CAAC,EAAE,MAAM,CAAC;CACpC;AAED,gEAAgE;AAChE,MAAM,MAAM,wBAAwB,GAAG,MAAM,CAAC,cAAc,MAAM,EAAE,EAAE,OAAO,CAAC,CAAC;AAE/E,sFAAsF;AACtF,MAAM,MAAM,mBAAmB,GAAG,WAAW,GAAG,wBAAwB,CAAC;AAEzE;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,cAAc,MAAM,EAAE,EAC3B,KAAK,EAAE,OAAO,GACb,IAAI,CAEN;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,cAAc,MAAM,EAAE,GAAG,OAAO,CAEvF"}
@@ -1,11 +1,16 @@
1
1
  /**
2
2
  * JSON Forms UI Schema generator for FormSpec forms.
3
+ *
4
+ * Routes through the canonical IR pipeline: Chain DSL → FormIR → UI Schema.
3
5
  */
4
6
  import type { FormElement, FormSpec } from "@formspec/core";
5
7
  import type { UISchema } from "./types.js";
6
8
  /**
7
9
  * Generates a JSON Forms UI Schema from a FormSpec.
8
10
  *
11
+ * All generation routes through the canonical IR. The chain DSL is first
12
+ * canonicalized to a FormIR, then the IR-based generator produces the schema.
13
+ *
9
14
  * @example
10
15
  * ```typescript
11
16
  * const form = formspec(
@@ -1 +1 @@
1
- {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/ui-schema/generator.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,QAAQ,EAGT,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAEV,QAAQ,EAIT,MAAM,YAAY,CAAC;AA2HpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,SAAS,WAAW,EAAE,EAC/D,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,GAChB,QAAQ,CAKV"}
1
+ {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/ui-schema/generator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,SAAS,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,CAG9F"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * JSON Forms UI Schema generator that operates on the canonical FormIR.
3
+ *
4
+ * This generator consumes the IR produced by the Canonicalize phase and
5
+ * produces a JSON Forms UI Schema. All downstream UI Schema generation
6
+ * should use this module for UI Schema generation.
7
+ */
8
+ import type { FormIR } from "@formspec/core";
9
+ import type { UISchema } from "./types.js";
10
+ /**
11
+ * Generates a JSON Forms UI Schema from a canonical `FormIR`.
12
+ *
13
+ * Mapping rules:
14
+ * - `FieldNode` → `ControlElement` with `scope: "#/properties/<name>"`
15
+ * - `displayName` annotation → `label` on the `ControlElement`
16
+ * - `GroupLayoutNode` → `GroupLayout` with recursively converted `elements`
17
+ * - `ConditionalLayoutNode` → children flattened with a `SHOW` rule
18
+ * - Nested conditionals → combined `allOf` rule
19
+ * - Root wrapper is always `{ type: "VerticalLayout", elements: [...] }`
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const ir = canonicalizeDSL(
24
+ * formspec(
25
+ * group("Customer", field.text("name", { label: "Name" })),
26
+ * when(is("status", "draft"), field.text("notes", { label: "Notes" })),
27
+ * )
28
+ * );
29
+ *
30
+ * const uiSchema = generateUiSchemaFromIR(ir);
31
+ * // {
32
+ * // type: "VerticalLayout",
33
+ * // elements: [
34
+ * // {
35
+ * // type: "Group",
36
+ * // label: "Customer",
37
+ * // elements: [{ type: "Control", scope: "#/properties/name", label: "Name" }]
38
+ * // },
39
+ * // {
40
+ * // type: "Control",
41
+ * // scope: "#/properties/notes",
42
+ * // label: "Notes",
43
+ * // rule: { effect: "SHOW", condition: { scope: "#/properties/status", schema: { const: "draft" } } }
44
+ * // }
45
+ * // ]
46
+ * // }
47
+ * ```
48
+ *
49
+ * @param ir - The canonical FormIR produced by the Canonicalize phase
50
+ * @returns A validated JSON Forms UI Schema
51
+ */
52
+ export declare function generateUiSchemaFromIR(ir: FormIR): UISchema;
53
+ //# sourceMappingURL=ir-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ir-generator.d.ts","sourceRoot":"","sources":["../../src/ui-schema/ir-generator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,EAA6C,MAAM,gBAAgB,CAAC;AACxF,OAAO,KAAK,EACV,QAAQ,EAMT,MAAM,YAAY,CAAC;AAuLpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,CAO3D"}