UNPKG

@x5e/gink

Version:

an eventually consistent database

64 lines 2.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const implementation_1 = require("../implementation"); const utils_1 = require("../implementation/utils"); it("Property.basics", async function () { for (const store of [ new implementation_1.IndexedDbStore("Property.basics", true), new implementation_1.MemoryStore(true), ]) { const instance = new implementation_1.Database(store); await instance.ready; const gd = instance.getGlobalDirectory(); const property = await instance.createProperty(); await property.set(gd, "foobar"); const gotten = await property.get(gd); (0, utils_1.ensure)(gotten === "foobar", `gotten=${gotten}`); const gp = instance.getGlobalProperty(); await property.set(gp, [1, 2, 3]); const gotten2 = await property.get(gp); (0, utils_1.ensure)((0, utils_1.sameData)(gotten2, [1, 2, 3])); const clearMuid = await property.clear(); const hasGp = await property.has(gd); (0, utils_1.ensure)(hasGp === false); const fromBefore = await property.get(gd, clearMuid.timestamp); (0, utils_1.ensure)(fromBefore === "foobar"); } }); it("Property.toMap", async function () { for (const store of [ new implementation_1.IndexedDbStore("Property.toMap", true), new implementation_1.MemoryStore(true), ]) { const instance = new implementation_1.Database(store); await instance.ready; const gd = instance.getGlobalDirectory(); const property = instance.getGlobalProperty(); await property.set(gd, "foobar"); await property.set(property, true); const asMap = await property.toMap(); const asObject = Object.fromEntries(asMap.entries()); (0, utils_1.ensure)(asMap.size === 2); (0, utils_1.ensure)(asObject["-1,-1,4"] === "foobar", Array.from(asMap.keys()).toString()); (0, utils_1.ensure)(asObject["-1,-1,10"] === true, Array.from(asMap.keys()).toString()); } }); it("Global property sets and gets names", async function () { for (const store of [ new implementation_1.IndexedDbStore("Global property sets and gets names", true), new implementation_1.MemoryStore(true), ]) { const instance = new implementation_1.Database(store); await instance.ready; const gd = instance.getGlobalDirectory(); const d2 = await instance.createDirectory(); await gd.setName("foo"); await d2.setName("bar"); const name = await gd.getName(); (0, utils_1.ensure)(name === "foo"); await gd.setName("changed"); const name2 = await gd.getName(); (0, utils_1.ensure)(name2 === "changed"); } }); //# sourceMappingURL=Property.test.js.map