@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.
@@ -1,6 +1,6 @@
1
1
  import * as _nestjs_common from '@nestjs/common';
2
2
  import { DynamicModule, OnApplicationBootstrap, OnModuleDestroy, ExecutionContext } from '@nestjs/common';
3
- import { U as UserConfig } from '../index-DCF9QSPY.cjs';
3
+ import { U as UserConfig } from '../index-Dyf4ttwU.cjs';
4
4
  import 'ts-morph';
5
5
 
6
6
  /**
@@ -1,6 +1,6 @@
1
1
  import * as _nestjs_common from '@nestjs/common';
2
2
  import { DynamicModule, OnApplicationBootstrap, OnModuleDestroy, ExecutionContext } from '@nestjs/common';
3
- import { U as UserConfig } from '../index-DCF9QSPY.js';
3
+ import { U as UserConfig } from '../index-Dyf4ttwU.js';
4
4
  import 'ts-morph';
5
5
 
6
6
  /**
@@ -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,30 +3345,78 @@ 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 = [];
3369
+ const namedClassArgs = {};
3319
3370
  for (const arg of expr.getArguments()) {
3320
- if (!Node5.isIdentifier(arg)) continue;
3321
- const decl = arg.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => Node5.isClassDeclaration(n));
3322
- if (decl) {
3323
- classArgs.push({
3324
- name: decl.getName() ?? arg.getText(),
3325
- filePath: decl.getSourceFile().getFilePath()
3326
- });
3371
+ const positional = resolveClassReference(arg);
3372
+ if (positional) {
3373
+ classArgs.push(positional);
3374
+ continue;
3375
+ }
3376
+ if (!Node5.isObjectLiteralExpression(arg)) continue;
3377
+ for (const prop of arg.getProperties()) {
3378
+ const named = resolvePropertyClassReference(prop);
3379
+ if (!named) continue;
3380
+ namedClassArgs[named.key] ??= named.ref;
3327
3381
  }
3328
3382
  }
3329
3383
  return {
3330
3384
  methods: returnedClass.getMethods(),
3331
- 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,
3332
3391
  factoryFilePath: factoryDecl.getSourceFile().getFilePath(),
3333
- classArgs
3392
+ classArgs,
3393
+ namedClassArgs
3334
3394
  };
3335
3395
  }
3396
+ function resolveClassReference(node) {
3397
+ const expr = unwrapExpression(node);
3398
+ if (!Node5.isIdentifier(expr)) return void 0;
3399
+ const decl = expr.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => n !== void 0 && Node5.isClassDeclaration(n));
3400
+ if (!decl) return void 0;
3401
+ return {
3402
+ name: decl.getName() ?? expr.getText(),
3403
+ filePath: decl.getSourceFile().getFilePath()
3404
+ };
3405
+ }
3406
+ function resolvePropertyClassReference(prop) {
3407
+ if (Node5.isShorthandPropertyAssignment(prop)) {
3408
+ const ref2 = resolveClassReference(prop.getNameNode());
3409
+ return ref2 ? { key: prop.getName(), ref: ref2 } : void 0;
3410
+ }
3411
+ if (!Node5.isPropertyAssignment(prop)) return void 0;
3412
+ const init = prop.getInitializer();
3413
+ if (!init) return void 0;
3414
+ const ref = resolveClassReference(init);
3415
+ if (!ref) return void 0;
3416
+ const nameNode = prop.getNameNode();
3417
+ const key = Node5.isStringLiteral(nameNode) ? nameNode.getLiteralValue() : prop.getName();
3418
+ return { key, ref };
3419
+ }
3336
3420
  var mixinTypeProject;
3337
3421
  function getMixinTypeProject() {
3338
3422
  mixinTypeProject ??= new Project3({
@@ -3362,7 +3446,7 @@ function resolveInstantiatedReturnType(cls, methodName) {
3362
3446
 
3363
3447
  // src/discovery/filter-for.ts
3364
3448
  function resolveMixinEntityClass(mixin, project) {
3365
- const entityArg = mixin?.classArgs[0];
3449
+ const entityArg = mixin?.namedClassArgs?.entity ?? mixin?.classArgs[0];
3366
3450
  if (!entityArg) return void 0;
3367
3451
  const file = project.getSourceFile(entityArg.filePath) ?? project.addSourceFileAtPathIfExists(entityArg.filePath);
3368
3452
  return file?.getClass(entityArg.name);
@@ -4595,7 +4679,8 @@ function extractFromSourceFile(sourceFile, project) {
4595
4679
  const mixinBinding = inherited ? {
4596
4680
  factoryName: inherited.factoryName,
4597
4681
  factoryFilePath: inherited.factoryFilePath,
4598
- classArgs: inherited.classArgs
4682
+ classArgs: inherited.classArgs,
4683
+ namedClassArgs: inherited.namedClassArgs
4599
4684
  } : void 0;
4600
4685
  const ownMethods = cls.getMethods();
4601
4686
  const ownNames = new Set(ownMethods.map((m) => m.getName()));
@@ -4827,7 +4912,7 @@ async function watch(config, onChange, options = {}) {
4827
4912
  }
4828
4913
 
4829
4914
  // src/index.ts
4830
- var VERSION = "0.17.2";
4915
+ var VERSION = "0.19.0";
4831
4916
 
4832
4917
  // src/generate-manifest.ts
4833
4918
  var MANIFEST_FILE = ".codegen-manifest.json";