Total Complexity | 5 |
Complexity/F | 1.25 |
Lines of Code | 46 |
Function Count | 4 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import StorageAdapterInterface from "./storage-adapter-interface"; |
||
2 | |||
3 | /** |
||
4 | * In memory storage adapter. |
||
5 | */ |
||
6 | export default class MemoryStorageAdapter implements StorageAdapterInterface { |
||
7 | /** |
||
8 | * The memory store |
||
9 | */ |
||
10 | #store: { [s: string]: any } = {}; |
||
11 | |||
12 | /** |
||
13 | * @inheritdoc |
||
14 | */ |
||
15 | get(key: string): Promise<any> { |
||
16 | return Promise.resolve(this.#store?.[key]); |
||
17 | } |
||
18 | |||
19 | /** |
||
20 | * @inheritdoc |
||
21 | */ |
||
22 | set(key: string, value: any): Promise<any> { |
||
23 | this.#store[key] = value; |
||
24 | |||
25 | return Promise.resolve(); |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * @inheritdoc |
||
30 | */ |
||
31 | remove(key: string): Promise<any> { |
||
32 | delete this.#store[key]; |
||
33 | |||
34 | return Promise.resolve(); |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * @inheritdoc |
||
39 | */ |
||
40 | empty(): Promise<any> { |
||
41 | this.#store = {}; |
||
42 | |||
43 | return Promise.resolve(); |
||
44 | } |
||
45 | } |
||
46 |