@deploybaseline/state-libsql
v0.14.0
Published
Save Baseline emulator state in a libSQL or Turso database
Readme
@deploybaseline/state-libsql
Keep Baseline emulator state and named snapshots in a libSQL database, such as Turso or a self-hosted sqld. It talks to the database over HTTP with @libsql/client, so there is no native module to build.
export BASELINE_STATE_AUTH_TOKEN=... # or append ?authToken=... to the URL
npx -p @deploybaseline/cli -p @deploybaseline/state-libsql baseline start --state libsql://my-db.turso.ioOr install both in your project (npm install -D @deploybaseline/cli @deploybaseline/state-libsql) and run baseline start --state libsql://... from a package.json script. Use libsql+https:// or libsql+http:// for a server that is not on libsql://.
- Tables.
baseline_stateholds the state: the row namedcurrentis the live state, and every other row is a named snapshot.baseline_state_lockholds the writer's lease. - One writer. The CLI holds a lease row and renews it every 10 seconds. A second process is refused with the process and host that hold it. A lease that goes 30 seconds without renewal (its holder crashed or lost the network) is taken over with a warning.
- The token is removed from the URL before it appears in any message.
In code, a store is a PersistenceAdapter, so createEmulator accepts it as state:
import { libsqlState } from '@deploybaseline/state-libsql'
const store = await libsqlState({ url: process.env.STATE_URL!, authToken: process.env.STATE_TOKEN })
// createEmulator({ service: 'github', port: 4001, state: store })
const lock = await store.lock() // optional: refuse a second writer
// ...
await lock.release()
store.close()For a local file, pass a client you created: libsqlState({ url: 'file:state.db', client: createClient({ url: 'file:state.db' }) }) with createClient from @libsql/client.
See Saved state.
