UNPKG

@pstdio/opfs-utils

Version:

Utilities for the browser's OPFS: ls, grep, safe file read, unified diff patching, and MIME helpers.

16 lines (15 loc) 772 B
import { JsonFileStorage } from './json-storage'; export interface StoreAdapter<T> { read(): T; replace(next: T): void; subscribe(listener: () => void): () => void; } export interface BindStoreOptions<T> { /** Merge OPFS value with in-memory value on initial hydrate. Defaults to file value. */ reconcile?: (fileValue: T, memoryValue: T) => T; /** Equality check to avoid unnecessary writes. Defaults to JSON.stringify comparison. */ areEqual?: (a: T, b: T) => boolean; /** If true (default) write the reconciled value back to disk after hydrating. */ writeAfterHydrate?: boolean; } export declare function bindStoreToJsonFile<T>(store: StoreAdapter<T>, storage: JsonFileStorage<T>, options?: BindStoreOptions<T>): Promise<() => void>;