refactor: split src into domain / application / infrastructure layers
Replace the history-driven lib/ + utils/ split with DDD layers: - domain/: aggregate, repositories, value objects, pure parsers/format - application/: feed-service, email-processor, feed-fetcher, stats - infrastructure/: logging, auth, KV/R2 adapters, HTTP, framework glue Pure file relocation; imports updated mechanically. Behaviour unchanged. Co-Authored-By: Claude Opus 4.7 <[email protected]>
This commit is contained in:
1 parent
ab1c15e69a
commit
7bf0f71f86
45 files changed
+90
-68
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import { Env, FeedConfig, EmailData } from "../types";
|
||||
import { MAX_FEED_ITEMS } from "../config/constants";
|
||||
import { FeedRepository } from "../domain/feed-repository";
|
||||
import { FeedId } from "../domain/value-objects/feed-id";
|
||||
|
||||
export interface FeedData {
|
||||
feedConfig: FeedConfig;
|
||||
emails: EmailData[];
|
||||
}
|
||||
|
||||
export async function fetchFeedData(
|
||||
feedId: string,
|
||||
env: Env,
|
||||
): Promise<FeedData | null> {
|
||||
const repo = FeedRepository.from(env);
|
||||
const id = FeedId.fromTrusted(feedId);
|
||||
|
||||
const feedMetadata = await repo.getMetadata(id);
|
||||
if (!feedMetadata) return null;
|
||||
|
||||
const feedConfig = (await repo.getConfig(id)) ?? {
|
||||
title: `Newsletter Feed ${feedId}`,
|
||||
description: "Converted email newsletter",
|
||||
language: "en",
|
||||
created_at: Date.now(),
|
||||
};
|
||||
|
||||
const emailRefs = feedMetadata.emails.slice(0, MAX_FEED_ITEMS);
|
||||
const emails: EmailData[] = [];
|
||||
for (const ref of emailRefs) {
|
||||
const data = await repo.getEmail(ref.key);
|
||||
if (data) emails.push(data);
|
||||
}
|
||||
|
||||
return { feedConfig, emails };
|
||||
}
|
||||
Reference in new issue
Block a user