"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const types_1 = require("@deepstream/types");
class LocalCache extends types_1.DeepstreamPlugin {
    constructor() {
        super(...arguments);
        this.description = 'Local Cache';
        this.data = new Map();
    }
    head(recordName, callback) {
        const data = this.data.get(recordName);
        process.nextTick(() => callback(null, data ? data.version : -1));
    }
    headBulk(recordNames, callback) {
        const versions = {};
        const missing = [];
        for (const name of recordNames) {
            const data = this.data.get(name);
            if (data) {
                versions[name] = data.version;
            }
            else {
                missing.push(name);
            }
        }
        process.nextTick(() => callback(null, versions, missing));
    }
    set(key, version, data, callback) {
        this.data.set(key, { version, data });
        process.nextTick(() => callback(null));
    }
    get(key, callback) {
        const data = this.data.get(key);
        if (!data) {
            process.nextTick(() => callback(null, -1, null));
        }
        else {
            process.nextTick(() => callback(null, data.version, data.data));
        }
    }
    delete(key, callback) {
        this.data.delete(key);
        process.nextTick(() => callback(null));
    }
    deleteBulk(keys, callback) {
        keys.forEach((key) => this.data.delete(key));
        process.nextTick(() => callback(null));
    }
}
exports.LocalCache = LocalCache;
exports.default = LocalCache;
//# sourceMappingURL=local-cache.js.map