@dudousxd/nestjs-codegen 0.5.0 → 0.5.1
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 +6 -0
- package/dist/cli/main.cjs +38 -11
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +38 -11
- package/dist/cli/main.js.map +1 -1
- package/dist/index.cjs +38 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +38 -11
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +37 -10
- package/dist/nest/index.cjs.map +1 -1
- package/dist/nest/index.js +37 -10
- package/dist/nest/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1216,18 +1216,27 @@ function refRootIdentifier(refName) {
|
|
|
1216
1216
|
function hasSource(src) {
|
|
1217
1217
|
return !!(src.schema || src.zodText || src.zodRef);
|
|
1218
1218
|
}
|
|
1219
|
+
function escapeRegExp(s) {
|
|
1220
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1221
|
+
}
|
|
1222
|
+
var wordBoundaryRegexCache = /* @__PURE__ */ new Map();
|
|
1223
|
+
function wordBoundaryRegex(token) {
|
|
1224
|
+
let re = wordBoundaryRegexCache.get(token);
|
|
1225
|
+
if (re === void 0) {
|
|
1226
|
+
re = new RegExp(`\\b${escapeRegExp(token)}\\b`, "g");
|
|
1227
|
+
wordBoundaryRegexCache.set(token, re);
|
|
1228
|
+
}
|
|
1229
|
+
return re;
|
|
1230
|
+
}
|
|
1219
1231
|
function applyRenames(text, renames) {
|
|
1220
1232
|
if (!renames || renames.size === 0) return text;
|
|
1221
1233
|
let out = text;
|
|
1222
1234
|
for (const [from, to] of renames) {
|
|
1223
1235
|
if (from === to) continue;
|
|
1224
|
-
out = out.replace(
|
|
1236
|
+
out = out.replace(wordBoundaryRegex(from), to);
|
|
1225
1237
|
}
|
|
1226
1238
|
return out;
|
|
1227
1239
|
}
|
|
1228
|
-
function escapeRegExp(s) {
|
|
1229
|
-
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1230
|
-
}
|
|
1231
1240
|
function isSelfReferential(name, text) {
|
|
1232
1241
|
return new RegExp(`\\b${escapeRegExp(name)}\\b`).test(text);
|
|
1233
1242
|
}
|
|
@@ -1239,7 +1248,23 @@ function planNestedSchemas(entries) {
|
|
|
1239
1248
|
const local = Object.entries(entry.nestedSchemas);
|
|
1240
1249
|
if (local.length === 0) continue;
|
|
1241
1250
|
const rename = /* @__PURE__ */ new Map();
|
|
1242
|
-
|
|
1251
|
+
const renameValues = /* @__PURE__ */ new Set();
|
|
1252
|
+
const setRename = (key, value) => {
|
|
1253
|
+
const prev = rename.get(key);
|
|
1254
|
+
rename.set(key, value);
|
|
1255
|
+
if (prev !== void 0 && prev !== value) {
|
|
1256
|
+
let stillUsed = false;
|
|
1257
|
+
for (const v of rename.values()) {
|
|
1258
|
+
if (v === prev) {
|
|
1259
|
+
stillUsed = true;
|
|
1260
|
+
break;
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
if (!stillUsed) renameValues.delete(prev);
|
|
1264
|
+
}
|
|
1265
|
+
renameValues.add(value);
|
|
1266
|
+
};
|
|
1267
|
+
for (const [name] of local) setRename(name, name);
|
|
1243
1268
|
const textFor = (name) => {
|
|
1244
1269
|
const raw = entry.nestedSchemas?.[name] ?? "";
|
|
1245
1270
|
return applyRenames(raw, rename);
|
|
@@ -1257,11 +1282,11 @@ function planNestedSchemas(entries) {
|
|
|
1257
1282
|
if (existing === text) continue;
|
|
1258
1283
|
let i = 2;
|
|
1259
1284
|
let candidate = `${name}_${i}`;
|
|
1260
|
-
while (globalSchemas.has(candidate) && globalSchemas.get(candidate) !== textFor(name) ||
|
|
1285
|
+
while (globalSchemas.has(candidate) && globalSchemas.get(candidate) !== textFor(name) || renameValues.has(candidate)) {
|
|
1261
1286
|
i += 1;
|
|
1262
1287
|
candidate = `${name}_${i}`;
|
|
1263
1288
|
}
|
|
1264
|
-
|
|
1289
|
+
setRename(name, candidate);
|
|
1265
1290
|
changed = true;
|
|
1266
1291
|
}
|
|
1267
1292
|
}
|
|
@@ -2549,6 +2574,7 @@ function extractSchemaFromDto(classDecl, sourceFile, project) {
|
|
|
2549
2574
|
warnings: [],
|
|
2550
2575
|
warnedDecorators: /* @__PURE__ */ new Set(),
|
|
2551
2576
|
emittedClasses: /* @__PURE__ */ new Map(),
|
|
2577
|
+
usedSchemaNames: /* @__PURE__ */ new Set(),
|
|
2552
2578
|
visiting: /* @__PURE__ */ new Set(),
|
|
2553
2579
|
recursiveSchemas: /* @__PURE__ */ new Set(),
|
|
2554
2580
|
depth: 0,
|
|
@@ -2734,6 +2760,7 @@ function buildNestedReference(className, fromFile, ctx, typeArgs = []) {
|
|
|
2734
2760
|
if (ctx.visiting.has(cacheKey)) {
|
|
2735
2761
|
const reserved = ctx.emittedClasses.get(cacheKey) ?? aliasFor(schemaBase, ctx);
|
|
2736
2762
|
ctx.emittedClasses.set(cacheKey, reserved);
|
|
2763
|
+
ctx.usedSchemaNames.add(reserved);
|
|
2737
2764
|
ctx.recursiveSchemas.add(reserved);
|
|
2738
2765
|
if (!ctx.warnedDecorators.has(`recursive:${reserved}`)) {
|
|
2739
2766
|
ctx.warnedDecorators.add(`recursive:${reserved}`);
|
|
@@ -2767,6 +2794,7 @@ function buildNestedReference(className, fromFile, ctx, typeArgs = []) {
|
|
|
2767
2794
|
});
|
|
2768
2795
|
for (const [k, v] of newBindings) ctx.typeBindings.set(k, v);
|
|
2769
2796
|
ctx.emittedClasses.set(cacheKey, schemaName);
|
|
2797
|
+
ctx.usedSchemaNames.add(schemaName);
|
|
2770
2798
|
ctx.visiting.add(cacheKey);
|
|
2771
2799
|
ctx.depth += 1;
|
|
2772
2800
|
const childNode = buildObject(resolved.decl, resolved.file, ctx);
|
|
@@ -2774,15 +2802,14 @@ function buildNestedReference(className, fromFile, ctx, typeArgs = []) {
|
|
|
2774
2802
|
ctx.visiting.delete(cacheKey);
|
|
2775
2803
|
for (const [k] of newBindings) ctx.typeBindings.delete(k);
|
|
2776
2804
|
ctx.named.set(schemaName, childNode);
|
|
2805
|
+
ctx.usedSchemaNames.add(schemaName);
|
|
2777
2806
|
return { kind: "ref", name: schemaName };
|
|
2778
2807
|
}
|
|
2779
2808
|
function aliasFor(className, ctx) {
|
|
2780
2809
|
const baseName = `${className}Schema`;
|
|
2781
2810
|
let candidate = baseName;
|
|
2782
2811
|
let i = 1;
|
|
2783
|
-
|
|
2784
|
-
for (const v of ctx.emittedClasses.values()) used.add(v);
|
|
2785
|
-
while (used.has(candidate)) {
|
|
2812
|
+
while (ctx.usedSchemaNames.has(candidate)) {
|
|
2786
2813
|
candidate = `${baseName}_${i}`;
|
|
2787
2814
|
i += 1;
|
|
2788
2815
|
}
|
|
@@ -4510,7 +4537,7 @@ function renderTsType(node, ctx) {
|
|
|
4510
4537
|
}
|
|
4511
4538
|
|
|
4512
4539
|
// src/index.ts
|
|
4513
|
-
var VERSION = "0.5.
|
|
4540
|
+
var VERSION = "0.5.1";
|
|
4514
4541
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4515
4542
|
0 && (module.exports = {
|
|
4516
4543
|
CodegenError,
|