@formspec/build 0.1.0-alpha.31 → 0.1.0-alpha.32

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.
@@ -0,0 +1,112 @@
1
+ import * as ts from "typescript";
2
+ import type { UISchema } from "../ui-schema/types.js";
3
+ import type { StaticBuildContext } from "../static-build.js";
4
+ import { type StaticSchemaGenerationOptions } from "./class-schema.js";
5
+ import { type JsonSchema2020 } from "../json-schema/ir-generator.js";
6
+ /**
7
+ * Generated schemas for a discovered declaration or signature type.
8
+ *
9
+ * `uiSchema` is `null` when the discovered type does not have an object-shaped
10
+ * root that can be represented as a JSON Forms layout.
11
+ *
12
+ * @public
13
+ */
14
+ export interface DiscoveredTypeSchemas {
15
+ /** JSON Schema 2020-12 for the resolved type. */
16
+ readonly jsonSchema: JsonSchema2020;
17
+ /** UI Schema for object-shaped roots, or `null` when not applicable. */
18
+ readonly uiSchema: UISchema | null;
19
+ }
20
+ /**
21
+ * Supported declaration kinds for declaration-driven schema generation.
22
+ *
23
+ * @public
24
+ */
25
+ export type SchemaSourceDeclaration = ts.ClassDeclaration | ts.InterfaceDeclaration | ts.TypeAliasDeclaration;
26
+ /**
27
+ * Options for generating schemas from a resolved declaration.
28
+ *
29
+ * @public
30
+ */
31
+ export interface GenerateSchemasFromDeclarationOptions extends StaticSchemaGenerationOptions {
32
+ /** Supported build context used for checker access and related analysis. */
33
+ readonly context: StaticBuildContext;
34
+ /** Declaration to turn into schemas. */
35
+ readonly declaration: SchemaSourceDeclaration;
36
+ }
37
+ /**
38
+ * Options for generating schemas from a resolved TypeScript type.
39
+ *
40
+ * @public
41
+ */
42
+ export interface GenerateSchemasFromTypeOptions extends StaticSchemaGenerationOptions {
43
+ /** Supported build context used for checker access and related analysis. */
44
+ readonly context: StaticBuildContext;
45
+ /** TypeScript type to turn into schemas. */
46
+ readonly type: ts.Type;
47
+ /**
48
+ * Optional source node associated with the type.
49
+ *
50
+ * When provided, FormSpec uses it as the source location for provenance and
51
+ * inline-type analysis.
52
+ */
53
+ readonly sourceNode?: ts.Node | undefined;
54
+ /** Optional logical name used for anonymous roots. */
55
+ readonly name?: string | undefined;
56
+ }
57
+ /**
58
+ * Options for generating schemas from a method or function parameter type.
59
+ *
60
+ * @public
61
+ */
62
+ export interface GenerateSchemasFromParameterOptions extends StaticSchemaGenerationOptions {
63
+ /** Supported build context used for checker access and related analysis. */
64
+ readonly context: StaticBuildContext;
65
+ /** Parameter declaration whose type should be converted into schemas. */
66
+ readonly parameter: ts.ParameterDeclaration;
67
+ }
68
+ /**
69
+ * Options for generating schemas from a method or function return type.
70
+ *
71
+ * @public
72
+ */
73
+ export interface GenerateSchemasFromReturnTypeOptions extends StaticSchemaGenerationOptions {
74
+ /** Supported build context used for checker access and related analysis. */
75
+ readonly context: StaticBuildContext;
76
+ /** Signature declaration whose return type should be converted into schemas. */
77
+ readonly declaration: ts.SignatureDeclaration;
78
+ }
79
+ /**
80
+ * Generates schemas from a resolved declaration using the supported public
81
+ * static-build workflow.
82
+ *
83
+ * Named declarations reuse the same analyzer semantics as FormSpec's existing
84
+ * top-level generation APIs. Non-object type aliases fall back to the generic
85
+ * resolved-type entry point.
86
+ *
87
+ * @public
88
+ */
89
+ export declare function generateSchemasFromDeclaration(options: GenerateSchemasFromDeclarationOptions): DiscoveredTypeSchemas;
90
+ /**
91
+ * Generates schemas from a resolved TypeScript type.
92
+ *
93
+ * This is the advanced public entry point for build tooling that already uses
94
+ * the TypeScript compiler API to discover types before handing them to
95
+ * FormSpec.
96
+ *
97
+ * @public
98
+ */
99
+ export declare function generateSchemasFromType(options: GenerateSchemasFromTypeOptions): DiscoveredTypeSchemas;
100
+ /**
101
+ * Generates schemas for a method or function parameter type.
102
+ *
103
+ * @public
104
+ */
105
+ export declare function generateSchemasFromParameter(options: GenerateSchemasFromParameterOptions): DiscoveredTypeSchemas;
106
+ /**
107
+ * Generates schemas for a method or function return type.
108
+ *
109
+ * @public
110
+ */
111
+ export declare function generateSchemasFromReturnType(options: GenerateSchemasFromReturnTypeOptions): DiscoveredTypeSchemas;
112
+ //# sourceMappingURL=discovered-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discovered-schema.d.ts","sourceRoot":"","sources":["../../src/generators/discovered-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAQjC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAS7D,OAAO,EAGL,KAAK,6BAA6B,EACnC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAA4B,KAAK,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAK/F;;;;;;;GAOG;AACH,MAAM,WAAW,qBAAqB;IACpC,iDAAiD;IACjD,QAAQ,CAAC,UAAU,EAAE,cAAc,CAAC;IACpC,wEAAwE;IACxE,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;CACpC;AAED;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,GAC/B,EAAE,CAAC,gBAAgB,GACnB,EAAE,CAAC,oBAAoB,GACvB,EAAE,CAAC,oBAAoB,CAAC;AAE5B;;;;GAIG;AACH,MAAM,WAAW,qCAAsC,SAAQ,6BAA6B;IAC1F,4EAA4E;IAC5E,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACrC,wCAAwC;IACxC,QAAQ,CAAC,WAAW,EAAE,uBAAuB,CAAC;CAC/C;AAED;;;;GAIG;AACH,MAAM,WAAW,8BAA+B,SAAQ,6BAA6B;IACnF,4EAA4E;IAC5E,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACrC,4CAA4C;IAC5C,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC;IACvB;;;;;OAKG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC,IAAI,GAAG,SAAS,CAAC;IAC1C,sDAAsD;IACtD,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACpC;AAED;;;;GAIG;AACH,MAAM,WAAW,mCAAoC,SAAQ,6BAA6B;IACxF,4EAA4E;IAC5E,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACrC,yEAAyE;IACzE,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC,oBAAoB,CAAC;CAC7C;AAED;;;;GAIG;AACH,MAAM,WAAW,oCAAqC,SAAQ,6BAA6B;IACzF,4EAA4E;IAC5E,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACrC,gFAAgF;IAChF,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC,oBAAoB,CAAC;CAC/C;AAwSD;;;;;;;;;GASG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,qCAAqC,GAC7C,qBAAqB,CA4EvB;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,8BAA8B,GACtC,qBAAqB,CAEvB;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,mCAAmC,GAC3C,qBAAqB,CAOvB;AAED;;;;GAIG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,oCAAoC,GAC5C,qBAAqB,CAkBvB"}
package/dist/index.cjs CHANGED
@@ -33,12 +33,20 @@ __export(index_exports, {
33
33
  buildFormSchemas: () => buildFormSchemas,
34
34
  buildMixedAuthoringSchemas: () => buildMixedAuthoringSchemas,
35
35
  createExtensionRegistry: () => createExtensionRegistry,
36
+ createStaticBuildContext: () => createStaticBuildContext,
37
+ createStaticBuildContextFromProgram: () => createStaticBuildContextFromProgram,
36
38
  generateJsonSchema: () => generateJsonSchema,
37
39
  generateSchemas: () => generateSchemas,
38
40
  generateSchemasFromClass: () => generateSchemasFromClass,
41
+ generateSchemasFromDeclaration: () => generateSchemasFromDeclaration,
42
+ generateSchemasFromParameter: () => generateSchemasFromParameter,
39
43
  generateSchemasFromProgram: () => generateSchemasFromProgram,
44
+ generateSchemasFromReturnType: () => generateSchemasFromReturnType,
45
+ generateSchemasFromType: () => generateSchemasFromType,
40
46
  generateUiSchema: () => generateUiSchema,
41
47
  jsonSchema7Schema: () => jsonSchema7Schema,
48
+ resolveModuleExport: () => resolveModuleExport,
49
+ resolveModuleExportDeclaration: () => resolveModuleExportDeclaration,
42
50
  uiSchemaSchema: () => uiSchema,
43
51
  writeSchemas: () => writeSchemas
44
52
  });
