UNPKG

@pstdio/opfs-utils

Version:

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

26 lines (25 loc) 1.14 kB
export interface JsonFileStorageOptions<T> { /** Initial fallback used when the file is missing or cannot be parsed. */ defaultValue: T; /** Relative path to the JSON file inside OPFS. */ filePath: string; /** Delay (ms) applied before writing successive updates. */ debounceMs?: number; /** Optional migration hook executed on the raw file value. */ migrate?: (fileValue: unknown) => T; /** Optional serializer. Defaults to pretty JSON. */ serialize?: (value: T) => string; /** Optional deserializer. Defaults to JSON.parse. */ deserialize?: (text: string) => unknown; /** Interval (ms) for polling OPFS changes. Set to 0 to disable polling. */ watchIntervalMs?: number; /** Custom BroadcastChannel identifier. Pass null to disable BroadcastChannel. */ broadcastChannelId?: string | null; } export interface JsonFileStorage<T> { read(): Promise<T>; write(next: T): Promise<void>; subscribe(listener: (next: T) => void): () => void; dispose(): void; } export declare function createJsonFileStorage<T>(options: JsonFileStorageOptions<T>): JsonFileStorage<T>;