@daiso-tech/core 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/_module.js +3 -1
- package/dist/cjs/_module.js.map +1 -1
- package/dist/cjs/_shared/kysely/_module.js +18 -0
- package/dist/cjs/_shared/kysely/_module.js.map +1 -0
- package/dist/cjs/_shared/kysely/kysely-table-name-transformer-plugin.js +45 -0
- package/dist/cjs/_shared/kysely/kysely-table-name-transformer-plugin.js.map +1 -0
- package/dist/cjs/_shared/redis/_module.js +20 -0
- package/dist/cjs/_shared/redis/_module.js.map +1 -0
- package/dist/cjs/_shared/redis/clear-iterable.js +25 -0
- package/dist/cjs/_shared/redis/clear-iterable.js.map +1 -0
- package/dist/cjs/_shared/redis/escape-redis-chars.js +41 -0
- package/dist/cjs/_shared/redis/escape-redis-chars.js.map +1 -0
- package/dist/cjs/_shared/redis/is-redis-type-error.js +9 -0
- package/dist/cjs/_shared/redis/is-redis-type-error.js.map +1 -0
- package/dist/cjs/_shared/utilities.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/_shared/async-cross-join-iterable.js.map +1 -1
- package/dist/cjs/collection/async-iterable-collection/async-iterable-collection.js.map +1 -1
- package/dist/cjs/collection/iterable-collection/_shared/cross-join-iterable.js.map +1 -1
- package/dist/cjs/contracts/_module.js +2 -0
- package/dist/cjs/contracts/_module.js.map +1 -1
- package/dist/cjs/contracts/collection/_module.js.map +1 -1
- package/dist/cjs/contracts/serializer/_module.js +18 -0
- package/dist/cjs/contracts/serializer/_module.js.map +1 -0
- package/dist/cjs/contracts/serializer/serializer.contract.js +25 -0
- package/dist/cjs/contracts/serializer/serializer.contract.js.map +1 -0
- package/dist/cjs/contracts/storage/_module.js +20 -0
- package/dist/cjs/contracts/storage/_module.js.map +1 -0
- package/dist/cjs/contracts/storage/_shared.js +32 -0
- package/dist/cjs/contracts/storage/_shared.js.map +1 -0
- package/dist/cjs/contracts/storage/storage-adapter.contract.js +3 -0
- package/dist/cjs/contracts/storage/storage-adapter.contract.js.map +1 -0
- package/dist/cjs/contracts/storage/storage.contract.js +3 -0
- package/dist/cjs/contracts/storage/storage.contract.js.map +1 -0
- package/dist/cjs/serializer/_module.js +22 -0
- package/dist/cjs/serializer/_module.js.map +1 -0
- package/dist/cjs/serializer/_shared/test-utilities/_module.js +18 -0
- package/dist/cjs/serializer/_shared/test-utilities/_module.js.map +1 -0
- package/dist/cjs/serializer/_shared/test-utilities/serializer.test-suite.js +361 -0
- package/dist/cjs/serializer/_shared/test-utilities/serializer.test-suite.js.map +1 -0
- package/dist/cjs/serializer/mongodb-serializer/_module.js +18 -0
- package/dist/cjs/serializer/mongodb-serializer/_module.js.map +1 -0
- package/dist/cjs/serializer/mongodb-serializer/mongodb-serializer.js +36 -0
- package/dist/cjs/serializer/mongodb-serializer/mongodb-serializer.js.map +1 -0
- package/dist/cjs/serializer/redis-serializer/_module.js +18 -0
- package/dist/cjs/serializer/redis-serializer/_module.js.map +1 -0
- package/dist/cjs/serializer/redis-serializer/redis-serializer.js +37 -0
- package/dist/cjs/serializer/redis-serializer/redis-serializer.js.map +1 -0
- package/dist/cjs/serializer/sql-serializer/_module.js +18 -0
- package/dist/cjs/serializer/sql-serializer/_module.js.map +1 -0
- package/dist/cjs/serializer/sql-serializer/sql-serializer.js +37 -0
- package/dist/cjs/serializer/sql-serializer/sql-serializer.js.map +1 -0
- package/dist/cjs/serializer/super-json-serializer/_module.js +18 -0
- package/dist/cjs/serializer/super-json-serializer/_module.js.map +1 -0
- package/dist/cjs/serializer/super-json-serializer/super-json-serializer.js +304 -0
- package/dist/cjs/serializer/super-json-serializer/super-json-serializer.js.map +1 -0
- package/dist/cjs/storage/_module.js +23 -0
- package/dist/cjs/storage/_module.js.map +1 -0
- package/dist/cjs/storage/_shared/test-utilities/_module.js +18 -0
- package/dist/cjs/storage/_shared/test-utilities/_module.js.map +1 -0
- package/dist/cjs/storage/_shared/test-utilities/storage-api.test-suite.js +572 -0
- package/dist/cjs/storage/_shared/test-utilities/storage-api.test-suite.js.map +1 -0
- package/dist/cjs/storage/_shared/test-utilities/storage-namespace.test-suite.js +241 -0
- package/dist/cjs/storage/_shared/test-utilities/storage-namespace.test-suite.js.map +1 -0
- package/dist/cjs/storage/_shared/test-utilities/storage-value.test-suite.js +4172 -0
- package/dist/cjs/storage/_shared/test-utilities/storage-value.test-suite.js.map +1 -0
- package/dist/cjs/storage/_shared/test-utilities/storage.test-suite.js +12 -0
- package/dist/cjs/storage/_shared/test-utilities/storage.test-suite.js.map +1 -0
- package/dist/cjs/storage/memory-storage-adapter/_module.js +18 -0
- package/dist/cjs/storage/memory-storage-adapter/_module.js.map +1 -0
- package/dist/cjs/storage/memory-storage-adapter/memory-storage-adapter.js +62 -0
- package/dist/cjs/storage/memory-storage-adapter/memory-storage-adapter.js.map +1 -0
- package/dist/cjs/storage/mongodb-storage-adapter/_module.js +6 -0
- package/dist/cjs/storage/mongodb-storage-adapter/_module.js.map +1 -0
- package/dist/cjs/storage/mongodb-storage-adapter/mongodb-storage-adapter.js +273 -0
- package/dist/cjs/storage/mongodb-storage-adapter/mongodb-storage-adapter.js.map +1 -0
- package/dist/cjs/storage/namespace-storage-adapter.js +66 -0
- package/dist/cjs/storage/namespace-storage-adapter.js.map +1 -0
- package/dist/cjs/storage/redis-storage-adapter/_module.js +18 -0
- package/dist/cjs/storage/redis-storage-adapter/_module.js.map +1 -0
- package/dist/cjs/storage/redis-storage-adapter/redis-storage-adapter.js +248 -0
- package/dist/cjs/storage/redis-storage-adapter/redis-storage-adapter.js.map +1 -0
- package/dist/cjs/storage/sqlite/_module.js +19 -0
- package/dist/cjs/storage/sqlite/_module.js.map +1 -0
- package/dist/cjs/storage/sqlite/_shared/_module.js +18 -0
- package/dist/cjs/storage/sqlite/_shared/_module.js.map +1 -0
- package/dist/cjs/storage/sqlite/_shared/base-sqlite-storage-adapter.js +224 -0
- package/dist/cjs/storage/sqlite/_shared/base-sqlite-storage-adapter.js.map +1 -0
- package/dist/cjs/storage/sqlite/libsql-storage-adapter/_module.js +18 -0
- package/dist/cjs/storage/sqlite/libsql-storage-adapter/_module.js.map +1 -0
- package/dist/cjs/storage/sqlite/libsql-storage-adapter/libsql-storage-adapter.js +53 -0
- package/dist/cjs/storage/sqlite/libsql-storage-adapter/libsql-storage-adapter.js.map +1 -0
- package/dist/cjs/storage/sqlite/sqlite-storage-adapter/_module.js +18 -0
- package/dist/cjs/storage/sqlite/sqlite-storage-adapter/_module.js.map +1 -0
- package/dist/cjs/storage/sqlite/sqlite-storage-adapter/sqlite-storage-adapter.js +52 -0
- package/dist/cjs/storage/sqlite/sqlite-storage-adapter/sqlite-storage-adapter.js.map +1 -0
- package/dist/cjs/storage/storage.js +291 -0
- package/dist/cjs/storage/storage.js.map +1 -0
- package/dist/cjs/storage/usable-storage-adapter.js +102 -0
- package/dist/cjs/storage/usable-storage-adapter.js.map +1 -0
- package/dist/esm/_module.js +3 -1
- package/dist/esm/_module.js.map +1 -1
- package/dist/esm/_shared/kysely/_module.js +2 -0
- package/dist/esm/_shared/kysely/_module.js.map +1 -0
- package/dist/esm/_shared/kysely/kysely-table-name-transformer-plugin.js +41 -0
- package/dist/esm/_shared/kysely/kysely-table-name-transformer-plugin.js.map +1 -0
- package/dist/esm/_shared/redis/_module.js +4 -0
- package/dist/esm/_shared/redis/_module.js.map +1 -0
- package/dist/esm/_shared/redis/clear-iterable.js +21 -0
- package/dist/esm/_shared/redis/clear-iterable.js.map +1 -0
- package/dist/esm/_shared/redis/escape-redis-chars.js +38 -0
- package/dist/esm/_shared/redis/escape-redis-chars.js.map +1 -0
- package/dist/esm/_shared/redis/is-redis-type-error.js +6 -0
- package/dist/esm/_shared/redis/is-redis-type-error.js.map +1 -0
- package/dist/esm/_shared/utilities.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/_shared/async-cross-join-iterable.js.map +1 -1
- package/dist/esm/collection/async-iterable-collection/async-iterable-collection.js.map +1 -1
- package/dist/esm/collection/iterable-collection/_shared/cross-join-iterable.js.map +1 -1
- package/dist/esm/contracts/_module.js +2 -0
- package/dist/esm/contracts/_module.js.map +1 -1
- package/dist/esm/contracts/collection/_module.js.map +1 -1
- package/dist/esm/contracts/serializer/_module.js +2 -0
- package/dist/esm/contracts/serializer/_module.js.map +1 -0
- package/dist/esm/contracts/serializer/serializer.contract.js +19 -0
- package/dist/esm/contracts/serializer/serializer.contract.js.map +1 -0
- package/dist/esm/contracts/storage/_module.js +4 -0
- package/dist/esm/contracts/storage/_module.js.map +1 -0
- package/dist/esm/contracts/storage/_shared.js +25 -0
- package/dist/esm/contracts/storage/_shared.js.map +1 -0
- package/dist/esm/contracts/storage/storage-adapter.contract.js +1 -0
- package/dist/esm/contracts/storage/storage-adapter.contract.js.map +1 -0
- package/dist/esm/contracts/storage/storage.contract.js +1 -0
- package/dist/esm/contracts/storage/storage.contract.js.map +1 -0
- package/dist/esm/serializer/_module.js +6 -0
- package/dist/esm/serializer/_module.js.map +1 -0
- package/dist/esm/serializer/_shared/test-utilities/_module.js +2 -0
- package/dist/esm/serializer/_shared/test-utilities/_module.js.map +1 -0
- package/dist/esm/serializer/_shared/test-utilities/serializer.test-suite.js +358 -0
- package/dist/esm/serializer/_shared/test-utilities/serializer.test-suite.js.map +1 -0
- package/dist/esm/serializer/mongodb-serializer/_module.js +2 -0
- package/dist/esm/serializer/mongodb-serializer/_module.js.map +1 -0
- package/dist/esm/serializer/mongodb-serializer/mongodb-serializer.js +32 -0
- package/dist/esm/serializer/mongodb-serializer/mongodb-serializer.js.map +1 -0
- package/dist/esm/serializer/redis-serializer/_module.js +2 -0
- package/dist/esm/serializer/redis-serializer/_module.js.map +1 -0
- package/dist/esm/serializer/redis-serializer/redis-serializer.js +33 -0
- package/dist/esm/serializer/redis-serializer/redis-serializer.js.map +1 -0
- package/dist/esm/serializer/sql-serializer/_module.js +2 -0
- package/dist/esm/serializer/sql-serializer/_module.js.map +1 -0
- package/dist/esm/serializer/sql-serializer/sql-serializer.js +33 -0
- package/dist/esm/serializer/sql-serializer/sql-serializer.js.map +1 -0
- package/dist/esm/serializer/super-json-serializer/_module.js +2 -0
- package/dist/esm/serializer/super-json-serializer/_module.js.map +1 -0
- package/dist/esm/serializer/super-json-serializer/super-json-serializer.js +277 -0
- package/dist/esm/serializer/super-json-serializer/super-json-serializer.js.map +1 -0
- package/dist/esm/storage/_module.js +7 -0
- package/dist/esm/storage/_module.js.map +1 -0
- package/dist/esm/storage/_shared/test-utilities/_module.js +2 -0
- package/dist/esm/storage/_shared/test-utilities/_module.js.map +1 -0
- package/dist/esm/storage/_shared/test-utilities/storage-api.test-suite.js +569 -0
- package/dist/esm/storage/_shared/test-utilities/storage-api.test-suite.js.map +1 -0
- package/dist/esm/storage/_shared/test-utilities/storage-namespace.test-suite.js +238 -0
- package/dist/esm/storage/_shared/test-utilities/storage-namespace.test-suite.js.map +1 -0
- package/dist/esm/storage/_shared/test-utilities/storage-value.test-suite.js +4169 -0
- package/dist/esm/storage/_shared/test-utilities/storage-value.test-suite.js.map +1 -0
- package/dist/esm/storage/_shared/test-utilities/storage.test-suite.js +9 -0
- package/dist/esm/storage/_shared/test-utilities/storage.test-suite.js.map +1 -0
- package/dist/esm/storage/memory-storage-adapter/_module.js +2 -0
- package/dist/esm/storage/memory-storage-adapter/_module.js.map +1 -0
- package/dist/esm/storage/memory-storage-adapter/memory-storage-adapter.js +58 -0
- package/dist/esm/storage/memory-storage-adapter/memory-storage-adapter.js.map +1 -0
- package/dist/esm/storage/mongodb-storage-adapter/_module.js +2 -0
- package/dist/esm/storage/mongodb-storage-adapter/_module.js.map +1 -0
- package/dist/esm/storage/mongodb-storage-adapter/mongodb-storage-adapter.js +266 -0
- package/dist/esm/storage/mongodb-storage-adapter/mongodb-storage-adapter.js.map +1 -0
- package/dist/esm/storage/namespace-storage-adapter.js +62 -0
- package/dist/esm/storage/namespace-storage-adapter.js.map +1 -0
- package/dist/esm/storage/redis-storage-adapter/_module.js +2 -0
- package/dist/esm/storage/redis-storage-adapter/_module.js.map +1 -0
- package/dist/esm/storage/redis-storage-adapter/redis-storage-adapter.js +244 -0
- package/dist/esm/storage/redis-storage-adapter/redis-storage-adapter.js.map +1 -0
- package/dist/esm/storage/sqlite/_module.js +3 -0
- package/dist/esm/storage/sqlite/_module.js.map +1 -0
- package/dist/esm/storage/sqlite/_shared/_module.js +2 -0
- package/dist/esm/storage/sqlite/_shared/_module.js.map +1 -0
- package/dist/esm/storage/sqlite/_shared/base-sqlite-storage-adapter.js +220 -0
- package/dist/esm/storage/sqlite/_shared/base-sqlite-storage-adapter.js.map +1 -0
- package/dist/esm/storage/sqlite/libsql-storage-adapter/_module.js +2 -0
- package/dist/esm/storage/sqlite/libsql-storage-adapter/_module.js.map +1 -0
- package/dist/esm/storage/sqlite/libsql-storage-adapter/libsql-storage-adapter.js +49 -0
- package/dist/esm/storage/sqlite/libsql-storage-adapter/libsql-storage-adapter.js.map +1 -0
- package/dist/esm/storage/sqlite/sqlite-storage-adapter/_module.js +2 -0
- package/dist/esm/storage/sqlite/sqlite-storage-adapter/_module.js.map +1 -0
- package/dist/esm/storage/sqlite/sqlite-storage-adapter/sqlite-storage-adapter.js +48 -0
- package/dist/esm/storage/sqlite/sqlite-storage-adapter/sqlite-storage-adapter.js.map +1 -0
- package/dist/esm/storage/storage.js +287 -0
- package/dist/esm/storage/storage.js.map +1 -0
- package/dist/esm/storage/usable-storage-adapter.js +98 -0
- package/dist/esm/storage/usable-storage-adapter.js.map +1 -0
- package/dist/types/_module.d.ts +3 -1
- package/dist/types/_shared/kysely/_module.d.ts +1 -0
- package/dist/types/_shared/kysely/kysely-table-name-transformer-plugin.d.ts +13 -0
- package/dist/types/_shared/redis/_module.d.ts +3 -0
- package/dist/types/_shared/redis/clear-iterable.d.ts +13 -0
- package/dist/types/_shared/redis/escape-redis-chars.d.ts +7 -0
- package/dist/types/_shared/redis/is-redis-type-error.d.ts +7 -0
- package/dist/types/_shared/types.d.ts +15 -2
- package/dist/types/_shared/utilities.d.ts +11 -1
- package/dist/types/collection/_shared.d.ts +1 -1
- package/dist/types/collection/async-iterable-collection/_shared/async-cross-join-iterable.d.ts +2 -1
- package/dist/types/collection/async-iterable-collection/_shared/async-group-by-iterable.d.ts +1 -1
- package/dist/types/collection/async-iterable-collection/async-iterable-collection.d.ts +2 -2
- package/dist/types/collection/iterable-collection/_shared/cross-join-iterable.d.ts +1 -1
- package/dist/types/collection/iterable-collection/_shared/group-by-iterable.d.ts +1 -1
- package/dist/types/collection/iterable-collection/iterable-collection.d.ts +1 -1
- package/dist/types/collection/list-collection/list-collection.d.ts +1 -1
- package/dist/types/contracts/_module.d.ts +2 -0
- package/dist/types/contracts/collection/_module.d.ts +0 -3
- package/dist/types/contracts/collection/_shared.d.ts +1 -1
- package/dist/types/contracts/collection/async-collection.contract.d.ts +3 -3
- package/dist/types/contracts/collection/collection.contract.d.ts +3 -3
- package/dist/types/contracts/serializer/_module.d.ts +1 -0
- package/dist/types/contracts/serializer/serializer.contract.d.ts +37 -0
- package/dist/types/contracts/storage/_module.d.ts +3 -0
- package/dist/types/contracts/storage/_shared.d.ts +27 -0
- package/dist/types/contracts/storage/storage-adapter.contract.d.ts +72 -0
- package/dist/types/contracts/storage/storage.contract.d.ts +147 -0
- package/dist/types/serializer/_module.d.ts +5 -0
- package/dist/types/serializer/_shared/test-utilities/_module.d.ts +1 -0
- package/dist/types/serializer/_shared/test-utilities/serializer.test-suite.d.ts +18 -0
- package/dist/types/serializer/mongodb-serializer/_module.d.ts +1 -0
- package/dist/types/serializer/mongodb-serializer/mongodb-serializer.d.ts +13 -0
- package/dist/types/serializer/redis-serializer/_module.d.ts +1 -0
- package/dist/types/serializer/redis-serializer/redis-serializer.d.ts +13 -0
- package/dist/types/serializer/sql-serializer/_module.d.ts +1 -0
- package/dist/types/serializer/sql-serializer/sql-serializer.d.ts +13 -0
- package/dist/types/serializer/super-json-serializer/_module.d.ts +1 -0
- package/dist/types/serializer/super-json-serializer/super-json-serializer.d.ts +37 -0
- package/dist/types/storage/_module.d.ts +6 -0
- package/dist/types/storage/_shared/test-utilities/_module.d.ts +1 -0
- package/dist/types/storage/_shared/test-utilities/storage-api.test-suite.d.ts +20 -0
- package/dist/types/storage/_shared/test-utilities/storage-namespace.test-suite.d.ts +20 -0
- package/dist/types/storage/_shared/test-utilities/storage-value.test-suite.d.ts +20 -0
- package/dist/types/storage/_shared/test-utilities/storage.test-suite.d.ts +20 -0
- package/dist/types/storage/memory-storage-adapter/_module.d.ts +1 -0
- package/dist/types/storage/memory-storage-adapter/memory-storage-adapter.d.ts +16 -0
- package/dist/types/storage/mongodb-storage-adapter/_module.d.ts +1 -0
- package/dist/types/storage/mongodb-storage-adapter/mongodb-storage-adapter.d.ts +46 -0
- package/dist/types/storage/namespace-storage-adapter.d.ts +30 -0
- package/dist/types/storage/redis-storage-adapter/_module.d.ts +1 -0
- package/dist/types/storage/redis-storage-adapter/redis-storage-adapter.d.ts +41 -0
- package/dist/types/storage/sqlite/_module.d.ts +2 -0
- package/dist/types/storage/sqlite/_shared/_module.d.ts +1 -0
- package/dist/types/storage/sqlite/_shared/base-sqlite-storage-adapter.d.ts +42 -0
- package/dist/types/storage/sqlite/libsql-storage-adapter/_module.d.ts +1 -0
- package/dist/types/storage/sqlite/libsql-storage-adapter/libsql-storage-adapter.d.ts +30 -0
- package/dist/types/storage/sqlite/sqlite-storage-adapter/_module.d.ts +1 -0
- package/dist/types/storage/sqlite/sqlite-storage-adapter/sqlite-storage-adapter.d.ts +30 -0
- package/dist/types/storage/storage.d.ts +36 -0
- package/dist/types/storage/usable-storage-adapter.d.ts +22 -0
- package/package.json +41 -6
|
@@ -0,0 +1,4172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.storageValueTestSuite = storageValueTestSuite;
|
|
4
|
+
const _module_1 = require("../../../storage/_module");
|
|
5
|
+
function storageValueTestSuite(settings) {
|
|
6
|
+
const { expect, test, createAdapter, describe, beforeEach } = settings;
|
|
7
|
+
let storage;
|
|
8
|
+
beforeEach(async () => {
|
|
9
|
+
storage = new _module_1.Storage(await createAdapter());
|
|
10
|
+
});
|
|
11
|
+
describe("Value tests:", () => {
|
|
12
|
+
describe("method: get / add", () => {
|
|
13
|
+
test("Should work with positive integer", async () => {
|
|
14
|
+
const value = 1;
|
|
15
|
+
await storage.add("a", value);
|
|
16
|
+
expect(await storage.get("a")).toBe(value);
|
|
17
|
+
});
|
|
18
|
+
test("Should work with negative integer", async () => {
|
|
19
|
+
const value = -1;
|
|
20
|
+
await storage.add("a", value);
|
|
21
|
+
expect(await storage.get("a")).toBe(value);
|
|
22
|
+
});
|
|
23
|
+
test("Should work with positive decimal", async () => {
|
|
24
|
+
const value = 1.5;
|
|
25
|
+
await storage.add("a", value);
|
|
26
|
+
expect(await storage.get("a")).toBe(value);
|
|
27
|
+
});
|
|
28
|
+
test("Should work with negative decimal", async () => {
|
|
29
|
+
const value = -1.5;
|
|
30
|
+
await storage.add("a", value);
|
|
31
|
+
expect(await storage.get("a")).toBe(value);
|
|
32
|
+
});
|
|
33
|
+
test("Should work with NaN", async () => {
|
|
34
|
+
const value = NaN;
|
|
35
|
+
await storage.add("a", value);
|
|
36
|
+
const getResult = await storage.get("a");
|
|
37
|
+
expect(getResult).toBeNaN();
|
|
38
|
+
});
|
|
39
|
+
test("Should work with Infinity", async () => {
|
|
40
|
+
const value = Infinity;
|
|
41
|
+
await storage.add("a", value);
|
|
42
|
+
const getResult = await storage.get("a");
|
|
43
|
+
expect(isFinite(getResult)).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
test("Should work with Bigint", async () => {
|
|
46
|
+
const value = 20n;
|
|
47
|
+
await storage.add("a", value);
|
|
48
|
+
expect(await storage.get("a")).toBe(value);
|
|
49
|
+
});
|
|
50
|
+
test("Should work with true", async () => {
|
|
51
|
+
const value = true;
|
|
52
|
+
await storage.add("a", value);
|
|
53
|
+
expect(await storage.get("a")).toBe(value);
|
|
54
|
+
});
|
|
55
|
+
test("Should work with false", async () => {
|
|
56
|
+
const value = false;
|
|
57
|
+
await storage.add("a", value);
|
|
58
|
+
expect(await storage.get("a")).toBe(value);
|
|
59
|
+
});
|
|
60
|
+
test("Should work with string", async () => {
|
|
61
|
+
const value = "str";
|
|
62
|
+
await storage.add("a", value);
|
|
63
|
+
expect(await storage.get("a")).toBe(value);
|
|
64
|
+
});
|
|
65
|
+
test("Should work with Date", async () => {
|
|
66
|
+
const value = new Date("2024-01-01");
|
|
67
|
+
await storage.add("a", value);
|
|
68
|
+
const getResult = await storage.get("a");
|
|
69
|
+
expect(getResult).toBeInstanceOf(Date);
|
|
70
|
+
expect(getResult).toEqual(value);
|
|
71
|
+
});
|
|
72
|
+
test("Should work with RegExp", async () => {
|
|
73
|
+
const value = /test/;
|
|
74
|
+
await storage.add("a", value);
|
|
75
|
+
const getResult = await storage.get("a");
|
|
76
|
+
expect(getResult).toBeInstanceOf(RegExp);
|
|
77
|
+
expect(getResult).toEqual(value);
|
|
78
|
+
});
|
|
79
|
+
test("Should work with Buffer", async () => {
|
|
80
|
+
const value = Buffer.from("asd");
|
|
81
|
+
await storage.add("a", value);
|
|
82
|
+
const getResult = await storage.get("a");
|
|
83
|
+
expect(getResult).toBeInstanceOf(Buffer);
|
|
84
|
+
expect(getResult?.toString("base64")).toEqual(value.toString("base64"));
|
|
85
|
+
});
|
|
86
|
+
test("Should work with Uint8Array", async () => {
|
|
87
|
+
const value = new Uint8Array(Buffer.from("asd"));
|
|
88
|
+
await storage.add("a", value);
|
|
89
|
+
const getResult = await storage.get("a");
|
|
90
|
+
expect(getResult).toBeInstanceOf(Uint8Array);
|
|
91
|
+
expect(getResult
|
|
92
|
+
? Buffer.from(getResult).toString("base64")
|
|
93
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
94
|
+
});
|
|
95
|
+
test("Should work with Int8Array", async () => {
|
|
96
|
+
const value = new Int8Array(Buffer.from("asd"));
|
|
97
|
+
await storage.add("a", value);
|
|
98
|
+
const getResult = await storage.get("a");
|
|
99
|
+
expect(getResult).toBeInstanceOf(Int8Array);
|
|
100
|
+
expect(getResult
|
|
101
|
+
? Buffer.from(getResult).toString("base64")
|
|
102
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
103
|
+
});
|
|
104
|
+
test("Should work with Uint16Array", async () => {
|
|
105
|
+
const value = new Uint16Array(Buffer.from("asd"));
|
|
106
|
+
await storage.add("a", value);
|
|
107
|
+
const getResult = await storage.get("a");
|
|
108
|
+
expect(getResult).toBeInstanceOf(Uint16Array);
|
|
109
|
+
expect(getResult
|
|
110
|
+
? Buffer.from(getResult).toString("base64")
|
|
111
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
112
|
+
});
|
|
113
|
+
test("Should work with Int16Array", async () => {
|
|
114
|
+
const value = new Int16Array(Buffer.from("asd"));
|
|
115
|
+
await storage.add("a", value);
|
|
116
|
+
const getResult = await storage.get("a");
|
|
117
|
+
expect(getResult).toBeInstanceOf(Int16Array);
|
|
118
|
+
expect(getResult
|
|
119
|
+
? Buffer.from(getResult).toString("base64")
|
|
120
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
121
|
+
});
|
|
122
|
+
test("Should work with Uint32Array", async () => {
|
|
123
|
+
const value = new Uint32Array(Buffer.from("asd"));
|
|
124
|
+
await storage.add("a", value);
|
|
125
|
+
const getResult = await storage.get("a");
|
|
126
|
+
expect(getResult).toBeInstanceOf(Uint32Array);
|
|
127
|
+
expect(getResult
|
|
128
|
+
? Buffer.from(getResult).toString("base64")
|
|
129
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
130
|
+
});
|
|
131
|
+
test("Should work with Int32Array", async () => {
|
|
132
|
+
const value = new Int32Array(Buffer.from("asd"));
|
|
133
|
+
await storage.add("a", value);
|
|
134
|
+
const getResult = await storage.get("a");
|
|
135
|
+
expect(getResult).toBeInstanceOf(Int32Array);
|
|
136
|
+
expect(getResult
|
|
137
|
+
? Buffer.from(getResult).toString("base64")
|
|
138
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
139
|
+
});
|
|
140
|
+
test("Should work with Float32Array", async () => {
|
|
141
|
+
const value = new Float32Array(Buffer.from("asd"));
|
|
142
|
+
await storage.add("a", value);
|
|
143
|
+
const getResult = await storage.get("a");
|
|
144
|
+
expect(getResult).toBeInstanceOf(Float32Array);
|
|
145
|
+
expect(getResult
|
|
146
|
+
? Buffer.from(getResult).toString("base64")
|
|
147
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
148
|
+
});
|
|
149
|
+
test("Should work with Float64Array", async () => {
|
|
150
|
+
const value = new Float64Array(Buffer.from("asd"));
|
|
151
|
+
await storage.add("a", value);
|
|
152
|
+
const getResult = await storage.get("a");
|
|
153
|
+
expect(getResult).toBeInstanceOf(Float64Array);
|
|
154
|
+
expect(getResult
|
|
155
|
+
? Buffer.from(getResult).toString("base64")
|
|
156
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
157
|
+
});
|
|
158
|
+
test("Should work with Set", async () => {
|
|
159
|
+
const value = new Set(["a", "b", "c"]);
|
|
160
|
+
await storage.add("a", value);
|
|
161
|
+
const getResult = await storage.get("a");
|
|
162
|
+
expect(getResult).toBeInstanceOf(Set);
|
|
163
|
+
expect(getResult).toEqual(value);
|
|
164
|
+
});
|
|
165
|
+
test("Should work with Set of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays", async () => {
|
|
166
|
+
const value = new Set([
|
|
167
|
+
0,
|
|
168
|
+
-1,
|
|
169
|
+
1,
|
|
170
|
+
-1.5,
|
|
171
|
+
1.5,
|
|
172
|
+
NaN,
|
|
173
|
+
Infinity,
|
|
174
|
+
2n,
|
|
175
|
+
true,
|
|
176
|
+
false,
|
|
177
|
+
"str",
|
|
178
|
+
new Date("2024-01-01"),
|
|
179
|
+
new Set(["a", "b", "c"]),
|
|
180
|
+
new Map([
|
|
181
|
+
["a", 1],
|
|
182
|
+
["b", 2],
|
|
183
|
+
["c", 3],
|
|
184
|
+
]),
|
|
185
|
+
{ a: 1, b: 2 },
|
|
186
|
+
[1, 2, 3],
|
|
187
|
+
/test/,
|
|
188
|
+
]);
|
|
189
|
+
await storage.add("a", value);
|
|
190
|
+
const getResult = await storage.get("a");
|
|
191
|
+
expect(getResult).toBeInstanceOf(Set);
|
|
192
|
+
expect(getResult).toEqual(value);
|
|
193
|
+
});
|
|
194
|
+
test("Should work with Map", async () => {
|
|
195
|
+
const value = new Map([
|
|
196
|
+
["a", 1],
|
|
197
|
+
["b", 2],
|
|
198
|
+
["c", 3],
|
|
199
|
+
]);
|
|
200
|
+
await storage.add("a", value);
|
|
201
|
+
const getResult = await storage.get("a");
|
|
202
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
203
|
+
expect(getResult).toEqual(value);
|
|
204
|
+
});
|
|
205
|
+
test("Should work with Map of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays values", async () => {
|
|
206
|
+
const value = new Map([
|
|
207
|
+
["a", 0],
|
|
208
|
+
["b", -1],
|
|
209
|
+
["c", 1],
|
|
210
|
+
["d", -1.5],
|
|
211
|
+
["e", 1.5],
|
|
212
|
+
["f", NaN],
|
|
213
|
+
["g", Infinity],
|
|
214
|
+
["h", 2n],
|
|
215
|
+
["j", true],
|
|
216
|
+
["l", false],
|
|
217
|
+
["i", "str"],
|
|
218
|
+
["r", new Date("2024-01-01")],
|
|
219
|
+
["k", new Set(["a", "b", "c"])],
|
|
220
|
+
[
|
|
221
|
+
"p",
|
|
222
|
+
new Map([
|
|
223
|
+
["a", 1],
|
|
224
|
+
["b", 2],
|
|
225
|
+
["c", 3],
|
|
226
|
+
]),
|
|
227
|
+
],
|
|
228
|
+
["a", /test/],
|
|
229
|
+
[1, { a: 2, b: -1 }],
|
|
230
|
+
[2, [1, 2, 3]],
|
|
231
|
+
]);
|
|
232
|
+
await storage.add("a", value);
|
|
233
|
+
const getResult = await storage.get("a");
|
|
234
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
235
|
+
expect(getResult).toEqual(value);
|
|
236
|
+
});
|
|
237
|
+
test("Should work with Map of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays keys", async () => {
|
|
238
|
+
const value = new Map([
|
|
239
|
+
[0, "a"],
|
|
240
|
+
[-1, "a"],
|
|
241
|
+
[1, "a"],
|
|
242
|
+
[-1.5, "a"],
|
|
243
|
+
[1.5, "a"],
|
|
244
|
+
[NaN, "a"],
|
|
245
|
+
[Infinity, "a"],
|
|
246
|
+
[2n, "a"],
|
|
247
|
+
[true, "a"],
|
|
248
|
+
[false, "a"],
|
|
249
|
+
["str", "a"],
|
|
250
|
+
[new Date("2024-01-01"), "a"],
|
|
251
|
+
[new Set(["a", "b", "c"]), "a"],
|
|
252
|
+
[
|
|
253
|
+
new Map([
|
|
254
|
+
["a", 1],
|
|
255
|
+
["b", 2],
|
|
256
|
+
["c", 3],
|
|
257
|
+
]),
|
|
258
|
+
"a",
|
|
259
|
+
],
|
|
260
|
+
[/test/, "a"],
|
|
261
|
+
[{ a: 2, b: -1 }, 1],
|
|
262
|
+
[[1, 2, 3], 2],
|
|
263
|
+
]);
|
|
264
|
+
await storage.add("a", value);
|
|
265
|
+
const getResult = await storage.get("a");
|
|
266
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
267
|
+
expect(getResult).toEqual(value);
|
|
268
|
+
});
|
|
269
|
+
test("Should work with array of number, boolean, string, Date, Set, Map, RegExp", async () => {
|
|
270
|
+
const value = [
|
|
271
|
+
0,
|
|
272
|
+
-1,
|
|
273
|
+
1,
|
|
274
|
+
-1.5,
|
|
275
|
+
1.5,
|
|
276
|
+
NaN,
|
|
277
|
+
Infinity,
|
|
278
|
+
2n,
|
|
279
|
+
true,
|
|
280
|
+
false,
|
|
281
|
+
"str",
|
|
282
|
+
new Date("2024-01-01"),
|
|
283
|
+
new Set(["a", "b", "c"]),
|
|
284
|
+
new Map([
|
|
285
|
+
["a", 1],
|
|
286
|
+
["b", 2],
|
|
287
|
+
["c", 3],
|
|
288
|
+
]),
|
|
289
|
+
/test/,
|
|
290
|
+
];
|
|
291
|
+
await storage.add("a", value);
|
|
292
|
+
const getResult = await storage.get("a");
|
|
293
|
+
expect(getResult).toEqual(value);
|
|
294
|
+
});
|
|
295
|
+
test("Should work with array of objects", async () => {
|
|
296
|
+
const value = [
|
|
297
|
+
Object.fromEntries([
|
|
298
|
+
["a", 0],
|
|
299
|
+
["b", -1],
|
|
300
|
+
["c", 1],
|
|
301
|
+
["d", -1.5],
|
|
302
|
+
["e", 1.5],
|
|
303
|
+
["f", NaN],
|
|
304
|
+
["g", Infinity],
|
|
305
|
+
["h", 2n],
|
|
306
|
+
["j", true],
|
|
307
|
+
["l", false],
|
|
308
|
+
["i", "str"],
|
|
309
|
+
["r", new Date("2024-01-01")],
|
|
310
|
+
["k", new Set(["a", "b", "c"])],
|
|
311
|
+
[
|
|
312
|
+
"p",
|
|
313
|
+
new Map([
|
|
314
|
+
["a", 1],
|
|
315
|
+
["b", 2],
|
|
316
|
+
["c", 3],
|
|
317
|
+
]),
|
|
318
|
+
],
|
|
319
|
+
["a", /test/],
|
|
320
|
+
]),
|
|
321
|
+
];
|
|
322
|
+
await storage.add("a", value);
|
|
323
|
+
const getResult = await storage.get("a");
|
|
324
|
+
expect(getResult).toEqual(value);
|
|
325
|
+
});
|
|
326
|
+
test("Should work with object of number, boolean, string, Date, Set, Map, RegExp", async () => {
|
|
327
|
+
const value = Object.fromEntries([
|
|
328
|
+
["a", 0],
|
|
329
|
+
["b", -1],
|
|
330
|
+
["c", 1],
|
|
331
|
+
["d", -1.5],
|
|
332
|
+
["e", 1.5],
|
|
333
|
+
["f", NaN],
|
|
334
|
+
["g", Infinity],
|
|
335
|
+
["h", 2n],
|
|
336
|
+
["j", true],
|
|
337
|
+
["l", false],
|
|
338
|
+
["i", "str"],
|
|
339
|
+
["r", new Date("2024-01-01")],
|
|
340
|
+
["k", new Set(["a", "b", "c"])],
|
|
341
|
+
[
|
|
342
|
+
"p",
|
|
343
|
+
new Map([
|
|
344
|
+
["a", 1],
|
|
345
|
+
["b", 2],
|
|
346
|
+
["c", 3],
|
|
347
|
+
]),
|
|
348
|
+
],
|
|
349
|
+
["a", /test/],
|
|
350
|
+
]);
|
|
351
|
+
await storage.add("a", value);
|
|
352
|
+
const getResult = await storage.get("a");
|
|
353
|
+
expect(getResult).toEqual(value);
|
|
354
|
+
});
|
|
355
|
+
test("Should work with object of arrays", async () => {
|
|
356
|
+
const value = {
|
|
357
|
+
a: [
|
|
358
|
+
0,
|
|
359
|
+
-1,
|
|
360
|
+
1,
|
|
361
|
+
-1.5,
|
|
362
|
+
1.5,
|
|
363
|
+
NaN,
|
|
364
|
+
Infinity,
|
|
365
|
+
2n,
|
|
366
|
+
true,
|
|
367
|
+
false,
|
|
368
|
+
"str",
|
|
369
|
+
new Date("2024-01-01"),
|
|
370
|
+
new Set(["a", "b", "c"]),
|
|
371
|
+
new Map([
|
|
372
|
+
["a", 1],
|
|
373
|
+
["b", 2],
|
|
374
|
+
["c", 3],
|
|
375
|
+
]),
|
|
376
|
+
/test/,
|
|
377
|
+
],
|
|
378
|
+
};
|
|
379
|
+
await storage.add("a", value);
|
|
380
|
+
const getResult = await storage.get("a");
|
|
381
|
+
expect(getResult).toEqual(value);
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
describe("method: getMany / addMany", () => {
|
|
385
|
+
test("Should work with positive integer", async () => {
|
|
386
|
+
const value = 1;
|
|
387
|
+
await storage.addMany({ a: value });
|
|
388
|
+
expect(await storage.getMany(["a"])).toEqual({ a: value });
|
|
389
|
+
});
|
|
390
|
+
test("Should work with negative integer", async () => {
|
|
391
|
+
const value = -1;
|
|
392
|
+
await storage.addMany({ a: value });
|
|
393
|
+
expect(await storage.getMany(["a"])).toEqual({ a: value });
|
|
394
|
+
});
|
|
395
|
+
test("Should work with positive decimal", async () => {
|
|
396
|
+
const value = 1.5;
|
|
397
|
+
await storage.addMany({ a: value });
|
|
398
|
+
expect(await storage.getMany(["a"])).toEqual({ a: value });
|
|
399
|
+
});
|
|
400
|
+
test("Should work with negative decimal", async () => {
|
|
401
|
+
const value = -1.5;
|
|
402
|
+
await storage.addMany({ a: value });
|
|
403
|
+
expect(await storage.getMany(["a"])).toEqual({ a: value });
|
|
404
|
+
});
|
|
405
|
+
test("Should work with NaN", async () => {
|
|
406
|
+
const value = NaN;
|
|
407
|
+
await storage.addMany({ a: value });
|
|
408
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
409
|
+
expect(getResult).toBeNaN();
|
|
410
|
+
});
|
|
411
|
+
test("Should work with Infinity", async () => {
|
|
412
|
+
const value = Infinity;
|
|
413
|
+
await storage.addMany({ a: value });
|
|
414
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
415
|
+
expect(isFinite(getResult)).toBe(false);
|
|
416
|
+
});
|
|
417
|
+
test("Should work with Bigint", async () => {
|
|
418
|
+
const value = 20n;
|
|
419
|
+
await storage.addMany({ a: value });
|
|
420
|
+
expect(await storage.getMany(["a"])).toEqual({ a: value });
|
|
421
|
+
});
|
|
422
|
+
test("Should work with true", async () => {
|
|
423
|
+
const value = true;
|
|
424
|
+
await storage.addMany({ a: value });
|
|
425
|
+
expect(await storage.getMany(["a"])).toEqual({ a: value });
|
|
426
|
+
});
|
|
427
|
+
test("Should work with false", async () => {
|
|
428
|
+
const value = false;
|
|
429
|
+
await storage.addMany({ a: value });
|
|
430
|
+
expect(await storage.getMany(["a"])).toEqual({ a: value });
|
|
431
|
+
});
|
|
432
|
+
test("Should work with string", async () => {
|
|
433
|
+
const value = "str";
|
|
434
|
+
await storage.addMany({ a: value });
|
|
435
|
+
expect(await storage.getMany(["a"])).toEqual({ a: value });
|
|
436
|
+
});
|
|
437
|
+
test("Should work with Date", async () => {
|
|
438
|
+
const value = new Date("2024-01-01");
|
|
439
|
+
await storage.addMany({ a: value });
|
|
440
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
441
|
+
expect(getResult).toBeInstanceOf(Date);
|
|
442
|
+
expect(getResult).toEqual(value);
|
|
443
|
+
});
|
|
444
|
+
test("Should work with RegExp", async () => {
|
|
445
|
+
const value = /test/;
|
|
446
|
+
await storage.addMany({ a: value });
|
|
447
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
448
|
+
expect(getResult).toBeInstanceOf(RegExp);
|
|
449
|
+
expect(getResult).toEqual(value);
|
|
450
|
+
});
|
|
451
|
+
test("Should work with Buffer", async () => {
|
|
452
|
+
const value = Buffer.from("asd");
|
|
453
|
+
await storage.addMany({ a: value });
|
|
454
|
+
const { a: getResult } = await storage.getMany([
|
|
455
|
+
"a",
|
|
456
|
+
]);
|
|
457
|
+
expect(getResult).toBeInstanceOf(Buffer);
|
|
458
|
+
expect(getResult?.toString("base64")).toEqual(value.toString("base64"));
|
|
459
|
+
});
|
|
460
|
+
test("Should work with Uint8Array", async () => {
|
|
461
|
+
const value = new Uint8Array(Buffer.from("asd"));
|
|
462
|
+
await storage.addMany({ a: value });
|
|
463
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
464
|
+
expect(getResult).toBeInstanceOf(Uint8Array);
|
|
465
|
+
expect(getResult
|
|
466
|
+
? Buffer.from(getResult).toString("base64")
|
|
467
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
468
|
+
});
|
|
469
|
+
test("Should work with Int8Array", async () => {
|
|
470
|
+
const value = new Int8Array(Buffer.from("asd"));
|
|
471
|
+
await storage.addMany({ a: value });
|
|
472
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
473
|
+
expect(getResult).toBeInstanceOf(Int8Array);
|
|
474
|
+
expect(getResult
|
|
475
|
+
? Buffer.from(getResult).toString("base64")
|
|
476
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
477
|
+
});
|
|
478
|
+
test("Should work with Uint16Array", async () => {
|
|
479
|
+
const value = new Uint16Array(Buffer.from("asd"));
|
|
480
|
+
await storage.addMany({ a: value });
|
|
481
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
482
|
+
expect(getResult).toBeInstanceOf(Uint16Array);
|
|
483
|
+
expect(getResult
|
|
484
|
+
? Buffer.from(getResult).toString("base64")
|
|
485
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
486
|
+
});
|
|
487
|
+
test("Should work with Int16Array", async () => {
|
|
488
|
+
const value = new Int16Array(Buffer.from("asd"));
|
|
489
|
+
await storage.addMany({ a: value });
|
|
490
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
491
|
+
expect(getResult).toBeInstanceOf(Int16Array);
|
|
492
|
+
expect(getResult
|
|
493
|
+
? Buffer.from(getResult).toString("base64")
|
|
494
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
495
|
+
});
|
|
496
|
+
test("Should work with Uint32Array", async () => {
|
|
497
|
+
const value = new Uint32Array(Buffer.from("asd"));
|
|
498
|
+
await storage.addMany({ a: value });
|
|
499
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
500
|
+
expect(getResult).toBeInstanceOf(Uint32Array);
|
|
501
|
+
expect(getResult
|
|
502
|
+
? Buffer.from(getResult).toString("base64")
|
|
503
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
504
|
+
});
|
|
505
|
+
test("Should work with Int32Array", async () => {
|
|
506
|
+
const value = new Int32Array(Buffer.from("asd"));
|
|
507
|
+
await storage.addMany({ a: value });
|
|
508
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
509
|
+
expect(getResult).toBeInstanceOf(Int32Array);
|
|
510
|
+
expect(getResult
|
|
511
|
+
? Buffer.from(getResult).toString("base64")
|
|
512
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
513
|
+
});
|
|
514
|
+
test("Should work with Float32Array", async () => {
|
|
515
|
+
const value = new Float32Array(Buffer.from("asd"));
|
|
516
|
+
await storage.addMany({ a: value });
|
|
517
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
518
|
+
expect(getResult).toBeInstanceOf(Float32Array);
|
|
519
|
+
expect(getResult
|
|
520
|
+
? Buffer.from(getResult).toString("base64")
|
|
521
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
522
|
+
});
|
|
523
|
+
test("Should work with Float64Array", async () => {
|
|
524
|
+
const value = new Float64Array(Buffer.from("asd"));
|
|
525
|
+
await storage.addMany({ a: value });
|
|
526
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
527
|
+
expect(getResult).toBeInstanceOf(Float64Array);
|
|
528
|
+
expect(getResult
|
|
529
|
+
? Buffer.from(getResult).toString("base64")
|
|
530
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
531
|
+
});
|
|
532
|
+
test("Should work with Set", async () => {
|
|
533
|
+
const value = new Set(["a", "b", "c"]);
|
|
534
|
+
await storage.addMany({ a: value });
|
|
535
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
536
|
+
expect(getResult).toBeInstanceOf(Set);
|
|
537
|
+
expect(getResult).toEqual(value);
|
|
538
|
+
});
|
|
539
|
+
test("Should work with Set of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays", async () => {
|
|
540
|
+
const value = new Set([
|
|
541
|
+
0,
|
|
542
|
+
-1,
|
|
543
|
+
1,
|
|
544
|
+
-1.5,
|
|
545
|
+
1.5,
|
|
546
|
+
NaN,
|
|
547
|
+
Infinity,
|
|
548
|
+
2n,
|
|
549
|
+
true,
|
|
550
|
+
false,
|
|
551
|
+
"str",
|
|
552
|
+
new Date("2024-01-01"),
|
|
553
|
+
new Set(["a", "b", "c"]),
|
|
554
|
+
new Map([
|
|
555
|
+
["a", 1],
|
|
556
|
+
["b", 2],
|
|
557
|
+
["c", 3],
|
|
558
|
+
]),
|
|
559
|
+
{ a: 1, b: 2 },
|
|
560
|
+
[1, 2, 3],
|
|
561
|
+
/test/,
|
|
562
|
+
]);
|
|
563
|
+
await storage.addMany({ a: value });
|
|
564
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
565
|
+
expect(getResult).toBeInstanceOf(Set);
|
|
566
|
+
expect(getResult).toEqual(value);
|
|
567
|
+
});
|
|
568
|
+
test("Should work with Map", async () => {
|
|
569
|
+
const value = new Map([
|
|
570
|
+
["a", 1],
|
|
571
|
+
["b", 2],
|
|
572
|
+
["c", 3],
|
|
573
|
+
]);
|
|
574
|
+
await storage.addMany({ a: value });
|
|
575
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
576
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
577
|
+
expect(getResult).toEqual(value);
|
|
578
|
+
});
|
|
579
|
+
test("Should work with Map of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays values", async () => {
|
|
580
|
+
const value = new Map([
|
|
581
|
+
["a", 0],
|
|
582
|
+
["b", -1],
|
|
583
|
+
["c", 1],
|
|
584
|
+
["d", -1.5],
|
|
585
|
+
["e", 1.5],
|
|
586
|
+
["f", NaN],
|
|
587
|
+
["g", Infinity],
|
|
588
|
+
["h", 2n],
|
|
589
|
+
["j", true],
|
|
590
|
+
["l", false],
|
|
591
|
+
["i", "str"],
|
|
592
|
+
["r", new Date("2024-01-01")],
|
|
593
|
+
["k", new Set(["a", "b", "c"])],
|
|
594
|
+
[
|
|
595
|
+
"p",
|
|
596
|
+
new Map([
|
|
597
|
+
["a", 1],
|
|
598
|
+
["b", 2],
|
|
599
|
+
["c", 3],
|
|
600
|
+
]),
|
|
601
|
+
],
|
|
602
|
+
["a", /test/],
|
|
603
|
+
[1, { a: 2, b: -1 }],
|
|
604
|
+
[2, [1, 2, 3]],
|
|
605
|
+
]);
|
|
606
|
+
await storage.addMany({ a: value });
|
|
607
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
608
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
609
|
+
expect(getResult).toEqual(value);
|
|
610
|
+
});
|
|
611
|
+
test("Should work with Map of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays keys", async () => {
|
|
612
|
+
const value = new Map([
|
|
613
|
+
[0, "a"],
|
|
614
|
+
[-1, "a"],
|
|
615
|
+
[1, "a"],
|
|
616
|
+
[-1.5, "a"],
|
|
617
|
+
[1.5, "a"],
|
|
618
|
+
[NaN, "a"],
|
|
619
|
+
[Infinity, "a"],
|
|
620
|
+
[2n, "a"],
|
|
621
|
+
[true, "a"],
|
|
622
|
+
[false, "a"],
|
|
623
|
+
["str", "a"],
|
|
624
|
+
[new Date("2024-01-01"), "a"],
|
|
625
|
+
[new Set(["a", "b", "c"]), "a"],
|
|
626
|
+
[
|
|
627
|
+
new Map([
|
|
628
|
+
["a", 1],
|
|
629
|
+
["b", 2],
|
|
630
|
+
["c", 3],
|
|
631
|
+
]),
|
|
632
|
+
"a",
|
|
633
|
+
],
|
|
634
|
+
[/test/, "a"],
|
|
635
|
+
[{ a: 2, b: -1 }, 1],
|
|
636
|
+
[[1, 2, 3], 2],
|
|
637
|
+
]);
|
|
638
|
+
await storage.addMany({ a: value });
|
|
639
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
640
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
641
|
+
expect(getResult).toEqual(value);
|
|
642
|
+
});
|
|
643
|
+
test("Should work with array of number, boolean, string, Date, Set, Map, RegExp", async () => {
|
|
644
|
+
const value = [
|
|
645
|
+
0,
|
|
646
|
+
-1,
|
|
647
|
+
1,
|
|
648
|
+
-1.5,
|
|
649
|
+
1.5,
|
|
650
|
+
NaN,
|
|
651
|
+
Infinity,
|
|
652
|
+
2n,
|
|
653
|
+
true,
|
|
654
|
+
false,
|
|
655
|
+
"str",
|
|
656
|
+
new Date("2024-01-01"),
|
|
657
|
+
new Set(["a", "b", "c"]),
|
|
658
|
+
new Map([
|
|
659
|
+
["a", 1],
|
|
660
|
+
["b", 2],
|
|
661
|
+
["c", 3],
|
|
662
|
+
]),
|
|
663
|
+
/test/,
|
|
664
|
+
];
|
|
665
|
+
await storage.addMany({ a: value });
|
|
666
|
+
const getResult = await storage.getMany(["a"]);
|
|
667
|
+
expect(getResult).toEqual({ a: value });
|
|
668
|
+
});
|
|
669
|
+
test("Should work with array of objects", async () => {
|
|
670
|
+
const value = [
|
|
671
|
+
Object.fromEntries([
|
|
672
|
+
["a", 0],
|
|
673
|
+
["b", -1],
|
|
674
|
+
["c", 1],
|
|
675
|
+
["d", -1.5],
|
|
676
|
+
["e", 1.5],
|
|
677
|
+
["f", NaN],
|
|
678
|
+
["g", Infinity],
|
|
679
|
+
["h", 2n],
|
|
680
|
+
["j", true],
|
|
681
|
+
["l", false],
|
|
682
|
+
["i", "str"],
|
|
683
|
+
["r", new Date("2024-01-01")],
|
|
684
|
+
["k", new Set(["a", "b", "c"])],
|
|
685
|
+
[
|
|
686
|
+
"p",
|
|
687
|
+
new Map([
|
|
688
|
+
["a", 1],
|
|
689
|
+
["b", 2],
|
|
690
|
+
["c", 3],
|
|
691
|
+
]),
|
|
692
|
+
],
|
|
693
|
+
["a", /test/],
|
|
694
|
+
]),
|
|
695
|
+
];
|
|
696
|
+
await storage.addMany({ a: value });
|
|
697
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
698
|
+
expect(getResult).toEqual(value);
|
|
699
|
+
});
|
|
700
|
+
test("Should work with object of number, boolean, string, Date, Set, Map, RegExp", async () => {
|
|
701
|
+
const value = Object.fromEntries([
|
|
702
|
+
["a", 0],
|
|
703
|
+
["b", -1],
|
|
704
|
+
["c", 1],
|
|
705
|
+
["d", -1.5],
|
|
706
|
+
["e", 1.5],
|
|
707
|
+
["f", NaN],
|
|
708
|
+
["g", Infinity],
|
|
709
|
+
["h", 2n],
|
|
710
|
+
["j", true],
|
|
711
|
+
["l", false],
|
|
712
|
+
["i", "str"],
|
|
713
|
+
["r", new Date("2024-01-01")],
|
|
714
|
+
["k", new Set(["a", "b", "c"])],
|
|
715
|
+
[
|
|
716
|
+
"p",
|
|
717
|
+
new Map([
|
|
718
|
+
["a", 1],
|
|
719
|
+
["b", 2],
|
|
720
|
+
["c", 3],
|
|
721
|
+
]),
|
|
722
|
+
],
|
|
723
|
+
["a", /test/],
|
|
724
|
+
]);
|
|
725
|
+
await storage.addMany({ a: value });
|
|
726
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
727
|
+
expect(getResult).toEqual(value);
|
|
728
|
+
});
|
|
729
|
+
test("Should work with object of arrays", async () => {
|
|
730
|
+
const value = {
|
|
731
|
+
a: [
|
|
732
|
+
0,
|
|
733
|
+
-1,
|
|
734
|
+
1,
|
|
735
|
+
-1.5,
|
|
736
|
+
1.5,
|
|
737
|
+
NaN,
|
|
738
|
+
Infinity,
|
|
739
|
+
2n,
|
|
740
|
+
true,
|
|
741
|
+
false,
|
|
742
|
+
"str",
|
|
743
|
+
new Date("2024-01-01"),
|
|
744
|
+
new Set(["a", "b", "c"]),
|
|
745
|
+
new Map([
|
|
746
|
+
["a", 1],
|
|
747
|
+
["b", 2],
|
|
748
|
+
["c", 3],
|
|
749
|
+
]),
|
|
750
|
+
/test/,
|
|
751
|
+
],
|
|
752
|
+
};
|
|
753
|
+
await storage.addMany({ a: value });
|
|
754
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
755
|
+
expect(getResult).toEqual(value);
|
|
756
|
+
});
|
|
757
|
+
});
|
|
758
|
+
describe("method: getOr", () => {
|
|
759
|
+
test("Should work with positive integer", async () => {
|
|
760
|
+
const value = 1;
|
|
761
|
+
await storage.add("a", value);
|
|
762
|
+
expect(await storage.getOr("a", -1)).toBe(value);
|
|
763
|
+
});
|
|
764
|
+
test("Should work with negative integer", async () => {
|
|
765
|
+
const value = -1;
|
|
766
|
+
await storage.add("a", value);
|
|
767
|
+
expect(await storage.getOr("a", -1)).toBe(value);
|
|
768
|
+
});
|
|
769
|
+
test("Should work with positive decimal", async () => {
|
|
770
|
+
const value = 1.5;
|
|
771
|
+
await storage.add("a", value);
|
|
772
|
+
expect(await storage.getOr("a", -1)).toBe(value);
|
|
773
|
+
});
|
|
774
|
+
test("Should work with negative decimal", async () => {
|
|
775
|
+
const value = -1.5;
|
|
776
|
+
await storage.add("a", value);
|
|
777
|
+
expect(await storage.getOr("a", -1)).toBe(value);
|
|
778
|
+
});
|
|
779
|
+
test("Should work with NaN", async () => {
|
|
780
|
+
const value = NaN;
|
|
781
|
+
await storage.add("a", value);
|
|
782
|
+
const getResult = await storage.getOr("a", -1);
|
|
783
|
+
expect(getResult).toBeNaN();
|
|
784
|
+
});
|
|
785
|
+
test("Should work with Infinity", async () => {
|
|
786
|
+
const value = Infinity;
|
|
787
|
+
await storage.add("a", value);
|
|
788
|
+
const getResult = await storage.getOr("a", -1);
|
|
789
|
+
expect(isFinite(getResult)).toBe(false);
|
|
790
|
+
});
|
|
791
|
+
test("Should work with Bigint", async () => {
|
|
792
|
+
const value = 20n;
|
|
793
|
+
await storage.add("a", value);
|
|
794
|
+
expect(await storage.getOr("a", -1)).toBe(value);
|
|
795
|
+
});
|
|
796
|
+
test("Should work with true", async () => {
|
|
797
|
+
const value = true;
|
|
798
|
+
await storage.add("a", value);
|
|
799
|
+
expect(await storage.getOr("a", -1)).toBe(value);
|
|
800
|
+
});
|
|
801
|
+
test("Should work with false", async () => {
|
|
802
|
+
const value = false;
|
|
803
|
+
await storage.add("a", value);
|
|
804
|
+
expect(await storage.getOr("a", -1)).toBe(value);
|
|
805
|
+
});
|
|
806
|
+
test("Should work with string", async () => {
|
|
807
|
+
const value = "str";
|
|
808
|
+
await storage.add("a", value);
|
|
809
|
+
expect(await storage.getOr("a", -1)).toBe(value);
|
|
810
|
+
});
|
|
811
|
+
test("Should work with Date", async () => {
|
|
812
|
+
const value = new Date("2024-01-01");
|
|
813
|
+
await storage.add("a", value);
|
|
814
|
+
const getResult = await storage.getOr("a", -1);
|
|
815
|
+
expect(getResult).toBeInstanceOf(Date);
|
|
816
|
+
expect(getResult).toEqual(value);
|
|
817
|
+
});
|
|
818
|
+
test("Should work with RegExp", async () => {
|
|
819
|
+
const value = /test/;
|
|
820
|
+
await storage.add("a", value);
|
|
821
|
+
const getResult = await storage.getOr("a", -1);
|
|
822
|
+
expect(getResult).toBeInstanceOf(RegExp);
|
|
823
|
+
expect(getResult).toEqual(value);
|
|
824
|
+
});
|
|
825
|
+
test("Should work with Buffer", async () => {
|
|
826
|
+
const value = Buffer.from("asd");
|
|
827
|
+
await storage.add("a", value);
|
|
828
|
+
const getResult = await storage.getOr("a", null);
|
|
829
|
+
expect(getResult).toBeInstanceOf(Buffer);
|
|
830
|
+
expect(getResult?.toString("base64")).toEqual(value.toString("base64"));
|
|
831
|
+
});
|
|
832
|
+
test("Should work with Uint8Array", async () => {
|
|
833
|
+
const value = new Uint8Array(Buffer.from("asd"));
|
|
834
|
+
await storage.add("a", value);
|
|
835
|
+
const getResult = await storage.getOr("a", null);
|
|
836
|
+
expect(getResult).toBeInstanceOf(Uint8Array);
|
|
837
|
+
expect(getResult
|
|
838
|
+
? Buffer.from(getResult).toString("base64")
|
|
839
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
840
|
+
});
|
|
841
|
+
test("Should work with Int8Array", async () => {
|
|
842
|
+
const value = new Int8Array(Buffer.from("asd"));
|
|
843
|
+
await storage.add("a", value);
|
|
844
|
+
const getResult = await storage.getOr("a", null);
|
|
845
|
+
expect(getResult).toBeInstanceOf(Int8Array);
|
|
846
|
+
expect(getResult
|
|
847
|
+
? Buffer.from(getResult).toString("base64")
|
|
848
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
849
|
+
});
|
|
850
|
+
test("Should work with Uint16Array", async () => {
|
|
851
|
+
const value = new Uint16Array(Buffer.from("asd"));
|
|
852
|
+
await storage.add("a", value);
|
|
853
|
+
const getResult = await storage.getOr("a", null);
|
|
854
|
+
expect(getResult).toBeInstanceOf(Uint16Array);
|
|
855
|
+
expect(getResult
|
|
856
|
+
? Buffer.from(getResult).toString("base64")
|
|
857
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
858
|
+
});
|
|
859
|
+
test("Should work with Int16Array", async () => {
|
|
860
|
+
const value = new Int16Array(Buffer.from("asd"));
|
|
861
|
+
await storage.add("a", value);
|
|
862
|
+
const getResult = await storage.getOr("a", null);
|
|
863
|
+
expect(getResult).toBeInstanceOf(Int16Array);
|
|
864
|
+
expect(getResult
|
|
865
|
+
? Buffer.from(getResult).toString("base64")
|
|
866
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
867
|
+
});
|
|
868
|
+
test("Should work with Uint32Array", async () => {
|
|
869
|
+
const value = new Uint32Array(Buffer.from("asd"));
|
|
870
|
+
await storage.add("a", value);
|
|
871
|
+
const getResult = await storage.getOr("a", null);
|
|
872
|
+
expect(getResult).toBeInstanceOf(Uint32Array);
|
|
873
|
+
expect(getResult
|
|
874
|
+
? Buffer.from(getResult).toString("base64")
|
|
875
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
876
|
+
});
|
|
877
|
+
test("Should work with Int32Array", async () => {
|
|
878
|
+
const value = new Int32Array(Buffer.from("asd"));
|
|
879
|
+
await storage.add("a", value);
|
|
880
|
+
const getResult = await storage.getOr("a", null);
|
|
881
|
+
expect(getResult).toBeInstanceOf(Int32Array);
|
|
882
|
+
expect(getResult
|
|
883
|
+
? Buffer.from(getResult).toString("base64")
|
|
884
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
885
|
+
});
|
|
886
|
+
test("Should work with Float32Array", async () => {
|
|
887
|
+
const value = new Float32Array(Buffer.from("asd"));
|
|
888
|
+
await storage.add("a", value);
|
|
889
|
+
const getResult = await storage.getOr("a", null);
|
|
890
|
+
expect(getResult).toBeInstanceOf(Float32Array);
|
|
891
|
+
expect(getResult
|
|
892
|
+
? Buffer.from(getResult).toString("base64")
|
|
893
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
894
|
+
});
|
|
895
|
+
test("Should work with Float64Array", async () => {
|
|
896
|
+
const value = new Float64Array(Buffer.from("asd"));
|
|
897
|
+
await storage.add("a", value);
|
|
898
|
+
const getResult = await storage.getOr("a", null);
|
|
899
|
+
expect(getResult).toBeInstanceOf(Float64Array);
|
|
900
|
+
expect(getResult
|
|
901
|
+
? Buffer.from(getResult).toString("base64")
|
|
902
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
903
|
+
});
|
|
904
|
+
test("Should work with Set", async () => {
|
|
905
|
+
const value = new Set(["a", "b", "c"]);
|
|
906
|
+
await storage.add("a", value);
|
|
907
|
+
const getResult = await storage.getOr("a", -1);
|
|
908
|
+
expect(getResult).toBeInstanceOf(Set);
|
|
909
|
+
expect(getResult).toEqual(value);
|
|
910
|
+
});
|
|
911
|
+
test("Should work with Set of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays", async () => {
|
|
912
|
+
const value = new Set([
|
|
913
|
+
0,
|
|
914
|
+
-1,
|
|
915
|
+
1,
|
|
916
|
+
-1.5,
|
|
917
|
+
1.5,
|
|
918
|
+
NaN,
|
|
919
|
+
Infinity,
|
|
920
|
+
2n,
|
|
921
|
+
true,
|
|
922
|
+
false,
|
|
923
|
+
"str",
|
|
924
|
+
new Date("2024-01-01"),
|
|
925
|
+
new Set(["a", "b", "c"]),
|
|
926
|
+
new Map([
|
|
927
|
+
["a", 1],
|
|
928
|
+
["b", 2],
|
|
929
|
+
["c", 3],
|
|
930
|
+
]),
|
|
931
|
+
{ a: 1, b: 2 },
|
|
932
|
+
[1, 2, 3],
|
|
933
|
+
/test/,
|
|
934
|
+
]);
|
|
935
|
+
await storage.add("a", value);
|
|
936
|
+
const getResult = await storage.getOr("a", -1);
|
|
937
|
+
expect(getResult).toBeInstanceOf(Set);
|
|
938
|
+
expect(getResult).toEqual(value);
|
|
939
|
+
});
|
|
940
|
+
test("Should work with Map", async () => {
|
|
941
|
+
const value = new Map([
|
|
942
|
+
["a", 1],
|
|
943
|
+
["b", 2],
|
|
944
|
+
["c", 3],
|
|
945
|
+
]);
|
|
946
|
+
await storage.add("a", value);
|
|
947
|
+
const getResult = await storage.getOr("a", -1);
|
|
948
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
949
|
+
expect(getResult).toEqual(value);
|
|
950
|
+
});
|
|
951
|
+
test("Should work with Map of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays values", async () => {
|
|
952
|
+
const value = new Map([
|
|
953
|
+
["a", 0],
|
|
954
|
+
["b", -1],
|
|
955
|
+
["c", 1],
|
|
956
|
+
["d", -1.5],
|
|
957
|
+
["e", 1.5],
|
|
958
|
+
["f", NaN],
|
|
959
|
+
["g", Infinity],
|
|
960
|
+
["h", 2n],
|
|
961
|
+
["j", true],
|
|
962
|
+
["l", false],
|
|
963
|
+
["i", "str"],
|
|
964
|
+
["r", new Date("2024-01-01")],
|
|
965
|
+
["k", new Set(["a", "b", "c"])],
|
|
966
|
+
[
|
|
967
|
+
"p",
|
|
968
|
+
new Map([
|
|
969
|
+
["a", 1],
|
|
970
|
+
["b", 2],
|
|
971
|
+
["c", 3],
|
|
972
|
+
]),
|
|
973
|
+
],
|
|
974
|
+
["a", /test/],
|
|
975
|
+
[1, { a: 2, b: -1 }],
|
|
976
|
+
[2, [1, 2, 3]],
|
|
977
|
+
]);
|
|
978
|
+
await storage.add("a", value);
|
|
979
|
+
const getResult = await storage.getOr("a", -1);
|
|
980
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
981
|
+
expect(getResult).toEqual(value);
|
|
982
|
+
});
|
|
983
|
+
test("Should work with Map of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays keys", async () => {
|
|
984
|
+
const value = new Map([
|
|
985
|
+
[0, "a"],
|
|
986
|
+
[-1, "a"],
|
|
987
|
+
[1, "a"],
|
|
988
|
+
[-1.5, "a"],
|
|
989
|
+
[1.5, "a"],
|
|
990
|
+
[NaN, "a"],
|
|
991
|
+
[Infinity, "a"],
|
|
992
|
+
[2n, "a"],
|
|
993
|
+
[true, "a"],
|
|
994
|
+
[false, "a"],
|
|
995
|
+
["str", "a"],
|
|
996
|
+
[new Date("2024-01-01"), "a"],
|
|
997
|
+
[new Set(["a", "b", "c"]), "a"],
|
|
998
|
+
[
|
|
999
|
+
new Map([
|
|
1000
|
+
["a", 1],
|
|
1001
|
+
["b", 2],
|
|
1002
|
+
["c", 3],
|
|
1003
|
+
]),
|
|
1004
|
+
"a",
|
|
1005
|
+
],
|
|
1006
|
+
[/test/, "a"],
|
|
1007
|
+
[{ a: 2, b: -1 }, 1],
|
|
1008
|
+
[[1, 2, 3], 2],
|
|
1009
|
+
]);
|
|
1010
|
+
await storage.add("a", value);
|
|
1011
|
+
const getResult = await storage.getOr("a", -1);
|
|
1012
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
1013
|
+
expect(getResult).toEqual(value);
|
|
1014
|
+
});
|
|
1015
|
+
test("Should work with array of number, boolean, string, Date, Set, Map, RegExp", async () => {
|
|
1016
|
+
const value = [
|
|
1017
|
+
0,
|
|
1018
|
+
-1,
|
|
1019
|
+
1,
|
|
1020
|
+
-1.5,
|
|
1021
|
+
1.5,
|
|
1022
|
+
NaN,
|
|
1023
|
+
Infinity,
|
|
1024
|
+
2n,
|
|
1025
|
+
true,
|
|
1026
|
+
false,
|
|
1027
|
+
"str",
|
|
1028
|
+
new Date("2024-01-01"),
|
|
1029
|
+
new Set(["a", "b", "c"]),
|
|
1030
|
+
new Map([
|
|
1031
|
+
["a", 1],
|
|
1032
|
+
["b", 2],
|
|
1033
|
+
["c", 3],
|
|
1034
|
+
]),
|
|
1035
|
+
/test/,
|
|
1036
|
+
];
|
|
1037
|
+
await storage.add("a", value);
|
|
1038
|
+
const getResult = await storage.getOr("a", -1);
|
|
1039
|
+
expect(getResult).toEqual(value);
|
|
1040
|
+
});
|
|
1041
|
+
test("Should work with array of objects", async () => {
|
|
1042
|
+
const value = [
|
|
1043
|
+
Object.fromEntries([
|
|
1044
|
+
["a", 0],
|
|
1045
|
+
["b", -1],
|
|
1046
|
+
["c", 1],
|
|
1047
|
+
["d", -1.5],
|
|
1048
|
+
["e", 1.5],
|
|
1049
|
+
["f", NaN],
|
|
1050
|
+
["g", Infinity],
|
|
1051
|
+
["h", 2n],
|
|
1052
|
+
["j", true],
|
|
1053
|
+
["l", false],
|
|
1054
|
+
["i", "str"],
|
|
1055
|
+
["r", new Date("2024-01-01")],
|
|
1056
|
+
["k", new Set(["a", "b", "c"])],
|
|
1057
|
+
[
|
|
1058
|
+
"p",
|
|
1059
|
+
new Map([
|
|
1060
|
+
["a", 1],
|
|
1061
|
+
["b", 2],
|
|
1062
|
+
["c", 3],
|
|
1063
|
+
]),
|
|
1064
|
+
],
|
|
1065
|
+
["a", /test/],
|
|
1066
|
+
]),
|
|
1067
|
+
];
|
|
1068
|
+
await storage.add("a", value);
|
|
1069
|
+
const getResult = await storage.getOr("a", -1);
|
|
1070
|
+
expect(getResult).toEqual(value);
|
|
1071
|
+
});
|
|
1072
|
+
test("Should work with object of number, boolean, string, Date, Set, Map, RegExp", async () => {
|
|
1073
|
+
const value = Object.fromEntries([
|
|
1074
|
+
["a", 0],
|
|
1075
|
+
["b", -1],
|
|
1076
|
+
["c", 1],
|
|
1077
|
+
["d", -1.5],
|
|
1078
|
+
["e", 1.5],
|
|
1079
|
+
["f", NaN],
|
|
1080
|
+
["g", Infinity],
|
|
1081
|
+
["h", 2n],
|
|
1082
|
+
["j", true],
|
|
1083
|
+
["l", false],
|
|
1084
|
+
["i", "str"],
|
|
1085
|
+
["r", new Date("2024-01-01")],
|
|
1086
|
+
["k", new Set(["a", "b", "c"])],
|
|
1087
|
+
[
|
|
1088
|
+
"p",
|
|
1089
|
+
new Map([
|
|
1090
|
+
["a", 1],
|
|
1091
|
+
["b", 2],
|
|
1092
|
+
["c", 3],
|
|
1093
|
+
]),
|
|
1094
|
+
],
|
|
1095
|
+
["a", /test/],
|
|
1096
|
+
]);
|
|
1097
|
+
await storage.add("a", value);
|
|
1098
|
+
const getResult = await storage.getOr("a", -1);
|
|
1099
|
+
expect(getResult).toEqual(value);
|
|
1100
|
+
});
|
|
1101
|
+
test("Should work with object of arrays", async () => {
|
|
1102
|
+
const value = {
|
|
1103
|
+
a: [
|
|
1104
|
+
0,
|
|
1105
|
+
-1,
|
|
1106
|
+
1,
|
|
1107
|
+
-1.5,
|
|
1108
|
+
1.5,
|
|
1109
|
+
NaN,
|
|
1110
|
+
Infinity,
|
|
1111
|
+
2n,
|
|
1112
|
+
true,
|
|
1113
|
+
false,
|
|
1114
|
+
"str",
|
|
1115
|
+
new Date("2024-01-01"),
|
|
1116
|
+
new Set(["a", "b", "c"]),
|
|
1117
|
+
new Map([
|
|
1118
|
+
["a", 1],
|
|
1119
|
+
["b", 2],
|
|
1120
|
+
["c", 3],
|
|
1121
|
+
]),
|
|
1122
|
+
/test/,
|
|
1123
|
+
],
|
|
1124
|
+
};
|
|
1125
|
+
await storage.add("a", value);
|
|
1126
|
+
const getResult = await storage.getOr("a", -1);
|
|
1127
|
+
expect(getResult).toEqual(value);
|
|
1128
|
+
});
|
|
1129
|
+
});
|
|
1130
|
+
describe("method: getOrMany", () => {
|
|
1131
|
+
test("Should work with positive integer", async () => {
|
|
1132
|
+
const value = 1;
|
|
1133
|
+
await storage.addMany({ a: value });
|
|
1134
|
+
expect(await storage.getOrMany({ a: -1 })).toEqual({
|
|
1135
|
+
a: value,
|
|
1136
|
+
});
|
|
1137
|
+
});
|
|
1138
|
+
test("Should work with negative integer", async () => {
|
|
1139
|
+
const value = -1;
|
|
1140
|
+
await storage.addMany({ a: value });
|
|
1141
|
+
expect(await storage.getOrMany({ a: -1 })).toEqual({
|
|
1142
|
+
a: value,
|
|
1143
|
+
});
|
|
1144
|
+
});
|
|
1145
|
+
test("Should work with positive decimal", async () => {
|
|
1146
|
+
const value = 1.5;
|
|
1147
|
+
await storage.addMany({ a: value });
|
|
1148
|
+
expect(await storage.getOrMany({ a: -1 })).toEqual({
|
|
1149
|
+
a: value,
|
|
1150
|
+
});
|
|
1151
|
+
});
|
|
1152
|
+
test("Should work with negative decimal", async () => {
|
|
1153
|
+
const value = -1.5;
|
|
1154
|
+
await storage.addMany({ a: value });
|
|
1155
|
+
expect(await storage.getOrMany({ a: -1 })).toEqual({
|
|
1156
|
+
a: value,
|
|
1157
|
+
});
|
|
1158
|
+
});
|
|
1159
|
+
test("Should work with NaN", async () => {
|
|
1160
|
+
const value = NaN;
|
|
1161
|
+
await storage.addMany({ a: value });
|
|
1162
|
+
const { a: getResult } = await storage.getOrMany({ a: -1 });
|
|
1163
|
+
expect(getResult).toBeNaN();
|
|
1164
|
+
});
|
|
1165
|
+
test("Should work with Infinity", async () => {
|
|
1166
|
+
const value = Infinity;
|
|
1167
|
+
await storage.addMany({ a: value });
|
|
1168
|
+
const { a: getResult } = await storage.getOrMany({ a: -1 });
|
|
1169
|
+
expect(isFinite(getResult)).toBe(false);
|
|
1170
|
+
});
|
|
1171
|
+
test("Should work with Bigint", async () => {
|
|
1172
|
+
const value = 20n;
|
|
1173
|
+
await storage.addMany({ a: value });
|
|
1174
|
+
expect(await storage.getOrMany({ a: -1 })).toEqual({
|
|
1175
|
+
a: value,
|
|
1176
|
+
});
|
|
1177
|
+
});
|
|
1178
|
+
test("Should work with true", async () => {
|
|
1179
|
+
const value = true;
|
|
1180
|
+
await storage.addMany({ a: value });
|
|
1181
|
+
expect(await storage.getOrMany({ a: -1 })).toEqual({
|
|
1182
|
+
a: value,
|
|
1183
|
+
});
|
|
1184
|
+
});
|
|
1185
|
+
test("Should work with false", async () => {
|
|
1186
|
+
const value = false;
|
|
1187
|
+
await storage.addMany({ a: value });
|
|
1188
|
+
expect(await storage.getOrMany({ a: -1 })).toEqual({
|
|
1189
|
+
a: value,
|
|
1190
|
+
});
|
|
1191
|
+
});
|
|
1192
|
+
test("Should work with string", async () => {
|
|
1193
|
+
const value = "str";
|
|
1194
|
+
await storage.addMany({ a: value });
|
|
1195
|
+
expect(await storage.getOrMany({ a: -1 })).toEqual({
|
|
1196
|
+
a: value,
|
|
1197
|
+
});
|
|
1198
|
+
});
|
|
1199
|
+
test("Should work with Date", async () => {
|
|
1200
|
+
const value = new Date("2024-01-01");
|
|
1201
|
+
await storage.addMany({ a: value });
|
|
1202
|
+
const { a: getResult } = await storage.getOrMany({ a: -1 });
|
|
1203
|
+
expect(getResult).toBeInstanceOf(Date);
|
|
1204
|
+
expect(getResult).toEqual(value);
|
|
1205
|
+
});
|
|
1206
|
+
test("Should work with RegExp", async () => {
|
|
1207
|
+
const value = /test/;
|
|
1208
|
+
await storage.addMany({ a: value });
|
|
1209
|
+
const { a: getResult } = await storage.getOrMany({ a: -1 });
|
|
1210
|
+
expect(getResult).toBeInstanceOf(RegExp);
|
|
1211
|
+
expect(getResult).toEqual(value);
|
|
1212
|
+
});
|
|
1213
|
+
test("Should work with Buffer", async () => {
|
|
1214
|
+
const value = Buffer.from("asd");
|
|
1215
|
+
await storage.addMany({ a: value });
|
|
1216
|
+
const { a: getResult } = await storage.getOrMany({ a: null });
|
|
1217
|
+
expect(getResult).toBeInstanceOf(Buffer);
|
|
1218
|
+
expect(getResult?.toString("base64")).toEqual(value.toString("base64"));
|
|
1219
|
+
});
|
|
1220
|
+
test("Should work with Uint8Array", async () => {
|
|
1221
|
+
const value = new Uint8Array(Buffer.from("asd"));
|
|
1222
|
+
await storage.addMany({ a: value });
|
|
1223
|
+
const { a: getResult } = await storage.getOrMany({ a: null });
|
|
1224
|
+
expect(getResult).toBeInstanceOf(Uint8Array);
|
|
1225
|
+
expect(getResult
|
|
1226
|
+
? Buffer.from(getResult).toString("base64")
|
|
1227
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
1228
|
+
});
|
|
1229
|
+
test("Should work with Int8Array", async () => {
|
|
1230
|
+
const value = new Int8Array(Buffer.from("asd"));
|
|
1231
|
+
await storage.addMany({ a: value });
|
|
1232
|
+
const { a: getResult } = await storage.getOrMany({ a: null });
|
|
1233
|
+
expect(getResult).toBeInstanceOf(Int8Array);
|
|
1234
|
+
expect(getResult
|
|
1235
|
+
? Buffer.from(getResult).toString("base64")
|
|
1236
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
1237
|
+
});
|
|
1238
|
+
test("Should work with Uint16Array", async () => {
|
|
1239
|
+
const value = new Uint16Array(Buffer.from("asd"));
|
|
1240
|
+
await storage.addMany({ a: value });
|
|
1241
|
+
const { a: getResult } = await storage.getOrMany({ a: null });
|
|
1242
|
+
expect(getResult).toBeInstanceOf(Uint16Array);
|
|
1243
|
+
expect(getResult
|
|
1244
|
+
? Buffer.from(getResult).toString("base64")
|
|
1245
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
1246
|
+
});
|
|
1247
|
+
test("Should work with Int16Array", async () => {
|
|
1248
|
+
const value = new Int16Array(Buffer.from("asd"));
|
|
1249
|
+
await storage.addMany({ a: value });
|
|
1250
|
+
const { a: getResult } = await storage.getOrMany({ a: null });
|
|
1251
|
+
expect(getResult).toBeInstanceOf(Int16Array);
|
|
1252
|
+
expect(getResult
|
|
1253
|
+
? Buffer.from(getResult).toString("base64")
|
|
1254
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
1255
|
+
});
|
|
1256
|
+
test("Should work with Uint32Array", async () => {
|
|
1257
|
+
const value = new Uint32Array(Buffer.from("asd"));
|
|
1258
|
+
await storage.addMany({ a: value });
|
|
1259
|
+
const { a: getResult } = await storage.getOrMany({ a: null });
|
|
1260
|
+
expect(getResult).toBeInstanceOf(Uint32Array);
|
|
1261
|
+
expect(getResult
|
|
1262
|
+
? Buffer.from(getResult).toString("base64")
|
|
1263
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
1264
|
+
});
|
|
1265
|
+
test("Should work with Int32Array", async () => {
|
|
1266
|
+
const value = new Int32Array(Buffer.from("asd"));
|
|
1267
|
+
await storage.addMany({ a: value });
|
|
1268
|
+
const { a: getResult } = await storage.getOrMany({ a: null });
|
|
1269
|
+
expect(getResult).toBeInstanceOf(Int32Array);
|
|
1270
|
+
expect(getResult
|
|
1271
|
+
? Buffer.from(getResult).toString("base64")
|
|
1272
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
1273
|
+
});
|
|
1274
|
+
test("Should work with Float32Array", async () => {
|
|
1275
|
+
const value = new Float32Array(Buffer.from("asd"));
|
|
1276
|
+
await storage.addMany({ a: value });
|
|
1277
|
+
const { a: getResult } = await storage.getOrMany({ a: null });
|
|
1278
|
+
expect(getResult).toBeInstanceOf(Float32Array);
|
|
1279
|
+
expect(getResult
|
|
1280
|
+
? Buffer.from(getResult).toString("base64")
|
|
1281
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
1282
|
+
});
|
|
1283
|
+
test("Should work with Float64Array", async () => {
|
|
1284
|
+
const value = new Float64Array(Buffer.from("asd"));
|
|
1285
|
+
await storage.addMany({ a: value });
|
|
1286
|
+
const { a: getResult } = await storage.getOrMany({ a: null });
|
|
1287
|
+
expect(getResult).toBeInstanceOf(Float64Array);
|
|
1288
|
+
expect(getResult
|
|
1289
|
+
? Buffer.from(getResult).toString("base64")
|
|
1290
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
1291
|
+
});
|
|
1292
|
+
test("Should work with Set", async () => {
|
|
1293
|
+
const value = new Set(["a", "b", "c"]);
|
|
1294
|
+
await storage.addMany({ a: value });
|
|
1295
|
+
const { a: getResult } = await storage.getOrMany({ a: -1 });
|
|
1296
|
+
expect(getResult).toBeInstanceOf(Set);
|
|
1297
|
+
expect(getResult).toEqual(value);
|
|
1298
|
+
});
|
|
1299
|
+
test("Should work with Set of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays", async () => {
|
|
1300
|
+
const value = new Set([
|
|
1301
|
+
0,
|
|
1302
|
+
-1,
|
|
1303
|
+
1,
|
|
1304
|
+
-1.5,
|
|
1305
|
+
1.5,
|
|
1306
|
+
NaN,
|
|
1307
|
+
Infinity,
|
|
1308
|
+
2n,
|
|
1309
|
+
true,
|
|
1310
|
+
false,
|
|
1311
|
+
"str",
|
|
1312
|
+
new Date("2024-01-01"),
|
|
1313
|
+
new Set(["a", "b", "c"]),
|
|
1314
|
+
new Map([
|
|
1315
|
+
["a", 1],
|
|
1316
|
+
["b", 2],
|
|
1317
|
+
["c", 3],
|
|
1318
|
+
]),
|
|
1319
|
+
{ a: 1, b: 2 },
|
|
1320
|
+
[1, 2, 3],
|
|
1321
|
+
/test/,
|
|
1322
|
+
]);
|
|
1323
|
+
await storage.addMany({ a: value });
|
|
1324
|
+
const { a: getResult } = await storage.getOrMany({ a: -1 });
|
|
1325
|
+
expect(getResult).toBeInstanceOf(Set);
|
|
1326
|
+
expect(getResult).toEqual(value);
|
|
1327
|
+
});
|
|
1328
|
+
test("Should work with Map", async () => {
|
|
1329
|
+
const value = new Map([
|
|
1330
|
+
["a", 1],
|
|
1331
|
+
["b", 2],
|
|
1332
|
+
["c", 3],
|
|
1333
|
+
]);
|
|
1334
|
+
await storage.addMany({ a: value });
|
|
1335
|
+
const { a: getResult } = await storage.getOrMany({ a: -1 });
|
|
1336
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
1337
|
+
expect(getResult).toEqual(value);
|
|
1338
|
+
});
|
|
1339
|
+
test("Should work with Map of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays values", async () => {
|
|
1340
|
+
const value = new Map([
|
|
1341
|
+
["a", 0],
|
|
1342
|
+
["b", -1],
|
|
1343
|
+
["c", 1],
|
|
1344
|
+
["d", -1.5],
|
|
1345
|
+
["e", 1.5],
|
|
1346
|
+
["f", NaN],
|
|
1347
|
+
["g", Infinity],
|
|
1348
|
+
["h", 2n],
|
|
1349
|
+
["j", true],
|
|
1350
|
+
["l", false],
|
|
1351
|
+
["i", "str"],
|
|
1352
|
+
["r", new Date("2024-01-01")],
|
|
1353
|
+
["k", new Set(["a", "b", "c"])],
|
|
1354
|
+
[
|
|
1355
|
+
"p",
|
|
1356
|
+
new Map([
|
|
1357
|
+
["a", 1],
|
|
1358
|
+
["b", 2],
|
|
1359
|
+
["c", 3],
|
|
1360
|
+
]),
|
|
1361
|
+
],
|
|
1362
|
+
["a", /test/],
|
|
1363
|
+
[1, { a: 2, b: -1 }],
|
|
1364
|
+
[2, [1, 2, 3]],
|
|
1365
|
+
]);
|
|
1366
|
+
await storage.addMany({ a: value });
|
|
1367
|
+
const { a: getResult } = await storage.getOrMany({ a: -1 });
|
|
1368
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
1369
|
+
expect(getResult).toEqual(value);
|
|
1370
|
+
});
|
|
1371
|
+
test("Should work with Map of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays keys", async () => {
|
|
1372
|
+
const value = new Map([
|
|
1373
|
+
[0, "a"],
|
|
1374
|
+
[-1, "a"],
|
|
1375
|
+
[1, "a"],
|
|
1376
|
+
[-1.5, "a"],
|
|
1377
|
+
[1.5, "a"],
|
|
1378
|
+
[NaN, "a"],
|
|
1379
|
+
[Infinity, "a"],
|
|
1380
|
+
[2n, "a"],
|
|
1381
|
+
[true, "a"],
|
|
1382
|
+
[false, "a"],
|
|
1383
|
+
["str", "a"],
|
|
1384
|
+
[new Date("2024-01-01"), "a"],
|
|
1385
|
+
[new Set(["a", "b", "c"]), "a"],
|
|
1386
|
+
[
|
|
1387
|
+
new Map([
|
|
1388
|
+
["a", 1],
|
|
1389
|
+
["b", 2],
|
|
1390
|
+
["c", 3],
|
|
1391
|
+
]),
|
|
1392
|
+
"a",
|
|
1393
|
+
],
|
|
1394
|
+
[/test/, "a"],
|
|
1395
|
+
[{ a: 2, b: -1 }, 1],
|
|
1396
|
+
[[1, 2, 3], 2],
|
|
1397
|
+
]);
|
|
1398
|
+
await storage.addMany({ a: value });
|
|
1399
|
+
const { a: getResult } = await storage.getOrMany({ a: -1 });
|
|
1400
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
1401
|
+
expect(getResult).toEqual(value);
|
|
1402
|
+
});
|
|
1403
|
+
test("Should work with array of number, boolean, string, Date, Set, Map, RegExp", async () => {
|
|
1404
|
+
const value = [
|
|
1405
|
+
0,
|
|
1406
|
+
-1,
|
|
1407
|
+
1,
|
|
1408
|
+
-1.5,
|
|
1409
|
+
1.5,
|
|
1410
|
+
NaN,
|
|
1411
|
+
Infinity,
|
|
1412
|
+
2n,
|
|
1413
|
+
true,
|
|
1414
|
+
false,
|
|
1415
|
+
"str",
|
|
1416
|
+
new Date("2024-01-01"),
|
|
1417
|
+
new Set(["a", "b", "c"]),
|
|
1418
|
+
new Map([
|
|
1419
|
+
["a", 1],
|
|
1420
|
+
["b", 2],
|
|
1421
|
+
["c", 3],
|
|
1422
|
+
]),
|
|
1423
|
+
/test/,
|
|
1424
|
+
];
|
|
1425
|
+
await storage.addMany({ a: value });
|
|
1426
|
+
const getResult = await storage.getOrMany({ a: -1 });
|
|
1427
|
+
expect(getResult).toEqual({ a: value });
|
|
1428
|
+
});
|
|
1429
|
+
test("Should work with array of objects", async () => {
|
|
1430
|
+
const value = [
|
|
1431
|
+
Object.fromEntries([
|
|
1432
|
+
["a", 0],
|
|
1433
|
+
["b", -1],
|
|
1434
|
+
["c", 1],
|
|
1435
|
+
["d", -1.5],
|
|
1436
|
+
["e", 1.5],
|
|
1437
|
+
["f", NaN],
|
|
1438
|
+
["g", Infinity],
|
|
1439
|
+
["h", 2n],
|
|
1440
|
+
["j", true],
|
|
1441
|
+
["l", false],
|
|
1442
|
+
["i", "str"],
|
|
1443
|
+
["r", new Date("2024-01-01")],
|
|
1444
|
+
["k", new Set(["a", "b", "c"])],
|
|
1445
|
+
[
|
|
1446
|
+
"p",
|
|
1447
|
+
new Map([
|
|
1448
|
+
["a", 1],
|
|
1449
|
+
["b", 2],
|
|
1450
|
+
["c", 3],
|
|
1451
|
+
]),
|
|
1452
|
+
],
|
|
1453
|
+
["a", /test/],
|
|
1454
|
+
]),
|
|
1455
|
+
];
|
|
1456
|
+
await storage.addMany({ a: value });
|
|
1457
|
+
const { a: getResult } = await storage.getOrMany({ a: -1 });
|
|
1458
|
+
expect(getResult).toEqual(value);
|
|
1459
|
+
});
|
|
1460
|
+
test("Should work with object of number, boolean, string, Date, Set, Map, RegExp", async () => {
|
|
1461
|
+
const value = Object.fromEntries([
|
|
1462
|
+
["a", 0],
|
|
1463
|
+
["b", -1],
|
|
1464
|
+
["c", 1],
|
|
1465
|
+
["d", -1.5],
|
|
1466
|
+
["e", 1.5],
|
|
1467
|
+
["f", NaN],
|
|
1468
|
+
["g", Infinity],
|
|
1469
|
+
["h", 2n],
|
|
1470
|
+
["j", true],
|
|
1471
|
+
["l", false],
|
|
1472
|
+
["i", "str"],
|
|
1473
|
+
["r", new Date("2024-01-01")],
|
|
1474
|
+
["k", new Set(["a", "b", "c"])],
|
|
1475
|
+
[
|
|
1476
|
+
"p",
|
|
1477
|
+
new Map([
|
|
1478
|
+
["a", 1],
|
|
1479
|
+
["b", 2],
|
|
1480
|
+
["c", 3],
|
|
1481
|
+
]),
|
|
1482
|
+
],
|
|
1483
|
+
["a", /test/],
|
|
1484
|
+
]);
|
|
1485
|
+
await storage.addMany({ a: value });
|
|
1486
|
+
const { a: getResult } = await storage.getOrMany({ a: -1 });
|
|
1487
|
+
expect(getResult).toEqual(value);
|
|
1488
|
+
});
|
|
1489
|
+
test("Should work with object of arrays", async () => {
|
|
1490
|
+
const value = {
|
|
1491
|
+
a: [
|
|
1492
|
+
0,
|
|
1493
|
+
-1,
|
|
1494
|
+
1,
|
|
1495
|
+
-1.5,
|
|
1496
|
+
1.5,
|
|
1497
|
+
NaN,
|
|
1498
|
+
Infinity,
|
|
1499
|
+
2n,
|
|
1500
|
+
true,
|
|
1501
|
+
false,
|
|
1502
|
+
"str",
|
|
1503
|
+
new Date("2024-01-01"),
|
|
1504
|
+
new Set(["a", "b", "c"]),
|
|
1505
|
+
new Map([
|
|
1506
|
+
["a", 1],
|
|
1507
|
+
["b", 2],
|
|
1508
|
+
["c", 3],
|
|
1509
|
+
]),
|
|
1510
|
+
/test/,
|
|
1511
|
+
],
|
|
1512
|
+
};
|
|
1513
|
+
await storage.addMany({ a: value });
|
|
1514
|
+
const { a: getResult } = await storage.getOrMany({ a: -1 });
|
|
1515
|
+
expect(getResult).toEqual(value);
|
|
1516
|
+
});
|
|
1517
|
+
});
|
|
1518
|
+
describe("method: getOrFail", () => {
|
|
1519
|
+
test("Should work with positive integer", async () => {
|
|
1520
|
+
const value = 1;
|
|
1521
|
+
await storage.add("a", value);
|
|
1522
|
+
expect(await storage.getOrFail("a")).toBe(value);
|
|
1523
|
+
});
|
|
1524
|
+
test("Should work with negative integer", async () => {
|
|
1525
|
+
const value = -1;
|
|
1526
|
+
await storage.add("a", value);
|
|
1527
|
+
expect(await storage.getOrFail("a")).toBe(value);
|
|
1528
|
+
});
|
|
1529
|
+
test("Should work with positive decimal", async () => {
|
|
1530
|
+
const value = 1.5;
|
|
1531
|
+
await storage.add("a", value);
|
|
1532
|
+
expect(await storage.getOrFail("a")).toBe(value);
|
|
1533
|
+
});
|
|
1534
|
+
test("Should work with negative decimal", async () => {
|
|
1535
|
+
const value = -1.5;
|
|
1536
|
+
await storage.add("a", value);
|
|
1537
|
+
expect(await storage.getOrFail("a")).toBe(value);
|
|
1538
|
+
});
|
|
1539
|
+
test("Should work with NaN", async () => {
|
|
1540
|
+
const value = NaN;
|
|
1541
|
+
await storage.add("a", value);
|
|
1542
|
+
const getResult = await storage.getOrFail("a");
|
|
1543
|
+
expect(getResult).toBeNaN();
|
|
1544
|
+
});
|
|
1545
|
+
test("Should work with Infinity", async () => {
|
|
1546
|
+
const value = Infinity;
|
|
1547
|
+
await storage.add("a", value);
|
|
1548
|
+
const getResult = await storage.getOrFail("a");
|
|
1549
|
+
expect(isFinite(getResult)).toBe(false);
|
|
1550
|
+
});
|
|
1551
|
+
test("Should work with Bigint", async () => {
|
|
1552
|
+
const value = 20n;
|
|
1553
|
+
await storage.add("a", value);
|
|
1554
|
+
expect(await storage.getOrFail("a")).toBe(value);
|
|
1555
|
+
});
|
|
1556
|
+
test("Should work with true", async () => {
|
|
1557
|
+
const value = true;
|
|
1558
|
+
await storage.add("a", value);
|
|
1559
|
+
expect(await storage.getOrFail("a")).toBe(value);
|
|
1560
|
+
});
|
|
1561
|
+
test("Should work with false", async () => {
|
|
1562
|
+
const value = false;
|
|
1563
|
+
await storage.add("a", value);
|
|
1564
|
+
expect(await storage.getOrFail("a")).toBe(value);
|
|
1565
|
+
});
|
|
1566
|
+
test("Should work with string", async () => {
|
|
1567
|
+
const value = "str";
|
|
1568
|
+
await storage.add("a", value);
|
|
1569
|
+
expect(await storage.getOrFail("a")).toBe(value);
|
|
1570
|
+
});
|
|
1571
|
+
test("Should work with Date", async () => {
|
|
1572
|
+
const value = new Date("2024-01-01");
|
|
1573
|
+
await storage.add("a", value);
|
|
1574
|
+
const getResult = await storage.getOrFail("a");
|
|
1575
|
+
expect(getResult).toBeInstanceOf(Date);
|
|
1576
|
+
expect(getResult).toEqual(value);
|
|
1577
|
+
});
|
|
1578
|
+
test("Should work with RegExp", async () => {
|
|
1579
|
+
const value = /test/;
|
|
1580
|
+
await storage.add("a", value);
|
|
1581
|
+
const getResult = await storage.getOrFail("a");
|
|
1582
|
+
expect(getResult).toBeInstanceOf(RegExp);
|
|
1583
|
+
expect(getResult).toEqual(value);
|
|
1584
|
+
});
|
|
1585
|
+
test("Should work with Buffer", async () => {
|
|
1586
|
+
const value = Buffer.from("asd");
|
|
1587
|
+
await storage.add("a", value);
|
|
1588
|
+
const getResult = await storage.getOrFail("a");
|
|
1589
|
+
expect(getResult).toBeInstanceOf(Buffer);
|
|
1590
|
+
expect(getResult.toString("base64")).toEqual(value.toString("base64"));
|
|
1591
|
+
});
|
|
1592
|
+
test("Should work with Uint8Array", async () => {
|
|
1593
|
+
const value = new Uint8Array(Buffer.from("asd"));
|
|
1594
|
+
await storage.add("a", value);
|
|
1595
|
+
const getResult = await storage.getOrFail("a");
|
|
1596
|
+
expect(getResult).toBeInstanceOf(Uint8Array);
|
|
1597
|
+
expect(Buffer.from(getResult).toString("base64")).toEqual(Buffer.from(value).toString("base64"));
|
|
1598
|
+
});
|
|
1599
|
+
test("Should work with Int8Array", async () => {
|
|
1600
|
+
const value = new Int8Array(Buffer.from("asd"));
|
|
1601
|
+
await storage.add("a", value);
|
|
1602
|
+
const getResult = await storage.getOrFail("a");
|
|
1603
|
+
expect(getResult).toBeInstanceOf(Int8Array);
|
|
1604
|
+
expect(Buffer.from(getResult).toString("base64")).toEqual(Buffer.from(value).toString("base64"));
|
|
1605
|
+
});
|
|
1606
|
+
test("Should work with Uint16Array", async () => {
|
|
1607
|
+
const value = new Uint16Array(Buffer.from("asd"));
|
|
1608
|
+
await storage.add("a", value);
|
|
1609
|
+
const getResult = await storage.getOrFail("a");
|
|
1610
|
+
expect(getResult).toBeInstanceOf(Uint16Array);
|
|
1611
|
+
expect(Buffer.from(getResult).toString("base64")).toEqual(Buffer.from(value).toString("base64"));
|
|
1612
|
+
});
|
|
1613
|
+
test("Should work with Int16Array", async () => {
|
|
1614
|
+
const value = new Int16Array(Buffer.from("asd"));
|
|
1615
|
+
await storage.add("a", value);
|
|
1616
|
+
const getResult = await storage.getOrFail("a");
|
|
1617
|
+
expect(getResult).toBeInstanceOf(Int16Array);
|
|
1618
|
+
expect(Buffer.from(getResult).toString("base64")).toEqual(Buffer.from(value).toString("base64"));
|
|
1619
|
+
});
|
|
1620
|
+
test("Should work with Uint32Array", async () => {
|
|
1621
|
+
const value = new Uint32Array(Buffer.from("asd"));
|
|
1622
|
+
await storage.add("a", value);
|
|
1623
|
+
const getResult = await storage.getOrFail("a");
|
|
1624
|
+
expect(getResult).toBeInstanceOf(Uint32Array);
|
|
1625
|
+
expect(Buffer.from(getResult).toString("base64")).toEqual(Buffer.from(value).toString("base64"));
|
|
1626
|
+
});
|
|
1627
|
+
test("Should work with Int32Array", async () => {
|
|
1628
|
+
const value = new Int32Array(Buffer.from("asd"));
|
|
1629
|
+
await storage.add("a", value);
|
|
1630
|
+
const getResult = await storage.getOrFail("a");
|
|
1631
|
+
expect(getResult).toBeInstanceOf(Int32Array);
|
|
1632
|
+
expect(Buffer.from(getResult).toString("base64")).toEqual(Buffer.from(value).toString("base64"));
|
|
1633
|
+
});
|
|
1634
|
+
test("Should work with Float32Array", async () => {
|
|
1635
|
+
const value = new Float32Array(Buffer.from("asd"));
|
|
1636
|
+
await storage.add("a", value);
|
|
1637
|
+
const getResult = await storage.getOrFail("a");
|
|
1638
|
+
expect(getResult).toBeInstanceOf(Float32Array);
|
|
1639
|
+
expect(Buffer.from(getResult).toString("base64")).toEqual(Buffer.from(value).toString("base64"));
|
|
1640
|
+
});
|
|
1641
|
+
test("Should work with Float64Array", async () => {
|
|
1642
|
+
const value = new Float64Array(Buffer.from("asd"));
|
|
1643
|
+
await storage.add("a", value);
|
|
1644
|
+
const getResult = await storage.getOrFail("a");
|
|
1645
|
+
expect(getResult).toBeInstanceOf(Float64Array);
|
|
1646
|
+
expect(Buffer.from(getResult).toString("base64")).toEqual(Buffer.from(value).toString("base64"));
|
|
1647
|
+
});
|
|
1648
|
+
test("Should work with Set", async () => {
|
|
1649
|
+
const value = new Set(["a", "b", "c"]);
|
|
1650
|
+
await storage.add("a", value);
|
|
1651
|
+
const getResult = await storage.getOrFail("a");
|
|
1652
|
+
expect(getResult).toBeInstanceOf(Set);
|
|
1653
|
+
expect(getResult).toEqual(value);
|
|
1654
|
+
});
|
|
1655
|
+
test("Should work with Set of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays", async () => {
|
|
1656
|
+
const value = new Set([
|
|
1657
|
+
0,
|
|
1658
|
+
-1,
|
|
1659
|
+
1,
|
|
1660
|
+
-1.5,
|
|
1661
|
+
1.5,
|
|
1662
|
+
NaN,
|
|
1663
|
+
Infinity,
|
|
1664
|
+
2n,
|
|
1665
|
+
true,
|
|
1666
|
+
false,
|
|
1667
|
+
"str",
|
|
1668
|
+
new Date("2024-01-01"),
|
|
1669
|
+
new Set(["a", "b", "c"]),
|
|
1670
|
+
new Map([
|
|
1671
|
+
["a", 1],
|
|
1672
|
+
["b", 2],
|
|
1673
|
+
["c", 3],
|
|
1674
|
+
]),
|
|
1675
|
+
{ a: 1, b: 2 },
|
|
1676
|
+
[1, 2, 3],
|
|
1677
|
+
/test/,
|
|
1678
|
+
]);
|
|
1679
|
+
await storage.add("a", value);
|
|
1680
|
+
const getResult = await storage.getOrFail("a");
|
|
1681
|
+
expect(getResult).toBeInstanceOf(Set);
|
|
1682
|
+
expect(getResult).toEqual(value);
|
|
1683
|
+
});
|
|
1684
|
+
test("Should work with Map", async () => {
|
|
1685
|
+
const value = new Map([
|
|
1686
|
+
["a", 1],
|
|
1687
|
+
["b", 2],
|
|
1688
|
+
["c", 3],
|
|
1689
|
+
]);
|
|
1690
|
+
await storage.add("a", value);
|
|
1691
|
+
const getResult = await storage.getOrFail("a");
|
|
1692
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
1693
|
+
expect(getResult).toEqual(value);
|
|
1694
|
+
});
|
|
1695
|
+
test("Should work with Map of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays values", async () => {
|
|
1696
|
+
const value = new Map([
|
|
1697
|
+
["a", 0],
|
|
1698
|
+
["b", -1],
|
|
1699
|
+
["c", 1],
|
|
1700
|
+
["d", -1.5],
|
|
1701
|
+
["e", 1.5],
|
|
1702
|
+
["f", NaN],
|
|
1703
|
+
["g", Infinity],
|
|
1704
|
+
["h", 2n],
|
|
1705
|
+
["j", true],
|
|
1706
|
+
["l", false],
|
|
1707
|
+
["i", "str"],
|
|
1708
|
+
["r", new Date("2024-01-01")],
|
|
1709
|
+
["k", new Set(["a", "b", "c"])],
|
|
1710
|
+
[
|
|
1711
|
+
"p",
|
|
1712
|
+
new Map([
|
|
1713
|
+
["a", 1],
|
|
1714
|
+
["b", 2],
|
|
1715
|
+
["c", 3],
|
|
1716
|
+
]),
|
|
1717
|
+
],
|
|
1718
|
+
["a", /test/],
|
|
1719
|
+
[1, { a: 2, b: -1 }],
|
|
1720
|
+
[2, [1, 2, 3]],
|
|
1721
|
+
]);
|
|
1722
|
+
await storage.add("a", value);
|
|
1723
|
+
const getResult = await storage.getOrFail("a");
|
|
1724
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
1725
|
+
expect(getResult).toEqual(value);
|
|
1726
|
+
});
|
|
1727
|
+
test("Should work with Map of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays keys", async () => {
|
|
1728
|
+
const value = new Map([
|
|
1729
|
+
[0, "a"],
|
|
1730
|
+
[-1, "a"],
|
|
1731
|
+
[1, "a"],
|
|
1732
|
+
[-1.5, "a"],
|
|
1733
|
+
[1.5, "a"],
|
|
1734
|
+
[NaN, "a"],
|
|
1735
|
+
[Infinity, "a"],
|
|
1736
|
+
[2n, "a"],
|
|
1737
|
+
[true, "a"],
|
|
1738
|
+
[false, "a"],
|
|
1739
|
+
["str", "a"],
|
|
1740
|
+
[new Date("2024-01-01"), "a"],
|
|
1741
|
+
[new Set(["a", "b", "c"]), "a"],
|
|
1742
|
+
[
|
|
1743
|
+
new Map([
|
|
1744
|
+
["a", 1],
|
|
1745
|
+
["b", 2],
|
|
1746
|
+
["c", 3],
|
|
1747
|
+
]),
|
|
1748
|
+
"a",
|
|
1749
|
+
],
|
|
1750
|
+
[/test/, "a"],
|
|
1751
|
+
[{ a: 2, b: -1 }, 1],
|
|
1752
|
+
[[1, 2, 3], 2],
|
|
1753
|
+
]);
|
|
1754
|
+
await storage.add("a", value);
|
|
1755
|
+
const getResult = await storage.getOrFail("a");
|
|
1756
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
1757
|
+
expect(getResult).toEqual(value);
|
|
1758
|
+
});
|
|
1759
|
+
test("Should work with array of number, boolean, string, Date, Set, Map, RegExp", async () => {
|
|
1760
|
+
const value = [
|
|
1761
|
+
0,
|
|
1762
|
+
-1,
|
|
1763
|
+
1,
|
|
1764
|
+
-1.5,
|
|
1765
|
+
1.5,
|
|
1766
|
+
NaN,
|
|
1767
|
+
Infinity,
|
|
1768
|
+
2n,
|
|
1769
|
+
true,
|
|
1770
|
+
false,
|
|
1771
|
+
"str",
|
|
1772
|
+
new Date("2024-01-01"),
|
|
1773
|
+
new Set(["a", "b", "c"]),
|
|
1774
|
+
new Map([
|
|
1775
|
+
["a", 1],
|
|
1776
|
+
["b", 2],
|
|
1777
|
+
["c", 3],
|
|
1778
|
+
]),
|
|
1779
|
+
/test/,
|
|
1780
|
+
];
|
|
1781
|
+
await storage.add("a", value);
|
|
1782
|
+
const getResult = await storage.getOrFail("a");
|
|
1783
|
+
expect(getResult).toEqual(value);
|
|
1784
|
+
});
|
|
1785
|
+
test("Should work with array of objects", async () => {
|
|
1786
|
+
const value = [
|
|
1787
|
+
Object.fromEntries([
|
|
1788
|
+
["a", 0],
|
|
1789
|
+
["b", -1],
|
|
1790
|
+
["c", 1],
|
|
1791
|
+
["d", -1.5],
|
|
1792
|
+
["e", 1.5],
|
|
1793
|
+
["f", NaN],
|
|
1794
|
+
["g", Infinity],
|
|
1795
|
+
["h", 2n],
|
|
1796
|
+
["j", true],
|
|
1797
|
+
["l", false],
|
|
1798
|
+
["i", "str"],
|
|
1799
|
+
["r", new Date("2024-01-01")],
|
|
1800
|
+
["k", new Set(["a", "b", "c"])],
|
|
1801
|
+
[
|
|
1802
|
+
"p",
|
|
1803
|
+
new Map([
|
|
1804
|
+
["a", 1],
|
|
1805
|
+
["b", 2],
|
|
1806
|
+
["c", 3],
|
|
1807
|
+
]),
|
|
1808
|
+
],
|
|
1809
|
+
["a", /test/],
|
|
1810
|
+
]),
|
|
1811
|
+
];
|
|
1812
|
+
await storage.add("a", value);
|
|
1813
|
+
const getResult = await storage.getOrFail("a");
|
|
1814
|
+
expect(getResult).toEqual(value);
|
|
1815
|
+
});
|
|
1816
|
+
test("Should work with object of number, boolean, string, Date, Set, Map, RegExp", async () => {
|
|
1817
|
+
const value = Object.fromEntries([
|
|
1818
|
+
["a", 0],
|
|
1819
|
+
["b", -1],
|
|
1820
|
+
["c", 1],
|
|
1821
|
+
["d", -1.5],
|
|
1822
|
+
["e", 1.5],
|
|
1823
|
+
["f", NaN],
|
|
1824
|
+
["g", Infinity],
|
|
1825
|
+
["h", 2n],
|
|
1826
|
+
["j", true],
|
|
1827
|
+
["l", false],
|
|
1828
|
+
["i", "str"],
|
|
1829
|
+
["r", new Date("2024-01-01")],
|
|
1830
|
+
["k", new Set(["a", "b", "c"])],
|
|
1831
|
+
[
|
|
1832
|
+
"p",
|
|
1833
|
+
new Map([
|
|
1834
|
+
["a", 1],
|
|
1835
|
+
["b", 2],
|
|
1836
|
+
["c", 3],
|
|
1837
|
+
]),
|
|
1838
|
+
],
|
|
1839
|
+
["a", /test/],
|
|
1840
|
+
]);
|
|
1841
|
+
await storage.add("a", value);
|
|
1842
|
+
const getResult = await storage.getOrFail("a");
|
|
1843
|
+
expect(getResult).toEqual(value);
|
|
1844
|
+
});
|
|
1845
|
+
test("Should work with object of arrays", async () => {
|
|
1846
|
+
const value = {
|
|
1847
|
+
a: [
|
|
1848
|
+
0,
|
|
1849
|
+
-1,
|
|
1850
|
+
1,
|
|
1851
|
+
-1.5,
|
|
1852
|
+
1.5,
|
|
1853
|
+
NaN,
|
|
1854
|
+
Infinity,
|
|
1855
|
+
2n,
|
|
1856
|
+
true,
|
|
1857
|
+
false,
|
|
1858
|
+
"str",
|
|
1859
|
+
new Date("2024-01-01"),
|
|
1860
|
+
new Set(["a", "b", "c"]),
|
|
1861
|
+
new Map([
|
|
1862
|
+
["a", 1],
|
|
1863
|
+
["b", 2],
|
|
1864
|
+
["c", 3],
|
|
1865
|
+
]),
|
|
1866
|
+
/test/,
|
|
1867
|
+
],
|
|
1868
|
+
};
|
|
1869
|
+
await storage.add("a", value);
|
|
1870
|
+
const getResult = await storage.getOrFail("a");
|
|
1871
|
+
expect(getResult).toEqual(value);
|
|
1872
|
+
});
|
|
1873
|
+
});
|
|
1874
|
+
describe("method: update", () => {
|
|
1875
|
+
test("Should work with positive integer", async () => {
|
|
1876
|
+
const value = 1;
|
|
1877
|
+
await storage.add("a", -1);
|
|
1878
|
+
await storage.update("a", value);
|
|
1879
|
+
expect(await storage.get("a")).toBe(value);
|
|
1880
|
+
});
|
|
1881
|
+
test("Should work with negative integer", async () => {
|
|
1882
|
+
const value = -1;
|
|
1883
|
+
await storage.add("a", -1);
|
|
1884
|
+
await storage.update("a", value);
|
|
1885
|
+
expect(await storage.get("a")).toBe(value);
|
|
1886
|
+
});
|
|
1887
|
+
test("Should work with positive decimal", async () => {
|
|
1888
|
+
const value = 1.5;
|
|
1889
|
+
await storage.add("a", -1);
|
|
1890
|
+
await storage.update("a", value);
|
|
1891
|
+
expect(await storage.get("a")).toBe(value);
|
|
1892
|
+
});
|
|
1893
|
+
test("Should work with negative decimal", async () => {
|
|
1894
|
+
const value = -1.5;
|
|
1895
|
+
await storage.add("a", -1);
|
|
1896
|
+
await storage.update("a", value);
|
|
1897
|
+
expect(await storage.get("a")).toBe(value);
|
|
1898
|
+
});
|
|
1899
|
+
test("Should work with NaN", async () => {
|
|
1900
|
+
const value = NaN;
|
|
1901
|
+
await storage.add("a", -1);
|
|
1902
|
+
await storage.update("a", value);
|
|
1903
|
+
const getResult = await storage.get("a");
|
|
1904
|
+
expect(getResult).toBeNaN();
|
|
1905
|
+
});
|
|
1906
|
+
test("Should work with Infinity", async () => {
|
|
1907
|
+
const value = Infinity;
|
|
1908
|
+
await storage.add("a", -1);
|
|
1909
|
+
await storage.update("a", value);
|
|
1910
|
+
const getResult = await storage.get("a");
|
|
1911
|
+
expect(isFinite(getResult)).toBe(false);
|
|
1912
|
+
});
|
|
1913
|
+
test("Should work with Bigint", async () => {
|
|
1914
|
+
const value = 20n;
|
|
1915
|
+
await storage.add("a", -1);
|
|
1916
|
+
await storage.update("a", value);
|
|
1917
|
+
expect(await storage.get("a")).toBe(value);
|
|
1918
|
+
});
|
|
1919
|
+
test("Should work with true", async () => {
|
|
1920
|
+
const value = true;
|
|
1921
|
+
await storage.add("a", -1);
|
|
1922
|
+
await storage.update("a", value);
|
|
1923
|
+
expect(await storage.get("a")).toBe(value);
|
|
1924
|
+
});
|
|
1925
|
+
test("Should work with false", async () => {
|
|
1926
|
+
const value = false;
|
|
1927
|
+
await storage.add("a", -1);
|
|
1928
|
+
await storage.update("a", value);
|
|
1929
|
+
expect(await storage.get("a")).toBe(value);
|
|
1930
|
+
});
|
|
1931
|
+
test("Should work with string", async () => {
|
|
1932
|
+
const value = "str";
|
|
1933
|
+
await storage.add("a", -1);
|
|
1934
|
+
await storage.update("a", value);
|
|
1935
|
+
expect(await storage.get("a")).toBe(value);
|
|
1936
|
+
});
|
|
1937
|
+
test("Should work with Date", async () => {
|
|
1938
|
+
const value = new Date("2024-01-01");
|
|
1939
|
+
await storage.add("a", -1);
|
|
1940
|
+
await storage.update("a", value);
|
|
1941
|
+
const getResult = await storage.get("a");
|
|
1942
|
+
expect(getResult).toBeInstanceOf(Date);
|
|
1943
|
+
expect(getResult).toEqual(value);
|
|
1944
|
+
});
|
|
1945
|
+
test("Should work with RegExp", async () => {
|
|
1946
|
+
const value = /test/;
|
|
1947
|
+
await storage.add("a", -1);
|
|
1948
|
+
await storage.update("a", value);
|
|
1949
|
+
const getResult = await storage.get("a");
|
|
1950
|
+
expect(getResult).toBeInstanceOf(RegExp);
|
|
1951
|
+
expect(getResult).toEqual(value);
|
|
1952
|
+
});
|
|
1953
|
+
test("Should work with Buffer", async () => {
|
|
1954
|
+
const value = Buffer.from("asd");
|
|
1955
|
+
await storage.add("a", -1);
|
|
1956
|
+
await storage.update("a", value);
|
|
1957
|
+
const getResult = await storage.get("a");
|
|
1958
|
+
expect(getResult).toBeInstanceOf(Buffer);
|
|
1959
|
+
expect(getResult?.toString("base64")).toEqual(value.toString("base64"));
|
|
1960
|
+
});
|
|
1961
|
+
test("Should work with Uint8Array", async () => {
|
|
1962
|
+
const value = new Uint8Array(Buffer.from("asd"));
|
|
1963
|
+
await storage.add("a", -1);
|
|
1964
|
+
await storage.update("a", value);
|
|
1965
|
+
const getResult = await storage.get("a");
|
|
1966
|
+
expect(getResult).toBeInstanceOf(Uint8Array);
|
|
1967
|
+
expect(getResult
|
|
1968
|
+
? Buffer.from(getResult).toString("base64")
|
|
1969
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
1970
|
+
});
|
|
1971
|
+
test("Should work with Int8Array", async () => {
|
|
1972
|
+
const value = new Int8Array(Buffer.from("asd"));
|
|
1973
|
+
await storage.add("a", -1);
|
|
1974
|
+
await storage.update("a", value);
|
|
1975
|
+
const getResult = await storage.get("a");
|
|
1976
|
+
expect(getResult).toBeInstanceOf(Int8Array);
|
|
1977
|
+
expect(getResult
|
|
1978
|
+
? Buffer.from(getResult).toString("base64")
|
|
1979
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
1980
|
+
});
|
|
1981
|
+
test("Should work with Uint16Array", async () => {
|
|
1982
|
+
const value = new Uint16Array(Buffer.from("asd"));
|
|
1983
|
+
await storage.add("a", -1);
|
|
1984
|
+
await storage.update("a", value);
|
|
1985
|
+
const getResult = await storage.get("a");
|
|
1986
|
+
expect(getResult).toBeInstanceOf(Uint16Array);
|
|
1987
|
+
expect(getResult
|
|
1988
|
+
? Buffer.from(getResult).toString("base64")
|
|
1989
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
1990
|
+
});
|
|
1991
|
+
test("Should work with Int16Array", async () => {
|
|
1992
|
+
const value = new Int16Array(Buffer.from("asd"));
|
|
1993
|
+
await storage.add("a", -1);
|
|
1994
|
+
await storage.update("a", value);
|
|
1995
|
+
const getResult = await storage.get("a");
|
|
1996
|
+
expect(getResult).toBeInstanceOf(Int16Array);
|
|
1997
|
+
expect(getResult
|
|
1998
|
+
? Buffer.from(getResult).toString("base64")
|
|
1999
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
2000
|
+
});
|
|
2001
|
+
test("Should work with Uint32Array", async () => {
|
|
2002
|
+
const value = new Uint32Array(Buffer.from("asd"));
|
|
2003
|
+
await storage.add("a", -1);
|
|
2004
|
+
await storage.update("a", value);
|
|
2005
|
+
const getResult = await storage.get("a");
|
|
2006
|
+
expect(getResult).toBeInstanceOf(Uint32Array);
|
|
2007
|
+
expect(getResult
|
|
2008
|
+
? Buffer.from(getResult).toString("base64")
|
|
2009
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
2010
|
+
});
|
|
2011
|
+
test("Should work with Int32Array", async () => {
|
|
2012
|
+
const value = new Int32Array(Buffer.from("asd"));
|
|
2013
|
+
await storage.add("a", -1);
|
|
2014
|
+
await storage.update("a", value);
|
|
2015
|
+
const getResult = await storage.get("a");
|
|
2016
|
+
expect(getResult).toBeInstanceOf(Int32Array);
|
|
2017
|
+
expect(getResult
|
|
2018
|
+
? Buffer.from(getResult).toString("base64")
|
|
2019
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
2020
|
+
});
|
|
2021
|
+
test("Should work with Float32Array", async () => {
|
|
2022
|
+
const value = new Float32Array(Buffer.from("asd"));
|
|
2023
|
+
await storage.add("a", -1);
|
|
2024
|
+
await storage.update("a", value);
|
|
2025
|
+
const getResult = await storage.get("a");
|
|
2026
|
+
expect(getResult).toBeInstanceOf(Float32Array);
|
|
2027
|
+
expect(getResult
|
|
2028
|
+
? Buffer.from(getResult).toString("base64")
|
|
2029
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
2030
|
+
});
|
|
2031
|
+
test("Should work with Float64Array", async () => {
|
|
2032
|
+
const value = new Float64Array(Buffer.from("asd"));
|
|
2033
|
+
await storage.add("a", -1);
|
|
2034
|
+
await storage.update("a", value);
|
|
2035
|
+
const getResult = await storage.get("a");
|
|
2036
|
+
expect(getResult).toBeInstanceOf(Float64Array);
|
|
2037
|
+
expect(getResult
|
|
2038
|
+
? Buffer.from(getResult).toString("base64")
|
|
2039
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
2040
|
+
});
|
|
2041
|
+
test("Should work with Set", async () => {
|
|
2042
|
+
const value = new Set(["a", "b", "c"]);
|
|
2043
|
+
await storage.add("a", -1);
|
|
2044
|
+
await storage.update("a", value);
|
|
2045
|
+
const getResult = await storage.get("a");
|
|
2046
|
+
expect(getResult).toBeInstanceOf(Set);
|
|
2047
|
+
expect(getResult).toEqual(value);
|
|
2048
|
+
});
|
|
2049
|
+
test("Should work with Set of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays", async () => {
|
|
2050
|
+
const value = new Set([
|
|
2051
|
+
0,
|
|
2052
|
+
-1,
|
|
2053
|
+
1,
|
|
2054
|
+
-1.5,
|
|
2055
|
+
1.5,
|
|
2056
|
+
NaN,
|
|
2057
|
+
Infinity,
|
|
2058
|
+
2n,
|
|
2059
|
+
true,
|
|
2060
|
+
false,
|
|
2061
|
+
"str",
|
|
2062
|
+
new Date("2024-01-01"),
|
|
2063
|
+
new Set(["a", "b", "c"]),
|
|
2064
|
+
new Map([
|
|
2065
|
+
["a", 1],
|
|
2066
|
+
["b", 2],
|
|
2067
|
+
["c", 3],
|
|
2068
|
+
]),
|
|
2069
|
+
{ a: 1, b: 2 },
|
|
2070
|
+
[1, 2, 3],
|
|
2071
|
+
/test/,
|
|
2072
|
+
]);
|
|
2073
|
+
await storage.add("a", -1);
|
|
2074
|
+
await storage.update("a", value);
|
|
2075
|
+
const getResult = await storage.get("a");
|
|
2076
|
+
expect(getResult).toBeInstanceOf(Set);
|
|
2077
|
+
expect(getResult).toEqual(value);
|
|
2078
|
+
});
|
|
2079
|
+
test("Should work with Map", async () => {
|
|
2080
|
+
const value = new Map([
|
|
2081
|
+
["a", 1],
|
|
2082
|
+
["b", 2],
|
|
2083
|
+
["c", 3],
|
|
2084
|
+
]);
|
|
2085
|
+
await storage.add("a", -1);
|
|
2086
|
+
await storage.update("a", value);
|
|
2087
|
+
const getResult = await storage.get("a");
|
|
2088
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
2089
|
+
expect(getResult).toEqual(value);
|
|
2090
|
+
});
|
|
2091
|
+
test("Should work with Map of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays values", async () => {
|
|
2092
|
+
const value = new Map([
|
|
2093
|
+
["a", 0],
|
|
2094
|
+
["b", -1],
|
|
2095
|
+
["c", 1],
|
|
2096
|
+
["d", -1.5],
|
|
2097
|
+
["e", 1.5],
|
|
2098
|
+
["f", NaN],
|
|
2099
|
+
["g", Infinity],
|
|
2100
|
+
["h", 2n],
|
|
2101
|
+
["j", true],
|
|
2102
|
+
["l", false],
|
|
2103
|
+
["i", "str"],
|
|
2104
|
+
["r", new Date("2024-01-01")],
|
|
2105
|
+
["k", new Set(["a", "b", "c"])],
|
|
2106
|
+
[
|
|
2107
|
+
"p",
|
|
2108
|
+
new Map([
|
|
2109
|
+
["a", 1],
|
|
2110
|
+
["b", 2],
|
|
2111
|
+
["c", 3],
|
|
2112
|
+
]),
|
|
2113
|
+
],
|
|
2114
|
+
["a", /test/],
|
|
2115
|
+
[1, { a: 2, b: -1 }],
|
|
2116
|
+
[2, [1, 2, 3]],
|
|
2117
|
+
]);
|
|
2118
|
+
await storage.add("a", -1);
|
|
2119
|
+
await storage.update("a", value);
|
|
2120
|
+
const getResult = await storage.get("a");
|
|
2121
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
2122
|
+
expect(getResult).toEqual(value);
|
|
2123
|
+
});
|
|
2124
|
+
test("Should work with Map of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays keys", async () => {
|
|
2125
|
+
const value = new Map([
|
|
2126
|
+
[0, "a"],
|
|
2127
|
+
[-1, "a"],
|
|
2128
|
+
[1, "a"],
|
|
2129
|
+
[-1.5, "a"],
|
|
2130
|
+
[1.5, "a"],
|
|
2131
|
+
[NaN, "a"],
|
|
2132
|
+
[Infinity, "a"],
|
|
2133
|
+
[2n, "a"],
|
|
2134
|
+
[true, "a"],
|
|
2135
|
+
[false, "a"],
|
|
2136
|
+
["str", "a"],
|
|
2137
|
+
[new Date("2024-01-01"), "a"],
|
|
2138
|
+
[new Set(["a", "b", "c"]), "a"],
|
|
2139
|
+
[
|
|
2140
|
+
new Map([
|
|
2141
|
+
["a", 1],
|
|
2142
|
+
["b", 2],
|
|
2143
|
+
["c", 3],
|
|
2144
|
+
]),
|
|
2145
|
+
"a",
|
|
2146
|
+
],
|
|
2147
|
+
[/test/, "a"],
|
|
2148
|
+
[{ a: 2, b: -1 }, 1],
|
|
2149
|
+
[[1, 2, 3], 2],
|
|
2150
|
+
]);
|
|
2151
|
+
await storage.add("a", -1);
|
|
2152
|
+
await storage.update("a", value);
|
|
2153
|
+
const getResult = await storage.get("a");
|
|
2154
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
2155
|
+
expect(getResult).toEqual(value);
|
|
2156
|
+
});
|
|
2157
|
+
test("Should work with array of number, boolean, string, Date, Set, Map, RegExp", async () => {
|
|
2158
|
+
const value = [
|
|
2159
|
+
0,
|
|
2160
|
+
-1,
|
|
2161
|
+
1,
|
|
2162
|
+
-1.5,
|
|
2163
|
+
1.5,
|
|
2164
|
+
NaN,
|
|
2165
|
+
Infinity,
|
|
2166
|
+
2n,
|
|
2167
|
+
true,
|
|
2168
|
+
false,
|
|
2169
|
+
"str",
|
|
2170
|
+
new Date("2024-01-01"),
|
|
2171
|
+
new Set(["a", "b", "c"]),
|
|
2172
|
+
new Map([
|
|
2173
|
+
["a", 1],
|
|
2174
|
+
["b", 2],
|
|
2175
|
+
["c", 3],
|
|
2176
|
+
]),
|
|
2177
|
+
/test/,
|
|
2178
|
+
];
|
|
2179
|
+
await storage.add("a", -1);
|
|
2180
|
+
await storage.update("a", value);
|
|
2181
|
+
const getResult = await storage.get("a");
|
|
2182
|
+
expect(getResult).toEqual(value);
|
|
2183
|
+
});
|
|
2184
|
+
test("Should work with array of objects", async () => {
|
|
2185
|
+
const value = [
|
|
2186
|
+
Object.fromEntries([
|
|
2187
|
+
["a", 0],
|
|
2188
|
+
["b", -1],
|
|
2189
|
+
["c", 1],
|
|
2190
|
+
["d", -1.5],
|
|
2191
|
+
["e", 1.5],
|
|
2192
|
+
["f", NaN],
|
|
2193
|
+
["g", Infinity],
|
|
2194
|
+
["h", 2n],
|
|
2195
|
+
["j", true],
|
|
2196
|
+
["l", false],
|
|
2197
|
+
["i", "str"],
|
|
2198
|
+
["r", new Date("2024-01-01")],
|
|
2199
|
+
["k", new Set(["a", "b", "c"])],
|
|
2200
|
+
[
|
|
2201
|
+
"p",
|
|
2202
|
+
new Map([
|
|
2203
|
+
["a", 1],
|
|
2204
|
+
["b", 2],
|
|
2205
|
+
["c", 3],
|
|
2206
|
+
]),
|
|
2207
|
+
],
|
|
2208
|
+
["a", /test/],
|
|
2209
|
+
]),
|
|
2210
|
+
];
|
|
2211
|
+
await storage.add("a", -1);
|
|
2212
|
+
await storage.update("a", value);
|
|
2213
|
+
const getResult = await storage.get("a");
|
|
2214
|
+
expect(getResult).toEqual(value);
|
|
2215
|
+
});
|
|
2216
|
+
test("Should work with object of number, boolean, string, Date, Set, Map, RegExp", async () => {
|
|
2217
|
+
const value = Object.fromEntries([
|
|
2218
|
+
["a", 0],
|
|
2219
|
+
["b", -1],
|
|
2220
|
+
["c", 1],
|
|
2221
|
+
["d", -1.5],
|
|
2222
|
+
["e", 1.5],
|
|
2223
|
+
["f", NaN],
|
|
2224
|
+
["g", Infinity],
|
|
2225
|
+
["h", 2n],
|
|
2226
|
+
["j", true],
|
|
2227
|
+
["l", false],
|
|
2228
|
+
["i", "str"],
|
|
2229
|
+
["r", new Date("2024-01-01")],
|
|
2230
|
+
["k", new Set(["a", "b", "c"])],
|
|
2231
|
+
[
|
|
2232
|
+
"p",
|
|
2233
|
+
new Map([
|
|
2234
|
+
["a", 1],
|
|
2235
|
+
["b", 2],
|
|
2236
|
+
["c", 3],
|
|
2237
|
+
]),
|
|
2238
|
+
],
|
|
2239
|
+
["a", /test/],
|
|
2240
|
+
]);
|
|
2241
|
+
await storage.add("a", -1);
|
|
2242
|
+
await storage.update("a", value);
|
|
2243
|
+
const getResult = await storage.get("a");
|
|
2244
|
+
expect(getResult).toEqual(value);
|
|
2245
|
+
});
|
|
2246
|
+
test("Should work with object of arrays", async () => {
|
|
2247
|
+
const value = {
|
|
2248
|
+
a: [
|
|
2249
|
+
0,
|
|
2250
|
+
-1,
|
|
2251
|
+
1,
|
|
2252
|
+
-1.5,
|
|
2253
|
+
1.5,
|
|
2254
|
+
NaN,
|
|
2255
|
+
Infinity,
|
|
2256
|
+
2n,
|
|
2257
|
+
true,
|
|
2258
|
+
false,
|
|
2259
|
+
"str",
|
|
2260
|
+
new Date("2024-01-01"),
|
|
2261
|
+
new Set(["a", "b", "c"]),
|
|
2262
|
+
new Map([
|
|
2263
|
+
["a", 1],
|
|
2264
|
+
["b", 2],
|
|
2265
|
+
["c", 3],
|
|
2266
|
+
]),
|
|
2267
|
+
/test/,
|
|
2268
|
+
],
|
|
2269
|
+
};
|
|
2270
|
+
await storage.add("a", -1);
|
|
2271
|
+
await storage.update("a", value);
|
|
2272
|
+
const getResult = await storage.get("a");
|
|
2273
|
+
expect(getResult).toEqual(value);
|
|
2274
|
+
});
|
|
2275
|
+
});
|
|
2276
|
+
describe("method: updateMany", () => {
|
|
2277
|
+
test("Should work with positive integer", async () => {
|
|
2278
|
+
const value = 1;
|
|
2279
|
+
await storage.add("a", -1);
|
|
2280
|
+
await storage.updateMany({ a: value });
|
|
2281
|
+
expect(await storage.getMany(["a"])).toEqual({ a: value });
|
|
2282
|
+
});
|
|
2283
|
+
test("Should work with negative integer", async () => {
|
|
2284
|
+
const value = -1;
|
|
2285
|
+
await storage.add("a", -1);
|
|
2286
|
+
await storage.updateMany({ a: value });
|
|
2287
|
+
expect(await storage.getMany(["a"])).toEqual({ a: value });
|
|
2288
|
+
});
|
|
2289
|
+
test("Should work with positive decimal", async () => {
|
|
2290
|
+
const value = 1.5;
|
|
2291
|
+
await storage.add("a", -1);
|
|
2292
|
+
await storage.updateMany({ a: value });
|
|
2293
|
+
expect(await storage.getMany(["a"])).toEqual({ a: value });
|
|
2294
|
+
});
|
|
2295
|
+
test("Should work with negative decimal", async () => {
|
|
2296
|
+
const value = -1.5;
|
|
2297
|
+
await storage.add("a", -1);
|
|
2298
|
+
await storage.updateMany({ a: value });
|
|
2299
|
+
expect(await storage.getMany(["a"])).toEqual({ a: value });
|
|
2300
|
+
});
|
|
2301
|
+
test("Should work with NaN", async () => {
|
|
2302
|
+
const value = NaN;
|
|
2303
|
+
await storage.add("a", -1);
|
|
2304
|
+
await storage.updateMany({ a: value });
|
|
2305
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
2306
|
+
expect(getResult).toBeNaN();
|
|
2307
|
+
});
|
|
2308
|
+
test("Should work with Infinity", async () => {
|
|
2309
|
+
const value = Infinity;
|
|
2310
|
+
await storage.add("a", -1);
|
|
2311
|
+
await storage.updateMany({ a: value });
|
|
2312
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
2313
|
+
expect(isFinite(getResult)).toBe(false);
|
|
2314
|
+
});
|
|
2315
|
+
test("Should work with Bigint", async () => {
|
|
2316
|
+
const value = 20n;
|
|
2317
|
+
await storage.add("a", -1);
|
|
2318
|
+
await storage.updateMany({ a: value });
|
|
2319
|
+
expect(await storage.getMany(["a"])).toEqual({ a: value });
|
|
2320
|
+
});
|
|
2321
|
+
test("Should work with true", async () => {
|
|
2322
|
+
const value = true;
|
|
2323
|
+
await storage.add("a", -1);
|
|
2324
|
+
await storage.updateMany({ a: value });
|
|
2325
|
+
expect(await storage.getMany(["a"])).toEqual({ a: value });
|
|
2326
|
+
});
|
|
2327
|
+
test("Should work with false", async () => {
|
|
2328
|
+
const value = false;
|
|
2329
|
+
await storage.add("a", -1);
|
|
2330
|
+
await storage.updateMany({ a: value });
|
|
2331
|
+
expect(await storage.getMany(["a"])).toEqual({ a: value });
|
|
2332
|
+
});
|
|
2333
|
+
test("Should work with string", async () => {
|
|
2334
|
+
const value = "str";
|
|
2335
|
+
await storage.add("a", -1);
|
|
2336
|
+
await storage.updateMany({ a: value });
|
|
2337
|
+
expect(await storage.getMany(["a"])).toEqual({ a: value });
|
|
2338
|
+
});
|
|
2339
|
+
test("Should work with Date", async () => {
|
|
2340
|
+
const value = new Date("2024-01-01");
|
|
2341
|
+
await storage.add("a", -1);
|
|
2342
|
+
await storage.updateMany({ a: value });
|
|
2343
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
2344
|
+
expect(getResult).toBeInstanceOf(Date);
|
|
2345
|
+
expect(getResult).toEqual(value);
|
|
2346
|
+
});
|
|
2347
|
+
test("Should work with RegExp", async () => {
|
|
2348
|
+
const value = /test/;
|
|
2349
|
+
await storage.add("a", -1);
|
|
2350
|
+
await storage.updateMany({ a: value });
|
|
2351
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
2352
|
+
expect(getResult).toBeInstanceOf(RegExp);
|
|
2353
|
+
expect(getResult).toEqual(value);
|
|
2354
|
+
});
|
|
2355
|
+
test("Should work with Buffer", async () => {
|
|
2356
|
+
const value = Buffer.from("asd");
|
|
2357
|
+
await storage.add("a", -1);
|
|
2358
|
+
await storage.updateMany({ a: value });
|
|
2359
|
+
const { a: getResult } = await storage.getMany([
|
|
2360
|
+
"a",
|
|
2361
|
+
]);
|
|
2362
|
+
expect(getResult).toBeInstanceOf(Buffer);
|
|
2363
|
+
expect(getResult?.toString("base64")).toEqual(value.toString("base64"));
|
|
2364
|
+
});
|
|
2365
|
+
test("Should work with Uint8Array", async () => {
|
|
2366
|
+
const value = new Uint8Array(Buffer.from("asd"));
|
|
2367
|
+
await storage.add("a", -1);
|
|
2368
|
+
await storage.updateMany({ a: value });
|
|
2369
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
2370
|
+
expect(getResult).toBeInstanceOf(Uint8Array);
|
|
2371
|
+
expect(getResult
|
|
2372
|
+
? Buffer.from(getResult).toString("base64")
|
|
2373
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
2374
|
+
});
|
|
2375
|
+
test("Should work with Int8Array", async () => {
|
|
2376
|
+
const value = new Int8Array(Buffer.from("asd"));
|
|
2377
|
+
await storage.add("a", -1);
|
|
2378
|
+
await storage.updateMany({ a: value });
|
|
2379
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
2380
|
+
expect(getResult).toBeInstanceOf(Int8Array);
|
|
2381
|
+
expect(getResult
|
|
2382
|
+
? Buffer.from(getResult).toString("base64")
|
|
2383
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
2384
|
+
});
|
|
2385
|
+
test("Should work with Uint16Array", async () => {
|
|
2386
|
+
const value = new Uint16Array(Buffer.from("asd"));
|
|
2387
|
+
await storage.add("a", -1);
|
|
2388
|
+
await storage.updateMany({ a: value });
|
|
2389
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
2390
|
+
expect(getResult).toBeInstanceOf(Uint16Array);
|
|
2391
|
+
expect(getResult
|
|
2392
|
+
? Buffer.from(getResult).toString("base64")
|
|
2393
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
2394
|
+
});
|
|
2395
|
+
test("Should work with Int16Array", async () => {
|
|
2396
|
+
const value = new Int16Array(Buffer.from("asd"));
|
|
2397
|
+
await storage.add("a", -1);
|
|
2398
|
+
await storage.updateMany({ a: value });
|
|
2399
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
2400
|
+
expect(getResult).toBeInstanceOf(Int16Array);
|
|
2401
|
+
expect(getResult
|
|
2402
|
+
? Buffer.from(getResult).toString("base64")
|
|
2403
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
2404
|
+
});
|
|
2405
|
+
test("Should work with Uint32Array", async () => {
|
|
2406
|
+
const value = new Uint32Array(Buffer.from("asd"));
|
|
2407
|
+
await storage.add("a", -1);
|
|
2408
|
+
await storage.updateMany({ a: value });
|
|
2409
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
2410
|
+
expect(getResult).toBeInstanceOf(Uint32Array);
|
|
2411
|
+
expect(getResult
|
|
2412
|
+
? Buffer.from(getResult).toString("base64")
|
|
2413
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
2414
|
+
});
|
|
2415
|
+
test("Should work with Int32Array", async () => {
|
|
2416
|
+
const value = new Int32Array(Buffer.from("asd"));
|
|
2417
|
+
await storage.add("a", -1);
|
|
2418
|
+
await storage.updateMany({ a: value });
|
|
2419
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
2420
|
+
expect(getResult).toBeInstanceOf(Int32Array);
|
|
2421
|
+
expect(getResult
|
|
2422
|
+
? Buffer.from(getResult).toString("base64")
|
|
2423
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
2424
|
+
});
|
|
2425
|
+
test("Should work with Float32Array", async () => {
|
|
2426
|
+
const value = new Float32Array(Buffer.from("asd"));
|
|
2427
|
+
await storage.add("a", -1);
|
|
2428
|
+
await storage.updateMany({ a: value });
|
|
2429
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
2430
|
+
expect(getResult).toBeInstanceOf(Float32Array);
|
|
2431
|
+
expect(getResult
|
|
2432
|
+
? Buffer.from(getResult).toString("base64")
|
|
2433
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
2434
|
+
});
|
|
2435
|
+
test("Should work with Float64Array", async () => {
|
|
2436
|
+
const value = new Float64Array(Buffer.from("asd"));
|
|
2437
|
+
await storage.add("a", -1);
|
|
2438
|
+
await storage.updateMany({ a: value });
|
|
2439
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
2440
|
+
expect(getResult).toBeInstanceOf(Float64Array);
|
|
2441
|
+
expect(getResult
|
|
2442
|
+
? Buffer.from(getResult).toString("base64")
|
|
2443
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
2444
|
+
});
|
|
2445
|
+
test("Should work with Set", async () => {
|
|
2446
|
+
const value = new Set(["a", "b", "c"]);
|
|
2447
|
+
await storage.add("a", -1);
|
|
2448
|
+
await storage.updateMany({ a: value });
|
|
2449
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
2450
|
+
expect(getResult).toBeInstanceOf(Set);
|
|
2451
|
+
expect(getResult).toEqual(value);
|
|
2452
|
+
});
|
|
2453
|
+
test("Should work with Set of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays", async () => {
|
|
2454
|
+
const value = new Set([
|
|
2455
|
+
0,
|
|
2456
|
+
-1,
|
|
2457
|
+
1,
|
|
2458
|
+
-1.5,
|
|
2459
|
+
1.5,
|
|
2460
|
+
NaN,
|
|
2461
|
+
Infinity,
|
|
2462
|
+
2n,
|
|
2463
|
+
true,
|
|
2464
|
+
false,
|
|
2465
|
+
"str",
|
|
2466
|
+
new Date("2024-01-01"),
|
|
2467
|
+
new Set(["a", "b", "c"]),
|
|
2468
|
+
new Map([
|
|
2469
|
+
["a", 1],
|
|
2470
|
+
["b", 2],
|
|
2471
|
+
["c", 3],
|
|
2472
|
+
]),
|
|
2473
|
+
{ a: 1, b: 2 },
|
|
2474
|
+
[1, 2, 3],
|
|
2475
|
+
/test/,
|
|
2476
|
+
]);
|
|
2477
|
+
await storage.add("a", -1);
|
|
2478
|
+
await storage.updateMany({ a: value });
|
|
2479
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
2480
|
+
expect(getResult).toBeInstanceOf(Set);
|
|
2481
|
+
expect(getResult).toEqual(value);
|
|
2482
|
+
});
|
|
2483
|
+
test("Should work with Map", async () => {
|
|
2484
|
+
const value = new Map([
|
|
2485
|
+
["a", 1],
|
|
2486
|
+
["b", 2],
|
|
2487
|
+
["c", 3],
|
|
2488
|
+
]);
|
|
2489
|
+
await storage.add("a", -1);
|
|
2490
|
+
await storage.updateMany({ a: value });
|
|
2491
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
2492
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
2493
|
+
expect(getResult).toEqual(value);
|
|
2494
|
+
});
|
|
2495
|
+
test("Should work with Map of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays values", async () => {
|
|
2496
|
+
const value = new Map([
|
|
2497
|
+
["a", 0],
|
|
2498
|
+
["b", -1],
|
|
2499
|
+
["c", 1],
|
|
2500
|
+
["d", -1.5],
|
|
2501
|
+
["e", 1.5],
|
|
2502
|
+
["f", NaN],
|
|
2503
|
+
["g", Infinity],
|
|
2504
|
+
["h", 2n],
|
|
2505
|
+
["j", true],
|
|
2506
|
+
["l", false],
|
|
2507
|
+
["i", "str"],
|
|
2508
|
+
["r", new Date("2024-01-01")],
|
|
2509
|
+
["k", new Set(["a", "b", "c"])],
|
|
2510
|
+
[
|
|
2511
|
+
"p",
|
|
2512
|
+
new Map([
|
|
2513
|
+
["a", 1],
|
|
2514
|
+
["b", 2],
|
|
2515
|
+
["c", 3],
|
|
2516
|
+
]),
|
|
2517
|
+
],
|
|
2518
|
+
["a", /test/],
|
|
2519
|
+
[1, { a: 2, b: -1 }],
|
|
2520
|
+
[2, [1, 2, 3]],
|
|
2521
|
+
]);
|
|
2522
|
+
await storage.add("a", -1);
|
|
2523
|
+
await storage.updateMany({ a: value });
|
|
2524
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
2525
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
2526
|
+
expect(getResult).toEqual(value);
|
|
2527
|
+
});
|
|
2528
|
+
test("Should work with Map of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays keys", async () => {
|
|
2529
|
+
const value = new Map([
|
|
2530
|
+
[0, "a"],
|
|
2531
|
+
[-1, "a"],
|
|
2532
|
+
[1, "a"],
|
|
2533
|
+
[-1.5, "a"],
|
|
2534
|
+
[1.5, "a"],
|
|
2535
|
+
[NaN, "a"],
|
|
2536
|
+
[Infinity, "a"],
|
|
2537
|
+
[2n, "a"],
|
|
2538
|
+
[true, "a"],
|
|
2539
|
+
[false, "a"],
|
|
2540
|
+
["str", "a"],
|
|
2541
|
+
[new Date("2024-01-01"), "a"],
|
|
2542
|
+
[new Set(["a", "b", "c"]), "a"],
|
|
2543
|
+
[
|
|
2544
|
+
new Map([
|
|
2545
|
+
["a", 1],
|
|
2546
|
+
["b", 2],
|
|
2547
|
+
["c", 3],
|
|
2548
|
+
]),
|
|
2549
|
+
"a",
|
|
2550
|
+
],
|
|
2551
|
+
[/test/, "a"],
|
|
2552
|
+
[{ a: 2, b: -1 }, 1],
|
|
2553
|
+
[[1, 2, 3], 2],
|
|
2554
|
+
]);
|
|
2555
|
+
await storage.add("a", -1);
|
|
2556
|
+
await storage.updateMany({ a: value });
|
|
2557
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
2558
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
2559
|
+
expect(getResult).toEqual(value);
|
|
2560
|
+
});
|
|
2561
|
+
test("Should work with array of number, boolean, string, Date, Set, Map, RegExp", async () => {
|
|
2562
|
+
const value = [
|
|
2563
|
+
0,
|
|
2564
|
+
-1,
|
|
2565
|
+
1,
|
|
2566
|
+
-1.5,
|
|
2567
|
+
1.5,
|
|
2568
|
+
NaN,
|
|
2569
|
+
Infinity,
|
|
2570
|
+
2n,
|
|
2571
|
+
true,
|
|
2572
|
+
false,
|
|
2573
|
+
"str",
|
|
2574
|
+
new Date("2024-01-01"),
|
|
2575
|
+
new Set(["a", "b", "c"]),
|
|
2576
|
+
new Map([
|
|
2577
|
+
["a", 1],
|
|
2578
|
+
["b", 2],
|
|
2579
|
+
["c", 3],
|
|
2580
|
+
]),
|
|
2581
|
+
/test/,
|
|
2582
|
+
];
|
|
2583
|
+
await storage.add("a", -1);
|
|
2584
|
+
await storage.updateMany({ a: value });
|
|
2585
|
+
const getResult = await storage.getMany(["a"]);
|
|
2586
|
+
expect(getResult).toEqual({ a: value });
|
|
2587
|
+
});
|
|
2588
|
+
test("Should work with array of objects", async () => {
|
|
2589
|
+
const value = [
|
|
2590
|
+
Object.fromEntries([
|
|
2591
|
+
["a", 0],
|
|
2592
|
+
["b", -1],
|
|
2593
|
+
["c", 1],
|
|
2594
|
+
["d", -1.5],
|
|
2595
|
+
["e", 1.5],
|
|
2596
|
+
["f", NaN],
|
|
2597
|
+
["g", Infinity],
|
|
2598
|
+
["h", 2n],
|
|
2599
|
+
["j", true],
|
|
2600
|
+
["l", false],
|
|
2601
|
+
["i", "str"],
|
|
2602
|
+
["r", new Date("2024-01-01")],
|
|
2603
|
+
["k", new Set(["a", "b", "c"])],
|
|
2604
|
+
[
|
|
2605
|
+
"p",
|
|
2606
|
+
new Map([
|
|
2607
|
+
["a", 1],
|
|
2608
|
+
["b", 2],
|
|
2609
|
+
["c", 3],
|
|
2610
|
+
]),
|
|
2611
|
+
],
|
|
2612
|
+
["a", /test/],
|
|
2613
|
+
]),
|
|
2614
|
+
];
|
|
2615
|
+
await storage.add("a", -1);
|
|
2616
|
+
await storage.updateMany({ a: value });
|
|
2617
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
2618
|
+
expect(getResult).toEqual(value);
|
|
2619
|
+
});
|
|
2620
|
+
test("Should work with object of number, boolean, string, Date, Set, Map, RegExp", async () => {
|
|
2621
|
+
const value = Object.fromEntries([
|
|
2622
|
+
["a", 0],
|
|
2623
|
+
["b", -1],
|
|
2624
|
+
["c", 1],
|
|
2625
|
+
["d", -1.5],
|
|
2626
|
+
["e", 1.5],
|
|
2627
|
+
["f", NaN],
|
|
2628
|
+
["g", Infinity],
|
|
2629
|
+
["h", 2n],
|
|
2630
|
+
["j", true],
|
|
2631
|
+
["l", false],
|
|
2632
|
+
["i", "str"],
|
|
2633
|
+
["r", new Date("2024-01-01")],
|
|
2634
|
+
["k", new Set(["a", "b", "c"])],
|
|
2635
|
+
[
|
|
2636
|
+
"p",
|
|
2637
|
+
new Map([
|
|
2638
|
+
["a", 1],
|
|
2639
|
+
["b", 2],
|
|
2640
|
+
["c", 3],
|
|
2641
|
+
]),
|
|
2642
|
+
],
|
|
2643
|
+
["a", /test/],
|
|
2644
|
+
]);
|
|
2645
|
+
await storage.add("a", -1);
|
|
2646
|
+
await storage.updateMany({ a: value });
|
|
2647
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
2648
|
+
expect(getResult).toEqual(value);
|
|
2649
|
+
});
|
|
2650
|
+
test("Should work with object of arrays", async () => {
|
|
2651
|
+
const value = {
|
|
2652
|
+
a: [
|
|
2653
|
+
0,
|
|
2654
|
+
-1,
|
|
2655
|
+
1,
|
|
2656
|
+
-1.5,
|
|
2657
|
+
1.5,
|
|
2658
|
+
NaN,
|
|
2659
|
+
Infinity,
|
|
2660
|
+
2n,
|
|
2661
|
+
true,
|
|
2662
|
+
false,
|
|
2663
|
+
"str",
|
|
2664
|
+
new Date("2024-01-01"),
|
|
2665
|
+
new Set(["a", "b", "c"]),
|
|
2666
|
+
new Map([
|
|
2667
|
+
["a", 1],
|
|
2668
|
+
["b", 2],
|
|
2669
|
+
["c", 3],
|
|
2670
|
+
]),
|
|
2671
|
+
/test/,
|
|
2672
|
+
],
|
|
2673
|
+
};
|
|
2674
|
+
await storage.add("a", -1);
|
|
2675
|
+
await storage.updateMany({ a: value });
|
|
2676
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
2677
|
+
expect(getResult).toEqual(value);
|
|
2678
|
+
});
|
|
2679
|
+
});
|
|
2680
|
+
describe("method: put", () => {
|
|
2681
|
+
test("Should work with positive integer", async () => {
|
|
2682
|
+
const value = 1;
|
|
2683
|
+
await storage.put("a", value);
|
|
2684
|
+
expect(await storage.get("a")).toBe(value);
|
|
2685
|
+
});
|
|
2686
|
+
test("Should work with negative integer", async () => {
|
|
2687
|
+
const value = -1;
|
|
2688
|
+
await storage.put("a", value);
|
|
2689
|
+
expect(await storage.get("a")).toBe(value);
|
|
2690
|
+
});
|
|
2691
|
+
test("Should work with positive decimal", async () => {
|
|
2692
|
+
const value = 1.5;
|
|
2693
|
+
await storage.put("a", value);
|
|
2694
|
+
expect(await storage.get("a")).toBe(value);
|
|
2695
|
+
});
|
|
2696
|
+
test("Should work with negative decimal", async () => {
|
|
2697
|
+
const value = -1.5;
|
|
2698
|
+
await storage.put("a", value);
|
|
2699
|
+
expect(await storage.get("a")).toBe(value);
|
|
2700
|
+
});
|
|
2701
|
+
test("Should work with NaN", async () => {
|
|
2702
|
+
const value = NaN;
|
|
2703
|
+
await storage.put("a", value);
|
|
2704
|
+
const getResult = await storage.get("a");
|
|
2705
|
+
expect(getResult).toBeNaN();
|
|
2706
|
+
});
|
|
2707
|
+
test("Should work with Infinity", async () => {
|
|
2708
|
+
const value = Infinity;
|
|
2709
|
+
await storage.put("a", value);
|
|
2710
|
+
const getResult = await storage.get("a");
|
|
2711
|
+
expect(isFinite(getResult)).toBe(false);
|
|
2712
|
+
});
|
|
2713
|
+
test("Should work with Bigint", async () => {
|
|
2714
|
+
const value = 20n;
|
|
2715
|
+
await storage.put("a", value);
|
|
2716
|
+
expect(await storage.get("a")).toBe(value);
|
|
2717
|
+
});
|
|
2718
|
+
test("Should work with true", async () => {
|
|
2719
|
+
const value = true;
|
|
2720
|
+
await storage.put("a", value);
|
|
2721
|
+
expect(await storage.get("a")).toBe(value);
|
|
2722
|
+
});
|
|
2723
|
+
test("Should work with false", async () => {
|
|
2724
|
+
const value = false;
|
|
2725
|
+
await storage.put("a", value);
|
|
2726
|
+
expect(await storage.get("a")).toBe(value);
|
|
2727
|
+
});
|
|
2728
|
+
test("Should work with string", async () => {
|
|
2729
|
+
const value = "str";
|
|
2730
|
+
await storage.put("a", value);
|
|
2731
|
+
expect(await storage.get("a")).toBe(value);
|
|
2732
|
+
});
|
|
2733
|
+
test("Should work with Date", async () => {
|
|
2734
|
+
const value = new Date("2024-01-01");
|
|
2735
|
+
await storage.put("a", value);
|
|
2736
|
+
const getResult = await storage.get("a");
|
|
2737
|
+
expect(getResult).toBeInstanceOf(Date);
|
|
2738
|
+
expect(getResult).toEqual(value);
|
|
2739
|
+
});
|
|
2740
|
+
test("Should work with RegExp", async () => {
|
|
2741
|
+
const value = /test/;
|
|
2742
|
+
await storage.put("a", value);
|
|
2743
|
+
const getResult = await storage.get("a");
|
|
2744
|
+
expect(getResult).toBeInstanceOf(RegExp);
|
|
2745
|
+
expect(getResult).toEqual(value);
|
|
2746
|
+
});
|
|
2747
|
+
test("Should work with Buffer", async () => {
|
|
2748
|
+
const value = Buffer.from("asd");
|
|
2749
|
+
await storage.put("a", value);
|
|
2750
|
+
const getResult = await storage.get("a");
|
|
2751
|
+
expect(getResult).toBeInstanceOf(Buffer);
|
|
2752
|
+
expect(getResult?.toString("base64")).toEqual(value.toString("base64"));
|
|
2753
|
+
});
|
|
2754
|
+
test("Should work with Uint8Array", async () => {
|
|
2755
|
+
const value = new Uint8Array(Buffer.from("asd"));
|
|
2756
|
+
await storage.put("a", value);
|
|
2757
|
+
const getResult = await storage.get("a");
|
|
2758
|
+
expect(getResult).toBeInstanceOf(Uint8Array);
|
|
2759
|
+
expect(getResult
|
|
2760
|
+
? Buffer.from(getResult).toString("base64")
|
|
2761
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
2762
|
+
});
|
|
2763
|
+
test("Should work with Int8Array", async () => {
|
|
2764
|
+
const value = new Int8Array(Buffer.from("asd"));
|
|
2765
|
+
await storage.put("a", value);
|
|
2766
|
+
const getResult = await storage.get("a");
|
|
2767
|
+
expect(getResult).toBeInstanceOf(Int8Array);
|
|
2768
|
+
expect(getResult
|
|
2769
|
+
? Buffer.from(getResult).toString("base64")
|
|
2770
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
2771
|
+
});
|
|
2772
|
+
test("Should work with Uint16Array", async () => {
|
|
2773
|
+
const value = new Uint16Array(Buffer.from("asd"));
|
|
2774
|
+
await storage.put("a", value);
|
|
2775
|
+
const getResult = await storage.get("a");
|
|
2776
|
+
expect(getResult).toBeInstanceOf(Uint16Array);
|
|
2777
|
+
expect(getResult
|
|
2778
|
+
? Buffer.from(getResult).toString("base64")
|
|
2779
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
2780
|
+
});
|
|
2781
|
+
test("Should work with Int16Array", async () => {
|
|
2782
|
+
const value = new Int16Array(Buffer.from("asd"));
|
|
2783
|
+
await storage.put("a", value);
|
|
2784
|
+
const getResult = await storage.get("a");
|
|
2785
|
+
expect(getResult).toBeInstanceOf(Int16Array);
|
|
2786
|
+
expect(getResult
|
|
2787
|
+
? Buffer.from(getResult).toString("base64")
|
|
2788
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
2789
|
+
});
|
|
2790
|
+
test("Should work with Uint32Array", async () => {
|
|
2791
|
+
const value = new Uint32Array(Buffer.from("asd"));
|
|
2792
|
+
await storage.put("a", value);
|
|
2793
|
+
const getResult = await storage.get("a");
|
|
2794
|
+
expect(getResult).toBeInstanceOf(Uint32Array);
|
|
2795
|
+
expect(getResult
|
|
2796
|
+
? Buffer.from(getResult).toString("base64")
|
|
2797
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
2798
|
+
});
|
|
2799
|
+
test("Should work with Int32Array", async () => {
|
|
2800
|
+
const value = new Int32Array(Buffer.from("asd"));
|
|
2801
|
+
await storage.put("a", value);
|
|
2802
|
+
const getResult = await storage.get("a");
|
|
2803
|
+
expect(getResult).toBeInstanceOf(Int32Array);
|
|
2804
|
+
expect(getResult
|
|
2805
|
+
? Buffer.from(getResult).toString("base64")
|
|
2806
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
2807
|
+
});
|
|
2808
|
+
test("Should work with Float32Array", async () => {
|
|
2809
|
+
const value = new Float32Array(Buffer.from("asd"));
|
|
2810
|
+
await storage.put("a", value);
|
|
2811
|
+
const getResult = await storage.get("a");
|
|
2812
|
+
expect(getResult).toBeInstanceOf(Float32Array);
|
|
2813
|
+
expect(getResult
|
|
2814
|
+
? Buffer.from(getResult).toString("base64")
|
|
2815
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
2816
|
+
});
|
|
2817
|
+
test("Should work with Float64Array", async () => {
|
|
2818
|
+
const value = new Float64Array(Buffer.from("asd"));
|
|
2819
|
+
await storage.put("a", value);
|
|
2820
|
+
const getResult = await storage.get("a");
|
|
2821
|
+
expect(getResult).toBeInstanceOf(Float64Array);
|
|
2822
|
+
expect(getResult
|
|
2823
|
+
? Buffer.from(getResult).toString("base64")
|
|
2824
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
2825
|
+
});
|
|
2826
|
+
test("Should work with Set", async () => {
|
|
2827
|
+
const value = new Set(["a", "b", "c"]);
|
|
2828
|
+
await storage.put("a", value);
|
|
2829
|
+
const getResult = await storage.get("a");
|
|
2830
|
+
expect(getResult).toBeInstanceOf(Set);
|
|
2831
|
+
expect(getResult).toEqual(value);
|
|
2832
|
+
});
|
|
2833
|
+
test("Should work with Set of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays", async () => {
|
|
2834
|
+
const value = new Set([
|
|
2835
|
+
0,
|
|
2836
|
+
-1,
|
|
2837
|
+
1,
|
|
2838
|
+
-1.5,
|
|
2839
|
+
1.5,
|
|
2840
|
+
NaN,
|
|
2841
|
+
Infinity,
|
|
2842
|
+
2n,
|
|
2843
|
+
true,
|
|
2844
|
+
false,
|
|
2845
|
+
"str",
|
|
2846
|
+
new Date("2024-01-01"),
|
|
2847
|
+
new Set(["a", "b", "c"]),
|
|
2848
|
+
new Map([
|
|
2849
|
+
["a", 1],
|
|
2850
|
+
["b", 2],
|
|
2851
|
+
["c", 3],
|
|
2852
|
+
]),
|
|
2853
|
+
{ a: 1, b: 2 },
|
|
2854
|
+
[1, 2, 3],
|
|
2855
|
+
/test/,
|
|
2856
|
+
]);
|
|
2857
|
+
await storage.put("a", value);
|
|
2858
|
+
const getResult = await storage.get("a");
|
|
2859
|
+
expect(getResult).toBeInstanceOf(Set);
|
|
2860
|
+
expect(getResult).toEqual(value);
|
|
2861
|
+
});
|
|
2862
|
+
test("Should work with Map", async () => {
|
|
2863
|
+
const value = new Map([
|
|
2864
|
+
["a", 1],
|
|
2865
|
+
["b", 2],
|
|
2866
|
+
["c", 3],
|
|
2867
|
+
]);
|
|
2868
|
+
await storage.put("a", value);
|
|
2869
|
+
const getResult = await storage.get("a");
|
|
2870
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
2871
|
+
expect(getResult).toEqual(value);
|
|
2872
|
+
});
|
|
2873
|
+
test("Should work with Map of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays values", async () => {
|
|
2874
|
+
const value = new Map([
|
|
2875
|
+
["a", 0],
|
|
2876
|
+
["b", -1],
|
|
2877
|
+
["c", 1],
|
|
2878
|
+
["d", -1.5],
|
|
2879
|
+
["e", 1.5],
|
|
2880
|
+
["f", NaN],
|
|
2881
|
+
["g", Infinity],
|
|
2882
|
+
["h", 2n],
|
|
2883
|
+
["j", true],
|
|
2884
|
+
["l", false],
|
|
2885
|
+
["i", "str"],
|
|
2886
|
+
["r", new Date("2024-01-01")],
|
|
2887
|
+
["k", new Set(["a", "b", "c"])],
|
|
2888
|
+
[
|
|
2889
|
+
"p",
|
|
2890
|
+
new Map([
|
|
2891
|
+
["a", 1],
|
|
2892
|
+
["b", 2],
|
|
2893
|
+
["c", 3],
|
|
2894
|
+
]),
|
|
2895
|
+
],
|
|
2896
|
+
["a", /test/],
|
|
2897
|
+
[1, { a: 2, b: -1 }],
|
|
2898
|
+
[2, [1, 2, 3]],
|
|
2899
|
+
]);
|
|
2900
|
+
await storage.put("a", value);
|
|
2901
|
+
const getResult = await storage.get("a");
|
|
2902
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
2903
|
+
expect(getResult).toEqual(value);
|
|
2904
|
+
});
|
|
2905
|
+
test("Should work with Map of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays keys", async () => {
|
|
2906
|
+
const value = new Map([
|
|
2907
|
+
[0, "a"],
|
|
2908
|
+
[-1, "a"],
|
|
2909
|
+
[1, "a"],
|
|
2910
|
+
[-1.5, "a"],
|
|
2911
|
+
[1.5, "a"],
|
|
2912
|
+
[NaN, "a"],
|
|
2913
|
+
[Infinity, "a"],
|
|
2914
|
+
[2n, "a"],
|
|
2915
|
+
[true, "a"],
|
|
2916
|
+
[false, "a"],
|
|
2917
|
+
["str", "a"],
|
|
2918
|
+
[new Date("2024-01-01"), "a"],
|
|
2919
|
+
[new Set(["a", "b", "c"]), "a"],
|
|
2920
|
+
[
|
|
2921
|
+
new Map([
|
|
2922
|
+
["a", 1],
|
|
2923
|
+
["b", 2],
|
|
2924
|
+
["c", 3],
|
|
2925
|
+
]),
|
|
2926
|
+
"a",
|
|
2927
|
+
],
|
|
2928
|
+
[/test/, "a"],
|
|
2929
|
+
[{ a: 2, b: -1 }, 1],
|
|
2930
|
+
[[1, 2, 3], 2],
|
|
2931
|
+
]);
|
|
2932
|
+
await storage.put("a", value);
|
|
2933
|
+
const getResult = await storage.get("a");
|
|
2934
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
2935
|
+
expect(getResult).toEqual(value);
|
|
2936
|
+
});
|
|
2937
|
+
test("Should work with array of number, boolean, string, Date, Set, Map, RegExp", async () => {
|
|
2938
|
+
const value = [
|
|
2939
|
+
0,
|
|
2940
|
+
-1,
|
|
2941
|
+
1,
|
|
2942
|
+
-1.5,
|
|
2943
|
+
1.5,
|
|
2944
|
+
NaN,
|
|
2945
|
+
Infinity,
|
|
2946
|
+
2n,
|
|
2947
|
+
true,
|
|
2948
|
+
false,
|
|
2949
|
+
"str",
|
|
2950
|
+
new Date("2024-01-01"),
|
|
2951
|
+
new Set(["a", "b", "c"]),
|
|
2952
|
+
new Map([
|
|
2953
|
+
["a", 1],
|
|
2954
|
+
["b", 2],
|
|
2955
|
+
["c", 3],
|
|
2956
|
+
]),
|
|
2957
|
+
/test/,
|
|
2958
|
+
];
|
|
2959
|
+
await storage.put("a", value);
|
|
2960
|
+
const getResult = await storage.get("a");
|
|
2961
|
+
expect(getResult).toEqual(value);
|
|
2962
|
+
});
|
|
2963
|
+
test("Should work with array of objects", async () => {
|
|
2964
|
+
const value = [
|
|
2965
|
+
Object.fromEntries([
|
|
2966
|
+
["a", 0],
|
|
2967
|
+
["b", -1],
|
|
2968
|
+
["c", 1],
|
|
2969
|
+
["d", -1.5],
|
|
2970
|
+
["e", 1.5],
|
|
2971
|
+
["f", NaN],
|
|
2972
|
+
["g", Infinity],
|
|
2973
|
+
["h", 2n],
|
|
2974
|
+
["j", true],
|
|
2975
|
+
["l", false],
|
|
2976
|
+
["i", "str"],
|
|
2977
|
+
["r", new Date("2024-01-01")],
|
|
2978
|
+
["k", new Set(["a", "b", "c"])],
|
|
2979
|
+
[
|
|
2980
|
+
"p",
|
|
2981
|
+
new Map([
|
|
2982
|
+
["a", 1],
|
|
2983
|
+
["b", 2],
|
|
2984
|
+
["c", 3],
|
|
2985
|
+
]),
|
|
2986
|
+
],
|
|
2987
|
+
["a", /test/],
|
|
2988
|
+
]),
|
|
2989
|
+
];
|
|
2990
|
+
await storage.put("a", value);
|
|
2991
|
+
const getResult = await storage.get("a");
|
|
2992
|
+
expect(getResult).toEqual(value);
|
|
2993
|
+
});
|
|
2994
|
+
test("Should work with object of number, boolean, string, Date, Set, Map, RegExp", async () => {
|
|
2995
|
+
const value = Object.fromEntries([
|
|
2996
|
+
["a", 0],
|
|
2997
|
+
["b", -1],
|
|
2998
|
+
["c", 1],
|
|
2999
|
+
["d", -1.5],
|
|
3000
|
+
["e", 1.5],
|
|
3001
|
+
["f", NaN],
|
|
3002
|
+
["g", Infinity],
|
|
3003
|
+
["h", 2n],
|
|
3004
|
+
["j", true],
|
|
3005
|
+
["l", false],
|
|
3006
|
+
["i", "str"],
|
|
3007
|
+
["r", new Date("2024-01-01")],
|
|
3008
|
+
["k", new Set(["a", "b", "c"])],
|
|
3009
|
+
[
|
|
3010
|
+
"p",
|
|
3011
|
+
new Map([
|
|
3012
|
+
["a", 1],
|
|
3013
|
+
["b", 2],
|
|
3014
|
+
["c", 3],
|
|
3015
|
+
]),
|
|
3016
|
+
],
|
|
3017
|
+
["a", /test/],
|
|
3018
|
+
]);
|
|
3019
|
+
await storage.put("a", value);
|
|
3020
|
+
const getResult = await storage.get("a");
|
|
3021
|
+
expect(getResult).toEqual(value);
|
|
3022
|
+
});
|
|
3023
|
+
test("Should work with object of arrays", async () => {
|
|
3024
|
+
const value = {
|
|
3025
|
+
a: [
|
|
3026
|
+
0,
|
|
3027
|
+
-1,
|
|
3028
|
+
1,
|
|
3029
|
+
-1.5,
|
|
3030
|
+
1.5,
|
|
3031
|
+
NaN,
|
|
3032
|
+
Infinity,
|
|
3033
|
+
2n,
|
|
3034
|
+
true,
|
|
3035
|
+
false,
|
|
3036
|
+
"str",
|
|
3037
|
+
new Date("2024-01-01"),
|
|
3038
|
+
new Set(["a", "b", "c"]),
|
|
3039
|
+
new Map([
|
|
3040
|
+
["a", 1],
|
|
3041
|
+
["b", 2],
|
|
3042
|
+
["c", 3],
|
|
3043
|
+
]),
|
|
3044
|
+
/test/,
|
|
3045
|
+
],
|
|
3046
|
+
};
|
|
3047
|
+
await storage.put("a", value);
|
|
3048
|
+
const getResult = await storage.get("a");
|
|
3049
|
+
expect(getResult).toEqual(value);
|
|
3050
|
+
});
|
|
3051
|
+
});
|
|
3052
|
+
describe("method: putMany", () => {
|
|
3053
|
+
test("Should work with positive integer", async () => {
|
|
3054
|
+
const value = 1;
|
|
3055
|
+
await storage.putMany({ a: value });
|
|
3056
|
+
expect(await storage.getMany(["a"])).toEqual({ a: value });
|
|
3057
|
+
});
|
|
3058
|
+
test("Should work with negative integer", async () => {
|
|
3059
|
+
const value = -1;
|
|
3060
|
+
await storage.putMany({ a: value });
|
|
3061
|
+
expect(await storage.getMany(["a"])).toEqual({ a: value });
|
|
3062
|
+
});
|
|
3063
|
+
test("Should work with positive decimal", async () => {
|
|
3064
|
+
const value = 1.5;
|
|
3065
|
+
await storage.putMany({ a: value });
|
|
3066
|
+
expect(await storage.getMany(["a"])).toEqual({ a: value });
|
|
3067
|
+
});
|
|
3068
|
+
test("Should work with negative decimal", async () => {
|
|
3069
|
+
const value = -1.5;
|
|
3070
|
+
await storage.putMany({ a: value });
|
|
3071
|
+
expect(await storage.getMany(["a"])).toEqual({ a: value });
|
|
3072
|
+
});
|
|
3073
|
+
test("Should work with NaN", async () => {
|
|
3074
|
+
const value = NaN;
|
|
3075
|
+
await storage.putMany({ a: value });
|
|
3076
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
3077
|
+
expect(getResult).toBeNaN();
|
|
3078
|
+
});
|
|
3079
|
+
test("Should work with Infinity", async () => {
|
|
3080
|
+
const value = Infinity;
|
|
3081
|
+
await storage.putMany({ a: value });
|
|
3082
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
3083
|
+
expect(isFinite(getResult)).toBe(false);
|
|
3084
|
+
});
|
|
3085
|
+
test("Should work with Bigint", async () => {
|
|
3086
|
+
const value = 20n;
|
|
3087
|
+
await storage.putMany({ a: value });
|
|
3088
|
+
expect(await storage.getMany(["a"])).toEqual({ a: value });
|
|
3089
|
+
});
|
|
3090
|
+
test("Should work with true", async () => {
|
|
3091
|
+
const value = true;
|
|
3092
|
+
await storage.putMany({ a: value });
|
|
3093
|
+
expect(await storage.getMany(["a"])).toEqual({ a: value });
|
|
3094
|
+
});
|
|
3095
|
+
test("Should work with false", async () => {
|
|
3096
|
+
const value = false;
|
|
3097
|
+
await storage.putMany({ a: value });
|
|
3098
|
+
expect(await storage.getMany(["a"])).toEqual({ a: value });
|
|
3099
|
+
});
|
|
3100
|
+
test("Should work with string", async () => {
|
|
3101
|
+
const value = "str";
|
|
3102
|
+
await storage.putMany({ a: value });
|
|
3103
|
+
expect(await storage.getMany(["a"])).toEqual({ a: value });
|
|
3104
|
+
});
|
|
3105
|
+
test("Should work with Date", async () => {
|
|
3106
|
+
const value = new Date("2024-01-01");
|
|
3107
|
+
await storage.putMany({ a: value });
|
|
3108
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
3109
|
+
expect(getResult).toBeInstanceOf(Date);
|
|
3110
|
+
expect(getResult).toEqual(value);
|
|
3111
|
+
});
|
|
3112
|
+
test("Should work with RegExp", async () => {
|
|
3113
|
+
const value = /test/;
|
|
3114
|
+
await storage.putMany({ a: value });
|
|
3115
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
3116
|
+
expect(getResult).toBeInstanceOf(RegExp);
|
|
3117
|
+
expect(getResult).toEqual(value);
|
|
3118
|
+
});
|
|
3119
|
+
test("Should work with Buffer", async () => {
|
|
3120
|
+
const value = Buffer.from("asd");
|
|
3121
|
+
await storage.putMany({ a: value });
|
|
3122
|
+
const { a: getResult } = await storage.getMany([
|
|
3123
|
+
"a",
|
|
3124
|
+
]);
|
|
3125
|
+
expect(getResult).toBeInstanceOf(Buffer);
|
|
3126
|
+
expect(getResult?.toString("base64")).toEqual(value.toString("base64"));
|
|
3127
|
+
});
|
|
3128
|
+
test("Should work with Uint8Array", async () => {
|
|
3129
|
+
const value = new Uint8Array(Buffer.from("asd"));
|
|
3130
|
+
await storage.putMany({ a: value });
|
|
3131
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
3132
|
+
expect(getResult).toBeInstanceOf(Uint8Array);
|
|
3133
|
+
expect(getResult
|
|
3134
|
+
? Buffer.from(getResult).toString("base64")
|
|
3135
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
3136
|
+
});
|
|
3137
|
+
test("Should work with Int8Array", async () => {
|
|
3138
|
+
const value = new Int8Array(Buffer.from("asd"));
|
|
3139
|
+
await storage.putMany({ a: value });
|
|
3140
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
3141
|
+
expect(getResult).toBeInstanceOf(Int8Array);
|
|
3142
|
+
expect(getResult
|
|
3143
|
+
? Buffer.from(getResult).toString("base64")
|
|
3144
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
3145
|
+
});
|
|
3146
|
+
test("Should work with Uint16Array", async () => {
|
|
3147
|
+
const value = new Uint16Array(Buffer.from("asd"));
|
|
3148
|
+
await storage.putMany({ a: value });
|
|
3149
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
3150
|
+
expect(getResult).toBeInstanceOf(Uint16Array);
|
|
3151
|
+
expect(getResult
|
|
3152
|
+
? Buffer.from(getResult).toString("base64")
|
|
3153
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
3154
|
+
});
|
|
3155
|
+
test("Should work with Int16Array", async () => {
|
|
3156
|
+
const value = new Int16Array(Buffer.from("asd"));
|
|
3157
|
+
await storage.putMany({ a: value });
|
|
3158
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
3159
|
+
expect(getResult).toBeInstanceOf(Int16Array);
|
|
3160
|
+
expect(getResult
|
|
3161
|
+
? Buffer.from(getResult).toString("base64")
|
|
3162
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
3163
|
+
});
|
|
3164
|
+
test("Should work with Uint32Array", async () => {
|
|
3165
|
+
const value = new Uint32Array(Buffer.from("asd"));
|
|
3166
|
+
await storage.putMany({ a: value });
|
|
3167
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
3168
|
+
expect(getResult).toBeInstanceOf(Uint32Array);
|
|
3169
|
+
expect(getResult
|
|
3170
|
+
? Buffer.from(getResult).toString("base64")
|
|
3171
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
3172
|
+
});
|
|
3173
|
+
test("Should work with Int32Array", async () => {
|
|
3174
|
+
const value = new Int32Array(Buffer.from("asd"));
|
|
3175
|
+
await storage.putMany({ a: value });
|
|
3176
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
3177
|
+
expect(getResult).toBeInstanceOf(Int32Array);
|
|
3178
|
+
expect(getResult
|
|
3179
|
+
? Buffer.from(getResult).toString("base64")
|
|
3180
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
3181
|
+
});
|
|
3182
|
+
test("Should work with Float32Array", async () => {
|
|
3183
|
+
const value = new Float32Array(Buffer.from("asd"));
|
|
3184
|
+
await storage.putMany({ a: value });
|
|
3185
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
3186
|
+
expect(getResult).toBeInstanceOf(Float32Array);
|
|
3187
|
+
expect(getResult
|
|
3188
|
+
? Buffer.from(getResult).toString("base64")
|
|
3189
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
3190
|
+
});
|
|
3191
|
+
test("Should work with Float64Array", async () => {
|
|
3192
|
+
const value = new Float64Array(Buffer.from("asd"));
|
|
3193
|
+
await storage.putMany({ a: value });
|
|
3194
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
3195
|
+
expect(getResult).toBeInstanceOf(Float64Array);
|
|
3196
|
+
expect(getResult
|
|
3197
|
+
? Buffer.from(getResult).toString("base64")
|
|
3198
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
3199
|
+
});
|
|
3200
|
+
test("Should work with Set", async () => {
|
|
3201
|
+
const value = new Set(["a", "b", "c"]);
|
|
3202
|
+
await storage.putMany({ a: value });
|
|
3203
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
3204
|
+
expect(getResult).toBeInstanceOf(Set);
|
|
3205
|
+
expect(getResult).toEqual(value);
|
|
3206
|
+
});
|
|
3207
|
+
test("Should work with Set of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays", async () => {
|
|
3208
|
+
const value = new Set([
|
|
3209
|
+
0,
|
|
3210
|
+
-1,
|
|
3211
|
+
1,
|
|
3212
|
+
-1.5,
|
|
3213
|
+
1.5,
|
|
3214
|
+
NaN,
|
|
3215
|
+
Infinity,
|
|
3216
|
+
2n,
|
|
3217
|
+
true,
|
|
3218
|
+
false,
|
|
3219
|
+
"str",
|
|
3220
|
+
new Date("2024-01-01"),
|
|
3221
|
+
new Set(["a", "b", "c"]),
|
|
3222
|
+
new Map([
|
|
3223
|
+
["a", 1],
|
|
3224
|
+
["b", 2],
|
|
3225
|
+
["c", 3],
|
|
3226
|
+
]),
|
|
3227
|
+
{ a: 1, b: 2 },
|
|
3228
|
+
[1, 2, 3],
|
|
3229
|
+
/test/,
|
|
3230
|
+
]);
|
|
3231
|
+
await storage.putMany({ a: value });
|
|
3232
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
3233
|
+
expect(getResult).toBeInstanceOf(Set);
|
|
3234
|
+
expect(getResult).toEqual(value);
|
|
3235
|
+
});
|
|
3236
|
+
test("Should work with Map", async () => {
|
|
3237
|
+
const value = new Map([
|
|
3238
|
+
["a", 1],
|
|
3239
|
+
["b", 2],
|
|
3240
|
+
["c", 3],
|
|
3241
|
+
]);
|
|
3242
|
+
await storage.putMany({ a: value });
|
|
3243
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
3244
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
3245
|
+
expect(getResult).toEqual(value);
|
|
3246
|
+
});
|
|
3247
|
+
test("Should work with Map of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays values", async () => {
|
|
3248
|
+
const value = new Map([
|
|
3249
|
+
["a", 0],
|
|
3250
|
+
["b", -1],
|
|
3251
|
+
["c", 1],
|
|
3252
|
+
["d", -1.5],
|
|
3253
|
+
["e", 1.5],
|
|
3254
|
+
["f", NaN],
|
|
3255
|
+
["g", Infinity],
|
|
3256
|
+
["h", 2n],
|
|
3257
|
+
["j", true],
|
|
3258
|
+
["l", false],
|
|
3259
|
+
["i", "str"],
|
|
3260
|
+
["r", new Date("2024-01-01")],
|
|
3261
|
+
["k", new Set(["a", "b", "c"])],
|
|
3262
|
+
[
|
|
3263
|
+
"p",
|
|
3264
|
+
new Map([
|
|
3265
|
+
["a", 1],
|
|
3266
|
+
["b", 2],
|
|
3267
|
+
["c", 3],
|
|
3268
|
+
]),
|
|
3269
|
+
],
|
|
3270
|
+
["a", /test/],
|
|
3271
|
+
[1, { a: 2, b: -1 }],
|
|
3272
|
+
[2, [1, 2, 3]],
|
|
3273
|
+
]);
|
|
3274
|
+
await storage.putMany({ a: value });
|
|
3275
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
3276
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
3277
|
+
expect(getResult).toEqual(value);
|
|
3278
|
+
});
|
|
3279
|
+
test("Should work with Map of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays keys", async () => {
|
|
3280
|
+
const value = new Map([
|
|
3281
|
+
[0, "a"],
|
|
3282
|
+
[-1, "a"],
|
|
3283
|
+
[1, "a"],
|
|
3284
|
+
[-1.5, "a"],
|
|
3285
|
+
[1.5, "a"],
|
|
3286
|
+
[NaN, "a"],
|
|
3287
|
+
[Infinity, "a"],
|
|
3288
|
+
[2n, "a"],
|
|
3289
|
+
[true, "a"],
|
|
3290
|
+
[false, "a"],
|
|
3291
|
+
["str", "a"],
|
|
3292
|
+
[new Date("2024-01-01"), "a"],
|
|
3293
|
+
[new Set(["a", "b", "c"]), "a"],
|
|
3294
|
+
[
|
|
3295
|
+
new Map([
|
|
3296
|
+
["a", 1],
|
|
3297
|
+
["b", 2],
|
|
3298
|
+
["c", 3],
|
|
3299
|
+
]),
|
|
3300
|
+
"a",
|
|
3301
|
+
],
|
|
3302
|
+
[/test/, "a"],
|
|
3303
|
+
[{ a: 2, b: -1 }, 1],
|
|
3304
|
+
[[1, 2, 3], 2],
|
|
3305
|
+
]);
|
|
3306
|
+
await storage.putMany({ a: value });
|
|
3307
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
3308
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
3309
|
+
expect(getResult).toEqual(value);
|
|
3310
|
+
});
|
|
3311
|
+
test("Should work with array of number, boolean, string, Date, Set, Map, RegExp", async () => {
|
|
3312
|
+
const value = [
|
|
3313
|
+
0,
|
|
3314
|
+
-1,
|
|
3315
|
+
1,
|
|
3316
|
+
-1.5,
|
|
3317
|
+
1.5,
|
|
3318
|
+
NaN,
|
|
3319
|
+
Infinity,
|
|
3320
|
+
2n,
|
|
3321
|
+
true,
|
|
3322
|
+
false,
|
|
3323
|
+
"str",
|
|
3324
|
+
new Date("2024-01-01"),
|
|
3325
|
+
new Set(["a", "b", "c"]),
|
|
3326
|
+
new Map([
|
|
3327
|
+
["a", 1],
|
|
3328
|
+
["b", 2],
|
|
3329
|
+
["c", 3],
|
|
3330
|
+
]),
|
|
3331
|
+
/test/,
|
|
3332
|
+
];
|
|
3333
|
+
await storage.putMany({ a: value });
|
|
3334
|
+
const getResult = await storage.getMany(["a"]);
|
|
3335
|
+
expect(getResult).toEqual({ a: value });
|
|
3336
|
+
});
|
|
3337
|
+
test("Should work with array of objects", async () => {
|
|
3338
|
+
const value = [
|
|
3339
|
+
Object.fromEntries([
|
|
3340
|
+
["a", 0],
|
|
3341
|
+
["b", -1],
|
|
3342
|
+
["c", 1],
|
|
3343
|
+
["d", -1.5],
|
|
3344
|
+
["e", 1.5],
|
|
3345
|
+
["f", NaN],
|
|
3346
|
+
["g", Infinity],
|
|
3347
|
+
["h", 2n],
|
|
3348
|
+
["j", true],
|
|
3349
|
+
["l", false],
|
|
3350
|
+
["i", "str"],
|
|
3351
|
+
["r", new Date("2024-01-01")],
|
|
3352
|
+
["k", new Set(["a", "b", "c"])],
|
|
3353
|
+
[
|
|
3354
|
+
"p",
|
|
3355
|
+
new Map([
|
|
3356
|
+
["a", 1],
|
|
3357
|
+
["b", 2],
|
|
3358
|
+
["c", 3],
|
|
3359
|
+
]),
|
|
3360
|
+
],
|
|
3361
|
+
["a", /test/],
|
|
3362
|
+
]),
|
|
3363
|
+
];
|
|
3364
|
+
await storage.putMany({ a: value });
|
|
3365
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
3366
|
+
expect(getResult).toEqual(value);
|
|
3367
|
+
});
|
|
3368
|
+
test("Should work with object of number, boolean, string, Date, Set, Map, RegExp", async () => {
|
|
3369
|
+
const value = Object.fromEntries([
|
|
3370
|
+
["a", 0],
|
|
3371
|
+
["b", -1],
|
|
3372
|
+
["c", 1],
|
|
3373
|
+
["d", -1.5],
|
|
3374
|
+
["e", 1.5],
|
|
3375
|
+
["f", NaN],
|
|
3376
|
+
["g", Infinity],
|
|
3377
|
+
["h", 2n],
|
|
3378
|
+
["j", true],
|
|
3379
|
+
["l", false],
|
|
3380
|
+
["i", "str"],
|
|
3381
|
+
["r", new Date("2024-01-01")],
|
|
3382
|
+
["k", new Set(["a", "b", "c"])],
|
|
3383
|
+
[
|
|
3384
|
+
"p",
|
|
3385
|
+
new Map([
|
|
3386
|
+
["a", 1],
|
|
3387
|
+
["b", 2],
|
|
3388
|
+
["c", 3],
|
|
3389
|
+
]),
|
|
3390
|
+
],
|
|
3391
|
+
["a", /test/],
|
|
3392
|
+
]);
|
|
3393
|
+
await storage.putMany({ a: value });
|
|
3394
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
3395
|
+
expect(getResult).toEqual(value);
|
|
3396
|
+
});
|
|
3397
|
+
test("Should work with object of arrays", async () => {
|
|
3398
|
+
const value = {
|
|
3399
|
+
a: [
|
|
3400
|
+
0,
|
|
3401
|
+
-1,
|
|
3402
|
+
1,
|
|
3403
|
+
-1.5,
|
|
3404
|
+
1.5,
|
|
3405
|
+
NaN,
|
|
3406
|
+
Infinity,
|
|
3407
|
+
2n,
|
|
3408
|
+
true,
|
|
3409
|
+
false,
|
|
3410
|
+
"str",
|
|
3411
|
+
new Date("2024-01-01"),
|
|
3412
|
+
new Set(["a", "b", "c"]),
|
|
3413
|
+
new Map([
|
|
3414
|
+
["a", 1],
|
|
3415
|
+
["b", 2],
|
|
3416
|
+
["c", 3],
|
|
3417
|
+
]),
|
|
3418
|
+
/test/,
|
|
3419
|
+
],
|
|
3420
|
+
};
|
|
3421
|
+
await storage.putMany({ a: value });
|
|
3422
|
+
const { a: getResult } = await storage.getMany(["a"]);
|
|
3423
|
+
expect(getResult).toEqual(value);
|
|
3424
|
+
});
|
|
3425
|
+
});
|
|
3426
|
+
describe("method: getAndRemove", () => {
|
|
3427
|
+
test("Should work with positive integer", async () => {
|
|
3428
|
+
const value = 1;
|
|
3429
|
+
await storage.add("a", value);
|
|
3430
|
+
expect(await storage.getAndRemove("a")).toBe(value);
|
|
3431
|
+
});
|
|
3432
|
+
test("Should work with negative integer", async () => {
|
|
3433
|
+
const value = -1;
|
|
3434
|
+
await storage.add("a", value);
|
|
3435
|
+
expect(await storage.getAndRemove("a")).toBe(value);
|
|
3436
|
+
});
|
|
3437
|
+
test("Should work with positive decimal", async () => {
|
|
3438
|
+
const value = 1.5;
|
|
3439
|
+
await storage.add("a", value);
|
|
3440
|
+
expect(await storage.getAndRemove("a")).toBe(value);
|
|
3441
|
+
});
|
|
3442
|
+
test("Should work with negative decimal", async () => {
|
|
3443
|
+
const value = -1.5;
|
|
3444
|
+
await storage.add("a", value);
|
|
3445
|
+
expect(await storage.getAndRemove("a")).toBe(value);
|
|
3446
|
+
});
|
|
3447
|
+
test("Should work with NaN", async () => {
|
|
3448
|
+
const value = NaN;
|
|
3449
|
+
await storage.add("a", value);
|
|
3450
|
+
const getResult = await storage.getAndRemove("a");
|
|
3451
|
+
expect(getResult).toBeNaN();
|
|
3452
|
+
});
|
|
3453
|
+
test("Should work with Infinity", async () => {
|
|
3454
|
+
const value = Infinity;
|
|
3455
|
+
await storage.add("a", value);
|
|
3456
|
+
const getResult = await storage.getAndRemove("a");
|
|
3457
|
+
expect(isFinite(getResult)).toBe(false);
|
|
3458
|
+
});
|
|
3459
|
+
test("Should work with Bigint", async () => {
|
|
3460
|
+
const value = 20n;
|
|
3461
|
+
await storage.add("a", value);
|
|
3462
|
+
expect(await storage.getAndRemove("a")).toBe(value);
|
|
3463
|
+
});
|
|
3464
|
+
test("Should work with true", async () => {
|
|
3465
|
+
const value = true;
|
|
3466
|
+
await storage.add("a", value);
|
|
3467
|
+
expect(await storage.getAndRemove("a")).toBe(value);
|
|
3468
|
+
});
|
|
3469
|
+
test("Should work with false", async () => {
|
|
3470
|
+
const value = false;
|
|
3471
|
+
await storage.add("a", value);
|
|
3472
|
+
expect(await storage.getAndRemove("a")).toBe(value);
|
|
3473
|
+
});
|
|
3474
|
+
test("Should work with string", async () => {
|
|
3475
|
+
const value = "str";
|
|
3476
|
+
await storage.add("a", value);
|
|
3477
|
+
expect(await storage.getAndRemove("a")).toBe(value);
|
|
3478
|
+
});
|
|
3479
|
+
test("Should work with Date", async () => {
|
|
3480
|
+
const value = new Date("2024-01-01");
|
|
3481
|
+
await storage.add("a", value);
|
|
3482
|
+
const getResult = await storage.getAndRemove("a");
|
|
3483
|
+
expect(getResult).toBeInstanceOf(Date);
|
|
3484
|
+
expect(getResult).toEqual(value);
|
|
3485
|
+
});
|
|
3486
|
+
test("Should work with RegExp", async () => {
|
|
3487
|
+
const value = /test/;
|
|
3488
|
+
await storage.add("a", value);
|
|
3489
|
+
const getResult = await storage.getAndRemove("a");
|
|
3490
|
+
expect(getResult).toBeInstanceOf(RegExp);
|
|
3491
|
+
expect(getResult).toEqual(value);
|
|
3492
|
+
});
|
|
3493
|
+
test("Should work with Buffer", async () => {
|
|
3494
|
+
const value = Buffer.from("asd");
|
|
3495
|
+
await storage.add("a", value);
|
|
3496
|
+
const getResult = await storage.get("a");
|
|
3497
|
+
expect(getResult).toBeInstanceOf(Buffer);
|
|
3498
|
+
expect(getResult?.toString("base64")).toEqual(value.toString("base64"));
|
|
3499
|
+
});
|
|
3500
|
+
test("Should work with Uint8Array", async () => {
|
|
3501
|
+
const value = new Uint8Array(Buffer.from("asd"));
|
|
3502
|
+
await storage.add("a", value);
|
|
3503
|
+
const getResult = await storage.get("a");
|
|
3504
|
+
expect(getResult).toBeInstanceOf(Uint8Array);
|
|
3505
|
+
expect(getResult
|
|
3506
|
+
? Buffer.from(getResult).toString("base64")
|
|
3507
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
3508
|
+
});
|
|
3509
|
+
test("Should work with Int8Array", async () => {
|
|
3510
|
+
const value = new Int8Array(Buffer.from("asd"));
|
|
3511
|
+
await storage.add("a", value);
|
|
3512
|
+
const getResult = await storage.get("a");
|
|
3513
|
+
expect(getResult).toBeInstanceOf(Int8Array);
|
|
3514
|
+
expect(getResult
|
|
3515
|
+
? Buffer.from(getResult).toString("base64")
|
|
3516
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
3517
|
+
});
|
|
3518
|
+
test("Should work with Uint16Array", async () => {
|
|
3519
|
+
const value = new Uint16Array(Buffer.from("asd"));
|
|
3520
|
+
await storage.add("a", value);
|
|
3521
|
+
const getResult = await storage.get("a");
|
|
3522
|
+
expect(getResult).toBeInstanceOf(Uint16Array);
|
|
3523
|
+
expect(getResult
|
|
3524
|
+
? Buffer.from(getResult).toString("base64")
|
|
3525
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
3526
|
+
});
|
|
3527
|
+
test("Should work with Int16Array", async () => {
|
|
3528
|
+
const value = new Int16Array(Buffer.from("asd"));
|
|
3529
|
+
await storage.add("a", value);
|
|
3530
|
+
const getResult = await storage.get("a");
|
|
3531
|
+
expect(getResult).toBeInstanceOf(Int16Array);
|
|
3532
|
+
expect(getResult
|
|
3533
|
+
? Buffer.from(getResult).toString("base64")
|
|
3534
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
3535
|
+
});
|
|
3536
|
+
test("Should work with Uint32Array", async () => {
|
|
3537
|
+
const value = new Uint32Array(Buffer.from("asd"));
|
|
3538
|
+
await storage.add("a", value);
|
|
3539
|
+
const getResult = await storage.get("a");
|
|
3540
|
+
expect(getResult).toBeInstanceOf(Uint32Array);
|
|
3541
|
+
expect(getResult
|
|
3542
|
+
? Buffer.from(getResult).toString("base64")
|
|
3543
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
3544
|
+
});
|
|
3545
|
+
test("Should work with Int32Array", async () => {
|
|
3546
|
+
const value = new Int32Array(Buffer.from("asd"));
|
|
3547
|
+
await storage.add("a", value);
|
|
3548
|
+
const getResult = await storage.get("a");
|
|
3549
|
+
expect(getResult).toBeInstanceOf(Int32Array);
|
|
3550
|
+
expect(getResult
|
|
3551
|
+
? Buffer.from(getResult).toString("base64")
|
|
3552
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
3553
|
+
});
|
|
3554
|
+
test("Should work with Float32Array", async () => {
|
|
3555
|
+
const value = new Float32Array(Buffer.from("asd"));
|
|
3556
|
+
await storage.add("a", value);
|
|
3557
|
+
const getResult = await storage.get("a");
|
|
3558
|
+
expect(getResult).toBeInstanceOf(Float32Array);
|
|
3559
|
+
expect(getResult
|
|
3560
|
+
? Buffer.from(getResult).toString("base64")
|
|
3561
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
3562
|
+
});
|
|
3563
|
+
test("Should work with Float64Array", async () => {
|
|
3564
|
+
const value = new Float64Array(Buffer.from("asd"));
|
|
3565
|
+
await storage.add("a", value);
|
|
3566
|
+
const getResult = await storage.get("a");
|
|
3567
|
+
expect(getResult).toBeInstanceOf(Float64Array);
|
|
3568
|
+
expect(getResult
|
|
3569
|
+
? Buffer.from(getResult).toString("base64")
|
|
3570
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
3571
|
+
});
|
|
3572
|
+
test("Should work with Set", async () => {
|
|
3573
|
+
const value = new Set(["a", "b", "c"]);
|
|
3574
|
+
await storage.add("a", value);
|
|
3575
|
+
const getResult = await storage.getAndRemove("a");
|
|
3576
|
+
expect(getResult).toBeInstanceOf(Set);
|
|
3577
|
+
expect(getResult).toEqual(value);
|
|
3578
|
+
});
|
|
3579
|
+
test("Should work with Set of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays", async () => {
|
|
3580
|
+
const value = new Set([
|
|
3581
|
+
0,
|
|
3582
|
+
-1,
|
|
3583
|
+
1,
|
|
3584
|
+
-1.5,
|
|
3585
|
+
1.5,
|
|
3586
|
+
NaN,
|
|
3587
|
+
Infinity,
|
|
3588
|
+
2n,
|
|
3589
|
+
true,
|
|
3590
|
+
false,
|
|
3591
|
+
"str",
|
|
3592
|
+
new Date("2024-01-01"),
|
|
3593
|
+
new Set(["a", "b", "c"]),
|
|
3594
|
+
new Map([
|
|
3595
|
+
["a", 1],
|
|
3596
|
+
["b", 2],
|
|
3597
|
+
["c", 3],
|
|
3598
|
+
]),
|
|
3599
|
+
{ a: 1, b: 2 },
|
|
3600
|
+
[1, 2, 3],
|
|
3601
|
+
/test/,
|
|
3602
|
+
]);
|
|
3603
|
+
await storage.add("a", value);
|
|
3604
|
+
const getResult = await storage.getAndRemove("a");
|
|
3605
|
+
expect(getResult).toBeInstanceOf(Set);
|
|
3606
|
+
expect(getResult).toEqual(value);
|
|
3607
|
+
});
|
|
3608
|
+
test("Should work with Map", async () => {
|
|
3609
|
+
const value = new Map([
|
|
3610
|
+
["a", 1],
|
|
3611
|
+
["b", 2],
|
|
3612
|
+
["c", 3],
|
|
3613
|
+
]);
|
|
3614
|
+
await storage.add("a", value);
|
|
3615
|
+
const getResult = await storage.getAndRemove("a");
|
|
3616
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
3617
|
+
expect(getResult).toEqual(value);
|
|
3618
|
+
});
|
|
3619
|
+
test("Should work with Map of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays values", async () => {
|
|
3620
|
+
const value = new Map([
|
|
3621
|
+
["a", 0],
|
|
3622
|
+
["b", -1],
|
|
3623
|
+
["c", 1],
|
|
3624
|
+
["d", -1.5],
|
|
3625
|
+
["e", 1.5],
|
|
3626
|
+
["f", NaN],
|
|
3627
|
+
["g", Infinity],
|
|
3628
|
+
["h", 2n],
|
|
3629
|
+
["j", true],
|
|
3630
|
+
["l", false],
|
|
3631
|
+
["i", "str"],
|
|
3632
|
+
["r", new Date("2024-01-01")],
|
|
3633
|
+
["k", new Set(["a", "b", "c"])],
|
|
3634
|
+
[
|
|
3635
|
+
"p",
|
|
3636
|
+
new Map([
|
|
3637
|
+
["a", 1],
|
|
3638
|
+
["b", 2],
|
|
3639
|
+
["c", 3],
|
|
3640
|
+
]),
|
|
3641
|
+
],
|
|
3642
|
+
["a", /test/],
|
|
3643
|
+
[1, { a: 2, b: -1 }],
|
|
3644
|
+
[2, [1, 2, 3]],
|
|
3645
|
+
]);
|
|
3646
|
+
await storage.add("a", value);
|
|
3647
|
+
const getResult = await storage.getAndRemove("a");
|
|
3648
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
3649
|
+
expect(getResult).toEqual(value);
|
|
3650
|
+
});
|
|
3651
|
+
test("Should work with Map of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays keys", async () => {
|
|
3652
|
+
const value = new Map([
|
|
3653
|
+
[0, "a"],
|
|
3654
|
+
[-1, "a"],
|
|
3655
|
+
[1, "a"],
|
|
3656
|
+
[-1.5, "a"],
|
|
3657
|
+
[1.5, "a"],
|
|
3658
|
+
[NaN, "a"],
|
|
3659
|
+
[Infinity, "a"],
|
|
3660
|
+
[2n, "a"],
|
|
3661
|
+
[true, "a"],
|
|
3662
|
+
[false, "a"],
|
|
3663
|
+
["str", "a"],
|
|
3664
|
+
[new Date("2024-01-01"), "a"],
|
|
3665
|
+
[new Set(["a", "b", "c"]), "a"],
|
|
3666
|
+
[
|
|
3667
|
+
new Map([
|
|
3668
|
+
["a", 1],
|
|
3669
|
+
["b", 2],
|
|
3670
|
+
["c", 3],
|
|
3671
|
+
]),
|
|
3672
|
+
"a",
|
|
3673
|
+
],
|
|
3674
|
+
[/test/, "a"],
|
|
3675
|
+
[{ a: 2, b: -1 }, 1],
|
|
3676
|
+
[[1, 2, 3], 2],
|
|
3677
|
+
]);
|
|
3678
|
+
await storage.add("a", value);
|
|
3679
|
+
const getResult = await storage.getAndRemove("a");
|
|
3680
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
3681
|
+
expect(getResult).toEqual(value);
|
|
3682
|
+
});
|
|
3683
|
+
test("Should work with array of number, boolean, string, Date, Set, Map, RegExp", async () => {
|
|
3684
|
+
const value = [
|
|
3685
|
+
0,
|
|
3686
|
+
-1,
|
|
3687
|
+
1,
|
|
3688
|
+
-1.5,
|
|
3689
|
+
1.5,
|
|
3690
|
+
NaN,
|
|
3691
|
+
Infinity,
|
|
3692
|
+
2n,
|
|
3693
|
+
true,
|
|
3694
|
+
false,
|
|
3695
|
+
"str",
|
|
3696
|
+
new Date("2024-01-01"),
|
|
3697
|
+
new Set(["a", "b", "c"]),
|
|
3698
|
+
new Map([
|
|
3699
|
+
["a", 1],
|
|
3700
|
+
["b", 2],
|
|
3701
|
+
["c", 3],
|
|
3702
|
+
]),
|
|
3703
|
+
/test/,
|
|
3704
|
+
];
|
|
3705
|
+
await storage.add("a", value);
|
|
3706
|
+
const getResult = await storage.getAndRemove("a");
|
|
3707
|
+
expect(getResult).toEqual(value);
|
|
3708
|
+
});
|
|
3709
|
+
test("Should work with array of objects", async () => {
|
|
3710
|
+
const value = [
|
|
3711
|
+
Object.fromEntries([
|
|
3712
|
+
["a", 0],
|
|
3713
|
+
["b", -1],
|
|
3714
|
+
["c", 1],
|
|
3715
|
+
["d", -1.5],
|
|
3716
|
+
["e", 1.5],
|
|
3717
|
+
["f", NaN],
|
|
3718
|
+
["g", Infinity],
|
|
3719
|
+
["h", 2n],
|
|
3720
|
+
["j", true],
|
|
3721
|
+
["l", false],
|
|
3722
|
+
["i", "str"],
|
|
3723
|
+
["r", new Date("2024-01-01")],
|
|
3724
|
+
["k", new Set(["a", "b", "c"])],
|
|
3725
|
+
[
|
|
3726
|
+
"p",
|
|
3727
|
+
new Map([
|
|
3728
|
+
["a", 1],
|
|
3729
|
+
["b", 2],
|
|
3730
|
+
["c", 3],
|
|
3731
|
+
]),
|
|
3732
|
+
],
|
|
3733
|
+
["a", /test/],
|
|
3734
|
+
]),
|
|
3735
|
+
];
|
|
3736
|
+
await storage.add("a", value);
|
|
3737
|
+
const getResult = await storage.getAndRemove("a");
|
|
3738
|
+
expect(getResult).toEqual(value);
|
|
3739
|
+
});
|
|
3740
|
+
test("Should work with object of number, boolean, string, Date, Set, Map, RegExp", async () => {
|
|
3741
|
+
const value = Object.fromEntries([
|
|
3742
|
+
["a", 0],
|
|
3743
|
+
["b", -1],
|
|
3744
|
+
["c", 1],
|
|
3745
|
+
["d", -1.5],
|
|
3746
|
+
["e", 1.5],
|
|
3747
|
+
["f", NaN],
|
|
3748
|
+
["g", Infinity],
|
|
3749
|
+
["h", 2n],
|
|
3750
|
+
["j", true],
|
|
3751
|
+
["l", false],
|
|
3752
|
+
["i", "str"],
|
|
3753
|
+
["r", new Date("2024-01-01")],
|
|
3754
|
+
["k", new Set(["a", "b", "c"])],
|
|
3755
|
+
[
|
|
3756
|
+
"p",
|
|
3757
|
+
new Map([
|
|
3758
|
+
["a", 1],
|
|
3759
|
+
["b", 2],
|
|
3760
|
+
["c", 3],
|
|
3761
|
+
]),
|
|
3762
|
+
],
|
|
3763
|
+
["a", /test/],
|
|
3764
|
+
]);
|
|
3765
|
+
await storage.add("a", value);
|
|
3766
|
+
const getResult = await storage.getAndRemove("a");
|
|
3767
|
+
expect(getResult).toEqual(value);
|
|
3768
|
+
});
|
|
3769
|
+
test("Should work with object of arrays", async () => {
|
|
3770
|
+
const value = {
|
|
3771
|
+
a: [
|
|
3772
|
+
0,
|
|
3773
|
+
-1,
|
|
3774
|
+
1,
|
|
3775
|
+
-1.5,
|
|
3776
|
+
1.5,
|
|
3777
|
+
NaN,
|
|
3778
|
+
Infinity,
|
|
3779
|
+
2n,
|
|
3780
|
+
true,
|
|
3781
|
+
false,
|
|
3782
|
+
"str",
|
|
3783
|
+
new Date("2024-01-01"),
|
|
3784
|
+
new Set(["a", "b", "c"]),
|
|
3785
|
+
new Map([
|
|
3786
|
+
["a", 1],
|
|
3787
|
+
["b", 2],
|
|
3788
|
+
["c", 3],
|
|
3789
|
+
]),
|
|
3790
|
+
/test/,
|
|
3791
|
+
],
|
|
3792
|
+
};
|
|
3793
|
+
await storage.add("a", value);
|
|
3794
|
+
const getResult = await storage.getAndRemove("a");
|
|
3795
|
+
expect(getResult).toEqual(value);
|
|
3796
|
+
});
|
|
3797
|
+
});
|
|
3798
|
+
describe("method: getOrAdd", () => {
|
|
3799
|
+
test("Should work with positive integer", async () => {
|
|
3800
|
+
const value = 1;
|
|
3801
|
+
await storage.getOrAdd("a", value);
|
|
3802
|
+
expect(await storage.getOrAdd("a", -1)).toBe(value);
|
|
3803
|
+
});
|
|
3804
|
+
test("Should work with negative integer", async () => {
|
|
3805
|
+
const value = -1;
|
|
3806
|
+
await storage.getOrAdd("a", value);
|
|
3807
|
+
expect(await storage.getOrAdd("a", -1)).toBe(value);
|
|
3808
|
+
});
|
|
3809
|
+
test("Should work with positive decimal", async () => {
|
|
3810
|
+
const value = 1.5;
|
|
3811
|
+
await storage.getOrAdd("a", value);
|
|
3812
|
+
expect(await storage.getOrAdd("a", -1)).toBe(value);
|
|
3813
|
+
});
|
|
3814
|
+
test("Should work with negative decimal", async () => {
|
|
3815
|
+
const value = -1.5;
|
|
3816
|
+
await storage.getOrAdd("a", value);
|
|
3817
|
+
expect(await storage.getOrAdd("a", -1)).toBe(value);
|
|
3818
|
+
});
|
|
3819
|
+
test("Should work with NaN", async () => {
|
|
3820
|
+
const value = NaN;
|
|
3821
|
+
await storage.getOrAdd("a", value);
|
|
3822
|
+
const getResult = await storage.getOrAdd("a", -1);
|
|
3823
|
+
expect(getResult).toBeNaN();
|
|
3824
|
+
});
|
|
3825
|
+
test("Should work with Infinity", async () => {
|
|
3826
|
+
const value = Infinity;
|
|
3827
|
+
await storage.getOrAdd("a", value);
|
|
3828
|
+
const getResult = await storage.getOrAdd("a", -1);
|
|
3829
|
+
expect(isFinite(getResult)).toBe(false);
|
|
3830
|
+
});
|
|
3831
|
+
test("Should work with Bigint", async () => {
|
|
3832
|
+
const value = 20n;
|
|
3833
|
+
await storage.getOrAdd("a", value);
|
|
3834
|
+
expect(await storage.getOrAdd("a", -1)).toBe(value);
|
|
3835
|
+
});
|
|
3836
|
+
test("Should work with true", async () => {
|
|
3837
|
+
const value = true;
|
|
3838
|
+
await storage.getOrAdd("a", value);
|
|
3839
|
+
expect(await storage.getOrAdd("a", -1)).toBe(value);
|
|
3840
|
+
});
|
|
3841
|
+
test("Should work with false", async () => {
|
|
3842
|
+
const value = false;
|
|
3843
|
+
await storage.getOrAdd("a", value);
|
|
3844
|
+
expect(await storage.getOrAdd("a", -1)).toBe(value);
|
|
3845
|
+
});
|
|
3846
|
+
test("Should work with string", async () => {
|
|
3847
|
+
const value = "str";
|
|
3848
|
+
await storage.getOrAdd("a", value);
|
|
3849
|
+
expect(await storage.getOrAdd("a", -1)).toBe(value);
|
|
3850
|
+
});
|
|
3851
|
+
test("Should work with Date", async () => {
|
|
3852
|
+
const value = new Date("2024-01-01");
|
|
3853
|
+
await storage.getOrAdd("a", value);
|
|
3854
|
+
const getResult = await storage.getOrAdd("a", -1);
|
|
3855
|
+
expect(getResult).toBeInstanceOf(Date);
|
|
3856
|
+
expect(getResult).toEqual(value);
|
|
3857
|
+
});
|
|
3858
|
+
test("Should work with RegExp", async () => {
|
|
3859
|
+
const value = /test/;
|
|
3860
|
+
await storage.getOrAdd("a", value);
|
|
3861
|
+
const getResult = await storage.getOrAdd("a", -1);
|
|
3862
|
+
expect(getResult).toBeInstanceOf(RegExp);
|
|
3863
|
+
expect(getResult).toEqual(value);
|
|
3864
|
+
});
|
|
3865
|
+
test("Should work with Buffer", async () => {
|
|
3866
|
+
const value = Buffer.from("asd");
|
|
3867
|
+
await storage.getOrAdd("a", value);
|
|
3868
|
+
const getResult = await storage.get("a");
|
|
3869
|
+
expect(getResult).toBeInstanceOf(Buffer);
|
|
3870
|
+
expect(getResult?.toString("base64")).toEqual(value.toString("base64"));
|
|
3871
|
+
});
|
|
3872
|
+
test("Should work with Uint8Array", async () => {
|
|
3873
|
+
const value = new Uint8Array(Buffer.from("asd"));
|
|
3874
|
+
await storage.getOrAdd("a", value);
|
|
3875
|
+
const getResult = await storage.get("a");
|
|
3876
|
+
expect(getResult).toBeInstanceOf(Uint8Array);
|
|
3877
|
+
expect(getResult
|
|
3878
|
+
? Buffer.from(getResult).toString("base64")
|
|
3879
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
3880
|
+
});
|
|
3881
|
+
test("Should work with Int8Array", async () => {
|
|
3882
|
+
const value = new Int8Array(Buffer.from("asd"));
|
|
3883
|
+
await storage.getOrAdd("a", value);
|
|
3884
|
+
const getResult = await storage.get("a");
|
|
3885
|
+
expect(getResult).toBeInstanceOf(Int8Array);
|
|
3886
|
+
expect(getResult
|
|
3887
|
+
? Buffer.from(getResult).toString("base64")
|
|
3888
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
3889
|
+
});
|
|
3890
|
+
test("Should work with Uint16Array", async () => {
|
|
3891
|
+
const value = new Uint16Array(Buffer.from("asd"));
|
|
3892
|
+
await storage.getOrAdd("a", value);
|
|
3893
|
+
const getResult = await storage.get("a");
|
|
3894
|
+
expect(getResult).toBeInstanceOf(Uint16Array);
|
|
3895
|
+
expect(getResult
|
|
3896
|
+
? Buffer.from(getResult).toString("base64")
|
|
3897
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
3898
|
+
});
|
|
3899
|
+
test("Should work with Int16Array", async () => {
|
|
3900
|
+
const value = new Int16Array(Buffer.from("asd"));
|
|
3901
|
+
await storage.getOrAdd("a", value);
|
|
3902
|
+
const getResult = await storage.get("a");
|
|
3903
|
+
expect(getResult).toBeInstanceOf(Int16Array);
|
|
3904
|
+
expect(getResult
|
|
3905
|
+
? Buffer.from(getResult).toString("base64")
|
|
3906
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
3907
|
+
});
|
|
3908
|
+
test("Should work with Uint32Array", async () => {
|
|
3909
|
+
const value = new Uint32Array(Buffer.from("asd"));
|
|
3910
|
+
await storage.getOrAdd("a", value);
|
|
3911
|
+
const getResult = await storage.get("a");
|
|
3912
|
+
expect(getResult).toBeInstanceOf(Uint32Array);
|
|
3913
|
+
expect(getResult
|
|
3914
|
+
? Buffer.from(getResult).toString("base64")
|
|
3915
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
3916
|
+
});
|
|
3917
|
+
test("Should work with Int32Array", async () => {
|
|
3918
|
+
const value = new Int32Array(Buffer.from("asd"));
|
|
3919
|
+
await storage.getOrAdd("a", value);
|
|
3920
|
+
const getResult = await storage.get("a");
|
|
3921
|
+
expect(getResult).toBeInstanceOf(Int32Array);
|
|
3922
|
+
expect(getResult
|
|
3923
|
+
? Buffer.from(getResult).toString("base64")
|
|
3924
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
3925
|
+
});
|
|
3926
|
+
test("Should work with Float32Array", async () => {
|
|
3927
|
+
const value = new Float32Array(Buffer.from("asd"));
|
|
3928
|
+
await storage.getOrAdd("a", value);
|
|
3929
|
+
const getResult = await storage.get("a");
|
|
3930
|
+
expect(getResult).toBeInstanceOf(Float32Array);
|
|
3931
|
+
expect(getResult
|
|
3932
|
+
? Buffer.from(getResult).toString("base64")
|
|
3933
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
3934
|
+
});
|
|
3935
|
+
test("Should work with Float64Array", async () => {
|
|
3936
|
+
const value = new Float64Array(Buffer.from("asd"));
|
|
3937
|
+
await storage.getOrAdd("a", value);
|
|
3938
|
+
const getResult = await storage.get("a");
|
|
3939
|
+
expect(getResult).toBeInstanceOf(Float64Array);
|
|
3940
|
+
expect(getResult
|
|
3941
|
+
? Buffer.from(getResult).toString("base64")
|
|
3942
|
+
: undefined).toEqual(Buffer.from(value).toString("base64"));
|
|
3943
|
+
});
|
|
3944
|
+
test("Should work with Set", async () => {
|
|
3945
|
+
const value = new Set(["a", "b", "c"]);
|
|
3946
|
+
await storage.getOrAdd("a", value);
|
|
3947
|
+
const getResult = await storage.getOrAdd("a", -1);
|
|
3948
|
+
expect(getResult).toBeInstanceOf(Set);
|
|
3949
|
+
expect(getResult).toEqual(value);
|
|
3950
|
+
});
|
|
3951
|
+
test("Should work with Set of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays", async () => {
|
|
3952
|
+
const value = new Set([
|
|
3953
|
+
0,
|
|
3954
|
+
-1,
|
|
3955
|
+
1,
|
|
3956
|
+
-1.5,
|
|
3957
|
+
1.5,
|
|
3958
|
+
NaN,
|
|
3959
|
+
Infinity,
|
|
3960
|
+
2n,
|
|
3961
|
+
true,
|
|
3962
|
+
false,
|
|
3963
|
+
"str",
|
|
3964
|
+
new Date("2024-01-01"),
|
|
3965
|
+
new Set(["a", "b", "c"]),
|
|
3966
|
+
new Map([
|
|
3967
|
+
["a", 1],
|
|
3968
|
+
["b", 2],
|
|
3969
|
+
["c", 3],
|
|
3970
|
+
]),
|
|
3971
|
+
{ a: 1, b: 2 },
|
|
3972
|
+
[1, 2, 3],
|
|
3973
|
+
/test/,
|
|
3974
|
+
]);
|
|
3975
|
+
await storage.getOrAdd("a", value);
|
|
3976
|
+
const getResult = await storage.getOrAdd("a", -1);
|
|
3977
|
+
expect(getResult).toBeInstanceOf(Set);
|
|
3978
|
+
expect(getResult).toEqual(value);
|
|
3979
|
+
});
|
|
3980
|
+
test("Should work with Map", async () => {
|
|
3981
|
+
const value = new Map([
|
|
3982
|
+
["a", 1],
|
|
3983
|
+
["b", 2],
|
|
3984
|
+
["c", 3],
|
|
3985
|
+
]);
|
|
3986
|
+
await storage.getOrAdd("a", value);
|
|
3987
|
+
const getResult = await storage.getOrAdd("a", -1);
|
|
3988
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
3989
|
+
expect(getResult).toEqual(value);
|
|
3990
|
+
});
|
|
3991
|
+
test("Should work with Map of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays values", async () => {
|
|
3992
|
+
const value = new Map([
|
|
3993
|
+
["a", 0],
|
|
3994
|
+
["b", -1],
|
|
3995
|
+
["c", 1],
|
|
3996
|
+
["d", -1.5],
|
|
3997
|
+
["e", 1.5],
|
|
3998
|
+
["f", NaN],
|
|
3999
|
+
["g", Infinity],
|
|
4000
|
+
["h", 2n],
|
|
4001
|
+
["j", true],
|
|
4002
|
+
["l", false],
|
|
4003
|
+
["i", "str"],
|
|
4004
|
+
["r", new Date("2024-01-01")],
|
|
4005
|
+
["k", new Set(["a", "b", "c"])],
|
|
4006
|
+
[
|
|
4007
|
+
"p",
|
|
4008
|
+
new Map([
|
|
4009
|
+
["a", 1],
|
|
4010
|
+
["b", 2],
|
|
4011
|
+
["c", 3],
|
|
4012
|
+
]),
|
|
4013
|
+
],
|
|
4014
|
+
["a", /test/],
|
|
4015
|
+
[1, { a: 2, b: -1 }],
|
|
4016
|
+
[2, [1, 2, 3]],
|
|
4017
|
+
]);
|
|
4018
|
+
await storage.getOrAdd("a", value);
|
|
4019
|
+
const getResult = await storage.getOrAdd("a", -1);
|
|
4020
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
4021
|
+
expect(getResult).toEqual(value);
|
|
4022
|
+
});
|
|
4023
|
+
test("Should work with Map of number, boolean, string, Date, Set, Map, RegExp, Objects, Arrays keys", async () => {
|
|
4024
|
+
const value = new Map([
|
|
4025
|
+
[0, "a"],
|
|
4026
|
+
[-1, "a"],
|
|
4027
|
+
[1, "a"],
|
|
4028
|
+
[-1.5, "a"],
|
|
4029
|
+
[1.5, "a"],
|
|
4030
|
+
[NaN, "a"],
|
|
4031
|
+
[Infinity, "a"],
|
|
4032
|
+
[2n, "a"],
|
|
4033
|
+
[true, "a"],
|
|
4034
|
+
[false, "a"],
|
|
4035
|
+
["str", "a"],
|
|
4036
|
+
[new Date("2024-01-01"), "a"],
|
|
4037
|
+
[new Set(["a", "b", "c"]), "a"],
|
|
4038
|
+
[
|
|
4039
|
+
new Map([
|
|
4040
|
+
["a", 1],
|
|
4041
|
+
["b", 2],
|
|
4042
|
+
["c", 3],
|
|
4043
|
+
]),
|
|
4044
|
+
"a",
|
|
4045
|
+
],
|
|
4046
|
+
[/test/, "a"],
|
|
4047
|
+
[{ a: 2, b: -1 }, 1],
|
|
4048
|
+
[[1, 2, 3], 2],
|
|
4049
|
+
]);
|
|
4050
|
+
await storage.getOrAdd("a", value);
|
|
4051
|
+
const getResult = await storage.getOrAdd("a", -1);
|
|
4052
|
+
expect(getResult).toBeInstanceOf(Map);
|
|
4053
|
+
expect(getResult).toEqual(value);
|
|
4054
|
+
});
|
|
4055
|
+
test("Should work with array of number, boolean, string, Date, Set, Map, RegExp", async () => {
|
|
4056
|
+
const value = [
|
|
4057
|
+
0,
|
|
4058
|
+
-1,
|
|
4059
|
+
1,
|
|
4060
|
+
-1.5,
|
|
4061
|
+
1.5,
|
|
4062
|
+
NaN,
|
|
4063
|
+
Infinity,
|
|
4064
|
+
2n,
|
|
4065
|
+
true,
|
|
4066
|
+
false,
|
|
4067
|
+
"str",
|
|
4068
|
+
new Date("2024-01-01"),
|
|
4069
|
+
new Set(["a", "b", "c"]),
|
|
4070
|
+
new Map([
|
|
4071
|
+
["a", 1],
|
|
4072
|
+
["b", 2],
|
|
4073
|
+
["c", 3],
|
|
4074
|
+
]),
|
|
4075
|
+
/test/,
|
|
4076
|
+
];
|
|
4077
|
+
await storage.getOrAdd("a", value);
|
|
4078
|
+
const getResult = await storage.getOrAdd("a", -1);
|
|
4079
|
+
expect(getResult).toEqual(value);
|
|
4080
|
+
});
|
|
4081
|
+
test("Should work with array of objects", async () => {
|
|
4082
|
+
const value = [
|
|
4083
|
+
Object.fromEntries([
|
|
4084
|
+
["a", 0],
|
|
4085
|
+
["b", -1],
|
|
4086
|
+
["c", 1],
|
|
4087
|
+
["d", -1.5],
|
|
4088
|
+
["e", 1.5],
|
|
4089
|
+
["f", NaN],
|
|
4090
|
+
["g", Infinity],
|
|
4091
|
+
["h", 2n],
|
|
4092
|
+
["j", true],
|
|
4093
|
+
["l", false],
|
|
4094
|
+
["i", "str"],
|
|
4095
|
+
["r", new Date("2024-01-01")],
|
|
4096
|
+
["k", new Set(["a", "b", "c"])],
|
|
4097
|
+
[
|
|
4098
|
+
"p",
|
|
4099
|
+
new Map([
|
|
4100
|
+
["a", 1],
|
|
4101
|
+
["b", 2],
|
|
4102
|
+
["c", 3],
|
|
4103
|
+
]),
|
|
4104
|
+
],
|
|
4105
|
+
["a", /test/],
|
|
4106
|
+
]),
|
|
4107
|
+
];
|
|
4108
|
+
await storage.getOrAdd("a", value);
|
|
4109
|
+
const getResult = await storage.getOrAdd("a", -1);
|
|
4110
|
+
expect(getResult).toEqual(value);
|
|
4111
|
+
});
|
|
4112
|
+
test("Should work with object of number, boolean, string, Date, Set, Map, RegExp", async () => {
|
|
4113
|
+
const value = Object.fromEntries([
|
|
4114
|
+
["a", 0],
|
|
4115
|
+
["b", -1],
|
|
4116
|
+
["c", 1],
|
|
4117
|
+
["d", -1.5],
|
|
4118
|
+
["e", 1.5],
|
|
4119
|
+
["f", NaN],
|
|
4120
|
+
["g", Infinity],
|
|
4121
|
+
["h", 2n],
|
|
4122
|
+
["j", true],
|
|
4123
|
+
["l", false],
|
|
4124
|
+
["i", "str"],
|
|
4125
|
+
["r", new Date("2024-01-01")],
|
|
4126
|
+
["k", new Set(["a", "b", "c"])],
|
|
4127
|
+
[
|
|
4128
|
+
"p",
|
|
4129
|
+
new Map([
|
|
4130
|
+
["a", 1],
|
|
4131
|
+
["b", 2],
|
|
4132
|
+
["c", 3],
|
|
4133
|
+
]),
|
|
4134
|
+
],
|
|
4135
|
+
["a", /test/],
|
|
4136
|
+
]);
|
|
4137
|
+
await storage.getOrAdd("a", value);
|
|
4138
|
+
const getResult = await storage.getOrAdd("a", -1);
|
|
4139
|
+
expect(getResult).toEqual(value);
|
|
4140
|
+
});
|
|
4141
|
+
test("Should work with object of arrays", async () => {
|
|
4142
|
+
const value = {
|
|
4143
|
+
a: [
|
|
4144
|
+
0,
|
|
4145
|
+
-1,
|
|
4146
|
+
1,
|
|
4147
|
+
-1.5,
|
|
4148
|
+
1.5,
|
|
4149
|
+
NaN,
|
|
4150
|
+
Infinity,
|
|
4151
|
+
2n,
|
|
4152
|
+
true,
|
|
4153
|
+
false,
|
|
4154
|
+
"str",
|
|
4155
|
+
new Date("2024-01-01"),
|
|
4156
|
+
new Set(["a", "b", "c"]),
|
|
4157
|
+
new Map([
|
|
4158
|
+
["a", 1],
|
|
4159
|
+
["b", 2],
|
|
4160
|
+
["c", 3],
|
|
4161
|
+
]),
|
|
4162
|
+
/test/,
|
|
4163
|
+
],
|
|
4164
|
+
};
|
|
4165
|
+
await storage.getOrAdd("a", value);
|
|
4166
|
+
const getResult = await storage.getOrAdd("a", -1);
|
|
4167
|
+
expect(getResult).toEqual(value);
|
|
4168
|
+
});
|
|
4169
|
+
});
|
|
4170
|
+
});
|
|
4171
|
+
}
|
|
4172
|
+
//# sourceMappingURL=storage-value.test-suite.js.map
|