@dudousxd/nestjs-codegen 0.24.0 → 0.25.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,39 @@
1
1
  # @dudousxd/nestjs-codegen
2
2
 
3
+ ## 0.25.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 0379b5a: Add NestJS 12 to the supported peer range.
8
+
9
+ `@dudousxd/nestjs-client`'s `@nestjs/common` peer read `^10.0.0 || ^11.0.0` and now also admits
10
+ `^12.0.0`. `@dudousxd/nestjs-codegen`'s peer already read `>=9.0.0`, so it admitted 12 unchanged;
11
+ its dev dependencies move onto the 12.x line so the suite runs against NestJS 12.
12
+
13
+ No source change was needed. NestJS 12 ships its core packages as pure ESM and these packages are
14
+ already `"type": "module"`; neither implements a `PipeTransform`, so the `ArgumentMetadata` generic
15
+ added in v12 does not reach this code, and neither subclasses `ConsoleLogger`.
16
+
17
+ The AST discovery path was exercised end-to-end against a real NestJS 12 application: the generated
18
+ client is byte-identical to the one produced before the bump, so v12's decorator and metadata
19
+ changes leave route and field discovery intact.
20
+
21
+ ## 0.25.0
22
+
23
+ ### Minor Changes
24
+
25
+ - 595c4b1: Follow a factory-produced controller's own heritage chain, so a factory that wraps a factory contributes every level's routes.
26
+
27
+ `class C extends createTableController(...)` was resolved one level deep: discovery found the class the factory returns and read **its own methods only**. A factory whose returned class itself extends something — another factory call, or an ordinary base class — lost everything the inner level declared. The controller was not skipped, which would at least be visible; it was generated with a subset of its routes and no warning anywhere, while Nest served all of them.
28
+
29
+ That gap made the natural way to give SOME controllers an extra route unusable. Wrapping the shared factory in a second one and declaring the extra route as an ordinary `@Post('export')` method is the shape that keeps every route statically visible — the conditionality becomes which factory a controller extends — but the wrapper's own base routes disappeared from the client, so the pattern looked broken and the alternative (declaring the handler undecorated and mounting it imperatively, `Post('export')(proto, 'export', descriptor)`) is invisible to a static scan by construction.
30
+
31
+ Discovery now walks the returned class's chain to any depth, the way Nest walks the prototype chain, resolving each base through the same factory resolution or as a plain class declaration. Nearest declaration wins, so a wrapper overriding an inner route still contributes one route rather than two — matching how a derived controller's own override was already resolved against its base.
32
+
33
+ Also fixes the types of an inherited route. A route's parameter and return annotations were resolved against the CONTROLLER's file, but they are written in the file that declares the handler — the factory's. A `@Body() body: ExportRequestDto` on a factory-declared method resolved against a file that never imports `ExportRequestDto` and silently degraded to `unknown`, so the route reached the client accepting anything. They now resolve in the declaring file, which is what the filter pass already did. For a route declared on the controller itself the two files are the same and nothing changes.
34
+
35
+ Both are additive: routes and types that were missing now appear. Regenerate and expect new entries for any controller extending a wrapping factory, and real body/query/response types where an inherited route previously had `unknown`.
36
+
3
37
  ## 0.24.0
4
38
 
5
39
  ### Minor Changes
package/dist/cli/main.cjs CHANGED
@@ -1653,6 +1653,32 @@ function resolveFactoryStaticClass(node) {
1653
1653
  if (!import_ts_morph5.Node.isIdentifier(inner)) return void 0;
1654
1654
  return inner.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => n !== void 0 && import_ts_morph5.Node.isClassDeclaration(n));
1655
1655
  }
1656
+ function resolveBaseClass(cls) {
1657
+ const heritage = cls.getExtends()?.getExpression();
1658
+ if (!heritage) return void 0;
1659
+ const call = resolveHeritageCall(heritage);
1660
+ if (call) {
1661
+ const factoryDecl = resolveFactoryDeclaration(call);
1662
+ return factoryDecl ? resolveReturnedClass(factoryDecl) : void 0;
1663
+ }
1664
+ const expr = unwrapExpression(heritage);
1665
+ if (!import_ts_morph5.Node.isIdentifier(expr)) return void 0;
1666
+ return expr.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => n !== void 0 && import_ts_morph5.Node.isClassDeclaration(n));
1667
+ }
1668
+ function collectMethodsThroughChain(returnedClass) {
1669
+ const byName = /* @__PURE__ */ new Map();
1670
+ const seen = /* @__PURE__ */ new Set();
1671
+ let current = returnedClass;
1672
+ while (current && !seen.has(current)) {
1673
+ seen.add(current);
1674
+ for (const method of current.getMethods()) {
1675
+ const name = method.getName();
1676
+ if (!byName.has(name)) byName.set(name, method);
1677
+ }
1678
+ current = resolveBaseClass(current);
1679
+ }
1680
+ return [...byName.values()];
1681
+ }
1656
1682
  function resolveInheritedMethods(cls) {
1657
1683
  const expr = resolveHeritageCall(cls.getExtends()?.getExpression());
1658
1684
  if (!expr) return void 0;
@@ -1692,7 +1718,7 @@ function resolveInheritedMethods(cls) {
1692
1718
  }
1693
1719
  }
1694
1720
  return {
1695
- methods: returnedClass.getMethods(),
1721
+ methods: collectMethodsThroughChain(returnedClass),
1696
1722
  // The DECLARATION's name, not the call-site text: consumers look the factory
1697
1723
  // back up by name inside `factoryFilePath`, which a qualified
1698
1724
  // `tables.createTableController` would never match. For a bare identifier
@@ -3066,7 +3092,7 @@ function extractDtoRoute(args) {
3066
3092
  const methodName = method.getName();
3067
3093
  const classAs = readAsDecorator(cls, `class ${className}`);
3068
3094
  const methodAs = readAsDecorator(method, `${className}.${methodName}`);
3069
- const dtoContract = extractDtoContract(method, sourceFile, project, mixin, cls);
3095
+ const dtoContract = extractDtoContract(method, method.getSourceFile(), project, mixin, cls);
3070
3096
  const mixinResponse = mixin ? resolveInstantiatedReturnType(cls, methodName) : void 0;
3071
3097
  return buildRoute({
3072
3098
  className,
@@ -5273,7 +5299,7 @@ async function watch(config, onChange, options = {}) {
5273
5299
  }
5274
5300
 
5275
5301
  // src/index.ts
5276
- var VERSION = "0.24.0";
5302
+ var VERSION = "0.25.1";
5277
5303
 
5278
5304
  // src/cli/codegen.ts
5279
5305
  async function runCodegen(opts = {}) {