// Hosts an in-memory PGlite database behind a TCP socket speaking the // Postgres wire protocol. Spawned by global-setup.ts as a child process. // // Deliberately plain .mjs so it can run under a bare `node` with no // TS loader, and deliberately never calls db.close()/server.stop(): // under Bun, PGlite teardown triggers an Emscripten exit(99) which would // kill the process with a non-zero code. Cleanup happens via SIGTERM/SIGKILL. import { PGlite } from '@electric-sql/pglite'; import { PGLiteSocketServer } from '@electric-sql/pglite-socket'; const db = new PGlite(); await db.waitReady; const server = new PGLiteSocketServer({ db, port: 0, host: '127.0.0.1', maxConnections: 20 }); await server.start(); const [host, port] = server.getServerConn().split(':'); console.log(`PGLITE_READY postgresql://postgres@${host}:${port}/postgres`); process.on('SIGTERM', () => process.exit(0)); process.on('SIGINT', () => process.exit(0));