@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/nest/index.cjs
CHANGED
|
@@ -1773,10 +1773,7 @@ function extractDtoContract(method, sourceFile, project) {
|
|
|
1773
1773
|
const filterInfo = extractApplyFilterInfo(method, sourceFile, project);
|
|
1774
1774
|
const query = extractQueryType(method, sourceFile, project);
|
|
1775
1775
|
const uploads = extractUploadedFiles(method);
|
|
1776
|
-
|
|
1777
|
-
const fileObject = `{ ${uploads.fields} }`;
|
|
1778
|
-
body = body ? `(${body}) & ${fileObject}` : fileObject;
|
|
1779
|
-
}
|
|
1776
|
+
const multipartBody = uploads.fields ? `{ ${uploads.fields} }` : null;
|
|
1780
1777
|
const streamElement = detectStreamElement(method);
|
|
1781
1778
|
const isStream = streamElement !== null;
|
|
1782
1779
|
if (filterInfo && filterInfo.source === "body") {
|
|
@@ -1860,7 +1857,8 @@ function extractDtoContract(method, sourceFile, project) {
|
|
|
1860
1857
|
bodySchema,
|
|
1861
1858
|
querySchema,
|
|
1862
1859
|
stream: isStream,
|
|
1863
|
-
multipart: uploads.multipart
|
|
1860
|
+
multipart: uploads.multipart,
|
|
1861
|
+
multipartBody
|
|
1864
1862
|
};
|
|
1865
1863
|
}
|
|
1866
1864
|
function resolveParamClass(method, decoratorName, sourceFile, project) {
|
|
@@ -2328,7 +2326,8 @@ function extractDtoRoute(args) {
|
|
|
2328
2326
|
bodySchema: dtoContract?.bodySchema ?? null,
|
|
2329
2327
|
querySchema: dtoContract?.querySchema ?? null,
|
|
2330
2328
|
stream: dtoContract?.stream ?? false,
|
|
2331
|
-
multipart: dtoContract?.multipart ?? false
|
|
2329
|
+
multipart: dtoContract?.multipart ?? false,
|
|
2330
|
+
multipartBody: dtoContract?.multipartBody ?? null
|
|
2332
2331
|
}
|
|
2333
2332
|
});
|
|
2334
2333
|
}
|
|
@@ -2939,7 +2938,15 @@ function emitRouterTypeBlock(tree, indent, outDir, serialization) {
|
|
|
2939
2938
|
const isFilterQuery = c.contractSource.filterSource === "query" && !!c.contractSource.filterFields?.length;
|
|
2940
2939
|
const query = queryRef ? queryRef.isArray ? `Array<${queryRef.name}>` : queryRef.name : isFilterQuery ? emitFilterQueryType(c) : c.contractSource.query ?? "never";
|
|
2941
2940
|
const bodyRef = c.contractSource.bodyRef;
|
|
2942
|
-
|
|
2941
|
+
let body = method === "GET" ? "never" : bodyRef ? bodyRef.isArray ? `Array<${bodyRef.name}>` : bodyRef.name : c.contractSource.body ?? "never";
|
|
2942
|
+
const multipartBody = c.contractSource.multipartBody;
|
|
2943
|
+
if (c.contractSource.multipart && multipartBody) {
|
|
2944
|
+
if (body === "never") {
|
|
2945
|
+
body = multipartBody;
|
|
2946
|
+
} else if (!bodyAcceptsAnything(body)) {
|
|
2947
|
+
body = `(${body}) & ${multipartBody}`;
|
|
2948
|
+
}
|
|
2949
|
+
}
|
|
2943
2950
|
const response = buildResponseType(c, outDir, serialization);
|
|
2944
2951
|
const error = buildErrorType(c);
|
|
2945
2952
|
const params = buildParamsType(c.params);
|
|
@@ -2958,6 +2965,25 @@ function emitRouterTypeBlock(tree, indent, outDir, serialization) {
|
|
|
2958
2965
|
}
|
|
2959
2966
|
return lines;
|
|
2960
2967
|
}
|
|
2968
|
+
function topLevelUnionArms(type) {
|
|
2969
|
+
const arms = [];
|
|
2970
|
+
let depth = 0;
|
|
2971
|
+
let start = 0;
|
|
2972
|
+
for (let i = 0; i < type.length; i++) {
|
|
2973
|
+
const ch = type[i];
|
|
2974
|
+
if (ch === "{" || ch === "[" || ch === "<" || ch === "(") depth++;
|
|
2975
|
+
else if (ch === "}" || ch === "]" || ch === ">" || ch === ")") depth--;
|
|
2976
|
+
else if (ch === "|" && depth === 0) {
|
|
2977
|
+
arms.push(type.slice(start, i).trim());
|
|
2978
|
+
start = i + 1;
|
|
2979
|
+
}
|
|
2980
|
+
}
|
|
2981
|
+
arms.push(type.slice(start).trim());
|
|
2982
|
+
return arms;
|
|
2983
|
+
}
|
|
2984
|
+
function bodyAcceptsAnything(body) {
|
|
2985
|
+
return topLevelUnionArms(body).some((arm) => arm === "unknown" || arm === "any");
|
|
2986
|
+
}
|
|
2961
2987
|
function buildRequestModel(c) {
|
|
2962
2988
|
const m = c.method.toLowerCase();
|
|
2963
2989
|
const flat = JSON.stringify(c.name);
|
|
@@ -4321,7 +4347,7 @@ async function acquireLock(outDir) {
|
|
|
4321
4347
|
}
|
|
4322
4348
|
|
|
4323
4349
|
// src/index.ts
|
|
4324
|
-
var VERSION = "0.13.
|
|
4350
|
+
var VERSION = "0.13.1";
|
|
4325
4351
|
|
|
4326
4352
|
// src/generate-manifest.ts
|
|
4327
4353
|
var MANIFEST_FILE = ".codegen-manifest.json";
|