Files
kill-the-news/src/domain/counters-repository.ts
T
Julien Herr a31ff42f59 refactor(domain): split Icon/WebSub/Counters out of FeedRepository
FeedRepository no longer owns favicons, WebSub subscriber lists or the
monitoring counters singleton. Each concern gets its own repository
(IconRepository, WebSubSubscriptionRepository, CountersRepository),
sharing the key schema via feed-keys. KV key strings are unchanged;
counters increment policy stays in utils/stats.ts.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-24 00:27:33 +02:00

24 lines
733 B
TypeScript

import { Counters, Env } from "../types";
import { STATS_KEY } from "./feed-keys";
/**
* KV access for the monitoring counters singleton (`stats:counters`). The
* increment policy lives in the application layer (utils/stats.ts); this
* repository owns only the raw read/write of the blob.
*/
export class CountersRepository {
constructor(private readonly kv: KVNamespace) {}
static from(env: Env): CountersRepository {
return new CountersRepository(env.EMAIL_STORAGE);
}
async getRaw(): Promise<Counters | null> {
return (await this.kv.get(STATS_KEY, { type: "json" })) as Counters | null;
}
async put(counters: Counters): Promise<void> {
await this.kv.put(STATS_KEY, JSON.stringify(counters));
}
}