@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.
@@ -1,5 +1,5 @@
1
1
  import { DynamicModule, OnApplicationBootstrap, OnModuleDestroy } from '@nestjs/common';
2
- import { U as UserConfig } from '../index-DgIAN5k5.cjs';
2
+ import { U as UserConfig } from '../index-SJc0gya_.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-DgIAN5k5.js';
2
+ import { U as UserConfig } from '../index-SJc0gya_.js';
3
3
  import 'ts-morph';
4
4
 
5
5
  /**
@@ -95,6 +95,7 @@ function applyDefaults(userConfig, cwd) {
95
95
  };
96
96
  }
97
97
  return {
98
+ debug: userConfig.debug ?? false,
98
99
  extensions: userConfig.extensions ?? [],
99
100
  // Non-null: validateUserConfig() above throws when `validation` is absent.
100
101
  validation: resolveAdapter(userConfig.validation),
@@ -160,6 +161,15 @@ import {
160
161
  Node as Node2
161
162
  } from "ts-morph";
162
163
 
164
+ // src/util/debug-log.ts
165
+ var debugEnabled = false;
166
+ function setCodegenDebug(enabled) {
167
+ debugEnabled = enabled;
168
+ }
169
+ function debugWarn(message) {
170
+ if (debugEnabled) console.warn(`[nestjs-codegen] ${message}`);
171
+ }
172
+
163
173
  // src/discovery/type-ref-resolution.ts
164
174
  import { readFileSync } from "fs";
165
175
  import { dirname, resolve as resolve2 } from "path";
@@ -678,7 +688,7 @@ function buildProperty(prop, classFile, ctx) {
678
688
  ctx.warnedDecorators.add(name);
679
689
  const msg = `@${name} is not translatable to a client validation schema and was skipped (server-only validation).`;
680
690
  ctx.warnings.push(msg);
681
- console.warn(`[nestjs-codegen] ${msg}`);
691
+ debugWarn(msg);
682
692
  }
683
693
  }
684
694
  }
@@ -729,7 +739,7 @@ function buildNestedReference(className, fromFile, ctx, typeArgs = []) {
729
739
  ctx.warnedDecorators.add(`recursive:${reserved}`);
730
740
  const msg = `${className} is a recursive type; the generated schema validates it via a lazy self-reference.`;
731
741
  ctx.warnings.push(msg);
732
- console.warn(`[nestjs-codegen] ${msg}`);
742
+ debugWarn(msg);
733
743
  }
734
744
  return { kind: "lazyRef", name: reserved };
735
745
  }
@@ -738,7 +748,7 @@ function buildNestedReference(className, fromFile, ctx, typeArgs = []) {
738
748
  ctx.warnedDecorators.add(`deep:${className}`);
739
749
  const msg = `${className} nesting is too deep to expand; the generated schema uses unknown for it.`;
740
750
  ctx.warnings.push(msg);
741
- console.warn(`[nestjs-codegen] ${msg}`);
751
+ debugWarn(msg);
742
752
  }
743
753
  return { kind: "unknown", note: "nesting too deep \u2014 not expanded" };
744
754
  }
@@ -879,7 +889,7 @@ function enumSchemaFromDecorator(decorator, classFile, ctx) {
879
889
  if (!ctx.warnedDecorators.has(`IsEnum:${name}`)) {
880
890
  ctx.warnedDecorators.add(`IsEnum:${name}`);
881
891
  ctx.warnings.push(msg);
882
- console.warn(`[nestjs-codegen] ${msg}`);
892
+ debugWarn(msg);
883
893
  }
884
894
  return { kind: "unknown", note: `@IsEnum(${name}): enum not resolvable to literals` };
885
895
  }
@@ -1514,14 +1524,33 @@ function extractQueryType(method, sourceFile, project) {
1514
1524
  for (const param of method.getParameters()) {
1515
1525
  const queryDecorator = param.getDecorators().find((d) => d.getName() === "Query");
1516
1526
  if (!queryDecorator) continue;
1517
- const queryArgs = queryDecorator.getArguments();
1518
- if (queryArgs.length > 0) continue;
1527
+ if (queryDecorator.getArguments().length > 0) continue;
1519
1528
  const typeNode = param.getTypeNode();
1520
1529
  if (typeNode) {
1521
1530
  return resolveTypeNodeToString(typeNode, sourceFile, project, 3);
1522
1531
  }
1523
1532
  }
1524
- return null;
1533
+ const entries = [];
1534
+ for (const param of method.getParameters()) {
1535
+ const queryDecorator = param.getDecorators().find((d) => d.getName() === "Query");
1536
+ if (!queryDecorator) continue;
1537
+ const queryArgs = queryDecorator.getArguments();
1538
+ const nameArg = queryArgs[0];
1539
+ if (!nameArg || !Node5.isStringLiteral(nameArg)) continue;
1540
+ const queryName = nameArg.getLiteralValue();
1541
+ const typeNode = param.getTypeNode();
1542
+ const queryType = typeNode ? resolveTypeNodeToString(typeNode, sourceFile, project, 3) : "string";
1543
+ entries.push(`${queryName}${isParamOptional(param) ? "?" : ""}: ${queryType}`);
1544
+ }
1545
+ return entries.length > 0 ? `{ ${entries.join("; ")} }` : null;
1546
+ }
1547
+ function isParamOptional(param) {
1548
+ if (param.hasQuestionToken() || param.hasInitializer()) return true;
1549
+ const typeNode = param.getTypeNode();
1550
+ if (typeNode && Node5.isUnionTypeNode(typeNode)) {
1551
+ return typeNode.getTypeNodes().some((t) => t.getKind() === SyntaxKind2.UndefinedKeyword);
1552
+ }
1553
+ return false;
1525
1554
  }
1526
1555
  function extractParamsType(method, sourceFile, project) {
1527
1556
  const entries = [];
@@ -4159,6 +4188,7 @@ function buildEmpty() {
4159
4188
 
4160
4189
  // src/generate.ts
4161
4190
  async function generate(config, inputRoutes = []) {
4191
+ setCodegenDebug(config.debug);
4162
4192
  const extensions = config.extensions ?? [];
4163
4193
  let routes = inputRoutes;
4164
4194
  const ctx = createExtensionContext(config, () => routes);