@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.
@@ -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,30 +3369,78 @@ 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 = [];
3393
+ const namedClassArgs = {};
3343
3394
  for (const arg of expr.getArguments()) {
3344
- if (!import_ts_morph6.Node.isIdentifier(arg)) continue;
3345
- const decl = arg.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => import_ts_morph6.Node.isClassDeclaration(n));
3346
- if (decl) {
3347
- classArgs.push({
3348
- name: decl.getName() ?? arg.getText(),
3349
- filePath: decl.getSourceFile().getFilePath()
3350
- });
3395
+ const positional = resolveClassReference(arg);
3396
+ if (positional) {
3397
+ classArgs.push(positional);
3398
+ continue;
3399
+ }
3400
+ if (!import_ts_morph6.Node.isObjectLiteralExpression(arg)) continue;
3401
+ for (const prop of arg.getProperties()) {
3402
+ const named = resolvePropertyClassReference(prop);
3403
+ if (!named) continue;
3404
+ namedClassArgs[named.key] ??= named.ref;
3351
3405
  }
3352
3406
  }
3353
3407
  return {
3354
3408
  methods: returnedClass.getMethods(),
3355
- 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,
3356
3415
  factoryFilePath: factoryDecl.getSourceFile().getFilePath(),
3357
- classArgs
3416
+ classArgs,
3417
+ namedClassArgs
3358
3418
  };
3359
3419
  }
3420
+ function resolveClassReference(node) {
3421
+ const expr = unwrapExpression(node);
3422
+ if (!import_ts_morph6.Node.isIdentifier(expr)) return void 0;
3423
+ const decl = expr.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => n !== void 0 && import_ts_morph6.Node.isClassDeclaration(n));
3424
+ if (!decl) return void 0;
3425
+ return {
3426
+ name: decl.getName() ?? expr.getText(),
3427
+ filePath: decl.getSourceFile().getFilePath()
3428
+ };
3429
+ }
3430
+ function resolvePropertyClassReference(prop) {
3431
+ if (import_ts_morph6.Node.isShorthandPropertyAssignment(prop)) {
3432
+ const ref2 = resolveClassReference(prop.getNameNode());
3433
+ return ref2 ? { key: prop.getName(), ref: ref2 } : void 0;
3434
+ }
3435
+ if (!import_ts_morph6.Node.isPropertyAssignment(prop)) return void 0;
3436
+ const init = prop.getInitializer();
3437
+ if (!init) return void 0;
3438
+ const ref = resolveClassReference(init);
3439
+ if (!ref) return void 0;
3440
+ const nameNode = prop.getNameNode();
3441
+ const key = import_ts_morph6.Node.isStringLiteral(nameNode) ? nameNode.getLiteralValue() : prop.getName();
3442
+ return { key, ref };
3443
+ }
3360
3444
  var mixinTypeProject;
3361
3445
  function getMixinTypeProject() {
3362
3446
  mixinTypeProject ??= new import_ts_morph6.Project({
@@ -3386,7 +3470,7 @@ function resolveInstantiatedReturnType(cls, methodName) {
3386
3470
 
3387
3471
  // src/discovery/filter-for.ts
3388
3472
  function resolveMixinEntityClass(mixin, project) {
3389
- const entityArg = mixin?.classArgs[0];
3473
+ const entityArg = mixin?.namedClassArgs?.entity ?? mixin?.classArgs[0];
3390
3474
  if (!entityArg) return void 0;
3391
3475
  const file = project.getSourceFile(entityArg.filePath) ?? project.addSourceFileAtPathIfExists(entityArg.filePath);
3392
3476
  return file?.getClass(entityArg.name);
@@ -4619,7 +4703,8 @@ function extractFromSourceFile(sourceFile, project) {
4619
4703
  const mixinBinding = inherited ? {
4620
4704
  factoryName: inherited.factoryName,
4621
4705
  factoryFilePath: inherited.factoryFilePath,
4622
- classArgs: inherited.classArgs
4706
+ classArgs: inherited.classArgs,
4707
+ namedClassArgs: inherited.namedClassArgs
4623
4708
  } : void 0;
4624
4709
  const ownMethods = cls.getMethods();
4625
4710
  const ownNames = new Set(ownMethods.map((m) => m.getName()));
@@ -4851,7 +4936,7 @@ async function watch(config, onChange, options = {}) {
4851
4936
  }
4852
4937
 
4853
4938
  // src/index.ts
4854
- var VERSION = "0.17.2";
4939
+ var VERSION = "0.19.0";
4855
4940
 
4856
4941
  // src/generate-manifest.ts
4857
4942
  var MANIFEST_FILE = ".codegen-manifest.json";