@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
package/README.md
CHANGED
|
@@ -74,6 +74,7 @@ Public helpers in this workflow:
|
|
|
74
74
|
- `createStaticBuildContextFromProgram(program, filePath)` - Reuse a host-owned `ts.Program`.
|
|
75
75
|
- `resolveModuleExport(context, exportName?)` - Resolve any exported symbol, including functions and other non-schema declarations.
|
|
76
76
|
- `resolveModuleExportDeclaration(context, exportName?)` - Resolve only schema-source declarations (`class`, `interface`, `type` alias).
|
|
77
|
+
- `resolveDeclarationMetadata(...)` - Resolve metadata for named types, methods, and properties using FormSpec's active metadata policy.
|
|
77
78
|
- `generateSchemasFromDeclaration(...)` - Generate from a resolved schema-source declaration.
|
|
78
79
|
- `generateSchemasFromParameter(...)` - Generate from a method or function parameter declaration.
|
|
79
80
|
- `generateSchemasFromReturnType(...)` - Generate from a method or function return type, unwrapping awaited `Promise<T>`-style returns before generation.
|
|
@@ -91,6 +92,7 @@ import {
|
|
|
91
92
|
generateSchemasFromDeclaration,
|
|
92
93
|
generateSchemasFromParameter,
|
|
93
94
|
generateSchemasFromReturnType,
|
|
95
|
+
resolveDeclarationMetadata,
|
|
94
96
|
resolveModuleExport,
|
|
95
97
|
resolveModuleExportDeclaration,
|
|
96
98
|
} from "@formspec/build";
|
|
@@ -107,6 +109,10 @@ if (serviceDeclaration && ts.isClassDeclaration(serviceDeclaration)) {
|
|
|
107
109
|
);
|
|
108
110
|
|
|
109
111
|
if (submitMethod?.parameters[0]) {
|
|
112
|
+
const methodMetadata = resolveDeclarationMetadata({
|
|
113
|
+
context,
|
|
114
|
+
declaration: submitMethod,
|
|
115
|
+
});
|
|
110
116
|
const inputSchemas = generateSchemasFromParameter({
|
|
111
117
|
context,
|
|
112
118
|
parameter: submitMethod.parameters[0],
|
package/dist/build-alpha.d.ts
CHANGED
|
@@ -1086,6 +1086,17 @@ export declare interface LabelElement {
|
|
|
1086
1086
|
readonly [k: string]: unknown;
|
|
1087
1087
|
}
|
|
1088
1088
|
|
|
1089
|
+
/**
|
|
1090
|
+
* Supported declaration kinds for standalone metadata resolution.
|
|
1091
|
+
*
|
|
1092
|
+
* This helper is intentionally limited to named type declarations,
|
|
1093
|
+
* methods/functions, and object-like properties. It does not currently expose
|
|
1094
|
+
* parameter or variable metadata resolution on the public build surface.
|
|
1095
|
+
*
|
|
1096
|
+
* @public
|
|
1097
|
+
*/
|
|
1098
|
+
export declare type MetadataSourceDeclaration = SchemaSourceDeclaration | ts.MethodDeclaration | ts.FunctionDeclaration | ts.PropertyDeclaration | ts.PropertySignature;
|
|
1099
|
+
|
|
1089
1100
|
/**
|
|
1090
1101
|
* Result of generating schemas from a mixed-authoring composition.
|
|
1091
1102
|
*
|
|
@@ -1102,6 +1113,27 @@ export { NumberField }
|
|
|
1102
1113
|
|
|
1103
1114
|
export { ObjectField }
|
|
1104
1115
|
|
|
1116
|
+
/**
|
|
1117
|
+
* Resolves metadata from a declaration using FormSpec's configured metadata
|
|
1118
|
+
* policy for the matching declaration kind.
|
|
1119
|
+
*
|
|
1120
|
+
* @public
|
|
1121
|
+
*/
|
|
1122
|
+
export declare function resolveDeclarationMetadata(options: ResolveDeclarationMetadataOptions): ResolvedMetadata | undefined;
|
|
1123
|
+
|
|
1124
|
+
/**
|
|
1125
|
+
* Options for resolving metadata from a declaration against the active
|
|
1126
|
+
* metadata policy.
|
|
1127
|
+
*
|
|
1128
|
+
* @public
|
|
1129
|
+
*/
|
|
1130
|
+
export declare interface ResolveDeclarationMetadataOptions extends StaticSchemaGenerationOptions {
|
|
1131
|
+
/** Supported build context used for checker access and related analysis. */
|
|
1132
|
+
readonly context: StaticBuildContext;
|
|
1133
|
+
/** Declaration whose metadata should be resolved. */
|
|
1134
|
+
readonly declaration: MetadataSourceDeclaration;
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1105
1137
|
/**
|
|
1106
1138
|
* Resolves an export from the context source file, following aliases and re-exports.
|
|
1107
1139
|
*
|
package/dist/build-beta.d.ts
CHANGED
|
@@ -1086,6 +1086,17 @@ export declare interface LabelElement {
|
|
|
1086
1086
|
readonly [k: string]: unknown;
|
|
1087
1087
|
}
|
|
1088
1088
|
|
|
1089
|
+
/**
|
|
1090
|
+
* Supported declaration kinds for standalone metadata resolution.
|
|
1091
|
+
*
|
|
1092
|
+
* This helper is intentionally limited to named type declarations,
|
|
1093
|
+
* methods/functions, and object-like properties. It does not currently expose
|
|
1094
|
+
* parameter or variable metadata resolution on the public build surface.
|
|
1095
|
+
*
|
|
1096
|
+
* @public
|
|
1097
|
+
*/
|
|
1098
|
+
export declare type MetadataSourceDeclaration = SchemaSourceDeclaration | ts.MethodDeclaration | ts.FunctionDeclaration | ts.PropertyDeclaration | ts.PropertySignature;
|
|
1099
|
+
|
|
1089
1100
|
/**
|
|
1090
1101
|
* Result of generating schemas from a mixed-authoring composition.
|
|
1091
1102
|
*
|
|
@@ -1102,6 +1113,27 @@ export { NumberField }
|
|
|
1102
1113
|
|
|
1103
1114
|
export { ObjectField }
|
|
1104
1115
|
|
|
1116
|
+
/**
|
|
1117
|
+
* Resolves metadata from a declaration using FormSpec's configured metadata
|
|
1118
|
+
* policy for the matching declaration kind.
|
|
1119
|
+
*
|
|
1120
|
+
* @public
|
|
1121
|
+
*/
|
|
1122
|
+
export declare function resolveDeclarationMetadata(options: ResolveDeclarationMetadataOptions): ResolvedMetadata | undefined;
|
|
1123
|
+
|
|
1124
|
+
/**
|
|
1125
|
+
* Options for resolving metadata from a declaration against the active
|
|
1126
|
+
* metadata policy.
|
|
1127
|
+
*
|
|
1128
|
+
* @public
|
|
1129
|
+
*/
|
|
1130
|
+
export declare interface ResolveDeclarationMetadataOptions extends StaticSchemaGenerationOptions {
|
|
1131
|
+
/** Supported build context used for checker access and related analysis. */
|
|
1132
|
+
readonly context: StaticBuildContext;
|
|
1133
|
+
/** Declaration whose metadata should be resolved. */
|
|
1134
|
+
readonly declaration: MetadataSourceDeclaration;
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1105
1137
|
/**
|
|
1106
1138
|
* Resolves an export from the context source file, following aliases and re-exports.
|
|
1107
1139
|
*
|
package/dist/build-internal.d.ts
CHANGED
|
@@ -1086,6 +1086,17 @@ export declare interface LabelElement {
|
|
|
1086
1086
|
readonly [k: string]: unknown;
|
|
1087
1087
|
}
|
|
1088
1088
|
|
|
1089
|
+
/**
|
|
1090
|
+
* Supported declaration kinds for standalone metadata resolution.
|
|
1091
|
+
*
|
|
1092
|
+
* This helper is intentionally limited to named type declarations,
|
|
1093
|
+
* methods/functions, and object-like properties. It does not currently expose
|
|
1094
|
+
* parameter or variable metadata resolution on the public build surface.
|
|
1095
|
+
*
|
|
1096
|
+
* @public
|
|
1097
|
+
*/
|
|
1098
|
+
export declare type MetadataSourceDeclaration = SchemaSourceDeclaration | ts.MethodDeclaration | ts.FunctionDeclaration | ts.PropertyDeclaration | ts.PropertySignature;
|
|
1099
|
+
|
|
1089
1100
|
/**
|
|
1090
1101
|
* Result of generating schemas from a mixed-authoring composition.
|
|
1091
1102
|
*
|
|
@@ -1102,6 +1113,27 @@ export { NumberField }
|
|
|
1102
1113
|
|
|
1103
1114
|
export { ObjectField }
|
|
1104
1115
|
|
|
1116
|
+
/**
|
|
1117
|
+
* Resolves metadata from a declaration using FormSpec's configured metadata
|
|
1118
|
+
* policy for the matching declaration kind.
|
|
1119
|
+
*
|
|
1120
|
+
* @public
|
|
1121
|
+
*/
|
|
1122
|
+
export declare function resolveDeclarationMetadata(options: ResolveDeclarationMetadataOptions): ResolvedMetadata | undefined;
|
|
1123
|
+
|
|
1124
|
+
/**
|
|
1125
|
+
* Options for resolving metadata from a declaration against the active
|
|
1126
|
+
* metadata policy.
|
|
1127
|
+
*
|
|
1128
|
+
* @public
|
|
1129
|
+
*/
|
|
1130
|
+
export declare interface ResolveDeclarationMetadataOptions extends StaticSchemaGenerationOptions {
|
|
1131
|
+
/** Supported build context used for checker access and related analysis. */
|
|
1132
|
+
readonly context: StaticBuildContext;
|
|
1133
|
+
/** Declaration whose metadata should be resolved. */
|
|
1134
|
+
readonly declaration: MetadataSourceDeclaration;
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1105
1137
|
/**
|
|
1106
1138
|
* Resolves an export from the context source file, following aliases and re-exports.
|
|
1107
1139
|
*
|
package/dist/build.d.ts
CHANGED
|
@@ -1086,6 +1086,17 @@ export declare interface LabelElement {
|
|
|
1086
1086
|
readonly [k: string]: unknown;
|
|
1087
1087
|
}
|
|
1088
1088
|
|
|
1089
|
+
/**
|
|
1090
|
+
* Supported declaration kinds for standalone metadata resolution.
|
|
1091
|
+
*
|
|
1092
|
+
* This helper is intentionally limited to named type declarations,
|
|
1093
|
+
* methods/functions, and object-like properties. It does not currently expose
|
|
1094
|
+
* parameter or variable metadata resolution on the public build surface.
|
|
1095
|
+
*
|
|
1096
|
+
* @public
|
|
1097
|
+
*/
|
|
1098
|
+
export declare type MetadataSourceDeclaration = SchemaSourceDeclaration | ts.MethodDeclaration | ts.FunctionDeclaration | ts.PropertyDeclaration | ts.PropertySignature;
|
|
1099
|
+
|
|
1089
1100
|
/**
|
|
1090
1101
|
* Result of generating schemas from a mixed-authoring composition.
|
|
1091
1102
|
*
|
|
@@ -1102,6 +1113,27 @@ export { NumberField }
|
|
|
1102
1113
|
|
|
1103
1114
|
export { ObjectField }
|
|
1104
1115
|
|
|
1116
|
+
/**
|
|
1117
|
+
* Resolves metadata from a declaration using FormSpec's configured metadata
|
|
1118
|
+
* policy for the matching declaration kind.
|
|
1119
|
+
*
|
|
1120
|
+
* @public
|
|
1121
|
+
*/
|
|
1122
|
+
export declare function resolveDeclarationMetadata(options: ResolveDeclarationMetadataOptions): ResolvedMetadata | undefined;
|
|
1123
|
+
|
|
1124
|
+
/**
|
|
1125
|
+
* Options for resolving metadata from a declaration against the active
|
|
1126
|
+
* metadata policy.
|
|
1127
|
+
*
|
|
1128
|
+
* @public
|
|
1129
|
+
*/
|
|
1130
|
+
export declare interface ResolveDeclarationMetadataOptions extends StaticSchemaGenerationOptions {
|
|
1131
|
+
/** Supported build context used for checker access and related analysis. */
|
|
1132
|
+
readonly context: StaticBuildContext;
|
|
1133
|
+
/** Declaration whose metadata should be resolved. */
|
|
1134
|
+
readonly declaration: MetadataSourceDeclaration;
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1105
1137
|
/**
|
|
1106
1138
|
* Resolves an export from the context source file, following aliases and re-exports.
|
|
1107
1139
|
*
|
package/dist/cli.cjs
CHANGED
|
@@ -5875,6 +5875,32 @@ function omitApiName(metadata) {
|
|
|
5875
5875
|
const { apiName: _apiName, ...rest } = metadata;
|
|
5876
5876
|
return Object.keys(rest).length > 0 ? rest : void 0;
|
|
5877
5877
|
}
|
|
5878
|
+
function enforceRequiredMetadata(metadata, declarationKind, logicalName, options) {
|
|
5879
|
+
const declarationPolicy = getDeclarationMetadataPolicy(
|
|
5880
|
+
normalizeMetadataPolicy(options.metadata),
|
|
5881
|
+
declarationKind
|
|
5882
|
+
);
|
|
5883
|
+
if (metadata?.apiName === void 0 && declarationPolicy.apiName.mode === "require-explicit") {
|
|
5884
|
+
throw new Error(
|
|
5885
|
+
`Metadata policy requires explicit apiName for ${declarationKind} "${logicalName}" on the tsdoc surface.`
|
|
5886
|
+
);
|
|
5887
|
+
}
|
|
5888
|
+
if (metadata?.displayName === void 0 && declarationPolicy.displayName.mode === "require-explicit") {
|
|
5889
|
+
throw new Error(
|
|
5890
|
+
`Metadata policy requires explicit displayName for ${declarationKind} "${logicalName}" on the tsdoc surface.`
|
|
5891
|
+
);
|
|
5892
|
+
}
|
|
5893
|
+
if (metadata?.apiNamePlural === void 0 && declarationPolicy.apiName.pluralization.mode === "require-explicit") {
|
|
5894
|
+
throw new Error(
|
|
5895
|
+
`Metadata policy requires explicit apiNamePlural for ${declarationKind} "${logicalName}" on the tsdoc surface.`
|
|
5896
|
+
);
|
|
5897
|
+
}
|
|
5898
|
+
if (metadata?.displayNamePlural === void 0 && declarationPolicy.displayName.pluralization.mode === "require-explicit") {
|
|
5899
|
+
throw new Error(
|
|
5900
|
+
`Metadata policy requires explicit displayNamePlural for ${declarationKind} "${logicalName}" on the tsdoc surface.`
|
|
5901
|
+
);
|
|
5902
|
+
}
|
|
5903
|
+
}
|
|
5878
5904
|
function describeRootType(rootType, typeRegistry, fallbackName) {
|
|
5879
5905
|
if (rootType.kind !== "reference") {
|
|
5880
5906
|
return {
|
|
@@ -6115,6 +6141,21 @@ function generateSchemasFromReturnType(options) {
|
|
|
6115
6141
|
name: fallbackName
|
|
6116
6142
|
});
|
|
6117
6143
|
}
|
|
6144
|
+
function resolveDeclarationMetadata(options) {
|
|
6145
|
+
const analysis = (0, import_internal5.analyzeMetadataForNodeWithChecker)({
|
|
6146
|
+
checker: options.context.checker,
|
|
6147
|
+
node: options.declaration,
|
|
6148
|
+
metadata: options.metadata,
|
|
6149
|
+
extensions: options.extensionRegistry?.extensions,
|
|
6150
|
+
buildContext: options.context
|
|
6151
|
+
});
|
|
6152
|
+
if (analysis === null) {
|
|
6153
|
+
return void 0;
|
|
6154
|
+
}
|
|
6155
|
+
const metadata = analysis.resolvedMetadata;
|
|
6156
|
+
enforceRequiredMetadata(metadata, analysis.declarationKind, analysis.logicalName, options);
|
|
6157
|
+
return metadata;
|
|
6158
|
+
}
|
|
6118
6159
|
function unwrapPromiseType(checker, type) {
|
|
6119
6160
|
if (!("getAwaitedType" in checker) || typeof checker.getAwaitedType !== "function") {
|
|
6120
6161
|
return type;
|
|
@@ -6134,11 +6175,12 @@ function unwrapPromiseTypeNode(typeNode) {
|
|
|
6134
6175
|
function isPromiseTypeReferenceNode(typeNode) {
|
|
6135
6176
|
return ts7.isTypeReferenceNode(typeNode) && ts7.isIdentifier(typeNode.typeName) && typeNode.typeName.text === "Promise" && typeNode.typeArguments !== void 0 && typeNode.typeArguments.length > 0;
|
|
6136
6177
|
}
|
|
6137
|
-
var ts7, import_internals6;
|
|
6178
|
+
var ts7, import_internal5, import_internals6;
|
|
6138
6179
|
var init_discovered_schema = __esm({
|
|
6139
6180
|
"src/generators/discovered-schema.ts"() {
|
|
6140
6181
|
"use strict";
|
|
6141
6182
|
ts7 = __toESM(require("typescript"), 1);
|
|
6183
|
+
import_internal5 = require("@formspec/analysis/internal");
|
|
6142
6184
|
init_class_analyzer();
|
|
6143
6185
|
init_class_schema();
|
|
6144
6186
|
init_ir_generator();
|
|
@@ -6370,6 +6412,7 @@ __export(index_exports, {
|
|
|
6370
6412
|
generateSchemasFromType: () => generateSchemasFromType,
|
|
6371
6413
|
generateUiSchema: () => generateUiSchema,
|
|
6372
6414
|
jsonSchema7Schema: () => jsonSchema7Schema,
|
|
6415
|
+
resolveDeclarationMetadata: () => resolveDeclarationMetadata,
|
|
6373
6416
|
resolveModuleExport: () => resolveModuleExport,
|
|
6374
6417
|
resolveModuleExportDeclaration: () => resolveModuleExportDeclaration,
|
|
6375
6418
|
uiSchemaSchema: () => uiSchema,
|