import { ActiveRecord } from './activerecord.js'; /** * Configuration options for connecting to a sync adapter */ export interface AdapterConfig { /** * Optional connection URL. Required by HTTP mode adapters like `TursoAdapter`, * not used by client-injected adapters like `TursoAdapter` (which carry the * connection in a pre-built client instance) or `SQLiteAdapter`. */ url?: string; authToken?: string; apiKey?: string; headers?: Record; timeout?: number; } /** * Query options for pulling data from remote */ export interface SyncQuery { table: string; since?: Date; where?: Record; limit?: number; offset?: number; includeDeleted?: boolean; } /** * Options for pushing data to remote */ export interface PushOptions { table?: string; batchSize?: number; onConflict?: ConflictStrategy; skipConflicts?: boolean; } /** * Result of a sync operation */ export interface SyncResult { pushed: number; pulled: number; conflicts: number; errors: Array<{ record: unknown; error: string; }>; timestamp: Date; } /** * Schema definition for a table */ export interface TableSchema { name: string; columns: ColumnDef[]; indexes: IndexDef[]; } export interface ColumnDef { name: string; type: string; nullable: boolean; default?: unknown; primaryKey?: boolean; autoIncrement?: boolean; } export interface IndexDef { name: string; columns: string[]; unique: boolean; } /** * Migration definition for schema changes */ export interface SyncMigration { version: number; name: string; up: (db: unknown) => Promise; down: (db: unknown) => Promise; } /** * Conflict resolution strategies */ export declare enum ConflictStrategy { LOCAL_WINS = "local", REMOTE_WINS = "remote", LAST_WRITE_WINS = "timestamp", CUSTOM = "custom" } /** * Sync status for tracking operations */ export declare enum SyncStatus { IDLE = "idle", SYNCING = "syncing", ERROR = "error", OFFLINE = "offline" } /** * Sync state tracked per model */ export interface SyncState { lastSyncAt: Date | null; lastPushAt: Date | null; lastPullAt: Date | null; status: SyncStatus; pendingOperations: number; } /** * Core Sync Adapter Interface * All 3rd party adapters must implement this interface */ export interface SyncAdapter { /** Adapter configuration */ config: AdapterConfig; /** Current sync state */ state: SyncState; /** * Establish connection to the remote database */ connect(config: AdapterConfig): Promise; /** * Close connection to the remote database */ disconnect(): Promise; /** * Check if adapter is connected */ isConnected(): boolean; /** * Pull records from remote database */ pull(query: SyncQuery): Promise; /** * Push records to remote database */ push(records: T[], options?: PushOptions): Promise; /** * Fetch remote schema for a table */ getRemoteSchema(table: string): Promise; /** * Apply a migration to the remote database */ applyMigration(migration: SyncMigration): Promise; /** * Ensure a table exists on the remote, creating it if necessary. * columns is an optional hint; the server may infer schema from first push. */ ensureTable(table: string, columns?: ColumnDef[]): Promise; /** * Resolve a conflict between local and remote records */ resolveConflict(local: T, remote: T, strategy?: ConflictStrategy): Promise; } /** * Base adapter class with common functionality * All concrete adapters should extend this class */ export declare abstract class BaseAdapter implements SyncAdapter { config: AdapterConfig; state: SyncState; protected connected: boolean; protected conflictResolver?: (local: unknown, remote: unknown) => Promise; /** * Connect to the remote database */ abstract connect(config: AdapterConfig): Promise; /** * Disconnect from the remote database */ abstract disconnect(): Promise; /** * Check if currently connected */ isConnected(): boolean; /** * Pull records from remote (must be implemented by subclass) */ abstract pull(query: SyncQuery): Promise; /** * Push records to remote (must be implemented by subclass) */ abstract push(records: T[], options?: PushOptions): Promise; /** * Get remote schema (must be implemented by subclass) */ abstract getRemoteSchema(table: string): Promise; /** * Apply migration to remote (must be implemented by subclass) */ abstract applyMigration(migration: SyncMigration): Promise; ensureTable(_table: string, _columns?: ColumnDef[]): Promise; /** * Resolve conflict using specified strategy */ resolveConflict(local: T, remote: T, strategy?: ConflictStrategy): Promise; /** * Set a custom conflict resolver function */ setConflictResolver(resolver: (local: unknown, remote: unknown) => Promise): void; /** * Update sync state */ protected updateState(updates: Partial): void; /** * Helper to validate config has required fields */ protected validateConfig(requiredFields: (keyof AdapterConfig)[]): void; } //# sourceMappingURL=sync-adapter.d.ts.map