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 }>;
|
) => Promise<{ changes: number; lastId?: number }>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface QueuedOperation {
|
interface QueuedOperation<T = unknown> {
|
||||||
type: "run" | "query" | "getOneRow" | "getAll";
|
type: "run" | "query" | "getOneRow" | "getAll";
|
||||||
sql: string;
|
sql: string;
|
||||||
params: unknown[];
|
params: unknown[];
|
||||||
resolve: (value: unknown) => void;
|
resolve: (value: T) => void;
|
||||||
reject: (reason: unknown) => void;
|
reject: (reason: unknown) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ class AbsurdSqlDatabaseService implements DatabaseService {
|
|||||||
private db: AbsurdSqlDatabase | null;
|
private db: AbsurdSqlDatabase | null;
|
||||||
private initialized: boolean;
|
private initialized: boolean;
|
||||||
private initializationPromise: Promise<void> | null = null;
|
private initializationPromise: Promise<void> | null = null;
|
||||||
private operationQueue: QueuedOperation[] = [];
|
private operationQueue: Array<QueuedOperation<any>> = [];
|
||||||
private isProcessingQueue: boolean = false;
|
private isProcessingQueue: boolean = false;
|
||||||
|
|
||||||
private constructor() {
|
private constructor() {
|
||||||
@@ -157,18 +157,19 @@ class AbsurdSqlDatabaseService implements DatabaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async queueOperation<T>(
|
private async queueOperation<T>(
|
||||||
type: QueuedOperation["type"],
|
type: QueuedOperation<T>["type"],
|
||||||
sql: string,
|
sql: string,
|
||||||
params: unknown[] = [],
|
params: unknown[] = [],
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise<T>((resolve, reject) => {
|
||||||
this.operationQueue.push({
|
const operation: QueuedOperation<T> = {
|
||||||
type,
|
type,
|
||||||
sql,
|
sql,
|
||||||
params,
|
params,
|
||||||
resolve,
|
resolve,
|
||||||
reject,
|
reject,
|
||||||
});
|
};
|
||||||
|
this.operationQueue.push(operation);
|
||||||
|
|
||||||
// If we're already initialized, start processing the queue
|
// If we're already initialized, start processing the queue
|
||||||
if (this.initialized && this.db) {
|
if (this.initialized && this.db) {
|
||||||
|
|||||||
Reference in New Issue
Block a user