refactor(data): add I*Repository interfaces and depend on them in stores
为 /src/data/repositories/ 下每个仓库类增加对应的接口契约,
接口文件存放在独立的 interfaces/ 子目录中。
改动:
- 新建 4 个接口文件 (iauth_repository / ichat_repository /
imetrics_repository / iuser_repository),纯 type-only,方法签名
与实现类完全一致
- 4 个实现类加 implements I{Name}Repository 子句,编译器自动校验契约
- 3 个 stores 文件 (auth / chat / user state machines) 改为依赖接口
类型:通过 `const xxxRepo: I{Name}Repository = xxxRepository` 局部别名,
actor 内部调用全部走别名
- barrelsby.json 加入 interfaces/ 目录,让自动 barrel 能覆盖
- Auto-regenerated repositories/index.ts 与 interfaces/index.ts
参照 storage 层已有的 IAuthStorage / IChatStorage / IUserStorage 模式。
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
"use client";
|
||||
|
||||
/**
|
||||
* IChatRepository 接口
|
||||
*
|
||||
* 对齐 Dart 端 `ChatRepository` 抽象(lib/data/repositories/chat_repository.dart):
|
||||
* - 远程:发送消息、获取历史
|
||||
* - 本地:写入 / 批量覆盖 / 读取 / 清空 / 计数
|
||||
*
|
||||
* 私有助手(`_chatToLocal` / `_localToChat` / `_mapLocalStorageResult`)不暴露。
|
||||
* 原始 Dart: lib/data/repositories/chat_repository_impl.dart
|
||||
*/
|
||||
|
||||
import type { Result } from "@/utils/result";
|
||||
import type { ChatHistoryResponse } from "@/data/dto/chat/chat_history_response";
|
||||
import type { ChatMessage } from "@/data/dto/chat/chat_message";
|
||||
import type { ChatSendResponse } from "@/data/dto/chat/chat_send_response";
|
||||
|
||||
export interface IChatRepository {
|
||||
/** 发送一条消息。 */
|
||||
sendMessage(
|
||||
message: string,
|
||||
options?: { image?: string; useWebSocket?: boolean },
|
||||
): Promise<Result<ChatSendResponse>>;
|
||||
|
||||
/** 获取聊天历史,分页参数默认 limit=50, offset=0。 */
|
||||
getHistory(limit?: number, offset?: number): Promise<Result<ChatHistoryResponse>>;
|
||||
|
||||
/** 把一条消息写入本地存储。 */
|
||||
saveMessageToLocal(message: ChatMessage): Promise<Result<void>>;
|
||||
|
||||
/** 批量覆盖写入:先清空本地存储,再写入新列表。 */
|
||||
saveMessagesToLocal(messages: readonly ChatMessage[]): Promise<Result<void>>;
|
||||
|
||||
/** 读取所有本地消息,按 dbId 升序。 */
|
||||
getLocalMessages(): Promise<Result<ChatMessage[]>>;
|
||||
|
||||
/** 清空本地消息。 */
|
||||
clearLocalMessages(): Promise<Result<void>>;
|
||||
|
||||
/** 获取本地消息数量。 */
|
||||
getLocalMessageCount(): Promise<Result<number>>;
|
||||
}
|
||||
Reference in New Issue
Block a user