import { BaseAdapter, AdapterConfig, SyncQuery, PushOptions, SyncResult, TableSchema, SyncMigration, ColumnDef } from '../sync-adapter.js'; import { ActiveRecord } from '../activerecord.js'; /** * Minimal subset of the `@tursodatabase/database` client API this adapter uses. * Compatible with any driver exposing prepared statements with `.run()` and * `.all()` methods (sync or async). Used for custom clients. */ export interface TursoClient { prepare(sql: string): TursoStatement; close?(): void | Promise; } export interface TursoStatement { run(...args: unknown[]): unknown | Promise; all(...args: unknown[]): unknown[] | Promise; } /** * Raw `@libsql/client` interface for type detection. * Only the methods we need are declared. */ interface LibsqlClient { execute(options: { sql: string; args?: unknown[]; }): Promise<{ rows: unknown[]; rowsAffected: number; lastInsertRowid?: number; columns: string[]; }>; close(): void; } export interface TursoAdapterConfig extends AdapterConfig { /** * A connected Turso/libSQL/SQLite client. * Pass a raw `@libsql/client` instance directly, or a custom client matching * the `TursoClient` interface for other drivers. * * If not provided, the adapter runs in HTTP mode and expects `url` to be set. */ client?: LibsqlClient | TursoClient; /** * Base URL for HTTP mode (e.g., 'http://localhost:3002'). * If provided, the adapter makes HTTP requests instead of using a direct client. */ url?: string; /** * Endpoint pattern for HTTP mode (e.g., '/{table}'). * Replaces '{table}' with the actual table name. */ endpointPattern?: string; /** Default owner_id when a record doesn't carry one (defaults to 'demo'). */ defaultOwnerId?: string; } /** * Turso (libSQL / SQLite) sync adapter. * * Provisions tables via `CREATE TABLE IF NOT EXISTS`, propagates schema * changes via `ALTER TABLE ADD COLUMN`, and handles push/pull with * version-based conflict detection. Maps the wire fields `_version` / * `_deletedAt` to the SQL columns `version` / `deleted_at`. * * @example * ```ts * import { createClient } from '@libsql/client'; * import { TursoAdapter } from 'idb-activerecord'; * * const client = createClient({ url: 'libsql://my-db.turso.io', authToken }); * const adapter = new TursoAdapter(); * await adapter.connect({ client }); * * db.enableAutoSync(adapter, { debounceMs: 500 }); * ``` */ export declare class TursoAdapter extends BaseAdapter { private client?; private rawClient?; private httpUrl?; private httpEndpointPattern?; private useHttp; connect(config: TursoAdapterConfig): Promise; disconnect(): Promise; /** * Create the table if missing, or ALTER TABLE ADD COLUMN for any newly * declared columns. SQLite's ALTER TABLE is limited (no drop/rename), * so existing columns are never modified. */ ensureTable(table: string, columns?: ColumnDef[]): Promise; pull(query: SyncQuery): Promise; push(records: T[], options?: PushOptions): Promise; getRemoteSchema(table: string): Promise; applyMigration(_migration: SyncMigration): Promise; private requireConnected; private exec; private queryAll; /** * Quote a SQL identifier (table or column). Uses double-quote SQLite syntax. * Throws on names containing double quotes or non-string input to prevent * injection through user-supplied table/column names. */ private identifier; private columnSql; private toSqliteType; private fromSqliteType; private formatDefault; private toSqlValue; /** * Shim a raw `@libsql/client` instance to the TursoClient interface. * @libsql/client uses `execute({ sql, args })` while TursoClient expects * `prepare(sql).run(...args)` / `.all(...args)`. */ private shimLibsqlClient; } export {}; //# sourceMappingURL=turso-adapter.d.ts.map