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

@@ -312,23 +312,29 @@ export async function testMessageEncryptionDecryption() {
}
// Simple encryption/decryption using Node's crypto
export async function simpleEncrypt(text: string, secret: string): Promise<string> {
export async function simpleEncrypt(
text: string,
secret: string,
): Promise<string> {
const iv = crypto.getRandomValues(new Uint8Array(16));
// Derive a 256-bit key from the secret using SHA-256
const keyData = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(secret));
const keyData = await crypto.subtle.digest(
"SHA-256",
new TextEncoder().encode(secret),
);
const key = await crypto.subtle.importKey(
'raw',
"raw",
keyData,
{ name: 'AES-GCM' },
{ name: "AES-GCM" },
false,
['encrypt']
["encrypt"],
);
const encrypted = await crypto.subtle.encrypt(
{ name: 'AES-GCM', iv },
{ name: "AES-GCM", iv },
key,
new TextEncoder().encode(text)
new TextEncoder().encode(text),
);
// Combine IV and encrypted data
@@ -339,27 +345,33 @@ export async function simpleEncrypt(text: string, secret: string): Promise<strin
return btoa(String.fromCharCode(...result));
}
export async function simpleDecrypt(encryptedText: string, secret: string): Promise<string> {
const data = Uint8Array.from(atob(encryptedText), c => c.charCodeAt(0));
export async function simpleDecrypt(
encryptedText: string,
secret: string,
): Promise<string> {
const data = Uint8Array.from(atob(encryptedText), (c) => c.charCodeAt(0));
// Extract IV and encrypted data
const iv = data.slice(0, 16);
const encrypted = data.slice(16);
// Derive the same 256-bit key from the secret using SHA-256
const keyData = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(secret));
const keyData = await crypto.subtle.digest(
"SHA-256",
new TextEncoder().encode(secret),
);
const key = await crypto.subtle.importKey(
'raw',
"raw",
keyData,
{ name: 'AES-GCM' },
{ name: "AES-GCM" },
false,
['decrypt']
["decrypt"],
);
const decrypted = await crypto.subtle.decrypt(
{ name: 'AES-GCM', iv },
{ name: "AES-GCM", iv },
key,
encrypted
encrypted,
);
return new TextDecoder().decode(decrypted);