Class: OpfsStorage

OPFS (Origin Private File System) storage adapter for Lix.

Provides persistent storage in the browser using the Origin Private File System API. Data persists across browser sessions and page refreshes.

Features auto-saving functionality when integrated with the hooks system.

Implements

Constructors

Constructor

new OpfsStorage(args: { path: string; }): OpfsStorage

Creates a new OpfsStorage instance.

Parameters

ParameterTypeDescription
args{ path: string; }-
args.pathstringPath/name of the file to store in OPFS

Returns

OpfsStorage

Methods

close()

close(): Promise<void>

Closes the database connection.

Performs a final save to OPFS before closing.

Returns

Promise<void>

Implementation of

LixStorageAdapter.close


connect()

connect(args: { lix: Lix; }): void

Called after the Lix instance is fully initialized. Sets up observers for persisting state changes.

Parameters

ParameterType
args{ lix: Lix; }
args.lixLix

Returns

void

Implementation of

LixStorageAdapter.connect


export()

export(): Promise<Blob>

Exports the current database state as a blob.

Returns

Promise<Blob>

Throws

Error if the database has not been opened yet

Implementation of

LixStorageAdapter.export


getPersistedState()

getPersistedState(): Promise<undefined | { activeAccounts?: Pick<{ id: LixGenerated<string>; name: string; }, "id" | "name">[]; }>

Returns any persisted state that should be restored.

Returns

Promise<undefined | { activeAccounts?: Pick<{ id: LixGenerated<string>; name: string; }, "id" | "name">[]; }>

Implementation of

LixStorageAdapter.getPersistedState


open()

open(args: { blob?: Blob; createBlob: () => Promise<Blob>; }): Promise<SqliteWasmDatabase>

Opens a database with OPFS persistence.

Loads existing data from OPFS if available, otherwise creates a new lix. Returns the same database instance on subsequent calls.

Parameters

ParameterType
args{ blob?: Blob; createBlob: () => Promise<Blob>; }
args.blob?Blob
args.createBlob() => Promise<Blob>

Returns

Promise<SqliteWasmDatabase>

Implementation of

LixStorageAdapter.open


clean()

static clean(): Promise<void>

Cleans the entire OPFS by removing all files. Useful for debugging and testing.

TODO refactor to only delete opfs adapter related files after https://github.com/opral/lix-sdk/issues/332 is implemented.

Returns

Promise<void>

Warning

This will delete ALL files in OPFS, not just Lix files!