forked from jsnbuchanan/crowd-funder-for-time-pwa
fix(db): resolve type compatibility in AbsurdSqlDatabaseService
- Make QueuedOperation interface generic to properly handle operation types - Fix type compatibility between queue operations and their resolvers - Use explicit typing for operation queue to handle generic types - Maintain type safety while allowing different operation return types This fixes a TypeScript error where the operation queue's resolve function was not properly typed to handle generic return types from database operations.
This commit is contained in:
@@ -19,11 +19,11 @@ interface AbsurdSqlDatabase {
|
||||
) => Promise<{ changes: number; lastId?: number }>;
|
||||
}
|
||||
|
||||
interface QueuedOperation {
|
||||
interface QueuedOperation<T = unknown> {
|
||||
type: "run" | "query" | "getOneRow" | "getAll";
|
||||
sql: string;
|
||||
params: unknown[];
|
||||
resolve: (value: unknown) => void;
|
||||
resolve: (value: T) => void;
|
||||
reject: (reason: unknown) => void;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ class AbsurdSqlDatabaseService implements DatabaseService {
|
||||
private db: AbsurdSqlDatabase | null;
|
||||
private initialized: boolean;
|
||||
private initializationPromise: Promise<void> | null = null;
|
||||
private operationQueue: QueuedOperation[] = [];
|
||||
private operationQueue: Array<QueuedOperation<any>> = [];
|
||||
private isProcessingQueue: boolean = false;
|
||||
|
||||
private constructor() {
|
||||
@@ -157,18 +157,19 @@ class AbsurdSqlDatabaseService implements DatabaseService {
|
||||
}
|
||||
|
||||
private async queueOperation<T>(
|
||||
type: QueuedOperation["type"],
|
||||
type: QueuedOperation<T>["type"],
|
||||
sql: string,
|
||||
params: unknown[] = [],
|
||||
): Promise<T> {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.operationQueue.push({
|
||||
return new Promise<T>((resolve, reject) => {
|
||||
const operation: QueuedOperation<T> = {
|
||||
type,
|
||||
sql,
|
||||
params,
|
||||
resolve,
|
||||
reject,
|
||||
});
|
||||
};
|
||||
this.operationQueue.push(operation);
|
||||
|
||||
// If we're already initialized, start processing the queue
|
||||
if (this.initialized && this.db) {
|
||||
|
||||
Reference in New Issue
Block a user