All files / dist/mock MockWriteModelApi.js

20.68% Statements 6/29
0% Branches 0/10
0% Functions 0/17
23.07% Lines 6/26

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 49 50 51 52 53 54 55  1x 1x 1x 1x 1x                                                                                               1x  
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MockWriteModelApi = void 0;
const WriteModelApi_1 = require("../WriteModelApi");
const ItemNotFound_1 = require("./ItemNotFound");
const rxjs_1 = require("rxjs");
//! Declares com.lightningkite.lightningdb.mock.MockWriteModelApi
class MockWriteModelApi extends WriteModelApi_1.WriteModelApi {
    constructor(table) {
        super();
        this.table = table;
    }
    post(value) {
        return (0, rxjs_1.of)(this.table.addItem(value));
    }
    postBulk(values) {
        return (0, rxjs_1.of)(values.map((it) => this.table.addItem(it)));
    }
    put(value) {
        return (0, rxjs_1.of)(this.table.replaceItem(value));
    }
    putBulk(values) {
        return (0, rxjs_1.of)(values.map((it) => this.table.replaceItem(it)));
    }
    patch(id, modification) {
        var _a;
        return (_a = (() => {
            var _a;
            const temp6 = ((_a = this.table.data.get(id)) !== null && _a !== void 0 ? _a : null);
            if (temp6 === null) {
                return null;
            }
            return ((item) => {
                const modified = modification.invoke(item);
                this.table.replaceItem(modified);
                return (0, rxjs_1.of)(modified);
            })(temp6);
        })()) !== null && _a !== void 0 ? _a : (0, rxjs_1.throwError)(new ItemNotFound_1.ItemNotFound(`404 item with key ${id} not found`));
    }
    patchBulk(modification) {
        return (0, rxjs_1.of)(this.table
            .asList().filter((it) => modification.condition.invoke(it)).map((it) => this.table.replaceItem(modification.modification.invoke(it))));
    }
    _delete(id) {
        return (0, rxjs_1.of)(this.table.deleteItemById(id));
    }
    deleteBulk(condition) {
        return (0, rxjs_1.of)(this.table
            .asList().filter((it) => condition.invoke(it)).forEach((it) => {
            this.table.deleteItem(it);
        }));
    }
}
exports.MockWriteModelApi = MockWriteModelApi;
//# sourceMappingURL=MockWriteModelApi.js.map