@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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @dudousxd/nestjs-codegen
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - ece130c: Fix: resolve `@Filterable({ entity })` entities imported from external npm packages so the route is still classified as a filter route. Previously, when a filter's entity (e.g. a MikroORM entity from `@dudousxd/nestjs-durable-store-mikro-orm`) was imported from `node_modules` rather than an in-repo `*.entity.ts`, the discovery type resolver returned no candidates for the bare module specifier and bailed — degrading the route to a plain bodyless route (`body: never; filterFields: never`, no `queryOptions`) and breaking the generated client (`x.queryOptions is not a function`).
8
+
9
+ The type resolver now falls back to the TypeScript compiler's own module resolution (`getModuleSpecifierSourceFile()`) for bare node_modules specifiers, locating the package's `.d.ts` declaration file and enumerating the entity's columns from it. External-package filter entities now get the same full `filterFields` union + `body: FilterQueryResult` + TanStack `queryOptions` helper as in-repo entities.
10
+
11
+ ## 0.5.2
12
+
13
+ ### Patch Changes
14
+
15
+ - f432450: Internal refactors (behavior-preserving): share `renderModule` across the zod/valibot adapters via a `createChainModuleRenderer` factory, and dedupe the nested-reference array-wrap + presence tail in `buildProperty` (`dto-to-ir`) behind a single `asField` closure.
16
+
3
17
  ## 0.5.1
4
18
 
5
19
  ### Patch Changes
package/dist/cli/main.cjs CHANGED
@@ -2270,7 +2270,6 @@ function resolveImportedType(name, sourceFile, project) {
2270
2270
  if (!namedImport) continue;
2271
2271
  const moduleSpecifier = importDecl.getModuleSpecifierValue();
2272
2272
  const candidates = resolveModuleSpecifier(moduleSpecifier, sourceFile, project);
2273
- if (candidates.length === 0) continue;
2274
2273
  for (const candidate of candidates) {
2275
2274
  let importedFile = project.getSourceFile(candidate);
2276
2275
  if (!importedFile) {
@@ -2285,9 +2284,25 @@ function resolveImportedType(name, sourceFile, project) {
2285
2284
  const viaReExport = resolveReExportedType(name, importedFile, project, /* @__PURE__ */ new Set());
2286
2285
  if (viaReExport) return viaReExport;
2287
2286
  }
2287
+ if (candidates.length === 0) {
2288
+ const viaCompiler = resolveBareSpecifierType(name, importDecl, project);
2289
+ if (viaCompiler) return viaCompiler;
2290
+ }
2288
2291
  }
2289
2292
  return resolveReExportedType(name, sourceFile, project, /* @__PURE__ */ new Set());
2290
2293
  }
2294
+ function resolveBareSpecifierType(name, importDecl, project) {
2295
+ let target;
2296
+ try {
2297
+ target = importDecl.getModuleSpecifierSourceFile();
2298
+ } catch {
2299
+ return null;
2300
+ }
2301
+ if (!target) return null;
2302
+ const direct = findTypeInFile(name, target);
2303
+ if (direct) return direct;
2304
+ return resolveReExportedType(name, target, project, /* @__PURE__ */ new Set());
2305
+ }
2291
2306
  function resolveReExportedType(name, file, project, seen) {
2292
2307
  const filePath = file.getFilePath();
2293
2308
  if (seen.has(filePath)) return null;
@@ -2571,37 +2586,28 @@ function buildProperty(prop, classFile, ctx) {
2571
2586
  const typeNode = prop.getTypeNode();
2572
2587
  const typeText = typeNode?.getText() ?? "unknown";
2573
2588
  const isArrayType = !!typeNode && import_ts_morph4.Node.isArrayTypeNode(typeNode);
2589
+ const asField = (child) => applyPresence(
2590
+ has("IsArray") || isArrayType ? { kind: "array", element: child } : child,
2591
+ decorators
2592
+ );
2574
2593
  const discriminator = resolveDiscriminator(dec("Type"));
2575
2594
  if (discriminator) {
2576
2595
  const options = discriminator.subTypes.map(
2577
2596
  (name) => buildNestedReference(name, classFile, ctx)
2578
2597
  );
2579
- const unionNode = {
2580
- kind: "union",
2581
- options,
2582
- discriminator: discriminator.property
2583
- };
2584
- const wrapArray = has("IsArray") || isArrayType;
2585
- const node2 = wrapArray ? { kind: "array", element: unionNode } : unionNode;
2586
- return applyPresence(node2, decorators);
2598
+ return asField({ kind: "union", options, discriminator: discriminator.property });
2587
2599
  }
2588
2600
  const propTypeParam = singularClassName(typeText);
2589
2601
  if (propTypeParam && ctx.typeBindings.has(propTypeParam)) {
2590
2602
  const bound = ctx.typeBindings.get(propTypeParam);
2591
- const childNode = buildNestedReference(bound, classFile, ctx);
2592
- const wrapArray = has("IsArray") || isArrayType;
2593
- const node2 = wrapArray ? { kind: "array", element: childNode } : childNode;
2594
- return applyPresence(node2, decorators);
2603
+ return asField(buildNestedReference(bound, classFile, ctx));
2595
2604
  }
2596
2605
  const typeRefName = resolveTypeFactoryName(dec("Type"));
2597
2606
  if (has("ValidateNested") || typeRefName) {
2598
2607
  const typeArgs = genericTypeArgNames(typeNode);
2599
2608
  const childName = typeRefName ?? singularClassName(typeText);
2600
2609
  if (childName) {
2601
- const childNode = buildNestedReference(childName, classFile, ctx, typeArgs);
2602
- const wrapArray = has("IsArray") || isArrayType;
2603
- const node2 = wrapArray ? { kind: "array", element: childNode } : childNode;
2604
- return applyPresence(node2, decorators);
2610
+ return asField(buildNestedReference(childName, classFile, ctx, typeArgs));
2605
2611
  }
2606
2612
  }
2607
2613
  let base = baseFromType(typeText, isArrayType);
@@ -4457,7 +4463,7 @@ async function watch(config, onChange) {
4457
4463
  }
4458
4464
 
4459
4465
  // src/index.ts
4460
- var VERSION = "0.5.1";
4466
+ var VERSION = "0.6.0";
4461
4467
 
4462
4468
  // src/cli/codegen.ts
4463
4469
  async function runCodegen(opts = {}) {