@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.
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor, S as SchemaNode, b as RenderContext, c as SchemaModule, d as RenderedModule, e as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext, f as SerializationMode } from './index-DCF9QSPY.cjs';
2
- export { A as AdapterUsage, g as ContractDescriptor, h as ContractSource, i as ControllerRef, N as NumberCheck, j as ScopeConfig, k as StringCheck, T as TypeRef, l as ValidationOption, r as resolveAdapter } from './index-DCF9QSPY.cjs';
1
+ import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor, S as SchemaNode, b as RenderContext, c as SchemaModule, d as RenderedModule, e as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext, f as SerializationMode } from './index-Dyf4ttwU.cjs';
2
+ export { A as AdapterUsage, g as ContractDescriptor, h as ContractSource, i as ControllerRef, N as NumberCheck, j as ScopeConfig, k as StringCheck, T as TypeRef, l as ValidationOption, r as resolveAdapter } from './index-Dyf4ttwU.cjs';
3
3
  import { ClassDeclaration, SourceFile, Project } from 'ts-morph';
4
4
 
5
5
  declare function defineConfig(c: UserConfig): UserConfig;
@@ -382,6 +382,6 @@ interface FastDiscoveryOptions {
382
382
  }
383
383
  declare function discoverContractsFast(opts: FastDiscoveryOptions): Promise<RouteDescriptor[]>;
384
384
 
385
- declare const VERSION = "0.17.2";
385
+ declare const VERSION = "0.19.0";
386
386
 
387
387
  export { type ChainModuleRendererOptions, CodegenError, type CodegenManifest, ConfigError, DriftGuardError, type EntryPoint, type FastDiscoveryOptions, type JsonSchema, type MocksEmitOptions, type OpenApiDocument, type OpenApiEmitOptions, type OpenApiInfo, RenderContext, RenderedModule, ResolvedConfig, RouteDescriptor, SchemaModule, SchemaNode, type TsTypeContext, UserConfig, VERSION, ValidationAdapter, type WatchOptions, type Watcher, acquireLock, buildMocksFile, buildOpenApiSpec, createChainModuleRenderer, defineConfig, discoverContractsFast, emitApi, emitForms, emitMocks, emitOpenApi, emitRoutes, extractSchemaFromDto, generate, loadConfig, renderTsType, resolveConfig, schemaModuleToJsonSchema, schemaNodeToJsonSchema, toObjectKey, typeNameFor, watch };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor, S as SchemaNode, b as RenderContext, c as SchemaModule, d as RenderedModule, e as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext, f as SerializationMode } from './index-DCF9QSPY.js';
2
- export { A as AdapterUsage, g as ContractDescriptor, h as ContractSource, i as ControllerRef, N as NumberCheck, j as ScopeConfig, k as StringCheck, T as TypeRef, l as ValidationOption, r as resolveAdapter } from './index-DCF9QSPY.js';
1
+ import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor, S as SchemaNode, b as RenderContext, c as SchemaModule, d as RenderedModule, e as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext, f as SerializationMode } from './index-Dyf4ttwU.js';
2
+ export { A as AdapterUsage, g as ContractDescriptor, h as ContractSource, i as ControllerRef, N as NumberCheck, j as ScopeConfig, k as StringCheck, T as TypeRef, l as ValidationOption, r as resolveAdapter } from './index-Dyf4ttwU.js';
3
3
  import { ClassDeclaration, SourceFile, Project } from 'ts-morph';
4
4
 
5
5
  declare function defineConfig(c: UserConfig): UserConfig;
@@ -382,6 +382,6 @@ interface FastDiscoveryOptions {
382
382
  }
383
383
  declare function discoverContractsFast(opts: FastDiscoveryOptions): Promise<RouteDescriptor[]>;
384
384
 
385
- declare const VERSION = "0.17.2";
385
+ declare const VERSION = "0.19.0";
386
386
 
387
387
  export { type ChainModuleRendererOptions, CodegenError, type CodegenManifest, ConfigError, DriftGuardError, type EntryPoint, type FastDiscoveryOptions, type JsonSchema, type MocksEmitOptions, type OpenApiDocument, type OpenApiEmitOptions, type OpenApiInfo, RenderContext, RenderedModule, ResolvedConfig, RouteDescriptor, SchemaModule, SchemaNode, type TsTypeContext, UserConfig, VERSION, ValidationAdapter, type WatchOptions, type Watcher, acquireLock, buildMocksFile, buildOpenApiSpec, createChainModuleRenderer, defineConfig, discoverContractsFast, emitApi, emitForms, emitMocks, emitOpenApi, emitRoutes, extractSchemaFromDto, generate, loadConfig, renderTsType, resolveConfig, schemaModuleToJsonSchema, schemaNodeToJsonSchema, toObjectKey, typeNameFor, watch };
