File size: 1,066 Bytes
2f527a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const _stores = new Set();

export class Store {
    id;

    constructor(name) {
        name = name.toUpperCase();

        if (_stores.has(name))
            throw `${name} store already exists`;
        _stores.add(name);

        this.id = name;
    }

    async _has(_key) { await Promise.reject("needs implementation"); }
    has(key) {
        if (typeof key !== 'string') {
            key = key.toString();
        }

        return this._has(key);
    }

    async _get(_key) { await Promise.reject("needs implementation"); }
    async get(key) {
        if (typeof key !== 'string') {
            key = key.toString();
        }

        const val = await this._get(key);
        if (val === null)
            return null;

        return val;
    }

    async _set(_key, _val, _exp_sec = -1) { await Promise.reject("needs implementation") }
    set(key, val, exp_sec = -1) {
        if (typeof key !== 'string') {
            key = key.toString();
        }

        exp_sec = Math.round(exp_sec);

        return this._set(key, val, exp_sec);
    }
};