Move four DDD tensions on the Feed aggregate to ground: - #1 The aggregate now holds a domain FeedState (camelCase) instead of the snake_case FeedConfig DTO; infrastructure/feed-mapper.ts owns the FeedState<->FeedConfig/FeedListItem translation as the sole snake_case site outside the HTTP edge. - #3 Replace the edit() recomputeExpiry control flag with a Lifetime VO: passing a lifetime recomputes expiry, omitting it preserves the current one (the dashboard quick-edit path). - #4 Domain events carry their own feedId; dispatchFeedEvents centralizes the drain+dispatch in the application layer (no more manual pullEvents at call sites), keeping infra->application dependency direction intact. - #6 Rename FeedId.fromTrusted to FeedId.unchecked to make the absence of revalidation explicit. Adds Lifetime + feed-mapper round-trip tests. 353 tests green, tsc clean, wrangler dry-run OK. Docs (CLAUDE.md) synced. Co-Authored-By: Claude Opus 4.7 <[email protected]>
52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
import { FeedConfig, FeedListItem } from "../types";
|
|
import { FeedState } from "../domain/feed-state";
|
|
import { FeedId } from "../domain/value-objects/feed-id";
|
|
|
|
/**
|
|
* The translation seam between the Feed aggregate's domain state (camelCase) and
|
|
* the persistence/edge DTOs (`FeedConfig`/`FeedListItem`, snake_case). This is
|
|
* the ONLY place outside the HTTP edge that knows the stored field names — the
|
|
* domain stays free of the storage dialect, and the repository round-trips
|
|
* through here on every load/save.
|
|
*/
|
|
|
|
/** Persisted config DTO → domain state (used by `FeedRepository.load`). */
|
|
export function fromConfigDTO(dto: FeedConfig): FeedState {
|
|
return {
|
|
title: dto.title,
|
|
description: dto.description,
|
|
language: dto.language,
|
|
author: dto.author,
|
|
allowedSenders: dto.allowed_senders ?? [],
|
|
blockedSenders: dto.blocked_senders ?? [],
|
|
createdAt: dto.created_at,
|
|
updatedAt: dto.updated_at,
|
|
expiresAt: dto.expires_at,
|
|
};
|
|
}
|
|
|
|
/** Domain state → persisted config DTO (used by `FeedRepository.save`). */
|
|
export function toConfigDTO(state: FeedState): FeedConfig {
|
|
return {
|
|
title: state.title,
|
|
description: state.description,
|
|
language: state.language,
|
|
author: state.author,
|
|
allowed_senders: state.allowedSenders,
|
|
blocked_senders: state.blockedSenders,
|
|
created_at: state.createdAt,
|
|
updated_at: state.updatedAt,
|
|
expires_at: state.expiresAt,
|
|
};
|
|
}
|
|
|
|
/** Domain state → the projection cached in the global `feeds:list` registry. */
|
|
export function toListItemDTO(id: FeedId, state: FeedState): FeedListItem {
|
|
return {
|
|
id: id.value,
|
|
title: state.title,
|
|
description: state.description,
|
|
expires_at: state.expiresAt,
|
|
};
|
|
}
|