Skip to content

@statesync/persistence


@statesync/persistence / IndexedDBBackendOptions

Interface: IndexedDBBackendOptions

Defined in: persistence/src/storage/indexed-db.ts:11

Configuration options for the IndexedDB storage backend.

Allows customization of the database name, object store, versioning, retry behavior, and lifecycle callbacks used when persisting snapshot data to the browser's IndexedDB API.

Properties

dbName

ts
dbName: string;

Defined in: persistence/src/storage/indexed-db.ts:18

The name of the IndexedDB database to open or create.

This name is scoped to the current origin and should be unique per application to avoid conflicts.


onBlocked()?

ts
optional onBlocked: () => void;

Defined in: persistence/src/storage/indexed-db.ts:75

Callback invoked when the database open request is blocked by another connection.

This typically happens when another tab has an open connection to an older version of the database. The blocked state is handled automatically via the retry mechanism, but this callback can be used for user notification or logging.

Returns

void


onUpgrade()?

ts
optional onUpgrade: (db, oldVersion, newVersion) => void;

Defined in: persistence/src/storage/indexed-db.ts:87

Callback invoked when the database requires a schema upgrade.

Called after the default upgrade logic (object store creation) has executed. Use this to perform custom schema migrations such as creating indexes.

Parameters

ParameterTypeDescription
dbIDBDatabaseThe IDBDatabase instance being upgraded.
oldVersionnumberThe previous schema version number (0 for newly created databases).
newVersionnumberThe new schema version number being upgraded to.

Returns

void


recordKey?

ts
optional recordKey: string;

Defined in: persistence/src/storage/indexed-db.ts:35

The key used to store and retrieve the snapshot record within the object store.

A separate metadata record is stored under ${recordKey}:metadata.

Default

ts
'snapshot'

retryAttempts?

ts
optional retryAttempts: number;

Defined in: persistence/src/storage/indexed-db.ts:57

The maximum number of retry attempts when the database connection is blocked or encounters a version-related error.

A blocked database typically occurs when another tab holds an open connection to an older version of the database.

Default

ts
3

retryDelayMs?

ts
optional retryDelayMs: number;

Defined in: persistence/src/storage/indexed-db.ts:66

The base delay in milliseconds between retry attempts.

The actual delay uses linear backoff: retryDelayMs * (attemptNumber + 1).

Default

ts
100

storeName

ts
storeName: string;

Defined in: persistence/src/storage/indexed-db.ts:26

The name of the object store within the database where snapshots are persisted.

The object store is automatically created during the database upgrade if it does not already exist.


version?

ts
optional version: number;

Defined in: persistence/src/storage/indexed-db.ts:46

The version number of the IndexedDB database schema.

Incrementing this value triggers the onupgradeneeded event, allowing schema migrations. The object store specified by storeName is automatically created if it does not exist during an upgrade.

Default

ts
1

Released under the MIT License.