Storage implementations for AT Protocol OAuth applications. Provides a simple key-value storage interface with implementations for in-memory and SQLite backends.
at main 70 lines 1.9 kB view raw
1/** 2 * Storage interface for OAuth sessions and tokens. 3 * Compatible with @tijs/oauth-client-deno, @tijs/hono-oauth-sessions, 4 * and @tijs/atproto-sessions. 5 */ 6export interface OAuthStorage { 7 /** 8 * Retrieve a value from storage 9 * @param key - Storage key 10 * @returns The value, or null if not found or expired 11 */ 12 get<T = unknown>(key: string): Promise<T | null>; 13 14 /** 15 * Store a value in storage with optional TTL 16 * @param key - Storage key 17 * @param value - Value to store (will be JSON serialized) 18 * @param options - Optional settings 19 * @param options.ttl - Time-to-live in seconds 20 */ 21 set<T = unknown>( 22 key: string, 23 value: T, 24 options?: { ttl?: number }, 25 ): Promise<void>; 26 27 /** 28 * Delete a value from storage 29 * @param key - Storage key 30 */ 31 delete(key: string): Promise<void>; 32} 33 34/** 35 * Minimal SQLite adapter interface. 36 * Adapts any SQLite driver to work with SQLiteStorage. 37 * 38 * Use one of the pre-built adapters or implement your own: 39 * - `valTownAdapter()` - For Val.Town sqlite and libSQL/Turso 40 * - `denoSqliteAdapter()` - For @db/sqlite (Deno native) 41 * - `betterSqlite3Adapter()` - For better-sqlite3 (Node.js) 42 * 43 * @example Custom adapter 44 * ```typescript 45 * const customAdapter: SQLiteAdapter = { 46 * execute: async (sql, params) => { 47 * const result = await myDriver.query(sql, params); 48 * return result.rows; 49 * } 50 * }; 51 * ``` 52 */ 53export interface SQLiteAdapter { 54 /** 55 * Execute a SQL query with parameters. 56 * @param sql - SQL query string with ? placeholders 57 * @param params - Parameter values for placeholders 58 * @returns Array of rows, where each row is an array of column values 59 */ 60 execute(sql: string, params: unknown[]): Promise<unknown[][]>; 61} 62 63/** 64 * Logger interface for debugging storage operations 65 */ 66export interface Logger { 67 log(...args: unknown[]): void; 68 warn(...args: unknown[]): void; 69 error(...args: unknown[]): void; 70}