-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
kv.repository.ts
87 lines (78 loc) · 2.39 KB
/
kv.repository.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
// Node module: @loopback/repository
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
import {DataObject, Options} from '../common-types';
import {Model} from '../model';
import {Repository} from './repository';
/**
* Filter for keys
*/
export type KeyValueFilter = {
/**
* Glob string to use to filter returned keys (i.e. `userid.*`). All
* connectors are required to support `*` and `?`. They may also support
* additional special characters that are specific to the backing database.
*/
match: string;
};
/**
* Key/Value operations for connector implementations
*/
export interface KeyValueRepository<T extends Model> extends Repository<T> {
/**
* Delete an entry by key
*
* @param key - Key for the entry
* @param options - Options for the operation
*/
delete(key: string, options?: Options): Promise<void>;
/**
* Delete all entries
*
* @param key - Key for the entry
* @param options - Options for the operation
*/
deleteAll(options?: Options): Promise<void>;
/**
* Get an entry by key
*
* @param key - Key for the entry
* @param options - Options for the operation
* @returns A promise of the entry
*/
get(key: string, options?: Options): Promise<T>;
/**
* Set an entry with key/value
*
* @param key - Key for the entry
* @param value - Value for the entry
* @param options - Options for the operation
*/
set(key: string, value: DataObject<T>, options?: Options): Promise<void>;
/**
* Set up ttl for an entry by key
*
* @param key - Key for the entry
* @param ttl - Ttl for the entry
* @param options - Options for the operation
*/
expire(key: string, ttl: number, options?: Options): Promise<void>;
/**
* Get ttl for an entry by key
*
* @param key - Key for the entry
* @param options - Options for the operation
* @returns A promise of the TTL value
*/
ttl?(key: string, options?: Options): Promise<number>;
/**
* Get an Iterator for matching keys
*
* @param filter - Filter for keys
* @param options - Options for the operation
* @returns An async iteratable iterator of keys so that the return value can
* be used with `for-await-of`.
*/
keys?(filter?: KeyValueFilter, options?: Options): AsyncIterable<string>;
}