import { Encrypter, EventEmitter } from '../utils'; export type StorageOpts = { syncInMemory?: boolean; encryption?: Encrypter; }; export type StoreEvents = { set: { key: string; value: any; }; delete: { key: string; }; clear: undefined; }; export declare abstract class BaseStorage { abstract listStores(): Promise>; abstract createStore(storeName: string, opts: StorageOpts): Promise; abstract getStore(storeName: string, opts: StorageOpts): Promise; abstract createOrGetStore(storeName: string, opts: StorageOpts): Promise; abstract deleteStore(storeName: string): Promise; abstract deleteDatabase(): Promise; } /** * Represents a wrapper object for accessing and manipulating a stored value. */ export type StoreValueProxy = { /** * Gets the current value from the store */ get(): Promise; /** * Gets the current value from the store or fails if undefined. */ getOrFail(): Promise; /** * Sets a new value in the store * @param newValue The value to store */ set(newValue: T): Promise; }; /** * Abstract base class for implementing key-value storage with event emission capabilities. * Extends EventEmitter to provide event handling for store operations. * * @example * ```typescript * class MyStore extends BaseStore { * async keys(): Promise> { * // Implementation * } * * async get(key: string): Promise { * // Implementation * } * * async set(key: string, value: T): Promise { * // Implementation * } * * async delete(key: string): Promise { * // Implementation * } * } * ``` */ export declare abstract class BaseStore extends EventEmitter { /** * Returns an array of all keys in the store. */ abstract keys(): Promise>; /** * Retrieves a value from the store by its key. * * @template T The type of the value to retrieve * @param key The key to lookup */ abstract get(key: string): Promise; /** * Stores a value in the store with the specified key. * * @template T The type of the value to store * @param key The key under which to store the value * @param value The value to store */ abstract set(key: string, value: T): Promise; /** * Removes a value from the store by its key. * * @param key The key to remove */ abstract delete(key: string): Promise; /** * Retrieves all key-value pairs from the store. * * @template T The type of the values in the store */ all(): Promise<{ [key: string]: T; }>; /** * Removes all key-value pairs from the store. */ clear(): Promise; /** * Checks if a key exists in the store. * * @param key The key to check */ has(key: string): Promise; /** * Retrieves multiple values from the store by their keys. * Filters out undefined values from the results. * * @template T The type of the values to retrieve * @param keys Array of keys to retrieve */ batchGet(keys: Array): Promise>; /** * Stores multiple key-value pairs in the store. * Emits 'set' events for each key-value pair. * * @template T The type of the values to store * @param items Map of key-value pairs to store */ batchSet(items: Map): Promise; /** * Closes the store connection. Override this method in implementing classes if needed. */ close(): Promise; /** * Retrieves a value from the store by its key, throwing an error if the value doesn't exist. * * @template T The type of the value to retrieve * @param key The key to lookup */ getOrFail(key: string): Promise; /** * Retrieves a value from the store by its key, or sets it using the provided setter function if it doesn't exist. * * @template T The type of the value to retrieve or set * @param key The key to lookup * @param setter Function to generate the value if it doesn't exist */ getOrSet(key: string, setter: () => T | Promise): Promise; /** * Creates a wrapper object that provides convenient access to a stored value. * The wrapper allows getting and setting the value using async property access. * * @template T The type of the value to wrap * @param key The key under which the value is stored * @returns An object with a getter and setter for the stored value * * @example * ```typescript * const numValue = store.proxy('myNumber'); * const value = await numValue.get(); // gets the stored value * await numValue.set(42); // sets the stored value * ``` */ proxy(key: string): StoreValueProxy; }