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): OpfsStorage

Creates a new OpfsStorage instance.

Parameters

args
path

string

Path/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): void

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

Parameters

args
lix

Lix

Returns

void

Implementation of

LixStorageAdapter.connect


export()

export(): Promise<Blob>

Exports the current database state as a blob.

Returns

Promise<Blob>

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


import()

import(blob): Promise<void>

Imports data from a blob, replacing the current database content.

Also saves the imported data to OPFS.

Parameters

blob

Blob

Returns

Promise<void>

Implementation of

LixStorageAdapter.import


open()

open(): 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.

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!