@dudousxd/nestjs-codegen 0.7.1 → 0.9.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,29 @@
1
1
  # @dudousxd/nestjs-codegen
2
2
 
3
+ ## 0.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - ff9e27b: feat(core): gate schema-translation advisories behind a new `debug` config flag (default off).
8
+
9
+ On every codegen pass the discovery layer logged a `[nestjs-codegen]` line to the
10
+ terminal for each schema-translation advisory — `@X is not translatable to a client
11
+ validation schema and was skipped`, `T is a recursive type; ... lazy self-reference`,
12
+ over-deep nesting, and unresolvable `@IsEnum`. On a real project these fire dozens of
13
+ times per run and are pure noise.
14
+
15
+ These advisories are already preserved where they matter: in the returned
16
+ `SchemaModule.warnings` array and as `// warning:` comments in the generated output.
17
+ The terminal copy is now opt-in: add `debug: true` to `nestjs-codegen.config.ts`
18
+ (or `NestjsCodegenModule.forRoot({ debug: true })`) to print them again. Default is
19
+ `false`, so a normal run is quiet. No effect on generated artifacts.
20
+
21
+ ## 0.8.0
22
+
23
+ ### Minor Changes
24
+
25
+ - 685583d: feat(core): synthesize the route `query` type from individual `@Query('name')` params. Handlers using named query params (e.g. `@Query('years') years?: number[]`, `@Query('q') q?: string | string[]`) now emit a typed `query` object — one property per param, keyed by the string-literal name, typed by the parameter annotation, optional when the param has `?` / a default / a `| undefined` type — instead of `query: never`. The existing whole-object `@Query() dto` form is unchanged and still wins when both forms appear on the same handler.
26
+
3
27
  ## 0.7.1
4
28
 
5
29
  ### Patch Changes
package/dist/cli/main.cjs CHANGED
@@ -142,6 +142,7 @@ function applyDefaults(userConfig, cwd) {
142
142
  };
143
143
  }
144
144
  return {
145
+ debug: userConfig.debug ?? false,
145
146
  extensions: userConfig.extensions ?? [],
146
147
  // Non-null: validateUserConfig() above throws when `validation` is absent.
147
148
  validation: resolveAdapter(userConfig.validation),
@@ -2108,8 +2109,18 @@ function buildEmpty() {
2108
2109
  ].join("\n");
2109
2110
  }
2110
2111
 
2112
+ // src/util/debug-log.ts
2113
+ var debugEnabled = false;
2114
+ function setCodegenDebug(enabled) {
2115
+ debugEnabled = enabled;
2116
+ }
2117
+ function debugWarn(message) {
2118
+ if (debugEnabled) console.warn(`[nestjs-codegen] ${message}`);
2119
+ }
2120
+
2111
2121
  // src/generate.ts
2112
2122
  async function generate(config, inputRoutes = []) {
2123
+ setCodegenDebug(config.debug);
2113
2124
  const extensions = config.extensions ?? [];
2114
2125
  let routes = inputRoutes;
2115
2126
  const ctx = createExtensionContext(config, () => routes);
@@ -2705,7 +2716,7 @@ function buildProperty(prop, classFile, ctx) {
2705
2716
  ctx.warnedDecorators.add(name);
2706
2717
  const msg = `@${name} is not translatable to a client validation schema and was skipped (server-only validation).`;
2707
2718
  ctx.warnings.push(msg);
2708
- console.warn(`[nestjs-codegen] ${msg}`);
2719
+ debugWarn(msg);
2709
2720
  }
2710
2721
  }
2711
2722
  }
@@ -2756,7 +2767,7 @@ function buildNestedReference(className, fromFile, ctx, typeArgs = []) {
2756
2767
  ctx.warnedDecorators.add(`recursive:${reserved}`);
2757
2768
  const msg = `${className} is a recursive type; the generated schema validates it via a lazy self-reference.`;
2758
2769
  ctx.warnings.push(msg);
2759
- console.warn(`[nestjs-codegen] ${msg}`);
2770
+ debugWarn(msg);
2760
2771
  }
