src/services/adapters/memory-storage-adapter.ts   A
last analyzed

Complexity

Total Complexity 5
Complexity/F 1.25

Size

Lines of Code 46
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 22
mnd 1
bc 1
fnc 4
dl 0
loc 46
rs 10
bpm 0.25
cpm 1.25
noi 0
c 0
b 0
f 0

4 Functions

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