angular-indexed-db-helper
Version:
A powerful and flexible Angular 11 library for managing client-side storage using IndexedDB with support for cache expiration and CRUD operations.
74 lines (73 loc) • 2.91 kB
TypeScript
export declare class IndexedDbHandler {
private dbName;
private storeName;
private storeNameList;
private cachedTime;
private dbInitialized;
constructor(dbName: string, storeName: string, storeNameList: string[], cachedTime: number);
/**
* Ensures that the database is fully set up before performing any operations.
* @returns A promise that resolves when the IndexedDB is initialized.
*/
whenInitialized(): Promise<IDBDatabase>;
/**
* Initializes the IndexedDB and creates the object store if it doesn't exist.
* @returns A promise that resolves to the IndexedDB instance.
*/
private initDB;
/**
* Saves data to the IndexedDB.
* @param key The key used to store the data.
* @param value The data to be saved.
* @param cacheTime Optional parameter to specify the cache time for the data.
* @returns A promise that resolves when the data is saved.
*/
saveData(key: string, value: any, cacheTime?: number | null): Promise<void>;
/**
* Retrieves data from the IndexedDB by key.
* @param key The key of the data to retrieve.
* @returns A promise that resolves to the data or null if not found or expired.
*/
getData(key: string): Promise<any>;
/**
* Removes data from the IndexedDB by key.
* @param key The key of the data to remove.
* @returns A promise that resolves when the data is removed.
*/
removeData(key: string): Promise<void>;
/**
* Updates data in the IndexedDB by key.
* @param key The key of the data to update.
* @param value The new data to update.
* @returns A promise that resolves when the data is updated.
*/
updateData(key: string, value: any): Promise<void>;
/**
* Retrieves all data from the IndexedDB store.
* Filters out expired data based on the cache time or default expiration time.
* @returns A promise that resolves to an array of all valid data items.
*/
getAll(): Promise<any[]>;
/**
* Clears all data in the IndexedDB store.
* @returns A promise that resolves when the store is cleared.
*/
clearStore(): Promise<void>;
/**
* Getter for the cached time value.
* @returns The current cached time value.
*/
getCachedTime(): number;
/**
* Setter for the cached time value.
* @param newCachedTime The new cached time value to set.
*/
setCachedTime(newCachedTime: number): void;
/**
* Checks if the data has expired based on the saved time and comparison time.
* @param savedTime The saved time of the data.
* @param comparisonTimeInMs The comparison time in milliseconds.
* @returns A promise that resolves to a boolean indicating if the data is expired.
*/
private checkIfExpired;
}