@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.
@@ -1,5 +1,5 @@
1
1
  import { DynamicModule, OnApplicationBootstrap, OnModuleDestroy } from '@nestjs/common';
2
- import { U as UserConfig } from '../index-DvUzPXdh.cjs';
2
+ import { U as UserConfig } from '../index-D8RIMVpU.cjs';
3
3
  import 'ts-morph';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  import { DynamicModule, OnApplicationBootstrap, OnModuleDestroy } from '@nestjs/common';
2
- import { U as UserConfig } from '../index-DvUzPXdh.js';
2
+ import { U as UserConfig } from '../index-D8RIMVpU.js';
3
3
  import 'ts-morph';
4
4
 
5
5
  /**
@@ -1446,6 +1446,19 @@ function resolveTypeNodeToString(typeNode, sourceFile, project, depth, subst = /
1446
1446
  dbg("unresolvable type:", name, "in", sourceFile.getFilePath());
1447
1447
  return "unknown";
1448
1448
  }
1449
+ if (Node5.isTypeLiteral(typeNode)) {
1450
+ const members = [];
1451
+ for (const member of typeNode.getMembers()) {
1452
+ if (Node5.isPropertySignature(member)) {
1453
+ const memberTypeNode = member.getTypeNode();
1454
+ const memberType = memberTypeNode ? resolveTypeNodeToString(memberTypeNode, sourceFile, project, depth, subst) : "unknown";
1455
+ members.push(`${member.getName()}${member.hasQuestionToken() ? "?" : ""}: ${memberType}`);
1456
+ } else {
1457
+ members.push(member.getText());
1458
+ }
1459
+ }
1460
+ return members.length > 0 ? `{ ${members.join("; ")} }` : "{}";
1461
+ }
1449
1462
  const kind = typeNode.getKind();
1450
1463
  if (kind === SyntaxKind2.StringKeyword) return "string";
1451
1464
  if (kind === SyntaxKind2.NumberKeyword) return "number";
@@ -1752,10 +1765,7 @@ function extractDtoContract(method, sourceFile, project) {
1752
1765
  const filterInfo = extractApplyFilterInfo(method, sourceFile, project);
1753
1766
  const query = extractQueryType(method, sourceFile, project);
1754
1767
  const uploads = extractUploadedFiles(method);
1755
- if (uploads.fields) {
1756
- const fileObject = `{ ${uploads.fields} }`;
1757
- body = body ? `(${body}) & ${fileObject}` : fileObject;
1758
- }
1768
+ const multipartBody = uploads.fields ? `{ ${uploads.fields} }` : null;
1759
1769
  const streamElement = detectStreamElement(method);
1760
1770
  const isStream = streamElement !== null;
1761
1771
  if (filterInfo && filterInfo.source === "body") {
@@ -1839,7 +1849,8 @@ function extractDtoContract(method, sourceFile, project) {
1839
1849
  bodySchema,
1840
1850
  querySchema,
1841
1851
  stream: isStream,
1842
- multipart: uploads.multipart
1852
+ multipart: uploads.multipart,
1853
+ multipartBody
1843
1854
  };
1844
1855
  }
1845
1856
  function resolveParamClass(method, decoratorName, sourceFile, project) {
@@ -2307,7 +2318,8 @@ function extractDtoRoute(args) {
2307
2318
  bodySchema: dtoContract?.bodySchema ?? null,
2308
2319
  querySchema: dtoContract?.querySchema ?? null,
2309
2320
  stream: dtoContract?.stream ?? false,
2310
- multipart: dtoContract?.multipart ?? false
2321
+ multipart: dtoContract?.multipart ?? false,
2322
+ multipartBody: dtoContract?.multipartBody ?? null
2311
2323
  }
2312
2324
  });
2313
2325
  }
@@ -2918,7 +2930,15 @@ function emitRouterTypeBlock(tree, indent, outDir, serialization) {
2918
2930
  const isFilterQuery = c.contractSource.filterSource === "query" && !!c.contractSource.filterFields?.length;
2919
2931
  const query = queryRef ? queryRef.isArray ? `Array<${queryRef.name}>` : queryRef.name : isFilterQuery ? emitFilterQueryType(c) : c.contractSource.query ?? "never";
2920
2932
  const bodyRef = c.contractSource.bodyRef;
2921
- const body = method === "GET" ? "never" : bodyRef ? bodyRef.isArray ? `Array<${bodyRef.name}>` : bodyRef.name : c.contractSource.body ?? "never";
2933
+ let body = method === "GET" ? "never" : bodyRef ? bodyRef.isArray ? `Array<${bodyRef.name}>` : bodyRef.name : c.contractSource.body ?? "never";
2934
+ const multipartBody = c.contractSource.multipartBody;
2935
+ if (c.contractSource.multipart && multipartBody) {
2936
+ if (body === "never") {
2937
+ body = multipartBody;
2938
+ } else if (!bodyAcceptsAnything(body)) {
2939
+ body = `(${body}) & ${multipartBody}`;
2940
+ }
2941
+ }
2922
2942
  const response = buildResponseType(c, outDir, serialization);
2923
2943
  const error = buildErrorType(c);
2924
2944
  const params = buildParamsType(c.params);
@@ -2937,6 +2957,25 @@ function emitRouterTypeBlock(tree, indent, outDir, serialization) {
2937
2957
  }
2938
2958
  return lines;
2939
2959
  }
2960
+ function topLevelUnionArms(type) {
2961
+ const arms = [];
2962
+ let depth = 0;
2963
+ let start = 0;
2964
+ for (let i = 0; i < type.length; i++) {
2965
+ const ch = type[i];
2966
+ if (ch === "{" || ch === "[" || ch === "<" || ch === "(") depth++;
2967
+ else if (ch === "}" || ch === "]" || ch === ">" || ch === ")") depth--;
2968
+ else if (ch === "|" && depth === 0) {
2969
+ arms.push(type.slice(start, i).trim());
2970
+ start = i + 1;
2971
+ }
2972
+ }
2973
+ arms.push(type.slice(start).trim());
2974
+ return arms;
2975
+ }
2976
+ function bodyAcceptsAnything(body) {
2977
+ return topLevelUnionArms(body).some((arm) => arm === "unknown" || arm === "any");
2978
+ }
2940
2979
  function buildRequestModel(c) {
2941
2980
  const m = c.method.toLowerCase();
2942
2981
  const flat = JSON.stringify(c.name);
@@ -4300,7 +4339,7 @@ async function acquireLock(outDir) {
4300
4339
  }
4301
4340
 
4302
4341
  // src/index.ts
4303
- var VERSION = "0.13.0";
4342
+ var VERSION = "0.13.2";
4304
4343
 
4305
4344
  // src/generate-manifest.ts
4306
4345
  var MANIFEST_FILE = ".codegen-manifest.json";