@fre4x/hn 1.0.43 → 1.0.45

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.
Files changed (2) hide show
  1. package/dist/index.js +11 -0
  2. package/package.json +2 -1
package/dist/index.js CHANGED
@@ -45515,6 +45515,7 @@ var HNApiClient = class {
45515
45515
  cache = /* @__PURE__ */ new Map();
45516
45516
  CACHE_TTL_MS = 60 * 1e3;
45517
45517
  // 60 seconds
45518
+ MAX_CACHE_SIZE = 100;
45518
45519
  /**
45519
45520
  * Helper to fetch data with a short TTL cache.
45520
45521
  * Useful for list endpoints that are paginated, preventing full re-fetches
@@ -45523,9 +45524,19 @@ var HNApiClient = class {
45523
45524
  async fetchWithCache(url3) {
45524
45525
  const cached2 = this.cache.get(url3);
45525
45526
  if (cached2 && Date.now() - cached2.timestamp < this.CACHE_TTL_MS) {
45527
+ this.cache.delete(url3);
45528
+ this.cache.set(url3, cached2);
45526
45529
  return cached2.data;
45527
45530
  }
45528
45531
  const response = await httpClient.get(`${url3}.json`);
45532
+ if (this.cache.has(url3)) {
45533
+ this.cache.delete(url3);
45534
+ } else if (this.cache.size >= this.MAX_CACHE_SIZE) {
45535
+ const oldestKey = this.cache.keys().next().value;
45536
+ if (oldestKey !== void 0) {
45537
+ this.cache.delete(oldestKey);
45538
+ }
45539
+ }
45529
45540
  this.cache.set(url3, { data: response.data, timestamp: Date.now() });
45530
45541
  return response.data;
45531
45542
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fre4x/hn",
3
- "version": "1.0.43",
3
+ "version": "1.0.45",
4
4
  "description": "A Hacker News MCP server for LLMs.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -16,6 +16,7 @@
16
16
  "start": "node dist/index.js",
17
17
  "dev": "tsx src/index.ts",
18
18
  "watch": "tsc -w",
19
+ "inspector": "cross-env MOCK=true npx @modelcontextprotocol/inspector node dist/index.js",
19
20
  "test": "vitest run --passWithNoTests --exclude dist"
20
21
  },
21
22
  "keywords": [