@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.
package/dist/cli/main.js CHANGED
@@ -2246,7 +2246,6 @@ function resolveImportedType(name, sourceFile, project) {
2246
2246
  if (!namedImport) continue;
2247
2247
  const moduleSpecifier = importDecl.getModuleSpecifierValue();
2248
2248
  const candidates = resolveModuleSpecifier(moduleSpecifier, sourceFile, project);
2249
- if (candidates.length === 0) continue;
2250
2249
  for (const candidate of candidates) {
2251
2250
  let importedFile = project.getSourceFile(candidate);
2252
2251
  if (!importedFile) {
@@ -2261,9 +2260,25 @@ function resolveImportedType(name, sourceFile, project) {
2261
2260
  const viaReExport = resolveReExportedType(name, importedFile, project, /* @__PURE__ */ new Set());
2262
2261
  if (viaReExport) return viaReExport;
2263
2262
  }
2263
+ if (candidates.length === 0) {
2264
+ const viaCompiler = resolveBareSpecifierType(name, importDecl, project);
2265
+ if (viaCompiler) return viaCompiler;
2266
+ }
2264
2267
  }
2265
2268
  return resolveReExportedType(name, sourceFile, project, /* @__PURE__ */ new Set());
2266
2269
  }
2270
+ function resolveBareSpecifierType(name, importDecl, project) {
2271
+ let target;
2272
+ try {
2273
+ target = importDecl.getModuleSpecifierSourceFile();
2274
+ } catch {
2275
+ return null;
2276
+ }
2277
+ if (!target) return null;
2278
+ const direct = findTypeInFile(name, target);
2279
+ if (direct) return direct;
2280
+ return resolveReExportedType(name, target, project, /* @__PURE__ */ new Set());
2281
+ }
2267
2282
  function resolveReExportedType(name, file, project, seen) {
2268
2283
  const filePath = file.getFilePath();
2269
2284
  if (seen.has(filePath)) return null;
@@ -2547,37 +2562,28 @@ function buildProperty(prop, classFile, ctx) {
2547
2562
  const typeNode = prop.getTypeNode();
2548
2563
  const typeText = typeNode?.getText() ?? "unknown";
2549
2564
  const isArrayType = !!typeNode && Node3.isArrayTypeNode(typeNode);
2565
+ const asField = (child) => applyPresence(
2566
+ has("IsArray") || isArrayType ? { kind: "array", element: child } : child,
2567
+ decorators
2568
+ );
2550
2569
  const discriminator = resolveDiscriminator(dec("Type"));
2551
2570
  if (discriminator) {
2552
2571
  const options = discriminator.subTypes.map(
2553
2572
  (name) => buildNestedReference(name, classFile, ctx)
2554
2573
  );
2555
- const unionNode = {
2556
- kind: "union",
2557
- options,
2558
- discriminator: discriminator.property
2559
- };
2560
- const wrapArray = has("IsArray") || isArrayType;
2561
- const node2 = wrapArray ? { kind: "array", element: unionNode } : unionNode;
2562
- return applyPresence(node2, decorators);
2574
+ return asField({ kind: "union", options, discriminator: discriminator.property });
2563
2575
  }
2564
2576
  const propTypeParam = singularClassName(typeText);
2565
2577
  if (propTypeParam && ctx.typeBindings.has(propTypeParam)) {
2566
2578
  const bound = ctx.typeBindings.get(propTypeParam);
2567
- const childNode = buildNestedReference(bound, classFile, ctx);
2568
- const wrapArray = has("IsArray") || isArrayType;
2569
- const node2 = wrapArray ? { kind: "array", element: childNode } : childNode;
2570
- return applyPresence(node2, decorators);
2579
+ return asField(buildNestedReference(bound, classFile, ctx));
2571
2580
  }
2572
2581
  const typeRefName = resolveTypeFactoryName(dec("Type"));
2573
2582
  if (has("ValidateNested") || typeRefName) {
2574
2583
  const typeArgs = genericTypeArgNames(typeNode);
2575
2584
  const childName = typeRefName ?? singularClassName(typeText);
2576
2585
  if (childName) {
2577
- const childNode = buildNestedReference(childName, classFile, ctx, typeArgs);
2578
- const wrapArray = has("IsArray") || isArrayType;
2579
- const node2 = wrapArray ? { kind: "array", element: childNode } : childNode;
2580
- return applyPresence(node2, decorators);
2586
+ return asField(buildNestedReference(childName, classFile, ctx, typeArgs));
2581
2587
  }
2582
2588
  }
2583
2589
  let base = baseFromType(typeText, isArrayType);
@@ -4438,7 +4444,7 @@ async function watch(config, onChange) {
4438
4444
  }
4439
4445
 
4440
4446
  // src/index.ts
4441
- var VERSION = "0.5.1";
4447
+ var VERSION = "0.6.0";
4442
4448
 
4443
4449
  // src/cli/codegen.ts
4444
4450
  async function runCodegen(opts = {}) {