|
1 | 1 | import type { Logger } from '@codebuff/common/types/contracts/logger' |
| 2 | +import type { |
| 3 | + DbOperations, |
| 4 | + DbWhereResult, |
| 5 | +} from '@codebuff/common/types/contracts/database' |
2 | 6 |
|
3 | | -// ============================================================================ |
4 | | -// Database Operations Interface |
5 | | -// ============================================================================ |
6 | | - |
7 | | -/* eslint-disable @typescript-eslint/no-explicit-any */ |
8 | | -/** |
9 | | - * Minimal database interface for dependency injection in API routes. |
10 | | - * Both the real CodebuffPgDatabase and test mocks can satisfy this interface. |
11 | | - * |
12 | | - * Uses `any` for table/column parameters to be compatible with Drizzle ORM's |
13 | | - * specific table types while remaining flexible for mocks. |
14 | | - */ |
15 | | -export interface DbOperations { |
16 | | - insert: (table: any) => { |
17 | | - values: (data: any) => PromiseLike<any> |
18 | | - } |
19 | | - update: (table: any) => { |
20 | | - set: (data: any) => { |
21 | | - where: (condition: any) => PromiseLike<any> |
22 | | - } |
23 | | - } |
24 | | - select: (columns?: any) => { |
25 | | - from: (table: any) => { |
26 | | - where: (condition: any) => DbWhereResult |
27 | | - } |
28 | | - } |
29 | | -} |
30 | | - |
31 | | -/** |
32 | | - * Result type for where() that supports multiple query patterns: |
33 | | - * - .limit(n) for simple queries |
34 | | - * - .orderBy(...).limit(n) for sorted queries |
35 | | - * - .then() for promise-like resolution |
36 | | - */ |
37 | | -export interface DbWhereResult { |
38 | | - then: <TResult = any[]>( |
39 | | - onfulfilled?: ((value: any[]) => TResult | PromiseLike<TResult>) | null | undefined, |
40 | | - ) => PromiseLike<TResult> |
41 | | - limit: (n: number) => PromiseLike<any[]> |
42 | | - orderBy: (...columns: any[]) => { |
43 | | - limit: (n: number) => PromiseLike<any[]> |
44 | | - } |
45 | | -} |
46 | | -/* eslint-enable @typescript-eslint/no-explicit-any */ |
| 7 | +// Re-export database interfaces for backwards compatibility with test imports |
| 8 | +export type { DbOperations, DbWhereResult } |
47 | 9 |
|
48 | 10 | // Compatibility layer: use bun:test mock when available, otherwise identity function |
49 | 11 | // This allows the utilities to work in both Bun and Jest environments |
|
0 commit comments