UNPKG

crann

Version:

Effortless State Synchronization for Web Extensions

60 lines (59 loc) 1.71 kB
/** * Persistence - Handles chrome.storage operations * * Responsibilities: * - Hydrate state from storage on startup * - Persist state changes to storage * - Manage storage key structure: crann:{name}:v{version}:{key} */ import { ConfigSchema, ValidatedConfig, DerivedSharedState, StoreOptions } from "./types"; export declare class Persistence<TConfig extends ConfigSchema> { private readonly config; private readonly options; constructor(config: ValidatedConfig<TConfig>, options?: StoreOptions); /** * Build a storage key with the structured format. * Format: crann:{name}:v{version}:{key} */ private buildKey; /** * Parse a storage key to extract components. */ private parseKey; /** * Get the metadata key for this store. * Format: crann:{name}:__meta */ private getMetaKey; /** * Hydrate state from chrome.storage. * Only loads keys that exist in the current config. */ hydrate(): Promise<Partial<DerivedSharedState<TConfig>>>; /** * Persist state changes to storage. * Only persists keys with persist: 'local' or 'session'. */ persist(state: Partial<DerivedSharedState<TConfig>>): Promise<void>; /** * Clear all persisted data for this store. */ clearAll(): Promise<void>; private updateMetadata; } /** * Find and remove orphaned Crann data from storage. * * @example * const removed = await clearOrphanedData({ * keepStores: ['myFeature', 'otherStore'], * dryRun: true, * }); */ export declare function clearOrphanedData(options: { keepStores: string[]; dryRun?: boolean; }): Promise<{ keys: string[]; count: number; }>;