2761
2772
  return { kind: "lazyRef", name: reserved };
2762
2773
  }
@@ -2765,7 +2776,7 @@ function buildNestedReference(className, fromFile, ctx, typeArgs = []) {
2765
2776
  ctx.warnedDecorators.add(`deep:${className}`);
2766
2777
  const msg = `${className} nesting is too deep to expand; the generated schema uses unknown for it.`;
2767
2778
  ctx.warnings.push(msg);
2768
- console.warn(`[nestjs-codegen] ${msg}`);
2779
+ debugWarn(msg);
2769
2780
  }
2770
2781
  return { kind: "unknown", note: "nesting too deep \u2014 not expanded" };
2771
2782
  }
@@ -2906,7 +2917,7 @@ function enumSchemaFromDecorator(decorator, classFile, ctx) {
2906
2917
  if (!ctx.warnedDecorators.has(`IsEnum:${name}`)) {
2907
2918
  ctx.warnedDecorators.add(`IsEnum:${name}`);
2908
2919
  ctx.warnings.push(msg);
2909
- console.warn(`[nestjs-codegen] ${msg}`);
2920
+ debugWarn(msg);
2910
2921
  }
2911
2922
  return { kind: "unknown", note: `@IsEnum(${name}): enum not resolvable to literals` };
2912
2923
  }
@@ -3536,14 +3547,33 @@ function extractQueryType(method, sourceFile, project) {
3536
3547
  for (const param of method.getParameters()) {
3537
3548
  const queryDecorator = param.getDecorators().find((d) => d.getName() === "Query");
3538
3549
  if (!queryDecorator) continue;
3539
- const queryArgs = queryDecorator.getArguments();
3540
- if (queryArgs.length > 0) continue;
3550
+ if (queryDecorator.getArguments().length > 0) continue;
3541
3551
  const typeNode = param.getTypeNode();
3542
3552
  if (typeNode) {
3543
3553
  return resolveTypeNodeToString(typeNode, sourceFile, project, 3);
3544
3554
  }
3545
3555
  }
3546
- return null;
3556
+ const entries = [];
3557
+ for (const param of method.getParameters()) {
3558
+ const queryDecorator = param.getDecorators().find((d) => d.getName() === "Query");
3559
+ if (!queryDecorator) continue;
3560
+ const queryArgs = queryDecorator.getArguments();
3561
+ const nameArg = queryArgs[0];
3562
+ if (!nameArg || !import_ts_morph7.Node.isStringLiteral(nameArg)) continue;
3563
+ const queryName = nameArg.getLiteralValue();
3564
+ const typeNode = param.getTypeNode();
3565
+ const queryType = typeNode ? resolveTypeNodeToString(typeNode, sourceFile, project, 3) : "string";
3566
+ entries.push(`${queryName}${isParamOptional(param) ? "?" : ""}: ${queryType}`);
3567
+ }
3568
+ return entries.length > 0 ? `{ ${entries.join("; ")} }` : null;
3569
+ }
3570
+ function isParamOptional(param) {
3571
+ if (param.hasQuestionToken() || param.hasInitializer()) return true;
3572
+ const typeNode = param.getTypeNode();
3573
+ if (typeNode && import_ts_morph7.Node.isUnionTypeNode(typeNode)) {
3574
+ return typeNode.getTypeNodes().some((t) => t.getKind() === import_ts_morph7.SyntaxKind.UndefinedKeyword);
3575
+ }
3576
+ return false;
3547
3577
  }
3548
3578
  function extractParamsType(method, sourceFile, project) {
3549
3579
  const entries = [];
@@ -4481,7 +4511,7 @@ async function watch(config, onChange) {
4481
4511
  }
4482
4512
 
4483
4513
  // src/index.ts
4484
- var VERSION = "0.7.1";
4514
+ var VERSION = "0.9.0";
4485
4515
 
4486
4516
  // src/cli/codegen.ts
4487
4517
  async function runCodegen(opts = {}) {