@dudousxd/nestjs-codegen 0.4.0 → 0.4.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 +55 -12
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +55 -12
- package/dist/cli/main.js.map +1 -1
- package/dist/index.cjs +55 -12
- 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 +55 -12
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +54 -11
- package/dist/nest/index.cjs.map +1 -1
- package/dist/nest/index.js +54 -11
- package/dist/nest/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @dudousxd/nestjs-codegen
|
|
2
2
|
|
|
3
|
+
## 0.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 6a6be24: perf: memoize type and enum resolution during generation — per-`Project` `WeakMap` caches for `findType`, `resolveTypeRef`'s named-symbol arm, and `resolveEnumValues`, so a type referenced N times is resolved once. Keyed by `Project` so each (watch) run gets a fresh cache; generated output is byte-identical.
|
|
8
|
+
|
|
3
9
|
## 0.4.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/dist/cli/main.cjs
CHANGED
|
@@ -1800,10 +1800,19 @@ function followModuleForType(name, moduleSpecifier, fromFile, project, seen) {
|
|
|
1800
1800
|
}
|
|
1801
1801
|
return null;
|
|
1802
1802
|
}
|
|
1803
|
+
var _findTypeCache = /* @__PURE__ */ new WeakMap();
|
|
1803
1804
|
function findType(name, sourceFile, project) {
|
|
1805
|
+
let byKey = _findTypeCache.get(project);
|
|
1806
|
+
if (byKey === void 0) {
|
|
1807
|
+
byKey = /* @__PURE__ */ new Map();
|
|
1808
|
+
_findTypeCache.set(project, byKey);
|
|
1809
|
+
}
|
|
1810
|
+
const key = `${sourceFile.getFilePath()}\0${name}`;
|
|
1811
|
+
if (byKey.has(key)) return byKey.get(key) ?? null;
|
|
1804
1812
|
const local = findTypeInFile(name, sourceFile);
|
|
1805
|
-
|
|
1806
|
-
|
|
1813
|
+
const result = local ?? resolveImportedType(name, sourceFile, project);
|
|
1814
|
+
byKey.set(key, result);
|
|
1815
|
+
return result;
|
|
1807
1816
|
}
|
|
1808
1817
|
var _NON_REF_NAMES = /* @__PURE__ */ new Set(["string", "number", "boolean", "void", "unknown", "any", "Date"]);
|
|
1809
1818
|
function _localDeclForKinds(name, file, kinds) {
|
|
@@ -1840,6 +1849,26 @@ function resolveTypeRef(nodeOrName, sourceFile, project, opts) {
|
|
|
1840
1849
|
if (_NON_REF_NAMES.has(refName)) return null;
|
|
1841
1850
|
name = refName;
|
|
1842
1851
|
}
|
|
1852
|
+
return _resolveNamedRef(name, sourceFile, project, opts);
|
|
1853
|
+
}
|
|
1854
|
+
var _resolveNamedRefCache = /* @__PURE__ */ new WeakMap();
|
|
1855
|
+
function _resolveNamedRef(name, sourceFile, project, opts) {
|
|
1856
|
+
let byKey = _resolveNamedRefCache.get(project);
|
|
1857
|
+
if (byKey === void 0) {
|
|
1858
|
+
byKey = /* @__PURE__ */ new Map();
|
|
1859
|
+
_resolveNamedRefCache.set(project, byKey);
|
|
1860
|
+
}
|
|
1861
|
+
const kindsKey = [...opts.kinds].sort().join(",");
|
|
1862
|
+
const key = `${sourceFile.getFilePath()}\0${name}\0${kindsKey}\0${opts.allowBareSpecifier ? 1 : 0}`;
|
|
1863
|
+
if (byKey.has(key)) {
|
|
1864
|
+
const cached = byKey.get(key) ?? null;
|
|
1865
|
+
return cached ? { ...cached } : null;
|
|
1866
|
+
}
|
|
1867
|
+
const computed = _computeNamedRef(name, sourceFile, project, opts);
|
|
1868
|
+
byKey.set(key, computed);
|
|
1869
|
+
return computed ? { ...computed } : null;
|
|
1870
|
+
}
|
|
1871
|
+
function _computeNamedRef(name, sourceFile, project, opts) {
|
|
1843
1872
|
if (_localDeclForKinds(name, sourceFile, opts.kinds)) {
|
|
1844
1873
|
return { name, filePath: sourceFile.getFilePath() };
|
|
1845
1874
|
}
|
|
@@ -2214,17 +2243,31 @@ var import_ts_morph6 = require("ts-morph");
|
|
|
2214
2243
|
var import_ts_morph5 = require("ts-morph");
|
|
2215
2244
|
|
|
2216
2245
|
// src/discovery/enum-resolution.ts
|
|
2246
|
+
var _enumCache = /* @__PURE__ */ new WeakMap();
|
|
2217
2247
|
function resolveEnumValues(name, sourceFile, project) {
|
|
2248
|
+
let byKey = _enumCache.get(project);
|
|
2249
|
+
if (byKey === void 0) {
|
|
2250
|
+
byKey = /* @__PURE__ */ new Map();
|
|
2251
|
+
_enumCache.set(project, byKey);
|
|
2252
|
+
}
|
|
2253
|
+
const key = `${sourceFile.getFilePath()}\0${name}`;
|
|
2254
|
+
if (byKey.has(key)) {
|
|
2255
|
+
const cached = byKey.get(key) ?? null;
|
|
2256
|
+
return cached ? { values: [...cached.values], numeric: cached.numeric } : null;
|
|
2257
|
+
}
|
|
2218
2258
|
const resolved = findType(name, sourceFile, project);
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
const
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2259
|
+
let result = null;
|
|
2260
|
+
if (resolved && resolved.kind === "enum") {
|
|
2261
|
+
let numeric = true;
|
|
2262
|
+
const values = resolved.members.map((m) => {
|
|
2263
|
+
const parsed = JSON.parse(m);
|
|
2264
|
+
if (typeof parsed === "string") numeric = false;
|
|
2265
|
+
return String(parsed);
|
|
2266
|
+
});
|
|
2267
|
+
if (values.length > 0) result = { values, numeric };
|
|
2268
|
+
}
|
|
2269
|
+
byKey.set(key, result);
|
|
2270
|
+
return result ? { values: [...result.values], numeric: result.numeric } : null;
|
|
2228
2271
|
}
|
|
2229
2272
|
|
|
2230
2273
|
// src/discovery/filter-field-types.ts
|
|
@@ -3494,7 +3537,7 @@ async function watch(config, onChange) {
|
|
|
3494
3537
|
}
|
|
3495
3538
|
|
|
3496
3539
|
// src/index.ts
|
|
3497
|
-
var VERSION = "0.4.
|
|
3540
|
+
var VERSION = "0.4.1";
|
|
3498
3541
|
|
|
3499
3542
|
// src/cli/codegen.ts
|
|
3500
3543
|
async function runCodegen(opts = {}) {
|