@dudousxd/nestjs-codegen 0.12.0 → 0.13.0

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-CxkGbILp.cjs';
2
+ import { U as UserConfig } from '../index-DvUzPXdh.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-CxkGbILp.js';
2
+ import { U as UserConfig } from '../index-DvUzPXdh.js';
3
3
  import 'ts-morph';
4
4
 
5
5
  /**
@@ -1568,6 +1568,55 @@ function extractParamsType(method, sourceFile, project) {
1568
1568
  }
1569
1569
  return entries.length > 0 ? `{ ${entries.join("; ")} }` : null;
1570
1570
  }
1571
+ function extractUploadedFiles(method) {
1572
+ const FILE = "File | Blob";
1573
+ const entries = [];
1574
+ let multipart = false;
1575
+ const hasUploadedFileParam = method.getParameters().some(
1576
+ (p) => p.getDecorators().some((d) => {
1577
+ const name = d.getName();
1578
+ return name === "UploadedFile" || name === "UploadedFiles";
1579
+ })
1580
+ );
1581
+ for (const decorator of method.getDecorators()) {
1582
+ if (decorator.getName() !== "UseInterceptors") continue;
1583
+ for (const arg of decorator.getArguments()) {
1584
+ if (!Node5.isCallExpression(arg)) continue;
1585
+ const interceptor = arg.getExpression().getText();
1586
+ const callArgs = arg.getArguments();
1587
+ const firstArg2 = callArgs[0];
1588
+ if (interceptor === "FileInterceptor") {
1589
+ if (firstArg2 && Node5.isStringLiteral(firstArg2)) {
1590
+ entries.push(`${firstArg2.getLiteralValue()}: ${FILE}`);
1591
+ multipart = true;
1592
+ }
1593
+ } else if (interceptor === "FilesInterceptor") {
1594
+ if (firstArg2 && Node5.isStringLiteral(firstArg2)) {
1595
+ entries.push(`${firstArg2.getLiteralValue()}: Array<${FILE}>`);
1596
+ multipart = true;
1597
+ }
1598
+ } else if (interceptor === "FileFieldsInterceptor") {
1599
+ if (firstArg2 && Node5.isArrayLiteralExpression(firstArg2)) {
1600
+ for (const el of firstArg2.getElements()) {
1601
+ if (!Node5.isObjectLiteralExpression(el)) continue;
1602
+ const nameProp = el.getProperty("name");
1603
+ if (nameProp && Node5.isPropertyAssignment(nameProp)) {
1604
+ const init = nameProp.getInitializer();
1605
+ if (init && Node5.isStringLiteral(init)) {
1606
+ entries.push(`${init.getLiteralValue()}: Array<${FILE}>`);
1607
+ }
1608
+ }
1609
+ }
1610
+ multipart = true;
1611
+ }
1612
+ } else if (interceptor === "AnyFilesInterceptor") {
1613
+ multipart = true;
1614
+ }
1615
+ }
1616
+ }
1617
+ if (hasUploadedFileParam) multipart = true;
1618
+ return { fields: entries.length > 0 ? entries.join("; ") : null, multipart };
1619
+ }
1571
1620
  function extractResponseType(method, sourceFile, project) {
1572
1621
  const apiResponseDecorator = method.getDecorators().find((d) => d.getName() === "ApiResponse" && (apiResponseStatus(d) ?? 0) < 400);
1573
1622
  if (apiResponseDecorator) {
@@ -1702,6 +1751,11 @@ function extractDtoContract(method, sourceFile, project) {
1702
1751
  let body = extractBodyType(method, sourceFile, project);
1703
1752
  const filterInfo = extractApplyFilterInfo(method, sourceFile, project);
1704
1753
  const query = extractQueryType(method, sourceFile, project);
1754
+ const uploads = extractUploadedFiles(method);
1755
+ if (uploads.fields) {
1756
+ const fileObject = `{ ${uploads.fields} }`;
1757
+ body = body ? `(${body}) & ${fileObject}` : fileObject;
1758
+ }
1705
1759
  const streamElement = detectStreamElement(method);
1706
1760
  const isStream = streamElement !== null;
1707
1761
  if (filterInfo && filterInfo.source === "body") {
@@ -1711,7 +1765,7 @@ function extractDtoContract(method, sourceFile, project) {
1711
1765
  const paramsType = extractParamsType(method, sourceFile, project);
1712
1766
  const response = isStream ? resolveTypeNodeToString(streamElement, sourceFile, project, 3) : extractResponseType(method, sourceFile, project);
1713
1767
  const errorInfo = extractErrorType(method, sourceFile, project);
1714
- if (body === null && query === null && paramsType === null && response === "unknown" && errorInfo === null && filterInfo === null && !isStream) {
1768
+ if (body === null && query === null && paramsType === null && response === "unknown" && errorInfo === null && filterInfo === null && !isStream && !uploads.multipart) {
1715
1769
  return null;
1716
1770
  }
1717
1771
  let bodyRef = null;
@@ -1784,7 +1838,8 @@ function extractDtoContract(method, sourceFile, project) {
1784
1838
  formWarnings,
1785
1839
  bodySchema,
1786
1840
  querySchema,
1787
- stream: isStream
1841
+ stream: isStream,
1842
+ multipart: uploads.multipart
1788
1843
  };
1789
1844
  }
1790
1845
  function resolveParamClass(method, decoratorName, sourceFile, project) {
@@ -2251,7 +2306,8 @@ function extractDtoRoute(args) {
2251
2306
  formWarnings: dtoContract?.formWarnings ?? [],
2252
2307
  bodySchema: dtoContract?.bodySchema ?? null,
2253
2308
  querySchema: dtoContract?.querySchema ?? null,
2254
- stream: dtoContract?.stream ?? false
2309
+ stream: dtoContract?.stream ?? false,
2310
+ multipart: dtoContract?.multipart ?? false
2255
2311
  }
2256
2312
  });
2257
2313
  }
@@ -2897,6 +2953,7 @@ function buildRequestModel(c) {
2897
2953
  const optsParts = [];
2898
2954
  if (hasQuery) optsParts.push("query: input?.query as Record<string, unknown> | undefined");
2899
2955
  if (hasBody) optsParts.push("body: input?.body");
2956
+ if (hasBody && c.contractSource.multipart) optsParts.push("multipart: true");
2900
2957
  const optsExpr = optsParts.length ? `{ ${optsParts.join(", ")} }` : "{}";
2901
2958
  return {
2902
2959
  routeName: c.name,
@@ -4243,7 +4300,7 @@ async function acquireLock(outDir) {
4243
4300
  }
4244
4301
 
4245
4302
  // src/index.ts
4246
- var VERSION = "0.12.0";
4303
+ var VERSION = "0.13.0";
4247
4304
 
4248
4305
  // src/generate-manifest.ts
4249
4306
  var MANIFEST_FILE = ".codegen-manifest.json";