@formspec/build 0.1.0-alpha.39 → 0.1.0-alpha.40
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 +6 -0
- package/dist/build-alpha.d.ts +32 -0
- package/dist/build-beta.d.ts +32 -0
- package/dist/build-internal.d.ts +32 -0
- package/dist/build.d.ts +32 -0
- package/dist/cli.cjs +44 -1
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +43 -0
- package/dist/cli.js.map +1 -1
- package/dist/generators/discovered-schema.d.ts +29 -0
- package/dist/generators/discovered-schema.d.ts.map +1 -1
- package/dist/index.cjs +44 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -32,6 +32,16 @@ export interface DiscoveredTypeSchemas {
|
|
|
32
32
|
* @public
|
|
33
33
|
*/
|
|
34
34
|
export type SchemaSourceDeclaration = ts.ClassDeclaration | ts.InterfaceDeclaration | ts.TypeAliasDeclaration;
|
|
35
|
+
/**
|
|
36
|
+
* Supported declaration kinds for standalone metadata resolution.
|
|
37
|
+
*
|
|
38
|
+
* This helper is intentionally limited to named type declarations,
|
|
39
|
+
* methods/functions, and object-like properties. It does not currently expose
|
|
40
|
+
* parameter or variable metadata resolution on the public build surface.
|
|
41
|
+
*
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export type MetadataSourceDeclaration = SchemaSourceDeclaration | ts.MethodDeclaration | ts.FunctionDeclaration | ts.PropertyDeclaration | ts.PropertySignature;
|
|
35
45
|
/**
|
|
36
46
|
* Options for generating schemas from a resolved declaration.
|
|
37
47
|
*
|
|
@@ -85,6 +95,18 @@ export interface GenerateSchemasFromReturnTypeOptions extends StaticSchemaGenera
|
|
|
85
95
|
/** Signature declaration whose return type should be converted into schemas. */
|
|
86
96
|
readonly declaration: ts.SignatureDeclaration;
|
|
87
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Options for resolving metadata from a declaration against the active
|
|
100
|
+
* metadata policy.
|
|
101
|
+
*
|
|
102
|
+
* @public
|
|
103
|
+
*/
|
|
104
|
+
export interface ResolveDeclarationMetadataOptions extends StaticSchemaGenerationOptions {
|
|
105
|
+
/** Supported build context used for checker access and related analysis. */
|
|
106
|
+
readonly context: StaticBuildContext;
|
|
107
|
+
/** Declaration whose metadata should be resolved. */
|
|
108
|
+
readonly declaration: MetadataSourceDeclaration;
|
|
109
|
+
}
|
|
88
110
|
/**
|
|
89
111
|
* Generates schemas from a resolved declaration using the supported public
|
|
90
112
|
* static-build workflow.
|
|
@@ -120,4 +142,11 @@ export declare function generateSchemasFromParameter(options: GenerateSchemasFro
|
|
|
120
142
|
* @public
|
|
121
143
|
*/
|
|
122
144
|
export declare function generateSchemasFromReturnType(options: GenerateSchemasFromReturnTypeOptions): DiscoveredTypeSchemas;
|
|
145
|
+
/**
|
|
146
|
+
* Resolves metadata from a declaration using FormSpec's configured metadata
|
|
147
|
+
* policy for the matching declaration kind.
|
|
148
|
+
*
|
|
149
|
+
* @public
|
|
150
|
+
*/
|
|
151
|
+
export declare function resolveDeclarationMetadata(options: ResolveDeclarationMetadataOptions): ResolvedMetadata | undefined;
|
|
123
152
|
//# sourceMappingURL=discovered-schema.d.ts.map
|
|
@@ -1 +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;
|
|
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,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAu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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;AAED;;;;;GAKG;AACH,MAAM,WAAW,iCAAkC,SAAQ,6BAA6B;IACtF,4EAA4E;IAC5E,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACrC,qDAAqD;IACrD,QAAQ,CAAC,WAAW,EAAE,yBAAyB,CAAC;CACjD;AA0VD;;;;;;;;;GASG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,qCAAqC,GAC7C,qBAAqB,CA+EvB;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;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,oCAAoC,GAC5C,qBAAqB,CAyBvB;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,iCAAiC,GACzC,gBAAgB,GAAG,SAAS,CAgB9B"}
|
package/dist/index.cjs
CHANGED
|
@@ -49,6 +49,7 @@ __export(index_exports, {
|
|
|
49
49
|
generateSchemasFromType: () => generateSchemasFromType,
|
|
50
50
|
generateUiSchema: () => generateUiSchema,
|
|
51
51
|
jsonSchema7Schema: () => jsonSchema7Schema,
|
|
52
|
+
resolveDeclarationMetadata: () => resolveDeclarationMetadata,
|
|
52
53
|
resolveModuleExport: () => resolveModuleExport,
|
|
53
54
|
resolveModuleExportDeclaration: () => resolveModuleExportDeclaration,
|
|
54
55
|
uiSchemaSchema: () => uiSchema,
|
|
@@ -5676,6 +5677,7 @@ function resolveModuleExportDeclaration(context, exportName = "default") {
|
|
|
5676
5677
|
|
|
5677
5678
|
// src/generators/discovered-schema.ts
|
|
5678
5679
|
var ts7 = __toESM(require("typescript"), 1);
|
|
5680
|
+
var import_internal5 = require("@formspec/analysis/internal");
|
|
5679
5681
|
var import_internals6 = require("@formspec/core/internals");
|
|
5680
5682
|
function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
5681
5683
|
return {
|
|
@@ -5749,6 +5751,32 @@ function omitApiName(metadata) {
|
|
|
5749
5751
|
const { apiName: _apiName, ...rest } = metadata;
|
|
5750
5752
|
return Object.keys(rest).length > 0 ? rest : void 0;
|
|
5751
5753
|
}
|
|
5754
|
+
function enforceRequiredMetadata(metadata, declarationKind, logicalName, options) {
|
|
5755
|
+
const declarationPolicy = getDeclarationMetadataPolicy(
|
|
5756
|
+
normalizeMetadataPolicy(options.metadata),
|
|
5757
|
+
declarationKind
|
|
5758
|
+
);
|
|
5759
|
+
if (metadata?.apiName === void 0 && declarationPolicy.apiName.mode === "require-explicit") {
|
|
5760
|
+
throw new Error(
|
|
5761
|
+
`Metadata policy requires explicit apiName for ${declarationKind} "${logicalName}" on the tsdoc surface.`
|
|
5762
|
+
);
|
|
5763
|
+
}
|
|
5764
|
+
if (metadata?.displayName === void 0 && declarationPolicy.displayName.mode === "require-explicit") {
|
|
5765
|
+
throw new Error(
|
|
5766
|
+
`Metadata policy requires explicit displayName for ${declarationKind} "${logicalName}" on the tsdoc surface.`
|
|
5767
|
+
);
|
|
5768
|
+
}
|
|
5769
|
+
if (metadata?.apiNamePlural === void 0 && declarationPolicy.apiName.pluralization.mode === "require-explicit") {
|
|
5770
|
+
throw new Error(
|
|
5771
|
+
`Metadata policy requires explicit apiNamePlural for ${declarationKind} "${logicalName}" on the tsdoc surface.`
|
|
5772
|
+
);
|
|
5773
|
+
}
|
|
5774
|
+
if (metadata?.displayNamePlural === void 0 && declarationPolicy.displayName.pluralization.mode === "require-explicit") {
|
|
5775
|
+
throw new Error(
|
|
5776
|
+
`Metadata policy requires explicit displayNamePlural for ${declarationKind} "${logicalName}" on the tsdoc surface.`
|
|
5777
|
+
);
|
|
5778
|
+
}
|
|
5779
|
+
}
|
|
5752
5780
|
function describeRootType(rootType, typeRegistry, fallbackName) {
|
|
5753
5781
|
if (rootType.kind !== "reference") {
|
|
5754
5782
|
return {
|
|
@@ -5989,6 +6017,21 @@ function generateSchemasFromReturnType(options) {
|
|
|
5989
6017
|
name: fallbackName
|
|
5990
6018
|
});
|
|
5991
6019
|
}
|
|
6020
|
+
function resolveDeclarationMetadata(options) {
|
|
6021
|
+
const analysis = (0, import_internal5.analyzeMetadataForNodeWithChecker)({
|
|
6022
|
+
checker: options.context.checker,
|
|
6023
|
+
node: options.declaration,
|
|
6024
|
+
metadata: options.metadata,
|
|
6025
|
+
extensions: options.extensionRegistry?.extensions,
|
|
6026
|
+
buildContext: options.context
|
|
6027
|
+
});
|
|
6028
|
+
if (analysis === null) {
|
|
6029
|
+
return void 0;
|
|
6030
|
+
}
|
|
6031
|
+
const metadata = analysis.resolvedMetadata;
|
|
6032
|
+
enforceRequiredMetadata(metadata, analysis.declarationKind, analysis.logicalName, options);
|
|
6033
|
+
return metadata;
|
|
6034
|
+
}
|
|
5992
6035
|
function unwrapPromiseType(checker, type) {
|
|
5993
6036
|
if (!("getAwaitedType" in checker) || typeof checker.getAwaitedType !== "function") {
|
|
5994
6037
|
return type;
|
|
@@ -6241,6 +6284,7 @@ function writeSchemas(form, options) {
|
|
|
6241
6284
|
generateSchemasFromType,
|
|
6242
6285
|
generateUiSchema,
|
|
6243
6286
|
jsonSchema7Schema,
|
|
6287
|
+
resolveDeclarationMetadata,
|
|
6244
6288
|
resolveModuleExport,
|
|
6245
6289
|
resolveModuleExportDeclaration,
|
|
6246
6290
|
uiSchemaSchema,
|