@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.
@@ -3308,10 +3308,46 @@ function resolveReturnedClass(factoryDecl) {
3308
3308
  }
3309
3309
  return void 0;
3310
3310
  }
3311
+ function factoryCalleeName(call) {
3312
+ const callee = unwrapExpression(call.getExpression());
3313
+ if (import_ts_morph6.Node.isIdentifier(callee)) return callee;
3314
+ if (import_ts_morph6.Node.isPropertyAccessExpression(callee)) {
3315
+ const name = callee.getNameNode();
3316
+ return import_ts_morph6.Node.isIdentifier(name) ? name : void 0;
3317
+ }
3318
+ return void 0;
3319
+ }
3311
3320
  function resolveFactoryDeclaration(call) {
3312
- const callee = call.getExpression();
3313
- if (!import_ts_morph6.Node.isIdentifier(callee)) return void 0;
3314
- return callee.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => import_ts_morph6.Node.isFunctionDeclaration(n));
3321
+ const name = factoryCalleeName(call);
3322
+ return name ? resolveFactoryFromName(name, /* @__PURE__ */ new Set()) : void 0;
3323
+ }
3324
+ function resolveFactoryFromName(name, seen) {
3325
+ if (seen.has(name)) return void 0;
3326
+ seen.add(name);
3327
+ const decls = name.getDefinitions().map((d) => d.getDeclarationNode()).filter((n) => n !== void 0);
3328
+ for (const decl of decls) {
3329
+ if (import_ts_morph6.Node.isFunctionDeclaration(decl) || import_ts_morph6.Node.isMethodDeclaration(decl)) return decl;
3330
+ if (import_ts_morph6.Node.isPropertyAssignment(decl)) {
3331
+ const init = decl.getInitializer();
3332
+ const inner = init ? unwrapExpression(init) : void 0;
3333
+ if (inner && import_ts_morph6.Node.isIdentifier(inner)) {
3334
+ const resolved = resolveFactoryFromName(inner, seen);
3335
+ if (resolved) return resolved;
3336
+ }
3337
+ continue;
3338
+ }
3339
+ if (import_ts_morph6.Node.isShorthandPropertyAssignment(decl)) {
3340
+ const nameNode = decl.getNameNode();
3341
+ const resolved = import_ts_morph6.Node.isIdentifier(nameNode) ? resolveFactoryFromName(nameNode, seen) : void 0;
3342
+ if (resolved) return resolved;
3343
+ }
3344
+ }
3345
+ return void 0;
3346
+ }
3347
+ function warnUnresolvedFactory(cls, calleeText, reason) {
3348
+ console.warn(
3349
+ `[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.`
3350
+ );
3315
3351
  }
3316
3352
  function resolveFactoryStaticClass(node) {
3317
3353
  if (!import_ts_morph6.Node.isPropertyAccessExpression(node)) return void 0;
@@ -3333,12 +3369,26 @@ function resolveFactoryStaticClass(node) {
3333
3369
  function resolveInheritedMethods(cls) {
3334
3370
  const expr = resolveHeritageCall(cls.getExtends()?.getExpression());
3335
3371
  if (!expr) return void 0;
3336
- const callee = expr.getExpression();
3337
- if (!import_ts_morph6.Node.isIdentifier(callee)) return void 0;
3372
+ const isController = cls.getDecorator("Controller") !== void 0;
3373
+ const calleeText = expr.getExpression().getText();
3338
3374
  const factoryDecl = resolveFactoryDeclaration(expr);
3339
- if (!factoryDecl) return void 0;
3375
+ if (!factoryDecl) {
3376
+ if (isController) {
3377
+ warnUnresolvedFactory(
3378
+ cls,
3379
+ calleeText,
3380
+ factoryCalleeName(expr) ? "its callee does not resolve to a function or method declaration" : "its callee is not a name that can be resolved statically"
3381
+ );
3382
+ }
3383
+ return void 0;
3384
+ }
3340
3385
  const returnedClass = resolveReturnedClass(factoryDecl);
3341
- if (!returnedClass) return void 0;
3386
+ if (!returnedClass) {
3387
+ if (isController) {
3388
+ warnUnresolvedFactory(cls, calleeText, "that factory does not return a class declaration");
3389
+ }
3390
+ return void 0;
3391
+ }
3342
3392
  const classArgs = [];
3343
3393
  const namedClassArgs = {};
3344
3394
  for (const arg of expr.getArguments()) {
@@ -3356,7 +3406,12 @@ function resolveInheritedMethods(cls) {
3356
3406
  }
3357
3407
  return {
3358
3408
  methods: returnedClass.getMethods(),
3359
- factoryName: callee.getText(),
3409
+ // The DECLARATION's name, not the call-site text: consumers look the factory
3410
+ // back up by name inside `factoryFilePath`, which a qualified
3411
+ // `tables.createTableController` would never match. For a bare identifier
3412
+ // the two coincide (bar an import alias, where the declaration name is the
3413
+ // one that resolves anyway).
3414
+ factoryName: factoryDecl.getName() ?? calleeText,
3360
3415
  factoryFilePath: factoryDecl.getSourceFile().getFilePath(),
3361
3416
  classArgs,
3362
3417
  namedClassArgs
@@ -4881,7 +4936,7 @@ async function watch(config, onChange, options = {}) {
4881
4936
  }
4882
4937
 
4883
4938
  // src/index.ts
4884
- var VERSION = "0.18.0";
4939
+ var VERSION = "0.19.0";
4885
4940
 
4886
4941
  // src/generate-manifest.ts
4887
4942
  var MANIFEST_FILE = ".codegen-manifest.json";