All files / dist/mock MockTable.js

30.76% Statements 8/26
0% Branches 0/10
0% Functions 0/10
33.33% Lines 8/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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  1x 1x 1x 1x 1x 1x 1x                                                                             1x  
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MockTable = void 0;
const SignalData_1 = require("../SignalData");
const khrysalis_runtime_1 = require("@lightningkite/khrysalis-runtime");
const iter_tools_es_1 = require("iter-tools-es");
const rxjs_1 = require("rxjs");
const operators_1 = require("rxjs/operators");
//! Declares com.lightningkite.lightningdb.mock.MockTable
class MockTable {
    constructor() {
        this.data = new khrysalis_runtime_1.EqualOverrideMap([]);
        this.signals = new rxjs_1.Subject();
    }
    observe(condition) {
        return this.signals.pipe((0, operators_1.map)((it) => (0, iter_tools_es_1.execPipe)(this.data.values(), (0, iter_tools_es_1.filter)((it) => condition.invoke(it)), iter_tools_es_1.toArray)));
    }
    getItem(id) {
        var _a;
        return ((_a = this.data.get(id)) !== null && _a !== void 0 ? _a : null);
    }
    asList() {
        return (0, iter_tools_es_1.toArray)(this.data.values());
    }
    addItem(item) {
        this.data.set(item._id, item);
        this.signals.next(new SignalData_1.SignalData(item, true, false));
        return item;
    }
    replaceItem(item) {
        this.data.set(item._id, item);
        this.signals.next(new SignalData_1.SignalData(item, false, false));
        return item;
    }
    deleteItem(item) {
        this.deleteItemById(item._id);
    }
    deleteItemById(id) {
        var _a;
        const item_16 = ((_a = this.data.get(id)) !== null && _a !== void 0 ? _a : null);
        if (item_16 !== null) {
            this.data.delete(id);
            this.signals.next(new SignalData_1.SignalData(item_16, false, true));
        }
    }
}
exports.MockTable = MockTable;
//# sourceMappingURL=MockTable.js.map