mirror of
https://github.com/juherr/kill-the-news.git
synced 2026-06-21 06:13:48 +00:00
a31ff42f59
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>
24 lines
733 B
TypeScript
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));
|
|
}
|
|
}
|