@aztec/kv-store 0.0.0-test.1 → 0.0.1-commit.b655e406
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 +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +5 -3
- 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/index.js +1 -1
- package/dest/indexeddb/map.d.ts +11 -5
- package/dest/indexeddb/map.d.ts.map +1 -1
- package/dest/indexeddb/map.js +38 -60
- 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 +78 -0
- 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 +12 -13
- package/dest/indexeddb/store.d.ts.map +1 -1
- package/dest/indexeddb/store.js +45 -42
- 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 +10 -8
- package/dest/interfaces/common.d.ts.map +1 -1
- package/dest/interfaces/common.js +8 -3
- package/dest/interfaces/index.d.ts +3 -1
- package/dest/interfaces/index.d.ts.map +1 -1
- package/dest/interfaces/index.js +2 -0
- package/dest/interfaces/map.d.ts +20 -48
- 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 +135 -70
- 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 +245 -0
- package/dest/interfaces/store.d.ts +17 -42
- package/dest/interfaces/store.d.ts.map +1 -1
- package/dest/interfaces/utils.d.ts +1 -0
- package/dest/interfaces/utils.d.ts.map +1 -1
- package/dest/interfaces/utils.js +2 -1
- package/dest/lmdb/array.d.ts +2 -1
- package/dest/lmdb/array.d.ts.map +1 -1
- package/dest/lmdb/index.js +2 -2
- package/dest/lmdb/map.d.ts +10 -22
- package/dest/lmdb/map.d.ts.map +1 -1
- package/dest/lmdb/map.js +15 -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 +7 -22
- package/dest/lmdb/store.d.ts.map +1 -1
- package/dest/lmdb/store.js +11 -31
- package/dest/lmdb-v2/array.d.ts +2 -1
- package/dest/lmdb-v2/array.d.ts.map +1 -1
- package/dest/lmdb-v2/array.js +1 -0
- package/dest/lmdb-v2/factory.d.ts +1 -1
- package/dest/lmdb-v2/factory.d.ts.map +1 -1
- package/dest/lmdb-v2/factory.js +16 -6
- package/dest/lmdb-v2/map.d.ts +10 -43
- package/dest/lmdb-v2/map.d.ts.map +1 -1
- package/dest/lmdb-v2/map.js +17 -103
- package/dest/lmdb-v2/message.d.ts +23 -4
- package/dest/lmdb-v2/message.d.ts.map +1 -1
- package/dest/lmdb-v2/message.js +6 -4
- package/dest/lmdb-v2/multi_map.d.ts +51 -0
- package/dest/lmdb-v2/multi_map.d.ts.map +1 -0
- package/dest/lmdb-v2/multi_map.js +113 -0
- package/dest/lmdb-v2/read_transaction.d.ts +2 -0
- package/dest/lmdb-v2/read_transaction.d.ts.map +1 -1
- package/dest/lmdb-v2/read_transaction.js +34 -0
- package/dest/lmdb-v2/set.d.ts +15 -0
- package/dest/lmdb-v2/set.d.ts.map +1 -0
- package/dest/lmdb-v2/set.js +23 -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 +9 -8
- package/dest/lmdb-v2/store.d.ts.map +1 -1
- package/dest/lmdb-v2/store.js +19 -7
- package/dest/lmdb-v2/utils.d.ts +2 -4
- package/dest/lmdb-v2/utils.d.ts.map +1 -1
- package/dest/lmdb-v2/write_transaction.d.ts +2 -4
- package/dest/lmdb-v2/write_transaction.d.ts.map +1 -1
- package/dest/stores/index.d.ts +1 -0
- package/dest/stores/index.d.ts.map +1 -1
- package/dest/stores/index.js +1 -0
- package/dest/stores/l2_tips_store.d.ts +2 -1
- package/dest/stores/l2_tips_store.d.ts.map +1 -1
- package/dest/stores/l2_tips_store.js +18 -9
- package/package.json +18 -14
- package/src/config.ts +6 -4
- package/src/indexeddb/array.ts +5 -1
- package/src/indexeddb/index.ts +2 -2
- package/src/indexeddb/map.ts +35 -53
- package/src/indexeddb/multi_map.ts +79 -0
- package/src/indexeddb/singleton.ts +4 -1
- package/src/indexeddb/store.ts +66 -56
- package/src/interfaces/array.ts +5 -3
- package/src/interfaces/common.ts +20 -9
- package/src/interfaces/index.ts +3 -1
- package/src/interfaces/map.ts +19 -53
- package/src/interfaces/map_test_suite.ts +73 -44
- package/src/interfaces/multi_map.ts +38 -0
- package/src/interfaces/multi_map_test_suite.ts +242 -0
- package/src/interfaces/store.ts +18 -53
- package/src/interfaces/utils.ts +1 -0
- package/src/lmdb/array.ts +2 -1
- package/src/lmdb/index.ts +3 -3
- package/src/lmdb/map.ts +23 -94
- package/src/lmdb/multi_map.ts +35 -0
- package/src/lmdb/store.ts +23 -47
- package/src/lmdb-v2/array.ts +7 -2
- package/src/lmdb-v2/factory.ts +17 -10
- package/src/lmdb-v2/map.ts +29 -126
- package/src/lmdb-v2/message.ts +23 -0
- package/src/lmdb-v2/multi_map.ts +141 -0
- package/src/lmdb-v2/read_transaction.ts +40 -0
- package/src/lmdb-v2/set.ts +33 -0
- package/src/lmdb-v2/singleton.ts +5 -1
- package/src/lmdb-v2/store.ts +22 -14
- package/src/lmdb-v2/write_transaction.ts +2 -2
- package/src/stores/index.ts +2 -0
- package/src/stores/l2_tips_store.ts +18 -9
- package/dest/interfaces/store_test_suite.d.ts +0 -3
- package/dest/interfaces/store_test_suite.d.ts.map +0 -1
- package/dest/interfaces/store_test_suite.js +0 -37
- package/src/interfaces/store_test_suite.ts +0 -56
package/dest/lmdb/map.js
CHANGED
|
@@ -35,24 +35,6 @@
|
|
|
35
35
|
getAsync(key) {
|
|
36
36
|
return Promise.resolve(this.get(key));
|
|
37
37
|
}
|
|
38
|
-
*getValues(key) {
|
|
39
|
-
const transaction = this.db.useReadTransaction();
|
|
40
|
-
try {
|
|
41
|
-
const values = this.db.getValues(this.slot(key), {
|
|
42
|
-
transaction
|
|
43
|
-
});
|
|
44
|
-
for (const value of values){
|
|
45
|
-
yield value?.[1];
|
|
46
|
-
}
|
|
47
|
-
} finally{
|
|
48
|
-
transaction.done();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
async *getValuesAsync(key) {
|
|
52
|
-
for (const value of this.getValues(key)){
|
|
53
|
-
yield value;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
38
|
has(key) {
|
|
57
39
|
return this.db.doesExist(this.slot(key));
|
|
58
40
|
}
|
|
@@ -65,6 +47,11 @@
|
|
|
65
47
|
val
|
|
66
48
|
]);
|
|
67
49
|
}
|
|
50
|
+
async setMany(entries) {
|
|
51
|
+
for (const { key, value } of entries){
|
|
52
|
+
await this.set(key, value);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
68
55
|
swap(key, fn) {
|
|
69
56
|
return this.db.childTransaction(()=>{
|
|
70
57
|
const slot = this.slot(key);
|
|
@@ -87,12 +74,6 @@
|
|
|
87
74
|
async delete(key) {
|
|
88
75
|
await this.db.remove(this.slot(key));
|
|
89
76
|
}
|
|
90
|
-
async deleteValue(key, val) {
|
|
91
|
-
await this.db.remove(this.slot(key), [
|
|
92
|
-
key,
|
|
93
|
-
val
|
|
94
|
-
]);
|
|
95
|
-
}
|
|
96
77
|
*entries(range = {}) {
|
|
97
78
|
const transaction = this.db.useReadTransaction();
|
|
98
79
|
try {
|
|
@@ -134,6 +115,16 @@
|
|
|
134
115
|
yield value;
|
|
135
116
|
}
|
|
136
117
|
}
|
|
118
|
+
size() {
|
|
119
|
+
const iterator = this.db.getRange({
|
|
120
|
+
start: this.startSentinel,
|
|
121
|
+
end: this.endSentinel
|
|
122
|
+
});
|
|
123
|
+
return iterator.asArray.length;
|
|
124
|
+
}
|
|
125
|
+
sizeAsync() {
|
|
126
|
+
return Promise.resolve(this.size());
|
|
127
|
+
}
|
|
137
128
|
*keys(range = {}) {
|
|
138
129
|
for (const [key, _] of this.entries(range)){
|
|
139
130
|
yield key;
|
|
@@ -163,60 +154,3 @@
|
|
|
163
154
|
}
|
|
164
155
|
}
|
|
165
156
|
}
|
|
166
|
-
export class LmdbAztecMapWithSize extends LmdbAztecMap {
|
|
167
|
-
#sizeCache;
|
|
168
|
-
constructor(rootDb, mapName){
|
|
169
|
-
super(rootDb, mapName);
|
|
170
|
-
}
|
|
171
|
-
async set(key, val) {
|
|
172
|
-
await this.db.childTransaction(()=>{
|
|
173
|
-
const exists = this.db.doesExist(this.slot(key));
|
|
174
|
-
this.db.putSync(this.slot(key), [
|
|
175
|
-
key,
|
|
176
|
-
val
|
|
177
|
-
], {
|
|
178
|
-
appendDup: true
|
|
179
|
-
});
|
|
180
|
-
if (!exists) {
|
|
181
|
-
this.#sizeCache = undefined; // Invalidate cache
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
async delete(key) {
|
|
186
|
-
await this.db.childTransaction(async ()=>{
|
|
187
|
-
const exists = this.db.doesExist(this.slot(key));
|
|
188
|
-
if (exists) {
|
|
189
|
-
await this.db.remove(this.slot(key));
|
|
190
|
-
this.#sizeCache = undefined; // Invalidate cache
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
async deleteValue(key, val) {
|
|
195
|
-
await this.db.childTransaction(async ()=>{
|
|
196
|
-
const exists = this.db.doesExist(this.slot(key));
|
|
197
|
-
if (exists) {
|
|
198
|
-
await this.db.remove(this.slot(key), [
|
|
199
|
-
key,
|
|
200
|
-
val
|
|
201
|
-
]);
|
|
202
|
-
this.#sizeCache = undefined; // Invalidate cache
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Gets the size of the map by counting entries.
|
|
208
|
-
* @returns The number of entries in the map
|
|
209
|
-
*/ size() {
|
|
210
|
-
if (this.#sizeCache === undefined) {
|
|
211
|
-
this.#sizeCache = this.db.getCount({
|
|
212
|
-
start: this.startSentinel,
|
|
213
|
-
end: this.endSentinel
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
return this.#sizeCache;
|
|
217
|
-
}
|
|
218
|
-
// Reset cache on clear/drop operations
|
|
219
|
-
clearCache() {
|
|
220
|
-
this.#sizeCache = undefined;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Key, Value } from '../interfaces/common.js';
|
|
2
|
+
import type { AztecAsyncMultiMap, AztecMultiMap } from '../interfaces/multi_map.js';
|
|
3
|
+
import { LmdbAztecMap } from './map.js';
|
|
4
|
+
/**
|
|
5
|
+
* A map backed by LMDB.
|
|
6
|
+
*/
|
|
7
|
+
export declare class LmdbAztecMultiMap<K extends Key, V extends Value> extends LmdbAztecMap<K, V> implements AztecMultiMap<K, V>, AztecAsyncMultiMap<K, V> {
|
|
8
|
+
getValues(key: K): IterableIterator<V>;
|
|
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/lmdb/multi_map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AACpF,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC;;GAEG;AACH,qBAAa,iBAAiB,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC,SAAS,KAAK,CAC3D,SAAQ,YAAY,CAAC,CAAC,EAAE,CAAC,CACzB,YAAW,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC;IAEvD,SAAS,CAAC,GAAG,EAAE,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC;IAchC,cAAc,CAAC,GAAG,EAAE,CAAC,GAAG,qBAAqB,CAAC,CAAC,CAAC;IAMjD,WAAW,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAGjD"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { LmdbAztecMap } from './map.js';
|
|
2
|
+
/**
|
|
3
|
+
* A map backed by LMDB.
|
|
4
|
+
*/ export class LmdbAztecMultiMap extends LmdbAztecMap {
|
|
5
|
+
*getValues(key) {
|
|
6
|
+
const transaction = this.db.useReadTransaction();
|
|
7
|
+
try {
|
|
8
|
+
const values = this.db.getValues(this.slot(key), {
|
|
9
|
+
transaction
|
|
10
|
+
});
|
|
11
|
+
for (const value of values){
|
|
12
|
+
yield value?.[1];
|
|
13
|
+
}
|
|
14
|
+
} finally{
|
|
15
|
+
transaction.done();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
async *getValuesAsync(key) {
|
|
19
|
+
for (const value of this.getValues(key)){
|
|
20
|
+
yield value;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
async deleteValue(key, val) {
|
|
24
|
+
await this.db.remove(this.slot(key), [
|
|
25
|
+
key,
|
|
26
|
+
val
|
|
27
|
+
]);
|
|
28
|
+
}
|
|
29
|
+
}
|
package/dest/lmdb/store.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
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
|
-
import type { AztecAsyncMap,
|
|
5
|
+
import type { AztecAsyncMap, AztecMap } from '../interfaces/map.js';
|
|
6
|
+
import type { AztecAsyncMultiMap, AztecMultiMap } from '../interfaces/multi_map.js';
|
|
6
7
|
import type { AztecAsyncSet, AztecSet } from '../interfaces/set.js';
|
|
7
8
|
import type { AztecAsyncSingleton, AztecSingleton } from '../interfaces/singleton.js';
|
|
8
9
|
import type { AztecAsyncKVStore, AztecKVStore } from '../interfaces/store.js';
|
|
@@ -30,17 +31,12 @@ export declare class AztecLmdbStore implements AztecKVStore, AztecAsyncKVStore {
|
|
|
30
31
|
*/
|
|
31
32
|
static open(path?: string, mapSizeKb?: number, // defaults to 1 GB map size
|
|
32
33
|
ephemeral?: boolean, log?: import("@aztec/foundation/log").Logger): AztecLmdbStore;
|
|
33
|
-
/**
|
|
34
|
-
* Forks the current DB into a new DB by backing it up to a temporary location and opening a new lmdb db.
|
|
35
|
-
* @returns A new AztecLmdbStore.
|
|
36
|
-
*/
|
|
37
|
-
fork(): Promise<AztecLmdbStore>;
|
|
38
34
|
/**
|
|
39
35
|
* Creates a new AztecMap in the store.
|
|
40
36
|
* @param name - Name of the map
|
|
41
37
|
* @returns A new AztecMap
|
|
42
38
|
*/
|
|
43
|
-
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>;
|
|
44
40
|
/**
|
|
45
41
|
* Creates a new AztecSet in the store.
|
|
46
42
|
* @param name - Name of the set
|
|
@@ -52,26 +48,14 @@ export declare class AztecLmdbStore implements AztecKVStore, AztecAsyncKVStore {
|
|
|
52
48
|
* @param name - Name of the map
|
|
53
49
|
* @returns A new AztecMultiMap
|
|
54
50
|
*/
|
|
55
|
-
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>;
|
|
56
52
|
openCounter<K extends Key>(name: string): AztecCounter<K> & AztecAsyncCounter<K>;
|
|
57
|
-
/**
|
|
58
|
-
* Creates a new AztecMultiMapWithSize in the store. A multi-map with size stores multiple values for a single key automatically.
|
|
59
|
-
* @param name - Name of the map
|
|
60
|
-
* @returns A new AztecMultiMapWithSize
|
|
61
|
-
*/
|
|
62
|
-
openMultiMapWithSize<K extends Key, V>(name: string): AztecMultiMapWithSize<K, V>;
|
|
63
|
-
/**
|
|
64
|
-
* Creates a new AztecMapWithSize in the store.
|
|
65
|
-
* @param name - Name of the map
|
|
66
|
-
* @returns A new AztecMapWithSize
|
|
67
|
-
*/
|
|
68
|
-
openMapWithSize<K extends Key, V>(name: string): AztecMapWithSize<K, V>;
|
|
69
53
|
/**
|
|
70
54
|
* Creates a new AztecArray in the store.
|
|
71
55
|
* @param name - Name of the array
|
|
72
56
|
* @returns A new AztecArray
|
|
73
57
|
*/
|
|
74
|
-
openArray<T>(name: string): AztecArray<T> & AztecAsyncArray<T>;
|
|
58
|
+
openArray<T extends Value>(name: string): AztecArray<T> & AztecAsyncArray<T>;
|
|
75
59
|
/**
|
|
76
60
|
* Creates a new AztecSingleton in the store.
|
|
77
61
|
* @param name - Name of the singleton
|
|
@@ -106,5 +90,6 @@ export declare class AztecLmdbStore implements AztecKVStore, AztecAsyncKVStore {
|
|
|
106
90
|
delete(): Promise<void>;
|
|
107
91
|
estimateSize(): Promise<StoreSize>;
|
|
108
92
|
private estimateSubDBSize;
|
|
93
|
+
backupTo(_dstPath: string, _compact?: boolean): Promise<void>;
|
|
109
94
|
}
|
|
110
95
|
//# sourceMappingURL=store.d.ts.map
|
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":"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"}
|
package/dest/lmdb/store.js
CHANGED
|
@@ -6,7 +6,8 @@ import { tmpdir } from 'os';
|
|
|
6
6
|
import { join } from 'path';
|
|
7
7
|
import { LmdbAztecArray } from './array.js';
|
|
8
8
|
import { LmdbAztecCounter } from './counter.js';
|
|
9
|
-
import { LmdbAztecMap
|
|
9
|
+
import { LmdbAztecMap } from './map.js';
|
|
10
|
+
import { LmdbAztecMultiMap } from './multi_map.js';
|
|
10
11
|
import { LmdbAztecSet } from './set.js';
|
|
11
12
|
import { LmdbAztecSingleton } from './singleton.js';
|
|
12
13
|
/**
|
|
@@ -63,21 +64,6 @@ import { LmdbAztecSingleton } from './singleton.js';
|
|
|
63
64
|
return new AztecLmdbStore(rootDb, ephemeral, dbPath);
|
|
64
65
|
}
|
|
65
66
|
/**
|
|
66
|
-
* Forks the current DB into a new DB by backing it up to a temporary location and opening a new lmdb db.
|
|
67
|
-
* @returns A new AztecLmdbStore.
|
|
68
|
-
*/ async fork() {
|
|
69
|
-
const baseDir = this.path;
|
|
70
|
-
this.#log.debug(`Forking store with basedir ${baseDir}`);
|
|
71
|
-
const forkPath = await fs.mkdtemp(join(baseDir, 'aztec-store-fork-'));
|
|
72
|
-
this.#log.verbose(`Forking store to ${forkPath}`);
|
|
73
|
-
await this.#rootDb.backup(forkPath, false);
|
|
74
|
-
const forkDb = open(forkPath, {
|
|
75
|
-
noSync: this.isEphemeral
|
|
76
|
-
});
|
|
77
|
-
this.#log.debug(`Forked store at ${forkPath} opened successfully`);
|
|
78
|
-
return new AztecLmdbStore(forkDb, this.isEphemeral, forkPath);
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
67
|
* Creates a new AztecMap in the store.
|
|
82
68
|
* @param name - Name of the map
|
|
83
69
|
* @returns A new AztecMap
|
|
@@ -96,26 +82,12 @@ import { LmdbAztecSingleton } from './singleton.js';
|
|
|
96
82
|
* @param name - Name of the map
|
|
97
83
|
* @returns A new AztecMultiMap
|
|
98
84
|
*/ openMultiMap(name) {
|
|
99
|
-
return new
|
|
85
|
+
return new LmdbAztecMultiMap(this.#multiMapData, name);
|
|
100
86
|
}
|
|
101
87
|
openCounter(name) {
|
|
102
88
|
return new LmdbAztecCounter(this.#data, name);
|
|
103
89
|
}
|
|
104
90
|
/**
|
|
105
|
-
* Creates a new AztecMultiMapWithSize in the store. A multi-map with size stores multiple values for a single key automatically.
|
|
106
|
-
* @param name - Name of the map
|
|
107
|
-
* @returns A new AztecMultiMapWithSize
|
|
108
|
-
*/ openMultiMapWithSize(name) {
|
|
109
|
-
return new LmdbAztecMapWithSize(this.#multiMapData, name);
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Creates a new AztecMapWithSize in the store.
|
|
113
|
-
* @param name - Name of the map
|
|
114
|
-
* @returns A new AztecMapWithSize
|
|
115
|
-
*/ openMapWithSize(name) {
|
|
116
|
-
return new LmdbAztecMapWithSize(this.#data, name);
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
91
|
* Creates a new AztecArray in the store.
|
|
120
92
|
* @param name - Name of the array
|
|
121
93
|
* @returns A new AztecArray
|
|
@@ -184,10 +156,15 @@ import { LmdbAztecSingleton } from './singleton.js';
|
|
|
184
156
|
if ('mapSize' in stats && typeof stats.mapSize === 'number') {
|
|
185
157
|
mapSize = stats.mapSize;
|
|
186
158
|
}
|
|
159
|
+
let physicalFileSize = 0;
|
|
160
|
+
if ('physicalFileSize' in stats && typeof stats.physicalFileSize === 'number') {
|
|
161
|
+
physicalFileSize = stats.physicalFileSize;
|
|
162
|
+
}
|
|
187
163
|
const dataResult = this.estimateSubDBSize(this.#data);
|
|
188
164
|
const multiResult = this.estimateSubDBSize(this.#multiMapData);
|
|
189
165
|
return Promise.resolve({
|
|
190
166
|
mappingSize: mapSize,
|
|
167
|
+
physicalFileSize: physicalFileSize,
|
|
191
168
|
actualSize: dataResult.actualSize + multiResult.actualSize,
|
|
192
169
|
numItems: dataResult.numItems + multiResult.numItems
|
|
193
170
|
});
|
|
@@ -213,4 +190,7 @@ import { LmdbAztecSingleton } from './singleton.js';
|
|
|
213
190
|
numItems
|
|
214
191
|
};
|
|
215
192
|
}
|
|
193
|
+
backupTo(_dstPath, _compact) {
|
|
194
|
+
throw new Error('Method not implemented.');
|
|
195
|
+
}
|
|
216
196
|
}
|
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;IAMjE,OAAO,CAAC,KAAK;IALf,OAAO,CAAC,MAAM,CAA8B;IAC5C,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,MAAM,CAAS;gBAGb,KAAK,EAAE,gBAAgB,EAC/B,IAAI,EAAE,MAAM;IAMd,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/array.js
CHANGED
|
@@ -7,6 +7,6 @@ export declare function openTmpStore(name: string, ephemeral?: boolean, dbMapSiz
|
|
|
7
7
|
maxReaders?: number, log?: Logger): Promise<AztecLMDBStoreV2>;
|
|
8
8
|
export declare function openStoreAt(dataDir: string, dbMapSizeKb?: number, // 10GB
|
|
9
9
|
maxReaders?: number, log?: Logger): Promise<AztecLMDBStoreV2>;
|
|
10
|
-
export declare function openVersionedStoreAt(
|
|
10
|
+
export declare function openVersionedStoreAt(dataDirectory: string, schemaVersion: number, rollupAddress: EthAddress, dbMapSizeKb?: number, // 10GB
|
|
11
11
|
maxReaders?: number, log?: Logger): Promise<AztecLMDBStoreV2>;
|
|
12
12
|
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/lmdb-v2/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAOlE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAI9C,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,eAAe,EACvB,GAAG,GAAE,MAAiD,GACrD,OAAO,CAAC,gBAAgB,CAAC,
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/lmdb-v2/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAOlE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAI9C,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,eAAe,EACvB,GAAG,GAAE,MAAiD,GACrD,OAAO,CAAC,gBAAgB,CAAC,CA6B3B;AAED,wBAAsB,YAAY,CAChC,IAAI,EAAE,MAAM,EACZ,SAAS,GAAE,OAAc,EACzB,WAAW,SAAqB,EAAE,OAAO;AACzC,UAAU,SAAc,EACxB,GAAG,GAAE,MAAiD,GACrD,OAAO,CAAC,gBAAgB,CAAC,CAqB3B;AAED,wBAAsB,WAAW,CAC/B,OAAO,EAAE,MAAM,EACf,WAAW,SAAqB,EAAE,OAAO;AACzC,UAAU,SAAc,EACxB,GAAG,GAAE,MAAyC,GAC7C,OAAO,CAAC,gBAAgB,CAAC,CAG3B;AAED,wBAAsB,oBAAoB,CACxC,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,UAAU,EACzB,WAAW,SAAqB,EAAE,OAAO;AACzC,UAAU,SAAc,EACxB,GAAG,GAAE,MAAyC,GAC7C,OAAO,CAAC,gBAAgB,CAAC,CAS3B"}
|
package/dest/lmdb-v2/factory.js
CHANGED
|
@@ -17,11 +17,16 @@ export async function createStore(name, schemaVersion, config, log = createLogge
|
|
|
17
17
|
});
|
|
18
18
|
const rollupAddress = l1Contracts ? l1Contracts.rollupAddress : EthAddress.ZERO;
|
|
19
19
|
// Create a version manager
|
|
20
|
-
const versionManager = new DatabaseVersionManager(
|
|
21
|
-
|
|
20
|
+
const versionManager = new DatabaseVersionManager({
|
|
21
|
+
schemaVersion,
|
|
22
|
+
rollupAddress,
|
|
23
|
+
dataDirectory: subDir,
|
|
24
|
+
onOpen: (dbDirectory)=>AztecLMDBStoreV2.new(dbDirectory, config.dataStoreMapSizeKb, MAX_READERS, ()=>Promise.resolve(), log)
|
|
25
|
+
});
|
|
26
|
+
log.info(`Creating ${name} data store at directory ${subDir} with map size ${config.dataStoreMapSizeKb} KB (LMDB v2)`);
|
|
22
27
|
[store] = await versionManager.open();
|
|
23
28
|
} else {
|
|
24
|
-
store = await openTmpStore(name, true, config.
|
|
29
|
+
store = await openTmpStore(name, true, config.dataStoreMapSizeKb, MAX_READERS, log);
|
|
25
30
|
}
|
|
26
31
|
return store;
|
|
27
32
|
}
|
|
@@ -53,8 +58,13 @@ export async function openStoreAt(dataDir, dbMapSizeKb = 10 * 1_024 * 1_024, max
|
|
|
53
58
|
log.debug(`Opening data store at: ${dataDir} with size: ${dbMapSizeKb} KB (LMDB v2)`);
|
|
54
59
|
return await AztecLMDBStoreV2.new(dataDir, dbMapSizeKb, maxReaders, undefined, log);
|
|
55
60
|
}
|
|
56
|
-
export async function openVersionedStoreAt(
|
|
57
|
-
log.debug(`Opening data store at: ${
|
|
58
|
-
const [store] = await new DatabaseVersionManager(
|
|
61
|
+
export async function openVersionedStoreAt(dataDirectory, schemaVersion, rollupAddress, dbMapSizeKb = 10 * 1_024 * 1_024, maxReaders = MAX_READERS, log = createLogger('kv-store:lmdb-v2')) {
|
|
62
|
+
log.debug(`Opening data store at: ${dataDirectory} with size: ${dbMapSizeKb} KB (LMDB v2)`);
|
|
63
|
+
const [store] = await new DatabaseVersionManager({
|
|
64
|
+
schemaVersion,
|
|
65
|
+
rollupAddress,
|
|
66
|
+
dataDirectory,
|
|
67
|
+
onOpen: (dataDir)=>AztecLMDBStoreV2.new(dataDir, dbMapSizeKb, maxReaders, undefined, log)
|
|
68
|
+
}).open();
|
|
59
69
|
return store;
|
|
60
70
|
}
|
package/dest/lmdb-v2/map.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Key, Range } from '../interfaces/common.js';
|
|
2
|
-
import type { AztecAsyncMap
|
|
1
|
+
import type { Key, Range, Value } from '../interfaces/common.js';
|
|
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;
|
|
@@ -13,45 +13,13 @@ export declare class LMDBMap<K extends Key, V> implements AztecAsyncMap<K, V> {
|
|
|
13
13
|
*/
|
|
14
14
|
set(key: K, val: V): Promise<void>;
|
|
15
15
|
/**
|
|
16
|
-
* Sets the
|
|
17
|
-
* @param
|
|
18
|
-
* @param val - The value to set
|
|
19
|
-
*/
|
|
20
|
-
setIfNotExists(key: K, val: V): Promise<boolean>;
|
|
21
|
-
/**
|
|
22
|
-
* Deletes the value at the given key.
|
|
23
|
-
* @param key - The key to delete the value at
|
|
16
|
+
* Sets the values at the given keys.
|
|
17
|
+
* @param entries - The entries to set
|
|
24
18
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
* Iterates over the map's key-value entries in the key's natural order
|
|
30
|
-
* @param range - The range of keys to iterate over
|
|
31
|
-
*/
|
|
32
|
-
entriesAsync(range?: Range<K>): AsyncIterableIterator<[K, V]>;
|
|
33
|
-
/**
|
|
34
|
-
* Iterates over the map's values in the key's natural order
|
|
35
|
-
* @param range - The range of keys to iterate over
|
|
36
|
-
*/
|
|
37
|
-
valuesAsync(range?: Range<K>): AsyncIterableIterator<V>;
|
|
38
|
-
/**
|
|
39
|
-
* Iterates over the map's keys in the key's natural order
|
|
40
|
-
* @param range - The range of keys to iterate over
|
|
41
|
-
*/
|
|
42
|
-
keysAsync(range?: Range<K>): AsyncIterableIterator<K>;
|
|
43
|
-
}
|
|
44
|
-
export declare class LMDBMultiMap<K extends Key, V> implements AztecAsyncMultiMap<K, V> {
|
|
45
|
-
private store;
|
|
46
|
-
private prefix;
|
|
47
|
-
private encoder;
|
|
48
|
-
constructor(store: AztecLMDBStoreV2, name: string);
|
|
49
|
-
/**
|
|
50
|
-
* Sets the value at the given key.
|
|
51
|
-
* @param key - The key to set the value at
|
|
52
|
-
* @param val - The value to set
|
|
53
|
-
*/
|
|
54
|
-
set(key: K, val: V): Promise<void>;
|
|
19
|
+
setMany(entries: {
|
|
20
|
+
key: K;
|
|
21
|
+
value: V;
|
|
22
|
+
}[]): Promise<void>;
|
|
55
23
|
/**
|
|
56
24
|
* Sets the value at the given key if it does not already exist.
|
|
57
25
|
* @param key - The key to set the value at
|
|
@@ -65,6 +33,7 @@ export declare class LMDBMultiMap<K extends Key, V> implements AztecAsyncMultiMa
|
|
|
65
33
|
delete(key: K): Promise<void>;
|
|
66
34
|
getAsync(key: K): Promise<V | undefined>;
|
|
67
35
|
hasAsync(key: K): Promise<boolean>;
|
|
36
|
+
sizeAsync(): Promise<number>;
|
|
68
37
|
/**
|
|
69
38
|
* Iterates over the map's key-value entries in the key's natural order
|
|
70
39
|
* @param range - The range of keys to iterate over
|
|
@@ -80,7 +49,5 @@ export declare class LMDBMultiMap<K extends Key, V> implements AztecAsyncMultiMa
|
|
|
80
49
|
* @param range - The range of keys to iterate over
|
|
81
50
|
*/
|
|
82
51
|
keysAsync(range?: Range<K>): AsyncIterableIterator<K>;
|
|
83
|
-
deleteValue(key: K, val: V | undefined): Promise<void>;
|
|
84
|
-
getValuesAsync(key: K): AsyncIterableIterator<V>;
|
|
85
52
|
}
|
|
86
53
|
//# sourceMappingURL=map.d.ts.map
|
|
@@ -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.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,EAAE,KAAK,gBAAgB,EAA+B,MAAM,YAAY,CAAC;AAGhF,qBAAa,OAAO,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC,SAAS,KAAK,CAAE,YAAW,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC;IAK/E,OAAO,CAAC,KAAK;IAJf,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAiB;gBAGtB,KAAK,EAAE,gBAAgB,EAC/B,IAAI,EAAE,MAAM;IAId;;;;OAIG;IACH,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlC;;;OAGG;IACG,OAAO,CAAC,OAAO,EAAE;QAAE,GAAG,EAAE,CAAC,CAAC;QAAC,KAAK,EAAE,CAAC,CAAA;KAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ7D;;;;OAIG;IACH,cAAc,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAYhD;;;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,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IAI5B;;;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;CAK7D"}
|
package/dest/lmdb-v2/map.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Encoder } from 'msgpackr';
|
|
2
|
+
// eslint-disable-next-line import/no-cycle
|
|
2
3
|
import { execInReadTx, execInWriteTx } from './store.js';
|
|
3
4
|
import { deserializeKey, maxKey, minKey, serializeKey } from './utils.js';
|
|
4
5
|
export class LMDBMap {
|
|
@@ -18,6 +19,16 @@ export class LMDBMap {
|
|
|
18
19
|
return execInWriteTx(this.store, (tx)=>tx.set(serializeKey(this.prefix, key), this.encoder.pack(val)));
|
|
19
20
|
}
|
|
20
21
|
/**
|
|
22
|
+
* Sets the values at the given keys.
|
|
23
|
+
* @param entries - The entries to set
|
|
24
|
+
*/ async setMany(entries) {
|
|
25
|
+
await execInWriteTx(this.store, async (tx)=>{
|
|
26
|
+
for (const { key, value } of entries){
|
|
27
|
+
await tx.set(serializeKey(this.prefix, key), this.encoder.pack(value));
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
21
32
|
* Sets the value at the given key if it does not already exist.
|
|
22
33
|
* @param key - The key to set the value at
|
|
23
34
|
* @param val - The value to set
|
|
@@ -47,20 +58,23 @@ export class LMDBMap {
|
|
|
47
58
|
hasAsync(key) {
|
|
48
59
|
return execInReadTx(this.store, async (tx)=>!!await tx.get(serializeKey(this.prefix, key)));
|
|
49
60
|
}
|
|
61
|
+
sizeAsync() {
|
|
62
|
+
return execInReadTx(this.store, (tx)=>tx.countEntries(minKey(this.prefix), maxKey(this.prefix), false));
|
|
63
|
+
}
|
|
50
64
|
/**
|
|
51
65
|
* Iterates over the map's key-value entries in the key's natural order
|
|
52
66
|
* @param range - The range of keys to iterate over
|
|
53
67
|
*/ async *entriesAsync(range) {
|
|
54
68
|
const reverse = range?.reverse ?? false;
|
|
55
|
-
const startKey = range?.start ? serializeKey(this.prefix, range.start) : minKey(this.prefix);
|
|
56
|
-
const endKey = range?.end ? serializeKey(this.prefix, range.end) : reverse ? maxKey(this.prefix) : undefined;
|
|
69
|
+
const startKey = range?.start !== undefined ? serializeKey(this.prefix, range.start) : minKey(this.prefix);
|
|
70
|
+
const endKey = range?.end !== undefined ? serializeKey(this.prefix, range.end) : reverse ? maxKey(this.prefix) : undefined;
|
|
57
71
|
let tx = this.store.getCurrentWriteTx();
|
|
58
72
|
const shouldClose = !tx;
|
|
59
73
|
tx ??= this.store.getReadTx();
|
|
60
74
|
try {
|
|
61
75
|
for await (const [key, val] of tx.iterate(reverse ? endKey : startKey, reverse ? startKey : endKey, reverse, range?.limit)){
|
|
62
76
|
const deserializedKey = deserializeKey(this.prefix, key);
|
|
63
|
-
if (
|
|
77
|
+
if (deserializedKey === false) {
|
|
64
78
|
break;
|
|
65
79
|
}
|
|
66
80
|
yield [
|
|
@@ -91,103 +105,3 @@ export class LMDBMap {
|
|
|
91
105
|
}
|
|
92
106
|
}
|
|
93
107
|
}
|
|
94
|
-
export class LMDBMultiMap {
|
|
95
|
-
store;
|
|
96
|
-
prefix;
|
|
97
|
-
encoder;
|
|
98
|
-
constructor(store, name){
|
|
99
|
-
this.store = store;
|
|
100
|
-
this.encoder = new Encoder();
|
|
101
|
-
this.prefix = `multimap:${name}`;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Sets the value at the given key.
|
|
105
|
-
* @param key - The key to set the value at
|
|
106
|
-
* @param val - The value to set
|
|
107
|
-
*/ set(key, val) {
|
|
108
|
-
return execInWriteTx(this.store, (tx)=>tx.setIndex(serializeKey(this.prefix, key), this.encoder.pack(val)));
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Sets the value at the given key if it does not already exist.
|
|
112
|
-
* @param key - The key to set the value at
|
|
113
|
-
* @param val - The value to set
|
|
114
|
-
*/ setIfNotExists(key, val) {
|
|
115
|
-
return execInWriteTx(this.store, async (tx)=>{
|
|
116
|
-
const exists = !!await this.getAsync(key);
|
|
117
|
-
if (!exists) {
|
|
118
|
-
await tx.setIndex(serializeKey(this.prefix, key), this.encoder.pack(val));
|
|
119
|
-
return true;
|
|
120
|
-
}
|
|
121
|
-
return false;
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Deletes the value at the given key.
|
|
126
|
-
* @param key - The key to delete the value at
|
|
127
|
-
*/ delete(key) {
|
|
128
|
-
return execInWriteTx(this.store, (tx)=>tx.removeIndex(serializeKey(this.prefix, key)));
|
|
129
|
-
}
|
|
130
|
-
getAsync(key) {
|
|
131
|
-
return execInReadTx(this.store, async (tx)=>{
|
|
132
|
-
const val = await tx.getIndex(serializeKey(this.prefix, key));
|
|
133
|
-
return val.length > 0 ? this.encoder.unpack(val[0]) : undefined;
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
hasAsync(key) {
|
|
137
|
-
return execInReadTx(this.store, async (tx)=>(await tx.getIndex(serializeKey(this.prefix, key))).length > 0);
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Iterates over the map's key-value entries in the key's natural order
|
|
141
|
-
* @param range - The range of keys to iterate over
|
|
142
|
-
*/ async *entriesAsync(range) {
|
|
143
|
-
const reverse = range?.reverse ?? false;
|
|
144
|
-
const startKey = range?.start ? serializeKey(this.prefix, range.start) : minKey(this.prefix);
|
|
145
|
-
const endKey = range?.end ? serializeKey(this.prefix, range.end) : reverse ? maxKey(this.prefix) : undefined;
|
|
146
|
-
let tx = this.store.getCurrentWriteTx();
|
|
147
|
-
const shouldClose = !tx;
|
|
148
|
-
tx ??= this.store.getReadTx();
|
|
149
|
-
try {
|
|
150
|
-
for await (const [key, vals] of tx.iterateIndex(reverse ? endKey : startKey, reverse ? startKey : endKey, reverse, range?.limit)){
|
|
151
|
-
const deserializedKey = deserializeKey(this.prefix, key);
|
|
152
|
-
if (!deserializedKey) {
|
|
153
|
-
break;
|
|
154
|
-
}
|
|
155
|
-
for (const val of vals){
|
|
156
|
-
yield [
|
|
157
|
-
deserializedKey,
|
|
158
|
-
this.encoder.unpack(val)
|
|
159
|
-
];
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
} finally{
|
|
163
|
-
if (shouldClose) {
|
|
164
|
-
tx.close();
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Iterates over the map's values in the key's natural order
|
|
170
|
-
* @param range - The range of keys to iterate over
|
|
171
|
-
*/ async *valuesAsync(range) {
|
|
172
|
-
for await (const [_, value] of this.entriesAsync(range)){
|
|
173
|
-
yield value;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Iterates over the map's keys in the key's natural order
|
|
178
|
-
* @param range - The range of keys to iterate over
|
|
179
|
-
*/ async *keysAsync(range) {
|
|
180
|
-
for await (const [key, _] of this.entriesAsync(range)){
|
|
181
|
-
yield key;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
deleteValue(key, val) {
|
|
185
|
-
return execInWriteTx(this.store, (tx)=>tx.removeIndex(serializeKey(this.prefix, key), this.encoder.pack(val)));
|
|
186
|
-
}
|
|
187
|
-
async *getValuesAsync(key) {
|
|
188
|
-
const values = await execInReadTx(this.store, (tx)=>tx.getIndex(serializeKey(this.prefix, key)));
|
|
189
|
-
for (const value of values){
|
|
190
|
-
yield this.encoder.unpack(value);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|