UNPKG

3.25 kBPlain TextView Raw
1// Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
2// Node module: @loopback/repository
3// This file is licensed under the MIT License.
4// License text available at https://opensource.org/licenses/MIT
5
6import {Filter} from '@loopback/filter';
7import {Class, Options} from '../common-types';
8import {Entity, EntityData} from '../model';
9import {Connector} from './connector';
10
11/**
12 * Key/Value operations for connector implementations
13 */
14export interface KVConnector<T extends Entity> extends Connector {
15 /**
16 * Delete an entry by key
17 * @param modelClass - Model class
18 * @param key - Key for the entry
19 * @param options - Options for the operation
20 * @returns Promise<true> if an entry is deleted for the id, otherwise
21 * Promise<false>
22 */
23 delete(
24 modelClass: Class<Entity>,
25 key: string,
26 options?: Options,
27 ): Promise<boolean>;
28
29 /**
30 * Delete all entries
31 * @param modelClass - Model class
32 * @param options - Options for the operation
33 * @returns A promise of the number of entries deleted
34 */
35 deleteAll(modelClass: Class<Entity>, options?: Options): Promise<number>;
36
37 /**
38 * Get an entry by key
39 * @param modelClass - Model class
40 * @param key - Key for the entry
41 * @param options - Options for the operation
42 * @returns A promise of the entry found for the key
43 */
44 get(modelClass: Class<Entity>, key: string, options?: Options): Promise<T>;
45
46 /**
47 * Set an entry with key/value
48 * @param modelClass - Model class
49 * @param key - Key for the entry
50 * @param value - Value for the entry
51 * @param options - Options for the operation
52 * @returns Promise<true> if an entry is set for the key, otherwise
53 * Promise<false>
54 */
55 set(
56 modelClass: Class<Entity>,
57 key: string,
58 value: EntityData,
59 options?: Options,
60 ): Promise<boolean>;
61
62 /**
63 * Set up ttl for an entry by key
64 * @param modelClass - Model class
65 * @param key - Key for the entry
66 * @param options - Options for the operation
67 * @returns Promise<true> if an entry is configured for the key, otherwise
68 * Promise<false>
69 */
70 expire(
71 modelClass: Class<Entity>,
72 key: string,
73 ttl: number,
74 options?: Options,
75 ): Promise<boolean>;
76
77 /**
78 * Get ttl for an entry by key
79 * @param modelClass - Model class
80 * @param key - Key for the entry
81 * @param ttl - Time to live in millisenconds
82 * @param options - Options for the operation
83 * @returns A promise of the TTL value
84 */
85 ttl?(
86 modelClass: Class<Entity>,
87 key: string,
88 ttl: number,
89 options?: Options,
90 ): Promise<number>;
91
92 /**
93 * Fetch all keys
94 * @param modelClass - Model class
95 * @param key - Key for the entry
96 * @param options - Options for the operation
97 * @returns A promise of an array of keys for all entries
98 */
99 keys?(modelClass: Class<Entity>, options?: Options): Promise<string[]>;
100
101 /**
102 * Get an Iterator for matching keys
103 * @param modelClass - Model class
104 * @param filter - Matching filter
105 * @param options - Options for the operation
106 * @returns A promise of an iterator of entries
107 */
108 iterateKeys?(
109 modelClass: Class<Entity>,
110 filter?: Filter,
111 options?: Options,
112 ): Promise<Iterator<T>>;
113}