@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/index.cjs CHANGED
@@ -3526,10 +3526,46 @@ function resolveReturnedClass(factoryDecl) {
3526
3526
  }
3527
3527
  return void 0;
3528
3528
  }
3529
+ function factoryCalleeName(call) {
3530
+ const callee = unwrapExpression(call.getExpression());
3531
+ if (import_ts_morph6.Node.isIdentifier(callee)) return callee;
3532
+ if (import_ts_morph6.Node.isPropertyAccessExpression(callee)) {
3533
+ const name = callee.getNameNode();
3534
+ return import_ts_morph6.Node.isIdentifier(name) ? name : void 0;
3535
+ }
3536
+ return void 0;
3537
+ }
3529
3538
  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));
3539
+ const name = factoryCalleeName(call);
3540
+ return name ? resolveFactoryFromName(name, /* @__PURE__ */ new Set()) : void 0;
3541
+ }
3542
+ function resolveFactoryFromName(name, seen) {
3543
+ if (seen.has(name)) return void 0;
3544
+ seen.add(name);
3545
+ const decls = name.getDefinitions().map((d) => d.getDeclarationNode()).filter((n) => n !== void 0);
3546
+ for (const decl of decls) {
3547
+ if (import_ts_morph6.Node.isFunctionDeclaration(decl) || import_ts_morph6.Node.isMethodDeclaration(decl)) return decl;
3548
+ if (import_ts_morph6.Node.isPropertyAssignment(decl)) {
3549
+ const init = decl.getInitializer();
3550
+ const inner = init ? unwrapExpression(init) : void 0;
3551
+ if (inner && import_ts_morph6.Node.isIdentifier(inner)) {
3552
+ const resolved = resolveFactoryFromName(inner, seen);
3553
+ if (resolved) return resolved;
3554
+ }
3555
+ continue;
3556
+ }
3557
+ if (import_ts_morph6.Node.isShorthandPropertyAssignment(decl)) {
3558
+ const nameNode = decl.getNameNode();
3559
+ const resolved = import_ts_morph6.Node.isIdentifier(nameNode) ? resolveFactoryFromName(nameNode, seen) : void 0;
3560
+ if (resolved) return resolved;
3561
+ }
3562
+ }
3563
+ return void 0;
3564
+ }
3565
+ function warnUnresolvedFactory(cls, calleeText, reason) {
3566
+ console.warn(
3567
+ `[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.`
3568
+ );
3533
3569
  }
3534
3570
  function resolveFactoryStaticClass(node) {
3535
3571
  if (!import_ts_morph6.Node.isPropertyAccessExpression(node)) return void 0;
@@ -3551,12 +3587,26 @@ function resolveFactoryStaticClass(node) {
3551
3587
  function resolveInheritedMethods(cls) {
3552
3588
  const expr = resolveHeritageCall(cls.getExtends()?.getExpression());
3553
3589
  if (!expr) return void 0;
3554
- const callee = expr.getExpression();
3555
- if (!import_ts_morph6.Node.isIdentifier(callee)) return void 0;
3590
+ const isController = cls.getDecorator("Controller") !== void 0;
3591
+ const calleeText = expr.getExpression().getText();
3556
3592
  const factoryDecl = resolveFactoryDeclaration(expr);
3557
- if (!factoryDecl) return void 0;
3593
+ if (!factoryDecl) {
3594
+ if (isController) {
3595
+ warnUnresolvedFactory(
3596
+ cls,
3597
+ calleeText,
3598
+ factoryCalleeName(expr) ? "its callee does not resolve to a function or method declaration" : "its callee is not a name that can be resolved statically"
3599
+ );
3600
+ }
3601
+ return void 0;
3602
+ }
3558
3603
  const returnedClass = resolveReturnedClass(factoryDecl);
3559
- if (!returnedClass) return void 0;
3604
+ if (!returnedClass) {
3605
+ if (isController) {
3606
+ warnUnresolvedFactory(cls, calleeText, "that factory does not return a class declaration");
3607
+ }
3608
+ return void 0;
3609
+ }
3560
3610
  const classArgs = [];
3561
3611
  const namedClassArgs = {};
3562
3612
  for (const arg of expr.getArguments()) {
@@ -3574,7 +3624,12 @@ function resolveInheritedMethods(cls) {
3574
3624
  }
3575
3625
  return {
3576
3626
  methods: returnedClass.getMethods(),
3577
- factoryName: callee.getText(),
3627
+ // The DECLARATION's name, not the call-site text: consumers look the factory
3628
+ // back up by name inside `factoryFilePath`, which a qualified
3629
+ // `tables.createTableController` would never match. For a bare identifier
3630
+ // the two coincide (bar an import alias, where the declaration name is the
3631
+ // one that resolves anyway).
3632
+ factoryName: factoryDecl.getName() ?? calleeText,
3578
3633
  factoryFilePath: factoryDecl.getSourceFile().getFilePath(),
3579
3634
  classArgs,
3580
3635
  namedClassArgs
@@ -5201,7 +5256,7 @@ function createChainModuleRenderer(opts) {
5201
5256
  }
5202
5257
 
5203
5258
  // src/index.ts
5204
- var VERSION = "0.18.0";
5259
+ var VERSION = "0.19.0";
5205
5260
  // Annotate the CommonJS export names for ESM import in node:
5206
5261
  0 && (module.exports = {
5207
5262
  CodegenError,