package/dist/index.js CHANGED
@@ -3480,10 +3480,46 @@ function resolveReturnedClass(factoryDecl) {
3480
3480
  }
3481
3481
  return void 0;
3482
3482
  }
3483
+ function factoryCalleeName(call) {
3484
+ const callee = unwrapExpression(call.getExpression());
3485
+ if (Node5.isIdentifier(callee)) return callee;
3486
+ if (Node5.isPropertyAccessExpression(callee)) {
3487
+ const name = callee.getNameNode();
3488
+ return Node5.isIdentifier(name) ? name : void 0;
3489
+ }
3490
+ return void 0;
3491
+ }
3483
3492
  function resolveFactoryDeclaration(call) {
3484
- const callee = call.getExpression();
3485
- if (!Node5.isIdentifier(callee)) return void 0;
3486
- return callee.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => Node5.isFunctionDeclaration(n));
3493
+ const name = factoryCalleeName(call);
3494
+ return name ? resolveFactoryFromName(name, /* @__PURE__ */ new Set()) : void 0;
3495
+ }
3496
+ function resolveFactoryFromName(name, seen) {
3497
+ if (seen.has(name)) return void 0;
3498
+ seen.add(name);
3499
+ const decls = name.getDefinitions().map((d) => d.getDeclarationNode()).filter((n) => n !== void 0);
3500
+ for (const decl of decls) {
3501
+ if (Node5.isFunctionDeclaration(decl) || Node5.isMethodDeclaration(decl)) return decl;
3502
+ if (Node5.isPropertyAssignment(decl)) {
3503
+ const init = decl.getInitializer();
3504
+ const inner = init ? unwrapExpression(init) : void 0;
3505
+ if (inner && Node5.isIdentifier(inner)) {
3506
+ const resolved = resolveFactoryFromName(inner, seen);
3507
+ if (resolved) return resolved;
3508
+ }
3509
+ continue;
3510
+ }
3511
+ if (Node5.isShorthandPropertyAssignment(decl)) {
3512
+ const nameNode = decl.getNameNode();
3513
+ const resolved = Node5.isIdentifier(nameNode) ? resolveFactoryFromName(nameNode, seen) : void 0;
3514
+ if (resolved) return resolved;
3515
+ }
3516
+ }
3517
+ return void 0;
3518
+ }
3519
+ function warnUnresolvedFactory(cls, calleeText, reason) {
3520
+ console.warn(
3521
+ `[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.`
3522
+ );
3487
3523
  }
