-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
class.ts
49 lines (44 loc) · 1.37 KB
/
class.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
export interface Kv {
/**
* Get the stored value by key. Returns undefined if the key doesn't exist in the store
*
* @param key Key to retrieve from the store
* @returns Stored value, or undefined if key doesn't exist
*/
get<T = unknown>(key: string): Promise<T | undefined>;
/**
* Save the given value to the store
*
* @param key Key to save in the store
* @param value Value to save to the store. Can be any JavaScript primitive, plain object, or array
*/
set<T = unknown>(key: string, value: T): Promise<void>;
/**
* Remove the given key from the store
*
* @param key Key to remove from the store
*/
delete(key: string): Promise<void>;
/**
* Check if a given key exists in the store
*
* @param key Key to check
*/
has(key: string): Promise<boolean>;
/**
* Increment the given stored value by the given amount
*
* @param key Key to increment in the store
* @param [amount=1] Amount to increment. Defaults to 1
* @returns Updated value
*/
increment(key: string, amount?: number): Promise<number>;
/**
* Save the given value to the store if the given value is larger than the existing value
*
* @param key Key to save in the store
* @param value Number to save to the store if it's bigger than the current value
* @returns Whether or not the given value was saved
*/
setMax(key: string, value: number): Promise<boolean>;
}