@formspec/build 0.1.0-alpha.1 → 0.1.0-alpha.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/README.md +138 -0
  2. package/dist/__tests__/analyzer-edge-cases.test.d.ts +13 -0
  3. package/dist/__tests__/analyzer-edge-cases.test.d.ts.map +1 -0
  4. package/dist/__tests__/analyzer.test.d.ts +5 -0
  5. package/dist/__tests__/analyzer.test.d.ts.map +1 -0
  6. package/dist/__tests__/codegen.test.d.ts +5 -0
  7. package/dist/__tests__/codegen.test.d.ts.map +1 -0
  8. package/dist/__tests__/decorator-pipeline.test.d.ts +11 -0
  9. package/dist/__tests__/decorator-pipeline.test.d.ts.map +1 -0
  10. package/dist/__tests__/fixtures/edge-cases.d.ts +110 -0
  11. package/dist/__tests__/fixtures/edge-cases.d.ts.map +1 -0
  12. package/dist/__tests__/fixtures/example-a-builtins.d.ts +12 -0
  13. package/dist/__tests__/fixtures/example-a-builtins.d.ts.map +1 -0
  14. package/dist/__tests__/fixtures/example-b-decorators.d.ts +5 -0
  15. package/dist/__tests__/fixtures/example-b-decorators.d.ts.map +1 -0
  16. package/dist/__tests__/fixtures/example-b-extended.d.ts +5 -0
  17. package/dist/__tests__/fixtures/example-b-extended.d.ts.map +1 -0
  18. package/dist/__tests__/fixtures/example-c-custom.d.ts +5 -0
  19. package/dist/__tests__/fixtures/example-c-custom.d.ts.map +1 -0
  20. package/dist/__tests__/fixtures/example-c-decorators.d.ts +5 -0
  21. package/dist/__tests__/fixtures/example-c-decorators.d.ts.map +1 -0
  22. package/dist/__tests__/fixtures/example-d-mixed-decorators.d.ts +6 -0
  23. package/dist/__tests__/fixtures/example-d-mixed-decorators.d.ts.map +1 -0
  24. package/dist/__tests__/fixtures/example-e-decorators.d.ts +11 -0
  25. package/dist/__tests__/fixtures/example-e-decorators.d.ts.map +1 -0
  26. package/dist/__tests__/fixtures/example-e-no-namespace.d.ts +5 -0
  27. package/dist/__tests__/fixtures/example-e-no-namespace.d.ts.map +1 -0
  28. package/dist/__tests__/fixtures/example-interface-types.d.ts +102 -0
  29. package/dist/__tests__/fixtures/example-interface-types.d.ts.map +1 -0
  30. package/dist/__tests__/fixtures/example-jsdoc-constraints.d.ts +16 -0
  31. package/dist/__tests__/fixtures/example-jsdoc-constraints.d.ts.map +1 -0
  32. package/dist/__tests__/fixtures/example-nested-class.d.ts +45 -0
  33. package/dist/__tests__/fixtures/example-nested-class.d.ts.map +1 -0
  34. package/dist/__tests__/fixtures/sample-forms.d.ts +55 -0
  35. package/dist/__tests__/fixtures/sample-forms.d.ts.map +1 -0
  36. package/dist/__tests__/interface-types.test.d.ts +11 -0
  37. package/dist/__tests__/interface-types.test.d.ts.map +1 -0
  38. package/dist/__tests__/jsdoc-constraints.test.d.ts +10 -0
  39. package/dist/__tests__/jsdoc-constraints.test.d.ts.map +1 -0
  40. package/dist/analyzer/class-analyzer.d.ts +139 -0
  41. package/dist/analyzer/class-analyzer.d.ts.map +1 -0
  42. package/dist/analyzer/decorator-extractor.d.ts +78 -0
  43. package/dist/analyzer/decorator-extractor.d.ts.map +1 -0
  44. package/dist/analyzer/jsdoc-constraints.d.ts +47 -0
  45. package/dist/analyzer/jsdoc-constraints.d.ts.map +1 -0
  46. package/dist/analyzer/program.d.ts +53 -0
  47. package/dist/analyzer/program.d.ts.map +1 -0
  48. package/dist/analyzer/type-converter.d.ts +75 -0
  49. package/dist/analyzer/type-converter.d.ts.map +1 -0
  50. package/dist/browser.cjs +549 -0
  51. package/dist/browser.cjs.map +1 -0
  52. package/dist/browser.d.ts +56 -0
  53. package/dist/browser.d.ts.map +1 -0
  54. package/dist/browser.js +501 -0
  55. package/dist/browser.js.map +1 -0
  56. package/dist/build.d.ts +890 -0
  57. package/dist/cli.cjs +2267 -0
  58. package/dist/cli.cjs.map +1 -0
  59. package/dist/cli.js +2204 -103
  60. package/dist/cli.js.map +1 -1
  61. package/dist/codegen/index.d.ts +75 -0
  62. package/dist/codegen/index.d.ts.map +1 -0
  63. package/dist/generators/class-schema.d.ts +114 -0
  64. package/dist/generators/class-schema.d.ts.map +1 -0
  65. package/dist/generators/method-schema.d.ts +67 -0
  66. package/dist/generators/method-schema.d.ts.map +1 -0
  67. package/dist/index.cjs +2093 -0
  68. package/dist/index.cjs.map +1 -0
  69. package/dist/index.d.ts +11 -3
  70. package/dist/index.d.ts.map +1 -1
  71. package/dist/index.js +2024 -104
  72. package/dist/index.js.map +1 -1
  73. package/dist/internals.cjs +1345 -0
  74. package/dist/internals.cjs.map +1 -0
  75. package/dist/internals.d.ts +21 -0
  76. package/dist/internals.d.ts.map +1 -0
  77. package/dist/internals.js +1298 -0
  78. package/dist/internals.js.map +1 -0
  79. package/dist/json-schema/generator.d.ts.map +1 -1
  80. package/dist/json-schema/schema.d.ts +16 -0
  81. package/dist/json-schema/schema.d.ts.map +1 -0
  82. package/dist/json-schema/types.d.ts +28 -0
  83. package/dist/json-schema/types.d.ts.map +1 -1
  84. package/dist/ui-schema/generator.d.ts +15 -0
  85. package/dist/ui-schema/generator.d.ts.map +1 -1
  86. package/dist/ui-schema/schema.d.ts +357 -0
  87. package/dist/ui-schema/schema.d.ts.map +1 -0
  88. package/dist/ui-schema/types.d.ts +8 -73
  89. package/dist/ui-schema/types.d.ts.map +1 -1
  90. package/package.json +25 -7
  91. package/dist/__tests__/cli.test.js +0 -178
  92. package/dist/__tests__/cli.test.js.map +0 -1
  93. package/dist/__tests__/edge-cases.test.js +0 -209
  94. package/dist/__tests__/edge-cases.test.js.map +0 -1
  95. package/dist/__tests__/generator.test.js +0 -208
  96. package/dist/__tests__/generator.test.js.map +0 -1
  97. package/dist/__tests__/integration.test.js +0 -163
  98. package/dist/__tests__/integration.test.js.map +0 -1
  99. package/dist/__tests__/write-schemas.test.js +0 -196
  100. package/dist/__tests__/write-schemas.test.js.map +0 -1
  101. package/dist/json-schema/generator.js +0 -146
  102. package/dist/json-schema/generator.js.map +0 -1
  103. package/dist/json-schema/types.js +0 -7
  104. package/dist/json-schema/types.js.map +0 -1
  105. package/dist/ui-schema/generator.js +0 -150
  106. package/dist/ui-schema/generator.js.map +0 -1
  107. package/dist/ui-schema/types.js +0 -8
  108. package/dist/ui-schema/types.js.map +0 -1
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Tests for interface and type alias schema generation.
3
+ *
4
+ * Covers the `generateSchemas` unified entry point, `analyzeInterface`,
5
+ * `analyzeTypeAlias`, `extractJSDocFieldMetadata`, `@EnumOptions` JSON
6
+ * parsing, nested type propagation, and error paths.
7
+ *
8
+ * @see https://json-schema.org/understanding-json-schema
9
+ */
10
+ export {};
11
+ //# sourceMappingURL=interface-types.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface-types.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/interface-types.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Unit tests for JSDoc constraint tag extraction.
3
+ *
4
+ * Verifies that {@link extractJSDocConstraints} correctly parses TSDoc
5
+ * constraint tags into synthetic DecoratorInfo objects.
6
+ *
7
+ * @see packages/core/src/types/decorators.ts for CONSTRAINT_TAG_DEFINITIONS
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=jsdoc-constraints.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsdoc-constraints.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/jsdoc-constraints.test.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Class analyzer for extracting fields, types, and decorators.
3
+ *
4
+ * Analyzes a TypeScript class declaration to extract:
5
+ * - Field names and TypeScript types
6
+ * - Decorator metadata (Field, Minimum, Maximum, etc.)
7
+ * - Field optionality
8
+ * - TSDoc @deprecated tags
9
+ * - Default values from property initializers
10
+ */
11
+ import * as ts from "typescript";
12
+ import { type DecoratorInfo } from "./decorator-extractor.js";
13
+ /**
14
+ * Analyzed field information from a class.
15
+ */
16
+ export interface FieldInfo {
17
+ /** Field name */
18
+ name: string;
19
+ /** TypeScript type node for the field */
20
+ typeNode: ts.TypeNode | undefined;
21
+ /** Resolved type from the type checker */
22
+ type: ts.Type;
23
+ /** Whether the field is optional (has ? modifier) */
24
+ optional: boolean;
25
+ /** Decorators applied to the field */
26
+ decorators: DecoratorInfo[];
27
+ /** Whether the field has a TSDoc @deprecated tag */
28
+ deprecated: boolean;
29
+ /** Default value extracted from the property initializer (literal values only) */
30
+ defaultValue: unknown;
31
+ }
32
+ /**
33
+ * Result of analyzing a class declaration.
34
+ */
35
+ export interface ClassAnalysis {
36
+ /** Class name */
37
+ name: string;
38
+ /** Analyzed fields */
39
+ fields: FieldInfo[];
40
+ /** Instance methods */
41
+ instanceMethods: MethodInfo[];
42
+ /** Static methods */
43
+ staticMethods: MethodInfo[];
44
+ }
45
+ /**
46
+ * Analyzed method information.
47
+ */
48
+ export interface MethodInfo {
49
+ /** Method name */
50
+ name: string;
51
+ /** Method parameters */
52
+ parameters: ParameterInfo[];
53
+ /** Return type node */
54
+ returnTypeNode: ts.TypeNode | undefined;
55
+ /** Resolved return type */
56
+ returnType: ts.Type;
57
+ }
58
+ /**
59
+ * Analyzed parameter information.
60
+ */
61
+ export interface ParameterInfo {
62
+ /** Parameter name */
63
+ name: string;
64
+ /** TypeScript type node */
65
+ typeNode: ts.TypeNode | undefined;
66
+ /** Resolved type */
67
+ type: ts.Type;
68
+ /** If this is InferSchema<typeof X>, the export name X */
69
+ formSpecExportName: string | null;
70
+ /** Whether the parameter is optional (has ? or default value) */
71
+ optional: boolean;
72
+ }
73
+ /**
74
+ * Analyzes a class declaration to extract fields and methods.
75
+ *
76
+ * @param classDecl - The class declaration to analyze
77
+ * @param checker - TypeScript type checker
78
+ * @returns Analysis result with fields and methods
79
+ */
80
+ export declare function analyzeClass(classDecl: ts.ClassDeclaration, checker: ts.TypeChecker): ClassAnalysis;
81
+ /**
82
+ * Analyzes a property declaration to extract field info.
83
+ */
84
+ export declare function analyzeField(prop: ts.PropertyDeclaration, checker: ts.TypeChecker): FieldInfo | null;
85
+ /**
86
+ * Analyzes an interface declaration to extract field information.
87
+ *
88
+ * Similar to {@link analyzeClass} but for interface declarations.
89
+ * Extracts JSDoc constraint tags (`@Minimum`, `@MaxLength`, etc.) and
90
+ * display metadata (`@Field_displayName`, `@Field_description`) from
91
+ * property signatures, producing the same {@link ClassAnalysis}
92
+ * structure for downstream schema generation.
93
+ *
94
+ * @param interfaceDecl - The interface declaration to analyze
95
+ * @param checker - TypeScript type checker
96
+ * @returns Analysis result with fields (no methods — interfaces have no implementations)
97
+ */
98
+ export declare function analyzeInterface(interfaceDecl: ts.InterfaceDeclaration, checker: ts.TypeChecker): ClassAnalysis;
99
+ /**
100
+ * Result of analyzing a type alias — either a successful analysis or
101
+ * an error describing why the alias can't be analyzed.
102
+ */
103
+ export type AnalyzeTypeAliasResult = {
104
+ ok: true;
105
+ analysis: ClassAnalysis;
106
+ } | {
107
+ ok: false;
108
+ error: string;
109
+ };
110
+ /**
111
+ * Analyzes a type alias declaration to extract field information.
112
+ *
113
+ * Supports type aliases whose body is a type literal (object type):
114
+ *
115
+ * ```typescript
116
+ * type Config = {
117
+ * // @Field_displayName Name @Minimum 1
118
+ * name: string;
119
+ * };
120
+ * ```
121
+ *
122
+ * Returns an error result (not an exception) for non-object-literal aliases,
123
+ * allowing callers to accumulate diagnostics across multiple types.
124
+ *
125
+ * @param typeAlias - The type alias declaration to analyze
126
+ * @param checker - TypeScript type checker
127
+ * @returns Success with analysis, or error with a diagnostic message including line number
128
+ */
129
+ export declare function analyzeTypeAlias(typeAlias: ts.TypeAliasDeclaration, checker: ts.TypeChecker): AnalyzeTypeAliasResult;
130
+ /**
131
+ * Analyzes an interface property signature to extract field info.
132
+ *
133
+ * Extracts JSDoc constraint tags (`@Minimum`, `@MaxLength`, etc.) and
134
+ * display metadata (`@DisplayName`, `@Description`) from the property's
135
+ * TSDoc comments. Also used by the type converter for nested interface/type
136
+ * alias constraint propagation.
137
+ */
138
+ export declare function analyzeInterfaceProperty(prop: ts.PropertySignature, checker: ts.TypeChecker): FieldInfo | null;
139
+ //# sourceMappingURL=class-analyzer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class-analyzer.d.ts","sourceRoot":"","sources":["../../src/analyzer/class-analyzer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAuC,KAAK,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAGnG;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,iBAAiB;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,QAAQ,EAAE,EAAE,CAAC,QAAQ,GAAG,SAAS,CAAC;IAClC,0CAA0C;IAC1C,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC;IACd,qDAAqD;IACrD,QAAQ,EAAE,OAAO,CAAC;IAClB,sCAAsC;IACtC,UAAU,EAAE,aAAa,EAAE,CAAC;IAC5B,oDAAoD;IACpD,UAAU,EAAE,OAAO,CAAC;IACpB,kFAAkF;IAClF,YAAY,EAAE,OAAO,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,iBAAiB;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,sBAAsB;IACtB,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,uBAAuB;IACvB,eAAe,EAAE,UAAU,EAAE,CAAC;IAC9B,qBAAqB;IACrB,aAAa,EAAE,UAAU,EAAE,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,wBAAwB;IACxB,UAAU,EAAE,aAAa,EAAE,CAAC;IAC5B,uBAAuB;IACvB,cAAc,EAAE,EAAE,CAAC,QAAQ,GAAG,SAAS,CAAC;IACxC,2BAA2B;IAC3B,UAA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AAW,GACtB,SAAS,GAAG,IAAI,CAyClB"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Decorator extractor for parsing decorator AST nodes.
3
+ *
4
+ * Extracts decorator names and arguments from class field decorators,
5
+ * supporting the FormSpec decorator DSL (@Field, @Minimum, @Maximum, etc.).
6
+ *
7
+ * Also supports branded type resolution via the TypeScript type checker
8
+ * to detect custom decorators created with `extendDecorator` and
9
+ * `customDecorator` from `@formspec/decorators`.
10
+ */
11
+ import * as ts from "typescript";
12
+ import { type FormSpecDecoratorName } from "@formspec/core";
13
+ /**
14
+ * Extracted decorator information.
15
+ */
16
+ export interface DecoratorInfo {
17
+ /** Decorator name (e.g., "Field", "Minimum") */
18
+ name: string;
19
+ /** Decorator arguments as literal values */
20
+ args: DecoratorArg[];
21
+ /** Raw AST node for the decorator (undefined for synthetic JSDoc constraint entries) */
22
+ node: ts.Decorator | undefined;
23
+ /** Resolved brand information from the type checker (populated by analyzeField) */
24
+ resolved?: ResolvedDecorator;
25
+ }
26
+ /**
27
+ * A decorator argument value.
28
+ * Can be a primitive, array, or object literal.
29
+ */
30
+ export type DecoratorArg = string | number | boolean | null | DecoratorArg[] | {
31
+ [key: string]: DecoratorArg;
32
+ };
33
+ /**
34
+ * Result of resolving a decorator via the type checker.
35
+ */
36
+ export interface ResolvedDecorator {
37
+ /** Decorator name as it appears in source */
38
+ name: string;
39
+ /** If this extends a built-in, the built-in name (e.g., "Field") */
40
+ extendsBuiltin?: string;
41
+ /** If this belongs to a CLI extension namespace, the namespace name */
42
+ extensionName?: string;
43
+ /** Whether this is a known FormSpec decorator (built-in or factory-created) */
44
+ isFormSpec: boolean;
45
+ /** Whether this is a marker (zero-arg) decorator */
46
+ isMarker: boolean;
47
+ }
48
+ /**
49
+ * Extracts decorators from a class member (property or method).
50
+ *
51
+ * @param member - The class member to extract decorators from
52
+ * @returns Array of extracted decorator info
53
+ */
54
+ export declare function extractDecorators(member: ts.PropertyDeclaration | ts.MethodDeclaration): DecoratorInfo[];
55
+ /**
56
+ * Known FormSpec decorators and their expected argument types.
57
+ *
58
+ * This metadata object provides additional information about each decorator's
59
+ * expected argument types. The keys are constrained to match FormSpecDecoratorName.
60
+ */
61
+ export declare const FORMSPEC_DECORATORS: Record<FormSpecDecoratorName, {
62
+ argTypes: readonly string[];
63
+ }>;
64
+ /**
65
+ * Resolves a decorator via the TypeScript type checker to determine
66
+ * if it is a FormSpec decorator (built-in, extended, or custom).
67
+ *
68
+ * This enables detection of:
69
+ * 1. Direct imports of built-in decorators from `@formspec/decorators`
70
+ * 2. Extended decorators created via `extendDecorator(...).as(...)`
71
+ * 3. Custom decorators created via `customDecorator(...).as(...)` or `.marker(...)`
72
+ *
73
+ * @param decorator - The decorator AST node
74
+ * @param checker - TypeScript type checker
75
+ * @returns Resolved decorator information, or null if not resolvable
76
+ */
77
+ export declare function resolveDecorator(decorator: ts.Decorator, checker: ts.TypeChecker): ResolvedDecorator | null;
78
+ //# sourceMappingURL=decorator-extractor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorator-extractor.d.ts","sourceRoot":"","sources":["../../src/analyzer/decorator-extractor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,4CAA4C;IAC5C,IAAI,EAAE,YAAY,EAAE,CAAC;IACrB,wFAAwF;IACxF,IAAI,EAAE,EAAE,CAAC,SAAS,GAAG,SAAS,CAAC;IAC/B,mFAAmF;IACnF,QAAQ,CAAC,EAAE,iBAAiB,CAAC;CAC9B;AAED;;;GAGG;AACH,MAAM,MAAM,YAAY,GACpB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,YAAY,EAAE,GACd;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAAA;CAAE,CAAC;AAEpC;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,oEAAoE;IACpE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,uEAAuE;IACvE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,+EAA+E;IAC/E,UAAU,EAAE,OAAO,CAAC;IACpB,oDAAoD;IACpD,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,EAAE,CAAC,mBAAmB,GAAG,EAAE,CAAC,iBAAiB,GACpD,aAAa,EAAE,CAgBjB;AA0KD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,qBAAqB,EAAE;IAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAuBrF,CAAC;AAgBX;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,EAAE,CAAC,SAAS,EACvB,OAAO,EAAE,EAAE,CAAC,WAAW,GACtB,iBAAiB,GAAG,IAAI,CAyH1B"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * JSDoc constraint tag extractor.
3
+ *
4
+ * Extracts constraint tags from JSDoc comments on class fields and returns
5
+ * synthetic {@link DecoratorInfo} objects that integrate seamlessly with
6
+ * the existing decorator-based constraint pipeline.
7
+ *
8
+ * Supported tags correspond to keys in {@link CONSTRAINT_TAG_DEFINITIONS}
9
+ * from `@formspec/core` (e.g., `@Minimum`, `@Maximum`, `@Pattern`).
10
+ */
11
+ import * as ts from "typescript";
12
+ import type { DecoratorInfo } from "./decorator-extractor.js";
13
+ /**
14
+ * Extracts JSDoc constraint tags from a TypeScript AST node and returns
15
+ * synthetic {@link DecoratorInfo} objects.
16
+ *
17
+ * For each recognised tag (case-sensitive PascalCase match against
18
+ * {@link CONSTRAINT_TAG_DEFINITIONS}), the comment text is parsed
19
+ * according to the tag's declared value type:
20
+ * - `"number"` tags: parsed via `Number()` — skipped when NaN
21
+ * - `"string"` tags (`Pattern`): used as-is (trimmed)
22
+ *
23
+ * @param node - The AST node to inspect for JSDoc tags
24
+ * @returns Synthetic decorator info objects for each valid constraint tag
25
+ */
26
+ export declare function extractJSDocConstraints(node: ts.Node): DecoratorInfo[];
27
+ /**
28
+ * Extracts `@Field_displayName` and `@Field_description` TSDoc tags from
29
+ * a node and returns a synthetic `Field` {@link DecoratorInfo} if either
30
+ * is present.
31
+ *
32
+ * This enables interface properties to carry display metadata via TSDoc
33
+ * tags instead of the `@Field` decorator (which requires a class):
34
+ *
35
+ * ```typescript
36
+ * interface Config {
37
+ * // @Field_displayName Program Name
38
+ * // @Field_description Internal identifier
39
+ * programName: string;
40
+ * }
41
+ * ```
42
+ *
43
+ * @param node - The AST node to inspect for display metadata tags
44
+ * @returns A synthetic `Field` decorator info, or null if no tags found
45
+ */
46
+ export declare function extractJSDocFieldMetadata(node: ts.Node): DecoratorInfo | null;
47
+ //# sourceMappingURL=jsdoc-constraints.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsdoc-constraints.d.ts","sourceRoot":"","sources":["../../src/analyzer/jsdoc-constraints.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,OAAO,KAAK,EAAgB,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE5E;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,aAAa,EAAE,CAoDtE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,aAAa,GAAG,IAAI,CAiC7E"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * TypeScript program setup for static analysis.
3
+ *
4
+ * Creates a TypeScript program with type checker from a source file,
5
+ * using the project's tsconfig.json for compiler options.
6
+ */
7
+ import * as ts from "typescript";
8
+ /**
9
+ * Result of creating a TypeScript program for analysis.
10
+ */
11
+ export interface ProgramContext {
12
+ /** The TypeScript program */
13
+ program: ts.Program;
14
+ /** Type checker for resolving types */
15
+ checker: ts.TypeChecker;
16
+ /** The source file being analyzed */
17
+ sourceFile: ts.SourceFile;
18
+ }
19
+ /**
20
+ * Creates a TypeScript program for analyzing a source file.
21
+ *
22
+ * Looks for tsconfig.json in the file's directory or parent directories.
23
+ * Falls back to default compiler options if no config is found.
24
+ *
25
+ * @param filePath - Absolute path to the TypeScript source file
26
+ * @returns Program context with checker and source file
27
+ */
28
+ export declare function createProgramContext(filePath: string): ProgramContext;
29
+ /**
30
+ * Finds a class declaration by name in a source file.
31
+ *
32
+ * @param sourceFile - The source file to search
33
+ * @param className - Name of the class to find
34
+ * @returns The class declaration node, or null if not found
35
+ */
36
+ export declare function findClassByName(sourceFile: ts.SourceFile, className: string): ts.ClassDeclaration | null;
37
+ /**
38
+ * Finds an interface declaration by name in a source file.
39
+ *
40
+ * @param sourceFile - The source file to search
41
+ * @param interfaceName - Name of the interface to find
42
+ * @returns The interface declaration node, or null if not found
43
+ */
44
+ export declare function findInterfaceByName(sourceFile: ts.SourceFile, interfaceName: string): ts.InterfaceDeclaration | null;
45
+ /**
46
+ * Finds a type alias declaration by name in a source file.
47
+ *
48
+ * @param sourceFile - The source file to search
49
+ * @param aliasName - Name of the type alias to find
50
+ * @returns The type alias declaration node, or null if not found
51
+ */
52
+ export declare function findTypeAliasByName(sourceFile: ts.SourceFile, aliasName: string): ts.TypeAliasDeclaration | null;
53
+ //# sourceMappingURL=program.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../../src/analyzer/program.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAGjC;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,6BAA6B;IAC7B,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC;IACpB,uCAAuC;IACvC,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC;IACxB,qCAAqC;IACrC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC;CAC3B;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,CA6DrE;AA6BD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,EAAE,CAAC,UAAU,EACzB,SAAS,EAAE,MAAM,GAChB,EAAE,CAAC,gBAAgB,GAAG,IAAI,CAE5B;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,EAAE,CAAC,UAAU,EACzB,aAAa,EAAE,MAAM,GACpB,EAAE,CAAC,oBAAoB,GAAG,IAAI,CAEhC;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,EAAE,CAAC,UAAU,EACzB,SAAS,EAAE,MAAM,GAChB,EAAE,CAAC,oBAAoB,GAAG,IAAI,CAEhC"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Type converter for transforming TypeScript types to JSON Schema and FormSpec.
3
+ *
4
+ * Converts TypeScript types (extracted via type checker) to:
5
+ * - JSON Schema definitions
6
+ * - FormSpec field definitions
7
+ */
8
+ import * as ts from "typescript";
9
+ import type { DecoratorInfo } from "./decorator-extractor.js";
10
+ import { type FieldInfo } from "./class-analyzer.js";
11
+ import { type ExtendedJSONSchema7 } from "../json-schema/types.js";
12
+ /**
13
+ * FormSpec field definition (simplified for output).
14
+ */
15
+ export interface FormSpecField {
16
+ _field: string;
17
+ id: string;
18
+ label?: string;
19
+ placeholder?: string;
20
+ description?: string;
21
+ required?: boolean;
22
+ min?: number;
23
+ max?: number;
24
+ step?: number;
25
+ minLength?: number;
26
+ maxLength?: number;
27
+ minItems?: number;
28
+ maxItems?: number;
29
+ pattern?: string;
30
+ options?: (string | {
31
+ id: string;
32
+ label: string;
33
+ })[];
34
+ showWhen?: object;
35
+ group?: string;
36
+ fields?: FormSpecField[];
37
+ }
38
+ /**
39
+ * Result of converting a TypeScript type.
40
+ */
41
+ export interface TypeConversionResult {
42
+ /** JSON Schema representation */
43
+ jsonSchema: ExtendedJSONSchema7;
44
+ /** FormSpec field type */
45
+ formSpecFieldType: string;
46
+ }
47
+ /**
48
+ * Converts a TypeScript type to JSON Schema and FormSpec field type.
49
+ *
50
+ * @param type - The TypeScript type to convert
51
+ * @param checker - TypeScript type checker
52
+ * @returns Conversion result with JSON Schema and FormSpec type
53
+ */
54
+ export declare function convertType(type: ts.Type, checker: ts.TypeChecker): TypeConversionResult;
55
+ /**
56
+ * Creates a FormSpec field definition from a field's type and decorators.
57
+ *
58
+ * @param fieldName - The field name
59
+ * @param type - The TypeScript type
60
+ * @param decorators - Decorators applied to the field
61
+ * @param optional - Whether the field is optional
62
+ * @param checker - TypeScript type checker
63
+ * @returns FormSpec field definition
64
+ */
65
+ export declare function createFormSpecField(fieldName: string, type: ts.Type, decorators: DecoratorInfo[], optional: boolean, checker: ts.TypeChecker, visitedTypes?: Set<ts.Type>): FormSpecField;
66
+ /**
67
+ * Applies decorator constraints to a JSON Schema.
68
+ *
69
+ * @param schema - The base JSON Schema
70
+ * @param decorators - Decorators to apply
71
+ * @param fieldInfo - Optional field info for deprecated/default values
72
+ * @returns Modified JSON Schema with constraints
73
+ */
74
+ export declare function applyDecoratorsToSchema(schema: ExtendedJSONSchema7, decorators: DecoratorInfo[], fieldInfo?: FieldInfo): ExtendedJSONSchema7;
75
+ //# sourceMappingURL=type-converter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-converter.d.ts","sourceRoot":"","sources":["../../src/analyzer/type-converter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,KAAK,EAAE,aAAa,E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