@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/cli/main.js
CHANGED
|
@@ -751,7 +751,15 @@ function emitRouterTypeBlock(tree, indent, outDir, serialization) {
|
|
|
751
751
|
const isFilterQuery = c.contractSource.filterSource === "query" && !!c.contractSource.filterFields?.length;
|
|
752
752
|
const query = queryRef ? queryRef.isArray ? `Array<${queryRef.name}>` : queryRef.name : isFilterQuery ? emitFilterQueryType(c) : c.contractSource.query ?? "never";
|
|
753
753
|
const bodyRef = c.contractSource.bodyRef;
|
|
754
|
-
|
|
754
|
+
let body = method === "GET" ? "never" : bodyRef ? bodyRef.isArray ? `Array<${bodyRef.name}>` : bodyRef.name : c.contractSource.body ?? "never";
|
|
755
|
+
const multipartBody = c.contractSource.multipartBody;
|
|
756
|
+
if (c.contractSource.multipart && multipartBody) {
|
|
757
|
+
if (body === "never") {
|
|
758
|
+
body = multipartBody;
|
|
759
|
+
} else if (!bodyAcceptsAnything(body)) {
|
|
760
|
+
body = `(${body}) & ${multipartBody}`;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
755
763
|
const response = buildResponseType(c, outDir, serialization);
|
|
756
764
|
const error = buildErrorType(c);
|
|
757
765
|
const params = buildParamsType(c.params);
|
|
@@ -770,6 +778,25 @@ function emitRouterTypeBlock(tree, indent, outDir, serialization) {
|
|
|
770
778
|
}
|
|
771
779
|
return lines;
|
|
772
780
|
}
|
|
781
|
+
function topLevelUnionArms(type) {
|
|
782
|
+
const arms = [];
|
|
783
|
+
let depth = 0;
|
|
784
|
+
let start = 0;
|
|
785
|
+
for (let i = 0; i < type.length; i++) {
|
|
786
|
+
const ch = type[i];
|
|
787
|
+
if (ch === "{" || ch === "[" || ch === "<" || ch === "(") depth++;
|
|
788
|
+
else if (ch === "}" || ch === "]" || ch === ">" || ch === ")") depth--;
|
|
789
|
+
else if (ch === "|" && depth === 0) {
|
|
790
|
+
arms.push(type.slice(start, i).trim());
|
|
791
|
+
start = i + 1;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
arms.push(type.slice(start).trim());
|
|
795
|
+
return arms;
|
|
796
|
+
}
|
|
797
|
+
function bodyAcceptsAnything(body) {
|
|
798
|
+
return topLevelUnionArms(body).some((arm) => arm === "unknown" || arm === "any");
|
|
799
|
+
}
|
|
773
800
|
function buildRequestModel(c) {
|
|
774
801
|
const m = c.method.toLowerCase();
|
|
775
802
|
const flat = JSON.stringify(c.name);
|
|
@@ -3866,10 +3893,7 @@ function extractDtoContract(method, sourceFile, project) {
|
|
|
3866
3893
|
const filterInfo = extractApplyFilterInfo(method, sourceFile, project);
|
|
3867
3894
|
const query = extractQueryType(method, sourceFile, project);
|
|
3868
3895
|
const uploads = extractUploadedFiles(method);
|
|
3869
|
-
|
|
3870
|
-
const fileObject = `{ ${uploads.fields} }`;
|
|
3871
|
-
body = body ? `(${body}) & ${fileObject}` : fileObject;
|
|
3872
|
-
}
|
|
3896
|
+
const multipartBody = uploads.fields ? `{ ${uploads.fields} }` : null;
|
|
3873
3897
|
const streamElement = detectStreamElement(method);
|
|
3874
3898
|
const isStream = streamElement !== null;
|
|
3875
3899
|
if (filterInfo && filterInfo.source === "body") {
|
|
@@ -3953,7 +3977,8 @@ function extractDtoContract(method, sourceFile, project) {
|
|
|
3953
3977
|
bodySchema,
|
|
3954
3978
|
querySchema,
|
|
3955
3979
|
stream: isStream,
|
|
3956
|
-
multipart: uploads.multipart
|
|
3980
|
+
multipart: uploads.multipart,
|
|
3981
|
+
multipartBody
|
|
3957
3982
|
};
|
|
3958
3983
|
}
|
|
3959
3984
|
function resolveParamClass(method, decoratorName, sourceFile, project) {
|
|
@@ -4439,7 +4464,8 @@ function extractDtoRoute(args) {
|
|
|
4439
4464
|
bodySchema: dtoContract?.bodySchema ?? null,
|
|
4440
4465
|
querySchema: dtoContract?.querySchema ?? null,
|
|
4441
4466
|
stream: dtoContract?.stream ?? false,
|
|
4442
|
-
multipart: dtoContract?.multipart ?? false
|
|
4467
|
+
multipart: dtoContract?.multipart ?? false,
|
|
4468
|
+
multipartBody: dtoContract?.multipartBody ?? null
|
|
4443
4469
|
}
|
|
4444
4470
|
});
|
|
4445
4471
|
}
|
|
@@ -4669,7 +4695,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
4669
4695
|
}
|
|
4670
4696
|
|
|
4671
4697
|
// src/index.ts
|
|
4672
|
-
var VERSION = "0.13.
|
|
4698
|
+
var VERSION = "0.13.1";
|
|
4673
4699
|
|
|
4674
4700
|
// src/cli/codegen.ts
|
|
4675
4701
|
async function runCodegen(opts = {}) {
|