UNPKG

@amitkhare/indexed-storage

Version:

A modern, localStorage-like API for IndexedDB with instance-based and static APIs, multi-store support, configurable databases, and enhanced capabilities

247 lines (246 loc) 7.86 kB
export default IndexedStorage; /** * IndexedStorage - A modern wrapper for IndexedDB with multi-store and multi-database support * * Usage patterns: * 1. Instance-based (new API): const storage = new IndexedStorage({ dbName: 'myApp', version: 1 }); * 2. Static methods (legacy API): IndexedStorage.setItem('key', 'value'); * * @class IndexedStorage */ declare class IndexedStorage { static _defaultInstance: null; /** * Get the default static instance * @private */ private static _getDefaultInstance; /** * Static method: Get an item * @param {string} key * @param {string} [storeName] * @returns {Promise<any>} */ static getItem(key: string, storeName?: string): Promise<any>; /** * Static method: Set an item * @param {string} key * @param {any} value * @param {string} [storeName] * @returns {Promise<void>} */ static setItem(key: string, value: any, storeName?: string): Promise<void>; /** * Static method: Remove an item * @param {string} key * @param {string} [storeName] * @returns {Promise<void>} */ static removeItem(key: string, storeName?: string): Promise<void>; /** * Static method: Clear a store * @param {string} [storeName] * @returns {Promise<void>} */ static clear(storeName?: string): Promise<void>; /** * Static method: Get all keys * @param {string} [storeName] * @returns {Promise<string[]>} */ static getAllKeys(storeName?: string): Promise<string[]>; /** * Static method: Get all values * @param {string} [storeName] * @returns {Promise<any[]>} */ static getAllValues(storeName?: string): Promise<any[]>; /** * Static method: Create a store * @param {string} storeName * @param {Object} [storeConfig] * @returns {Promise<void>} */ static createStore(storeName: string, storeConfig?: Object): Promise<void>; /** * Static method: Delete a store * @param {string} storeName * @returns {Promise<void>} */ static deleteStore(storeName: string): Promise<void>; /** * Static method: Get store info * @param {string} [storeName] * @returns {Promise<Object>} */ static getStoreInfo(storeName?: string): Promise<Object>; /** * Static method: List stores * @returns {Promise<string[]>} */ static listStores(): Promise<string[]>; /** * Static method: Initialize * @returns {Promise<IDBDatabase>} */ static init(): Promise<IDBDatabase>; /** * Static method: Close */ static close(): void; /** * Static method: Get store-specific API * @param {string} storeName * @returns {Object} */ static getStore(storeName: string): Object; /** * Static method: Get all stores data * @returns {Promise<Object>} */ static getAllStoresData(): Promise<Object>; /** * Static method: Clear all stores * @returns {Promise<void>} */ static clearAllStores(): Promise<void>; /** * Static method: Get available stores * @returns {Promise<string[]>} */ static getAvailableStores(): Promise<string[]>; /** * Static method: Set multiple stores * @param {Object} storeData * @returns {Promise<void>} */ static setMultipleStores(storeData: Object): Promise<void>; /** * Static method: Get multiple stores * @param {Object} storeKeys * @returns {Promise<Object>} */ static getMultipleStores(storeKeys: Object): Promise<Object>; constructor(config?: {}); config: { dbName: any; version: any; storeName: any; storeConfig: any; additionalStores: any; storeConfigs: any; logging: any; }; db: any; isInitialized: boolean; /** * Initialize the database connection asynchronously * @private */ private _initializeAsync; /** * Initialize the database connection * @returns {Promise<IDBDatabase>} */ init(): Promise<IDBDatabase>; /** * Get an item from the store * @param {string} key - The key to retrieve * @param {string} [storeName] - Store name (defaults to configured store) * @returns {Promise<any>} */ getItem(key: string, storeName?: string): Promise<any>; /** * Set an item in the store * @param {string} key - The key to store * @param {any} value - The value to store * @param {string} [storeName] - Store name (defaults to configured store) * @returns {Promise<void>} */ setItem(key: string, value: any, storeName?: string): Promise<void>; /** * Remove an item from the store * @param {string} key - The key to remove * @param {string} [storeName] - Store name (defaults to configured store) * @returns {Promise<void>} */ removeItem(key: string, storeName?: string): Promise<void>; /** * Clear all items from a store * @param {string} [storeName] - Store name (defaults to configured store) * @returns {Promise<void>} */ clear(storeName?: string): Promise<void>; /** * Get all keys from a store * @param {string} [storeName] - Store name (defaults to configured store) * @returns {Promise<string[]>} */ getAllKeys(storeName?: string): Promise<string[]>; /** * Get all values from a store * @param {string} [storeName] - Store name (defaults to configured store) * @returns {Promise<any[]>} */ getAllValues(storeName?: string): Promise<any[]>; /** * Create a new store in the database * @param {string} storeName - Name of the store to create * @param {Object} [storeConfig] - Store configuration * @returns {Promise<void>} */ createStore(storeName: string, storeConfig?: Object): Promise<void>; /** * Delete a store from the database * @param {string} storeName - Name of the store to delete * @returns {Promise<void>} */ deleteStore(storeName: string): Promise<void>; /** * Get store information * @param {string} [storeName] - Store name (defaults to configured store) * @returns {Promise<Object>} */ getStoreInfo(storeName?: string): Promise<Object>; /** * List all stores in the database * @returns {Promise<string[]>} */ listStores(): Promise<string[]>; /** * Close the database connection */ close(): void; /** * Get a store-specific API for easier multi-store operations * @param {string} storeName - Name of the store * @returns {Object} Store-specific API object */ getStore(storeName: string): Object; /** * Get data from all stores in the database * @returns {Promise<Object>} Object with store names as keys and their data as values */ getAllStoresData(): Promise<Object>; /** * Clear all stores in the database * @returns {Promise<void>} */ clearAllStores(): Promise<void>; /** * Get available stores (alias for listStores for consistency with multi-store API) * @returns {Promise<string[]>} */ getAvailableStores(): Promise<string[]>; /** * Set multiple items across different stores * @param {Object} storeData - Object with store names as keys and data objects as values * @returns {Promise<void>} */ setMultipleStores(storeData: Object): Promise<void>; /** * Get multiple items from different stores * @param {Object} storeKeys - Object with store names as keys and key arrays as values * @returns {Promise<Object>} Object with store names as keys and retrieved data as values */ getMultipleStores(storeKeys: Object): Promise<Object>; }