Configuration for persistedInput.

The shape captures the four moving parts of write-through persistence — where (key + storage), what version (version + migrate), what to do on failure (preserveOnError + onError), and a deprecated migration-only callback retained for adopter compatibility. The defaults (preserveOnError: true, onError: console.warn) mirror the issue #138 contract: persistence failures are observable but never fatal, and the on-disk envelope is never silently discarded.

interface PersistedInputOptions<T> {
    key: string;
    migrate?: (storedValue: unknown, storedVersion: number) => T;
    onError?: PersistenceErrorHandler;
    onMigrationFailure?: (
        info: {
            error?: unknown;
            expectedVersion: number;
            key: string;
            storedVersion: number;
        },
    ) => void;
    preserveOnError?: boolean;
    storage: StorageAdapter;
    version: number;
}

Type Parameters

Properties

key: string

Storage key under which the envelope is written.

migrate?: (storedValue: unknown, storedVersion: number) => T

Migrate an older-versioned stored value to current T. If absent and the stored version differs, the in-memory value falls back to initial; on-disk envelope is preserved when preserveOnError is true (default).

Callback invoked on every PersistenceError. Default is a single console.warn per failure so behaviour remains audible during the rollout window.

onMigrationFailure?: (
    info: {
        error?: unknown;
        expectedVersion: number;
        key: string;
        storedVersion: number;
    },
) => void

Legacy migration-failure callback retained for backwards compatibility. New code should use onError instead. When supplied, it is invoked alongside onError for migrate-shaped failures so existing consumers keep receiving notifications.

Prefer onError(PersistenceError).

preserveOnError?: boolean

If true (default), parse / migrate / serialise / quota failures leave the existing on-disk envelope untouched. Issue #138 mandates this behaviour; flip to false only when callers explicitly want the old "drop on failure" semantics.

Backing store.

version: number

Schema version of T.