11import type { Logger } from '@codebuff/common/types/contracts/logger'
22
33// ============================================================================
4- // Testable Database Interface
4+ // Database Operations Interface
55// ============================================================================
66
77/* eslint-disable @typescript-eslint/no-explicit-any */
88/**
99 * Minimal database interface for dependency injection in API routes.
1010 * Both the real CodebuffPgDatabase and test mocks can satisfy this interface.
1111 *
12- * This allows tests to provide mock implementations without type casting.
1312 * Uses `any` for table/column parameters to be compatible with Drizzle ORM's
1413 * specific table types while remaining flexible for mocks.
1514 */
16- export interface TestableDb {
15+ export interface DbOperations {
1716 insert : ( table : any ) => {
1817 values : ( data : any ) => PromiseLike < any >
1918 }
@@ -24,7 +23,7 @@ export interface TestableDb {
2423 }
2524 select : ( columns ?: any ) => {
2625 from : ( table : any ) => {
27- where : ( condition : any ) => TestableDbWhereResult
26+ where : ( condition : any ) => DbWhereResult
2827 }
2928 }
3029}
@@ -35,7 +34,7 @@ export interface TestableDb {
3534 * - .orderBy(...).limit(n) for sorted queries
3635 * - .then() for promise-like resolution
3736 */
38- export interface TestableDbWhereResult {
37+ export interface DbWhereResult {
3938 then : < TResult = any [ ] > (
4039 onfulfilled ?: ( ( value : any [ ] ) => TResult | PromiseLike < TResult > ) | null | undefined ,
4140 ) => PromiseLike < TResult >
@@ -364,9 +363,9 @@ export interface MockDbFactoryConfig {
364363
365364/**
366365 * Return type of createMockDb - a complete mock database object.
367- * Implements TestableDb for type-safe dependency injection in tests.
366+ * Implements DbOperations for type-safe dependency injection in tests.
368367 */
369- export type MockDb = TestableDb
368+ export type MockDb = DbOperations
370369
371370/**
372371 * Creates a complete mock database object with insert, update, and select operations.
@@ -393,13 +392,13 @@ export type MockDb = TestableDb
393392 * })
394393 * ```
395394 */
396- export function createMockDb ( config : MockDbFactoryConfig = { } ) : TestableDb {
397- // Use type assertion since Mock types don't perfectly match TestableDb
395+ export function createMockDb ( config : MockDbFactoryConfig = { } ) : DbOperations {
396+ // Use type assertion since Mock types don't perfectly match DbOperations
398397 // but the runtime behavior is correct
399398 return {
400399 insert : createMockDbInsert ( config . insert ) ,
401400 update : createMockDbUpdate ( config . update ) ,
402- select : createMockDbSimpleSelect ( config . select ) as TestableDb [ 'select' ] ,
401+ select : createMockDbSimpleSelect ( config . select ) as DbOperations [ 'select' ] ,
403402 }
404403}
405404
@@ -421,10 +420,10 @@ export function createMockDbWithErrors(config: {
421420 selectError ?: Error
422421 /** Results to return from select queries (before any error is thrown) */
423422 selectResults ?: unknown [ ]
424- } = { } ) : TestableDb {
423+ } = { } ) : DbOperations {
425424 const { insertError, updateError, selectError, selectResults = [ ] } = config
426425
427- // Use type assertion since Mock types don't perfectly match TestableDb
426+ // Use type assertion since Mock types don't perfectly match DbOperations
428427 // but the runtime behavior is correct
429428 return {
430429 insert : mock ( ( ) => ( {
@@ -466,7 +465,7 @@ export function createMockDbWithErrors(config: {
466465 return cb ?.( selectResults ) ?? selectResults
467466 } ) ,
468467 } ) ) ,
469- } ) ) as TestableDb [ 'select' ] ,
468+ } ) ) as DbOperations [ 'select' ] ,
470469 }
471470}
472471
@@ -494,8 +493,8 @@ export function createMockDbWithErrors(config: {
494493 * })
495494 * ```
496495 */
497- export function createSelectOnlyMockDb ( selectResults : unknown [ ] ) : TestableDb {
498- const createWhereResult = ( ) : TestableDbWhereResult => ( {
496+ export function createSelectOnlyMockDb ( selectResults : unknown [ ] ) : DbOperations {
497+ const createWhereResult = ( ) : DbWhereResult => ( {
499498 then : < TResult = unknown [ ] > (
500499 onfulfilled ?:
501500 | ( ( value : unknown [ ] ) => TResult | PromiseLike < TResult > )
0 commit comments