@statesync/persistence / StorageBackend
Interface: StorageBackend<T>
Defined in: persistence/src/types.ts:167
Abstract storage backend for persisting snapshots.
Implementations must handle serialization/deserialization internally. The save/load methods work with SnapshotEnvelope to preserve revision metadata alongside the application state.
Built-in implementations include localStorage, sessionStorage, IndexedDB, and an in-memory backend for testing.
Example
const storage: StorageBackend<MyState> = createLocalStorageBackend({
key: 'my-app-state',
});Extended by
Type Parameters
| Type Parameter | Description |
|---|---|
T | The shape of the application state. |
Methods
clear()?
optional clear(): Promise<void>;Defined in: persistence/src/types.ts:190
Remove all persisted data from this backend's storage key.
This method is optional -- not all backends support clearing.
Returns
Promise<void>
A promise that resolves when the data has been removed.
load()
load(): Promise<SnapshotEnvelope<T> | null>;Defined in: persistence/src/types.ts:181
Load the most recent snapshot from persistent storage.
Returns
Promise<SnapshotEnvelope<T> | null>
The stored snapshot, or null if no snapshot has been persisted yet.
save()
save(snapshot): Promise<void>;Defined in: persistence/src/types.ts:174
Save a snapshot to persistent storage.
Parameters
| Parameter | Type | Description |
|---|---|---|
snapshot | SnapshotEnvelope<T> | The snapshot envelope to persist. |
Returns
Promise<void>
A promise that resolves when the write is complete.
