@dudousxd/nestjs-codegen 0.19.0 → 0.21.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 +79 -0
- package/dist/cli/main.cjs +95 -34
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +95 -34
- package/dist/cli/main.js.map +1 -1
- package/dist/index.cjs +95 -34
- 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 +95 -34
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +95 -34
- package/dist/nest/index.cjs.map +1 -1
- package/dist/nest/index.js +95 -34
- package/dist/nest/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -382,6 +382,6 @@ interface FastDiscoveryOptions {
|
|
|
382
382
|
}
|
|
383
383
|
declare function discoverContractsFast(opts: FastDiscoveryOptions): Promise<RouteDescriptor[]>;
|
|
384
384
|
|
|
385
|
-
declare const VERSION = "0.
|
|
385
|
+
declare const VERSION = "0.21.0";
|
|
386
386
|
|
|
387
387
|
export { type ChainModuleRendererOptions, CodegenError, type CodegenManifest, ConfigError, DriftGuardError, type EntryPoint, type FastDiscoveryOptions, type JsonSchema, type MocksEmitOptions, type OpenApiDocument, type OpenApiEmitOptions, type OpenApiInfo, RenderContext, RenderedModule, ResolvedConfig, RouteDescriptor, SchemaModule, SchemaNode, type TsTypeContext, UserConfig, VERSION, ValidationAdapter, type WatchOptions, type Watcher, acquireLock, buildMocksFile, buildOpenApiSpec, createChainModuleRenderer, defineConfig, discoverContractsFast, emitApi, emitForms, emitMocks, emitOpenApi, emitRoutes, extractSchemaFromDto, generate, loadConfig, renderTsType, resolveConfig, schemaModuleToJsonSchema, schemaNodeToJsonSchema, toObjectKey, typeNameFor, watch };
|
package/dist/index.d.ts
CHANGED
|
@@ -382,6 +382,6 @@ interface FastDiscoveryOptions {
|
|
|
382
382
|
}
|
|
383
383
|
declare function discoverContractsFast(opts: FastDiscoveryOptions): Promise<RouteDescriptor[]>;
|
|
384
384
|
|
|
385
|
-
declare const VERSION = "0.
|
|
385
|
+
declare const VERSION = "0.21.0";
|
|
386
386
|
|
|
387
387
|
export { type ChainModuleRendererOptions, CodegenError, type CodegenManifest, ConfigError, DriftGuardError, type EntryPoint, type FastDiscoveryOptions, type JsonSchema, type MocksEmitOptions, type OpenApiDocument, type OpenApiEmitOptions, type OpenApiInfo, RenderContext, RenderedModule, ResolvedConfig, RouteDescriptor, SchemaModule, SchemaNode, type TsTypeContext, UserConfig, VERSION, ValidationAdapter, type WatchOptions, type Watcher, acquireLock, buildMocksFile, buildOpenApiSpec, createChainModuleRenderer, defineConfig, discoverContractsFast, emitApi, emitForms, emitMocks, emitOpenApi, emitRoutes, extractSchemaFromDto, generate, loadConfig, renderTsType, resolveConfig, schemaModuleToJsonSchema, schemaNodeToJsonSchema, toObjectKey, typeNameFor, watch };
|
package/dist/index.js
CHANGED
|
@@ -3642,10 +3642,15 @@ function resolveInstantiatedReturnType(cls, methodName) {
|
|
|
3642
3642
|
|
|
3643
3643
|
// src/discovery/filter-for.ts
|
|
3644
3644
|
function resolveMixinEntityClass(mixin, project) {
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
return
|
|
3645
|
+
return resolveClassRef(mixin?.namedClassArgs?.entity ?? mixin?.classArgs[0], project);
|
|
3646
|
+
}
|
|
3647
|
+
function resolveMixinFilterClass(mixin, project) {
|
|
3648
|
+
return resolveClassRef(mixin?.namedClassArgs?.filter, project);
|
|
3649
|
+
}
|
|
3650
|
+
function resolveClassRef(ref, project) {
|
|
3651
|
+
if (!ref) return void 0;
|
|
3652
|
+
const file = project.getSourceFile(ref.filePath) ?? project.addSourceFileAtPathIfExists(ref.filePath);
|
|
3653
|
+
return file?.getClass(ref.name);
|
|
3649
3654
|
}
|
|
3650
3655
|
function classifyFilterForHint(typeInit) {
|
|
3651
3656
|
if (Node6.isStringLiteral(typeInit)) {
|
|
@@ -3720,7 +3725,7 @@ function extractFilterForHints(classDecl, project) {
|
|
|
3720
3725
|
}
|
|
3721
3726
|
return hints;
|
|
3722
3727
|
}
|
|
3723
|
-
function extractApplyFilterInfo(method, sourceFile, project, mixin) {
|
|
3728
|
+
function extractApplyFilterInfo(method, sourceFile, project, mixin, controllerClass) {
|
|
3724
3729
|
const declFile = method.getSourceFile();
|
|
3725
3730
|
const mixinEntity = resolveMixinEntityClass(mixin, project);
|
|
3726
3731
|
for (const param of method.getParameters()) {
|
|
@@ -3745,31 +3750,55 @@ function extractApplyFilterInfo(method, sourceFile, project, mixin) {
|
|
|
3745
3750
|
}
|
|
3746
3751
|
const filterClassName = filterClassArg.getText();
|
|
3747
3752
|
const resolved = factoryStaticClass ? void 0 : findType(filterClassName, declFile, project);
|
|
3748
|
-
const
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
byName.set(key, toFilterFieldType(key, classified));
|
|
3759
|
-
}
|
|
3760
|
-
fieldTypes = [...byName.values()];
|
|
3761
|
-
}
|
|
3762
|
-
if (fieldTypes.length === 0) return null;
|
|
3763
|
-
const fieldNames = fieldTypes.map((f) => f.name);
|
|
3753
|
+
const declaredClass = factoryStaticClass ?? (resolved?.kind === "class" ? resolved.decl : resolveLocalClassDeclaration(filterClassArg));
|
|
3754
|
+
const ownRoute = !mixin || (controllerClass ? method.getParent() === controllerClass : declFile.getFilePath() !== mixin.factoryFilePath);
|
|
3755
|
+
const namedByRoute = ownRoute && Node6.isIdentifier(filterClassArg) ? declaredClass : void 0;
|
|
3756
|
+
for (const candidate of orderFilterCandidates({
|
|
3757
|
+
namedByRoute,
|
|
3758
|
+
supplied: resolveMixinFilterClass(mixin, project),
|
|
3759
|
+
declared: declaredClass
|
|
3760
|
+
})) {
|
|
3761
|
+
const fieldTypes = collectFilterFields(candidate, project, mixinEntity);
|
|
3762
|
+
if (fieldTypes.length === 0) continue;
|
|
3764
3763
|
return {
|
|
3765
|
-
fieldNames,
|
|
3764
|
+
fieldNames: fieldTypes.map((f) => f.name),
|
|
3766
3765
|
fieldTypes,
|
|
3767
3766
|
source
|
|
3768
3767
|
};
|
|
3769
3768
|
}
|
|
3769
|
+
if (declaredClass) return null;
|
|
3770
3770
|
}
|
|
3771
3771
|
return null;
|
|
3772
3772
|
}
|
|
3773
|
+
function orderFilterCandidates(sources) {
|
|
3774
|
+
const ordered = [];
|
|
3775
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3776
|
+
const push = (decl, preferDeclaredEntity) => {
|
|
3777
|
+
if (!decl || seen.has(decl)) return;
|
|
3778
|
+
seen.add(decl);
|
|
3779
|
+
ordered.push({ decl, preferDeclaredEntity });
|
|
3780
|
+
};
|
|
3781
|
+
push(sources.namedByRoute, true);
|
|
3782
|
+
push(sources.supplied, true);
|
|
3783
|
+
push(sources.declared, false);
|
|
3784
|
+
return ordered;
|
|
3785
|
+
}
|
|
3786
|
+
function collectFilterFields(candidate, project, mixinEntity) {
|
|
3787
|
+
const { decl, preferDeclaredEntity } = candidate;
|
|
3788
|
+
let fieldTypes = extractClassPropertyTypes(decl, project);
|
|
3789
|
+
if (fieldTypes.length === 0) {
|
|
3790
|
+
fieldTypes = extractFilterableEntityFields(decl, project, mixinEntity, preferDeclaredEntity);
|
|
3791
|
+
}
|
|
3792
|
+
const filterForHints = extractFilterForHints(decl, project);
|
|
3793
|
+
if (filterForHints.size > 0) {
|
|
3794
|
+
const byName = new Map(fieldTypes.map((f) => [f.name, f]));
|
|
3795
|
+
for (const [key, classified] of filterForHints) {
|
|
3796
|
+
byName.set(key, toFilterFieldType(key, classified));
|
|
3797
|
+
}
|
|
3798
|
+
fieldTypes = [...byName.values()];
|
|
3799
|
+
}
|
|
3800
|
+
return fieldTypes;
|
|
3801
|
+
}
|
|
3773
3802
|
var RELATION_DECORATORS = /* @__PURE__ */ new Set(["OneToMany", "ManyToOne", "ManyToMany", "OneToOne"]);
|
|
3774
3803
|
function collectEntityFields(entityDecl, sourceFile, project, prefix, visited) {
|
|
3775
3804
|
const entityName = entityDecl.getName() ?? "";
|
|
@@ -3848,21 +3877,53 @@ function resolveDeclaredEntity(optionsArg, filterClass, project) {
|
|
|
3848
3877
|
if (!resolved || resolved.kind !== "class") return void 0;
|
|
3849
3878
|
return resolved.decl;
|
|
3850
3879
|
}
|
|
3851
|
-
function
|
|
3880
|
+
function readFieldNameList(optionsArg, key) {
|
|
3881
|
+
if (!Node6.isObjectLiteralExpression(optionsArg)) return void 0;
|
|
3882
|
+
const prop = optionsArg.getProperty(key);
|
|
3883
|
+
if (!prop || !Node6.isPropertyAssignment(prop)) return void 0;
|
|
3884
|
+
const init = prop.getInitializer();
|
|
3885
|
+
if (!init || !Node6.isArrayLiteralExpression(init)) return void 0;
|
|
3886
|
+
const names = /* @__PURE__ */ new Set();
|
|
3887
|
+
for (const el of init.getElements()) {
|
|
3888
|
+
if (Node6.isStringLiteral(el)) {
|
|
3889
|
+
names.add(el.getLiteralValue());
|
|
3890
|
+
continue;
|
|
3891
|
+
}
|
|
3892
|
+
if (Node6.isObjectLiteralExpression(el)) {
|
|
3893
|
+
const fieldProp = el.getProperty("field");
|
|
3894
|
+
if (fieldProp && Node6.isPropertyAssignment(fieldProp)) {
|
|
3895
|
+
const fieldInit = fieldProp.getInitializer();
|
|
3896
|
+
if (fieldInit && Node6.isStringLiteral(fieldInit)) {
|
|
3897
|
+
names.add(fieldInit.getLiteralValue());
|
|
3898
|
+
continue;
|
|
3899
|
+
}
|
|
3900
|
+
}
|
|
3901
|
+
}
|
|
3902
|
+
return void 0;
|
|
3903
|
+
}
|
|
3904
|
+
return names;
|
|
3905
|
+
}
|
|
3906
|
+
function narrowToDeclaredFields(fields, optionsArg) {
|
|
3907
|
+
const allowed = readFieldNameList(optionsArg, "allowed");
|
|
3908
|
+
const blocked = readFieldNameList(optionsArg, "blocked");
|
|
3909
|
+
if (!allowed && !blocked) return fields;
|
|
3910
|
+
return fields.filter(
|
|
3911
|
+
(f) => (!allowed || allowed.has(f.name)) && !(blocked?.has(f.name) ?? false)
|
|
3912
|
+
);
|
|
3913
|
+
}
|
|
3914
|
+
function extractFilterableEntityFields(filterClass, project, entityOverride, preferDeclaredEntity = false) {
|
|
3852
3915
|
const filterableDecorator = filterClass.getDecorators().find((d) => d.getName() === "Filterable");
|
|
3853
3916
|
if (!filterableDecorator) return [];
|
|
3854
3917
|
const args = filterableDecorator.getArguments();
|
|
3855
3918
|
if (args.length === 0) return [];
|
|
3856
3919
|
const optionsArg = args[0];
|
|
3857
3920
|
if (!Node6.isObjectLiteralExpression(optionsArg)) return [];
|
|
3858
|
-
const
|
|
3921
|
+
const declaredEntity = resolveDeclaredEntity(optionsArg, filterClass, project);
|
|
3922
|
+
const entityDecl = preferDeclaredEntity ? declaredEntity ?? entityOverride : entityOverride ?? declaredEntity;
|
|
3859
3923
|
if (!entityDecl) return [];
|
|
3860
|
-
const fields =
|
|
3861
|
-
entityDecl,
|
|
3862
|
-
|
|
3863
|
-
project,
|
|
3864
|
-
"",
|
|
3865
|
-
/* @__PURE__ */ new Set()
|
|
3924
|
+
const fields = narrowToDeclaredFields(
|
|
3925
|
+
collectEntityFields(entityDecl, entityDecl.getSourceFile(), project, "", /* @__PURE__ */ new Set()),
|
|
3926
|
+
optionsArg
|
|
3866
3927
|
);
|
|
3867
3928
|
const relationsDecorator = filterClass.getDecorators().find((d) => d.getName() === "Relations");
|
|
3868
3929
|
if (relationsDecorator) {
|
|
@@ -4281,9 +4342,9 @@ function unwrapNamedContainer(node, names) {
|
|
|
4281
4342
|
}
|
|
4282
4343
|
return node;
|
|
4283
4344
|
}
|
|
4284
|
-
function extractDtoContract(method, sourceFile, project, mixin) {
|
|
4345
|
+
function extractDtoContract(method, sourceFile, project, mixin, controllerClass) {
|
|
4285
4346
|
let body = extractBodyType(method, sourceFile, project);
|
|
4286
|
-
const filterInfo = extractApplyFilterInfo(method, sourceFile, project, mixin);
|
|
4347
|
+
const filterInfo = extractApplyFilterInfo(method, sourceFile, project, mixin, controllerClass);
|
|
4287
4348
|
const query = extractQueryType(method, sourceFile, project);
|
|
4288
4349
|
const uploads = extractUploadedFiles(method);
|
|
4289
4350
|
const multipartBody = uploads.fields ? `{ ${uploads.fields} }` : null;
|
|
@@ -4846,7 +4907,7 @@ function extractDtoRoute(args) {
|
|
|
4846
4907
|
const methodName = method.getName();
|
|
4847
4908
|
const classAs = readAsDecorator(cls, `class ${className}`);
|
|
4848
4909
|
const methodAs = readAsDecorator(method, `${className}.${methodName}`);
|
|
4849
|
-
const dtoContract = extractDtoContract(method, sourceFile, project, mixin);
|
|
4910
|
+
const dtoContract = extractDtoContract(method, sourceFile, project, mixin, cls);
|
|
4850
4911
|
const mixinResponse = mixin ? resolveInstantiatedReturnType(cls, methodName) : void 0;
|
|
4851
4912
|
return buildRoute({
|
|
4852
4913
|
className,
|
|
@@ -5210,7 +5271,7 @@ function createChainModuleRenderer(opts) {
|
|
|
5210
5271
|
}
|
|
5211
5272
|
|
|
5212
5273
|
// src/index.ts
|
|
5213
|
-
var VERSION = "0.
|
|
5274
|
+
var VERSION = "0.21.0";
|
|
5214
5275
|
export {
|
|
5215
5276
|
CodegenError,
|
|
5216
5277
|
ConfigError,
|