@aztec/kv-store 0.0.1-commit.f504929 → 0.0.1-commit.f5a9928
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/README.md +10 -1
- package/dest/bench/shared_map_bench.d.ts +19 -0
- package/dest/bench/shared_map_bench.d.ts.map +1 -0
- package/dest/bench/shared_map_bench.js +91 -0
- package/dest/deprecated/indexeddb/array.d.ts +22 -0
- package/dest/deprecated/indexeddb/array.d.ts.map +1 -0
- package/dest/deprecated/indexeddb/index.d.ts +7 -0
- package/dest/deprecated/indexeddb/index.d.ts.map +1 -0
- package/dest/deprecated/indexeddb/index.js +8 -0
- package/dest/deprecated/indexeddb/map.d.ts +38 -0
- package/dest/deprecated/indexeddb/map.d.ts.map +1 -0
- package/dest/deprecated/indexeddb/multi_map.d.ts +14 -0
- package/dest/deprecated/indexeddb/multi_map.d.ts.map +1 -0
- package/dest/{indexeddb → deprecated/indexeddb}/multi_map.js +2 -1
- package/dest/deprecated/indexeddb/set.d.ts +17 -0
- package/dest/deprecated/indexeddb/set.d.ts.map +1 -0
- package/dest/deprecated/indexeddb/singleton.d.ts +17 -0
- package/dest/deprecated/indexeddb/singleton.d.ts.map +1 -0
- package/dest/deprecated/indexeddb/store.d.ts +98 -0
- package/dest/deprecated/indexeddb/store.d.ts.map +1 -0
- package/dest/{indexeddb → deprecated/indexeddb}/store.js +2 -0
- package/dest/interfaces/array_test_suite.d.ts +1 -1
- package/dest/interfaces/array_test_suite.d.ts.map +1 -1
- package/dest/interfaces/array_test_suite.js +33 -34
- package/dest/interfaces/index.d.ts +2 -2
- package/dest/interfaces/index.d.ts.map +1 -1
- package/dest/interfaces/map_test_suite.d.ts +1 -1
- package/dest/interfaces/map_test_suite.d.ts.map +1 -1
- package/dest/interfaces/map_test_suite.js +32 -33
- package/dest/interfaces/multi_map_test_suite.d.ts +1 -1
- package/dest/interfaces/multi_map_test_suite.d.ts.map +1 -1
- package/dest/interfaces/multi_map_test_suite.js +68 -69
- package/dest/interfaces/set_test_suite.d.ts +1 -1
- package/dest/interfaces/set_test_suite.d.ts.map +1 -1
- package/dest/interfaces/set_test_suite.js +13 -14
- package/dest/interfaces/singleton_test_suite.d.ts +1 -1
- package/dest/interfaces/singleton_test_suite.d.ts.map +1 -1
- package/dest/interfaces/singleton_test_suite.js +6 -7
- package/dest/lmdb/index.d.ts +2 -2
- package/dest/lmdb/index.d.ts.map +1 -1
- package/dest/lmdb/index.js +2 -2
- package/dest/lmdb/store.d.ts +3 -3
- package/dest/lmdb/store.d.ts.map +1 -1
- package/dest/lmdb/store.js +12 -8
- package/dest/lmdb-v2/factory.d.ts +30 -4
- package/dest/lmdb-v2/factory.d.ts.map +1 -1
- package/dest/lmdb-v2/factory.js +62 -10
- package/dest/lmdb-v2/read_transaction.js +21 -19
- package/dest/lmdb-v2/store.d.ts +2 -2
- package/dest/lmdb-v2/store.d.ts.map +1 -1
- package/dest/lmdb-v2/store.js +4 -4
- package/dest/sqlite-opfs/array.d.ts +21 -0
- package/dest/sqlite-opfs/array.d.ts.map +1 -0
- package/dest/sqlite-opfs/array.js +128 -0
- package/dest/sqlite-opfs/errors.d.ts +54 -0
- package/dest/sqlite-opfs/errors.d.ts.map +1 -0
- package/dest/sqlite-opfs/errors.js +77 -0
- package/dest/sqlite-opfs/index.d.ts +14 -0
- package/dest/sqlite-opfs/index.d.ts.map +1 -0
- package/dest/sqlite-opfs/index.js +16 -0
- package/dest/sqlite-opfs/internal/ordered-binary-browser.d.ts +32 -0
- package/dest/sqlite-opfs/internal/ordered-binary-browser.d.ts.map +1 -0
- package/dest/sqlite-opfs/internal/ordered-binary-browser.js +448 -0
- package/dest/sqlite-opfs/manage.d.ts +22 -0
- package/dest/sqlite-opfs/manage.d.ts.map +1 -0
- package/dest/sqlite-opfs/manage.js +38 -0
- package/dest/sqlite-opfs/map.d.ts +35 -0
- package/dest/sqlite-opfs/map.d.ts.map +1 -0
- package/dest/sqlite-opfs/map.js +163 -0
- package/dest/sqlite-opfs/messages.d.ts +66 -0
- package/dest/sqlite-opfs/messages.d.ts.map +1 -0
- package/dest/sqlite-opfs/messages.js +5 -0
- package/dest/sqlite-opfs/multi_map.d.ts +16 -0
- package/dest/sqlite-opfs/multi_map.d.ts.map +1 -0
- package/dest/sqlite-opfs/multi_map.js +67 -0
- package/dest/sqlite-opfs/pool_integrity.d.ts +20 -0
- package/dest/sqlite-opfs/pool_integrity.d.ts.map +1 -0
- package/dest/sqlite-opfs/pool_integrity.js +282 -0
- package/dest/sqlite-opfs/pool_lock.d.ts +8 -0
- package/dest/sqlite-opfs/pool_lock.d.ts.map +1 -0
- package/dest/sqlite-opfs/pool_lock.js +47 -0
- package/dest/sqlite-opfs/set.d.ts +13 -0
- package/dest/sqlite-opfs/set.d.ts.map +1 -0
- package/dest/sqlite-opfs/set.js +19 -0
- package/dest/sqlite-opfs/singleton.d.ts +13 -0
- package/dest/sqlite-opfs/singleton.d.ts.map +1 -0
- package/dest/sqlite-opfs/singleton.js +48 -0
- package/dest/sqlite-opfs/store.d.ts +84 -0
- package/dest/sqlite-opfs/store.d.ts.map +1 -0
- package/dest/sqlite-opfs/store.js +317 -0
- package/dest/sqlite-opfs/worker.d.ts +2 -0
- package/dest/sqlite-opfs/worker.d.ts.map +1 -0
- package/dest/sqlite-opfs/worker.js +275 -0
- package/dest/stores/l2_tips_store.d.ts +7 -13
- package/dest/stores/l2_tips_store.d.ts.map +1 -1
- package/dest/stores/l2_tips_store.js +24 -43
- package/package.json +24 -22
- package/src/bench/shared_map_bench.ts +111 -0
- package/src/{indexeddb → deprecated/indexeddb}/array.ts +2 -2
- package/src/deprecated/indexeddb/index.ts +12 -0
- package/src/{indexeddb → deprecated/indexeddb}/map.ts +2 -2
- package/src/{indexeddb → deprecated/indexeddb}/multi_map.ts +5 -3
- package/src/{indexeddb → deprecated/indexeddb}/set.ts +2 -2
- package/src/{indexeddb → deprecated/indexeddb}/singleton.ts +2 -2
- package/src/{indexeddb → deprecated/indexeddb}/store.ts +10 -9
- package/src/interfaces/array_test_suite.ts +33 -35
- package/src/interfaces/index.ts +1 -1
- package/src/interfaces/map_test_suite.ts +32 -34
- package/src/interfaces/multi_map_test_suite.ts +65 -67
- package/src/interfaces/set_test_suite.ts +13 -15
- package/src/interfaces/singleton_test_suite.ts +6 -8
- package/src/lmdb/index.ts +3 -3
- package/src/lmdb/store.ts +12 -8
- package/src/lmdb-v2/factory.ts +86 -10
- package/src/lmdb-v2/read_transaction.ts +23 -23
- package/src/lmdb-v2/store.ts +4 -2
- package/src/sqlite-opfs/array.ts +124 -0
- package/src/sqlite-opfs/errors.ts +94 -0
- package/src/sqlite-opfs/index.ts +27 -0
- package/src/sqlite-opfs/internal/ordered-binary-browser.js +465 -0
- package/src/sqlite-opfs/manage.ts +46 -0
- package/src/sqlite-opfs/map.ts +163 -0
- package/src/sqlite-opfs/messages.ts +39 -0
- package/src/sqlite-opfs/multi_map.ts +74 -0
- package/src/sqlite-opfs/pool_integrity.ts +327 -0
- package/src/sqlite-opfs/pool_lock.ts +62 -0
- package/src/sqlite-opfs/set.ts +29 -0
- package/src/sqlite-opfs/singleton.ts +48 -0
- package/src/sqlite-opfs/store.ts +330 -0
- package/src/sqlite-opfs/worker.ts +259 -0
- package/src/stores/l2_tips_store.ts +20 -41
- package/dest/config.d.ts +0 -17
- package/dest/config.d.ts.map +0 -1
- package/dest/config.js +0 -26
- package/dest/indexeddb/array.d.ts +0 -22
- package/dest/indexeddb/array.d.ts.map +0 -1
- package/dest/indexeddb/index.d.ts +0 -7
- package/dest/indexeddb/index.d.ts.map +0 -1
- package/dest/indexeddb/index.js +0 -16
- package/dest/indexeddb/map.d.ts +0 -38
- package/dest/indexeddb/map.d.ts.map +0 -1
- package/dest/indexeddb/multi_map.d.ts +0 -14
- package/dest/indexeddb/multi_map.d.ts.map +0 -1
- package/dest/indexeddb/set.d.ts +0 -17
- package/dest/indexeddb/set.d.ts.map +0 -1
- package/dest/indexeddb/singleton.d.ts +0 -17
- package/dest/indexeddb/singleton.d.ts.map +0 -1
- package/dest/indexeddb/store.d.ts +0 -96
- package/dest/indexeddb/store.d.ts.map +0 -1
- package/src/config.ts +0 -36
- package/src/indexeddb/index.ts +0 -31
- /package/dest/{indexeddb → deprecated/indexeddb}/array.js +0 -0
- /package/dest/{indexeddb → deprecated/indexeddb}/map.js +0 -0
- /package/dest/{indexeddb → deprecated/indexeddb}/set.js +0 -0
- /package/dest/{indexeddb → deprecated/indexeddb}/singleton.js +0 -0
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { first } from '@aztec/foundation/iterable';
|
|
2
|
+
|
|
1
3
|
import { hash } from 'ohash';
|
|
2
4
|
|
|
3
|
-
import type { Key, Value } from '
|
|
4
|
-
import type { AztecAsyncMultiMap } from '
|
|
5
|
+
import type { Key, Value } from '../../interfaces/common.js';
|
|
6
|
+
import type { AztecAsyncMultiMap } from '../../interfaces/multi_map.js';
|
|
5
7
|
import { IndexedDBAztecMap } from './map.js';
|
|
6
8
|
|
|
7
9
|
/**
|
|
@@ -35,7 +37,7 @@ export class IndexedDBAztecMultiMap<K extends Key, V extends Value>
|
|
|
35
37
|
// Instead, we iterate in reverse order to get the last inserted entry
|
|
36
38
|
const index = this.db.index('keyCount');
|
|
37
39
|
const rangeQuery = IDBKeyRange.upperBound([this.container, this.normalizeKey(key), Number.MAX_SAFE_INTEGER]);
|
|
38
|
-
const maxEntry =
|
|
40
|
+
const maxEntry = await first(index.iterate(rangeQuery, 'prevunique'));
|
|
39
41
|
const count = maxEntry?.value?.keyCount ?? 0;
|
|
40
42
|
await this.db.put({
|
|
41
43
|
value: val,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { IDBPDatabase, IDBPObjectStore } from 'idb';
|
|
2
2
|
|
|
3
|
-
import type { Key, Range } from '
|
|
4
|
-
import type { AztecAsyncSet } from '
|
|
3
|
+
import type { Key, Range } from '../../interfaces/common.js';
|
|
4
|
+
import type { AztecAsyncSet } from '../../interfaces/set.js';
|
|
5
5
|
import { IndexedDBAztecMap } from './map.js';
|
|
6
6
|
import type { AztecIDBSchema } from './store.js';
|
|
7
7
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { IDBPDatabase, IDBPObjectStore } from 'idb';
|
|
2
2
|
import { hash } from 'ohash';
|
|
3
3
|
|
|
4
|
-
import type { Value } from '
|
|
5
|
-
import type { AztecAsyncSingleton } from '
|
|
4
|
+
import type { Value } from '../../interfaces/common.js';
|
|
5
|
+
import type { AztecAsyncSingleton } from '../../interfaces/singleton.js';
|
|
6
6
|
import type { AztecIDBSchema } from './store.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -3,14 +3,14 @@ import { SerialQueue } from '@aztec/foundation/queue';
|
|
|
3
3
|
|
|
4
4
|
import { type DBSchema, type IDBPDatabase, deleteDB, openDB } from 'idb';
|
|
5
5
|
|
|
6
|
-
import type { AztecAsyncArray } from '
|
|
7
|
-
import type { Key, StoreSize, Value } from '
|
|
8
|
-
import type { AztecAsyncCounter } from '
|
|
9
|
-
import type { AztecAsyncMap } from '
|
|
10
|
-
import type { AztecAsyncMultiMap } from '
|
|
11
|
-
import type { AztecAsyncSet } from '
|
|
12
|
-
import type { AztecAsyncSingleton } from '
|
|
13
|
-
import type { AztecAsyncKVStore } from '
|
|
6
|
+
import type { AztecAsyncArray } from '../../interfaces/array.js';
|
|
7
|
+
import type { Key, StoreSize, Value } from '../../interfaces/common.js';
|
|
8
|
+
import type { AztecAsyncCounter } from '../../interfaces/counter.js';
|
|
9
|
+
import type { AztecAsyncMap } from '../../interfaces/map.js';
|
|
10
|
+
import type { AztecAsyncMultiMap } from '../../interfaces/multi_map.js';
|
|
11
|
+
import type { AztecAsyncSet } from '../../interfaces/set.js';
|
|
12
|
+
import type { AztecAsyncSingleton } from '../../interfaces/singleton.js';
|
|
13
|
+
import type { AztecAsyncKVStore } from '../../interfaces/store.js';
|
|
14
14
|
import { IndexedDBAztecArray } from './array.js';
|
|
15
15
|
import { IndexedDBAztecMap } from './map.js';
|
|
16
16
|
import { IndexedDBAztecMultiMap } from './multi_map.js';
|
|
@@ -41,8 +41,9 @@ export interface AztecIDBSchema extends DBSchema {
|
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* A key-value store backed by IndexedDB.
|
|
44
|
+
*
|
|
45
|
+
* @deprecated The IndexedDB backend is being retired. Use `@aztec/kv-store/sqlite-opfs` instead.
|
|
44
46
|
*/
|
|
45
|
-
|
|
46
47
|
export class AztecIndexedDBStore implements AztecAsyncKVStore {
|
|
47
48
|
#rootDB: IDBPDatabase<AztecIDBSchema>;
|
|
48
49
|
#name: string;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { toArray } from '@aztec/foundation/iterable';
|
|
2
2
|
|
|
3
|
-
import { expect } from 'chai';
|
|
4
|
-
|
|
5
3
|
import type { AztecArray, AztecAsyncArray } from './array.js';
|
|
6
4
|
import type { AztecAsyncKVStore, AztecKVStore } from './store.js';
|
|
7
5
|
import { isSyncStore } from './utils.js';
|
|
@@ -53,12 +51,12 @@ export function describeAztecArray(
|
|
|
53
51
|
await arr.push(2);
|
|
54
52
|
await arr.push(3);
|
|
55
53
|
|
|
56
|
-
expect(await length()).
|
|
54
|
+
expect(await length()).toBe(3);
|
|
57
55
|
|
|
58
|
-
expect(await arr.pop()).
|
|
59
|
-
expect(await arr.pop()).
|
|
60
|
-
expect(await arr.pop()).
|
|
61
|
-
expect(await arr.pop()).
|
|
56
|
+
expect(await arr.pop()).toBe(3);
|
|
57
|
+
expect(await arr.pop()).toBe(2);
|
|
58
|
+
expect(await arr.pop()).toBe(1);
|
|
59
|
+
expect(await arr.pop()).toBe(undefined);
|
|
62
60
|
});
|
|
63
61
|
|
|
64
62
|
it('should be able to get values by index', async () => {
|
|
@@ -66,14 +64,14 @@ export function describeAztecArray(
|
|
|
66
64
|
await arr.push(2);
|
|
67
65
|
await arr.push(3);
|
|
68
66
|
|
|
69
|
-
expect(await at(0)).
|
|
70
|
-
expect(await at(1)).
|
|
71
|
-
expect(await at(2)).
|
|
72
|
-
expect(await at(3)).
|
|
73
|
-
expect(await at(-1)).
|
|
74
|
-
expect(await at(-2)).
|
|
75
|
-
expect(await at(-3)).
|
|
76
|
-
expect(await at(-4)).
|
|
67
|
+
expect(await at(0)).toBe(1);
|
|
68
|
+
expect(await at(1)).toBe(2);
|
|
69
|
+
expect(await at(2)).toBe(3);
|
|
70
|
+
expect(await at(3)).toBe(undefined);
|
|
71
|
+
expect(await at(-1)).toBe(3);
|
|
72
|
+
expect(await at(-2)).toBe(2);
|
|
73
|
+
expect(await at(-3)).toBe(1);
|
|
74
|
+
expect(await at(-4)).toBe(undefined);
|
|
77
75
|
});
|
|
78
76
|
|
|
79
77
|
it('should be able to set values by index', async () => {
|
|
@@ -81,27 +79,27 @@ export function describeAztecArray(
|
|
|
81
79
|
await arr.push(2);
|
|
82
80
|
await arr.push(3);
|
|
83
81
|
|
|
84
|
-
expect(await arr.setAt(0, 4)).
|
|
85
|
-
expect(await arr.setAt(1, 5)).
|
|
86
|
-
expect(await arr.setAt(2, 6)).
|
|
82
|
+
expect(await arr.setAt(0, 4)).toBe(true);
|
|
83
|
+
expect(await arr.setAt(1, 5)).toBe(true);
|
|
84
|
+
expect(await arr.setAt(2, 6)).toBe(true);
|
|
87
85
|
|
|
88
|
-
expect(await arr.setAt(3, 7)).
|
|
86
|
+
expect(await arr.setAt(3, 7)).toBe(false);
|
|
89
87
|
|
|
90
|
-
expect(await at(0)).
|
|
91
|
-
expect(await at(1)).
|
|
92
|
-
expect(await at(2)).
|
|
93
|
-
expect(await at(3)).
|
|
88
|
+
expect(await at(0)).toBe(4);
|
|
89
|
+
expect(await at(1)).toBe(5);
|
|
90
|
+
expect(await at(2)).toBe(6);
|
|
91
|
+
expect(await at(3)).toBe(undefined);
|
|
94
92
|
|
|
95
|
-
expect(await arr.setAt(-1, 8)).
|
|
96
|
-
expect(await arr.setAt(-2, 9)).
|
|
97
|
-
expect(await arr.setAt(-3, 10)).
|
|
93
|
+
expect(await arr.setAt(-1, 8)).toBe(true);
|
|
94
|
+
expect(await arr.setAt(-2, 9)).toBe(true);
|
|
95
|
+
expect(await arr.setAt(-3, 10)).toBe(true);
|
|
98
96
|
|
|
99
|
-
expect(await arr.setAt(-4, 11)).
|
|
97
|
+
expect(await arr.setAt(-4, 11)).toBe(false);
|
|
100
98
|
|
|
101
|
-
expect(await at(-1)).
|
|
102
|
-
expect(await at(-2)).
|
|
103
|
-
expect(await at(-3)).
|
|
104
|
-
expect(await at(-4)).
|
|
99
|
+
expect(await at(-1)).toBe(8);
|
|
100
|
+
expect(await at(-2)).toBe(9);
|
|
101
|
+
expect(await at(-3)).toBe(10);
|
|
102
|
+
expect(await at(-4)).toBe(undefined);
|
|
105
103
|
});
|
|
106
104
|
|
|
107
105
|
it('should be able to iterate over values', async () => {
|
|
@@ -109,8 +107,8 @@ export function describeAztecArray(
|
|
|
109
107
|
await arr.push(2);
|
|
110
108
|
await arr.push(3);
|
|
111
109
|
|
|
112
|
-
expect(await values()).
|
|
113
|
-
expect(await entries()).
|
|
110
|
+
expect(await values()).toEqual([1, 2, 3]);
|
|
111
|
+
expect(await entries()).toEqual([
|
|
114
112
|
[0, 1],
|
|
115
113
|
[1, 2],
|
|
116
114
|
[2, 3],
|
|
@@ -123,8 +121,8 @@ export function describeAztecArray(
|
|
|
123
121
|
await arr.push(3);
|
|
124
122
|
|
|
125
123
|
const arr2 = store.openArray<number>('test');
|
|
126
|
-
expect(await length(arr2)).
|
|
127
|
-
expect(await values(arr2)).
|
|
124
|
+
expect(await length(arr2)).toBe(3);
|
|
125
|
+
expect(await values(arr2)).toEqual(await values());
|
|
128
126
|
});
|
|
129
127
|
});
|
|
130
128
|
}
|
package/src/interfaces/index.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { toArray } from '@aztec/foundation/iterable';
|
|
2
2
|
|
|
3
|
-
import { expect } from 'chai';
|
|
4
|
-
|
|
5
3
|
import type { Key, Range } from './common.js';
|
|
6
4
|
import type { AztecAsyncMap, AztecMap } from './map.js';
|
|
7
5
|
import type { AztecAsyncKVStore, AztecKVStore } from './store.js';
|
|
@@ -59,9 +57,9 @@ export function describeAztecMap(
|
|
|
59
57
|
await map.set('foo', 'bar');
|
|
60
58
|
await map.set('baz', 'qux');
|
|
61
59
|
|
|
62
|
-
expect(await get('foo')).
|
|
63
|
-
expect(await get('baz')).
|
|
64
|
-
expect(await get('quux')).
|
|
60
|
+
expect(await get('foo')).toBe('bar');
|
|
61
|
+
expect(await get('baz')).toBe('qux');
|
|
62
|
+
expect(await get('quux')).toBe(undefined);
|
|
65
63
|
});
|
|
66
64
|
|
|
67
65
|
it('should be able to set many values', async () => {
|
|
@@ -69,7 +67,7 @@ export function describeAztecMap(
|
|
|
69
67
|
await map.setMany(pairs);
|
|
70
68
|
|
|
71
69
|
for (const { key, value } of pairs) {
|
|
72
|
-
expect(await get(key)).
|
|
70
|
+
expect(await get(key)).toBe(value);
|
|
73
71
|
}
|
|
74
72
|
});
|
|
75
73
|
|
|
@@ -77,14 +75,14 @@ export function describeAztecMap(
|
|
|
77
75
|
await map.set('foo', 'bar');
|
|
78
76
|
await map.set('foo', 'baz');
|
|
79
77
|
|
|
80
|
-
expect(await get('foo')).
|
|
78
|
+
expect(await get('foo')).toBe('baz');
|
|
81
79
|
});
|
|
82
80
|
|
|
83
81
|
it('should be able to set values if they do not exist', async () => {
|
|
84
|
-
expect(await map.setIfNotExists('foo', 'bar')).
|
|
85
|
-
expect(await map.setIfNotExists('foo', 'baz')).
|
|
82
|
+
expect(await map.setIfNotExists('foo', 'bar')).toBe(true);
|
|
83
|
+
expect(await map.setIfNotExists('foo', 'baz')).toBe(false);
|
|
86
84
|
|
|
87
|
-
expect(await get('foo')).
|
|
85
|
+
expect(await get('foo')).toBe('bar');
|
|
88
86
|
});
|
|
89
87
|
|
|
90
88
|
it('should be able to delete values', async () => {
|
|
@@ -93,56 +91,56 @@ export function describeAztecMap(
|
|
|
93
91
|
|
|
94
92
|
await map.delete('foo');
|
|
95
93
|
|
|
96
|
-
expect(await get('foo')).
|
|
97
|
-
expect(await get('baz')).
|
|
94
|
+
expect(await get('foo')).toBe(undefined);
|
|
95
|
+
expect(await get('baz')).toBe('qux');
|
|
98
96
|
});
|
|
99
97
|
|
|
100
98
|
it('should be able to return size of the map', async () => {
|
|
101
99
|
await map.set('foo', 'bar');
|
|
102
|
-
expect(await size()).
|
|
100
|
+
expect(await size()).toBe(1);
|
|
103
101
|
await map.set('baz', 'qux');
|
|
104
|
-
expect(await size()).
|
|
102
|
+
expect(await size()).toBe(2);
|
|
105
103
|
|
|
106
104
|
await map.delete('foo');
|
|
107
|
-
expect(await size()).
|
|
105
|
+
expect(await size()).toBe(1);
|
|
108
106
|
});
|
|
109
107
|
|
|
110
108
|
it('returns 0 for empty map size', async () => {
|
|
111
|
-
expect(await size()).
|
|
109
|
+
expect(await size()).toBe(0);
|
|
112
110
|
});
|
|
113
111
|
|
|
114
112
|
it('calculates size correctly across multiple operations', async () => {
|
|
115
|
-
expect(await size()).
|
|
113
|
+
expect(await size()).toBe(0);
|
|
116
114
|
|
|
117
115
|
// Add items
|
|
118
116
|
await map.set('a', 'value1');
|
|
119
117
|
await map.set('b', 'value2');
|
|
120
118
|
await map.set('c', 'value3');
|
|
121
|
-
expect(await size()).
|
|
119
|
+
expect(await size()).toBe(3);
|
|
122
120
|
|
|
123
121
|
// Update existing (size should not change)
|
|
124
122
|
await map.set('b', 'updated');
|
|
125
|
-
expect(await size()).
|
|
123
|
+
expect(await size()).toBe(3);
|
|
126
124
|
|
|
127
125
|
// Delete some
|
|
128
126
|
await map.delete('a');
|
|
129
|
-
expect(await size()).
|
|
127
|
+
expect(await size()).toBe(2);
|
|
130
128
|
|
|
131
129
|
// Delete all
|
|
132
130
|
await map.delete('b');
|
|
133
131
|
await map.delete('c');
|
|
134
|
-
expect(await size()).
|
|
132
|
+
expect(await size()).toBe(0);
|
|
135
133
|
});
|
|
136
134
|
|
|
137
135
|
it('should be able to iterate over entries when there are no keys', async () => {
|
|
138
|
-
expect(await entries()).
|
|
136
|
+
expect(await entries()).toEqual([]);
|
|
139
137
|
});
|
|
140
138
|
|
|
141
139
|
it('should be able to iterate over entries', async () => {
|
|
142
140
|
await map.set('foo', 'bar');
|
|
143
141
|
await map.set('baz', 'qux');
|
|
144
142
|
|
|
145
|
-
expect(await entries()).
|
|
143
|
+
expect(await entries()).toEqual([
|
|
146
144
|
['baz', 'qux'],
|
|
147
145
|
['foo', 'bar'],
|
|
148
146
|
]);
|
|
@@ -152,21 +150,21 @@ export function describeAztecMap(
|
|
|
152
150
|
await map.set('foo', 'bar');
|
|
153
151
|
await map.set('baz', 'quux');
|
|
154
152
|
|
|
155
|
-
expect(await values()).
|
|
153
|
+
expect(await values()).toEqual(['quux', 'bar']);
|
|
156
154
|
});
|
|
157
155
|
|
|
158
156
|
it('should be able to iterate over keys', async () => {
|
|
159
157
|
await map.set('foo', 'bar');
|
|
160
158
|
await map.set('baz', 'qux');
|
|
161
159
|
|
|
162
|
-
expect(await keys()).
|
|
160
|
+
expect(await keys()).toEqual(['baz', 'foo']);
|
|
163
161
|
});
|
|
164
162
|
|
|
165
163
|
it('should be able to iterate over string keys that represent numbers', async () => {
|
|
166
164
|
await map.set('0x22', 'bar');
|
|
167
165
|
await map.set('0x31', 'qux');
|
|
168
166
|
|
|
169
|
-
expect(await keys()).
|
|
167
|
+
expect(await keys()).toEqual(['0x22', '0x31']);
|
|
170
168
|
});
|
|
171
169
|
|
|
172
170
|
for (const [name, data] of [
|
|
@@ -186,14 +184,14 @@ export function describeAztecMap(
|
|
|
186
184
|
await map.set(c, 'c');
|
|
187
185
|
await map.set(d, 'd');
|
|
188
186
|
|
|
189
|
-
expect(await keys()).
|
|
190
|
-
expect(await keys({ start: b, end: c })).
|
|
191
|
-
expect(await keys({ start: b })).
|
|
192
|
-
expect(await keys({ end: c })).
|
|
193
|
-
expect(await keys({ start: b, end: c, reverse: true })).
|
|
194
|
-
expect(await keys({ start: b, limit: 1 })).
|
|
195
|
-
expect(await keys({ start: b, reverse: true })).
|
|
196
|
-
expect(await keys({ end: b, reverse: true })).
|
|
187
|
+
expect(await keys()).toEqual([a, b, c, d]);
|
|
188
|
+
expect(await keys({ start: b, end: c })).toEqual([b]);
|
|
189
|
+
expect(await keys({ start: b })).toEqual([b, c, d]);
|
|
190
|
+
expect(await keys({ end: c })).toEqual([a, b]);
|
|
191
|
+
expect(await keys({ start: b, end: c, reverse: true })).toEqual([c]);
|
|
192
|
+
expect(await keys({ start: b, limit: 1 })).toEqual([b]);
|
|
193
|
+
expect(await keys({ start: b, reverse: true })).toEqual([d, c]);
|
|
194
|
+
expect(await keys({ end: b, reverse: true })).toEqual([b, a]);
|
|
197
195
|
});
|
|
198
196
|
}
|
|
199
197
|
});
|