@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 +24 -0
- package/dist/cli/main.cjs +38 -8
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +38 -8
- package/dist/cli/main.js.map +1 -1
- package/dist/extension/index.d.cts +1 -1
- package/dist/extension/index.d.ts +1 -1
- package/dist/{index-DgIAN5k5.d.cts → index-SJc0gya_.d.cts} +10 -0
- package/dist/{index-DgIAN5k5.d.ts → index-SJc0gya_.d.ts} +10 -0
- package/dist/index.cjs +38 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +38 -8
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +37 -7
- package/dist/nest/index.cjs.map +1 -1
- package/dist/nest/index.d.cts +1 -1
- package/dist/nest/index.d.ts +1 -1
- package/dist/nest/index.js +37 -7
- package/dist/nest/index.js.map +1 -1
- package/package.json +1 -1
package/dist/nest/index.cjs
CHANGED
|
@@ -131,6 +131,7 @@ function applyDefaults(userConfig, cwd) {
|
|
|
131
131
|
};
|
|
132
132
|
}
|
|
133
133
|
return {
|
|
134
|
+
debug: userConfig.debug ?? false,
|
|
134
135
|
extensions: userConfig.extensions ?? [],
|
|
135
136
|
// Non-null: validateUserConfig() above throws when `validation` is absent.
|
|
136
137
|
validation: resolveAdapter(userConfig.validation),
|
|
@@ -188,6 +189,15 @@ var import_ts_morph5 = require("ts-morph");
|
|
|
188
189
|
// src/discovery/dto-to-ir.ts
|
|
189
190
|
var import_ts_morph2 = require("ts-morph");
|
|
190
191
|
|
|
192
|
+
// src/util/debug-log.ts
|
|
193
|
+
var debugEnabled = false;
|
|
194
|
+
function setCodegenDebug(enabled) {
|
|
195
|
+
debugEnabled = enabled;
|
|
196
|
+
}
|
|
197
|
+
function debugWarn(message) {
|
|
198
|
+
if (debugEnabled) console.warn(`[nestjs-codegen] ${message}`);
|
|
199
|
+
}
|
|
200
|
+
|
|
191
201
|
// src/discovery/type-ref-resolution.ts
|
|
192
202
|
var import_node_fs = require("fs");
|
|
193
203
|
var import_node_path2 = require("path");
|
|
@@ -704,7 +714,7 @@ function buildProperty(prop, classFile, ctx) {
|
|
|
704
714
|
ctx.warnedDecorators.add(name);
|
|
705
715
|
const msg = `@${name} is not translatable to a client validation schema and was skipped (server-only validation).`;
|
|
706
716
|
ctx.warnings.push(msg);
|
|
707
|
-
|
|
717
|
+
debugWarn(msg);
|
|
708
718
|
}
|
|
709
719
|
}
|
|
710
720
|
}
|
|
@@ -755,7 +765,7 @@ function buildNestedReference(className, fromFile, ctx, typeArgs = []) {
|
|
|
755
765
|
ctx.warnedDecorators.add(`recursive:${reserved}`);
|
|
756
766
|
const msg = `${className} is a recursive type; the generated schema validates it via a lazy self-reference.`;
|
|
757
767
|
ctx.warnings.push(msg);
|
|
758
|
-
|
|
768
|
+
debugWarn(msg);
|
|
759
769
|
}
|
|
760
770
|
return { kind: "lazyRef", name: reserved };
|
|
761
771
|
}
|
|
@@ -764,7 +774,7 @@ function buildNestedReference(className, fromFile, ctx, typeArgs = []) {
|
|
|
764
774
|
ctx.warnedDecorators.add(`deep:${className}`);
|
|
765
775
|
const msg = `${className} nesting is too deep to expand; the generated schema uses unknown for it.`;
|
|
766
776
|
ctx.warnings.push(msg);
|
|
767
|
-
|
|
777
|
+
debugWarn(msg);
|
|
768
778
|
}
|
|
769
779
|
return { kind: "unknown", note: "nesting too deep \u2014 not expanded" };
|
|
770
780
|
}
|
|
@@ -905,7 +915,7 @@ function enumSchemaFromDecorator(decorator, classFile, ctx) {
|
|
|
905
915
|
if (!ctx.warnedDecorators.has(`IsEnum:${name}`)) {
|
|
906
916
|
ctx.warnedDecorators.add(`IsEnum:${name}`);
|
|
907
917
|
ctx.warnings.push(msg);
|
|
908
|
-
|
|
918
|
+
debugWarn(msg);
|
|
909
919
|
}
|
|
910
920
|
return { kind: "unknown", note: `@IsEnum(${name}): enum not resolvable to literals` };
|
|
911
921
|
}
|
|
@@ -1535,14 +1545,33 @@ function extractQueryType(method, sourceFile, project) {
|
|
|
1535
1545
|
for (const param of method.getParameters()) {
|
|
1536
1546
|
const queryDecorator = param.getDecorators().find((d) => d.getName() === "Query");
|
|
1537
1547
|
if (!queryDecorator) continue;
|
|
1538
|
-
|
|
1539
|
-
if (queryArgs.length > 0) continue;
|
|
1548
|
+
if (queryDecorator.getArguments().length > 0) continue;
|
|
1540
1549
|
const typeNode = param.getTypeNode();
|
|
1541
1550
|
if (typeNode) {
|
|
1542
1551
|
return resolveTypeNodeToString(typeNode, sourceFile, project, 3);
|
|
1543
1552
|
}
|
|
1544
1553
|
}
|
|
1545
|
-
|
|
1554
|
+
const entries = [];
|
|
1555
|
+
for (const param of method.getParameters()) {
|
|
1556
|
+
const queryDecorator = param.getDecorators().find((d) => d.getName() === "Query");
|
|
1557
|
+
if (!queryDecorator) continue;
|
|
1558
|
+
const queryArgs = queryDecorator.getArguments();
|
|
1559
|
+
const nameArg = queryArgs[0];
|
|
1560
|
+
if (!nameArg || !import_ts_morph5.Node.isStringLiteral(nameArg)) continue;
|
|
1561
|
+
const queryName = nameArg.getLiteralValue();
|
|
1562
|
+
const typeNode = param.getTypeNode();
|
|
1563
|
+
const queryType = typeNode ? resolveTypeNodeToString(typeNode, sourceFile, project, 3) : "string";
|
|
1564
|
+
entries.push(`${queryName}${isParamOptional(param) ? "?" : ""}: ${queryType}`);
|
|
1565
|
+
}
|
|
1566
|
+
return entries.length > 0 ? `{ ${entries.join("; ")} }` : null;
|
|
1567
|
+
}
|
|
1568
|
+
function isParamOptional(param) {
|
|
1569
|
+
if (param.hasQuestionToken() || param.hasInitializer()) return true;
|
|
1570
|
+
const typeNode = param.getTypeNode();
|
|
1571
|
+
if (typeNode && import_ts_morph5.Node.isUnionTypeNode(typeNode)) {
|
|
1572
|
+
return typeNode.getTypeNodes().some((t) => t.getKind() === import_ts_morph5.SyntaxKind.UndefinedKeyword);
|
|
1573
|
+
}
|
|
1574
|
+
return false;
|
|
1546
1575
|
}
|
|
1547
1576
|
function extractParamsType(method, sourceFile, project) {
|
|
1548
1577
|
const entries = [];
|
|
@@ -4180,6 +4209,7 @@ function buildEmpty() {
|
|
|
4180
4209
|
|
|
4181
4210
|
// src/generate.ts
|
|
4182
4211
|
async function generate(config, inputRoutes = []) {
|
|
4212
|
+
setCodegenDebug(config.debug);
|
|
4183
4213
|
const extensions = config.extensions ?? [];
|
|
4184
4214
|
let routes = inputRoutes;
|
|
4185
4215
|
const ctx = createExtensionContext(config, () => routes);
|