Lix = {
call: (name:string,args?:unknown) =>Promise<unknown>;close: () =>Promise<void>;db:Kysely<LixDatabaseSchema>;engine?:LixEngine;hooks:LixHooks;observe:ReturnType<typeofcreateObserve>;plugin: {getAll: () =>Promise<LixPlugin[]>; };toBlob: () =>Promise<Blob>; }
call: (
name:string,args?:unknown) =>Promise<unknown>
Calls a named engine function and returns its result.
Preferred entrypoint for invoking engine functions.
| Parameter | Type |
|---|---|
name | string |
args? | unknown |
Promise<unknown>
close: () =>
Promise<void>
Closes the lix instance and its storage.
Promise<void>
db:
Kysely<LixDatabaseSchema>
optionalengine:LixEngine
In‑process engine context bound to the live database.
When Lix runs in‑process (same thread as the database),
engine is available and tests can directly call helpers
that accept { engine }.
When Lix runs out‑of‑process (for example inside a Worker), the engine
is not accessible from the main thread and will be undefined. In those
environments, use lix.call to invoke engine functions across the
boundary.
Guidance:
lix.db for normal queries and lix.call for engine
operations. Reserve lix.engine for unit tests or internal SDK code
that explicitly requires in‑process access alongside the database.lix.engine in application/business logic, since it
may be undefined in worker/remote environments.Unit test in the same process
test("example test", async () => {
// InMemory environment runs in the same process (in‑process engine).
const lix = await openLix({
environment: new InMemoryenvironment()
});
executeSync({
engine: lix.engine!,
data: [...],
});
});Worker/remote environment – prefer router calls
await lix.call("lix_insert_transaction_state", { timestamp, data });hooks:
LixHooks
Hooks for listening to database lifecycle events.
Allows registering callbacks that fire at specific points in Lix's execution, such as when state changes are committed.
observe:
ReturnType<typeofcreateObserve>
plugin: {
getAll: () =>Promise<LixPlugin[]>; }
getAll: () =>
Promise<LixPlugin[]>
Promise<LixPlugin[]>
toBlob: () =>
Promise<Blob>
Serialises the Lix into a Blob.
Use this helper to persist the current state to disk or send it to a
server. By convention, persisted Lix files use the .lix extension.
import { writeFile } from "node:fs/promises";
const blob = await lix.toBlob();
await writeFile("repo.lix", Buffer.from(await blob.arrayBuffer()));const blob = await lix.toBlob();
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "repo.lix";
a.click();
URL.revokeObjectURL(url);Promise<Blob>