/** * 通用存储适配器接口 * 提供统一的数据存储操作方法,支持不同类型的持久化方案(数据库、文件系统、内存等) */ /** * 存储配置接口 */ export interface StorageConfig { /** * 存储类型标识 */ type: string; /** * 连接配置或路径配置 */ connection?: Record; /** * 存储特定的配置参数 */ options?: Record; } /** * 查询条件接口 */ export interface QueryCondition { /** * 字段名与值的映射 */ [key: string]: any; /** * 模糊匹配字段 */ $like?: Record; /** * 范围查询字段 */ $gt?: Record; $gte?: Record; $lt?: Record; $lte?: Record; /** * 包含查询字段 */ $in?: Record; /** * 不等于查询字段 */ $ne?: Record; /** * 逻辑与 */ $and?: QueryCondition[]; /** * 逻辑或 */ $or?: QueryCondition[]; } /** * 排序条件接口 */ export interface SortOption { /** * 字段名与排序方向的映射 */ [key: string]: 'asc' | 'desc'; } /** * 通用存储适配器接口定义 */ export interface StorageAdapter { /** * 初始化存储连接 * @param config 存储配置 * @returns Promise */ initialize(config: StorageConfig): Promise; /** * 关闭存储连接 * @returns Promise */ close(): Promise; /** * 创建记录 * @param namespace 命名空间/集合/表名 * @param data 要创建的数据 * @returns Promise 创建后的记录 */ create(namespace: string, data: Partial): Promise; /** * 根据ID获取记录 * @param namespace 命名空间/集合/表名 * @param id 记录ID * @returns Promise 查询到的记录或null */ getById(namespace: string, id: string): Promise; /** * 根据条件查询记录 * @param namespace 命名空间/集合/表名 * @param query 查询条件 * @param skip 跳过的记录数 * @param limit 返回的最大记录数 * @param sort 排序条件 * @returns Promise<{data: T[], total: number}> 查询结果和总记录数 */ find( namespace: string, query?: QueryCondition, skip?: number, limit?: number, sort?: SortOption ): Promise<{data: T[], total: number}>; /** * 更新记录 * @param namespace 命名空间/集合/表名 * @param id 记录ID * @param data 更新的数据 * @returns Promise 更新后的记录或null */ update(namespace: string, id: string, data: Partial): Promise; /** * 删除记录 * @param namespace 命名空间/集合/表名 * @param id 记录ID * @returns Promise 是否删除成功 */ delete(namespace: string, id: string): Promise; /** * 批量创建记录 * @param namespace 命名空间/集合/表名 * @param dataList 要创建的记录列表 * @returns Promise 创建后的记录列表 */ bulkCreate(namespace: string, dataList: Partial[]): Promise; /** * 检查存储是否可用 * @returns Promise 存储是否可用 */ isAvailable(): Promise; }