- SseHub (project-scoped client mgmt + broadcast, implements SseBroadcaster) with SSE-formatted payload; singleton getSseHub - ChatRepository (message CRUD, soft-delete, search, pagination, project isolation) + ChatService (membership permission, send/edit/delete, @email mention -> mention notification, SSE broadcast of created/updated/deleted) - SSE stream endpoint (ReadableStream + heartbeat + abort cleanup, membership) - Chat message API routes (history/send/edit/delete) - ChatWindow client (EventSource auto-reconnect, history fetch, realtime append/update/delete), chat page, ProjectNav チャット link - SseEvent type now carries ChatMessage for chat events - Unit (SseHub, ChatRepository, ChatService) + integration chat-sse-broadcast + e2e chat-sse (two contexts realtime)
74 lines
2.6 KiB
TypeScript
74 lines
2.6 KiB
TypeScript
import { getDb } from '@/lib/db/sqlite';
|
|
import { ProjectRepository } from '@/repositories/ProjectRepository';
|
|
import { ProjectMemberRepository } from '@/repositories/ProjectMemberRepository';
|
|
import { NotificationRepository } from '@/repositories/NotificationRepository';
|
|
import { ActivityLogRepository } from '@/repositories/ActivityLogRepository';
|
|
import { UserRepository } from '@/repositories/UserRepository';
|
|
import { ProjectService } from '@/services/ProjectService';
|
|
import { NotificationService } from '@/services/NotificationService';
|
|
import { ActivityLogService } from '@/services/ActivityLogService';
|
|
import { BoardService } from '@/services/BoardService';
|
|
import { BoardRepository } from '@/repositories/BoardRepository';
|
|
import { NoteService } from '@/services/NoteService';
|
|
import { ProjectNoteRepository } from '@/repositories/ProjectNoteRepository';
|
|
import { ChatService } from '@/services/ChatService';
|
|
import { ChatRepository } from '@/repositories/ChatRepository';
|
|
import { getSseHub } from '@/lib/sse/hub';
|
|
|
|
/**
|
|
* Route Handler用に各Repository/Serviceを構築するファクトリ。
|
|
* 依存はすべて同じgetDb()接続を共有し、トランザクション境界を機能させる。
|
|
*/
|
|
export function createProjectService(): ProjectService {
|
|
const db = getDb();
|
|
return new ProjectService(
|
|
new ProjectRepository(db),
|
|
new ProjectMemberRepository(db),
|
|
new NotificationRepository(db),
|
|
db
|
|
);
|
|
}
|
|
|
|
export function createNotificationService(): NotificationService {
|
|
return new NotificationService(new NotificationRepository(getDb()));
|
|
}
|
|
|
|
export function createActivityLogService(): ActivityLogService {
|
|
return new ActivityLogService(new ActivityLogRepository(getDb()));
|
|
}
|
|
|
|
export function createBoardService(): BoardService {
|
|
const db = getDb();
|
|
return new BoardService(
|
|
new BoardRepository(db),
|
|
new ProjectMemberRepository(db),
|
|
new NotificationService(new NotificationRepository(db)),
|
|
new ActivityLogService(new ActivityLogRepository(db))
|
|
);
|
|
}
|
|
|
|
export function createNoteService(): NoteService {
|
|
const db = getDb();
|
|
return new NoteService(
|
|
new ProjectNoteRepository(db),
|
|
new ProjectMemberRepository(db),
|
|
new NotificationService(new NotificationRepository(db)),
|
|
new ActivityLogService(new ActivityLogRepository(db))
|
|
);
|
|
}
|
|
|
|
export function createChatService(): ChatService {
|
|
const db = getDb();
|
|
return new ChatService(
|
|
new ChatRepository(db),
|
|
new ProjectMemberRepository(db),
|
|
new UserRepository(db),
|
|
new NotificationService(new NotificationRepository(db)),
|
|
getSseHub()
|
|
);
|
|
}
|
|
|
|
export function createUserRepository(): UserRepository {
|
|
return new UserRepository(getDb());
|
|
}
|