UNPKG

3.37 kBTypeScriptView Raw
1export declare function promisifyRequest<T = undefined>(request: IDBRequest<T> | IDBTransaction): Promise<T>;
2export declare function createStore(dbName: string, storeName: string): UseStore;
3export declare type UseStore = <T>(txMode: IDBTransactionMode, callback: (store: IDBObjectStore) => T | PromiseLike<T>) => Promise<T>;
4/**
5 * Get a value by its key.
6 *
7 * @param key
8 * @param customStore Method to get a custom store. Use with caution (see the docs).
9 */
10export declare function get<T = any>(key: IDBValidKey, customStore?: UseStore): Promise<T | undefined>;
11/**
12 * Set a value with a key.
13 *
14 * @param key
15 * @param value
16 * @param customStore Method to get a custom store. Use with caution (see the docs).
17 */
18export declare function set(key: IDBValidKey, value: any, customStore?: UseStore): Promise<void>;
19/**
20 * Set multiple values at once. This is faster than calling set() multiple times.
21 * It's also atomic – if one of the pairs can't be added, none will be added.
22 *
23 * @param entries Array of entries, where each entry is an array of `[key, value]`.
24 * @param customStore Method to get a custom store. Use with caution (see the docs).
25 */
26export declare function setMany(entries: [IDBValidKey, any][], customStore?: UseStore): Promise<void>;
27/**
28 * Get multiple values by their keys
29 *
30 * @param keys
31 * @param customStore Method to get a custom store. Use with caution (see the docs).
32 */
33export declare function getMany<T = any>(keys: IDBValidKey[], customStore?: UseStore): Promise<T[]>;
34/**
35 * Update a value. This lets you see the old value and update it as an atomic operation.
36 *
37 * @param key
38 * @param updater A callback that takes the old value and returns a new value.
39 * @param customStore Method to get a custom store. Use with caution (see the docs).
40 */
41export declare function update<T = any>(key: IDBValidKey, updater: (oldValue: T | undefined) => T, customStore?: UseStore): Promise<void>;
42/**
43 * Delete a particular key from the store.
44 *
45 * @param key
46 * @param customStore Method to get a custom store. Use with caution (see the docs).
47 */
48export declare function del(key: IDBValidKey, customStore?: UseStore): Promise<void>;
49/**
50 * Delete multiple keys at once.
51 *
52 * @param keys List of keys to delete.
53 * @param customStore Method to get a custom store. Use with caution (see the docs).
54 */
55export declare function delMany(keys: IDBValidKey[], customStore?: UseStore): Promise<void>;
56/**
57 * Clear all values in the store.
58 *
59 * @param customStore Method to get a custom store. Use with caution (see the docs).
60 */
61export declare function clear(customStore?: UseStore): Promise<void>;
62/**
63 * Get all keys in the store.
64 *
65 * @param customStore Method to get a custom store. Use with caution (see the docs).
66 */
67export declare function keys<KeyType extends IDBValidKey>(customStore?: UseStore): Promise<KeyType[]>;
68/**
69 * Get all values in the store.
70 *
71 * @param customStore Method to get a custom store. Use with caution (see the docs).
72 */
73export declare function values<T = any>(customStore?: UseStore): Promise<T[]>;
74/**
75 * Get all entries in the store. Each entry is an array of `[key, value]`.
76 *
77 * @param customStore Method to get a custom store. Use with caution (see the docs).
78 */
79export declare function entries<KeyType extends IDBValidKey, ValueType = any>(customStore?: UseStore): Promise<[KeyType, ValueType][]>;