@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
74 lines (73 loc) • 2.58 kB
TypeScript
/**
* Storage management composable for handling storage estimates, monitoring, and migration
* Provides a localStorage-like API for IndexedDB operations
* @param {Object} config - Configuration options
* @param {string} config.dbName - Database name (default: 'LocalStorageDB')
* @param {number} config.dbVersion - Database version (default: 1)
* @param {string} config.storeName - Object store name (default: 'localStates')
* @param {string[]} config.additionalStores - Additional store names to create (optional)
*/
export function useStorageManager(config?: {
dbName: string;
dbVersion: number;
storeName: string;
additionalStores: string[];
}): {
storage: {
/**
* Get item from storage
* @param {string} key - Storage key
* @returns {Promise<any>} - Stored value or null
*/
getItem(key: string): Promise<any>;
/**
* Set item in storage
* @param {string} key - Storage key
* @param {any} value - Value to store
* @returns {Promise<void>}
*/
setItem(key: string, value: any): Promise<void>;
/**
* Remove item from storage
* @param {string} key - Storage key
* @returns {Promise<void>}
*/
removeItem(key: string): Promise<void>;
/**
* Check if item exists in storage
* @param {string} key - Storage key
* @returns {Promise<boolean>}
*/
hasItem(key: string): Promise<boolean>;
/**
* Clear all items from storage
* @returns {Promise<void>}
*/
clear(): Promise<void>;
/**
* Get all keys from storage
* @returns {Promise<string[]>}
*/
getAllKeys(): Promise<string[]>;
/**
* Test storage availability
* @returns {Promise<boolean>}
*/
testAvailability(): Promise<boolean>;
};
getStorageEstimate: () => Promise<Object>;
getStorageUsage: (specificKey?: string) => Promise<Object>;
getStorageWarningLevel: () => Promise<string>;
calculateUsage: () => Promise<Object>;
formatBytes: (bytes: number) => string;
testStorageAvailability: () => Promise<boolean>;
migrateFromLocalStorage: (key: string) => Promise<boolean>;
createStoreManager: (storeName: string) => Object;
getAllStoresData: () => Promise<Object>;
clearAllStores: () => Promise<void>;
getAvailableStores: () => string[];
dbName: any;
dbVersion: any;
primaryStore: any;
allStores: any;
};