import { createMigratorHandler } from './handler.mjs'; type Runtime = { nonce: string; handler: ReturnType }; const globalRuntime = globalThis as typeof globalThis & { tangledMigrator?: Runtime }; export function localRuntime() { const origin = process.env.TANGLED_MIGRATOR_ORIGIN; const stateDirectory = process.env.TANGLED_MIGRATOR_STATE_DIR; const nonce = process.env.TANGLED_MIGRATOR_NONCE; if (!origin || !stateDirectory || !nonce) throw new Error('Start the local application with bun start or bun run dev.'); if (!globalRuntime.tangledMigrator || globalRuntime.tangledMigrator.nonce !== nonce) { globalRuntime.tangledMigrator = { nonce, handler: createMigratorHandler({ origin, stateDirectory, nonce }) }; } return globalRuntime.tangledMigrator; }