@formspec/build 0.1.0-alpha.10 → 0.1.0-alpha.12

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 (210) hide show
  1. package/README.md +51 -15
  2. package/dist/__tests__/chain-dsl-canonicalizer.test.d.ts +2 -0
  3. package/dist/__tests__/chain-dsl-canonicalizer.test.d.ts.map +1 -0
  4. package/dist/__tests__/constraint-validator.test.d.ts +2 -0
  5. package/dist/__tests__/constraint-validator.test.d.ts.map +1 -0
  6. package/dist/__tests__/extension-api.test.d.ts +2 -0
  7. package/dist/__tests__/extension-api.test.d.ts.map +1 -0
  8. package/dist/__tests__/fixtures/example-a-builtins.d.ts +18 -0
  9. package/dist/__tests__/fixtures/example-a-builtins.d.ts.map +1 -1
  10. package/dist/__tests__/ir-analyzer.test.d.ts +11 -0
  11. package/dist/__tests__/ir-analyzer.test.d.ts.map +1 -0
  12. package/dist/__tests__/ir-jsdoc-constraints.test.d.ts +12 -0
  13. package/dist/__tests__/ir-jsdoc-constraints.test.d.ts.map +1 -0
  14. package/dist/__tests__/ir-json-schema-generator.test.d.ts +11 -0
  15. package/dist/__tests__/ir-json-schema-generator.test.d.ts.map +1 -0
  16. package/dist/__tests__/ir-ui-schema-generator.test.d.ts +2 -0
  17. package/dist/__tests__/ir-ui-schema-generator.test.d.ts.map +1 -0
  18. package/dist/__tests__/jsdoc-constraints.test.d.ts +4 -4
  19. package/dist/__tests__/parity/fixtures/address/chain-dsl.d.ts +9 -0
  20. package/dist/__tests__/parity/fixtures/address/chain-dsl.d.ts.map +1 -0
  21. package/dist/__tests__/parity/fixtures/address/expected-ir.d.ts +9 -0
  22. package/dist/__tests__/parity/fixtures/address/expected-ir.d.ts.map +1 -0
  23. package/dist/__tests__/parity/fixtures/address/tsdoc.d.ts +19 -0
  24. package/dist/__tests__/parity/fixtures/address/tsdoc.d.ts.map +1 -0
  25. package/dist/__tests__/parity/fixtures/product-config/chain-dsl.d.ts +13 -0
  26. package/dist/__tests__/parity/fixtures/product-config/chain-dsl.d.ts.map +1 -0
  27. package/dist/__tests__/parity/fixtures/product-config/expected-ir.d.ts +9 -0
  28. package/dist/__tests__/parity/fixtures/product-config/expected-ir.d.ts.map +1 -0
  29. package/dist/__tests__/parity/fixtures/product-config/tsdoc.d.ts +28 -0
  30. package/dist/__tests__/parity/fixtures/product-config/tsdoc.d.ts.map +1 -0
  31. package/dist/__tests__/parity/fixtures/user-registration/chain-dsl.d.ts +12 -0
  32. package/dist/__tests__/parity/fixtures/user-registration/chain-dsl.d.ts.map +1 -0
  33. package/dist/__tests__/parity/fixtures/user-registration/expected-ir.d.ts +9 -0
  34. package/dist/__tests__/parity/fixtures/user-registration/expected-ir.d.ts.map +1 -0
  35. package/dist/__tests__/parity/fixtures/user-registration/tsdoc.d.ts +19 -0
  36. package/dist/__tests__/parity/fixtures/user-registration/tsdoc.d.ts.map +1 -0
  37. package/dist/__tests__/parity/parity.test.d.ts +14 -0
  38. package/dist/__tests__/parity/parity.test.d.ts.map +1 -0
  39. package/dist/__tests__/parity/utils.d.ts +139 -0
  40. package/dist/__tests__/parity/utils.d.ts.map +1 -0
  41. package/dist/analyzer/class-analyzer.d.ts +54 -99
  42. package/dist/analyzer/class-analyzer.d.ts.map +1 -1
  43. package/dist/analyzer/jsdoc-constraints.d.ts +78 -30
  44. package/dist/analyzer/jsdoc-constraints.d.ts.map +1 -1
  45. package/dist/analyzer/tsdoc-parser.d.ts +61 -0
  46. package/dist/analyzer/tsdoc-parser.d.ts.map +1 -0
  47. package/dist/browser.cjs +1200 -0
  48. package/dist/browser.cjs.map +1 -0
  49. package/dist/browser.d.ts +12 -6
  50. package/dist/browser.d.ts.map +1 -1
  51. package/dist/browser.js +1147 -44
  52. package/dist/browser.js.map +1 -1
  53. package/dist/build.d.ts +385 -160
  54. package/dist/canonicalize/chain-dsl-canonicalizer.d.ts +18 -0
  55. package/dist/canonicalize/chain-dsl-canonicalizer.d.ts.map +1 -0
  56. package/dist/canonicalize/index.d.ts +8 -0
  57. package/dist/canonicalize/index.d.ts.map +1 -0
  58. package/dist/canonicalize/tsdoc-canonicalizer.d.ts +34 -0
  59. package/dist/canonicalize/tsdoc-canonicalizer.d.ts.map +1 -0
  60. package/dist/cli.cjs +2028 -0
  61. package/dist/cli.cjs.map +1 -0
  62. package/dist/cli.js +1978 -101
  63. package/dist/cli.js.map +1 -1
  64. package/dist/extensions/index.d.ts +8 -0
  65. package/dist/extensions/index.d.ts.map +1 -0
  66. package/dist/extensions/registry.d.ts +55 -0
  67. package/dist/extensions/registry.d.ts.map +1 -0
  68. package/dist/generators/class-schema.d.ts +28 -47
  69. package/dist/generators/class-schema.d.ts.map +1 -1
  70. package/dist/generators/method-schema.d.ts +6 -8
  71. package/dist/generators/method-schema.d.ts.map +1 -1
  72. package/dist/index.cjs +1832 -0
  73. package/dist/index.cjs.map +1 -0
  74. package/dist/index.d.ts +8 -8
  75. package/dist/index.d.ts.map +1 -1
  76. package/dist/index.js +1779 -114
  77. package/dist/index.js.map +1 -1
  78. package/dist/internals.cjs +2125 -0
  79. package/dist/internals.cjs.map +1 -0
  80. package/dist/internals.d.ts +12 -2
  81. package/dist/internals.d.ts.map +1 -1
  82. package/dist/internals.js +2084 -21
  83. package/dist/internals.js.map +1 -1
  84. package/dist/json-schema/generator.d.ts +10 -5
  85. package/dist/json-schema/generator.d.ts.map +1 -1
  86. package/dist/json-schema/ir-generator.d.ts +84 -0
  87. package/dist/json-schema/ir-generator.d.ts.map +1 -0
  88. package/dist/json-schema/schema.d.ts +16 -0
  89. package/dist/json-schema/schema.d.ts.map +1 -0
  90. package/dist/json-schema/types.d.ts +5 -6
  91. package/dist/json-schema/types.d.ts.map +1 -1
  92. package/dist/ui-schema/generator.d.ts +5 -0
  93. package/dist/ui-schema/generator.d.ts.map +1 -1
  94. package/dist/ui-schema/ir-generator.d.ts +53 -0
  95. package/dist/ui-schema/ir-generator.d.ts.map +1 -0
  96. package/dist/ui-schema/schema.d.ts +357 -0
  97. package/dist/ui-schema/schema.d.ts.map +1 -0
  98. package/dist/ui-schema/types.d.ts +8 -73
  99. package/dist/ui-schema/types.d.ts.map +1 -1
  100. package/dist/validate/constraint-validator.d.ts +66 -0
  101. package/dist/validate/constraint-validator.d.ts.map +1 -0
  102. package/dist/validate/index.d.ts +9 -0
  103. package/dist/validate/index.d.ts.map +1 -0
  104. package/package.json +15 -9
  105. package/dist/__tests__/analyzer-edge-cases.test.d.ts +0 -13
  106. package/dist/__tests__/analyzer-edge-cases.test.d.ts.map +0 -1
  107. package/dist/__tests__/analyzer-edge-cases.test.js +0 -376
  108. package/dist/__tests__/analyzer-edge-cases.test.js.map +0 -1
  109. package/dist/__tests__/analyzer.test.d.ts +0 -5
  110. package/dist/__tests__/analyzer.test.d.ts.map +0 -1
  111. package/dist/__tests__/analyzer.test.js +0 -190
  112. package/dist/__tests__/analyzer.test.js.map +0 -1
  113. package/dist/__tests__/cli.test.js +0 -178
  114. package/dist/__tests__/cli.test.js.map +0 -1
  115. package/dist/__tests__/codegen.test.d.ts +0 -5
  116. package/dist/__tests__/codegen.test.d.ts.map +0 -1
  117. package/dist/__tests__/codegen.test.js +0 -506
  118. package/dist/__tests__/codegen.test.js.map +0 -1
  119. package/dist/__tests__/decorator-pipeline.test.d.ts +0 -11
  120. package/dist/__tests__/decorator-pipeline.test.d.ts.map +0 -1
  121. package/dist/__tests__/decorator-pipeline.test.js +0 -460
  122. package/dist/__tests__/decorator-pipeline.test.js.map +0 -1
  123. package/dist/__tests__/edge-cases.test.js +0 -215
  124. package/dist/__tests__/edge-cases.test.js.map +0 -1
  125. package/dist/__tests__/fixtures/edge-cases.js +0 -137
  126. package/dist/__tests__/fixtures/edge-cases.js.map +0 -1
  127. package/dist/__tests__/fixtures/example-a-builtins.js +0 -100
  128. package/dist/__tests__/fixtures/example-a-builtins.js.map +0 -1
  129. package/dist/__tests__/fixtures/example-b-decorators.d.ts +0 -5
  130. package/dist/__tests__/fixtures/example-b-decorators.d.ts.map +0 -1
  131. package/dist/__tests__/fixtures/example-b-decorators.js +0 -5
  132. package/dist/__tests__/fixtures/example-b-decorators.js.map +0 -1
  133. package/dist/__tests__/fixtures/example-b-extended.d.ts +0 -5
  134. package/dist/__tests__/fixtures/example-b-extended.d.ts.map +0 -1
  135. package/dist/__tests__/fixtures/example-b-extended.js +0 -60
  136. package/dist/__tests__/fixtures/example-b-extended.js.map +0 -1
  137. package/dist/__tests__/fixtures/example-c-custom.d.ts +0 -5
  138. package/dist/__tests__/fixtures/example-c-custom.d.ts.map +0 -1
  139. package/dist/__tests__/fixtures/example-c-custom.js +0 -61
  140. package/dist/__tests__/fixtures/example-c-custom.js.map +0 -1
  141. package/dist/__tests__/fixtures/example-c-decorators.d.ts +0 -5
  142. package/dist/__tests__/fixtures/example-c-decorators.d.ts.map +0 -1
  143. package/dist/__tests__/fixtures/example-c-decorators.js +0 -4
  144. package/dist/__tests__/fixtures/example-c-decorators.js.map +0 -1
  145. package/dist/__tests__/fixtures/example-d-mixed-decorators.d.ts +0 -6
  146. package/dist/__tests__/fixtures/example-d-mixed-decorators.d.ts.map +0 -1
  147. package/dist/__tests__/fixtures/example-d-mixed-decorators.js +0 -75
  148. package/dist/__tests__/fixtures/example-d-mixed-decorators.js.map +0 -1
  149. package/dist/__tests__/fixtures/example-e-decorators.d.ts +0 -11
  150. package/dist/__tests__/fixtures/example-e-decorators.d.ts.map +0 -1
  151. package/dist/__tests__/fixtures/example-e-decorators.js +0 -10
  152. package/dist/__tests__/fixtures/example-e-decorators.js.map +0 -1
  153. package/dist/__tests__/fixtures/example-e-no-namespace.d.ts +0 -5
  154. package/dist/__tests__/fixtures/example-e-no-namespace.d.ts.map +0 -1
  155. package/dist/__tests__/fixtures/example-e-no-namespace.js +0 -61
  156. package/dist/__tests__/fixtures/example-e-no-namespace.js.map +0 -1
  157. package/dist/__tests__/fixtures/example-interface-types.js +0 -8
  158. package/dist/__tests__/fixtures/example-interface-types.js.map +0 -1
  159. package/dist/__tests__/fixtures/example-jsdoc-constraints.d.ts +0 -16
  160. package/dist/__tests__/fixtures/example-jsdoc-constraints.d.ts.map +0 -1
  161. package/dist/__tests__/fixtures/example-jsdoc-constraints.js +0 -98
  162. package/dist/__tests__/fixtures/example-jsdoc-constraints.js.map +0 -1
  163. package/dist/__tests__/fixtures/example-nested-class.d.ts +0 -45
  164. package/dist/__tests__/fixtures/example-nested-class.d.ts.map +0 -1
  165. package/dist/__tests__/fixtures/example-nested-class.js +0 -248
  166. package/dist/__tests__/fixtures/example-nested-class.js.map +0 -1
  167. package/dist/__tests__/fixtures/sample-forms.js +0 -78
  168. package/dist/__tests__/fixtures/sample-forms.js.map +0 -1
  169. package/dist/__tests__/generator.test.js +0 -234
  170. package/dist/__tests__/generator.test.js.map +0 -1
  171. package/dist/__tests__/integration.test.js +0 -161
  172. package/dist/__tests__/integration.test.js.map +0 -1
  173. package/dist/__tests__/interface-types.test.d.ts +0 -11
  174. package/dist/__tests__/interface-types.test.d.ts.map +0 -1
  175. package/dist/__tests__/interface-types.test.js +0 -404
  176. package/dist/__tests__/interface-types.test.js.map +0 -1
  177. package/dist/__tests__/jsdoc-constraints.test.js +0 -465
  178. package/dist/__tests__/jsdoc-constraints.test.js.map +0 -1
  179. package/dist/__tests__/write-schemas.test.js +0 -198
  180. package/dist/__tests__/write-schemas.test.js.map +0 -1
  181. package/dist/analyzer/class-analyzer.js +0 -377
  182. package/dist/analyzer/class-analyzer.js.map +0 -1
  183. package/dist/analyzer/decorator-extractor.d.ts +0 -78
  184. package/dist/analyzer/decorator-extractor.d.ts.map +0 -1
  185. package/dist/analyzer/decorator-extractor.js +0 -336
  186. package/dist/analyzer/decorator-extractor.js.map +0 -1
  187. package/dist/analyzer/jsdoc-constraints.js +0 -153
  188. package/dist/analyzer/jsdoc-constraints.js.map +0 -1
  189. package/dist/analyzer/program.js +0 -114
  190. package/dist/analyzer/program.js.map +0 -1
  191. package/dist/analyzer/type-converter.d.ts +0 -75
  192. package/dist/analyzer/type-converter.d.ts.map +0 -1
  193. package/dist/analyzer/type-converter.js +0 -474
  194. package/dist/analyzer/type-converter.js.map +0 -1
  195. package/dist/codegen/index.d.ts +0 -75
  196. package/dist/codegen/index.d.ts.map +0 -1
  197. package/dist/codegen/index.js +0 -597
  198. package/dist/codegen/index.js.map +0 -1
  199. package/dist/generators/class-schema.js +0 -140
  200. package/dist/generators/class-schema.js.map +0 -1
  201. package/dist/generators/method-schema.js +0 -108
  202. package/dist/generators/method-schema.js.map +0 -1
  203. package/dist/json-schema/generator.js +0 -166
  204. package/dist/json-schema/generator.js.map +0 -1
  205. package/dist/json-schema/types.js +0 -33
  206. package/dist/json-schema/types.js.map +0 -1
  207. package/dist/ui-schema/generator.js +0 -148
  208. package/dist/ui-schema/generator.js.map +0 -1
  209. package/dist/ui-schema/types.js +0 -8
  210. package/dist/ui-schema/types.js.map +0 -1
