46996e5a67
- Extract makeManagedRuntime() to src/effect/managed-runtime.ts so AppRuntime and BootstrapRuntime stop duplicating the lazy ManagedRuntime + dispose pattern, and document the shared-memoMap dispose ordering invariant. - Add lazy.resetIf(expected) and use it in 3 compare-and-reset call sites (db.close, AppRuntime.dispose, disposeWebHandler). - Drop dead `filename` option from EffectDrizzleSqlite MakeConfig. - Drop redundant `patched` IIFE flag (patchClass is already idempotent). - Add module-load assertion that Effect's protocol keys are present so a silent breakage on an Effect upgrade becomes a loud failure at import. - Collapse share-next test `live()` into the wider `wired()` factory. - Document lifecycle constraint in db-effect.ts and test/fixture/db.ts.
18 lines
852 B
TypeScript
18 lines
852 B
TypeScript
import { rm } from "fs/promises"
|
|
import { Database } from "@/storage/db"
|
|
import { disposeAllInstances } from "./fixture"
|
|
|
|
// Order matters and must stay serial: every runtime that transitively consumes
|
|
// `DatabaseEffect.layer` shares the global layer memoMap with the others, so
|
|
// each one's memoized Service value still references the live SQLite handle.
|
|
// We dispose every runtime/handler first, then close the DB. If a future
|
|
// module-scoped runtime is added that depends on the DB, register its
|
|
// dispose() here.
|
|
export async function resetDatabase() {
|
|
await disposeAllInstances().catch(() => undefined)
|
|
Database.close()
|
|
await rm(Database.Path, { force: true }).catch(() => undefined)
|
|
await rm(`${Database.Path}-wal`, { force: true }).catch(() => undefined)
|
|
await rm(`${Database.Path}-shm`, { force: true }).catch(() => undefined)
|
|
}
|