@aztec/kv-store 0.0.1-commit.96bb3f7 → 0.0.1-commit.993d240
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/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/indexeddb/array.js +18 -6
- package/dest/indexeddb/index.d.ts +3 -3
- package/dest/indexeddb/index.d.ts.map +1 -1
- package/dest/indexeddb/index.js +3 -6
- package/dest/indexeddb/map.d.ts +8 -2
- package/dest/indexeddb/map.d.ts.map +1 -1
- package/dest/indexeddb/map.js +23 -13
- package/dest/indexeddb/multi_map.d.ts +2 -1
- package/dest/indexeddb/multi_map.d.ts.map +1 -1
- package/dest/indexeddb/multi_map.js +16 -1
- package/dest/indexeddb/singleton.js +3 -1
- package/dest/indexeddb/store.d.ts +3 -3
- package/dest/indexeddb/store.d.ts.map +1 -1
- package/dest/indexeddb/store.js +6 -4
- 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 +74 -29
- 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 +84 -60
- 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/interfaces/utils.d.ts +2 -1
- package/dest/interfaces/utils.d.ts.map +1 -1
- package/dest/interfaces/utils.js +2 -1
- package/dest/lmdb/index.d.ts +3 -3
- package/dest/lmdb/index.d.ts.map +1 -1
- package/dest/lmdb/index.js +4 -4
- 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 +32 -7
- package/dest/lmdb-v2/factory.d.ts.map +1 -1
- package/dest/lmdb-v2/factory.js +71 -16
- package/dest/lmdb-v2/read_transaction.js +21 -19
- package/dest/lmdb-v2/store.d.ts +3 -3
- package/dest/lmdb-v2/store.d.ts.map +1 -1
- package/dest/lmdb-v2/store.js +5 -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 +27 -0
- package/dest/sqlite-opfs/errors.d.ts.map +1 -0
- package/dest/sqlite-opfs/errors.js +34 -0
- package/dest/sqlite-opfs/index.d.ts +16 -0
- package/dest/sqlite-opfs/index.d.ts.map +1 -0
- package/dest/sqlite-opfs/index.js +22 -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/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/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 +79 -0
- package/dest/sqlite-opfs/store.d.ts.map +1 -0
- package/dest/sqlite-opfs/store.js +281 -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 +249 -0
- package/dest/stores/l2_tips_store.d.ts +3 -3
- package/dest/stores/l2_tips_store.d.ts.map +1 -1
- package/dest/stores/l2_tips_store.js +2 -2
- package/dest/utils.d.ts +9 -6
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +51 -16
- package/package.json +30 -26
- package/src/bench/shared_map_bench.ts +111 -0
- package/src/indexeddb/array.ts +4 -4
- package/src/indexeddb/index.ts +9 -7
- package/src/indexeddb/map.ts +24 -11
- package/src/indexeddb/multi_map.ts +15 -1
- package/src/indexeddb/singleton.ts +1 -1
- package/src/indexeddb/store.ts +13 -6
- package/src/interfaces/array_test_suite.ts +33 -35
- package/src/interfaces/index.ts +1 -1
- package/src/interfaces/map_test_suite.ts +56 -30
- package/src/interfaces/multi_map_test_suite.ts +88 -58
- package/src/interfaces/set_test_suite.ts +13 -15
- package/src/interfaces/singleton_test_suite.ts +6 -8
- package/src/interfaces/utils.ts +1 -0
- package/src/lmdb/index.ts +10 -5
- package/src/lmdb/store.ts +12 -8
- package/src/lmdb-v2/factory.ts +93 -19
- package/src/lmdb-v2/read_transaction.ts +23 -23
- package/src/lmdb-v2/store.ts +7 -4
- package/src/sqlite-opfs/array.ts +124 -0
- package/src/sqlite-opfs/errors.ts +44 -0
- package/src/sqlite-opfs/index.ts +39 -0
- package/src/sqlite-opfs/internal/ordered-binary-browser.js +465 -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/set.ts +29 -0
- package/src/sqlite-opfs/singleton.ts +48 -0
- package/src/sqlite-opfs/store.ts +296 -0
- package/src/sqlite-opfs/worker.ts +231 -0
- package/src/stores/l2_tips_store.ts +3 -2
- package/src/utils.ts +79 -21
- package/dest/config.d.ts +0 -17
- package/dest/config.d.ts.map +0 -1
- package/dest/config.js +0 -26
- package/src/config.ts +0 -36
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { toArray } from '@aztec/foundation/iterable';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
2
|
import { isSyncStore } from './utils.js';
|
|
4
3
|
export function describeAztecMap(testName, getStore, forceAsync = false) {
|
|
5
4
|
describe(testName, ()=>{
|
|
@@ -30,9 +29,9 @@ export function describeAztecMap(testName, getStore, forceAsync = false) {
|
|
|
30
29
|
it('should be able to set and get values', async ()=>{
|
|
31
30
|
await map.set('foo', 'bar');
|
|
32
31
|
await map.set('baz', 'qux');
|
|
33
|
-
expect(await get('foo')).
|
|
34
|
-
expect(await get('baz')).
|
|
35
|
-
expect(await get('quux')).
|
|
32
|
+
expect(await get('foo')).toBe('bar');
|
|
33
|
+
expect(await get('baz')).toBe('qux');
|
|
34
|
+
expect(await get('quux')).toBe(undefined);
|
|
36
35
|
});
|
|
37
36
|
it('should be able to set many values', async ()=>{
|
|
38
37
|
const pairs = Array.from({
|
|
@@ -43,41 +42,62 @@ export function describeAztecMap(testName, getStore, forceAsync = false) {
|
|
|
43
42
|
}));
|
|
44
43
|
await map.setMany(pairs);
|
|
45
44
|
for (const { key, value } of pairs){
|
|
46
|
-
expect(await get(key)).
|
|
45
|
+
expect(await get(key)).toBe(value);
|
|
47
46
|
}
|
|
48
47
|
});
|
|
49
48
|
it('should be able to overwrite values', async ()=>{
|
|
50
49
|
await map.set('foo', 'bar');
|
|
51
50
|
await map.set('foo', 'baz');
|
|
52
|
-
expect(await get('foo')).
|
|
51
|
+
expect(await get('foo')).toBe('baz');
|
|
53
52
|
});
|
|
54
53
|
it('should be able to set values if they do not exist', async ()=>{
|
|
55
|
-
expect(await map.setIfNotExists('foo', 'bar')).
|
|
56
|
-
expect(await map.setIfNotExists('foo', 'baz')).
|
|
57
|
-
expect(await get('foo')).
|
|
54
|
+
expect(await map.setIfNotExists('foo', 'bar')).toBe(true);
|
|
55
|
+
expect(await map.setIfNotExists('foo', 'baz')).toBe(false);
|
|
56
|
+
expect(await get('foo')).toBe('bar');
|
|
58
57
|
});
|
|
59
58
|
it('should be able to delete values', async ()=>{
|
|
60
59
|
await map.set('foo', 'bar');
|
|
61
60
|
await map.set('baz', 'qux');
|
|
62
61
|
await map.delete('foo');
|
|
63
|
-
expect(await get('foo')).
|
|
64
|
-
expect(await get('baz')).
|
|
62
|
+
expect(await get('foo')).toBe(undefined);
|
|
63
|
+
expect(await get('baz')).toBe('qux');
|
|
65
64
|
});
|
|
66
65
|
it('should be able to return size of the map', async ()=>{
|
|
67
66
|
await map.set('foo', 'bar');
|
|
68
|
-
expect(await size()).
|
|
67
|
+
expect(await size()).toBe(1);
|
|
69
68
|
await map.set('baz', 'qux');
|
|
70
|
-
expect(await size()).
|
|
69
|
+
expect(await size()).toBe(2);
|
|
71
70
|
await map.delete('foo');
|
|
72
|
-
expect(await size()).
|
|
71
|
+
expect(await size()).toBe(1);
|
|
72
|
+
});
|
|
73
|
+
it('returns 0 for empty map size', async ()=>{
|
|
74
|
+
expect(await size()).toBe(0);
|
|
75
|
+
});
|
|
76
|
+
it('calculates size correctly across multiple operations', async ()=>{
|
|
77
|
+
expect(await size()).toBe(0);
|
|
78
|
+
// Add items
|
|
79
|
+
await map.set('a', 'value1');
|
|
80
|
+
await map.set('b', 'value2');
|
|
81
|
+
await map.set('c', 'value3');
|
|
82
|
+
expect(await size()).toBe(3);
|
|
83
|
+
// Update existing (size should not change)
|
|
84
|
+
await map.set('b', 'updated');
|
|
85
|
+
expect(await size()).toBe(3);
|
|
86
|
+
// Delete some
|
|
87
|
+
await map.delete('a');
|
|
88
|
+
expect(await size()).toBe(2);
|
|
89
|
+
// Delete all
|
|
90
|
+
await map.delete('b');
|
|
91
|
+
await map.delete('c');
|
|
92
|
+
expect(await size()).toBe(0);
|
|
73
93
|
});
|
|
74
94
|
it('should be able to iterate over entries when there are no keys', async ()=>{
|
|
75
|
-
expect(await entries()).
|
|
95
|
+
expect(await entries()).toEqual([]);
|
|
76
96
|
});
|
|
77
97
|
it('should be able to iterate over entries', async ()=>{
|
|
78
98
|
await map.set('foo', 'bar');
|
|
79
99
|
await map.set('baz', 'qux');
|
|
80
|
-
expect(await entries()).
|
|
100
|
+
expect(await entries()).toEqual([
|
|
81
101
|
[
|
|
82
102
|
'baz',
|
|
83
103
|
'qux'
|
|
@@ -91,7 +111,7 @@ export function describeAztecMap(testName, getStore, forceAsync = false) {
|
|
|
91
111
|
it('should be able to iterate over values', async ()=>{
|
|
92
112
|
await map.set('foo', 'bar');
|
|
93
113
|
await map.set('baz', 'quux');
|
|
94
|
-
expect(await values()).
|
|
114
|
+
expect(await values()).toEqual([
|
|
95
115
|
'quux',
|
|
96
116
|
'bar'
|
|
97
117
|
]);
|
|
@@ -99,7 +119,7 @@ export function describeAztecMap(testName, getStore, forceAsync = false) {
|
|
|
99
119
|
it('should be able to iterate over keys', async ()=>{
|
|
100
120
|
await map.set('foo', 'bar');
|
|
101
121
|
await map.set('baz', 'qux');
|
|
102
|
-
expect(await keys()).
|
|
122
|
+
expect(await keys()).toEqual([
|
|
103
123
|
'baz',
|
|
104
124
|
'foo'
|
|
105
125
|
]);
|
|
@@ -107,7 +127,7 @@ export function describeAztecMap(testName, getStore, forceAsync = false) {
|
|
|
107
127
|
it('should be able to iterate over string keys that represent numbers', async ()=>{
|
|
108
128
|
await map.set('0x22', 'bar');
|
|
109
129
|
await map.set('0x31', 'qux');
|
|
110
|
-
expect(await keys()).
|
|
130
|
+
expect(await keys()).toEqual([
|
|
111
131
|
'0x22',
|
|
112
132
|
'0x31'
|
|
113
133
|
]);
|
|
@@ -131,8 +151,15 @@ export function describeAztecMap(testName, getStore, forceAsync = false) {
|
|
|
131
151
|
4
|
|
132
152
|
]
|
|
133
153
|
],
|
|
134
|
-
|
|
135
|
-
|
|
154
|
+
[
|
|
155
|
+
'negative numbers',
|
|
156
|
+
[
|
|
157
|
+
-4,
|
|
158
|
+
-3,
|
|
159
|
+
-2,
|
|
160
|
+
-1
|
|
161
|
+
]
|
|
162
|
+
],
|
|
136
163
|
[
|
|
137
164
|
'strings',
|
|
138
165
|
[
|
|
@@ -150,6 +177,24 @@ export function describeAztecMap(testName, getStore, forceAsync = false) {
|
|
|
150
177
|
2,
|
|
151
178
|
3
|
|
152
179
|
]
|
|
180
|
+
],
|
|
181
|
+
[
|
|
182
|
+
'large numbers',
|
|
183
|
+
[
|
|
184
|
+
100,
|
|
185
|
+
999,
|
|
186
|
+
1000,
|
|
187
|
+
1001
|
|
188
|
+
]
|
|
189
|
+
],
|
|
190
|
+
[
|
|
191
|
+
'mixed negative and positive',
|
|
192
|
+
[
|
|
193
|
+
-1000,
|
|
194
|
+
-1,
|
|
195
|
+
1,
|
|
196
|
+
1000
|
|
197
|
+
]
|
|
153
198
|
]
|
|
154
199
|
]){
|
|
155
200
|
it(`supports range queries over ${name} keys`, async ()=>{
|
|
@@ -158,7 +203,7 @@ export function describeAztecMap(testName, getStore, forceAsync = false) {
|
|
|
158
203
|
await map.set(b, 'b');
|
|
159
204
|
await map.set(c, 'c');
|
|
160
205
|
await map.set(d, 'd');
|
|
161
|
-
expect(await keys()).
|
|
206
|
+
expect(await keys()).toEqual([
|
|
162
207
|
a,
|
|
163
208
|
b,
|
|
164
209
|
c,
|
|
@@ -167,19 +212,19 @@ export function describeAztecMap(testName, getStore, forceAsync = false) {
|
|
|
167
212
|
expect(await keys({
|
|
168
213
|
start: b,
|
|
169
214
|
end: c
|
|
170
|
-
})).
|
|
215
|
+
})).toEqual([
|
|
171
216
|
b
|
|
172
217
|
]);
|
|
173
218
|
expect(await keys({
|
|
174
219
|
start: b
|
|
175
|
-
})).
|
|
220
|
+
})).toEqual([
|
|
176
221
|
b,
|
|
177
222
|
c,
|
|
178
223
|
d
|
|
179
224
|
]);
|
|
180
225
|
expect(await keys({
|
|
181
226
|
end: c
|
|
182
|
-
})).
|
|
227
|
+
})).toEqual([
|
|
183
228
|
a,
|
|
184
229
|
b
|
|
185
230
|
]);
|
|
@@ -187,26 +232,26 @@ export function describeAztecMap(testName, getStore, forceAsync = false) {
|
|
|
187
232
|
start: b,
|
|
188
233
|
end: c,
|
|
189
234
|
reverse: true
|
|
190
|
-
})).
|
|
235
|
+
})).toEqual([
|
|
191
236
|
c
|
|
192
237
|
]);
|
|
193
238
|
expect(await keys({
|
|
194
239
|
start: b,
|
|
195
240
|
limit: 1
|
|
196
|
-
})).
|
|
241
|
+
})).toEqual([
|
|
197
242
|
b
|
|
198
243
|
]);
|
|
199
244
|
expect(await keys({
|
|
200
245
|
start: b,
|
|
201
246
|
reverse: true
|
|
202
|
-
})).
|
|
247
|
+
})).toEqual([
|
|
203
248
|
d,
|
|
204
249
|
c
|
|
205
250
|
]);
|
|
206
251
|
expect(await keys({
|
|
207
252
|
end: b,
|
|
208
253
|
reverse: true
|
|
209
|
-
})).
|
|
254
|
+
})).toEqual([
|
|
210
255
|
b,
|
|
211
256
|
a
|
|
212
257
|
]);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { AztecAsyncKVStore, AztecKVStore } from './store.js';
|
|
2
2
|
export declare function describeAztecMultiMap(testName: string, getStore: () => AztecKVStore | Promise<AztecAsyncKVStore>, forceAsync?: boolean): void;
|
|
3
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibXVsdGlfbWFwX3Rlc3Rfc3VpdGUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9pbnRlcmZhY2VzL211bHRpX21hcF90ZXN0X3N1aXRlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUlBLE9BQU8sS0FBSyxFQUFFLGlCQUFpQixFQUFFLFlBQVksRUFBRSxNQUFNLFlBQVksQ0FBQztBQUdsRSx3QkFBZ0IscUJBQXFCLENBQ25DLFFBQVEsRUFBRSxNQUFNLEVBQ2hCLFFBQVEsRUFBRSxNQUFNLFlBQVksR0FBRyxPQUFPLENBQUMsaUJBQWlCLENBQUMsRUFDekQsVUFBVSxHQUFFLE9BQWUsUUF5VzVCIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multi_map_test_suite.d.ts","sourceRoot":"","sources":["../../src/interfaces/multi_map_test_suite.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"multi_map_test_suite.d.ts","sourceRoot":"","sources":["../../src/interfaces/multi_map_test_suite.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAGlE,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,YAAY,GAAG,OAAO,CAAC,iBAAiB,CAAC,EACzD,UAAU,GAAE,OAAe,QAyW5B"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { toArray } from '@aztec/foundation/iterable';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
2
|
import { isSyncStore } from './utils.js';
|
|
4
3
|
export function describeAztecMultiMap(testName, getStore, forceAsync = false) {
|
|
5
4
|
describe(testName, ()=>{
|
|
@@ -36,37 +35,62 @@ export function describeAztecMultiMap(testName, getStore, forceAsync = false) {
|
|
|
36
35
|
it('should be able to set and get values', async ()=>{
|
|
37
36
|
await multiMap.set('foo', 'bar');
|
|
38
37
|
await multiMap.set('baz', 'qux');
|
|
39
|
-
expect(await get('foo')).
|
|
40
|
-
expect(await get('baz')).
|
|
41
|
-
expect(await get('quux')).
|
|
38
|
+
expect(await get('foo')).toBe('bar');
|
|
39
|
+
expect(await get('baz')).toBe('qux');
|
|
40
|
+
expect(await get('quux')).toBe(undefined);
|
|
42
41
|
});
|
|
43
42
|
it('should be able to set values if they do not exist', async ()=>{
|
|
44
|
-
expect(await multiMap.setIfNotExists('foo', 'bar')).
|
|
45
|
-
expect(await multiMap.setIfNotExists('foo', 'baz')).
|
|
46
|
-
expect(await get('foo')).
|
|
43
|
+
expect(await multiMap.setIfNotExists('foo', 'bar')).toBe(true);
|
|
44
|
+
expect(await multiMap.setIfNotExists('foo', 'baz')).toBe(false);
|
|
45
|
+
expect(await get('foo')).toBe('bar');
|
|
47
46
|
});
|
|
48
47
|
it('should be able to delete values', async ()=>{
|
|
49
48
|
await multiMap.set('foo', 'bar');
|
|
50
49
|
await multiMap.set('baz', 'qux');
|
|
51
50
|
await multiMap.delete('foo');
|
|
52
|
-
expect(await get('foo')).
|
|
53
|
-
expect(await get('baz')).
|
|
51
|
+
expect(await get('foo')).toBe(undefined);
|
|
52
|
+
expect(await get('baz')).toBe('qux');
|
|
54
53
|
});
|
|
55
54
|
it('should be able to get size of the map', async ()=>{
|
|
56
55
|
await multiMap.set('foo', 'bar');
|
|
57
|
-
expect(await size()).
|
|
56
|
+
expect(await size()).toBe(1);
|
|
58
57
|
await multiMap.set('baz', 'qux');
|
|
59
|
-
expect(await size()).
|
|
58
|
+
expect(await size()).toBe(2);
|
|
60
59
|
await multiMap.delete('foo');
|
|
61
|
-
expect(await size()).
|
|
60
|
+
expect(await size()).toBe(1);
|
|
61
|
+
});
|
|
62
|
+
it('returns 0 for empty multimap size', async ()=>{
|
|
63
|
+
expect(await size()).toBe(0);
|
|
64
|
+
});
|
|
65
|
+
it('calculates size correctly with multiple values per key', async ()=>{
|
|
66
|
+
expect(await size()).toBe(0);
|
|
67
|
+
// Add multiple values for same key
|
|
68
|
+
await multiMap.set('key1', 'value1');
|
|
69
|
+
expect(await size()).toBe(1);
|
|
70
|
+
await multiMap.set('key1', 'value2');
|
|
71
|
+
expect(await size()).toBe(2);
|
|
72
|
+
await multiMap.set('key1', 'value3');
|
|
73
|
+
expect(await size()).toBe(3);
|
|
74
|
+
// Add values for different key
|
|
75
|
+
await multiMap.set('key2', 'value4');
|
|
76
|
+
expect(await size()).toBe(4);
|
|
77
|
+
// Delete one value from key1
|
|
78
|
+
await multiMap.deleteValue('key1', 'value2');
|
|
79
|
+
expect(await size()).toBe(3);
|
|
80
|
+
// Delete entire key
|
|
81
|
+
await multiMap.delete('key1');
|
|
82
|
+
expect(await size()).toBe(1);
|
|
83
|
+
// Delete last key
|
|
84
|
+
await multiMap.delete('key2');
|
|
85
|
+
expect(await size()).toBe(0);
|
|
62
86
|
});
|
|
63
87
|
it('should be able to iterate over entries when there are no keys', async ()=>{
|
|
64
|
-
expect(await entries()).
|
|
88
|
+
expect(await entries()).toEqual([]);
|
|
65
89
|
});
|
|
66
90
|
it('should be able to iterate over entries', async ()=>{
|
|
67
91
|
await multiMap.set('foo', 'bar');
|
|
68
92
|
await multiMap.set('baz', 'qux');
|
|
69
|
-
expect(await entries()).
|
|
93
|
+
expect(await entries()).toEqual([
|
|
70
94
|
[
|
|
71
95
|
'baz',
|
|
72
96
|
'qux'
|
|
@@ -80,7 +104,7 @@ export function describeAztecMultiMap(testName, getStore, forceAsync = false) {
|
|
|
80
104
|
it('should be able to iterate over values', async ()=>{
|
|
81
105
|
await multiMap.set('foo', 'bar');
|
|
82
106
|
await multiMap.set('baz', 'quux');
|
|
83
|
-
expect(await values()).
|
|
107
|
+
expect(await values()).toEqual([
|
|
84
108
|
'quux',
|
|
85
109
|
'bar'
|
|
86
110
|
]);
|
|
@@ -88,7 +112,7 @@ export function describeAztecMultiMap(testName, getStore, forceAsync = false) {
|
|
|
88
112
|
it('should be able to iterate over keys', async ()=>{
|
|
89
113
|
await multiMap.set('foo', 'bar');
|
|
90
114
|
await multiMap.set('baz', 'qux');
|
|
91
|
-
expect(await keys()).
|
|
115
|
+
expect(await keys()).toEqual([
|
|
92
116
|
'baz',
|
|
93
117
|
'foo'
|
|
94
118
|
]);
|
|
@@ -96,7 +120,7 @@ export function describeAztecMultiMap(testName, getStore, forceAsync = false) {
|
|
|
96
120
|
it('should be able to get multiple values for a single key', async ()=>{
|
|
97
121
|
await multiMap.set('foo', 'bar');
|
|
98
122
|
await multiMap.set('foo', 'baz');
|
|
99
|
-
expect(await getValues('foo')).
|
|
123
|
+
expect(await getValues('foo')).toEqual([
|
|
100
124
|
'bar',
|
|
101
125
|
'baz'
|
|
102
126
|
]);
|
|
@@ -104,7 +128,7 @@ export function describeAztecMultiMap(testName, getStore, forceAsync = false) {
|
|
|
104
128
|
it('should ignore multiple identical values', async ()=>{
|
|
105
129
|
await multiMap.set('foo', 'bar');
|
|
106
130
|
await multiMap.set('foo', 'bar');
|
|
107
|
-
expect(await getValues('foo')).
|
|
131
|
+
expect(await getValues('foo')).toEqual([
|
|
108
132
|
'bar'
|
|
109
133
|
]);
|
|
110
134
|
});
|
|
@@ -113,7 +137,7 @@ export function describeAztecMultiMap(testName, getStore, forceAsync = false) {
|
|
|
113
137
|
await multiMap.set('foo', '2');
|
|
114
138
|
await multiMap.set('foo', '3');
|
|
115
139
|
await multiMap.deleteValue('foo', '2');
|
|
116
|
-
expect(await getValues('foo')).
|
|
140
|
+
expect(await getValues('foo')).toEqual([
|
|
117
141
|
'1',
|
|
118
142
|
'3'
|
|
119
143
|
]);
|
|
@@ -122,25 +146,25 @@ export function describeAztecMultiMap(testName, getStore, forceAsync = false) {
|
|
|
122
146
|
await multiMap.set('foo', '1');
|
|
123
147
|
await multiMap.set('foo', '2');
|
|
124
148
|
await multiMap.set('foo', '3');
|
|
125
|
-
expect(await size()).
|
|
149
|
+
expect(await size()).toBe(3);
|
|
126
150
|
await multiMap.set('bar', '1');
|
|
127
151
|
await multiMap.set('bar', '2');
|
|
128
152
|
await multiMap.set('bar', '3');
|
|
129
|
-
expect(await size()).
|
|
153
|
+
expect(await size()).toBe(6);
|
|
130
154
|
await multiMap.deleteValue('foo', '2');
|
|
131
|
-
expect(await size()).
|
|
155
|
+
expect(await size()).toBe(5);
|
|
132
156
|
});
|
|
133
157
|
it('should be able to delete the last and first values for a key', async ()=>{
|
|
134
158
|
await multiMap.set('foo', '1');
|
|
135
159
|
await multiMap.set('foo', '2');
|
|
136
160
|
await multiMap.set('foo', '3');
|
|
137
161
|
await multiMap.deleteValue('foo', '1');
|
|
138
|
-
expect(await getValues('foo')).
|
|
162
|
+
expect(await getValues('foo')).toEqual([
|
|
139
163
|
'2',
|
|
140
164
|
'3'
|
|
141
165
|
]);
|
|
142
166
|
await multiMap.deleteValue('foo', '3');
|
|
143
|
-
expect(await getValues('foo')).
|
|
167
|
+
expect(await getValues('foo')).toEqual([
|
|
144
168
|
'2'
|
|
145
169
|
]);
|
|
146
170
|
});
|
|
@@ -151,7 +175,7 @@ export function describeAztecMultiMap(testName, getStore, forceAsync = false) {
|
|
|
151
175
|
await multiMap.deleteValue('foo', '1');
|
|
152
176
|
await multiMap.deleteValue('foo', '3');
|
|
153
177
|
await multiMap.deleteValue('foo', '2');
|
|
154
|
-
expect(await getValues('foo')).
|
|
178
|
+
expect(await getValues('foo')).toEqual([]);
|
|
155
179
|
});
|
|
156
180
|
it('should be able to insert after deletion', async ()=>{
|
|
157
181
|
await multiMap.set('foo', '1');
|
|
@@ -159,14 +183,14 @@ export function describeAztecMultiMap(testName, getStore, forceAsync = false) {
|
|
|
159
183
|
await multiMap.set('foo', '3');
|
|
160
184
|
await multiMap.deleteValue('foo', '2');
|
|
161
185
|
await multiMap.set('foo', 'bar');
|
|
162
|
-
expect(await getValues('foo')).
|
|
186
|
+
expect(await getValues('foo')).toEqual([
|
|
163
187
|
'1',
|
|
164
188
|
'3',
|
|
165
189
|
'bar'
|
|
166
190
|
]);
|
|
167
191
|
// Delete the just-added entry
|
|
168
192
|
await multiMap.deleteValue('foo', 'bar');
|
|
169
|
-
expect(await getValues('foo')).
|
|
193
|
+
expect(await getValues('foo')).toEqual([
|
|
170
194
|
'1',
|
|
171
195
|
'3'
|
|
172
196
|
]);
|
|
@@ -175,7 +199,7 @@ export function describeAztecMultiMap(testName, getStore, forceAsync = false) {
|
|
|
175
199
|
// LMDB and IndexedDB behave differently here, the former ordering by value and the latter by insertion. This is
|
|
176
200
|
// fine because there is no expectation for values in a multimap to be ordered.
|
|
177
201
|
const values = (await getValues('foo')).sort((a, b)=>a.localeCompare(b));
|
|
178
|
-
expect(values).
|
|
202
|
+
expect(values).toEqual([
|
|
179
203
|
'1',
|
|
180
204
|
'2',
|
|
181
205
|
'3'
|
|
@@ -187,7 +211,7 @@ export function describeAztecMultiMap(testName, getStore, forceAsync = false) {
|
|
|
187
211
|
// Insert some more
|
|
188
212
|
await multiMap.set('foo', 'baz');
|
|
189
213
|
await multiMap.set('foo', 'qux');
|
|
190
|
-
expect(await getValues('foo')).
|
|
214
|
+
expect(await getValues('foo')).toEqual([
|
|
191
215
|
'baz',
|
|
192
216
|
'qux'
|
|
193
217
|
]);
|
|
@@ -200,19 +224,19 @@ export function describeAztecMultiMap(testName, getStore, forceAsync = false) {
|
|
|
200
224
|
expect(await keys({
|
|
201
225
|
start: 'b',
|
|
202
226
|
end: 'c'
|
|
203
|
-
})).
|
|
227
|
+
})).toEqual([
|
|
204
228
|
'b'
|
|
205
229
|
]);
|
|
206
230
|
expect(await keys({
|
|
207
231
|
start: 'b'
|
|
208
|
-
})).
|
|
232
|
+
})).toEqual([
|
|
209
233
|
'b',
|
|
210
234
|
'c',
|
|
211
235
|
'd'
|
|
212
236
|
]);
|
|
213
237
|
expect(await keys({
|
|
214
238
|
end: 'c'
|
|
215
|
-
})).
|
|
239
|
+
})).toEqual([
|
|
216
240
|
'a',
|
|
217
241
|
'b'
|
|
218
242
|
]);
|
|
@@ -220,86 +244,86 @@ export function describeAztecMultiMap(testName, getStore, forceAsync = false) {
|
|
|
220
244
|
start: 'b',
|
|
221
245
|
end: 'c',
|
|
222
246
|
reverse: true
|
|
223
|
-
})).
|
|
247
|
+
})).toEqual([
|
|
224
248
|
'c'
|
|
225
249
|
]);
|
|
226
250
|
expect(await keys({
|
|
227
251
|
start: 'b',
|
|
228
252
|
limit: 1
|
|
229
|
-
})).
|
|
253
|
+
})).toEqual([
|
|
230
254
|
'b'
|
|
231
255
|
]);
|
|
232
256
|
expect(await keys({
|
|
233
257
|
start: 'b',
|
|
234
258
|
reverse: true
|
|
235
|
-
})).
|
|
259
|
+
})).toEqual([
|
|
236
260
|
'd',
|
|
237
261
|
'c'
|
|
238
262
|
]);
|
|
239
263
|
expect(await keys({
|
|
240
264
|
end: 'b',
|
|
241
265
|
reverse: true
|
|
242
|
-
})).
|
|
266
|
+
})).toEqual([
|
|
243
267
|
'b',
|
|
244
268
|
'a'
|
|
245
269
|
]);
|
|
246
270
|
});
|
|
247
271
|
it('returns 0 for missing key', async ()=>{
|
|
248
|
-
expect(await getValueCount('missing')).
|
|
272
|
+
expect(await getValueCount('missing')).toBe(0);
|
|
249
273
|
});
|
|
250
274
|
it('counts a single value', async ()=>{
|
|
251
275
|
await multiMap.set('foo', 'bar');
|
|
252
|
-
expect(await getValueCount('foo')).
|
|
276
|
+
expect(await getValueCount('foo')).toBe(1);
|
|
253
277
|
});
|
|
254
278
|
it('counts multiple distinct values for same key', async ()=>{
|
|
255
279
|
await multiMap.set('foo', 'bar');
|
|
256
280
|
await multiMap.set('foo', 'baz');
|
|
257
281
|
await multiMap.set('foo', 'qux');
|
|
258
|
-
expect(await getValueCount('foo')).
|
|
282
|
+
expect(await getValueCount('foo')).toBe(3);
|
|
259
283
|
});
|
|
260
284
|
it('does not increase count for duplicate inserts', async ()=>{
|
|
261
285
|
await multiMap.set('foo', 'bar');
|
|
262
286
|
await multiMap.set('foo', 'bar');
|
|
263
287
|
await multiMap.set('foo', 'baz');
|
|
264
288
|
await multiMap.set('foo', 'baz');
|
|
265
|
-
expect(await getValueCount('foo')).
|
|
266
|
-
expect(await getValues('foo')).
|
|
289
|
+
expect(await getValueCount('foo')).toBe(2);
|
|
290
|
+
expect((await getValues('foo')).sort()).toEqual([
|
|
267
291
|
'bar',
|
|
268
292
|
'baz'
|
|
269
|
-
]);
|
|
293
|
+
].sort());
|
|
270
294
|
});
|
|
271
295
|
it('decrements when deleting a single value', async ()=>{
|
|
272
296
|
await multiMap.set('foo', '1');
|
|
273
297
|
await multiMap.set('foo', '2');
|
|
274
298
|
await multiMap.set('foo', '3');
|
|
275
|
-
expect(await getValueCount('foo')).
|
|
299
|
+
expect(await getValueCount('foo')).toBe(3);
|
|
276
300
|
await multiMap.deleteValue('foo', '2');
|
|
277
|
-
expect(await getValueCount('foo')).
|
|
278
|
-
expect(await getValues('foo')).
|
|
301
|
+
expect(await getValueCount('foo')).toBe(2);
|
|
302
|
+
expect((await getValues('foo')).sort()).toEqual([
|
|
279
303
|
'1',
|
|
280
304
|
'3'
|
|
281
|
-
]);
|
|
305
|
+
].sort());
|
|
282
306
|
});
|
|
283
307
|
it('does not change count when deleting a non-existent value', async ()=>{
|
|
284
308
|
await multiMap.set('foo', '1');
|
|
285
309
|
await multiMap.set('foo', '3');
|
|
286
|
-
expect(await getValueCount('foo')).
|
|
310
|
+
expect(await getValueCount('foo')).toBe(2);
|
|
287
311
|
await multiMap.deleteValue('foo', '2');
|
|
288
|
-
expect(await getValueCount('foo')).
|
|
312
|
+
expect(await getValueCount('foo')).toBe(2);
|
|
289
313
|
});
|
|
290
314
|
it('clears all values when deleting a key', async ()=>{
|
|
291
315
|
await multiMap.set('foo', 'bar');
|
|
292
316
|
await multiMap.set('foo', 'baz');
|
|
293
|
-
expect(await getValueCount('foo')).
|
|
317
|
+
expect(await getValueCount('foo')).toBe(2);
|
|
294
318
|
await multiMap.delete('foo');
|
|
295
|
-
expect(await getValueCount('foo')).
|
|
296
|
-
expect(await getValues('foo')).
|
|
319
|
+
expect(await getValueCount('foo')).toBe(0);
|
|
320
|
+
expect(await getValues('foo')).toEqual([]);
|
|
297
321
|
});
|
|
298
322
|
it('count equals enumerated values length', async ()=>{
|
|
299
323
|
await multiMap.set('foo', '1');
|
|
300
324
|
await multiMap.set('foo', '2');
|
|
301
325
|
const vals = await getValues('foo');
|
|
302
|
-
expect(await getValueCount('foo')).
|
|
326
|
+
expect(await getValueCount('foo')).toBe(vals.length);
|
|
303
327
|
});
|
|
304
328
|
it('sum of per-key counts equals total size', async ()=>{
|
|
305
329
|
await multiMap.set('foo', '1');
|
|
@@ -311,29 +335,29 @@ export function describeAztecMultiMap(testName, getStore, forceAsync = false) {
|
|
|
311
335
|
const uniqueKeys = Array.from(new Set(allKeys));
|
|
312
336
|
const counts = await Promise.all(uniqueKeys.map((k)=>getValueCount(k)));
|
|
313
337
|
const sum = counts.reduce((s, n)=>s + n, 0);
|
|
314
|
-
expect(sum).
|
|
338
|
+
expect(sum).toBe(await size());
|
|
315
339
|
});
|
|
316
340
|
it('supports sparse slots: delete middle, reinsert new, count remains correct', async ()=>{
|
|
317
341
|
await multiMap.set('foo', '1');
|
|
318
342
|
await multiMap.set('foo', '2');
|
|
319
343
|
await multiMap.set('foo', '3');
|
|
320
|
-
expect(await getValueCount('foo')).
|
|
344
|
+
expect(await getValueCount('foo')).toBe(3);
|
|
321
345
|
await multiMap.deleteValue('foo', '2');
|
|
322
|
-
expect(await getValueCount('foo')).
|
|
346
|
+
expect(await getValueCount('foo')).toBe(2);
|
|
323
347
|
await multiMap.set('foo', '4');
|
|
324
|
-
expect(await getValueCount('foo')).
|
|
325
|
-
expect(await getValues('foo')).
|
|
348
|
+
expect(await getValueCount('foo')).toBe(3);
|
|
349
|
+
expect((await getValues('foo')).sort()).toEqual([
|
|
326
350
|
'1',
|
|
327
351
|
'3',
|
|
328
352
|
'4'
|
|
329
|
-
]);
|
|
353
|
+
].sort());
|
|
330
354
|
});
|
|
331
355
|
it('multiple keys are independent', async ()=>{
|
|
332
356
|
await multiMap.set('foo', '1');
|
|
333
357
|
await multiMap.set('foo', '2');
|
|
334
358
|
await multiMap.set('bar', '3');
|
|
335
|
-
expect(await getValueCount('foo')).
|
|
336
|
-
expect(await getValueCount('bar')).
|
|
359
|
+
expect(await getValueCount('foo')).toBe(2);
|
|
360
|
+
expect(await getValueCount('bar')).toBe(1);
|
|
337
361
|
});
|
|
338
362
|
});
|
|
339
363
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { AztecAsyncKVStore, AztecKVStore } from './store.js';
|
|
2
2
|
export declare function describeAztecSet(testName: string, getStore: () => AztecKVStore | Promise<AztecAsyncKVStore>, forceAsync?: boolean): void;
|
|
3
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2V0X3Rlc3Rfc3VpdGUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9pbnRlcmZhY2VzL3NldF90ZXN0X3N1aXRlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUlBLE9BQU8sS0FBSyxFQUFFLGlCQUFpQixFQUFFLFlBQVksRUFBRSxNQUFNLFlBQVksQ0FBQztBQUdsRSx3QkFBZ0IsZ0JBQWdCLENBQzlCLFFBQVEsRUFBRSxNQUFNLEVBQ2hCLFFBQVEsRUFBRSxNQUFNLFlBQVksR0FBRyxPQUFPLENBQUMsaUJBQWlCLENBQUMsRUFDekQsVUFBVSxHQUFFLE9BQWUsUUFvRTVCIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"set_test_suite.d.ts","sourceRoot":"","sources":["../../src/interfaces/set_test_suite.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"set_test_suite.d.ts","sourceRoot":"","sources":["../../src/interfaces/set_test_suite.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAGlE,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,YAAY,GAAG,OAAO,CAAC,iBAAiB,CAAC,EACzD,UAAU,GAAE,OAAe,QAoE5B"}
|