/** * 通用文件系统接口,兼容 Node.js fs 和浏览器 fs 实现 * * `size()` 和 `rmdir()` 为可选方法——某些后端适配器(如 * zen-fs-remotestoragejs 的 adaptFileSystem)不提供这两个方法, * 调用方应通过 try/catch 或类型守卫来处理其缺失的情况。 */ export interface IFileSystem { readFile(path: string, encoding: string): Promise; writeFile(path: string, data: string): Promise; readdir(path: string): Promise; mkdir(path: string, options?: { recursive?: boolean; }): Promise; stat(path: string): Promise<{ isFile(): boolean; isDirectory(): boolean; mtime: Date; }>; size?(path: string): Promise; unlink(path: string): Promise; rename(oldPath: string, newPath: string): Promise; exists(path: string): Promise; rmdir?(path: string): Promise; } /** * 存储的文档数据 */ export interface StoredDocument { _id: string; _rev: string; _deleted?: boolean; _revisions?: { start: number; ids: string[]; }; [key: string]: any; } export type SyncConflictReason = 'same' | 'remote-newer' | 'local-newer' | 'conflict' | 'unknown'; export interface SyncConflictContext { docId: string; direction: 'pull' | 'push'; reason: SyncConflictReason; localRev?: string; remoteRev?: string; } export type SyncConflictDecision = { action: 'use-local'; reason?: string; } | { action: 'use-remote'; reason?: string; } | { action: 'merge'; doc: StoredDocument | Record; reason?: string; } | { action: 'keep-conflict'; reason?: string; }; export type SyncConflictResolver = (localDoc: StoredDocument | Record, remoteDoc: StoredDocument | Record, context: SyncConflictContext) => SyncConflictDecision | Promise; /** * 数据文件内容(rev2:去 sequence,仅由 _rev 决定版本) */ export interface DataFileContent { version: string; timestamp: number; documents: StoredDocument[]; } /** * 同步选项(rev2:去 manifest / 全局 sequence / 目录重排) */ export interface SyncOptions { basePath: string; maxFileSize?: number; mergeThreshold?: number; mergeCheckInterval?: number; autoMerge?: boolean; conflictResolver?: SyncConflictResolver; onProgress?: SyncProgressCallback; } /** * 同步进度(阶段 + 各维度计数)。业务层可据此展示「服务器剩余 N 个文件待读取」「本地 M 条记录待上传」等提示。 * - phase: 'pull' | 'push' | 'done' | 'skip' * - pull 阶段:remoteFilesTotal=服务器数据文件总数,remoteFilesRead=已读取文件数,localPendingToApply=待写入本地的记录数 * - push 阶段:localDocsTotal=本地待上传文档数,localFilesWritten=已写入服务器的文件数,localFilesTotal=将生成的文件总数 */ export interface SyncProgress { phase: 'pull' | 'push' | 'done' | 'skip' | 'error'; remoteFilesTotal?: number; remoteFilesRead?: number; localPendingToApply?: number; localDocsTotal?: number; localFilesWritten?: number; localFilesTotal?: number; message?: string; } export type SyncProgressCallback = (progress: SyncProgress) => void; /** * 本地缓存:记录目标文件系统每个文档的 _rev(push 差异筛选用) */ export interface RemoteRevCache { basePath: string; revs: Record; } /** * 本地缓存:记录已写入文件的内容哈希(pull 跳过未变文件用) */ export interface ProcessedFilesCache { basePath: string; hashes: Record; } /** * 本地缓存:上次 push 的 update_seq(轻量跳过用) */ export interface SyncSeqCache { basePath: string; lastPushedSeq: number | null; } /** * 锁信息 */ export interface LockInfo { id: string; timestamp: number; operation: string; } //# sourceMappingURL=types.d.ts.map