1 | import { DataObject, Options } from '../common-types';
|
2 | import { Model } from '../model';
|
3 | import { Repository } from './repository';
|
4 | /**
|
5 | * Filter for keys
|
6 | */
|
7 | export type KeyValueFilter = {
|
8 | /**
|
9 | * Glob string to use to filter returned keys (i.e. `userid.*`). All
|
10 | * connectors are required to support `*` and `?`. They may also support
|
11 | * additional special characters that are specific to the backing database.
|
12 | */
|
13 | match: string;
|
14 | };
|
15 | /**
|
16 | * Key/Value operations for connector implementations
|
17 | */
|
18 | export interface KeyValueRepository<T extends Model> extends Repository<T> {
|
19 | /**
|
20 | * Delete an entry by key
|
21 | *
|
22 | * @param key - Key for the entry
|
23 | * @param options - Options for the operation
|
24 | */
|
25 | delete(key: string, options?: Options): Promise<void>;
|
26 | /**
|
27 | * Delete all entries
|
28 | *
|
29 | * @param key - Key for the entry
|
30 | * @param options - Options for the operation
|
31 | */
|
32 | deleteAll(options?: Options): Promise<void>;
|
33 | /**
|
34 | * Get an entry by key
|
35 | *
|
36 | * @param key - Key for the entry
|
37 | * @param options - Options for the operation
|
38 | * @returns A promise of the entry
|
39 | */
|
40 | get(key: string, options?: Options): Promise<T>;
|
41 | /**
|
42 | * Set an entry with key/value
|
43 | *
|
44 | * @param key - Key for the entry
|
45 | * @param value - Value for the entry
|
46 | * @param options - Options for the operation
|
47 | */
|
48 | set(key: string, value: DataObject<T>, options?: Options): Promise<void>;
|
49 | /**
|
50 | * Set up ttl for an entry by key
|
51 | *
|
52 | * @param key - Key for the entry
|
53 | * @param ttl - Ttl for the entry
|
54 | * @param options - Options for the operation
|
55 | */
|
56 | expire(key: string, ttl: number, options?: Options): Promise<void>;
|
57 | /**
|
58 | * Get ttl for an entry by key
|
59 | *
|
60 | * @param key - Key for the entry
|
61 | * @param options - Options for the operation
|
62 | * @returns A promise of the TTL value
|
63 | */
|
64 | ttl?(key: string, options?: Options): Promise<number>;
|
65 | /**
|
66 | * Get an Iterator for matching keys
|
67 | *
|
68 | * @param filter - Filter for keys
|
69 | * @param options - Options for the operation
|
70 | * @returns An async iteratable iterator of keys so that the return value can
|
71 | * be used with `for-await-of`.
|
72 | */
|
73 | keys?(filter?: KeyValueFilter, options?: Options): AsyncIterable<string>;
|
74 | }
|