@dudousxd/nestjs-codegen 0.13.0 → 0.13.2
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 +26 -0
- package/dist/cli/main.cjs +47 -8
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +47 -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 +47 -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 +47 -8
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +47 -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 +47 -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);
|
|
@@ -3560,6 +3587,19 @@ function resolveTypeNodeToString(typeNode, sourceFile, project, depth, subst = /
|
|
|
3560
3587
|
dbg("unresolvable type:", name, "in", sourceFile.getFilePath());
|
|
3561
3588
|
return "unknown";
|
|
3562
3589
|
}
|
|
3590
|
+
if (Node6.isTypeLiteral(typeNode)) {
|
|
3591
|
+
const members = [];
|
|
3592
|
+
for (const member of typeNode.getMembers()) {
|
|
3593
|
+
if (Node6.isPropertySignature(member)) {
|
|
3594
|
+
const memberTypeNode = member.getTypeNode();
|
|
3595
|
+
const memberType = memberTypeNode ? resolveTypeNodeToString(memberTypeNode, sourceFile, project, depth, subst) : "unknown";
|
|
3596
|
+
members.push(`${member.getName()}${member.hasQuestionToken() ? "?" : ""}: ${memberType}`);
|
|
3597
|
+
} else {
|
|
3598
|
+
members.push(member.getText());
|
|
3599
|
+
}
|
|
3600
|
+
}
|
|
3601
|
+
return members.length > 0 ? `{ ${members.join("; ")} }` : "{}";
|
|
3602
|
+
}
|
|
3563
3603
|
const kind = typeNode.getKind();
|
|
3564
3604
|
if (kind === SyntaxKind3.StringKeyword) return "string";
|
|
3565
3605
|
if (kind === SyntaxKind3.NumberKeyword) return "number";
|
|
@@ -3866,10 +3906,7 @@ function extractDtoContract(method, sourceFile, project) {
|
|
|
3866
3906
|
const filterInfo = extractApplyFilterInfo(method, sourceFile, project);
|
|
3867
3907
|
const query = extractQueryType(method, sourceFile, project);
|
|
3868
3908
|
const uploads = extractUploadedFiles(method);
|
|
3869
|
-
|
|
3870
|
-
const fileObject = `{ ${uploads.fields} }`;
|
|
3871
|
-
body = body ? `(${body}) & ${fileObject}` : fileObject;
|
|
3872
|
-
}
|
|
3909
|
+
const multipartBody = uploads.fields ? `{ ${uploads.fields} }` : null;
|
|
3873
3910
|
const streamElement = detectStreamElement(method);
|
|
3874
3911
|
const isStream = streamElement !== null;
|
|
3875
3912
|
if (filterInfo && filterInfo.source === "body") {
|
|
@@ -3953,7 +3990,8 @@ function extractDtoContract(method, sourceFile, project) {
|
|
|
3953
3990
|
bodySchema,
|
|
3954
3991
|
querySchema,
|
|
3955
3992
|
stream: isStream,
|
|
3956
|
-
multipart: uploads.multipart
|
|
3993
|
+
multipart: uploads.multipart,
|
|
3994
|
+
multipartBody
|
|
3957
3995
|
};
|
|
3958
3996
|
}
|
|
3959
3997
|
function resolveParamClass(method, decoratorName, sourceFile, project) {
|
|
@@ -4439,7 +4477,8 @@ function extractDtoRoute(args) {
|
|
|
4439
4477
|
bodySchema: dtoContract?.bodySchema ?? null,
|
|
4440
4478
|
querySchema: dtoContract?.querySchema ?? null,
|
|
4441
4479
|
stream: dtoContract?.stream ?? false,
|
|
4442
|
-
multipart: dtoContract?.multipart ?? false
|
|
4480
|
+
multipart: dtoContract?.multipart ?? false,
|
|
4481
|
+
multipartBody: dtoContract?.multipartBody ?? null
|
|
4443
4482
|
}
|
|
4444
4483
|
});
|
|
4445
4484
|
}
|
|
@@ -4669,7 +4708,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
4669
4708
|
}
|
|
4670
4709
|
|
|
4671
4710
|
// src/index.ts
|
|
4672
|
-
var VERSION = "0.13.
|
|
4711
|
+
var VERSION = "0.13.2";
|
|
4673
4712
|
|
|
4674
4713
|
// src/cli/codegen.ts
|
|
4675
4714
|
async function runCodegen(opts = {}) {
|