@dudousxd/nestjs-codegen 0.3.0 → 0.4.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 +27 -0
- package/dist/cli/main.cjs +25 -9
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +25 -9
- 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-oH5t7x4G.d.cts → index-DA4uySjo.d.cts} +29 -1
- package/dist/{index-oH5t7x4G.d.ts → index-DA4uySjo.d.ts} +29 -1
- package/dist/index.cjs +76 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -4
- package/dist/index.d.ts +29 -4
- package/dist/index.js +75 -9
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +24 -8
- 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 +24 -8
- package/dist/nest/index.js.map +1 -1
- package/package.json +2 -2
package/dist/nest/index.d.cts
CHANGED
package/dist/nest/index.d.ts
CHANGED
package/dist/nest/index.js
CHANGED
|
@@ -427,10 +427,7 @@ function extractSchemaFromDto(classDecl, sourceFile, project) {
|
|
|
427
427
|
depth: 0
|
|
428
428
|
};
|
|
429
429
|
const root = buildObject(classDecl, sourceFile, ctx);
|
|
430
|
-
|
|
431
|
-
ctx.named.set(schemaName, { kind: "unknown", note: "recursive type \u2014 not expanded" });
|
|
432
|
-
}
|
|
433
|
-
return { root, named: ctx.named, warnings: ctx.warnings };
|
|
430
|
+
return { root, named: ctx.named, warnings: ctx.warnings, recursive: ctx.recursiveSchemas };
|
|
434
431
|
}
|
|
435
432
|
function buildObject(classDecl, classFile, ctx) {
|
|
436
433
|
const props = classDecl.getProperties();
|
|
@@ -450,7 +447,7 @@ function buildProperty(prop, classFile, ctx) {
|
|
|
450
447
|
const dec = (n) => decorators.get(n);
|
|
451
448
|
const typeNode = prop.getTypeNode();
|
|
452
449
|
const typeText = typeNode?.getText() ?? "unknown";
|
|
453
|
-
const isArrayType = !!typeNode &&
|
|
450
|
+
const isArrayType = !!typeNode && Node2.isArrayTypeNode(typeNode);
|
|
454
451
|
const typeRefName = resolveTypeFactoryName(dec("Type"));
|
|
455
452
|
if (has("ValidateNested") || typeRefName) {
|
|
456
453
|
const childName = typeRefName ?? singularClassName(typeText);
|
|
@@ -581,18 +578,27 @@ function baseFromType(typeText, isArrayType) {
|
|
|
581
578
|
}
|
|
582
579
|
}
|
|
583
580
|
function buildNestedReference(className, fromFile, ctx) {
|
|
584
|
-
if (ctx.visiting.has(className)
|
|
581
|
+
if (ctx.visiting.has(className)) {
|
|
585
582
|
const reserved = ctx.emittedClasses.get(className) ?? aliasFor(className, ctx);
|
|
586
583
|
ctx.emittedClasses.set(className, reserved);
|
|
587
584
|
ctx.recursiveSchemas.add(reserved);
|
|
588
585
|
if (!ctx.warnedDecorators.has(`recursive:${reserved}`)) {
|
|
589
586
|
ctx.warnedDecorators.add(`recursive:${reserved}`);
|
|
590
|
-
const msg = `${className} is a recursive type
|
|
587
|
+
const msg = `${className} is a recursive type; the generated schema validates it via a lazy self-reference.`;
|
|
591
588
|
ctx.warnings.push(msg);
|
|
592
589
|
console.warn(`[nestjs-codegen] ${msg}`);
|
|
593
590
|
}
|
|
594
591
|
return { kind: "lazyRef", name: reserved };
|
|
595
592
|
}
|
|
593
|
+
if (ctx.depth >= 8) {
|
|
594
|
+
if (!ctx.warnedDecorators.has(`deep:${className}`)) {
|
|
595
|
+
ctx.warnedDecorators.add(`deep:${className}`);
|
|
596
|
+
const msg = `${className} nesting is too deep to expand; the generated schema uses unknown for it.`;
|
|
597
|
+
ctx.warnings.push(msg);
|
|
598
|
+
console.warn(`[nestjs-codegen] ${msg}`);
|
|
599
|
+
}
|
|
600
|
+
return { kind: "unknown", note: "nesting too deep \u2014 not expanded" };
|
|
601
|
+
}
|
|
596
602
|
const existing = ctx.emittedClasses.get(className);
|
|
597
603
|
if (existing) return { kind: "ref", name: existing };
|
|
598
604
|
const schemaName = aliasFor(className, ctx);
|
|
@@ -2926,6 +2932,8 @@ function buildFormsFileWithAdapter(routes, outDir, adapter, config) {
|
|
|
2926
2932
|
}
|
|
2927
2933
|
const { globalSchemas, renamesByEntry } = planNestedSchemas(entries);
|
|
2928
2934
|
const irNamed = /* @__PURE__ */ new Map();
|
|
2935
|
+
const irTypeAliases = /* @__PURE__ */ new Map();
|
|
2936
|
+
const irAnnotations = /* @__PURE__ */ new Map();
|
|
2929
2937
|
const decls = [];
|
|
2930
2938
|
const mapEntries = [];
|
|
2931
2939
|
let used = false;
|
|
@@ -2933,6 +2941,8 @@ function buildFormsFileWithAdapter(routes, outDir, adapter, config) {
|
|
|
2933
2941
|
if (src.schema) {
|
|
2934
2942
|
const r = adapter.renderModule(src.schema);
|
|
2935
2943
|
for (const [n, t] of r.namedNestedSchemas) irNamed.set(n, t);
|
|
2944
|
+
if (r.namedTypeAliases) for (const [n, t] of r.namedTypeAliases) irTypeAliases.set(n, t);
|
|
2945
|
+
if (r.namedAnnotations) for (const [n, a] of r.namedAnnotations) irAnnotations.set(n, a);
|
|
2936
2946
|
return { text: r.schemaText };
|
|
2937
2947
|
}
|
|
2938
2948
|
if (src.zodText) {
|
|
@@ -3006,7 +3016,13 @@ function buildFormsFileWithAdapter(routes, outDir, adapter, config) {
|
|
|
3006
3016
|
for (const [n, t] of irNamed) if (!allNested.has(n)) allNested.set(n, t);
|
|
3007
3017
|
if (allNested.size > 0) {
|
|
3008
3018
|
lines.push("// Hoisted nested schemas (shared across endpoints).");
|
|
3009
|
-
for (const [n,
|
|
3019
|
+
for (const [n, alias] of irTypeAliases) {
|
|
3020
|
+
if (allNested.has(n)) lines.push(`${alias};`);
|
|
3021
|
+
}
|
|
3022
|
+
for (const [n, t] of allNested) {
|
|
3023
|
+
const annotation = irAnnotations.get(n);
|
|
3024
|
+
lines.push(`const ${n}${annotation ? `: ${annotation}` : ""} = ${t};`);
|
|
3025
|
+
}
|
|
3010
3026
|
lines.push("");
|
|
3011
3027
|
}
|
|
3012
3028
|
lines.push(...decls);
|