chex-storage
Version:
A wrapper library for Chrome extension storage local - the standard storage in the chrome extension.
88 lines (87 loc) • 2.57 kB
TypeScript
import { Optional, StorageKey } from "typing";
import ChexStorageWhereMethods from "./_where";
declare class ChexTable<TData, TKeyPropName extends keyof TData> {
#private;
constructor(database: string, name: string, keyName: StorageKey<TKeyPropName>);
/**
* Get data database
*/
private getDatabase;
/**
* Generate key
* When add new data, it'll detect auto create or not key
* @param data
* @returns
*/
private generateKey;
/**
* Querying data with the specified key condition
*
* @param keyWhere
* @returns ChexStorageWhereMethods
*/
where(keyWhere: string): ChexStorageWhereMethods<TData>;
/**
* Adds new data to the table and returns the key of the added data.
*
* @param data
* @returns Key value
*/
add(data: Optional<TData, TKeyPropName>): Promise<TData[TKeyPropName]>;
/**
* Adds multiple data entries to the table
*
* @param data
*/
bulkAdd(data: Optional<TData, TKeyPropName>[]): Promise<void>;
/**
* Gets all data from the table or gets data by a specific key
*
* @param key
* @returns Data | undefined
*/
get(): Promise<TData[]>;
get(key: TData[TKeyPropName]): Promise<TData | undefined>;
/**
* Updates data in the table by key and returns the key of the updated data
*
* @param key
* @param change
*/
update(keyValue: TData[TKeyPropName], change: Partial<Omit<TData, TKeyPropName>>): Promise<TData[TKeyPropName]>;
/**
* Update data for create new record
*
* @param keyValue
* @param change
* @param defaultValue
* @returns
*/
updateOrCreate(keyValue: TData[TKeyPropName], change: Partial<Omit<TData, TKeyPropName>>, defaultValue: Omit<TData, TKeyPropName>): Promise<TData[TKeyPropName]>;
/**
* Updates all data in the table with the specified changes.
*
* @param change
*/
updateAll(change: Partial<Omit<TData, TKeyPropName>>): Promise<void>;
/**
* Deletes multiple data entries from the table by their keys
*
* @param keyValue
*/
delete(keyValue: TData[TKeyPropName]): Promise<void>;
/**
* Delete
*
* @param keyValues
*/
bulkDelete(keyValues: TData[TKeyPropName][]): Promise<void>;
/**
* Query data with the same of filter factory function
*
* @param callback
* @returns TData[]
*/
filter(callback: (row: TData) => boolean): Promise<TData[]>;
}
export default ChexTable;