UNPKG

@x5e/gink

Version:

an eventually consistent database

56 lines 2.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const implementation_1 = require("../implementation"); const utils_1 = require("../implementation/utils"); const test_utils_1 = require("./test_utils"); it("set, get, delete, and size work as intended", async function () { for (const store of [ new implementation_1.IndexedDbStore("PM.test1", true), new implementation_1.MemoryStore(true), ]) { const instance = new implementation_1.Database({ store }); await instance.ready; const pm1 = await implementation_1.PairMap.create(instance); const box1 = await implementation_1.Box.create(instance); const box2 = await implementation_1.Box.create(instance); const box3 = await implementation_1.Box.create(instance); (0, utils_1.ensure)((await pm1.size()) === 0); await pm1.set([box1, box2], "box1 -> box2"); (0, utils_1.ensure)((await pm1.get([box1, box2])) === "box1 -> box2"); (0, utils_1.ensure)((await pm1.size()) === 1); await pm1.delete([box1, box2]); (0, utils_1.ensure)((await pm1.size()) === 0); (0, utils_1.ensure)(!(await pm1.get([box1, box2]))); await pm1.set([box2, box3], "box2 -> box3"); await pm1.set([box1, box3], "box1 -> box3"); (0, utils_1.ensure)((await pm1.size()) === 2); await pm1.set([box1, box2], "box1 -> box2"); (0, utils_1.ensure)((await pm1.get([box1, box2])) === "box1 -> box2"); } }); it("asOf and items work as intended", async function () { for (const store of [ new implementation_1.IndexedDbStore("PM.test2", true), new implementation_1.MemoryStore(true), ]) { const instance = new implementation_1.Database({ store }); await instance.ready; const pm1 = await implementation_1.PairMap.create(instance); const box1 = await implementation_1.Box.create(instance); const box2 = await implementation_1.Box.create(instance); const box3 = await implementation_1.Box.create(instance); await pm1.set([box1, box2], "box1 -> box2"); await (0, test_utils_1.sleep)(10); const time0 = Date.now() * 1000; await (0, test_utils_1.sleep)(10); await pm1.set([box2, box3], "box2 -> box3"); await pm1.set([box1, box3], "box1 -> box3"); (0, utils_1.ensure)((await pm1.size()) === 3); (0, utils_1.ensure)((await pm1.size(time0)) === 1); (0, utils_1.ensure)(await pm1.has([box1, box2], time0)); (0, utils_1.ensure)(!(await pm1.has([box1, box3], time0))); (0, utils_1.ensure)(await pm1.get([box1, box2], time0)); (0, utils_1.ensure)(!(await pm1.get([box1, box3], time0))); } }); //# sourceMappingURL=PairMap.test.js.map