@aztec/kv-store 0.0.1-commit.86469d5 → 0.0.1-commit.8655d4a
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/index.d.ts +2 -2
- package/dest/indexeddb/index.d.ts.map +1 -1
- package/dest/indexeddb/index.js +1 -1
- package/dest/indexeddb/map.d.ts +7 -1
- package/dest/indexeddb/map.d.ts.map +1 -1
- package/dest/indexeddb/map.js +12 -2
- package/dest/indexeddb/multi_map.js +1 -1
- package/dest/indexeddb/store.d.ts +1 -1
- 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 +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 +29 -4
- package/dest/lmdb-v2/factory.d.ts.map +1 -1
- package/dest/lmdb-v2/factory.js +61 -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 +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/package.json +28 -26
- package/src/bench/shared_map_bench.ts +111 -0
- package/src/indexeddb/index.ts +2 -2
- package/src/indexeddb/map.ts +14 -2
- package/src/indexeddb/multi_map.ts +1 -1
- package/src/indexeddb/store.ts +6 -4
- 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 +80 -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 +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/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
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
2
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
3
|
+
|
|
4
|
+
import type { Key } from '../interfaces/common.js';
|
|
5
|
+
import type { AztecAsyncMap } from '../interfaces/map.js';
|
|
6
|
+
import type { AztecAsyncKVStore } from '../interfaces/store.js';
|
|
7
|
+
|
|
8
|
+
/** One benchmark measurement. */
|
|
9
|
+
export type BenchResult = {
|
|
10
|
+
/** Benchmark name (includes the backend prefix for disambiguation). */
|
|
11
|
+
name: string;
|
|
12
|
+
value: number;
|
|
13
|
+
unit: 'ms' | 'us';
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type BenchReporter = (results: BenchResult[]) => void | Promise<void>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Runs the standard Map benchmark suite against any `AztecAsyncKVStore` backend,
|
|
20
|
+
* populates `results`, and calls `reporter` in `afterAll`.
|
|
21
|
+
*
|
|
22
|
+
* Kept free of Node-only deps (`fs`, `path`) so the same runner works under
|
|
23
|
+
* vitest-browser for IndexedDB and SQLite-OPFS.
|
|
24
|
+
*/
|
|
25
|
+
export function describeAztecMapBench(
|
|
26
|
+
backendPrefix: string,
|
|
27
|
+
getStore: () => Promise<AztecAsyncKVStore>,
|
|
28
|
+
logger: Logger,
|
|
29
|
+
reporter: BenchReporter,
|
|
30
|
+
) {
|
|
31
|
+
describe(`${backendPrefix} Map benchmarks`, () => {
|
|
32
|
+
let store: AztecAsyncKVStore;
|
|
33
|
+
let map: AztecAsyncMap<Key, string>;
|
|
34
|
+
|
|
35
|
+
const results: BenchResult[] = [];
|
|
36
|
+
|
|
37
|
+
const generateKeyValuePairs = (count: number, offset = 0) => {
|
|
38
|
+
const keys = Array.from({ length: count }, (_, i) => `key-${i + offset}`);
|
|
39
|
+
const values = Array.from({ length: count }, (_, i) => `value-${i + offset}`);
|
|
40
|
+
return keys.map((key, i) => ({ key, value: values[i] }));
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const record = (name: string, value: number, unit: BenchResult['unit']) => {
|
|
44
|
+
results.push({ name: `${backendPrefix}/Map/${name}`, value, unit });
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
beforeEach(async () => {
|
|
48
|
+
store = await getStore();
|
|
49
|
+
map = store.openMap<Key, string>('test');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
afterEach(async () => {
|
|
53
|
+
await store.delete();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
afterAll(async () => {
|
|
57
|
+
const pretty = results.map(r => `${r.name}: ${r.value.toFixed(2)} ${r.unit}`).join('\n');
|
|
58
|
+
logger.info(`\n${pretty}\n`);
|
|
59
|
+
await reporter(results);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('adds individual values', async () => {
|
|
63
|
+
const pairs = generateKeyValuePairs(1000);
|
|
64
|
+
const timer = new Timer();
|
|
65
|
+
for (const pair of pairs) {
|
|
66
|
+
await map.set(pair.key, pair.value);
|
|
67
|
+
}
|
|
68
|
+
record('Individual insertion', timer.ms() / pairs.length, 'ms');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('adds batched values', async () => {
|
|
72
|
+
const batches = Array.from({ length: 100 }, (_, i) => generateKeyValuePairs(1000, i * 1000));
|
|
73
|
+
const timer = new Timer();
|
|
74
|
+
for (const batch of batches) {
|
|
75
|
+
await map.setMany(batch);
|
|
76
|
+
}
|
|
77
|
+
record(`Batch insertion of ${batches[0].length} items`, timer.ms() / batches.length, 'ms');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('reads individual values', async () => {
|
|
81
|
+
const pairs = generateKeyValuePairs(10000);
|
|
82
|
+
await map.setMany(pairs);
|
|
83
|
+
const timer = new Timer();
|
|
84
|
+
for (const pair of pairs) {
|
|
85
|
+
await map.getAsync(pair.key);
|
|
86
|
+
}
|
|
87
|
+
record('Individual read', (timer.ms() * 1000) / pairs.length, 'us');
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('reads via a cursor', async () => {
|
|
91
|
+
const pairs = generateKeyValuePairs(10000);
|
|
92
|
+
await map.setMany(pairs);
|
|
93
|
+
const timer = new Timer();
|
|
94
|
+
for await (const _ of map.entriesAsync()) {
|
|
95
|
+
// consume
|
|
96
|
+
}
|
|
97
|
+
record(`Iterator per item read of ${pairs.length} items`, (timer.ms() * 1000) / pairs.length, 'us');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('reads the size of the map', async () => {
|
|
101
|
+
const numIterations = 1000;
|
|
102
|
+
const pairs = generateKeyValuePairs(10000);
|
|
103
|
+
await map.setMany(pairs);
|
|
104
|
+
const timer = new Timer();
|
|
105
|
+
for (let i = 0; i < numIterations; i++) {
|
|
106
|
+
await map.sizeAsync();
|
|
107
|
+
}
|
|
108
|
+
record(`Read size of ${pairs.length} items`, (timer.ms() * 1000) / numIterations, 'us');
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
}
|
package/src/indexeddb/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
2
3
|
|
|
3
|
-
import type { DataStoreConfig } from '../config.js';
|
|
4
4
|
import { initStoreForRollupAndSchemaVersion } from '../utils.js';
|
|
5
5
|
import { AztecIndexedDBStore } from './store.js';
|
|
6
6
|
|
|
@@ -23,7 +23,7 @@ export async function createStore(
|
|
|
23
23
|
: `Creating ${name} ephemeral data store with map size ${config.dataStoreMapSizeKb} KB`,
|
|
24
24
|
);
|
|
25
25
|
const store = await AztecIndexedDBStore.open(createLogger('kv-store:indexeddb'), dataDirectory ?? '', false);
|
|
26
|
-
return initStoreForRollupAndSchemaVersion(store, schemaVersion, config.
|
|
26
|
+
return initStoreForRollupAndSchemaVersion(store, schemaVersion, config.rollupAddress, log);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export function openTmpStore(ephemeral: boolean = false): Promise<AztecIndexedDBStore> {
|
package/src/indexeddb/map.ts
CHANGED
|
@@ -31,7 +31,7 @@ export class IndexedDBAztecMap<K extends Key, V extends Value> implements AztecA
|
|
|
31
31
|
|
|
32
32
|
async getAsync(key: K): Promise<V | undefined> {
|
|
33
33
|
const data = await this.db.get(this.slot(key));
|
|
34
|
-
return data
|
|
34
|
+
return data ? this.restoreBuffers(data.value as V) : undefined;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
async hasAsync(key: K): Promise<boolean> {
|
|
@@ -94,7 +94,7 @@ export class IndexedDBAztecMap<K extends Key, V extends Value> implements AztecA
|
|
|
94
94
|
if (range.limit && count >= range.limit) {
|
|
95
95
|
return;
|
|
96
96
|
}
|
|
97
|
-
yield [this.#denormalizeKey(cursor.value.key), cursor.value.value] as [K, V];
|
|
97
|
+
yield [this.#denormalizeKey(cursor.value.key), this.restoreBuffers(cursor.value.value as V)] as [K, V];
|
|
98
98
|
count++;
|
|
99
99
|
}
|
|
100
100
|
}
|
|
@@ -111,6 +111,18 @@ export class IndexedDBAztecMap<K extends Key, V extends Value> implements AztecA
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
/**
|
|
115
|
+
* IndexedDB's structured clone downcasts Buffer (a Node.js subclass of Uint8Array) to plain Uint8Array.
|
|
116
|
+
* This breaks .toString() behavior: Buffer.toString() returns UTF-8, Uint8Array.toString() returns
|
|
117
|
+
* comma-separated decimal bytes. We restore Buffer identity on read so callers get consistent behavior.
|
|
118
|
+
*/
|
|
119
|
+
protected restoreBuffers(val: V): V {
|
|
120
|
+
if (val instanceof Uint8Array && !Buffer.isBuffer(val)) {
|
|
121
|
+
return Buffer.from(val) as V;
|
|
122
|
+
}
|
|
123
|
+
return val;
|
|
124
|
+
}
|
|
125
|
+
|
|
114
126
|
#denormalizeKey(key: (string | number | Uint8Array)[]): K {
|
|
115
127
|
return (key.length > 1 ? key : key[0]) as K;
|
|
116
128
|
}
|
package/src/indexeddb/store.ts
CHANGED
|
@@ -192,18 +192,20 @@ export class AztecIndexedDBStore implements AztecAsyncKVStore {
|
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
/** Deletes this store and removes the database */
|
|
195
|
-
delete() {
|
|
195
|
+
async delete() {
|
|
196
196
|
this.#containers.clear();
|
|
197
|
+
await this.#txQueue.end();
|
|
197
198
|
this.#rootDB.close();
|
|
198
|
-
|
|
199
|
+
await deleteDB(this.#name);
|
|
199
200
|
}
|
|
200
201
|
|
|
201
202
|
estimateSize(): Promise<StoreSize> {
|
|
202
203
|
return Promise.resolve({ mappingSize: 0, physicalFileSize: 0, actualSize: 0, numItems: 0 });
|
|
203
204
|
}
|
|
204
205
|
|
|
205
|
-
close(): Promise<void> {
|
|
206
|
-
|
|
206
|
+
async close(): Promise<void> {
|
|
207
|
+
await this.#txQueue.end();
|
|
208
|
+
this.#rootDB.close();
|
|
207
209
|
}
|
|
208
210
|
|
|
209
211
|
backupTo(_dstPath: string, _compact?: boolean): Promise<void> {
|
|
@@ -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
|
});
|