@statesync/persistence / PersistenceApplierOptions
Interface: PersistenceApplierOptions<T>
Defined in: persistence/src/types.ts:636
Configuration options for createPersistenceApplier.
Controls which storage backend to use, how saves are throttled, schema versioning, compression, integrity checking, cross-tab sync, and error handling.
Example
const options: PersistenceApplierOptions<MyState> = {
storage: createLocalStorageBackend({ key: 'my-state' }),
applier: myInnerApplier,
throttling: { debounceMs: 300, maxWaitMs: 2000 },
schemaVersion: 3,
ttlMs: 24 * 60 * 60 * 1000,
compression: createLZCompressionAdapter(),
};Type Parameters
| Type Parameter | Description |
|---|---|
T | The shape of the application state being persisted. |
Properties
applier
applier: object;Defined in: persistence/src/types.ts:648
The inner applier to which snapshot application is delegated.
The persistence applier always forwards snapshots to this applier first, even if the subsequent storage write fails.
apply()
apply(snapshot): void | Promise<void>;Parameters
| Parameter | Type |
|---|---|
snapshot | SnapshotEnvelope<T> |
Returns
void | Promise<void>
compression?
optional compression: CompressionAdapter;Defined in: persistence/src/types.ts:700
Compression adapter to use for reducing the size of persisted data.
Applied after JSON serialization and before writing to storage. The same adapter must be used for both saving and loading.
crossTabSync?
optional crossTabSync: CrossTabSyncOptions;Defined in: persistence/src/types.ts:718
Options for cross-tab synchronization via the BroadcastChannel API.
When provided, saves are broadcast to other tabs and incoming snapshots from other tabs are applied to the inner applier.
debounceMs?
optional debounceMs: number;Defined in: persistence/src/types.ts:657
Simple debounce delay in milliseconds for save operations.
Deprecated
Use throttling.debounceMs instead for more control.
enableHash?
optional enableHash: boolean;Defined in: persistence/src/types.ts:710
Whether to compute and store an integrity hash with each save.
When enabled, a non-cryptographic hash is stored in metadata and can be verified during load via LoadOptions.verifyHash.
Default Value
false
onPersistenceError()?
optional onPersistenceError: (context) => void;Defined in: persistence/src/types.ts:674
Callback invoked when a persistence operation fails.
Errors in persistence do not prevent the inner applier from receiving snapshots. Use this callback for logging, metrics, or user notification.
Parameters
| Parameter | Type | Description |
|---|---|---|
context | PersistenceErrorContext | Details about the failed operation. |
Returns
void
schemaVersion?
optional schemaVersion: number;Defined in: persistence/src/types.ts:684
The current schema version of the application state.
Stored in metadata alongside each snapshot. During load, the stored version is compared to this value to determine if migration is needed.
Default Value
1
storage
storage: StorageBackend<T>;Defined in: persistence/src/types.ts:640
The storage backend used to read and write snapshots.
throttling?
optional throttling: SaveThrottlingOptions;Defined in: persistence/src/types.ts:664
Advanced throttling and debouncing options for save operations.
When provided, these take precedence over the deprecated debounceMs.
ttlMs?
optional ttlMs: number;Defined in: persistence/src/types.ts:692
Time-to-live for cached snapshots, in milliseconds.
When set, snapshots older than this duration are discarded during load. Set to undefined for no expiration.
