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