mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-06 07:12:12 +03:00
* fix(db): pre-init sql.js WASM ahead of any getDbInstance() consumer (#7288) * fix(db): close sqljs preinit ordering gap without top-level await (#7288) The previous fix added a top-level await barrier at the bottom of src/lib/db/core.ts to guarantee sql.js pre-init before any consumer reached getDbInstance(). That made core.ts an async ES module, which broke esbuild's CJS require() bundling for every test file that does require("../../src/lib/db/core.ts") (tsx's CJS require hook rejects requiring a transitive dependency with a top-level await), and caused unrelated tests running in the same node:test process to fail with "Promise resolution is still pending but the event loop has already resolved". Move the fix to the real startup entrypoint instead: registerNodejs() (src/instrumentation-node.ts) now awaits ensureDbReadyForBoot() before ensureSecrets()/clearStaleCrashCooldowns()/getSettings()/initAuditLog(), all of which reach getDbInstance() transitively. ensureDbInitialized() is idempotent, so later getDbInstance() calls are free cache reads. The driverFactory.ts error-surfacing improvements from the original #7288 fix (logging swallowed sync-driver errors, surfacing the real sql.js pre-init failure instead of the generic "not pre-initialized yet" message) are unchanged. Updated tests/unit/db-sqljs-preinit-ordering-gap-7288.test.ts to prove: no top-level await in core.ts, the corrected call order in registerNodejs() (source-order assertion), and the original getDbInstance()-no-longer-throws-the-misleading-message behavior driven via the same warm-up path ensureDbReadyForBoot() now guarantees ahead of every other startup step. * refactor(db): drop the orphaned preInitSqlJsIfSyncDriversUnavailable helper (#7288) Moving the ordering guarantee to registerNodejs() left this exported helper with zero production callers — its own docblock still claimed it was 'Chamada no top level de core.ts', describing an architecture the hotfix removed. It was also redundant: ensureDbInitialized() already does tryOpenSync-then-preInitSqlJs on the real boot path (core.ts:1358). Its two tests exercised the helper as a stand-in for the real warm-up ('Simulates the fixed ordering'), so they proved a simulation rather than production behaviour. They now drive ensureDbReadyForBoot()/tryOpenSync() directly. The ordering guard still fails against the unfixed instrumentation-node.ts (verified) and the whole file is 4/4 green. The live parts of the driverFactory change (logSwallowedDriverError, getSqlJsPreInitError) are untouched — both have real callers.
752 B
752 B
- fix(db):
getDbInstance()now guarantees sql.js WASM has already been pre-initialized (via a top-level await insrc/lib/db/core.ts) before ANY consumer can reach it, closing an ordering gap where early startup steps (ensureSecrets(),clearStaleCrashCooldowns(),getSettings(),initAuditLog()) calledgetDbInstance()beforeensureDbReadyForBoot()had a chance to runpreInitSqlJs()— turning a recoverable driver failure into a hard boot crash (sql.js WASM ainda não foi pré-inicializado) whenever bothbetter-sqlite3andnode:sqlitefailed to open an existingstorage.sqlite.tryOpenSync()also now logs the real underlying cause of each swallowed sync-driver failure instead of an emptycatch {}. (#7288, #7494)