@formspec/build 0.1.0-alpha.5 → 0.1.0-alpha.51

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 (119) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +238 -93
  3. package/dist/analyzer/class-analyzer.d.ts +135 -0
  4. package/dist/analyzer/class-analyzer.d.ts.map +1 -0
  5. package/dist/analyzer/jsdoc-constraints.d.ts +53 -0
  6. package/dist/analyzer/jsdoc-constraints.d.ts.map +1 -0
  7. package/dist/analyzer/program.d.ts +97 -0
  8. package/dist/analyzer/program.d.ts.map +1 -0
  9. package/dist/analyzer/tsdoc-parser.d.ts +124 -0
  10. package/dist/analyzer/tsdoc-parser.d.ts.map +1 -0
  11. package/dist/browser.cjs +2212 -0
  12. package/dist/browser.cjs.map +1 -0
  13. package/dist/browser.d.ts +74 -0
  14. package/dist/browser.d.ts.map +1 -0
  15. package/dist/browser.js +2167 -0
  16. package/dist/browser.js.map +1 -0
  17. package/dist/build-alpha.d.ts +2408 -0
  18. package/dist/build-beta.d.ts +2408 -0
  19. package/dist/build-internal.d.ts +2408 -0
  20. package/dist/build.d.ts +2209 -151
  21. package/dist/canonicalize/chain-dsl-canonicalizer.d.ts +22 -0
  22. package/dist/canonicalize/chain-dsl-canonicalizer.d.ts.map +1 -0
  23. package/dist/canonicalize/index.d.ts +8 -0
  24. package/dist/canonicalize/index.d.ts.map +1 -0
  25. package/dist/canonicalize/tsdoc-canonicalizer.d.ts +38 -0
  26. package/dist/canonicalize/tsdoc-canonicalizer.d.ts.map +1 -0
  27. package/dist/cli.cjs +7111 -0
  28. package/dist/cli.cjs.map +1 -0
  29. package/dist/cli.js +7070 -103
  30. package/dist/cli.js.map +1 -1
  31. package/dist/extensions/index.d.ts +8 -0
  32. package/dist/extensions/index.d.ts.map +1 -0
  33. package/dist/extensions/registry.d.ts +142 -0
  34. package/dist/extensions/registry.d.ts.map +1 -0
  35. package/dist/extensions/resolve-custom-type.d.ts +37 -0
  36. package/dist/extensions/resolve-custom-type.d.ts.map +1 -0
  37. package/dist/extensions/symbol-registry.d.ts +33 -0
  38. package/dist/extensions/symbol-registry.d.ts.map +1 -0
  39. package/dist/extensions/ts-type-utils.d.ts +40 -0
  40. package/dist/extensions/ts-type-utils.d.ts.map +1 -0
  41. package/dist/generators/class-schema.d.ts +392 -0
  42. package/dist/generators/class-schema.d.ts.map +1 -0
  43. package/dist/generators/discovered-schema.d.ts +152 -0
  44. package/dist/generators/discovered-schema.d.ts.map +1 -0
  45. package/dist/generators/method-schema.d.ts +72 -0
  46. package/dist/generators/method-schema.d.ts.map +1 -0
  47. package/dist/generators/mixed-authoring.d.ts +52 -0
  48. package/dist/generators/mixed-authoring.d.ts.map +1 -0
  49. package/dist/index.cjs +6786 -0
  50. package/dist/index.cjs.map +1 -0
  51. package/dist/index.d.ts +51 -8
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +6751 -107
  54. package/dist/index.js.map +1 -1
  55. package/dist/internals.cjs +5736 -0
  56. package/dist/internals.cjs.map +1 -0
  57. package/dist/internals.d.ts +32 -0
  58. package/dist/internals.d.ts.map +1 -0
  59. package/dist/internals.js +5706 -0
  60. package/dist/internals.js.map +1 -0
  61. package/dist/json-schema/generator.d.ts +32 -6
  62. package/dist/json-schema/generator.d.ts.map +1 -1
  63. package/dist/json-schema/ir-generator.d.ts +149 -0
  64. package/dist/json-schema/ir-generator.d.ts.map +1 -0
  65. package/dist/json-schema/schema.d.ts +23 -0
  66. package/dist/json-schema/schema.d.ts.map +1 -0
  67. package/dist/json-schema/types.d.ts +76 -2
  68. package/dist/json-schema/types.d.ts.map +1 -1
  69. package/dist/metadata/collision-guards.d.ts +3 -0
  70. package/dist/metadata/collision-guards.d.ts.map +1 -0
  71. package/dist/metadata/index.d.ts +7 -0
  72. package/dist/metadata/index.d.ts.map +1 -0
  73. package/dist/metadata/policy.d.ts +12 -0
  74. package/dist/metadata/policy.d.ts.map +1 -0
  75. package/dist/metadata/resolve.d.ts +21 -0
  76. package/dist/metadata/resolve.d.ts.map +1 -0
  77. package/dist/static-build.d.ts +61 -0
  78. package/dist/static-build.d.ts.map +1 -0
  79. package/dist/ui-schema/generator.d.ts +18 -2
  80. package/dist/ui-schema/generator.d.ts.map +1 -1
  81. package/dist/ui-schema/ir-generator.d.ts +54 -0
  82. package/dist/ui-schema/ir-generator.d.ts.map +1 -0
  83. package/dist/ui-schema/schema.d.ts +429 -0
  84. package/dist/ui-schema/schema.d.ts.map +1 -0
  85. package/dist/ui-schema/types.d.ts +179 -35
  86. package/dist/ui-schema/types.d.ts.map +1 -1
  87. package/dist/validate/constraint-validator.d.ts +85 -0
  88. package/dist/validate/constraint-validator.d.ts.map +1 -0
  89. package/dist/validate/index.d.ts +9 -0
  90. package/dist/validate/index.d.ts.map +1 -0
  91. package/package.json +30 -11
  92. package/dist/__tests__/cli.test.d.ts +0 -2
  93. package/dist/__tests__/cli.test.d.ts.map +0 -1
  94. package/dist/__tests__/cli.test.js +0 -178
  95. package/dist/__tests__/cli.test.js.map +0 -1
  96. package/dist/__tests__/edge-cases.test.d.ts +0 -7
  97. package/dist/__tests__/edge-cases.test.d.ts.map +0 -1
  98. package/dist/__tests__/edge-cases.test.js +0 -217
  99. package/dist/__tests__/edge-cases.test.js.map +0 -1
  100. package/dist/__tests__/generator.test.d.ts +0 -2
  101. package/dist/__tests__/generator.test.d.ts.map +0 -1
  102. package/dist/__tests__/generator.test.js +0 -234
  103. package/dist/__tests__/generator.test.js.map +0 -1
  104. package/dist/__tests__/integration.test.d.ts +0 -8
  105. package/dist/__tests__/integration.test.d.ts.map +0 -1
  106. package/dist/__tests__/integration.test.js +0 -163
  107. package/dist/__tests__/integration.test.js.map +0 -1
  108. package/dist/__tests__/write-schemas.test.d.ts +0 -2
  109. package/dist/__tests__/write-schemas.test.d.ts.map +0 -1
  110. package/dist/__tests__/write-schemas.test.js +0 -196
  111. package/dist/__tests__/write-schemas.test.js.map +0 -1
  112. package/dist/json-schema/generator.js +0 -167
  113. package/dist/json-schema/generator.js.map +0 -1
  114. package/dist/json-schema/types.js +0 -7
  115. package/dist/json-schema/types.js.map +0 -1
  116. package/dist/ui-schema/generator.js +0 -150
  117. package/dist/ui-schema/generator.js.map +0 -1
  118. package/dist/ui-schema/types.js +0 -8
  119. package/dist/ui-schema/types.js.map +0 -1
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Extension registry for `@formspec/build`.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ export { createExtensionRegistry } from "./registry.js";
7
+ export type { ExtensionRegistry, ExtensionTypeLookupResult, MutableExtensionRegistry, } from "./registry.js";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/extensions/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,YAAY,EACV,iBAAiB,EACjB,yBAAyB,EACzB,wBAAwB,GACzB,MAAM,eAAe,CAAC"}
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Extension registry for resolving custom types, constraints, and annotations
3
+ * during JSON Schema generation and IR validation.
4
+ *
5
+ * The registry is created from a list of {@link ExtensionDefinition} objects
6
+ * and provides O(1) lookup by fully-qualified ID (extensionId + "/" + name).
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ import type * as ts from "typescript";
11
+ import type { ExtensionDefinition, CustomTypeRegistration, CustomConstraintRegistration, CustomAnnotationRegistration, ConstraintTagRegistration, BuiltinConstraintBroadeningRegistration } from "@formspec/core";
12
+ /**
13
+ * The result of a successful extension type lookup.
14
+ *
15
+ * Returned by {@link ExtensionRegistry.findTypeByName},
16
+ * {@link ExtensionRegistry.findTypeByBrand}, and
17
+ * {@link ExtensionRegistry.findTypeBySymbol}.
18
+ *
19
+ * @public
20
+ */
21
+ export interface ExtensionTypeLookupResult {
22
+ /** The fully-qualified extension ID (e.g., "x-stripe/monetary"). */
23
+ readonly extensionId: string;
24
+ /** The custom type registration matched by this lookup. */
25
+ readonly registration: CustomTypeRegistration;
26
+ }
27
+ /**
28
+ * A registry of extensions that provides lookup by fully-qualified ID.
29
+ *
30
+ * Type IDs follow the format: `<extensionId>/<typeName>`
31
+ * Constraint IDs follow the format: `<extensionId>/<constraintName>`
32
+ * Annotation IDs follow the format: `<extensionId>/<annotationName>`
33
+ *
34
+ * @public
35
+ */
36
+ export interface ExtensionRegistry {
37
+ /** The extensions registered in this registry (in registration order). */
38
+ readonly extensions: readonly ExtensionDefinition[];
39
+ /**
40
+ * Look up a custom type registration by its fully-qualified type ID.
41
+ *
42
+ * @param typeId - The fully-qualified type ID (e.g., "x-stripe/monetary/Decimal").
43
+ * @returns The registration if found, otherwise `undefined`.
44
+ */
45
+ findType(typeId: string): CustomTypeRegistration | undefined;
46
+ /**
47
+ * Look up a custom type registration by a TypeScript-facing type name.
48
+ *
49
+ * This is used during TSDoc/class analysis to resolve extension-defined
50
+ * custom types from source-level declarations.
51
+ */
52
+ findTypeByName(typeName: string): ExtensionTypeLookupResult | undefined;
53
+ /**
54
+ * Look up a custom type registration by a brand identifier.
55
+ *
56
+ * This is used during class analysis to resolve extension-defined custom types
57
+ * via structural brand detection (`unique symbol` computed property keys).
58
+ * Brand identifiers are stored as plain strings, so they must be unique
59
+ * across all extensions loaded into the registry.
60
+ *
61
+ * @param brand - The identifier text of the `unique symbol` brand variable.
62
+ */
63
+ findTypeByBrand(brand: string): ExtensionTypeLookupResult | undefined;
64
+ /**
65
+ * Look up a custom type by its TypeScript symbol identity.
66
+ *
67
+ * Built from `defineCustomType<T>()` type parameter extraction in the config file.
68
+ * This is the most precise detection path — it uses `ts.Symbol` identity, which is
69
+ * immune to import aliases and name collisions.
70
+ *
71
+ * Returns `undefined` until {@link MutableExtensionRegistry.setSymbolMap} has been
72
+ * called (i.e., before the TypeScript program is available), or when the symbol is
73
+ * not registered via a type parameter.
74
+ *
75
+ * @param symbol - The canonical TypeScript symbol to look up.
76
+ */
77
+ findTypeBySymbol(symbol: ts.Symbol): ExtensionTypeLookupResult | undefined;
78
+ /**
79
+ * Look up a custom constraint registration by its fully-qualified constraint ID.
80
+ *
81
+ * @param constraintId - The fully-qualified constraint ID.
82
+ * @returns The registration if found, otherwise `undefined`.
83
+ */
84
+ findConstraint(constraintId: string): CustomConstraintRegistration | undefined;
85
+ /**
86
+ * Look up a TSDoc custom constraint-tag registration by tag name.
87
+ */
88
+ findConstraintTag(tagName: string): {
89
+ readonly extensionId: string;
90
+ readonly registration: ConstraintTagRegistration;
91
+ } | undefined;
92
+ /**
93
+ * Look up built-in tag broadening for a given custom type ID.
94
+ */
95
+ findBuiltinConstraintBroadening(typeId: string, tagName: string): {
96
+ readonly extensionId: string;
97
+ readonly registration: BuiltinConstraintBroadeningRegistration;
98
+ } | undefined;
99
+ /**
100
+ * Look up a custom annotation registration by its fully-qualified annotation ID.
101
+ *
102
+ * @param annotationId - The fully-qualified annotation ID.
103
+ * @returns The registration if found, otherwise `undefined`.
104
+ */
105
+ findAnnotation(annotationId: string): CustomAnnotationRegistration | undefined;
106
+ }
107
+ /**
108
+ * Mutable extension registry used internally by the build pipeline.
109
+ *
110
+ * Extends {@link ExtensionRegistry} with `setSymbolMap`, which must be called
111
+ * after the TypeScript program is created. Consumer code should accept only
112
+ * the read-only {@link ExtensionRegistry} interface.
113
+ *
114
+ * @public
115
+ */
116
+ export interface MutableExtensionRegistry extends ExtensionRegistry {
117
+ /**
118
+ * Sets the symbol map built from config AST analysis.
119
+ *
120
+ * Called after the TypeScript program is created and the config file is analyzed.
121
+ * Prior to this call, {@link ExtensionRegistry.findTypeBySymbol} always returns
122
+ * `undefined`.
123
+ *
124
+ * @param map - A map from canonical `ts.Symbol` to the matching registry entry.
125
+ */
126
+ setSymbolMap(map: Map<ts.Symbol, ExtensionTypeLookupResult>): void;
127
+ }
128
+ /**
129
+ * Creates an extension registry from a list of extension definitions.
130
+ *
131
+ * The registry indexes all types, constraints, and annotations by their
132
+ * fully-qualified IDs (`<extensionId>/<name>`) for O(1) lookup during
133
+ * generation and validation.
134
+ *
135
+ * @param extensions - The extension definitions to register.
136
+ * @returns An {@link ExtensionRegistry} instance.
137
+ * @throws If duplicate type/constraint/annotation IDs are detected across extensions.
138
+ *
139
+ * @public
140
+ */
141
+ export declare function createExtensionRegistry(extensions: readonly ExtensionDefinition[]): MutableExtensionRegistry;
142
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/extensions/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EACV,mBAAmB,EACnB,sBAAsB,EACtB,4BAA4B,EAC5B,4BAA4B,EAC5B,yBAAyB,EACzB,uCAAuC,EACxC,MAAM,gBAAgB,CAAC;AAexB;;;;;;;;GAQG;AACH,MAAM,WAAW,yBAAyB;IACxC,oEAAoE;IACpE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,2DAA2D;IAC3D,QAAQ,CAAC,YAAY,EAAE,sBAAsB,CAAC;CAC/C;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAiB;IAChC,0EAA0E;IAC1E,QAAQ,CAAC,UAAU,EAAE,SAAS,mBAAmB,EAAE,CAAC;IAEpD;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,sBAAsB,GAAG,SAAS,CAAC;IAC7D;;;;;OAKG;IACH,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,yBAAyB,GAAG,SAAS,CAAC;IACxE;;;;;;;;;OASG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,yBAAyB,GAAG,SAAS,CAAC;IAEtE;;;;;;;;;;;;OAYG;IACH,gBAAgB,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,GAAG,yBAAyB,GAAG,SAAS,CAAC;IAE3E;;;;;OAKG;IACH,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,4BAA4B,GAAG,SAAS,CAAC;IAC/E;;OAEG;IACH,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAC7B;QACE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;QAC7B,QAAQ,CAAC,YAAY,EAAE,yBAAyB,CAAC;KAClD,GACD,SAAS,CAAC;IACd;;OAEG;IACH,+BAA+B,CAC7B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GAEb;QACE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;QAC7B,QAAQ,CAAC,YAAY,EAAE,uCAAuC,CAAC;KAChE,GACD,SAAS,CAAC;IAEd;;;;;OAKG;IACH,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,4BAA4B,GAAG,SAAS,CAAC;CAChF;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,wBAAyB,SAAQ,iBAAiB;IACjE;;;;;;;;OAQG;IACH,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,yBAAyB,CAAC,GAAG,IAAI,CAAC;CACpE;AAuBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,SAAS,mBAAmB,EAAE,GACzC,wBAAwB,CAuK1B"}
@@ -0,0 +1,37 @@
1
+ import * as ts from "typescript";
2
+ import type { ExtensionRegistry, ExtensionTypeLookupResult } from "./registry.js";
3
+ /**
4
+ * Resolves a TypeScript type to an extension-registered custom type, trying
5
+ * all three registration mechanisms in order of precision:
6
+ *
7
+ * 1. **Name-based** (via `sourceNode` AST walk) — matches the user-written
8
+ * alias identifier (e.g. `amount: Decimal` → `"Decimal"`). Requires a
9
+ * source node to walk; used by the direct-field code path.
10
+ * 2. **Symbol-based** — matches `ts.Symbol` identity via
11
+ * `ExtensionRegistry.findTypeBySymbol`, populated from
12
+ * `defineCustomType<T>()` type parameter extraction. Works for any type
13
+ * regardless of import aliases or name collisions.
14
+ * 3. **Brand-based** — matches the `brand` identifier encoded into
15
+ * intersection types as computed-property keys (e.g.
16
+ * `string & { [__decimalBrand]: true }`). Structural; independent of
17
+ * declaration names.
18
+ *
19
+ * Name-based resolution also has a symbol-fallback path that uses
20
+ * `type.aliasSymbol?.getName()` when no `sourceNode` is provided, so
21
+ * path-resolved types can still match name-registered custom types.
22
+ *
23
+ * Nullable unions (`T | null`, `T | undefined`, `T | null | undefined`) are
24
+ * stripped before every detection attempt, so registrations apply through
25
+ * nullable wrappers transparently.
26
+ *
27
+ * Returns `null` when no registered custom type matches.
28
+ */
29
+ export declare function resolveCustomTypeFromTsType(type: ts.Type, checker: ts.TypeChecker, registry: ExtensionRegistry | undefined, sourceNode?: ts.Node): ExtensionTypeLookupResult | null;
30
+ /**
31
+ * Returns the fully-qualified type ID for a resolved custom-type lookup.
32
+ *
33
+ * Type IDs have the form `${extensionId}/${typeName}`, matching the format
34
+ * produced elsewhere in the build pipeline.
35
+ */
36
+ export declare function customTypeIdFromLookup(result: ExtensionTypeLookupResult): string;
37
+ //# sourceMappingURL=resolve-custom-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-custom-type.d.ts","sourceRoot":"","sources":["../../src/extensions/resolve-custom-type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAIjC,OAAO,KAAK,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAoDlF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,QAAQ,EAAE,iBAAiB,GAAG,SAAS,EACvC,UAAU,CAAC,EAAE,EAAE,CAAC,IAAI,GACnB,yBAAyB,GAAG,IAAI,CA8ClC;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,yBAAyB,GAAG,MAAM,CAEhF"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Symbol-based custom type registry.
3
+ *
4
+ * Walks the FormSpec config file AST to find `defineCustomType<T>()` calls,
5
+ * extracts the TypeScript type argument, resolves it to a canonical `ts.Symbol`,
6
+ * and builds a `Map` for O(1) symbol-identity lookup during field analysis.
7
+ *
8
+ * This detection path is the most precise available — it uses TypeScript's own
9
+ * type identity, making it immune to import aliases and name collisions.
10
+ *
11
+ * @packageDocumentation
12
+ */
13
+ import * as ts from "typescript";
14
+ import type { ExtensionRegistry, ExtensionTypeLookupResult } from "./registry.js";
15
+ /**
16
+ * Walks the config file's AST to find `defineCustomType<T>()` calls,
17
+ * extracts type arguments, resolves them to ts.Symbol, and builds a
18
+ * Map for O(1) symbol-identity lookup during field analysis.
19
+ *
20
+ * Returns an empty map if the config file isn't in the program, has
21
+ * no `defineCustomType` calls, or none have type arguments.
22
+ *
23
+ * @param configPath - Absolute path to the FormSpec config file.
24
+ * @param program - The TypeScript program that includes the config file.
25
+ * @param checker - Type checker for the program.
26
+ * @param extensionRegistry - The runtime extension registry already built from
27
+ * the config's export; used to look up the matching registration by typeName.
28
+ * @returns A map from canonical ts.Symbol to the matching registry entry.
29
+ *
30
+ * @public
31
+ */
32
+ export declare function buildSymbolMapFromConfig(configPath: string, program: ts.Program, checker: ts.TypeChecker, extensionRegistry: ExtensionRegistry): Map<ts.Symbol, ExtensionTypeLookupResult>;
33
+ //# sourceMappingURL=symbol-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"symbol-registry.d.ts","sourceRoot":"","sources":["../../src/extensions/symbol-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,OAAO,KAAK,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAOlF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,wBAAwB,CACtC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,EAAE,CAAC,OAAO,EACnB,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,iBAAiB,EAAE,iBAAiB,GACnC,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,yBAAyB,CAAC,CA+D3C"}
@@ -0,0 +1,40 @@
1
+ import * as ts from "typescript";
2
+ /**
3
+ * Collects all brand identifier texts from an intersection type's computed
4
+ * property names.
5
+ *
6
+ * Walks `type.getProperties()` looking for computed property names backed
7
+ * by plain identifiers — the standard `unique symbol` brand pattern. Returns
8
+ * all matching identifiers so that types with multiple brands (e.g.,
9
+ * `number & { [__integerBrand]: true } & { [__otherBrand]: true }`) are
10
+ * fully inspected regardless of property order.
11
+ */
12
+ export declare function collectBrandIdentifiers(type: ts.Type): readonly string[];
13
+ /**
14
+ * Resolves a TypeScript type to its canonical `ts.Symbol`, following alias chains.
15
+ *
16
+ * `aliasSymbol` tracks type aliases (e.g. `type Foo = Bar`); `getSymbol()` tracks
17
+ * the structural symbol. We prefer `aliasSymbol` when present so that aliased
18
+ * types resolve to the declaration site rather than the structural shape.
19
+ *
20
+ * Returns `undefined` for bare primitives and anonymous types, which have no
21
+ * symbol.
22
+ */
23
+ export declare function resolveCanonicalSymbol(type: ts.Type, checker: ts.TypeChecker): ts.Symbol | undefined;
24
+ /**
25
+ * Extracts the `ts.TypeNode` backing a property / parameter / type-alias
26
+ * declaration. Returns the node itself when `sourceNode` is already a type
27
+ * node, or `undefined` otherwise.
28
+ */
29
+ export declare function extractTypeNodeFromSource(sourceNode: ts.Node): ts.TypeNode | undefined;
30
+ /**
31
+ * Resolves a `ts.TypeReferenceNode` to its declaring `ts.TypeAliasDeclaration`,
32
+ * if the reference names a type alias — following import aliases so that
33
+ * `import { Foo } from "./types"; field: Foo` resolves through to the
34
+ * original `type Foo = ...` declaration.
35
+ *
36
+ * Returns `undefined` for references to non-alias declarations (interfaces,
37
+ * classes, modules, etc.).
38
+ */
39
+ export declare function getTypeAliasDeclarationFromTypeReference(typeNode: ts.TypeReferenceNode, checker: ts.TypeChecker): ts.TypeAliasDeclaration | undefined;
40
+ //# sourceMappingURL=ts-type-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ts-type-utils.d.ts","sourceRoot":"","sources":["../../src/extensions/ts-type-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,SAAS,MAAM,EAAE,CAcxE;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,OAAO,EAAE,EAAE,CAAC,WAAW,GACtB,EAAE,CAAC,MAAM,GAAG,SAAS,CAIvB;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,QAAQ,GAAG,SAAS,CAatF;AAUD;;;;;;;;GAQG;AACH,wBAAgB,wCAAwC,CACtD,QAAQ,EAAE,EAAE,CAAC,iBAAiB,EAC9B,OAAO,EAAE,EAAE,CAAC,WAAW,GACtB,EAAE,CAAC,oBAAoB,GAAG,SAAS,CAGrC"}
@@ -0,0 +1,392 @@
1
+ /**
2
+ * Class schema generator.
3
+ *
4
+ * Generates JSON Schema 2020-12 and JSON Forms UI Schema from statically
5
+ * analyzed class/interface/type alias declarations, routing through the
6
+ * canonical FormIR pipeline.
7
+ */
8
+ import * as ts from "typescript";
9
+ import type { UISchema } from "../ui-schema/types.js";
10
+ import type { MetadataPolicyInput } from "@formspec/core";
11
+ import type { FormSpecConfig } from "@formspec/config";
12
+ import { type DiscriminatorResolutionOptions, type IRClassAnalysis } from "../analyzer/class-analyzer.js";
13
+ import { type TSDocSource } from "../canonicalize/index.js";
14
+ import { type GenerateJsonSchemaFromIROptions, type JsonSchema2020 } from "../json-schema/ir-generator.js";
15
+ import { type ExtensionRegistry } from "../extensions/index.js";
16
+ import { type ValidationDiagnostic } from "../validate/index.js";
17
+ export type { DiscriminatorResolutionOptions } from "../analyzer/class-analyzer.js";
18
+ /**
19
+ * Generated schemas for a class.
20
+ *
21
+ * @beta
22
+ */
23
+ export interface ClassSchemas {
24
+ /** JSON Schema 2020-12 for validation */
25
+ jsonSchema: JsonSchema2020;
26
+ /** JSON Forms UI Schema for rendering */
27
+ uiSchema: UISchema;
28
+ }
29
+ /**
30
+ * Non-throwing schema generation result with structured diagnostics.
31
+ *
32
+ * @public
33
+ */
34
+ export interface DetailedClassSchemasResult {
35
+ /** Whether schema generation completed without error-severity diagnostics. */
36
+ readonly ok: boolean;
37
+ /** Collected analysis and validation diagnostics for this target. */
38
+ readonly diagnostics: readonly ValidationDiagnostic[];
39
+ /** JSON Schema 2020-12 for validation, when generation succeeds. */
40
+ readonly jsonSchema?: JsonSchema2020 | undefined;
41
+ /** JSON Forms UI Schema for rendering, when generation succeeds. */
42
+ readonly uiSchema?: UISchema | undefined;
43
+ }
44
+ /**
45
+ * A batch target for non-throwing schema generation.
46
+ *
47
+ * @public
48
+ */
49
+ export interface SchemaGenerationTarget {
50
+ /** Path to the TypeScript source file. */
51
+ readonly filePath: string;
52
+ /** Name of the exported class, interface, or type alias to analyze. */
53
+ readonly typeName: string;
54
+ }
55
+ /**
56
+ * Batch options for non-throwing schema generation.
57
+ *
58
+ * @public
59
+ */
60
+ export interface GenerateSchemasBatchOptions extends StaticSchemaGenerationOptions {
61
+ /** Targets to analyze and generate. */
62
+ readonly targets: readonly SchemaGenerationTarget[];
63
+ }
64
+ /**
65
+ * Batch options for non-throwing schema generation using an existing program.
66
+ *
67
+ * @public
68
+ */
69
+ export interface GenerateSchemasBatchFromProgramOptions extends StaticSchemaGenerationOptions {
70
+ /** Existing TypeScript program supplied by the caller. */
71
+ readonly program: ts.Program;
72
+ /** Targets to analyze and generate. */
73
+ readonly targets: readonly SchemaGenerationTarget[];
74
+ }
75
+ /**
76
+ * Result for a single target in a batch generation request.
77
+ *
78
+ * @public
79
+ */
80
+ export interface DetailedSchemaGenerationTargetResult extends DetailedClassSchemasResult {
81
+ /** Path to the TypeScript source file. */
82
+ readonly filePath: string;
83
+ /** Name of the exported class, interface, or type alias that was analyzed. */
84
+ readonly typeName: string;
85
+ }
86
+ /**
87
+ * Generates JSON Schema 2020-12 and UI Schema from an IR class analysis.
88
+ *
89
+ * Routes through the canonical IR pipeline:
90
+ * IRClassAnalysis → canonicalizeTSDoc → FormIR → JSON Schema / UI Schema
91
+ *
92
+ * @param analysis - The IR analysis result (from analyzeClassToIR, analyzeInterfaceToIR, or analyzeTypeAliasToIR)
93
+ * @param source - Optional source file metadata for provenance
94
+ * @returns Generated JSON Schema and UI Schema
95
+ */
96
+ export declare function generateClassSchemas(analysis: IRClassAnalysis, source?: TSDocSource, options?: GenerateJsonSchemaFromIROptions & {
97
+ metadata?: MetadataPolicyInput | undefined;
98
+ }): ClassSchemas;
99
+ /**
100
+ * Generates JSON Schema 2020-12 and UI Schema from an IR class analysis
101
+ * without throwing on validation diagnostics.
102
+ *
103
+ * @public
104
+ */
105
+ export declare function generateClassSchemasDetailed(analysis: IRClassAnalysis, source?: TSDocSource, options?: GenerateJsonSchemaFromIROptions & {
106
+ metadata?: MetadataPolicyInput | undefined;
107
+ }): DetailedClassSchemasResult;
108
+ /**
109
+ * Shared options for schema generation flows that support custom extensions.
110
+ *
111
+ * @public
112
+ */
113
+ export interface StaticSchemaGenerationOptions {
114
+ /**
115
+ * FormSpec project configuration. When provided, resolves `extensionRegistry`,
116
+ * `vendorPrefix`, `enumSerialization`, and `metadata` from the config object.
117
+ * Direct options take precedence over config values.
118
+ */
119
+ readonly config?: FormSpecConfig | undefined;
120
+ /**
121
+ * Registry used to resolve custom types, constraints, and annotations.
122
+ * @deprecated Provide a `FormSpecConfig` via the `config` option instead.
123
+ */
124
+ readonly extensionRegistry?: ExtensionRegistry | undefined;
125
+ /**
126
+ * Vendor prefix for emitted extension keywords.
127
+ * @defaultValue "x-formspec"
128
+ * @deprecated Provide a `FormSpecConfig` via the `config` option instead.
129
+ */
130
+ readonly vendorPrefix?: string | undefined;
131
+ /**
132
+ * JSON Schema representation to use for static enums.
133
+ * @defaultValue "enum"
134
+ * @deprecated Provide a `FormSpecConfig` via the `config` option instead.
135
+ */
136
+ readonly enumSerialization?: "enum" | "oneOf";
137
+ /**
138
+ * Metadata resolution policy for static schema generation.
139
+ * @deprecated Provide a `FormSpecConfig` via the `config` option instead.
140
+ */
141
+ readonly metadata?: MetadataPolicyInput | undefined;
142
+ /** Discriminator-specific schema generation behavior. */
143
+ readonly discriminator?: DiscriminatorResolutionOptions | undefined;
144
+ /**
145
+ * Absolute path to the FormSpec config file (e.g., `formspec.config.ts`).
146
+ *
147
+ * When provided alongside a `config` that includes extensions, the build
148
+ * pipeline includes the config file in the TypeScript program and extracts
149
+ * `defineCustomType<T>()` type parameters. This enables symbol-based custom
150
+ * type detection — the most precise resolution path, immune to import aliases
151
+ * and name collisions.
152
+ *
153
+ * Obtain this from `loadFormSpecConfig()`:
154
+ * ```typescript
155
+ * const { config, configPath } = await loadFormSpecConfig();
156
+ * await generateSchemas({ filePath, typeName, config, configPath, errorReporting: "throw" });
157
+ * ```
158
+ */
159
+ readonly configPath?: string | undefined;
160
+ }
161
+ /**
162
+ * Options for generating schemas from a decorated class.
163
+ *
164
+ * @public
165
+ */
166
+ export interface GenerateFromClassOptions extends StaticSchemaGenerationOptions {
167
+ /** Path to the TypeScript source file */
168
+ filePath: string;
169
+ /** Class name to analyze */
170
+ className: string;
171
+ }
172
+ /**
173
+ * Result of generating schemas from a decorated class.
174
+ *
175
+ * @public
176
+ */
177
+ export interface GenerateFromClassResult {
178
+ /** JSON Schema 2020-12 for validation */
179
+ jsonSchema: JsonSchema2020;
180
+ /** JSON Forms UI Schema for rendering */
181
+ uiSchema: UISchema;
182
+ }
183
+ /**
184
+ * Options for generating schemas from a named type inside an existing TypeScript program.
185
+ *
186
+ * @public
187
+ */
188
+ export interface GenerateSchemasFromProgramOptions extends StaticSchemaGenerationOptions {
189
+ /** Existing TypeScript program supplied by the caller. */
190
+ readonly program: ts.Program;
191
+ /** Path to the TypeScript source file */
192
+ readonly filePath: string;
193
+ /** Name of the exported class, interface, or type alias to analyze */
194
+ readonly typeName: string;
195
+ /**
196
+ * Controls whether error-severity diagnostics throw or are returned in the result.
197
+ */
198
+ readonly errorReporting: "throw" | "diagnostics";
199
+ }
200
+ /**
201
+ * Generates JSON Schema and UI Schema from a decorated TypeScript class.
202
+ *
203
+ * This is a high-level entry point that handles the entire pipeline:
204
+ * creating a TypeScript program, finding the class, analyzing it to IR,
205
+ * and generating schemas — all in one call.
206
+ *
207
+ * @example
208
+ * ```typescript
209
+ * const result = generateSchemasFromClass({
210
+ * filePath: "./src/forms.ts",
211
+ * className: "UserForm",
212
+ * });
213
+ * console.log(result.jsonSchema);
214
+ * ```
215
+ *
216
+ * @param options - File path, class name, and optional compiler options
217
+ * @returns Generated JSON Schema and UI Schema
218
+ *
219
+ * @public
220
+ */
221
+ export declare function generateSchemasFromClass(options: GenerateFromClassOptions): GenerateFromClassResult;
222
+ /**
223
+ * Options for generating schemas from a named type (class, interface, or type alias).
224
+ *
225
+ * @public
226
+ */
227
+ export interface GenerateSchemasOptions extends StaticSchemaGenerationOptions {
228
+ /** Path to the TypeScript source file */
229
+ readonly filePath: string;
230
+ /** Name of the exported class, interface, or type alias to analyze */
231
+ readonly typeName: string;
232
+ /**
233
+ * Controls whether error-severity diagnostics throw or are returned in the result.
234
+ */
235
+ readonly errorReporting: "throw" | "diagnostics";
236
+ }
237
+ /**
238
+ * Generates JSON Schema and UI Schema from a named TypeScript
239
+ * type — a decorated class, an interface with TSDoc tags, or a type alias.
240
+ *
241
+ * This is the recommended entry point. It automatically detects whether
242
+ * the name resolves to a class, interface, or type alias and uses the
243
+ * appropriate IR analysis pipeline.
244
+ *
245
+ * @example
246
+ * ```typescript
247
+ * const result = generateSchemas({
248
+ * filePath: "./src/config.ts",
249
+ * typeName: "DiscountConfig",
250
+ * errorReporting: "throw",
251
+ * });
252
+ * ```
253
+ */
254
+ /**
255
+ * Generates JSON Schema and UI Schema from a named type and throws when
256
+ * generation reports error-severity diagnostics.
257
+ *
258
+ * @param options - File path, type name, and explicit throw-on-error reporting
259
+ * @returns Generated JSON Schema and UI Schema
260
+ *
261
+ * @public
262
+ */
263
+ export declare function generateSchemas(options: GenerateSchemasOptions & {
264
+ readonly errorReporting: "throw";
265
+ }): GenerateFromClassResult;
266
+ /**
267
+ * Generates JSON Schema and UI Schema from a named type and returns structured
268
+ * diagnostics instead of throwing on validation or analysis failures.
269
+ *
270
+ * @param options - File path, type name, and explicit diagnostics reporting
271
+ * @returns Structured generation result with diagnostics
272
+ *
273
+ * @public
274
+ */
275
+ export declare function generateSchemas(options: GenerateSchemasOptions & {
276
+ readonly errorReporting: "diagnostics";
277
+ }): DetailedClassSchemasResult;
278
+ /**
279
+ * Generates JSON Schema and UI Schema from a named type.
280
+ *
281
+ * @deprecated Pass `errorReporting` explicitly. Omitting it defaults to `"throw"` only for backward compatibility.
282
+ * @param options - File path and type name
283
+ * @returns Generated JSON Schema and UI Schema
284
+ *
285
+ * @public
286
+ */
287
+ export declare function generateSchemas(options: StaticSchemaGenerationOptions & {
288
+ readonly filePath: string;
289
+ readonly typeName: string;
290
+ }): GenerateFromClassResult;
291
+ /**
292
+ * Generates JSON Schema and UI Schema from a named type within an existing
293
+ * TypeScript program supplied by the caller.
294
+ *
295
+ * This low-level entry point lets downstream tooling reuse a host-owned
296
+ * `Program` for both FormSpec extraction and other TypeScript analysis.
297
+ */
298
+ /**
299
+ * Generates JSON Schema and UI Schema from a named type within an existing
300
+ * TypeScript program and throws when generation reports error-severity diagnostics.
301
+ *
302
+ * @param options - Host program, file path, type name, and explicit throw-on-error reporting
303
+ * @returns Generated JSON Schema and UI Schema
304
+ *
305
+ * @public
306
+ */
307
+ export declare function generateSchemasFromProgram(options: GenerateSchemasFromProgramOptions & {
308
+ readonly errorReporting: "throw";
309
+ }): GenerateFromClassResult;
310
+ /**
311
+ * Generates JSON Schema and UI Schema from a named type within an existing
312
+ * TypeScript program and returns structured diagnostics instead of throwing on
313
+ * validation or analysis failures.
314
+ *
315
+ * @param options - Host program, file path, type name, and explicit diagnostics reporting
316
+ * @returns Structured generation result with diagnostics
317
+ *
318
+ * @public
319
+ */
320
+ export declare function generateSchemasFromProgram(options: GenerateSchemasFromProgramOptions & {
321
+ readonly errorReporting: "diagnostics";
322
+ }): DetailedClassSchemasResult;
323
+ /**
324
+ * Generates JSON Schema and UI Schema from a named type within an existing
325
+ * TypeScript program.
326
+ *
327
+ * @deprecated Pass `errorReporting` explicitly. Omitting it defaults to `"throw"` only for backward compatibility.
328
+ * @param options - Host program, file path, and type name
329
+ * @returns Generated JSON Schema and UI Schema
330
+ *
331
+ * @public
332
+ */
333
+ export declare function generateSchemasFromProgram(options: StaticSchemaGenerationOptions & {
334
+ readonly program: ts.Program;
335
+ readonly filePath: string;
336
+ readonly typeName: string;
337
+ }): GenerateFromClassResult;
338
+ /**
339
+ * Generates JSON Schema and UI Schema from a named type and returns structured
340
+ * diagnostics instead of throwing on validation or analysis failures.
341
+ * @deprecated Use `generateSchemas({ ...options, errorReporting: "diagnostics" })` instead.
342
+ *
343
+ * @public
344
+ */
345
+ export declare function generateSchemasDetailed(options: StaticSchemaGenerationOptions & {
346
+ readonly filePath: string;
347
+ readonly typeName: string;
348
+ }): DetailedClassSchemasResult;
349
+ /**
350
+ * Generates JSON Schema and UI Schema from a named type within an existing
351
+ * TypeScript program and returns structured diagnostics instead of throwing on
352
+ * validation or analysis failures.
353
+ * @deprecated Use `generateSchemasFromProgram({ ...options, errorReporting: "diagnostics" })` instead.
354
+ *
355
+ * @public
356
+ */
357
+ export declare function generateSchemasFromProgramDetailed(options: StaticSchemaGenerationOptions & {
358
+ readonly program: ts.Program;
359
+ readonly filePath: string;
360
+ readonly typeName: string;
361
+ }): DetailedClassSchemasResult;
362
+ /**
363
+ * Generates schemas for many targets and returns per-target diagnostics instead
364
+ * of failing on the first problem.
365
+ *
366
+ * @public
367
+ */
368
+ export declare function generateSchemasBatch(options: GenerateSchemasBatchOptions): readonly DetailedSchemaGenerationTargetResult[];
369
+ /**
370
+ * Generates schemas for many targets from an existing TypeScript program and
371
+ * returns per-target diagnostics instead of failing on the first problem.
372
+ *
373
+ * @public
374
+ */
375
+ export declare function generateSchemasBatchFromProgram(options: GenerateSchemasBatchFromProgramOptions): readonly DetailedSchemaGenerationTargetResult[];
376
+ /**
377
+ * Resolves the effective extension registry, vendor prefix, enum serialization,
378
+ * and metadata from a `StaticSchemaGenerationOptions` object.
379
+ *
380
+ * Prefers explicit deprecated fields when present, falling back to the
381
+ * `config` object. This is the migration bridge — once all callers use
382
+ * `config`, the deprecated field reads can be removed.
383
+ *
384
+ * @internal
385
+ */
386
+ export declare function resolveStaticOptions(options: StaticSchemaGenerationOptions): {
387
+ extensionRegistry: ExtensionRegistry | undefined;
388
+ vendorPrefix: string | undefined;
389
+ enumSerialization: "enum" | "oneOf" | undefined;
390
+ metadata: MetadataPolicyInput | undefined;
391
+ };
392
+ //# sourceMappingURL=class-schema.d.ts.map