@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.d.cts
CHANGED
|
@@ -264,6 +264,6 @@ interface FastDiscoveryOptions {
|
|
|
264
264
|
}
|
|
265
265
|
declare function discoverContractsFast(opts: FastDiscoveryOptions): Promise<RouteDescriptor[]>;
|
|
266
266
|
|
|
267
|
-
declare const VERSION = "0.5.
|
|
267
|
+
declare const VERSION = "0.5.1";
|
|
268
268
|
|
|
269
269
|
export { CodegenError, ConfigError, type FastDiscoveryOptions, type JsonSchema, type MocksEmitOptions, type OpenApiDocument, type OpenApiEmitOptions, type OpenApiInfo, ResolvedConfig, RouteDescriptor, SchemaModule, SchemaNode, type TsTypeContext, UserConfig, VERSION, ValidationAdapter, type Watcher, acquireLock, buildMocksFile, buildOpenApiSpec, defineConfig, discoverContractsFast, emitApi, emitForms, emitMocks, emitOpenApi, emitRoutes, extractSchemaFromDto, generate, loadConfig, renderTsType, resolveConfig, schemaModuleToJsonSchema, schemaNodeToJsonSchema, watch };
|
package/dist/index.d.ts
CHANGED
|
@@ -264,6 +264,6 @@ interface FastDiscoveryOptions {
|
|
|
264
264
|
}
|
|
265
265
|
declare function discoverContractsFast(opts: FastDiscoveryOptions): Promise<RouteDescriptor[]>;
|
|
266
266
|
|
|
267
|
-
declare const VERSION = "0.5.
|
|
267
|
+
declare const VERSION = "0.5.1";
|
|
268
268
|
|
|
269
269
|
export { CodegenError, ConfigError, type FastDiscoveryOptions, type JsonSchema, type MocksEmitOptions, type OpenApiDocument, type OpenApiEmitOptions, type OpenApiInfo, ResolvedConfig, RouteDescriptor, SchemaModule, SchemaNode, type TsTypeContext, UserConfig, VERSION, ValidationAdapter, type Watcher, acquireLock, buildMocksFile, buildOpenApiSpec, defineConfig, discoverContractsFast, emitApi, emitForms, emitMocks, emitOpenApi, emitRoutes, extractSchemaFromDto, generate, loadConfig, renderTsType, resolveConfig, schemaModuleToJsonSchema, schemaNodeToJsonSchema, watch };
|
package/dist/index.js
CHANGED
|
@@ -1159,18 +1159,27 @@ function refRootIdentifier(refName) {
|
|
|
1159
1159
|
function hasSource(src) {
|
|
1160
1160
|
return !!(src.schema || src.zodText || src.zodRef);
|
|
1161
1161
|
}
|
|
1162
|
+
function escapeRegExp(s) {
|
|
1163
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1164
|
+
}
|
|
1165
|
+
var wordBoundaryRegexCache = /* @__PURE__ */ new Map();
|
|
1166
|
+
function wordBoundaryRegex(token) {
|
|
1167
|
+
let re = wordBoundaryRegexCache.get(token);
|
|
1168
|
+
if (re === void 0) {
|
|
1169
|
+
re = new RegExp(`\\b${escapeRegExp(token)}\\b`, "g");
|
|
1170
|
+
wordBoundaryRegexCache.set(token, re);
|
|
1171
|
+
}
|
|
1172
|
+
return re;
|
|
1173
|
+
}
|
|
1162
1174
|
function applyRenames(text, renames) {
|
|
1163
1175
|
if (!renames || renames.size === 0) return text;
|
|
1164
1176
|
let out = text;
|
|
1165
1177
|
for (const [from, to] of renames) {
|
|
1166
1178
|
if (from === to) continue;
|
|
1167
|
-
out = out.replace(
|
|
1179
|
+
out = out.replace(wordBoundaryRegex(from), to);
|
|
1168
1180
|
}
|
|
1169
1181
|
return out;
|
|
1170
1182
|
}
|
|
1171
|
-
function escapeRegExp(s) {
|
|
1172
|
-
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1173
|
-
}
|
|
1174
1183
|
function isSelfReferential(name, text) {
|
|
1175
1184
|
return new RegExp(`\\b${escapeRegExp(name)}\\b`).test(text);
|
|
1176
1185
|
}
|
|
@@ -1182,7 +1191,23 @@ function planNestedSchemas(entries) {
|
|
|
1182
1191
|
const local = Object.entries(entry.nestedSchemas);
|
|
1183
1192
|
if (local.length === 0) continue;
|
|
1184
1193
|
const rename = /* @__PURE__ */ new Map();
|
|
1185
|
-
|
|
1194
|
+
const renameValues = /* @__PURE__ */ new Set();
|
|
1195
|
+
const setRename = (key, value) => {
|
|
1196
|
+
const prev = rename.get(key);
|
|
1197
|
+
rename.set(key, value);
|
|
1198
|
+
if (prev !== void 0 && prev !== value) {
|
|
1199
|
+
let stillUsed = false;
|
|
1200
|
+
for (const v of rename.values()) {
|
|
1201
|
+
if (v === prev) {
|
|
1202
|
+
stillUsed = true;
|
|
1203
|
+
break;
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
if (!stillUsed) renameValues.delete(prev);
|
|
1207
|
+
}
|
|
1208
|
+
renameValues.add(value);
|
|
1209
|
+
};
|
|
1210
|
+
for (const [name] of local) setRename(name, name);
|
|
1186
1211
|
const textFor = (name) => {
|
|
1187
1212
|
const raw = entry.nestedSchemas?.[name] ?? "";
|
|
1188
1213
|
return applyRenames(raw, rename);
|
|
@@ -1200,11 +1225,11 @@ function planNestedSchemas(entries) {
|
|
|
1200
1225
|
if (existing === text) continue;
|
|
1201
1226
|
let i = 2;
|
|
1202
1227
|
let candidate = `${name}_${i}`;
|
|
1203
|
-
while (globalSchemas.has(candidate) && globalSchemas.get(candidate) !== textFor(name) ||
|
|
1228
|
+
while (globalSchemas.has(candidate) && globalSchemas.get(candidate) !== textFor(name) || renameValues.has(candidate)) {
|
|
1204
1229
|
i += 1;
|
|
1205
1230
|
candidate = `${name}_${i}`;
|
|
1206
1231
|
}
|
|
1207
|
-
|
|
1232
|
+
setRename(name, candidate);
|
|
1208
1233
|
changed = true;
|
|
1209
1234
|
}
|
|
1210
1235
|
}
|
|
@@ -2502,6 +2527,7 @@ function extractSchemaFromDto(classDecl, sourceFile, project) {
|
|
|
2502
2527
|
warnings: [],
|
|
2503
2528
|
warnedDecorators: /* @__PURE__ */ new Set(),
|
|
2504
2529
|
emittedClasses: /* @__PURE__ */ new Map(),
|
|
2530
|
+
usedSchemaNames: /* @__PURE__ */ new Set(),
|
|
2505
2531
|
visiting: /* @__PURE__ */ new Set(),
|
|
2506
2532
|
recursiveSchemas: /* @__PURE__ */ new Set(),
|
|
2507
2533
|
depth: 0,
|
|
@@ -2687,6 +2713,7 @@ function buildNestedReference(className, fromFile, ctx, typeArgs = []) {
|
|
|
2687
2713
|
if (ctx.visiting.has(cacheKey)) {
|
|
2688
2714
|
const reserved = ctx.emittedClasses.get(cacheKey) ?? aliasFor(schemaBase, ctx);
|
|
2689
2715
|
ctx.emittedClasses.set(cacheKey, reserved);
|
|
2716
|
+
ctx.usedSchemaNames.add(reserved);
|
|
2690
2717
|
ctx.recursiveSchemas.add(reserved);
|
|
2691
2718
|
if (!ctx.warnedDecorators.has(`recursive:${reserved}`)) {
|
|
2692
2719
|
ctx.warnedDecorators.add(`recursive:${reserved}`);
|
|
@@ -2720,6 +2747,7 @@ function buildNestedReference(className, fromFile, ctx, typeArgs = []) {
|
|
|
2720
2747
|
});
|
|
2721
2748
|
for (const [k, v] of newBindings) ctx.typeBindings.set(k, v);
|
|
2722
2749
|
ctx.emittedClasses.set(cacheKey, schemaName);
|
|
2750
|
+
ctx.usedSchemaNames.add(schemaName);
|
|
2723
2751
|
ctx.visiting.add(cacheKey);
|
|
2724
2752
|
ctx.depth += 1;
|
|
2725
2753
|
const childNode = buildObject(resolved.decl, resolved.file, ctx);
|
|
@@ -2727,15 +2755,14 @@ function buildNestedReference(className, fromFile, ctx, typeArgs = []) {
|
|
|
2727
2755
|
ctx.visiting.delete(cacheKey);
|
|
2728
2756
|
for (const [k] of newBindings) ctx.typeBindings.delete(k);
|
|
2729
2757
|
ctx.named.set(schemaName, childNode);
|
|
2758
|
+
ctx.usedSchemaNames.add(schemaName);
|
|
2730
2759
|
return { kind: "ref", name: schemaName };
|
|
2731
2760
|
}
|
|
2732
2761
|
function aliasFor(className, ctx) {
|
|
2733
2762
|
const baseName = `${className}Schema`;
|
|
2734
2763
|
let candidate = baseName;
|
|
2735
2764
|
let i = 1;
|
|
2736
|
-
|
|
2737
|
-
for (const v of ctx.emittedClasses.values()) used.add(v);
|
|
2738
|
-
while (used.has(candidate)) {
|
|
2765
|
+
while (ctx.usedSchemaNames.has(candidate)) {
|
|
2739
2766
|
candidate = `${baseName}_${i}`;
|
|
2740
2767
|
i += 1;
|
|
2741
2768
|
}
|
|
@@ -4468,7 +4495,7 @@ function renderTsType(node, ctx) {
|
|
|
4468
4495
|
}
|
|
4469
4496
|
|
|
4470
4497
|
// src/index.ts
|
|
4471
|
-
var VERSION = "0.5.
|
|
4498
|
+
var VERSION = "0.5.1";
|
|
4472
4499
|
export {
|
|
4473
4500
|
CodegenError,
|
|
4474
4501
|
ConfigError,
|