@dudousxd/nestjs-codegen 0.18.0 → 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/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 callee = call.getExpression();
3477
- if (!Node5.isIdentifier(callee)) return void 0;
3478
- return callee.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => Node5.isFunctionDeclaration(n));
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,12 +3533,26 @@ 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 callee = expr.getExpression();
3501
- if (!Node5.isIdentifier(callee)) return void 0;
3536
+ const isController = cls.getDecorator("Controller") !== void 0;
3537
+ const calleeText = expr.getExpression().getText();
3502
3538
  const factoryDecl = resolveFactoryDeclaration(expr);
3503
- if (!factoryDecl) return void 0;
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) return void 0;
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 = [];
3507
3557
  const namedClassArgs = {};
3508
3558
  for (const arg of expr.getArguments()) {
@@ -3520,7 +3570,12 @@ function resolveInheritedMethods(cls) {
3520
3570
  }
3521
3571
  return {
3522
3572
  methods: returnedClass.getMethods(),
3523
- factoryName: callee.getText(),
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,
3524
3579
  factoryFilePath: factoryDecl.getSourceFile().getFilePath(),
3525
3580
  classArgs,
3526
3581
  namedClassArgs
@@ -5064,7 +5119,7 @@ async function watch(config, onChange, options = {}) {
5064
5119
  }
5065
5120
 
5066
5121
  // src/index.ts
5067
- var VERSION = "0.18.0";
5122
+ var VERSION = "0.19.0";
5068
5123
 
5069
5124
  // src/cli/codegen.ts
5070
5125
  async function runCodegen(opts = {}) {