| 26 | * @template CreateDTO 创建时的数据传输对象类型(默认排除 id 和 createdAt) |
| 27 | */ |
| 28 | export interface IEntityStore<T, CreateDTO = Omit<T, 'id' | 'createdAt'>> |
| 29 | extends IInitializable, IResettable { |
| 30 | // ==================== 读取操作 ==================== |
| 31 | |
| 32 | /** |
| 33 | * 根据 ID 获取单个实体 |
| 34 | */ |
| 35 | getById(id: string): T | undefined |
| 36 | |
| 37 | /** |
| 38 | * 获取所有实体 |
| 39 | */ |
| 40 | getAll(): T[] |
| 41 | |
| 42 | // ==================== 创建操作 ==================== |
| 43 | |
| 44 | /** |
| 45 | * 创建单个实体 |
| 46 | * @returns 创建后的完整实体(含生成的 id 和 createdAt) |
| 47 | */ |
| 48 | create(data: CreateDTO): Promise<T> |
| 49 | |
| 50 | /** |
| 51 | * 批量创建实体 |
| 52 | * @returns 创建后的完整实体数组 |
| 53 | */ |
| 54 | createMany(data: CreateDTO[]): Promise<T[]> |
| 55 | |
| 56 | // ==================== 更新操作 ==================== |
| 57 | |
| 58 | /** |
| 59 | * 更新单个实体 |
| 60 | */ |
| 61 | update(id: string, changes: Partial<T>): Promise<void> |
| 62 | |
| 63 | /** |
| 64 | * 批量更新实体 |
| 65 | */ |
| 66 | updateMany(updates: Array<{ id: string; changes: Partial<T> }>): Promise<void> |
| 67 | |
| 68 | // ==================== 删除操作 ==================== |
| 69 | |
| 70 | /** |
| 71 | * 删除单个实体 |
| 72 | */ |
| 73 | delete(id: string): Promise<void> |
| 74 | |
| 75 | /** |
| 76 | * 批量删除实体 |
| 77 | */ |
| 78 | deleteMany(ids: string[]): Promise<void> |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * 缓存型 Store 接口 |
no outgoing calls
no test coverage detected