@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.
@@ -283,7 +283,6 @@ function resolveImportedType(name, sourceFile, project) {
283
283
  if (!namedImport) continue;
284
284
  const moduleSpecifier = importDecl.getModuleSpecifierValue();
285
285
  const candidates = resolveModuleSpecifier(moduleSpecifier, sourceFile, project);
286
- if (candidates.length === 0) continue;
287
286
  for (const candidate of candidates) {
288
287
  let importedFile = project.getSourceFile(candidate);
289
288
  if (!importedFile) {
@@ -298,9 +297,25 @@ function resolveImportedType(name, sourceFile, project) {
298
297
  const viaReExport = resolveReExportedType(name, importedFile, project, /* @__PURE__ */ new Set());
299
298
  if (viaReExport) return viaReExport;
300
299
  }
300
+ if (candidates.length === 0) {
301
+ const viaCompiler = resolveBareSpecifierType(name, importDecl, project);
302
+ if (viaCompiler) return viaCompiler;
303
+ }
301
304
  }
302
305
  return resolveReExportedType(name, sourceFile, project, /* @__PURE__ */ new Set());
303
306
  }
307
+ function resolveBareSpecifierType(name, importDecl, project) {
308
+ let target;
309
+ try {
310
+ target = importDecl.getModuleSpecifierSourceFile();
311
+ } catch {
312
+ return null;
313
+ }
314
+ if (!target) return null;
315
+ const direct = findTypeInFile(name, target);
316
+ if (direct) return direct;
317
+ return resolveReExportedType(name, target, project, /* @__PURE__ */ new Set());
318
+ }
304
319
  function resolveReExportedType(name, file, project, seen) {
305
320
  const filePath = file.getFilePath();
306
321
  if (seen.has(filePath)) return null;
@@ -584,37 +599,28 @@ function buildProperty(prop, classFile, ctx) {
584
599
  const typeNode = prop.getTypeNode();
585
600
  const typeText = typeNode?.getText() ?? "unknown";
586
601
  const isArrayType = !!typeNode && import_ts_morph2.Node.isArrayTypeNode(typeNode);
602
+ const asField = (child) => applyPresence(
603
+ has("IsArray") || isArrayType ? { kind: "array", element: child } : child,
604
+ decorators
605
+ );
587
606
  const discriminator = resolveDiscriminator(dec("Type"));
588
607
  if (discriminator) {
589
608
  const options = discriminator.subTypes.map(
590
609
  (name) => buildNestedReference(name, classFile, ctx)
591
610
  );
592
- const unionNode = {
593
- kind: "union",
594
- options,
595
- discriminator: discriminator.property
596
- };
597
- const wrapArray = has("IsArray") || isArrayType;
598
- const node2 = wrapArray ? { kind: "array", element: unionNode } : unionNode;
599
- return applyPresence(node2, decorators);
611
+ return asField({ kind: "union", options, discriminator: discriminator.property });
600
612
  }
601
613
  const propTypeParam = singularClassName(typeText);
602
614
  if (propTypeParam && ctx.typeBindings.has(propTypeParam)) {
603
615
  const bound = ctx.typeBindings.get(propTypeParam);
604
- const childNode = buildNestedReference(bound, classFile, ctx);
605
- const wrapArray = has("IsArray") || isArrayType;
606
- const node2 = wrapArray ? { kind: "array", element: childNode } : childNode;
607
- return applyPresence(node2, decorators);
616
+ return asField(buildNestedReference(bound, classFile, ctx));
608
617
  }
609
618
  const typeRefName = resolveTypeFactoryName(dec("Type"));
610
619
  if (has("ValidateNested") || typeRefName) {
611
620
  const typeArgs = genericTypeArgNames(typeNode);
612
621
  const childName = typeRefName ?? singularClassName(typeText);
613
622
  if (childName) {
614
- const childNode = buildNestedReference(childName, classFile, ctx, typeArgs);
615
- const wrapArray = has("IsArray") || isArrayType;
616
- const node2 = wrapArray ? { kind: "array", element: childNode } : childNode;
617
- return applyPresence(node2, decorators);
623
+ return asField(buildNestedReference(childName, classFile, ctx, typeArgs));
618
624
  }
619
625
  }
620
626
  let base = baseFromType(typeText, isArrayType);