@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/dist/index.cjs CHANGED
@@ -1822,10 +1822,19 @@ function followModuleForType(name, moduleSpecifier, fromFile, project, seen) {
1822
1822
  }
1823
1823
  return null;
1824
1824
  }
1825
+ var _findTypeCache = /* @__PURE__ */ new WeakMap();
1825
1826
  function findType(name, sourceFile, project) {
1827
+ let byKey = _findTypeCache.get(project);
1828
+ if (byKey === void 0) {
1829
+ byKey = /* @__PURE__ */ new Map();
1830
+ _findTypeCache.set(project, byKey);
1831
+ }
1832
+ const key = `${sourceFile.getFilePath()}\0${name}`;
1833
+ if (byKey.has(key)) return byKey.get(key) ?? null;
1826
1834
  const local = findTypeInFile(name, sourceFile);
1827
- if (local) return local;
1828
- return resolveImportedType(name, sourceFile, project);
1835
+ const result = local ?? resolveImportedType(name, sourceFile, project);
1836
+ byKey.set(key, result);
1837
+ return result;
1829
1838
  }
1830
1839
  var _NON_REF_NAMES = /* @__PURE__ */ new Set(["string", "number", "boolean", "void", "unknown", "any", "Date"]);
1831
1840
  function _localDeclForKinds(name, file, kinds) {
@@ -1862,6 +1871,26 @@ function resolveTypeRef(nodeOrName, sourceFile, project, opts) {
1862
1871
  if (_NON_REF_NAMES.has(refName)) return null;
1863
1872
  name = refName;
1864
1873
  }
1874
+ return _resolveNamedRef(name, sourceFile, project, opts);
1875
+ }
1876
+ var _resolveNamedRefCache = /* @__PURE__ */ new WeakMap();
1877
+ function _resolveNamedRef(name, sourceFile, project, opts) {
1878
+ let byKey = _resolveNamedRefCache.get(project);
1879
+ if (byKey === void 0) {
1880
+ byKey = /* @__PURE__ */ new Map();
1881
+ _resolveNamedRefCache.set(project, byKey);
1882
+ }
1883
+ const kindsKey = [...opts.kinds].sort().join(",");
1884
+ const key = `${sourceFile.getFilePath()}\0${name}\0${kindsKey}\0${opts.allowBareSpecifier ? 1 : 0}`;
1885
+ if (byKey.has(key)) {
1886
+ const cached = byKey.get(key) ?? null;
1887
+ return cached ? { ...cached } : null;
1888
+ }
1889
+ const computed = _computeNamedRef(name, sourceFile, project, opts);
1890
+ byKey.set(key, computed);
1891
+ return computed ? { ...computed } : null;
1892
+ }
1893
+ function _computeNamedRef(name, sourceFile, project, opts) {
1865
1894
  if (_localDeclForKinds(name, sourceFile, opts.kinds)) {
1866
1895
  return { name, filePath: sourceFile.getFilePath() };
1867
1896
  }
@@ -2236,17 +2265,31 @@ var import_ts_morph6 = require("ts-morph");
2236
2265
  var import_ts_morph5 = require("ts-morph");
2237
2266
 
2238
2267
  // src/discovery/enum-resolution.ts
2268
+ var _enumCache = /* @__PURE__ */ new WeakMap();
2239
2269
  function resolveEnumValues(name, sourceFile, project) {
2270
+ let byKey = _enumCache.get(project);
2271
+ if (byKey === void 0) {
2272
+ byKey = /* @__PURE__ */ new Map();
2273
+ _enumCache.set(project, byKey);
2274
+ }
2275
+ const key = `${sourceFile.getFilePath()}\0${name}`;
2276
+ if (byKey.has(key)) {
2277
+ const cached = byKey.get(key) ?? null;
2278
+ return cached ? { values: [...cached.values], numeric: cached.numeric } : null;
2279
+ }
2240
2280
  const resolved = findType(name, sourceFile, project);
2241
- if (!resolved || resolved.kind !== "enum") return null;
2242
- let numeric = true;
2243
- const values = resolved.members.map((m) => {
2244
- const parsed = JSON.parse(m);
2245
- if (typeof parsed === "string") numeric = false;
2246
- return String(parsed);
2247
- });
2248
- if (values.length === 0) return null;
2249
- return { values, numeric };
2281
+ let result = null;
2282
+ if (resolved && resolved.kind === "enum") {
2283
+ let numeric = true;
2284
+ const values = resolved.members.map((m) => {
2285
+ const parsed = JSON.parse(m);
2286
+ if (typeof parsed === "string") numeric = false;
2287
+ return String(parsed);
2288
+ });
2289
+ if (values.length > 0) result = { values, numeric };
2290
+ }
2291
+ byKey.set(key, result);
2292
+ return result ? { values: [...result.values], numeric: result.numeric } : null;
2250
2293
  }
2251
2294
 
2252
2295
  // src/discovery/filter-field-types.ts
@@ -3565,7 +3608,7 @@ function renderTsType(node, ctx) {
3565
3608
  }
3566
3609
 
3567
3610
  // src/index.ts
3568
- var VERSION = "0.4.0";
3611
+ var VERSION = "0.4.1";
3569
3612
  // Annotate the CommonJS export names for ESM import in node:
3570
3613
  0 && (module.exports = {
3571
3614
  CodegenError,