@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/cli/main.js
CHANGED
|
@@ -108,6 +108,7 @@ function applyDefaults(userConfig, cwd) {
|
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
110
|
return {
|
|
111
|
+
debug: userConfig.debug ?? false,
|
|
111
112
|
extensions: userConfig.extensions ?? [],
|
|
112
113
|
// Non-null: validateUserConfig() above throws when `validation` is absent.
|
|
113
114
|
validation: resolveAdapter(userConfig.validation),
|
|
@@ -2074,8 +2075,18 @@ function buildEmpty() {
|
|
|
2074
2075
|
].join("\n");
|
|
2075
2076
|
}
|
|
2076
2077
|
|
|
2078
|
+
// src/util/debug-log.ts
|
|
2079
|
+
var debugEnabled = false;
|
|
2080
|
+
function setCodegenDebug(enabled) {
|
|
2081
|
+
debugEnabled = enabled;
|
|
2082
|
+
}
|
|
2083
|
+
function debugWarn(message) {
|
|
2084
|
+
if (debugEnabled) console.warn(`[nestjs-codegen] ${message}`);
|
|
2085
|
+
}
|
|
2086
|
+
|
|
2077
2087
|
// src/generate.ts
|
|
2078
2088
|
async function generate(config, inputRoutes = []) {
|
|
2089
|
+
setCodegenDebug(config.debug);
|
|
2079
2090
|
const extensions = config.extensions ?? [];
|
|
2080
2091
|
let routes = inputRoutes;
|
|
2081
2092
|
const ctx = createExtensionContext(config, () => routes);
|
|
@@ -2681,7 +2692,7 @@ function buildProperty(prop, classFile, ctx) {
|
|
|
2681
2692
|
ctx.warnedDecorators.add(name);
|
|
2682
2693
|
const msg = `@${name} is not translatable to a client validation schema and was skipped (server-only validation).`;
|
|
2683
2694
|
ctx.warnings.push(msg);
|
|
2684
|
-
|
|
2695
|
+
debugWarn(msg);
|
|
2685
2696
|
}
|
|
2686
2697
|
}
|
|
2687
2698
|
}
|
|
@@ -2732,7 +2743,7 @@ function buildNestedReference(className, fromFile, ctx, typeArgs = []) {
|
|
|
2732
2743
|
ctx.warnedDecorators.add(`recursive:${reserved}`);
|
|
2733
2744
|
const msg = `${className} is a recursive type; the generated schema validates it via a lazy self-reference.`;
|
|
2734
2745
|
ctx.warnings.push(msg);
|
|
2735
|
-
|
|
2746
|
+
debugWarn(msg);
|
|
2736
2747
|
}
|
|
2737
2748
|
return { kind: "lazyRef", name: reserved };
|
|
2738
2749
|
}
|
|
@@ -2741,7 +2752,7 @@ function buildNestedReference(className, fromFile, ctx, typeArgs = []) {
|
|
|
2741
2752
|
ctx.warnedDecorators.add(`deep:${className}`);
|
|
2742
2753
|
const msg = `${className} nesting is too deep to expand; the generated schema uses unknown for it.`;
|
|
2743
2754
|
ctx.warnings.push(msg);
|
|
2744
|
-
|
|
2755
|
+
debugWarn(msg);
|
|
2745
2756
|
}
|
|
2746
2757
|
return { kind: "unknown", note: "nesting too deep \u2014 not expanded" };
|
|
2747
2758
|
}
|
|
@@ -2882,7 +2893,7 @@ function enumSchemaFromDecorator(decorator, classFile, ctx) {
|
|
|
2882
2893
|
if (!ctx.warnedDecorators.has(`IsEnum:${name}`)) {
|
|
2883
2894
|
ctx.warnedDecorators.add(`IsEnum:${name}`);
|
|
2884
2895
|
ctx.warnings.push(msg);
|
|
2885
|
-
|
|
2896
|
+
debugWarn(msg);
|
|
2886
2897
|
}
|
|
2887
2898
|
return { kind: "unknown", note: `@IsEnum(${name}): enum not resolvable to literals` };
|
|
2888
2899
|
}
|
|
@@ -3517,14 +3528,33 @@ function extractQueryType(method, sourceFile, project) {
|
|
|
3517
3528
|
for (const param of method.getParameters()) {
|
|
3518
3529
|
const queryDecorator = param.getDecorators().find((d) => d.getName() === "Query");
|
|
3519
3530
|
if (!queryDecorator) continue;
|
|
3520
|
-
|
|
3521
|
-
if (queryArgs.length > 0) continue;
|
|
3531
|
+
if (queryDecorator.getArguments().length > 0) continue;
|
|
3522
3532
|
const typeNode = param.getTypeNode();
|
|
3523
3533
|
if (typeNode) {
|
|
3524
3534
|
return resolveTypeNodeToString(typeNode, sourceFile, project, 3);
|
|
3525
3535
|
}
|
|
3526
3536
|
}
|
|
3527
|
-
|
|
3537
|
+
const entries = [];
|
|
3538
|
+
for (const param of method.getParameters()) {
|
|
3539
|
+
const queryDecorator = param.getDecorators().find((d) => d.getName() === "Query");
|
|
3540
|
+
if (!queryDecorator) continue;
|
|
3541
|
+
const queryArgs = queryDecorator.getArguments();
|
|
3542
|
+
const nameArg = queryArgs[0];
|
|
3543
|
+
if (!nameArg || !Node6.isStringLiteral(nameArg)) continue;
|
|
3544
|
+
const queryName = nameArg.getLiteralValue();
|
|
3545
|
+
const typeNode = param.getTypeNode();
|
|
3546
|
+
const queryType = typeNode ? resolveTypeNodeToString(typeNode, sourceFile, project, 3) : "string";
|
|
3547
|
+
entries.push(`${queryName}${isParamOptional(param) ? "?" : ""}: ${queryType}`);
|
|
3548
|
+
}
|
|
3549
|
+
return entries.length > 0 ? `{ ${entries.join("; ")} }` : null;
|
|
3550
|
+
}
|
|
3551
|
+
function isParamOptional(param) {
|
|
3552
|
+
if (param.hasQuestionToken() || param.hasInitializer()) return true;
|
|
3553
|
+
const typeNode = param.getTypeNode();
|
|
3554
|
+
if (typeNode && Node6.isUnionTypeNode(typeNode)) {
|
|
3555
|
+
return typeNode.getTypeNodes().some((t) => t.getKind() === SyntaxKind3.UndefinedKeyword);
|
|
3556
|
+
}
|
|
3557
|
+
return false;
|
|
3528
3558
|
}
|
|
3529
3559
|
function extractParamsType(method, sourceFile, project) {
|
|
3530
3560
|
const entries = [];
|
|
@@ -4462,7 +4492,7 @@ async function watch(config, onChange) {
|
|
|
4462
4492
|
}
|
|
4463
4493
|
|
|
4464
4494
|
// src/index.ts
|
|
4465
|
-
var VERSION = "0.
|
|
4495
|
+
var VERSION = "0.9.0";
|
|
4466
4496
|
|
|
4467
4497
|
// src/cli/codegen.ts
|
|
4468
4498
|
async function runCodegen(opts = {}) {
|