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

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.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/canonicalize/chain-dsl-canonicalizer.ts","../src/canonicalize/tsdoc-canonicalizer.ts","../src/json-schema/ir-generator.ts","../src/json-schema/generator.ts","../src/ui-schema/schema.ts","../src/ui-schema/ir-generator.ts","../src/ui-schema/generator.ts","../src/index.ts","../src/json-schema/types.ts","../src/json-schema/schema.ts","../src/analyzer/program.ts","../src/analyzer/class-analyzer.ts","../src/analyzer/jsdoc-constraints.ts","../src/analyzer/tsdoc-parser.ts","../src/generators/class-schema.ts"],"sourcesContent":["/**\n * Canonicalizer that translates chain DSL `FormSpec` objects into the\n * canonical FormIR intermediate representation.\n *\n * This module maps the runtime objects produced by `@formspec/dsl` builder\n * functions (`field.*`, `group`, `when`, `formspec`) into the IR that all\n * downstream phases (validation, JSON Schema generation, UI Schema generation)\n * consume.\n */\n\nimport type {\n // Source types (chain DSL)\n AnyField,\n ArrayField,\n BooleanField,\n Conditional,\n DynamicEnumField,\n DynamicSchemaField,\n EnumOptionValue,\n FormElement,\n FormSpec,\n Group,\n NumberField,\n ObjectField,\n StaticEnumField,\n TextField,\n // IR types\n JsonValue,\n AnnotationNode,\n ArrayTypeNode,\n ConstraintNode,\n ConditionalLayoutNode,\n DisplayNameAnnotationNode,\n DynamicTypeNode,\n EnumMember,\n EnumTypeNode,\n FieldNode,\n FormIR,\n FormIRElement,\n GroupLayoutNode,\n LengthConstraintNode,\n NumericConstraintNode,\n ObjectProperty,\n ObjectTypeNode,\n PlaceholderAnnotationNode,\n PrimitiveTypeNode,\n Provenance,\n TypeNode,\n} from \"@formspec/core\";\nimport { IR_VERSION } from \"@formspec/core\";\n\n// =============================================================================\n// CONSTANTS\n// =============================================================================\n\n/** Default provenance for chain DSL nodes (no source location available). */\nconst CHAIN_DSL_PROVENANCE: Provenance = {\n surface: \"chain-dsl\",\n file: \"\",\n line: 0,\n column: 0,\n} as const;\n\n// =============================================================================\n// TYPE GUARDS\n// =============================================================================\n\nfunction isGroup(el: FormElement): el is Group<readonly FormElement[]> {\n return el._type === \"group\";\n}\n\nfunction isConditional(\n el: FormElement\n): el is Conditional<string, unknown, readonly FormElement[]> {\n return el._type === \"conditional\";\n}\n\nfunction isField(el: FormElement): el is AnyField {\n return el._type === \"field\";\n}\n\n// =============================================================================\n// PUBLIC API\n// =============================================================================\n\n/**\n * Translates a chain DSL `FormSpec` into the canonical `FormIR`.\n *\n * @param form - A form specification created via `formspec(...)` from `@formspec/dsl`\n * @returns The canonical intermediate representation\n */\nexport function canonicalizeChainDSL(form: FormSpec<readonly FormElement[]>): FormIR {\n return {\n kind: \"form-ir\",\n irVersion: IR_VERSION,\n elements: canonicalizeElements(form.elements),\n typeRegistry: {},\n provenance: CHAIN_DSL_PROVENANCE,\n };\n}\n\n// =============================================================================\n// ELEMENT CANONICALIZATION\n// =============================================================================\n\n/**\n * Canonicalizes an array of chain DSL form elements into IR elements.\n */\nfunction canonicalizeElements(elements: readonly FormElement[]): FormIRElement[] {\n return elements.map(canonicalizeElement);\n}\n\n/**\n * Dispatches a single form element to its specific canonicalization function.\n */\nfunction canonicalizeElement(element: FormElement): FormIRElement {\n if (isField(element)) {\n return canonicalizeField(element);\n }\n if (isGroup(element)) {\n return canonicalizeGroup(element);\n }\n if (isConditional(element)) {\n return canonicalizeConditional(element);\n }\n const _exhaustive: never = element;\n throw new Error(`Unknown element type: ${JSON.stringify(_exhaustive)}`);\n}\n\n// =============================================================================\n// FIELD CANONICALIZATION\n// =============================================================================\n\n/**\n * Dispatches a field element to its type-specific canonicalization function.\n */\nfunction canonicalizeField(field: AnyField): FieldNode {\n switch (field._field) {\n case \"text\":\n return canonicalizeTextField(field);\n case \"number\":\n return canonicalizeNumberField(field);\n case \"boolean\":\n return canonicalizeBooleanField(field);\n case \"enum\":\n return canonicalizeStaticEnumField(field);\n case \"dynamic_enum\":\n return canonicalizeDynamicEnumField(field);\n case \"dynamic_schema\":\n return canonicalizeDynamicSchemaField(field);\n case \"array\":\n return canonicalizeArrayField(field);\n case \"object\":\n return canonicalizeObjectField(field);\n default: {\n const _exhaustive: never = field;\n throw new Error(`Unknown field type: ${JSON.stringify(_exhaustive)}`);\n }\n }\n}\n\n// =============================================================================\n// SPECIFIC FIELD TYPE CANONICALIZERS\n// =============================================================================\n\nfunction canonicalizeTextField(field: TextField<string>): FieldNode {\n const type: PrimitiveTypeNode = { kind: \"primitive\", primitiveKind: \"string\" };\n return buildFieldNode(\n field.name,\n type,\n field.required,\n buildAnnotations(field.label, field.placeholder)\n );\n}\n\nfunction canonicalizeNumberField(field: NumberField<string>): FieldNode {\n const type: PrimitiveTypeNode = { kind: \"primitive\", primitiveKind: \"number\" };\n const constraints: ConstraintNode[] = [];\n\n if (field.min !== undefined) {\n const c: NumericConstraintNode = {\n kind: \"constraint\",\n constraintKind: \"minimum\",\n value: field.min,\n provenance: CHAIN_DSL_PROVENANCE,\n };\n constraints.push(c);\n }\n\n if (field.max !== undefined) {\n const c: NumericConstraintNode = {\n kind: \"constraint\",\n constraintKind: \"maximum\",\n value: field.max,\n provenance: CHAIN_DSL_PROVENANCE,\n };\n constraints.push(c);\n }\n\n return buildFieldNode(\n field.name,\n type,\n field.required,\n buildAnnotations(field.label),\n constraints\n );\n}\n\nfunction canonicalizeBooleanField(field: BooleanField<string>): FieldNode {\n const type: PrimitiveTypeNode = { kind: \"primitive\", primitiveKind: \"boolean\" };\n return buildFieldNode(field.name, type, field.required, buildAnnotations(field.label));\n}\n\nfunction canonicalizeStaticEnumField(\n field: StaticEnumField<string, readonly EnumOptionValue[]>\n): FieldNode {\n const members: EnumMember[] = field.options.map((opt) => {\n if (typeof opt === \"string\") {\n return { value: opt } satisfies EnumMember;\n }\n // Object option with id/label\n return { value: opt.id, displayName: opt.label } satisfies EnumMember;\n });\n\n const type: EnumTypeNode = { kind: \"enum\", members };\n return buildFieldNode(field.name, type, field.required, buildAnnotations(field.label));\n}\n\nfunction canonicalizeDynamicEnumField(field: DynamicEnumField<string, string>): FieldNode {\n const type: DynamicTypeNode = {\n kind: \"dynamic\",\n dynamicKind: \"enum\",\n sourceKey: field.source,\n parameterFields: field.params ? [...field.params] : [],\n };\n return buildFieldNode(field.name, type, field.required, buildAnnotations(field.label));\n}\n\nfunction canonicalizeDynamicSchemaField(field: DynamicSchemaField<string>): FieldNode {\n const type: DynamicTypeNode = {\n kind: \"dynamic\",\n dynamicKind: \"schema\",\n sourceKey: field.schemaSource,\n parameterFields: [],\n };\n return buildFieldNode(field.name, type, field.required, buildAnnotations(field.label));\n}\n\nfunction canonicalizeArrayField(field: ArrayField<string, readonly FormElement[]>): FieldNode {\n // Array items form an object type from the sub-elements\n const itemProperties = buildObjectProperties(field.items);\n const itemsType: ObjectTypeNode = {\n kind: \"object\",\n properties: itemProperties,\n additionalProperties: false,\n };\n const type: ArrayTypeNode = { kind: \"array\", items: itemsType };\n\n const constraints: ConstraintNode[] = [];\n if (field.minItems !== undefined) {\n const c: LengthConstraintNode = {\n kind: \"constraint\",\n constraintKind: \"minItems\",\n value: field.minItems,\n provenance: CHAIN_DSL_PROVENANCE,\n };\n constraints.push(c);\n }\n if (field.maxItems !== undefined) {\n const c: LengthConstraintNode = {\n kind: \"constraint\",\n constraintKind: \"maxItems\",\n value: field.maxItems,\n provenance: CHAIN_DSL_PROVENANCE,\n };\n constraints.push(c);\n }\n\n return buildFieldNode(\n field.name,\n type,\n field.required,\n buildAnnotations(field.label),\n constraints\n );\n}\n\nfunction canonicalizeObjectField(field: ObjectField<string, readonly FormElement[]>): FieldNode {\n const properties = buildObjectProperties(field.properties);\n const type: ObjectTypeNode = {\n kind: \"object\",\n properties,\n additionalProperties: false,\n };\n return buildFieldNode(field.name, type, field.required, buildAnnotations(field.label));\n}\n\n// =============================================================================\n// LAYOUT CANONICALIZATION\n// =============================================================================\n\nfunction canonicalizeGroup(g: Group<readonly FormElement[]>): GroupLayoutNode {\n return {\n kind: \"group\",\n label: g.label,\n elements: canonicalizeElements(g.elements),\n provenance: CHAIN_DSL_PROVENANCE,\n };\n}\n\nfunction canonicalizeConditional(\n c: Conditional<string, unknown, readonly FormElement[]>\n): ConditionalLayoutNode {\n return {\n kind: \"conditional\",\n fieldName: c.field,\n // Conditional values from the chain DSL are JSON-serializable primitives\n // (strings, numbers, booleans) produced by the `is()` predicate helper.\n value: assertJsonValue(c.value),\n elements: canonicalizeElements(c.elements),\n provenance: CHAIN_DSL_PROVENANCE,\n };\n}\n\n// =============================================================================\n// HELPERS\n// =============================================================================\n\n/**\n * Validates that a value is JSON-serializable (`JsonValue`).\n * The chain DSL's `is()` helper constrains conditional values to\n * JSON-compatible primitives, but the TypeScript type is `unknown`.\n * This runtime guard replaces an `as` cast with a validated assertion.\n */\nfunction assertJsonValue(v: unknown): JsonValue {\n if (v === null || typeof v === \"string\" || typeof v === \"number\" || typeof v === \"boolean\") {\n return v;\n }\n if (Array.isArray(v)) {\n return v.map(assertJsonValue);\n }\n if (typeof v === \"object\") {\n const result: Record<string, JsonValue> = {};\n for (const [key, val] of Object.entries(v)) {\n result[key] = assertJsonValue(val);\n }\n return result;\n }\n // Remaining types (function, symbol, bigint, undefined) are not JSON-serializable\n throw new TypeError(`Conditional value is not a valid JsonValue: ${typeof v}`);\n}\n\n/**\n * Builds a FieldNode from common field properties.\n */\nfunction buildFieldNode(\n name: string,\n type: TypeNode,\n required: boolean | undefined,\n annotations: AnnotationNode[],\n constraints: ConstraintNode[] = []\n): FieldNode {\n return {\n kind: \"field\",\n name,\n type,\n required: required === true,\n constraints,\n annotations,\n provenance: CHAIN_DSL_PROVENANCE,\n };\n}\n\n/**\n * Builds annotation nodes from optional label and placeholder values.\n */\nfunction buildAnnotations(label?: string, placeholder?: string): AnnotationNode[] {\n const annotations: AnnotationNode[] = [];\n\n if (label !== undefined) {\n const a: DisplayNameAnnotationNode = {\n kind: \"annotation\",\n annotationKind: \"displayName\",\n value: label,\n provenance: CHAIN_DSL_PROVENANCE,\n };\n annotations.push(a);\n }\n\n if (placeholder !== undefined) {\n const a: PlaceholderAnnotationNode = {\n kind: \"annotation\",\n annotationKind: \"placeholder\",\n value: placeholder,\n provenance: CHAIN_DSL_PROVENANCE,\n };\n annotations.push(a);\n }\n\n return annotations;\n}\n\n/**\n * Converts an array of form elements into ObjectProperty nodes.\n * Used for ObjectField properties and ArrayField items.\n *\n * Only field elements produce properties; groups and conditionals within\n * an object/array context are recursively flattened to extract their fields.\n *\n * Fields inside conditional branches are always marked `optional: true`\n * because their presence in the data depends on the condition being met.\n * This matches the DSL's type inference behavior where conditional fields\n * produce optional properties in `InferFormSchema`.\n *\n * @param elements - The form elements to convert\n * @param insideConditional - Whether these elements are inside a conditional branch\n */\nfunction buildObjectProperties(\n elements: readonly FormElement[],\n insideConditional = false\n): ObjectProperty[] {\n const properties: ObjectProperty[] = [];\n\n for (const el of elements) {\n if (isField(el)) {\n const fieldNode = canonicalizeField(el);\n properties.push({\n name: fieldNode.name,\n type: fieldNode.type,\n // Fields inside a conditional branch are always optional in the\n // data schema, regardless of their `required` flag — the condition\n // may not be met, so the field may be absent.\n optional: insideConditional || !fieldNode.required,\n constraints: fieldNode.constraints,\n annotations: fieldNode.annotations,\n provenance: CHAIN_DSL_PROVENANCE,\n });\n } else if (isGroup(el)) {\n // Groups inside object/array items contribute their fields by flattening.\n // Groups do not affect optionality — pass through the current state.\n properties.push(...buildObjectProperties(el.elements, insideConditional));\n } else if (isConditional(el)) {\n // Conditionals inside object/array items contribute their fields by\n // flattening, but all fields inside are forced optional.\n properties.push(...buildObjectProperties(el.elements, true));\n }\n }\n\n return properties;\n}\n","/**\n * TSDoc canonicalizer — assembles an {@link IRClassAnalysis} into a canonical\n * {@link FormIR}, applying layout metadata from `@Group` and `@ShowWhen`\n * decorators.\n *\n * The analysis functions in `class-analyzer.ts` produce `FieldNode[]`,\n * `fieldLayouts`, and `typeRegistry` directly. This canonicalizer uses\n * the layout metadata to wrap fields in `GroupLayoutNode` and\n * `ConditionalLayoutNode` elements.\n */\n\nimport type {\n FormIR,\n FormIRElement,\n FieldNode,\n GroupLayoutNode,\n ConditionalLayoutNode,\n Provenance,\n} from \"@formspec/core\";\nimport { IR_VERSION } from \"@formspec/core\";\nimport type { IRClassAnalysis, FieldLayoutMetadata } from \"../analyzer/class-analyzer.js\";\n\n/**\n * Source-level metadata for provenance tracking.\n */\nexport interface TSDocSource {\n /** Absolute path to the source file. */\n readonly file: string;\n}\n\n/**\n * Wraps an {@link IRClassAnalysis} (from `analyzeClassToIR`,\n * `analyzeInterfaceToIR`, or `analyzeTypeAliasToIR`) into a canonical\n * {@link FormIR}.\n *\n * Fields with `@Group` decorators are grouped into `GroupLayoutNode` elements.\n * Fields with `@ShowWhen` decorators are wrapped in `ConditionalLayoutNode` elements.\n * When both are present, the conditional wraps the field inside the group.\n *\n * @param analysis - IR analysis result (fields are already FieldNode[])\n * @param source - Optional source file metadata for provenance\n * @returns The canonical FormIR\n */\nexport function canonicalizeTSDoc(analysis: IRClassAnalysis, source?: TSDocSource): FormIR {\n const file = source?.file ?? \"\";\n\n const provenance: Provenance = {\n surface: \"tsdoc\",\n file,\n line: 1,\n column: 0,\n };\n\n const elements = assembleElements(analysis.fields, analysis.fieldLayouts, provenance);\n\n return {\n kind: \"form-ir\",\n irVersion: IR_VERSION,\n elements,\n typeRegistry: analysis.typeRegistry,\n provenance,\n };\n}\n\n/**\n * Assembles flat fields and their layout metadata into a tree of\n * `FormIRElement[]` with groups and conditionals.\n *\n * Fields are processed in order. Consecutive fields with the same\n * `@Group` label are collected into a single `GroupLayoutNode`.\n * Fields with `@ShowWhen` are wrapped in `ConditionalLayoutNode`.\n */\nfunction assembleElements(\n fields: readonly FieldNode[],\n layouts: readonly FieldLayoutMetadata[],\n provenance: Provenance\n): readonly FormIRElement[] {\n const elements: FormIRElement[] = [];\n\n // Group consecutive fields with the same group label together.\n // We use an ordered map to preserve insertion order of groups.\n const groupMap = new Map<string, FormIRElement[]>();\n const topLevelOrder: (\n | { type: \"group\"; label: string }\n | { type: \"element\"; element: FormIRElement }\n )[] = [];\n\n for (let i = 0; i < fields.length; i++) {\n const field = fields[i];\n const layout = layouts[i];\n if (!field || !layout) continue;\n\n // Wrap in conditional if @ShowWhen is present\n const element = wrapInConditional(field, layout, provenance);\n\n if (layout.groupLabel !== undefined) {\n const label = layout.groupLabel;\n let groupElements = groupMap.get(label);\n if (!groupElements) {\n groupElements = [];\n groupMap.set(label, groupElements);\n topLevelOrder.push({ type: \"group\", label });\n }\n groupElements.push(element);\n } else {\n topLevelOrder.push({ type: \"element\", element });\n }\n }\n\n // Assemble the final element array in order\n for (const entry of topLevelOrder) {\n if (entry.type === \"group\") {\n const groupElements = groupMap.get(entry.label);\n if (groupElements) {\n const groupNode: GroupLayoutNode = {\n kind: \"group\",\n label: entry.label,\n elements: groupElements,\n provenance,\n };\n elements.push(groupNode);\n // Clear so duplicate group labels in topLevelOrder don't re-emit\n groupMap.delete(entry.label);\n }\n } else {\n elements.push(entry.element);\n }\n }\n\n return elements;\n}\n\n/**\n * Wraps a field in a `ConditionalLayoutNode` if the layout has `showWhen` metadata.\n */\nfunction wrapInConditional(\n field: FieldNode,\n layout: FieldLayoutMetadata,\n provenance: Provenance\n): FormIRElement {\n if (layout.showWhen === undefined) {\n return field;\n }\n\n const conditional: ConditionalLayoutNode = {\n kind: \"conditional\",\n fieldName: layout.showWhen.field,\n value: layout.showWhen.value,\n elements: [field],\n provenance,\n };\n\n return conditional;\n}\n","/**\n * JSON Schema 2020-12 generator that consumes the canonical FormIR.\n *\n * This generator is a pure function of the IR. It never consults the TypeScript\n * AST or surface syntax directly — only the IR (per the JSON Schema vocabulary spec §1.2).\n *\n * @see https://json-schema.org/draft/2020-12/schema\n * @see https://json-schema.org/draft/2020-12/schema\n */\n\nimport type {\n FormIR,\n FormIRElement,\n FieldNode,\n TypeNode,\n PrimitiveTypeNode,\n EnumTypeNode,\n ArrayTypeNode,\n ObjectTypeNode,\n UnionTypeNode,\n ReferenceTypeNode,\n DynamicTypeNode,\n CustomTypeNode,\n ConstraintNode,\n AnnotationNode,\n ObjectProperty,\n} from \"@formspec/core\";\n\n// =============================================================================\n// OUTPUT TYPE\n// =============================================================================\n\n/**\n * A JSON Schema 2020-12 document, sub-schema, or keyword collection.\n *\n * This interface covers the subset of JSON Schema 2020-12 that this generator\n * emits, plus an index signature for custom `x-formspec-*` extension keywords.\n */\nexport interface JsonSchema2020 {\n $schema?: string;\n $ref?: string;\n $defs?: Record<string, JsonSchema2020>;\n type?: string;\n properties?: Record<string, JsonSchema2020>;\n required?: string[];\n items?: JsonSchema2020;\n additionalProperties?: boolean;\n enum?: readonly (string | number)[];\n const?: string | number | boolean | null;\n oneOf?: readonly JsonSchema2020[];\n anyOf?: readonly JsonSchema2020[];\n // Constraints\n minimum?: number;\n maximum?: number;\n exclusiveMinimum?: number;\n exclusiveMaximum?: number;\n multipleOf?: number;\n minLength?: number;\n maxLength?: number;\n minItems?: number;\n maxItems?: number;\n pattern?: string;\n uniqueItems?: boolean;\n // Annotations\n title?: string;\n description?: string;\n default?: unknown;\n deprecated?: boolean;\n // Extensions (open for vendor-prefixed keywords, e.g., x-formspec-*, x-stripe-*)\n // The vendor prefix is configurable (white-labelable).\n [key: `x-${string}`]: unknown;\n}\n\n// =============================================================================\n// CONTEXT\n// =============================================================================\n\n/**\n * Mutable accumulator passed through the generation traversal.\n *\n * Using a context object rather than return-value threading keeps the\n * recursive generators simple and avoids repeated object spreading.\n */\ninterface GeneratorContext {\n /** Named type schemas collected during traversal, keyed by reference name. */\n readonly defs: Record<string, JsonSchema2020>;\n}\n\nfunction makeContext(): GeneratorContext {\n return { defs: {} };\n}\n\n// =============================================================================\n// PUBLIC API\n// =============================================================================\n\n/**\n * Generates a JSON Schema 2020-12 object from a canonical FormIR.\n *\n * Groups and conditionals are flattened — they influence UI layout but do not\n * affect the data schema. All fields appear at the level they would occupy in\n * the output data.\n *\n * Named types in the `typeRegistry` are emitted as `$defs` entries and\n * referenced via `$ref` (per PP7 — high-fidelity output).\n *\n * @example\n * ```typescript\n * import { canonicalizeDSL } from \"./canonicalize/index.js\";\n * import { generateJsonSchemaFromIR } from \"./json-schema/ir-generator.js\";\n * import { formspec, field } from \"@formspec/dsl\";\n *\n * const form = formspec(\n * field.text(\"name\", { label: \"Name\", required: true }),\n * field.number(\"age\", { min: 0 }),\n * );\n * const ir = canonicalizeDSL(form);\n * const schema = generateJsonSchemaFromIR(ir);\n * // {\n * // $schema: \"https://json-schema.org/draft/2020-12/schema\",\n * // type: \"object\",\n * // properties: {\n * // name: { type: \"string\", title: \"Name\" },\n * // age: { type: \"number\", minimum: 0 }\n * // },\n * // required: [\"name\"]\n * // }\n * ```\n *\n * @param ir - The canonical FormIR produced by a canonicalizer\n * @returns A plain JSON-serializable JSON Schema 2020-12 object\n */\nexport function generateJsonSchemaFromIR(ir: FormIR): JsonSchema2020 {\n const ctx = makeContext();\n\n // Seed $defs from the type registry so referenced types are available even if\n // the field tree traversal never visits them (e.g., unreferenced types added\n // by a TSDoc canonicalizer pass).\n for (const [name, typeDef] of Object.entries(ir.typeRegistry)) {\n ctx.defs[name] = generateTypeNode(typeDef.type, ctx);\n }\n\n const properties: Record<string, JsonSchema2020> = {};\n const required: string[] = [];\n\n collectFields(ir.elements, properties, required, ctx);\n\n // Deduplicate required (same field can appear across conditional branches).\n const uniqueRequired = [...new Set(required)];\n\n const result: JsonSchema2020 = {\n $schema: \"https://json-schema.org/draft/2020-12/schema\",\n type: \"object\",\n properties,\n ...(uniqueRequired.length > 0 && { required: uniqueRequired }),\n };\n\n if (Object.keys(ctx.defs).length > 0) {\n result.$defs = ctx.defs;\n }\n\n return result;\n}\n\n// =============================================================================\n// ELEMENT TRAVERSAL\n// =============================================================================\n\n/**\n * Recursively visits all IR elements, collecting field schemas and required names.\n *\n * Groups and conditionals are transparent to the schema — their children are\n * lifted to the enclosing level (per the JSON Schema vocabulary spec §1.2).\n */\nfunction collectFields(\n elements: readonly FormIRElement[],\n properties: Record<string, JsonSchema2020>,\n required: string[],\n ctx: GeneratorContext\n): void {\n for (const element of elements) {\n switch (element.kind) {\n case \"field\":\n properties[element.name] = generateFieldSchema(element, ctx);\n if (element.required) {\n required.push(element.name);\n }\n break;\n\n case \"group\":\n // Groups are UI-only; flatten children into the enclosing schema.\n collectFields(element.elements, properties, required, ctx);\n break;\n\n case \"conditional\":\n // Conditional visibility is UI-only; all fields remain in the schema.\n collectFields(element.elements, properties, required, ctx);\n break;\n\n default: {\n const _exhaustive: never = element;\n void _exhaustive;\n }\n }\n }\n}\n\n// =============================================================================\n// FIELD SCHEMA GENERATION\n// =============================================================================\n\n/**\n * Generates the JSON Schema sub-schema for a single FieldNode.\n */\nfunction generateFieldSchema(field: FieldNode, ctx: GeneratorContext): JsonSchema2020 {\n const schema = generateTypeNode(field.type, ctx);\n\n // Apply constraints. multipleOf:1 on a number type is a special case: it\n // promotes the type to \"integer\" and removes the multipleOf keyword.\n applyConstraints(schema, field.constraints);\n\n // Apply annotations (title, description, default, deprecated, etc.).\n applyAnnotations(schema, field.annotations);\n\n return schema;\n}\n\n// =============================================================================\n// TYPE NODE GENERATION\n// =============================================================================\n\n/**\n * Converts a TypeNode to a JSON Schema sub-schema.\n *\n * This function is intentionally exhaustive — all TypeNode variants are handled.\n * TypeScript's exhaustiveness check via the default branch ensures new variants\n * added to the IR are caught at compile time.\n */\nfunction generateTypeNode(type: TypeNode, ctx: GeneratorContext): JsonSchema2020 {\n switch (type.kind) {\n case \"primitive\":\n return generatePrimitiveType(type);\n\n case \"enum\":\n return generateEnumType(type);\n\n case \"array\":\n return generateArrayType(type, ctx);\n\n case \"object\":\n return generateObjectType(type, ctx);\n\n case \"union\":\n return generateUnionType(type, ctx);\n\n case \"reference\":\n return generateReferenceType(type);\n\n case \"dynamic\":\n return generateDynamicType(type);\n\n case \"custom\":\n return generateCustomType(type);\n\n default: {\n // TypeScript exhaustiveness guard.\n const _exhaustive: never = type;\n return _exhaustive;\n }\n }\n}\n\n/**\n * Maps primitive IR types to JSON Schema type keywords.\n *\n * Note: `integer` is NOT a primitive kind in the IR. Integer semantics are\n * expressed via a `multipleOf: 1` constraint on a number type; `applyConstraints`\n * handles the promotion (per the JSON Schema vocabulary spec §2.1).\n */\nfunction generatePrimitiveType(type: PrimitiveTypeNode): JsonSchema2020 {\n return { type: type.primitiveKind };\n}\n\n/**\n * Generates JSON Schema for a static enum type.\n *\n * When any member has a displayName, the output uses the `oneOf` form with\n * per-member `const`/`title` entries (per the JSON Schema vocabulary spec §2.3). Otherwise the\n * flat `enum` keyword is used (simpler, equally valid).\n */\nfunction generateEnumType(type: EnumTypeNode): JsonSchema2020 {\n const hasDisplayNames = type.members.some((m) => m.displayName !== undefined);\n\n if (hasDisplayNames) {\n return {\n oneOf: type.members.map((m) => {\n const entry: JsonSchema2020 = { const: m.value };\n if (m.displayName !== undefined) {\n entry.title = m.displayName;\n }\n return entry;\n }),\n };\n }\n\n return { enum: type.members.map((m) => m.value) };\n}\n\n/**\n * Generates JSON Schema for an array type.\n * Per 2020-12, `items` is a single schema (not an array); tuple types use\n * `prefixItems` + `items: false`.\n */\nfunction generateArrayType(type: ArrayTypeNode, ctx: GeneratorContext): JsonSchema2020 {\n return {\n type: \"array\",\n items: generateTypeNode(type.items, ctx),\n };\n}\n\n/**\n * Generates JSON Schema for an object type.\n *\n * `additionalProperties` is only emitted when the IR explicitly disallows extra\n * properties. The default per the JSON Schema vocabulary spec §2.5 is to omit it (allow policy).\n */\nfunction generateObjectType(type: ObjectTypeNode, ctx: GeneratorContext): JsonSchema2020 {\n const properties: Record<string, JsonSchema2020> = {};\n const required: string[] = [];\n\n for (const prop of type.properties) {\n properties[prop.name] = generatePropertySchema(prop, ctx);\n if (!prop.optional) {\n required.push(prop.name);\n }\n }\n\n const schema: JsonSchema2020 = { type: \"object\", properties };\n\n if (required.length > 0) {\n schema.required = required;\n }\n\n if (!type.additionalProperties) {\n // IR default is false (closed objects). Emit explicitly when disallowed.\n schema.additionalProperties = false;\n }\n\n return schema;\n}\n\n/**\n * Generates a schema for an ObjectProperty, applying its use-site constraints\n * and annotations (per the JSON Schema vocabulary spec §5.4 — inline allOf at use site).\n */\nfunction generatePropertySchema(prop: ObjectProperty, ctx: GeneratorContext): JsonSchema2020 {\n const schema = generateTypeNode(prop.type, ctx);\n applyConstraints(schema, prop.constraints);\n applyAnnotations(schema, prop.annotations);\n return schema;\n}\n\n/**\n * Generates JSON Schema for a union type.\n *\n * Union handling strategy:\n * - Boolean shorthand: `true | false` → `{ type: \"boolean\" }` (not anyOf)\n * - All other unions → `anyOf` (members may overlap; discriminated union\n * detection is deferred to a future phase per design doc 003 §7.4)\n */\nfunction generateUnionType(type: UnionTypeNode, ctx: GeneratorContext): JsonSchema2020 {\n // Boolean shorthand: union of true-literal and false-literal → type: \"boolean\"\n if (isBooleanUnion(type)) {\n return { type: \"boolean\" };\n }\n\n // Default: anyOf for all non-boolean unions.\n // Discriminated union detection (shared required property with distinct consts)\n // is deferred to a future phase.\n return {\n anyOf: type.members.map((m) => generateTypeNode(m, ctx)),\n };\n}\n\n/**\n * Returns true if the union is `true | false` (boolean shorthand).\n */\nfunction isBooleanUnion(type: UnionTypeNode): boolean {\n if (type.members.length !== 2) return false;\n const kinds = type.members.map((m) => m.kind);\n // Both must be primitives; check if both are \"boolean\" primitives.\n // The IR currently does not have a boolean literal node, so boolean union\n // is represented as two primitive boolean members.\n return (\n kinds.every((k) => k === \"primitive\") &&\n type.members.every((m) => m.kind === \"primitive\" && m.primitiveKind === \"boolean\")\n );\n}\n\n/**\n * Generates JSON Schema for a reference type.\n *\n * The referenced type's schema is stored in `$defs` (seeded from the type\n * registry before traversal begins). The reference simply emits a `$ref`.\n */\nfunction generateReferenceType(type: ReferenceTypeNode): JsonSchema2020 {\n return { $ref: `#/$defs/${type.name}` };\n}\n\n/**\n * Generates JSON Schema for a dynamic type (runtime-resolved enum or schema).\n *\n * Dynamic enums emit `x-formspec-source` and optionally `x-formspec-params`.\n * Dynamic schemas emit `x-formspec-schemaSource` with `additionalProperties: true`\n * since the actual schema is determined at runtime (per the JSON Schema vocabulary spec §3.2).\n */\nfunction generateDynamicType(type: DynamicTypeNode): JsonSchema2020 {\n if (type.dynamicKind === \"enum\") {\n const schema: JsonSchema2020 = {\n type: \"string\",\n \"x-formspec-source\": type.sourceKey,\n };\n if (type.parameterFields.length > 0) {\n schema[\"x-formspec-params\"] = [...type.parameterFields];\n }\n return schema;\n }\n\n // dynamicKind === \"schema\"\n return {\n type: \"object\",\n additionalProperties: true,\n \"x-formspec-schemaSource\": type.sourceKey,\n };\n}\n\n/**\n * CustomTypeNode is a placeholder for Phase 8 extensions.\n * Emits a minimal passthrough object type until the extension API is implemented.\n */\nfunction generateCustomType(_type: CustomTypeNode): JsonSchema2020 {\n return { type: \"object\" };\n}\n\n// =============================================================================\n// CONSTRAINT APPLICATION\n// =============================================================================\n\n/**\n * Applies constraint nodes onto an existing JSON Schema object (mutates in place).\n *\n * All callers pass freshly-created objects so there is no aliasing risk.\n *\n * Special rule (per the JSON Schema vocabulary spec §2.1): `multipleOf: 1` on a `\"number\"` type\n * promotes to `\"integer\"` and suppresses the `multipleOf` keyword (integer is a\n * subtype of number; expressing it via multipleOf:1 is redundant).\n *\n * Path-targeted constraints (e.g., `@minimum :value 0`) are emitted at the field\n * level here; full sub-field targeting via allOf composition is a Phase 4 concern.\n */\nfunction applyConstraints(schema: JsonSchema2020, constraints: readonly ConstraintNode[]): void {\n for (const constraint of constraints) {\n switch (constraint.constraintKind) {\n case \"minimum\":\n schema.minimum = constraint.value;\n break;\n\n case \"maximum\":\n schema.maximum = constraint.value;\n break;\n\n case \"exclusiveMinimum\":\n schema.exclusiveMinimum = constraint.value;\n break;\n\n case \"exclusiveMaximum\":\n schema.exclusiveMaximum = constraint.value;\n break;\n\n case \"multipleOf\": {\n const { value } = constraint;\n if (value === 1 && schema.type === \"number\") {\n // Promote number → integer; omit the multipleOf keyword (redundant).\n schema.type = \"integer\";\n } else {\n schema.multipleOf = value;\n }\n break;\n }\n\n case \"minLength\":\n schema.minLength = constraint.value;\n break;\n\n case \"maxLength\":\n schema.maxLength = constraint.value;\n break;\n\n case \"minItems\":\n schema.minItems = constraint.value;\n break;\n\n case \"maxItems\":\n schema.maxItems = constraint.value;\n break;\n\n case \"pattern\":\n schema.pattern = constraint.pattern;\n break;\n\n case \"uniqueItems\":\n schema.uniqueItems = constraint.value;\n break;\n\n case \"allowedMembers\":\n // EnumMemberConstraintNode — not yet emitted to JSON Schema (Phase 6 validation).\n break;\n\n case \"custom\":\n // CustomConstraintNode — handled by Phase 8 extensions.\n break;\n\n default: {\n // TypeScript exhaustiveness guard.\n const _exhaustive: never = constraint;\n void _exhaustive;\n }\n }\n }\n}\n\n// =============================================================================\n// ANNOTATION APPLICATION\n// =============================================================================\n\n/**\n * Applies annotation nodes onto an existing JSON Schema object (mutates in place).\n *\n * Mapping per the JSON Schema vocabulary spec §2.8:\n * - `displayName` → `title`\n * - `description` → `description`\n * - `defaultValue` → `default`\n * - `deprecated` → `deprecated: true` (2020-12 standard annotation)\n *\n * UI-only annotations (`placeholder`, `formatHint`) are silently ignored here —\n * they belong in the UI Schema, not the data schema.\n */\nfunction applyAnnotations(schema: JsonSchema2020, annotations: readonly AnnotationNode[]): void {\n for (const annotation of annotations) {\n switch (annotation.annotationKind) {\n case \"displayName\":\n schema.title = annotation.value;\n break;\n\n case \"description\":\n schema.description = annotation.value;\n break;\n\n case \"defaultValue\":\n schema.default = annotation.value;\n break;\n\n case \"deprecated\":\n schema.deprecated = true;\n break;\n\n case \"placeholder\":\n // UI-only — belongs in UI Schema, not emitted here.\n break;\n\n case \"formatHint\":\n // UI-only — belongs in UI Schema, not emitted here.\n break;\n\n case \"custom\":\n // CustomAnnotationNode — handled by Phase 8 extensions.\n break;\n\n default: {\n // TypeScript exhaustiveness guard.\n const _exhaustive: never = annotation;\n void _exhaustive;\n }\n }\n }\n}\n","/**\n * JSON Schema generator for FormSpec forms.\n *\n * Routes through the canonical IR pipeline: Chain DSL → FormIR → JSON Schema 2020-12.\n */\n\nimport type { FormElement, FormSpec } from \"@formspec/core\";\nimport { canonicalizeChainDSL } from \"../canonicalize/index.js\";\nimport { generateJsonSchemaFromIR, type JsonSchema2020 } from \"./ir-generator.js\";\n\n/**\n * Generates a JSON Schema 2020-12 from a FormSpec.\n *\n * All generation routes through the canonical IR. The chain DSL is first\n * canonicalized to a FormIR, then the IR-based generator produces the schema.\n *\n * @example\n * ```typescript\n * const form = formspec(\n * field.text(\"name\", { label: \"Name\", required: true }),\n * field.number(\"age\", { min: 0 }),\n * );\n *\n * const schema = generateJsonSchema(form);\n * // {\n * // $schema: \"https://json-schema.org/draft/2020-12/schema\",\n * // type: \"object\",\n * // properties: {\n * // name: { type: \"string\", title: \"Name\" },\n * // age: { type: \"number\", minimum: 0 }\n * // },\n * // required: [\"name\"]\n * // }\n * ```\n *\n * @param form - The FormSpec to convert\n * @returns A JSON Schema 2020-12 object\n */\nexport function generateJsonSchema<E extends readonly FormElement[]>(\n form: FormSpec<E>\n): JsonSchema2020 {\n const ir = canonicalizeChainDSL(form);\n return generateJsonSchemaFromIR(ir);\n}\n","/**\n * Zod schemas for JSON Forms UI Schema.\n *\n * These schemas are the source of truth for UI Schema validation.\n * TypeScript types are derived from these schemas via `z.infer<>`.\n *\n * @see https://jsonforms.io/docs/uischema/\n */\n\nimport { z } from \"zod\";\n\n// =============================================================================\n// Primitive helpers\n// =============================================================================\n\n/** JSON Pointer string (e.g., \"#/properties/fieldName\") */\nconst jsonPointerSchema = z.string();\n\n// =============================================================================\n// Rule Effect and Element Type enums\n// =============================================================================\n\n/**\n * Zod schema for rule effect values.\n */\nexport const ruleEffectSchema = z.enum([\"SHOW\", \"HIDE\", \"ENABLE\", \"DISABLE\"]);\n\n/**\n * Rule effect types for conditional visibility.\n */\nexport type RuleEffect = z.infer<typeof ruleEffectSchema>;\n\n/**\n * Zod schema for UI Schema element type strings.\n */\nexport const uiSchemaElementTypeSchema = z.enum([\n \"Control\",\n \"VerticalLayout\",\n \"HorizontalLayout\",\n \"Group\",\n \"Categorization\",\n \"Category\",\n \"Label\",\n]);\n\n/**\n * UI Schema element types.\n */\nexport type UISchemaElementType = z.infer<typeof uiSchemaElementTypeSchema>;\n\n// =============================================================================\n// Rule Condition Schema (recursive)\n// =============================================================================\n\n// Forward-declare the recursive TypeScript type.\n// We use an interface here (rather than z.infer<>) because the recursive\n// z.lazy() type annotation requires us to pre-declare the shape.\n/**\n * JSON Schema subset used in rule conditions.\n */\nexport interface RuleConditionSchema {\n const?: unknown;\n enum?: readonly unknown[];\n type?: string;\n not?: RuleConditionSchema;\n minimum?: number;\n maximum?: number;\n exclusiveMinimum?: number;\n exclusiveMaximum?: number;\n minLength?: number;\n properties?: Record<string, RuleConditionSchema>;\n required?: string[];\n allOf?: RuleConditionSchema[];\n}\n\n// Build the Zod schema referencing the pre-declared interface.\n// We use z.ZodType<RuleConditionSchema> so the recursive reference works.\n// The interface uses `?` (exact optional), and z.ZodType checks output only,\n// so the optional fields (which Zod infers as `T | undefined`) are compatible\n// because `T | undefined` is assignable to the optional field slot.\n//\n// @ts-expect-error -- exactOptionalPropertyTypes: the Zod output type for optional\n// fields is `T | undefined`, but our interface uses `?` (exact optional, key may\n// be absent). This is a known mismatch when using z.ZodType<T> with\n// exactOptionalPropertyTypes:true; the runtime behavior is correct.\nexport const ruleConditionSchema: z.ZodType<RuleConditionSchema> = z.lazy(() =>\n z\n .object({\n const: z.unknown().optional(),\n enum: z.array(z.unknown()).readonly().optional(),\n type: z.string().optional(),\n not: ruleConditionSchema.optional(),\n minimum: z.number().optional(),\n maximum: z.number().optional(),\n exclusiveMinimum: z.number().optional(),\n exclusiveMaximum: z.number().optional(),\n minLength: z.number().optional(),\n properties: z.record(z.string(), ruleConditionSchema).optional(),\n required: z.array(z.string()).optional(),\n allOf: z.array(ruleConditionSchema).optional(),\n })\n .strict()\n);\n\n// =============================================================================\n// Schema-Based Condition and Rule\n// =============================================================================\n\n/**\n * Zod schema for a schema-based rule condition.\n */\nexport const schemaBasedConditionSchema = z\n .object({\n scope: jsonPointerSchema,\n schema: ruleConditionSchema,\n })\n .strict();\n\n/**\n * Condition for a rule.\n */\nexport type SchemaBasedCondition = z.infer<typeof schemaBasedConditionSchema>;\n\n/**\n * Zod schema for a UI Schema rule.\n */\nexport const ruleSchema = z\n .object({\n effect: ruleEffectSchema,\n condition: schemaBasedConditionSchema,\n })\n .strict();\n\n/**\n * Rule for conditional element visibility/enablement.\n */\nexport type Rule = z.infer<typeof ruleSchema>;\n\n// =============================================================================\n// UI Schema Element Schemas (recursive via z.lazy)\n// =============================================================================\n\n// Forward-declare UISchemaElement so layout schemas can reference it.\n// We declare the type up-front and wire the Zod schema below.\n/**\n * Union of all UI Schema element types.\n */\nexport type UISchemaElement =\n | ControlElement\n | VerticalLayout\n | HorizontalLayout\n | GroupLayout\n | Categorization\n | Category\n | LabelElement;\n\n// The Zod schema for UISchemaElement is defined as a const using z.lazy(),\n// which defers evaluation until first use. This allows all element schemas\n// below to be referenced even though they are declared after this line.\nexport const uiSchemaElementSchema: z.ZodType<UISchemaElement> = z.lazy(() =>\n z.union([\n controlSchema,\n verticalLayoutSchema,\n horizontalLayoutSchema,\n groupLayoutSchema,\n categorizationSchema,\n categorySchema,\n labelElementSchema,\n ])\n) as z.ZodType<UISchemaElement>;\n\n// -----------------------------------------------------------------------------\n// Control\n// -----------------------------------------------------------------------------\n\n/**\n * Zod schema for a Control element.\n */\nexport const controlSchema = z\n .object({\n type: z.literal(\"Control\"),\n scope: jsonPointerSchema,\n label: z.union([z.string(), z.literal(false)]).optional(),\n rule: ruleSchema.optional(),\n options: z.record(z.string(), z.unknown()).optional(),\n })\n .passthrough();\n\n/**\n * A Control element that binds to a JSON Schema property.\n */\nexport type ControlElement = z.infer<typeof controlSchema>;\n\n// -----------------------------------------------------------------------------\n// VerticalLayout\n// -----------------------------------------------------------------------------\n\n// Pre-declare the interface so the Zod schema can reference UISchemaElement.\n/**\n * A vertical layout element.\n */\nexport interface VerticalLayout {\n type: \"VerticalLayout\";\n elements: UISchemaElement[];\n rule?: Rule | undefined;\n options?: Record<string, unknown> | undefined;\n [k: string]: unknown;\n}\n\nexport const verticalLayoutSchema: z.ZodType<VerticalLayout> = z.lazy(() =>\n z\n .object({\n type: z.literal(\"VerticalLayout\"),\n elements: z.array(uiSchemaElementSchema),\n rule: ruleSchema.optional(),\n options: z.record(z.string(), z.unknown()).optional(),\n })\n .passthrough()\n);\n\n// -----------------------------------------------------------------------------\n// HorizontalLayout\n// -----------------------------------------------------------------------------\n\n/**\n * A horizontal layout element.\n */\nexport interface HorizontalLayout {\n type: \"HorizontalLayout\";\n elements: UISchemaElement[];\n rule?: Rule | undefined;\n options?: Record<string, unknown> | undefined;\n [k: string]: unknown;\n}\n\nexport const horizontalLayoutSchema: z.ZodType<HorizontalLayout> = z.lazy(() =>\n z\n .object({\n type: z.literal(\"HorizontalLayout\"),\n elements: z.array(uiSchemaElementSchema),\n rule: ruleSchema.optional(),\n options: z.record(z.string(), z.unknown()).optional(),\n })\n .passthrough()\n);\n\n// -----------------------------------------------------------------------------\n// GroupLayout\n// -----------------------------------------------------------------------------\n\n/**\n * A group element with a label.\n */\nexport interface GroupLayout {\n type: \"Group\";\n label: string;\n elements: UISchemaElement[];\n rule?: Rule | undefined;\n options?: Record<string, unknown> | undefined;\n [k: string]: unknown;\n}\n\nexport const groupLayoutSchema: z.ZodType<GroupLayout> = z.lazy(() =>\n z\n .object({\n type: z.literal(\"Group\"),\n label: z.string(),\n elements: z.array(uiSchemaElementSchema),\n rule: ruleSchema.optional(),\n options: z.record(z.string(), z.unknown()).optional(),\n })\n .passthrough()\n);\n\n// -----------------------------------------------------------------------------\n// Category\n// -----------------------------------------------------------------------------\n\n/**\n * A Category element, used inside a Categorization layout.\n */\nexport interface Category {\n type: \"Category\";\n label: string;\n elements: UISchemaElement[];\n rule?: Rule | undefined;\n options?: Record<string, unknown> | undefined;\n [k: string]: unknown;\n}\n\nexport const categorySchema: z.ZodType<Category> = z.lazy(() =>\n z\n .object({\n type: z.literal(\"Category\"),\n label: z.string(),\n elements: z.array(uiSchemaElementSchema),\n rule: ruleSchema.optional(),\n options: z.record(z.string(), z.unknown()).optional(),\n })\n .passthrough()\n);\n\n// -----------------------------------------------------------------------------\n// Categorization\n// -----------------------------------------------------------------------------\n\n/**\n * A Categorization element (tab-based layout).\n */\nexport interface Categorization {\n type: \"Categorization\";\n elements: Category[];\n label?: string | undefined;\n rule?: Rule | undefined;\n options?: Record<string, unknown> | undefined;\n [k: string]: unknown;\n}\n\nexport const categorizationSchema: z.ZodType<Categorization> = z.lazy(() =>\n z\n .object({\n type: z.literal(\"Categorization\"),\n elements: z.array(categorySchema),\n label: z.string().optional(),\n rule: ruleSchema.optional(),\n options: z.record(z.string(), z.unknown()).optional(),\n })\n .passthrough()\n);\n\n// -----------------------------------------------------------------------------\n// LabelElement\n// -----------------------------------------------------------------------------\n\n/**\n * Zod schema for a Label element.\n */\nexport const labelElementSchema = z\n .object({\n type: z.literal(\"Label\"),\n text: z.string(),\n rule: ruleSchema.optional(),\n options: z.record(z.string(), z.unknown()).optional(),\n })\n .passthrough();\n\n/**\n * A Label element for displaying static text.\n */\nexport type LabelElement = z.infer<typeof labelElementSchema>;\n\n// =============================================================================\n// Root UISchema\n// =============================================================================\n\n/**\n * Root UI Schema (always a layout — not a Control, Category, or Label).\n */\nexport type UISchema = VerticalLayout | HorizontalLayout | GroupLayout | Categorization;\n\n/**\n * Zod schema for the root UI Schema (layout types only).\n */\nexport const uiSchema: z.ZodType<UISchema> = z.lazy(() =>\n z.union([verticalLayoutSchema, horizontalLayoutSchema, groupLayoutSchema, categorizationSchema])\n) as z.ZodType<UISchema>;\n","/**\n * JSON Forms UI Schema generator that operates on the canonical FormIR.\n *\n * This generator consumes the IR produced by the Canonicalize phase and\n * produces a JSON Forms UI Schema. All downstream UI Schema generation\n * should use this module for UI Schema generation.\n */\n\nimport type { FormIR, FormIRElement, FieldNode, GroupLayoutNode } from \"@formspec/core\";\nimport type { UISchema, UISchemaElement, ControlElement, GroupLayout, Rule } from \"./types.js\";\nimport { uiSchema as uiSchemaValidator } from \"./schema.js\";\nimport { z } from \"zod\";\n\n// =============================================================================\n// HELPERS\n// =============================================================================\n\n/**\n * Parses a value through a Zod schema, converting validation errors to a\n * descriptive Error.\n */\nfunction parseOrThrow<T>(schema: z.ZodType<T>, value: unknown, label: string): T {\n try {\n return schema.parse(value);\n } catch (error) {\n if (error instanceof z.ZodError) {\n throw new Error(\n `Generated ${label} failed validation:\\n${error.issues.map((i) => ` ${i.path.join(\".\")}: ${i.message}`).join(\"\\n\")}`\n );\n }\n throw error;\n }\n}\n\n/**\n * Converts a field name to a JSON Pointer scope string.\n */\nfunction fieldToScope(fieldName: string): string {\n return `#/properties/${fieldName}`;\n}\n\n/**\n * Creates a SHOW rule for a single conditional field/value pair.\n */\nfunction createShowRule(fieldName: string, value: unknown): Rule {\n return {\n effect: \"SHOW\",\n condition: {\n scope: fieldToScope(fieldName),\n schema: { const: value },\n },\n };\n}\n\n/**\n * Combines two SHOW rules into a single rule using an allOf condition.\n *\n * When elements are nested inside multiple conditionals, all parent conditions\n * must be met for the element to be visible. This function merges the two\n * conditions into a single rule using allOf so that JSON Forms evaluates\n * both predicates simultaneously.\n */\nfunction combineRules(parentRule: Rule, childRule: Rule): Rule {\n const parentCondition = parentRule.condition;\n const childCondition = childRule.condition;\n\n return {\n effect: \"SHOW\",\n condition: {\n scope: \"#\",\n schema: {\n allOf: [\n {\n properties: {\n [parentCondition.scope.replace(\"#/properties/\", \"\")]: parentCondition.schema,\n },\n },\n {\n properties: {\n [childCondition.scope.replace(\"#/properties/\", \"\")]: childCondition.schema,\n },\n },\n ],\n },\n },\n };\n}\n\n// =============================================================================\n// ELEMENT CONVERSION\n// =============================================================================\n\n/**\n * Converts a FieldNode from the IR to a ControlElement.\n *\n * The label is sourced from the first `displayName` annotation on the field,\n * matching how the chain DSL propagates the `label` option through the\n * canonicalization phase.\n */\nfunction fieldNodeToControl(field: FieldNode, parentRule?: Rule): ControlElement {\n const displayNameAnnotation = field.annotations.find((a) => a.annotationKind === \"displayName\");\n\n const control: ControlElement = {\n type: \"Control\",\n scope: fieldToScope(field.name),\n ...(displayNameAnnotation !== undefined && { label: displayNameAnnotation.value }),\n ...(parentRule !== undefined && { rule: parentRule }),\n };\n\n return control;\n}\n\n/**\n * Converts a GroupLayoutNode from the IR to a GroupLayout element.\n *\n * The group's children are recursively converted; the optional parent rule is\n * forwarded to nested elements so that a group inside a conditional inherits\n * the visibility rule.\n */\nfunction groupNodeToLayout(group: GroupLayoutNode, parentRule?: Rule): GroupLayout {\n return {\n type: \"Group\",\n label: group.label,\n elements: irElementsToUiSchema(group.elements, parentRule),\n ...(parentRule !== undefined && { rule: parentRule }),\n };\n}\n\n/**\n * Converts an array of IR elements to UI Schema elements.\n *\n * @param elements - The IR elements to convert\n * @param parentRule - Optional rule inherited from a parent ConditionalLayoutNode\n * @returns Array of UI Schema elements\n */\nfunction irElementsToUiSchema(\n elements: readonly FormIRElement[],\n parentRule?: Rule\n): UISchemaElement[] {\n const result: UISchemaElement[] = [];\n\n for (const element of elements) {\n switch (element.kind) {\n case \"field\": {\n result.push(fieldNodeToControl(element, parentRule));\n break;\n }\n\n case \"group\": {\n result.push(groupNodeToLayout(element, parentRule));\n break;\n }\n\n case \"conditional\": {\n // Build the rule for this conditional level.\n const newRule = createShowRule(element.fieldName, element.value);\n // Combine with the inherited parent rule for nested conditionals.\n const combinedRule = parentRule !== undefined ? combineRules(parentRule, newRule) : newRule;\n // Children are flattened into the parent container with the combined\n // rule attached.\n const childElements = irElementsToUiSchema(element.elements, combinedRule);\n result.push(...childElements);\n break;\n }\n\n default: {\n const _exhaustive: never = element;\n void _exhaustive;\n throw new Error(\"Unhandled IR element kind\");\n }\n }\n }\n\n return result;\n}\n\n// =============================================================================\n// PUBLIC API\n// =============================================================================\n\n/**\n * Generates a JSON Forms UI Schema from a canonical `FormIR`.\n *\n * Mapping rules:\n * - `FieldNode` → `ControlElement` with `scope: \"#/properties/<name>\"`\n * - `displayName` annotation → `label` on the `ControlElement`\n * - `GroupLayoutNode` → `GroupLayout` with recursively converted `elements`\n * - `ConditionalLayoutNode` → children flattened with a `SHOW` rule\n * - Nested conditionals → combined `allOf` rule\n * - Root wrapper is always `{ type: \"VerticalLayout\", elements: [...] }`\n *\n * @example\n * ```typescript\n * const ir = canonicalizeDSL(\n * formspec(\n * group(\"Customer\", field.text(\"name\", { label: \"Name\" })),\n * when(is(\"status\", \"draft\"), field.text(\"notes\", { label: \"Notes\" })),\n * )\n * );\n *\n * const uiSchema = generateUiSchemaFromIR(ir);\n * // {\n * // type: \"VerticalLayout\",\n * // elements: [\n * // {\n * // type: \"Group\",\n * // label: \"Customer\",\n * // elements: [{ type: \"Control\", scope: \"#/properties/name\", label: \"Name\" }]\n * // },\n * // {\n * // type: \"Control\",\n * // scope: \"#/properties/notes\",\n * // label: \"Notes\",\n * // rule: { effect: \"SHOW\", condition: { scope: \"#/properties/status\", schema: { const: \"draft\" } } }\n * // }\n * // ]\n * // }\n * ```\n *\n * @param ir - The canonical FormIR produced by the Canonicalize phase\n * @returns A validated JSON Forms UI Schema\n */\nexport function generateUiSchemaFromIR(ir: FormIR): UISchema {\n const result: UISchema = {\n type: \"VerticalLayout\",\n elements: irElementsToUiSchema(ir.elements),\n };\n\n return parseOrThrow(uiSchemaValidator, result, \"UI Schema\");\n}\n","/**\n * JSON Forms UI Schema generator for FormSpec forms.\n *\n * Routes through the canonical IR pipeline: Chain DSL → FormIR → UI Schema.\n */\n\nimport type { FormElement, FormSpec } from \"@formspec/core\";\nimport { canonicalizeChainDSL } from \"../canonicalize/index.js\";\nimport { generateUiSchemaFromIR } from \"./ir-generator.js\";\nimport type { UISchema } from \"./types.js\";\n\n/**\n * Generates a JSON Forms UI Schema from a FormSpec.\n *\n * All generation routes through the canonical IR. The chain DSL is first\n * canonicalized to a FormIR, then the IR-based generator produces the schema.\n *\n * @example\n * ```typescript\n * const form = formspec(\n * group(\"Customer\",\n * field.text(\"name\", { label: \"Name\" }),\n * ),\n * when(\"status\", \"draft\",\n * field.text(\"notes\", { label: \"Notes\" }),\n * ),\n * );\n *\n * const uiSchema = generateUiSchema(form);\n * // {\n * // type: \"VerticalLayout\",\n * // elements: [\n * // {\n * // type: \"Group\",\n * // label: \"Customer\",\n * // elements: [\n * // { type: \"Control\", scope: \"#/properties/name\", label: \"Name\" }\n * // ]\n * // },\n * // {\n * // type: \"Control\",\n * // scope: \"#/properties/notes\",\n * // label: \"Notes\",\n * // rule: {\n * // effect: \"SHOW\",\n * // condition: { scope: \"#/properties/status\", schema: { const: \"draft\" } }\n * // }\n * // }\n * // ]\n * // }\n * ```\n *\n * @param form - The FormSpec to convert\n * @returns A JSON Forms UI Schema\n */\nexport function generateUiSchema<E extends readonly FormElement[]>(form: FormSpec<E>): UISchema {\n const ir = canonicalizeChainDSL(form);\n return generateUiSchemaFromIR(ir);\n}\n","/**\n * `@formspec/build` - Build tools for FormSpec\n *\n * This package provides generators to compile FormSpec forms into:\n * - JSON Schema 2020-12 (for validation)\n * - JSON Forms UI Schema (for rendering)\n *\n * @example\n * ```typescript\n * import { buildFormSchemas } from \"@formspec/build\";\n * import { formspec, field, group } from \"@formspec/dsl\";\n *\n * const form = formspec(\n * group(\"Customer\",\n * field.text(\"name\", { label: \"Name\", required: true }),\n * field.text(\"email\", { label: \"Email\" }),\n * ),\n * );\n *\n * const { jsonSchema, uiSchema } = buildFormSchemas(form);\n * ```\n *\n * @packageDocumentation\n */\n\nimport type { FormElement, FormSpec } from \"@formspec/core\";\nimport { generateJsonSchema } from \"./json-schema/generator.js\";\nimport { generateUiSchema } from \"./ui-schema/generator.js\";\nimport type { JsonSchema2020 } from \"./json-schema/ir-generator.js\";\nimport type { UISchema } from \"./ui-schema/types.js\";\nimport * as fs from \"node:fs\";\nimport * as path from \"node:path\";\n\n// =============================================================================\n// Type Exports\n// =============================================================================\n\nexport type { JsonSchema2020 } from \"./json-schema/ir-generator.js\";\n\nexport type {\n JSONSchema7,\n JSONSchemaType,\n ExtendedJSONSchema7,\n FormSpecSchemaExtensions,\n} from \"./json-schema/types.js\";\n\nexport { setSchemaExtension, getSchemaExtension } from \"./json-schema/types.js\";\n\nexport type {\n UISchema,\n UISchemaElement,\n UISchemaElementBase,\n UISchemaElementType,\n ControlElement,\n VerticalLayout,\n HorizontalLayout,\n GroupLayout,\n Categorization,\n Category,\n LabelElement,\n Rule,\n RuleEffect,\n RuleConditionSchema,\n SchemaBasedCondition,\n} from \"./ui-schema/types.js\";\n\nexport type {\n ClassSchemas,\n GenerateFromClassOptions,\n GenerateFromClassResult,\n GenerateSchemasOptions,\n} from \"./generators/class-schema.js\";\n\n// =============================================================================\n// Zod Validation Schemas\n// =============================================================================\n\nexport {\n ruleEffectSchema,\n uiSchemaElementTypeSchema,\n ruleConditionSchema,\n schemaBasedConditionSchema,\n ruleSchema,\n controlSchema,\n verticalLayoutSchema,\n horizontalLayoutSchema,\n groupLayoutSchema,\n categorizationSchema,\n categorySchema,\n labelElementSchema,\n uiSchemaElementSchema,\n uiSchema as uiSchemaSchema,\n} from \"./ui-schema/schema.js\";\n\nexport { jsonSchemaTypeSchema, jsonSchema7Schema } from \"./json-schema/schema.js\";\n\n// =============================================================================\n// Chain DSL Generators\n// =============================================================================\n\nexport { generateJsonSchema } from \"./json-schema/generator.js\";\nexport { generateUiSchema } from \"./ui-schema/generator.js\";\n\n// =============================================================================\n// Class/Interface Analysis: High-Level Entry Points\n// =============================================================================\n\nexport { generateSchemasFromClass, generateSchemas } from \"./generators/class-schema.js\";\n\n// generateSchemas is the recommended entry point — it auto-detects class/interface/type alias.\n// generateSchemasFromClass is retained for backwards compatibility.\n\n/**\n * Result of building form schemas.\n */\nexport interface BuildResult {\n /** JSON Schema 2020-12 for validation */\n readonly jsonSchema: JsonSchema2020;\n /** JSON Forms UI Schema for rendering */\n readonly uiSchema: UISchema;\n}\n\n/**\n * Builds both JSON Schema and UI Schema from a FormSpec.\n *\n * This is a convenience function that combines `generateJsonSchema`\n * and `generateUiSchema`.\n *\n * @example\n * ```typescript\n * const form = formspec(\n * field.text(\"name\", { required: true }),\n * field.number(\"age\", { min: 0 }),\n * );\n *\n * const { jsonSchema, uiSchema } = buildFormSchemas(form);\n *\n * // Use with JSON Forms renderer\n * <JsonForms\n * schema={jsonSchema}\n * uischema={uiSchema}\n * data={formData}\n * renderers={materialRenderers}\n * />\n * ```\n *\n * @param form - The FormSpec to build schemas from\n * @returns Object containing both jsonSchema and uiSchema\n */\nexport function buildFormSchemas<E extends readonly FormElement[]>(form: FormSpec<E>): BuildResult {\n return {\n jsonSchema: generateJsonSchema(form),\n uiSchema: generateUiSchema(form),\n };\n}\n\n/**\n * Options for writing schemas to disk.\n */\nexport interface WriteSchemasOptions {\n /** Output directory for the schema files */\n readonly outDir: string;\n /** Base name for the output files (without extension). Defaults to \"schema\" */\n readonly name?: string;\n /** Number of spaces for JSON indentation. Defaults to 2 */\n readonly indent?: number;\n}\n\n/**\n * Result of writing schemas to disk.\n */\nexport interface WriteSchemasResult {\n /** Path to the generated JSON Schema file */\n readonly jsonSchemaPath: string;\n /** Path to the generated UI Schema file */\n readonly uiSchemaPath: string;\n}\n\n/**\n * Builds and writes both JSON Schema and UI Schema files to disk.\n *\n * This is a convenience function for build-time schema generation.\n * It creates the output directory if it doesn't exist.\n *\n * @example\n * ```typescript\n * import { formspec, field } from \"formspec\";\n * import { writeSchemas } from \"@formspec/build\";\n *\n * const ProductForm = formspec(\n * field.text(\"name\", { required: true }),\n * field.enum(\"status\", [\"draft\", \"active\"]),\n * );\n *\n * // Write schemas to ./generated/product-schema.json and ./generated/product-uischema.json\n * const { jsonSchemaPath, uiSchemaPath } = writeSchemas(ProductForm, {\n * outDir: \"./generated\",\n * name: \"product\",\n * });\n *\n * console.log(`Generated: ${jsonSchemaPath}, ${uiSchemaPath}`);\n * ```\n *\n * @param form - The FormSpec to build schemas from\n * @param options - Output options (directory, file name, indentation)\n * @returns Object containing paths to the generated files\n */\nexport function writeSchemas<E extends readonly FormElement[]>(\n form: FormSpec<E>,\n options: WriteSchemasOptions\n): WriteSchemasResult {\n const { outDir, name = \"schema\", indent = 2 } = options;\n\n // Build schemas\n const { jsonSchema, uiSchema } = buildFormSchemas(form);\n\n // Ensure output directory exists\n if (!fs.existsSync(outDir)) {\n fs.mkdirSync(outDir, { recursive: true });\n }\n\n // Write files\n const jsonSchemaPath = path.join(outDir, `${name}-schema.json`);\n const uiSchemaPath = path.join(outDir, `${name}-uischema.json`);\n\n fs.writeFileSync(jsonSchemaPath, JSON.stringify(jsonSchema, null, indent));\n fs.writeFileSync(uiSchemaPath, JSON.stringify(uiSchema, null, indent));\n\n return { jsonSchemaPath, uiSchemaPath };\n}\n","/**\n * JSON Schema type definitions.\n *\n * These types are a subset of JSON Schema sufficient for form generation.\n */\n\n/**\n * JSON Schema primitive types.\n */\nexport type JSONSchemaType =\n | \"string\"\n | \"number\"\n | \"integer\"\n | \"boolean\"\n | \"object\"\n | \"array\"\n | \"null\";\n\n/**\n * A JSON Schema definition (legacy subset used by Zod validator and types.ts).\n */\nexport interface JSONSchema7 {\n $schema?: string;\n $id?: string;\n $ref?: string;\n\n // Metadata\n title?: string;\n description?: string;\n deprecated?: boolean;\n\n // Type\n type?: JSONSchemaType | JSONSchemaType[];\n\n // String validation\n minLength?: number;\n maxLength?: number;\n pattern?: string;\n\n // Number validation\n minimum?: number;\n maximum?: number;\n exclusiveMinimum?: number;\n exclusiveMaximum?: number;\n\n // Enum\n enum?: readonly (string | number | boolean | null)[];\n const?: string | number | boolean | null;\n\n // Object\n properties?: Record<string, JSONSchema7>;\n required?: string[];\n additionalProperties?: boolean | JSONSchema7;\n\n // Array\n items?: JSONSchema7 | JSONSchema7[];\n minItems?: number;\n maxItems?: number;\n\n // Composition\n allOf?: JSONSchema7[];\n anyOf?: JSONSchema7[];\n oneOf?: JSONSchema7[];\n not?: JSONSchema7;\n\n // Conditional\n if?: JSONSchema7;\n then?: JSONSchema7;\n else?: JSONSchema7;\n\n // Format\n format?: string;\n\n // Default\n default?: unknown;\n\n // =============================================================================\n // FormSpec Extensions (x- prefixed)\n // =============================================================================\n\n /**\n * Data source key for dynamic enum fields.\n * Indicates that options should be fetched from a registered resolver.\n */\n \"x-formspec-source\"?: string;\n\n /**\n * Field names whose values are needed to fetch dynamic enum options.\n * Used for dependent/cascading dropdowns.\n */\n \"x-formspec-params\"?: readonly string[];\n\n /**\n * Schema source identifier for dynamic schema fields.\n * Indicates that the schema should be loaded dynamically at runtime.\n */\n \"x-formspec-schemaSource\"?: string;\n}\n\n/** Extension properties for custom FormSpec decorators. */\nexport type FormSpecSchemaExtensions = Record<`x-formspec-${string}`, unknown>;\n\n/** JSON Schema with FormSpec extension properties for arbitrary x-formspec-* keys. */\nexport type ExtendedJSONSchema7 = JSONSchema7 & FormSpecSchemaExtensions;\n\n/**\n * Sets a FormSpec extension property on a JSON Schema node.\n *\n * Use this to safely add `x-formspec-*` properties to any schema,\n * including nested schemas typed as `JSONSchema7` (which don't carry\n * the extension index signature).\n *\n * @param schema - Any JSON Schema node\n * @param key - Extension key (must start with `x-formspec-`)\n * @param value - Extension value\n */\nexport function setSchemaExtension(\n schema: object,\n key: `x-formspec-${string}`,\n value: unknown\n): void {\n (schema as Record<string, unknown>)[key] = value;\n}\n\n/**\n * Reads a FormSpec extension property from a JSON Schema node.\n *\n * Accepts any schema object — `JSONSchema7`, `JsonSchema2020`, `ExtendedJSONSchema7`, etc.\n *\n * @param schema - Any JSON Schema node\n * @param key - Extension key (must start with `x-formspec-`)\n * @returns The extension value, or `undefined` if not present\n */\nexport function getSchemaExtension(schema: object, key: `x-formspec-${string}`): unknown {\n return (schema as Record<string, unknown>)[key];\n}\n","/**\n * Zod schemas for JSON Schema output validation.\n *\n * These schemas cover the subset of JSON Schema that FormSpec generates,\n * plus the FormSpec-specific `x-formspec-*` extension properties.\n *\n * @see https://json-schema.org/draft/2020-12/schema\n */\n\nimport { z } from \"zod\";\nimport type { JSONSchema7 } from \"./types.js\";\n\n// =============================================================================\n// JSON Schema type enum\n// =============================================================================\n\n/**\n * Zod schema for JSON Schema primitive type strings.\n */\nexport const jsonSchemaTypeSchema = z.enum([\n \"string\",\n \"number\",\n \"integer\",\n \"boolean\",\n \"object\",\n \"array\",\n \"null\",\n]);\n\n// =============================================================================\n// JSON Schema validator schema (recursive)\n// =============================================================================\n\n// We annotate with z.ZodType<JSONSchema7> for the recursive self-reference.\n// The @ts-expect-error is required because exactOptionalPropertyTypes:true causes\n// Zod's inferred output type for optional fields (`T | undefined`) to be\n// incompatible with the JSONSchema7 interface's exact optional fields (`T?`).\n// The runtime behavior is correct: z.optional() will strip `undefined` values\n// during parsing and correctly handle absent keys.\n//\n// @ts-expect-error -- exactOptionalPropertyTypes: Zod optional infers `T | undefined`\n// but JSONSchema7 uses exact optional `?:` which disallows explicit undefined.\nexport const jsonSchema7Schema: z.ZodType<JSONSchema7> = z.lazy(() =>\n z\n .object({\n $schema: z.string().optional(),\n $id: z.string().optional(),\n $ref: z.string().optional(),\n\n // Metadata\n title: z.string().optional(),\n description: z.string().optional(),\n deprecated: z.boolean().optional(),\n\n // Type\n type: z.union([jsonSchemaTypeSchema, z.array(jsonSchemaTypeSchema)]).optional(),\n\n // String validation\n minLength: z.number().optional(),\n maxLength: z.number().optional(),\n pattern: z.string().optional(),\n\n // Number validation\n minimum: z.number().optional(),\n maximum: z.number().optional(),\n exclusiveMinimum: z.number().optional(),\n exclusiveMaximum: z.number().optional(),\n\n // Enum\n enum: z\n .array(z.union([z.string(), z.number(), z.boolean(), z.null()]))\n .readonly()\n .optional(),\n const: z.union([z.string(), z.number(), z.boolean(), z.null()]).optional(),\n\n // Object\n properties: z.record(z.string(), jsonSchema7Schema).optional(),\n required: z.array(z.string()).optional(),\n additionalProperties: z.union([z.boolean(), jsonSchema7Schema]).optional(),\n\n // Array\n items: z.union([jsonSchema7Schema, z.array(jsonSchema7Schema)]).optional(),\n minItems: z.number().optional(),\n maxItems: z.number().optional(),\n\n // Composition\n allOf: z.array(jsonSchema7Schema).optional(),\n anyOf: z.array(jsonSchema7Schema).optional(),\n oneOf: z.array(jsonSchema7Schema).optional(),\n not: jsonSchema7Schema.optional(),\n\n // Conditional\n if: jsonSchema7Schema.optional(),\n then: jsonSchema7Schema.optional(),\n else: jsonSchema7Schema.optional(),\n\n // Format\n format: z.string().optional(),\n\n // Default\n default: z.unknown().optional(),\n\n // FormSpec extensions\n \"x-formspec-source\": z.string().optional(),\n \"x-formspec-params\": z.array(z.string()).readonly().optional(),\n \"x-formspec-schemaSource\": z.string().optional(),\n })\n // passthrough preserves arbitrary x-formspec-* extension properties\n // added by custom decorators without causing validation failures\n .passthrough()\n);\n","/**\n * TypeScript program setup for static analysis.\n *\n * Creates a TypeScript program with type checker from a source file,\n * using the project's tsconfig.json for compiler options.\n */\n\nimport * as ts from \"typescript\";\nimport * as path from \"node:path\";\n\n/**\n * Result of creating a TypeScript program for analysis.\n */\nexport interface ProgramContext {\n /** The TypeScript program */\n program: ts.Program;\n /** Type checker for resolving types */\n checker: ts.TypeChecker;\n /** The source file being analyzed */\n sourceFile: ts.SourceFile;\n}\n\n/**\n * Creates a TypeScript program for analyzing a source file.\n *\n * Looks for tsconfig.json in the file's directory or parent directories.\n * Falls back to default compiler options if no config is found.\n *\n * @param filePath - Absolute path to the TypeScript source file\n * @returns Program context with checker and source file\n */\nexport function createProgramContext(filePath: string): ProgramContext {\n const absolutePath = path.resolve(filePath);\n const fileDir = path.dirname(absolutePath);\n\n // Find tsconfig.json - using ts.sys.fileExists which has `this: void` requirement\n const configPath = ts.findConfigFile(fileDir, ts.sys.fileExists.bind(ts.sys), \"tsconfig.json\");\n\n let compilerOptions: ts.CompilerOptions;\n let fileNames: string[];\n\n if (configPath) {\n const configFile = ts.readConfigFile(configPath, ts.sys.readFile.bind(ts.sys));\n if (configFile.error) {\n throw new Error(\n `Error reading tsconfig.json: ${ts.flattenDiagnosticMessageText(configFile.error.messageText, \"\\n\")}`\n );\n }\n\n const parsed = ts.parseJsonConfigFileContent(\n configFile.config,\n ts.sys,\n path.dirname(configPath)\n );\n\n if (parsed.errors.length > 0) {\n const errorMessages = parsed.errors\n .map((e) => ts.flattenDiagnosticMessageText(e.messageText, \"\\n\"))\n .join(\"\\n\");\n throw new Error(`Error parsing tsconfig.json: ${errorMessages}`);\n }\n\n compilerOptions = parsed.options;\n // Include the target file in the program\n fileNames = parsed.fileNames.includes(absolutePath)\n ? parsed.fileNames\n : [...parsed.fileNames, absolutePath];\n } else {\n // Fallback to default options\n compilerOptions = {\n target: ts.ScriptTarget.ES2022,\n module: ts.ModuleKind.NodeNext,\n moduleResolution: ts.ModuleResolutionKind.NodeNext,\n strict: true,\n skipLibCheck: true,\n declaration: true,\n };\n fileNames = [absolutePath];\n }\n\n const program = ts.createProgram(fileNames, compilerOptions);\n const sourceFile = program.getSourceFile(absolutePath);\n\n if (!sourceFile) {\n throw new Error(`Could not find source file: ${absolutePath}`);\n }\n\n return {\n program,\n checker: program.getTypeChecker(),\n sourceFile,\n };\n}\n\n/**\n * Generic AST node finder by name. Walks the source file tree and returns\n * the first node matching the predicate with the given name.\n */\nfunction findNodeByName<T extends ts.Node>(\n sourceFile: ts.SourceFile,\n name: string,\n predicate: (node: ts.Node) => node is T,\n getName: (node: T) => string | undefined\n): T | null {\n let result: T | null = null;\n\n function visit(node: ts.Node): void {\n if (result) return;\n\n if (predicate(node) && getName(node) === name) {\n result = node;\n return;\n }\n\n ts.forEachChild(node, visit);\n }\n\n visit(sourceFile);\n return result;\n}\n\n/**\n * Finds a class declaration by name in a source file.\n *\n * @param sourceFile - The source file to search\n * @param className - Name of the class to find\n * @returns The class declaration node, or null if not found\n */\nexport function findClassByName(\n sourceFile: ts.SourceFile,\n className: string\n): ts.ClassDeclaration | null {\n return findNodeByName(sourceFile, className, ts.isClassDeclaration, (n) => n.name?.text);\n}\n\n/**\n * Finds an interface declaration by name in a source file.\n *\n * @param sourceFile - The source file to search\n * @param interfaceName - Name of the interface to find\n * @returns The interface declaration node, or null if not found\n */\nexport function findInterfaceByName(\n sourceFile: ts.SourceFile,\n interfaceName: string\n): ts.InterfaceDeclaration | null {\n return findNodeByName(sourceFile, interfaceName, ts.isInterfaceDeclaration, (n) => n.name.text);\n}\n\n/**\n * Finds a type alias declaration by name in a source file.\n *\n * @param sourceFile - The source file to search\n * @param aliasName - Name of the type alias to find\n * @returns The type alias declaration node, or null if not found\n */\nexport function findTypeAliasByName(\n sourceFile: ts.SourceFile,\n aliasName: string\n): ts.TypeAliasDeclaration | null {\n return findNodeByName(sourceFile, aliasName, ts.isTypeAliasDeclaration, (n) => n.name.text);\n}\n","/**\n * Class analyzer for extracting fields, types, and JSDoc constraints.\n *\n * Produces `IRClassAnalysis` containing `FieldNode[]` and `typeRegistry`\n * directly from class, interface, or type alias declarations.\n * All downstream generation routes through the canonical FormIR.\n */\n\nimport * as ts from \"typescript\";\nimport type {\n FieldNode,\n TypeNode,\n ConstraintNode,\n AnnotationNode,\n Provenance,\n ObjectProperty,\n TypeDefinition,\n JsonValue,\n} from \"@formspec/core\";\nimport {\n extractJSDocConstraintNodes,\n extractJSDocAnnotationNodes,\n extractDefaultValueAnnotation,\n} from \"./jsdoc-constraints.js\";\n\n// =============================================================================\n// TYPE GUARDS\n// =============================================================================\n\n/**\n * Type guard for ts.ObjectType — checks that the TypeFlags.Object bit is set.\n */\nfunction isObjectType(type: ts.Type): type is ts.ObjectType {\n return !!(type.flags & ts.TypeFlags.Object);\n}\n\n/**\n * Type guard for ts.TypeReference — checks ObjectFlags.Reference on top of ObjectType.\n * The internal `as` cast is isolated inside this guard and is required because\n * TypeScript's public API does not expose objectFlags on ts.Type directly.\n */\nfunction isTypeReference(type: ts.Type): type is ts.TypeReference {\n // as cast is isolated inside type guard\n return (\n !!(type.flags & ts.TypeFlags.Object) &&\n !!((type as ts.ObjectType).objectFlags & ts.ObjectFlags.Reference)\n );\n}\n\n// =============================================================================\n// IR OUTPUT TYPES\n// =============================================================================\n\n/**\n * Layout metadata extracted from `@Group` and `@ShowWhen` decorators.\n * One entry per field, in the same order as `fields`.\n */\nexport interface FieldLayoutMetadata {\n /** Group label from `@Group(\"label\")`, or undefined if ungrouped. */\n readonly groupLabel?: string;\n /** ShowWhen condition from `@ShowWhen({ field, value })`, or undefined if always visible. */\n readonly showWhen?: { readonly field: string; readonly value: JsonValue };\n}\n\n/**\n * Result of analyzing a class/interface/type alias into canonical IR.\n */\nexport interface IRClassAnalysis {\n /** Type name */\n readonly name: string;\n /** Analyzed fields as canonical IR FieldNodes */\n readonly fields: readonly FieldNode[];\n /** Layout metadata per field (same order/length as `fields`). */\n readonly fieldLayouts: readonly FieldLayoutMetadata[];\n /** Named type definitions referenced by fields */\n readonly typeRegistry: Record<string, TypeDefinition>;\n /** Instance methods (retained for downstream method-schema generation) */\n readonly instanceMethods: readonly MethodInfo[];\n /** Static methods */\n readonly staticMethods: readonly MethodInfo[];\n}\n\n/**\n * Result of analyzing a type alias into IR — either success or error.\n */\nexport type AnalyzeTypeAliasToIRResult =\n | { readonly ok: true; readonly analysis: IRClassAnalysis }\n | { readonly ok: false; readonly error: string };\n\n// =============================================================================\n// IR ANALYSIS — PUBLIC API\n// =============================================================================\n\n/**\n * Analyzes a class declaration and produces canonical IR FieldNodes.\n */\nexport function analyzeClassToIR(\n classDecl: ts.ClassDeclaration,\n checker: ts.TypeChecker,\n file = \"\"\n): IRClassAnalysis {\n const name = classDecl.name?.text ?? \"AnonymousClass\";\n const fields: FieldNode[] = [];\n const fieldLayouts: FieldLayoutMetadata[] = [];\n const typeRegistry: Record<string, TypeDefinition> = {};\n const visiting = new Set<ts.Type>();\n const instanceMethods: MethodInfo[] = [];\n const staticMethods: MethodInfo[] = [];\n\n for (const member of classDecl.members) {\n if (ts.isPropertyDeclaration(member)) {\n const fieldNode = analyzeFieldToIR(member, checker, file, typeRegistry, visiting);\n if (fieldNode) {\n fields.push(fieldNode);\n fieldLayouts.push({});\n }\n } else if (ts.isMethodDeclaration(member)) {\n const methodInfo = analyzeMethod(member, checker);\n if (methodInfo) {\n const isStatic = member.modifiers?.some((m) => m.kind === ts.SyntaxKind.StaticKeyword);\n if (isStatic) {\n staticMethods.push(methodInfo);\n } else {\n instanceMethods.push(methodInfo);\n }\n }\n }\n }\n\n return { name, fields, fieldLayouts, typeRegistry, instanceMethods, staticMethods };\n}\n\n/**\n * Analyzes an interface declaration and produces canonical IR FieldNodes.\n */\nexport function analyzeInterfaceToIR(\n interfaceDecl: ts.InterfaceDeclaration,\n checker: ts.TypeChecker,\n file = \"\"\n): IRClassAnalysis {\n const name = interfaceDecl.name.text;\n const fields: FieldNode[] = [];\n const typeRegistry: Record<string, TypeDefinition> = {};\n const visiting = new Set<ts.Type>();\n\n for (const member of interfaceDecl.members) {\n if (ts.isPropertySignature(member)) {\n const fieldNode = analyzeInterfacePropertyToIR(member, checker, file, typeRegistry, visiting);\n if (fieldNode) {\n fields.push(fieldNode);\n }\n }\n }\n\n const fieldLayouts: FieldLayoutMetadata[] = fields.map(() => ({}));\n return { name, fields, fieldLayouts, typeRegistry, instanceMethods: [], staticMethods: [] };\n}\n\n/**\n * Analyzes a type alias declaration and produces canonical IR FieldNodes.\n */\nexport function analyzeTypeAliasToIR(\n typeAlias: ts.TypeAliasDeclaration,\n checker: ts.TypeChecker,\n file = \"\"\n): AnalyzeTypeAliasToIRResult {\n if (!ts.isTypeLiteralNode(typeAlias.type)) {\n const sourceFile = typeAlias.getSourceFile();\n const { line } = sourceFile.getLineAndCharacterOfPosition(typeAlias.getStart());\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- enum reverse mapping can be undefined for compiler-internal kinds\n const kindDesc = ts.SyntaxKind[typeAlias.type.kind] ?? \"unknown\";\n return {\n ok: false,\n error: `Type alias \"${typeAlias.name.text}\" at line ${String(line + 1)} is not an object type literal (found ${kindDesc})`,\n };\n }\n\n const name = typeAlias.name.text;\n const fields: FieldNode[] = [];\n const typeRegistry: Record<string, TypeDefinition> = {};\n const visiting = new Set<ts.Type>();\n\n for (const member of typeAlias.type.members) {\n if (ts.isPropertySignature(member)) {\n const fieldNode = analyzeInterfacePropertyToIR(member, checker, file, typeRegistry, visiting);\n if (fieldNode) {\n fields.push(fieldNode);\n }\n }\n }\n\n return {\n ok: true,\n analysis: {\n name,\n fields,\n fieldLayouts: fields.map(() => ({})),\n typeRegistry,\n instanceMethods: [],\n staticMethods: [],\n },\n };\n}\n\n// =============================================================================\n// IR FIELD ANALYSIS — PRIVATE\n// =============================================================================\n\n/**\n * Analyzes a class property declaration into a canonical IR FieldNode.\n */\nfunction analyzeFieldToIR(\n prop: ts.PropertyDeclaration,\n checker: ts.TypeChecker,\n file: string,\n typeRegistry: Record<string, TypeDefinition>,\n visiting: Set<ts.Type>\n): FieldNode | null {\n if (!ts.isIdentifier(prop.name)) {\n return null;\n }\n\n const name = prop.name.text;\n const tsType = checker.getTypeAtLocation(prop);\n const optional = prop.questionToken !== undefined;\n const provenance = provenanceForNode(prop, file);\n\n // Resolve ts.Type → TypeNode\n const type = resolveTypeNode(tsType, checker, file, typeRegistry, visiting);\n\n // Collect constraints\n const constraints: ConstraintNode[] = [];\n\n // Inherit constraints from type alias declarations (lower precedence)\n if (prop.type) {\n constraints.push(...extractTypeAliasConstraintNodes(prop.type, checker, file));\n }\n\n // Extract JSDoc constraints\n constraints.push(...extractJSDocConstraintNodes(prop, file));\n\n // Collect annotations\n const annotations: AnnotationNode[] = [];\n\n // JSDoc annotations (@Field_displayName, @Field_description, @deprecated)\n annotations.push(...extractJSDocAnnotationNodes(prop, file));\n\n // Default value annotation\n const defaultAnnotation = extractDefaultValueAnnotation(prop.initializer, file);\n if (defaultAnnotation) {\n annotations.push(defaultAnnotation);\n }\n\n return {\n kind: \"field\",\n name,\n type,\n required: !optional,\n constraints,\n annotations,\n provenance,\n };\n}\n\n/**\n * Analyzes an interface/type-alias property signature into a canonical IR FieldNode.\n */\nfunction analyzeInterfacePropertyToIR(\n prop: ts.PropertySignature,\n checker: ts.TypeChecker,\n file: string,\n typeRegistry: Record<string, TypeDefinition>,\n visiting: Set<ts.Type>\n): FieldNode | null {\n if (!ts.isIdentifier(prop.name)) {\n return null;\n }\n\n const name = prop.name.text;\n const tsType = checker.getTypeAtLocation(prop);\n const optional = prop.questionToken !== undefined;\n const provenance = provenanceForNode(prop, file);\n\n // Resolve ts.Type → TypeNode\n const type = resolveTypeNode(tsType, checker, file, typeRegistry, visiting);\n\n // Collect constraints\n const constraints: ConstraintNode[] = [];\n\n // Inherit constraints from type alias declarations\n if (prop.type) {\n constraints.push(...extractTypeAliasConstraintNodes(prop.type, checker, file));\n }\n\n // JSDoc constraints\n constraints.push(...extractJSDocConstraintNodes(prop, file));\n\n // Collect annotations\n const annotations: AnnotationNode[] = [];\n\n // JSDoc annotations (@Field_displayName, @Field_description, @deprecated)\n annotations.push(...extractJSDocAnnotationNodes(prop, file));\n\n return {\n kind: \"field\",\n name,\n type,\n required: !optional,\n constraints,\n annotations,\n provenance,\n };\n}\n\n// =============================================================================\n// TYPE RESOLUTION — ts.Type → TypeNode\n// =============================================================================\n\n/**\n * Resolves a TypeScript type to a canonical IR TypeNode.\n */\nexport function resolveTypeNode(\n type: ts.Type,\n checker: ts.TypeChecker,\n file: string,\n typeRegistry: Record<string, TypeDefinition>,\n visiting: Set<ts.Type>\n): TypeNode {\n // --- Primitives ---\n if (type.flags & ts.TypeFlags.String) {\n return { kind: \"primitive\", primitiveKind: \"string\" };\n }\n if (type.flags & ts.TypeFlags.Number) {\n return { kind: \"primitive\", primitiveKind: \"number\" };\n }\n if (type.flags & ts.TypeFlags.Boolean) {\n return { kind: \"primitive\", primitiveKind: \"boolean\" };\n }\n if (type.flags & ts.TypeFlags.Null) {\n return { kind: \"primitive\", primitiveKind: \"null\" };\n }\n if (type.flags & ts.TypeFlags.Undefined) {\n // Undefined maps to null for nullable semantics in JSON Schema\n return { kind: \"primitive\", primitiveKind: \"null\" };\n }\n\n // --- String literal ---\n if (type.isStringLiteral()) {\n return {\n kind: \"enum\",\n members: [{ value: type.value }],\n };\n }\n\n // --- Number literal ---\n if (type.isNumberLiteral()) {\n return {\n kind: \"enum\",\n members: [{ value: type.value }],\n };\n }\n\n // --- Union types ---\n if (type.isUnion()) {\n return resolveUnionType(type, checker, file, typeRegistry, visiting);\n }\n\n // --- Array types ---\n if (checker.isArrayType(type)) {\n return resolveArrayType(type, checker, file, typeRegistry, visiting);\n }\n\n // --- Object types ---\n if (isObjectType(type)) {\n return resolveObjectType(type, checker, file, typeRegistry, visiting);\n }\n\n // --- Fallback: treat unknown/any/void as string ---\n return { kind: \"primitive\", primitiveKind: \"string\" };\n}\n\nfunction resolveUnionType(\n type: ts.UnionType,\n checker: ts.TypeChecker,\n file: string,\n typeRegistry: Record<string, TypeDefinition>,\n visiting: Set<ts.Type>\n): TypeNode {\n const allTypes = type.types;\n\n const nonNullTypes = allTypes.filter(\n (t) => !(t.flags & (ts.TypeFlags.Null | ts.TypeFlags.Undefined))\n );\n const hasNull = allTypes.some((t) => t.flags & ts.TypeFlags.Null);\n\n // Boolean union: true | false → boolean primitive\n const isBooleanUnion =\n nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags & ts.TypeFlags.BooleanLiteral);\n\n if (isBooleanUnion) {\n const boolNode: TypeNode = { kind: \"primitive\", primitiveKind: \"boolean\" };\n if (hasNull) {\n return {\n kind: \"union\",\n members: [boolNode, { kind: \"primitive\", primitiveKind: \"null\" }],\n };\n }\n return boolNode;\n }\n\n // All string literals → EnumTypeNode\n const allStringLiterals = nonNullTypes.every((t) => t.isStringLiteral());\n if (allStringLiterals && nonNullTypes.length > 0) {\n const stringTypes = nonNullTypes.filter((t): t is ts.StringLiteralType => t.isStringLiteral());\n const enumNode: TypeNode = {\n kind: \"enum\",\n members: stringTypes.map((t) => ({ value: t.value })),\n };\n if (hasNull) {\n return {\n kind: \"union\",\n members: [enumNode, { kind: \"primitive\", primitiveKind: \"null\" }],\n };\n }\n return enumNode;\n }\n\n // All number literals → EnumTypeNode\n const allNumberLiterals = nonNullTypes.every((t) => t.isNumberLiteral());\n if (allNumberLiterals && nonNullTypes.length > 0) {\n const numberTypes = nonNullTypes.filter((t): t is ts.NumberLiteralType => t.isNumberLiteral());\n const enumNode: TypeNode = {\n kind: \"enum\",\n members: numberTypes.map((t) => ({ value: t.value })),\n };\n if (hasNull) {\n return {\n kind: \"union\",\n members: [enumNode, { kind: \"primitive\", primitiveKind: \"null\" }],\n };\n }\n return enumNode;\n }\n\n // Nullable wrapper: T | null with single non-null type\n if (nonNullTypes.length === 1 && nonNullTypes[0]) {\n const inner = resolveTypeNode(nonNullTypes[0], checker, file, typeRegistry, visiting);\n if (hasNull) {\n return {\n kind: \"union\",\n members: [inner, { kind: \"primitive\", primitiveKind: \"null\" }],\n };\n }\n return inner;\n }\n\n // General union\n const members = nonNullTypes.map((t) =>\n resolveTypeNode(t, checker, file, typeRegistry, visiting)\n );\n if (hasNull) {\n members.push({ kind: \"primitive\", primitiveKind: \"null\" });\n }\n return { kind: \"union\", members };\n}\n\nfunction resolveArrayType(\n type: ts.Type,\n checker: ts.TypeChecker,\n file: string,\n typeRegistry: Record<string, TypeDefinition>,\n visiting: Set<ts.Type>\n): TypeNode {\n const typeArgs = isTypeReference(type) ? type.typeArguments : undefined;\n const elementType = typeArgs?.[0];\n\n const items = elementType\n ? resolveTypeNode(elementType, checker, file, typeRegistry, visiting)\n : ({ kind: \"primitive\", primitiveKind: \"string\" } satisfies TypeNode);\n\n return { kind: \"array\", items };\n}\n\nfunction resolveObjectType(\n type: ts.ObjectType,\n checker: ts.TypeChecker,\n file: string,\n typeRegistry: Record<string, TypeDefinition>,\n visiting: Set<ts.Type>\n): TypeNode {\n // Circular reference guard\n if (visiting.has(type)) {\n return { kind: \"object\", properties: [], additionalProperties: false };\n }\n visiting.add(type);\n\n // Check if this is a named type already in the registry\n const typeName = getNamedTypeName(type);\n if (typeName && typeName in typeRegistry) {\n visiting.delete(type);\n return { kind: \"reference\", name: typeName, typeArguments: [] };\n }\n\n const properties: ObjectProperty[] = [];\n\n // Get FieldInfo-level analysis from named type declarations for constraint propagation\n const fieldInfoMap = getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visiting);\n\n for (const prop of type.getProperties()) {\n const declaration = prop.valueDeclaration ?? prop.declarations?.[0];\n if (!declaration) continue;\n\n const propType = checker.getTypeOfSymbolAtLocation(prop, declaration);\n const optional = !!(prop.flags & ts.SymbolFlags.Optional);\n const propTypeNode = resolveTypeNode(propType, checker, file, typeRegistry, visiting);\n\n // Get constraints and annotations from the declaration if available\n const fieldNodeInfo = fieldInfoMap?.get(prop.name);\n\n properties.push({\n name: prop.name,\n type: propTypeNode,\n optional,\n constraints: fieldNodeInfo?.constraints ?? [],\n annotations: fieldNodeInfo?.annotations ?? [],\n provenance: fieldNodeInfo?.provenance ?? provenanceForFile(file),\n });\n }\n\n visiting.delete(type);\n\n const objectNode: TypeNode = {\n kind: \"object\",\n properties,\n additionalProperties: false,\n };\n\n // Register named types\n if (typeName) {\n typeRegistry[typeName] = {\n name: typeName,\n type: objectNode,\n provenance: provenanceForFile(file),\n };\n return { kind: \"reference\", name: typeName, typeArguments: [] };\n }\n\n return objectNode;\n}\n\n// =============================================================================\n// NAMED TYPE FIELD INFO MAP — for nested constraint propagation\n// =============================================================================\n\ninterface FieldNodeInfo {\n readonly constraints: readonly ConstraintNode[];\n readonly annotations: readonly AnnotationNode[];\n readonly provenance: Provenance;\n}\n\n/**\n * Builds a map from property name to constraint/annotation info for named types.\n * This enables propagating TSDoc constraints from nested type declarations.\n */\nfunction getNamedTypeFieldNodeInfoMap(\n type: ts.Type,\n checker: ts.TypeChecker,\n file: string,\n typeRegistry: Record<string, TypeDefinition>,\n visiting: Set<ts.Type>\n): Map<string, FieldNodeInfo> | null {\n const symbols = [type.getSymbol(), type.aliasSymbol].filter(\n (s): s is ts.Symbol => s?.declarations != null && s.declarations.length > 0\n );\n\n for (const symbol of symbols) {\n const declarations = symbol.declarations;\n if (!declarations) continue;\n\n // Try class declaration\n const classDecl = declarations.find(ts.isClassDeclaration);\n if (classDecl) {\n const map = new Map<string, FieldNodeInfo>();\n for (const member of classDecl.members) {\n if (ts.isPropertyDeclaration(member) && ts.isIdentifier(member.name)) {\n const fieldNode = analyzeFieldToIR(member, checker, file, typeRegistry, visiting);\n if (fieldNode) {\n map.set(fieldNode.name, {\n constraints: [...fieldNode.constraints],\n annotations: [...fieldNode.annotations],\n provenance: fieldNode.provenance,\n });\n }\n }\n }\n return map;\n }\n\n // Try interface declaration\n const interfaceDecl = declarations.find(ts.isInterfaceDeclaration);\n if (interfaceDecl) {\n return buildFieldNodeInfoMap(interfaceDecl.members, checker, file, typeRegistry, visiting);\n }\n\n // Try type alias with type literal body\n const typeAliasDecl = declarations.find(ts.isTypeAliasDeclaration);\n if (typeAliasDecl && ts.isTypeLiteralNode(typeAliasDecl.type)) {\n return buildFieldNodeInfoMap(\n typeAliasDecl.type.members,\n checker,\n file,\n typeRegistry,\n visiting\n );\n }\n }\n\n return null;\n}\n\nfunction buildFieldNodeInfoMap(\n members: ts.NodeArray<ts.TypeElement>,\n checker: ts.TypeChecker,\n file: string,\n typeRegistry: Record<string, TypeDefinition>,\n visiting: Set<ts.Type>\n): Map<string, FieldNodeInfo> {\n const map = new Map<string, FieldNodeInfo>();\n for (const member of members) {\n if (ts.isPropertySignature(member)) {\n const fieldNode = analyzeInterfacePropertyToIR(member, checker, file, typeRegistry, visiting);\n if (fieldNode) {\n map.set(fieldNode.name, {\n constraints: [...fieldNode.constraints],\n annotations: [...fieldNode.annotations],\n provenance: fieldNode.provenance,\n });\n }\n }\n }\n return map;\n}\n\n// =============================================================================\n// TYPE ALIAS CONSTRAINT PROPAGATION\n// =============================================================================\n\n/**\n * Given a type node referencing a type alias, extracts IR ConstraintNodes\n * from the alias declaration's JSDoc tags.\n */\nfunction extractTypeAliasConstraintNodes(\n typeNode: ts.TypeNode,\n checker: ts.TypeChecker,\n file: string\n): ConstraintNode[] {\n if (!ts.isTypeReferenceNode(typeNode)) return [];\n\n const symbol = checker.getSymbolAtLocation(typeNode.typeName);\n if (!symbol?.declarations) return [];\n\n const aliasDecl = symbol.declarations.find(ts.isTypeAliasDeclaration);\n if (!aliasDecl) return [];\n\n // Don't extract from object type aliases\n if (ts.isTypeLiteralNode(aliasDecl.type)) return [];\n\n return extractJSDocConstraintNodes(aliasDecl, file);\n}\n\n// =============================================================================\n// PROVENANCE HELPERS\n// =============================================================================\n\nfunction provenanceForNode(node: ts.Node, file: string): Provenance {\n const sourceFile = node.getSourceFile();\n const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n return {\n surface: \"tsdoc\",\n file,\n line: line + 1,\n column: character,\n };\n}\n\nfunction provenanceForFile(file: string): Provenance {\n return { surface: \"tsdoc\", file, line: 0, column: 0 };\n}\n\n// =============================================================================\n// NAMED TYPE HELPERS\n// =============================================================================\n\n/**\n * Extracts a stable type name from a ts.ObjectType when it originates from\n * a named declaration (class, interface, or type alias).\n */\nfunction getNamedTypeName(type: ts.ObjectType): string | null {\n const symbol = type.getSymbol();\n if (symbol?.declarations) {\n const decl = symbol.declarations[0];\n if (\n decl &&\n (ts.isClassDeclaration(decl) ||\n ts.isInterfaceDeclaration(decl) ||\n ts.isTypeAliasDeclaration(decl))\n ) {\n const name = ts.isClassDeclaration(decl) ? decl.name?.text : decl.name.text;\n if (name) return name;\n }\n }\n\n const aliasSymbol = type.aliasSymbol;\n if (aliasSymbol?.declarations) {\n const aliasDecl = aliasSymbol.declarations.find(ts.isTypeAliasDeclaration);\n if (aliasDecl) {\n return aliasDecl.name.text;\n }\n }\n\n return null;\n}\n\n// =============================================================================\n// SHARED OUTPUT TYPES\n// =============================================================================\n\n/**\n * Analyzed method information.\n */\nexport interface MethodInfo {\n /** Method name */\n name: string;\n /** Method parameters */\n parameters: ParameterInfo[];\n /** Return type node */\n returnTypeNode: ts.TypeNode | undefined;\n /** Resolved return type */\n returnType: ts.Type;\n}\n\n/**\n * Analyzed parameter information.\n */\nexport interface ParameterInfo {\n /** Parameter name */\n name: string;\n /** TypeScript type node */\n typeNode: ts.TypeNode | undefined;\n /** Resolved type */\n type: ts.Type;\n /** If this is InferSchema<typeof X>, the export name X */\n formSpecExportName: string | null;\n /** Whether the parameter is optional (has ? or default value) */\n optional: boolean;\n}\n\n// =============================================================================\n// SHARED HELPERS\n// =============================================================================\n\n/**\n * Analyzes a method declaration to extract method info.\n * Shared between IR and legacy paths.\n */\nfunction analyzeMethod(method: ts.MethodDeclaration, checker: ts.TypeChecker): MethodInfo | null {\n if (!ts.isIdentifier(method.name)) {\n return null;\n }\n\n const name = method.name.text;\n const parameters: ParameterInfo[] = [];\n\n for (const param of method.parameters) {\n if (ts.isIdentifier(param.name)) {\n const paramInfo = analyzeParameter(param, checker);\n parameters.push(paramInfo);\n }\n }\n\n const returnTypeNode = method.type;\n const signature = checker.getSignatureFromDeclaration(method);\n const returnType = signature\n ? checker.getReturnTypeOfSignature(signature)\n : checker.getTypeAtLocation(method);\n\n return { name, parameters, returnTypeNode, returnType };\n}\n\nfunction analyzeParameter(param: ts.ParameterDeclaration, checker: ts.TypeChecker): ParameterInfo {\n const name = ts.isIdentifier(param.name) ? param.name.text : \"param\";\n const typeNode = param.type;\n const type = checker.getTypeAtLocation(param);\n const formSpecExportName = detectFormSpecReference(typeNode);\n const optional = param.questionToken !== undefined || param.initializer !== undefined;\n\n return { name, typeNode, type, formSpecExportName, optional };\n}\n\nfunction detectFormSpecReference(typeNode: ts.TypeNode | undefined): string | null {\n if (!typeNode) return null;\n\n if (!ts.isTypeReferenceNode(typeNode)) return null;\n\n const typeName = ts.isIdentifier(typeNode.typeName)\n ? typeNode.typeName.text\n : ts.isQualifiedName(typeNode.typeName)\n ? typeNode.typeName.right.text\n : null;\n\n if (typeName !== \"InferSchema\" && typeName !== \"InferFormSchema\") return null;\n\n const typeArg = typeNode.typeArguments?.[0];\n if (!typeArg || !ts.isTypeQueryNode(typeArg)) return null;\n\n if (ts.isIdentifier(typeArg.exprName)) {\n return typeArg.exprName.text;\n }\n\n if (ts.isQualifiedName(typeArg.exprName)) {\n return typeArg.exprName.right.text;\n }\n\n return null;\n}\n","/**\n * JSDoc constraint and annotation extractor.\n *\n * Extracts constraints and annotation tags from JSDoc comments on\n * class/interface fields and returns canonical IR nodes directly:\n * - {@link ConstraintNode} for set-influencing tags (@Minimum, @Pattern, etc.)\n * - {@link AnnotationNode} for value-influencing tags (@Field_displayName, etc.)\n *\n * The IR extraction path uses the official `@microsoft/tsdoc` parser for\n * constraints (all TSDoc-compliant alphanumeric names) and the TypeScript\n * compiler JSDoc API for annotation tags (which contain underscores, e.g.\n * `@Field_displayName`).\n *\n * Supported constraints correspond to keys in {@link BUILTIN_CONSTRAINT_DEFINITIONS}\n * from `@formspec/core` (e.g., `@Minimum`, `@Maximum`, `@Pattern`).\n */\n\nimport * as ts from \"typescript\";\nimport {\n BUILTIN_CONSTRAINT_DEFINITIONS,\n type BuiltinConstraintName,\n type ConstraintNode,\n type AnnotationNode,\n type JsonValue,\n} from \"@formspec/core\";\nimport { parseTSDocTags, hasDeprecatedTagTSDoc } from \"./tsdoc-parser.js\";\n\n// =============================================================================\n// Legacy types — previously in decorator-extractor.ts, now owned here\n// =============================================================================\n\n/**\n * A constraint argument value.\n */\nexport type ConstraintArg =\n | string\n | number\n | boolean\n | null\n | ConstraintArg[]\n | { [key: string]: ConstraintArg };\n\n/**\n * Extracted constraint information from a JSDoc tag.\n * @deprecated Use {@link ConstraintNode} from the IR path instead.\n */\nexport interface ConstraintInfo {\n /** Constraint name (e.g., \"Minimum\", \"Pattern\", \"Field\") */\n name: string;\n /** Constraint arguments as literal values */\n args: ConstraintArg[];\n /** Raw AST node (undefined for synthetic JSDoc constraint entries) */\n node: ts.Decorator | undefined;\n}\n\n// =============================================================================\n// IR API — uses @microsoft/tsdoc for structured parsing\n// =============================================================================\n\n/**\n * Extracts constraints from JSDoc comments on a TypeScript AST node and returns\n * canonical {@link ConstraintNode} objects.\n *\n * Uses the official `@microsoft/tsdoc` parser for structured tag extraction.\n * Constraints are registered as custom block tags in the TSDoc configuration.\n *\n * @param node - The AST node to inspect for JSDoc tags\n * @param file - Absolute path to the source file for provenance\n * @returns Canonical constraint nodes for each valid constraint tag\n */\nexport function extractJSDocConstraintNodes(node: ts.Node, file = \"\"): ConstraintNode[] {\n const result = parseTSDocTags(node, file);\n return [...result.constraints];\n}\n\n/**\n * Extracts `@Field_displayName`, `@Field_description`, and `@deprecated`\n * TSDoc tags from a node and returns canonical {@link AnnotationNode} objects.\n *\n * Uses a hybrid approach:\n * - `@deprecated` is extracted via the TSDoc parser (standard tag).\n * - `@Field_displayName` and `@Field_description` are extracted via the\n * TypeScript compiler JSDoc API because they contain underscores which\n * are invalid in TSDoc tag names.\n *\n * @param node - The AST node to inspect for annotation tags\n * @param file - Absolute path to the source file for provenance\n * @returns Canonical annotation nodes\n */\nexport function extractJSDocAnnotationNodes(node: ts.Node, file = \"\"): AnnotationNode[] {\n const result = parseTSDocTags(node, file);\n return [...result.annotations];\n}\n\n/**\n * Checks if a node has a TSDoc `@deprecated` tag.\n *\n * Uses the TSDoc parser for structured detection.\n */\nexport function hasDeprecatedTag(node: ts.Node): boolean {\n return hasDeprecatedTagTSDoc(node);\n}\n\n/**\n * Extracts a default value from a property initializer and returns a\n * {@link DefaultValueAnnotationNode} if present.\n *\n * Only extracts literal values (strings, numbers, booleans, null).\n */\nexport function extractDefaultValueAnnotation(\n initializer: ts.Expression | undefined,\n file = \"\"\n): AnnotationNode | null {\n if (!initializer) return null;\n\n let value: JsonValue | undefined;\n\n if (ts.isStringLiteral(initializer)) {\n value = initializer.text;\n } else if (ts.isNumericLiteral(initializer)) {\n value = Number(initializer.text);\n } else if (initializer.kind === ts.SyntaxKind.TrueKeyword) {\n value = true;\n } else if (initializer.kind === ts.SyntaxKind.FalseKeyword) {\n value = false;\n } else if (initializer.kind === ts.SyntaxKind.NullKeyword) {\n value = null;\n } else if (ts.isPrefixUnaryExpression(initializer)) {\n if (\n initializer.operator === ts.SyntaxKind.MinusToken &&\n ts.isNumericLiteral(initializer.operand)\n ) {\n value = -Number(initializer.operand.text);\n }\n }\n\n if (value === undefined) return null;\n\n const sourceFile = initializer.getSourceFile();\n const { line, character } = sourceFile.getLineAndCharacterOfPosition(initializer.getStart());\n\n return {\n kind: \"annotation\",\n annotationKind: \"defaultValue\",\n value,\n provenance: {\n surface: \"tsdoc\",\n file,\n line: line + 1,\n column: character,\n },\n };\n}\n\n// =============================================================================\n// LEGACY API — backward compatibility for decorator-based pipeline\n// =============================================================================\n\n/**\n * Extracts JSDoc constraint tags and returns synthetic {@link ConstraintInfo}\n * objects for backward compatibility with the decorator-based pipeline.\n *\n * Uses the TypeScript compiler JSDoc API (not TSDoc parser) to maintain\n * identical behavior with the legacy pipeline.\n *\n * @deprecated Use {@link extractJSDocConstraintNodes} for IR output.\n */\nexport function extractJSDocConstraints(node: ts.Node): ConstraintInfo[] {\n const results: ConstraintInfo[] = [];\n const jsDocTags = ts.getJSDocTags(node);\n\n for (const tag of jsDocTags) {\n const tagName = tag.tagName.text;\n\n if (!(tagName in BUILTIN_CONSTRAINT_DEFINITIONS)) {\n continue;\n }\n\n const constraintName = tagName as BuiltinConstraintName;\n const expectedType = BUILTIN_CONSTRAINT_DEFINITIONS[constraintName];\n\n const commentText = getTagCommentText(tag);\n if (commentText === undefined || commentText === \"\") {\n continue;\n }\n\n const trimmed = commentText.trim();\n if (trimmed === \"\") {\n continue;\n }\n\n if (expectedType === \"number\") {\n const value = Number(trimmed);\n if (Number.isNaN(value)) {\n continue;\n }\n results.push(createSyntheticDecorator(constraintName, value));\n } else if (expectedType === \"json\") {\n try {\n const parsed: unknown = JSON.parse(trimmed);\n if (!Array.isArray(parsed)) {\n continue;\n }\n results.push(createSyntheticDecorator(constraintName, parsed as ConstraintArg));\n } catch {\n continue;\n }\n } else {\n results.push(createSyntheticDecorator(constraintName, trimmed));\n }\n }\n\n return results;\n}\n\n/**\n * Extracts `@Field_displayName` and `@Field_description` TSDoc tags\n * and returns a synthetic `Field` {@link ConstraintInfo} for backward\n * compatibility with the decorator-based pipeline.\n *\n * @deprecated Use {@link extractJSDocAnnotationNodes} for IR output.\n */\nexport function extractJSDocFieldMetadata(node: ts.Node): ConstraintInfo | null {\n const jsDocTags = ts.getJSDocTags(node);\n\n let displayName: string | undefined;\n let description: string | undefined;\n\n for (const tag of jsDocTags) {\n const tagName = tag.tagName.text;\n const commentText = getTagCommentText(tag);\n if (commentText === undefined || commentText.trim() === \"\") {\n continue;\n }\n\n const trimmed = commentText.trim();\n\n if (tagName === \"Field_displayName\") {\n displayName = trimmed;\n } else if (tagName === \"Field_description\") {\n description = trimmed;\n }\n }\n\n if (displayName === undefined && description === undefined) {\n return null;\n }\n\n const fieldOpts: Record<string, ConstraintArg> = {\n ...(displayName !== undefined ? { displayName } : {}),\n ...(description !== undefined ? { description } : {}),\n };\n\n return createSyntheticDecorator(\"Field\", fieldOpts);\n}\n\n// =============================================================================\n// PRIVATE HELPERS\n// =============================================================================\n\n/**\n * Extracts the text content from a JSDoc tag's comment.\n *\n * The `tag.comment` property can be a plain string, an array of\n * `JSDocComment` nodes, or undefined. This helper normalises all\n * three cases to a single `string | undefined`.\n */\nfunction getTagCommentText(tag: ts.JSDocTag): string | undefined {\n if (tag.comment === undefined) {\n return undefined;\n }\n if (typeof tag.comment === \"string\") {\n return tag.comment;\n }\n // NodeArray<JSDocComment> — concatenate text spans\n return ts.getTextOfJSDocComment(tag.comment);\n}\n\n/**\n * Creates a synthetic {@link ConstraintInfo} for backward compatibility.\n */\nfunction createSyntheticDecorator(name: string, value: ConstraintArg): ConstraintInfo {\n return {\n name,\n args: [value],\n node: undefined,\n };\n}\n","/**\n * TSDoc-based structured tag parser.\n *\n * Bridges the TypeScript compiler AST with the official `@microsoft/tsdoc`\n * parser to extract constraint and annotation tags from JSDoc comments\n * on class/interface/type-alias properties.\n *\n * The parser recognises two categories of tags:\n *\n * 1. **Constraint tags** (all alphanumeric, TSDoc-compliant):\n * `@Minimum`, `@Maximum`, `@ExclusiveMinimum`, `@ExclusiveMaximum`,\n * `@MinLength`, `@MaxLength`, `@Pattern`, `@EnumOptions`\n * — Parsed via TSDocParser as custom block tags.\n *\n * 2. **Annotation tags** (`@Field_displayName`, `@Field_description`):\n * These contain underscores which are not valid in TSDoc tag names.\n * They are extracted via the TypeScript compiler's `ts.getJSDocTags()`\n * until a future migration to underscore-free tag names.\n *\n * The `@deprecated` tag is a standard TSDoc block tag, parsed structurally.\n *\n * **Fallback strategy**: TSDoc treats `{` / `}` as inline tag delimiters and\n * `@` as a tag prefix, so content containing these characters (e.g. JSON\n * objects in `@EnumOptions`, regex patterns with `@` in `@Pattern`) gets\n * mangled by the TSDoc parser. For these tags, the raw text is extracted\n * via the TS compiler's `ts.getJSDocTags()` API which preserves content\n * verbatim.\n */\n\nimport * as ts from \"typescript\";\nimport {\n TSDocParser,\n TSDocConfiguration,\n TSDocTagDefinition,\n TSDocTagSyntaxKind,\n DocPlainText,\n DocSoftBreak,\n TextRange,\n type DocNode,\n type DocBlock,\n} from \"@microsoft/tsdoc\";\nimport {\n BUILTIN_CONSTRAINT_DEFINITIONS,\n type BuiltinConstraintName,\n type ConstraintNode,\n type AnnotationNode,\n type Provenance,\n type NumericConstraintNode,\n type LengthConstraintNode,\n} from \"@formspec/core\";\n\n// =============================================================================\n// CONFIGURATION\n// =============================================================================\n\n/**\n * Constraint tag name → constraint kind mapping for numeric constraints.\n */\nconst NUMERIC_CONSTRAINT_MAP: Record<string, NumericConstraintNode[\"constraintKind\"]> = {\n Minimum: \"minimum\",\n Maximum: \"maximum\",\n ExclusiveMinimum: \"exclusiveMinimum\",\n ExclusiveMaximum: \"exclusiveMaximum\",\n};\n\n/**\n * Constraint tag name → constraint kind mapping for length constraints.\n */\nconst LENGTH_CONSTRAINT_MAP: Record<string, LengthConstraintNode[\"constraintKind\"]> = {\n MinLength: \"minLength\",\n MaxLength: \"maxLength\",\n};\n\n/**\n * Tags whose content may contain TSDoc-significant characters (`{}`, `@`)\n * and must be extracted via the TS compiler JSDoc API rather than the\n * TSDoc DocNode tree to avoid content mangling.\n *\n * - `@Pattern`: regex patterns commonly contain `@` (e.g. email validation)\n * - `@EnumOptions`: JSON arrays may contain object literals with `{}`\n */\nconst TAGS_REQUIRING_RAW_TEXT = new Set([\"Pattern\", \"EnumOptions\"]);\n\n/**\n * Type guard that checks whether a tag name is a known BuiltinConstraintName.\n */\nfunction isBuiltinConstraintName(tagName: string): tagName is BuiltinConstraintName {\n return tagName in BUILTIN_CONSTRAINT_DEFINITIONS;\n}\n\n/**\n * Creates a TSDocConfiguration with FormSpec custom block tag definitions\n * registered for all constraint tags.\n */\nfunction createFormSpecTSDocConfig(): TSDocConfiguration {\n const config = new TSDocConfiguration();\n\n // Register each constraint tag as a custom block tag (allowMultiple so\n // repeated tags don't produce warnings).\n for (const tagName of Object.keys(BUILTIN_CONSTRAINT_DEFINITIONS)) {\n config.addTagDefinition(\n new TSDocTagDefinition({\n tagName: \"@\" + tagName,\n syntaxKind: TSDocTagSyntaxKind.BlockTag,\n allowMultiple: true,\n })\n );\n }\n\n return config;\n}\n\n/**\n * Shared parser instance — thread-safe because TSDocParser is stateless;\n * all parse state lives in the returned ParserContext.\n */\nlet sharedParser: TSDocParser | undefined;\n\nfunction getParser(): TSDocParser {\n sharedParser ??= new TSDocParser(createFormSpecTSDocConfig());\n return sharedParser;\n}\n\n// =============================================================================\n// PUBLIC API\n// =============================================================================\n\n/**\n * Result of parsing a single JSDoc comment attached to a TS AST node.\n */\nexport interface TSDocParseResult {\n /** Constraint IR nodes extracted from custom block tags. */\n readonly constraints: readonly ConstraintNode[];\n /** Annotation IR nodes extracted from modifier/block tags and TS JSDoc API. */\n readonly annotations: readonly AnnotationNode[];\n}\n\n/**\n * Parses the JSDoc comment attached to a TypeScript AST node using the\n * official TSDoc parser and returns canonical IR constraint and annotation\n * nodes.\n *\n * For constraint tags (`@Minimum`, `@Pattern`, `@EnumOptions`, etc.),\n * the structured TSDoc parser is used. For annotation tags that contain\n * underscores (`@Field_displayName`, `@Field_description`), the TypeScript\n * compiler JSDoc API is used as a fallback.\n *\n * @param node - The TS AST node to inspect (PropertyDeclaration, PropertySignature, etc.)\n * @param file - Absolute source file path for provenance\n * @returns Parsed constraint and annotation nodes\n */\nexport function parseTSDocTags(node: ts.Node, file = \"\"): TSDocParseResult {\n const constraints: ConstraintNode[] = [];\n const annotations: AnnotationNode[] = [];\n\n // ----- Phase 1: TSDoc structural parse for constraint tags -----\n const sourceFile = node.getSourceFile();\n const sourceText = sourceFile.getFullText();\n const commentRanges = ts.getLeadingCommentRanges(sourceText, node.getFullStart());\n\n if (commentRanges) {\n for (const range of commentRanges) {\n // Only parse /** ... */ comments (kind 3 = MultiLineCommentTrivia)\n if (range.kind !== ts.SyntaxKind.MultiLineCommentTrivia) {\n continue;\n }\n const commentText = sourceText.substring(range.pos, range.end);\n if (!commentText.startsWith(\"/**\")) {\n continue;\n }\n\n const parser = getParser();\n const parserContext = parser.parseRange(\n TextRange.fromStringRange(sourceText, range.pos, range.end)\n );\n const docComment = parserContext.docComment;\n\n // Extract constraint nodes from custom blocks.\n // Tags in TAGS_REQUIRING_RAW_TEXT are skipped here and handled via the\n // TS compiler API in Phase 1b below.\n for (const block of docComment.customBlocks) {\n const tagName = block.blockTag.tagName.substring(1); // Remove leading @\n if (TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;\n\n const text = extractBlockText(block).trim();\n if (text === \"\") continue;\n\n const provenance = provenanceForComment(range, sourceFile, file, tagName);\n const constraintNode = parseConstraintValue(tagName, text, provenance);\n if (constraintNode) {\n constraints.push(constraintNode);\n }\n }\n\n // Extract @deprecated from the standard deprecated block\n if (docComment.deprecatedBlock !== undefined) {\n annotations.push({\n kind: \"annotation\",\n annotationKind: \"deprecated\",\n provenance: provenanceForComment(range, sourceFile, file, \"deprecated\"),\n });\n }\n }\n }\n\n // ----- Phase 1b: TS compiler API for tags with TSDoc-incompatible content -----\n // @Pattern and @EnumOptions content can contain `@` and `{}` characters\n // which the TSDoc parser treats as structural markers. We extract these\n // via the TS compiler API which preserves content verbatim.\n const jsDocTagsAll = ts.getJSDocTags(node);\n for (const tag of jsDocTagsAll) {\n const tagName = tag.tagName.text;\n if (!TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;\n\n const commentText = getTagCommentText(tag);\n if (commentText === undefined || commentText.trim() === \"\") continue;\n\n const text = commentText.trim();\n const provenance = provenanceForJSDocTag(tag, file);\n const constraintNode = parseConstraintValue(tagName, text, provenance);\n if (constraintNode) {\n constraints.push(constraintNode);\n }\n }\n\n // ----- Phase 2: TS compiler JSDoc API for underscore-containing annotation tags -----\n // @Field_displayName and @Field_description contain underscores which\n // are invalid in TSDoc tag names. We extract them via the TS compiler API.\n let displayName: string | undefined;\n let description: string | undefined;\n let displayNameTag: ts.JSDocTag | undefined;\n let descriptionTag: ts.JSDocTag | undefined;\n\n for (const tag of jsDocTagsAll) {\n const tagName = tag.tagName.text;\n const commentText = getTagCommentText(tag);\n if (commentText === undefined || commentText.trim() === \"\") {\n continue;\n }\n\n const trimmed = commentText.trim();\n\n if (tagName === \"Field_displayName\") {\n displayName = trimmed;\n displayNameTag = tag;\n } else if (tagName === \"Field_description\") {\n description = trimmed;\n descriptionTag = tag;\n }\n }\n\n if (displayName !== undefined && displayNameTag) {\n annotations.push({\n kind: \"annotation\",\n annotationKind: \"displayName\",\n value: displayName,\n provenance: provenanceForJSDocTag(displayNameTag, file),\n });\n }\n\n if (description !== undefined && descriptionTag) {\n annotations.push({\n kind: \"annotation\",\n annotationKind: \"description\",\n value: description,\n provenance: provenanceForJSDocTag(descriptionTag, file),\n });\n }\n\n return { constraints, annotations };\n}\n\n/**\n * Checks if a TS AST node has a `@deprecated` tag using the TSDoc parser.\n *\n * Falls back to the TS compiler API for nodes without doc comments.\n */\nexport function hasDeprecatedTagTSDoc(node: ts.Node): boolean {\n const sourceFile = node.getSourceFile();\n const sourceText = sourceFile.getFullText();\n const commentRanges = ts.getLeadingCommentRanges(sourceText, node.getFullStart());\n\n if (commentRanges) {\n for (const range of commentRanges) {\n if (range.kind !== ts.SyntaxKind.MultiLineCommentTrivia) continue;\n const commentText = sourceText.substring(range.pos, range.end);\n if (!commentText.startsWith(\"/**\")) continue;\n\n const parser = getParser();\n const parserContext = parser.parseRange(\n TextRange.fromStringRange(sourceText, range.pos, range.end)\n );\n if (parserContext.docComment.deprecatedBlock !== undefined) {\n return true;\n }\n }\n }\n\n return false;\n}\n\n// =============================================================================\n// PRIVATE HELPERS — TSDoc text extraction\n// =============================================================================\n\n/**\n * Recursively extracts plain text content from a TSDoc DocNode tree.\n *\n * Walks child nodes and concatenates DocPlainText and DocSoftBreak content.\n */\nfunction extractBlockText(block: DocBlock): string {\n return extractPlainText(block.content);\n}\n\nfunction extractPlainText(node: DocNode): string {\n let result = \"\";\n if (node instanceof DocPlainText) {\n return node.text;\n }\n if (node instanceof DocSoftBreak) {\n return \" \";\n }\n if (typeof node.getChildNodes === \"function\") {\n for (const child of node.getChildNodes()) {\n result += extractPlainText(child);\n }\n }\n return result;\n}\n\n// =============================================================================\n// PRIVATE HELPERS — constraint value parsing\n// =============================================================================\n\n/**\n * Parses a raw text value extracted from a TSDoc block tag into an IR\n * ConstraintNode based on the tag name and BUILTIN_CONSTRAINT_DEFINITIONS.\n */\nfunction parseConstraintValue(\n tagName: string,\n text: string,\n provenance: Provenance\n): ConstraintNode | null {\n if (!isBuiltinConstraintName(tagName)) {\n return null;\n }\n\n const expectedType = BUILTIN_CONSTRAINT_DEFINITIONS[tagName];\n\n if (expectedType === \"number\") {\n const value = Number(text);\n if (Number.isNaN(value)) {\n return null;\n }\n\n const numericKind = NUMERIC_CONSTRAINT_MAP[tagName];\n if (numericKind) {\n return {\n kind: \"constraint\",\n constraintKind: numericKind,\n value,\n provenance,\n };\n }\n\n const lengthKind = LENGTH_CONSTRAINT_MAP[tagName];\n if (lengthKind) {\n return {\n kind: \"constraint\",\n constraintKind: lengthKind,\n value,\n provenance,\n };\n }\n\n return null;\n }\n\n if (expectedType === \"json\") {\n try {\n const parsed: unknown = JSON.parse(text);\n if (!Array.isArray(parsed)) {\n return null;\n }\n const members: (string | number)[] = [];\n for (const item of parsed) {\n if (typeof item === \"string\" || typeof item === \"number\") {\n members.push(item);\n } else if (typeof item === \"object\" && item !== null && \"id\" in item) {\n const id = (item as Record<string, unknown>)[\"id\"];\n if (typeof id === \"string\" || typeof id === \"number\") {\n members.push(id);\n }\n }\n }\n return {\n kind: \"constraint\",\n constraintKind: \"allowedMembers\",\n members,\n provenance,\n };\n } catch {\n return null;\n }\n }\n\n // expectedType === \"string\" — only remaining case after number and json\n return {\n kind: \"constraint\",\n constraintKind: \"pattern\",\n pattern: text,\n provenance,\n };\n}\n\n// =============================================================================\n// PRIVATE HELPERS — provenance\n// =============================================================================\n\nfunction provenanceForComment(\n range: ts.CommentRange,\n sourceFile: ts.SourceFile,\n file: string,\n tagName: string\n): Provenance {\n const { line, character } = sourceFile.getLineAndCharacterOfPosition(range.pos);\n return {\n surface: \"tsdoc\",\n file,\n line: line + 1,\n column: character,\n tagName: \"@\" + tagName,\n };\n}\n\nfunction provenanceForJSDocTag(tag: ts.JSDocTag, file: string): Provenance {\n const sourceFile = tag.getSourceFile();\n const { line, character } = sourceFile.getLineAndCharacterOfPosition(tag.getStart());\n return {\n surface: \"tsdoc\",\n file,\n line: line + 1,\n column: character,\n tagName: \"@\" + tag.tagName.text,\n };\n}\n\n/**\n * Extracts the text content from a TypeScript JSDoc tag's comment.\n */\nfunction getTagCommentText(tag: ts.JSDocTag): string | undefined {\n if (tag.comment === undefined) {\n return undefined;\n }\n if (typeof tag.comment === \"string\") {\n return tag.comment;\n }\n return ts.getTextOfJSDocComment(tag.comment);\n}\n","/**\n * Class schema generator.\n *\n * Generates JSON Schema 2020-12 and JSON Forms UI Schema from statically\n * analyzed class/interface/type alias declarations, routing through the\n * canonical FormIR pipeline.\n */\n\nimport type { UISchema } from \"../ui-schema/types.js\";\nimport {\n createProgramContext,\n findClassByName,\n findInterfaceByName,\n findTypeAliasByName,\n} from \"../analyzer/program.js\";\nimport {\n analyzeClassToIR,\n analyzeInterfaceToIR,\n analyzeTypeAliasToIR,\n type IRClassAnalysis,\n} from \"../analyzer/class-analyzer.js\";\nimport { canonicalizeTSDoc, type TSDocSource } from \"../canonicalize/index.js\";\nimport { generateJsonSchemaFromIR, type JsonSchema2020 } from \"../json-schema/ir-generator.js\";\nimport { generateUiSchemaFromIR } from \"../ui-schema/ir-generator.js\";\n\n/**\n * Generated schemas for a class.\n */\nexport interface ClassSchemas {\n /** JSON Schema 2020-12 for validation */\n jsonSchema: JsonSchema2020;\n /** JSON Forms UI Schema for rendering */\n uiSchema: UISchema;\n}\n\n/**\n * Generates JSON Schema 2020-12 and UI Schema from an IR class analysis.\n *\n * Routes through the canonical IR pipeline:\n * IRClassAnalysis → canonicalizeTSDoc → FormIR → JSON Schema / UI Schema\n *\n * @param analysis - The IR analysis result (from analyzeClassToIR, analyzeInterfaceToIR, or analyzeTypeAliasToIR)\n * @param source - Optional source file metadata for provenance\n * @returns Generated JSON Schema and UI Schema\n */\nexport function generateClassSchemas(\n analysis: IRClassAnalysis,\n source?: TSDocSource\n): ClassSchemas {\n const ir = canonicalizeTSDoc(analysis, source);\n return {\n jsonSchema: generateJsonSchemaFromIR(ir),\n uiSchema: generateUiSchemaFromIR(ir),\n };\n}\n\n/**\n * Options for generating schemas from a decorated class.\n */\nexport interface GenerateFromClassOptions {\n /** Path to the TypeScript source file */\n filePath: string;\n /** Class name to analyze */\n className: string;\n}\n\n/**\n * Result of generating schemas from a decorated class.\n */\nexport interface GenerateFromClassResult {\n /** JSON Schema 2020-12 for validation */\n jsonSchema: JsonSchema2020;\n /** JSON Forms UI Schema for rendering */\n uiSchema: UISchema;\n}\n\n/**\n * Generates JSON Schema and UI Schema from a decorated TypeScript class.\n *\n * This is a high-level entry point that handles the entire pipeline:\n * creating a TypeScript program, finding the class, analyzing it to IR,\n * and generating schemas — all in one call.\n *\n * @example\n * ```typescript\n * const result = generateSchemasFromClass({\n * filePath: \"./src/forms.ts\",\n * className: \"UserForm\",\n * });\n * console.log(result.jsonSchema);\n * ```\n *\n * @param options - File path, class name, and optional compiler options\n * @returns Generated JSON Schema and UI Schema\n */\nexport function generateSchemasFromClass(\n options: GenerateFromClassOptions\n): GenerateFromClassResult {\n const ctx = createProgramContext(options.filePath);\n const classDecl = findClassByName(ctx.sourceFile, options.className);\n\n if (!classDecl) {\n throw new Error(`Class \"${options.className}\" not found in ${options.filePath}`);\n }\n\n const analysis = analyzeClassToIR(classDecl, ctx.checker, options.filePath);\n return generateClassSchemas(analysis, { file: options.filePath });\n}\n\n/**\n * Options for generating schemas from a named type (class, interface, or type alias).\n */\nexport interface GenerateSchemasOptions {\n /** Path to the TypeScript source file */\n filePath: string;\n /** Name of the exported class, interface, or type alias to analyze */\n typeName: string;\n}\n\n/**\n * Generates JSON Schema and UI Schema from a named TypeScript\n * type — a decorated class, an interface with TSDoc tags, or a type alias.\n *\n * This is the recommended entry point. It automatically detects whether\n * the name resolves to a class, interface, or type alias and uses the\n * appropriate IR analysis pipeline.\n *\n * @example\n * ```typescript\n * const result = generateSchemas({\n * filePath: \"./src/config.ts\",\n * typeName: \"DiscountConfig\",\n * });\n * ```\n *\n * @param options - File path and type name\n * @returns Generated JSON Schema and UI Schema\n */\nexport function generateSchemas(options: GenerateSchemasOptions): GenerateFromClassResult {\n const ctx = createProgramContext(options.filePath);\n const source: TSDocSource = { file: options.filePath };\n\n // Try class first\n const classDecl = findClassByName(ctx.sourceFile, options.typeName);\n if (classDecl) {\n const analysis = analyzeClassToIR(classDecl, ctx.checker, options.filePath);\n return generateClassSchemas(analysis, source);\n }\n\n // Try interface\n const interfaceDecl = findInterfaceByName(ctx.sourceFile, options.typeName);\n if (interfaceDecl) {\n const analysis = analyzeInterfaceToIR(interfaceDecl, ctx.checker, options.filePath);\n return generateClassSchemas(analysis, source);\n }\n\n // Try type alias\n const typeAlias = findTypeAliasByName(ctx.sourceFile, options.typeName);\n if (typeAlias) {\n const result = analyzeTypeAliasToIR(typeAlias, ctx.checker, options.filePath);\n if (result.ok) {\n return generateClassSchemas(result.analysis, source);\n }\n throw new Error(result.error);\n }\n\n throw new Error(\n `Type \"${options.typeName}\" not found as a class, interface, or type alias in ${options.filePath}`\n );\n}\n"],"mappings":";AAiDA,SAAS,kBAAkB;AAO3B,IAAM,uBAAmC;AAAA,EACvC,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,QAAQ;AACV;AAMA,SAAS,QAAQ,IAAsD;AACrE,SAAO,GAAG,UAAU;AACtB;AAEA,SAAS,cACP,IAC4D;AAC5D,SAAO,GAAG,UAAU;AACtB;AAEA,SAAS,QAAQ,IAAiC;AAChD,SAAO,GAAG,UAAU;AACtB;AAYO,SAAS,qBAAqB,MAAgD;AACnF,SAAO;AAAA,IACL,MAAM;AAAA,IACN,WAAW;AAAA,IACX,UAAU,qBAAqB,KAAK,QAAQ;AAAA,IAC5C,cAAc,CAAC;AAAA,IACf,YAAY;AAAA,EACd;AACF;AASA,SAAS,qBAAqB,UAAmD;AAC/E,SAAO,SAAS,IAAI,mBAAmB;AACzC;AAKA,SAAS,oBAAoB,SAAqC;AAChE,MAAI,QAAQ,OAAO,GAAG;AACpB,WAAO,kBAAkB,OAAO;AAAA,EAClC;AACA,MAAI,QAAQ,OAAO,GAAG;AACpB,WAAO,kBAAkB,OAAO;AAAA,EAClC;AACA,MAAI,cAAc,OAAO,GAAG;AAC1B,WAAO,wBAAwB,OAAO;AAAA,EACxC;AACA,QAAM,cAAqB;AAC3B,QAAM,IAAI,MAAM,yBAAyB,KAAK,UAAU,WAAW,CAAC,EAAE;AACxE;AASA,SAAS,kBAAkB,OAA4B;AACrD,UAAQ,MAAM,QAAQ;AAAA,IACpB,KAAK;AACH,aAAO,sBAAsB,KAAK;AAAA,IACpC,KAAK;AACH,aAAO,wBAAwB,KAAK;AAAA,IACt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UAAU,YAAY,MAAM,MAAM,CAAC;AACzE,EAAG,iBAAc,cAAc,KAAK,UAAUA,WAAU,MAAM,MAAM,CAAC;AAErE,SAAO,EAAE,gBAAgB,aAAa;AACxC;","names":["IR_VERSION","z","path","z","ts","ts","BUILTIN_CONSTRAINT_DEFINITIONS","ts","isBooleanUnion","uiSchema"]}
1
+ {"version":3,"sources":["../src/canonicalize/chain-dsl-canonicalizer.ts","../src/canonicalize/tsdoc-canonicalizer.ts","../src/json-schema/ir-generator.ts","../src/json-schema/generator.ts","../src/ui-schema/schema.ts","../src/ui-schema/ir-generator.ts","../src/ui-schema/generator.ts","../src/index.ts","../src/json-schema/types.ts","../src/json-schema/schema.ts","../src/analyzer/program.ts","../src/analyzer/class-analyzer.ts","../src/analyzer/jsdoc-constraints.ts","../src/analyzer/tsdoc-parser.ts","../src/generators/class-schema.ts"],"sourcesContent":["/**\n * Canonicalizer that translates chain DSL `FormSpec` objects into the\n * canonical FormIR intermediate representation.\n *\n * This module maps the runtime objects produced by `@formspec/dsl` builder\n * functions (`field.*`, `group`, `when`, `formspec`) into the IR that all\n * downstream phases (validation, JSON Schema generation, UI Schema generation)\n * consume.\n */\n\nimport type {\n // Source types (chain DSL)\n AnyField,\n ArrayField,\n BooleanField,\n Conditional,\n DynamicEnumField,\n DynamicSchemaField,\n EnumOptionValue,\n FormElement,\n FormSpec,\n Group,\n NumberField,\n ObjectField,\n StaticEnumField,\n TextField,\n // IR types\n JsonValue,\n AnnotationNode,\n ArrayTypeNode,\n ConstraintNode,\n ConditionalLayoutNode,\n DisplayNameAnnotationNode,\n DynamicTypeNode,\n EnumMember,\n EnumTypeNode,\n FieldNode,\n FormIR,\n FormIRElement,\n GroupLayoutNode,\n LengthConstraintNode,\n NumericConstraintNode,\n ObjectProperty,\n PatternConstraintNode,\n ObjectTypeNode,\n PlaceholderAnnotationNode,\n PrimitiveTypeNode,\n Provenance,\n TypeNode,\n} from \"@formspec/core\";\nimport { IR_VERSION } from \"@formspec/core\";\n\n// =============================================================================\n// CONSTANTS\n// =============================================================================\n\n/** Default provenance for chain DSL nodes (no source location available). */\nconst CHAIN_DSL_PROVENANCE: Provenance = {\n surface: \"chain-dsl\",\n file: \"\",\n line: 0,\n column: 0,\n} as const;\n\n// =============================================================================\n// TYPE GUARDS\n// =============================================================================\n\nfunction isGroup(el: FormElement): el is Group<readonly FormElement[]> {\n return el._type === \"group\";\n}\n\nfunction isConditional(\n el: FormElement\n): el is Conditional<string, unknown, readonly FormElement[]> {\n return el._type === \"conditional\";\n}\n\nfunction isField(el: FormElement): el is AnyField {\n return el._type === \"field\";\n}\n\n// =============================================================================\n// PUBLIC API\n// =============================================================================\n\n/**\n * Translates a chain DSL `FormSpec` into the canonical `FormIR`.\n *\n * @param form - A form specification created via `formspec(...)` from `@formspec/dsl`\n * @returns The canonical intermediate representation\n */\nexport function canonicalizeChainDSL(form: FormSpec<readonly FormElement[]>): FormIR {\n return {\n kind: \"form-ir\",\n irVersion: IR_VERSION,\n elements: canonicalizeElements(form.elements),\n typeRegistry: {},\n provenance: CHAIN_DSL_PROVENANCE,\n };\n}\n\n// =============================================================================\n// ELEMENT CANONICALIZATION\n// =============================================================================\n\n/**\n * Canonicalizes an array of chain DSL form elements into IR elements.\n */\nfunction canonicalizeElements(elements: readonly FormElement[]): FormIRElement[] {\n return elements.map(canonicalizeElement);\n}\n\n/**\n * Dispatches a single form element to its specific canonicalization function.\n */\nfunction canonicalizeElement(element: FormElement): FormIRElement {\n if (isField(element)) {\n return canonicalizeField(element);\n }\n if (isGroup(element)) {\n return canonicalizeGroup(element);\n }\n if (isConditional(element)) {\n return canonicalizeConditional(element);\n }\n const _exhaustive: never = element;\n throw new Error(`Unknown element type: ${JSON.stringify(_exhaustive)}`);\n}\n\n// =============================================================================\n// FIELD CANONICALIZATION\n// =============================================================================\n\n/**\n * Dispatches a field element to its type-specific canonicalization function.\n */\nfunction canonicalizeField(field: AnyField): FieldNode {\n switch (field._field) {\n case \"text\":\n return canonicalizeTextField(field);\n case \"number\":\n return canonicalizeNumberField(field);\n case \"boolean\":\n return canonicalizeBooleanField(field);\n case \"enum\":\n return canonicalizeStaticEnumField(field);\n case \"dynamic_enum\":\n return canonicalizeDynamicEnumField(field);\n case \"dynamic_schema\":\n return canonicalizeDynamicSchemaField(field);\n case \"array\":\n return canonicalizeArrayField(field);\n case \"object\":\n return canonicalizeObjectField(field);\n default: {\n const _exhaustive: never = field;\n throw new Error(`Unknown field type: ${JSON.stringify(_exhaustive)}`);\n }\n }\n}\n\n// =============================================================================\n// SPECIFIC FIELD TYPE CANONICALIZERS\n// =============================================================================\n\nfunction canonicalizeTextField(field: TextField<string>): FieldNode {\n const type: PrimitiveTypeNode = { kind: \"primitive\", primitiveKind: \"string\" };\n const constraints: ConstraintNode[] = [];\n\n if (field.minLength !== undefined) {\n const c: LengthConstraintNode = {\n kind: \"constraint\",\n constraintKind: \"minLength\",\n value: field.minLength,\n provenance: CHAIN_DSL_PROVENANCE,\n };\n constraints.push(c);\n }\n\n if (field.maxLength !== undefined) {\n const c: LengthConstraintNode = {\n kind: \"constraint\",\n constraintKind: \"maxLength\",\n value: field.maxLength,\n provenance: CHAIN_DSL_PROVENANCE,\n };\n constraints.push(c);\n }\n\n if (field.pattern !== undefined) {\n const c: PatternConstraintNode = {\n kind: \"constraint\",\n constraintKind: \"pattern\",\n pattern: field.pattern,\n provenance: CHAIN_DSL_PROVENANCE,\n };\n constraints.push(c);\n }\n\n return buildFieldNode(\n field.name,\n type,\n field.required,\n buildAnnotations(field.label, field.placeholder),\n constraints\n );\n}\n\nfunction canonicalizeNumberField(field: NumberField<string>): FieldNode {\n const type: PrimitiveTypeNode = { kind: \"primitive\", primitiveKind: \"number\" };\n const constraints: ConstraintNode[] = [];\n\n if (field.min !== undefined) {\n const c: NumericConstraintNode = {\n kind: \"constraint\",\n constraintKind: \"minimum\",\n value: field.min,\n provenance: CHAIN_DSL_PROVENANCE,\n };\n constraints.push(c);\n }\n\n if (field.max !== undefined) {\n const c: NumericConstraintNode = {\n kind: \"constraint\",\n constraintKind: \"maximum\",\n value: field.max,\n provenance: CHAIN_DSL_PROVENANCE,\n };\n constraints.push(c);\n }\n\n if (field.multipleOf !== undefined) {\n const c: NumericConstraintNode = {\n kind: \"constraint\",\n constraintKind: \"multipleOf\",\n value: field.multipleOf,\n provenance: CHAIN_DSL_PROVENANCE,\n };\n constraints.push(c);\n }\n\n return buildFieldNode(\n field.name,\n type,\n field.required,\n buildAnnotations(field.label),\n constraints\n );\n}\n\nfunction canonicalizeBooleanField(field: BooleanField<string>): FieldNode {\n const type: PrimitiveTypeNode = { kind: \"primitive\", primitiveKind: \"boolean\" };\n return buildFieldNode(field.name, type, field.required, buildAnnotations(field.label));\n}\n\nfunction canonicalizeStaticEnumField(\n field: StaticEnumField<string, readonly EnumOptionValue[]>\n): FieldNode {\n const members: EnumMember[] = field.options.map((opt) => {\n if (typeof opt === \"string\") {\n return { value: opt } satisfies EnumMember;\n }\n // Object option with id/label\n return { value: opt.id, displayName: opt.label } satisfies EnumMember;\n });\n\n const type: EnumTypeNode = { kind: \"enum\", members };\n return buildFieldNode(field.name, type, field.required, buildAnnotations(field.label));\n}\n\nfunction canonicalizeDynamicEnumField(field: DynamicEnumField<string, string>): FieldNode {\n const type: DynamicTypeNode = {\n kind: \"dynamic\",\n dynamicKind: \"enum\",\n sourceKey: field.source,\n parameterFields: field.params ? [...field.params] : [],\n };\n return buildFieldNode(field.name, type, field.required, buildAnnotations(field.label));\n}\n\nfunction canonicalizeDynamicSchemaField(field: DynamicSchemaField<string>): FieldNode {\n const type: DynamicTypeNode = {\n kind: \"dynamic\",\n dynamicKind: \"schema\",\n sourceKey: field.schemaSource,\n parameterFields: [],\n };\n return buildFieldNode(field.name, type, field.required, buildAnnotations(field.label));\n}\n\nfunction canonicalizeArrayField(field: ArrayField<string, readonly FormElement[]>): FieldNode {\n // Array items form an object type from the sub-elements\n const itemProperties = buildObjectProperties(field.items);\n const itemsType: ObjectTypeNode = {\n kind: \"object\",\n properties: itemProperties,\n additionalProperties: false,\n };\n const type: ArrayTypeNode = { kind: \"array\", items: itemsType };\n\n const constraints: ConstraintNode[] = [];\n if (field.minItems !== undefined) {\n const c: LengthConstraintNode = {\n kind: \"constraint\",\n constraintKind: \"minItems\",\n value: field.minItems,\n provenance: CHAIN_DSL_PROVENANCE,\n };\n constraints.push(c);\n }\n if (field.maxItems !== undefined) {\n const c: LengthConstraintNode = {\n kind: \"constraint\",\n constraintKind: \"maxItems\",\n value: field.maxItems,\n provenance: CHAIN_DSL_PROVENANCE,\n };\n constraints.push(c);\n }\n\n return buildFieldNode(\n field.name,\n type,\n field.required,\n buildAnnotations(field.label),\n constraints\n );\n}\n\nfunction canonicalizeObjectField(field: ObjectField<string, readonly FormElement[]>): FieldNode {\n const properties = buildObjectProperties(field.properties);\n const type: ObjectTypeNode = {\n kind: \"object\",\n properties,\n additionalProperties: false,\n };\n return buildFieldNode(field.name, type, field.required, buildAnnotations(field.label));\n}\n\n// =============================================================================\n// LAYOUT CANONICALIZATION\n// =============================================================================\n\nfunction canonicalizeGroup(g: Group<readonly FormElement[]>): GroupLayoutNode {\n return {\n kind: \"group\",\n label: g.label,\n elements: canonicalizeElements(g.elements),\n provenance: CHAIN_DSL_PROVENANCE,\n };\n}\n\nfunction canonicalizeConditional(\n c: Conditional<string, unknown, readonly FormElement[]>\n): ConditionalLayoutNode {\n return {\n kind: \"conditional\",\n fieldName: c.field,\n // Conditional values from the chain DSL are JSON-serializable primitives\n // (strings, numbers, booleans) produced by the `is()` predicate helper.\n value: assertJsonValue(c.value),\n elements: canonicalizeElements(c.elements),\n provenance: CHAIN_DSL_PROVENANCE,\n };\n}\n\n// =============================================================================\n// HELPERS\n// =============================================================================\n\n/**\n * Validates that a value is JSON-serializable (`JsonValue`).\n * The chain DSL's `is()` helper constrains conditional values to\n * JSON-compatible primitives, but the TypeScript type is `unknown`.\n * This runtime guard replaces an `as` cast with a validated assertion.\n */\nfunction assertJsonValue(v: unknown): JsonValue {\n if (v === null || typeof v === \"string\" || typeof v === \"number\" || typeof v === \"boolean\") {\n return v;\n }\n if (Array.isArray(v)) {\n return v.map(assertJsonValue);\n }\n if (typeof v === \"object\") {\n const result: Record<string, JsonValue> = {};\n for (const [key, val] of Object.entries(v)) {\n result[key] = assertJsonValue(val);\n }\n return result;\n }\n // Remaining types (function, symbol, bigint, undefined) are not JSON-serializable\n throw new TypeError(`Conditional value is not a valid JsonValue: ${typeof v}`);\n}\n\n/**\n * Builds a FieldNode from common field properties.\n */\nfunction buildFieldNode(\n name: string,\n type: TypeNode,\n required: boolean | undefined,\n annotations: AnnotationNode[],\n constraints: ConstraintNode[] = []\n): FieldNode {\n return {\n kind: \"field\",\n name,\n type,\n required: required === true,\n constraints,\n annotations,\n provenance: CHAIN_DSL_PROVENANCE,\n };\n}\n\n/**\n * Builds annotation nodes from optional label and placeholder values.\n */\nfunction buildAnnotations(label?: string, placeholder?: string): AnnotationNode[] {\n const annotations: AnnotationNode[] = [];\n\n if (label !== undefined) {\n const a: DisplayNameAnnotationNode = {\n kind: \"annotation\",\n annotationKind: \"displayName\",\n value: label,\n provenance: CHAIN_DSL_PROVENANCE,\n };\n annotations.push(a);\n }\n\n if (placeholder !== undefined) {\n const a: PlaceholderAnnotationNode = {\n kind: \"annotation\",\n annotationKind: \"placeholder\",\n value: placeholder,\n provenance: CHAIN_DSL_PROVENANCE,\n };\n annotations.push(a);\n }\n\n return annotations;\n}\n\n/**\n * Converts an array of form elements into ObjectProperty nodes.\n * Used for ObjectField properties and ArrayField items.\n *\n * Only field elements produce properties; groups and conditionals within\n * an object/array context are recursively flattened to extract their fields.\n *\n * Fields inside conditional branches are always marked `optional: true`\n * because their presence in the data depends on the condition being met.\n * This matches the DSL's type inference behavior where conditional fields\n * produce optional properties in `InferFormSchema`.\n *\n * @param elements - The form elements to convert\n * @param insideConditional - Whether these elements are inside a conditional branch\n */\nfunction buildObjectProperties(\n elements: readonly FormElement[],\n insideConditional = false\n): ObjectProperty[] {\n const properties: ObjectProperty[] = [];\n\n for (const el of elements) {\n if (isField(el)) {\n const fieldNode = canonicalizeField(el);\n properties.push({\n name: fieldNode.name,\n type: fieldNode.type,\n // Fields inside a conditional branch are always optional in the\n // data schema, regardless of their `required` flag — the condition\n // may not be met, so the field may be absent.\n optional: insideConditional || !fieldNode.required,\n constraints: fieldNode.constraints,\n annotations: fieldNode.annotations,\n provenance: CHAIN_DSL_PROVENANCE,\n });\n } else if (isGroup(el)) {\n // Groups inside object/array items contribute their fields by flattening.\n // Groups do not affect optionality — pass through the current state.\n properties.push(...buildObjectProperties(el.elements, insideConditional));\n } else if (isConditional(el)) {\n // Conditionals inside object/array items contribute their fields by\n // flattening, but all fields inside are forced optional.\n properties.push(...buildObjectProperties(el.elements, true));\n }\n }\n\n return properties;\n}\n","/**\n * TSDoc canonicalizer — assembles an {@link IRClassAnalysis} into a canonical\n * {@link FormIR}, applying layout metadata from `@Group` and `@ShowWhen`\n * decorators.\n *\n * The analysis functions in `class-analyzer.ts` produce `FieldNode[]`,\n * `fieldLayouts`, and `typeRegistry` directly. This canonicalizer uses\n * the layout metadata to wrap fields in `GroupLayoutNode` and\n * `ConditionalLayoutNode` elements.\n */\n\nimport type {\n FormIR,\n FormIRElement,\n FieldNode,\n GroupLayoutNode,\n ConditionalLayoutNode,\n Provenance,\n} from \"@formspec/core\";\nimport { IR_VERSION } from \"@formspec/core\";\nimport type { IRClassAnalysis, FieldLayoutMetadata } from \"../analyzer/class-analyzer.js\";\n\n/**\n * Source-level metadata for provenance tracking.\n */\nexport interface TSDocSource {\n /** Absolute path to the source file. */\n readonly file: string;\n}\n\n/**\n * Wraps an {@link IRClassAnalysis} (from `analyzeClassToIR`,\n * `analyzeInterfaceToIR`, or `analyzeTypeAliasToIR`) into a canonical\n * {@link FormIR}.\n *\n * Fields with `@Group` decorators are grouped into `GroupLayoutNode` elements.\n * Fields with `@ShowWhen` decorators are wrapped in `ConditionalLayoutNode` elements.\n * When both are present, the conditional wraps the field inside the group.\n *\n * @param analysis - IR analysis result (fields are already FieldNode[])\n * @param source - Optional source file metadata for provenance\n * @returns The canonical FormIR\n */\nexport function canonicalizeTSDoc(analysis: IRClassAnalysis, source?: TSDocSource): FormIR {\n const file = source?.file ?? \"\";\n\n const provenance: Provenance = {\n surface: \"tsdoc\",\n file,\n line: 1,\n column: 0,\n };\n\n const elements = assembleElements(analysis.fields, analysis.fieldLayouts, provenance);\n\n return {\n kind: \"form-ir\",\n irVersion: IR_VERSION,\n elements,\n typeRegistry: analysis.typeRegistry,\n provenance,\n };\n}\n\n/**\n * Assembles flat fields and their layout metadata into a tree of\n * `FormIRElement[]` with groups and conditionals.\n *\n * Fields are processed in order. Consecutive fields with the same\n * `@Group` label are collected into a single `GroupLayoutNode`.\n * Fields with `@ShowWhen` are wrapped in `ConditionalLayoutNode`.\n */\nfunction assembleElements(\n fields: readonly FieldNode[],\n layouts: readonly FieldLayoutMetadata[],\n provenance: Provenance\n): readonly FormIRElement[] {\n const elements: FormIRElement[] = [];\n\n // Group consecutive fields with the same group label together.\n // We use an ordered map to preserve insertion order of groups.\n const groupMap = new Map<string, FormIRElement[]>();\n const topLevelOrder: (\n | { type: \"group\"; label: string }\n | { type: \"element\"; element: FormIRElement }\n )[] = [];\n\n for (let i = 0; i < fields.length; i++) {\n const field = fields[i];\n const layout = layouts[i];\n if (!field || !layout) continue;\n\n // Wrap in conditional if @ShowWhen is present\n const element = wrapInConditional(field, layout, provenance);\n\n if (layout.groupLabel !== undefined) {\n const label = layout.groupLabel;\n let groupElements = groupMap.get(label);\n if (!groupElements) {\n groupElements = [];\n groupMap.set(label, groupElements);\n topLevelOrder.push({ type: \"group\", label });\n }\n groupElements.push(element);\n } else {\n topLevelOrder.push({ type: \"element\", element });\n }\n }\n\n // Assemble the final element array in order\n for (const entry of topLevelOrder) {\n if (entry.type === \"group\") {\n const groupElements = groupMap.get(entry.label);\n if (groupElements) {\n const groupNode: GroupLayoutNode = {\n kind: \"group\",\n label: entry.label,\n elements: groupElements,\n provenance,\n };\n elements.push(groupNode);\n // Clear so duplicate group labels in topLevelOrder don't re-emit\n groupMap.delete(entry.label);\n }\n } else {\n elements.push(entry.element);\n }\n }\n\n return elements;\n}\n\n/**\n * Wraps a field in a `ConditionalLayoutNode` if the layout has `showWhen` metadata.\n */\nfunction wrapInConditional(\n field: FieldNode,\n layout: FieldLayoutMetadata,\n provenance: Provenance\n): FormIRElement {\n if (layout.showWhen === undefined) {\n return field;\n }\n\n const conditional: ConditionalLayoutNode = {\n kind: \"conditional\",\n fieldName: layout.showWhen.field,\n value: layout.showWhen.value,\n elements: [field],\n provenance,\n };\n\n return conditional;\n}\n","/**\n * JSON Schema 2020-12 generator that consumes the canonical FormIR.\n *\n * This generator is a pure function of the IR. It never consults the TypeScript\n * AST or surface syntax directly — only the IR (per the JSON Schema vocabulary spec §1.2).\n *\n * @see https://json-schema.org/draft/2020-12/schema\n * @see https://json-schema.org/draft/2020-12/schema\n */\n\nimport type {\n FormIR,\n FormIRElement,\n FieldNode,\n TypeNode,\n PrimitiveTypeNode,\n EnumTypeNode,\n ArrayTypeNode,\n ObjectTypeNode,\n UnionTypeNode,\n ReferenceTypeNode,\n DynamicTypeNode,\n CustomTypeNode,\n ConstraintNode,\n AnnotationNode,\n ObjectProperty,\n} from \"@formspec/core\";\n\n// =============================================================================\n// OUTPUT TYPE\n// =============================================================================\n\n/**\n * A JSON Schema 2020-12 document, sub-schema, or keyword collection.\n *\n * This interface covers the subset of JSON Schema 2020-12 that this generator\n * emits, plus an index signature for custom `x-formspec-*` extension keywords.\n */\nexport interface JsonSchema2020 {\n $schema?: string;\n $ref?: string;\n $defs?: Record<string, JsonSchema2020>;\n type?: string;\n properties?: Record<string, JsonSchema2020>;\n required?: string[];\n items?: JsonSchema2020;\n additionalProperties?: boolean;\n enum?: readonly (string | number)[];\n const?: string | number | boolean | null;\n oneOf?: readonly JsonSchema2020[];\n anyOf?: readonly JsonSchema2020[];\n // Constraints\n minimum?: number;\n maximum?: number;\n exclusiveMinimum?: number;\n exclusiveMaximum?: number;\n multipleOf?: number;\n minLength?: number;\n maxLength?: number;\n minItems?: number;\n maxItems?: number;\n pattern?: string;\n uniqueItems?: boolean;\n // Annotations\n title?: string;\n description?: string;\n default?: unknown;\n deprecated?: boolean;\n // Extensions (open for vendor-prefixed keywords, e.g., x-formspec-*, x-stripe-*)\n // The vendor prefix is configurable (white-labelable).\n [key: `x-${string}`]: unknown;\n}\n\n// =============================================================================\n// CONTEXT\n// =============================================================================\n\n/**\n * Mutable accumulator passed through the generation traversal.\n *\n * Using a context object rather than return-value threading keeps the\n * recursive generators simple and avoids repeated object spreading.\n */\ninterface GeneratorContext {\n /** Named type schemas collected during traversal, keyed by reference name. */\n readonly defs: Record<string, JsonSchema2020>;\n}\n\nfunction makeContext(): GeneratorContext {\n return { defs: {} };\n}\n\n// =============================================================================\n// PUBLIC API\n// =============================================================================\n\n/**\n * Generates a JSON Schema 2020-12 object from a canonical FormIR.\n *\n * Groups and conditionals are flattened — they influence UI layout but do not\n * affect the data schema. All fields appear at the level they would occupy in\n * the output data.\n *\n * Named types in the `typeRegistry` are emitted as `$defs` entries and\n * referenced via `$ref` (per PP7 — high-fidelity output).\n *\n * @example\n * ```typescript\n * import { canonicalizeDSL } from \"./canonicalize/index.js\";\n * import { generateJsonSchemaFromIR } from \"./json-schema/ir-generator.js\";\n * import { formspec, field } from \"@formspec/dsl\";\n *\n * const form = formspec(\n * field.text(\"name\", { label: \"Name\", required: true }),\n * field.number(\"age\", { min: 0 }),\n * );\n * const ir = canonicalizeDSL(form);\n * const schema = generateJsonSchemaFromIR(ir);\n * // {\n * // $schema: \"https://json-schema.org/draft/2020-12/schema\",\n * // type: \"object\",\n * // properties: {\n * // name: { type: \"string\", title: \"Name\" },\n * // age: { type: \"number\", minimum: 0 }\n * // },\n * // required: [\"name\"]\n * // }\n * ```\n *\n * @param ir - The canonical FormIR produced by a canonicalizer\n * @returns A plain JSON-serializable JSON Schema 2020-12 object\n */\nexport function generateJsonSchemaFromIR(ir: FormIR): JsonSchema2020 {\n const ctx = makeContext();\n\n // Seed $defs from the type registry so referenced types are available even if\n // the field tree traversal never visits them (e.g., unreferenced types added\n // by a TSDoc canonicalizer pass).\n for (const [name, typeDef] of Object.entries(ir.typeRegistry)) {\n ctx.defs[name] = generateTypeNode(typeDef.type, ctx);\n }\n\n const properties: Record<string, JsonSchema2020> = {};\n const required: string[] = [];\n\n collectFields(ir.elements, properties, required, ctx);\n\n // Deduplicate required (same field can appear across conditional branches).\n const uniqueRequired = [...new Set(required)];\n\n const result: JsonSchema2020 = {\n $schema: \"https://json-schema.org/draft/2020-12/schema\",\n type: \"object\",\n properties,\n ...(uniqueRequired.length > 0 && { required: uniqueRequired }),\n };\n\n if (Object.keys(ctx.defs).length > 0) {\n result.$defs = ctx.defs;\n }\n\n return result;\n}\n\n// =============================================================================\n// ELEMENT TRAVERSAL\n// =============================================================================\n\n/**\n * Recursively visits all IR elements, collecting field schemas and required names.\n *\n * Groups and conditionals are transparent to the schema — their children are\n * lifted to the enclosing level (per the JSON Schema vocabulary spec §1.2).\n */\nfunction collectFields(\n elements: readonly FormIRElement[],\n properties: Record<string, JsonSchema2020>,\n required: string[],\n ctx: GeneratorContext\n): void {\n for (const element of elements) {\n switch (element.kind) {\n case \"field\":\n properties[element.name] = generateFieldSchema(element, ctx);\n if (element.required) {\n required.push(element.name);\n }\n break;\n\n case \"group\":\n // Groups are UI-only; flatten children into the enclosing schema.\n collectFields(element.elements, properties, required, ctx);\n break;\n\n case \"conditional\":\n // Conditional visibility is UI-only; all fields remain in the schema.\n collectFields(element.elements, properties, required, ctx);\n break;\n\n default: {\n const _exhaustive: never = element;\n void _exhaustive;\n }\n }\n }\n}\n\n// =============================================================================\n// FIELD SCHEMA GENERATION\n// =============================================================================\n\n/**\n * Generates the JSON Schema sub-schema for a single FieldNode.\n */\nfunction generateFieldSchema(field: FieldNode, ctx: GeneratorContext): JsonSchema2020 {\n const schema = generateTypeNode(field.type, ctx);\n\n // Apply constraints. multipleOf:1 on a number type is a special case: it\n // promotes the type to \"integer\" and removes the multipleOf keyword.\n applyConstraints(schema, field.constraints);\n\n // Apply annotations (title, description, default, deprecated, etc.).\n applyAnnotations(schema, field.annotations);\n\n return schema;\n}\n\n// =============================================================================\n// TYPE NODE GENERATION\n// =============================================================================\n\n/**\n * Converts a TypeNode to a JSON Schema sub-schema.\n *\n * This function is intentionally exhaustive — all TypeNode variants are handled.\n * TypeScript's exhaustiveness check via the default branch ensures new variants\n * added to the IR are caught at compile time.\n */\nfunction generateTypeNode(type: TypeNode, ctx: GeneratorContext): JsonSchema2020 {\n switch (type.kind) {\n case \"primitive\":\n return generatePrimitiveType(type);\n\n case \"enum\":\n return generateEnumType(type);\n\n case \"array\":\n return generateArrayType(type, ctx);\n\n case \"object\":\n return generateObjectType(type, ctx);\n\n case \"union\":\n return generateUnionType(type, ctx);\n\n case \"reference\":\n return generateReferenceType(type);\n\n case \"dynamic\":\n return generateDynamicType(type);\n\n case \"custom\":\n return generateCustomType(type);\n\n default: {\n // TypeScript exhaustiveness guard.\n const _exhaustive: never = type;\n return _exhaustive;\n }\n }\n}\n\n/**\n * Maps primitive IR types to JSON Schema type keywords.\n *\n * Note: `integer` is NOT a primitive kind in the IR. Integer semantics are\n * expressed via a `multipleOf: 1` constraint on a number type; `applyConstraints`\n * handles the promotion (per the JSON Schema vocabulary spec §2.1).\n */\nfunction generatePrimitiveType(type: PrimitiveTypeNode): JsonSchema2020 {\n return { type: type.primitiveKind };\n}\n\n/**\n * Generates JSON Schema for a static enum type.\n *\n * When any member has a displayName, the output uses the `oneOf` form with\n * per-member `const`/`title` entries (per the JSON Schema vocabulary spec §2.3). Otherwise the\n * flat `enum` keyword is used (simpler, equally valid).\n */\nfunction generateEnumType(type: EnumTypeNode): JsonSchema2020 {\n const hasDisplayNames = type.members.some((m) => m.displayName !== undefined);\n\n if (hasDisplayNames) {\n return {\n oneOf: type.members.map((m) => {\n const entry: JsonSchema2020 = { const: m.value };\n if (m.displayName !== undefined) {\n entry.title = m.displayName;\n }\n return entry;\n }),\n };\n }\n\n return { enum: type.members.map((m) => m.value) };\n}\n\n/**\n * Generates JSON Schema for an array type.\n * Per 2020-12, `items` is a single schema (not an array); tuple types use\n * `prefixItems` + `items: false`.\n */\nfunction generateArrayType(type: ArrayTypeNode, ctx: GeneratorContext): JsonSchema2020 {\n return {\n type: \"array\",\n items: generateTypeNode(type.items, ctx),\n };\n}\n\n/**\n * Generates JSON Schema for an object type.\n *\n * `additionalProperties` is only emitted when the IR explicitly disallows extra\n * properties. The default per the JSON Schema vocabulary spec §2.5 is to omit it (allow policy).\n */\nfunction generateObjectType(type: ObjectTypeNode, ctx: GeneratorContext): JsonSchema2020 {\n const properties: Record<string, JsonSchema2020> = {};\n const required: string[] = [];\n\n for (const prop of type.properties) {\n properties[prop.name] = generatePropertySchema(prop, ctx);\n if (!prop.optional) {\n required.push(prop.name);\n }\n }\n\n const schema: JsonSchema2020 = { type: \"object\", properties };\n\n if (required.length > 0) {\n schema.required = required;\n }\n\n if (!type.additionalProperties) {\n // IR default is false (closed objects). Emit explicitly when disallowed.\n schema.additionalProperties = false;\n }\n\n return schema;\n}\n\n/**\n * Generates a schema for an ObjectProperty, applying its use-site constraints\n * and annotations (per the JSON Schema vocabulary spec §5.4 — inline allOf at use site).\n */\nfunction generatePropertySchema(prop: ObjectProperty, ctx: GeneratorContext): JsonSchema2020 {\n const schema = generateTypeNode(prop.type, ctx);\n applyConstraints(schema, prop.constraints);\n applyAnnotations(schema, prop.annotations);\n return schema;\n}\n\n/**\n * Generates JSON Schema for a union type.\n *\n * Union handling strategy:\n * - Boolean shorthand: `true | false` → `{ type: \"boolean\" }` (not anyOf)\n * - All other unions → `anyOf` (members may overlap; discriminated union\n * detection is deferred to a future phase per design doc 003 §7.4)\n */\nfunction generateUnionType(type: UnionTypeNode, ctx: GeneratorContext): JsonSchema2020 {\n // Boolean shorthand: union of true-literal and false-literal → type: \"boolean\"\n if (isBooleanUnion(type)) {\n return { type: \"boolean\" };\n }\n\n // Default: anyOf for all non-boolean unions.\n // Discriminated union detection (shared required property with distinct consts)\n // is deferred to a future phase.\n return {\n anyOf: type.members.map((m) => generateTypeNode(m, ctx)),\n };\n}\n\n/**\n * Returns true if the union is `true | false` (boolean shorthand).\n */\nfunction isBooleanUnion(type: UnionTypeNode): boolean {\n if (type.members.length !== 2) return false;\n const kinds = type.members.map((m) => m.kind);\n // Both must be primitives; check if both are \"boolean\" primitives.\n // The IR currently does not have a boolean literal node, so boolean union\n // is represented as two primitive boolean members.\n return (\n kinds.every((k) => k === \"primitive\") &&\n type.members.every((m) => m.kind === \"primitive\" && m.primitiveKind === \"boolean\")\n );\n}\n\n/**\n * Generates JSON Schema for a reference type.\n *\n * The referenced type's schema is stored in `$defs` (seeded from the type\n * registry before traversal begins). The reference simply emits a `$ref`.\n */\nfunction generateReferenceType(type: ReferenceTypeNode): JsonSchema2020 {\n return { $ref: `#/$defs/${type.name}` };\n}\n\n/**\n * Generates JSON Schema for a dynamic type (runtime-resolved enum or schema).\n *\n * Dynamic enums emit `x-formspec-source` and optionally `x-formspec-params`.\n * Dynamic schemas emit `x-formspec-schemaSource` with `additionalProperties: true`\n * since the actual schema is determined at runtime (per the JSON Schema vocabulary spec §3.2).\n */\nfunction generateDynamicType(type: DynamicTypeNode): JsonSchema2020 {\n if (type.dynamicKind === \"enum\") {\n const schema: JsonSchema2020 = {\n type: \"string\",\n \"x-formspec-source\": type.sourceKey,\n };\n if (type.parameterFields.length > 0) {\n schema[\"x-formspec-params\"] = [...type.parameterFields];\n }\n return schema;\n }\n\n // dynamicKind === \"schema\"\n return {\n type: \"object\",\n additionalProperties: true,\n \"x-formspec-schemaSource\": type.sourceKey,\n };\n}\n\n/**\n * CustomTypeNode is a placeholder for Phase 8 extensions.\n * Emits a minimal passthrough object type until the extension API is implemented.\n */\nfunction generateCustomType(_type: CustomTypeNode): JsonSchema2020 {\n return { type: \"object\" };\n}\n\n// =============================================================================\n// CONSTRAINT APPLICATION\n// =============================================================================\n\n/**\n * Applies constraint nodes onto an existing JSON Schema object (mutates in place).\n *\n * All callers pass freshly-created objects so there is no aliasing risk.\n *\n * Special rule (per the JSON Schema vocabulary spec §2.1): `multipleOf: 1` on a `\"number\"` type\n * promotes to `\"integer\"` and suppresses the `multipleOf` keyword (integer is a\n * subtype of number; expressing it via multipleOf:1 is redundant).\n *\n * Path-targeted constraints (e.g., `@minimum :value 0`) are emitted at the field\n * level here; full sub-field targeting via allOf composition is a Phase 4 concern.\n */\nfunction applyConstraints(schema: JsonSchema2020, constraints: readonly ConstraintNode[]): void {\n for (const constraint of constraints) {\n switch (constraint.constraintKind) {\n case \"minimum\":\n schema.minimum = constraint.value;\n break;\n\n case \"maximum\":\n schema.maximum = constraint.value;\n break;\n\n case \"exclusiveMinimum\":\n schema.exclusiveMinimum = constraint.value;\n break;\n\n case \"exclusiveMaximum\":\n schema.exclusiveMaximum = constraint.value;\n break;\n\n case \"multipleOf\": {\n const { value } = constraint;\n if (value === 1 && schema.type === \"number\") {\n // Promote number → integer; omit the multipleOf keyword (redundant).\n schema.type = \"integer\";\n } else {\n schema.multipleOf = value;\n }\n break;\n }\n\n case \"minLength\":\n schema.minLength = constraint.value;\n break;\n\n case \"maxLength\":\n schema.maxLength = constraint.value;\n break;\n\n case \"minItems\":\n schema.minItems = constraint.value;\n break;\n\n case \"maxItems\":\n schema.maxItems = constraint.value;\n break;\n\n case \"pattern\":\n schema.pattern = constraint.pattern;\n break;\n\n case \"uniqueItems\":\n schema.uniqueItems = constraint.value;\n break;\n\n case \"allowedMembers\":\n // EnumMemberConstraintNode — not yet emitted to JSON Schema (Phase 6 validation).\n break;\n\n case \"custom\":\n // CustomConstraintNode — handled by Phase 8 extensions.\n break;\n\n default: {\n // TypeScript exhaustiveness guard.\n const _exhaustive: never = constraint;\n void _exhaustive;\n }\n }\n }\n}\n\n// =============================================================================\n// ANNOTATION APPLICATION\n// =============================================================================\n\n/**\n * Applies annotation nodes onto an existing JSON Schema object (mutates in place).\n *\n * Mapping per the JSON Schema vocabulary spec §2.8:\n * - `displayName` → `title`\n * - `description` → `description`\n * - `defaultValue` → `default`\n * - `deprecated` → `deprecated: true` (2020-12 standard annotation)\n *\n * UI-only annotations (`placeholder`, `formatHint`) are silently ignored here —\n * they belong in the UI Schema, not the data schema.\n */\nfunction applyAnnotations(schema: JsonSchema2020, annotations: readonly AnnotationNode[]): void {\n for (const annotation of annotations) {\n switch (annotation.annotationKind) {\n case \"displayName\":\n schema.title = annotation.value;\n break;\n\n case \"description\":\n schema.description = annotation.value;\n break;\n\n case \"defaultValue\":\n schema.default = annotation.value;\n break;\n\n case \"deprecated\":\n schema.deprecated = true;\n break;\n\n case \"placeholder\":\n // UI-only — belongs in UI Schema, not emitted here.\n break;\n\n case \"formatHint\":\n // UI-only — belongs in UI Schema, not emitted here.\n break;\n\n case \"custom\":\n // CustomAnnotationNode — handled by Phase 8 extensions.\n break;\n\n default: {\n // TypeScript exhaustiveness guard.\n const _exhaustive: never = annotation;\n void _exhaustive;\n }\n }\n }\n}\n","/**\n * JSON Schema generator for FormSpec forms.\n *\n * Routes through the canonical IR pipeline: Chain DSL → FormIR → JSON Schema 2020-12.\n */\n\nimport type { FormElement, FormSpec } from \"@formspec/core\";\nimport { canonicalizeChainDSL } from \"../canonicalize/index.js\";\nimport { generateJsonSchemaFromIR, type JsonSchema2020 } from \"./ir-generator.js\";\n\n/**\n * Generates a JSON Schema 2020-12 from a FormSpec.\n *\n * All generation routes through the canonical IR. The chain DSL is first\n * canonicalized to a FormIR, then the IR-based generator produces the schema.\n *\n * @example\n * ```typescript\n * const form = formspec(\n * field.text(\"name\", { label: \"Name\", required: true }),\n * field.number(\"age\", { min: 0 }),\n * );\n *\n * const schema = generateJsonSchema(form);\n * // {\n * // $schema: \"https://json-schema.org/draft/2020-12/schema\",\n * // type: \"object\",\n * // properties: {\n * // name: { type: \"string\", title: \"Name\" },\n * // age: { type: \"number\", minimum: 0 }\n * // },\n * // required: [\"name\"]\n * // }\n * ```\n *\n * @param form - The FormSpec to convert\n * @returns A JSON Schema 2020-12 object\n */\nexport function generateJsonSchema<E extends readonly FormElement[]>(\n form: FormSpec<E>\n): JsonSchema2020 {\n const ir = canonicalizeChainDSL(form);\n return generateJsonSchemaFromIR(ir);\n}\n","/**\n * Zod schemas for JSON Forms UI Schema.\n *\n * These schemas are the source of truth for UI Schema validation.\n * TypeScript types are derived from these schemas via `z.infer<>`.\n *\n * @see https://jsonforms.io/docs/uischema/\n */\n\nimport { z } from \"zod\";\n\n// =============================================================================\n// Primitive helpers\n// =============================================================================\n\n/** JSON Pointer string (e.g., \"#/properties/fieldName\") */\nconst jsonPointerSchema = z.string();\n\n// =============================================================================\n// Rule Effect and Element Type enums\n// =============================================================================\n\n/**\n * Zod schema for rule effect values.\n */\nexport const ruleEffectSchema = z.enum([\"SHOW\", \"HIDE\", \"ENABLE\", \"DISABLE\"]);\n\n/**\n * Rule effect types for conditional visibility.\n */\nexport type RuleEffect = z.infer<typeof ruleEffectSchema>;\n\n/**\n * Zod schema for UI Schema element type strings.\n */\nexport const uiSchemaElementTypeSchema = z.enum([\n \"Control\",\n \"VerticalLayout\",\n \"HorizontalLayout\",\n \"Group\",\n \"Categorization\",\n \"Category\",\n \"Label\",\n]);\n\n/**\n * UI Schema element types.\n */\nexport type UISchemaElementType = z.infer<typeof uiSchemaElementTypeSchema>;\n\n// =============================================================================\n// Rule Condition Schema (recursive)\n// =============================================================================\n\n// Forward-declare the recursive TypeScript type.\n// We use an interface here (rather than z.infer<>) because the recursive\n// z.lazy() type annotation requires us to pre-declare the shape.\n/**\n * JSON Schema subset used in rule conditions.\n */\nexport interface RuleConditionSchema {\n const?: unknown;\n enum?: readonly unknown[];\n type?: string;\n not?: RuleConditionSchema;\n minimum?: number;\n maximum?: number;\n exclusiveMinimum?: number;\n exclusiveMaximum?: number;\n minLength?: number;\n properties?: Record<string, RuleConditionSchema>;\n required?: string[];\n allOf?: RuleConditionSchema[];\n}\n\n// Build the Zod schema referencing the pre-declared interface.\n// We use z.ZodType<RuleConditionSchema> so the recursive reference works.\n// The interface uses `?` (exact optional), and z.ZodType checks output only,\n// so the optional fields (which Zod infers as `T | undefined`) are compatible\n// because `T | undefined` is assignable to the optional field slot.\n//\n// @ts-expect-error -- exactOptionalPropertyTypes: the Zod output type for optional\n// fields is `T | undefined`, but our interface uses `?` (exact optional, key may\n// be absent). This is a known mismatch when using z.ZodType<T> with\n// exactOptionalPropertyTypes:true; the runtime behavior is correct.\nexport const ruleConditionSchema: z.ZodType<RuleConditionSchema> = z.lazy(() =>\n z\n .object({\n const: z.unknown().optional(),\n enum: z.array(z.unknown()).readonly().optional(),\n type: z.string().optional(),\n not: ruleConditionSchema.optional(),\n minimum: z.number().optional(),\n maximum: z.number().optional(),\n exclusiveMinimum: z.number().optional(),\n exclusiveMaximum: z.number().optional(),\n minLength: z.number().optional(),\n properties: z.record(z.string(), ruleConditionSchema).optional(),\n required: z.array(z.string()).optional(),\n allOf: z.array(ruleConditionSchema).optional(),\n })\n .strict()\n);\n\n// =============================================================================\n// Schema-Based Condition and Rule\n// =============================================================================\n\n/**\n * Zod schema for a schema-based rule condition.\n */\nexport const schemaBasedConditionSchema = z\n .object({\n scope: jsonPointerSchema,\n schema: ruleConditionSchema,\n })\n .strict();\n\n/**\n * Condition for a rule.\n */\nexport type SchemaBasedCondition = z.infer<typeof schemaBasedConditionSchema>;\n\n/**\n * Zod schema for a UI Schema rule.\n */\nexport const ruleSchema = z\n .object({\n effect: ruleEffectSchema,\n condition: schemaBasedConditionSchema,\n })\n .strict();\n\n/**\n * Rule for conditional element visibility/enablement.\n */\nexport type Rule = z.infer<typeof ruleSchema>;\n\n// =============================================================================\n// UI Schema Element Schemas (recursive via z.lazy)\n// =============================================================================\n\n// Forward-declare UISchemaElement so layout schemas can reference it.\n// We declare the type up-front and wire the Zod schema below.\n/**\n * Union of all UI Schema element types.\n */\nexport type UISchemaElement =\n | ControlElement\n | VerticalLayout\n | HorizontalLayout\n | GroupLayout\n | Categorization\n | Category\n | LabelElement;\n\n// The Zod schema for UISchemaElement is defined as a const using z.lazy(),\n// which defers evaluation until first use. This allows all element schemas\n// below to be referenced even though they are declared after this line.\nexport const uiSchemaElementSchema: z.ZodType<UISchemaElement> = z.lazy(() =>\n z.union([\n controlSchema,\n verticalLayoutSchema,\n horizontalLayoutSchema,\n groupLayoutSchema,\n categorizationSchema,\n categorySchema,\n labelElementSchema,\n ])\n) as z.ZodType<UISchemaElement>;\n\n// -----------------------------------------------------------------------------\n// Control\n// -----------------------------------------------------------------------------\n\n/**\n * Zod schema for a Control element.\n */\nexport const controlSchema = z\n .object({\n type: z.literal(\"Control\"),\n scope: jsonPointerSchema,\n label: z.union([z.string(), z.literal(false)]).optional(),\n rule: ruleSchema.optional(),\n options: z.record(z.string(), z.unknown()).optional(),\n })\n .passthrough();\n\n/**\n * A Control element that binds to a JSON Schema property.\n */\nexport type ControlElement = z.infer<typeof controlSchema>;\n\n// -----------------------------------------------------------------------------\n// VerticalLayout\n// -----------------------------------------------------------------------------\n\n// Pre-declare the interface so the Zod schema can reference UISchemaElement.\n/**\n * A vertical layout element.\n */\nexport interface VerticalLayout {\n type: \"VerticalLayout\";\n elements: UISchemaElement[];\n rule?: Rule | undefined;\n options?: Record<string, unknown> | undefined;\n [k: string]: unknown;\n}\n\nexport const verticalLayoutSchema: z.ZodType<VerticalLayout> = z.lazy(() =>\n z\n .object({\n type: z.literal(\"VerticalLayout\"),\n elements: z.array(uiSchemaElementSchema),\n rule: ruleSchema.optional(),\n options: z.record(z.string(), z.unknown()).optional(),\n })\n .passthrough()\n);\n\n// -----------------------------------------------------------------------------\n// HorizontalLayout\n// -----------------------------------------------------------------------------\n\n/**\n * A horizontal layout element.\n */\nexport interface HorizontalLayout {\n type: \"HorizontalLayout\";\n elements: UISchemaElement[];\n rule?: Rule | undefined;\n options?: Record<string, unknown> | undefined;\n [k: string]: unknown;\n}\n\nexport const horizontalLayoutSchema: z.ZodType<HorizontalLayout> = z.lazy(() =>\n z\n .object({\n type: z.literal(\"HorizontalLayout\"),\n elements: z.array(uiSchemaElementSchema),\n rule: ruleSchema.optional(),\n options: z.record(z.string(), z.unknown()).optional(),\n })\n .passthrough()\n);\n\n// -----------------------------------------------------------------------------\n// GroupLayout\n// -----------------------------------------------------------------------------\n\n/**\n * A group element with a label.\n */\nexport interface GroupLayout {\n type: \"Group\";\n label: string;\n elements: UISchemaElement[];\n rule?: Rule | undefined;\n options?: Record<string, unknown> | undefined;\n [k: string]: unknown;\n}\n\nexport const groupLayoutSchema: z.ZodType<GroupLayout> = z.lazy(() =>\n z\n .object({\n type: z.literal(\"Group\"),\n label: z.string(),\n elements: z.array(uiSchemaElementSchema),\n rule: ruleSchema.optional(),\n options: z.record(z.string(), z.unknown()).optional(),\n })\n .passthrough()\n);\n\n// -----------------------------------------------------------------------------\n// Category\n// -----------------------------------------------------------------------------\n\n/**\n * A Category element, used inside a Categorization layout.\n */\nexport interface Category {\n type: \"Category\";\n label: string;\n elements: UISchemaElement[];\n rule?: Rule | undefined;\n options?: Record<string, unknown> | undefined;\n [k: string]: unknown;\n}\n\nexport const categorySchema: z.ZodType<Category> = z.lazy(() =>\n z\n .object({\n type: z.literal(\"Category\"),\n label: z.string(),\n elements: z.array(uiSchemaElementSchema),\n rule: ruleSchema.optional(),\n options: z.record(z.string(), z.unknown()).optional(),\n })\n .passthrough()\n);\n\n// -----------------------------------------------------------------------------\n// Categorization\n// -----------------------------------------------------------------------------\n\n/**\n * A Categorization element (tab-based layout).\n */\nexport interface Categorization {\n type: \"Categorization\";\n elements: Category[];\n label?: string | undefined;\n rule?: Rule | undefined;\n options?: Record<string, unknown> | undefined;\n [k: string]: unknown;\n}\n\nexport const categorizationSchema: z.ZodType<Categorization> = z.lazy(() =>\n z\n .object({\n type: z.literal(\"Categorization\"),\n elements: z.array(categorySchema),\n label: z.string().optional(),\n rule: ruleSchema.optional(),\n options: z.record(z.string(), z.unknown()).optional(),\n })\n .passthrough()\n);\n\n// -----------------------------------------------------------------------------\n// LabelElement\n// -----------------------------------------------------------------------------\n\n/**\n * Zod schema for a Label element.\n */\nexport const labelElementSchema = z\n .object({\n type: z.literal(\"Label\"),\n text: z.string(),\n rule: ruleSchema.optional(),\n options: z.record(z.string(), z.unknown()).optional(),\n })\n .passthrough();\n\n/**\n * A Label element for displaying static text.\n */\nexport type LabelElement = z.infer<typeof labelElementSchema>;\n\n// =============================================================================\n// Root UISchema\n// =============================================================================\n\n/**\n * Root UI Schema (always a layout — not a Control, Category, or Label).\n */\nexport type UISchema = VerticalLayout | HorizontalLayout | GroupLayout | Categorization;\n\n/**\n * Zod schema for the root UI Schema (layout types only).\n */\nexport const uiSchema: z.ZodType<UISchema> = z.lazy(() =>\n z.union([verticalLayoutSchema, horizontalLayoutSchema, groupLayoutSchema, categorizationSchema])\n) as z.ZodType<UISchema>;\n","/**\n * JSON Forms UI Schema generator that operates on the canonical FormIR.\n *\n * This generator consumes the IR produced by the Canonicalize phase and\n * produces a JSON Forms UI Schema. All downstream UI Schema generation\n * should use this module for UI Schema generation.\n */\n\nimport type { FormIR, FormIRElement, FieldNode, GroupLayoutNode } from \"@formspec/core\";\nimport type { UISchema, UISchemaElement, ControlElement, GroupLayout, Rule } from \"./types.js\";\nimport { uiSchema as uiSchemaValidator } from \"./schema.js\";\nimport { z } from \"zod\";\n\n// =============================================================================\n// HELPERS\n// =============================================================================\n\n/**\n * Parses a value through a Zod schema, converting validation errors to a\n * descriptive Error.\n */\nfunction parseOrThrow<T>(schema: z.ZodType<T>, value: unknown, label: string): T {\n try {\n return schema.parse(value);\n } catch (error) {\n if (error instanceof z.ZodError) {\n throw new Error(\n `Generated ${label} failed validation:\\n${error.issues.map((i) => ` ${i.path.join(\".\")}: ${i.message}`).join(\"\\n\")}`\n );\n }\n throw error;\n }\n}\n\n/**\n * Converts a field name to a JSON Pointer scope string.\n */\nfunction fieldToScope(fieldName: string): string {\n return `#/properties/${fieldName}`;\n}\n\n/**\n * Creates a SHOW rule for a single conditional field/value pair.\n */\nfunction createShowRule(fieldName: string, value: unknown): Rule {\n return {\n effect: \"SHOW\",\n condition: {\n scope: fieldToScope(fieldName),\n schema: { const: value },\n },\n };\n}\n\n/**\n * Combines two SHOW rules into a single rule using an allOf condition.\n *\n * When elements are nested inside multiple conditionals, all parent conditions\n * must be met for the element to be visible. This function merges the two\n * conditions into a single rule using allOf so that JSON Forms evaluates\n * both predicates simultaneously.\n */\nfunction combineRules(parentRule: Rule, childRule: Rule): Rule {\n const parentCondition = parentRule.condition;\n const childCondition = childRule.condition;\n\n return {\n effect: \"SHOW\",\n condition: {\n scope: \"#\",\n schema: {\n allOf: [\n {\n properties: {\n [parentCondition.scope.replace(\"#/properties/\", \"\")]: parentCondition.schema,\n },\n },\n {\n properties: {\n [childCondition.scope.replace(\"#/properties/\", \"\")]: childCondition.schema,\n },\n },\n ],\n },\n },\n };\n}\n\n// =============================================================================\n// ELEMENT CONVERSION\n// =============================================================================\n\n/**\n * Converts a FieldNode from the IR to a ControlElement.\n *\n * The label is sourced from the first `displayName` annotation on the field,\n * matching how the chain DSL propagates the `label` option through the\n * canonicalization phase.\n */\nfunction fieldNodeToControl(field: FieldNode, parentRule?: Rule): ControlElement {\n const displayNameAnnotation = field.annotations.find((a) => a.annotationKind === \"displayName\");\n\n const control: ControlElement = {\n type: \"Control\",\n scope: fieldToScope(field.name),\n ...(displayNameAnnotation !== undefined && { label: displayNameAnnotation.value }),\n ...(parentRule !== undefined && { rule: parentRule }),\n };\n\n return control;\n}\n\n/**\n * Converts a GroupLayoutNode from the IR to a GroupLayout element.\n *\n * The group's children are recursively converted; the optional parent rule is\n * forwarded to nested elements so that a group inside a conditional inherits\n * the visibility rule.\n */\nfunction groupNodeToLayout(group: GroupLayoutNode, parentRule?: Rule): GroupLayout {\n return {\n type: \"Group\",\n label: group.label,\n elements: irElementsToUiSchema(group.elements, parentRule),\n ...(parentRule !== undefined && { rule: parentRule }),\n };\n}\n\n/**\n * Converts an array of IR elements to UI Schema elements.\n *\n * @param elements - The IR elements to convert\n * @param parentRule - Optional rule inherited from a parent ConditionalLayoutNode\n * @returns Array of UI Schema elements\n */\nfunction irElementsToUiSchema(\n elements: readonly FormIRElement[],\n parentRule?: Rule\n): UISchemaElement[] {\n const result: UISchemaElement[] = [];\n\n for (const element of elements) {\n switch (element.kind) {\n case \"field\": {\n result.push(fieldNodeToControl(element, parentRule));\n break;\n }\n\n case \"group\": {\n result.push(groupNodeToLayout(element, parentRule));\n break;\n }\n\n case \"conditional\": {\n // Build the rule for this conditional level.\n const newRule = createShowRule(element.fieldName, element.value);\n // Combine with the inherited parent rule for nested conditionals.\n const combinedRule = parentRule !== undefined ? combineRules(parentRule, newRule) : newRule;\n // Children are flattened into the parent container with the combined\n // rule attached.\n const childElements = irElementsToUiSchema(element.elements, combinedRule);\n result.push(...childElements);\n break;\n }\n\n default: {\n const _exhaustive: never = element;\n void _exhaustive;\n throw new Error(\"Unhandled IR element kind\");\n }\n }\n }\n\n return result;\n}\n\n// =============================================================================\n// PUBLIC API\n// =============================================================================\n\n/**\n * Generates a JSON Forms UI Schema from a canonical `FormIR`.\n *\n * Mapping rules:\n * - `FieldNode` → `ControlElement` with `scope: \"#/properties/<name>\"`\n * - `displayName` annotation → `label` on the `ControlElement`\n * - `GroupLayoutNode` → `GroupLayout` with recursively converted `elements`\n * - `ConditionalLayoutNode` → children flattened with a `SHOW` rule\n * - Nested conditionals → combined `allOf` rule\n * - Root wrapper is always `{ type: \"VerticalLayout\", elements: [...] }`\n *\n * @example\n * ```typescript\n * const ir = canonicalizeDSL(\n * formspec(\n * group(\"Customer\", field.text(\"name\", { label: \"Name\" })),\n * when(is(\"status\", \"draft\"), field.text(\"notes\", { label: \"Notes\" })),\n * )\n * );\n *\n * const uiSchema = generateUiSchemaFromIR(ir);\n * // {\n * // type: \"VerticalLayout\",\n * // elements: [\n * // {\n * // type: \"Group\",\n * // label: \"Customer\",\n * // elements: [{ type: \"Control\", scope: \"#/properties/name\", label: \"Name\" }]\n * // },\n * // {\n * // type: \"Control\",\n * // scope: \"#/properties/notes\",\n * // label: \"Notes\",\n * // rule: { effect: \"SHOW\", condition: { scope: \"#/properties/status\", schema: { const: \"draft\" } } }\n * // }\n * // ]\n * // }\n * ```\n *\n * @param ir - The canonical FormIR produced by the Canonicalize phase\n * @returns A validated JSON Forms UI Schema\n */\nexport function generateUiSchemaFromIR(ir: FormIR): UISchema {\n const result: UISchema = {\n type: \"VerticalLayout\",\n elements: irElementsToUiSchema(ir.elements),\n };\n\n return parseOrThrow(uiSchemaValidator, result, \"UI Schema\");\n}\n","/**\n * JSON Forms UI Schema generator for FormSpec forms.\n *\n * Routes through the canonical IR pipeline: Chain DSL → FormIR → UI Schema.\n */\n\nimport type { FormElement, FormSpec } from \"@formspec/core\";\nimport { canonicalizeChainDSL } from \"../canonicalize/index.js\";\nimport { generateUiSchemaFromIR } from \"./ir-generator.js\";\nimport type { UISchema } from \"./types.js\";\n\n/**\n * Generates a JSON Forms UI Schema from a FormSpec.\n *\n * All generation routes through the canonical IR. The chain DSL is first\n * canonicalized to a FormIR, then the IR-based generator produces the schema.\n *\n * @example\n * ```typescript\n * const form = formspec(\n * group(\"Customer\",\n * field.text(\"name\", { label: \"Name\" }),\n * ),\n * when(\"status\", \"draft\",\n * field.text(\"notes\", { label: \"Notes\" }),\n * ),\n * );\n *\n * const uiSchema = generateUiSchema(form);\n * // {\n * // type: \"VerticalLayout\",\n * // elements: [\n * // {\n * // type: \"Group\",\n * // label: \"Customer\",\n * // elements: [\n * // { type: \"Control\", scope: \"#/properties/name\", label: \"Name\" }\n * // ]\n * // },\n * // {\n * // type: \"Control\",\n * // scope: \"#/properties/notes\",\n * // label: \"Notes\",\n * // rule: {\n * // effect: \"SHOW\",\n * // condition: { scope: \"#/properties/status\", schema: { const: \"draft\" } }\n * // }\n * // }\n * // ]\n * // }\n * ```\n *\n * @param form - The FormSpec to convert\n * @returns A JSON Forms UI Schema\n */\nexport function generateUiSchema<E extends readonly FormElement[]>(form: FormSpec<E>): UISchema {\n const ir = canonicalizeChainDSL(form);\n return generateUiSchemaFromIR(ir);\n}\n","/**\n * `@formspec/build` - Build tools for FormSpec\n *\n * This package provides generators to compile FormSpec forms into:\n * - JSON Schema 2020-12 (for validation)\n * - JSON Forms UI Schema (for rendering)\n *\n * @example\n * ```typescript\n * import { buildFormSchemas } from \"@formspec/build\";\n * import { formspec, field, group } from \"@formspec/dsl\";\n *\n * const form = formspec(\n * group(\"Customer\",\n * field.text(\"name\", { label: \"Name\", required: true }),\n * field.text(\"email\", { label: \"Email\" }),\n * ),\n * );\n *\n * const { jsonSchema, uiSchema } = buildFormSchemas(form);\n * ```\n *\n * @packageDocumentation\n */\n\nimport type { FormElement, FormSpec } from \"@formspec/core\";\nimport { generateJsonSchema } from \"./json-schema/generator.js\";\nimport { generateUiSchema } from \"./ui-schema/generator.js\";\nimport type { JsonSchema2020 } from \"./json-schema/ir-generator.js\";\nimport type { UISchema } from \"./ui-schema/types.js\";\nimport * as fs from \"node:fs\";\nimport * as path from \"node:path\";\n\n// =============================================================================\n// Type Exports\n// =============================================================================\n\nexport type { JsonSchema2020 } from \"./json-schema/ir-generator.js\";\n\nexport type {\n JSONSchema7,\n JSONSchemaType,\n ExtendedJSONSchema7,\n FormSpecSchemaExtensions,\n} from \"./json-schema/types.js\";\n\nexport { setSchemaExtension, getSchemaExtension } from \"./json-schema/types.js\";\n\nexport type {\n UISchema,\n UISchemaElement,\n UISchemaElementBase,\n UISchemaElementType,\n ControlElement,\n VerticalLayout,\n HorizontalLayout,\n GroupLayout,\n Categorization,\n Category,\n LabelElement,\n Rule,\n RuleEffect,\n RuleConditionSchema,\n SchemaBasedCondition,\n} from \"./ui-schema/types.js\";\n\nexport type {\n ClassSchemas,\n GenerateFromClassOptions,\n GenerateFromClassResult,\n GenerateSchemasOptions,\n} from \"./generators/class-schema.js\";\n\n// =============================================================================\n// Zod Validation Schemas\n// =============================================================================\n\nexport {\n ruleEffectSchema,\n uiSchemaElementTypeSchema,\n ruleConditionSchema,\n schemaBasedConditionSchema,\n ruleSchema,\n controlSchema,\n verticalLayoutSchema,\n horizontalLayoutSchema,\n groupLayoutSchema,\n categorizationSchema,\n categorySchema,\n labelElementSchema,\n uiSchemaElementSchema,\n uiSchema as uiSchemaSchema,\n} from \"./ui-schema/schema.js\";\n\nexport { jsonSchemaTypeSchema, jsonSchema7Schema } from \"./json-schema/schema.js\";\n\n// =============================================================================\n// Chain DSL Generators\n// =============================================================================\n\nexport { generateJsonSchema } from \"./json-schema/generator.js\";\nexport { generateUiSchema } from \"./ui-schema/generator.js\";\n\n// =============================================================================\n// Class/Interface Analysis: High-Level Entry Points\n// =============================================================================\n\nexport { generateSchemasFromClass, generateSchemas } from \"./generators/class-schema.js\";\n\n// generateSchemas is the recommended entry point — it auto-detects class/interface/type alias.\n// generateSchemasFromClass is retained for backwards compatibility.\n\n/**\n * Result of building form schemas.\n */\nexport interface BuildResult {\n /** JSON Schema 2020-12 for validation */\n readonly jsonSchema: JsonSchema2020;\n /** JSON Forms UI Schema for rendering */\n readonly uiSchema: UISchema;\n}\n\n/**\n * Builds both JSON Schema and UI Schema from a FormSpec.\n *\n * This is a convenience function that combines `generateJsonSchema`\n * and `generateUiSchema`.\n *\n * @example\n * ```typescript\n * const form = formspec(\n * field.text(\"name\", { required: true }),\n * field.number(\"age\", { min: 0 }),\n * );\n *\n * const { jsonSchema, uiSchema } = buildFormSchemas(form);\n *\n * // Use with JSON Forms renderer\n * <JsonForms\n * schema={jsonSchema}\n * uischema={uiSchema}\n * data={formData}\n * renderers={materialRenderers}\n * />\n * ```\n *\n * @param form - The FormSpec to build schemas from\n * @returns Object containing both jsonSchema and uiSchema\n */\nexport function buildFormSchemas<E extends readonly FormElement[]>(form: FormSpec<E>): BuildResult {\n return {\n jsonSchema: generateJsonSchema(form),\n uiSchema: generateUiSchema(form),\n };\n}\n\n/**\n * Options for writing schemas to disk.\n */\nexport interface WriteSchemasOptions {\n /** Output directory for the schema files */\n readonly outDir: string;\n /** Base name for the output files (without extension). Defaults to \"schema\" */\n readonly name?: string;\n /** Number of spaces for JSON indentation. Defaults to 2 */\n readonly indent?: number;\n}\n\n/**\n * Result of writing schemas to disk.\n */\nexport interface WriteSchemasResult {\n /** Path to the generated JSON Schema file */\n readonly jsonSchemaPath: string;\n /** Path to the generated UI Schema file */\n readonly uiSchemaPath: string;\n}\n\n/**\n * Builds and writes both JSON Schema and UI Schema files to disk.\n *\n * This is a convenience function for build-time schema generation.\n * It creates the output directory if it doesn't exist.\n *\n * @example\n * ```typescript\n * import { formspec, field } from \"formspec\";\n * import { writeSchemas } from \"@formspec/build\";\n *\n * const ProductForm = formspec(\n * field.text(\"name\", { required: true }),\n * field.enum(\"status\", [\"draft\", \"active\"]),\n * );\n *\n * // Write schemas to ./generated/product-schema.json and ./generated/product-uischema.json\n * const { jsonSchemaPath, uiSchemaPath } = writeSchemas(ProductForm, {\n * outDir: \"./generated\",\n * name: \"product\",\n * });\n *\n * console.log(`Generated: ${jsonSchemaPath}, ${uiSchemaPath}`);\n * ```\n *\n * @param form - The FormSpec to build schemas from\n * @param options - Output options (directory, file name, indentation)\n * @returns Object containing paths to the generated files\n */\nexport function writeSchemas<E extends readonly FormElement[]>(\n form: FormSpec<E>,\n options: WriteSchemasOptions\n): WriteSchemasResult {\n const { outDir, name = \"schema\", indent = 2 } = options;\n\n // Build schemas\n const { jsonSchema, uiSchema } = buildFormSchemas(form);\n\n // Ensure output directory exists\n if (!fs.existsSync(outDir)) {\n fs.mkdirSync(outDir, { recursive: true });\n }\n\n // Write files\n const jsonSchemaPath = path.join(outDir, `${name}-schema.json`);\n const uiSchemaPath = path.join(outDir, `${name}-uischema.json`);\n\n fs.writeFileSync(jsonSchemaPath, JSON.stringify(jsonSchema, null, indent));\n fs.writeFileSync(uiSchemaPath, JSON.stringify(uiSchema, null, indent));\n\n return { jsonSchemaPath, uiSchemaPath };\n}\n","/**\n * JSON Schema type definitions.\n *\n * These types are a subset of JSON Schema sufficient for form generation.\n */\n\n/**\n * JSON Schema primitive types.\n */\nexport type JSONSchemaType =\n | \"string\"\n | \"number\"\n | \"integer\"\n | \"boolean\"\n | \"object\"\n | \"array\"\n | \"null\";\n\n/**\n * A JSON Schema definition (legacy subset used by Zod validator and types.ts).\n */\nexport interface JSONSchema7 {\n $schema?: string;\n $id?: string;\n $ref?: string;\n\n // Metadata\n title?: string;\n description?: string;\n deprecated?: boolean;\n\n // Type\n type?: JSONSchemaType | JSONSchemaType[];\n\n // String validation\n minLength?: number;\n maxLength?: number;\n pattern?: string;\n\n // Number validation\n minimum?: number;\n maximum?: number;\n exclusiveMinimum?: number;\n exclusiveMaximum?: number;\n\n // Enum\n enum?: readonly (string | number | boolean | null)[];\n const?: string | number | boolean | null;\n\n // Object\n properties?: Record<string, JSONSchema7>;\n required?: string[];\n additionalProperties?: boolean | JSONSchema7;\n\n // Array\n items?: JSONSchema7 | JSONSchema7[];\n minItems?: number;\n maxItems?: number;\n\n // Composition\n allOf?: JSONSchema7[];\n anyOf?: JSONSchema7[];\n oneOf?: JSONSchema7[];\n not?: JSONSchema7;\n\n // Conditional\n if?: JSONSchema7;\n then?: JSONSchema7;\n else?: JSONSchema7;\n\n // Format\n format?: string;\n\n // Default\n default?: unknown;\n\n // =============================================================================\n // FormSpec Extensions (x- prefixed)\n // =============================================================================\n\n /**\n * Data source key for dynamic enum fields.\n * Indicates that options should be fetched from a registered resolver.\n */\n \"x-formspec-source\"?: string;\n\n /**\n * Field names whose values are needed to fetch dynamic enum options.\n * Used for dependent/cascading dropdowns.\n */\n \"x-formspec-params\"?: readonly string[];\n\n /**\n * Schema source identifier for dynamic schema fields.\n * Indicates that the schema should be loaded dynamically at runtime.\n */\n \"x-formspec-schemaSource\"?: string;\n}\n\n/** Extension properties for custom FormSpec decorators. */\nexport type FormSpecSchemaExtensions = Record<`x-formspec-${string}`, unknown>;\n\n/** JSON Schema with FormSpec extension properties for arbitrary x-formspec-* keys. */\nexport type ExtendedJSONSchema7 = JSONSchema7 & FormSpecSchemaExtensions;\n\n/**\n * Sets a FormSpec extension property on a JSON Schema node.\n *\n * Use this to safely add `x-formspec-*` properties to any schema,\n * including nested schemas typed as `JSONSchema7` (which don't carry\n * the extension index signature).\n *\n * @param schema - Any JSON Schema node\n * @param key - Extension key (must start with `x-formspec-`)\n * @param value - Extension value\n */\nexport function setSchemaExtension(\n schema: object,\n key: `x-formspec-${string}`,\n value: unknown\n): void {\n (schema as Record<string, unknown>)[key] = value;\n}\n\n/**\n * Reads a FormSpec extension property from a JSON Schema node.\n *\n * Accepts any schema object — `JSONSchema7`, `JsonSchema2020`, `ExtendedJSONSchema7`, etc.\n *\n * @param schema - Any JSON Schema node\n * @param key - Extension key (must start with `x-formspec-`)\n * @returns The extension value, or `undefined` if not present\n */\nexport function getSchemaExtension(schema: object, key: `x-formspec-${string}`): unknown {\n return (schema as Record<string, unknown>)[key];\n}\n","/**\n * Zod schemas for JSON Schema output validation.\n *\n * These schemas cover the subset of JSON Schema that FormSpec generates,\n * plus the FormSpec-specific `x-formspec-*` extension properties.\n *\n * @see https://json-schema.org/draft/2020-12/schema\n */\n\nimport { z } from \"zod\";\nimport type { JSONSchema7 } from \"./types.js\";\n\n// =============================================================================\n// JSON Schema type enum\n// =============================================================================\n\n/**\n * Zod schema for JSON Schema primitive type strings.\n */\nexport const jsonSchemaTypeSchema = z.enum([\n \"string\",\n \"number\",\n \"integer\",\n \"boolean\",\n \"object\",\n \"array\",\n \"null\",\n]);\n\n// =============================================================================\n// JSON Schema validator schema (recursive)\n// =============================================================================\n\n// We annotate with z.ZodType<JSONSchema7> for the recursive self-reference.\n// The @ts-expect-error is required because exactOptionalPropertyTypes:true causes\n// Zod's inferred output type for optional fields (`T | undefined`) to be\n// incompatible with the JSONSchema7 interface's exact optional fields (`T?`).\n// The runtime behavior is correct: z.optional() will strip `undefined` values\n// during parsing and correctly handle absent keys.\n//\n// @ts-expect-error -- exactOptionalPropertyTypes: Zod optional infers `T | undefined`\n// but JSONSchema7 uses exact optional `?:` which disallows explicit undefined.\nexport const jsonSchema7Schema: z.ZodType<JSONSchema7> = z.lazy(() =>\n z\n .object({\n $schema: z.string().optional(),\n $id: z.string().optional(),\n $ref: z.string().optional(),\n\n // Metadata\n title: z.string().optional(),\n description: z.string().optional(),\n deprecated: z.boolean().optional(),\n\n // Type\n type: z.union([jsonSchemaTypeSchema, z.array(jsonSchemaTypeSchema)]).optional(),\n\n // String validation\n minLength: z.number().optional(),\n maxLength: z.number().optional(),\n pattern: z.string().optional(),\n\n // Number validation\n minimum: z.number().optional(),\n maximum: z.number().optional(),\n exclusiveMinimum: z.number().optional(),\n exclusiveMaximum: z.number().optional(),\n\n // Enum\n enum: z\n .array(z.union([z.string(), z.number(), z.boolean(), z.null()]))\n .readonly()\n .optional(),\n const: z.union([z.string(), z.number(), z.boolean(), z.null()]).optional(),\n\n // Object\n properties: z.record(z.string(), jsonSchema7Schema).optional(),\n required: z.array(z.string()).optional(),\n additionalProperties: z.union([z.boolean(), jsonSchema7Schema]).optional(),\n\n // Array\n items: z.union([jsonSchema7Schema, z.array(jsonSchema7Schema)]).optional(),\n minItems: z.number().optional(),\n maxItems: z.number().optional(),\n\n // Composition\n allOf: z.array(jsonSchema7Schema).optional(),\n anyOf: z.array(jsonSchema7Schema).optional(),\n oneOf: z.array(jsonSchema7Schema).optional(),\n not: jsonSchema7Schema.optional(),\n\n // Conditional\n if: jsonSchema7Schema.optional(),\n then: jsonSchema7Schema.optional(),\n else: jsonSchema7Schema.optional(),\n\n // Format\n format: z.string().optional(),\n\n // Default\n default: z.unknown().optional(),\n\n // FormSpec extensions\n \"x-formspec-source\": z.string().optional(),\n \"x-formspec-params\": z.array(z.string()).readonly().optional(),\n \"x-formspec-schemaSource\": z.string().optional(),\n })\n // passthrough preserves arbitrary x-formspec-* extension properties\n // added by custom decorators without causing validation failures\n .passthrough()\n);\n","/**\n * TypeScript program setup for static analysis.\n *\n * Creates a TypeScript program with type checker from a source file,\n * using the project's tsconfig.json for compiler options.\n */\n\nimport * as ts from \"typescript\";\nimport * as path from \"node:path\";\n\n/**\n * Result of creating a TypeScript program for analysis.\n */\nexport interface ProgramContext {\n /** The TypeScript program */\n program: ts.Program;\n /** Type checker for resolving types */\n checker: ts.TypeChecker;\n /** The source file being analyzed */\n sourceFile: ts.SourceFile;\n}\n\n/**\n * Creates a TypeScript program for analyzing a source file.\n *\n * Looks for tsconfig.json in the file's directory or parent directories.\n * Falls back to default compiler options if no config is found.\n *\n * @param filePath - Absolute path to the TypeScript source file\n * @returns Program context with checker and source file\n */\nexport function createProgramContext(filePath: string): ProgramContext {\n const absolutePath = path.resolve(filePath);\n const fileDir = path.dirname(absolutePath);\n\n // Find tsconfig.json - using ts.sys.fileExists which has `this: void` requirement\n const configPath = ts.findConfigFile(fileDir, ts.sys.fileExists.bind(ts.sys), \"tsconfig.json\");\n\n let compilerOptions: ts.CompilerOptions;\n let fileNames: string[];\n\n if (configPath) {\n const configFile = ts.readConfigFile(configPath, ts.sys.readFile.bind(ts.sys));\n if (configFile.error) {\n throw new Error(\n `Error reading tsconfig.json: ${ts.flattenDiagnosticMessageText(configFile.error.messageText, \"\\n\")}`\n );\n }\n\n const parsed = ts.parseJsonConfigFileContent(\n configFile.config,\n ts.sys,\n path.dirname(configPath)\n );\n\n if (parsed.errors.length > 0) {\n const errorMessages = parsed.errors\n .map((e) => ts.flattenDiagnosticMessageText(e.messageText, \"\\n\"))\n .join(\"\\n\");\n throw new Error(`Error parsing tsconfig.json: ${errorMessages}`);\n }\n\n compilerOptions = parsed.options;\n // Include the target file in the program\n fileNames = parsed.fileNames.includes(absolutePath)\n ? parsed.fileNames\n : [...parsed.fileNames, absolutePath];\n } else {\n // Fallback to default options\n compilerOptions = {\n target: ts.ScriptTarget.ES2022,\n module: ts.ModuleKind.NodeNext,\n moduleResolution: ts.ModuleResolutionKind.NodeNext,\n strict: true,\n skipLibCheck: true,\n declaration: true,\n };\n fileNames = [absolutePath];\n }\n\n const program = ts.createProgram(fileNames, compilerOptions);\n const sourceFile = program.getSourceFile(absolutePath);\n\n if (!sourceFile) {\n throw new Error(`Could not find source file: ${absolutePath}`);\n }\n\n return {\n program,\n checker: program.getTypeChecker(),\n sourceFile,\n };\n}\n\n/**\n * Generic AST node finder by name. Walks the source file tree and returns\n * the first node matching the predicate with the given name.\n */\nfunction findNodeByName<T extends ts.Node>(\n sourceFile: ts.SourceFile,\n name: string,\n predicate: (node: ts.Node) => node is T,\n getName: (node: T) => string | undefined\n): T | null {\n let result: T | null = null;\n\n function visit(node: ts.Node): void {\n if (result) return;\n\n if (predicate(node) && getName(node) === name) {\n result = node;\n return;\n }\n\n ts.forEachChild(node, visit);\n }\n\n visit(sourceFile);\n return result;\n}\n\n/**\n * Finds a class declaration by name in a source file.\n *\n * @param sourceFile - The source file to search\n * @param className - Name of the class to find\n * @returns The class declaration node, or null if not found\n */\nexport function findClassByName(\n sourceFile: ts.SourceFile,\n className: string\n): ts.ClassDeclaration | null {\n return findNodeByName(sourceFile, className, ts.isClassDeclaration, (n) => n.name?.text);\n}\n\n/**\n * Finds an interface declaration by name in a source file.\n *\n * @param sourceFile - The source file to search\n * @param interfaceName - Name of the interface to find\n * @returns The interface declaration node, or null if not found\n */\nexport function findInterfaceByName(\n sourceFile: ts.SourceFile,\n interfaceName: string\n): ts.InterfaceDeclaration | null {\n return findNodeByName(sourceFile, interfaceName, ts.isInterfaceDeclaration, (n) => n.name.text);\n}\n\n/**\n * Finds a type alias declaration by name in a source file.\n *\n * @param sourceFile - The source file to search\n * @param aliasName - Name of the type alias to find\n * @returns The type alias declaration node, or null if not found\n */\nexport function findTypeAliasByName(\n sourceFile: ts.SourceFile,\n aliasName: string\n): ts.TypeAliasDeclaration | null {\n return findNodeByName(sourceFile, aliasName, ts.isTypeAliasDeclaration, (n) => n.name.text);\n}\n","/**\n * Class analyzer for extracting fields, types, and JSDoc constraints.\n *\n * Produces `IRClassAnalysis` containing `FieldNode[]` and `typeRegistry`\n * directly from class, interface, or type alias declarations.\n * All downstream generation routes through the canonical FormIR.\n */\n\nimport * as ts from \"typescript\";\nimport type {\n FieldNode,\n TypeNode,\n ConstraintNode,\n AnnotationNode,\n Provenance,\n ObjectProperty,\n TypeDefinition,\n JsonValue,\n} from \"@formspec/core\";\nimport {\n extractJSDocConstraintNodes,\n extractJSDocAnnotationNodes,\n extractDefaultValueAnnotation,\n} from \"./jsdoc-constraints.js\";\n\n// =============================================================================\n// TYPE GUARDS\n// =============================================================================\n\n/**\n * Type guard for ts.ObjectType — checks that the TypeFlags.Object bit is set.\n */\nfunction isObjectType(type: ts.Type): type is ts.ObjectType {\n return !!(type.flags & ts.TypeFlags.Object);\n}\n\n/**\n * Type guard for ts.TypeReference — checks ObjectFlags.Reference on top of ObjectType.\n * The internal `as` cast is isolated inside this guard and is required because\n * TypeScript's public API does not expose objectFlags on ts.Type directly.\n */\nfunction isTypeReference(type: ts.Type): type is ts.TypeReference {\n // as cast is isolated inside type guard\n return (\n !!(type.flags & ts.TypeFlags.Object) &&\n !!((type as ts.ObjectType).objectFlags & ts.ObjectFlags.Reference)\n );\n}\n\n// =============================================================================\n// IR OUTPUT TYPES\n// =============================================================================\n\n/**\n * Layout metadata extracted from `@Group` and `@ShowWhen` decorators.\n * One entry per field, in the same order as `fields`.\n */\nexport interface FieldLayoutMetadata {\n /** Group label from `@Group(\"label\")`, or undefined if ungrouped. */\n readonly groupLabel?: string;\n /** ShowWhen condition from `@ShowWhen({ field, value })`, or undefined if always visible. */\n readonly showWhen?: { readonly field: string; readonly value: JsonValue };\n}\n\n/**\n * Result of analyzing a class/interface/type alias into canonical IR.\n */\nexport interface IRClassAnalysis {\n /** Type name */\n readonly name: string;\n /** Analyzed fields as canonical IR FieldNodes */\n readonly fields: readonly FieldNode[];\n /** Layout metadata per field (same order/length as `fields`). */\n readonly fieldLayouts: readonly FieldLayoutMetadata[];\n /** Named type definitions referenced by fields */\n readonly typeRegistry: Record<string, TypeDefinition>;\n /** Instance methods (retained for downstream method-schema generation) */\n readonly instanceMethods: readonly MethodInfo[];\n /** Static methods */\n readonly staticMethods: readonly MethodInfo[];\n}\n\n/**\n * Result of analyzing a type alias into IR — either success or error.\n */\nexport type AnalyzeTypeAliasToIRResult =\n | { readonly ok: true; readonly analysis: IRClassAnalysis }\n | { readonly ok: false; readonly error: string };\n\n// =============================================================================\n// IR ANALYSIS — PUBLIC API\n// =============================================================================\n\n/**\n * Analyzes a class declaration and produces canonical IR FieldNodes.\n */\nexport function analyzeClassToIR(\n classDecl: ts.ClassDeclaration,\n checker: ts.TypeChecker,\n file = \"\"\n): IRClassAnalysis {\n const name = classDecl.name?.text ?? \"AnonymousClass\";\n const fields: FieldNode[] = [];\n const fieldLayouts: FieldLayoutMetadata[] = [];\n const typeRegistry: Record<string, TypeDefinition> = {};\n const visiting = new Set<ts.Type>();\n const instanceMethods: MethodInfo[] = [];\n const staticMethods: MethodInfo[] = [];\n\n for (const member of classDecl.members) {\n if (ts.isPropertyDeclaration(member)) {\n const fieldNode = analyzeFieldToIR(member, checker, file, typeRegistry, visiting);\n if (fieldNode) {\n fields.push(fieldNode);\n fieldLayouts.push({});\n }\n } else if (ts.isMethodDeclaration(member)) {\n const methodInfo = analyzeMethod(member, checker);\n if (methodInfo) {\n const isStatic = member.modifiers?.some((m) => m.kind === ts.SyntaxKind.StaticKeyword);\n if (isStatic) {\n staticMethods.push(methodInfo);\n } else {\n instanceMethods.push(methodInfo);\n }\n }\n }\n }\n\n return { name, fields, fieldLayouts, typeRegistry, instanceMethods, staticMethods };\n}\n\n/**\n * Analyzes an interface declaration and produces canonical IR FieldNodes.\n */\nexport function analyzeInterfaceToIR(\n interfaceDecl: ts.InterfaceDeclaration,\n checker: ts.TypeChecker,\n file = \"\"\n): IRClassAnalysis {\n const name = interfaceDecl.name.text;\n const fields: FieldNode[] = [];\n const typeRegistry: Record<string, TypeDefinition> = {};\n const visiting = new Set<ts.Type>();\n\n for (const member of interfaceDecl.members) {\n if (ts.isPropertySignature(member)) {\n const fieldNode = analyzeInterfacePropertyToIR(member, checker, file, typeRegistry, visiting);\n if (fieldNode) {\n fields.push(fieldNode);\n }\n }\n }\n\n const fieldLayouts: FieldLayoutMetadata[] = fields.map(() => ({}));\n return { name, fields, fieldLayouts, typeRegistry, instanceMethods: [], staticMethods: [] };\n}\n\n/**\n * Analyzes a type alias declaration and produces canonical IR FieldNodes.\n */\nexport function analyzeTypeAliasToIR(\n typeAlias: ts.TypeAliasDeclaration,\n checker: ts.TypeChecker,\n file = \"\"\n): AnalyzeTypeAliasToIRResult {\n if (!ts.isTypeLiteralNode(typeAlias.type)) {\n const sourceFile = typeAlias.getSourceFile();\n const { line } = sourceFile.getLineAndCharacterOfPosition(typeAlias.getStart());\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- enum reverse mapping can be undefined for compiler-internal kinds\n const kindDesc = ts.SyntaxKind[typeAlias.type.kind] ?? \"unknown\";\n return {\n ok: false,\n error: `Type alias \"${typeAlias.name.text}\" at line ${String(line + 1)} is not an object type literal (found ${kindDesc})`,\n };\n }\n\n const name = typeAlias.name.text;\n const fields: FieldNode[] = [];\n const typeRegistry: Record<string, TypeDefinition> = {};\n const visiting = new Set<ts.Type>();\n\n for (const member of typeAlias.type.members) {\n if (ts.isPropertySignature(member)) {\n const fieldNode = analyzeInterfacePropertyToIR(member, checker, file, typeRegistry, visiting);\n if (fieldNode) {\n fields.push(fieldNode);\n }\n }\n }\n\n return {\n ok: true,\n analysis: {\n name,\n fields,\n fieldLayouts: fields.map(() => ({})),\n typeRegistry,\n instanceMethods: [],\n staticMethods: [],\n },\n };\n}\n\n// =============================================================================\n// IR FIELD ANALYSIS — PRIVATE\n// =============================================================================\n\n/**\n * Analyzes a class property declaration into a canonical IR FieldNode.\n */\nfunction analyzeFieldToIR(\n prop: ts.PropertyDeclaration,\n checker: ts.TypeChecker,\n file: string,\n typeRegistry: Record<string, TypeDefinition>,\n visiting: Set<ts.Type>\n): FieldNode | null {\n if (!ts.isIdentifier(prop.name)) {\n return null;\n }\n\n const name = prop.name.text;\n const tsType = checker.getTypeAtLocation(prop);\n const optional = prop.questionToken !== undefined;\n const provenance = provenanceForNode(prop, file);\n\n // Resolve ts.Type → TypeNode\n const type = resolveTypeNode(tsType, checker, file, typeRegistry, visiting);\n\n // Collect constraints\n const constraints: ConstraintNode[] = [];\n\n // Inherit constraints from type alias declarations (lower precedence)\n if (prop.type) {\n constraints.push(...extractTypeAliasConstraintNodes(prop.type, checker, file));\n }\n\n // Extract JSDoc constraints\n constraints.push(...extractJSDocConstraintNodes(prop, file));\n\n // Collect annotations\n const annotations: AnnotationNode[] = [];\n\n // JSDoc annotations (@Field_displayName, @Field_description, @deprecated)\n annotations.push(...extractJSDocAnnotationNodes(prop, file));\n\n // Default value annotation\n const defaultAnnotation = extractDefaultValueAnnotation(prop.initializer, file);\n if (defaultAnnotation) {\n annotations.push(defaultAnnotation);\n }\n\n return {\n kind: \"field\",\n name,\n type,\n required: !optional,\n constraints,\n annotations,\n provenance,\n };\n}\n\n/**\n * Analyzes an interface/type-alias property signature into a canonical IR FieldNode.\n */\nfunction analyzeInterfacePropertyToIR(\n prop: ts.PropertySignature,\n checker: ts.TypeChecker,\n file: string,\n typeRegistry: Record<string, TypeDefinition>,\n visiting: Set<ts.Type>\n): FieldNode | null {\n if (!ts.isIdentifier(prop.name)) {\n return null;\n }\n\n const name = prop.name.text;\n const tsType = checker.getTypeAtLocation(prop);\n const optional = prop.questionToken !== undefined;\n const provenance = provenanceForNode(prop, file);\n\n // Resolve ts.Type → TypeNode\n const type = resolveTypeNode(tsType, checker, file, typeRegistry, visiting);\n\n // Collect constraints\n const constraints: ConstraintNode[] = [];\n\n // Inherit constraints from type alias declarations\n if (prop.type) {\n constraints.push(...extractTypeAliasConstraintNodes(prop.type, checker, file));\n }\n\n // JSDoc constraints\n constraints.push(...extractJSDocConstraintNodes(prop, file));\n\n // Collect annotations\n const annotations: AnnotationNode[] = [];\n\n // JSDoc annotations (@Field_displayName, @Field_description, @deprecated)\n annotations.push(...extractJSDocAnnotationNodes(prop, file));\n\n return {\n kind: \"field\",\n name,\n type,\n required: !optional,\n constraints,\n annotations,\n provenance,\n };\n}\n\n// =============================================================================\n// TYPE RESOLUTION — ts.Type → TypeNode\n// =============================================================================\n\n/**\n * Resolves a TypeScript type to a canonical IR TypeNode.\n */\nexport function resolveTypeNode(\n type: ts.Type,\n checker: ts.TypeChecker,\n file: string,\n typeRegistry: Record<string, TypeDefinition>,\n visiting: Set<ts.Type>\n): TypeNode {\n // --- Primitives ---\n if (type.flags & ts.TypeFlags.String) {\n return { kind: \"primitive\", primitiveKind: \"string\" };\n }\n if (type.flags & ts.TypeFlags.Number) {\n return { kind: \"primitive\", primitiveKind: \"number\" };\n }\n if (type.flags & ts.TypeFlags.Boolean) {\n return { kind: \"primitive\", primitiveKind: \"boolean\" };\n }\n if (type.flags & ts.TypeFlags.Null) {\n return { kind: \"primitive\", primitiveKind: \"null\" };\n }\n if (type.flags & ts.TypeFlags.Undefined) {\n // Undefined maps to null for nullable semantics in JSON Schema\n return { kind: \"primitive\", primitiveKind: \"null\" };\n }\n\n // --- String literal ---\n if (type.isStringLiteral()) {\n return {\n kind: \"enum\",\n members: [{ value: type.value }],\n };\n }\n\n // --- Number literal ---\n if (type.isNumberLiteral()) {\n return {\n kind: \"enum\",\n members: [{ value: type.value }],\n };\n }\n\n // --- Union types ---\n if (type.isUnion()) {\n return resolveUnionType(type, checker, file, typeRegistry, visiting);\n }\n\n // --- Array types ---\n if (checker.isArrayType(type)) {\n return resolveArrayType(type, checker, file, typeRegistry, visiting);\n }\n\n // --- Object types ---\n if (isObjectType(type)) {\n return resolveObjectType(type, checker, file, typeRegistry, visiting);\n }\n\n // --- Fallback: treat unknown/any/void as string ---\n return { kind: \"primitive\", primitiveKind: \"string\" };\n}\n\nfunction resolveUnionType(\n type: ts.UnionType,\n checker: ts.TypeChecker,\n file: string,\n typeRegistry: Record<string, TypeDefinition>,\n visiting: Set<ts.Type>\n): TypeNode {\n const allTypes = type.types;\n\n const nonNullTypes = allTypes.filter(\n (t) => !(t.flags & (ts.TypeFlags.Null | ts.TypeFlags.Undefined))\n );\n const hasNull = allTypes.some((t) => t.flags & ts.TypeFlags.Null);\n\n // Boolean union: true | false → boolean primitive\n const isBooleanUnion =\n nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags & ts.TypeFlags.BooleanLiteral);\n\n if (isBooleanUnion) {\n const boolNode: TypeNode = { kind: \"primitive\", primitiveKind: \"boolean\" };\n if (hasNull) {\n return {\n kind: \"union\",\n members: [boolNode, { kind: \"primitive\", primitiveKind: \"null\" }],\n };\n }\n return boolNode;\n }\n\n // All string literals → EnumTypeNode\n const allStringLiterals = nonNullTypes.every((t) => t.isStringLiteral());\n if (allStringLiterals && nonNullTypes.length > 0) {\n const stringTypes = nonNullTypes.filter((t): t is ts.StringLiteralType => t.isStringLiteral());\n const enumNode: TypeNode = {\n kind: \"enum\",\n members: stringTypes.map((t) => ({ value: t.value })),\n };\n if (hasNull) {\n return {\n kind: \"union\",\n members: [enumNode, { kind: \"primitive\", primitiveKind: \"null\" }],\n };\n }\n return enumNode;\n }\n\n // All number literals → EnumTypeNode\n const allNumberLiterals = nonNullTypes.every((t) => t.isNumberLiteral());\n if (allNumberLiterals && nonNullTypes.length > 0) {\n const numberTypes = nonNullTypes.filter((t): t is ts.NumberLiteralType => t.isNumberLiteral());\n const enumNode: TypeNode = {\n kind: \"enum\",\n members: numberTypes.map((t) => ({ value: t.value })),\n };\n if (hasNull) {\n return {\n kind: \"union\",\n members: [enumNode, { kind: \"primitive\", primitiveKind: \"null\" }],\n };\n }\n return enumNode;\n }\n\n // Nullable wrapper: T | null with single non-null type\n if (nonNullTypes.length === 1 && nonNullTypes[0]) {\n const inner = resolveTypeNode(nonNullTypes[0], checker, file, typeRegistry, visiting);\n if (hasNull) {\n return {\n kind: \"union\",\n members: [inner, { kind: \"primitive\", primitiveKind: \"null\" }],\n };\n }\n return inner;\n }\n\n // General union\n const members = nonNullTypes.map((t) =>\n resolveTypeNode(t, checker, file, typeRegistry, visiting)\n );\n if (hasNull) {\n members.push({ kind: \"primitive\", primitiveKind: \"null\" });\n }\n return { kind: \"union\", members };\n}\n\nfunction resolveArrayType(\n type: ts.Type,\n checker: ts.TypeChecker,\n file: string,\n typeRegistry: Record<string, TypeDefinition>,\n visiting: Set<ts.Type>\n): TypeNode {\n const typeArgs = isTypeReference(type) ? type.typeArguments : undefined;\n const elementType = typeArgs?.[0];\n\n const items = elementType\n ? resolveTypeNode(elementType, checker, file, typeRegistry, visiting)\n : ({ kind: \"primitive\", primitiveKind: \"string\" } satisfies TypeNode);\n\n return { kind: \"array\", items };\n}\n\nfunction resolveObjectType(\n type: ts.ObjectType,\n checker: ts.TypeChecker,\n file: string,\n typeRegistry: Record<string, TypeDefinition>,\n visiting: Set<ts.Type>\n): TypeNode {\n // Circular reference guard\n if (visiting.has(type)) {\n return { kind: \"object\", properties: [], additionalProperties: false };\n }\n visiting.add(type);\n\n // Check if this is a named type already in the registry\n const typeName = getNamedTypeName(type);\n if (typeName && typeName in typeRegistry) {\n visiting.delete(type);\n return { kind: \"reference\", name: typeName, typeArguments: [] };\n }\n\n const properties: ObjectProperty[] = [];\n\n // Get FieldInfo-level analysis from named type declarations for constraint propagation\n const fieldInfoMap = getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visiting);\n\n for (const prop of type.getProperties()) {\n const declaration = prop.valueDeclaration ?? prop.declarations?.[0];\n if (!declaration) continue;\n\n const propType = checker.getTypeOfSymbolAtLocation(prop, declaration);\n const optional = !!(prop.flags & ts.SymbolFlags.Optional);\n const propTypeNode = resolveTypeNode(propType, checker, file, typeRegistry, visiting);\n\n // Get constraints and annotations from the declaration if available\n const fieldNodeInfo = fieldInfoMap?.get(prop.name);\n\n properties.push({\n name: prop.name,\n type: propTypeNode,\n optional,\n constraints: fieldNodeInfo?.constraints ?? [],\n annotations: fieldNodeInfo?.annotations ?? [],\n provenance: fieldNodeInfo?.provenance ?? provenanceForFile(file),\n });\n }\n\n visiting.delete(type);\n\n const objectNode: TypeNode = {\n kind: \"object\",\n properties,\n additionalProperties: false,\n };\n\n // Register named types\n if (typeName) {\n typeRegistry[typeName] = {\n name: typeName,\n type: objectNode,\n provenance: provenanceForFile(file),\n };\n return { kind: \"reference\", name: typeName, typeArguments: [] };\n }\n\n return objectNode;\n}\n\n// =============================================================================\n// NAMED TYPE FIELD INFO MAP — for nested constraint propagation\n// =============================================================================\n\ninterface FieldNodeInfo {\n readonly constraints: readonly ConstraintNode[];\n readonly annotations: readonly AnnotationNode[];\n readonly provenance: Provenance;\n}\n\n/**\n * Builds a map from property name to constraint/annotation info for named types.\n * This enables propagating TSDoc constraints from nested type declarations.\n */\nfunction getNamedTypeFieldNodeInfoMap(\n type: ts.Type,\n checker: ts.TypeChecker,\n file: string,\n typeRegistry: Record<string, TypeDefinition>,\n visiting: Set<ts.Type>\n): Map<string, FieldNodeInfo> | null {\n const symbols = [type.getSymbol(), type.aliasSymbol].filter(\n (s): s is ts.Symbol => s?.declarations != null && s.declarations.length > 0\n );\n\n for (const symbol of symbols) {\n const declarations = symbol.declarations;\n if (!declarations) continue;\n\n // Try class declaration\n const classDecl = declarations.find(ts.isClassDeclaration);\n if (classDecl) {\n const map = new Map<string, FieldNodeInfo>();\n for (const member of classDecl.members) {\n if (ts.isPropertyDeclaration(member) && ts.isIdentifier(member.name)) {\n const fieldNode = analyzeFieldToIR(member, checker, file, typeRegistry, visiting);\n if (fieldNode) {\n map.set(fieldNode.name, {\n constraints: [...fieldNode.constraints],\n annotations: [...fieldNode.annotations],\n provenance: fieldNode.provenance,\n });\n }\n }\n }\n return map;\n }\n\n // Try interface declaration\n const interfaceDecl = declarations.find(ts.isInterfaceDeclaration);\n if (interfaceDecl) {\n return buildFieldNodeInfoMap(interfaceDecl.members, checker, file, typeRegistry, visiting);\n }\n\n // Try type alias with type literal body\n const typeAliasDecl = declarations.find(ts.isTypeAliasDeclaration);\n if (typeAliasDecl && ts.isTypeLiteralNode(typeAliasDecl.type)) {\n return buildFieldNodeInfoMap(\n typeAliasDecl.type.members,\n checker,\n file,\n typeRegistry,\n visiting\n );\n }\n }\n\n return null;\n}\n\nfunction buildFieldNodeInfoMap(\n members: ts.NodeArray<ts.TypeElement>,\n checker: ts.TypeChecker,\n file: string,\n typeRegistry: Record<string, TypeDefinition>,\n visiting: Set<ts.Type>\n): Map<string, FieldNodeInfo> {\n const map = new Map<string, FieldNodeInfo>();\n for (const member of members) {\n if (ts.isPropertySignature(member)) {\n const fieldNode = analyzeInterfacePropertyToIR(member, checker, file, typeRegistry, visiting);\n if (fieldNode) {\n map.set(fieldNode.name, {\n constraints: [...fieldNode.constraints],\n annotations: [...fieldNode.annotations],\n provenance: fieldNode.provenance,\n });\n }\n }\n }\n return map;\n}\n\n// =============================================================================\n// TYPE ALIAS CONSTRAINT PROPAGATION\n// =============================================================================\n\n/**\n * Given a type node referencing a type alias, extracts IR ConstraintNodes\n * from the alias declaration's JSDoc tags.\n */\nfunction extractTypeAliasConstraintNodes(\n typeNode: ts.TypeNode,\n checker: ts.TypeChecker,\n file: string\n): ConstraintNode[] {\n if (!ts.isTypeReferenceNode(typeNode)) return [];\n\n const symbol = checker.getSymbolAtLocation(typeNode.typeName);\n if (!symbol?.declarations) return [];\n\n const aliasDecl = symbol.declarations.find(ts.isTypeAliasDeclaration);\n if (!aliasDecl) return [];\n\n // Don't extract from object type aliases\n if (ts.isTypeLiteralNode(aliasDecl.type)) return [];\n\n return extractJSDocConstraintNodes(aliasDecl, file);\n}\n\n// =============================================================================\n// PROVENANCE HELPERS\n// =============================================================================\n\nfunction provenanceForNode(node: ts.Node, file: string): Provenance {\n const sourceFile = node.getSourceFile();\n const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n return {\n surface: \"tsdoc\",\n file,\n line: line + 1,\n column: character,\n };\n}\n\nfunction provenanceForFile(file: string): Provenance {\n return { surface: \"tsdoc\", file, line: 0, column: 0 };\n}\n\n// =============================================================================\n// NAMED TYPE HELPERS\n// =============================================================================\n\n/**\n * Extracts a stable type name from a ts.ObjectType when it originates from\n * a named declaration (class, interface, or type alias).\n */\nfunction getNamedTypeName(type: ts.ObjectType): string | null {\n const symbol = type.getSymbol();\n if (symbol?.declarations) {\n const decl = symbol.declarations[0];\n if (\n decl &&\n (ts.isClassDeclaration(decl) ||\n ts.isInterfaceDeclaration(decl) ||\n ts.isTypeAliasDeclaration(decl))\n ) {\n const name = ts.isClassDeclaration(decl) ? decl.name?.text : decl.name.text;\n if (name) return name;\n }\n }\n\n const aliasSymbol = type.aliasSymbol;\n if (aliasSymbol?.declarations) {\n const aliasDecl = aliasSymbol.declarations.find(ts.isTypeAliasDeclaration);\n if (aliasDecl) {\n return aliasDecl.name.text;\n }\n }\n\n return null;\n}\n\n// =============================================================================\n// SHARED OUTPUT TYPES\n// =============================================================================\n\n/**\n * Analyzed method information.\n */\nexport interface MethodInfo {\n /** Method name */\n name: string;\n /** Method parameters */\n parameters: ParameterInfo[];\n /** Return type node */\n returnTypeNode: ts.TypeNode | undefined;\n /** Resolved return type */\n returnType: ts.Type;\n}\n\n/**\n * Analyzed parameter information.\n */\nexport interface ParameterInfo {\n /** Parameter name */\n name: string;\n /** TypeScript type node */\n typeNode: ts.TypeNode | undefined;\n /** Resolved type */\n type: ts.Type;\n /** If this is InferSchema<typeof X>, the export name X */\n formSpecExportName: string | null;\n /** Whether the parameter is optional (has ? or default value) */\n optional: boolean;\n}\n\n// =============================================================================\n// SHARED HELPERS\n// =============================================================================\n\n/**\n * Analyzes a method declaration to extract method info.\n * Shared between IR and legacy paths.\n */\nfunction analyzeMethod(method: ts.MethodDeclaration, checker: ts.TypeChecker): MethodInfo | null {\n if (!ts.isIdentifier(method.name)) {\n return null;\n }\n\n const name = method.name.text;\n const parameters: ParameterInfo[] = [];\n\n for (const param of method.parameters) {\n if (ts.isIdentifier(param.name)) {\n const paramInfo = analyzeParameter(param, checker);\n parameters.push(paramInfo);\n }\n }\n\n const returnTypeNode = method.type;\n const signature = checker.getSignatureFromDeclaration(method);\n const returnType = signature\n ? checker.getReturnTypeOfSignature(signature)\n : checker.getTypeAtLocation(method);\n\n return { name, parameters, returnTypeNode, returnType };\n}\n\nfunction analyzeParameter(param: ts.ParameterDeclaration, checker: ts.TypeChecker): ParameterInfo {\n const name = ts.isIdentifier(param.name) ? param.name.text : \"param\";\n const typeNode = param.type;\n const type = checker.getTypeAtLocation(param);\n const formSpecExportName = detectFormSpecReference(typeNode);\n const optional = param.questionToken !== undefined || param.initializer !== undefined;\n\n return { name, typeNode, type, formSpecExportName, optional };\n}\n\nfunction detectFormSpecReference(typeNode: ts.TypeNode | undefined): string | null {\n if (!typeNode) return null;\n\n if (!ts.isTypeReferenceNode(typeNode)) return null;\n\n const typeName = ts.isIdentifier(typeNode.typeName)\n ? typeNode.typeName.text\n : ts.isQualifiedName(typeNode.typeName)\n ? typeNode.typeName.right.text\n : null;\n\n if (typeName !== \"InferSchema\" && typeName !== \"InferFormSchema\") return null;\n\n const typeArg = typeNode.typeArguments?.[0];\n if (!typeArg || !ts.isTypeQueryNode(typeArg)) return null;\n\n if (ts.isIdentifier(typeArg.exprName)) {\n return typeArg.exprName.text;\n }\n\n if (ts.isQualifiedName(typeArg.exprName)) {\n return typeArg.exprName.right.text;\n }\n\n return null;\n}\n","/**\n * JSDoc constraint and annotation extractor.\n *\n * Extracts constraints and annotation tags from JSDoc comments on\n * class/interface fields and returns canonical IR nodes directly:\n * - {@link ConstraintNode} for set-influencing tags (@Minimum, @Pattern, etc.)\n * - {@link AnnotationNode} for value-influencing tags (@Field_displayName, etc.)\n *\n * The IR extraction path uses the official `@microsoft/tsdoc` parser for\n * constraints (all TSDoc-compliant alphanumeric names) and the TypeScript\n * compiler JSDoc API for annotation tags (which contain underscores, e.g.\n * `@Field_displayName`).\n *\n * Supported constraints correspond to keys in {@link BUILTIN_CONSTRAINT_DEFINITIONS}\n * from `@formspec/core` (e.g., `@Minimum`, `@Maximum`, `@Pattern`).\n */\n\nimport * as ts from \"typescript\";\nimport {\n BUILTIN_CONSTRAINT_DEFINITIONS,\n type BuiltinConstraintName,\n type ConstraintNode,\n type AnnotationNode,\n type JsonValue,\n} from \"@formspec/core\";\nimport { parseTSDocTags, hasDeprecatedTagTSDoc } from \"./tsdoc-parser.js\";\n\n// =============================================================================\n// Legacy types — previously in decorator-extractor.ts, now owned here\n// =============================================================================\n\n/**\n * A constraint argument value.\n */\nexport type ConstraintArg =\n | string\n | number\n | boolean\n | null\n | ConstraintArg[]\n | { [key: string]: ConstraintArg };\n\n/**\n * Extracted constraint information from a JSDoc tag.\n * @deprecated Use {@link ConstraintNode} from the IR path instead.\n */\nexport interface ConstraintInfo {\n /** Constraint name (e.g., \"Minimum\", \"Pattern\", \"Field\") */\n name: string;\n /** Constraint arguments as literal values */\n args: ConstraintArg[];\n /** Raw AST node (undefined for synthetic JSDoc constraint entries) */\n node: ts.Decorator | undefined;\n}\n\n// =============================================================================\n// IR API — uses @microsoft/tsdoc for structured parsing\n// =============================================================================\n\n/**\n * Extracts constraints from JSDoc comments on a TypeScript AST node and returns\n * canonical {@link ConstraintNode} objects.\n *\n * Uses the official `@microsoft/tsdoc` parser for structured tag extraction.\n * Constraints are registered as custom block tags in the TSDoc configuration.\n *\n * @param node - The AST node to inspect for JSDoc tags\n * @param file - Absolute path to the source file for provenance\n * @returns Canonical constraint nodes for each valid constraint tag\n */\nexport function extractJSDocConstraintNodes(node: ts.Node, file = \"\"): ConstraintNode[] {\n const result = parseTSDocTags(node, file);\n return [...result.constraints];\n}\n\n/**\n * Extracts `@Field_displayName`, `@Field_description`, and `@deprecated`\n * TSDoc tags from a node and returns canonical {@link AnnotationNode} objects.\n *\n * Uses a hybrid approach:\n * - `@deprecated` is extracted via the TSDoc parser (standard tag).\n * - `@Field_displayName` and `@Field_description` are extracted via the\n * TypeScript compiler JSDoc API because they contain underscores which\n * are invalid in TSDoc tag names.\n *\n * @param node - The AST node to inspect for annotation tags\n * @param file - Absolute path to the source file for provenance\n * @returns Canonical annotation nodes\n */\nexport function extractJSDocAnnotationNodes(node: ts.Node, file = \"\"): AnnotationNode[] {\n const result = parseTSDocTags(node, file);\n return [...result.annotations];\n}\n\n/**\n * Checks if a node has a TSDoc `@deprecated` tag.\n *\n * Uses the TSDoc parser for structured detection.\n */\nexport function hasDeprecatedTag(node: ts.Node): boolean {\n return hasDeprecatedTagTSDoc(node);\n}\n\n/**\n * Extracts a default value from a property initializer and returns a\n * {@link DefaultValueAnnotationNode} if present.\n *\n * Only extracts literal values (strings, numbers, booleans, null).\n */\nexport function extractDefaultValueAnnotation(\n initializer: ts.Expression | undefined,\n file = \"\"\n): AnnotationNode | null {\n if (!initializer) return null;\n\n let value: JsonValue | undefined;\n\n if (ts.isStringLiteral(initializer)) {\n value = initializer.text;\n } else if (ts.isNumericLiteral(initializer)) {\n value = Number(initializer.text);\n } else if (initializer.kind === ts.SyntaxKind.TrueKeyword) {\n value = true;\n } else if (initializer.kind === ts.SyntaxKind.FalseKeyword) {\n value = false;\n } else if (initializer.kind === ts.SyntaxKind.NullKeyword) {\n value = null;\n } else if (ts.isPrefixUnaryExpression(initializer)) {\n if (\n initializer.operator === ts.SyntaxKind.MinusToken &&\n ts.isNumericLiteral(initializer.operand)\n ) {\n value = -Number(initializer.operand.text);\n }\n }\n\n if (value === undefined) return null;\n\n const sourceFile = initializer.getSourceFile();\n const { line, character } = sourceFile.getLineAndCharacterOfPosition(initializer.getStart());\n\n return {\n kind: \"annotation\",\n annotationKind: \"defaultValue\",\n value,\n provenance: {\n surface: \"tsdoc\",\n file,\n line: line + 1,\n column: character,\n },\n };\n}\n\n// =============================================================================\n// LEGACY API — backward compatibility for decorator-based pipeline\n// =============================================================================\n\n/**\n * Extracts JSDoc constraint tags and returns synthetic {@link ConstraintInfo}\n * objects for backward compatibility with the decorator-based pipeline.\n *\n * Uses the TypeScript compiler JSDoc API (not TSDoc parser) to maintain\n * identical behavior with the legacy pipeline.\n *\n * @deprecated Use {@link extractJSDocConstraintNodes} for IR output.\n */\nexport function extractJSDocConstraints(node: ts.Node): ConstraintInfo[] {\n const results: ConstraintInfo[] = [];\n const jsDocTags = ts.getJSDocTags(node);\n\n for (const tag of jsDocTags) {\n const tagName = tag.tagName.text;\n\n if (!(tagName in BUILTIN_CONSTRAINT_DEFINITIONS)) {\n continue;\n }\n\n const constraintName = tagName as BuiltinConstraintName;\n const expectedType = BUILTIN_CONSTRAINT_DEFINITIONS[constraintName];\n\n const commentText = getTagCommentText(tag);\n if (commentText === undefined || commentText === \"\") {\n continue;\n }\n\n const trimmed = commentText.trim();\n if (trimmed === \"\") {\n continue;\n }\n\n if (expectedType === \"number\") {\n const value = Number(trimmed);\n if (Number.isNaN(value)) {\n continue;\n }\n results.push(createSyntheticDecorator(constraintName, value));\n } else if (expectedType === \"json\") {\n try {\n const parsed: unknown = JSON.parse(trimmed);\n if (!Array.isArray(parsed)) {\n continue;\n }\n results.push(createSyntheticDecorator(constraintName, parsed as ConstraintArg));\n } catch {\n continue;\n }\n } else {\n results.push(createSyntheticDecorator(constraintName, trimmed));\n }\n }\n\n return results;\n}\n\n/**\n * Extracts `@Field_displayName` and `@Field_description` TSDoc tags\n * and returns a synthetic `Field` {@link ConstraintInfo} for backward\n * compatibility with the decorator-based pipeline.\n *\n * @deprecated Use {@link extractJSDocAnnotationNodes} for IR output.\n */\nexport function extractJSDocFieldMetadata(node: ts.Node): ConstraintInfo | null {\n const jsDocTags = ts.getJSDocTags(node);\n\n let displayName: string | undefined;\n let description: string | undefined;\n\n for (const tag of jsDocTags) {\n const tagName = tag.tagName.text;\n const commentText = getTagCommentText(tag);\n if (commentText === undefined || commentText.trim() === \"\") {\n continue;\n }\n\n const trimmed = commentText.trim();\n\n if (tagName === \"Field_displayName\") {\n displayName = trimmed;\n } else if (tagName === \"Field_description\") {\n description = trimmed;\n }\n }\n\n if (displayName === undefined && description === undefined) {\n return null;\n }\n\n const fieldOpts: Record<string, ConstraintArg> = {\n ...(displayName !== undefined ? { displayName } : {}),\n ...(description !== undefined ? { description } : {}),\n };\n\n return createSyntheticDecorator(\"Field\", fieldOpts);\n}\n\n// =============================================================================\n// PRIVATE HELPERS\n// =============================================================================\n\n/**\n * Extracts the text content from a JSDoc tag's comment.\n *\n * The `tag.comment` property can be a plain string, an array of\n * `JSDocComment` nodes, or undefined. This helper normalises all\n * three cases to a single `string | undefined`.\n */\nfunction getTagCommentText(tag: ts.JSDocTag): string | undefined {\n if (tag.comment === undefined) {\n return undefined;\n }\n if (typeof tag.comment === \"string\") {\n return tag.comment;\n }\n // NodeArray<JSDocComment> — concatenate text spans\n return ts.getTextOfJSDocComment(tag.comment);\n}\n\n/**\n * Creates a synthetic {@link ConstraintInfo} for backward compatibility.\n */\nfunction createSyntheticDecorator(name: string, value: ConstraintArg): ConstraintInfo {\n return {\n name,\n args: [value],\n node: undefined,\n };\n}\n","/**\n * TSDoc-based structured tag parser.\n *\n * Bridges the TypeScript compiler AST with the official `@microsoft/tsdoc`\n * parser to extract constraint and annotation tags from JSDoc comments\n * on class/interface/type-alias properties.\n *\n * The parser recognises two categories of tags:\n *\n * 1. **Constraint tags** (all alphanumeric, TSDoc-compliant):\n * `@Minimum`, `@Maximum`, `@ExclusiveMinimum`, `@ExclusiveMaximum`,\n * `@MinLength`, `@MaxLength`, `@Pattern`, `@EnumOptions`\n * — Parsed via TSDocParser as custom block tags.\n *\n * 2. **Annotation tags** (`@Field_displayName`, `@Field_description`):\n * These contain underscores which are not valid in TSDoc tag names.\n * They are extracted via the TypeScript compiler's `ts.getJSDocTags()`\n * until a future migration to underscore-free tag names.\n *\n * The `@deprecated` tag is a standard TSDoc block tag, parsed structurally.\n *\n * **Fallback strategy**: TSDoc treats `{` / `}` as inline tag delimiters and\n * `@` as a tag prefix, so content containing these characters (e.g. JSON\n * objects in `@EnumOptions`, regex patterns with `@` in `@Pattern`) gets\n * mangled by the TSDoc parser. For these tags, the raw text is extracted\n * via the TS compiler's `ts.getJSDocTags()` API which preserves content\n * verbatim.\n */\n\nimport * as ts from \"typescript\";\nimport {\n TSDocParser,\n TSDocConfiguration,\n TSDocTagDefinition,\n TSDocTagSyntaxKind,\n DocPlainText,\n DocSoftBreak,\n TextRange,\n type DocNode,\n type DocBlock,\n} from \"@microsoft/tsdoc\";\nimport {\n BUILTIN_CONSTRAINT_DEFINITIONS,\n type BuiltinConstraintName,\n type ConstraintNode,\n type AnnotationNode,\n type Provenance,\n type NumericConstraintNode,\n type LengthConstraintNode,\n} from \"@formspec/core\";\n\n// =============================================================================\n// CONFIGURATION\n// =============================================================================\n\n/**\n * Constraint tag name → constraint kind mapping for numeric constraints.\n */\nconst NUMERIC_CONSTRAINT_MAP: Record<string, NumericConstraintNode[\"constraintKind\"]> = {\n Minimum: \"minimum\",\n Maximum: \"maximum\",\n ExclusiveMinimum: \"exclusiveMinimum\",\n ExclusiveMaximum: \"exclusiveMaximum\",\n};\n\n/**\n * Constraint tag name → constraint kind mapping for length constraints.\n */\nconst LENGTH_CONSTRAINT_MAP: Record<string, LengthConstraintNode[\"constraintKind\"]> = {\n MinLength: \"minLength\",\n MaxLength: \"maxLength\",\n};\n\n/**\n * Tags whose content may contain TSDoc-significant characters (`{}`, `@`)\n * and must be extracted via the TS compiler JSDoc API rather than the\n * TSDoc DocNode tree to avoid content mangling.\n *\n * - `@Pattern`: regex patterns commonly contain `@` (e.g. email validation)\n * - `@EnumOptions`: JSON arrays may contain object literals with `{}`\n */\nconst TAGS_REQUIRING_RAW_TEXT = new Set([\"Pattern\", \"EnumOptions\"]);\n\n/**\n * Type guard that checks whether a tag name is a known BuiltinConstraintName.\n */\nfunction isBuiltinConstraintName(tagName: string): tagName is BuiltinConstraintName {\n return tagName in BUILTIN_CONSTRAINT_DEFINITIONS;\n}\n\n/**\n * Creates a TSDocConfiguration with FormSpec custom block tag definitions\n * registered for all constraint tags.\n */\nfunction createFormSpecTSDocConfig(): TSDocConfiguration {\n const config = new TSDocConfiguration();\n\n // Register each constraint tag as a custom block tag (allowMultiple so\n // repeated tags don't produce warnings).\n for (const tagName of Object.keys(BUILTIN_CONSTRAINT_DEFINITIONS)) {\n config.addTagDefinition(\n new TSDocTagDefinition({\n tagName: \"@\" + tagName,\n syntaxKind: TSDocTagSyntaxKind.BlockTag,\n allowMultiple: true,\n })\n );\n }\n\n return config;\n}\n\n/**\n * Shared parser instance — thread-safe because TSDocParser is stateless;\n * all parse state lives in the returned ParserContext.\n */\nlet sharedParser: TSDocParser | undefined;\n\nfunction getParser(): TSDocParser {\n sharedParser ??= new TSDocParser(createFormSpecTSDocConfig());\n return sharedParser;\n}\n\n// =============================================================================\n// PUBLIC API\n// =============================================================================\n\n/**\n * Result of parsing a single JSDoc comment attached to a TS AST node.\n */\nexport interface TSDocParseResult {\n /** Constraint IR nodes extracted from custom block tags. */\n readonly constraints: readonly ConstraintNode[];\n /** Annotation IR nodes extracted from modifier/block tags and TS JSDoc API. */\n readonly annotations: readonly AnnotationNode[];\n}\n\n/**\n * Parses the JSDoc comment attached to a TypeScript AST node using the\n * official TSDoc parser and returns canonical IR constraint and annotation\n * nodes.\n *\n * For constraint tags (`@Minimum`, `@Pattern`, `@EnumOptions`, etc.),\n * the structured TSDoc parser is used. For annotation tags that contain\n * underscores (`@Field_displayName`, `@Field_description`), the TypeScript\n * compiler JSDoc API is used as a fallback.\n *\n * @param node - The TS AST node to inspect (PropertyDeclaration, PropertySignature, etc.)\n * @param file - Absolute source file path for provenance\n * @returns Parsed constraint and annotation nodes\n */\nexport function parseTSDocTags(node: ts.Node, file = \"\"): TSDocParseResult {\n const constraints: ConstraintNode[] = [];\n const annotations: AnnotationNode[] = [];\n\n // ----- Phase 1: TSDoc structural parse for constraint tags -----\n const sourceFile = node.getSourceFile();\n const sourceText = sourceFile.getFullText();\n const commentRanges = ts.getLeadingCommentRanges(sourceText, node.getFullStart());\n\n if (commentRanges) {\n for (const range of commentRanges) {\n // Only parse /** ... */ comments (kind 3 = MultiLineCommentTrivia)\n if (range.kind !== ts.SyntaxKind.MultiLineCommentTrivia) {\n continue;\n }\n const commentText = sourceText.substring(range.pos, range.end);\n if (!commentText.startsWith(\"/**\")) {\n continue;\n }\n\n const parser = getParser();\n const parserContext = parser.parseRange(\n TextRange.fromStringRange(sourceText, range.pos, range.end)\n );\n const docComment = parserContext.docComment;\n\n // Extract constraint nodes from custom blocks.\n // Tags in TAGS_REQUIRING_RAW_TEXT are skipped here and handled via the\n // TS compiler API in Phase 1b below.\n for (const block of docComment.customBlocks) {\n const tagName = block.blockTag.tagName.substring(1); // Remove leading @\n if (TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;\n\n const text = extractBlockText(block).trim();\n if (text === \"\") continue;\n\n const provenance = provenanceForComment(range, sourceFile, file, tagName);\n const constraintNode = parseConstraintValue(tagName, text, provenance);\n if (constraintNode) {\n constraints.push(constraintNode);\n }\n }\n\n // Extract @deprecated from the standard deprecated block\n if (docComment.deprecatedBlock !== undefined) {\n annotations.push({\n kind: \"annotation\",\n annotationKind: \"deprecated\",\n provenance: provenanceForComment(range, sourceFile, file, \"deprecated\"),\n });\n }\n }\n }\n\n // ----- Phase 1b: TS compiler API for tags with TSDoc-incompatible content -----\n // @Pattern and @EnumOptions content can contain `@` and `{}` characters\n // which the TSDoc parser treats as structural markers. We extract these\n // via the TS compiler API which preserves content verbatim.\n const jsDocTagsAll = ts.getJSDocTags(node);\n for (const tag of jsDocTagsAll) {\n const tagName = tag.tagName.text;\n if (!TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;\n\n const commentText = getTagCommentText(tag);\n if (commentText === undefined || commentText.trim() === \"\") continue;\n\n const text = commentText.trim();\n const provenance = provenanceForJSDocTag(tag, file);\n const constraintNode = parseConstraintValue(tagName, text, provenance);\n if (constraintNode) {\n constraints.push(constraintNode);\n }\n }\n\n // ----- Phase 2: TS compiler JSDoc API for underscore-containing annotation tags -----\n // @Field_displayName and @Field_description contain underscores which\n // are invalid in TSDoc tag names. We extract them via the TS compiler API.\n let displayName: string | undefined;\n let description: string | undefined;\n let displayNameTag: ts.JSDocTag | undefined;\n let descriptionTag: ts.JSDocTag | undefined;\n\n for (const tag of jsDocTagsAll) {\n const tagName = tag.tagName.text;\n const commentText = getTagCommentText(tag);\n if (commentText === undefined || commentText.trim() === \"\") {\n continue;\n }\n\n const trimmed = commentText.trim();\n\n if (tagName === \"Field_displayName\") {\n displayName = trimmed;\n displayNameTag = tag;\n } else if (tagName === \"Field_description\") {\n description = trimmed;\n descriptionTag = tag;\n }\n }\n\n if (displayName !== undefined && displayNameTag) {\n annotations.push({\n kind: \"annotation\",\n annotationKind: \"displayName\",\n value: displayName,\n provenance: provenanceForJSDocTag(displayNameTag, file),\n });\n }\n\n if (description !== undefined && descriptionTag) {\n annotations.push({\n kind: \"annotation\",\n annotationKind: \"description\",\n value: description,\n provenance: provenanceForJSDocTag(descriptionTag, file),\n });\n }\n\n return { constraints, annotations };\n}\n\n/**\n * Checks if a TS AST node has a `@deprecated` tag using the TSDoc parser.\n *\n * Falls back to the TS compiler API for nodes without doc comments.\n */\nexport function hasDeprecatedTagTSDoc(node: ts.Node): boolean {\n const sourceFile = node.getSourceFile();\n const sourceText = sourceFile.getFullText();\n const commentRanges = ts.getLeadingCommentRanges(sourceText, node.getFullStart());\n\n if (commentRanges) {\n for (const range of commentRanges) {\n if (range.kind !== ts.SyntaxKind.MultiLineCommentTrivia) continue;\n const commentText = sourceText.substring(range.pos, range.end);\n if (!commentText.startsWith(\"/**\")) continue;\n\n const parser = getParser();\n const parserContext = parser.parseRange(\n TextRange.fromStringRange(sourceText, range.pos, range.end)\n );\n if (parserContext.docComment.deprecatedBlock !== undefined) {\n return true;\n }\n }\n }\n\n return false;\n}\n\n// =============================================================================\n// PRIVATE HELPERS — TSDoc text extraction\n// =============================================================================\n\n/**\n * Recursively extracts plain text content from a TSDoc DocNode tree.\n *\n * Walks child nodes and concatenates DocPlainText and DocSoftBreak content.\n */\nfunction extractBlockText(block: DocBlock): string {\n return extractPlainText(block.content);\n}\n\nfunction extractPlainText(node: DocNode): string {\n let result = \"\";\n if (node instanceof DocPlainText) {\n return node.text;\n }\n if (node instanceof DocSoftBreak) {\n return \" \";\n }\n if (typeof node.getChildNodes === \"function\") {\n for (const child of node.getChildNodes()) {\n result += extractPlainText(child);\n }\n }\n return result;\n}\n\n// =============================================================================\n// PRIVATE HELPERS — constraint value parsing\n// =============================================================================\n\n/**\n * Parses a raw text value extracted from a TSDoc block tag into an IR\n * ConstraintNode based on the tag name and BUILTIN_CONSTRAINT_DEFINITIONS.\n */\nfunction parseConstraintValue(\n tagName: string,\n text: string,\n provenance: Provenance\n): ConstraintNode | null {\n if (!isBuiltinConstraintName(tagName)) {\n return null;\n }\n\n const expectedType = BUILTIN_CONSTRAINT_DEFINITIONS[tagName];\n\n if (expectedType === \"number\") {\n const value = Number(text);\n if (Number.isNaN(value)) {\n return null;\n }\n\n const numericKind = NUMERIC_CONSTRAINT_MAP[tagName];\n if (numericKind) {\n return {\n kind: \"constraint\",\n constraintKind: numericKind,\n value,\n provenance,\n };\n }\n\n const lengthKind = LENGTH_CONSTRAINT_MAP[tagName];\n if (lengthKind) {\n return {\n kind: \"constraint\",\n constraintKind: lengthKind,\n value,\n provenance,\n };\n }\n\n return null;\n }\n\n if (expectedType === \"json\") {\n try {\n const parsed: unknown = JSON.parse(text);\n if (!Array.isArray(parsed)) {\n return null;\n }\n const members: (string | number)[] = [];\n for (const item of parsed) {\n if (typeof item === \"string\" || typeof item === \"number\") {\n members.push(item);\n } else if (typeof item === \"object\" && item !== null && \"id\" in item) {\n const id = (item as Record<string, unknown>)[\"id\"];\n if (typeof id === \"string\" || typeof id === \"number\") {\n members.push(id);\n }\n }\n }\n return {\n kind: \"constraint\",\n constraintKind: \"allowedMembers\",\n members,\n provenance,\n };\n } catch {\n return null;\n }\n }\n\n // expectedType === \"string\" — only remaining case after number and json\n return {\n kind: \"constraint\",\n constraintKind: \"pattern\",\n pattern: text,\n provenance,\n };\n}\n\n// =============================================================================\n// PRIVATE HELPERS — provenance\n// =============================================================================\n\nfunction provenanceForComment(\n range: ts.CommentRange,\n sourceFile: ts.SourceFile,\n file: string,\n tagName: string\n): Provenance {\n const { line, character } = sourceFile.getLineAndCharacterOfPosition(range.pos);\n return {\n surface: \"tsdoc\",\n file,\n line: line + 1,\n column: character,\n tagName: \"@\" + tagName,\n };\n}\n\nfunction provenanceForJSDocTag(tag: ts.JSDocTag, file: string): Provenance {\n const sourceFile = tag.getSourceFile();\n const { line, character } = sourceFile.getLineAndCharacterOfPosition(tag.getStart());\n return {\n surface: \"tsdoc\",\n file,\n line: line + 1,\n column: character,\n tagName: \"@\" + tag.tagName.text,\n };\n}\n\n/**\n * Extracts the text content from a TypeScript JSDoc tag's comment.\n */\nfunction getTagCommentText(tag: ts.JSDocTag): string | undefined {\n if (tag.comment === undefined) {\n return undefined;\n }\n if (typeof tag.comment === \"string\") {\n return tag.comment;\n }\n return ts.getTextOfJSDocComment(tag.comment);\n}\n","/**\n * Class schema generator.\n *\n * Generates JSON Schema 2020-12 and JSON Forms UI Schema from statically\n * analyzed class/interface/type alias declarations, routing through the\n * canonical FormIR pipeline.\n */\n\nimport type { UISchema } from \"../ui-schema/types.js\";\nimport {\n createProgramContext,\n findClassByName,\n findInterfaceByName,\n findTypeAliasByName,\n} from \"../analyzer/program.js\";\nimport {\n analyzeClassToIR,\n analyzeInterfaceToIR,\n analyzeTypeAliasToIR,\n type IRClassAnalysis,\n} from \"../analyzer/class-analyzer.js\";\nimport { canonicalizeTSDoc, type TSDocSource } from \"../canonicalize/index.js\";\nimport { generateJsonSchemaFromIR, type JsonSchema2020 } from \"../json-schema/ir-generator.js\";\nimport { generateUiSchemaFromIR } from \"../ui-schema/ir-generator.js\";\n\n/**\n * Generated schemas for a class.\n */\nexport interface ClassSchemas {\n /** JSON Schema 2020-12 for validation */\n jsonSchema: JsonSchema2020;\n /** JSON Forms UI Schema for rendering */\n uiSchema: UISchema;\n}\n\n/**\n * Generates JSON Schema 2020-12 and UI Schema from an IR class analysis.\n *\n * Routes through the canonical IR pipeline:\n * IRClassAnalysis → canonicalizeTSDoc → FormIR → JSON Schema / UI Schema\n *\n * @param analysis - The IR analysis result (from analyzeClassToIR, analyzeInterfaceToIR, or analyzeTypeAliasToIR)\n * @param source - Optional source file metadata for provenance\n * @returns Generated JSON Schema and UI Schema\n */\nexport function generateClassSchemas(\n analysis: IRClassAnalysis,\n source?: TSDocSource\n): ClassSchemas {\n const ir = canonicalizeTSDoc(analysis, source);\n return {\n jsonSchema: generateJsonSchemaFromIR(ir),\n uiSchema: generateUiSchemaFromIR(ir),\n };\n}\n\n/**\n * Options for generating schemas from a decorated class.\n */\nexport interface GenerateFromClassOptions {\n /** Path to the TypeScript source file */\n filePath: string;\n /** Class name to analyze */\n className: string;\n}\n\n/**\n * Result of generating schemas from a decorated class.\n */\nexport interface GenerateFromClassResult {\n /** JSON Schema 2020-12 for validation */\n jsonSchema: JsonSchema2020;\n /** JSON Forms UI Schema for rendering */\n uiSchema: UISchema;\n}\n\n/**\n * Generates JSON Schema and UI Schema from a decorated TypeScript class.\n *\n * This is a high-level entry point that handles the entire pipeline:\n * creating a TypeScript program, finding the class, analyzing it to IR,\n * and generating schemas — all in one call.\n *\n * @example\n * ```typescript\n * const result = generateSchemasFromClass({\n * filePath: \"./src/forms.ts\",\n * className: \"UserForm\",\n * });\n * console.log(result.jsonSchema);\n * ```\n *\n * @param options - File path, class name, and optional compiler options\n * @returns Generated JSON Schema and UI Schema\n */\nexport function generateSchemasFromClass(\n options: GenerateFromClassOptions\n): GenerateFromClassResult {\n const ctx = createProgramContext(options.filePath);\n const classDecl = findClassByName(ctx.sourceFile, options.className);\n\n if (!classDecl) {\n throw new Error(`Class \"${options.className}\" not found in ${options.filePath}`);\n }\n\n const analysis = analyzeClassToIR(classDecl, ctx.checker, options.filePath);\n return generateClassSchemas(analysis, { file: options.filePath });\n}\n\n/**\n * Options for generating schemas from a named type (class, interface, or type alias).\n */\nexport interface GenerateSchemasOptions {\n /** Path to the TypeScript source file */\n filePath: string;\n /** Name of the exported class, interface, or type alias to analyze */\n typeName: string;\n}\n\n/**\n * Generates JSON Schema and UI Schema from a named TypeScript\n * type — a decorated class, an interface with TSDoc tags, or a type alias.\n *\n * This is the recommended entry point. It automatically detects whether\n * the name resolves to a class, interface, or type alias and uses the\n * appropriate IR analysis pipeline.\n *\n * @example\n * ```typescript\n * const result = generateSchemas({\n * filePath: \"./src/config.ts\",\n * typeName: \"DiscountConfig\",\n * });\n * ```\n *\n * @param options - File path and type name\n * @returns Generated JSON Schema and UI Schema\n */\nexport function generateSchemas(options: GenerateSchemasOptions): GenerateFromClassResult {\n const ctx = createProgramContext(options.filePath);\n const source: TSDocSource = { file: options.filePath };\n\n // Try class first\n const classDecl = findClassByName(ctx.sourceFile, options.typeName);\n if (classDecl) {\n const analysis = analyzeClassToIR(classDecl, ctx.checker, options.filePath);\n return generateClassSchemas(analysis, source);\n }\n\n // Try interface\n const interfaceDecl = findInterfaceByName(ctx.sourceFile, options.typeName);\n if (interfaceDecl) {\n const analysis = analyzeInterfaceToIR(interfaceDecl, ctx.checker, options.filePath);\n return generateClassSchemas(analysis, source);\n }\n\n // Try type alias\n const typeAlias = findTypeAliasByName(ctx.sourceFile, options.typeName);\n if (typeAlias) {\n const result = analyzeTypeAliasToIR(typeAlias, ctx.checker, options.filePath);\n if (result.ok) {\n return generateClassSchemas(result.analysis, source);\n }\n throw new Error(result.error);\n }\n\n throw new Error(\n `Type \"${options.typeName}\" not found as a class, interface, or type alias in ${options.filePath}`\n );\n}\n"],"mappings":";AAkDA,SAAS,kBAAkB;AAO3B,IAAM,uBAAmC;AAAA,EACvC,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,QAAQ;AACV;AAMA,SAAS,QAAQ,IAAsD;AACrE,SAAO,GAAG,UAAU;AACtB;AAEA,SAAS,cACP,IAC4D;AAC5D,SAAO,GAAG,UAAU;AACtB;AAEA,SAAS,QAAQ,IAAiC;AAChD,SAAO,GAAG,UAAU;AACtB;AAYO,SAAS,qBAAqB,MAAgD;AACnF,SAAO;AAAA,IACL,MAA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