3488
3524
  function resolveFactoryStaticClass(node) {
3489
3525
  if (!Node5.isPropertyAccessExpression(node)) return void 0;
@@ -3505,30 +3541,78 @@ function resolveFactoryStaticClass(node) {
3505
3541
  function resolveInheritedMethods(cls) {
3506
3542
  const expr = resolveHeritageCall(cls.getExtends()?.getExpression());
3507
3543
  if (!expr) return void 0;
3508
- const callee = expr.getExpression();
3509
- if (!Node5.isIdentifier(callee)) return void 0;
3544
+ const isController = cls.getDecorator("Controller") !== void 0;
3545
+ const calleeText = expr.getExpression().getText();
3510
3546
  const factoryDecl = resolveFactoryDeclaration(expr);
3511
- if (!factoryDecl) return void 0;
3547
+ if (!factoryDecl) {
3548
+ if (isController) {
3549
+ warnUnresolvedFactory(
3550
+ cls,
3551
+ calleeText,
3552
+ factoryCalleeName(expr) ? "its callee does not resolve to a function or method declaration" : "its callee is not a name that can be resolved statically"
3553
+ );
3554
+ }
3555
+ return void 0;
3556
+ }
3512
3557
  const returnedClass = resolveReturnedClass(factoryDecl);
3513
- if (!returnedClass) return void 0;
3558
+ if (!returnedClass) {
3559
+ if (isController) {
3560
+ warnUnresolvedFactory(cls, calleeText, "that factory does not return a class declaration");
3561
+ }
3562
+ return void 0;
3563
+ }
3514
3564
  const classArgs = [];
3565
+ const namedClassArgs = {};
3515
3566
  for (const arg of expr.getArguments()) {
3516
- if (!Node5.isIdentifier(arg)) continue;
3517
- const decl = arg.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => Node5.isClassDeclaration(n));
3518
- if (decl) {
3519
- classArgs.push({
3520
- name: decl.getName() ?? arg.getText(),
3521
- filePath: decl.getSourceFile().getFilePath()
3522
- });
3567
+ const positional = resolveClassReference(arg);
3568
+ if (positional) {
3569
+ classArgs.push(positional);
3570
+ continue;
3571
+ }
3572
+ if (!Node5.isObjectLiteralExpression(arg)) continue;
3573
+ for (const prop of arg.getProperties()) {
3574
+ const named = resolvePropertyClassReference(prop);
3575
+ if (!named) continue;
3576
+ namedClassArgs[named.key] ??= named.ref;
3523
3577
  }
3524
3578
  }
3525
3579
  return {
3526
3580
  methods: returnedClass.getMethods(),
3527
- factoryName: callee.getText(),
3581
+ // The DECLARATION's name, not the call-site text: consumers look the factory
3582
+ // back up by name inside `factoryFilePath`, which a qualified
3583
+ // `tables.createTableController` would never match. For a bare identifier
3584
+ // the two coincide (bar an import alias, where the declaration name is the
3585
+ // one that resolves anyway).
3586
+ factoryName: factoryDecl.getName() ?? calleeText,
3528
3587
  factoryFilePath: factoryDecl.getSourceFile().getFilePath(),
3529
- classArgs
3588
+ classArgs,
3589
+ namedClassArgs
3530
3590
  };
3531
3591
  }
3592
+ function resolveClassReference(node) {
3593
+ const expr = unwrapExpression(node);
3594
+ if (!Node5.isIdentifier(expr)) return void 0;
3595
+ const decl = expr.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => n !== void 0 && Node5.isClassDeclaration(n));
3596
+ if (!decl) return void 0;
3597
+ return {
3598
+ name: decl.getName() ?? expr.getText(),
3599
+ filePath: decl.getSourceFile().getFilePath()
3600
+ };
3601
+ }
3602
+ function resolvePropertyClassReference(prop) {
3603
+ if (Node5.isShorthandPropertyAssignment(prop)) {
3604
+ const ref2 = resolveClassReference(prop.getNameNode());
3605
+ return ref2 ? { key: prop.getName(), ref: ref2 } : void 0;
3606
+ }
3607
+ if (!Node5.isPropertyAssignment(prop)) return void 0;
3608
+ const init = prop.getInitializer();
3609
+ if (!init) return void 0;
3610
+ const ref = resolveClassReference(init);
3611
+ if (!ref) return void 0;
3612
+ const nameNode = prop.getNameNode();
3613
+ const key = Node5.isStringLiteral(nameNode) ? nameNode.getLiteralValue() : prop.getName();
3614
+ return { key, ref };
3615
+ }
3532
3616
  var mixinTypeProject;
3533
3617
  function getMixinTypeProject() {
3534
3618
  mixinTypeProject ??= new Project3({
@@ -3558,7 +3642,7 @@ function resolveInstantiatedReturnType(cls, methodName) {
3558
3642
 
3559
3643
  // src/discovery/filter-for.ts
3560
3644
  function resolveMixinEntityClass(mixin, project) {
3561
- const entityArg = mixin?.classArgs[0];
3645
+ const entityArg = mixin?.namedClassArgs?.entity ?? mixin?.classArgs[0];
3562
3646
  if (!entityArg) return void 0;
3563
3647
  const file = project.getSourceFile(entityArg.filePath) ?? project.addSourceFileAtPathIfExists(entityArg.filePath);
3564
3648
  return file?.getClass(entityArg.name);
@@ -4810,7 +4894,8 @@ function extractFromSourceFile(sourceFile, project) {
4810
4894
  const mixinBinding = inherited ? {
4811
4895
  factoryName: inherited.factoryName,
4812
4896
  factoryFilePath: inherited.factoryFilePath,
4813
- classArgs: inherited.classArgs
4897
+ classArgs: inherited.classArgs,
4898
+ namedClassArgs: inherited.namedClassArgs
4814
4899
  } : void 0;
4815
4900
  const ownMethods = cls.getMethods();
4816
4901
  const ownNames = new Set(ownMethods.map((m) => m.getName()));
@@ -5125,7 +5210,7 @@ function createChainModuleRenderer(opts) {
5125
5210
  }
5126
5211
 
5127
5212
  // src/index.ts
5128
- var VERSION = "0.17.2";
5213
+ var VERSION = "0.19.0";
5129
5214
  export {
5130
5215
  CodegenError,
5131
5216
  ConfigError,