-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
stores.ts
68 lines (60 loc) · 2.48 KB
/
stores.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { Serializable } from "./load/serializable.js";
/** @deprecated For backwards compatibility only. Remove on next minor version upgrade. */
export interface BaseStoreInterface<K, V> {
/**
* Method to get multiple values for a set of keys.
* @param {K[]} keys - An array of keys.
* @returns {Promise<(V | undefined)[]>} - A Promise that resolves with array of values or undefined if key not found.
*/
mget(keys: K[]): Promise<(V | undefined)[]>;
/**
* Method to set a value for multiple keys.
* @param {[K, V][]} keyValuePairs - An array of key-value pairs.
* @returns {Promise<void>} - A Promise that resolves when the operation is complete.
*/
mset(keyValuePairs: [K, V][]): Promise<void>;
/**
* Method to delete multiple keys.
* @param {K[]} keys - An array of keys to delete.
* @returns {Promise<void>} - A Promise that resolves when the operation is complete.
*/
mdelete(keys: K[]): Promise<void>;
/**
* Method to yield keys optionally based on a prefix.
* @param {string} prefix - Optional prefix to filter keys.
* @returns {AsyncGenerator<K | string>} - An asynchronous generator that yields keys on iteration.
*/
yieldKeys(prefix?: string): AsyncGenerator<K | string>;
}
/**
* Abstract interface for a key-value store.
*/
export abstract class BaseStore<K, V>
extends Serializable
implements BaseStoreInterface<K, V>
{
/**
* Abstract method to get multiple values for a set of keys.
* @param {K[]} keys - An array of keys.
* @returns {Promise<(V | undefined)[]>} - A Promise that resolves with array of values or undefined if key not found.
*/
abstract mget(keys: K[]): Promise<(V | undefined)[]>;
/**
* Abstract method to set a value for multiple keys.
* @param {[K, V][]} keyValuePairs - An array of key-value pairs.
* @returns {Promise<void>} - A Promise that resolves when the operation is complete.
*/
abstract mset(keyValuePairs: [K, V][]): Promise<void>;
/**
* Abstract method to delete multiple keys.
* @param {K[]} keys - An array of keys to delete.
* @returns {Promise<void>} - A Promise that resolves when the operation is complete.
*/
abstract mdelete(keys: K[]): Promise<void>;
/**
* Abstract method to yield keys optionally based on a prefix.
* @param {string} prefix - Optional prefix to filter keys.
* @returns {AsyncGenerator<K | string>} - An asynchronous generator that yields keys on iteration.
*/
abstract yieldKeys(prefix?: string): AsyncGenerator<K | string>;
}