@dudousxd/nestjs-codegen 0.13.0 → 0.13.1
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 +20 -0
- package/dist/cli/main.cjs +34 -8
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +34 -8
- 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-DvUzPXdh.d.cts → index-D8RIMVpU.d.cts} +10 -2
- package/dist/{index-DvUzPXdh.d.ts → index-D8RIMVpU.d.ts} +10 -2
- package/dist/index.cjs +34 -8
- 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 +34 -8
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +34 -8
- 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 +34 -8
- 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-D8RIMVpU.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-D8RIMVpU.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.13.
|
|
325
|
+
declare const VERSION = "0.13.1";
|
|
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-D8RIMVpU.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-D8RIMVpU.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.13.
|
|
325
|
+
declare const VERSION = "0.13.1";
|
|
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
|
@@ -756,7 +756,15 @@ function emitRouterTypeBlock(tree, indent, outDir, serialization) {
|
|
|
756
756
|
const isFilterQuery = c.contractSource.filterSource === "query" && !!c.contractSource.filterFields?.length;
|
|
757
757
|
const query = queryRef ? queryRef.isArray ? `Array<${queryRef.name}>` : queryRef.name : isFilterQuery ? emitFilterQueryType(c) : c.contractSource.query ?? "never";
|
|
758
758
|
const bodyRef = c.contractSource.bodyRef;
|
|
759
|
-
|
|
759
|
+
let body = method === "GET" ? "never" : bodyRef ? bodyRef.isArray ? `Array<${bodyRef.name}>` : bodyRef.name : c.contractSource.body ?? "never";
|
|
760
|
+
const multipartBody = c.contractSource.multipartBody;
|
|
761
|
+
if (c.contractSource.multipart && multipartBody) {
|
|
762
|
+
if (body === "never") {
|
|
763
|
+
body = multipartBody;
|
|
764
|
+
} else if (!bodyAcceptsAnything(body)) {
|
|
765
|
+
body = `(${body}) & ${multipartBody}`;
|
|
766
|
+
}
|
|
767
|
+
}
|
|
760
768
|
const response = buildResponseType(c, outDir, serialization);
|
|
761
769
|
const error = buildErrorType(c);
|
|
762
770
|
const params = buildParamsType(c.params);
|
|
@@ -775,6 +783,25 @@ function emitRouterTypeBlock(tree, indent, outDir, serialization) {
|
|
|
775
783
|
}
|
|
776
784
|
return lines;
|
|
777
785
|
}
|
|
786
|
+
function topLevelUnionArms(type) {
|
|
787
|
+
const arms = [];
|
|
788
|
+
let depth = 0;
|
|
789
|
+
let start = 0;
|
|
790
|
+
for (let i = 0; i < type.length; i++) {
|
|
791
|
+
const ch = type[i];
|
|
792
|
+
if (ch === "{" || ch === "[" || ch === "<" || ch === "(") depth++;
|
|
793
|
+
else if (ch === "}" || ch === "]" || ch === ">" || ch === ")") depth--;
|
|
794
|
+
else if (ch === "|" && depth === 0) {
|
|
795
|
+
arms.push(type.slice(start, i).trim());
|
|
796
|
+
start = i + 1;
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
arms.push(type.slice(start).trim());
|
|
800
|
+
return arms;
|
|
801
|
+
}
|
|
802
|
+
function bodyAcceptsAnything(body) {
|
|
803
|
+
return topLevelUnionArms(body).some((arm) => arm === "unknown" || arm === "any");
|
|
804
|
+
}
|
|
778
805
|
function buildRequestModel(c) {
|
|
779
806
|
const m = c.method.toLowerCase();
|
|
780
807
|
const flat = JSON.stringify(c.name);
|
|
@@ -3874,10 +3901,7 @@ function extractDtoContract(method, sourceFile, project) {
|
|
|
3874
3901
|
const filterInfo = extractApplyFilterInfo(method, sourceFile, project);
|
|
3875
3902
|
const query = extractQueryType(method, sourceFile, project);
|
|
3876
3903
|
const uploads = extractUploadedFiles(method);
|
|
3877
|
-
|
|
3878
|
-
const fileObject = `{ ${uploads.fields} }`;
|
|
3879
|
-
body = body ? `(${body}) & ${fileObject}` : fileObject;
|
|
3880
|
-
}
|
|
3904
|
+
const multipartBody = uploads.fields ? `{ ${uploads.fields} }` : null;
|
|
3881
3905
|
const streamElement = detectStreamElement(method);
|
|
3882
3906
|
const isStream = streamElement !== null;
|
|
3883
3907
|
if (filterInfo && filterInfo.source === "body") {
|
|
@@ -3961,7 +3985,8 @@ function extractDtoContract(method, sourceFile, project) {
|
|
|
3961
3985
|
bodySchema,
|
|
3962
3986
|
querySchema,
|
|
3963
3987
|
stream: isStream,
|
|
3964
|
-
multipart: uploads.multipart
|
|
3988
|
+
multipart: uploads.multipart,
|
|
3989
|
+
multipartBody
|
|
3965
3990
|
};
|
|
3966
3991
|
}
|
|
3967
3992
|
function resolveParamClass(method, decoratorName, sourceFile, project) {
|
|
@@ -4447,7 +4472,8 @@ function extractDtoRoute(args) {
|
|
|
4447
4472
|
bodySchema: dtoContract?.bodySchema ?? null,
|
|
4448
4473
|
querySchema: dtoContract?.querySchema ?? null,
|
|
4449
4474
|
stream: dtoContract?.stream ?? false,
|
|
4450
|
-
multipart: dtoContract?.multipart ?? false
|
|
4475
|
+
multipart: dtoContract?.multipart ?? false,
|
|
4476
|
+
multipartBody: dtoContract?.multipartBody ?? null
|
|
4451
4477
|
}
|
|
4452
4478
|
});
|
|
4453
4479
|
}
|
|
@@ -4760,7 +4786,7 @@ function createChainModuleRenderer(opts) {
|
|
|
4760
4786
|
}
|
|
4761
4787
|
|
|
4762
4788
|
// src/index.ts
|
|
4763
|
-
var VERSION = "0.13.
|
|
4789
|
+
var VERSION = "0.13.1";
|
|
4764
4790
|
export {
|
|
4765
4791
|
CodegenError,
|
|
4766
4792
|
ConfigError,
|