@aztec/kv-store 0.82.3 → 0.83.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/dest/indexeddb/array.d.ts +2 -1
- package/dest/indexeddb/array.d.ts.map +1 -1
- package/dest/indexeddb/array.js +3 -0
- package/dest/indexeddb/map.d.ts +2 -2
- package/dest/indexeddb/map.d.ts.map +1 -1
- package/dest/indexeddb/map.js +2 -0
- package/dest/indexeddb/multi_map.d.ts +2 -2
- package/dest/indexeddb/multi_map.d.ts.map +1 -1
- package/dest/indexeddb/multi_map.js +20 -10
- package/dest/indexeddb/singleton.d.ts +2 -1
- package/dest/indexeddb/singleton.d.ts.map +1 -1
- package/dest/indexeddb/singleton.js +3 -1
- package/dest/indexeddb/store.d.ts +8 -6
- package/dest/indexeddb/store.d.ts.map +1 -1
- package/dest/indexeddb/store.js +7 -0
- package/dest/interfaces/array.d.ts +4 -3
- package/dest/interfaces/array.d.ts.map +1 -1
- package/dest/interfaces/array.js +1 -3
- package/dest/interfaces/common.d.ts +1 -0
- package/dest/interfaces/common.d.ts.map +1 -1
- package/dest/interfaces/map.d.ts +4 -4
- package/dest/interfaces/map.d.ts.map +1 -1
- package/dest/interfaces/multi_map.d.ts +3 -3
- package/dest/interfaces/multi_map.d.ts.map +1 -1
- package/dest/interfaces/multi_map_test_suite.d.ts.map +1 -1
- package/dest/interfaces/multi_map_test_suite.js +7 -0
- package/dest/interfaces/store.d.ts +9 -9
- package/dest/interfaces/store.d.ts.map +1 -1
- package/dest/lmdb/array.d.ts +2 -1
- package/dest/lmdb/array.d.ts.map +1 -1
- package/dest/lmdb/map.d.ts +2 -2
- package/dest/lmdb/map.d.ts.map +1 -1
- package/dest/lmdb/multi_map.d.ts +2 -2
- package/dest/lmdb/multi_map.d.ts.map +1 -1
- package/dest/lmdb/store.d.ts +4 -4
- package/dest/lmdb/store.d.ts.map +1 -1
- package/dest/lmdb-v2/array.d.ts +2 -1
- package/dest/lmdb-v2/array.d.ts.map +1 -1
- package/dest/lmdb-v2/map.d.ts +2 -2
- package/dest/lmdb-v2/map.d.ts.map +1 -1
- package/dest/lmdb-v2/multi_map.d.ts +2 -2
- package/dest/lmdb-v2/multi_map.d.ts.map +1 -1
- package/dest/lmdb-v2/store.d.ts +5 -5
- package/dest/lmdb-v2/store.d.ts.map +1 -1
- package/dest/stores/l2_tips_memory_store.d.ts +1 -0
- package/dest/stores/l2_tips_memory_store.d.ts.map +1 -1
- package/dest/stores/l2_tips_memory_store.js +10 -4
- package/dest/stores/l2_tips_store.d.ts +1 -0
- package/dest/stores/l2_tips_store.d.ts.map +1 -1
- package/dest/stores/l2_tips_store.js +10 -4
- package/package.json +6 -5
- package/src/indexeddb/array.ts +5 -1
- package/src/indexeddb/map.ts +4 -2
- package/src/indexeddb/multi_map.ts +26 -14
- package/src/indexeddb/singleton.ts +4 -1
- package/src/indexeddb/store.ts +15 -7
- package/src/interfaces/array.ts +5 -3
- package/src/interfaces/common.ts +2 -0
- package/src/interfaces/map.ts +4 -4
- package/src/interfaces/multi_map.ts +3 -3
- package/src/interfaces/multi_map_test_suite.ts +7 -0
- package/src/interfaces/store.ts +9 -9
- package/src/lmdb/array.ts +2 -1
- package/src/lmdb/map.ts +2 -2
- package/src/lmdb/multi_map.ts +2 -2
- package/src/lmdb/store.ts +4 -4
- package/src/lmdb-v2/array.ts +2 -1
- package/src/lmdb-v2/map.ts +2 -2
- package/src/lmdb-v2/multi_map.ts +2 -2
- package/src/lmdb-v2/store.ts +5 -5
- package/src/stores/l2_tips_memory_store.ts +11 -4
- package/src/stores/l2_tips_store.ts +11 -4
package/dest/lmdb/store.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type RootDatabase } from 'lmdb';
|
|
2
2
|
import type { AztecArray, AztecAsyncArray } from '../interfaces/array.js';
|
|
3
|
-
import type { Key, StoreSize } from '../interfaces/common.js';
|
|
3
|
+
import type { Key, StoreSize, Value } from '../interfaces/common.js';
|
|
4
4
|
import type { AztecAsyncCounter, AztecCounter } from '../interfaces/counter.js';
|
|
5
5
|
import type { AztecAsyncMap, AztecMap } from '../interfaces/map.js';
|
|
6
6
|
import type { AztecAsyncMultiMap, AztecMultiMap } from '../interfaces/multi_map.js';
|
|
@@ -36,7 +36,7 @@ export declare class AztecLmdbStore implements AztecKVStore, AztecAsyncKVStore {
|
|
|
36
36
|
* @param name - Name of the map
|
|
37
37
|
* @returns A new AztecMap
|
|
38
38
|
*/
|
|
39
|
-
openMap<K extends Key, V>(name: string): AztecMap<K, V> & AztecAsyncMap<K, V>;
|
|
39
|
+
openMap<K extends Key, V extends Value>(name: string): AztecMap<K, V> & AztecAsyncMap<K, V>;
|
|
40
40
|
/**
|
|
41
41
|
* Creates a new AztecSet in the store.
|
|
42
42
|
* @param name - Name of the set
|
|
@@ -48,14 +48,14 @@ export declare class AztecLmdbStore implements AztecKVStore, AztecAsyncKVStore {
|
|
|
48
48
|
* @param name - Name of the map
|
|
49
49
|
* @returns A new AztecMultiMap
|
|
50
50
|
*/
|
|
51
|
-
openMultiMap<K extends Key, V>(name: string): AztecMultiMap<K, V> & AztecAsyncMultiMap<K, V>;
|
|
51
|
+
openMultiMap<K extends Key, V extends Value>(name: string): AztecMultiMap<K, V> & AztecAsyncMultiMap<K, V>;
|
|
52
52
|
openCounter<K extends Key>(name: string): AztecCounter<K> & AztecAsyncCounter<K>;
|
|
53
53
|
/**
|
|
54
54
|
* Creates a new AztecArray in the store.
|
|
55
55
|
* @param name - Name of the array
|
|
56
56
|
* @returns A new AztecArray
|
|
57
57
|
*/
|
|
58
|
-
openArray<T>(name: string): AztecArray<T> & AztecAsyncArray<T>;
|
|
58
|
+
openArray<T extends Value>(name: string): AztecArray<T> & AztecAsyncArray<T>;
|
|
59
59
|
/**
|
|
60
60
|
* Creates a new AztecSingleton in the store.
|
|
61
61
|
* @param name - Name of the singleton
|
package/dest/lmdb/store.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/lmdb/store.ts"],"names":[],"mappings":"AAIA,OAAO,EAAiB,KAAK,YAAY,EAAQ,MAAM,MAAM,CAAC;AAI9D,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/lmdb/store.ts"],"names":[],"mappings":"AAIA,OAAO,EAAiB,KAAK,YAAY,EAAQ,MAAM,MAAM,CAAC;AAI9D,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAChF,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AACpF,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACtF,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAQ9E;;GAEG;AACH,qBAAa,cAAe,YAAW,YAAY,EAAE,iBAAiB;;aAQlB,WAAW,EAAE,OAAO;IAAE,OAAO,CAAC,IAAI;IAPpF,WAAW,OAAiB;gBAOhB,MAAM,EAAE,YAAY,EAAkB,WAAW,EAAE,OAAO,EAAU,IAAI,EAAE,MAAM;IAgB5F;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,IA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,CAAC;IAIjE;;OAEG;IACG,KAAK;IAMX;;OAEG;IACG,IAAI;IAMV;;OAEG;IACG,KAAK;IAMX,kEAAkE;IAC5D,MAAM;IASZ,YAAY,IAAI,OAAO,CAAC,SAAS,CAAC;IAiBlC,OAAO,CAAC,iBAAiB;IA4BzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAG9D"}
|
package/dest/lmdb-v2/array.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AztecAsyncArray } from '../interfaces/array.js';
|
|
2
|
+
import type { Value } from '../interfaces/common.js';
|
|
2
3
|
import { AztecLMDBStoreV2 } from './store.js';
|
|
3
|
-
export declare class LMDBArray<T> implements AztecAsyncArray<T> {
|
|
4
|
+
export declare class LMDBArray<T extends Value> implements AztecAsyncArray<T> {
|
|
4
5
|
private store;
|
|
5
6
|
private length;
|
|
6
7
|
private encoder;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../src/lmdb-v2/array.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../src/lmdb-v2/array.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAIrD,OAAO,EAAE,gBAAgB,EAA+B,MAAM,YAAY,CAAC;AAG3E,qBAAa,SAAS,CAAC,CAAC,SAAS,KAAK,CAAE,YAAW,eAAe,CAAC,CAAC,CAAC;IAKvD,OAAO,CAAC,KAAK;IAJzB,OAAO,CAAC,MAAM,CAA8B;IAC5C,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,MAAM,CAAS;gBAEH,KAAK,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM;IAKzD,GAAG,IAAI,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAgB7B,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAWnC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAc9C,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAexC,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAI7B,YAAY,IAAI,qBAAqB,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IA2BlD,WAAW,IAAI,qBAAqB,CAAC,CAAC,CAAC;IAM9C,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,qBAAqB,CAAC,CAAC,CAAC;CAGnD"}
|
package/dest/lmdb-v2/map.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Key, Range } from '../interfaces/common.js';
|
|
1
|
+
import type { Key, Range, Value } from '../interfaces/common.js';
|
|
2
2
|
import type { AztecAsyncMap } from '../interfaces/map.js';
|
|
3
3
|
import { type AztecLMDBStoreV2 } from './store.js';
|
|
4
|
-
export declare class LMDBMap<K extends Key, V> implements AztecAsyncMap<K, V> {
|
|
4
|
+
export declare class LMDBMap<K extends Key, V extends Value> implements AztecAsyncMap<K, V> {
|
|
5
5
|
private store;
|
|
6
6
|
private prefix;
|
|
7
7
|
private encoder;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/lmdb-v2/map.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/lmdb-v2/map.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,qBAAqB,CAAC,CAAC,CAAC;CAK7D"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Key, Range } from '../interfaces/common.js';
|
|
1
|
+
import type { Key, Range, Value } from '../interfaces/common.js';
|
|
2
2
|
import type { AztecAsyncMultiMap } from '../interfaces/multi_map.js';
|
|
3
3
|
import { type AztecLMDBStoreV2 } from './store.js';
|
|
4
|
-
export declare class LMDBMultiMap<K extends Key, V> implements AztecAsyncMultiMap<K, V> {
|
|
4
|
+
export declare class LMDBMultiMap<K extends Key, V extends Value> implements AztecAsyncMultiMap<K, V> {
|
|
5
5
|
private store;
|
|
6
6
|
private prefix;
|
|
7
7
|
private encoder;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multi_map.d.ts","sourceRoot":"","sources":["../../src/lmdb-v2/multi_map.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"multi_map.d.ts","sourceRoot":"","sources":["../../src/lmdb-v2/multi_map.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAErE,OAAO,EAAE,KAAK,gBAAgB,EAA+B,MAAM,YAAY,CAAC;AAGhF,qBAAa,YAAY,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC,SAAS,KAAK,CAAE,YAAW,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC;IAG/E,OAAO,CAAC,KAAK;IAFzB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAiB;gBACZ,KAAK,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM;IAIzD;;;;OAIG;IACH,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlC;;;;OAIG;IACH,cAAc,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAWhD;;;OAGG;IACH,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7B,QAAQ,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAOxC,QAAQ,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAIlC;;;OAGG;IACI,YAAY,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,qBAAqB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAgCpE;;;OAGG;IACI,WAAW,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,qBAAqB,CAAC,CAAC,CAAC;IAM9D;;;OAGG;IACI,SAAS,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,qBAAqB,CAAC,CAAC,CAAC;IAM5D,WAAW,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/C,cAAc,CAAC,GAAG,EAAE,CAAC,GAAG,qBAAqB,CAAC,CAAC,CAAC;CAMxD"}
|
package/dest/lmdb-v2/store.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Logger } from '@aztec/foundation/log';
|
|
2
2
|
import type { AztecAsyncArray } from '../interfaces/array.js';
|
|
3
|
-
import type { Key, StoreSize } from '../interfaces/common.js';
|
|
3
|
+
import type { Key, StoreSize, Value } from '../interfaces/common.js';
|
|
4
4
|
import type { AztecAsyncCounter } from '../interfaces/counter.js';
|
|
5
5
|
import type { AztecAsyncMap } from '../interfaces/map.js';
|
|
6
6
|
import type { AztecAsyncMultiMap } from '../interfaces/multi_map.js';
|
|
@@ -26,10 +26,10 @@ export declare class AztecLMDBStoreV2 implements AztecAsyncKVStore, LMDBMessageC
|
|
|
26
26
|
backupTo(dstPath: string, compact?: boolean): Promise<void>;
|
|
27
27
|
getReadTx(): ReadTransaction;
|
|
28
28
|
getCurrentWriteTx(): WriteTransaction | undefined;
|
|
29
|
-
openMap<K extends Key, V>(name: string): AztecAsyncMap<K, V>;
|
|
30
|
-
openMultiMap<K extends Key, V>(name: string): AztecAsyncMultiMap<K, V>;
|
|
31
|
-
openSingleton<T>(name: string): AztecAsyncSingleton<T>;
|
|
32
|
-
openArray<T>(name: string): AztecAsyncArray<T>;
|
|
29
|
+
openMap<K extends Key, V extends Value>(name: string): AztecAsyncMap<K, V>;
|
|
30
|
+
openMultiMap<K extends Key, V extends Value>(name: string): AztecAsyncMultiMap<K, V>;
|
|
31
|
+
openSingleton<T extends Value>(name: string): AztecAsyncSingleton<T>;
|
|
32
|
+
openArray<T extends Value>(name: string): AztecAsyncArray<T>;
|
|
33
33
|
openSet<K extends Key>(_name: string): AztecAsyncSet<K>;
|
|
34
34
|
openCounter<K extends Key>(_name: string): AztecAsyncCounter<K>;
|
|
35
35
|
transactionAsync<T extends Exclude<any, Promise<any>>>(callback: (tx: WriteTransaction) => Promise<T>): Promise<T>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/lmdb-v2/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAOlE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/lmdb-v2/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM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SAAS,CAAC;CAQhD;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,gBAAgB,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,gBAAgB,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAO9G;AAED,wBAAsB,YAAY,CAAC,CAAC,EAClC,KAAK,EAAE,gBAAgB,EACvB,EAAE,EAAE,CAAC,EAAE,EAAE,eAAe,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAC1C,OAAO,CAAC,CAAC,CAAC,CAYZ"}
|
|
@@ -7,5 +7,6 @@ export declare class L2TipsMemoryStore implements L2BlockStreamEventHandler, L2B
|
|
|
7
7
|
getL2Tips(): Promise<L2Tips>;
|
|
8
8
|
private getL2Tip;
|
|
9
9
|
handleBlockStreamEvent(event: L2BlockStreamEvent): Promise<void>;
|
|
10
|
+
private saveTag;
|
|
10
11
|
}
|
|
11
12
|
//# sourceMappingURL=l2_tips_memory_store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"l2_tips_memory_store.d.ts","sourceRoot":"","sources":["../../src/stores/l2_tips_memory_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kBAAkB,EAClB,yBAAyB,EACzB,8BAA8B,EAE9B,MAAM,EACP,MAAM,qBAAqB,CAAC;AAE7B,oEAAoE;AACpE,qBAAa,iBAAkB,YAAW,yBAAyB,EAAE,8BAA8B;IACjG,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAsC;IAClE,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAkC;IAE9D,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAI3D,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IAQnC,OAAO,CAAC,QAAQ;IAaH,sBAAsB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"l2_tips_memory_store.d.ts","sourceRoot":"","sources":["../../src/stores/l2_tips_memory_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kBAAkB,EAClB,yBAAyB,EACzB,8BAA8B,EAE9B,MAAM,EACP,MAAM,qBAAqB,CAAC;AAE7B,oEAAoE;AACpE,qBAAa,iBAAkB,YAAW,yBAAyB,EAAE,8BAA8B;IACjG,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAsC;IAClE,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAkC;IAE9D,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAI3D,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IAQnC,OAAO,CAAC,QAAQ;IAaH,sBAAsB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IA2B7E,OAAO,CAAC,OAAO;CAMhB"}
|
|
@@ -40,19 +40,25 @@
|
|
|
40
40
|
break;
|
|
41
41
|
}
|
|
42
42
|
case 'chain-pruned':
|
|
43
|
-
this.
|
|
43
|
+
this.saveTag('latest', event.block);
|
|
44
44
|
break;
|
|
45
45
|
case 'chain-proven':
|
|
46
|
-
this.
|
|
46
|
+
this.saveTag('proven', event.block);
|
|
47
47
|
break;
|
|
48
48
|
case 'chain-finalized':
|
|
49
|
-
this.
|
|
49
|
+
this.saveTag('finalized', event.block);
|
|
50
50
|
for (const key of this.l2BlockHashesStore.keys()){
|
|
51
|
-
if (key < event.
|
|
51
|
+
if (key < event.block.number) {
|
|
52
52
|
this.l2BlockHashesStore.delete(key);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
break;
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
+
saveTag(name, block) {
|
|
59
|
+
this.l2TipsStore.set(name, block.number);
|
|
60
|
+
if (block.hash) {
|
|
61
|
+
this.l2BlockHashesStore.set(block.number, block.hash);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
58
64
|
}
|
|
@@ -9,5 +9,6 @@ export declare class L2TipsKVStore implements L2BlockStreamEventHandler, L2Block
|
|
|
9
9
|
getL2Tips(): Promise<L2Tips>;
|
|
10
10
|
private getL2Tip;
|
|
11
11
|
handleBlockStreamEvent(event: L2BlockStreamEvent): Promise<void>;
|
|
12
|
+
private saveTag;
|
|
12
13
|
}
|
|
13
14
|
//# sourceMappingURL=l2_tips_store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"l2_tips_store.d.ts","sourceRoot":"","sources":["../../src/stores/l2_tips_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kBAAkB,EAClB,yBAAyB,EACzB,8BAA8B,EAE9B,MAAM,EACP,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE,oEAAoE;AACpE,qBAAa,aAAc,YAAW,yBAAyB,EAAE,8BAA8B;IAC7F,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoC;IAChE,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAgC;gBAEvD,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM;IAKhD,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAIrD,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;YAQ3B,QAAQ;IAaT,sBAAsB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"l2_tips_store.d.ts","sourceRoot":"","sources":["../../src/stores/l2_tips_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kBAAkB,EAClB,yBAAyB,EACzB,8BAA8B,EAE9B,MAAM,EACP,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE,oEAAoE;AACpE,qBAAa,aAAc,YAAW,yBAAyB,EAAE,8BAA8B;IAC7F,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoC;IAChE,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAgC;gBAEvD,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM;IAKhD,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAIrD,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;YAQ3B,QAAQ;IAaT,sBAAsB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;YAyB/D,OAAO;CAMtB"}
|
|
@@ -50,19 +50,25 @@
|
|
|
50
50
|
break;
|
|
51
51
|
}
|
|
52
52
|
case 'chain-pruned':
|
|
53
|
-
await this.
|
|
53
|
+
await this.saveTag('latest', event.block);
|
|
54
54
|
break;
|
|
55
55
|
case 'chain-proven':
|
|
56
|
-
await this.
|
|
56
|
+
await this.saveTag('proven', event.block);
|
|
57
57
|
break;
|
|
58
58
|
case 'chain-finalized':
|
|
59
|
-
await this.
|
|
59
|
+
await this.saveTag('finalized', event.block);
|
|
60
60
|
for await (const key of this.l2BlockHashesStore.keysAsync({
|
|
61
|
-
end: event.
|
|
61
|
+
end: event.block.number
|
|
62
62
|
})){
|
|
63
63
|
await this.l2BlockHashesStore.delete(key);
|
|
64
64
|
}
|
|
65
65
|
break;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
+
async saveTag(name, block) {
|
|
69
|
+
await this.l2TipsStore.set(name, block.number);
|
|
70
|
+
if (block.hash) {
|
|
71
|
+
await this.l2BlockHashesStore.set(block.number, block.hash);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
68
74
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/kv-store",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.83.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/interfaces/index.js",
|
|
@@ -25,13 +25,14 @@
|
|
|
25
25
|
"./package.local.json"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aztec/ethereum": "0.
|
|
29
|
-
"@aztec/foundation": "0.
|
|
30
|
-
"@aztec/native": "0.
|
|
31
|
-
"@aztec/stdlib": "0.
|
|
28
|
+
"@aztec/ethereum": "0.83.0",
|
|
29
|
+
"@aztec/foundation": "0.83.0",
|
|
30
|
+
"@aztec/native": "0.83.0",
|
|
31
|
+
"@aztec/stdlib": "0.83.0",
|
|
32
32
|
"idb": "^8.0.0",
|
|
33
33
|
"lmdb": "^3.2.0",
|
|
34
34
|
"msgpackr": "^1.11.2",
|
|
35
|
+
"ohash": "^2.0.11",
|
|
35
36
|
"ordered-binary": "^1.5.3"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
package/src/indexeddb/array.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { IDBPDatabase, IDBPObjectStore } from 'idb';
|
|
2
|
+
import { hash } from 'ohash';
|
|
2
3
|
|
|
3
4
|
import type { AztecAsyncArray } from '../interfaces/array.js';
|
|
5
|
+
import type { Value } from '../interfaces/common.js';
|
|
4
6
|
import type { AztecIDBSchema } from './store.js';
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* A persistent array backed by IndexedDB.
|
|
8
10
|
*/
|
|
9
|
-
export class IndexedDBAztecArray<T> implements AztecAsyncArray<T> {
|
|
11
|
+
export class IndexedDBAztecArray<T extends Value> implements AztecAsyncArray<T> {
|
|
10
12
|
#_db?: IDBPObjectStore<AztecIDBSchema, ['data'], 'data', 'readwrite'>;
|
|
11
13
|
#rootDB: IDBPDatabase<AztecIDBSchema>;
|
|
12
14
|
#container: string;
|
|
@@ -39,6 +41,7 @@ export class IndexedDBAztecArray<T> implements AztecAsyncArray<T> {
|
|
|
39
41
|
for (const val of vals) {
|
|
40
42
|
await this.db.put({
|
|
41
43
|
value: val,
|
|
44
|
+
hash: hash(val),
|
|
42
45
|
container: this.#container,
|
|
43
46
|
key: this.#name,
|
|
44
47
|
keyCount: length + 1,
|
|
@@ -86,6 +89,7 @@ export class IndexedDBAztecArray<T> implements AztecAsyncArray<T> {
|
|
|
86
89
|
|
|
87
90
|
await this.db.put({
|
|
88
91
|
value: val,
|
|
92
|
+
hash: hash(val),
|
|
89
93
|
container: this.#container,
|
|
90
94
|
key: this.#name,
|
|
91
95
|
keyCount: index + 1,
|
package/src/indexeddb/map.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { IDBPDatabase, IDBPObjectStore } from 'idb';
|
|
2
|
+
import { hash } from 'ohash';
|
|
2
3
|
|
|
3
|
-
import type { Key, Range } from '../interfaces/common.js';
|
|
4
|
+
import type { Key, Range, Value } from '../interfaces/common.js';
|
|
4
5
|
import type { AztecAsyncMap } from '../interfaces/map.js';
|
|
5
6
|
import type { AztecIDBSchema } from './store.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* A map backed by IndexedDB.
|
|
9
10
|
*/
|
|
10
|
-
export class IndexedDBAztecMap<K extends Key, V> implements AztecAsyncMap<K, V> {
|
|
11
|
+
export class IndexedDBAztecMap<K extends Key, V extends Value> implements AztecAsyncMap<K, V> {
|
|
11
12
|
protected name: string;
|
|
12
13
|
protected container: string;
|
|
13
14
|
|
|
@@ -41,6 +42,7 @@ export class IndexedDBAztecMap<K extends Key, V> implements AztecAsyncMap<K, V>
|
|
|
41
42
|
async set(key: K, val: V): Promise<void> {
|
|
42
43
|
await this.db.put({
|
|
43
44
|
value: val,
|
|
45
|
+
hash: hash(val),
|
|
44
46
|
container: this.container,
|
|
45
47
|
key: this.normalizeKey(key),
|
|
46
48
|
keyCount: 1,
|
|
@@ -1,20 +1,34 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { hash } from 'ohash';
|
|
2
|
+
|
|
3
|
+
import type { Key, Value } from '../interfaces/common.js';
|
|
2
4
|
import type { AztecAsyncMultiMap } from '../interfaces/multi_map.js';
|
|
3
5
|
import { IndexedDBAztecMap } from './map.js';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* A multi map backed by IndexedDB.
|
|
7
9
|
*/
|
|
8
|
-
export class IndexedDBAztecMultiMap<K extends Key, V>
|
|
10
|
+
export class IndexedDBAztecMultiMap<K extends Key, V extends Value>
|
|
9
11
|
extends IndexedDBAztecMap<K, V>
|
|
10
12
|
implements AztecAsyncMultiMap<K, V>
|
|
11
13
|
{
|
|
12
14
|
override async set(key: K, val: V): Promise<void> {
|
|
15
|
+
const exists = !!(await this.db
|
|
16
|
+
.index('hash')
|
|
17
|
+
.get(
|
|
18
|
+
IDBKeyRange.bound(
|
|
19
|
+
[this.container, this.normalizeKey(key), hash(val)],
|
|
20
|
+
[this.container, this.normalizeKey(key), hash(val)],
|
|
21
|
+
),
|
|
22
|
+
));
|
|
23
|
+
if (exists) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
13
26
|
const count = await this.db
|
|
14
27
|
.index('key')
|
|
15
28
|
.count(IDBKeyRange.bound([this.container, this.normalizeKey(key)], [this.container, this.normalizeKey(key)]));
|
|
16
29
|
await this.db.put({
|
|
17
30
|
value: val,
|
|
31
|
+
hash: hash(val),
|
|
18
32
|
container: this.container,
|
|
19
33
|
key: this.normalizeKey(key),
|
|
20
34
|
keyCount: count + 1,
|
|
@@ -36,18 +50,16 @@ export class IndexedDBAztecMultiMap<K extends Key, V>
|
|
|
36
50
|
}
|
|
37
51
|
|
|
38
52
|
async deleteValue(key: K, val: V): Promise<void> {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
53
|
+
const fullKey = await this.db
|
|
54
|
+
.index('hash')
|
|
55
|
+
.getKey(
|
|
56
|
+
IDBKeyRange.bound(
|
|
57
|
+
[this.container, this.normalizeKey(key), hash(val)],
|
|
58
|
+
[this.container, this.normalizeKey(key), hash(val)],
|
|
59
|
+
),
|
|
60
|
+
);
|
|
61
|
+
if (fullKey) {
|
|
62
|
+
await this.db.delete(fullKey);
|
|
51
63
|
}
|
|
52
64
|
}
|
|
53
65
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { IDBPDatabase, IDBPObjectStore } from 'idb';
|
|
2
|
+
import { hash } from 'ohash';
|
|
2
3
|
|
|
4
|
+
import type { Value } from '../interfaces/common.js';
|
|
3
5
|
import type { AztecAsyncSingleton } from '../interfaces/singleton.js';
|
|
4
6
|
import type { AztecIDBSchema } from './store.js';
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* Stores a single value in IndexedDB.
|
|
8
10
|
*/
|
|
9
|
-
export class IndexedDBAztecSingleton<T> implements AztecAsyncSingleton<T> {
|
|
11
|
+
export class IndexedDBAztecSingleton<T extends Value> implements AztecAsyncSingleton<T> {
|
|
10
12
|
#_db?: IDBPObjectStore<AztecIDBSchema, ['data'], 'data', 'readwrite'>;
|
|
11
13
|
#rootDB: IDBPDatabase<AztecIDBSchema>;
|
|
12
14
|
#container: string;
|
|
@@ -38,6 +40,7 @@ export class IndexedDBAztecSingleton<T> implements AztecAsyncSingleton<T> {
|
|
|
38
40
|
key: this.#slot,
|
|
39
41
|
keyCount: 1,
|
|
40
42
|
value: val,
|
|
43
|
+
hash: hash(val),
|
|
41
44
|
});
|
|
42
45
|
return result !== undefined;
|
|
43
46
|
}
|
package/src/indexeddb/store.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Logger } from '@aztec/foundation/log';
|
|
|
3
3
|
import { type DBSchema, type IDBPDatabase, deleteDB, openDB } from 'idb';
|
|
4
4
|
|
|
5
5
|
import type { AztecAsyncArray } from '../interfaces/array.js';
|
|
6
|
-
import type { Key, StoreSize } from '../interfaces/common.js';
|
|
6
|
+
import type { Key, StoreSize, Value } from '../interfaces/common.js';
|
|
7
7
|
import type { AztecAsyncCounter } from '../interfaces/counter.js';
|
|
8
8
|
import type { AztecAsyncMap } from '../interfaces/map.js';
|
|
9
9
|
import type { AztecAsyncMultiMap } from '../interfaces/multi_map.js';
|
|
@@ -16,13 +16,20 @@ import { IndexedDBAztecMultiMap } from './multi_map.js';
|
|
|
16
16
|
import { IndexedDBAztecSet } from './set.js';
|
|
17
17
|
import { IndexedDBAztecSingleton } from './singleton.js';
|
|
18
18
|
|
|
19
|
-
export type StoredData<V> = {
|
|
19
|
+
export type StoredData<V extends Value> = {
|
|
20
|
+
value: V;
|
|
21
|
+
container: string;
|
|
22
|
+
key: string;
|
|
23
|
+
keyCount: number;
|
|
24
|
+
slot: string;
|
|
25
|
+
hash: string;
|
|
26
|
+
};
|
|
20
27
|
|
|
21
28
|
export interface AztecIDBSchema extends DBSchema {
|
|
22
29
|
data: {
|
|
23
30
|
value: StoredData<any>;
|
|
24
31
|
key: string;
|
|
25
|
-
indexes: { container: string; key: string; keyCount: number };
|
|
32
|
+
indexes: { container: string; key: string; keyCount: number; hash: string };
|
|
26
33
|
};
|
|
27
34
|
}
|
|
28
35
|
|
|
@@ -67,6 +74,7 @@ export class AztecIndexedDBStore implements AztecAsyncKVStore {
|
|
|
67
74
|
|
|
68
75
|
objectStore.createIndex('key', ['container', 'key'], { unique: false });
|
|
69
76
|
objectStore.createIndex('keyCount', ['container', 'key', 'keyCount'], { unique: false });
|
|
77
|
+
objectStore.createIndex('hash', ['container', 'key', 'hash'], { unique: true });
|
|
70
78
|
},
|
|
71
79
|
});
|
|
72
80
|
|
|
@@ -79,7 +87,7 @@ export class AztecIndexedDBStore implements AztecAsyncKVStore {
|
|
|
79
87
|
* @param name - Name of the map
|
|
80
88
|
* @returns A new AztecMap
|
|
81
89
|
*/
|
|
82
|
-
openMap<K extends Key, V>(name: string): AztecAsyncMap<K, V> {
|
|
90
|
+
openMap<K extends Key, V extends Value>(name: string): AztecAsyncMap<K, V> {
|
|
83
91
|
const map = new IndexedDBAztecMap<K, V>(this.#rootDB, name);
|
|
84
92
|
this.#containers.add(map);
|
|
85
93
|
return map;
|
|
@@ -101,7 +109,7 @@ export class AztecIndexedDBStore implements AztecAsyncKVStore {
|
|
|
101
109
|
* @param name - Name of the map
|
|
102
110
|
* @returns A new AztecMultiMap
|
|
103
111
|
*/
|
|
104
|
-
openMultiMap<K extends Key, V>(name: string): AztecAsyncMultiMap<K, V> {
|
|
112
|
+
openMultiMap<K extends Key, V extends Value>(name: string): AztecAsyncMultiMap<K, V> {
|
|
105
113
|
const multimap = new IndexedDBAztecMultiMap<K, V>(this.#rootDB, name);
|
|
106
114
|
this.#containers.add(multimap);
|
|
107
115
|
return multimap;
|
|
@@ -116,7 +124,7 @@ export class AztecIndexedDBStore implements AztecAsyncKVStore {
|
|
|
116
124
|
* @param name - Name of the array
|
|
117
125
|
* @returns A new AztecArray
|
|
118
126
|
*/
|
|
119
|
-
openArray<T>(name: string): AztecAsyncArray<T> {
|
|
127
|
+
openArray<T extends Value>(name: string): AztecAsyncArray<T> {
|
|
120
128
|
const array = new IndexedDBAztecArray<T>(this.#rootDB, name);
|
|
121
129
|
this.#containers.add(array);
|
|
122
130
|
return array;
|
|
@@ -127,7 +135,7 @@ export class AztecIndexedDBStore implements AztecAsyncKVStore {
|
|
|
127
135
|
* @param name - Name of the singleton
|
|
128
136
|
* @returns A new AztecSingleton
|
|
129
137
|
*/
|
|
130
|
-
openSingleton<T>(name: string): AztecAsyncSingleton<T> {
|
|
138
|
+
openSingleton<T extends Value>(name: string): AztecAsyncSingleton<T> {
|
|
131
139
|
const singleton = new IndexedDBAztecSingleton<T>(this.#rootDB, name);
|
|
132
140
|
this.#containers.add(singleton);
|
|
133
141
|
return singleton;
|
package/src/interfaces/array.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import type { Value } from './common.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* An array backed by a persistent store. Can not have any holes in it.
|
|
3
5
|
*/
|
|
4
|
-
interface BaseAztecArray<T> {
|
|
6
|
+
interface BaseAztecArray<T extends Value> {
|
|
5
7
|
/**
|
|
6
8
|
* Pushes values to the end of the array
|
|
7
9
|
* @param vals - The values to push to the end of the array
|
|
@@ -27,7 +29,7 @@ interface BaseAztecArray<T> {
|
|
|
27
29
|
/**
|
|
28
30
|
* An array backed by a persistent store. Can not have any holes in it.
|
|
29
31
|
*/
|
|
30
|
-
export interface AztecAsyncArray<T> extends BaseAztecArray<T> {
|
|
32
|
+
export interface AztecAsyncArray<T extends Value> extends BaseAztecArray<T> {
|
|
31
33
|
/**
|
|
32
34
|
* The size of the array
|
|
33
35
|
*/
|
|
@@ -58,7 +60,7 @@ export interface AztecAsyncArray<T> extends BaseAztecArray<T> {
|
|
|
58
60
|
[Symbol.asyncIterator](): AsyncIterableIterator<T>;
|
|
59
61
|
}
|
|
60
62
|
|
|
61
|
-
export interface AztecArray<T> extends BaseAztecArray<T> {
|
|
63
|
+
export interface AztecArray<T extends Value> extends BaseAztecArray<T> {
|
|
62
64
|
/**
|
|
63
65
|
* The size of the array
|
|
64
66
|
*/
|
package/src/interfaces/common.ts
CHANGED
package/src/interfaces/map.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { Key, Range } from './common.js';
|
|
1
|
+
import type { Key, Range, Value } from './common.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* A map backed by a persistent store.
|
|
5
5
|
*/
|
|
6
|
-
interface AztecBaseMap<K extends Key, V> {
|
|
6
|
+
interface AztecBaseMap<K extends Key, V extends Value> {
|
|
7
7
|
/**
|
|
8
8
|
* Sets the value at the given key.
|
|
9
9
|
* @param key - The key to set the value at
|
|
@@ -24,7 +24,7 @@ interface AztecBaseMap<K extends Key, V> {
|
|
|
24
24
|
*/
|
|
25
25
|
delete(key: K): Promise<void>;
|
|
26
26
|
}
|
|
27
|
-
export interface AztecMap<K extends Key, V> extends AztecBaseMap<K, V> {
|
|
27
|
+
export interface AztecMap<K extends Key, V extends Value> extends AztecBaseMap<K, V> {
|
|
28
28
|
/**
|
|
29
29
|
* Gets the value at the given key.
|
|
30
30
|
* @param key - The key to get the value from
|
|
@@ -65,7 +65,7 @@ export interface AztecMap<K extends Key, V> extends AztecBaseMap<K, V> {
|
|
|
65
65
|
/**
|
|
66
66
|
* A map backed by a persistent store.
|
|
67
67
|
*/
|
|
68
|
-
export interface AztecAsyncMap<K extends Key, V> extends AztecBaseMap<K, V> {
|
|
68
|
+
export interface AztecAsyncMap<K extends Key, V extends Value> extends AztecBaseMap<K, V> {
|
|
69
69
|
/**
|
|
70
70
|
* Gets the value at the given key.
|
|
71
71
|
* @param key - The key to get the value from
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { Key } from './common.js';
|
|
1
|
+
import type { Key, Value } from './common.js';
|
|
2
2
|
import type { AztecAsyncMap, AztecMap } from './map.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* A map backed by a persistent store that can have multiple values for a single key.
|
|
6
6
|
*/
|
|
7
|
-
export interface AztecMultiMap<K extends Key, V> extends AztecMap<K, V> {
|
|
7
|
+
export interface AztecMultiMap<K extends Key, V extends Value> extends AztecMap<K, V> {
|
|
8
8
|
/**
|
|
9
9
|
* Gets all the values at the given key.
|
|
10
10
|
* @param key - The key to get the values from
|
|
@@ -22,7 +22,7 @@ export interface AztecMultiMap<K extends Key, V> extends AztecMap<K, V> {
|
|
|
22
22
|
/**
|
|
23
23
|
* A map backed by a persistent store that can have multiple values for a single key.
|
|
24
24
|
*/
|
|
25
|
-
export interface AztecAsyncMultiMap<K extends Key, V> extends AztecAsyncMap<K, V> {
|
|
25
|
+
export interface AztecAsyncMultiMap<K extends Key, V extends Value> extends AztecAsyncMap<K, V> {
|
|
26
26
|
/**
|
|
27
27
|
* Gets all the values at the given key.
|
|
28
28
|
* @param key - The key to get the values from
|
|
@@ -116,6 +116,13 @@ export function describeAztecMultiMap(
|
|
|
116
116
|
expect(await getValues('foo')).to.deep.equal(['bar', 'baz']);
|
|
117
117
|
});
|
|
118
118
|
|
|
119
|
+
it('should ignore multiple identical values', async () => {
|
|
120
|
+
await multiMap.set('foo', 'bar');
|
|
121
|
+
await multiMap.set('foo', 'bar');
|
|
122
|
+
|
|
123
|
+
expect(await getValues('foo')).to.deep.equal(['bar']);
|
|
124
|
+
});
|
|
125
|
+
|
|
119
126
|
it('should be able to delete individual values for a single key', async () => {
|
|
120
127
|
await multiMap.set('foo', 'bar');
|
|
121
128
|
await multiMap.set('foo', 'baz');
|