@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/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor, S as SchemaNode, b as RenderContext, c as SchemaModule, d as RenderedModule, e as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext, f as SerializationMode } from './index-DvUzPXdh.cjs';
2
- export { A as AdapterUsage, g as ContractDescriptor, h as ContractSource, i as ControllerRef, N as NumberCheck, j as ScopeConfig, k as StringCheck, T as TypeRef, l as ValidationOption, r as resolveAdapter } from './index-DvUzPXdh.cjs';
1
+ import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor, S as SchemaNode, b as RenderContext, c as SchemaModule, d as RenderedModule, e as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext, f as SerializationMode } from './index-D8RIMVpU.cjs';
2
+ export { A as AdapterUsage, g as ContractDescriptor, h as ContractSource, i as ControllerRef, N as NumberCheck, j as ScopeConfig, k as StringCheck, T as TypeRef, l as ValidationOption, r as resolveAdapter } from './index-D8RIMVpU.cjs';
3
3
  import { ClassDeclaration, SourceFile, Project } from 'ts-morph';
4
4
 
5
5
  declare function defineConfig(c: UserConfig): UserConfig;
@@ -322,6 +322,6 @@ interface FastDiscoveryOptions {
322
322
  }
323
323
  declare function discoverContractsFast(opts: FastDiscoveryOptions): Promise<RouteDescriptor[]>;
324
324
 
325
- declare const VERSION = "0.13.0";
325
+ declare const VERSION = "0.13.2";
326
326
 
327
327
  export { type ChainModuleRendererOptions, CodegenError, type CodegenManifest, ConfigError, type FastDiscoveryOptions, type JsonSchema, type MocksEmitOptions, type OpenApiDocument, type OpenApiEmitOptions, type OpenApiInfo, RenderContext, RenderedModule, ResolvedConfig, RouteDescriptor, SchemaModule, SchemaNode, type TsTypeContext, UserConfig, VERSION, ValidationAdapter, type WatchOptions, type Watcher, acquireLock, buildMocksFile, buildOpenApiSpec, createChainModuleRenderer, defineConfig, discoverContractsFast, emitApi, emitForms, emitMocks, emitOpenApi, emitRoutes, extractSchemaFromDto, generate, loadConfig, renderTsType, resolveConfig, schemaModuleToJsonSchema, schemaNodeToJsonSchema, toObjectKey, typeNameFor, watch };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor, S as SchemaNode, b as RenderContext, c as SchemaModule, d as RenderedModule, e as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext, f as SerializationMode } from './index-DvUzPXdh.js';
2
- export { A as AdapterUsage, g as ContractDescriptor, h as ContractSource, i as ControllerRef, N as NumberCheck, j as ScopeConfig, k as StringCheck, T as TypeRef, l as ValidationOption, r as resolveAdapter } from './index-DvUzPXdh.js';
1
+ import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor, S as SchemaNode, b as RenderContext, c as SchemaModule, d as RenderedModule, e as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext, f as SerializationMode } from './index-D8RIMVpU.js';
2
+ export { A as AdapterUsage, g as ContractDescriptor, h as ContractSource, i as ControllerRef, N as NumberCheck, j as ScopeConfig, k as StringCheck, T as TypeRef, l as ValidationOption, r as resolveAdapter } from './index-D8RIMVpU.js';
3
3
  import { ClassDeclaration, SourceFile, Project } from 'ts-morph';
4
4
 
5
5
  declare function defineConfig(c: UserConfig): UserConfig;
@@ -322,6 +322,6 @@ interface FastDiscoveryOptions {
322
322
  }
323
323
  declare function discoverContractsFast(opts: FastDiscoveryOptions): Promise<RouteDescriptor[]>;
324
324
 
325
- declare const VERSION = "0.13.0";
325
+ declare const VERSION = "0.13.2";
326
326
 
327
327
  export { type ChainModuleRendererOptions, CodegenError, type CodegenManifest, ConfigError, type FastDiscoveryOptions, type JsonSchema, type MocksEmitOptions, type OpenApiDocument, type OpenApiEmitOptions, type OpenApiInfo, RenderContext, RenderedModule, ResolvedConfig, RouteDescriptor, SchemaModule, SchemaNode, type TsTypeContext, UserConfig, VERSION, ValidationAdapter, type WatchOptions, type Watcher, acquireLock, buildMocksFile, buildOpenApiSpec, createChainModuleRenderer, defineConfig, discoverContractsFast, emitApi, emitForms, emitMocks, emitOpenApi, emitRoutes, extractSchemaFromDto, generate, loadConfig, renderTsType, resolveConfig, schemaModuleToJsonSchema, schemaNodeToJsonSchema, toObjectKey, typeNameFor, watch };
