@dudousxd/nestjs-codegen 0.17.1 → 0.18.0
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 +48 -0
- package/dist/cli/main.cjs +228 -174
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +222 -168
- package/dist/cli/main.js.map +1 -1
- package/dist/extension/index.d.cts +1 -1
- package/dist/extension/index.d.ts +1 -1
- package/dist/{index-DCF9QSPY.d.cts → index-Dyf4ttwU.d.cts} +24 -1
- package/dist/{index-DCF9QSPY.d.ts → index-Dyf4ttwU.d.ts} +24 -1
- package/dist/index.cjs +228 -174
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +222 -168
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +228 -174
- package/dist/nest/index.cjs.map +1 -1
- package/dist/nest/index.d.cts +1 -1
- package/dist/nest/index.d.ts +1 -1
- package/dist/nest/index.js +222 -168
- package/dist/nest/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2453,7 +2453,7 @@ import {
|
|
|
2453
2453
|
|
|
2454
2454
|
// src/discovery/dto-type-resolver.ts
|
|
2455
2455
|
import {
|
|
2456
|
-
Node as
|
|
2456
|
+
Node as Node7,
|
|
2457
2457
|
SyntaxKind as SyntaxKind3
|
|
2458
2458
|
} from "ts-morph";
|
|
2459
2459
|
|
|
@@ -3216,7 +3216,7 @@ function inSchemaFromDecorator(decorator) {
|
|
|
3216
3216
|
|
|
3217
3217
|
// src/discovery/filter-for.ts
|
|
3218
3218
|
import {
|
|
3219
|
-
Node as
|
|
3219
|
+
Node as Node6
|
|
3220
3220
|
} from "ts-morph";
|
|
3221
3221
|
|
|
3222
3222
|
// src/discovery/filter-field-types.ts
|
|
@@ -3439,15 +3439,161 @@ function toFilterFieldType(name, r) {
|
|
|
3439
3439
|
return ft;
|
|
3440
3440
|
}
|
|
3441
3441
|
|
|
3442
|
+
// src/discovery/heritage.ts
|
|
3443
|
+
import { Node as Node5, Project as Project3 } from "ts-morph";
|
|
3444
|
+
function resolveHeritageCall(node) {
|
|
3445
|
+
if (!node) return void 0;
|
|
3446
|
+
const expr = unwrapExpression(node);
|
|
3447
|
+
if (Node5.isCallExpression(expr)) return expr;
|
|
3448
|
+
if (!Node5.isIdentifier(expr)) return void 0;
|
|
3449
|
+
const decl = expr.getDefinitions().map((d) => d.getDeclarationNode()).find(
|
|
3450
|
+
(n) => n !== void 0 && Node5.isVariableDeclaration(n)
|
|
3451
|
+
);
|
|
3452
|
+
const init = decl?.getInitializer();
|
|
3453
|
+
if (!init) return void 0;
|
|
3454
|
+
const unwrapped = unwrapExpression(init);
|
|
3455
|
+
return Node5.isCallExpression(unwrapped) ? unwrapped : void 0;
|
|
3456
|
+
}
|
|
3457
|
+
function unwrapExpression(node) {
|
|
3458
|
+
let current = node;
|
|
3459
|
+
while (Node5.isAsExpression(current) || Node5.isSatisfiesExpression(current) || Node5.isParenthesizedExpression(current) || Node5.isTypeAssertion(current)) {
|
|
3460
|
+
current = current.getExpression();
|
|
3461
|
+
}
|
|
3462
|
+
return current;
|
|
3463
|
+
}
|
|
3464
|
+
function resolveReturnedClass(factoryDecl) {
|
|
3465
|
+
const body = factoryDecl.getBody();
|
|
3466
|
+
if (!body) return void 0;
|
|
3467
|
+
const returns = body.getDescendants().filter((n) => Node5.isReturnStatement(n));
|
|
3468
|
+
for (const ret of returns) {
|
|
3469
|
+
const expr = ret.getExpression();
|
|
3470
|
+
if (!expr) continue;
|
|
3471
|
+
const inner = unwrapExpression(expr);
|
|
3472
|
+
if (Node5.isClassExpression(inner)) {
|
|
3473
|
+
return inner;
|
|
3474
|
+
}
|
|
3475
|
+
if (Node5.isIdentifier(inner)) {
|
|
3476
|
+
const name = inner.getText();
|
|
3477
|
+
const decl = body.getDescendants().find((n) => Node5.isClassDeclaration(n) && n.getName() === name);
|
|
3478
|
+
if (decl) return decl;
|
|
3479
|
+
}
|
|
3480
|
+
}
|
|
3481
|
+
return void 0;
|
|
3482
|
+
}
|
|
3483
|
+
function resolveFactoryDeclaration(call) {
|
|
3484
|
+
const callee = call.getExpression();
|
|
3485
|
+
if (!Node5.isIdentifier(callee)) return void 0;
|
|
3486
|
+
return callee.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => Node5.isFunctionDeclaration(n));
|
|
3487
|
+
}
|
|
3488
|
+
function resolveFactoryStaticClass(node) {
|
|
3489
|
+
if (!Node5.isPropertyAccessExpression(node)) return void 0;
|
|
3490
|
+
const call = resolveHeritageCall(node.getExpression());
|
|
3491
|
+
if (!call) return void 0;
|
|
3492
|
+
const factoryDecl = resolveFactoryDeclaration(call);
|
|
3493
|
+
if (!factoryDecl) return void 0;
|
|
3494
|
+
const returnedClass = resolveReturnedClass(factoryDecl);
|
|
3495
|
+
if (!returnedClass) return void 0;
|
|
3496
|
+
const staticProp = returnedClass.getStaticProperties().find((p) => p.getName() === node.getName());
|
|
3497
|
+
if (!staticProp || !Node5.isPropertyDeclaration(staticProp)) return void 0;
|
|
3498
|
+
const init = staticProp.getInitializer();
|
|
3499
|
+
if (!init) return void 0;
|
|
3500
|
+
const inner = unwrapExpression(init);
|
|
3501
|
+
if (Node5.isClassExpression(inner)) return inner;
|
|
3502
|
+
if (!Node5.isIdentifier(inner)) return void 0;
|
|
3503
|
+
return inner.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => n !== void 0 && Node5.isClassDeclaration(n));
|
|
3504
|
+
}
|
|
3505
|
+
function resolveInheritedMethods(cls) {
|
|
3506
|
+
const expr = resolveHeritageCall(cls.getExtends()?.getExpression());
|
|
3507
|
+
if (!expr) return void 0;
|
|
3508
|
+
const callee = expr.getExpression();
|
|
3509
|
+
if (!Node5.isIdentifier(callee)) return void 0;
|
|
3510
|
+
const factoryDecl = resolveFactoryDeclaration(expr);
|
|
3511
|
+
if (!factoryDecl) return void 0;
|
|
3512
|
+
const returnedClass = resolveReturnedClass(factoryDecl);
|
|
3513
|
+
if (!returnedClass) return void 0;
|
|
3514
|
+
const classArgs = [];
|
|
3515
|
+
const namedClassArgs = {};
|
|
3516
|
+
for (const arg of expr.getArguments()) {
|
|
3517
|
+
const positional = resolveClassReference(arg);
|
|
3518
|
+
if (positional) {
|
|
3519
|
+
classArgs.push(positional);
|
|
3520
|
+
continue;
|
|
3521
|
+
}
|
|
3522
|
+
if (!Node5.isObjectLiteralExpression(arg)) continue;
|
|
3523
|
+
for (const prop of arg.getProperties()) {
|
|
3524
|
+
const named = resolvePropertyClassReference(prop);
|
|
3525
|
+
if (!named) continue;
|
|
3526
|
+
namedClassArgs[named.key] ??= named.ref;
|
|
3527
|
+
}
|
|
3528
|
+
}
|
|
3529
|
+
return {
|
|
3530
|
+
methods: returnedClass.getMethods(),
|
|
3531
|
+
factoryName: callee.getText(),
|
|
3532
|
+
factoryFilePath: factoryDecl.getSourceFile().getFilePath(),
|
|
3533
|
+
classArgs,
|
|
3534
|
+
namedClassArgs
|
|
3535
|
+
};
|
|
3536
|
+
}
|
|
3537
|
+
function resolveClassReference(node) {
|
|
3538
|
+
const expr = unwrapExpression(node);
|
|
3539
|
+
if (!Node5.isIdentifier(expr)) return void 0;
|
|
3540
|
+
const decl = expr.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => n !== void 0 && Node5.isClassDeclaration(n));
|
|
3541
|
+
if (!decl) return void 0;
|
|
3542
|
+
return {
|
|
3543
|
+
name: decl.getName() ?? expr.getText(),
|
|
3544
|
+
filePath: decl.getSourceFile().getFilePath()
|
|
3545
|
+
};
|
|
3546
|
+
}
|
|
3547
|
+
function resolvePropertyClassReference(prop) {
|
|
3548
|
+
if (Node5.isShorthandPropertyAssignment(prop)) {
|
|
3549
|
+
const ref2 = resolveClassReference(prop.getNameNode());
|
|
3550
|
+
return ref2 ? { key: prop.getName(), ref: ref2 } : void 0;
|
|
3551
|
+
}
|
|
3552
|
+
if (!Node5.isPropertyAssignment(prop)) return void 0;
|
|
3553
|
+
const init = prop.getInitializer();
|
|
3554
|
+
if (!init) return void 0;
|
|
3555
|
+
const ref = resolveClassReference(init);
|
|
3556
|
+
if (!ref) return void 0;
|
|
3557
|
+
const nameNode = prop.getNameNode();
|
|
3558
|
+
const key = Node5.isStringLiteral(nameNode) ? nameNode.getLiteralValue() : prop.getName();
|
|
3559
|
+
return { key, ref };
|
|
3560
|
+
}
|
|
3561
|
+
var mixinTypeProject;
|
|
3562
|
+
function getMixinTypeProject() {
|
|
3563
|
+
mixinTypeProject ??= new Project3({
|
|
3564
|
+
skipAddingFilesFromTsConfig: true,
|
|
3565
|
+
compilerOptions: { strict: true }
|
|
3566
|
+
});
|
|
3567
|
+
return mixinTypeProject;
|
|
3568
|
+
}
|
|
3569
|
+
function clearMixinTypeProject() {
|
|
3570
|
+
mixinTypeProject = void 0;
|
|
3571
|
+
}
|
|
3572
|
+
function resolveInstantiatedReturnType(cls, methodName) {
|
|
3573
|
+
const filePath = cls.getSourceFile().getFilePath();
|
|
3574
|
+
const className = cls.getName();
|
|
3575
|
+
if (!className) return void 0;
|
|
3576
|
+
const project = getMixinTypeProject();
|
|
3577
|
+
const sourceFile = project.getSourceFile(filePath) ?? project.addSourceFileAtPathIfExists(filePath);
|
|
3578
|
+
const typedCls = sourceFile?.getClass(className);
|
|
3579
|
+
if (!typedCls) return void 0;
|
|
3580
|
+
const prop = typedCls.getType().getProperty(methodName);
|
|
3581
|
+
if (!prop) return void 0;
|
|
3582
|
+
const returnType = prop.getTypeAtLocation(typedCls).getCallSignatures()[0]?.getReturnType();
|
|
3583
|
+
if (!returnType) return void 0;
|
|
3584
|
+
const unwrapped = returnType.getSymbol()?.getName() === "Promise" ? returnType.getTypeArguments()[0] ?? returnType : returnType;
|
|
3585
|
+
return unwrapped.getText(typedCls);
|
|
3586
|
+
}
|
|
3587
|
+
|
|
3442
3588
|
// src/discovery/filter-for.ts
|
|
3443
3589
|
function resolveMixinEntityClass(mixin, project) {
|
|
3444
|
-
const entityArg = mixin?.classArgs[0];
|
|
3590
|
+
const entityArg = mixin?.namedClassArgs?.entity ?? mixin?.classArgs[0];
|
|
3445
3591
|
if (!entityArg) return void 0;
|
|
3446
3592
|
const file = project.getSourceFile(entityArg.filePath) ?? project.addSourceFileAtPathIfExists(entityArg.filePath);
|
|
3447
3593
|
return file?.getClass(entityArg.name);
|
|
3448
3594
|
}
|
|
3449
3595
|
function classifyFilterForHint(typeInit) {
|
|
3450
|
-
if (
|
|
3596
|
+
if (Node6.isStringLiteral(typeInit)) {
|
|
3451
3597
|
switch (typeInit.getLiteralValue()) {
|
|
3452
3598
|
case "string":
|
|
3453
3599
|
return { kind: "string" };
|
|
@@ -3461,10 +3607,10 @@ function classifyFilterForHint(typeInit) {
|
|
|
3461
3607
|
return null;
|
|
3462
3608
|
}
|
|
3463
3609
|
}
|
|
3464
|
-
if (
|
|
3610
|
+
if (Node6.isArrayLiteralExpression(typeInit)) {
|
|
3465
3611
|
const values = [];
|
|
3466
3612
|
for (const el of typeInit.getElements()) {
|
|
3467
|
-
if (!
|
|
3613
|
+
if (!Node6.isStringLiteral(el)) return null;
|
|
3468
3614
|
values.push(el.getLiteralValue());
|
|
3469
3615
|
}
|
|
3470
3616
|
if (values.length === 0) return null;
|
|
@@ -3499,11 +3645,11 @@ function extractFilterForHints(classDecl, project) {
|
|
|
3499
3645
|
if (!filterForDec) continue;
|
|
3500
3646
|
const args = filterForDec.getArguments();
|
|
3501
3647
|
const keyArg = args[0];
|
|
3502
|
-
const inputKey = keyArg &&
|
|
3648
|
+
const inputKey = keyArg && Node6.isStringLiteral(keyArg) ? keyArg.getLiteralValue() : method.getName();
|
|
3503
3649
|
const optsArg = args[1];
|
|
3504
|
-
if (optsArg &&
|
|
3650
|
+
if (optsArg && Node6.isObjectLiteralExpression(optsArg)) {
|
|
3505
3651
|
const typeProp = optsArg.getProperty("type");
|
|
3506
|
-
if (typeProp &&
|
|
3652
|
+
if (typeProp && Node6.isPropertyAssignment(typeProp)) {
|
|
3507
3653
|
const typeInit = typeProp.getInitializer();
|
|
3508
3654
|
if (typeInit) {
|
|
3509
3655
|
const classified = classifyFilterForHint(typeInit);
|
|
@@ -3528,21 +3674,23 @@ function extractApplyFilterInfo(method, sourceFile, project, mixin) {
|
|
|
3528
3674
|
const args = filterDecorator.getArguments();
|
|
3529
3675
|
if (args.length === 0) continue;
|
|
3530
3676
|
const filterClassArg = args[0];
|
|
3531
|
-
if (!filterClassArg
|
|
3677
|
+
if (!filterClassArg) continue;
|
|
3678
|
+
const factoryStaticClass = resolveFactoryStaticClass(filterClassArg);
|
|
3679
|
+
if (!factoryStaticClass && !Node6.isIdentifier(filterClassArg)) continue;
|
|
3532
3680
|
let source = "query";
|
|
3533
3681
|
const optionsArg = args[1];
|
|
3534
|
-
if (optionsArg &&
|
|
3682
|
+
if (optionsArg && Node6.isObjectLiteralExpression(optionsArg)) {
|
|
3535
3683
|
const sourceProp = optionsArg.getProperty("source");
|
|
3536
|
-
if (sourceProp &&
|
|
3684
|
+
if (sourceProp && Node6.isPropertyAssignment(sourceProp)) {
|
|
3537
3685
|
const init = sourceProp.getInitializer();
|
|
3538
|
-
if (init &&
|
|
3686
|
+
if (init && Node6.isStringLiteral(init) && init.getLiteralValue() === "body") {
|
|
3539
3687
|
source = "body";
|
|
3540
3688
|
}
|
|
3541
3689
|
}
|
|
3542
3690
|
}
|
|
3543
3691
|
const filterClassName = filterClassArg.getText();
|
|
3544
|
-
const resolved = findType(filterClassName, declFile, project);
|
|
3545
|
-
const classDecl = resolved?.kind === "class" ? resolved.decl : resolveLocalClassDeclaration(filterClassArg);
|
|
3692
|
+
const resolved = factoryStaticClass ? void 0 : findType(filterClassName, declFile, project);
|
|
3693
|
+
const classDecl = factoryStaticClass ?? (resolved?.kind === "class" ? resolved.decl : resolveLocalClassDeclaration(filterClassArg));
|
|
3546
3694
|
if (classDecl) {
|
|
3547
3695
|
let fieldTypes = extractClassPropertyTypes(classDecl, project);
|
|
3548
3696
|
if (fieldTypes.length === 0) {
|
|
@@ -3598,22 +3746,22 @@ function resolveRelationEntity(prop, sourceFile, project) {
|
|
|
3598
3746
|
const args = dec.getArguments();
|
|
3599
3747
|
if (args.length === 0) continue;
|
|
3600
3748
|
const arg = args[0];
|
|
3601
|
-
if (
|
|
3749
|
+
if (Node6.isObjectLiteralExpression(arg)) {
|
|
3602
3750
|
const entityProp = arg.getProperty("entity");
|
|
3603
|
-
if (entityProp &&
|
|
3751
|
+
if (entityProp && Node6.isPropertyAssignment(entityProp)) {
|
|
3604
3752
|
const init = entityProp.getInitializer();
|
|
3605
|
-
if (init &&
|
|
3753
|
+
if (init && Node6.isArrowFunction(init)) {
|
|
3606
3754
|
const body = init.getBody();
|
|
3607
|
-
if (
|
|
3755
|
+
if (Node6.isIdentifier(body)) {
|
|
3608
3756
|
const resolved = findType(body.getText(), prop.getSourceFile(), project);
|
|
3609
3757
|
if (resolved?.kind === "class") return resolved.decl;
|
|
3610
3758
|
}
|
|
3611
3759
|
}
|
|
3612
3760
|
}
|
|
3613
3761
|
}
|
|
3614
|
-
if (
|
|
3762
|
+
if (Node6.isArrowFunction(arg)) {
|
|
3615
3763
|
const body = arg.getBody();
|
|
3616
|
-
if (
|
|
3764
|
+
if (Node6.isIdentifier(body)) {
|
|
3617
3765
|
const resolved = findType(body.getText(), prop.getSourceFile(), project);
|
|
3618
3766
|
if (resolved?.kind === "class") return resolved.decl;
|
|
3619
3767
|
}
|
|
@@ -3632,15 +3780,15 @@ function extractClassPropertyTypes(classDecl, project) {
|
|
|
3632
3780
|
return fields;
|
|
3633
3781
|
}
|
|
3634
3782
|
function resolveLocalClassDeclaration(identifier) {
|
|
3635
|
-
if (!
|
|
3636
|
-
return identifier.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => n !== void 0 &&
|
|
3783
|
+
if (!Node6.isIdentifier(identifier)) return void 0;
|
|
3784
|
+
return identifier.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => n !== void 0 && Node6.isClassDeclaration(n));
|
|
3637
3785
|
}
|
|
3638
3786
|
function resolveDeclaredEntity(optionsArg, filterClass, project) {
|
|
3639
|
-
if (!
|
|
3787
|
+
if (!Node6.isObjectLiteralExpression(optionsArg)) return void 0;
|
|
3640
3788
|
const entityProp = optionsArg.getProperty("entity");
|
|
3641
|
-
if (!entityProp || !
|
|
3789
|
+
if (!entityProp || !Node6.isPropertyAssignment(entityProp)) return void 0;
|
|
3642
3790
|
const entityInit = entityProp.getInitializer();
|
|
3643
|
-
if (!entityInit || !
|
|
3791
|
+
if (!entityInit || !Node6.isIdentifier(entityInit)) return void 0;
|
|
3644
3792
|
const resolved = findType(entityInit.getText(), filterClass.getSourceFile(), project);
|
|
3645
3793
|
if (!resolved || resolved.kind !== "class") return void 0;
|
|
3646
3794
|
return resolved.decl;
|
|
@@ -3651,7 +3799,7 @@ function extractFilterableEntityFields(filterClass, project, entityOverride) {
|
|
|
3651
3799
|
const args = filterableDecorator.getArguments();
|
|
3652
3800
|
if (args.length === 0) return [];
|
|
3653
3801
|
const optionsArg = args[0];
|
|
3654
|
-
if (!
|
|
3802
|
+
if (!Node6.isObjectLiteralExpression(optionsArg)) return [];
|
|
3655
3803
|
const entityDecl = entityOverride ?? resolveDeclaredEntity(optionsArg, filterClass, project);
|
|
3656
3804
|
if (!entityDecl) return [];
|
|
3657
3805
|
const fields = collectEntityFields(
|
|
@@ -3664,17 +3812,17 @@ function extractFilterableEntityFields(filterClass, project, entityOverride) {
|
|
|
3664
3812
|
const relationsDecorator = filterClass.getDecorators().find((d) => d.getName() === "Relations");
|
|
3665
3813
|
if (relationsDecorator) {
|
|
3666
3814
|
const relArgs = relationsDecorator.getArguments();
|
|
3667
|
-
if (relArgs.length > 0 &&
|
|
3815
|
+
if (relArgs.length > 0 && Node6.isObjectLiteralExpression(relArgs[0])) {
|
|
3668
3816
|
for (const relProp of relArgs[0].getProperties()) {
|
|
3669
|
-
if (!
|
|
3817
|
+
if (!Node6.isPropertyAssignment(relProp)) continue;
|
|
3670
3818
|
const relInit = relProp.getInitializer();
|
|
3671
|
-
if (!relInit || !
|
|
3819
|
+
if (!relInit || !Node6.isObjectLiteralExpression(relInit)) continue;
|
|
3672
3820
|
const keysProp = relInit.getProperty("keys");
|
|
3673
|
-
if (!keysProp || !
|
|
3821
|
+
if (!keysProp || !Node6.isPropertyAssignment(keysProp)) continue;
|
|
3674
3822
|
const keysInit = keysProp.getInitializer();
|
|
3675
|
-
if (!keysInit || !
|
|
3823
|
+
if (!keysInit || !Node6.isArrayLiteralExpression(keysInit)) continue;
|
|
3676
3824
|
for (const el of keysInit.getElements()) {
|
|
3677
|
-
if (
|
|
3825
|
+
if (Node6.isStringLiteral(el)) {
|
|
3678
3826
|
fields.push(toFilterFieldType(el.getLiteralValue(), { kind: "unknown" }));
|
|
3679
3827
|
}
|
|
3680
3828
|
}
|
|
@@ -3715,22 +3863,22 @@ var PASSTHROUGH_UTILITY = /* @__PURE__ */ new Set([
|
|
|
3715
3863
|
]);
|
|
3716
3864
|
function resolveTypeNodeToString(typeNode, sourceFile, project, depth, subst = /* @__PURE__ */ new Map()) {
|
|
3717
3865
|
if (depth <= 0) return "unknown";
|
|
3718
|
-
if (
|
|
3866
|
+
if (Node7.isArrayTypeNode(typeNode)) {
|
|
3719
3867
|
const elementType = typeNode.getElementTypeNode();
|
|
3720
3868
|
return `Array<${resolveTypeNodeToString(elementType, sourceFile, project, depth, subst)}>`;
|
|
3721
3869
|
}
|
|
3722
|
-
if (
|
|
3870
|
+
if (Node7.isUnionTypeNode(typeNode)) {
|
|
3723
3871
|
return typeNode.getTypeNodes().map((t) => resolveTypeNodeToString(t, sourceFile, project, depth, subst)).join(" | ");
|
|
3724
3872
|
}
|
|
3725
|
-
if (
|
|
3873
|
+
if (Node7.isIntersectionTypeNode(typeNode)) {
|
|
3726
3874
|
return typeNode.getTypeNodes().map((t) => resolveTypeNodeToString(t, sourceFile, project, depth, subst)).join(" & ");
|
|
3727
3875
|
}
|
|
3728
|
-
if (
|
|
3876
|
+
if (Node7.isParenthesizedTypeNode(typeNode)) {
|
|
3729
3877
|
return `(${resolveTypeNodeToString(typeNode.getTypeNode(), sourceFile, project, depth, subst)})`;
|
|
3730
3878
|
}
|
|
3731
|
-
if (
|
|
3879
|
+
if (Node7.isTypeReference(typeNode)) {
|
|
3732
3880
|
const typeName = typeNode.getTypeName();
|
|
3733
|
-
const name =
|
|
3881
|
+
const name = Node7.isIdentifier(typeName) ? typeName.getText() : typeNode.getText();
|
|
3734
3882
|
const bound = subst.get(name);
|
|
3735
3883
|
if (bound !== void 0) return bound;
|
|
3736
3884
|
if (name === "string" || name === "number" || name === "boolean") return name;
|
|
@@ -3753,10 +3901,10 @@ function resolveTypeNodeToString(typeNode, sourceFile, project, depth, subst = /
|
|
|
3753
3901
|
dbg("unresolvable type:", name, "in", sourceFile.getFilePath());
|
|
3754
3902
|
return "unknown";
|
|
3755
3903
|
}
|
|
3756
|
-
if (
|
|
3904
|
+
if (Node7.isTypeLiteral(typeNode)) {
|
|
3757
3905
|
const members = [];
|
|
3758
3906
|
for (const member of typeNode.getMembers()) {
|
|
3759
|
-
if (
|
|
3907
|
+
if (Node7.isPropertySignature(member)) {
|
|
3760
3908
|
const memberTypeNode = member.getTypeNode();
|
|
3761
3909
|
const memberType = memberTypeNode ? resolveTypeNodeToString(memberTypeNode, sourceFile, project, depth, subst) : "unknown";
|
|
3762
3910
|
members.push(`${member.getName()}${member.hasQuestionToken() ? "?" : ""}: ${memberType}`);
|
|
@@ -3856,7 +4004,7 @@ function extractQueryType(method, sourceFile, project) {
|
|
|
3856
4004
|
if (!queryDecorator) continue;
|
|
3857
4005
|
const queryArgs = queryDecorator.getArguments();
|
|
3858
4006
|
const nameArg = queryArgs[0];
|
|
3859
|
-
if (!nameArg || !
|
|
4007
|
+
if (!nameArg || !Node7.isStringLiteral(nameArg)) continue;
|
|
3860
4008
|
const queryName = nameArg.getLiteralValue();
|
|
3861
4009
|
const typeNode = param.getTypeNode();
|
|
3862
4010
|
const queryType = typeNode ? resolveTypeNodeToString(typeNode, sourceFile, project, 3) : "string";
|
|
@@ -3867,7 +4015,7 @@ function extractQueryType(method, sourceFile, project) {
|
|
|
3867
4015
|
function isParamOptional(param) {
|
|
3868
4016
|
if (param.hasQuestionToken() || param.hasInitializer()) return true;
|
|
3869
4017
|
const typeNode = param.getTypeNode();
|
|
3870
|
-
if (typeNode &&
|
|
4018
|
+
if (typeNode && Node7.isUnionTypeNode(typeNode)) {
|
|
3871
4019
|
return typeNode.getTypeNodes().some((t) => t.getKind() === SyntaxKind3.UndefinedKeyword);
|
|
3872
4020
|
}
|
|
3873
4021
|
return false;
|
|
@@ -3880,7 +4028,7 @@ function extractParamsType(method, sourceFile, project) {
|
|
|
3880
4028
|
const paramArgs = paramDecorator.getArguments();
|
|
3881
4029
|
if (paramArgs.length === 0) continue;
|
|
3882
4030
|
const nameArg = paramArgs[0];
|
|
3883
|
-
if (!
|
|
4031
|
+
if (!Node7.isStringLiteral(nameArg)) continue;
|
|
3884
4032
|
const paramName = nameArg.getLiteralValue();
|
|
3885
4033
|
const typeNode = param.getTypeNode();
|
|
3886
4034
|
const paramType = typeNode ? resolveTypeNodeToString(typeNode, sourceFile, project, 3) : "string";
|
|
@@ -3901,28 +4049,28 @@ function extractUploadedFiles(method) {
|
|
|
3901
4049
|
for (const decorator of method.getDecorators()) {
|
|
3902
4050
|
if (decorator.getName() !== "UseInterceptors") continue;
|
|
3903
4051
|
for (const arg of decorator.getArguments()) {
|
|
3904
|
-
if (!
|
|
4052
|
+
if (!Node7.isCallExpression(arg)) continue;
|
|
3905
4053
|
const interceptor = arg.getExpression().getText();
|
|
3906
4054
|
const callArgs = arg.getArguments();
|
|
3907
4055
|
const firstArg2 = callArgs[0];
|
|
3908
4056
|
if (interceptor === "FileInterceptor") {
|
|
3909
|
-
if (firstArg2 &&
|
|
4057
|
+
if (firstArg2 && Node7.isStringLiteral(firstArg2)) {
|
|
3910
4058
|
entries.push(`${firstArg2.getLiteralValue()}: ${FILE}`);
|
|
3911
4059
|
multipart = true;
|
|
3912
4060
|
}
|
|
3913
4061
|
} else if (interceptor === "FilesInterceptor") {
|
|
3914
|
-
if (firstArg2 &&
|
|
4062
|
+
if (firstArg2 && Node7.isStringLiteral(firstArg2)) {
|
|
3915
4063
|
entries.push(`${firstArg2.getLiteralValue()}: Array<${FILE}>`);
|
|
3916
4064
|
multipart = true;
|
|
3917
4065
|
}
|
|
3918
4066
|
} else if (interceptor === "FileFieldsInterceptor") {
|
|
3919
|
-
if (firstArg2 &&
|
|
4067
|
+
if (firstArg2 && Node7.isArrayLiteralExpression(firstArg2)) {
|
|
3920
4068
|
for (const el of firstArg2.getElements()) {
|
|
3921
|
-
if (!
|
|
4069
|
+
if (!Node7.isObjectLiteralExpression(el)) continue;
|
|
3922
4070
|
const nameProp = el.getProperty("name");
|
|
3923
|
-
if (nameProp &&
|
|
4071
|
+
if (nameProp && Node7.isPropertyAssignment(nameProp)) {
|
|
3924
4072
|
const init = nameProp.getInitializer();
|
|
3925
|
-
if (init &&
|
|
4073
|
+
if (init && Node7.isStringLiteral(init)) {
|
|
3926
4074
|
entries.push(`${init.getLiteralValue()}: Array<${FILE}>`);
|
|
3927
4075
|
}
|
|
3928
4076
|
}
|
|
@@ -3942,13 +4090,13 @@ function extractResponseType(method, sourceFile, project) {
|
|
|
3942
4090
|
if (apiResponseDecorator) {
|
|
3943
4091
|
const args = apiResponseDecorator.getArguments();
|
|
3944
4092
|
const optsArg = args[0];
|
|
3945
|
-
if (optsArg &&
|
|
4093
|
+
if (optsArg && Node7.isObjectLiteralExpression(optsArg)) {
|
|
3946
4094
|
for (const prop of optsArg.getProperties()) {
|
|
3947
|
-
if (!
|
|
4095
|
+
if (!Node7.isPropertyAssignment(prop)) continue;
|
|
3948
4096
|
if (prop.getName() !== "type") continue;
|
|
3949
4097
|
const val = prop.getInitializer();
|
|
3950
4098
|
if (!val) continue;
|
|
3951
|
-
if (
|
|
4099
|
+
if (Node7.isArrayLiteralExpression(val)) {
|
|
3952
4100
|
const elements = val.getElements();
|
|
3953
4101
|
const firstEl = elements[0];
|
|
3954
4102
|
if (elements.length > 0 && firstEl !== void 0) {
|
|
@@ -3969,24 +4117,24 @@ function extractResponseType(method, sourceFile, project) {
|
|
|
3969
4117
|
}
|
|
3970
4118
|
function apiResponseStatus(decorator) {
|
|
3971
4119
|
const optsArg = decorator.getArguments()[0];
|
|
3972
|
-
if (!optsArg || !
|
|
4120
|
+
if (!optsArg || !Node7.isObjectLiteralExpression(optsArg)) return null;
|
|
3973
4121
|
for (const prop of optsArg.getProperties()) {
|
|
3974
|
-
if (!
|
|
4122
|
+
if (!Node7.isPropertyAssignment(prop)) continue;
|
|
3975
4123
|
if (prop.getName() !== "status") continue;
|
|
3976
4124
|
const val = prop.getInitializer();
|
|
3977
|
-
if (val &&
|
|
4125
|
+
if (val && Node7.isNumericLiteral(val)) return Number(val.getLiteralValue());
|
|
3978
4126
|
}
|
|
3979
4127
|
return null;
|
|
3980
4128
|
}
|
|
3981
4129
|
function apiResponseTypeNode(decorator) {
|
|
3982
4130
|
const optsArg = decorator.getArguments()[0];
|
|
3983
|
-
if (!optsArg || !
|
|
4131
|
+
if (!optsArg || !Node7.isObjectLiteralExpression(optsArg)) return null;
|
|
3984
4132
|
for (const prop of optsArg.getProperties()) {
|
|
3985
|
-
if (!
|
|
4133
|
+
if (!Node7.isPropertyAssignment(prop)) continue;
|
|
3986
4134
|
if (prop.getName() !== "type") continue;
|
|
3987
4135
|
const val = prop.getInitializer();
|
|
3988
4136
|
if (!val) return null;
|
|
3989
|
-
if (
|
|
4137
|
+
if (Node7.isArrayLiteralExpression(val)) {
|
|
3990
4138
|
const first = val.getElements()[0];
|
|
3991
4139
|
return first ? { node: first, isArray: true } : null;
|
|
3992
4140
|
}
|
|
@@ -4004,7 +4152,7 @@ function extractErrorType(method, sourceFile, project) {
|
|
|
4004
4152
|
const inner = resolveIdentifierToClassType(typeInfo.node, sourceFile, project, 3);
|
|
4005
4153
|
const type = typeInfo.isArray ? `Array<${inner}>` : inner;
|
|
4006
4154
|
let ref = null;
|
|
4007
|
-
if (
|
|
4155
|
+
if (Node7.isIdentifier(typeInfo.node)) {
|
|
4008
4156
|
const name = typeInfo.node.getText();
|
|
4009
4157
|
const localDecl = sourceFile.getInterface(name) || sourceFile.getClass(name) || sourceFile.getTypeAlias(name);
|
|
4010
4158
|
if (localDecl?.isExported()) {
|
|
@@ -4021,7 +4169,7 @@ function extractErrorType(method, sourceFile, project) {
|
|
|
4021
4169
|
return null;
|
|
4022
4170
|
}
|
|
4023
4171
|
function resolveIdentifierToClassType(node, sourceFile, project, depth) {
|
|
4024
|
-
if (!
|
|
4172
|
+
if (!Node7.isIdentifier(node)) return "unknown";
|
|
4025
4173
|
const name = node.getText();
|
|
4026
4174
|
const resolved = findType(name, sourceFile, project);
|
|
4027
4175
|
if (resolved) {
|
|
@@ -4041,9 +4189,9 @@ var STREAM_ENVELOPES = /* @__PURE__ */ new Set(["MessageEvent", "MessageEventLik
|
|
|
4041
4189
|
var BINARY_RESPONSE_TYPES = /* @__PURE__ */ new Set(["StreamableFile", "Buffer"]);
|
|
4042
4190
|
function detectBinaryResponse(method) {
|
|
4043
4191
|
const node = unwrapNamedContainer(method.getReturnTypeNode(), /* @__PURE__ */ new Set(["Promise"]));
|
|
4044
|
-
if (!node || !
|
|
4192
|
+
if (!node || !Node7.isTypeReference(node)) return false;
|
|
4045
4193
|
const typeName = node.getTypeName();
|
|
4046
|
-
const name =
|
|
4194
|
+
const name = Node7.isIdentifier(typeName) ? typeName.getText() : "";
|
|
4047
4195
|
return BINARY_RESPONSE_TYPES.has(name);
|
|
4048
4196
|
}
|
|
4049
4197
|
function detectStreamElement(method) {
|
|
@@ -4058,9 +4206,9 @@ function detectStreamElement(method) {
|
|
|
4058
4206
|
return null;
|
|
4059
4207
|
}
|
|
4060
4208
|
function streamContainerElement(node) {
|
|
4061
|
-
if (!node || !
|
|
4209
|
+
if (!node || !Node7.isTypeReference(node)) return null;
|
|
4062
4210
|
const typeName = node.getTypeName();
|
|
4063
|
-
const name =
|
|
4211
|
+
const name = Node7.isIdentifier(typeName) ? typeName.getText() : "";
|
|
4064
4212
|
if (STREAM_CONTAINERS.has(name) || STREAM_CONTAINERS_GENERATOR.has(name)) {
|
|
4065
4213
|
return node.getTypeArguments()[0] ?? null;
|
|
4066
4214
|
}
|
|
@@ -4070,9 +4218,9 @@ function hasAsQueryDecorator(method) {
|
|
|
4070
4218
|
return method.getDecorators().some((d) => d.getName() === "AsQuery");
|
|
4071
4219
|
}
|
|
4072
4220
|
function unwrapNamedContainer(node, names) {
|
|
4073
|
-
if (!node || !
|
|
4221
|
+
if (!node || !Node7.isTypeReference(node)) return node;
|
|
4074
4222
|
const typeName = node.getTypeName();
|
|
4075
|
-
const name =
|
|
4223
|
+
const name = Node7.isIdentifier(typeName) ? typeName.getText() : "";
|
|
4076
4224
|
if (names.has(name)) {
|
|
4077
4225
|
return node.getTypeArguments()[0] ?? node;
|
|
4078
4226
|
}
|
|
@@ -4118,11 +4266,11 @@ function extractDtoContract(method, sourceFile, project, mixin) {
|
|
|
4118
4266
|
if (apiResp) {
|
|
4119
4267
|
const args = apiResp.getArguments();
|
|
4120
4268
|
const optsArg = args[0];
|
|
4121
|
-
if (optsArg &&
|
|
4269
|
+
if (optsArg && Node7.isObjectLiteralExpression(optsArg)) {
|
|
4122
4270
|
for (const prop of optsArg.getProperties()) {
|
|
4123
|
-
if (
|
|
4271
|
+
if (Node7.isPropertyAssignment(prop) && prop.getName() === "type") {
|
|
4124
4272
|
const val = prop.getInitializer();
|
|
4125
|
-
if (val &&
|
|
4273
|
+
if (val && Node7.isIdentifier(val)) {
|
|
4126
4274
|
const name = val.getText();
|
|
4127
4275
|
const localDecl = sourceFile.getInterface(name) || sourceFile.getClass(name) || sourceFile.getTypeAlias(name);
|
|
4128
4276
|
if (localDecl?.isExported()) {
|
|
@@ -4190,101 +4338,6 @@ function resolveParamClass(method, decoratorName, sourceFile, project) {
|
|
|
4190
4338
|
return null;
|
|
4191
4339
|
}
|
|
4192
4340
|
|
|
4193
|
-
// src/discovery/heritage.ts
|
|
4194
|
-
import { Node as Node7, Project as Project3 } from "ts-morph";
|
|
4195
|
-
function resolveHeritageCall(node) {
|
|
4196
|
-
if (!node) return void 0;
|
|
4197
|
-
const expr = unwrapExpression(node);
|
|
4198
|
-
if (Node7.isCallExpression(expr)) return expr;
|
|
4199
|
-
if (!Node7.isIdentifier(expr)) return void 0;
|
|
4200
|
-
const decl = expr.getDefinitions().map((d) => d.getDeclarationNode()).find(
|
|
4201
|
-
(n) => n !== void 0 && Node7.isVariableDeclaration(n)
|
|
4202
|
-
);
|
|
4203
|
-
const init = decl?.getInitializer();
|
|
4204
|
-
if (!init) return void 0;
|
|
4205
|
-
const unwrapped = unwrapExpression(init);
|
|
4206
|
-
return Node7.isCallExpression(unwrapped) ? unwrapped : void 0;
|
|
4207
|
-
}
|
|
4208
|
-
function unwrapExpression(node) {
|
|
4209
|
-
let current = node;
|
|
4210
|
-
while (Node7.isAsExpression(current) || Node7.isSatisfiesExpression(current) || Node7.isParenthesizedExpression(current) || Node7.isTypeAssertion(current)) {
|
|
4211
|
-
current = current.getExpression();
|
|
4212
|
-
}
|
|
4213
|
-
return current;
|
|
4214
|
-
}
|
|
4215
|
-
function resolveReturnedClass(factoryDecl) {
|
|
4216
|
-
const body = factoryDecl.getBody();
|
|
4217
|
-
if (!body) return void 0;
|
|
4218
|
-
const returns = body.getDescendants().filter((n) => Node7.isReturnStatement(n));
|
|
4219
|
-
for (const ret of returns) {
|
|
4220
|
-
const expr = ret.getExpression();
|
|
4221
|
-
if (!expr) continue;
|
|
4222
|
-
const inner = unwrapExpression(expr);
|
|
4223
|
-
if (Node7.isClassExpression(inner)) {
|
|
4224
|
-
return inner;
|
|
4225
|
-
}
|
|
4226
|
-
if (Node7.isIdentifier(inner)) {
|
|
4227
|
-
const name = inner.getText();
|
|
4228
|
-
const decl = body.getDescendants().find((n) => Node7.isClassDeclaration(n) && n.getName() === name);
|
|
4229
|
-
if (decl) return decl;
|
|
4230
|
-
}
|
|
4231
|
-
}
|
|
4232
|
-
return void 0;
|
|
4233
|
-
}
|
|
4234
|
-
function resolveInheritedMethods(cls) {
|
|
4235
|
-
const expr = resolveHeritageCall(cls.getExtends()?.getExpression());
|
|
4236
|
-
if (!expr) return void 0;
|
|
4237
|
-
const callee = expr.getExpression();
|
|
4238
|
-
if (!Node7.isIdentifier(callee)) return void 0;
|
|
4239
|
-
const factoryDecl = callee.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => Node7.isFunctionDeclaration(n));
|
|
4240
|
-
if (!factoryDecl) return void 0;
|
|
4241
|
-
const returnedClass = resolveReturnedClass(factoryDecl);
|
|
4242
|
-
if (!returnedClass) return void 0;
|
|
4243
|
-
const classArgs = [];
|
|
4244
|
-
for (const arg of expr.getArguments()) {
|
|
4245
|
-
if (!Node7.isIdentifier(arg)) continue;
|
|
4246
|
-
const decl = arg.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => Node7.isClassDeclaration(n));
|
|
4247
|
-
if (decl) {
|
|
4248
|
-
classArgs.push({
|
|
4249
|
-
name: decl.getName() ?? arg.getText(),
|
|
4250
|
-
filePath: decl.getSourceFile().getFilePath()
|
|
4251
|
-
});
|
|
4252
|
-
}
|
|
4253
|
-
}
|
|
4254
|
-
return {
|
|
4255
|
-
methods: returnedClass.getMethods(),
|
|
4256
|
-
factoryName: callee.getText(),
|
|
4257
|
-
factoryFilePath: factoryDecl.getSourceFile().getFilePath(),
|
|
4258
|
-
classArgs
|
|
4259
|
-
};
|
|
4260
|
-
}
|
|
4261
|
-
var mixinTypeProject;
|
|
4262
|
-
function getMixinTypeProject() {
|
|
4263
|
-
mixinTypeProject ??= new Project3({
|
|
4264
|
-
skipAddingFilesFromTsConfig: true,
|
|
4265
|
-
compilerOptions: { strict: true }
|
|
4266
|
-
});
|
|
4267
|
-
return mixinTypeProject;
|
|
4268
|
-
}
|
|
4269
|
-
function clearMixinTypeProject() {
|
|
4270
|
-
mixinTypeProject = void 0;
|
|
4271
|
-
}
|
|
4272
|
-
function resolveInstantiatedReturnType(cls, methodName) {
|
|
4273
|
-
const filePath = cls.getSourceFile().getFilePath();
|
|
4274
|
-
const className = cls.getName();
|
|
4275
|
-
if (!className) return void 0;
|
|
4276
|
-
const project = getMixinTypeProject();
|
|
4277
|
-
const sourceFile = project.getSourceFile(filePath) ?? project.addSourceFileAtPathIfExists(filePath);
|
|
4278
|
-
const typedCls = sourceFile?.getClass(className);
|
|
4279
|
-
if (!typedCls) return void 0;
|
|
4280
|
-
const prop = typedCls.getType().getProperty(methodName);
|
|
4281
|
-
if (!prop) return void 0;
|
|
4282
|
-
const returnType = prop.getTypeAtLocation(typedCls).getCallSignatures()[0]?.getReturnType();
|
|
4283
|
-
if (!returnType) return void 0;
|
|
4284
|
-
const unwrapped = returnType.getSymbol()?.getName() === "Promise" ? returnType.getTypeArguments()[0] ?? returnType : returnType;
|
|
4285
|
-
return unwrapped.getText(typedCls);
|
|
4286
|
-
}
|
|
4287
|
-
|
|
4288
4341
|
// src/discovery/zod-ast-to-ts.ts
|
|
4289
4342
|
import { Node as Node8, SyntaxKind as SyntaxKind4 } from "ts-morph";
|
|
4290
4343
|
function zodAstToTs(node) {
|
|
@@ -4786,7 +4839,8 @@ function extractFromSourceFile(sourceFile, project) {
|
|
|
4786
4839
|
const mixinBinding = inherited ? {
|
|
4787
4840
|
factoryName: inherited.factoryName,
|
|
4788
4841
|
factoryFilePath: inherited.factoryFilePath,
|
|
4789
|
-
classArgs: inherited.classArgs
|
|
4842
|
+
classArgs: inherited.classArgs,
|
|
4843
|
+
namedClassArgs: inherited.namedClassArgs
|
|
4790
4844
|
} : void 0;
|
|
4791
4845
|
const ownMethods = cls.getMethods();
|
|
4792
4846
|
const ownNames = new Set(ownMethods.map((m) => m.getName()));
|
|
@@ -5101,7 +5155,7 @@ function createChainModuleRenderer(opts) {
|
|
|
5101
5155
|
}
|
|
5102
5156
|
|
|
5103
5157
|
// src/index.ts
|
|
5104
|
-
var VERSION = "0.
|
|
5158
|
+
var VERSION = "0.18.0";
|
|
5105
5159
|
export {
|
|
5106
5160
|
CodegenError,
|
|
5107
5161
|
ConfigError,
|