@dudousxd/nestjs-codegen 0.17.2 → 0.18.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 +26 -0
- package/dist/cli/main.cjs +41 -11
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +41 -11
- package/dist/cli/main.js.map +1 -1
- package/dist/extension/index.d.cts +1 -1
- package/dist/extension/index.d.ts +1 -1
- package/dist/{index-DCF9QSPY.d.cts → index-Dyf4ttwU.d.cts} +24 -1
- package/dist/{index-DCF9QSPY.d.ts → index-Dyf4ttwU.d.ts} +24 -1
- package/dist/index.cjs +41 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +41 -11
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +41 -11
- package/dist/nest/index.cjs.map +1 -1
- package/dist/nest/index.d.cts +1 -1
- package/dist/nest/index.d.ts +1 -1
- package/dist/nest/index.js +41 -11
- package/dist/nest/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @dudousxd/nestjs-codegen
|
|
2
2
|
|
|
3
|
+
## 0.18.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 553e503: Resolve the entity of a controller factory called with a single options object.
|
|
8
|
+
|
|
9
|
+
`class X extends createTableController({ entity: Util, dto: UtilDTO })` emitted
|
|
10
|
+
every one of its routes with `body: never` and `filterFields: never` — the typed
|
|
11
|
+
filter builder gone from the client, with `tsc` and codegen both green. Only the
|
|
12
|
+
positional form (`createTableController(Util, { dto })`) worked: discovery
|
|
13
|
+
collected call-site classes by scanning for identifier ARGUMENTS, and an object
|
|
14
|
+
literal is not one, so the entity behind the factory's generated
|
|
15
|
+
`@Filterable({ entity })` was unresolvable. Measured downstream at 22 tables
|
|
16
|
+
losing their filter builder at once.
|
|
17
|
+
|
|
18
|
+
Class-valued properties of an options-object argument are now collected too,
|
|
19
|
+
keyed by property name, and the entity resolver prefers a named `entity` over the
|
|
20
|
+
first positional argument. Both call forms work, so a codebase can migrate table
|
|
21
|
+
by table.
|
|
22
|
+
|
|
23
|
+
`MixinBinding` gains `namedClassArgs: Record<string, { name, filePath }>`
|
|
24
|
+
alongside the unchanged positional `classArgs`. The key is what identifies an
|
|
25
|
+
argument's role once there is no positional order to read it from, and consumers
|
|
26
|
+
want different properties: this package resolves `entity`, while
|
|
27
|
+
`@dudousxd/nestjs-filter-codegen` reads `filter` off the same binding.
|
|
28
|
+
|
|
3
29
|
## 0.17.2
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
package/dist/cli/main.cjs
CHANGED
|
@@ -3523,23 +3523,52 @@ function resolveInheritedMethods(cls) {
|
|
|
3523
3523
|
const returnedClass = resolveReturnedClass(factoryDecl);
|
|
3524
3524
|
if (!returnedClass) return void 0;
|
|
3525
3525
|
const classArgs = [];
|
|
3526
|
+
const namedClassArgs = {};
|
|
3526
3527
|
for (const arg of expr.getArguments()) {
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3528
|
+
const positional = resolveClassReference(arg);
|
|
3529
|
+
if (positional) {
|
|
3530
|
+
classArgs.push(positional);
|
|
3531
|
+
continue;
|
|
3532
|
+
}
|
|
3533
|
+
if (!import_ts_morph6.Node.isObjectLiteralExpression(arg)) continue;
|
|
3534
|
+
for (const prop of arg.getProperties()) {
|
|
3535
|
+
const named = resolvePropertyClassReference(prop);
|
|
3536
|
+
if (!named) continue;
|
|
3537
|
+
namedClassArgs[named.key] ??= named.ref;
|
|
3534
3538
|
}
|
|
3535
3539
|
}
|
|
3536
3540
|
return {
|
|
3537
3541
|
methods: returnedClass.getMethods(),
|
|
3538
3542
|
factoryName: callee.getText(),
|
|
3539
3543
|
factoryFilePath: factoryDecl.getSourceFile().getFilePath(),
|
|
3540
|
-
classArgs
|
|
3544
|
+
classArgs,
|
|
3545
|
+
namedClassArgs
|
|
3541
3546
|
};
|
|
3542
3547
|
}
|
|
3548
|
+
function resolveClassReference(node) {
|
|
3549
|
+
const expr = unwrapExpression(node);
|
|
3550
|
+
if (!import_ts_morph6.Node.isIdentifier(expr)) return void 0;
|
|
3551
|
+
const decl = expr.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => n !== void 0 && import_ts_morph6.Node.isClassDeclaration(n));
|
|
3552
|
+
if (!decl) return void 0;
|
|
3553
|
+
return {
|
|
3554
|
+
name: decl.getName() ?? expr.getText(),
|
|
3555
|
+
filePath: decl.getSourceFile().getFilePath()
|
|
3556
|
+
};
|
|
3557
|
+
}
|
|
3558
|
+
function resolvePropertyClassReference(prop) {
|
|
3559
|
+
if (import_ts_morph6.Node.isShorthandPropertyAssignment(prop)) {
|
|
3560
|
+
const ref2 = resolveClassReference(prop.getNameNode());
|
|
3561
|
+
return ref2 ? { key: prop.getName(), ref: ref2 } : void 0;
|
|
3562
|
+
}
|
|
3563
|
+
if (!import_ts_morph6.Node.isPropertyAssignment(prop)) return void 0;
|
|
3564
|
+
const init = prop.getInitializer();
|
|
3565
|
+
if (!init) return void 0;
|
|
3566
|
+
const ref = resolveClassReference(init);
|
|
3567
|
+
if (!ref) return void 0;
|
|
3568
|
+
const nameNode = prop.getNameNode();
|
|
3569
|
+
const key = import_ts_morph6.Node.isStringLiteral(nameNode) ? nameNode.getLiteralValue() : prop.getName();
|
|
3570
|
+
return { key, ref };
|
|
3571
|
+
}
|
|
3543
3572
|
var mixinTypeProject;
|
|
3544
3573
|
function getMixinTypeProject() {
|
|
3545
3574
|
mixinTypeProject ??= new import_ts_morph6.Project({
|
|
@@ -3569,7 +3598,7 @@ function resolveInstantiatedReturnType(cls, methodName) {
|
|
|
3569
3598
|
|
|
3570
3599
|
// src/discovery/filter-for.ts
|
|
3571
3600
|
function resolveMixinEntityClass(mixin, project) {
|
|
3572
|
-
const entityArg = mixin?.classArgs[0];
|
|
3601
|
+
const entityArg = mixin?.namedClassArgs?.entity ?? mixin?.classArgs[0];
|
|
3573
3602
|
if (!entityArg) return void 0;
|
|
3574
3603
|
const file = project.getSourceFile(entityArg.filePath) ?? project.addSourceFileAtPathIfExists(entityArg.filePath);
|
|
3575
3604
|
return file?.getClass(entityArg.name);
|
|
@@ -4821,7 +4850,8 @@ function extractFromSourceFile(sourceFile, project) {
|
|
|
4821
4850
|
const mixinBinding = inherited ? {
|
|
4822
4851
|
factoryName: inherited.factoryName,
|
|
4823
4852
|
factoryFilePath: inherited.factoryFilePath,
|
|
4824
|
-
classArgs: inherited.classArgs
|
|
4853
|
+
classArgs: inherited.classArgs,
|
|
4854
|
+
namedClassArgs: inherited.namedClassArgs
|
|
4825
4855
|
} : void 0;
|
|
4826
4856
|
const ownMethods = cls.getMethods();
|
|
4827
4857
|
const ownNames = new Set(ownMethods.map((m) => m.getName()));
|
|
@@ -5053,7 +5083,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
5053
5083
|
}
|
|
5054
5084
|
|
|
5055
5085
|
// src/index.ts
|
|
5056
|
-
var VERSION = "0.
|
|
5086
|
+
var VERSION = "0.18.0";
|
|
5057
5087
|
|
|
5058
5088
|
// src/cli/codegen.ts
|
|
5059
5089
|
async function runCodegen(opts = {}) {
|