mirror of
https://github.com/juherr/kill-the-news.git
synced 2026-06-20 22:03:48 +00:00
f823a5f222
Make the domain stop depending on infrastructure ("imports point inward").
- Point 2: relocate the four KV adapters (FeedRepository, IconRepository,
WebSubSubscriptionRepository, CountersRepository) from domain/ to
infrastructure/, where the logger import is legitimate. The domain now keeps
only the pure key schema (feed-keys.ts), the Feed aggregate and value objects;
it imports nothing outward. Deliberately no hand-rolled 24-method port
interface (YAGNI without DI) — relocation alone fixes the direction.
- Point 6c: EmailParser.extractFeedId now returns a validated FeedId value
object instead of a raw string, so the most untrusted input (an inbound
recipient address) is guarded at the parse boundary and no longer round-trips
through FeedId.fromTrusted in the ingest path.
All import paths updated; CLAUDE.md source layout/KV-schema notes updated.
351 tests pass; tsc --noEmit clean.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
32 lines
937 B
TypeScript
32 lines
937 B
TypeScript
import { Env } from "../types";
|
|
import { feedKeys } from "../domain/feed-keys";
|
|
|
|
/**
|
|
* KV access for cached per-domain favicons (`icon:<domain>`). Entries may be
|
|
* positive (base64 bytes) or negative (a sentinel marking a failed fetch), and
|
|
* always carry a TTL — the cache's sole expiry mechanism.
|
|
*/
|
|
export class IconRepository {
|
|
constructor(private readonly kv: KVNamespace) {}
|
|
|
|
static from(env: Env): IconRepository {
|
|
return new IconRepository(env.EMAIL_STORAGE);
|
|
}
|
|
|
|
getText(domain: string): Promise<string | null> {
|
|
return this.kv.get(feedKeys.icon(domain), "text");
|
|
}
|
|
|
|
async getJson<T>(domain: string): Promise<T | null> {
|
|
return (await this.kv.get(feedKeys.icon(domain), {
|
|
type: "json",
|
|
})) as T | null;
|
|
}
|
|
|
|
async put(domain: string, value: string, ttlSeconds: number): Promise<void> {
|
|
await this.kv.put(feedKeys.icon(domain), value, {
|
|
expirationTtl: ttlSeconds,
|
|
});
|
|
}
|
|
}
|