Completed
Push — main ( cbb93c...4a83d6 )
by Alberto
26s queued 12s
created

MemoryStorageAdapter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 21
dl 0
loc 42
rs 10
c 0
b 0
f 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A empty 0 8 1
A remove 0 8 1
A set 0 8 1
A get 0 6 2
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