export type DataOp = "add" | "remove"; export type DataStore = Record; export type DataSender = (op: DataOp, keys: string[], value?: string) => void; type DataReceiver = (data: DataStore) => void; export type Unsubscribe = () => void; export declare function v2StoreKey(key: string): string; export declare function v2UnescapedStoreKey(key: string): string; export declare function stripV2Prefix(key: string): string; export interface PeprStore { /** * Returns the current value associated with the given key, or null if the given key does not exist. */ getItem(key: string): string | null; /** * Removes all key/value pairs, if there are any. */ clear(): void; /** * Removes the key/value pair with the given key, if a key/value pair with the given key exists. */ removeItem(key: string): void; /** * Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously. */ setItem(key: string, value: string): void; /** * Subscribe to changes in the store. This API behaves similarly to the [Svelte Store API](https://vercel.com/docs/beginner-sveltekit/svelte-stores#using-the-store). * * @param listener - The callback to be invoked when the store changes. * @returns A function to unsubscribe from the listener. */ subscribe(listener: DataReceiver): Unsubscribe; /** * Register a function to be called when the store is ready. */ onReady(callback: DataReceiver): void; /** * Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously. * Resolves when the key/value show up in the store. */ setItemAndWait(key: string, value: string): Promise; /** * Remove the value of the key. * Resolves when the key does not show up in the store. */ removeItemAndWait(key: string): Promise; } /** * A key-value data store that can be used to persist data that should be shared across Pepr controllers and capabilities. * * The API is similar to the [Storage API](https://developer.mozilla.org/docs/Web/API/Storage) */ export declare class Storage implements PeprStore { #private; registerSender: (send: DataSender) => void; receive: (data: DataStore) => void; getItem: (key: string) => string | null; clear: () => void; removeItem: (key: string) => void; setItem: (key: string, value: string) => void; /** * Creates a promise and subscribes to the store, the promise resolves when * the key and value are seen in the store. * * @param key - The key to add into the store * @param value - The value of the key * @returns */ setItemAndWait: (key: string, value: string) => Promise; /** * Creates a promise and subscribes to the store, the promise resolves when * the key is removed from the store. * * @param key - The key to add into the store * @returns */ removeItemAndWait: (key: string) => Promise; subscribe: (subscriber: DataReceiver) => (() => void); onReady: (callback: DataReceiver) => void; /** * Remove a subscriber from the list of subscribers. * @param idx - The index of the subscriber to remove. */ unsubscribe: (idx: number) => void; } export {}; //# sourceMappingURL=storage.d.ts.map