• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mongodb-js / mongodb-mcp-server / 16292877152

15 Jul 2025 12:10PM UTC coverage: 77.385% (+2.1%) from 75.27%
16292877152

push

github

web-flow
chore(tests): switch to vitest (#363)

498 of 687 branches covered (72.49%)

Branch coverage included in aggregate %.

0 of 27 new or added lines in 2 files covered. (0.0%)

293 existing lines in 26 files now uncovered.

2828 of 3611 relevant lines covered (78.32%)

28.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.56
/src/telemetry/eventCache.ts
1
import { LRUCache } from "lru-cache";
2✔
2
import { BaseEvent } from "./types.js";
3

4
/**
5
 * Singleton class for in-memory telemetry event caching
6
 * Provides a central storage for telemetry events that couldn't be sent
7
 * Uses LRU cache to automatically drop oldest events when limit is exceeded
8
 */
9
export class EventCache {
2✔
10
    private static instance: EventCache;
11
    private static readonly MAX_EVENTS = 1000;
36✔
12

13
    private cache: LRUCache<number, BaseEvent>;
14
    private nextId = 0;
36✔
15

16
    constructor() {
36✔
17
        this.cache = new LRUCache({
29✔
18
            max: EventCache.MAX_EVENTS,
29✔
19
            // Using FIFO eviction strategy for events
20
            allowStale: false,
29✔
21
            updateAgeOnGet: false,
29✔
22
        });
29✔
23
    }
29✔
24

25
    /**
26
     * Gets the singleton instance of EventCache
27
     * @returns The EventCache instance
28
     */
29
    public static getInstance(): EventCache {
36✔
30
        if (!EventCache.instance) {
35✔
31
            EventCache.instance = new EventCache();
29✔
32
        }
29✔
33
        return EventCache.instance;
35✔
34
    }
35✔
35

36
    /**
37
     * Gets a copy of the currently cached events
38
     * @returns Array of cached BaseEvent objects
39
     */
40
    public getEvents(): BaseEvent[] {
36✔
41
        return Array.from(this.cache.values());
34✔
42
    }
34✔
43

44
    /**
45
     * Appends new events to the cached events
46
     * LRU cache automatically handles dropping oldest events when limit is exceeded
47
     * @param events - The events to append
48
     */
49
    public appendEvents(events: BaseEvent[]): void {
36✔
50
        for (const event of events) {
×
51
            this.cache.set(this.nextId++, event);
×
UNCOV
52
        }
×
UNCOV
53
    }
×
54

55
    /**
56
     * Clears all cached events
57
     */
58
    public clearEvents(): void {
36✔
59
        this.cache.clear();
×
60
        this.nextId = 0;
×
UNCOV
61
    }
×
62
}
36✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc