refactor(domain): extract the KV key schema into feed-keys.ts

Move the feed:/icon:/websub: key builders out of FeedRepository into a
pure feed-keys module so the wire format lives in one place, shared by
the repositories to come. Strings are byte-identical; behaviour unchanged.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Julien Herr
2026-05-24 00:24:43 +02:00
parent 49f69ff19e
commit b347f2f625
2 changed files with 54 additions and 15 deletions
+40
View File
@@ -0,0 +1,40 @@
import { FEEDS_LIST_KEY, STATS_KEY } from "../config/constants";
/**
* The KV key schema, in one pure place. Every repository builds its keys here so
* the wire format lives in a single module — never inline a `feed:`/`icon:`/
* `websub:` string elsewhere. Strings are byte-identical to the original schema;
* changing them would require migrating live KV data.
*/
const WEBSUB_PREFIX = "websub:subs:";
export const feedKeys = {
config: (feedId: string): string => `feed:${feedId}:config`,
metadata: (feedId: string): string => `feed:${feedId}:metadata`,
/** Prefix covering every key owned by a feed (config, metadata, emails). */
feedPrefix: (feedId: string): string => `feed:${feedId}:`,
/** Mint a fresh, time-ordered email key. Call once and reuse the result. */
newEmail: (feedId: string): string => `feed:${feedId}:${Date.now()}`,
/** KV key for a domain's cached favicon (shared across feeds). */
icon: (domain: string): string => `icon:${domain}`,
websub: (feedId: string): string => `${WEBSUB_PREFIX}${feedId}`,
/** Prefix matching every per-feed WebSub subscription key. */
websubPrefix: (): string => WEBSUB_PREFIX,
/** True when `key` is an email entry (not the feed's config/metadata key). */
isEmail: (feedId: string, key: string): boolean => {
const suffix = key.slice(feedKeys.feedPrefix(feedId).length);
return suffix !== "config" && suffix !== "metadata";
},
/** Recover the feed id embedded in an email key (`feed:<id>:<ts>`). */
feedIdFromEmail: (key: string): string => key.split(":")[1],
} as const;
export { FEEDS_LIST_KEY, STATS_KEY };