@aztec/kv-store 0.80.0 → 0.82.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/config.d.ts.map +1 -1
- package/dest/config.js +3 -1
- package/dest/indexeddb/map.d.ts +5 -4
- package/dest/indexeddb/map.d.ts.map +1 -1
- package/dest/indexeddb/map.js +13 -53
- package/dest/indexeddb/multi_map.d.ts +12 -0
- package/dest/indexeddb/multi_map.d.ts.map +1 -0
- package/dest/indexeddb/multi_map.js +54 -0
- package/dest/indexeddb/store.d.ts +2 -1
- package/dest/indexeddb/store.d.ts.map +1 -1
- package/dest/indexeddb/store.js +2 -1
- package/dest/interfaces/index.d.ts +1 -0
- package/dest/interfaces/index.d.ts.map +1 -1
- package/dest/interfaces/index.js +1 -0
- package/dest/interfaces/map.d.ts +0 -46
- package/dest/interfaces/map.d.ts.map +1 -1
- package/dest/interfaces/map.js +1 -1
- package/dest/interfaces/map_test_suite.d.ts.map +1 -1
- package/dest/interfaces/map_test_suite.js +6 -20
- package/dest/interfaces/multi_map.d.ts +35 -0
- package/dest/interfaces/multi_map.d.ts.map +1 -0
- package/dest/interfaces/multi_map.js +3 -0
- package/dest/interfaces/multi_map_test_suite.d.ts +3 -0
- package/dest/interfaces/multi_map_test_suite.d.ts.map +1 -0
- package/dest/interfaces/multi_map_test_suite.js +151 -0
- package/dest/interfaces/store.d.ts +2 -13
- package/dest/interfaces/store.d.ts.map +1 -1
- package/dest/lmdb/map.d.ts +2 -18
- package/dest/lmdb/map.d.ts.map +1 -1
- package/dest/lmdb/map.js +0 -81
- package/dest/lmdb/multi_map.d.ts +12 -0
- package/dest/lmdb/multi_map.d.ts.map +1 -0
- package/dest/lmdb/multi_map.js +29 -0
- package/dest/lmdb/store.d.ts +2 -13
- package/dest/lmdb/store.d.ts.map +1 -1
- package/dest/lmdb/store.js +3 -16
- package/dest/lmdb-v2/array.d.ts.map +1 -1
- package/dest/lmdb-v2/array.js +1 -0
- package/dest/lmdb-v2/map.d.ts +1 -43
- package/dest/lmdb-v2/map.d.ts.map +1 -1
- package/dest/lmdb-v2/map.js +1 -100
- package/dest/lmdb-v2/multi_map.d.ts +46 -0
- package/dest/lmdb-v2/multi_map.d.ts.map +1 -0
- package/dest/lmdb-v2/multi_map.js +103 -0
- package/dest/lmdb-v2/singleton.d.ts.map +1 -1
- package/dest/lmdb-v2/singleton.js +1 -0
- package/dest/lmdb-v2/store.d.ts +2 -1
- package/dest/lmdb-v2/store.d.ts.map +1 -1
- package/dest/lmdb-v2/store.js +5 -1
- package/dest/stores/l2_tips_store.d.ts.map +1 -1
- package/dest/stores/l2_tips_store.js +7 -4
- package/package.json +5 -5
- package/src/config.ts +3 -1
- package/src/indexeddb/map.ts +15 -47
- package/src/indexeddb/multi_map.ts +53 -0
- package/src/indexeddb/store.ts +9 -3
- package/src/interfaces/index.ts +1 -0
- package/src/interfaces/map.ts +0 -52
- package/src/interfaces/map_test_suite.ts +18 -33
- package/src/interfaces/multi_map.ts +38 -0
- package/src/interfaces/multi_map_test_suite.ts +143 -0
- package/src/interfaces/store.ts +2 -22
- package/src/lmdb/map.ts +2 -88
- package/src/lmdb/multi_map.ts +35 -0
- package/src/lmdb/store.ts +5 -27
- package/src/lmdb-v2/array.ts +1 -0
- package/src/lmdb-v2/map.ts +2 -120
- package/src/lmdb-v2/multi_map.ts +126 -0
- package/src/lmdb-v2/singleton.ts +1 -0
- package/src/lmdb-v2/store.ts +7 -2
- package/src/stores/l2_tips_store.ts +5 -3
package/dest/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,kBAAkB,EAA6C,MAAM,0BAA0B,CAAC;AAC9G,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAEhE,MAAM,MAAM,eAAe,GAAG;IAC5B,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,WAAW,CAAC,EAAE;QAAE,aAAa,EAAE,UAAU,CAAA;KAAE,CAAC;CAC7C,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,kBAAkB,CAAC,eAAe,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,kBAAkB,EAA6C,MAAM,0BAA0B,CAAC;AAC9G,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAEhE,MAAM,MAAM,eAAe,GAAG;IAC5B,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,WAAW,CAAC,EAAE;QAAE,aAAa,EAAE,UAAU,CAAA;KAAE,CAAC;CAC7C,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,kBAAkB,CAAC,eAAe,CAgBlE,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,oBAAoB,IAAI,eAAe,CAEtD"}
|
package/dest/config.js
CHANGED
package/dest/indexeddb/map.d.ts
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
import type { IDBPDatabase, IDBPObjectStore } from 'idb';
|
|
2
2
|
import type { Key, Range } from '../interfaces/common.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { AztecAsyncMap } from '../interfaces/map.js';
|
|
4
4
|
import type { AztecIDBSchema } from './store.js';
|
|
5
5
|
/**
|
|
6
6
|
* A map backed by IndexedDB.
|
|
7
7
|
*/
|
|
8
|
-
export declare class IndexedDBAztecMap<K extends Key, V> implements
|
|
8
|
+
export declare class IndexedDBAztecMap<K extends Key, V> implements AztecAsyncMap<K, V> {
|
|
9
9
|
#private;
|
|
10
10
|
protected name: string;
|
|
11
|
+
protected container: string;
|
|
11
12
|
constructor(rootDB: IDBPDatabase<AztecIDBSchema>, mapName: string);
|
|
12
13
|
set db(db: IDBPObjectStore<AztecIDBSchema, ['data'], 'data', 'readwrite'> | undefined);
|
|
13
14
|
get db(): IDBPObjectStore<AztecIDBSchema, ['data'], 'data', 'readwrite'>;
|
|
14
15
|
getAsync(key: K): Promise<V | undefined>;
|
|
15
|
-
getValuesAsync(key: K): AsyncIterableIterator<V>;
|
|
16
16
|
hasAsync(key: K): Promise<boolean>;
|
|
17
17
|
set(key: K, val: V): Promise<void>;
|
|
18
18
|
swap(_key: K, _fn: (val: V | undefined) => V): Promise<void>;
|
|
19
19
|
setIfNotExists(key: K, val: V): Promise<boolean>;
|
|
20
20
|
delete(key: K): Promise<void>;
|
|
21
|
-
deleteValue(key: K, val: V): Promise<void>;
|
|
22
21
|
entriesAsync(range?: Range<K>): AsyncIterableIterator<[K, V]>;
|
|
23
22
|
valuesAsync(range?: Range<K>): AsyncIterableIterator<V>;
|
|
24
23
|
keysAsync(range?: Range<K>): AsyncIterableIterator<K>;
|
|
24
|
+
protected normalizeKey(key: K): string;
|
|
25
|
+
protected slot(key: K, index?: number): string;
|
|
25
26
|
}
|
|
26
27
|
//# sourceMappingURL=map.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/indexeddb/map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;AAEzD,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/indexeddb/map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;AAEzD,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAA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,KAAK,GAAE,KAAK,CAAC,CAAC,CAAM,GAAG,qBAAqB,CAAC,CAAC,CAAC;IAM3D,SAAS,CAAC,KAAK,GAAE,KAAK,CAAC,CAAC,CAAM,GAAG,qBAAqB,CAAC,CAAC,CAAC;IAWhE,SAAS,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,GAAG,MAAM;IAKtC,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,GAAE,MAAU,GAAG,MAAM;CAGlD"}
|
package/dest/indexeddb/map.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
* A map backed by IndexedDB.
|
|
3
3
|
*/ export class IndexedDBAztecMap {
|
|
4
4
|
name;
|
|
5
|
-
|
|
5
|
+
container;
|
|
6
6
|
#_db;
|
|
7
7
|
#rootDB;
|
|
8
8
|
constructor(rootDB, mapName){
|
|
9
9
|
this.name = mapName;
|
|
10
|
-
this
|
|
10
|
+
this.container = `map:${mapName}`;
|
|
11
11
|
this.#rootDB = rootDB;
|
|
12
12
|
}
|
|
13
13
|
set db(db) {
|
|
@@ -17,42 +17,20 @@
|
|
|
17
17
|
return this.#_db ? this.#_db : this.#rootDB.transaction('data', 'readwrite').store;
|
|
18
18
|
}
|
|
19
19
|
async getAsync(key) {
|
|
20
|
-
const data = await this.db.get(this
|
|
20
|
+
const data = await this.db.get(this.slot(key));
|
|
21
21
|
return data?.value;
|
|
22
22
|
}
|
|
23
|
-
async *getValuesAsync(key) {
|
|
24
|
-
const index = this.db.index('keyCount');
|
|
25
|
-
const rangeQuery = IDBKeyRange.bound([
|
|
26
|
-
this.#container,
|
|
27
|
-
this.#normalizeKey(key),
|
|
28
|
-
0
|
|
29
|
-
], [
|
|
30
|
-
this.#container,
|
|
31
|
-
this.#normalizeKey(key),
|
|
32
|
-
Number.MAX_SAFE_INTEGER
|
|
33
|
-
], false, false);
|
|
34
|
-
for await (const cursor of index.iterate(rangeQuery)){
|
|
35
|
-
yield cursor.value.value;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
23
|
async hasAsync(key) {
|
|
39
24
|
const result = await this.getAsync(key) !== undefined;
|
|
40
25
|
return result;
|
|
41
26
|
}
|
|
42
27
|
async set(key, val) {
|
|
43
|
-
const count = await this.db.index('key').count(IDBKeyRange.bound([
|
|
44
|
-
this.#container,
|
|
45
|
-
this.#normalizeKey(key)
|
|
46
|
-
], [
|
|
47
|
-
this.#container,
|
|
48
|
-
this.#normalizeKey(key)
|
|
49
|
-
]));
|
|
50
28
|
await this.db.put({
|
|
51
29
|
value: val,
|
|
52
|
-
container: this
|
|
53
|
-
key: this
|
|
54
|
-
keyCount:
|
|
55
|
-
slot: this
|
|
30
|
+
container: this.container,
|
|
31
|
+
key: this.normalizeKey(key),
|
|
32
|
+
keyCount: 1,
|
|
33
|
+
slot: this.slot(key)
|
|
56
34
|
});
|
|
57
35
|
}
|
|
58
36
|
swap(_key, _fn) {
|
|
@@ -66,33 +44,15 @@
|
|
|
66
44
|
return false;
|
|
67
45
|
}
|
|
68
46
|
async delete(key) {
|
|
69
|
-
await this.db.delete(this
|
|
70
|
-
}
|
|
71
|
-
async deleteValue(key, val) {
|
|
72
|
-
const index = this.db.index('keyCount');
|
|
73
|
-
const rangeQuery = IDBKeyRange.bound([
|
|
74
|
-
this.#container,
|
|
75
|
-
this.#normalizeKey(key),
|
|
76
|
-
0
|
|
77
|
-
], [
|
|
78
|
-
this.#container,
|
|
79
|
-
this.#normalizeKey(key),
|
|
80
|
-
Number.MAX_SAFE_INTEGER
|
|
81
|
-
], false, false);
|
|
82
|
-
for await (const cursor of index.iterate(rangeQuery)){
|
|
83
|
-
if (JSON.stringify(cursor.value.value) === JSON.stringify(val)) {
|
|
84
|
-
await cursor.delete();
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
47
|
+
await this.db.delete(this.slot(key));
|
|
88
48
|
}
|
|
89
49
|
async *entriesAsync(range = {}) {
|
|
90
50
|
const index = this.db.index('key');
|
|
91
51
|
const rangeQuery = IDBKeyRange.bound([
|
|
92
|
-
this
|
|
52
|
+
this.container,
|
|
93
53
|
range.start ?? ''
|
|
94
54
|
], [
|
|
95
|
-
this
|
|
55
|
+
this.container,
|
|
96
56
|
range.end ?? '\uffff'
|
|
97
57
|
], !!range.reverse, !range.reverse);
|
|
98
58
|
let count = 0;
|
|
@@ -121,13 +81,13 @@
|
|
|
121
81
|
const denormalizedKey = key.split(',').map((part)=>isNaN(parseInt(part)) ? part : parseInt(part));
|
|
122
82
|
return denormalizedKey.length > 1 ? denormalizedKey : key;
|
|
123
83
|
}
|
|
124
|
-
|
|
84
|
+
normalizeKey(key) {
|
|
125
85
|
const arrayKey = Array.isArray(key) ? key : [
|
|
126
86
|
key
|
|
127
87
|
];
|
|
128
88
|
return arrayKey.join(',');
|
|
129
89
|
}
|
|
130
|
-
|
|
131
|
-
return `map:${this.name}:slot:${this
|
|
90
|
+
slot(key, index = 0) {
|
|
91
|
+
return `map:${this.name}:slot:${this.normalizeKey(key)}:${index}`;
|
|
132
92
|
}
|
|
133
93
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Key } from '../interfaces/common.js';
|
|
2
|
+
import type { AztecAsyncMultiMap } from '../interfaces/multi_map.js';
|
|
3
|
+
import { IndexedDBAztecMap } from './map.js';
|
|
4
|
+
/**
|
|
5
|
+
* A multi map backed by IndexedDB.
|
|
6
|
+
*/
|
|
7
|
+
export declare class IndexedDBAztecMultiMap<K extends Key, V> extends IndexedDBAztecMap<K, V> implements AztecAsyncMultiMap<K, V> {
|
|
8
|
+
set(key: K, val: V): Promise<void>;
|
|
9
|
+
getValuesAsync(key: K): AsyncIterableIterator<V>;
|
|
10
|
+
deleteValue(key: K, val: V): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=multi_map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi_map.d.ts","sourceRoot":"","sources":["../../src/indexeddb/multi_map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C;;GAEG;AACH,qBAAa,sBAAsB,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC,CAClD,SAAQ,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAC9B,YAAW,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC;IAEpB,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAa1C,cAAc,CAAC,GAAG,EAAE,CAAC,GAAG,qBAAqB,CAAC,CAAC,CAAC;IAajD,WAAW,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAejD"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { IndexedDBAztecMap } from './map.js';
|
|
2
|
+
/**
|
|
3
|
+
* A multi map backed by IndexedDB.
|
|
4
|
+
*/ export class IndexedDBAztecMultiMap extends IndexedDBAztecMap {
|
|
5
|
+
async set(key, val) {
|
|
6
|
+
const count = await this.db.index('key').count(IDBKeyRange.bound([
|
|
7
|
+
this.container,
|
|
8
|
+
this.normalizeKey(key)
|
|
9
|
+
], [
|
|
10
|
+
this.container,
|
|
11
|
+
this.normalizeKey(key)
|
|
12
|
+
]));
|
|
13
|
+
await this.db.put({
|
|
14
|
+
value: val,
|
|
15
|
+
container: this.container,
|
|
16
|
+
key: this.normalizeKey(key),
|
|
17
|
+
keyCount: count + 1,
|
|
18
|
+
slot: this.slot(key, count)
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async *getValuesAsync(key) {
|
|
22
|
+
const index = this.db.index('keyCount');
|
|
23
|
+
const rangeQuery = IDBKeyRange.bound([
|
|
24
|
+
this.container,
|
|
25
|
+
this.normalizeKey(key),
|
|
26
|
+
0
|
|
27
|
+
], [
|
|
28
|
+
this.container,
|
|
29
|
+
this.normalizeKey(key),
|
|
30
|
+
Number.MAX_SAFE_INTEGER
|
|
31
|
+
], false, false);
|
|
32
|
+
for await (const cursor of index.iterate(rangeQuery)){
|
|
33
|
+
yield cursor.value.value;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async deleteValue(key, val) {
|
|
37
|
+
const index = this.db.index('keyCount');
|
|
38
|
+
const rangeQuery = IDBKeyRange.bound([
|
|
39
|
+
this.container,
|
|
40
|
+
this.normalizeKey(key),
|
|
41
|
+
0
|
|
42
|
+
], [
|
|
43
|
+
this.container,
|
|
44
|
+
this.normalizeKey(key),
|
|
45
|
+
Number.MAX_SAFE_INTEGER
|
|
46
|
+
], false, false);
|
|
47
|
+
for await (const cursor of index.iterate(rangeQuery)){
|
|
48
|
+
if (JSON.stringify(cursor.value.value) === JSON.stringify(val)) {
|
|
49
|
+
await cursor.delete();
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -3,7 +3,8 @@ import { type DBSchema, type IDBPDatabase } from 'idb';
|
|
|
3
3
|
import type { AztecAsyncArray } from '../interfaces/array.js';
|
|
4
4
|
import type { Key, StoreSize } from '../interfaces/common.js';
|
|
5
5
|
import type { AztecAsyncCounter } from '../interfaces/counter.js';
|
|
6
|
-
import type { AztecAsyncMap
|
|
6
|
+
import type { AztecAsyncMap } from '../interfaces/map.js';
|
|
7
|
+
import type { AztecAsyncMultiMap } from '../interfaces/multi_map.js';
|
|
7
8
|
import type { AztecAsyncSet } from '../interfaces/set.js';
|
|
8
9
|
import type { AztecAsyncSingleton } from '../interfaces/singleton.js';
|
|
9
10
|
import type { AztecAsyncKVStore } from '../interfaces/store.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["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H,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,eAAe,CAAC,CAAC,CAAC;IAM9C;;;;OAIG;IACH,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,mBAAmB,CAAC,CAAC,CAAC;IAMtD;;;;OAIG;IACG,gBAAgB,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAkBjE;;OAEG;IACG,KAAK;IAIX,kDAAkD;IAClD,MAAM;IAMN,YAAY,IAAI,OAAO,CAAC,SAAS,CAAC;IAIlC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAGvB"}
|
package/dest/indexeddb/store.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { deleteDB, openDB } from 'idb';
|
|
2
2
|
import { IndexedDBAztecArray } from './array.js';
|
|
3
3
|
import { IndexedDBAztecMap } from './map.js';
|
|
4
|
+
import { IndexedDBAztecMultiMap } from './multi_map.js';
|
|
4
5
|
import { IndexedDBAztecSet } from './set.js';
|
|
5
6
|
import { IndexedDBAztecSingleton } from './singleton.js';
|
|
6
7
|
/**
|
|
@@ -95,7 +96,7 @@ import { IndexedDBAztecSingleton } from './singleton.js';
|
|
|
95
96
|
* @param name - Name of the map
|
|
96
97
|
* @returns A new AztecMultiMap
|
|
97
98
|
*/ openMultiMap(name) {
|
|
98
|
-
const multimap = new
|
|
99
|
+
const multimap = new IndexedDBAztecMultiMap(this.#rootDB, name);
|
|
99
100
|
this.#containers.add(multimap);
|
|
100
101
|
return multimap;
|
|
101
102
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
|
package/dest/interfaces/index.js
CHANGED
package/dest/interfaces/map.d.ts
CHANGED
|
@@ -53,36 +53,6 @@ export interface AztecMap<K extends Key, V> extends AztecBaseMap<K, V> {
|
|
|
53
53
|
*/
|
|
54
54
|
clear(): Promise<void>;
|
|
55
55
|
}
|
|
56
|
-
export interface AztecMapWithSize<K extends Key, V> extends AztecMap<K, V> {
|
|
57
|
-
/**
|
|
58
|
-
* Gets the size of the map.
|
|
59
|
-
* @returns The size of the map
|
|
60
|
-
*/
|
|
61
|
-
size(): number;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* A map backed by a persistent store that can have multiple values for a single key.
|
|
65
|
-
*/
|
|
66
|
-
export interface AztecMultiMap<K extends Key, V> extends AztecMap<K, V> {
|
|
67
|
-
/**
|
|
68
|
-
* Gets all the values at the given key.
|
|
69
|
-
* @param key - The key to get the values from
|
|
70
|
-
*/
|
|
71
|
-
getValues(key: K): IterableIterator<V>;
|
|
72
|
-
/**
|
|
73
|
-
* Deletes a specific value at the given key.
|
|
74
|
-
* @param key - The key to delete the value at
|
|
75
|
-
* @param val - The value to delete
|
|
76
|
-
*/
|
|
77
|
-
deleteValue(key: K, val: V): Promise<void>;
|
|
78
|
-
}
|
|
79
|
-
export interface AztecMultiMapWithSize<K extends Key, V> extends AztecMultiMap<K, V> {
|
|
80
|
-
/**
|
|
81
|
-
* Gets the size of the map.
|
|
82
|
-
* @returns The size of the map
|
|
83
|
-
*/
|
|
84
|
-
size(): number;
|
|
85
|
-
}
|
|
86
56
|
/**
|
|
87
57
|
* A map backed by a persistent store.
|
|
88
58
|
*/
|
|
@@ -114,21 +84,5 @@ export interface AztecAsyncMap<K extends Key, V> extends AztecBaseMap<K, V> {
|
|
|
114
84
|
*/
|
|
115
85
|
keysAsync(range?: Range<K>): AsyncIterableIterator<K>;
|
|
116
86
|
}
|
|
117
|
-
/**
|
|
118
|
-
* A map backed by a persistent store that can have multiple values for a single key.
|
|
119
|
-
*/
|
|
120
|
-
export interface AztecAsyncMultiMap<K extends Key, V> extends AztecAsyncMap<K, V> {
|
|
121
|
-
/**
|
|
122
|
-
* Gets all the values at the given key.
|
|
123
|
-
* @param key - The key to get the values from
|
|
124
|
-
*/
|
|
125
|
-
getValuesAsync(key: K): AsyncIterableIterator<V>;
|
|
126
|
-
/**
|
|
127
|
-
* Deletes a specific value at the given key.
|
|
128
|
-
* @param key - The key to delete the value at
|
|
129
|
-
* @param val - The value to delete
|
|
130
|
-
*/
|
|
131
|
-
deleteValue(key: K, val: V): Promise<void>;
|
|
132
|
-
}
|
|
133
87
|
export {};
|
|
134
88
|
//# sourceMappingURL=map.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/interfaces/map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAE9C;;GAEG;AACH,UAAU,YAAY,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC;IACrC;;;;OAIG;IACH,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnC;;;;OAIG;IACH,cAAc,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE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AAE,CAAC,CAAC,CAAC,CAAC;IAE9D;;;OAGG;IACH,WAAW,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAExD;;;OAGG;IACH,SAAS,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAAC;CACvD"}
|
package/dest/interfaces/map.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map_test_suite.d.ts","sourceRoot":"","sources":["../../src/interfaces/map_test_suite.ts"],"names":[],"mappings":"AAMA,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,
|
|
1
|
+
{"version":3,"file":"map_test_suite.d.ts","sourceRoot":"","sources":["../../src/interfaces/map_test_suite.ts"],"names":[],"mappings":"AAMA,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,QAmH5B"}
|
|
@@ -7,7 +7,7 @@ export function describeAztecMap(testName, getStore, forceAsync = false) {
|
|
|
7
7
|
let map;
|
|
8
8
|
beforeEach(async ()=>{
|
|
9
9
|
store = await getStore();
|
|
10
|
-
map = store.
|
|
10
|
+
map = store.openMap('test');
|
|
11
11
|
});
|
|
12
12
|
afterEach(async ()=>{
|
|
13
13
|
await store.delete();
|
|
@@ -24,9 +24,6 @@ export function describeAztecMap(testName, getStore, forceAsync = false) {
|
|
|
24
24
|
async function keys(range, sut = map) {
|
|
25
25
|
return isSyncStore(store) && !forceAsync ? await toArray(sut.keys(range)) : await toArray(sut.keysAsync(range));
|
|
26
26
|
}
|
|
27
|
-
async function getValues(key) {
|
|
28
|
-
return isSyncStore(store) && !forceAsync ? await toArray(map.getValues(key)) : await toArray(map.getValuesAsync(key));
|
|
29
|
-
}
|
|
30
27
|
it('should be able to set and get values', async ()=>{
|
|
31
28
|
await map.set('foo', 'bar');
|
|
32
29
|
await map.set('baz', 'qux');
|
|
@@ -34,6 +31,11 @@ export function describeAztecMap(testName, getStore, forceAsync = false) {
|
|
|
34
31
|
expect(await get('baz')).to.equal('qux');
|
|
35
32
|
expect(await get('quux')).to.equal(undefined);
|
|
36
33
|
});
|
|
34
|
+
it('should be able to overwrite values', async ()=>{
|
|
35
|
+
await map.set('foo', 'bar');
|
|
36
|
+
await map.set('foo', 'baz');
|
|
37
|
+
expect(await get('foo')).to.equal('baz');
|
|
38
|
+
});
|
|
37
39
|
it('should be able to set values if they do not exist', async ()=>{
|
|
38
40
|
expect(await map.setIfNotExists('foo', 'bar')).to.equal(true);
|
|
39
41
|
expect(await map.setIfNotExists('foo', 'baz')).to.equal(false);
|
|
@@ -79,22 +81,6 @@ export function describeAztecMap(testName, getStore, forceAsync = false) {
|
|
|
79
81
|
'foo'
|
|
80
82
|
]);
|
|
81
83
|
});
|
|
82
|
-
it('should be able to get multiple values for a single key', async ()=>{
|
|
83
|
-
await map.set('foo', 'bar');
|
|
84
|
-
await map.set('foo', 'baz');
|
|
85
|
-
expect(await getValues('foo')).to.deep.equal([
|
|
86
|
-
'bar',
|
|
87
|
-
'baz'
|
|
88
|
-
]);
|
|
89
|
-
});
|
|
90
|
-
it('should be able to delete individual values for a single key', async ()=>{
|
|
91
|
-
await map.set('foo', 'bar');
|
|
92
|
-
await map.set('foo', 'baz');
|
|
93
|
-
await map.deleteValue('foo', 'bar');
|
|
94
|
-
expect(await getValues('foo')).to.deep.equal([
|
|
95
|
-
'baz'
|
|
96
|
-
]);
|
|
97
|
-
});
|
|
98
84
|
it('supports range queries', async ()=>{
|
|
99
85
|
await map.set('a', 'a');
|
|
100
86
|
await map.set('b', 'b');
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Key } from './common.js';
|
|
2
|
+
import type { AztecAsyncMap, AztecMap } from './map.js';
|
|
3
|
+
/**
|
|
4
|
+
* A map backed by a persistent store that can have multiple values for a single key.
|
|
5
|
+
*/
|
|
6
|
+
export interface AztecMultiMap<K extends Key, V> extends AztecMap<K, V> {
|
|
7
|
+
/**
|
|
8
|
+
* Gets all the values at the given key.
|
|
9
|
+
* @param key - The key to get the values from
|
|
10
|
+
*/
|
|
11
|
+
getValues(key: K): IterableIterator<V>;
|
|
12
|
+
/**
|
|
13
|
+
* Deletes a specific value at the given key.
|
|
14
|
+
* @param key - The key to delete the value at
|
|
15
|
+
* @param val - The value to delete
|
|
16
|
+
*/
|
|
17
|
+
deleteValue(key: K, val: V): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A map backed by a persistent store that can have multiple values for a single key.
|
|
21
|
+
*/
|
|
22
|
+
export interface AztecAsyncMultiMap<K extends Key, V> extends AztecAsyncMap<K, V> {
|
|
23
|
+
/**
|
|
24
|
+
* Gets all the values at the given key.
|
|
25
|
+
* @param key - The key to get the values from
|
|
26
|
+
*/
|
|
27
|
+
getValuesAsync(key: K): AsyncIterableIterator<V>;
|
|
28
|
+
/**
|
|
29
|
+
* Deletes a specific value at the given key.
|
|
30
|
+
* @param key - The key to delete the value at
|
|
31
|
+
* @param val - The value to delete
|
|
32
|
+
*/
|
|
33
|
+
deleteValue(key: K, val: V): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=multi_map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi_map.d.ts","sourceRoot":"","sources":["../../src/interfaces/multi_map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC,CAAE,SAAQ,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;IACrE;;;OAGG;IACH,SAAS,CAAC,GAAG,EAAE,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAEvC;;;;OAIG;IACH,WAAW,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5C;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC,CAAE,SAAQ,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC;IAC/E;;;OAGG;IACH,cAAc,CAAC,GAAG,EAAE,CAAC,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAEjD;;;;OAIG;IACH,WAAW,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi_map_test_suite.d.ts","sourceRoot":"","sources":["../../src/interfaces/multi_map_test_suite.ts"],"names":[],"mappings":"AAMA,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,QAkI5B"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { toArray } from '@aztec/foundation/iterable';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
import { isSyncStore } from './utils.js';
|
|
4
|
+
export function describeAztecMultiMap(testName, getStore, forceAsync = false) {
|
|
5
|
+
describe(testName, ()=>{
|
|
6
|
+
let store;
|
|
7
|
+
let multiMap;
|
|
8
|
+
beforeEach(async ()=>{
|
|
9
|
+
store = await getStore();
|
|
10
|
+
multiMap = store.openMultiMap('test');
|
|
11
|
+
});
|
|
12
|
+
afterEach(async ()=>{
|
|
13
|
+
await store.delete();
|
|
14
|
+
});
|
|
15
|
+
async function get(key, sut = multiMap) {
|
|
16
|
+
return isSyncStore(store) && !forceAsync ? sut.get(key) : await sut.getAsync(key);
|
|
17
|
+
}
|
|
18
|
+
async function entries() {
|
|
19
|
+
return isSyncStore(store) && !forceAsync ? await toArray(multiMap.entries()) : await toArray(multiMap.entriesAsync());
|
|
20
|
+
}
|
|
21
|
+
async function values() {
|
|
22
|
+
return isSyncStore(store) && !forceAsync ? await toArray(multiMap.values()) : await toArray(multiMap.valuesAsync());
|
|
23
|
+
}
|
|
24
|
+
async function keys(range, sut = multiMap) {
|
|
25
|
+
return isSyncStore(store) && !forceAsync ? await toArray(sut.keys(range)) : await toArray(sut.keysAsync(range));
|
|
26
|
+
}
|
|
27
|
+
async function getValues(key) {
|
|
28
|
+
return isSyncStore(store) && !forceAsync ? await toArray(multiMap.getValues(key)) : await toArray(multiMap.getValuesAsync(key));
|
|
29
|
+
}
|
|
30
|
+
it('should be able to set and get values', async ()=>{
|
|
31
|
+
await multiMap.set('foo', 'bar');
|
|
32
|
+
await multiMap.set('baz', 'qux');
|
|
33
|
+
expect(await get('foo')).to.equal('bar');
|
|
34
|
+
expect(await get('baz')).to.equal('qux');
|
|
35
|
+
expect(await get('quux')).to.equal(undefined);
|
|
36
|
+
});
|
|
37
|
+
it('should be able to set values if they do not exist', async ()=>{
|
|
38
|
+
expect(await multiMap.setIfNotExists('foo', 'bar')).to.equal(true);
|
|
39
|
+
expect(await multiMap.setIfNotExists('foo', 'baz')).to.equal(false);
|
|
40
|
+
expect(await get('foo')).to.equal('bar');
|
|
41
|
+
});
|
|
42
|
+
it('should be able to delete values', async ()=>{
|
|
43
|
+
await multiMap.set('foo', 'bar');
|
|
44
|
+
await multiMap.set('baz', 'qux');
|
|
45
|
+
await multiMap.delete('foo');
|
|
46
|
+
expect(await get('foo')).to.equal(undefined);
|
|
47
|
+
expect(await get('baz')).to.equal('qux');
|
|
48
|
+
});
|
|
49
|
+
it('should be able to iterate over entries when there are no keys', async ()=>{
|
|
50
|
+
expect(await entries()).to.deep.equal([]);
|
|
51
|
+
});
|
|
52
|
+
it('should be able to iterate over entries', async ()=>{
|
|
53
|
+
await multiMap.set('foo', 'bar');
|
|
54
|
+
await multiMap.set('baz', 'qux');
|
|
55
|
+
expect(await entries()).to.deep.equal([
|
|
56
|
+
[
|
|
57
|
+
'baz',
|
|
58
|
+
'qux'
|
|
59
|
+
],
|
|
60
|
+
[
|
|
61
|
+
'foo',
|
|
62
|
+
'bar'
|
|
63
|
+
]
|
|
64
|
+
]);
|
|
65
|
+
});
|
|
66
|
+
it('should be able to iterate over values', async ()=>{
|
|
67
|
+
await multiMap.set('foo', 'bar');
|
|
68
|
+
await multiMap.set('baz', 'quux');
|
|
69
|
+
expect(await values()).to.deep.equal([
|
|
70
|
+
'quux',
|
|
71
|
+
'bar'
|
|
72
|
+
]);
|
|
73
|
+
});
|
|
74
|
+
it('should be able to iterate over keys', async ()=>{
|
|
75
|
+
await multiMap.set('foo', 'bar');
|
|
76
|
+
await multiMap.set('baz', 'qux');
|
|
77
|
+
expect(await keys()).to.deep.equal([
|
|
78
|
+
'baz',
|
|
79
|
+
'foo'
|
|
80
|
+
]);
|
|
81
|
+
});
|
|
82
|
+
it('should be able to get multiple values for a single key', async ()=>{
|
|
83
|
+
await multiMap.set('foo', 'bar');
|
|
84
|
+
await multiMap.set('foo', 'baz');
|
|
85
|
+
expect(await getValues('foo')).to.deep.equal([
|
|
86
|
+
'bar',
|
|
87
|
+
'baz'
|
|
88
|
+
]);
|
|
89
|
+
});
|
|
90
|
+
it('should be able to delete individual values for a single key', async ()=>{
|
|
91
|
+
await multiMap.set('foo', 'bar');
|
|
92
|
+
await multiMap.set('foo', 'baz');
|
|
93
|
+
await multiMap.deleteValue('foo', 'bar');
|
|
94
|
+
expect(await getValues('foo')).to.deep.equal([
|
|
95
|
+
'baz'
|
|
96
|
+
]);
|
|
97
|
+
});
|
|
98
|
+
it('supports range queries', async ()=>{
|
|
99
|
+
await multiMap.set('a', 'a');
|
|
100
|
+
await multiMap.set('b', 'b');
|
|
101
|
+
await multiMap.set('c', 'c');
|
|
102
|
+
await multiMap.set('d', 'd');
|
|
103
|
+
expect(await keys({
|
|
104
|
+
start: 'b',
|
|
105
|
+
end: 'c'
|
|
106
|
+
})).to.deep.equal([
|
|
107
|
+
'b'
|
|
108
|
+
]);
|
|
109
|
+
expect(await keys({
|
|
110
|
+
start: 'b'
|
|
111
|
+
})).to.deep.equal([
|
|
112
|
+
'b',
|
|
113
|
+
'c',
|
|
114
|
+
'd'
|
|
115
|
+
]);
|
|
116
|
+
expect(await keys({
|
|
117
|
+
end: 'c'
|
|
118
|
+
})).to.deep.equal([
|
|
119
|
+
'a',
|
|
120
|
+
'b'
|
|
121
|
+
]);
|
|
122
|
+
expect(await keys({
|
|
123
|
+
start: 'b',
|
|
124
|
+
end: 'c',
|
|
125
|
+
reverse: true
|
|
126
|
+
})).to.deep.equal([
|
|
127
|
+
'c'
|
|
128
|
+
]);
|
|
129
|
+
expect(await keys({
|
|
130
|
+
start: 'b',
|
|
131
|
+
limit: 1
|
|
132
|
+
})).to.deep.equal([
|
|
133
|
+
'b'
|
|
134
|
+
]);
|
|
135
|
+
expect(await keys({
|
|
136
|
+
start: 'b',
|
|
137
|
+
reverse: true
|
|
138
|
+
})).to.deep.equal([
|
|
139
|
+
'd',
|
|
140
|
+
'c'
|
|
141
|
+
]);
|
|
142
|
+
expect(await keys({
|
|
143
|
+
end: 'b',
|
|
144
|
+
reverse: true
|
|
145
|
+
})).to.deep.equal([
|
|
146
|
+
'b',
|
|
147
|
+
'a'
|
|
148
|
+
]);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
}
|