@dudousxd/nestjs-codegen 0.24.0 → 0.25.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/CHANGELOG.md +16 -0
- package/dist/cli/main.cjs +29 -3
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +29 -3
- package/dist/cli/main.js.map +1 -1
- package/dist/index.cjs +29 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +29 -3
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +29 -3
- package/dist/nest/index.cjs.map +1 -1
- package/dist/nest/index.js +29 -3
- package/dist/nest/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @dudousxd/nestjs-codegen
|
|
2
2
|
|
|
3
|
+
## 0.25.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 595c4b1: Follow a factory-produced controller's own heritage chain, so a factory that wraps a factory contributes every level's routes.
|
|
8
|
+
|
|
9
|
+
`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.
|
|
10
|
+
|
|
11
|
+
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.
|
|
12
|
+
|
|
13
|
+
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.
|
|
14
|
+
|
|
15
|
+
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.
|
|
16
|
+
|
|
17
|
+
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`.
|
|
18
|
+
|
|
3
19
|
## 0.24.0
|
|
4
20
|
|
|
5
21
|
### 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
|
|
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,
|
|
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.
|
|
5302
|
+
var VERSION = "0.25.0";
|
|
5277
5303
|
|
|
5278
5304
|
// src/cli/codegen.ts
|
|
5279
5305
|
async function runCodegen(opts = {}) {
|