@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.d.cts
CHANGED
package/dist/nest/index.d.ts
CHANGED
package/dist/nest/index.js
CHANGED
|
@@ -1752,10 +1752,7 @@ function extractDtoContract(method, sourceFile, project) {
|
|
|
1752
1752
|
const filterInfo = extractApplyFilterInfo(method, sourceFile, project);
|
|
1753
1753
|
const query = extractQueryType(method, sourceFile, project);
|
|
1754
1754
|
const uploads = extractUploadedFiles(method);
|
|
1755
|
-
|
|
1756
|
-
const fileObject = `{ ${uploads.fields} }`;
|
|
1757
|
-
body = body ? `(${body}) & ${fileObject}` : fileObject;
|
|
1758
|
-
}
|
|
1755
|
+
const multipartBody = uploads.fields ? `{ ${uploads.fields} }` : null;
|
|
1759
1756
|
const streamElement = detectStreamElement(method);
|
|
1760
1757
|
const isStream = streamElement !== null;
|
|
1761
1758
|
if (filterInfo && filterInfo.source === "body") {
|
|
@@ -1839,7 +1836,8 @@ function extractDtoContract(method, sourceFile, project) {
|
|
|
1839
1836
|
bodySchema,
|
|
1840
1837
|
querySchema,
|
|
1841
1838
|
stream: isStream,
|
|
1842
|
-
multipart: uploads.multipart
|
|
1839
|
+
multipart: uploads.multipart,
|
|
1840
|
+
multipartBody
|
|
1843
1841
|
};
|
|
1844
1842
|
}
|
|
1845
1843
|
function resolveParamClass(method, decoratorName, sourceFile, project) {
|
|
@@ -2307,7 +2305,8 @@ function extractDtoRoute(args) {
|
|
|
2307
2305
|
bodySchema: dtoContract?.bodySchema ?? null,
|
|
2308
2306
|
querySchema: dtoContract?.querySchema ?? null,
|
|
2309
2307
|
stream: dtoContract?.stream ?? false,
|
|
2310
|
-
multipart: dtoContract?.multipart ?? false
|
|
2308
|
+
multipart: dtoContract?.multipart ?? false,
|
|
2309
|
+
multipartBody: dtoContract?.multipartBody ?? null
|
|
2311
2310
|
}
|
|
2312
2311
|
});
|
|
2313
2312
|
}
|
|
@@ -2918,7 +2917,15 @@ function emitRouterTypeBlock(tree, indent, outDir, serialization) {
|
|
|
2918
2917
|
const isFilterQuery = c.contractSource.filterSource === "query" && !!c.contractSource.filterFields?.length;
|
|
2919
2918
|
const query = queryRef ? queryRef.isArray ? `Array<${queryRef.name}>` : queryRef.name : isFilterQuery ? emitFilterQueryType(c) : c.contractSource.query ?? "never";
|
|
2920
2919
|
const bodyRef = c.contractSource.bodyRef;
|
|
2921
|
-
|
|
2920
|
+
let body = method === "GET" ? "never" : bodyRef ? bodyRef.isArray ? `Array<${bodyRef.name}>` : bodyRef.name : c.contractSource.body ?? "never";
|
|
2921
|
+
const multipartBody = c.contractSource.multipartBody;
|
|
2922
|
+
if (c.contractSource.multipart && multipartBody) {
|
|
2923
|
+
if (body === "never") {
|
|
2924
|
+
body = multipartBody;
|
|
2925
|
+
} else if (!bodyAcceptsAnything(body)) {
|
|
2926
|
+
body = `(${body}) & ${multipartBody}`;
|
|
2927
|
+
}
|
|
2928
|
+
}
|
|
2922
2929
|
const response = buildResponseType(c, outDir, serialization);
|
|
2923
2930
|
const error = buildErrorType(c);
|
|
2924
2931
|
const params = buildParamsType(c.params);
|
|
@@ -2937,6 +2944,25 @@ function emitRouterTypeBlock(tree, indent, outDir, serialization) {
|
|
|
2937
2944
|
}
|
|
2938
2945
|
return lines;
|
|
2939
2946
|
}
|
|
2947
|
+
function topLevelUnionArms(type) {
|
|
2948
|
+
const arms = [];
|
|
2949
|
+
let depth = 0;
|
|
2950
|
+
let start = 0;
|
|
2951
|
+
for (let i = 0; i < type.length; i++) {
|
|
2952
|
+
const ch = type[i];
|
|
2953
|
+
if (ch === "{" || ch === "[" || ch === "<" || ch === "(") depth++;
|
|
2954
|
+
else if (ch === "}" || ch === "]" || ch === ">" || ch === ")") depth--;
|
|
2955
|
+
else if (ch === "|" && depth === 0) {
|
|
2956
|
+
arms.push(type.slice(start, i).trim());
|
|
2957
|
+
start = i + 1;
|
|
2958
|
+
}
|
|
2959
|
+
}
|
|
2960
|
+
arms.push(type.slice(start).trim());
|
|
2961
|
+
return arms;
|
|
2962
|
+
}
|
|
2963
|
+
function bodyAcceptsAnything(body) {
|
|
2964
|
+
return topLevelUnionArms(body).some((arm) => arm === "unknown" || arm === "any");
|
|
2965
|
+
}
|
|
2940
2966
|
function buildRequestModel(c) {
|
|
2941
2967
|
const m = c.method.toLowerCase();
|
|
2942
2968
|
const flat = JSON.stringify(c.name);
|
|
@@ -4300,7 +4326,7 @@ async function acquireLock(outDir) {
|
|
|
4300
4326
|
}
|
|
4301
4327
|
|
|
4302
4328
|
// src/index.ts
|
|
4303
|
-
var VERSION = "0.13.
|
|
4329
|
+
var VERSION = "0.13.1";
|
|
4304
4330
|
|
|
4305
4331
|
// src/generate-manifest.ts
|
|
4306
4332
|
var MANIFEST_FILE = ".codegen-manifest.json";
|