refactor(domain): split updateFeedRecord into renameFeed and editFeed

The inPlace boolean hid two distinct intentions. Replace it with two
intention-revealing operations backed by Feed.rename (presentational,
never touches expiry) and Feed.edit (full edit, recomputes expiry,
rejects expired). Add FeedRepository.saveConfig so these config-only
edits don't re-write (and risk clobbering) the email index.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Julien Herr
2026-05-24 00:35:07 +02:00
parent c45f6677fe
commit 05388b45c8
6 changed files with 95 additions and 53 deletions
+42
View File
@@ -132,4 +132,46 @@ export class Feed {
this._metadata.emails = kept;
return { removed };
}
/**
* In-place edit of the presentational fields only. Never touches expiry or the
* sender policy — used by the dashboard's minimal title/description edit.
*/
rename(patch: { title?: string; description?: string }): void {
if (patch.title !== undefined) this._config.title = patch.title;
if (patch.description !== undefined) {
this._config.description = patch.description;
}
this._config.updated_at = Date.now();
}
/**
* Full edit: apply the patch and recompute expiry from `FEED_TTL_HOURS` or a
* supplied lifetime (an absent lifetime preserves the current expiry). Rejects
* an already-expired feed without mutating it.
*/
edit(patch: UpdateFeedInput, env: Env): { status: "ok" | "expired" } {
if (this.isExpired()) return { status: "expired" };
const expiresAt =
env.FEED_TTL_HOURS || patch.lifetimeHours !== undefined
? resolveExpiresAt(env, patch.lifetimeHours)
: this._config.expires_at;
if (patch.title !== undefined) this._config.title = patch.title;
if (patch.description !== undefined) {
this._config.description = patch.description;
}
if (patch.language !== undefined) this._config.language = patch.language;
if (patch.allowedSenders !== undefined) {
this._config.allowed_senders = patch.allowedSenders;
}
if (patch.blockedSenders !== undefined) {
this._config.blocked_senders = patch.blockedSenders;
}
this._config.updated_at = Date.now();
this._config.expires_at = expiresAt;
return { status: "ok" };
}
}