@dudousxd/nestjs-codegen 0.12.0 → 0.13.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 +31 -0
- package/dist/cli/main.cjs +61 -4
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +61 -4
- 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-CxkGbILp.d.cts → index-DvUzPXdh.d.cts} +7 -0
- package/dist/{index-CxkGbILp.d.ts → index-DvUzPXdh.d.ts} +7 -0
- package/dist/index.cjs +61 -4
- 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 +61 -4
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +61 -4
- 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 +61 -4
- package/dist/nest/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor, S as SchemaNode, b as RenderContext, c as SchemaModule, d as RenderedModule, e as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext, f as SerializationMode } from './index-
|
|
2
|
-
export { A as AdapterUsage, g as ContractDescriptor, h as ContractSource, i as ControllerRef, N as NumberCheck, j as ScopeConfig, k as StringCheck, T as TypeRef, l as ValidationOption, r as resolveAdapter } from './index-
|
|
1
|
+
import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor, S as SchemaNode, b as RenderContext, c as SchemaModule, d as RenderedModule, e as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext, f as SerializationMode } from './index-DvUzPXdh.cjs';
|
|
2
|
+
export { A as AdapterUsage, g as ContractDescriptor, h as ContractSource, i as ControllerRef, N as NumberCheck, j as ScopeConfig, k as StringCheck, T as TypeRef, l as ValidationOption, r as resolveAdapter } from './index-DvUzPXdh.cjs';
|
|
3
3
|
import { ClassDeclaration, SourceFile, Project } from 'ts-morph';
|
|
4
4
|
|
|
5
5
|
declare function defineConfig(c: UserConfig): UserConfig;
|
|
@@ -322,6 +322,6 @@ interface FastDiscoveryOptions {
|
|
|
322
322
|
}
|
|
323
323
|
declare function discoverContractsFast(opts: FastDiscoveryOptions): Promise<RouteDescriptor[]>;
|
|
324
324
|
|
|
325
|
-
declare const VERSION = "0.
|
|
325
|
+
declare const VERSION = "0.13.0";
|
|
326
326
|
|
|
327
327
|
export { type ChainModuleRendererOptions, CodegenError, type CodegenManifest, ConfigError, 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
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor, S as SchemaNode, b as RenderContext, c as SchemaModule, d as RenderedModule, e as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext, f as SerializationMode } from './index-
|
|
2
|
-
export { A as AdapterUsage, g as ContractDescriptor, h as ContractSource, i as ControllerRef, N as NumberCheck, j as ScopeConfig, k as StringCheck, T as TypeRef, l as ValidationOption, r as resolveAdapter } from './index-
|
|
1
|
+
import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor, S as SchemaNode, b as RenderContext, c as SchemaModule, d as RenderedModule, e as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext, f as SerializationMode } from './index-DvUzPXdh.js';
|
|
2
|
+
export { A as AdapterUsage, g as ContractDescriptor, h as ContractSource, i as ControllerRef, N as NumberCheck, j as ScopeConfig, k as StringCheck, T as TypeRef, l as ValidationOption, r as resolveAdapter } from './index-DvUzPXdh.js';
|
|
3
3
|
import { ClassDeclaration, SourceFile, Project } from 'ts-morph';
|
|
4
4
|
|
|
5
5
|
declare function defineConfig(c: UserConfig): UserConfig;
|
|
@@ -322,6 +322,6 @@ interface FastDiscoveryOptions {
|
|
|
322
322
|
}
|
|
323
323
|
declare function discoverContractsFast(opts: FastDiscoveryOptions): Promise<RouteDescriptor[]>;
|
|
324
324
|
|
|
325
|
-
declare const VERSION = "0.
|
|
325
|
+
declare const VERSION = "0.13.0";
|
|
326
326
|
|
|
327
327
|
export { type ChainModuleRendererOptions, CodegenError, type CodegenManifest, ConfigError, 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
|
@@ -791,6 +791,7 @@ function buildRequestModel(c) {
|
|
|
791
791
|
const optsParts = [];
|
|
792
792
|
if (hasQuery) optsParts.push("query: input?.query as Record<string, unknown> | undefined");
|
|
793
793
|
if (hasBody) optsParts.push("body: input?.body");
|
|
794
|
+
if (hasBody && c.contractSource.multipart) optsParts.push("multipart: true");
|
|
794
795
|
const optsExpr = optsParts.length ? `{ ${optsParts.join(", ")} }` : "{}";
|
|
795
796
|
return {
|
|
796
797
|
routeName: c.name,
|
|
@@ -3689,6 +3690,55 @@ function extractParamsType(method, sourceFile, project) {
|
|
|
3689
3690
|
}
|
|
3690
3691
|
return entries.length > 0 ? `{ ${entries.join("; ")} }` : null;
|
|
3691
3692
|
}
|
|
3693
|
+
function extractUploadedFiles(method) {
|
|
3694
|
+
const FILE = "File | Blob";
|
|
3695
|
+
const entries = [];
|
|
3696
|
+
let multipart = false;
|
|
3697
|
+
const hasUploadedFileParam = method.getParameters().some(
|
|
3698
|
+
(p) => p.getDecorators().some((d) => {
|
|
3699
|
+
const name = d.getName();
|
|
3700
|
+
return name === "UploadedFile" || name === "UploadedFiles";
|
|
3701
|
+
})
|
|
3702
|
+
);
|
|
3703
|
+
for (const decorator of method.getDecorators()) {
|
|
3704
|
+
if (decorator.getName() !== "UseInterceptors") continue;
|
|
3705
|
+
for (const arg of decorator.getArguments()) {
|
|
3706
|
+
if (!Node6.isCallExpression(arg)) continue;
|
|
3707
|
+
const interceptor = arg.getExpression().getText();
|
|
3708
|
+
const callArgs = arg.getArguments();
|
|
3709
|
+
const firstArg2 = callArgs[0];
|
|
3710
|
+
if (interceptor === "FileInterceptor") {
|
|
3711
|
+
if (firstArg2 && Node6.isStringLiteral(firstArg2)) {
|
|
3712
|
+
entries.push(`${firstArg2.getLiteralValue()}: ${FILE}`);
|
|
3713
|
+
multipart = true;
|
|
3714
|
+
}
|
|
3715
|
+
} else if (interceptor === "FilesInterceptor") {
|
|
3716
|
+
if (firstArg2 && Node6.isStringLiteral(firstArg2)) {
|
|
3717
|
+
entries.push(`${firstArg2.getLiteralValue()}: Array<${FILE}>`);
|
|
3718
|
+
multipart = true;
|
|
3719
|
+
}
|
|
3720
|
+
} else if (interceptor === "FileFieldsInterceptor") {
|
|
3721
|
+
if (firstArg2 && Node6.isArrayLiteralExpression(firstArg2)) {
|
|
3722
|
+
for (const el of firstArg2.getElements()) {
|
|
3723
|
+
if (!Node6.isObjectLiteralExpression(el)) continue;
|
|
3724
|
+
const nameProp = el.getProperty("name");
|
|
3725
|
+
if (nameProp && Node6.isPropertyAssignment(nameProp)) {
|
|
3726
|
+
const init = nameProp.getInitializer();
|
|
3727
|
+
if (init && Node6.isStringLiteral(init)) {
|
|
3728
|
+
entries.push(`${init.getLiteralValue()}: Array<${FILE}>`);
|
|
3729
|
+
}
|
|
3730
|
+
}
|
|
3731
|
+
}
|
|
3732
|
+
multipart = true;
|
|
3733
|
+
}
|
|
3734
|
+
} else if (interceptor === "AnyFilesInterceptor") {
|
|
3735
|
+
multipart = true;
|
|
3736
|
+
}
|
|
3737
|
+
}
|
|
3738
|
+
}
|
|
3739
|
+
if (hasUploadedFileParam) multipart = true;
|
|
3740
|
+
return { fields: entries.length > 0 ? entries.join("; ") : null, multipart };
|
|
3741
|
+
}
|
|
3692
3742
|
function extractResponseType(method, sourceFile, project) {
|
|
3693
3743
|
const apiResponseDecorator = method.getDecorators().find((d) => d.getName() === "ApiResponse" && (apiResponseStatus(d) ?? 0) < 400);
|
|
3694
3744
|
if (apiResponseDecorator) {
|
|
@@ -3823,6 +3873,11 @@ function extractDtoContract(method, sourceFile, project) {
|
|
|
3823
3873
|
let body = extractBodyType(method, sourceFile, project);
|
|
3824
3874
|
const filterInfo = extractApplyFilterInfo(method, sourceFile, project);
|
|
3825
3875
|
const query = extractQueryType(method, sourceFile, project);
|
|
3876
|
+
const uploads = extractUploadedFiles(method);
|
|
3877
|
+
if (uploads.fields) {
|
|
3878
|
+
const fileObject = `{ ${uploads.fields} }`;
|
|
3879
|
+
body = body ? `(${body}) & ${fileObject}` : fileObject;
|
|
3880
|
+
}
|
|
3826
3881
|
const streamElement = detectStreamElement(method);
|
|
3827
3882
|
const isStream = streamElement !== null;
|
|
3828
3883
|
if (filterInfo && filterInfo.source === "body") {
|
|
@@ -3832,7 +3887,7 @@ function extractDtoContract(method, sourceFile, project) {
|
|
|
3832
3887
|
const paramsType = extractParamsType(method, sourceFile, project);
|
|
3833
3888
|
const response = isStream ? resolveTypeNodeToString(streamElement, sourceFile, project, 3) : extractResponseType(method, sourceFile, project);
|
|
3834
3889
|
const errorInfo = extractErrorType(method, sourceFile, project);
|
|
3835
|
-
if (body === null && query === null && paramsType === null && response === "unknown" && errorInfo === null && filterInfo === null && !isStream) {
|
|
3890
|
+
if (body === null && query === null && paramsType === null && response === "unknown" && errorInfo === null && filterInfo === null && !isStream && !uploads.multipart) {
|
|
3836
3891
|
return null;
|
|
3837
3892
|
}
|
|
3838
3893
|
let bodyRef = null;
|
|
@@ -3905,7 +3960,8 @@ function extractDtoContract(method, sourceFile, project) {
|
|
|
3905
3960
|
formWarnings,
|
|
3906
3961
|
bodySchema,
|
|
3907
3962
|
querySchema,
|
|
3908
|
-
stream: isStream
|
|
3963
|
+
stream: isStream,
|
|
3964
|
+
multipart: uploads.multipart
|
|
3909
3965
|
};
|
|
3910
3966
|
}
|
|
3911
3967
|
function resolveParamClass(method, decoratorName, sourceFile, project) {
|
|
@@ -4390,7 +4446,8 @@ function extractDtoRoute(args) {
|
|
|
4390
4446
|
formWarnings: dtoContract?.formWarnings ?? [],
|
|
4391
4447
|
bodySchema: dtoContract?.bodySchema ?? null,
|
|
4392
4448
|
querySchema: dtoContract?.querySchema ?? null,
|
|
4393
|
-
stream: dtoContract?.stream ?? false
|
|
4449
|
+
stream: dtoContract?.stream ?? false,
|
|
4450
|
+
multipart: dtoContract?.multipart ?? false
|
|
4394
4451
|
}
|
|
4395
4452
|
});
|
|
4396
4453
|
}
|
|
@@ -4703,7 +4760,7 @@ function createChainModuleRenderer(opts) {
|
|
|
4703
4760
|
}
|
|
4704
4761
|
|
|
4705
4762
|
// src/index.ts
|
|
4706
|
-
var VERSION = "0.
|
|
4763
|
+
var VERSION = "0.13.0";
|
|
4707
4764
|
export {
|
|
4708
4765
|
CodegenError,
|
|
4709
4766
|
ConfigError,
|