1 | import { Filter } from '@loopback/filter';
|
2 | import { Class, Options } from '../common-types';
|
3 | import { Entity, EntityData } from '../model';
|
4 | import { Connector } from './connector';
|
5 | /**
|
6 | * Key/Value operations for connector implementations
|
7 | */
|
8 | export interface KVConnector<T extends Entity> extends Connector {
|
9 | /**
|
10 | * Delete an entry by key
|
11 | * @param modelClass - Model class
|
12 | * @param key - Key for the entry
|
13 | * @param options - Options for the operation
|
14 | * @returns Promise<true> if an entry is deleted for the id, otherwise
|
15 | * Promise<false>
|
16 | */
|
17 | delete(modelClass: Class<Entity>, key: string, options?: Options): Promise<boolean>;
|
18 | /**
|
19 | * Delete all entries
|
20 | * @param modelClass - Model class
|
21 | * @param options - Options for the operation
|
22 | * @returns A promise of the number of entries deleted
|
23 | */
|
24 | deleteAll(modelClass: Class<Entity>, options?: Options): Promise<number>;
|
25 | /**
|
26 | * Get an entry by key
|
27 | * @param modelClass - Model class
|
28 | * @param key - Key for the entry
|
29 | * @param options - Options for the operation
|
30 | * @returns A promise of the entry found for the key
|
31 | */
|
32 | get(modelClass: Class<Entity>, key: string, options?: Options): Promise<T>;
|
33 | /**
|
34 | * Set an entry with key/value
|
35 | * @param modelClass - Model class
|
36 | * @param key - Key for the entry
|
37 | * @param value - Value for the entry
|
38 | * @param options - Options for the operation
|
39 | * @returns Promise<true> if an entry is set for the key, otherwise
|
40 | * Promise<false>
|
41 | */
|
42 | set(modelClass: Class<Entity>, key: string, value: EntityData, options?: Options): Promise<boolean>;
|
43 | /**
|
44 | * Set up ttl for an entry by key
|
45 | * @param modelClass - Model class
|
46 | * @param key - Key for the entry
|
47 | * @param options - Options for the operation
|
48 | * @returns Promise<true> if an entry is configured for the key, otherwise
|
49 | * Promise<false>
|
50 | */
|
51 | expire(modelClass: Class<Entity>, key: string, ttl: number, options?: Options): Promise<boolean>;
|
52 | /**
|
53 | * Get ttl for an entry by key
|
54 | * @param modelClass - Model class
|
55 | * @param key - Key for the entry
|
56 | * @param ttl - Time to live in millisenconds
|
57 | * @param options - Options for the operation
|
58 | * @returns A promise of the TTL value
|
59 | */
|
60 | ttl?(modelClass: Class<Entity>, key: string, ttl: number, options?: Options): Promise<number>;
|
61 | /**
|
62 | * Fetch all keys
|
63 | * @param modelClass - Model class
|
64 | * @param key - Key for the entry
|
65 | * @param options - Options for the operation
|
66 | * @returns A promise of an array of keys for all entries
|
67 | */
|
68 | keys?(modelClass: Class<Entity>, options?: Options): Promise<string[]>;
|
69 | /**
|
70 | * Get an Iterator for matching keys
|
71 | * @param modelClass - Model class
|
72 | * @param filter - Matching filter
|
73 | * @param options - Options for the operation
|
74 | * @returns A promise of an iterator of entries
|
75 | */
|
76 | iterateKeys?(modelClass: Class<Entity>, filter?: Filter, options?: Options): Promise<Iterator<T>>;
|
77 | }
|