@dudousxd/nestjs-codegen 0.17.2 → 0.19.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 +76 -0
- package/dist/cli/main.cjs +104 -19
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +104 -19
- 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 +104 -19
- 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 +104 -19
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +104 -19
- 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 +104 -19
- package/dist/nest/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/main.js
CHANGED
|
@@ -3472,10 +3472,46 @@ function resolveReturnedClass(factoryDecl) {
|
|
|
3472
3472
|
}
|
|
3473
3473
|
return void 0;
|
|
3474
3474
|
}
|
|
3475
|
+
function factoryCalleeName(call) {
|
|
3476
|
+
const callee = unwrapExpression(call.getExpression());
|
|
3477
|
+
if (Node5.isIdentifier(callee)) return callee;
|
|
3478
|
+
if (Node5.isPropertyAccessExpression(callee)) {
|
|
3479
|
+
const name = callee.getNameNode();
|
|
3480
|
+
return Node5.isIdentifier(name) ? name : void 0;
|
|
3481
|
+
}
|
|
3482
|
+
return void 0;
|
|
3483
|
+
}
|
|
3475
3484
|
function resolveFactoryDeclaration(call) {
|
|
3476
|
-
const
|
|
3477
|
-
|
|
3478
|
-
|
|
3485
|
+
const name = factoryCalleeName(call);
|
|
3486
|
+
return name ? resolveFactoryFromName(name, /* @__PURE__ */ new Set()) : void 0;
|
|
3487
|
+
}
|
|
3488
|
+
function resolveFactoryFromName(name, seen) {
|
|
3489
|
+
if (seen.has(name)) return void 0;
|
|
3490
|
+
seen.add(name);
|
|
3491
|
+
const decls = name.getDefinitions().map((d) => d.getDeclarationNode()).filter((n) => n !== void 0);
|
|
3492
|
+
for (const decl of decls) {
|
|
3493
|
+
if (Node5.isFunctionDeclaration(decl) || Node5.isMethodDeclaration(decl)) return decl;
|
|
3494
|
+
if (Node5.isPropertyAssignment(decl)) {
|
|
3495
|
+
const init = decl.getInitializer();
|
|
3496
|
+
const inner = init ? unwrapExpression(init) : void 0;
|
|
3497
|
+
if (inner && Node5.isIdentifier(inner)) {
|
|
3498
|
+
const resolved = resolveFactoryFromName(inner, seen);
|
|
3499
|
+
if (resolved) return resolved;
|
|
3500
|
+
}
|
|
3501
|
+
continue;
|
|
3502
|
+
}
|
|
3503
|
+
if (Node5.isShorthandPropertyAssignment(decl)) {
|
|
3504
|
+
const nameNode = decl.getNameNode();
|
|
3505
|
+
const resolved = Node5.isIdentifier(nameNode) ? resolveFactoryFromName(nameNode, seen) : void 0;
|
|
3506
|
+
if (resolved) return resolved;
|
|
3507
|
+
}
|
|
3508
|
+
}
|
|
3509
|
+
return void 0;
|
|
3510
|
+
}
|
|
3511
|
+
function warnUnresolvedFactory(cls, calleeText, reason) {
|
|
3512
|
+
console.warn(
|
|
3513
|
+
`[nestjs-codegen/fast] ${cls.getName() ?? "<anonymous class>"} in ${cls.getSourceFile().getFilePath()} extends ${calleeText}(...) but ${reason} \u2014 it contributes NO routes to the generated client. Resolvable factory callees: a name (\`factory(...)\`), a namespace or object property (\`ns.factory(...)\`), or a static method (\`Factory.create(...)\`), each resolving to a function or method declaration that returns a class.`
|
|
3514
|
+
);
|
|
3479
3515
|
}
|
|
3480
3516
|
function resolveFactoryStaticClass(node) {
|
|
3481
3517
|
if (!Node5.isPropertyAccessExpression(node)) return void 0;
|
|
@@ -3497,30 +3533,78 @@ function resolveFactoryStaticClass(node) {
|
|
|
3497
3533
|
function resolveInheritedMethods(cls) {
|
|
3498
3534
|
const expr = resolveHeritageCall(cls.getExtends()?.getExpression());
|
|
3499
3535
|
if (!expr) return void 0;
|
|
3500
|
-
const
|
|
3501
|
-
|
|
3536
|
+
const isController = cls.getDecorator("Controller") !== void 0;
|
|
3537
|
+
const calleeText = expr.getExpression().getText();
|
|
3502
3538
|
const factoryDecl = resolveFactoryDeclaration(expr);
|
|
3503
|
-
if (!factoryDecl)
|
|
3539
|
+
if (!factoryDecl) {
|
|
3540
|
+
if (isController) {
|
|
3541
|
+
warnUnresolvedFactory(
|
|
3542
|
+
cls,
|
|
3543
|
+
calleeText,
|
|
3544
|
+
factoryCalleeName(expr) ? "its callee does not resolve to a function or method declaration" : "its callee is not a name that can be resolved statically"
|
|
3545
|
+
);
|
|
3546
|
+
}
|
|
3547
|
+
return void 0;
|
|
3548
|
+
}
|
|
3504
3549
|
const returnedClass = resolveReturnedClass(factoryDecl);
|
|
3505
|
-
if (!returnedClass)
|
|
3550
|
+
if (!returnedClass) {
|
|
3551
|
+
if (isController) {
|
|
3552
|
+
warnUnresolvedFactory(cls, calleeText, "that factory does not return a class declaration");
|
|
3553
|
+
}
|
|
3554
|
+
return void 0;
|
|
3555
|
+
}
|
|
3506
3556
|
const classArgs = [];
|
|
3557
|
+
const namedClassArgs = {};
|
|
3507
3558
|
for (const arg of expr.getArguments()) {
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3559
|
+
const positional = resolveClassReference(arg);
|
|
3560
|
+
if (positional) {
|
|
3561
|
+
classArgs.push(positional);
|
|
3562
|
+
continue;
|
|
3563
|
+
}
|
|
3564
|
+
if (!Node5.isObjectLiteralExpression(arg)) continue;
|
|
3565
|
+
for (const prop of arg.getProperties()) {
|
|
3566
|
+
const named = resolvePropertyClassReference(prop);
|
|
3567
|
+
if (!named) continue;
|
|
3568
|
+
namedClassArgs[named.key] ??= named.ref;
|
|
3515
3569
|
}
|
|
3516
3570
|
}
|
|
3517
3571
|
return {
|
|
3518
3572
|
methods: returnedClass.getMethods(),
|
|
3519
|
-
|
|
3573
|
+
// The DECLARATION's name, not the call-site text: consumers look the factory
|
|
3574
|
+
// back up by name inside `factoryFilePath`, which a qualified
|
|
3575
|
+
// `tables.createTableController` would never match. For a bare identifier
|
|
3576
|
+
// the two coincide (bar an import alias, where the declaration name is the
|
|
3577
|
+
// one that resolves anyway).
|
|
3578
|
+
factoryName: factoryDecl.getName() ?? calleeText,
|
|
3520
3579
|
factoryFilePath: factoryDecl.getSourceFile().getFilePath(),
|
|
3521
|
-
classArgs
|
|
3580
|
+
classArgs,
|
|
3581
|
+
namedClassArgs
|
|
3522
3582
|
};
|
|
3523
3583
|
}
|
|
3584
|
+
function resolveClassReference(node) {
|
|
3585
|
+
const expr = unwrapExpression(node);
|
|
3586
|
+
if (!Node5.isIdentifier(expr)) return void 0;
|
|
3587
|
+
const decl = expr.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => n !== void 0 && Node5.isClassDeclaration(n));
|
|
3588
|
+
if (!decl) return void 0;
|
|
3589
|
+
return {
|
|
3590
|
+
name: decl.getName() ?? expr.getText(),
|
|
3591
|
+
filePath: decl.getSourceFile().getFilePath()
|
|
3592
|
+
};
|
|
3593
|
+
}
|
|
3594
|
+
function resolvePropertyClassReference(prop) {
|
|
3595
|
+
if (Node5.isShorthandPropertyAssignment(prop)) {
|
|
3596
|
+
const ref2 = resolveClassReference(prop.getNameNode());
|
|
3597
|
+
return ref2 ? { key: prop.getName(), ref: ref2 } : void 0;
|
|
3598
|
+
}
|
|
3599
|
+
if (!Node5.isPropertyAssignment(prop)) return void 0;
|
|
3600
|
+
const init = prop.getInitializer();
|
|
3601
|
+
if (!init) return void 0;
|
|
3602
|
+
const ref = resolveClassReference(init);
|
|
3603
|
+
if (!ref) return void 0;
|
|
3604
|
+
const nameNode = prop.getNameNode();
|
|
3605
|
+
const key = Node5.isStringLiteral(nameNode) ? nameNode.getLiteralValue() : prop.getName();
|
|
3606
|
+
return { key, ref };
|
|
3607
|
+
}
|
|
3524
3608
|
var mixinTypeProject;
|
|
3525
3609
|
function getMixinTypeProject() {
|
|
3526
3610
|
mixinTypeProject ??= new Project3({
|
|
@@ -3550,7 +3634,7 @@ function resolveInstantiatedReturnType(cls, methodName) {
|
|
|
3550
3634
|
|
|
3551
3635
|
// src/discovery/filter-for.ts
|
|
3552
3636
|
function resolveMixinEntityClass(mixin, project) {
|
|
3553
|
-
const entityArg = mixin?.classArgs[0];
|
|
3637
|
+
const entityArg = mixin?.namedClassArgs?.entity ?? mixin?.classArgs[0];
|
|
3554
3638
|
if (!entityArg) return void 0;
|
|
3555
3639
|
const file = project.getSourceFile(entityArg.filePath) ?? project.addSourceFileAtPathIfExists(entityArg.filePath);
|
|
3556
3640
|
return file?.getClass(entityArg.name);
|
|
@@ -4802,7 +4886,8 @@ function extractFromSourceFile(sourceFile, project) {
|
|
|
4802
4886
|
const mixinBinding = inherited ? {
|
|
4803
4887
|
factoryName: inherited.factoryName,
|
|
4804
4888
|
factoryFilePath: inherited.factoryFilePath,
|
|
4805
|
-
classArgs: inherited.classArgs
|
|
4889
|
+
classArgs: inherited.classArgs,
|
|
4890
|
+
namedClassArgs: inherited.namedClassArgs
|
|
4806
4891
|
} : void 0;
|
|
4807
4892
|
const ownMethods = cls.getMethods();
|
|
4808
4893
|
const ownNames = new Set(ownMethods.map((m) => m.getName()));
|
|
@@ -5034,7 +5119,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
5034
5119
|
}
|
|
5035
5120
|
|
|
5036
5121
|
// src/index.ts
|
|
5037
|
-
var VERSION = "0.
|
|
5122
|
+
var VERSION = "0.19.0";
|
|
5038
5123
|
|
|
5039
5124
|
// src/cli/codegen.ts
|
|
5040
5125
|
async function runCodegen(opts = {}) {
|