// ── Event types ────────────────────────────────────────────── export type EventType = 'put' | 'delete'; export interface SyncEvent { type: EventType; store: string; // "kv" | collection name key: string; id?: string; // present for collection documents ts: number; // millisecond Unix epoch clientId: string; data?: unknown; // absent on deletes rev?: number; } // ── Index / collection options ─────────────────────────────── export interface IndexDefinition { name: string; fields: (keyof T & string)[] | string[]; } export interface StoreOptions { name: string; indexes?: IndexDefinition[]; } export interface OpenOptions { dbName?: string; autoSyncIntervalMs?: number; clientId?: string; conflictResolver?: (current: unknown, incoming: unknown) => unknown; /** Passed to sqlite3InitModule(). Use locateFile to override .wasm loading. */ sqlite3Config?: Record; } // ── Store record shapes ────────────────────────────────────── export interface KVRecord { key: string; value: unknown; ts: number; rev: number; } export interface DocRecord { store: string; id: string; data: unknown; ts: number; rev: number; deleted?: boolean; } // ── Index range (replaces IDBKeyRange for SQLite) ──────────── export interface IndexRange { gt?: unknown; gte?: unknown; lt?: unknown; lte?: unknown; } // ── Event emitter ──────────────────────────────────────────── export type SyncDBEventName = | 'sync:start' | 'sync:end' | 'change' | 'conflict' | 'folder:lost-permission'; export type SyncDBEventHandler = (...args: unknown[]) => void; // ── KV API surface ─────────────────────────────────────────── export interface KVApi { get(key: string): Promise; set(key: string, value: T): Promise; delete(key: string): Promise; has(key: string): Promise; keys(): Promise; entries(): Promise>; } // ── Collection API surface ─────────────────────────────────── export interface CollectionApi { get(id: string): Promise; put(doc: T): Promise; delete(id: string): Promise; all(): Promise; findByIndex(indexName: string, value: unknown): Promise; queryByIndex(indexName: string, range: IndexRange): Promise; }