@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.
- package/README.md +82 -5
- package/dist/analyzer/class-analyzer.d.ts +6 -0
- package/dist/analyzer/class-analyzer.d.ts.map +1 -1
- package/dist/build-alpha.d.ts +180 -0
- package/dist/build-beta.d.ts +180 -0
- package/dist/build-internal.d.ts +180 -0
- package/dist/build.d.ts +180 -0
- package/dist/cli.cjs +418 -9
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +416 -9
- package/dist/cli.js.map +1 -1
- package/dist/generators/discovered-schema.d.ts +112 -0
- package/dist/generators/discovered-schema.d.ts.map +1 -0
- package/dist/index.cjs +407 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +399 -9
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +31 -9
- package/dist/internals.cjs.map +1 -1
- package/dist/internals.js +31 -9
- package/dist/internals.js.map +1 -1
- package/dist/static-build.d.ts +61 -0
- package/dist/static-build.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -36,12 +36,16 @@ export { createExtensionRegistry } from "./extensions/index.js";
|
|
|
36
36
|
export type { ExtensionRegistry } from "./extensions/index.js";
|
|
37
37
|
export type { UISchema, UISchemaElement, UISchemaElementBase, UISchemaElementType, ControlElement, VerticalLayout, HorizontalLayout, GroupLayout, Categorization, Category, LabelElement, Rule, RuleEffect, RuleConditionSchema, SchemaBasedCondition, } from "./ui-schema/types.js";
|
|
38
38
|
export type { GenerateFromClassOptions, GenerateFromClassResult, GenerateSchemasOptions, GenerateSchemasFromProgramOptions, StaticSchemaGenerationOptions, } from "./generators/class-schema.js";
|
|
39
|
+
export type { StaticBuildContext } from "./static-build.js";
|
|
40
|
+
export type { DiscoveredTypeSchemas, GenerateSchemasFromDeclarationOptions, GenerateSchemasFromParameterOptions, GenerateSchemasFromReturnTypeOptions, GenerateSchemasFromTypeOptions, SchemaSourceDeclaration, } from "./generators/discovered-schema.js";
|
|
39
41
|
export type { BuildMixedAuthoringSchemasOptions, MixedAuthoringSchemas, } from "./generators/mixed-authoring.js";
|
|
40
42
|
export { jsonSchema7Schema } from "./json-schema/schema.js";
|
|
41
43
|
export { uiSchema as uiSchemaSchema } from "./ui-schema/schema.js";
|
|
42
44
|
export { generateJsonSchema } from "./json-schema/generator.js";
|
|
43
45
|
export { generateUiSchema } from "./ui-schema/generator.js";
|
|
44
46
|
export { generateSchemasFromClass, generateSchemas, generateSchemasFromProgram, } from "./generators/class-schema.js";
|
|
47
|
+
export { createStaticBuildContext, createStaticBuildContextFromProgram, resolveModuleExport, resolveModuleExportDeclaration, } from "./static-build.js";
|
|
48
|
+
export { generateSchemasFromDeclaration, generateSchemasFromParameter, generateSchemasFromReturnType, generateSchemasFromType, } from "./generators/discovered-schema.js";
|
|
45
49
|
export { buildMixedAuthoringSchemas } from "./generators/mixed-authoring.js";
|
|
46
50
|
/**
|
|
47
51
|
* Result of building form schemas.
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAsB,KAAK,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAChG,OAAO,EAAoB,KAAK,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAC1F,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAQrD,YAAY,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,YAAY,EAAE,yBAAy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", declarationKind, logicalName, buildContext)
|
|
2889
2889
|
);
|
|
2890
2890
|
}
|
|
2891
|
+
function analyzeDeclarationRootInfo(declaration, checker, file = "", extensionRegistry, metadataPolicy) {
|
|
2892
|
+
const normalizedMetadataPolicy = normalizeMetadataPolicy(metadataPolicy);
|
|
2893
|
+
const declarationType = checker.getTypeAtLocation(declaration);
|
|
2894
|
+
const logicalName = ts3.isClassDeclaration(declaration) ? declaration.name?.text ?? "AnonymousClass" : declaration.name.text;
|
|
2895
|
+
const docResult = extractJSDocParseResult(
|
|
2896
|
+
declaration,
|
|
2897
|
+
file,
|
|
2898
|
+
makeParseOptions(extensionRegistry, void 0, checker, declarationType, declarationType)
|
|
2899
|
+
);
|
|
2900
|
+
const metadata = resolveNodeMetadata(normalizedMetadataPolicy, "type", logicalName, declaration, {
|
|
2901
|
+
checker,
|
|
2902
|
+
declaration,
|
|
2903
|
+
subjectType: declarationType,
|
|
2904
|
+
hostType: declarationType
|
|
2905
|
+
});
|
|
2906
|
+
return {
|
|
2907
|
+
...metadata !== void 0 && { metadata },
|
|
2908
|
+
annotations: docResult.annotations,
|
|
2909
|
+
diagnostics: docResult.diagnostics
|
|
2910
|
+
};
|
|
2911
|
+
}
|
|
2891
2912
|
function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, metadataPolicy) {
|
|
2892
2913
|
const normalizedMetadataPolicy = normalizeMetadataPolicy(metadataPolicy);
|
|
2893
2914
|
const name = classDecl.name?.text ?? "AnonymousClass";
|
|
@@ -3302,10 +3323,7 @@ function resolveLiteralDiscriminatorPropertyValue(boundType, fieldName, checker,
|
|
|
3302
3323
|
if (resolvedAnchorNode === null) {
|
|
3303
3324
|
return void 0;
|
|
3304
3325
|
}
|
|
3305
|
-
const propertyType = checker.getTypeOfSymbolAtLocation(
|
|
3306
|
-
propertySymbol,
|
|
3307
|
-
resolvedAnchorNode
|
|
3308
|
-
);
|
|
3326
|
+
const propertyType = checker.getTypeOfSymbolAtLocation(propertySymbol, resolvedAnchorNode);
|
|
3309
3327
|
if (propertyType.isStringLiteral()) {
|
|
3310
3328
|
return propertyType.value;
|
|
3311
3329
|
}
|
|
@@ -4264,14 +4282,39 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4264
4282
|
collectedDiagnostics
|
|
4265
4283
|
);
|
|
4266
4284
|
const fieldNodeInfo = fieldInfoMap?.get(prop.name);
|
|
4285
|
+
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ? ts3.isPropertySignature(declaration) ? analyzeInterfacePropertyToIR(
|
|
4286
|
+
declaration,
|
|
4287
|
+
checker,
|
|
4288
|
+
file,
|
|
4289
|
+
typeRegistry,
|
|
4290
|
+
visiting,
|
|
4291
|
+
collectedDiagnostics,
|
|
4292
|
+
type,
|
|
4293
|
+
metadataPolicy,
|
|
4294
|
+
extensionRegistry
|
|
4295
|
+
) : ts3.isPropertyDeclaration(declaration) ? analyzeFieldToIR(
|
|
4296
|
+
declaration,
|
|
4297
|
+
checker,
|
|
4298
|
+
file,
|
|
4299
|
+
typeRegistry,
|
|
4300
|
+
visiting,
|
|
4301
|
+
collectedDiagnostics,
|
|
4302
|
+
type,
|
|
4303
|
+
metadataPolicy,
|
|
4304
|
+
extensionRegistry
|
|
4305
|
+
) : null : null;
|
|
4306
|
+
const resolvedFieldNodeInfo = fieldNodeInfo ?? inlineFieldNodeInfo;
|
|
4307
|
+
const resolvedPropertyType = inlineFieldNodeInfo?.type ?? propTypeNode;
|
|
4267
4308
|
properties.push({
|
|
4268
4309
|
name: prop.name,
|
|
4269
|
-
...
|
|
4270
|
-
|
|
4310
|
+
...resolvedFieldNodeInfo?.metadata !== void 0 && {
|
|
4311
|
+
metadata: resolvedFieldNodeInfo.metadata
|
|
4312
|
+
},
|
|
4313
|
+
type: resolvedPropertyType,
|
|
4271
4314
|
optional,
|
|
4272
|
-
constraints:
|
|
4273
|
-
annotations:
|
|
4274
|
-
provenance:
|
|
4315
|
+
constraints: resolvedFieldNodeInfo?.constraints ?? [],
|
|
4316
|
+
annotations: resolvedFieldNodeInfo?.annotations ?? [],
|
|
4317
|
+
provenance: resolvedFieldNodeInfo?.provenance ?? provenanceForFile(file)
|
|
4275
4318
|
});
|
|
4276
4319
|
}
|
|
4277
4320
|
visiting.delete(type);
|
|
@@ -4869,6 +4912,345 @@ function generateSchemasFromProgram(options) {
|
|
|
4869
4912
|
);
|
|
4870
4913
|
}
|
|
4871
4914
|
|
|
4915
|
+
// src/static-build.ts
|
|
4916
|
+
import * as ts6 from "typescript";
|
|
4917
|
+
function toStaticBuildContext(context) {
|
|
4918
|
+
return context;
|
|
4919
|
+
}
|
|
4920
|
+
function createStaticBuildContext(filePath) {
|
|
4921
|
+
return toStaticBuildContext(createProgramContext(filePath));
|
|
4922
|
+
}
|
|
4923
|
+
function createStaticBuildContextFromProgram(program, filePath) {
|
|
4924
|
+
return toStaticBuildContext(createProgramContextFromProgram(program, filePath));
|
|
4925
|
+
}
|
|
4926
|
+
function getModuleSymbol(context) {
|
|
4927
|
+
const sourceFileWithSymbol = context.sourceFile;
|
|
4928
|
+
return context.checker.getSymbolAtLocation(context.sourceFile) ?? sourceFileWithSymbol.symbol;
|
|
4929
|
+
}
|
|
4930
|
+
function isSchemaSourceDeclaration(declaration) {
|
|
4931
|
+
return ts6.isClassDeclaration(declaration) || ts6.isInterfaceDeclaration(declaration) || ts6.isTypeAliasDeclaration(declaration);
|
|
4932
|
+
}
|
|
4933
|
+
function resolveModuleExport(context, exportName = "default") {
|
|
4934
|
+
const moduleSymbol = getModuleSymbol(context);
|
|
4935
|
+
if (moduleSymbol === void 0) {
|
|
4936
|
+
return null;
|
|
4937
|
+
}
|
|
4938
|
+
const exportSymbol = context.checker.getExportsOfModule(moduleSymbol).find((candidate) => candidate.name === exportName) ?? null;
|
|
4939
|
+
if (exportSymbol === null) {
|
|
4940
|
+
return null;
|
|
4941
|
+
}
|
|
4942
|
+
return exportSymbol.flags & ts6.SymbolFlags.Alias ? context.checker.getAliasedSymbol(exportSymbol) : exportSymbol;
|
|
4943
|
+
}
|
|
4944
|
+
function resolveModuleExportDeclaration(context, exportName = "default") {
|
|
4945
|
+
return resolveModuleExport(context, exportName)?.declarations?.find(isSchemaSourceDeclaration) ?? null;
|
|
4946
|
+
}
|
|
4947
|
+
|
|
4948
|
+
// src/generators/discovered-schema.ts
|
|
4949
|
+
import * as ts7 from "typescript";
|
|
4950
|
+
import { IR_VERSION as IR_VERSION3 } from "@formspec/core/internals";
|
|
4951
|
+
function toDiscoveredTypeSchemas(result) {
|
|
4952
|
+
return result;
|
|
4953
|
+
}
|
|
4954
|
+
function isNamedTypeDeclaration(declaration) {
|
|
4955
|
+
return ts7.isClassDeclaration(declaration) || ts7.isInterfaceDeclaration(declaration) || ts7.isTypeAliasDeclaration(declaration);
|
|
4956
|
+
}
|
|
4957
|
+
function hasConcreteTypeArguments(type, checker) {
|
|
4958
|
+
if ("aliasTypeArguments" in type && Array.isArray(type.aliasTypeArguments) && type.aliasTypeArguments.length > 0) {
|
|
4959
|
+
return true;
|
|
4960
|
+
}
|
|
4961
|
+
if ((type.flags & ts7.TypeFlags.Object) === 0) {
|
|
4962
|
+
return false;
|
|
4963
|
+
}
|
|
4964
|
+
const objectType = type;
|
|
4965
|
+
if ((objectType.objectFlags & ts7.ObjectFlags.Reference) === 0) {
|
|
4966
|
+
return false;
|
|
4967
|
+
}
|
|
4968
|
+
return checker.getTypeArguments(objectType).length > 0;
|
|
4969
|
+
}
|
|
4970
|
+
function getNamedTypeDeclaration2(type) {
|
|
4971
|
+
const symbol = type.getSymbol();
|
|
4972
|
+
if (symbol?.declarations !== void 0) {
|
|
4973
|
+
const declaration = symbol.declarations[0];
|
|
4974
|
+
if (declaration !== void 0 && isNamedTypeDeclaration(declaration)) {
|
|
4975
|
+
return declaration;
|
|
4976
|
+
}
|
|
4977
|
+
}
|
|
4978
|
+
const aliasDeclaration = type.aliasSymbol?.declarations?.find(ts7.isTypeAliasDeclaration);
|
|
4979
|
+
return aliasDeclaration;
|
|
4980
|
+
}
|
|
4981
|
+
function getFallbackName(sourceNode, fallback = "AnonymousType") {
|
|
4982
|
+
if (sourceNode !== void 0 && "name" in sourceNode) {
|
|
4983
|
+
const namedNode = sourceNode;
|
|
4984
|
+
if (namedNode.name !== void 0 && ts7.isIdentifier(namedNode.name)) {
|
|
4985
|
+
return namedNode.name.text;
|
|
4986
|
+
}
|
|
4987
|
+
}
|
|
4988
|
+
return fallback;
|
|
4989
|
+
}
|
|
4990
|
+
function createObjectRootAnalysis(name, properties, typeRegistry, metadata, annotations) {
|
|
4991
|
+
const fields = properties.map((property) => ({
|
|
4992
|
+
kind: "field",
|
|
4993
|
+
name: property.name,
|
|
4994
|
+
...property.metadata !== void 0 && { metadata: property.metadata },
|
|
4995
|
+
type: property.type,
|
|
4996
|
+
required: !property.optional,
|
|
4997
|
+
constraints: property.constraints,
|
|
4998
|
+
annotations: property.annotations,
|
|
4999
|
+
provenance: property.provenance
|
|
5000
|
+
}));
|
|
5001
|
+
return {
|
|
5002
|
+
name,
|
|
5003
|
+
...metadata !== void 0 && { metadata },
|
|
5004
|
+
fields,
|
|
5005
|
+
fieldLayouts: fields.map(() => ({})),
|
|
5006
|
+
typeRegistry,
|
|
5007
|
+
...annotations !== void 0 && annotations.length > 0 && { annotations },
|
|
5008
|
+
instanceMethods: [],
|
|
5009
|
+
staticMethods: [],
|
|
5010
|
+
diagnostics: []
|
|
5011
|
+
};
|
|
5012
|
+
}
|
|
5013
|
+
function omitApiName(metadata) {
|
|
5014
|
+
if (metadata?.apiName === void 0) {
|
|
5015
|
+
return metadata;
|
|
5016
|
+
}
|
|
5017
|
+
const { apiName: _apiName, ...rest } = metadata;
|
|
5018
|
+
return Object.keys(rest).length > 0 ? rest : void 0;
|
|
5019
|
+
}
|
|
5020
|
+
function describeRootType(rootType, typeRegistry, fallbackName) {
|
|
5021
|
+
if (rootType.kind !== "reference") {
|
|
5022
|
+
return {
|
|
5023
|
+
name: fallbackName,
|
|
5024
|
+
type: rootType
|
|
5025
|
+
};
|
|
5026
|
+
}
|
|
5027
|
+
const definition = typeRegistry[rootType.name];
|
|
5028
|
+
if (definition === void 0) {
|
|
5029
|
+
return {
|
|
5030
|
+
name: rootType.name,
|
|
5031
|
+
type: rootType
|
|
5032
|
+
};
|
|
5033
|
+
}
|
|
5034
|
+
return {
|
|
5035
|
+
name: definition.name,
|
|
5036
|
+
...definition.metadata !== void 0 && { metadata: definition.metadata },
|
|
5037
|
+
...definition.annotations !== void 0 && definition.annotations.length > 0 && { annotations: definition.annotations },
|
|
5038
|
+
type: definition.type
|
|
5039
|
+
};
|
|
5040
|
+
}
|
|
5041
|
+
function toStandaloneJsonSchema(root, typeRegistry, options) {
|
|
5042
|
+
const syntheticFieldMetadata = omitApiName(root.metadata);
|
|
5043
|
+
const syntheticField = {
|
|
5044
|
+
kind: "field",
|
|
5045
|
+
name: "__result",
|
|
5046
|
+
...syntheticFieldMetadata !== void 0 && { metadata: syntheticFieldMetadata },
|
|
5047
|
+
type: root.type,
|
|
5048
|
+
required: true,
|
|
5049
|
+
constraints: [],
|
|
5050
|
+
annotations: [...root.annotations ?? []],
|
|
5051
|
+
provenance: {
|
|
5052
|
+
surface: "tsdoc",
|
|
5053
|
+
file: "",
|
|
5054
|
+
line: 1,
|
|
5055
|
+
column: 0
|
|
5056
|
+
}
|
|
5057
|
+
};
|
|
5058
|
+
const schema = generateJsonSchemaFromIR(
|
|
5059
|
+
{
|
|
5060
|
+
kind: "form-ir",
|
|
5061
|
+
name: root.name,
|
|
5062
|
+
irVersion: IR_VERSION3,
|
|
5063
|
+
elements: [syntheticField],
|
|
5064
|
+
...root.metadata !== void 0 && { metadata: root.metadata },
|
|
5065
|
+
...root.annotations !== void 0 && root.annotations.length > 0 && { rootAnnotations: root.annotations },
|
|
5066
|
+
typeRegistry,
|
|
5067
|
+
provenance: syntheticField.provenance
|
|
5068
|
+
},
|
|
5069
|
+
{
|
|
5070
|
+
extensionRegistry: options?.extensionRegistry,
|
|
5071
|
+
vendorPrefix: options?.vendorPrefix
|
|
5072
|
+
}
|
|
5073
|
+
);
|
|
5074
|
+
const result = schema.properties?.["__result"];
|
|
5075
|
+
if (result === void 0) {
|
|
5076
|
+
throw new Error("FormSpec failed to extract the standalone schema root from the synthetic IR.");
|
|
5077
|
+
}
|
|
5078
|
+
if (schema.$defs === void 0 || Object.keys(schema.$defs).length === 0) {
|
|
5079
|
+
return {
|
|
5080
|
+
...schema.$schema !== void 0 && { $schema: schema.$schema },
|
|
5081
|
+
...result
|
|
5082
|
+
};
|
|
5083
|
+
}
|
|
5084
|
+
return {
|
|
5085
|
+
...schema.$schema !== void 0 && { $schema: schema.$schema },
|
|
5086
|
+
...result,
|
|
5087
|
+
$defs: schema.$defs
|
|
5088
|
+
};
|
|
5089
|
+
}
|
|
5090
|
+
function generateSchemasFromAnalysis(analysis, filePath, options) {
|
|
5091
|
+
return toDiscoveredTypeSchemas(
|
|
5092
|
+
generateClassSchemas(
|
|
5093
|
+
analysis,
|
|
5094
|
+
{ file: filePath },
|
|
5095
|
+
{
|
|
5096
|
+
extensionRegistry: options?.extensionRegistry,
|
|
5097
|
+
metadata: options?.metadata,
|
|
5098
|
+
vendorPrefix: options?.vendorPrefix
|
|
5099
|
+
}
|
|
5100
|
+
)
|
|
5101
|
+
);
|
|
5102
|
+
}
|
|
5103
|
+
function generateSchemasFromResolvedType(options, skipNamedDeclaration = false, rootOverride) {
|
|
5104
|
+
const namedDeclaration = skipNamedDeclaration || hasConcreteTypeArguments(options.type, options.context.checker) ? void 0 : getNamedTypeDeclaration2(options.type);
|
|
5105
|
+
if (namedDeclaration !== void 0) {
|
|
5106
|
+
return generateSchemasFromDeclaration({
|
|
5107
|
+
...options,
|
|
5108
|
+
declaration: namedDeclaration
|
|
5109
|
+
});
|
|
5110
|
+
}
|
|
5111
|
+
const filePath = options.sourceNode?.getSourceFile().fileName ?? options.context.sourceFile.fileName;
|
|
5112
|
+
const typeRegistry = {};
|
|
5113
|
+
const diagnostics = [];
|
|
5114
|
+
const rootType = resolveTypeNode(
|
|
5115
|
+
options.type,
|
|
5116
|
+
options.context.checker,
|
|
5117
|
+
filePath,
|
|
5118
|
+
typeRegistry,
|
|
5119
|
+
/* @__PURE__ */ new Set(),
|
|
5120
|
+
options.sourceNode,
|
|
5121
|
+
normalizeMetadataPolicy(options.metadata),
|
|
5122
|
+
options.extensionRegistry,
|
|
5123
|
+
diagnostics
|
|
5124
|
+
);
|
|
5125
|
+
if (diagnostics.length > 0) {
|
|
5126
|
+
const diagnosticDetails = diagnostics.map((diagnostic) => `${diagnostic.code}: ${diagnostic.message}`).join("; ");
|
|
5127
|
+
throw new Error(
|
|
5128
|
+
`FormSpec validation failed while generating discovered type schemas. ${diagnosticDetails}`
|
|
5129
|
+
);
|
|
5130
|
+
}
|
|
5131
|
+
const describedRoot = describeRootType(
|
|
5132
|
+
rootType,
|
|
5133
|
+
typeRegistry,
|
|
5134
|
+
options.name ?? getFallbackName(options.sourceNode)
|
|
5135
|
+
);
|
|
5136
|
+
const mergedMetadata = mergeResolvedMetadata(describedRoot.metadata, rootOverride?.metadata);
|
|
5137
|
+
const root = {
|
|
5138
|
+
...describedRoot,
|
|
5139
|
+
...rootOverride?.name !== void 0 && { name: rootOverride.name },
|
|
5140
|
+
...mergedMetadata !== void 0 && { metadata: mergedMetadata },
|
|
5141
|
+
...rootOverride?.annotations !== void 0 && { annotations: rootOverride.annotations }
|
|
5142
|
+
};
|
|
5143
|
+
if (root.type.kind === "object") {
|
|
5144
|
+
return generateSchemasFromAnalysis(
|
|
5145
|
+
createObjectRootAnalysis(
|
|
5146
|
+
options.name ?? root.name,
|
|
5147
|
+
root.type.properties,
|
|
5148
|
+
typeRegistry,
|
|
5149
|
+
root.metadata,
|
|
5150
|
+
root.annotations
|
|
5151
|
+
),
|
|
5152
|
+
filePath,
|
|
5153
|
+
options
|
|
5154
|
+
);
|
|
5155
|
+
}
|
|
5156
|
+
return {
|
|
5157
|
+
jsonSchema: toStandaloneJsonSchema(root, typeRegistry, options),
|
|
5158
|
+
uiSchema: null
|
|
5159
|
+
};
|
|
5160
|
+
}
|
|
5161
|
+
function generateSchemasFromDeclaration(options) {
|
|
5162
|
+
const filePath = options.declaration.getSourceFile().fileName;
|
|
5163
|
+
if (ts7.isClassDeclaration(options.declaration)) {
|
|
5164
|
+
return generateSchemasFromAnalysis(
|
|
5165
|
+
analyzeClassToIR(
|
|
5166
|
+
options.declaration,
|
|
5167
|
+
options.context.checker,
|
|
5168
|
+
filePath,
|
|
5169
|
+
options.extensionRegistry,
|
|
5170
|
+
options.metadata
|
|
5171
|
+
),
|
|
5172
|
+
filePath,
|
|
5173
|
+
options
|
|
5174
|
+
);
|
|
5175
|
+
}
|
|
5176
|
+
if (ts7.isInterfaceDeclaration(options.declaration)) {
|
|
5177
|
+
return generateSchemasFromAnalysis(
|
|
5178
|
+
analyzeInterfaceToIR(
|
|
5179
|
+
options.declaration,
|
|
5180
|
+
options.context.checker,
|
|
5181
|
+
filePath,
|
|
5182
|
+
options.extensionRegistry,
|
|
5183
|
+
options.metadata
|
|
5184
|
+
),
|
|
5185
|
+
filePath,
|
|
5186
|
+
options
|
|
5187
|
+
);
|
|
5188
|
+
}
|
|
5189
|
+
if (ts7.isTypeAliasDeclaration(options.declaration)) {
|
|
5190
|
+
const analyzedAlias = analyzeTypeAliasToIR(
|
|
5191
|
+
options.declaration,
|
|
5192
|
+
options.context.checker,
|
|
5193
|
+
filePath,
|
|
5194
|
+
options.extensionRegistry,
|
|
5195
|
+
options.metadata
|
|
5196
|
+
);
|
|
5197
|
+
if (analyzedAlias.ok) {
|
|
5198
|
+
return generateSchemasFromAnalysis(analyzedAlias.analysis, filePath, options);
|
|
5199
|
+
}
|
|
5200
|
+
const aliasRootInfo = analyzeDeclarationRootInfo(
|
|
5201
|
+
options.declaration,
|
|
5202
|
+
options.context.checker,
|
|
5203
|
+
filePath,
|
|
5204
|
+
options.extensionRegistry,
|
|
5205
|
+
options.metadata
|
|
5206
|
+
);
|
|
5207
|
+
if (aliasRootInfo.diagnostics.length > 0) {
|
|
5208
|
+
const diagnosticDetails = aliasRootInfo.diagnostics.map((diagnostic) => `${diagnostic.code}: ${diagnostic.message}`).join("; ");
|
|
5209
|
+
throw new Error(
|
|
5210
|
+
`FormSpec validation failed while generating discovered type schemas. ${diagnosticDetails}`
|
|
5211
|
+
);
|
|
5212
|
+
}
|
|
5213
|
+
return generateSchemasFromResolvedType(
|
|
5214
|
+
{
|
|
5215
|
+
...options,
|
|
5216
|
+
type: options.context.checker.getTypeAtLocation(options.declaration),
|
|
5217
|
+
sourceNode: options.declaration,
|
|
5218
|
+
name: options.declaration.name.text
|
|
5219
|
+
},
|
|
5220
|
+
true,
|
|
5221
|
+
{
|
|
5222
|
+
name: options.declaration.name.text,
|
|
5223
|
+
...aliasRootInfo.metadata !== void 0 && { metadata: aliasRootInfo.metadata },
|
|
5224
|
+
...aliasRootInfo.annotations.length > 0 && { annotations: aliasRootInfo.annotations }
|
|
5225
|
+
}
|
|
5226
|
+
);
|
|
5227
|
+
}
|
|
5228
|
+
const _exhaustive = options.declaration;
|
|
5229
|
+
return _exhaustive;
|
|
5230
|
+
}
|
|
5231
|
+
function generateSchemasFromType(options) {
|
|
5232
|
+
return generateSchemasFromResolvedType(options);
|
|
5233
|
+
}
|
|
5234
|
+
function generateSchemasFromParameter(options) {
|
|
5235
|
+
return generateSchemasFromResolvedType({
|
|
5236
|
+
...options,
|
|
5237
|
+
type: options.context.checker.getTypeAtLocation(options.parameter),
|
|
5238
|
+
sourceNode: options.parameter,
|
|
5239
|
+
name: getFallbackName(options.parameter, "Parameter")
|
|
5240
|
+
});
|
|
5241
|
+
}
|
|
5242
|
+
function generateSchemasFromReturnType(options) {
|
|
5243
|
+
const signature = options.context.checker.getSignatureFromDeclaration(options.declaration);
|
|
5244
|
+
const type = signature !== void 0 ? options.context.checker.getReturnTypeOfSignature(signature) : options.context.checker.getTypeAtLocation(options.declaration);
|
|
5245
|
+
const fallbackName = options.declaration.name !== void 0 && ts7.isIdentifier(options.declaration.name) ? `${options.declaration.name.text}ReturnType` : "ReturnType";
|
|
5246
|
+
return generateSchemasFromResolvedType({
|
|
5247
|
+
...options,
|
|
5248
|
+
type,
|
|
5249
|
+
sourceNode: options.declaration.type ?? options.declaration,
|
|
5250
|
+
name: fallbackName
|
|
5251
|
+
});
|
|
5252
|
+
}
|
|
5253
|
+
|
|
4872
5254
|
// src/generators/mixed-authoring.ts
|
|
4873
5255
|
function buildMixedAuthoringSchemas(options) {
|
|
4874
5256
|
const { filePath, typeName, overlays, ...schemaOptions } = options;
|
|
@@ -5083,12 +5465,20 @@ export {
|
|
|
5083
5465
|
buildFormSchemas,
|
|
5084
5466
|
buildMixedAuthoringSchemas,
|
|
5085
5467
|
createExtensionRegistry,
|
|
5468
|
+
createStaticBuildContext,
|
|
5469
|
+
createStaticBuildContextFromProgram,
|
|
5086
5470
|
generateJsonSchema,
|
|
5087
5471
|
generateSchemas,
|
|
5088
5472
|
generateSchemasFromClass,
|
|
5473
|
+
generateSchemasFromDeclaration,
|
|
5474
|
+
generateSchemasFromParameter,
|
|
5089
5475
|
generateSchemasFromProgram,
|
|
5476
|
+
generateSchemasFromReturnType,
|
|
5477
|
+
generateSchemasFromType,
|
|
5090
5478
|
generateUiSchema,
|
|
5091
5479
|
jsonSchema7Schema,
|
|
5480
|
+
resolveModuleExport,
|
|
5481
|
+
resolveModuleExportDeclaration,
|
|
5092
5482
|
uiSchema as uiSchemaSchema,
|
|
5093
5483
|
writeSchemas
|
|
5094
5484
|
};
|