@dudousxd/nestjs-codegen 0.5.1 → 0.6.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-B0mS84Jj.cjs';
2
+ import { U as UserConfig } from '../index-_qRai4M3.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-B0mS84Jj.js';
2
+ import { U as UserConfig } from '../index-_qRai4M3.js';
3
3
  import 'ts-morph';
4
4
 
5
5
  /**
@@ -257,7 +257,6 @@ function resolveImportedType(name, sourceFile, project) {
257
257
  if (!namedImport) continue;
258
258
  const moduleSpecifier = importDecl.getModuleSpecifierValue();
259
259
  const candidates = resolveModuleSpecifier(moduleSpecifier, sourceFile, project);
260
- if (candidates.length === 0) continue;
261
260
  for (const candidate of candidates) {
262
261
  let importedFile = project.getSourceFile(candidate);
263
262
  if (!importedFile) {
@@ -272,9 +271,25 @@ function resolveImportedType(name, sourceFile, project) {
272
271
  const viaReExport = resolveReExportedType(name, importedFile, project, /* @__PURE__ */ new Set());
273
272
  if (viaReExport) return viaReExport;
274
273
  }
274
+ if (candidates.length === 0) {
275
+ const viaCompiler = resolveBareSpecifierType(name, importDecl, project);
276
+ if (viaCompiler) return viaCompiler;
277
+ }
275
278
  }
276
279
  return resolveReExportedType(name, sourceFile, project, /* @__PURE__ */ new Set());
277
280
  }
281
+ function resolveBareSpecifierType(name, importDecl, project) {
282
+ let target;
283
+ try {
284
+ target = importDecl.getModuleSpecifierSourceFile();
285
+ } catch {
286
+ return null;
287
+ }
288
+ if (!target) return null;
289
+ const direct = findTypeInFile(name, target);
290
+ if (direct) return direct;
291
+ return resolveReExportedType(name, target, project, /* @__PURE__ */ new Set());
292
+ }
278
293
  function resolveReExportedType(name, file, project, seen) {
279
294
  const filePath = file.getFilePath();
280
295
  if (seen.has(filePath)) return null;
@@ -558,37 +573,28 @@ function buildProperty(prop, classFile, ctx) {
558
573
  const typeNode = prop.getTypeNode();
559
574
  const typeText = typeNode?.getText() ?? "unknown";
560
575
  const isArrayType = !!typeNode && Node2.isArrayTypeNode(typeNode);
576
+ const asField = (child) => applyPresence(
577
+ has("IsArray") || isArrayType ? { kind: "array", element: child } : child,
578
+ decorators
579
+ );
561
580
  const discriminator = resolveDiscriminator(dec("Type"));
562
581
  if (discriminator) {
563
582
  const options = discriminator.subTypes.map(
564
583
  (name) => buildNestedReference(name, classFile, ctx)
565
584
  );
566
- const unionNode = {
567
- kind: "union",
568
- options,
569
- discriminator: discriminator.property
570
- };
571
- const wrapArray = has("IsArray") || isArrayType;
572
- const node2 = wrapArray ? { kind: "array", element: unionNode } : unionNode;
573
- return applyPresence(node2, decorators);
585
+ return asField({ kind: "union", options, discriminator: discriminator.property });
574
586
  }
575
587
  const propTypeParam = singularClassName(typeText);
576
588
  if (propTypeParam && ctx.typeBindings.has(propTypeParam)) {
577
589
  const bound = ctx.typeBindings.get(propTypeParam);
578
- const childNode = buildNestedReference(bound, classFile, ctx);
579
- const wrapArray = has("IsArray") || isArrayType;
580
- const node2 = wrapArray ? { kind: "array", element: childNode } : childNode;
581
- return applyPresence(node2, decorators);
590
+ return asField(buildNestedReference(bound, classFile, ctx));
582
591
  }
583
592
  const typeRefName = resolveTypeFactoryName(dec("Type"));
584
593
  if (has("ValidateNested") || typeRefName) {
585
594
  const typeArgs = genericTypeArgNames(typeNode);
586
595
  const childName = typeRefName ?? singularClassName(typeText);
587
596
  if (childName) {
588
- const childNode = buildNestedReference(childName, classFile, ctx, typeArgs);
589
- const wrapArray = has("IsArray") || isArrayType;
590
- const node2 = wrapArray ? { kind: "array", element: childNode } : childNode;
591
- return applyPresence(node2, decorators);
597
+ return asField(buildNestedReference(childName, classFile, ctx, typeArgs));
592
598
  }
593
599
  }
594
600
  let base = baseFromType(typeText, isArrayType);