package/dist/cli.cjs ADDED
@@ -0,0 +1,2028 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __esm = (fn, res) => function __init() {
10
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
11
+ };
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
+ // If the importer is in node compatibility mode or this is not an ESM
26
+ // file that has been converted to a CommonJS file using a Babel-
27
+ // compatible transform (i.e. "__esModule" has not been set), then set
28
+ // "default" to the CommonJS "module.exports" for node compatibility.
29
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30
+ mod
31
+ ));
32
+
33
+ // src/canonicalize/chain-dsl-canonicalizer.ts
34
+ function isGroup(el) {
35
+ return el._type === "group";
36
+ }
37
+ function isConditional(el) {
38
+ return el._type === "conditional";
39
+ }
40
+ function isField(el) {
41
+ return el._type === "field";
42
+ }
43
+ function canonicalizeChainDSL(form) {
44
+ return {
45
+ kind: "form-ir",
46
+ irVersion: import_core.IR_VERSION,
47
+ elements: canonicalizeElements(form.elements),
48
+ typeRegistry: {},
49
+ provenance: CHAIN_DSL_PROVENANCE
50
+ };
51
+ }
52
+ function canonicalizeElements(elements) {
53
+ return elements.map(canonicalizeElement);
54
+ }
55
+ function canonicalizeElement(element) {
56
+ if (isField(element)) {
57
+ return canonicalizeField(element);
58
+ }
59
+ if (isGroup(element)) {
60
+ return canonicalizeGroup(element);
61
+ }
62
+ if (isConditional(element)) {
63
+ return canonicalizeConditional(element);
64
+ }
65
+ const _exhaustive = element;
66
+ throw new Error(`Unknown element type: ${JSON.stringify(_exhaustive)}`);
67
+ }
68
+ function canonicalizeField(field) {
69
+ switch (field._field) {
70
+ case "text":
71
+ return canonicalizeTextField(field);
72
+ case "number":
73
+ return canonicalizeNumberField(field);
74
+ case "boolean":
75
+ return canonicalizeBooleanField(field);
76
+ case "enum":
77
+ return canonicalizeStaticEnumField(field);
78
+ case "dynamic_enum":
79
+ return canonicalizeDynamicEnumField(field);
80
+ case "dynamic_schema":
81
+ return canonicalizeDynamicSchemaField(field);
82
+ case "array":
83
+ return canonicalizeArrayField(field);
84
+ case "object":
85
+ return canonicalizeObjectField(field);
86
+ default: {
87
+ const _exhaustive = field;
88
+ throw new Error(`Unknown field type: ${JSON.stringify(_exhaustive)}`);
89
+ }
90
+ }
91
+ }
92
+ function canonicalizeTextField(field) {
93
+ const type = { kind: "primitive", primitiveKind: "string" };
94
+ return buildFieldNode(
95
+ field.name,
96
+ type,
97
+ field.required,
98
+ buildAnnotations(field.label, field.placeholder)
99
+ );
100
+ }
101
+ function canonicalizeNumberField(field) {
102
+ const type = { kind: "primitive", primitiveKind: "number" };
103
+ const constraints = [];
104
+ if (field.min !== void 0) {
105
+ const c = {
106
+ kind: "constraint",
107
+ constraintKind: "minimum",
108
+ value: field.min,
109
+ provenance: CHAIN_DSL_PROVENANCE
110
+ };
111
+ constraints.push(c);
112
+ }
113
+ if (field.max !== void 0) {
114
+ const c = {
115
+ kind: "constraint",
116
+ constraintKind: "maximum",
117
+ value: field.max,
118
+ provenance: CHAIN_DSL_PROVENANCE
119
+ };
120
+ constraints.push(c);
121
+ }
122
+ return buildFieldNode(
123
+ field.name,
124
+ type,
125
+ field.required,
126
+ buildAnnotations(field.label),
127
+ constraints
128
+ );
129
+ }
130
+ function canonicalizeBooleanField(field) {
131
+ const type = { kind: "primitive", primitiveKind: "boolean" };
132
+ return buildFieldNode(field.name, type, field.required, buildAnnotations(field.label));
133
+ }
134
+ function canonicalizeStaticEnumField(field) {
135
+ const members = field.options.map((opt) => {
136
+ if (typeof opt === "string") {
137
+ return { value: opt };
138
+ }
139
+ return { value: opt.id, displayName: opt.label };
140
+ });
141
+ const type = { kind: "enum", members };
142
+ return buildFieldNode(field.name, type, field.required, buildAnnotations(field.label));
143
+ }
144
+ function canonicalizeDynamicEnumField(field) {
145
+ const type = {
146
+ kind: "dynamic",
147
+ dynamicKind: "enum",
148
+ sourceKey: field.source,
149
+ parameterFields: field.params ? [...field.params] : []
150
+ };
151
+ return buildFieldNode(field.name, type, field.required, buildAnnotations(field.label));
152
+ }
153
+ function canonicalizeDynamicSchemaField(field) {
154
+ const type = {
155
+ kind: "dynamic",
156
+ dynamicKind: "schema",
157
+ sourceKey: field.schemaSource,
158
+ parameterFields: []
159
+ };
160
+ return buildFieldNode(field.name, type, field.required, buildAnnotations(field.label));
161
+ }
162
+ function canonicalizeArrayField(field) {
163
+ const itemProperties = buildObjectProperties(field.items);
164
+ const itemsType = {
165
+ kind: "object",
166
+ properties: itemProperties,
167
+ additionalProperties: false
168
+ };
169
+ const type = { kind: "array", items: itemsType };
170
+ const constraints = [];
171
+ if (field.minItems !== void 0) {
172
+ const c = {
173
+ kind: "constraint",
174
+ constraintKind: "minItems",
175
+ value: field.minItems,
176
+ provenance: CHAIN_DSL_PROVENANCE
177
+ };
178
+ constraints.push(c);
179
+ }
180
+ if (field.maxItems !== void 0) {
181
+ const c = {
182
+ kind: "constraint",
183
+ constraintKind: "maxItems",
184
+ value: field.maxItems,
185
+ provenance: CHAIN_DSL_PROVENANCE
186
+ };
187
+ constraints.push(c);
188
+ }
189
+ return buildFieldNode(
190
+ field.name,
191
+ type,
192
+ field.required,
193
+ buildAnnotations(field.label),
194
+ constraints
195
+ );
196
+ }
197
+ function canonicalizeObjectField(field) {
198
+ const properties = buildObjectProperties(field.properties);
199
+ const type = {
200
+ kind: "object",
201
+ properties,
202
+ additionalProperties: false
203
+ };
204
+ return buildFieldNode(field.name, type, field.required, buildAnnotations(field.label));
205
+ }
206
+ function canonicalizeGroup(g) {
207
+ return {
208
+ kind: "group",
209
+ label: g.label,
210
+ elements: canonicalizeElements(g.elements),
211
+ provenance: CHAIN_DSL_PROVENANCE
212
+ };
213
+ }
214
+ function canonicalizeConditional(c) {
215
+ return {
216
+ kind: "conditional",
217
+ fieldName: c.field,
218
+ // Conditional values from the chain DSL are JSON-serializable primitives
219
+ // (strings, numbers, booleans) produced by the `is()` predicate helper.
220
+ value: assertJsonValue(c.value),
221
+ elements: canonicalizeElements(c.elements),
222
+ provenance: CHAIN_DSL_PROVENANCE
223
+ };
224
+ }
225
+ function assertJsonValue(v) {
226
+ if (v === null || typeof v === "string" || typeof v === "number" || typeof v === "boolean") {
227
+ return v;
228
+ }
229
+ if (Array.isArray(v)) {
230
+ return v.map(assertJsonValue);
231
+ }
232
+ if (typeof v === "object") {
233
+ const result = {};
234
+ for (const [key, val] of Object.entries(v)) {
235
+ result[key] = assertJsonValue(val);
236
+ }
237
+ return result;
238
+ }
239
+ throw new TypeError(`Conditional value is not a valid JsonValue: ${typeof v}`);
240
+ }
241
+ function buildFieldNode(name, type, required, annotations, constraints = []) {
242
+ return {
243
+ kind: "field",
244
+ name,
245
+ type,
246
+ required: required === true,
247
+ constraints,
248
+ annotations,
249
+ provenance: CHAIN_DSL_PROVENANCE
250
+ };
251
+ }
252
+ function buildAnnotations(label, placeholder) {
253
+ const annotations = [];
254
+ if (label !== void 0) {
255
+ const a = {
256
+ kind: "annotation",
257
+ annotationKind: "displayName",
258
+ value: label,
259
+ provenance: CHAIN_DSL_PROVENANCE
260
+ };
261
+ annotations.push(a);
262
+ }
263
+ if (placeholder !== void 0) {
264
+ const a = {
265
+ kind: "annotation",
266
+ annotationKind: "placeholder",
267
+ value: placeholder,
268
+ provenance: CHAIN_DSL_PROVENANCE
269
+ };
270
+ annotations.push(a);
271
+ }
272
+ return annotations;
273
+ }
274
+ function buildObjectProperties(elements, insideConditional = false) {
275
+ const properties = [];
276
+ for (const el of elements) {
277
+ if (isField(el)) {
278
+ const fieldNode = canonicalizeField(el);
279
+ properties.push({
280
+ name: fieldNode.name,
281
+ type: fieldNode.type,
282
+ // Fields inside a conditional branch are always optional in the
283
+ // data schema, regardless of their `required` flag — the condition
284
+ // may not be met, so the field may be absent.
285
+ optional: insideConditional || !fieldNode.required,
286
+ constraints: fieldNode.constraints,
287
+ annotations: fieldNode.annotations,
288
+ provenance: CHAIN_DSL_PROVENANCE
289
+ });
290
+ } else if (isGroup(el)) {
291
+ properties.push(...buildObjectProperties(el.elements, insideConditional));
292
+ } else if (isConditional(el)) {
293
+ properties.push(...buildObjectProperties(el.elements, true));
294
+ }
295
+ }
296
+ return properties;
297
+ }
298
+ var import_core, CHAIN_DSL_PROVENANCE;
299
+ var init_chain_dsl_canonicalizer = __esm({
300
+ "src/canonicalize/chain-dsl-canonicalizer.ts"() {
301
+ "use strict";
302
+ import_core = require("@formspec/core");
303
+ CHAIN_DSL_PROVENANCE = {
304
+ surface: "chain-dsl",
305
+ file: "",
306
+ line: 0,
307
+ column: 0
308
+ };
309
+ }
310
+ });
311
+
312
+ // src/canonicalize/tsdoc-canonicalizer.ts
313
+ function canonicalizeTSDoc(analysis, source) {
314
+ const file = source?.file ?? "";
315
+ const provenance = {
316
+ surface: "tsdoc",
317
+ file,
318
+ line: 1,
319
+ column: 0
320
+ };
321
+ const elements = assembleElements(analysis.fields, analysis.fieldLayouts, provenance);
322
+ return {
323
+ kind: "form-ir",
324
+ irVersion: import_core2.IR_VERSION,
325
+ elements,
326
+ typeRegistry: analysis.typeRegistry,
327
+ provenance
328
+ };
329
+ }
330
+ function assembleElements(fields, layouts, provenance) {
331
+ const elements = [];
332
+ const groupMap = /* @__PURE__ */ new Map();
333
+ const topLevelOrder = [];
334
+ for (let i = 0; i < fields.length; i++) {
335
+ const field = fields[i];
336
+ const layout = layouts[i];
337
+ if (!field || !layout) continue;
338
+ const element = wrapInConditional(field, layout, provenance);
339
+ if (layout.groupLabel !== void 0) {
340
+ const label = layout.groupLabel;
341
+ let groupElements = groupMap.get(label);
342
+ if (!groupElements) {
343
+ groupElements = [];
344
+ groupMap.set(label, groupElements);
345
+ topLevelOrder.push({ type: "group", label });
346
+ }
347
+ groupElements.push(element);
348
+ } else {
349
+ topLevelOrder.push({ type: "element", element });
350
+ }
351
+ }
352
+ for (const entry of topLevelOrder) {
353
+ if (entry.type === "group") {
354
+ const groupElements = groupMap.get(entry.label);
355
+ if (groupElements) {
356
+ const groupNode = {
357
+ kind: "group",
358
+ label: entry.label,
359
+ elements: groupElements,
360
+ provenance
361
+ };
362
+ elements.push(groupNode);
363
+ groupMap.delete(entry.label);
364
+ }
365
+ } else {
366
+ elements.push(entry.element);
367
+ }
368
+ }
369
+ return elements;
370
+ }
371
+ function wrapInConditional(field, layout, provenance) {
372
+ if (layout.showWhen === void 0) {
373
+ return field;
374
+ }
375
+ const conditional = {
376
+ kind: "conditional",
377
+ fieldName: layout.showWhen.field,
378
+ value: layout.showWhen.value,
379
+ elements: [field],
380
+ provenance
381
+ };
382
+ return conditional;
383
+ }
384
+ var import_core2;
385
+ var init_tsdoc_canonicalizer = __esm({
386
+ "src/canonicalize/tsdoc-canonicalizer.ts"() {
387
+ "use strict";
388
+ import_core2 = require("@formspec/core");
389
+ }
390
+ });
391
+
392
+ // src/canonicalize/index.ts
393
+ var init_canonicalize = __esm({
394
+ "src/canonicalize/index.ts"() {
395
+ "use strict";
396
+ init_chain_dsl_canonicalizer();
397
+ init_tsdoc_canonicalizer();
398
+ }
399
+ });
400
+
401
+ // src/json-schema/ir-generator.ts
402
+ function makeContext() {
403
+ return { defs: {} };
404
+ }
405
+ function generateJsonSchemaFromIR(ir) {
406
+ const ctx = makeContext();
407
+ for (const [name, typeDef] of Object.entries(ir.typeRegistry)) {
408
+ ctx.defs[name] = generateTypeNode(typeDef.type, ctx);
409
+ }
410
+ const properties = {};
411
+ const required = [];
412
+ collectFields(ir.elements, properties, required, ctx);
413
+ const uniqueRequired = [...new Set(required)];
414
+ const result = {
415
+ $schema: "https://json-schema.org/draft/2020-12/schema",
416
+ type: "object",
417
+ properties,
418
+ ...uniqueRequired.length > 0 && { required: uniqueRequired }
419
+ };
420
+ if (Object.keys(ctx.defs).length > 0) {
421
+ result.$defs = ctx.defs;
422
+ }
423
+ return result;
424
+ }
425
+ function collectFields(elements, properties, required, ctx) {
426
+ for (const element of elements) {
427
+ switch (element.kind) {
428
+ case "field":
429
+ properties[element.name] = generateFieldSchema(element, ctx);
430
+ if (element.required) {
431
+ required.push(element.name);
432
+ }
433
+ break;
434
+ case "group":
435
+ collectFields(element.elements, properties, required, ctx);
436
+ break;
437
+ case "conditional":
438
+ collectFields(element.elements, properties, required, ctx);
439
+ break;
440
+ default: {
441
+ const _exhaustive = element;
442
+ void _exhaustive;
443
+ }
444
+ }
445
+ }
446
+ }
447
+ function generateFieldSchema(field, ctx) {
448
+ const schema = generateTypeNode(field.type, ctx);
449
+ applyConstraints(schema, field.constraints);
450
+ applyAnnotations(schema, field.annotations);
451
+ return schema;
452
+ }
453
+ function generateTypeNode(type, ctx) {
454
+ switch (type.kind) {
455
+ case "primitive":
456
+ return generatePrimitiveType(type);
457
+ case "enum":
458
+ return generateEnumType(type);
459
+ case "array":
460
+ return generateArrayType(type, ctx);
461
+ case "object":
462
+ return generateObjectType(type, ctx);
463
+ case "union":
464
+ return generateUnionType(type, ctx);
465
+ case "reference":
466
+ return generateReferenceType(type);
467
+ case "dynamic":
468
+ return generateDynamicType(type);
469
+ case "custom":
470
+ return generateCustomType(type);
471
+ default: {
472
+ const _exhaustive = type;
473
+ return _exhaustive;
474
+ }
475
+ }
476
+ }
477
+ function generatePrimitiveType(type) {
478
+ return { type: type.primitiveKind };
479
+ }
480
+ function generateEnumType(type) {
481
+ const hasDisplayNames = type.members.some((m) => m.displayName !== void 0);
482
+ if (hasDisplayNames) {
483
+ return {
484
+ oneOf: type.members.map((m) => {
485
+ const entry = { const: m.value };
486
+ if (m.displayName !== void 0) {
487
+ entry.title = m.displayName;
488
+ }
489
+ return entry;
490
+ })
491
+ };
492
+ }
493
+ return { enum: type.members.map((m) => m.value) };
494
+ }
495
+ function generateArrayType(type, ctx) {
496
+ return {
497
+ type: "array",
498
+ items: generateTypeNode(type.items, ctx)
499
+ };
500
+ }
501
+ function generateObjectType(type, ctx) {
502
+ const properties = {};
503
+ const required = [];
504
+ for (const prop of type.properties) {
505
+ properties[prop.name] = generatePropertySchema(prop, ctx);
506
+ if (!prop.optional) {
507
+ required.push(prop.name);
508
+ }
509
+ }
510
+ const schema = { type: "object", properties };
511
+ if (required.length > 0) {
512
+ schema.required = required;
513
+ }
514
+ if (!type.additionalProperties) {
515
+ schema.additionalProperties = false;
516
+ }
517
+ return schema;
518
+ }
519
+ function generatePropertySchema(prop, ctx) {
520
+ const schema = generateTypeNode(prop.type, ctx);
521
+ applyConstraints(schema, prop.constraints);
522
+ applyAnnotations(schema, prop.annotations);
523
+ return schema;
524
+ }
525
+ function generateUnionType(type, ctx) {
526
+ if (isBooleanUnion(type)) {
527
+ return { type: "boolean" };
528
+ }
529
+ return {
530
+ anyOf: type.members.map((m) => generateTypeNode(m, ctx))
531
+ };
532
+ }
533
+ function isBooleanUnion(type) {
534
+ if (type.members.length !== 2) return false;
535
+ const kinds = type.members.map((m) => m.kind);
536
+ return kinds.every((k) => k === "primitive") && type.members.every((m) => m.kind === "primitive" && m.primitiveKind === "boolean");
537
+ }
538
+ function generateReferenceType(type) {
539
+ return { $ref: `#/$defs/${type.name}` };
540
+ }
541
+ function generateDynamicType(type) {
542
+ if (type.dynamicKind === "enum") {
543
+ const schema = {
544
+ type: "string",
545
+ "x-formspec-source": type.sourceKey
546
+ };
547
+ if (type.parameterFields.length > 0) {
548
+ schema["x-formspec-params"] = [...type.parameterFields];
549
+ }
550
+ return schema;
551
+ }
552
+ return {
553
+ type: "object",
554
+ additionalProperties: true,
555
+ "x-formspec-schemaSource": type.sourceKey
556
+ };
557
+ }
558
+ function generateCustomType(_type) {
559
+ return { type: "object" };
560
+ }
561
+ function applyConstraints(schema, constraints) {
562
+ for (const constraint of constraints) {
563
+ switch (constraint.constraintKind) {
564
+ case "minimum":
565
+ schema.minimum = constraint.value;
566
+ break;
567
+ case "maximum":
568
+ schema.maximum = constraint.value;
569
+ break;
570
+ case "exclusiveMinimum":
571
+ schema.exclusiveMinimum = constraint.value;
572
+ break;
573
+ case "exclusiveMaximum":
574
+ schema.exclusiveMaximum = constraint.value;
575
+ break;
576
+ case "multipleOf": {
577
+ const { value } = constraint;
578
+ if (value === 1 && schema.type === "number") {
579
+ schema.type = "integer";
580
+ } else {
581
+ schema.multipleOf = value;
582
+ }
583
+ break;
584
+ }
585
+ case "minLength":
586
+ schema.minLength = constraint.value;
587
+ break;
588
+ case "maxLength":
589
+ schema.maxLength = constraint.value;
590
+ break;
591
+ case "minItems":
592
+ schema.minItems = constraint.value;
593
+ break;
594
+ case "maxItems":
595
+ schema.maxItems = constraint.value;
596
+ break;
597
+ case "pattern":
598
+ schema.pattern = constraint.pattern;
599
+ break;
600
+ case "uniqueItems":
601
+ schema.uniqueItems = constraint.value;
602
+ break;
603
+ case "allowedMembers":
604
+ break;
605
+ case "custom":
606
+ break;
607
+ default: {
608
+ const _exhaustive = constraint;
609
+ void _exhaustive;
610
+ }
611
+ }
612
+ }
613
+ }
614
+ function applyAnnotations(schema, annotations) {
615
+ for (const annotation of annotations) {
616
+ switch (annotation.annotationKind) {
617
+ case "displayName":
618
+ schema.title = annotation.value;
619
+ break;
620
+ case "description":
621
+ schema.description = annotation.value;
622
+ break;
623
+ case "defaultValue":
624
+ schema.default = annotation.value;
625
+ break;
626
+ case "deprecated":
627
+ schema.deprecated = true;
628
+ break;
629
+ case "placeholder":
630
+ break;
631
+ case "formatHint":
632
+ break;
633
+ case "custom":
634
+ break;
635
+ default: {
636
+ const _exhaustive = annotation;
637
+ void _exhaustive;
638
+ }
639
+ }
640
+ }
641
+ }
642
+ var init_ir_generator = __esm({
643
+ "src/json-schema/ir-generator.ts"() {
644
+ "use strict";
645
+ }
646
+ });
647
+
648
+ // src/json-schema/generator.ts
649
+ function generateJsonSchema(form) {
650
+ const ir = canonicalizeChainDSL(form);
651
+ return generateJsonSchemaFromIR(ir);
652
+ }
653
+ var init_generator = __esm({
654
+ "src/json-schema/generator.ts"() {
655
+ "use strict";
656
+ init_canonicalize();
657
+ init_ir_generator();
658
+ }
659
+ });
660
+
661
+ // src/ui-schema/schema.ts
662
+ var import_zod, jsonPointerSchema, ruleEffectSchema, uiSchemaElementTypeSchema, ruleConditionSchema, schemaBasedConditionSchema, ruleSchema, uiSchemaElementSchema, controlSchema, verticalLayoutSchema, horizontalLayoutSchema, groupLayoutSchema, categorySchema, categorizationSchema, labelElementSchema, uiSchema;
663
+ var init_schema = __esm({
664
+ "src/ui-schema/schema.ts"() {
665
+ "use strict";
666
+ import_zod = require("zod");
667
+ jsonPointerSchema = import_zod.z.string();
668
+ ruleEffectSchema = import_zod.z.enum(["SHOW", "HIDE", "ENABLE", "DISABLE"]);
669
+ uiSchemaElementTypeSchema = import_zod.z.enum([
670
+ "Control",
671
+ "VerticalLayout",
672
+ "HorizontalLayout",
673
+ "Group",
674
+ "Categorization",
675
+ "Category",
676
+ "Label"
677
+ ]);
678
+ ruleConditionSchema = import_zod.z.lazy(
679
+ () => import_zod.z.object({
680
+ const: import_zod.z.unknown().optional(),
681
+ enum: import_zod.z.array(import_zod.z.unknown()).readonly().optional(),
682
+ type: import_zod.z.string().optional(),
683
+ not: ruleConditionSchema.optional(),
684
+ minimum: import_zod.z.number().optional(),
685
+ maximum: import_zod.z.number().optional(),
686
+ exclusiveMinimum: import_zod.z.number().optional(),
687
+ exclusiveMaximum: import_zod.z.number().optional(),
688
+ minLength: import_zod.z.number().optional(),
689
+ properties: import_zod.z.record(import_zod.z.string(), ruleConditionSchema).optional(),
690
+ required: import_zod.z.array(import_zod.z.string()).optional(),
691
+ allOf: import_zod.z.array(ruleConditionSchema).optional()
692
+ }).strict()
693
+ );
694
+ schemaBasedConditionSchema = import_zod.z.object({
695
+ scope: jsonPointerSchema,
696
+ schema: ruleConditionSchema
697
+ }).strict();
698
+ ruleSchema = import_zod.z.object({
699
+ effect: ruleEffectSchema,
700
+ condition: schemaBasedConditionSchema
701
+ }).strict();
702
+ uiSchemaElementSchema = import_zod.z.lazy(
703
+ () => import_zod.z.union([
704
+ controlSchema,
705
+ verticalLayoutSchema,
706
+ horizontalLayoutSchema,
707
+ groupLayoutSchema,
708
+ categorizationSchema,
709
+ categorySchema,
710
+ labelElementSchema
711
+ ])
712
+ );
713
+ controlSchema = import_zod.z.object({
714
+ type: import_zod.z.literal("Control"),
715
+ scope: jsonPointerSchema,
716
+ label: import_zod.z.union([import_zod.z.string(), import_zod.z.literal(false)]).optional(),
717
+ rule: ruleSchema.optional(),
718
+ options: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional()
719
+ }).passthrough();
720
+ verticalLayoutSchema = import_zod.z.lazy(
721
+ () => import_zod.z.object({
722
+ type: import_zod.z.literal("VerticalLayout"),
723
+ elements: import_zod.z.array(uiSchemaElementSchema),
724
+ rule: ruleSchema.optional(),
725
+ options: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional()
726
+ }).passthrough()
727
+ );
728
+ horizontalLayoutSchema = import_zod.z.lazy(
729
+ () => import_zod.z.object({
730
+ type: import_zod.z.literal("HorizontalLayout"),
731
+ elements: import_zod.z.array(uiSchemaElementSchema),
732
+ rule: ruleSchema.optional(),
733
+ options: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional()
734
+ }).passthrough()
735
+ );
736
+ groupLayoutSchema = import_zod.z.lazy(
737
+ () => import_zod.z.object({
738
+ type: import_zod.z.literal("Group"),
739
+ label: import_zod.z.string(),
740
+ elements: import_zod.z.array(uiSchemaElementSchema),
741
+ rule: ruleSchema.optional(),
742
+ options: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional()
743
+ }).passthrough()
744
+ );
745
+ categorySchema = import_zod.z.lazy(
746
+ () => import_zod.z.object({
747
+ type: import_zod.z.literal("Category"),
748
+ label: import_zod.z.string(),
749
+ elements: import_zod.z.array(uiSchemaElementSchema),
750
+ rule: ruleSchema.optional(),
751
+ options: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional()
752
+ }).passthrough()
753
+ );
754
+ categorizationSchema = import_zod.z.lazy(
755
+ () => import_zod.z.object({
756
+ type: import_zod.z.literal("Categorization"),
757
+ elements: import_zod.z.array(categorySchema),
758
+ label: import_zod.z.string().optional(),
759
+ rule: ruleSchema.optional(),
760
+ options: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional()
761
+ }).passthrough()
762
+ );
763
+ labelElementSchema = import_zod.z.object({
764
+ type: import_zod.z.literal("Label"),
765
+ text: import_zod.z.string(),
766
+ rule: ruleSchema.optional(),
767
+ options: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional()
768
+ }).passthrough();
769
+ uiSchema = import_zod.z.lazy(
770
+ () => import_zod.z.union([verticalLayoutSchema, horizontalLayoutSchema, groupLayoutSchema, categorizationSchema])
771
+ );
772
+ }
773
+ });
774
+
775
+ // src/ui-schema/ir-generator.ts
776
+ function parseOrThrow(schema, value, label) {
777
+ try {
778
+ return schema.parse(value);
779
+ } catch (error) {
780
+ if (error instanceof import_zod2.z.ZodError) {
781
+ throw new Error(
782
+ `Generated ${label} failed validation:
783
+ ${error.issues.map((i) => ` ${i.path.join(".")}: ${i.message}`).join("\n")}`
784
+ );
785
+ }
786
+ throw error;
787
+ }
788
+ }
789
+ function fieldToScope(fieldName) {
790
+ return `#/properties/${fieldName}`;
791
+ }
792
+ function createShowRule(fieldName, value) {
793
+ return {
794
+ effect: "SHOW",
795
+ condition: {
796
+ scope: fieldToScope(fieldName),
797
+ schema: { const: value }
798
+ }
799
+ };
800
+ }
801
+ function combineRules(parentRule, childRule) {
802
+ const parentCondition = parentRule.condition;
803
+ const childCondition = childRule.condition;
804
+ return {
805
+ effect: "SHOW",
806
+ condition: {
807
+ scope: "#",
808
+ schema: {
809
+ allOf: [
810
+ {
811
+ properties: {
812
+ [parentCondition.scope.replace("#/properties/", "")]: parentCondition.schema
813
+ }
814
+ },
815
+ {
816
+ properties: {
817
+ [childCondition.scope.replace("#/properties/", "")]: childCondition.schema
818
+ }
819
+ }
820
+ ]
821
+ }
822
+ }
823
+ };
824
+ }
825
+ function fieldNodeToControl(field, parentRule) {
826
+ const displayNameAnnotation = field.annotations.find((a) => a.annotationKind === "displayName");
827
+ const control = {
828
+ type: "Control",
829
+ scope: fieldToScope(field.name),
830
+ ...displayNameAnnotation !== void 0 && { label: displayNameAnnotation.value },
831
+ ...parentRule !== void 0 && { rule: parentRule }
832
+ };
833
+ return control;
834
+ }
835
+ function groupNodeToLayout(group, parentRule) {
836
+ return {
837
+ type: "Group",
838
+ label: group.label,
839
+ elements: irElementsToUiSchema(group.elements, parentRule),
840
+ ...parentRule !== void 0 && { rule: parentRule }
841
+ };
842
+ }
843
+ function irElementsToUiSchema(elements, parentRule) {
844
+ const result = [];
845
+ for (const element of elements) {
846
+ switch (element.kind) {
847
+ case "field": {
848
+ result.push(fieldNodeToControl(element, parentRule));
849
+ break;
850
+ }
851
+ case "group": {
852
+ result.push(groupNodeToLayout(element, parentRule));
853
+ break;
854
+ }
855
+ case "conditional": {
856
+ const newRule = createShowRule(element.fieldName, element.value);
857
+ const combinedRule = parentRule !== void 0 ? combineRules(parentRule, newRule) : newRule;
858
+ const childElements = irElementsToUiSchema(element.elements, combinedRule);
859
+ result.push(...childElements);
860
+ break;
861
+ }
862
+ default: {
863
+ const _exhaustive = element;
864
+ void _exhaustive;
865
+ throw new Error("Unhandled IR element kind");
866
+ }
867
+ }
868
+ }
869
+ return result;
870
+ }
871
+ function generateUiSchemaFromIR(ir) {
872
+ const result = {
873
+ type: "VerticalLayout",
874
+ elements: irElementsToUiSchema(ir.elements)
875
+ };
876
+ return parseOrThrow(uiSchema, result, "UI Schema");
877
+ }
878
+ var import_zod2;
879
+ var init_ir_generator2 = __esm({
880
+ "src/ui-schema/ir-generator.ts"() {
881
+ "use strict";
882
+ init_schema();
883
+ import_zod2 = require("zod");
884
+ }
885
+ });
886
+
887
+ // src/ui-schema/generator.ts
888
+ function generateUiSchema(form) {
889
+ const ir = canonicalizeChainDSL(form);
890
+ return generateUiSchemaFromIR(ir);
891
+ }
892
+ var init_generator2 = __esm({
893
+ "src/ui-schema/generator.ts"() {
894
+ "use strict";
895
+ init_canonicalize();
896
+ init_ir_generator2();
897
+ }
898
+ });
899
+
900
+ // src/json-schema/types.ts
901
+ function setSchemaExtension(schema, key, value) {
902
+ schema[key] = value;
903
+ }
904
+ function getSchemaExtension(schema, key) {
905
+ return schema[key];
906
+ }
907
+ var init_types = __esm({
908
+ "src/json-schema/types.ts"() {
909
+ "use strict";
910
+ }
911
+ });
912
+
913
+ // src/json-schema/schema.ts
914
+ var import_zod3, jsonSchemaTypeSchema, jsonSchema7Schema;
915
+ var init_schema2 = __esm({
916
+ "src/json-schema/schema.ts"() {
917
+ "use strict";
918
+ import_zod3 = require("zod");
919
+ jsonSchemaTypeSchema = import_zod3.z.enum([
920
+ "string",
921
+ "number",
922
+ "integer",
923
+ "boolean",
924
+ "object",
925
+ "array",
926
+ "null"
927
+ ]);
928
+ jsonSchema7Schema = import_zod3.z.lazy(
929
+ () => import_zod3.z.object({
930
+ $schema: import_zod3.z.string().optional(),
931
+ $id: import_zod3.z.string().optional(),
932
+ $ref: import_zod3.z.string().optional(),
933
+ // Metadata
934
+ title: import_zod3.z.string().optional(),
935
+ description: import_zod3.z.string().optional(),
936
+ deprecated: import_zod3.z.boolean().optional(),
937
+ // Type
938
+ type: import_zod3.z.union([jsonSchemaTypeSchema, import_zod3.z.array(jsonSchemaTypeSchema)]).optional(),
939
+ // String validation
940
+ minLength: import_zod3.z.number().optional(),
941
+ maxLength: import_zod3.z.number().optional(),
942
+ pattern: import_zod3.z.string().optional(),
943
+ // Number validation
944
+ minimum: import_zod3.z.number().optional(),
945
+ maximum: import_zod3.z.number().optional(),
946
+ exclusiveMinimum: import_zod3.z.number().optional(),
947
+ exclusiveMaximum: import_zod3.z.number().optional(),
948
+ // Enum
949
+ enum: import_zod3.z.array(import_zod3.z.union([import_zod3.z.string(), import_zod3.z.number(), import_zod3.z.boolean(), import_zod3.z.null()])).readonly().optional(),
950
+ const: import_zod3.z.union([import_zod3.z.string(), import_zod3.z.number(), import_zod3.z.boolean(), import_zod3.z.null()]).optional(),
951
+ // Object
952
+ properties: import_zod3.z.record(import_zod3.z.string(), jsonSchema7Schema).optional(),
953
+ required: import_zod3.z.array(import_zod3.z.string()).optional(),
954
+ additionalProperties: import_zod3.z.union([import_zod3.z.boolean(), jsonSchema7Schema]).optional(),
955
+ // Array
956
+ items: import_zod3.z.union([jsonSchema7Schema, import_zod3.z.array(jsonSchema7Schema)]).optional(),
957
+ minItems: import_zod3.z.number().optional(),
958
+ maxItems: import_zod3.z.number().optional(),
959
+ // Composition
960
+ allOf: import_zod3.z.array(jsonSchema7Schema).optional(),
961
+ anyOf: import_zod3.z.array(jsonSchema7Schema).optional(),
962
+ oneOf: import_zod3.z.array(jsonSchema7Schema).optional(),
963
+ not: jsonSchema7Schema.optional(),
964
+ // Conditional
965
+ if: jsonSchema7Schema.optional(),
966
+ then: jsonSchema7Schema.optional(),
967
+ else: jsonSchema7Schema.optional(),
968
+ // Format
969
+ format: import_zod3.z.string().optional(),
970
+ // Default
971
+ default: import_zod3.z.unknown().optional(),
972
+ // FormSpec extensions
973
+ "x-formspec-source": import_zod3.z.string().optional(),
974
+ "x-formspec-params": import_zod3.z.array(import_zod3.z.string()).readonly().optional(),
975
+ "x-formspec-schemaSource": import_zod3.z.string().optional()
976
+ }).passthrough()
977
+ );
978
+ }
979
+ });
980
+
981
+ // src/analyzer/program.ts
982
+ function createProgramContext(filePath) {
983
+ const absolutePath = path.resolve(filePath);
984
+ const fileDir = path.dirname(absolutePath);
985
+ const configPath = ts.findConfigFile(fileDir, ts.sys.fileExists.bind(ts.sys), "tsconfig.json");
986
+ let compilerOptions;
987
+ let fileNames;
988
+ if (configPath) {
989
+ const configFile = ts.readConfigFile(configPath, ts.sys.readFile.bind(ts.sys));
990
+ if (configFile.error) {
991
+ throw new Error(
992
+ `Error reading tsconfig.json: ${ts.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`
993
+ );
994
+ }
995
+ const parsed = ts.parseJsonConfigFileContent(
996
+ configFile.config,
997
+ ts.sys,
998
+ path.dirname(configPath)
999
+ );
1000
+ if (parsed.errors.length > 0) {
1001
+ const errorMessages = parsed.errors.map((e) => ts.flattenDiagnosticMessageText(e.messageText, "\n")).join("\n");
1002
+ throw new Error(`Error parsing tsconfig.json: ${errorMessages}`);
1003
+ }
1004
+ compilerOptions = parsed.options;
1005
+ fileNames = parsed.fileNames.includes(absolutePath) ? parsed.fileNames : [...parsed.fileNames, absolutePath];
1006
+ } else {
1007
+ compilerOptions = {
1008
+ target: ts.ScriptTarget.ES2022,
1009
+ module: ts.ModuleKind.NodeNext,
1010
+ moduleResolution: ts.ModuleResolutionKind.NodeNext,
1011
+ strict: true,
1012
+ skipLibCheck: true,
1013
+ declaration: true
1014
+ };
1015
+ fileNames = [absolutePath];
1016
+ }
1017
+ const program = ts.createProgram(fileNames, compilerOptions);
1018
+ const sourceFile = program.getSourceFile(absolutePath);
1019
+ if (!sourceFile) {
1020
+ throw new Error(`Could not find source file: ${absolutePath}`);
1021
+ }
1022
+ return {
1023
+ program,
1024
+ checker: program.getTypeChecker(),
1025
+ sourceFile
1026
+ };
1027
+ }
1028
+ function findNodeByName(sourceFile, name, predicate, getName) {
1029
+ let result = null;
1030
+ function visit(node) {
1031
+ if (result) return;
1032
+ if (predicate(node) && getName(node) === name) {
1033
+ result = node;
1034
+ return;
1035
+ }
1036
+ ts.forEachChild(node, visit);
1037
+ }
1038
+ visit(sourceFile);
1039
+ return result;
1040
+ }
1041
+ function findClassByName(sourceFile, className) {
1042
+ return findNodeByName(sourceFile, className, ts.isClassDeclaration, (n) => n.name?.text);
1043
+ }
1044
+ function findInterfaceByName(sourceFile, interfaceName) {
1045
+ return findNodeByName(sourceFile, interfaceName, ts.isInterfaceDeclaration, (n) => n.name.text);
1046
+ }
1047
+ function findTypeAliasByName(sourceFile, aliasName) {
1048
+ return findNodeByName(sourceFile, aliasName, ts.isTypeAliasDeclaration, (n) => n.name.text);
1049
+ }
1050
+ var ts, path;
1051
+ var init_program = __esm({
1052
+ "src/analyzer/program.ts"() {
1053
+ "use strict";
1054
+ ts = __toESM(require("typescript"), 1);
1055
+ path = __toESM(require("path"), 1);
1056
+ }
1057
+ });
1058
+
1059
+ // src/analyzer/tsdoc-parser.ts
1060
+ function isBuiltinConstraintName(tagName) {
1061
+ return tagName in import_core3.BUILTIN_CONSTRAINT_DEFINITIONS;
1062
+ }
1063
+ function createFormSpecTSDocConfig() {
1064
+ const config = new import_tsdoc.TSDocConfiguration();
1065
+ for (const tagName of Object.keys(import_core3.BUILTIN_CONSTRAINT_DEFINITIONS)) {
1066
+ config.addTagDefinition(
1067
+ new import_tsdoc.TSDocTagDefinition({
1068
+ tagName: "@" + tagName,
1069
+ syntaxKind: import_tsdoc.TSDocTagSyntaxKind.BlockTag,
1070
+ allowMultiple: true
1071
+ })
1072
+ );
1073
+ }
1074
+ return config;
1075
+ }
1076
+ function getParser() {
1077
+ sharedParser ??= new import_tsdoc.TSDocParser(createFormSpecTSDocConfig());
1078
+ return sharedParser;
1079
+ }
1080
+ function parseTSDocTags(node, file = "") {
1081
+ const constraints = [];
1082
+ const annotations = [];
1083
+ const sourceFile = node.getSourceFile();
1084
+ const sourceText = sourceFile.getFullText();
1085
+ const commentRanges = ts2.getLeadingCommentRanges(sourceText, node.getFullStart());
1086
+ if (commentRanges) {
1087
+ for (const range of commentRanges) {
1088
+ if (range.kind !== ts2.SyntaxKind.MultiLineCommentTrivia) {
1089
+ continue;
1090
+ }
1091
+ const commentText = sourceText.substring(range.pos, range.end);
1092
+ if (!commentText.startsWith("/**")) {
1093
+ continue;
1094
+ }
1095
+ const parser = getParser();
1096
+ const parserContext = parser.parseRange(
1097
+ import_tsdoc.TextRange.fromStringRange(sourceText, range.pos, range.end)
1098
+ );
1099
+ const docComment = parserContext.docComment;
1100
+ for (const block of docComment.customBlocks) {
1101
+ const tagName = block.blockTag.tagName.substring(1);
1102
+ if (TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;
1103
+ const text = extractBlockText(block).trim();
1104
+ if (text === "") continue;
1105
+ const provenance = provenanceForComment(range, sourceFile, file, tagName);
1106
+ const constraintNode = parseConstraintValue(tagName, text, provenance);
1107
+ if (constraintNode) {
1108
+ constraints.push(constraintNode);
1109
+ }
1110
+ }
1111
+ if (docComment.deprecatedBlock !== void 0) {
1112
+ annotations.push({
1113
+ kind: "annotation",
1114
+ annotationKind: "deprecated",
1115
+ provenance: provenanceForComment(range, sourceFile, file, "deprecated")
1116
+ });
1117
+ }
1118
+ }
1119
+ }
1120
+ const jsDocTagsAll = ts2.getJSDocTags(node);
1121
+ for (const tag of jsDocTagsAll) {
1122
+ const tagName = tag.tagName.text;
1123
+ if (!TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;
1124
+ const commentText = getTagCommentText(tag);
1125
+ if (commentText === void 0 || commentText.trim() === "") continue;
1126
+ const text = commentText.trim();
1127
+ const provenance = provenanceForJSDocTag(tag, file);
1128
+ const constraintNode = parseConstraintValue(tagName, text, provenance);
1129
+ if (constraintNode) {
1130
+ constraints.push(constraintNode);
1131
+ }
1132
+ }
1133
+ let displayName;
1134
+ let description;
1135
+ let displayNameTag;
1136
+ let descriptionTag;
1137
+ for (const tag of jsDocTagsAll) {
1138
+ const tagName = tag.tagName.text;
1139
+ const commentText = getTagCommentText(tag);
1140
+ if (commentText === void 0 || commentText.trim() === "") {
1141
+ continue;
1142
+ }
1143
+ const trimmed = commentText.trim();
1144
+ if (tagName === "Field_displayName") {
1145
+ displayName = trimmed;
1146
+ displayNameTag = tag;
1147
+ } else if (tagName === "Field_description") {
1148
+ description = trimmed;
1149
+ descriptionTag = tag;
1150
+ }
1151
+ }
1152
+ if (displayName !== void 0 && displayNameTag) {
1153
+ annotations.push({
1154
+ kind: "annotation",
1155
+ annotationKind: "displayName",
1156
+ value: displayName,
1157
+ provenance: provenanceForJSDocTag(displayNameTag, file)
1158
+ });
1159
+ }
1160
+ if (description !== void 0 && descriptionTag) {
1161
+ annotations.push({
1162
+ kind: "annotation",
1163
+ annotationKind: "description",
1164
+ value: description,
1165
+ provenance: provenanceForJSDocTag(descriptionTag, file)
1166
+ });
1167
+ }
1168
+ return { constraints, annotations };
1169
+ }
1170
+ function extractBlockText(block) {
1171
+ return extractPlainText(block.content);
1172
+ }
1173
+ function extractPlainText(node) {
1174
+ let result = "";
1175
+ if (node instanceof import_tsdoc.DocPlainText) {
1176
+ return node.text;
1177
+ }
1178
+ if (node instanceof import_tsdoc.DocSoftBreak) {
1179
+ return " ";
1180
+ }
1181
+ if (typeof node.getChildNodes === "function") {
1182
+ for (const child of node.getChildNodes()) {
1183
+ result += extractPlainText(child);
1184
+ }
1185
+ }
1186
+ return result;
1187
+ }
1188
+ function parseConstraintValue(tagName, text, provenance) {
1189
+ if (!isBuiltinConstraintName(tagName)) {
1190
+ return null;
1191
+ }
1192
+ const expectedType = import_core3.BUILTIN_CONSTRAINT_DEFINITIONS[tagName];
1193
+ if (expectedType === "number") {
1194
+ const value = Number(text);
1195
+ if (Number.isNaN(value)) {
1196
+ return null;
1197
+ }
1198
+ const numericKind = NUMERIC_CONSTRAINT_MAP[tagName];
1199
+ if (numericKind) {
1200
+ return {
1201
+ kind: "constraint",
1202
+ constraintKind: numericKind,
1203
+ value,
1204
+ provenance
1205
+ };
1206
+ }
1207
+ const lengthKind = LENGTH_CONSTRAINT_MAP[tagName];
1208
+ if (lengthKind) {
1209
+ return {
1210
+ kind: "constraint",
1211
+ constraintKind: lengthKind,
1212
+ value,
1213
+ provenance
1214
+ };
1215
+ }
1216
+ return null;
1217
+ }
1218
+ if (expectedType === "json") {
1219
+ try {
1220
+ const parsed = JSON.parse(text);
1221
+ if (!Array.isArray(parsed)) {
1222
+ return null;
1223
+ }
1224
+ const members = [];
1225
+ for (const item of parsed) {
1226
+ if (typeof item === "string" || typeof item === "number") {
1227
+ members.push(item);
1228
+ } else if (typeof item === "object" && item !== null && "id" in item) {
1229
+ const id = item["id"];
1230
+ if (typeof id === "string" || typeof id === "number") {
1231
+ members.push(id);
1232
+ }
1233
+ }
1234
+ }
1235
+ return {
1236
+ kind: "constraint",
1237
+ constraintKind: "allowedMembers",
1238
+ members,
1239
+ provenance
1240
+ };
1241
+ } catch {
1242
+ return null;
1243
+ }
1244
+ }
1245
+ return {
1246
+ kind: "constraint",
1247
+ constraintKind: "pattern",
1248
+ pattern: text,
1249
+ provenance
1250
+ };
1251
+ }
1252
+ function provenanceForComment(range, sourceFile, file, tagName) {
1253
+ const { line, character } = sourceFile.getLineAndCharacterOfPosition(range.pos);
1254
+ return {
1255
+ surface: "tsdoc",
1256
+ file,
1257
+ line: line + 1,
1258
+ column: character,
1259
+ tagName: "@" + tagName
1260
+ };
1261
+ }
1262
+ function provenanceForJSDocTag(tag, file) {
1263
+ const sourceFile = tag.getSourceFile();
1264
+ const { line, character } = sourceFile.getLineAndCharacterOfPosition(tag.getStart());
1265
+ return {
1266
+ surface: "tsdoc",
1267
+ file,
1268
+ line: line + 1,
1269
+ column: character,
1270
+ tagName: "@" + tag.tagName.text
1271
+ };
1272
+ }
1273
+ function getTagCommentText(tag) {
1274
+ if (tag.comment === void 0) {
1275
+ return void 0;
1276
+ }
1277
+ if (typeof tag.comment === "string") {
1278
+ return tag.comment;
1279
+ }
1280
+ return ts2.getTextOfJSDocComment(tag.comment);
1281
+ }
1282
+ var ts2, import_tsdoc, import_core3, NUMERIC_CONSTRAINT_MAP, LENGTH_CONSTRAINT_MAP, TAGS_REQUIRING_RAW_TEXT, sharedParser;
1283
+ var init_tsdoc_parser = __esm({
1284
+ "src/analyzer/tsdoc-parser.ts"() {
1285
+ "use strict";
1286
+ ts2 = __toESM(require("typescript"), 1);
1287
+ import_tsdoc = require("@microsoft/tsdoc");
1288
+ import_core3 = require("@formspec/core");
1289
+ NUMERIC_CONSTRAINT_MAP = {
1290
+ Minimum: "minimum",
1291
+ Maximum: "maximum",
1292
+ ExclusiveMinimum: "exclusiveMinimum",
1293
+ ExclusiveMaximum: "exclusiveMaximum"
1294
+ };
1295
+ LENGTH_CONSTRAINT_MAP = {
1296
+ MinLength: "minLength",
1297
+ MaxLength: "maxLength"
1298
+ };
1299
+ TAGS_REQUIRING_RAW_TEXT = /* @__PURE__ */ new Set(["Pattern", "EnumOptions"]);
1300
+ }
1301
+ });
1302
+
1303
+ // src/analyzer/jsdoc-constraints.ts
1304
+ function extractJSDocConstraintNodes(node, file = "") {
1305
+ const result = parseTSDocTags(node, file);
1306
+ return [...result.constraints];
1307
+ }
1308
+ function extractJSDocAnnotationNodes(node, file = "") {
1309
+ const result = parseTSDocTags(node, file);
1310
+ return [...result.annotations];
1311
+ }
1312
+ function extractDefaultValueAnnotation(initializer, file = "") {
1313
+ if (!initializer) return null;
1314
+ let value;
1315
+ if (ts3.isStringLiteral(initializer)) {
1316
+ value = initializer.text;
1317
+ } else if (ts3.isNumericLiteral(initializer)) {
1318
+ value = Number(initializer.text);
1319
+ } else if (initializer.kind === ts3.SyntaxKind.TrueKeyword) {
1320
+ value = true;
1321
+ } else if (initializer.kind === ts3.SyntaxKind.FalseKeyword) {
1322
+ value = false;
1323
+ } else if (initializer.kind === ts3.SyntaxKind.NullKeyword) {
1324
+ value = null;
1325
+ } else if (ts3.isPrefixUnaryExpression(initializer)) {
1326
+ if (initializer.operator === ts3.SyntaxKind.MinusToken && ts3.isNumericLiteral(initializer.operand)) {
1327
+ value = -Number(initializer.operand.text);
1328
+ }
1329
+ }
1330
+ if (value === void 0) return null;
1331
+ const sourceFile = initializer.getSourceFile();
1332
+ const { line, character } = sourceFile.getLineAndCharacterOfPosition(initializer.getStart());
1333
+ return {
1334
+ kind: "annotation",
1335
+ annotationKind: "defaultValue",
1336
+ value,
1337
+ provenance: {
1338
+ surface: "tsdoc",
1339
+ file,
1340
+ line: line + 1,
1341
+ column: character
1342
+ }
1343
+ };
1344
+ }
1345
+ var ts3, import_core4;
1346
+ var init_jsdoc_constraints = __esm({
1347
+ "src/analyzer/jsdoc-constraints.ts"() {
1348
+ "use strict";
1349
+ ts3 = __toESM(require("typescript"), 1);
1350
+ import_core4 = require("@formspec/core");
1351
+ init_tsdoc_parser();
1352
+ }
1353
+ });
1354
+
1355
+ // src/analyzer/class-analyzer.ts
1356
+ function isObjectType(type) {
1357
+ return !!(type.flags & ts4.TypeFlags.Object);
1358
+ }
1359
+ function isTypeReference(type) {
1360
+ return !!(type.flags & ts4.TypeFlags.Object) && !!(type.objectFlags & ts4.ObjectFlags.Reference);
1361
+ }
1362
+ function analyzeClassToIR(classDecl, checker, file = "") {
1363
+ const name = classDecl.name?.text ?? "AnonymousClass";
1364
+ const fields = [];
1365
+ const fieldLayouts = [];
1366
+ const typeRegistry = {};
1367
+ const visiting = /* @__PURE__ */ new Set();
1368
+ const instanceMethods = [];
1369
+ const staticMethods = [];
1370
+ for (const member of classDecl.members) {
1371
+ if (ts4.isPropertyDeclaration(member)) {
1372
+ const fieldNode = analyzeFieldToIR(member, checker, file, typeRegistry, visiting);
1373
+ if (fieldNode) {
1374
+ fields.push(fieldNode);
1375
+ fieldLayouts.push({});
1376
+ }
1377
+ } else if (ts4.isMethodDeclaration(member)) {
1378
+ const methodInfo = analyzeMethod(member, checker);
1379
+ if (methodInfo) {
1380
+ const isStatic = member.modifiers?.some((m) => m.kind === ts4.SyntaxKind.StaticKeyword);
1381
+ if (isStatic) {
1382
+ staticMethods.push(methodInfo);
1383
+ } else {
1384
+ instanceMethods.push(methodInfo);
1385
+ }
1386
+ }
1387
+ }
1388
+ }
1389
+ return { name, fields, fieldLayouts, typeRegistry, instanceMethods, staticMethods };
1390
+ }
1391
+ function analyzeInterfaceToIR(interfaceDecl, checker, file = "") {
1392
+ const name = interfaceDecl.name.text;
1393
+ const fields = [];
1394
+ const typeRegistry = {};
1395
+ const visiting = /* @__PURE__ */ new Set();
1396
+ for (const member of interfaceDecl.members) {
1397
+ if (ts4.isPropertySignature(member)) {
1398
+ const fieldNode = analyzeInterfacePropertyToIR(member, checker, file, typeRegistry, visiting);
1399
+ if (fieldNode) {
1400
+ fields.push(fieldNode);
1401
+ }
1402
+ }
1403
+ }
1404
+ const fieldLayouts = fields.map(() => ({}));
1405
+ return { name, fields, fieldLayouts, typeRegistry, instanceMethods: [], staticMethods: [] };
1406
+ }
1407
+ function analyzeTypeAliasToIR(typeAlias, checker, file = "") {
1408
+ if (!ts4.isTypeLiteralNode(typeAlias.type)) {
1409
+ const sourceFile = typeAlias.getSourceFile();
1410
+ const { line } = sourceFile.getLineAndCharacterOfPosition(typeAlias.getStart());
1411
+ const kindDesc = ts4.SyntaxKind[typeAlias.type.kind] ?? "unknown";
1412
+ return {
1413
+ ok: false,
1414
+ error: `Type alias "${typeAlias.name.text}" at line ${String(line + 1)} is not an object type literal (found ${kindDesc})`
1415
+ };
1416
+ }
1417
+ const name = typeAlias.name.text;
1418
+ const fields = [];
1419
+ const typeRegistry = {};
1420
+ const visiting = /* @__PURE__ */ new Set();
1421
+ for (const member of typeAlias.type.members) {
1422
+ if (ts4.isPropertySignature(member)) {
1423
+ const fieldNode = analyzeInterfacePropertyToIR(member, checker, file, typeRegistry, visiting);
1424
+ if (fieldNode) {
1425
+ fields.push(fieldNode);
1426
+ }
1427
+ }
1428
+ }
1429
+ return {
1430
+ ok: true,
1431
+ analysis: {
1432
+ name,
1433
+ fields,
1434
+ fieldLayouts: fields.map(() => ({})),
1435
+ typeRegistry,
1436
+ instanceMethods: [],
1437
+ staticMethods: []
1438
+ }
1439
+ };
1440
+ }
1441
+ function analyzeFieldToIR(prop, checker, file, typeRegistry, visiting) {
1442
+ if (!ts4.isIdentifier(prop.name)) {
1443
+ return null;
1444
+ }
1445
+ const name = prop.name.text;
1446
+ const tsType = checker.getTypeAtLocation(prop);
1447
+ const optional = prop.questionToken !== void 0;
1448
+ const provenance = provenanceForNode(prop, file);
1449
+ const type = resolveTypeNode(tsType, checker, file, typeRegistry, visiting);
1450
+ const constraints = [];
1451
+ if (prop.type) {
1452
+ constraints.push(...extractTypeAliasConstraintNodes(prop.type, checker, file));
1453
+ }
1454
+ constraints.push(...extractJSDocConstraintNodes(prop, file));
1455
+ const annotations = [];
1456
+ annotations.push(...extractJSDocAnnotationNodes(prop, file));
1457
+ const defaultAnnotation = extractDefaultValueAnnotation(prop.initializer, file);
1458
+ if (defaultAnnotation) {
1459
+ annotations.push(defaultAnnotation);
1460
+ }
1461
+ return {
1462
+ kind: "field",
1463
+ name,
1464
+ type,
1465
+ required: !optional,
1466
+ constraints,
1467
+ annotations,
1468
+ provenance
1469
+ };
1470
+ }
1471
+ function analyzeInterfacePropertyToIR(prop, checker, file, typeRegistry, visiting) {
1472
+ if (!ts4.isIdentifier(prop.name)) {
1473
+ return null;
1474
+ }
1475
+ const name = prop.name.text;
1476
+ const tsType = checker.getTypeAtLocation(prop);
1477
+ const optional = prop.questionToken !== void 0;
1478
+ const provenance = provenanceForNode(prop, file);
1479
+ const type = resolveTypeNode(tsType, checker, file, typeRegistry, visiting);
1480
+ const constraints = [];
1481
+ if (prop.type) {
1482
+ constraints.push(...extractTypeAliasConstraintNodes(prop.type, checker, file));
1483
+ }
1484
+ constraints.push(...extractJSDocConstraintNodes(prop, file));
1485
+ const annotations = [];
1486
+ annotations.push(...extractJSDocAnnotationNodes(prop, file));
1487
+ return {
1488
+ kind: "field",
1489
+ name,
1490
+ type,
1491
+ required: !optional,
1492
+ constraints,
1493
+ annotations,
1494
+ provenance
1495
+ };
1496
+ }
1497
+ function resolveTypeNode(type, checker, file, typeRegistry, visiting) {
1498
+ if (type.flags & ts4.TypeFlags.String) {
1499
+ return { kind: "primitive", primitiveKind: "string" };
1500
+ }
1501
+ if (type.flags & ts4.TypeFlags.Number) {
1502
+ return { kind: "primitive", primitiveKind: "number" };
1503
+ }
1504
+ if (type.flags & ts4.TypeFlags.Boolean) {
1505
+ return { kind: "primitive", primitiveKind: "boolean" };
1506
+ }
1507
+ if (type.flags & ts4.TypeFlags.Null) {
1508
+ return { kind: "primitive", primitiveKind: "null" };
1509
+ }
1510
+ if (type.flags & ts4.TypeFlags.Undefined) {
1511
+ return { kind: "primitive", primitiveKind: "null" };
1512
+ }
1513
+ if (type.isStringLiteral()) {
1514
+ return {
1515
+ kind: "enum",
1516
+ members: [{ value: type.value }]
1517
+ };
1518
+ }
1519
+ if (type.isNumberLiteral()) {
1520
+ return {
1521
+ kind: "enum",
1522
+ members: [{ value: type.value }]
1523
+ };
1524
+ }
1525
+ if (type.isUnion()) {
1526
+ return resolveUnionType(type, checker, file, typeRegistry, visiting);
1527
+ }
1528
+ if (checker.isArrayType(type)) {
1529
+ return resolveArrayType(type, checker, file, typeRegistry, visiting);
1530
+ }
1531
+ if (isObjectType(type)) {
1532
+ return resolveObjectType(type, checker, file, typeRegistry, visiting);
1533
+ }
1534
+ return { kind: "primitive", primitiveKind: "string" };
1535
+ }
1536
+ function resolveUnionType(type, checker, file, typeRegistry, visiting) {
1537
+ const allTypes = type.types;
1538
+ const nonNullTypes = allTypes.filter(
1539
+ (t) => !(t.flags & (ts4.TypeFlags.Null | ts4.TypeFlags.Undefined))
1540
+ );
1541
+ const hasNull = allTypes.some((t) => t.flags & ts4.TypeFlags.Null);
1542
+ const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags & ts4.TypeFlags.BooleanLiteral);
1543
+ if (isBooleanUnion2) {
1544
+ const boolNode = { kind: "primitive", primitiveKind: "boolean" };
1545
+ if (hasNull) {
1546
+ return {
1547
+ kind: "union",
1548
+ members: [boolNode, { kind: "primitive", primitiveKind: "null" }]
1549
+ };
1550
+ }
1551
+ return boolNode;
1552
+ }
1553
+ const allStringLiterals = nonNullTypes.every((t) => t.isStringLiteral());
1554
+ if (allStringLiterals && nonNullTypes.length > 0) {
1555
+ const stringTypes = nonNullTypes.filter((t) => t.isStringLiteral());
1556
+ const enumNode = {
1557
+ kind: "enum",
1558
+ members: stringTypes.map((t) => ({ value: t.value }))
1559
+ };
1560
+ if (hasNull) {
1561
+ return {
1562
+ kind: "union",
1563
+ members: [enumNode, { kind: "primitive", primitiveKind: "null" }]
1564
+ };
1565
+ }
1566
+ return enumNode;
1567
+ }
1568
+ const allNumberLiterals = nonNullTypes.every((t) => t.isNumberLiteral());
1569
+ if (allNumberLiterals && nonNullTypes.length > 0) {
1570
+ const numberTypes = nonNullTypes.filter((t) => t.isNumberLiteral());
1571
+ const enumNode = {
1572
+ kind: "enum",
1573
+ members: numberTypes.map((t) => ({ value: t.value }))
1574
+ };
1575
+ if (hasNull) {
1576
+ return {
1577
+ kind: "union",
1578
+ members: [enumNode, { kind: "primitive", primitiveKind: "null" }]
1579
+ };
1580
+ }
1581
+ return enumNode;
1582
+ }
1583
+ if (nonNullTypes.length === 1 && nonNullTypes[0]) {
1584
+ const inner = resolveTypeNode(nonNullTypes[0], checker, file, typeRegistry, visiting);
1585
+ if (hasNull) {
1586
+ return {
1587
+ kind: "union",
1588
+ members: [inner, { kind: "primitive", primitiveKind: "null" }]
1589
+ };
1590
+ }
1591
+ return inner;
1592
+ }
1593
+ const members = nonNullTypes.map(
1594
+ (t) => resolveTypeNode(t, checker, file, typeRegistry, visiting)
1595
+ );
1596
+ if (hasNull) {
1597
+ members.push({ kind: "primitive", primitiveKind: "null" });
1598
+ }
1599
+ return { kind: "union", members };
1600
+ }
1601
+ function resolveArrayType(type, checker, file, typeRegistry, visiting) {
1602
+ const typeArgs = isTypeReference(type) ? type.typeArguments : void 0;
1603
+ const elementType = typeArgs?.[0];
1604
+ const items = elementType ? resolveTypeNode(elementType, checker, file, typeRegistry, visiting) : { kind: "primitive", primitiveKind: "string" };
1605
+ return { kind: "array", items };
1606
+ }
1607
+ function resolveObjectType(type, checker, file, typeRegistry, visiting) {
1608
+ if (visiting.has(type)) {
1609
+ return { kind: "object", properties: [], additionalProperties: false };
1610
+ }
1611
+ visiting.add(type);
1612
+ const typeName = getNamedTypeName(type);
1613
+ if (typeName && typeName in typeRegistry) {
1614
+ visiting.delete(type);
1615
+ return { kind: "reference", name: typeName, typeArguments: [] };
1616
+ }
1617
+ const properties = [];
1618
+ const fieldInfoMap = getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visiting);
1619
+ for (const prop of type.getProperties()) {
1620
+ const declaration = prop.valueDeclaration ?? prop.declarations?.[0];
1621
+ if (!declaration) continue;
1622
+ const propType = checker.getTypeOfSymbolAtLocation(prop, declaration);
1623
+ const optional = !!(prop.flags & ts4.SymbolFlags.Optional);
1624
+ const propTypeNode = resolveTypeNode(propType, checker, file, typeRegistry, visiting);
1625
+ const fieldNodeInfo = fieldInfoMap?.get(prop.name);
1626
+ properties.push({
1627
+ name: prop.name,
1628
+ type: propTypeNode,
1629
+ optional,
1630
+ constraints: fieldNodeInfo?.constraints ?? [],
1631
+ annotations: fieldNodeInfo?.annotations ?? [],
1632
+ provenance: fieldNodeInfo?.provenance ?? provenanceForFile(file)
1633
+ });
1634
+ }
1635
+ visiting.delete(type);
1636
+ const objectNode = {
1637
+ kind: "object",
1638
+ properties,
1639
+ additionalProperties: false
1640
+ };
1641
+ if (typeName) {
1642
+ typeRegistry[typeName] = {
1643
+ name: typeName,
1644
+ type: objectNode,
1645
+ provenance: provenanceForFile(file)
1646
+ };
1647
+ return { kind: "reference", name: typeName, typeArguments: [] };
1648
+ }
1649
+ return objectNode;
1650
+ }
1651
+ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visiting) {
1652
+ const symbols = [type.getSymbol(), type.aliasSymbol].filter(
1653
+ (s) => s?.declarations != null && s.declarations.length > 0
1654
+ );
1655
+ for (const symbol of symbols) {
1656
+ const declarations = symbol.declarations;
1657
+ if (!declarations) continue;
1658
+ const classDecl = declarations.find(ts4.isClassDeclaration);
1659
+ if (classDecl) {
1660
+ const map = /* @__PURE__ */ new Map();
1661
+ for (const member of classDecl.members) {
1662
+ if (ts4.isPropertyDeclaration(member) && ts4.isIdentifier(member.name)) {
1663
+ const fieldNode = analyzeFieldToIR(member, checker, file, typeRegistry, visiting);
1664
+ if (fieldNode) {
1665
+ map.set(fieldNode.name, {
1666
+ constraints: [...fieldNode.constraints],
1667
+ annotations: [...fieldNode.annotations],
1668
+ provenance: fieldNode.provenance
1669
+ });
1670
+ }
1671
+ }
1672
+ }
1673
+ return map;
1674
+ }
1675
+ const interfaceDecl = declarations.find(ts4.isInterfaceDeclaration);
1676
+ if (interfaceDecl) {
1677
+ return buildFieldNodeInfoMap(interfaceDecl.members, checker, file, typeRegistry, visiting);
1678
+ }
1679
+ const typeAliasDecl = declarations.find(ts4.isTypeAliasDeclaration);
1680
+ if (typeAliasDecl && ts4.isTypeLiteralNode(typeAliasDecl.type)) {
1681
+ return buildFieldNodeInfoMap(
1682
+ typeAliasDecl.type.members,
1683
+ checker,
1684
+ file,
1685
+ typeRegistry,
1686
+ visiting
1687
+ );
1688
+ }
1689
+ }
1690
+ return null;
1691
+ }
1692
+ function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting) {
1693
+ const map = /* @__PURE__ */ new Map();
1694
+ for (const member of members) {
1695
+ if (ts4.isPropertySignature(member)) {
1696
+ const fieldNode = analyzeInterfacePropertyToIR(member, checker, file, typeRegistry, visiting);
1697
+ if (fieldNode) {
1698
+ map.set(fieldNode.name, {
1699
+ constraints: [...fieldNode.constraints],
1700
+ annotations: [...fieldNode.annotations],
1701
+ provenance: fieldNode.provenance
1702
+ });
1703
+ }
1704
+ }
1705
+ }
1706
+ return map;
1707
+ }
1708
+ function extractTypeAliasConstraintNodes(typeNode, checker, file) {
1709
+ if (!ts4.isTypeReferenceNode(typeNode)) return [];
1710
+ const symbol = checker.getSymbolAtLocation(typeNode.typeName);
1711
+ if (!symbol?.declarations) return [];
1712
+ const aliasDecl = symbol.declarations.find(ts4.isTypeAliasDeclaration);
1713
+ if (!aliasDecl) return [];
1714
+ if (ts4.isTypeLiteralNode(aliasDecl.type)) return [];
1715
+ return extractJSDocConstraintNodes(aliasDecl, file);
1716
+ }
1717
+ function provenanceForNode(node, file) {
1718
+ const sourceFile = node.getSourceFile();
1719
+ const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
1720
+ return {
1721
+ surface: "tsdoc",
1722
+ file,
1723
+ line: line + 1,
1724
+ column: character
1725
+ };
1726
+ }
1727
+ function provenanceForFile(file) {
1728
+ return { surface: "tsdoc", file, line: 0, column: 0 };
1729
+ }
1730
+ function getNamedTypeName(type) {
1731
+ const symbol = type.getSymbol();
1732
+ if (symbol?.declarations) {
1733
+ const decl = symbol.declarations[0];
1734
+ if (decl && (ts4.isClassDeclaration(decl) || ts4.isInterfaceDeclaration(decl) || ts4.isTypeAliasDeclaration(decl))) {
1735
+ const name = ts4.isClassDeclaration(decl) ? decl.name?.text : decl.name.text;
1736
+ if (name) return name;
1737
+ }
1738
+ }
1739
+ const aliasSymbol = type.aliasSymbol;
1740
+ if (aliasSymbol?.declarations) {
1741
+ const aliasDecl = aliasSymbol.declarations.find(ts4.isTypeAliasDeclaration);
1742
+ if (aliasDecl) {
1743
+ return aliasDecl.name.text;
1744
+ }
1745
+ }
1746
+ return null;
1747
+ }
1748
+ function analyzeMethod(method, checker) {
1749
+ if (!ts4.isIdentifier(method.name)) {
1750
+ return null;
1751
+ }
1752
+ const name = method.name.text;
1753
+ const parameters = [];
1754
+ for (const param of method.parameters) {
1755
+ if (ts4.isIdentifier(param.name)) {
1756
+ const paramInfo = analyzeParameter(param, checker);
1757
+ parameters.push(paramInfo);
1758
+ }
1759
+ }
1760
+ const returnTypeNode = method.type;
1761
+ const signature = checker.getSignatureFromDeclaration(method);
1762
+ const returnType = signature ? checker.getReturnTypeOfSignature(signature) : checker.getTypeAtLocation(method);
1763
+ return { name, parameters, returnTypeNode, returnType };
1764
+ }
1765
+ function analyzeParameter(param, checker) {
1766
+ const name = ts4.isIdentifier(param.name) ? param.name.text : "param";
1767
+ const typeNode = param.type;
1768
+ const type = checker.getTypeAtLocation(param);
1769
+ const formSpecExportName = detectFormSpecReference(typeNode);
1770
+ const optional = param.questionToken !== void 0 || param.initializer !== void 0;
1771
+ return { name, typeNode, type, formSpecExportName, optional };
1772
+ }
1773
+ function detectFormSpecReference(typeNode) {
1774
+ if (!typeNode) return null;
1775
+ if (!ts4.isTypeReferenceNode(typeNode)) return null;
1776
+ const typeName = ts4.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : ts4.isQualifiedName(typeNode.typeName) ? typeNode.typeName.right.text : null;
1777
+ if (typeName !== "InferSchema" && typeName !== "InferFormSchema") return null;
1778
+ const typeArg = typeNode.typeArguments?.[0];
1779
+ if (!typeArg || !ts4.isTypeQueryNode(typeArg)) return null;
1780
+ if (ts4.isIdentifier(typeArg.exprName)) {
1781
+ return typeArg.exprName.text;
1782
+ }
1783
+ if (ts4.isQualifiedName(typeArg.exprName)) {
1784
+ return typeArg.exprName.right.text;
1785
+ }
1786
+ return null;
1787
+ }
1788
+ var ts4;
1789
+ var init_class_analyzer = __esm({
1790
+ "src/analyzer/class-analyzer.ts"() {
1791
+ "use strict";
1792
+ ts4 = __toESM(require("typescript"), 1);
1793
+ init_jsdoc_constraints();
1794
+ }
1795
+ });
1796
+
1797
+ // src/generators/class-schema.ts
1798
+ function generateClassSchemas(analysis, source) {
1799
+ const ir = canonicalizeTSDoc(analysis, source);
1800
+ return {
1801
+ jsonSchema: generateJsonSchemaFromIR(ir),
1802
+ uiSchema: generateUiSchemaFromIR(ir)
1803
+ };
1804
+ }
1805
+ function generateSchemasFromClass(options) {
1806
+ const ctx = createProgramContext(options.filePath);
1807
+ const classDecl = findClassByName(ctx.sourceFile, options.className);
1808
+ if (!classDecl) {
1809
+ throw new Error(`Class "${options.className}" not found in ${options.filePath}`);
1810
+ }
1811
+ const analysis = analyzeClassToIR(classDecl, ctx.checker, options.filePath);
1812
+ return generateClassSchemas(analysis, { file: options.filePath });
1813
+ }
1814
+ function generateSchemas(options) {
1815
+ const ctx = createProgramContext(options.filePath);
1816
+ const source = { file: options.filePath };
1817
+ const classDecl = findClassByName(ctx.sourceFile, options.typeName);
1818
+ if (classDecl) {
1819
+ const analysis = analyzeClassToIR(classDecl, ctx.checker, options.filePath);
1820
+ return generateClassSchemas(analysis, source);
1821
+ }
1822
+ const interfaceDecl = findInterfaceByName(ctx.sourceFile, options.typeName);
1823
+ if (interfaceDecl) {
1824
+ const analysis = analyzeInterfaceToIR(interfaceDecl, ctx.checker, options.filePath);
1825
+ return generateClassSchemas(analysis, source);
1826
+ }
1827
+ const typeAlias = findTypeAliasByName(ctx.sourceFile, options.typeName);
1828
+ if (typeAlias) {
1829
+ const result = analyzeTypeAliasToIR(typeAlias, ctx.checker, options.filePath);
1830
+ if (result.ok) {
1831
+ return generateClassSchemas(result.analysis, source);
1832
+ }
1833
+ throw new Error(result.error);
1834
+ }
1835
+ throw new Error(
1836
+ `Type "${options.typeName}" not found as a class, interface, or type alias in ${options.filePath}`
1837
+ );
1838
+ }
1839
+ var init_class_schema = __esm({
1840
+ "src/generators/class-schema.ts"() {
1841
+ "use strict";
1842
+ init_program();
1843
+ init_class_analyzer();
1844
+ init_canonicalize();
1845
+ init_ir_generator();
1846
+ init_ir_generator2();
1847
+ }
1848
+ });
1849
+
1850
+ // src/index.ts
1851
+ var index_exports = {};
1852
+ __export(index_exports, {
1853
+ buildFormSchemas: () => buildFormSchemas,
1854
+ categorizationSchema: () => categorizationSchema,
1855
+ categorySchema: () => categorySchema,
1856
+ controlSchema: () => controlSchema,
1857
+ generateJsonSchema: () => generateJsonSchema,
1858
+ generateSchemas: () => generateSchemas,
1859
+ generateSchemasFromClass: () => generateSchemasFromClass,
1860
+ generateUiSchema: () => generateUiSchema,
1861
+ getSchemaExtension: () => getSchemaExtension,
1862
+ groupLayoutSchema: () => groupLayoutSchema,
1863
+ horizontalLayoutSchema: () => horizontalLayoutSchema,
1864
+ jsonSchema7Schema: () => jsonSchema7Schema,
1865
+ jsonSchemaTypeSchema: () => jsonSchemaTypeSchema,
1866
+ labelElementSchema: () => labelElementSchema,
1867
+ ruleConditionSchema: () => ruleConditionSchema,
1868
+ ruleEffectSchema: () => ruleEffectSchema,
1869
+ ruleSchema: () => ruleSchema,
1870
+ schemaBasedConditionSchema: () => schemaBasedConditionSchema,
1871
+ setSchemaExtension: () => setSchemaExtension,
1872
+ uiSchemaElementSchema: () => uiSchemaElementSchema,
1873
+ uiSchemaElementTypeSchema: () => uiSchemaElementTypeSchema,
1874
+ uiSchemaSchema: () => uiSchema,
1875
+ verticalLayoutSchema: () => verticalLayoutSchema,
1876
+ writeSchemas: () => writeSchemas
1877
+ });
1878
+ function buildFormSchemas(form) {
1879
+ return {
1880
+ jsonSchema: generateJsonSchema(form),
1881
+ uiSchema: generateUiSchema(form)
1882
+ };
1883
+ }
1884
+ function writeSchemas(form, options) {
1885
+ const { outDir, name = "schema", indent = 2 } = options;
1886
+ const { jsonSchema, uiSchema: uiSchema2 } = buildFormSchemas(form);
1887
+ if (!fs.existsSync(outDir)) {
1888
+ fs.mkdirSync(outDir, { recursive: true });
1889
+ }
1890
+ const jsonSchemaPath = path2.join(outDir, `${name}-schema.json`);
1891
+ const uiSchemaPath = path2.join(outDir, `${name}-uischema.json`);
1892
+ fs.writeFileSync(jsonSchemaPath, JSON.stringify(jsonSchema, null, indent));
1893
+ fs.writeFileSync(uiSchemaPath, JSON.stringify(uiSchema2, null, indent));
1894
+ return { jsonSchemaPath, uiSchemaPath };
1895
+ }
1896
+ var fs, path2;
1897
+ var init_index = __esm({
1898
+ "src/index.ts"() {
1899
+ "use strict";
1900
+ init_generator();
1901
+ init_generator2();
1902
+ fs = __toESM(require("fs"), 1);
1903
+ path2 = __toESM(require("path"), 1);
1904
+ init_types();
1905
+ init_schema();
1906
+ init_schema2();
1907
+ init_generator();
1908
+ init_generator2();
1909
+ init_class_schema();
1910
+ }
1911
+ });
1912
+
1913
+ // src/cli.ts
1914
+ var path3 = __toESM(require("path"), 1);
1915
+ var import_node_url = require("url");
1916
+ function printHelp() {
1917
+ console.log(`
1918
+ FormSpec Build CLI - Generate JSON Schema and UI Schema
1919
+
1920
+ Usage:
1921
+ formspec-build <input-file> [options]
1922
+
1923
+ Options:
1924
+ -o, --out-dir <dir> Output directory (default: ./generated)
1925
+ -n, --name <name> Base name for output files (default: derived from input)
1926
+ -h, --help Show this help message
1927
+
1928
+ Example:
1929
+ formspec-build src/forms/product.ts -o ./schemas -n product
1930
+
1931
+ The input file should export a FormSpec as its default export or as 'form':
1932
+ // product-form.ts
1933
+ import { formspec, field } from "formspec";
1934
+ export default formspec(field.text("name"));
1935
+ // or: export const form = formspec(field.text("name"));
1936
+ `);
1937
+ }
1938
+ function parseArgs(args) {
1939
+ const positional = [];
1940
+ let outDir = "./generated";
1941
+ let name = "";
1942
+ for (let i = 0; i < args.length; i++) {
1943
+ const arg = args[i];
1944
+ if (arg === void 0) continue;
1945
+ if (arg === "-h" || arg === "--help") {
1946
+ printHelp();
1947
+ process.exit(0);
1948
+ }
1949
+ if (arg === "-o" || arg === "--out-dir") {
1950
+ const nextArg = args[i + 1];
1951
+ if (!nextArg) {
1952
+ console.error("Error: --out-dir requires a value");
1953
+ return null;
1954
+ }
1955
+ outDir = nextArg;
1956
+ i++;
1957
+ continue;
1958
+ }
1959
+ if (arg === "-n" || arg === "--name") {
1960
+ const nextArg = args[i + 1];
1961
+ if (!nextArg) {
1962
+ console.error("Error: --name requires a value");
1963
+ return null;
1964
+ }
1965
+ name = nextArg;
1966
+ i++;
1967
+ continue;
1968
+ }
1969
+ if (arg.startsWith("-")) {
1970
+ console.error(`Error: Unknown option: ${arg}`);
1971
+ return null;
1972
+ }
1973
+ positional.push(arg);
1974
+ }
1975
+ if (positional.length === 0) {
1976
+ console.error("Error: No input file specified");
1977
+ printHelp();
1978
+ return null;
1979
+ }
1980
+ const inputFile = positional[0];
1981
+ if (!inputFile) {
1982
+ console.error("Error: No input file specified");
1983
+ return null;
1984
+ }
1985
+ if (!name) {
1986
+ name = path3.basename(inputFile, path3.extname(inputFile));
1987
+ }
1988
+ return { inputFile, outDir, name };
1989
+ }
1990
+ async function main() {
1991
+ const args = process.argv.slice(2);
1992
+ const options = parseArgs(args);
1993
+ if (!options) {
1994
+ process.exit(1);
1995
+ }
1996
+ const { inputFile, outDir, name } = options;
1997
+ const absoluteInput = path3.resolve(process.cwd(), inputFile);
1998
+ try {
1999
+ const fileUrl = (0, import_node_url.pathToFileURL)(absoluteInput).href;
2000
+ const module2 = await import(fileUrl);
2001
+ const form = module2["default"] ?? module2["form"];
2002
+ if (!form || typeof form !== "object" || !("elements" in form)) {
2003
+ console.error("Error: Input file must export a FormSpec as default export or as 'form'");
2004
+ console.error("Example:");
2005
+ console.error(' export default formspec(field.text("name"));');
2006
+ console.error(" // or");
2007
+ console.error(' export const form = formspec(field.text("name"));');
2008
+ process.exit(1);
2009
+ }
2010
+ const { writeSchemas: writeSchemas2 } = await Promise.resolve().then(() => (init_index(), index_exports));
2011
+ const { jsonSchemaPath, uiSchemaPath } = writeSchemas2(
2012
+ form,
2013
+ { outDir, name }
2014
+ );
2015
+ console.log("Generated:");
2016
+ console.log(` ${jsonSchemaPath}`);
2017
+ console.log(` ${uiSchemaPath}`);
2018
+ } catch (error) {
2019
+ if (error instanceof Error) {
2020
+ console.error(`Error: ${error.message}`);
2021
+ } else {
2022
+ console.error("Error:", error);
2023
+ }
2024
+ process.exit(1);
2025
+ }
2026
+ }
2027
+ void main();
2028
+ //# sourceMappingURL=cli.cjs.map