logo
  • Docs
  • API Reference
    Overview
    Functions
    acceptChangeProposal
    applyChangeSet
    attachConversation
    attachLabel
    commitIsAncestorOf
    commitIsDescendantOf
    createAccount
    createChangeProposal
    createChangeSet
    createCheckpoint
    createConversation
    createConversationMessage
    createHooks
    createLabel
    createLog
    createLspInMemoryEnvironment
    createQuerySync
    createServerProtocolHandler
    createVersion
    createVersionFromCommit
    detachConversation
    detachLabel
    ebEntity
    getTimestamp
    humanId
    mergeVersion
    nanoId
    newLixFile
    nextSequenceNumber
    normalizeDirectoryPath
    normalizeFilePath
    normalizePathSegment
    openLix
    random
    rejectChangeProposal
    selectCommitDiff
    selectVersionDiff
    selectWorkingDiff
    switchAccount
    switchVersion
    transition
    uuidV7
    uuidV7Sync
    validateLixSchema
    validateLixSchemaDefinition
    withWriterKey
    Type Aliases
    Account
    ActiveAccount
    Change
    ChangeAuthor
    DetectedChange
    EntityStateByVersionView
    EntityStateHistoryView
    EntityStateView
    EnvironmentActorHandle
    FromLixSchemaDefinition
    JSONType
    Lix
    LixActiveVersion
    LixChangeProposal
    LixChangeSet
    LixChangeSetElement
    LixCommit
    LixCommitEdge
    LixConversation
    LixConversationMessage
    LixDatabaseSchema
    LixDirectoryDescriptor
    LixEntity
    LixEntityCanonical
    LixEntityConversation
    LixEntityLabel
    LixFile
    LixFileDescriptor
    LixGenerated
    LixHooks
    LixInsertable
    LixKeyValue
    LixLabel
    LixLog
    LixPlugin
    LixSchemaDefinition
    LixSelectable
    LixServerProtocolHandlerContext
    LixUpdateable
    LixVersion
    LixVersionDescriptor
    LixVersionTip
    NewChange
    NewState
    NewStateByVersion
    NewStateByVersionRow
    NewStateRow
    QuerySync
    RenderDiffArgs
    SpawnActorOptions
    State
    StateByVersion
    StateByVersionRow
    StateByVersionRowUpdate
    StateByVersionUpdate
    StateByVersionView
    StateCommitChange
    StateHistory
    StateRow
    StateRowUpdate
    StateUpdate
    StateView
    StateWithTombstonesRow
    StateWithTombstonesView
    StoredSchema
    ToKysely
    Variables
    JSONTypeSchema
    LixAccountSchema
    LixActiveAccountSchema
    LixActiveVersionSchema
    LixChangeAuthorSchema
    LixChangeProposalSchema
    LixChangeSetElementSchema
    LixChangeSetSchema
    LixCommitEdgeSchema
    LixCommitSchema
    LixConversationMessageSchema
    LixConversationSchema
    LixDirectoryDescriptorSchema
    LixFileDescriptorSchema
    LixKeyValueSchema
    LixLabelSchema
    LixLogSchema
    LixSchemaDefinition
    LixStoredSchemaSchema
    LixVersionDescriptorSchema
    LixVersionTipSchema
    mockJsonPlugin
    Classes
    InMemoryEnvironment
    LixObservable
    OpfsSahEnvironment
    Interfaces
    LixEnvironment
    Previous pageJSONTypeNext pageLixActiveVersion

    #Type Alias: Lix

    Lix = { call: (name: string, args?: unknown) => Promise<unknown>; close: () => Promise<void>; db: Kysely<LixDatabaseSchema>; engine?: LixEngine; hooks: LixHooks; observe: ReturnType<typeof createObserve>; plugin: { getAll: () => Promise<LixPlugin[]>; }; toBlob: () => Promise<Blob>; }

    #Properties

    #call()

    call: (name: string, args?: unknown) => Promise<unknown>

    Calls a named engine function and returns its result.

    Preferred entrypoint for invoking engine functions.

    #Parameters

    ParameterType
    namestring
    args?unknown

    #Returns

    Promise<unknown>


    #close()

    close: () => Promise<void>

    Closes the lix instance and its storage.

    #Returns

    Promise<void>


    #db

    db: Kysely<LixDatabaseSchema>


    #engine?

    optional engine: 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:

    • Prefer 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.
    • Do not rely on lix.engine in application/business logic, since it may be undefined in worker/remote environments.

    Unit test in the same process

    #Examples

    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

    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

    observe: ReturnType<typeof createObserve>


    #plugin

    plugin: { getAll: () => Promise<LixPlugin[]>; }

    #getAll()

    getAll: () => Promise<LixPlugin[]>

    #Returns

    Promise<LixPlugin[]>


    #toBlob()

    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.

    #Examples

    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);

    #Returns

    Promise<Blob>