package/dist/index.js CHANGED
@@ -756,7 +756,15 @@ function emitRouterTypeBlock(tree, indent, outDir, serialization) {
756
756
  const isFilterQuery = c.contractSource.filterSource === "query" && !!c.contractSource.filterFields?.length;
757
757
  const query = queryRef ? queryRef.isArray ? `Array<${queryRef.name}>` : queryRef.name : isFilterQuery ? emitFilterQueryType(c) : c.contractSource.query ?? "never";
758
758
  const bodyRef = c.contractSource.bodyRef;
759
- const body = method === "GET" ? "never" : bodyRef ? bodyRef.isArray ? `Array<${bodyRef.name}>` : bodyRef.name : c.contractSource.body ?? "never";
759
+ let body = method === "GET" ? "never" : bodyRef ? bodyRef.isArray ? `Array<${bodyRef.name}>` : bodyRef.name : c.contractSource.body ?? "never";
760
+ const multipartBody = c.contractSource.multipartBody;
761
+ if (c.contractSource.multipart && multipartBody) {
762
+ if (body === "never") {
763
+ body = multipartBody;
764
+ } else if (!bodyAcceptsAnything(body)) {
765
+ body = `(${body}) & ${multipartBody}`;
766
+ }
767
+ }
760
768
  const response = buildResponseType(c, outDir, serialization);
761
769
  const error = buildErrorType(c);
762
770
  const params = buildParamsType(c.params);
@@ -775,6 +783,25 @@ function emitRouterTypeBlock(tree, indent, outDir, serialization) {
775
783
  }
776
784
  return lines;
777
785
  }
786
+ function topLevelUnionArms(type) {
787
+ const arms = [];
788
+ let depth = 0;
789
+ let start = 0;
790
+ for (let i = 0; i < type.length; i++) {
791
+ const ch = type[i];
792
+ if (ch === "{" || ch === "[" || ch === "<" || ch === "(") depth++;
793
+ else if (ch === "}" || ch === "]" || ch === ">" || ch === ")") depth--;
794
+ else if (ch === "|" && depth === 0) {
795
+ arms.push(type.slice(start, i).trim());
796
+ start = i + 1;
797
+ }
798
+ }
799
+ arms.push(type.slice(start).trim());
800
+ return arms;
801
+ }
802
+ function bodyAcceptsAnything(body) {
803
+ return topLevelUnionArms(body).some((arm) => arm === "unknown" || arm === "any");
804
+ }
778
805
  function buildRequestModel(c) {
779
806
  const m = c.method.toLowerCase();
780
807
  const flat = JSON.stringify(c.name);
@@ -3568,6 +3595,19 @@ function resolveTypeNodeToString(typeNode, sourceFile, project, depth, subst = /
3568
3595
  dbg("unresolvable type:", name, "in", sourceFile.getFilePath());
3569
3596
  return "unknown";
3570
3597
  }
3598
+ if (Node6.isTypeLiteral(typeNode)) {
3599
+ const members = [];
3600
+ for (const member of typeNode.getMembers()) {
3601
+ if (Node6.isPropertySignature(member)) {
3602
+ const memberTypeNode = member.getTypeNode();
3603
+ const memberType = memberTypeNode ? resolveTypeNodeToString(memberTypeNode, sourceFile, project, depth, subst) : "unknown";
3604
+ members.push(`${member.getName()}${member.hasQuestionToken() ? "?" : ""}: ${memberType}`);
3605
+ } else {
3606
+ members.push(member.getText());
3607
+ }
3608
+ }
3609
+ return members.length > 0 ? `{ ${members.join("; ")} }` : "{}";
3610
+ }
3571
3611
  const kind = typeNode.getKind();
3572
3612
  if (kind === SyntaxKind3.StringKeyword) return "string";
3573
3613
  if (kind === SyntaxKind3.NumberKeyword) return "number";
@@ -3874,10 +3914,7 @@ function extractDtoContract(method, sourceFile, project) {
3874
3914
  const filterInfo = extractApplyFilterInfo(method, sourceFile, project);
3875
3915
  const query = extractQueryType(method, sourceFile, project);
3876
3916
  const uploads = extractUploadedFiles(method);
3877
- if (uploads.fields) {
3878
- const fileObject = `{ ${uploads.fields} }`;
3879
- body = body ? `(${body}) & ${fileObject}` : fileObject;
3880
- }
3917
+ const multipartBody = uploads.fields ? `{ ${uploads.fields} }` : null;
3881
3918
  const streamElement = detectStreamElement(method);
3882
3919
  const isStream = streamElement !== null;
3883
3920
  if (filterInfo && filterInfo.source === "body") {
@@ -3961,7 +3998,8 @@ function extractDtoContract(method, sourceFile, project) {
3961
3998
  bodySchema,
3962
3999
  querySchema,
3963
4000
  stream: isStream,
3964
- multipart: uploads.multipart
4001
+ multipart: uploads.multipart,
4002
+ multipartBody
3965
4003
  };
3966
4004
  }
3967
4005
  function resolveParamClass(method, decoratorName, sourceFile, project) {
@@ -4447,7 +4485,8 @@ function extractDtoRoute(args) {
4447
4485
  bodySchema: dtoContract?.bodySchema ?? null,
4448
4486
  querySchema: dtoContract?.querySchema ?? null,
4449
4487
  stream: dtoContract?.stream ?? false,
4450
- multipart: dtoContract?.multipart ?? false
4488
+ multipart: dtoContract?.multipart ?? false,
4489
+ multipartBody: dtoContract?.multipartBody ?? null
4451
4490
  }
4452
4491
  });
4453
4492
  }
@@ -4760,7 +4799,7 @@ function createChainModuleRenderer(opts) {
4760
4799
  }
4761
4800
 
4762
4801
  // src/index.ts
4763
- var VERSION = "0.13.0";
4802
+ var VERSION = "0.13.2";
4764
4803
  export {
4765
4804
  CodegenError,
4766
4805
  ConfigError,