fix: move lexical declarations outside case blocks in AbsurdSqlDatabaseService

- Move queryResult and allResult declarations outside switch statement
- Change const declarations to let since they're now in outer scope
- Remove const declarations from inside case blocks

This fixes the 'no-case-declarations' linter errors by ensuring variables
are declared in a scope that encompasses all case blocks, preventing
potential scoping issues.

Note: Type definition errors for external modules remain and should be
addressed separately.
This commit is contained in:
Matthew Raymer
2025-05-27 03:14:02 +00:00
parent 3c0bdeaed3
commit 0f1ac2b230
17 changed files with 2849 additions and 536 deletions

View File

@@ -20,11 +20,11 @@ interface AbsurdSqlDatabase {
}
interface QueuedOperation {
type: 'run' | 'query' | 'getOneRow' | 'getAll';
type: "run" | "query" | "getOneRow" | "getAll";
sql: string;
params: unknown[];
resolve: (value: any) => void;
reject: (reason: any) => void;
resolve: (value: unknown) => void;
reject: (reason: unknown) => void;
}
class AbsurdSqlDatabaseService implements DatabaseService {
@@ -111,7 +111,7 @@ class AbsurdSqlDatabaseService implements DatabaseService {
await runMigrations(sqlExec);
this.initialized = true;
// Start processing the queue after initialization
this.processQueue();
}
@@ -122,26 +122,28 @@ class AbsurdSqlDatabaseService implements DatabaseService {
}
this.isProcessingQueue = true;
while (this.operationQueue.length > 0) {
const operation = this.operationQueue.shift();
if (!operation) continue;
try {
let result;
let queryResult;
let allResult;
switch (operation.type) {
case 'run':
case "run":
result = await this.db.run(operation.sql, operation.params);
break;
case 'query':
case "query":
result = await this.db.exec(operation.sql, operation.params);
break;
case 'getOneRow':
const queryResult = await this.db.exec(operation.sql, operation.params);
case "getOneRow":
queryResult = await this.db.exec(operation.sql, operation.params);
result = queryResult[0]?.values[0];
break;
case 'getAll':
const allResult = await this.db.exec(operation.sql, operation.params);
case "getAll":
allResult = await this.db.exec(operation.sql, operation.params);
result = allResult[0]?.values || [];
break;
}
@@ -155,7 +157,7 @@ class AbsurdSqlDatabaseService implements DatabaseService {
}
private async queueOperation<T>(
type: QueuedOperation['type'],
type: QueuedOperation["type"],
sql: string,
params: unknown[] = [],
): Promise<T> {
@@ -205,13 +207,17 @@ class AbsurdSqlDatabaseService implements DatabaseService {
params: unknown[] = [],
): Promise<{ changes: number; lastId?: number }> {
await this.waitForInitialization();
return this.queueOperation<{ changes: number; lastId?: number }>('run', sql, params);
return this.queueOperation<{ changes: number; lastId?: number }>(
"run",
sql,
params,
);
}
// Note that the resulting array may be empty if there are no results from the query
async query(sql: string, params: unknown[] = []): Promise<QueryExecResult[]> {
await this.waitForInitialization();
return this.queueOperation<QueryExecResult[]>('query', sql, params);
return this.queueOperation<QueryExecResult[]>("query", sql, params);
}
async getOneRow(
@@ -219,12 +225,12 @@ class AbsurdSqlDatabaseService implements DatabaseService {
params: unknown[] = [],
): Promise<unknown[] | undefined> {
await this.waitForInitialization();
return this.queueOperation<unknown[] | undefined>('getOneRow', sql, params);
return this.queueOperation<unknown[] | undefined>("getOneRow", sql, params);
}
async getAll(sql: string, params: unknown[] = []): Promise<unknown[][]> {
await this.waitForInitialization();
return this.queueOperation<unknown[][]>('getAll', sql, params);
return this.queueOperation<unknown[][]>("getAll", sql, params);
}
}

View File

@@ -115,5 +115,8 @@ export interface PlatformService {
* @param params - The parameters to pass to the statement
* @returns Promise resolving to the result of the statement
*/
dbExec(sql: string, params?: unknown[]): Promise<{ changes: number; lastId?: number }>;
dbExec(
sql: string,
params?: unknown[],
): Promise<{ changes: number; lastId?: number }>;
}

View File

@@ -481,7 +481,10 @@ export class CapacitorPlatformService implements PlatformService {
dbQuery(sql: string, params?: unknown[]): Promise<QueryExecResult> {
throw new Error("Not implemented for " + sql + " with params " + params);
}
dbExec(sql: string, params?: unknown[]): Promise<{ changes: number; lastId?: number }> {
dbExec(
sql: string,
params?: unknown[],
): Promise<{ changes: number; lastId?: number }> {
throw new Error("Not implemented for " + sql + " with params " + params);
}
}

View File

@@ -113,7 +113,10 @@ export class ElectronPlatformService implements PlatformService {
dbQuery(sql: string, params?: unknown[]): Promise<QueryExecResult> {
throw new Error("Not implemented for " + sql + " with params " + params);
}
dbExec(sql: string, params?: unknown[]): Promise<{ changes: number; lastId?: number }> {
dbExec(
sql: string,
params?: unknown[],
): Promise<{ changes: number; lastId?: number }> {
throw new Error("Not implemented for " + sql + " with params " + params);
}
}

View File

@@ -114,7 +114,10 @@ export class PyWebViewPlatformService implements PlatformService {
dbQuery(sql: string, params?: unknown[]): Promise<QueryExecResult> {
throw new Error("Not implemented for " + sql + " with params " + params);
}
dbExec(sql: string, params?: unknown[]): Promise<{ changes: number; lastId?: number }> {
dbExec(
sql: string,
params?: unknown[],
): Promise<{ changes: number; lastId?: number }> {
throw new Error("Not implemented for " + sql + " with params " + params);
}
}

View File

@@ -372,7 +372,10 @@ export class WebPlatformService implements PlatformService {
/**
* @see PlatformService.dbExec
*/
dbExec(sql: string, params?: unknown[]): Promise<{ changes: number; lastId?: number }> {
dbExec(
sql: string,
params?: unknown[],
): Promise<{ changes: number; lastId?: number }> {
return databaseService.run(sql, params);
}
}