@@ -2907,6 +2915,27 @@ function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node,
2907
2915
  makeMetadataContext("tsdoc", declarationKind, logicalName, buildContext)
2908
2916
  );
2909
2917
  }
2918
+ function analyzeDeclarationRootInfo(declaration, checker, file = "", extensionRegistry, metadataPolicy) {
2919
+ const normalizedMetadataPolicy = normalizeMetadataPolicy(metadataPolicy);
2920
+ const declarationType = checker.getTypeAtLocation(declaration);
2921
+ const logicalName = ts3.isClassDeclaration(declaration) ? declaration.name?.text ?? "AnonymousClass" : declaration.name.text;
2922
+ const docResult = extractJSDocParseResult(
2923
+ declaration,
2924
+ file,
2925
+ makeParseOptions(extensionRegistry, void 0, checker, declarationType, declarationType)
2926
+ );
2927
+ const metadata = resolveNodeMetadata(normalizedMetadataPolicy, "type", logicalName, declaration, {
2928
+ checker,
2929
+ declaration,
2930
+ subjectType: declarationType,
2931
+ hostType: declarationType
2932
+ });
2933
+ return {
2934
+ ...metadata !== void 0 && { metadata },
2935
+ annotations: docResult.annotations,
2936
+ diagnostics: docResult.diagnostics
2937
+ };
2938
+ }
2910
2939
  function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, metadataPolicy) {
2911
2940
  const normalizedMetadataPolicy = normalizeMetadataPolicy(metadataPolicy);
2912
2941
  const name = classDecl.name?.text ?? "AnonymousClass";
@@ -3321,10 +3350,7 @@ function resolveLiteralDiscriminatorPropertyValue(boundType, fieldName, checker,
3321
3350
  if (resolvedAnchorNode === null) {
3322
3351
  return void 0;
3323
3352
  }
3324
- const propertyType = checker.getTypeOfSymbolAtLocation(
3325
- propertySymbol,
3326
- resolvedAnchorNode
3327
- );
3353
+ const propertyType = checker.getTypeOfSymbolAtLocation(propertySymbol, resolvedAnchorNode);
3328
3354
  if (propertyType.isStringLiteral()) {
3329
3355
  return propertyType.value;
3330
3356
  }
@@ -4283,14 +4309,39 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
4283
4309
  collectedDiagnostics
4284
4310
  );
4285
4311
  const fieldNodeInfo = fieldInfoMap?.get(prop.name);
4312
+ const inlineFieldNodeInfo = fieldNodeInfo === void 0 ? ts3.isPropertySignature(declaration) ? analyzeInterfacePropertyToIR(
4313
+ declaration,
4314
+ checker,
4315
+ file,
4316
+ typeRegistry,
4317
+ visiting,
4318
+ collectedDiagnostics,
4319
+ type,
4320
+ metadataPolicy,
4321
+ extensionRegistry
4322
+ ) : ts3.isPropertyDeclaration(declaration) ? analyzeFieldToIR(
4323
+ declaration,
4324
+ checker,
4325
+ file,
4326
+ typeRegistry,
4327
+ visiting,
4328
+ collectedDiagnostics,
4329
+ type,
4330
+ metadataPolicy,
4331
+ extensionRegistry
4332
+ ) : null : null;
4333
+ const resolvedFieldNodeInfo = fieldNodeInfo ?? inlineFieldNodeInfo;
4334
+ const resolvedPropertyType = inlineFieldNodeInfo?.type ?? propTypeNode;
4286
4335
  properties.push({
4287
4336
  name: prop.name,
4288
- ...fieldNodeInfo?.metadata !== void 0 && { metadata: fieldNodeInfo.metadata },
4289
- type: propTypeNode,
4337
+ ...resolvedFieldNodeInfo?.metadata !== void 0 && {
4338
+ metadata: resolvedFieldNodeInfo.metadata
4339
+ },
4340
+ type: resolvedPropertyType,
4290
4341
  optional,
4291
- constraints: fieldNodeInfo?.constraints ?? [],
4292
- annotations: fieldNodeInfo?.annotations ?? [],
4293
- provenance: fieldNodeInfo?.provenance ?? provenanceForFile(file)
4342
+ constraints: resolvedFieldNodeInfo?.constraints ?? [],
4343
+ annotations: resolvedFieldNodeInfo?.annotations ?? [],
4344
+ provenance: resolvedFieldNodeInfo?.provenance ?? provenanceForFile(file)
4294
4345
  });
4295
4346
  }
