From 4c9f4d1439b7b9ab37d7e9cb51df9912bf0749c2 Mon Sep 17 00:00:00 2001 From: brobert Date: Mon, 10 Nov 2025 18:19:16 +0100 Subject: [PATCH] refactor: quitar AsyncLocalStorage del locator y dejar currentDb simple Co-authored-by: aider (openrouter/openai/gpt-5) --- src/db/locator.ts | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/db/locator.ts b/src/db/locator.ts index 1d04f1f..9a1be67 100644 --- a/src/db/locator.ts +++ b/src/db/locator.ts @@ -1,5 +1,4 @@ import type { Database } from 'bun:sqlite'; -import { AsyncLocalStorage } from 'node:async_hooks'; /** * Error específico cuando se intenta acceder a la DB sin haberla configurado. @@ -13,18 +12,11 @@ export class DbNotConfiguredError extends Error { let currentDb: Database | null = null; -// AsyncLocalStorage para aislar DB por contexto en tests (paralelismo seguro) -let testScope: AsyncLocalStorage | null = null; - /** * Establece la instancia global de DB. * Se permite sobrescribir (útil en tests). */ export function setDb(db: Database): void { - if (process.env.NODE_ENV === 'test') { - if (!testScope) testScope = new AsyncLocalStorage(); - try { testScope.enterWith(db); } catch {} - } currentDb = db; } @@ -32,13 +24,6 @@ export function setDb(db: Database): void { * Obtiene la instancia global de DB o lanza si no está configurada. */ export function getDb(): Database { - if (process.env.NODE_ENV === 'test') { - if (!testScope) testScope = new AsyncLocalStorage(); - const scoped = testScope.getStore(); - if (scoped) return scoped; - // En tests, no hacemos fallback a currentDb para evitar contaminación entre suites - throw new DbNotConfiguredError('Database has not been configured. Call setDb(db) before using getDb().'); - } if (currentDb) return currentDb; throw new DbNotConfiguredError('Database has not been configured. Call setDb(db) before using getDb().'); } @@ -48,7 +33,6 @@ export function getDb(): Database { */ export function resetDb(): void { currentDb = null; - // En tests no tocamos testScope para no invalidar contextos de otras suites en paralelo } /** @@ -56,7 +40,6 @@ export function resetDb(): void { */ export function clearDb(): void { currentDb = null; - // En tests no tocamos testScope para no invalidar contextos de otras suites en paralelo } /**