import EventEmitter from '../util/event.emitter';
import { ERROR } from '../types';
class Cache extends EventEmitter {
    _data = new Map();
    get data() {
        return this.getAll();
    }
    set data(map) {
        throw ERROR.CACHE_SET_ERROR;
    }
    save(source) {
        if (!Array.isArray(source)) {
            this._data.set(source.id, source);
            return;
        }
        source.forEach(s => this._data.set(s.id, s));
    }
    get(id) {
        return this._data.get(id);
    }
    remove(id) {
        this._data.delete(id);
    }
    getAll() {
        const list = [];
        for (const pair of this._data) {
            list.push(pair[1]);
        }
        return list;
    }
    removeAll() {
        const ids = [];
        for (const pair of this._data) {
            ids.push(pair[0]);
        }
        this._data = new Map();
        return ids;
    }
}
export default Cache;
//# sourceMappingURL=cache.js.map