4296
4347
  visiting.delete(type);
@@ -4886,6 +4937,345 @@ function generateSchemasFromProgram(options) {
4886
4937
  );
4887
4938
  }
4888
4939
 
4940
+ // src/static-build.ts
4941
+ var ts6 = __toESM(require("typescript"), 1);
4942
+ function toStaticBuildContext(context) {
4943
+ return context;
4944
+ }
4945
+ function createStaticBuildContext(filePath) {
4946
+ return toStaticBuildContext(createProgramContext(filePath));
4947
+ }
4948
+ function createStaticBuildContextFromProgram(program, filePath) {
4949
+ return toStaticBuildContext(createProgramContextFromProgram(program, filePath));
4950
+ }
4951
+ function getModuleSymbol(context) {
4952
+ const sourceFileWithSymbol = context.sourceFile;
4953
+ return context.checker.getSymbolAtLocation(context.sourceFile) ?? sourceFileWithSymbol.symbol;
4954
+ }
4955
+ function isSchemaSourceDeclaration(declaration) {
4956
+ return ts6.isClassDeclaration(declaration) || ts6.isInterfaceDeclaration(declaration) || ts6.isTypeAliasDeclaration(declaration);
4957
+ }
4958
+ function resolveModuleExport(context, exportName = "default") {
4959
+ const moduleSymbol = getModuleSymbol(context);
4960
+ if (moduleSymbol === void 0) {
4961
+ return null;
4962
+ }
4963
+ const exportSymbol = context.checker.getExportsOfModule(moduleSymbol).find((candidate) => candidate.name === exportName) ?? null;
4964
+ if (exportSymbol === null) {
4965
+ return null;
4966
+ }
4967
+ return exportSymbol.flags & ts6.SymbolFlags.Alias ? context.checker.getAliasedSymbol(exportSymbol) : exportSymbol;
4968
+ }
4969
+ function resolveModuleExportDeclaration(context, exportName = "default") {
4970
+ return resolveModuleExport(context, exportName)?.declarations?.find(isSchemaSourceDeclaration) ?? null;
4971
+ }
4972
+
4973
+ // src/generators/discovered-schema.ts
4974
+ var ts7 = __toESM(require("typescript"), 1);
4975
+ var import_internals5 = require("@formspec/core/internals");
4976
+ function toDiscoveredTypeSchemas(result) {
4977
+ return result;
4978
+ }
4979
+ function isNamedTypeDeclaration(declaration) {
4980
+ return ts7.isClassDeclaration(declaration) || ts7.isInterfaceDeclaration(declaration) || ts7.isTypeAliasDeclaration(declaration);
4981
+ }
4982
+ function hasConcreteTypeArguments(type, checker) {
4983
+ if ("aliasTypeArguments" in type && Array.isArray(type.aliasTypeArguments) && type.aliasTypeArguments.length > 0) {
4984
+ return true;
4985
+ }
4986
+ if ((type.flags & ts7.TypeFlags.Object) === 0) {
4987
+ return false;
4988
+ }
4989
+ const objectType = type;
4990
+ if ((objectType.objectFlags & ts7.ObjectFlags.Reference) === 0) {
4991
+ return false;
4992
+ }
4993
+ return checker.getTypeArguments(objectType).length > 0;
4994
+ }
4995
+ function getNamedTypeDeclaration2(type) {
4996
+ const symbol = type.getSymbol();
4997
+ if (symbol?.declarations !== void 0) {
4998
+ const declaration = symbol.declarations[0];
4999
+ if (declaration !== void 0 && isNamedTypeDeclaration(declaration)) {
5000
+ return declaration;
5001
+ }
5002
+ }
5003
+ const aliasDeclaration = type.aliasSymbol?.declarations?.find(ts7.isTypeAliasDeclaration);
5004
+ return aliasDeclaration;
5005
+ }
5006
+ function getFallbackName(sourceNode, fallback = "AnonymousType") {
5007
+ if (sourceNode !== void 0 && "name" in sourceNode) {
5008
+ const namedNode = sourceNode;
5009
+ if (namedNode.name !== void 0 && ts7.isIdentifier(namedNode.name)) {
5010
+ return namedNode.name.text;
5011
+ }
5012
+ }
5013
+ return fallback;
5014
+ }
5015
+ function createObjectRootAnalysis(name, properties, typeRegistry, metadata, annotations) {
5016
+ const fields = properties.map((property) => ({
5017
+ kind: "field",
5018
+ name: property.name,
5019
+ ...property.metadata !== void 0 && { metadata: property.metadata },
5020
+ type: property.type,
5021
+ required: !property.optional,
5022
+ constraints: property.constraints,
5023
+ annotations: property.annotations,
5024
+ provenance: property.provenance
5025
+ }));
5026
+ return {
5027
+ name,
5028
+ ...metadata !== void 0 && { metadata },
5029
+ fields,
5030
+ fieldLayouts: fields.map(() => ({})),
5031
+ typeRegistry,
5032
+ ...annotations !== void 0 && annotations.length > 0 && { annotations },
5033
+ instanceMethods: [],
5034
+ staticMethods: [],
5035
+ diagnostics: []
5036
+ };
5037
+ }
5038
+ function omitApiName(metadata) {
5039
+ if (metadata?.apiName === void 0) {
5040
+ return metadata;
5041
+ }
5042
+ const { apiName: _apiName, ...rest } = metadata;
5043
+ return Object.keys(rest).length > 0 ? rest : void 0;
5044
+ }
5045
+ function describeRootType(rootType, typeRegistry, fallbackName) {
5046
+ if (rootType.kind !== "reference") {
5047
+ return {
5048
+ name: fallbackName,
5049
+ type: rootType
5050
+ };
5051
+ }
5052
+ const definition = typeRegistry[rootType.name];
5053
+ if (definition === void 0) {
5054
+ return {
5055
+ name: rootType.name,
5056
+ type: rootType
5057
+ };
5058
+ }
5059
+ return {
5060
+ name: definition.name,
5061
+ ...definition.metadata !== void 0 && { metadata: definition.metadata },
5062
+ ...definition.annotations !== void 0 && definition.annotations.length > 0 && { annotations: definition.annotations },
5063
+ type: definition.type
5064
+ };
5065
+ }
5066
+ function toStandaloneJsonSchema(root, typeRegistry, options) {
5067
+ const syntheticFieldMetadata = omitApiName(root.metadata);
5068
+ const syntheticField = {
5069
+ kind: "field",
5070
+ name: "__result",
5071
+ ...syntheticFieldMetadata !== void 0 && { metadata: syntheticFieldMetadata },
5072
+ type: root.type,
5073
+ required: true,
5074
+ constraints: [],
5075
+ annotations: [...root.annotations ?? []],
5076
+ provenance: {
5077
+ surface: "tsdoc",
5078
+ file: "",
5079
+ line: 1,
5080
+ column: 0
5081
+ }
5082
+ };
5083
+ const schema = generateJsonSchemaFromIR(
5084
+ {
5085
+ kind: "form-ir",
5086
+ name: root.name,
5087
+ irVersion: import_internals5.IR_VERSION,
5088
+ elements: [syntheticField],
5089
+ ...root.metadata !== void 0 && { metadata: root.metadata },
5090
+ ...root.annotations !== void 0 && root.annotations.length > 0 && { rootAnnotations: root.annotations },
5091
+ typeRegistry,
5092
+ provenance: syntheticField.provenance
5093
+ },
5094
+ {
5095
+ extensionRegistry: options?.extensionRegistry,
5096
+ vendorPrefix: options?.vendorPrefix
5097
+ }
5098
+ );
5099
+ const result = schema.properties?.["__result"];
5100
+ if (result === void 0) {
5101
+ throw new Error("FormSpec failed to extract the standalone schema root from the synthetic IR.");
5102
+ }
5103
+ if (schema.$defs === void 0 || Object.keys(schema.$defs).length === 0) {
5104
+ return {
5105
+ ...schema.$schema !== void 0 && { $schema: schema.$schema },
5106
+ ...result
5107
+ };
5108
+ }
5109
+ return {
5110
+ ...schema.$schema !== void 0 && { $schema: schema.$schema },
5111
+ ...result,
5112
+ $defs: schema.$defs
5113
+ };
5114
+ }
5115
+ function generateSchemasFromAnalysis(analysis, filePath, options) {
5116
+ return toDiscoveredTypeSchemas(
5117
+ generateClassSchemas(
5118
+ analysis,
5119
+ { file: filePath },
5120
+ {
5121
+ extensionRegistry: options?.extensionRegistry,
5122
+ metadata: options?.metadata,
5123
+ vendorPrefix: options?.vendorPrefix
5124
+ }
5125
+ )
5126
+ );
5127
+ }
5128
+ function generateSchemasFromResolvedType(options, skipNamedDeclaration = false, rootOverride) {
5129
+ const namedDeclaration = skipNamedDeclaration || hasConcreteTypeArguments(options.type, options.context.checker) ? void 0 : getNamedTypeDeclaration2(options.type);
5130
+ if (namedDeclaration !== void 0) {
5131
+ return generateSchemasFromDeclaration({
5132
+ ...options,
5133
+ declaration: namedDeclaration
5134
+ });
5135
+ }
5136
+ const filePath = options.sourceNode?.getSourceFile().fileName ?? options.context.sourceFile.fileName;
5137
+ const typeRegistry = {};
5138
+ const diagnostics = [];
5139
+ const rootType = resolveTypeNode(
5140
+ options.type,
5141
+ options.context.checker,
5142
+ filePath,
5143
+ typeRegistry,
5144
+ /* @__PURE__ */ new Set(),
5145
+ options.sourceNode,
5146
+ normalizeMetadataPolicy(options.metadata),
5147
+ options.extensionRegistry,
5148
+ diagnostics
5149
+ );
5150
+ if (diagnostics.length > 0) {
5151
+ const diagnosticDetails = diagnostics.map((diagnostic) => `${diagnostic.code}: ${diagnostic.message}`).join("; ");
5152
+ throw new Error(
5153
+ `FormSpec validation failed while generating discovered type schemas. ${diagnosticDetails}`
5154
+ );
5155
+ }
5156
+ const describedRoot = describeRootType(
5157
+ rootType,
5158
+ typeRegistry,
5159
+ options.name ?? getFallbackName(options.sourceNode)
5160
+ );
5161
+ const mergedMetadata = mergeResolvedMetadata(describedRoot.metadata, rootOverride?.metadata);
5162
+ const root = {
5163
+ ...describedRoot,
5164
+ ...rootOverride?.name !== void 0 && { name: rootOverride.name },
5165
+ ...mergedMetadata !== void 0 && { metadata: mergedMetadata },
5166
+ ...rootOverride?.annotations !== void 0 && { annotations: rootOverride.annotations }
5167
+ };
5168
+ if (root.type.kind === "object") {
5169
+ return generateSchemasFromAnalysis(
5170
+ createObjectRootAnalysis(
5171
+ options.name ?? root.name,
5172
+ root.type.properties,
5173
+ typeRegistry,
5174
+ root.metadata,
5175
+ root.annotations
5176
+ ),
5177
+ filePath,
5178
+ options
5179
+ );
5180
+ }
5181
+ return {
5182
+ jsonSchema: toStandaloneJsonSchema(root, typeRegistry, options),
5183
+ uiSchema: null
5184
+ };
5185
+ }
5186
+ function generateSchemasFromDeclaration(options) {
5187
+ const filePath = options.declaration.getSourceFile().fileName;
5188
+ if (ts7.isClassDeclaration(options.declaration)) {
5189
+ return generateSchemasFromAnalysis(
5190
+ analyzeClassToIR(
5191
+ options.declaration,
5192
+ options.context.checker,
5193
+ filePath,
5194
+ options.extensionRegistry,
5195
+ options.metadata
5196
+ ),
5197
+ filePath,
5198
+ options
5199
+ );
5200
+ }
5201
+ if (ts7.isInterfaceDeclaration(options.declaration)) {
5202
+ return generateSchemasFromAnalysis(
5203
+ analyzeInterfaceToIR(
5204
+ options.declaration,
5205
+ options.context.checker,
5206
+ filePath,
5207
+ options.extensionRegistry,
5208
+ options.metadata
5209
+ ),
5210
+ filePath,
5211
+ options
5212
+ );
5213
+ }
5214
+ if (ts7.isTypeAliasDeclaration(options.declaration)) {
5215
+ const analyzedAlias = analyzeTypeAliasToIR(
5216
+ options.declaration,
5217
+ options.context.checker,
5218
+ filePath,
5219
+ options.extensionRegistry,
5220
+ options.metadata
5221
+ );
5222
+ if (analyzedAlias.ok) {
5223
+ return generateSchemasFromAnalysis(analyzedAlias.analysis, filePath, options);
5224
+ }
5225
+ const aliasRootInfo = analyzeDeclarationRootInfo(
5226
+ options.declaration,
5227
+ options.context.checker,
5228
+ filePath,
5229
+ options.extensionRegistry,
5230
+ options.metadata
5231
+ );
5232
+ if (aliasRootInfo.diagnostics.length > 0) {
5233
+ const diagnosticDetails = aliasRootInfo.diagnostics.map((diagnostic) => `${diagnostic.code}: ${diagnostic.message}`).join("; ");
5234
+ throw new Error(
5235
+ `FormSpec validation failed while generating discovered type schemas. ${diagnosticDetails}`
5236
+ );
5237
+ }
5238
+ return generateSchemasFromResolvedType(
5239
+ {
5240
+ ...options,
5241
+ type: options.context.checker.getTypeAtLocation(options.declaration),
5242
+ sourceNode: options.declaration,
5243
+ name: options.declaration.name.text
5244
+ },
5245
+ true,
5246
+ {
5247
+ name: options.declaration.name.text,
5248
+ ...aliasRootInfo.metadata !== void 0 && { metadata: aliasRootInfo.metadata },
5249
+ ...aliasRootInfo.annotations.length > 0 && { annotations: aliasRootInfo.annotations }
5250
+ }
5251
+ );
5252
+ }
5253
+ const _exhaustive = options.declaration;
5254
+ return _exhaustive;
5255
+ }
5256
+ function generateSchemasFromType(options) {
5257
+ return generateSchemasFromResolvedType(options);
5258
+ }
5259
+ function generateSchemasFromParameter(options) {
5260
+ return generateSchemasFromResolvedType({
5261
+ ...options,
5262
+ type: options.context.checker.getTypeAtLocation(options.parameter),
5263
+ sourceNode: options.parameter,
5264
+ name: getFallbackName(options.parameter, "Parameter")
5265
+ });
5266
+ }
5267
+ function generateSchemasFromReturnType(options) {
5268
+ const signature = options.context.checker.getSignatureFromDeclaration(options.declaration);
5269
+ const type = signature !== void 0 ? options.context.checker.getReturnTypeOfSignature(signature) : options.context.checker.getTypeAtLocation(options.declaration);
5270
+ const fallbackName = options.declaration.name !== void 0 && ts7.isIdentifier(options.declaration.name) ? `${options.declaration.name.text}ReturnType` : "ReturnType";
5271
+ return generateSchemasFromResolvedType({
5272
+ ...options,
5273
+ type,
5274
+ sourceNode: options.declaration.type ?? options.declaration,
5275
+ name: fallbackName
5276
+ });
5277
+ }
5278
+
4889
5279
  // src/generators/mixed-authoring.ts
4890
5280
  function buildMixedAuthoringSchemas(options) {
4891
5281
  const { filePath, typeName, overlays, ...schemaOptions } = options;
@@ -5101,12 +5491,20 @@ function writeSchemas(form, options) {
5101
5491
  buildFormSchemas,
5102
5492
  buildMixedAuthoringSchemas,
5103
5493
  createExtensionRegistry,
5494
+ createStaticBuildContext,
5495
+ createStaticBuildContextFromProgram,
5104
5496
  generateJsonSchema,
5105
5497
  generateSchemas,
5106
5498
  generateSchemasFromClass,
5499
+ generateSchemasFromDeclaration,
5500
+ generateSchemasFromParameter,
5107
5501
  generateSchemasFromProgram,
5502
+ generateSchemasFromReturnType,
5503
+ generateSchemasFromType,
5108
5504
  generateUiSchema,
5109
5505
  jsonSchema7Schema,
5506
+ resolveModuleExport,
5507
+ resolveModuleExportDeclaration,
5110
5508
  uiSchemaSchema,
5111
5509
  writeSchemas
5112
5510
  });