From f2c49872a6b604c82372f886d801d61392328e68 Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Wed, 28 May 2025 13:20:01 +0000 Subject: [PATCH] fix: resolve TypeScript errors in database service implementation - Remove unnecessary generic type parameter from AbsurdSqlDatabaseService - Fix type handling in operation queue and result processing - Correct WebPlatformService dbGetOneRow implementation to use imported databaseService - Add proper type annotations for database operation results This commit improves type safety and fixes several TypeScript errors that were preventing proper type checking in the database service layer. --- src/services/AbsurdSqlDatabaseService.ts | 28 +++++++++----------- src/services/platforms/WebPlatformService.ts | 4 +++ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/services/AbsurdSqlDatabaseService.ts b/src/services/AbsurdSqlDatabaseService.ts index 4695251c..4df552a8 100644 --- a/src/services/AbsurdSqlDatabaseService.ts +++ b/src/services/AbsurdSqlDatabaseService.ts @@ -6,11 +6,11 @@ import { runMigrations } from "../db-sql/migration"; import type { DatabaseService, QueryExecResult } from "../interfaces/database"; import { logger } from "@/utils/logger"; -interface QueuedOperation { +interface QueuedOperation { type: "run" | "query" | "getOneRow" | "getAll"; sql: string; params: unknown[]; - resolve: (value: T) => void; + resolve: (value: unknown) => void; reject: (reason: unknown) => void; } @@ -22,12 +22,12 @@ interface AbsurdSqlDatabase { ) => Promise<{ changes: number; lastId?: number }>; } -class AbsurdSqlDatabaseService implements DatabaseService { +class AbsurdSqlDatabaseService implements DatabaseService { private static instance: AbsurdSqlDatabaseService | null = null; private db: AbsurdSqlDatabase | null; private initialized: boolean; private initializationPromise: Promise | null = null; - private operationQueue: Array> = []; + private operationQueue: Array = []; private isProcessingQueue: boolean = false; private constructor() { @@ -123,9 +123,7 @@ class AbsurdSqlDatabaseService implements DatabaseService { if (!operation) continue; try { - let result; - let queryResult; - let allResult; + let result: unknown; switch (operation.type) { case "run": result = await this.db.run(operation.sql, operation.params); @@ -134,11 +132,11 @@ class AbsurdSqlDatabaseService implements DatabaseService { result = await this.db.exec(operation.sql, operation.params); break; case "getOneRow": - queryResult = await this.db.exec(operation.sql, operation.params); + const queryResult = await this.db.exec(operation.sql, operation.params); result = queryResult[0]?.values[0]; break; case "getAll": - allResult = await this.db.exec(operation.sql, operation.params); + const allResult = await this.db.exec(operation.sql, operation.params); result = allResult[0]?.values || []; break; } @@ -151,17 +149,17 @@ class AbsurdSqlDatabaseService implements DatabaseService { this.isProcessingQueue = false; } - private async queueOperation( - type: QueuedOperation["type"], + private async queueOperation( + type: QueuedOperation["type"], sql: string, params: unknown[] = [], - ): Promise { - return new Promise((resolve, reject) => { - const operation: QueuedOperation = { + ): Promise { + return new Promise((resolve, reject) => { + const operation: QueuedOperation = { type, sql, params, - resolve, + resolve: (value: unknown) => resolve(value as R), reject, }; this.operationQueue.push(operation); diff --git a/src/services/platforms/WebPlatformService.ts b/src/services/platforms/WebPlatformService.ts index 14c51f76..8f8dd6b9 100644 --- a/src/services/platforms/WebPlatformService.ts +++ b/src/services/platforms/WebPlatformService.ts @@ -381,4 +381,8 @@ export class WebPlatformService implements PlatformService { ): Promise<{ changes: number; lastId?: number }> { return databaseService.run(sql, params); } + + async dbGetOneRow(sql: string, params?: unknown[]): Promise { + return databaseService.query(sql, params).then((result: QueryExecResult[]) => result[0]?.values[0]); + } }