@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.
@@ -3284,10 +3284,46 @@ function resolveReturnedClass(factoryDecl) {
3284
3284
  }
3285
3285
  return void 0;
3286
3286
  }
3287
+ function factoryCalleeName(call) {
3288
+ const callee = unwrapExpression(call.getExpression());
3289
+ if (Node5.isIdentifier(callee)) return callee;
3290
+ if (Node5.isPropertyAccessExpression(callee)) {
3291
+ const name = callee.getNameNode();
3292
+ return Node5.isIdentifier(name) ? name : void 0;
3293
+ }
3294
+ return void 0;
3295
+ }
3287
3296
  function resolveFactoryDeclaration(call) {
3288
- const callee = call.getExpression();
3289
- if (!Node5.isIdentifier(callee)) return void 0;
3290
- return callee.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => Node5.isFunctionDeclaration(n));
3297
+ const name = factoryCalleeName(call);
3298
+ return name ? resolveFactoryFromName(name, /* @__PURE__ */ new Set()) : void 0;
3299
+ }
3300
+ function resolveFactoryFromName(name, seen) {
3301
+ if (seen.has(name)) return void 0;
3302
+ seen.add(name);
3303
+ const decls = name.getDefinitions().map((d) => d.getDeclarationNode()).filter((n) => n !== void 0);
3304
+ for (const decl of decls) {
3305
+ if (Node5.isFunctionDeclaration(decl) || Node5.isMethodDeclaration(decl)) return decl;
3306
+ if (Node5.isPropertyAssignment(decl)) {
3307
+ const init = decl.getInitializer();
3308
+ const inner = init ? unwrapExpression(init) : void 0;
3309
+ if (inner && Node5.isIdentifier(inner)) {
3310
+ const resolved = resolveFactoryFromName(inner, seen);
3311
+ if (resolved) return resolved;
3312
+ }
3313
+ continue;
3314
+ }
3315
+ if (Node5.isShorthandPropertyAssignment(decl)) {
3316
+ const nameNode = decl.getNameNode();
3317
+ const resolved = Node5.isIdentifier(nameNode) ? resolveFactoryFromName(nameNode, seen) : void 0;
3318
+ if (resolved) return resolved;
3319
+ }
3320
+ }
3321
+ return void 0;
3322
+ }
3323
+ function warnUnresolvedFactory(cls, calleeText, reason) {
3324
+ console.warn(
3325
+ `[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.`
3326
+ );
3291
3327
  }
3292
3328
  function resolveFactoryStaticClass(node) {
3293
3329
  if (!Node5.isPropertyAccessExpression(node)) return void 0;
@@ -3309,12 +3345,26 @@ function resolveFactoryStaticClass(node) {
3309
3345
  function resolveInheritedMethods(cls) {
3310
3346
  const expr = resolveHeritageCall(cls.getExtends()?.getExpression());
3311
3347
  if (!expr) return void 0;
3312
- const callee = expr.getExpression();
3313
- if (!Node5.isIdentifier(callee)) return void 0;
3348
+ const isController = cls.getDecorator("Controller") !== void 0;
3349
+ const calleeText = expr.getExpression().getText();
3314
3350
  const factoryDecl = resolveFactoryDeclaration(expr);
3315
- if (!factoryDecl) return void 0;
3351
+ if (!factoryDecl) {
3352
+ if (isController) {
3353
+ warnUnresolvedFactory(
3354
+ cls,
3355
+ calleeText,
3356
+ factoryCalleeName(expr) ? "its callee does not resolve to a function or method declaration" : "its callee is not a name that can be resolved statically"
3357
+ );
3358
+ }
3359
+ return void 0;
3360
+ }
3316
3361
  const returnedClass = resolveReturnedClass(factoryDecl);
3317
- if (!returnedClass) return void 0;
3362
+ if (!returnedClass) {
3363
+ if (isController) {
3364
+ warnUnresolvedFactory(cls, calleeText, "that factory does not return a class declaration");
3365
+ }
3366
+ return void 0;
3367
+ }
3318
3368
  const classArgs = [];
3319
3369
  const namedClassArgs = {};
3320
3370
  for (const arg of expr.getArguments()) {
@@ -3332,7 +3382,12 @@ function resolveInheritedMethods(cls) {
3332
3382
  }
3333
3383
  return {
3334
3384
  methods: returnedClass.getMethods(),
3335
- factoryName: callee.getText(),
3385
+ // The DECLARATION's name, not the call-site text: consumers look the factory
3386
+ // back up by name inside `factoryFilePath`, which a qualified
3387
+ // `tables.createTableController` would never match. For a bare identifier
3388
+ // the two coincide (bar an import alias, where the declaration name is the
3389
+ // one that resolves anyway).
3390
+ factoryName: factoryDecl.getName() ?? calleeText,
3336
3391
  factoryFilePath: factoryDecl.getSourceFile().getFilePath(),
3337
3392
  classArgs,
3338
3393
  namedClassArgs
@@ -4857,7 +4912,7 @@ async function watch(config, onChange, options = {}) {
4857
4912
  }
4858
4913
 
4859
4914
  // src/index.ts
4860
- var VERSION = "0.18.0";
4915
+ var VERSION = "0.19.0";
4861
4916
 
4862
4917
  // src/generate-manifest.ts
4863
4918
  var MANIFEST_FILE = ".codegen-manifest.json";