@dudousxd/nestjs-codegen 0.17.1 → 0.17.2
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/CHANGELOG.md +22 -0
- package/dist/cli/main.cjs +196 -172
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +190 -166
- package/dist/cli/main.js.map +1 -1
- package/dist/index.cjs +196 -172
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +190 -166
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +196 -172
- package/dist/nest/index.cjs.map +1 -1
- package/dist/nest/index.js +190 -166
- package/dist/nest/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2510,7 +2510,7 @@ var import_fast_glob3 = __toESM(require("fast-glob"), 1);
|
|
|
2510
2510
|
var import_ts_morph10 = require("ts-morph");
|
|
2511
2511
|
|
|
2512
2512
|
// src/discovery/dto-type-resolver.ts
|
|
2513
|
-
var
|
|
2513
|
+
var import_ts_morph8 = require("ts-morph");
|
|
2514
2514
|
|
|
2515
2515
|
// src/discovery/dto-to-ir.ts
|
|
2516
2516
|
var import_ts_morph4 = require("ts-morph");
|
|
@@ -3266,7 +3266,7 @@ function inSchemaFromDecorator(decorator) {
|
|
|
3266
3266
|
}
|
|
3267
3267
|
|
|
3268
3268
|
// src/discovery/filter-for.ts
|
|
3269
|
-
var
|
|
3269
|
+
var import_ts_morph7 = require("ts-morph");
|
|
3270
3270
|
|
|
3271
3271
|
// src/discovery/filter-field-types.ts
|
|
3272
3272
|
var import_ts_morph5 = require("ts-morph");
|
|
@@ -3485,6 +3485,123 @@ function toFilterFieldType(name, r) {
|
|
|
3485
3485
|
return ft;
|
|
3486
3486
|
}
|
|
3487
3487
|
|
|
3488
|
+
// src/discovery/heritage.ts
|
|
3489
|
+
var import_ts_morph6 = require("ts-morph");
|
|
3490
|
+
function resolveHeritageCall(node) {
|
|
3491
|
+
if (!node) return void 0;
|
|
3492
|
+
const expr = unwrapExpression(node);
|
|
3493
|
+
if (import_ts_morph6.Node.isCallExpression(expr)) return expr;
|
|
3494
|
+
if (!import_ts_morph6.Node.isIdentifier(expr)) return void 0;
|
|
3495
|
+
const decl = expr.getDefinitions().map((d) => d.getDeclarationNode()).find(
|
|
3496
|
+
(n) => n !== void 0 && import_ts_morph6.Node.isVariableDeclaration(n)
|
|
3497
|
+
);
|
|
3498
|
+
const init = decl?.getInitializer();
|
|
3499
|
+
if (!init) return void 0;
|
|
3500
|
+
const unwrapped = unwrapExpression(init);
|
|
3501
|
+
return import_ts_morph6.Node.isCallExpression(unwrapped) ? unwrapped : void 0;
|
|
3502
|
+
}
|
|
3503
|
+
function unwrapExpression(node) {
|
|
3504
|
+
let current = node;
|
|
3505
|
+
while (import_ts_morph6.Node.isAsExpression(current) || import_ts_morph6.Node.isSatisfiesExpression(current) || import_ts_morph6.Node.isParenthesizedExpression(current) || import_ts_morph6.Node.isTypeAssertion(current)) {
|
|
3506
|
+
current = current.getExpression();
|
|
3507
|
+
}
|
|
3508
|
+
return current;
|
|
3509
|
+
}
|
|
3510
|
+
function resolveReturnedClass(factoryDecl) {
|
|
3511
|
+
const body = factoryDecl.getBody();
|
|
3512
|
+
if (!body) return void 0;
|
|
3513
|
+
const returns = body.getDescendants().filter((n) => import_ts_morph6.Node.isReturnStatement(n));
|
|
3514
|
+
for (const ret of returns) {
|
|
3515
|
+
const expr = ret.getExpression();
|
|
3516
|
+
if (!expr) continue;
|
|
3517
|
+
const inner = unwrapExpression(expr);
|
|
3518
|
+
if (import_ts_morph6.Node.isClassExpression(inner)) {
|
|
3519
|
+
return inner;
|
|
3520
|
+
}
|
|
3521
|
+
if (import_ts_morph6.Node.isIdentifier(inner)) {
|
|
3522
|
+
const name = inner.getText();
|
|
3523
|
+
const decl = body.getDescendants().find((n) => import_ts_morph6.Node.isClassDeclaration(n) && n.getName() === name);
|
|
3524
|
+
if (decl) return decl;
|
|
3525
|
+
}
|
|
3526
|
+
}
|
|
3527
|
+
return void 0;
|
|
3528
|
+
}
|
|
3529
|
+
function resolveFactoryDeclaration(call) {
|
|
3530
|
+
const callee = call.getExpression();
|
|
3531
|
+
if (!import_ts_morph6.Node.isIdentifier(callee)) return void 0;
|
|
3532
|
+
return callee.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => import_ts_morph6.Node.isFunctionDeclaration(n));
|
|
3533
|
+
}
|
|
3534
|
+
function resolveFactoryStaticClass(node) {
|
|
3535
|
+
if (!import_ts_morph6.Node.isPropertyAccessExpression(node)) return void 0;
|
|
3536
|
+
const call = resolveHeritageCall(node.getExpression());
|
|
3537
|
+
if (!call) return void 0;
|
|
3538
|
+
const factoryDecl = resolveFactoryDeclaration(call);
|
|
3539
|
+
if (!factoryDecl) return void 0;
|
|
3540
|
+
const returnedClass = resolveReturnedClass(factoryDecl);
|
|
3541
|
+
if (!returnedClass) return void 0;
|
|
3542
|
+
const staticProp = returnedClass.getStaticProperties().find((p) => p.getName() === node.getName());
|
|
3543
|
+
if (!staticProp || !import_ts_morph6.Node.isPropertyDeclaration(staticProp)) return void 0;
|
|
3544
|
+
const init = staticProp.getInitializer();
|
|
3545
|
+
if (!init) return void 0;
|
|
3546
|
+
const inner = unwrapExpression(init);
|
|
3547
|
+
if (import_ts_morph6.Node.isClassExpression(inner)) return inner;
|
|
3548
|
+
if (!import_ts_morph6.Node.isIdentifier(inner)) return void 0;
|
|
3549
|
+
return inner.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => n !== void 0 && import_ts_morph6.Node.isClassDeclaration(n));
|
|
3550
|
+
}
|
|
3551
|
+
function resolveInheritedMethods(cls) {
|
|
3552
|
+
const expr = resolveHeritageCall(cls.getExtends()?.getExpression());
|
|
3553
|
+
if (!expr) return void 0;
|
|
3554
|
+
const callee = expr.getExpression();
|
|
3555
|
+
if (!import_ts_morph6.Node.isIdentifier(callee)) return void 0;
|
|
3556
|
+
const factoryDecl = resolveFactoryDeclaration(expr);
|
|
3557
|
+
if (!factoryDecl) return void 0;
|
|
3558
|
+
const returnedClass = resolveReturnedClass(factoryDecl);
|
|
3559
|
+
if (!returnedClass) return void 0;
|
|
3560
|
+
const classArgs = [];
|
|
3561
|
+
for (const arg of expr.getArguments()) {
|
|
3562
|
+
if (!import_ts_morph6.Node.isIdentifier(arg)) continue;
|
|
3563
|
+
const decl = arg.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => import_ts_morph6.Node.isClassDeclaration(n));
|
|
3564
|
+
if (decl) {
|
|
3565
|
+
classArgs.push({
|
|
3566
|
+
name: decl.getName() ?? arg.getText(),
|
|
3567
|
+
filePath: decl.getSourceFile().getFilePath()
|
|
3568
|
+
});
|
|
3569
|
+
}
|
|
3570
|
+
}
|
|
3571
|
+
return {
|
|
3572
|
+
methods: returnedClass.getMethods(),
|
|
3573
|
+
factoryName: callee.getText(),
|
|
3574
|
+
factoryFilePath: factoryDecl.getSourceFile().getFilePath(),
|
|
3575
|
+
classArgs
|
|
3576
|
+
};
|
|
3577
|
+
}
|
|
3578
|
+
var mixinTypeProject;
|
|
3579
|
+
function getMixinTypeProject() {
|
|
3580
|
+
mixinTypeProject ??= new import_ts_morph6.Project({
|
|
3581
|
+
skipAddingFilesFromTsConfig: true,
|
|
3582
|
+
compilerOptions: { strict: true }
|
|
3583
|
+
});
|
|
3584
|
+
return mixinTypeProject;
|
|
3585
|
+
}
|
|
3586
|
+
function clearMixinTypeProject() {
|
|
3587
|
+
mixinTypeProject = void 0;
|
|
3588
|
+
}
|
|
3589
|
+
function resolveInstantiatedReturnType(cls, methodName) {
|
|
3590
|
+
const filePath = cls.getSourceFile().getFilePath();
|
|
3591
|
+
const className = cls.getName();
|
|
3592
|
+
if (!className) return void 0;
|
|
3593
|
+
const project = getMixinTypeProject();
|
|
3594
|
+
const sourceFile = project.getSourceFile(filePath) ?? project.addSourceFileAtPathIfExists(filePath);
|
|
3595
|
+
const typedCls = sourceFile?.getClass(className);
|
|
3596
|
+
if (!typedCls) return void 0;
|
|
3597
|
+
const prop = typedCls.getType().getProperty(methodName);
|
|
3598
|
+
if (!prop) return void 0;
|
|
3599
|
+
const returnType = prop.getTypeAtLocation(typedCls).getCallSignatures()[0]?.getReturnType();
|
|
3600
|
+
if (!returnType) return void 0;
|
|
3601
|
+
const unwrapped = returnType.getSymbol()?.getName() === "Promise" ? returnType.getTypeArguments()[0] ?? returnType : returnType;
|
|
3602
|
+
return unwrapped.getText(typedCls);
|
|
3603
|
+
}
|
|
3604
|
+
|
|
3488
3605
|
// src/discovery/filter-for.ts
|
|
3489
3606
|
function resolveMixinEntityClass(mixin, project) {
|
|
3490
3607
|
const entityArg = mixin?.classArgs[0];
|
|
@@ -3493,7 +3610,7 @@ function resolveMixinEntityClass(mixin, project) {
|
|
|
3493
3610
|
return file?.getClass(entityArg.name);
|
|
3494
3611
|
}
|
|
3495
3612
|
function classifyFilterForHint(typeInit) {
|
|
3496
|
-
if (
|
|
3613
|
+
if (import_ts_morph7.Node.isStringLiteral(typeInit)) {
|
|
3497
3614
|
switch (typeInit.getLiteralValue()) {
|
|
3498
3615
|
case "string":
|
|
3499
3616
|
return { kind: "string" };
|
|
@@ -3507,10 +3624,10 @@ function classifyFilterForHint(typeInit) {
|
|
|
3507
3624
|
return null;
|
|
3508
3625
|
}
|
|
3509
3626
|
}
|
|
3510
|
-
if (
|
|
3627
|
+
if (import_ts_morph7.Node.isArrayLiteralExpression(typeInit)) {
|
|
3511
3628
|
const values = [];
|
|
3512
3629
|
for (const el of typeInit.getElements()) {
|
|
3513
|
-
if (!
|
|
3630
|
+
if (!import_ts_morph7.Node.isStringLiteral(el)) return null;
|
|
3514
3631
|
values.push(el.getLiteralValue());
|
|
3515
3632
|
}
|
|
3516
3633
|
if (values.length === 0) return null;
|
|
@@ -3545,11 +3662,11 @@ function extractFilterForHints(classDecl, project) {
|
|
|
3545
3662
|
if (!filterForDec) continue;
|
|
3546
3663
|
const args = filterForDec.getArguments();
|
|
3547
3664
|
const keyArg = args[0];
|
|
3548
|
-
const inputKey = keyArg &&
|
|
3665
|
+
const inputKey = keyArg && import_ts_morph7.Node.isStringLiteral(keyArg) ? keyArg.getLiteralValue() : method.getName();
|
|
3549
3666
|
const optsArg = args[1];
|
|
3550
|
-
if (optsArg &&
|
|
3667
|
+
if (optsArg && import_ts_morph7.Node.isObjectLiteralExpression(optsArg)) {
|
|
3551
3668
|
const typeProp = optsArg.getProperty("type");
|
|
3552
|
-
if (typeProp &&
|
|
3669
|
+
if (typeProp && import_ts_morph7.Node.isPropertyAssignment(typeProp)) {
|
|
3553
3670
|
const typeInit = typeProp.getInitializer();
|
|
3554
3671
|
if (typeInit) {
|
|
3555
3672
|
const classified = classifyFilterForHint(typeInit);
|
|
@@ -3574,21 +3691,23 @@ function extractApplyFilterInfo(method, sourceFile, project, mixin) {
|
|
|
3574
3691
|
const args = filterDecorator.getArguments();
|
|
3575
3692
|
if (args.length === 0) continue;
|
|
3576
3693
|
const filterClassArg = args[0];
|
|
3577
|
-
if (!filterClassArg
|
|
3694
|
+
if (!filterClassArg) continue;
|
|
3695
|
+
const factoryStaticClass = resolveFactoryStaticClass(filterClassArg);
|
|
3696
|
+
if (!factoryStaticClass && !import_ts_morph7.Node.isIdentifier(filterClassArg)) continue;
|
|
3578
3697
|
let source = "query";
|
|
3579
3698
|
const optionsArg = args[1];
|
|
3580
|
-
if (optionsArg &&
|
|
3699
|
+
if (optionsArg && import_ts_morph7.Node.isObjectLiteralExpression(optionsArg)) {
|
|
3581
3700
|
const sourceProp = optionsArg.getProperty("source");
|
|
3582
|
-
if (sourceProp &&
|
|
3701
|
+
if (sourceProp && import_ts_morph7.Node.isPropertyAssignment(sourceProp)) {
|
|
3583
3702
|
const init = sourceProp.getInitializer();
|
|
3584
|
-
if (init &&
|
|
3703
|
+
if (init && import_ts_morph7.Node.isStringLiteral(init) && init.getLiteralValue() === "body") {
|
|
3585
3704
|
source = "body";
|
|
3586
3705
|
}
|
|
3587
3706
|
}
|
|
3588
3707
|
}
|
|
3589
3708
|
const filterClassName = filterClassArg.getText();
|
|
3590
|
-
const resolved = findType(filterClassName, declFile, project);
|
|
3591
|
-
const classDecl = resolved?.kind === "class" ? resolved.decl : resolveLocalClassDeclaration(filterClassArg);
|
|
3709
|
+
const resolved = factoryStaticClass ? void 0 : findType(filterClassName, declFile, project);
|
|
3710
|
+
const classDecl = factoryStaticClass ?? (resolved?.kind === "class" ? resolved.decl : resolveLocalClassDeclaration(filterClassArg));
|
|
3592
3711
|
if (classDecl) {
|
|
3593
3712
|
let fieldTypes = extractClassPropertyTypes(classDecl, project);
|
|
3594
3713
|
if (fieldTypes.length === 0) {
|
|
@@ -3644,22 +3763,22 @@ function resolveRelationEntity(prop, sourceFile, project) {
|
|
|
3644
3763
|
const args = dec.getArguments();
|
|
3645
3764
|
if (args.length === 0) continue;
|
|
3646
3765
|
const arg = args[0];
|
|
3647
|
-
if (
|
|
3766
|
+
if (import_ts_morph7.Node.isObjectLiteralExpression(arg)) {
|
|
3648
3767
|
const entityProp = arg.getProperty("entity");
|
|
3649
|
-
if (entityProp &&
|
|
3768
|
+
if (entityProp && import_ts_morph7.Node.isPropertyAssignment(entityProp)) {
|
|
3650
3769
|
const init = entityProp.getInitializer();
|
|
3651
|
-
if (init &&
|
|
3770
|
+
if (init && import_ts_morph7.Node.isArrowFunction(init)) {
|
|
3652
3771
|
const body = init.getBody();
|
|
3653
|
-
if (
|
|
3772
|
+
if (import_ts_morph7.Node.isIdentifier(body)) {
|
|
3654
3773
|
const resolved = findType(body.getText(), prop.getSourceFile(), project);
|
|
3655
3774
|
if (resolved?.kind === "class") return resolved.decl;
|
|
3656
3775
|
}
|
|
3657
3776
|
}
|
|
3658
3777
|
}
|
|
3659
3778
|
}
|
|
3660
|
-
if (
|
|
3779
|
+
if (import_ts_morph7.Node.isArrowFunction(arg)) {
|
|
3661
3780
|
const body = arg.getBody();
|
|
3662
|
-
if (
|
|
3781
|
+
if (import_ts_morph7.Node.isIdentifier(body)) {
|
|
3663
3782
|
const resolved = findType(body.getText(), prop.getSourceFile(), project);
|
|
3664
3783
|
if (resolved?.kind === "class") return resolved.decl;
|
|
3665
3784
|
}
|
|
@@ -3678,15 +3797,15 @@ function extractClassPropertyTypes(classDecl, project) {
|
|
|
3678
3797
|
return fields;
|
|
3679
3798
|
}
|
|
3680
3799
|
function resolveLocalClassDeclaration(identifier) {
|
|
3681
|
-
if (!
|
|
3682
|
-
return identifier.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => n !== void 0 &&
|
|
3800
|
+
if (!import_ts_morph7.Node.isIdentifier(identifier)) return void 0;
|
|
3801
|
+
return identifier.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => n !== void 0 && import_ts_morph7.Node.isClassDeclaration(n));
|
|
3683
3802
|
}
|
|
3684
3803
|
function resolveDeclaredEntity(optionsArg, filterClass, project) {
|
|
3685
|
-
if (!
|
|
3804
|
+
if (!import_ts_morph7.Node.isObjectLiteralExpression(optionsArg)) return void 0;
|
|
3686
3805
|
const entityProp = optionsArg.getProperty("entity");
|
|
3687
|
-
if (!entityProp || !
|
|
3806
|
+
if (!entityProp || !import_ts_morph7.Node.isPropertyAssignment(entityProp)) return void 0;
|
|
3688
3807
|
const entityInit = entityProp.getInitializer();
|
|
3689
|
-
if (!entityInit || !
|
|
3808
|
+
if (!entityInit || !import_ts_morph7.Node.isIdentifier(entityInit)) return void 0;
|
|
3690
3809
|
const resolved = findType(entityInit.getText(), filterClass.getSourceFile(), project);
|
|
3691
3810
|
if (!resolved || resolved.kind !== "class") return void 0;
|
|
3692
3811
|
return resolved.decl;
|
|
@@ -3697,7 +3816,7 @@ function extractFilterableEntityFields(filterClass, project, entityOverride) {
|
|
|
3697
3816
|
const args = filterableDecorator.getArguments();
|
|
3698
3817
|
if (args.length === 0) return [];
|
|
3699
3818
|
const optionsArg = args[0];
|
|
3700
|
-
if (!
|
|
3819
|
+
if (!import_ts_morph7.Node.isObjectLiteralExpression(optionsArg)) return [];
|
|
3701
3820
|
const entityDecl = entityOverride ?? resolveDeclaredEntity(optionsArg, filterClass, project);
|
|
3702
3821
|
if (!entityDecl) return [];
|
|
3703
3822
|
const fields = collectEntityFields(
|
|
@@ -3710,17 +3829,17 @@ function extractFilterableEntityFields(filterClass, project, entityOverride) {
|
|
|
3710
3829
|
const relationsDecorator = filterClass.getDecorators().find((d) => d.getName() === "Relations");
|
|
3711
3830
|
if (relationsDecorator) {
|
|
3712
3831
|
const relArgs = relationsDecorator.getArguments();
|
|
3713
|
-
if (relArgs.length > 0 &&
|
|
3832
|
+
if (relArgs.length > 0 && import_ts_morph7.Node.isObjectLiteralExpression(relArgs[0])) {
|
|
3714
3833
|
for (const relProp of relArgs[0].getProperties()) {
|
|
3715
|
-
if (!
|
|
3834
|
+
if (!import_ts_morph7.Node.isPropertyAssignment(relProp)) continue;
|
|
3716
3835
|
const relInit = relProp.getInitializer();
|
|
3717
|
-
if (!relInit || !
|
|
3836
|
+
if (!relInit || !import_ts_morph7.Node.isObjectLiteralExpression(relInit)) continue;
|
|
3718
3837
|
const keysProp = relInit.getProperty("keys");
|
|
3719
|
-
if (!keysProp || !
|
|
3838
|
+
if (!keysProp || !import_ts_morph7.Node.isPropertyAssignment(keysProp)) continue;
|
|
3720
3839
|
const keysInit = keysProp.getInitializer();
|
|
3721
|
-
if (!keysInit || !
|
|
3840
|
+
if (!keysInit || !import_ts_morph7.Node.isArrayLiteralExpression(keysInit)) continue;
|
|
3722
3841
|
for (const el of keysInit.getElements()) {
|
|
3723
|
-
if (
|
|
3842
|
+
if (import_ts_morph7.Node.isStringLiteral(el)) {
|
|
3724
3843
|
fields.push(toFilterFieldType(el.getLiteralValue(), { kind: "unknown" }));
|
|
3725
3844
|
}
|
|
3726
3845
|
}
|
|
@@ -3761,22 +3880,22 @@ var PASSTHROUGH_UTILITY = /* @__PURE__ */ new Set([
|
|
|
3761
3880
|
]);
|
|
3762
3881
|
function resolveTypeNodeToString(typeNode, sourceFile, project, depth, subst = /* @__PURE__ */ new Map()) {
|
|
3763
3882
|
if (depth <= 0) return "unknown";
|
|
3764
|
-
if (
|
|
3883
|
+
if (import_ts_morph8.Node.isArrayTypeNode(typeNode)) {
|
|
3765
3884
|
const elementType = typeNode.getElementTypeNode();
|
|
3766
3885
|
return `Array<${resolveTypeNodeToString(elementType, sourceFile, project, depth, subst)}>`;
|
|
3767
3886
|
}
|
|
3768
|
-
if (
|
|
3887
|
+
if (import_ts_morph8.Node.isUnionTypeNode(typeNode)) {
|
|
3769
3888
|
return typeNode.getTypeNodes().map((t) => resolveTypeNodeToString(t, sourceFile, project, depth, subst)).join(" | ");
|
|
3770
3889
|
}
|
|
3771
|
-
if (
|
|
3890
|
+
if (import_ts_morph8.Node.isIntersectionTypeNode(typeNode)) {
|
|
3772
3891
|
return typeNode.getTypeNodes().map((t) => resolveTypeNodeToString(t, sourceFile, project, depth, subst)).join(" & ");
|
|
3773
3892
|
}
|
|
3774
|
-
if (
|
|
3893
|
+
if (import_ts_morph8.Node.isParenthesizedTypeNode(typeNode)) {
|
|
3775
3894
|
return `(${resolveTypeNodeToString(typeNode.getTypeNode(), sourceFile, project, depth, subst)})`;
|
|
3776
3895
|
}
|
|
3777
|
-
if (
|
|
3896
|
+
if (import_ts_morph8.Node.isTypeReference(typeNode)) {
|
|
3778
3897
|
const typeName = typeNode.getTypeName();
|
|
3779
|
-
const name =
|
|
3898
|
+
const name = import_ts_morph8.Node.isIdentifier(typeName) ? typeName.getText() : typeNode.getText();
|
|
3780
3899
|
const bound = subst.get(name);
|
|
3781
3900
|
if (bound !== void 0) return bound;
|
|
3782
3901
|
if (name === "string" || name === "number" || name === "boolean") return name;
|
|
@@ -3799,10 +3918,10 @@ function resolveTypeNodeToString(typeNode, sourceFile, project, depth, subst = /
|
|
|
3799
3918
|
dbg("unresolvable type:", name, "in", sourceFile.getFilePath());
|
|
3800
3919
|
return "unknown";
|
|
3801
3920
|
}
|
|
3802
|
-
if (
|
|
3921
|
+
if (import_ts_morph8.Node.isTypeLiteral(typeNode)) {
|
|
3803
3922
|
const members = [];
|
|
3804
3923
|
for (const member of typeNode.getMembers()) {
|
|
3805
|
-
if (
|
|
3924
|
+
if (import_ts_morph8.Node.isPropertySignature(member)) {
|
|
3806
3925
|
const memberTypeNode = member.getTypeNode();
|
|
3807
3926
|
const memberType = memberTypeNode ? resolveTypeNodeToString(memberTypeNode, sourceFile, project, depth, subst) : "unknown";
|
|
3808
3927
|
members.push(`${member.getName()}${member.hasQuestionToken() ? "?" : ""}: ${memberType}`);
|
|
@@ -3813,11 +3932,11 @@ function resolveTypeNodeToString(typeNode, sourceFile, project, depth, subst = /
|
|
|
3813
3932
|
return members.length > 0 ? `{ ${members.join("; ")} }` : "{}";
|
|
3814
3933
|
}
|
|
3815
3934
|
const kind = typeNode.getKind();
|
|
3816
|
-
if (kind ===
|
|
3817
|
-
if (kind ===
|
|
3818
|
-
if (kind ===
|
|
3819
|
-
if (kind ===
|
|
3820
|
-
if (kind ===
|
|
3935
|
+
if (kind === import_ts_morph8.SyntaxKind.StringKeyword) return "string";
|
|
3936
|
+
if (kind === import_ts_morph8.SyntaxKind.NumberKeyword) return "number";
|
|
3937
|
+
if (kind === import_ts_morph8.SyntaxKind.BooleanKeyword) return "boolean";
|
|
3938
|
+
if (kind === import_ts_morph8.SyntaxKind.UnknownKeyword) return "unknown";
|
|
3939
|
+
if (kind === import_ts_morph8.SyntaxKind.AnyKeyword) return "unknown";
|
|
3821
3940
|
return typeNode.getText();
|
|
3822
3941
|
}
|
|
3823
3942
|
function unwrapFirstTypeArg(typeNode, sourceFile, project, depth, mode, subst = /* @__PURE__ */ new Map()) {
|
|
@@ -3902,7 +4021,7 @@ function extractQueryType(method, sourceFile, project) {
|
|
|
3902
4021
|
if (!queryDecorator) continue;
|
|
3903
4022
|
const queryArgs = queryDecorator.getArguments();
|
|
3904
4023
|
const nameArg = queryArgs[0];
|
|
3905
|
-
if (!nameArg || !
|
|
4024
|
+
if (!nameArg || !import_ts_morph8.Node.isStringLiteral(nameArg)) continue;
|
|
3906
4025
|
const queryName = nameArg.getLiteralValue();
|
|
3907
4026
|
const typeNode = param.getTypeNode();
|
|
3908
4027
|
const queryType = typeNode ? resolveTypeNodeToString(typeNode, sourceFile, project, 3) : "string";
|
|
@@ -3913,8 +4032,8 @@ function extractQueryType(method, sourceFile, project) {
|
|
|
3913
4032
|
function isParamOptional(param) {
|
|
3914
4033
|
if (param.hasQuestionToken() || param.hasInitializer()) return true;
|
|
3915
4034
|
const typeNode = param.getTypeNode();
|
|
3916
|
-
if (typeNode &&
|
|
3917
|
-
return typeNode.getTypeNodes().some((t) => t.getKind() ===
|
|
4035
|
+
if (typeNode && import_ts_morph8.Node.isUnionTypeNode(typeNode)) {
|
|
4036
|
+
return typeNode.getTypeNodes().some((t) => t.getKind() === import_ts_morph8.SyntaxKind.UndefinedKeyword);
|
|
3918
4037
|
}
|
|
3919
4038
|
return false;
|
|
3920
4039
|
}
|
|
@@ -3926,7 +4045,7 @@ function extractParamsType(method, sourceFile, project) {
|
|
|
3926
4045
|
const paramArgs = paramDecorator.getArguments();
|
|
3927
4046
|
if (paramArgs.length === 0) continue;
|
|
3928
4047
|
const nameArg = paramArgs[0];
|
|
3929
|
-
if (!
|
|
4048
|
+
if (!import_ts_morph8.Node.isStringLiteral(nameArg)) continue;
|
|
3930
4049
|
const paramName = nameArg.getLiteralValue();
|
|
3931
4050
|
const typeNode = param.getTypeNode();
|
|
3932
4051
|
const paramType = typeNode ? resolveTypeNodeToString(typeNode, sourceFile, project, 3) : "string";
|
|
@@ -3947,28 +4066,28 @@ function extractUploadedFiles(method) {
|
|
|
3947
4066
|
for (const decorator of method.getDecorators()) {
|
|
3948
4067
|
if (decorator.getName() !== "UseInterceptors") continue;
|
|
3949
4068
|
for (const arg of decorator.getArguments()) {
|
|
3950
|
-
if (!
|
|
4069
|
+
if (!import_ts_morph8.Node.isCallExpression(arg)) continue;
|
|
3951
4070
|
const interceptor = arg.getExpression().getText();
|
|
3952
4071
|
const callArgs = arg.getArguments();
|
|
3953
4072
|
const firstArg2 = callArgs[0];
|
|
3954
4073
|
if (interceptor === "FileInterceptor") {
|
|
3955
|
-
if (firstArg2 &&
|
|
4074
|
+
if (firstArg2 && import_ts_morph8.Node.isStringLiteral(firstArg2)) {
|
|
3956
4075
|
entries.push(`${firstArg2.getLiteralValue()}: ${FILE}`);
|
|
3957
4076
|
multipart = true;
|
|
3958
4077
|
}
|
|
3959
4078
|
} else if (interceptor === "FilesInterceptor") {
|
|
3960
|
-
if (firstArg2 &&
|
|
4079
|
+
if (firstArg2 && import_ts_morph8.Node.isStringLiteral(firstArg2)) {
|
|
3961
4080
|
entries.push(`${firstArg2.getLiteralValue()}: Array<${FILE}>`);
|
|
3962
4081
|
multipart = true;
|
|
3963
4082
|
}
|
|
3964
4083
|
} else if (interceptor === "FileFieldsInterceptor") {
|
|
3965
|
-
if (firstArg2 &&
|
|
4084
|
+
if (firstArg2 && import_ts_morph8.Node.isArrayLiteralExpression(firstArg2)) {
|
|
3966
4085
|
for (const el of firstArg2.getElements()) {
|
|
3967
|
-
if (!
|
|
4086
|
+
if (!import_ts_morph8.Node.isObjectLiteralExpression(el)) continue;
|
|
3968
4087
|
const nameProp = el.getProperty("name");
|
|
3969
|
-
if (nameProp &&
|
|
4088
|
+
if (nameProp && import_ts_morph8.Node.isPropertyAssignment(nameProp)) {
|
|
3970
4089
|
const init = nameProp.getInitializer();
|
|
3971
|
-
if (init &&
|
|
4090
|
+
if (init && import_ts_morph8.Node.isStringLiteral(init)) {
|
|
3972
4091
|
entries.push(`${init.getLiteralValue()}: Array<${FILE}>`);
|
|
3973
4092
|
}
|
|
3974
4093
|
}
|
|
@@ -3988,13 +4107,13 @@ function extractResponseType(method, sourceFile, project) {
|
|
|
3988
4107
|
if (apiResponseDecorator) {
|
|
3989
4108
|
const args = apiResponseDecorator.getArguments();
|
|
3990
4109
|
const optsArg = args[0];
|
|
3991
|
-
if (optsArg &&
|
|
4110
|
+
if (optsArg && import_ts_morph8.Node.isObjectLiteralExpression(optsArg)) {
|
|
3992
4111
|
for (const prop of optsArg.getProperties()) {
|
|
3993
|
-
if (!
|
|
4112
|
+
if (!import_ts_morph8.Node.isPropertyAssignment(prop)) continue;
|
|
3994
4113
|
if (prop.getName() !== "type") continue;
|
|
3995
4114
|
const val = prop.getInitializer();
|
|
3996
4115
|
if (!val) continue;
|
|
3997
|
-
if (
|
|
4116
|
+
if (import_ts_morph8.Node.isArrayLiteralExpression(val)) {
|
|
3998
4117
|
const elements = val.getElements();
|
|
3999
4118
|
const firstEl = elements[0];
|
|
4000
4119
|
if (elements.length > 0 && firstEl !== void 0) {
|
|
@@ -4015,24 +4134,24 @@ function extractResponseType(method, sourceFile, project) {
|
|
|
4015
4134
|
}
|
|
4016
4135
|
function apiResponseStatus(decorator) {
|
|
4017
4136
|
const optsArg = decorator.getArguments()[0];
|
|
4018
|
-
if (!optsArg || !
|
|
4137
|
+
if (!optsArg || !import_ts_morph8.Node.isObjectLiteralExpression(optsArg)) return null;
|
|
4019
4138
|
for (const prop of optsArg.getProperties()) {
|
|
4020
|
-
if (!
|
|
4139
|
+
if (!import_ts_morph8.Node.isPropertyAssignment(prop)) continue;
|
|
4021
4140
|
if (prop.getName() !== "status") continue;
|
|
4022
4141
|
const val = prop.getInitializer();
|
|
4023
|
-
if (val &&
|
|
4142
|
+
if (val && import_ts_morph8.Node.isNumericLiteral(val)) return Number(val.getLiteralValue());
|
|
4024
4143
|
}
|
|
4025
4144
|
return null;
|
|
4026
4145
|
}
|
|
4027
4146
|
function apiResponseTypeNode(decorator) {
|
|
4028
4147
|
const optsArg = decorator.getArguments()[0];
|
|
4029
|
-
if (!optsArg || !
|
|
4148
|
+
if (!optsArg || !import_ts_morph8.Node.isObjectLiteralExpression(optsArg)) return null;
|
|
4030
4149
|
for (const prop of optsArg.getProperties()) {
|
|
4031
|
-
if (!
|
|
4150
|
+
if (!import_ts_morph8.Node.isPropertyAssignment(prop)) continue;
|
|
4032
4151
|
if (prop.getName() !== "type") continue;
|
|
4033
4152
|
const val = prop.getInitializer();
|
|
4034
4153
|
if (!val) return null;
|
|
4035
|
-
if (
|
|
4154
|
+
if (import_ts_morph8.Node.isArrayLiteralExpression(val)) {
|
|
4036
4155
|
const first = val.getElements()[0];
|
|
4037
4156
|
return first ? { node: first, isArray: true } : null;
|
|
4038
4157
|
}
|
|
@@ -4050,7 +4169,7 @@ function extractErrorType(method, sourceFile, project) {
|
|
|
4050
4169
|
const inner = resolveIdentifierToClassType(typeInfo.node, sourceFile, project, 3);
|
|
4051
4170
|
const type = typeInfo.isArray ? `Array<${inner}>` : inner;
|
|
4052
4171
|
let ref = null;
|
|
4053
|
-
if (
|
|
4172
|
+
if (import_ts_morph8.Node.isIdentifier(typeInfo.node)) {
|
|
4054
4173
|
const name = typeInfo.node.getText();
|
|
4055
4174
|
const localDecl = sourceFile.getInterface(name) || sourceFile.getClass(name) || sourceFile.getTypeAlias(name);
|
|
4056
4175
|
if (localDecl?.isExported()) {
|
|
@@ -4067,7 +4186,7 @@ function extractErrorType(method, sourceFile, project) {
|
|
|
4067
4186
|
return null;
|
|
4068
4187
|
}
|
|
4069
4188
|
function resolveIdentifierToClassType(node, sourceFile, project, depth) {
|
|
4070
|
-
if (!
|
|
4189
|
+
if (!import_ts_morph8.Node.isIdentifier(node)) return "unknown";
|
|
4071
4190
|
const name = node.getText();
|
|
4072
4191
|
const resolved = findType(name, sourceFile, project);
|
|
4073
4192
|
if (resolved) {
|
|
@@ -4087,9 +4206,9 @@ var STREAM_ENVELOPES = /* @__PURE__ */ new Set(["MessageEvent", "MessageEventLik
|
|
|
4087
4206
|
var BINARY_RESPONSE_TYPES = /* @__PURE__ */ new Set(["StreamableFile", "Buffer"]);
|
|
4088
4207
|
function detectBinaryResponse(method) {
|
|
4089
4208
|
const node = unwrapNamedContainer(method.getReturnTypeNode(), /* @__PURE__ */ new Set(["Promise"]));
|
|
4090
|
-
if (!node || !
|
|
4209
|
+
if (!node || !import_ts_morph8.Node.isTypeReference(node)) return false;
|
|
4091
4210
|
const typeName = node.getTypeName();
|
|
4092
|
-
const name =
|
|
4211
|
+
const name = import_ts_morph8.Node.isIdentifier(typeName) ? typeName.getText() : "";
|
|
4093
4212
|
return BINARY_RESPONSE_TYPES.has(name);
|
|
4094
4213
|
}
|
|
4095
4214
|
function detectStreamElement(method) {
|
|
@@ -4104,9 +4223,9 @@ function detectStreamElement(method) {
|
|
|
4104
4223
|
return null;
|
|
4105
4224
|
}
|
|
4106
4225
|
function streamContainerElement(node) {
|
|
4107
|
-
if (!node || !
|
|
4226
|
+
if (!node || !import_ts_morph8.Node.isTypeReference(node)) return null;
|
|
4108
4227
|
const typeName = node.getTypeName();
|
|
4109
|
-
const name =
|
|
4228
|
+
const name = import_ts_morph8.Node.isIdentifier(typeName) ? typeName.getText() : "";
|
|
4110
4229
|
if (STREAM_CONTAINERS.has(name) || STREAM_CONTAINERS_GENERATOR.has(name)) {
|
|
4111
4230
|
return node.getTypeArguments()[0] ?? null;
|
|
4112
4231
|
}
|
|
@@ -4116,9 +4235,9 @@ function hasAsQueryDecorator(method) {
|
|
|
4116
4235
|
return method.getDecorators().some((d) => d.getName() === "AsQuery");
|
|
4117
4236
|
}
|
|
4118
4237
|
function unwrapNamedContainer(node, names) {
|
|
4119
|
-
if (!node || !
|
|
4238
|
+
if (!node || !import_ts_morph8.Node.isTypeReference(node)) return node;
|
|
4120
4239
|
const typeName = node.getTypeName();
|
|
4121
|
-
const name =
|
|
4240
|
+
const name = import_ts_morph8.Node.isIdentifier(typeName) ? typeName.getText() : "";
|
|
4122
4241
|
if (names.has(name)) {
|
|
4123
4242
|
return node.getTypeArguments()[0] ?? node;
|
|
4124
4243
|
}
|
|
@@ -4164,11 +4283,11 @@ function extractDtoContract(method, sourceFile, project, mixin) {
|
|
|
4164
4283
|
if (apiResp) {
|
|
4165
4284
|
const args = apiResp.getArguments();
|
|
4166
4285
|
const optsArg = args[0];
|
|
4167
|
-
if (optsArg &&
|
|
4286
|
+
if (optsArg && import_ts_morph8.Node.isObjectLiteralExpression(optsArg)) {
|
|
4168
4287
|
for (const prop of optsArg.getProperties()) {
|
|
4169
|
-
if (
|
|
4288
|
+
if (import_ts_morph8.Node.isPropertyAssignment(prop) && prop.getName() === "type") {
|
|
4170
4289
|
const val = prop.getInitializer();
|
|
4171
|
-
if (val &&
|
|
4290
|
+
if (val && import_ts_morph8.Node.isIdentifier(val)) {
|
|
4172
4291
|
const name = val.getText();
|
|
4173
4292
|
const localDecl = sourceFile.getInterface(name) || sourceFile.getClass(name) || sourceFile.getTypeAlias(name);
|
|
4174
4293
|
if (localDecl?.isExported()) {
|
|
@@ -4236,101 +4355,6 @@ function resolveParamClass(method, decoratorName, sourceFile, project) {
|
|
|
4236
4355
|
return null;
|
|
4237
4356
|
}
|
|
4238
4357
|
|
|
4239
|
-
// src/discovery/heritage.ts
|
|
4240
|
-
var import_ts_morph8 = require("ts-morph");
|
|
4241
|
-
function resolveHeritageCall(node) {
|
|
4242
|
-
if (!node) return void 0;
|
|
4243
|
-
const expr = unwrapExpression(node);
|
|
4244
|
-
if (import_ts_morph8.Node.isCallExpression(expr)) return expr;
|
|
4245
|
-
if (!import_ts_morph8.Node.isIdentifier(expr)) return void 0;
|
|
4246
|
-
const decl = expr.getDefinitions().map((d) => d.getDeclarationNode()).find(
|
|
4247
|
-
(n) => n !== void 0 && import_ts_morph8.Node.isVariableDeclaration(n)
|
|
4248
|
-
);
|
|
4249
|
-
const init = decl?.getInitializer();
|
|
4250
|
-
if (!init) return void 0;
|
|
4251
|
-
const unwrapped = unwrapExpression(init);
|
|
4252
|
-
return import_ts_morph8.Node.isCallExpression(unwrapped) ? unwrapped : void 0;
|
|
4253
|
-
}
|
|
4254
|
-
function unwrapExpression(node) {
|
|
4255
|
-
let current = node;
|
|
4256
|
-
while (import_ts_morph8.Node.isAsExpression(current) || import_ts_morph8.Node.isSatisfiesExpression(current) || import_ts_morph8.Node.isParenthesizedExpression(current) || import_ts_morph8.Node.isTypeAssertion(current)) {
|
|
4257
|
-
current = current.getExpression();
|
|
4258
|
-
}
|
|
4259
|
-
return current;
|
|
4260
|
-
}
|
|
4261
|
-
function resolveReturnedClass(factoryDecl) {
|
|
4262
|
-
const body = factoryDecl.getBody();
|
|
4263
|
-
if (!body) return void 0;
|
|
4264
|
-
const returns = body.getDescendants().filter((n) => import_ts_morph8.Node.isReturnStatement(n));
|
|
4265
|
-
for (const ret of returns) {
|
|
4266
|
-
const expr = ret.getExpression();
|
|
4267
|
-
if (!expr) continue;
|
|
4268
|
-
const inner = unwrapExpression(expr);
|
|
4269
|
-
if (import_ts_morph8.Node.isClassExpression(inner)) {
|
|
4270
|
-
return inner;
|
|
4271
|
-
}
|
|
4272
|
-
if (import_ts_morph8.Node.isIdentifier(inner)) {
|
|
4273
|
-
const name = inner.getText();
|
|
4274
|
-
const decl = body.getDescendants().find((n) => import_ts_morph8.Node.isClassDeclaration(n) && n.getName() === name);
|
|
4275
|
-
if (decl) return decl;
|
|
4276
|
-
}
|
|
4277
|
-
}
|
|
4278
|
-
return void 0;
|
|
4279
|
-
}
|
|
4280
|
-
function resolveInheritedMethods(cls) {
|
|
4281
|
-
const expr = resolveHeritageCall(cls.getExtends()?.getExpression());
|
|
4282
|
-
if (!expr) return void 0;
|
|
4283
|
-
const callee = expr.getExpression();
|
|
4284
|
-
if (!import_ts_morph8.Node.isIdentifier(callee)) return void 0;
|
|
4285
|
-
const factoryDecl = callee.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => import_ts_morph8.Node.isFunctionDeclaration(n));
|
|
4286
|
-
if (!factoryDecl) return void 0;
|
|
4287
|
-
const returnedClass = resolveReturnedClass(factoryDecl);
|
|
4288
|
-
if (!returnedClass) return void 0;
|
|
4289
|
-
const classArgs = [];
|
|
4290
|
-
for (const arg of expr.getArguments()) {
|
|
4291
|
-
if (!import_ts_morph8.Node.isIdentifier(arg)) continue;
|
|
4292
|
-
const decl = arg.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => import_ts_morph8.Node.isClassDeclaration(n));
|
|
4293
|
-
if (decl) {
|
|
4294
|
-
classArgs.push({
|
|
4295
|
-
name: decl.getName() ?? arg.getText(),
|
|
4296
|
-
filePath: decl.getSourceFile().getFilePath()
|
|
4297
|
-
});
|
|
4298
|
-
}
|
|
4299
|
-
}
|
|
4300
|
-
return {
|
|
4301
|
-
methods: returnedClass.getMethods(),
|
|
4302
|
-
factoryName: callee.getText(),
|
|
4303
|
-
factoryFilePath: factoryDecl.getSourceFile().getFilePath(),
|
|
4304
|
-
classArgs
|
|
4305
|
-
};
|
|
4306
|
-
}
|
|
4307
|
-
var mixinTypeProject;
|
|
4308
|
-
function getMixinTypeProject() {
|
|
4309
|
-
mixinTypeProject ??= new import_ts_morph8.Project({
|
|
4310
|
-
skipAddingFilesFromTsConfig: true,
|
|
4311
|
-
compilerOptions: { strict: true }
|
|
4312
|
-
});
|
|
4313
|
-
return mixinTypeProject;
|
|
4314
|
-
}
|
|
4315
|
-
function clearMixinTypeProject() {
|
|
4316
|
-
mixinTypeProject = void 0;
|
|
4317
|
-
}
|
|
4318
|
-
function resolveInstantiatedReturnType(cls, methodName) {
|
|
4319
|
-
const filePath = cls.getSourceFile().getFilePath();
|
|
4320
|
-
const className = cls.getName();
|
|
4321
|
-
if (!className) return void 0;
|
|
4322
|
-
const project = getMixinTypeProject();
|
|
4323
|
-
const sourceFile = project.getSourceFile(filePath) ?? project.addSourceFileAtPathIfExists(filePath);
|
|
4324
|
-
const typedCls = sourceFile?.getClass(className);
|
|
4325
|
-
if (!typedCls) return void 0;
|
|
4326
|
-
const prop = typedCls.getType().getProperty(methodName);
|
|
4327
|
-
if (!prop) return void 0;
|
|
4328
|
-
const returnType = prop.getTypeAtLocation(typedCls).getCallSignatures()[0]?.getReturnType();
|
|
4329
|
-
if (!returnType) return void 0;
|
|
4330
|
-
const unwrapped = returnType.getSymbol()?.getName() === "Promise" ? returnType.getTypeArguments()[0] ?? returnType : returnType;
|
|
4331
|
-
return unwrapped.getText(typedCls);
|
|
4332
|
-
}
|
|
4333
|
-
|
|
4334
4358
|
// src/discovery/zod-ast-to-ts.ts
|
|
4335
4359
|
var import_ts_morph9 = require("ts-morph");
|
|
4336
4360
|
function zodAstToTs(node) {
|
|
@@ -5147,7 +5171,7 @@ function createChainModuleRenderer(opts) {
|
|
|
5147
5171
|
}
|
|
5148
5172
|
|
|
5149
5173
|
// src/index.ts
|
|
5150
|
-
var VERSION = "0.17.
|
|
5174
|
+
var VERSION = "0.17.2";
|
|
5151
5175
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5152
5176
|
0 && (module.exports = {
|
|
5153
5177
|
CodegenError,
|