@formspec/build 0.1.0-alpha.35 → 0.1.0-alpha.37
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 +1 -1
- package/dist/analyzer/class-analyzer.d.ts +4 -0
- package/dist/analyzer/class-analyzer.d.ts.map +1 -1
- package/dist/analyzer/program.d.ts.map +1 -1
- package/dist/build-alpha.d.ts +2 -0
- package/dist/build-beta.d.ts +2 -0
- package/dist/build-internal.d.ts +2 -0
- package/dist/build.d.ts +2 -0
- package/dist/cli.cjs +207 -12
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +207 -12
- package/dist/cli.js.map +1 -1
- package/dist/generators/discovered-schema.d.ts +2 -0
- package/dist/generators/discovered-schema.d.ts.map +1 -1
- package/dist/index.cjs +207 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +207 -12
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +213 -10
- package/dist/internals.cjs.map +1 -1
- package/dist/internals.js +213 -10
- package/dist/internals.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -76,7 +76,7 @@ Public helpers in this workflow:
|
|
|
76
76
|
- `resolveModuleExportDeclaration(context, exportName?)` - Resolve only schema-source declarations (`class`, `interface`, `type` alias).
|
|
77
77
|
- `generateSchemasFromDeclaration(...)` - Generate from a resolved schema-source declaration.
|
|
78
78
|
- `generateSchemasFromParameter(...)` - Generate from a method or function parameter declaration.
|
|
79
|
-
- `generateSchemasFromReturnType(...)` - Generate from a method or function return type.
|
|
79
|
+
- `generateSchemasFromReturnType(...)` - Generate from a method or function return type, unwrapping awaited `Promise<T>`-style returns before generation.
|
|
80
80
|
- `generateSchemasFromType(...)` - Generate directly from a resolved `ts.Type`.
|
|
81
81
|
|
|
82
82
|
Use `resolveModuleExportDeclaration(...)` when your tooling wants to hand a resolved
|
|
@@ -11,6 +11,7 @@ import type { FieldNode, TypeNode, AnnotationNode, TypeDefinition, JsonValue, Re
|
|
|
11
11
|
import type { ExtensionRegistry } from "../extensions/index.js";
|
|
12
12
|
import type { MetadataPolicyInput } from "@formspec/core";
|
|
13
13
|
import { normalizeMetadataPolicy } from "../metadata/index.js";
|
|
14
|
+
export declare function isResolvableObjectLikeAliasTypeNode(typeNode: ts.TypeNode): boolean;
|
|
14
15
|
/**
|
|
15
16
|
* Layout metadata extracted from `@Group` and `@ShowWhen` TSDoc tags.
|
|
16
17
|
* One entry per field, in the same order as `fields`.
|
|
@@ -47,6 +48,7 @@ export interface IRClassAnalysis {
|
|
|
47
48
|
/** Static methods */
|
|
48
49
|
readonly staticMethods: readonly MethodInfo[];
|
|
49
50
|
}
|
|
51
|
+
export type AnalyzeTypeAliasToIRFailureKind = "duplicate-properties" | "not-object-like";
|
|
50
52
|
/**
|
|
51
53
|
* Result of analyzing a type alias into IR — either success or error.
|
|
52
54
|
*/
|
|
@@ -55,6 +57,7 @@ export type AnalyzeTypeAliasToIRResult = {
|
|
|
55
57
|
readonly analysis: IRClassAnalysis;
|
|
56
58
|
} | {
|
|
57
59
|
readonly ok: false;
|
|
60
|
+
readonly kind: AnalyzeTypeAliasToIRFailureKind;
|
|
58
61
|
readonly error: string;
|
|
59
62
|
};
|
|
60
63
|
export interface DeclarationRootInfo {
|
|
@@ -95,6 +98,7 @@ export declare function analyzeInterfaceToIR(interfaceDecl: ts.InterfaceDeclarat
|
|
|
95
98
|
* Analyzes a type alias declaration and produces canonical IR FieldNodes.
|
|
96
99
|
*/
|
|
97
100
|
export declare function analyzeTypeAliasToIR(typeAlias: ts.TypeAliasDeclaration, checker: ts.TypeChecker, file?: string, extensionRegistry?: ExtensionRegistry, metadataPolicy?: MetadataPolicyInput, discriminatorOptions?: DiscriminatorResolutionOptions): AnalyzeTypeAliasToIRResult;
|
|
101
|
+
export declare function getAnalyzableObjectLikePropertyName(name: ts.PropertyName): string | null;
|
|
98
102
|
/**
|
|
99
103
|
* Resolves a TypeScript type to a canonical IR TypeNode.
|
|
100
104
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"class-analyzer.d.ts","sourceRoot":"","sources":["../../src/analyzer/class-analyzer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAGL,KAAK,4BAA4B,EAElC,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EACV,SAAS,EACT,QAAQ,EAIR,cAAc,EAId,cAAc,EACd,SAAS,EACT,gBAAgB,EAEjB,MAAM,0BAA0B,CAAC;AAQlC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAgC,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"class-analyzer.d.ts","sourceRoot":"","sources":["../../src/analyzer/class-analyzer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAGL,KAAK,4BAA4B,EAElC,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EACV,SAAS,EACT,QAAQ,EAIR,cAAc,EAId,cAAc,EACd,SAAS,EACT,gBAAgB,EAEjB,MAAM,0BAA0B,CAAC;AAQlC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAgC,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAiB7F,wBAAgB,mCAAmC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,GAAG,OAAO,CAclF;AA0ED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,qEAAqE;IACrE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,6FAA6F;IAC7F,Q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B;IAC3B,QAAQ,EAAE,EAAE,CAAC,QAAQ,GAAG,SAAS,CAAC;IAClC,oBAAoB;IACpB,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC;IACd,0DAA0D;IAC1D,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,iEAAiE;IACjE,QAAQ,EAAE,OAAO,CAAC;CACnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../../src/analyzer/program.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../../src/analyzer/program.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAIjC,OAAO,EASL,KAAK,8BAA8B,EACnC,KAAK,eAAe,EAErB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,6BAA6B;IAC7B,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC;IACpB,uCAAuC;IACvC,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC;IACxB,qCAAqC;IACrC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,EAAE,CAAC,OAAO,EACnB,QAAQ,EAAE,MAAM,GACf,cAAc,CAahB;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,CA6DrE;AA6BD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,EAAE,CAAC,UAAU,EACzB,SAAS,EAAE,MAAM,GAChB,EAAE,CAAC,gBAAgB,GAAG,IAAI,CAE5B;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,EAAE,CAAC,UAAU,EACzB,aAAa,EAAE,MAAM,GACpB,EAAE,CAAC,oBAAoB,GAAG,IAAI,CAEhC;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,EAAE,CAAC,UAAU,EACzB,SAAS,EAAE,MAAM,GAChB,EAAE,CAAC,oBAAoB,GAAG,IAAI,CAEhC;AAiID;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,iBAAiB,CAAC,EAAE,iBAAiB,EACrC,cAAc,CAAC,EAAE,mBAAmB,EACpC,oBAAoB,CAAC,EAAE,8BAA8B,GACpD,eAAe,CAUjB;AAED;;GAEG;AACH,wBAAgB,sCAAsC,CACpD,GAAG,EAAE,cAAc,EACnB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,iBAAiB,CAAC,EAAE,iBAAiB,EACrC,cAAc,CAAC,EAAE,mBAAmB,EACpC,oBAAoB,CAAC,EAAE,8BAA8B,GACpD,eAAe,CAkGjB"}
|
package/dist/build-alpha.d.ts
CHANGED
|
@@ -554,6 +554,8 @@ export declare interface GenerateSchemasFromProgramOptions extends StaticSchemaG
|
|
|
554
554
|
/**
|
|
555
555
|
* Generates schemas for a method or function return type.
|
|
556
556
|
*
|
|
557
|
+
* Awaited `Promise<T>`-style return types are unwrapped before generation.
|
|
558
|
+
*
|
|
557
559
|
* @public
|
|
558
560
|
*/
|
|
559
561
|
export declare function generateSchemasFromReturnType(options: GenerateSchemasFromReturnTypeOptions): DiscoveredTypeSchemas;
|
package/dist/build-beta.d.ts
CHANGED
|
@@ -554,6 +554,8 @@ export declare interface GenerateSchemasFromProgramOptions extends StaticSchemaG
|
|
|
554
554
|
/**
|
|
555
555
|
* Generates schemas for a method or function return type.
|
|
556
556
|
*
|
|
557
|
+
* Awaited `Promise<T>`-style return types are unwrapped before generation.
|
|
558
|
+
*
|
|
557
559
|
* @public
|
|
558
560
|
*/
|
|
559
561
|
export declare function generateSchemasFromReturnType(options: GenerateSchemasFromReturnTypeOptions): DiscoveredTypeSchemas;
|
package/dist/build-internal.d.ts
CHANGED
|
@@ -554,6 +554,8 @@ export declare interface GenerateSchemasFromProgramOptions extends StaticSchemaG
|
|
|
554
554
|
/**
|
|
555
555
|
* Generates schemas for a method or function return type.
|
|
556
556
|
*
|
|
557
|
+
* Awaited `Promise<T>`-style return types are unwrapped before generation.
|
|
558
|
+
*
|
|
557
559
|
* @public
|
|
558
560
|
*/
|
|
559
561
|
export declare function generateSchemasFromReturnType(options: GenerateSchemasFromReturnTypeOptions): DiscoveredTypeSchemas;
|
package/dist/build.d.ts
CHANGED
|
@@ -554,6 +554,8 @@ export declare interface GenerateSchemasFromProgramOptions extends StaticSchemaG
|
|
|
554
554
|
/**
|
|
555
555
|
* Generates schemas for a method or function return type.
|
|
556
556
|
*
|
|
557
|
+
* Awaited `Promise<T>`-style return types are unwrapped before generation.
|
|
558
|
+
*
|
|
557
559
|
* @public
|
|
558
560
|
*/
|
|
559
561
|
export declare function generateSchemasFromReturnType(options: GenerateSchemasFromReturnTypeOptions): DiscoveredTypeSchemas;
|
package/dist/cli.cjs
CHANGED
|
@@ -3003,6 +3003,21 @@ function isObjectType(type) {
|
|
|
3003
3003
|
function isIntersectionType(type) {
|
|
3004
3004
|
return !!(type.flags & ts3.TypeFlags.Intersection);
|
|
3005
3005
|
}
|
|
3006
|
+
function isResolvableObjectLikeAliasTypeNode(typeNode) {
|
|
3007
|
+
if (ts3.isParenthesizedTypeNode(typeNode)) {
|
|
3008
|
+
return isResolvableObjectLikeAliasTypeNode(typeNode.type);
|
|
3009
|
+
}
|
|
3010
|
+
if (ts3.isTypeLiteralNode(typeNode) || ts3.isTypeReferenceNode(typeNode)) {
|
|
3011
|
+
return true;
|
|
3012
|
+
}
|
|
3013
|
+
return ts3.isIntersectionTypeNode(typeNode) && typeNode.types.length > 0 && typeNode.types.every((member) => isResolvableObjectLikeAliasTypeNode(member));
|
|
3014
|
+
}
|
|
3015
|
+
function isSemanticallyPlainObjectLikeType(type, checker) {
|
|
3016
|
+
if (isIntersectionType(type)) {
|
|
3017
|
+
return type.types.length > 0 && type.types.every((member) => isSemanticallyPlainObjectLikeType(member, checker));
|
|
3018
|
+
}
|
|
3019
|
+
return isObjectType(type) && checker.getSignaturesOfType(type, ts3.SignatureKind.Call).length === 0 && checker.getSignaturesOfType(type, ts3.SignatureKind.Construct).length === 0 && !checker.isArrayType(type) && !checker.isTupleType(type);
|
|
3020
|
+
}
|
|
3006
3021
|
function isTypeReference(type) {
|
|
3007
3022
|
return !!(type.flags & ts3.TypeFlags.Object) && !!(type.objectFlags & ts3.ObjectFlags.Reference);
|
|
3008
3023
|
}
|
|
@@ -3255,6 +3270,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3255
3270
|
const kindDesc = ts3.SyntaxKind[typeAlias.type.kind] ?? "unknown";
|
|
3256
3271
|
return {
|
|
3257
3272
|
ok: false,
|
|
3273
|
+
kind: "not-object-like",
|
|
3258
3274
|
error: `Type alias "${typeAlias.name.text}" at line ${String(line + 1)} is not an object-like type alias (found ${kindDesc})`
|
|
3259
3275
|
};
|
|
3260
3276
|
}
|
|
@@ -3269,6 +3285,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3269
3285
|
const { line } = sourceFile.getLineAndCharacterOfPosition(typeAlias.getStart());
|
|
3270
3286
|
return {
|
|
3271
3287
|
ok: false,
|
|
3288
|
+
kind: "duplicate-properties",
|
|
3272
3289
|
error: `Type alias "${name}" at line ${String(line + 1)} contains duplicate property names across object-like members: ${duplicatePropertyNames.join(", ")}`
|
|
3273
3290
|
};
|
|
3274
3291
|
}
|
|
@@ -3965,10 +3982,10 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
3965
3982
|
return [...duplicates].sort();
|
|
3966
3983
|
}
|
|
3967
3984
|
function getAnalyzableObjectLikePropertyName(name) {
|
|
3968
|
-
if (
|
|
3969
|
-
return
|
|
3985
|
+
if (ts3.isIdentifier(name) || ts3.isStringLiteral(name) || ts3.isNumericLiteral(name)) {
|
|
3986
|
+
return name.text;
|
|
3970
3987
|
}
|
|
3971
|
-
return
|
|
3988
|
+
return null;
|
|
3972
3989
|
}
|
|
3973
3990
|
function applyEnumMemberDisplayNames(type, annotations) {
|
|
3974
3991
|
if (!annotations.some(
|
|
@@ -4059,7 +4076,7 @@ function resolveRegisteredCustomTypeFromTypeNode(typeNode, extensionRegistry, ch
|
|
|
4059
4076
|
};
|
|
4060
4077
|
}
|
|
4061
4078
|
if (ts3.isTypeReferenceNode(typeNode) && ts3.isIdentifier(typeNode.typeName)) {
|
|
4062
|
-
const aliasDecl =
|
|
4079
|
+
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
4063
4080
|
if (aliasDecl !== void 0) {
|
|
4064
4081
|
return resolveRegisteredCustomTypeFromTypeNode(aliasDecl.type, extensionRegistry, checker);
|
|
4065
4082
|
}
|
|
@@ -4178,6 +4195,19 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4178
4195
|
diagnostics
|
|
4179
4196
|
);
|
|
4180
4197
|
}
|
|
4198
|
+
if (resolvedSourceTypeNode !== void 0 && isResolvableObjectLikeAliasTypeNode(resolvedSourceTypeNode) && isSemanticallyPlainObjectLikeType(type, checker)) {
|
|
4199
|
+
return resolveObjectType(
|
|
4200
|
+
type,
|
|
4201
|
+
checker,
|
|
4202
|
+
file,
|
|
4203
|
+
typeRegistry,
|
|
4204
|
+
visiting,
|
|
4205
|
+
sourceNode,
|
|
4206
|
+
metadataPolicy,
|
|
4207
|
+
extensionRegistry,
|
|
4208
|
+
diagnostics
|
|
4209
|
+
);
|
|
4210
|
+
}
|
|
4181
4211
|
}
|
|
4182
4212
|
if (isObjectType(type)) {
|
|
4183
4213
|
return resolveObjectType(
|
|
@@ -4252,13 +4282,13 @@ function getReferencedTypeAliasDeclaration(sourceNode, checker) {
|
|
|
4252
4282
|
if (!typeNode || !ts3.isTypeReferenceNode(typeNode)) {
|
|
4253
4283
|
return void 0;
|
|
4254
4284
|
}
|
|
4255
|
-
return
|
|
4285
|
+
return getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
4256
4286
|
}
|
|
4257
4287
|
function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
4258
4288
|
if (!ts3.isTypeReferenceNode(typeNode)) {
|
|
4259
4289
|
return false;
|
|
4260
4290
|
}
|
|
4261
|
-
const aliasDecl =
|
|
4291
|
+
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
4262
4292
|
if (!aliasDecl) {
|
|
4263
4293
|
return false;
|
|
4264
4294
|
}
|
|
@@ -4827,8 +4857,7 @@ function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new
|
|
|
4827
4857
|
if (!ts3.isTypeReferenceNode(typeNode) || !ts3.isIdentifier(typeNode.typeName)) {
|
|
4828
4858
|
return typeNode;
|
|
4829
4859
|
}
|
|
4830
|
-
const
|
|
4831
|
-
const aliasDecl = symbol?.declarations?.find(ts3.isTypeAliasDeclaration);
|
|
4860
|
+
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
4832
4861
|
if (aliasDecl === void 0 || visited.has(aliasDecl)) {
|
|
4833
4862
|
return typeNode;
|
|
4834
4863
|
}
|
|
@@ -4877,8 +4906,7 @@ function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegis
|
|
|
4877
4906
|
);
|
|
4878
4907
|
}
|
|
4879
4908
|
const symbol = checker.getSymbolAtLocation(typeNode.typeName);
|
|
4880
|
-
|
|
4881
|
-
const aliasDecl = symbol.declarations.find(ts3.isTypeAliasDeclaration);
|
|
4909
|
+
const aliasDecl = getAliasedTypeAliasDeclaration(symbol, checker);
|
|
4882
4910
|
if (!aliasDecl) return [];
|
|
4883
4911
|
if (ts3.isTypeLiteralNode(aliasDecl.type)) return [];
|
|
4884
4912
|
const aliasFieldType = resolveTypeNode(
|
|
@@ -4901,6 +4929,18 @@ function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegis
|
|
|
4901
4929
|
);
|
|
4902
4930
|
return constraints;
|
|
4903
4931
|
}
|
|
4932
|
+
function getAliasedSymbol(symbol, checker) {
|
|
4933
|
+
if (symbol === void 0) {
|
|
4934
|
+
return void 0;
|
|
4935
|
+
}
|
|
4936
|
+
return symbol.flags & ts3.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
4937
|
+
}
|
|
4938
|
+
function getAliasedTypeAliasDeclaration(symbol, checker) {
|
|
4939
|
+
return getAliasedSymbol(symbol, checker)?.declarations?.find(ts3.isTypeAliasDeclaration);
|
|
4940
|
+
}
|
|
4941
|
+
function getTypeAliasDeclarationFromTypeReference(typeNode, checker) {
|
|
4942
|
+
return getAliasedTypeAliasDeclaration(checker.getSymbolAtLocation(typeNode.typeName), checker);
|
|
4943
|
+
}
|
|
4904
4944
|
function provenanceForNode(node, file) {
|
|
4905
4945
|
const sourceFile = node.getSourceFile();
|
|
4906
4946
|
const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
@@ -5091,6 +5131,95 @@ function findInterfaceByName(sourceFile, interfaceName) {
|
|
|
5091
5131
|
function findTypeAliasByName(sourceFile, aliasName) {
|
|
5092
5132
|
return findNodeByName(sourceFile, aliasName, ts4.isTypeAliasDeclaration, (n) => n.name.text);
|
|
5093
5133
|
}
|
|
5134
|
+
function getResolvedObjectRootType(rootType, typeRegistry) {
|
|
5135
|
+
if (rootType.kind === "object") {
|
|
5136
|
+
return rootType;
|
|
5137
|
+
}
|
|
5138
|
+
if (rootType.kind !== "reference") {
|
|
5139
|
+
return null;
|
|
5140
|
+
}
|
|
5141
|
+
const definition = typeRegistry[rootType.name];
|
|
5142
|
+
return definition?.type.kind === "object" ? definition.type : null;
|
|
5143
|
+
}
|
|
5144
|
+
function createResolvedObjectAliasAnalysis(name, rootType, typeRegistry, rootInfo, diagnostics) {
|
|
5145
|
+
const resolvedRootType = getResolvedObjectRootType(rootType, typeRegistry);
|
|
5146
|
+
if (resolvedRootType === null) {
|
|
5147
|
+
return null;
|
|
5148
|
+
}
|
|
5149
|
+
const fields = resolvedRootType.properties.map((property) => ({
|
|
5150
|
+
kind: "field",
|
|
5151
|
+
name: property.name,
|
|
5152
|
+
...property.metadata !== void 0 && { metadata: property.metadata },
|
|
5153
|
+
type: property.type,
|
|
5154
|
+
required: !property.optional,
|
|
5155
|
+
constraints: property.constraints,
|
|
5156
|
+
annotations: property.annotations,
|
|
5157
|
+
provenance: property.provenance
|
|
5158
|
+
}));
|
|
5159
|
+
return {
|
|
5160
|
+
name,
|
|
5161
|
+
...rootInfo.metadata !== void 0 && { metadata: rootInfo.metadata },
|
|
5162
|
+
fields,
|
|
5163
|
+
fieldLayouts: fields.map(() => ({})),
|
|
5164
|
+
typeRegistry,
|
|
5165
|
+
...rootInfo.annotations.length > 0 && { annotations: [...rootInfo.annotations] },
|
|
5166
|
+
...diagnostics.length > 0 && { diagnostics: [...diagnostics] },
|
|
5167
|
+
instanceMethods: [],
|
|
5168
|
+
staticMethods: []
|
|
5169
|
+
};
|
|
5170
|
+
}
|
|
5171
|
+
function containsTypeReferenceInObjectLikeAlias(typeNode) {
|
|
5172
|
+
if (ts4.isParenthesizedTypeNode(typeNode)) {
|
|
5173
|
+
return containsTypeReferenceInObjectLikeAlias(typeNode.type);
|
|
5174
|
+
}
|
|
5175
|
+
if (ts4.isTypeReferenceNode(typeNode)) {
|
|
5176
|
+
return true;
|
|
5177
|
+
}
|
|
5178
|
+
return ts4.isIntersectionTypeNode(typeNode) && typeNode.types.some((member) => containsTypeReferenceInObjectLikeAlias(member));
|
|
5179
|
+
}
|
|
5180
|
+
function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
5181
|
+
if (ts4.isParenthesizedTypeNode(typeNode)) {
|
|
5182
|
+
return collectFallbackAliasMemberPropertyNames(typeNode.type, checker);
|
|
5183
|
+
}
|
|
5184
|
+
if (ts4.isTypeLiteralNode(typeNode)) {
|
|
5185
|
+
const propertyNames = [];
|
|
5186
|
+
for (const member of typeNode.members) {
|
|
5187
|
+
if (!ts4.isPropertySignature(member)) {
|
|
5188
|
+
continue;
|
|
5189
|
+
}
|
|
5190
|
+
const propertyName = getAnalyzableObjectLikePropertyName(member.name);
|
|
5191
|
+
if (propertyName !== null) {
|
|
5192
|
+
propertyNames.push(propertyName);
|
|
5193
|
+
}
|
|
5194
|
+
}
|
|
5195
|
+
return propertyNames;
|
|
5196
|
+
}
|
|
5197
|
+
if (ts4.isTypeReferenceNode(typeNode)) {
|
|
5198
|
+
return checker.getTypeFromTypeNode(typeNode).getProperties().map((property) => property.getName());
|
|
5199
|
+
}
|
|
5200
|
+
return null;
|
|
5201
|
+
}
|
|
5202
|
+
function findFallbackAliasDuplicatePropertyNames(typeNode, checker) {
|
|
5203
|
+
if (!ts4.isIntersectionTypeNode(typeNode)) {
|
|
5204
|
+
return [];
|
|
5205
|
+
}
|
|
5206
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5207
|
+
const duplicates = /* @__PURE__ */ new Set();
|
|
5208
|
+
for (const member of typeNode.types) {
|
|
5209
|
+
const propertyNames = collectFallbackAliasMemberPropertyNames(member, checker);
|
|
5210
|
+
if (propertyNames === null) {
|
|
5211
|
+
continue;
|
|
5212
|
+
}
|
|
5213
|
+
for (const propertyName of propertyNames) {
|
|
5214
|
+
if (seen.has(propertyName)) {
|
|
5215
|
+
duplicates.add(propertyName);
|
|
5216
|
+
} else {
|
|
5217
|
+
seen.add(propertyName);
|
|
5218
|
+
}
|
|
5219
|
+
}
|
|
5220
|
+
}
|
|
5221
|
+
return [...duplicates].sort();
|
|
5222
|
+
}
|
|
5094
5223
|
function analyzeNamedTypeToIR(filePath, typeName, extensionRegistry, metadataPolicy, discriminatorOptions) {
|
|
5095
5224
|
const ctx = createProgramContext(filePath);
|
|
5096
5225
|
return analyzeNamedTypeToIRFromProgramContext(
|
|
@@ -5139,6 +5268,51 @@ function analyzeNamedTypeToIRFromProgramContext(ctx, filePath, typeName, extensi
|
|
|
5139
5268
|
if (result.ok) {
|
|
5140
5269
|
return result.analysis;
|
|
5141
5270
|
}
|
|
5271
|
+
const fallbackEligible = result.kind === "not-object-like" && isResolvableObjectLikeAliasTypeNode(typeAlias.type) && containsTypeReferenceInObjectLikeAlias(typeAlias.type);
|
|
5272
|
+
if (!fallbackEligible) {
|
|
5273
|
+
throw new Error(result.error);
|
|
5274
|
+
}
|
|
5275
|
+
const duplicatePropertyNames = findFallbackAliasDuplicatePropertyNames(
|
|
5276
|
+
typeAlias.type,
|
|
5277
|
+
ctx.checker
|
|
5278
|
+
);
|
|
5279
|
+
if (duplicatePropertyNames.length > 0) {
|
|
5280
|
+
const sourceFile = typeAlias.getSourceFile();
|
|
5281
|
+
const { line } = sourceFile.getLineAndCharacterOfPosition(typeAlias.getStart());
|
|
5282
|
+
throw new Error(
|
|
5283
|
+
`Type alias "${typeAlias.name.text}" at line ${String(line + 1)} contains duplicate property names across object-like members: ${duplicatePropertyNames.join(", ")}`
|
|
5284
|
+
);
|
|
5285
|
+
}
|
|
5286
|
+
const rootInfo = analyzeDeclarationRootInfo(
|
|
5287
|
+
typeAlias,
|
|
5288
|
+
ctx.checker,
|
|
5289
|
+
analysisFilePath,
|
|
5290
|
+
extensionRegistry,
|
|
5291
|
+
metadataPolicy
|
|
5292
|
+
);
|
|
5293
|
+
const diagnostics = [...rootInfo.diagnostics];
|
|
5294
|
+
const typeRegistry = {};
|
|
5295
|
+
const rootType = resolveTypeNode(
|
|
5296
|
+
ctx.checker.getTypeAtLocation(typeAlias),
|
|
5297
|
+
ctx.checker,
|
|
5298
|
+
analysisFilePath,
|
|
5299
|
+
typeRegistry,
|
|
5300
|
+
/* @__PURE__ */ new Set(),
|
|
5301
|
+
typeAlias,
|
|
5302
|
+
createAnalyzerMetadataPolicy(metadataPolicy, discriminatorOptions),
|
|
5303
|
+
extensionRegistry,
|
|
5304
|
+
diagnostics
|
|
5305
|
+
);
|
|
5306
|
+
const fallbackAnalysis = createResolvedObjectAliasAnalysis(
|
|
5307
|
+
typeAlias.name.text,
|
|
5308
|
+
rootType,
|
|
5309
|
+
typeRegistry,
|
|
5310
|
+
rootInfo,
|
|
5311
|
+
diagnostics
|
|
5312
|
+
);
|
|
5313
|
+
if (fallbackAnalysis !== null) {
|
|
5314
|
+
return fallbackAnalysis;
|
|
5315
|
+
}
|
|
5142
5316
|
throw new Error(result.error);
|
|
5143
5317
|
}
|
|
5144
5318
|
throw new Error(
|
|
@@ -5683,15 +5857,36 @@ function generateSchemasFromParameter(options) {
|
|
|
5683
5857
|
}
|
|
5684
5858
|
function generateSchemasFromReturnType(options) {
|
|
5685
5859
|
const signature = options.context.checker.getSignatureFromDeclaration(options.declaration);
|
|
5686
|
-
const
|
|
5860
|
+
const returnType = signature !== void 0 ? options.context.checker.getReturnTypeOfSignature(signature) : options.context.checker.getTypeAtLocation(options.declaration);
|
|
5861
|
+
const type = unwrapPromiseType(options.context.checker, returnType);
|
|
5862
|
+
const sourceNode = type !== returnType ? unwrapPromiseTypeNode(options.declaration.type) ?? options.declaration.type ?? options.declaration : options.declaration.type ?? options.declaration;
|
|
5687
5863
|
const fallbackName = options.declaration.name !== void 0 && ts7.isIdentifier(options.declaration.name) ? `${options.declaration.name.text}ReturnType` : "ReturnType";
|
|
5688
5864
|
return generateSchemasFromResolvedType({
|
|
5689
5865
|
...options,
|
|
5690
5866
|
type,
|
|
5691
|
-
sourceNode
|
|
5867
|
+
sourceNode,
|
|
5692
5868
|
name: fallbackName
|
|
5693
5869
|
});
|
|
5694
5870
|
}
|
|
5871
|
+
function unwrapPromiseType(checker, type) {
|
|
5872
|
+
if (!("getAwaitedType" in checker) || typeof checker.getAwaitedType !== "function") {
|
|
5873
|
+
return type;
|
|
5874
|
+
}
|
|
5875
|
+
return checker.getAwaitedType(type) ?? type;
|
|
5876
|
+
}
|
|
5877
|
+
function unwrapPromiseTypeNode(typeNode) {
|
|
5878
|
+
if (typeNode === void 0) {
|
|
5879
|
+
return void 0;
|
|
5880
|
+
}
|
|
5881
|
+
if (ts7.isParenthesizedTypeNode(typeNode)) {
|
|
5882
|
+
const unwrapped = unwrapPromiseTypeNode(typeNode.type);
|
|
5883
|
+
return unwrapped ?? typeNode;
|
|
5884
|
+
}
|
|
5885
|
+
return isPromiseTypeReferenceNode(typeNode) ? typeNode.typeArguments[0] : typeNode;
|
|
5886
|
+
}
|
|
5887
|
+
function isPromiseTypeReferenceNode(typeNode) {
|
|
5888
|
+
return ts7.isTypeReferenceNode(typeNode) && ts7.isIdentifier(typeNode.typeName) && typeNode.typeName.text === "Promise" && typeNode.typeArguments !== void 0 && typeNode.typeArguments.length > 0;
|
|
5889
|
+
}
|
|
5695
5890
|
var ts7, import_internals6;
|
|
5696
5891
|
var init_discovered_schema = __esm({
|
|
5697
5892
|
"src/generators/discovered-schema.ts"() {
|