UNPKG

zeno-db

Version:

A lightweight, offline-first client-side database with automatic sync capabilities

104 lines (103 loc) 2.61 kB
export interface Change { key: string; value: any; timestamp: number; clientId?: string; operation?: 'set' | 'delete'; op?: 'set' | 'delete'; } export interface StorageConfig { type: 'indexeddb'; name?: string; storeName?: string; version?: number; } export interface SyncConfig { type: 'websocket' | 'postgres'; url?: string; postgres?: { host: string; port: number; database: string; user: string; password: string; tableName?: string; pollInterval?: number; ssl?: boolean | { rejectUnauthorized?: boolean; }; }; } export interface ZenoConfig { storage: StorageConfig; sync: SyncConfig; clientId?: string; softDelete?: { enabled: boolean; fieldName?: string; permanentDeleteAfter?: number; }; syncInterval?: number; wsUrl?: string; } export interface SyncAdapter { connect(): Promise<void>; disconnect(): Promise<void>; sendChange(change: Change): Promise<void>; onConnected(callback: () => void): void; onDisconnected(callback: () => void): void; } export interface StorageAdapter { init(): Promise<void>; get(key: string): Promise<any>; set(key: string, value: any): Promise<void>; delete(key: string): Promise<void>; getAll(): Promise<Record<string, any>>; keys(): Promise<string[]>; subscribe(callback: (key: string, value: any) => void): void; notifySubscribers(key: string, value: any): void; getChanges(): Change[]; clearChanges(): void; queueChange(change: Change): void; getMany?(keys: string[]): Promise<any[]>; setMany?(items: { id: string; [key: string]: any; }[]): Promise<void>; } export type SyncEventType = 'connection_change' | 'sync_started' | 'sync_progress' | 'sync_completed'; export interface SyncStatus { isOnline: boolean; isSyncing: boolean; syncProgress: number; pendingChangesCount: number; } export interface SyncEvent { type: SyncEventType; status: SyncStatus; } export interface SoftDeleteConfig { enabled: boolean; fieldName?: string; permanentDeleteAfter?: number; } export interface ClientConfig { storage: { type: 'indexeddb'; name: string; }; sync: { type: 'websocket'; url: string; }; clientId: string; softDelete?: SoftDeleteConfig; } export interface ServerConfig { port: number; pg: { connectionString: string; table: string; }; softDelete?: SoftDeleteConfig; }