@dudousxd/nestjs-codegen 0.19.0 → 0.20.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 +52 -0
- package/dist/cli/main.cjs +91 -30
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +91 -30
- package/dist/cli/main.js.map +1 -1
- package/dist/index.cjs +91 -30
- 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 +91 -30
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +91 -30
- package/dist/nest/index.cjs.map +1 -1
- package/dist/nest/index.js +91 -30
- package/dist/nest/index.js.map +1 -1
- package/package.json +1 -1
package/dist/nest/index.js
CHANGED
|
@@ -3446,10 +3446,15 @@ function resolveInstantiatedReturnType(cls, methodName) {
|
|
|
3446
3446
|
|
|
3447
3447
|
// src/discovery/filter-for.ts
|
|
3448
3448
|
function resolveMixinEntityClass(mixin, project) {
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
return
|
|
3449
|
+
return resolveClassRef(mixin?.namedClassArgs?.entity ?? mixin?.classArgs[0], project);
|
|
3450
|
+
}
|
|
3451
|
+
function resolveMixinFilterClass(mixin, project) {
|
|
3452
|
+
return resolveClassRef(mixin?.namedClassArgs?.filter, project);
|
|
3453
|
+
}
|
|
3454
|
+
function resolveClassRef(ref, project) {
|
|
3455
|
+
if (!ref) return void 0;
|
|
3456
|
+
const file = project.getSourceFile(ref.filePath) ?? project.addSourceFileAtPathIfExists(ref.filePath);
|
|
3457
|
+
return file?.getClass(ref.name);
|
|
3453
3458
|
}
|
|
3454
3459
|
function classifyFilterForHint(typeInit) {
|
|
3455
3460
|
if (Node6.isStringLiteral(typeInit)) {
|
|
@@ -3549,31 +3554,55 @@ function extractApplyFilterInfo(method, sourceFile, project, mixin) {
|
|
|
3549
3554
|
}
|
|
3550
3555
|
const filterClassName = filterClassArg.getText();
|
|
3551
3556
|
const resolved = factoryStaticClass ? void 0 : findType(filterClassName, declFile, project);
|
|
3552
|
-
const
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
byName.set(key, toFilterFieldType(key, classified));
|
|
3563
|
-
}
|
|
3564
|
-
fieldTypes = [...byName.values()];
|
|
3565
|
-
}
|
|
3566
|
-
if (fieldTypes.length === 0) return null;
|
|
3567
|
-
const fieldNames = fieldTypes.map((f) => f.name);
|
|
3557
|
+
const declaredClass = factoryStaticClass ?? (resolved?.kind === "class" ? resolved.decl : resolveLocalClassDeclaration(filterClassArg));
|
|
3558
|
+
const ownRoute = !mixin || declFile.getFilePath() !== mixin.factoryFilePath;
|
|
3559
|
+
const namedByRoute = ownRoute && Node6.isIdentifier(filterClassArg) ? declaredClass : void 0;
|
|
3560
|
+
for (const candidate of orderFilterCandidates({
|
|
3561
|
+
namedByRoute,
|
|
3562
|
+
supplied: resolveMixinFilterClass(mixin, project),
|
|
3563
|
+
declared: declaredClass
|
|
3564
|
+
})) {
|
|
3565
|
+
const fieldTypes = collectFilterFields(candidate, project, mixinEntity);
|
|
3566
|
+
if (fieldTypes.length === 0) continue;
|
|
3568
3567
|
return {
|
|
3569
|
-
fieldNames,
|
|
3568
|
+
fieldNames: fieldTypes.map((f) => f.name),
|
|
3570
3569
|
fieldTypes,
|
|
3571
3570
|
source
|
|
3572
3571
|
};
|
|
3573
3572
|
}
|
|
3573
|
+
if (declaredClass) return null;
|
|
3574
3574
|
}
|
|
3575
3575
|
return null;
|
|
3576
3576
|
}
|
|
3577
|
+
function orderFilterCandidates(sources) {
|
|
3578
|
+
const ordered = [];
|
|
3579
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3580
|
+
const push = (decl, preferDeclaredEntity) => {
|
|
3581
|
+
if (!decl || seen.has(decl)) return;
|
|
3582
|
+
seen.add(decl);
|
|
3583
|
+
ordered.push({ decl, preferDeclaredEntity });
|
|
3584
|
+
};
|
|
3585
|
+
push(sources.namedByRoute, true);
|
|
3586
|
+
push(sources.supplied, true);
|
|
3587
|
+
push(sources.declared, false);
|
|
3588
|
+
return ordered;
|
|
3589
|
+
}
|
|
3590
|
+
function collectFilterFields(candidate, project, mixinEntity) {
|
|
3591
|
+
const { decl, preferDeclaredEntity } = candidate;
|
|
3592
|
+
let fieldTypes = extractClassPropertyTypes(decl, project);
|
|
3593
|
+
if (fieldTypes.length === 0) {
|
|
3594
|
+
fieldTypes = extractFilterableEntityFields(decl, project, mixinEntity, preferDeclaredEntity);
|
|
3595
|
+
}
|
|
3596
|
+
const filterForHints = extractFilterForHints(decl, project);
|
|
3597
|
+
if (filterForHints.size > 0) {
|
|
3598
|
+
const byName = new Map(fieldTypes.map((f) => [f.name, f]));
|
|
3599
|
+
for (const [key, classified] of filterForHints) {
|
|
3600
|
+
byName.set(key, toFilterFieldType(key, classified));
|
|
3601
|
+
}
|
|
3602
|
+
fieldTypes = [...byName.values()];
|
|
3603
|
+
}
|
|
3604
|
+
return fieldTypes;
|
|
3605
|
+
}
|
|
3577
3606
|
var RELATION_DECORATORS = /* @__PURE__ */ new Set(["OneToMany", "ManyToOne", "ManyToMany", "OneToOne"]);
|
|
3578
3607
|
function collectEntityFields(entityDecl, sourceFile, project, prefix, visited) {
|
|
3579
3608
|
const entityName = entityDecl.getName() ?? "";
|
|
@@ -3652,21 +3681,53 @@ function resolveDeclaredEntity(optionsArg, filterClass, project) {
|
|
|
3652
3681
|
if (!resolved || resolved.kind !== "class") return void 0;
|
|
3653
3682
|
return resolved.decl;
|
|
3654
3683
|
}
|
|
3655
|
-
function
|
|
3684
|
+
function readFieldNameList(optionsArg, key) {
|
|
3685
|
+
if (!Node6.isObjectLiteralExpression(optionsArg)) return void 0;
|
|
3686
|
+
const prop = optionsArg.getProperty(key);
|
|
3687
|
+
if (!prop || !Node6.isPropertyAssignment(prop)) return void 0;
|
|
3688
|
+
const init = prop.getInitializer();
|
|
3689
|
+
if (!init || !Node6.isArrayLiteralExpression(init)) return void 0;
|
|
3690
|
+
const names = /* @__PURE__ */ new Set();
|
|
3691
|
+
for (const el of init.getElements()) {
|
|
3692
|
+
if (Node6.isStringLiteral(el)) {
|
|
3693
|
+
names.add(el.getLiteralValue());
|
|
3694
|
+
continue;
|
|
3695
|
+
}
|
|
3696
|
+
if (Node6.isObjectLiteralExpression(el)) {
|
|
3697
|
+
const fieldProp = el.getProperty("field");
|
|
3698
|
+
if (fieldProp && Node6.isPropertyAssignment(fieldProp)) {
|
|
3699
|
+
const fieldInit = fieldProp.getInitializer();
|
|
3700
|
+
if (fieldInit && Node6.isStringLiteral(fieldInit)) {
|
|
3701
|
+
names.add(fieldInit.getLiteralValue());
|
|
3702
|
+
continue;
|
|
3703
|
+
}
|
|
3704
|
+
}
|
|
3705
|
+
}
|
|
3706
|
+
return void 0;
|
|
3707
|
+
}
|
|
3708
|
+
return names;
|
|
3709
|
+
}
|
|
3710
|
+
function narrowToDeclaredFields(fields, optionsArg) {
|
|
3711
|
+
const allowed = readFieldNameList(optionsArg, "allowed");
|
|
3712
|
+
const blocked = readFieldNameList(optionsArg, "blocked");
|
|
3713
|
+
if (!allowed && !blocked) return fields;
|
|
3714
|
+
return fields.filter(
|
|
3715
|
+
(f) => (!allowed || allowed.has(f.name)) && !(blocked?.has(f.name) ?? false)
|
|
3716
|
+
);
|
|
3717
|
+
}
|
|
3718
|
+
function extractFilterableEntityFields(filterClass, project, entityOverride, preferDeclaredEntity = false) {
|
|
3656
3719
|
const filterableDecorator = filterClass.getDecorators().find((d) => d.getName() === "Filterable");
|
|
3657
3720
|
if (!filterableDecorator) return [];
|
|
3658
3721
|
const args = filterableDecorator.getArguments();
|
|
3659
3722
|
if (args.length === 0) return [];
|
|
3660
3723
|
const optionsArg = args[0];
|
|
3661
3724
|
if (!Node6.isObjectLiteralExpression(optionsArg)) return [];
|
|
3662
|
-
const
|
|
3725
|
+
const declaredEntity = resolveDeclaredEntity(optionsArg, filterClass, project);
|
|
3726
|
+
const entityDecl = preferDeclaredEntity ? declaredEntity ?? entityOverride : entityOverride ?? declaredEntity;
|
|
3663
3727
|
if (!entityDecl) return [];
|
|
3664
|
-
const fields =
|
|
3665
|
-
entityDecl,
|
|
3666
|
-
|
|
3667
|
-
project,
|
|
3668
|
-
"",
|
|
3669
|
-
/* @__PURE__ */ new Set()
|
|
3728
|
+
const fields = narrowToDeclaredFields(
|
|
3729
|
+
collectEntityFields(entityDecl, entityDecl.getSourceFile(), project, "", /* @__PURE__ */ new Set()),
|
|
3730
|
+
optionsArg
|
|
3670
3731
|
);
|
|
3671
3732
|
const relationsDecorator = filterClass.getDecorators().find((d) => d.getName() === "Relations");
|
|
3672
3733
|
if (relationsDecorator) {
|
|
@@ -4912,7 +4973,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
4912
4973
|
}
|
|
4913
4974
|
|
|
4914
4975
|
// src/index.ts
|
|
4915
|
-
var VERSION = "0.
|
|
4976
|
+
var VERSION = "0.20.0";
|
|
4916
4977
|
|
|
4917
4978
|
// src/generate-manifest.ts
|
|
4918
4979
|
var MANIFEST_FILE = ".codegen-manifest.json";
|