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 7cc35803c9
commit dac7705003
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);
}
}