@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
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { m as ApiClientLayer, n as ApiHeaderContribution, o as ApiModuleDeps, C as CodegenExtension, p as EmittedFile, E as ExtensionContext, L as LeafModel, q as RequestModel, s as RequestShape, t as defineExtension, u as requestShape } from '../index-
|
|
1
|
+
export { m as ApiClientLayer, n as ApiHeaderContribution, o as ApiModuleDeps, C as CodegenExtension, p as EmittedFile, E as ExtensionContext, L as LeafModel, q as RequestModel, s as RequestShape, t as defineExtension, u as requestShape } from '../index-Dyf4ttwU.cjs';
|
|
2
2
|
import 'ts-morph';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { m as ApiClientLayer, n as ApiHeaderContribution, o as ApiModuleDeps, C as CodegenExtension, p as EmittedFile, E as ExtensionContext, L as LeafModel, q as RequestModel, s as RequestShape, t as defineExtension, u as requestShape } from '../index-
|
|
1
|
+
export { m as ApiClientLayer, n as ApiHeaderContribution, o as ApiModuleDeps, C as CodegenExtension, p as EmittedFile, E as ExtensionContext, L as LeafModel, q as RequestModel, s as RequestShape, t as defineExtension, u as requestShape } from '../index-Dyf4ttwU.js';
|
|
2
2
|
import 'ts-morph';
|
|
@@ -550,11 +550,34 @@ interface ContractDescriptor {
|
|
|
550
550
|
interface MixinBinding {
|
|
551
551
|
factoryName: string;
|
|
552
552
|
factoryFilePath: string;
|
|
553
|
-
/**
|
|
553
|
+
/**
|
|
554
|
+
* POSITIONAL call-site arguments that resolve to a class declaration, in
|
|
555
|
+
* argument order — `createTableController(Entity, { dto })` yields one entry.
|
|
556
|
+
*/
|
|
554
557
|
classArgs: Array<{
|
|
555
558
|
name: string;
|
|
556
559
|
filePath: string;
|
|
557
560
|
}>;
|
|
561
|
+
/**
|
|
562
|
+
* Class-valued properties of an OPTIONS-OBJECT call-site argument, keyed by
|
|
563
|
+
* property name — `createTableController({ entity: Entity, filter: Filter })`
|
|
564
|
+
* yields `entity` and `filter`.
|
|
565
|
+
*
|
|
566
|
+
* Keyed by name rather than flattened into {@link classArgs} because the key
|
|
567
|
+
* is what identifies the argument's role: with a single object argument there
|
|
568
|
+
* is no positional order to read a role out of, and consumers want different
|
|
569
|
+
* properties. This package resolves `entity` (to derive the filter fields of a
|
|
570
|
+
* factory-generated `@Filterable({ entity })`, whose `entity` names the
|
|
571
|
+
* factory's own parameter and resolves to nothing on its own);
|
|
572
|
+
* `@dudousxd/nestjs-filter-codegen` reads `filter` off this same binding to
|
|
573
|
+
* resolve a call-site-supplied filter class. Empty for a purely positional
|
|
574
|
+
* call; both maps are populated independently, so a factory may be called
|
|
575
|
+
* either way.
|
|
576
|
+
*/
|
|
577
|
+
namedClassArgs: Record<string, {
|
|
578
|
+
name: string;
|
|
579
|
+
filePath: string;
|
|
580
|
+
}>;
|
|
558
581
|
}
|
|
559
582
|
interface ControllerRef {
|
|
560
583
|
className: string;
|
|
@@ -550,11 +550,34 @@ interface ContractDescriptor {
|
|
|
550
550
|
interface MixinBinding {
|
|
551
551
|
factoryName: string;
|
|
552
552
|
factoryFilePath: string;
|
|
553
|
-
/**
|
|
553
|
+
/**
|
|
554
|
+
* POSITIONAL call-site arguments that resolve to a class declaration, in
|
|
555
|
+
* argument order — `createTableController(Entity, { dto })` yields one entry.
|
|
556
|
+
*/
|
|
554
557
|
classArgs: Array<{
|
|
555
558
|
name: string;
|
|
556
559
|
filePath: string;
|
|
557
560
|
}>;
|
|
561
|
+
/**
|
|
562
|
+
* Class-valued properties of an OPTIONS-OBJECT call-site argument, keyed by
|
|
563
|
+
* property name — `createTableController({ entity: Entity, filter: Filter })`
|
|
564
|
+
* yields `entity` and `filter`.
|
|
565
|
+
*
|
|
566
|
+
* Keyed by name rather than flattened into {@link classArgs} because the key
|
|
567
|
+
* is what identifies the argument's role: with a single object argument there
|
|
568
|
+
* is no positional order to read a role out of, and consumers want different
|
|
569
|
+
* properties. This package resolves `entity` (to derive the filter fields of a
|
|
570
|
+
* factory-generated `@Filterable({ entity })`, whose `entity` names the
|
|
571
|
+
* factory's own parameter and resolves to nothing on its own);
|
|
572
|
+
* `@dudousxd/nestjs-filter-codegen` reads `filter` off this same binding to
|
|
573
|
+
* resolve a call-site-supplied filter class. Empty for a purely positional
|
|
574
|
+
* call; both maps are populated independently, so a factory may be called
|
|
575
|
+
* either way.
|
|
576
|
+
*/
|
|
577
|
+
namedClassArgs: Record<string, {
|
|
578
|
+
name: string;
|
|
579
|
+
filePath: string;
|
|
580
|
+
}>;
|
|
558
581
|
}
|
|
559
582
|
interface ControllerRef {
|
|
560
583
|
className: string;
|
package/dist/index.cjs
CHANGED
|
@@ -3558,23 +3558,52 @@ function resolveInheritedMethods(cls) {
|
|
|
3558
3558
|
const returnedClass = resolveReturnedClass(factoryDecl);
|
|
3559
3559
|
if (!returnedClass) return void 0;
|
|
3560
3560
|
const classArgs = [];
|
|
3561
|
+
const namedClassArgs = {};
|
|
3561
3562
|
for (const arg of expr.getArguments()) {
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3563
|
+
const positional = resolveClassReference(arg);
|
|
3564
|
+
if (positional) {
|
|
3565
|
+
classArgs.push(positional);
|
|
3566
|
+
continue;
|
|
3567
|
+
}
|
|
3568
|
+
if (!import_ts_morph6.Node.isObjectLiteralExpression(arg)) continue;
|
|
3569
|
+
for (const prop of arg.getProperties()) {
|
|
3570
|
+
const named = resolvePropertyClassReference(prop);
|
|
3571
|
+
if (!named) continue;
|
|
3572
|
+
namedClassArgs[named.key] ??= named.ref;
|
|
3569
3573
|
}
|
|
3570
3574
|
}
|
|
3571
3575
|
return {
|
|
3572
3576
|
methods: returnedClass.getMethods(),
|
|
3573
3577
|
factoryName: callee.getText(),
|
|
3574
3578
|
factoryFilePath: factoryDecl.getSourceFile().getFilePath(),
|
|
3575
|
-
classArgs
|
|
3579
|
+
classArgs,
|
|
3580
|
+
namedClassArgs
|
|
3576
3581
|
};
|
|
3577
3582
|
}
|
|
3583
|
+
function resolveClassReference(node) {
|
|
3584
|
+
const expr = unwrapExpression(node);
|
|
3585
|
+
if (!import_ts_morph6.Node.isIdentifier(expr)) return void 0;
|
|
3586
|
+
const decl = expr.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => n !== void 0 && import_ts_morph6.Node.isClassDeclaration(n));
|
|
3587
|
+
if (!decl) return void 0;
|
|
3588
|
+
return {
|
|
3589
|
+
name: decl.getName() ?? expr.getText(),
|
|
3590
|
+
filePath: decl.getSourceFile().getFilePath()
|
|
3591
|
+
};
|
|
3592
|
+
}
|
|
3593
|
+
function resolvePropertyClassReference(prop) {
|
|
3594
|
+
if (import_ts_morph6.Node.isShorthandPropertyAssignment(prop)) {
|
|
3595
|
+
const ref2 = resolveClassReference(prop.getNameNode());
|
|
3596
|
+
return ref2 ? { key: prop.getName(), ref: ref2 } : void 0;
|
|
3597
|
+
}
|
|
3598
|
+
if (!import_ts_morph6.Node.isPropertyAssignment(prop)) return void 0;
|
|
3599
|
+
const init = prop.getInitializer();
|
|
3600
|
+
if (!init) return void 0;
|
|
3601
|
+
const ref = resolveClassReference(init);
|
|
3602
|
+
if (!ref) return void 0;
|
|
3603
|
+
const nameNode = prop.getNameNode();
|
|
3604
|
+
const key = import_ts_morph6.Node.isStringLiteral(nameNode) ? nameNode.getLiteralValue() : prop.getName();
|
|
3605
|
+
return { key, ref };
|
|
3606
|
+
}
|
|
3578
3607
|
var mixinTypeProject;
|
|
3579
3608
|
function getMixinTypeProject() {
|
|
3580
3609
|
mixinTypeProject ??= new import_ts_morph6.Project({
|
|
@@ -3604,7 +3633,7 @@ function resolveInstantiatedReturnType(cls, methodName) {
|
|
|
3604
3633
|
|
|
3605
3634
|
// src/discovery/filter-for.ts
|
|
3606
3635
|
function resolveMixinEntityClass(mixin, project) {
|
|
3607
|
-
const entityArg = mixin?.classArgs[0];
|
|
3636
|
+
const entityArg = mixin?.namedClassArgs?.entity ?? mixin?.classArgs[0];
|
|
3608
3637
|
if (!entityArg) return void 0;
|
|
3609
3638
|
const file = project.getSourceFile(entityArg.filePath) ?? project.addSourceFileAtPathIfExists(entityArg.filePath);
|
|
3610
3639
|
return file?.getClass(entityArg.name);
|
|
@@ -4856,7 +4885,8 @@ function extractFromSourceFile(sourceFile, project) {
|
|
|
4856
4885
|
const mixinBinding = inherited ? {
|
|
4857
4886
|
factoryName: inherited.factoryName,
|
|
4858
4887
|
factoryFilePath: inherited.factoryFilePath,
|
|
4859
|
-
classArgs: inherited.classArgs
|
|
4888
|
+
classArgs: inherited.classArgs,
|
|
4889
|
+
namedClassArgs: inherited.namedClassArgs
|
|
4860
4890
|
} : void 0;
|
|
4861
4891
|
const ownMethods = cls.getMethods();
|
|
4862
4892
|
const ownNames = new Set(ownMethods.map((m) => m.getName()));
|
|
@@ -5171,7 +5201,7 @@ function createChainModuleRenderer(opts) {
|
|
|
5171
5201
|
}
|
|
5172
5202
|
|
|
5173
5203
|
// src/index.ts
|
|
5174
|
-
var VERSION = "0.
|
|
5204
|
+
var VERSION = "0.18.0";
|
|
5175
5205
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5176
5206
|
0 && (module.exports = {
|
|
5177
5207
|
CodegenError,
|