@aztec/kv-store 0.0.0-test.1 → 0.0.1-commit.017a351
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/README.md +8 -1
- package/dest/bench/shared_map_bench.d.ts +19 -0
- package/dest/bench/shared_map_bench.d.ts.map +1 -0
- package/dest/bench/shared_map_bench.js +91 -0
- package/dest/indexeddb/array.d.ts +3 -2
- package/dest/indexeddb/array.d.ts.map +1 -1
- package/dest/indexeddb/array.js +24 -7
- package/dest/indexeddb/index.d.ts +3 -3
- package/dest/indexeddb/index.d.ts.map +1 -1
- package/dest/indexeddb/index.js +4 -7
- package/dest/indexeddb/map.d.ts +18 -6
- package/dest/indexeddb/map.d.ts.map +1 -1
- package/dest/indexeddb/map.js +51 -63
- package/dest/indexeddb/multi_map.d.ts +14 -0
- package/dest/indexeddb/multi_map.d.ts.map +1 -0
- package/dest/indexeddb/multi_map.js +107 -0
- package/dest/indexeddb/set.d.ts +1 -1
- package/dest/indexeddb/set.d.ts.map +1 -1
- package/dest/indexeddb/singleton.d.ts +3 -2
- package/dest/indexeddb/singleton.d.ts.map +1 -1
- package/dest/indexeddb/singleton.js +6 -2
- package/dest/indexeddb/store.d.ts +15 -16
- package/dest/indexeddb/store.d.ts.map +1 -1
- package/dest/indexeddb/store.js +51 -46
- package/dest/interfaces/array.d.ts +5 -4
- package/dest/interfaces/array.d.ts.map +1 -1
- package/dest/interfaces/array.js +1 -3
- package/dest/interfaces/array_test_suite.d.ts +1 -1
- package/dest/interfaces/array_test_suite.d.ts.map +1 -1
- package/dest/interfaces/array_test_suite.js +33 -34
- package/dest/interfaces/common.d.ts +11 -9
- package/dest/interfaces/common.d.ts.map +1 -1
- package/dest/interfaces/common.js +8 -3
- package/dest/interfaces/counter.d.ts +1 -1
- package/dest/interfaces/index.d.ts +4 -2
- package/dest/interfaces/index.d.ts.map +1 -1
- package/dest/interfaces/index.js +2 -0
- package/dest/interfaces/map.d.ts +21 -49
- package/dest/interfaces/map.d.ts.map +1 -1
- package/dest/interfaces/map.js +1 -1
- package/dest/interfaces/map_test_suite.d.ts +1 -1
- package/dest/interfaces/map_test_suite.d.ts.map +1 -1
- package/dest/interfaces/map_test_suite.js +193 -83
- package/dest/interfaces/multi_map.d.ts +41 -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 +363 -0
- package/dest/interfaces/set.d.ts +1 -1
- package/dest/interfaces/set_test_suite.d.ts +1 -1
- package/dest/interfaces/set_test_suite.d.ts.map +1 -1
- package/dest/interfaces/set_test_suite.js +13 -14
- package/dest/interfaces/singleton.d.ts +1 -1
- package/dest/interfaces/singleton_test_suite.d.ts +1 -1
- package/dest/interfaces/singleton_test_suite.d.ts.map +1 -1
- package/dest/interfaces/singleton_test_suite.js +6 -7
- package/dest/interfaces/store.d.ts +18 -43
- package/dest/interfaces/store.d.ts.map +1 -1
- package/dest/interfaces/utils.d.ts +3 -1
- package/dest/interfaces/utils.d.ts.map +1 -1
- package/dest/interfaces/utils.js +3 -1
- package/dest/lmdb/array.d.ts +3 -2
- package/dest/lmdb/array.d.ts.map +1 -1
- package/dest/lmdb/array.js +4 -2
- package/dest/lmdb/counter.d.ts +1 -1
- package/dest/lmdb/counter.d.ts.map +1 -1
- package/dest/lmdb/index.d.ts +3 -3
- package/dest/lmdb/index.d.ts.map +1 -1
- package/dest/lmdb/index.js +6 -6
- package/dest/lmdb/map.d.ts +11 -23
- package/dest/lmdb/map.d.ts.map +1 -1
- package/dest/lmdb/map.js +15 -81
- package/dest/lmdb/multi_map.d.ts +13 -0
- package/dest/lmdb/multi_map.d.ts.map +1 -0
- package/dest/lmdb/multi_map.js +44 -0
- package/dest/lmdb/set.d.ts +1 -1
- package/dest/lmdb/set.d.ts.map +1 -1
- package/dest/lmdb/singleton.d.ts +1 -1
- package/dest/lmdb/singleton.d.ts.map +1 -1
- package/dest/lmdb/store.d.ts +11 -27
- package/dest/lmdb/store.d.ts.map +1 -1
- package/dest/lmdb/store.js +24 -40
- package/dest/lmdb-v2/array.d.ts +4 -3
- package/dest/lmdb-v2/array.d.ts.map +1 -1
- package/dest/lmdb-v2/array.js +4 -2
- package/dest/lmdb-v2/factory.d.ts +32 -10
- package/dest/lmdb-v2/factory.d.ts.map +1 -1
- package/dest/lmdb-v2/factory.js +83 -18
- package/dest/lmdb-v2/index.d.ts +1 -1
- package/dest/lmdb-v2/map.d.ts +12 -45
- package/dest/lmdb-v2/map.d.ts.map +1 -1
- package/dest/lmdb-v2/map.js +17 -104
- package/dest/lmdb-v2/message.d.ts +24 -5
- 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 +52 -0
- package/dest/lmdb-v2/multi_map.d.ts.map +1 -0
- package/dest/lmdb-v2/multi_map.js +123 -0
- package/dest/lmdb-v2/read_transaction.d.ts +3 -1
- package/dest/lmdb-v2/read_transaction.d.ts.map +1 -1
- package/dest/lmdb-v2/read_transaction.js +47 -11
- 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 +2 -2
- package/dest/lmdb-v2/singleton.d.ts.map +1 -1
- package/dest/lmdb-v2/singleton.js +1 -1
- package/dest/lmdb-v2/store.d.ts +13 -13
- package/dest/lmdb-v2/store.d.ts.map +1 -1
- package/dest/lmdb-v2/store.js +22 -32
- package/dest/lmdb-v2/tx-helpers.d.ts +6 -0
- package/dest/lmdb-v2/tx-helpers.d.ts.map +1 -0
- package/dest/lmdb-v2/tx-helpers.js +21 -0
- package/dest/lmdb-v2/utils.d.ts +3 -14
- package/dest/lmdb-v2/utils.d.ts.map +1 -1
- package/dest/lmdb-v2/utils.js +0 -94
- package/dest/lmdb-v2/write_transaction.d.ts +3 -5
- package/dest/lmdb-v2/write_transaction.d.ts.map +1 -1
- package/dest/lmdb-v2/write_transaction.js +9 -5
- package/dest/sqlite-opfs/array.d.ts +21 -0
- package/dest/sqlite-opfs/array.d.ts.map +1 -0
- package/dest/sqlite-opfs/array.js +128 -0
- package/dest/sqlite-opfs/errors.d.ts +27 -0
- package/dest/sqlite-opfs/errors.d.ts.map +1 -0
- package/dest/sqlite-opfs/errors.js +34 -0
- package/dest/sqlite-opfs/index.d.ts +16 -0
- package/dest/sqlite-opfs/index.d.ts.map +1 -0
- package/dest/sqlite-opfs/index.js +22 -0
- package/dest/sqlite-opfs/internal/ordered-binary-browser.d.ts +32 -0
- package/dest/sqlite-opfs/internal/ordered-binary-browser.d.ts.map +1 -0
- package/dest/sqlite-opfs/internal/ordered-binary-browser.js +448 -0
- package/dest/sqlite-opfs/map.d.ts +35 -0
- package/dest/sqlite-opfs/map.d.ts.map +1 -0
- package/dest/sqlite-opfs/map.js +163 -0
- package/dest/sqlite-opfs/messages.d.ts +66 -0
- package/dest/sqlite-opfs/messages.d.ts.map +1 -0
- package/dest/sqlite-opfs/messages.js +5 -0
- package/dest/sqlite-opfs/multi_map.d.ts +16 -0
- package/dest/sqlite-opfs/multi_map.d.ts.map +1 -0
- package/dest/sqlite-opfs/multi_map.js +67 -0
- package/dest/sqlite-opfs/set.d.ts +13 -0
- package/dest/sqlite-opfs/set.d.ts.map +1 -0
- package/dest/sqlite-opfs/set.js +19 -0
- package/dest/sqlite-opfs/singleton.d.ts +13 -0
- package/dest/sqlite-opfs/singleton.d.ts.map +1 -0
- package/dest/sqlite-opfs/singleton.js +48 -0
- package/dest/sqlite-opfs/store.d.ts +79 -0
- package/dest/sqlite-opfs/store.d.ts.map +1 -0
- package/dest/sqlite-opfs/store.js +281 -0
- package/dest/sqlite-opfs/worker.d.ts +2 -0
- package/dest/sqlite-opfs/worker.d.ts.map +1 -0
- package/dest/sqlite-opfs/worker.js +249 -0
- package/dest/stores/index.d.ts +2 -1
- package/dest/stores/index.d.ts.map +1 -1
- package/dest/stores/index.js +1 -0
- package/dest/stores/l2_tips_store.d.ts +25 -9
- package/dest/stores/l2_tips_store.d.ts.map +1 -1
- package/dest/stores/l2_tips_store.js +64 -46
- package/dest/utils.d.ts +9 -6
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +51 -16
- package/package.json +44 -33
- package/src/bench/shared_map_bench.ts +111 -0
- package/src/indexeddb/array.ts +9 -5
- package/src/indexeddb/index.ts +11 -9
- package/src/indexeddb/map.ts +51 -56
- package/src/indexeddb/multi_map.ts +105 -0
- package/src/indexeddb/singleton.ts +5 -2
- package/src/indexeddb/store.ts +77 -60
- package/src/interfaces/array.ts +5 -3
- package/src/interfaces/array_test_suite.ts +33 -35
- 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 +113 -58
- package/src/interfaces/multi_map.ts +45 -0
- package/src/interfaces/multi_map_test_suite.ts +372 -0
- package/src/interfaces/set_test_suite.ts +13 -15
- package/src/interfaces/singleton_test_suite.ts +6 -8
- package/src/interfaces/store.ts +18 -53
- package/src/interfaces/utils.ts +2 -0
- package/src/lmdb/array.ts +2 -1
- package/src/lmdb/index.ts +13 -8
- package/src/lmdb/map.ts +23 -94
- package/src/lmdb/multi_map.ts +51 -0
- package/src/lmdb/store.ts +36 -56
- package/src/lmdb-v2/array.ts +8 -3
- package/src/lmdb-v2/factory.ts +107 -26
- package/src/lmdb-v2/map.ts +30 -127
- package/src/lmdb-v2/message.ts +23 -0
- package/src/lmdb-v2/multi_map.ts +150 -0
- package/src/lmdb-v2/read_transaction.ts +53 -13
- package/src/lmdb-v2/set.ts +33 -0
- package/src/lmdb-v2/singleton.ts +6 -2
- package/src/lmdb-v2/store.ts +28 -44
- package/src/lmdb-v2/tx-helpers.ts +29 -0
- package/src/lmdb-v2/utils.ts +0 -118
- package/src/lmdb-v2/write_transaction.ts +11 -10
- package/src/sqlite-opfs/array.ts +124 -0
- package/src/sqlite-opfs/errors.ts +44 -0
- package/src/sqlite-opfs/index.ts +39 -0
- package/src/sqlite-opfs/internal/ordered-binary-browser.js +465 -0
- package/src/sqlite-opfs/map.ts +163 -0
- package/src/sqlite-opfs/messages.ts +39 -0
- package/src/sqlite-opfs/multi_map.ts +74 -0
- package/src/sqlite-opfs/set.ts +29 -0
- package/src/sqlite-opfs/singleton.ts +48 -0
- package/src/sqlite-opfs/store.ts +296 -0
- package/src/sqlite-opfs/worker.ts +231 -0
- package/src/stores/index.ts +2 -0
- package/src/stores/l2_tips_store.ts +68 -49
- package/src/utils.ts +79 -21
- package/dest/config.d.ts +0 -17
- package/dest/config.d.ts.map +0 -1
- package/dest/config.js +0 -24
- 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/config.ts +0 -34
- package/src/interfaces/store_test_suite.ts +0 -56
package/dest/lmdb-v2/store.js
CHANGED
|
@@ -2,13 +2,16 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
2
2
|
import { Semaphore, SerialQueue } from '@aztec/foundation/queue';
|
|
3
3
|
import { MsgpackChannel, NativeLMDBStore } from '@aztec/native';
|
|
4
4
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
5
|
-
import { rm } from 'fs/promises';
|
|
5
|
+
import { mkdir, rm } from 'fs/promises';
|
|
6
6
|
import { LMDBArray } from './array.js';
|
|
7
|
-
import { LMDBMap
|
|
7
|
+
import { LMDBMap } from './map.js';
|
|
8
8
|
import { Database, LMDBMessageType } from './message.js';
|
|
9
|
+
import { LMDBMultiMap } from './multi_map.js';
|
|
9
10
|
import { ReadTransaction } from './read_transaction.js';
|
|
11
|
+
import { LMDBSet } from './set.js';
|
|
10
12
|
import { LMDBSingleValue } from './singleton.js';
|
|
11
13
|
import { WriteTransaction } from './write_transaction.js';
|
|
14
|
+
export { execInReadTx, execInWriteTx } from './tx-helpers.js';
|
|
12
15
|
export class AztecLMDBStoreV2 {
|
|
13
16
|
dataDir;
|
|
14
17
|
log;
|
|
@@ -18,7 +21,7 @@ export class AztecLMDBStoreV2 {
|
|
|
18
21
|
writerCtx;
|
|
19
22
|
writerQueue;
|
|
20
23
|
availableCursors;
|
|
21
|
-
constructor(dataDir, mapSize, maxReaders, log, cleanup){
|
|
24
|
+
constructor(dataDir, mapSize, maxReaders, log, cleanup, ephemeral = false){
|
|
22
25
|
this.dataDir = dataDir;
|
|
23
26
|
this.log = log;
|
|
24
27
|
this.cleanup = cleanup;
|
|
@@ -26,7 +29,7 @@ export class AztecLMDBStoreV2 {
|
|
|
26
29
|
this.writerCtx = new AsyncLocalStorage();
|
|
27
30
|
this.writerQueue = new SerialQueue();
|
|
28
31
|
this.log.info(`Starting data store with maxReaders ${maxReaders}`);
|
|
29
|
-
this.channel = new MsgpackChannel(new NativeLMDBStore(dataDir, mapSize, maxReaders));
|
|
32
|
+
this.channel = new MsgpackChannel(new NativeLMDBStore(dataDir, mapSize, maxReaders, ephemeral));
|
|
30
33
|
// leave one reader to always be available for regular, atomic, reads
|
|
31
34
|
this.availableCursors = new Semaphore(maxReaders - 1);
|
|
32
35
|
}
|
|
@@ -45,11 +48,21 @@ export class AztecLMDBStoreV2 {
|
|
|
45
48
|
});
|
|
46
49
|
this.open = true;
|
|
47
50
|
}
|
|
48
|
-
static async new(dataDir, dbMapSizeKb = 10 * 1024 * 1024, maxReaders = 16, cleanup,
|
|
49
|
-
const
|
|
51
|
+
static async new(dataDir, dbMapSizeKb = 10 * 1024 * 1024, maxReaders = 16, cleanup, bindings, ephemeral = false) {
|
|
52
|
+
const log = createLogger('kv-store:lmdb-v2', bindings);
|
|
53
|
+
const db = new AztecLMDBStoreV2(dataDir, dbMapSizeKb, maxReaders, log, cleanup, ephemeral);
|
|
50
54
|
await db.start();
|
|
51
55
|
return db;
|
|
52
56
|
}
|
|
57
|
+
async backupTo(dstPath, compact = true) {
|
|
58
|
+
await mkdir(dstPath, {
|
|
59
|
+
recursive: true
|
|
60
|
+
});
|
|
61
|
+
await this.channel.sendMessage(LMDBMessageType.COPY_STORE, {
|
|
62
|
+
dstPath,
|
|
63
|
+
compact
|
|
64
|
+
});
|
|
65
|
+
}
|
|
53
66
|
getReadTx() {
|
|
54
67
|
if (!this.open) {
|
|
55
68
|
throw new Error('Store is closed');
|
|
@@ -75,8 +88,8 @@ export class AztecLMDBStoreV2 {
|
|
|
75
88
|
openArray(name) {
|
|
76
89
|
return new LMDBArray(this, name);
|
|
77
90
|
}
|
|
78
|
-
openSet(
|
|
79
|
-
|
|
91
|
+
openSet(name) {
|
|
92
|
+
return new LMDBSet(this, name);
|
|
80
93
|
}
|
|
81
94
|
openCounter(_name) {
|
|
82
95
|
throw new Error('Not implemented');
|
|
@@ -109,9 +122,6 @@ export class AztecLMDBStoreV2 {
|
|
|
109
122
|
clear() {
|
|
110
123
|
return Promise.resolve();
|
|
111
124
|
}
|
|
112
|
-
fork() {
|
|
113
|
-
throw new Error('Not implemented');
|
|
114
|
-
}
|
|
115
125
|
async delete() {
|
|
116
126
|
await this.close();
|
|
117
127
|
await rm(this.dataDir, {
|
|
@@ -153,29 +163,9 @@ export class AztecLMDBStoreV2 {
|
|
|
153
163
|
const resp = await this.sendMessage(LMDBMessageType.STATS, undefined);
|
|
154
164
|
return {
|
|
155
165
|
mappingSize: Number(resp.dbMapSizeBytes),
|
|
166
|
+
physicalFileSize: Number(resp.dbPhysicalFileSizeBytes),
|
|
156
167
|
actualSize: resp.stats.reduce((s, db)=>Number(db.totalUsedSize) + s, 0),
|
|
157
168
|
numItems: resp.stats.reduce((s, db)=>Number(db.numDataItems) + s, 0)
|
|
158
169
|
};
|
|
159
170
|
}
|
|
160
171
|
}
|
|
161
|
-
export function execInWriteTx(store, fn) {
|
|
162
|
-
const currentWrite = store.getCurrentWriteTx();
|
|
163
|
-
if (currentWrite) {
|
|
164
|
-
return fn(currentWrite);
|
|
165
|
-
} else {
|
|
166
|
-
return store.transactionAsync(fn);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
export async function execInReadTx(store, fn) {
|
|
170
|
-
const currentWrite = store.getCurrentWriteTx();
|
|
171
|
-
if (currentWrite) {
|
|
172
|
-
return await fn(currentWrite);
|
|
173
|
-
} else {
|
|
174
|
-
const tx = store.getReadTx();
|
|
175
|
-
try {
|
|
176
|
-
return await fn(tx);
|
|
177
|
-
} finally{
|
|
178
|
-
tx.close();
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ReadTransaction } from './read_transaction.js';
|
|
2
|
+
import type { AztecLMDBStoreV2 } from './store.js';
|
|
3
|
+
import type { WriteTransaction } from './write_transaction.js';
|
|
4
|
+
export declare function execInWriteTx<T>(store: AztecLMDBStoreV2, fn: (tx: WriteTransaction) => Promise<T>): Promise<T>;
|
|
5
|
+
export declare function execInReadTx<T>(store: AztecLMDBStoreV2, fn: (tx: ReadTransaction) => T | Promise<T>): Promise<T>;
|
|
6
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHgtaGVscGVycy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2xtZGItdjIvdHgtaGVscGVycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxlQUFlLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUM3RCxPQUFPLEtBQUssRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLFlBQVksQ0FBQztBQUNuRCxPQUFPLEtBQUssRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBRS9ELHdCQUFnQixhQUFhLENBQUMsQ0FBQyxFQUFFLEtBQUssRUFBRSxnQkFBZ0IsRUFBRSxFQUFFLEVBQUUsQ0FBQyxFQUFFLEVBQUUsZ0JBQWdCLEtBQUssT0FBTyxDQUFDLENBQUMsQ0FBQyxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsQ0FPOUc7QUFFRCx3QkFBc0IsWUFBWSxDQUFDLENBQUMsRUFDbEMsS0FBSyxFQUFFLGdCQUFnQixFQUN2QixFQUFFLEVBQUUsQ0FBQyxFQUFFLEVBQUUsZUFBZSxLQUFLLENBQUMsR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFDLEdBQzFDLE9BQU8sQ0FBQyxDQUFDLENBQUMsQ0FZWiJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tx-helpers.d.ts","sourceRoot":"","sources":["../../src/lmdb-v2/tx-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,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"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function execInWriteTx(store, fn) {
|
|
2
|
+
const currentWrite = store.getCurrentWriteTx();
|
|
3
|
+
if (currentWrite) {
|
|
4
|
+
return fn(currentWrite);
|
|
5
|
+
} else {
|
|
6
|
+
return store.transactionAsync(fn);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export async function execInReadTx(store, fn) {
|
|
10
|
+
const currentWrite = store.getCurrentWriteTx();
|
|
11
|
+
if (currentWrite) {
|
|
12
|
+
return await fn(currentWrite);
|
|
13
|
+
} else {
|
|
14
|
+
const tx = store.getReadTx();
|
|
15
|
+
try {
|
|
16
|
+
return await fn(tx);
|
|
17
|
+
} finally{
|
|
18
|
+
tx.close();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
package/dest/lmdb-v2/utils.d.ts
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
1
|
import type { Key } from '../interfaces/common.js';
|
|
4
|
-
type Cmp<T> = (a: T, b: T) => -1 | 0 | 1;
|
|
5
|
-
export declare function dedupeSortedArray<T>(arr: T[], cmp: Cmp<T>): void;
|
|
6
|
-
export declare function insertIntoSortedArray<T>(arr: T[], item: T, cmp: (a: T, b: T) => number): void;
|
|
7
|
-
export declare function findIndexInSortedArray<T, N>(values: T[], needle: N, cmp: (a: T, b: N) => number): number;
|
|
8
|
-
export declare function findInSortedArray<T, N>(values: T[], needle: N, cmp: (a: T, b: N) => number): T | undefined;
|
|
9
|
-
export declare function removeAnyOf<T, N>(arr: T[], vals: N[], cmp: (a: T, b: N) => -1 | 0 | 1): void;
|
|
10
|
-
export declare function removeFromSortedArray<T, N>(arr: T[], val: N, cmp: (a: T, b: N) => -1 | 0 | 1): void;
|
|
11
|
-
export declare function merge<T>(arr: T[], toInsert: T[], cmp: (a: T, b: T) => -1 | 0 | 1): void;
|
|
12
2
|
export declare function keyCmp(a: [Uint8Array, Uint8Array[] | null], b: [Uint8Array, Uint8Array[] | null]): -1 | 0 | 1;
|
|
13
3
|
export declare function singleKeyCmp(a: [Uint8Array, Uint8Array[] | null], b: Uint8Array): -1 | 0 | 1;
|
|
14
|
-
export declare function minKey(prefix: string): Buffer
|
|
15
|
-
export declare function maxKey(prefix: string): Buffer
|
|
4
|
+
export declare function minKey(prefix: string): Buffer<ArrayBufferLike>;
|
|
5
|
+
export declare function maxKey(prefix: string): Buffer<ArrayBufferLike>;
|
|
16
6
|
export declare function serializeKey(prefix: string, key: Key): Buffer;
|
|
17
7
|
export declare function deserializeKey<K extends Key>(prefix: string, key: Uint8Array): K | false;
|
|
18
|
-
|
|
19
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
8
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9sbWRiLXYyL3V0aWxzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBLE9BQU8sS0FBSyxFQUFFLEdBQUcsRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBRW5ELHdCQUFnQixNQUFNLENBQUMsQ0FBQyxFQUFFLENBQUMsVUFBVSxFQUFFLFVBQVUsRUFBRSxHQUFHLElBQUksQ0FBQyxFQUFFLENBQUMsRUFBRSxDQUFDLFVBQVUsRUFBRSxVQUFVLEVBQUUsR0FBRyxJQUFJLENBQUMsR0FBRyxDQUFDLENBQUMsR0FBRyxDQUFDLEdBQUcsQ0FBQyxDQUU3RztBQUVELHdCQUFnQixZQUFZLENBQUMsQ0FBQyxFQUFFLENBQUMsVUFBVSxFQUFFLFVBQVUsRUFBRSxHQUFHLElBQUksQ0FBQyxFQUFFLENBQUMsRUFBRSxVQUFVLEdBQUcsQ0FBQyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsQ0FFNUY7QUFFRCx3QkFBZ0IsTUFBTSxDQUFDLE1BQU0sRUFBRSxNQUFNLDJCQUVwQztBQUVELHdCQUFnQixNQUFNLENBQUMsTUFBTSxFQUFFLE1BQU0sMkJBRXBDO0FBRUQsd0JBQWdCLFlBQVksQ0FBQyxNQUFNLEVBQUUsTUFBTSxFQUFFLEdBQUcsRUFBRSxHQUFHLEdBQUcsTUFBTSxDQUU3RDtBQUVELHdCQUFnQixjQUFjLENBQUMsQ0FBQyxTQUFTLEdBQUcsRUFBRSxNQUFNLEVBQUUsTUFBTSxFQUFFLEdBQUcsRUFBRSxVQUFVLEdBQUcsQ0FBQyxHQUFHLEtBQUssQ0FPeEYifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/lmdb-v2/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/lmdb-v2/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAC;AAEnD,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,UAAU,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAE7G;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,UAAU,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC,EAAE,UAAU,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAE5F;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,2BAEpC;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,2BAEpC;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,MAAM,CAE7D;AAED,wBAAgB,cAAc,CAAC,CAAC,SAAS,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,GAAG,CAAC,GAAG,KAAK,CAOxF"}
|
package/dest/lmdb-v2/utils.js
CHANGED
|
@@ -1,98 +1,4 @@
|
|
|
1
1
|
import { MAXIMUM_KEY, fromBufferKey, toBufferKey } from 'ordered-binary';
|
|
2
|
-
export function dedupeSortedArray(arr, cmp) {
|
|
3
|
-
for(let i = 0; i < arr.length; i++){
|
|
4
|
-
let j = i + 1;
|
|
5
|
-
for(; j < arr.length; j++){
|
|
6
|
-
const res = cmp(arr[i], arr[j]);
|
|
7
|
-
if (res === 0) {
|
|
8
|
-
continue;
|
|
9
|
-
} else if (res < 0) {
|
|
10
|
-
break;
|
|
11
|
-
} else {
|
|
12
|
-
throw new Error('Array not sorted');
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
if (j - i > 1) {
|
|
16
|
-
arr.splice(i + 1, j - i - 1);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export function insertIntoSortedArray(arr, item, cmp) {
|
|
21
|
-
let left = 0;
|
|
22
|
-
let right = arr.length;
|
|
23
|
-
while(left < right){
|
|
24
|
-
const mid = left + right >> 1;
|
|
25
|
-
const comparison = cmp(arr[mid], item);
|
|
26
|
-
if (comparison < 0) {
|
|
27
|
-
left = mid + 1;
|
|
28
|
-
} else {
|
|
29
|
-
right = mid;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
arr.splice(left, 0, item);
|
|
33
|
-
}
|
|
34
|
-
export function findIndexInSortedArray(values, needle, cmp) {
|
|
35
|
-
let start = 0;
|
|
36
|
-
let end = values.length - 1;
|
|
37
|
-
while(start <= end){
|
|
38
|
-
const mid = start + ((end - start) / 2 | 0);
|
|
39
|
-
const res = cmp(values[mid], needle);
|
|
40
|
-
if (res === 0) {
|
|
41
|
-
return mid;
|
|
42
|
-
} else if (res > 0) {
|
|
43
|
-
end = mid - 1;
|
|
44
|
-
} else {
|
|
45
|
-
start = mid + 1;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return -1;
|
|
49
|
-
}
|
|
50
|
-
export function findInSortedArray(values, needle, cmp) {
|
|
51
|
-
const idx = findIndexInSortedArray(values, needle, cmp);
|
|
52
|
-
return idx > -1 ? values[idx] : undefined;
|
|
53
|
-
}
|
|
54
|
-
export function removeAnyOf(arr, vals, cmp) {
|
|
55
|
-
let writeIdx = 0;
|
|
56
|
-
let readIdx = 0;
|
|
57
|
-
let valIdx = 0;
|
|
58
|
-
while(readIdx < arr.length && valIdx < vals.length){
|
|
59
|
-
const comparison = cmp(arr[readIdx], vals[valIdx]);
|
|
60
|
-
if (comparison < 0) {
|
|
61
|
-
arr[writeIdx++] = arr[readIdx++];
|
|
62
|
-
} else if (comparison > 0) {
|
|
63
|
-
valIdx++;
|
|
64
|
-
} else {
|
|
65
|
-
readIdx++;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
while(readIdx < arr.length){
|
|
69
|
-
arr[writeIdx++] = arr[readIdx++];
|
|
70
|
-
}
|
|
71
|
-
arr.length = writeIdx;
|
|
72
|
-
}
|
|
73
|
-
export function removeFromSortedArray(arr, val, cmp) {
|
|
74
|
-
const idx = findIndexInSortedArray(arr, val, cmp);
|
|
75
|
-
if (idx > -1) {
|
|
76
|
-
arr.splice(idx, 1);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
export function merge(arr, toInsert, cmp) {
|
|
80
|
-
const result = new Array(arr.length + toInsert.length);
|
|
81
|
-
let i = 0, j = 0, k = 0;
|
|
82
|
-
while(i < arr.length && j < toInsert.length){
|
|
83
|
-
result[k++] = cmp(arr[i], toInsert[j]) <= 0 ? arr[i++] : toInsert[j++];
|
|
84
|
-
}
|
|
85
|
-
while(i < arr.length){
|
|
86
|
-
result[k++] = arr[i++];
|
|
87
|
-
}
|
|
88
|
-
while(j < toInsert.length){
|
|
89
|
-
result[k++] = toInsert[j++];
|
|
90
|
-
}
|
|
91
|
-
for(i = 0; i < result.length; i++){
|
|
92
|
-
arr[i] = result[i];
|
|
93
|
-
}
|
|
94
|
-
arr.length = result.length;
|
|
95
|
-
}
|
|
96
2
|
export function keyCmp(a, b) {
|
|
97
3
|
return Buffer.compare(a[0], b[0]);
|
|
98
4
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
1
|
import { type Batch } from './message.js';
|
|
4
2
|
import { ReadTransaction } from './read_transaction.js';
|
|
5
3
|
export declare class WriteTransaction extends ReadTransaction {
|
|
@@ -12,8 +10,8 @@ export declare class WriteTransaction extends ReadTransaction {
|
|
|
12
10
|
setIndex(key: Buffer, ...values: Buffer[]): Promise<void>;
|
|
13
11
|
removeIndex(key: Buffer, ...values: Buffer[]): Promise<void>;
|
|
14
12
|
getIndex(key: Buffer): Promise<Uint8Array[]>;
|
|
15
|
-
iterate(startKey: Uint8Array, endKey?: Uint8Array
|
|
16
|
-
iterateIndex(startKey: Uint8Array, endKey?: Uint8Array
|
|
13
|
+
iterate(startKey: Uint8Array, endKey?: Uint8Array, reverse?: boolean, limit?: number): AsyncIterable<[Uint8Array, Uint8Array]>;
|
|
14
|
+
iterateIndex(startKey: Uint8Array, endKey?: Uint8Array, reverse?: boolean, limit?: number): AsyncIterable<[Uint8Array, Uint8Array[]]>;
|
|
17
15
|
commit(): Promise<void>;
|
|
18
16
|
}
|
|
19
|
-
//# sourceMappingURL=
|
|
17
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid3JpdGVfdHJhbnNhY3Rpb24uZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9sbWRiLXYyL3dyaXRlX3RyYW5zYWN0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQVVBLE9BQU8sRUFBRSxLQUFLLEtBQUssRUFBNkIsTUFBTSxjQUFjLENBQUM7QUFDckUsT0FBTyxFQUFFLGVBQWUsRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBR3hELHFCQUFhLGdCQUFpQixTQUFRLGVBQWU7O0lBRW5ELFNBQWdCLFNBQVMsRUFBRSxLQUFLLENBRzlCO0lBQ0YsU0FBZ0IsVUFBVSxFQUFFLEtBQUssQ0FHL0I7SUFFRixHQUFHLENBQUMsR0FBRyxFQUFFLFVBQVUsRUFBRSxLQUFLLEVBQUUsVUFBVSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FnQnJEO0lBRUQsTUFBTSxDQUFDLEdBQUcsRUFBRSxVQUFVLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQVlyQztJQUVxQixHQUFHLENBQUMsR0FBRyxFQUFFLE1BQU0sR0FBRyxPQUFPLENBQUMsVUFBVSxHQUFHLFNBQVMsQ0FBQyxDQWF0RTtJQUVELFFBQVEsQ0FBQyxHQUFHLEVBQUUsTUFBTSxFQUFFLEdBQUcsTUFBTSxFQUFFLE1BQU0sRUFBRSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0EyQnhEO0lBRUQsV0FBVyxDQUFDLEdBQUcsRUFBRSxNQUFNLEVBQUUsR0FBRyxNQUFNLEVBQUUsTUFBTSxFQUFFLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQXFDM0Q7SUFFcUIsUUFBUSxDQUFDLEdBQUcsRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUFDLFVBQVUsRUFBRSxDQUFDLENBcUJqRTtJQUVzQixPQUFPLENBQzVCLFFBQVEsRUFBRSxVQUFVLEVBQ3BCLE1BQU0sQ0FBQyxFQUFFLFVBQVUsRUFDbkIsT0FBTyxDQUFDLEVBQUUsT0FBTyxFQUNqQixLQUFLLENBQUMsRUFBRSxNQUFNLEdBQ2IsYUFBYSxDQUFDLENBQUMsVUFBVSxFQUFFLFVBQVUsQ0FBQyxDQUFDLENBV3pDO0lBRXNCLFlBQVksQ0FDakMsUUFBUSxFQUFFLFVBQVUsRUFDcEIsTUFBTSxDQUFDLEVBQUUsVUFBVSxFQUNuQixPQUFPLENBQUMsRUFBRSxPQUFPLEVBQ2pCLEtBQUssQ0FBQyxFQUFFLE1BQU0sR0FDYixhQUFhLENBQUMsQ0FBQyxVQUFVLEVBQUUsVUFBVSxFQUFFLENBQUMsQ0FBQyxDQW9CM0M7SUFrR1ksTUFBTSxrQkFTbEI7Q0FDRiJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write_transaction.d.ts","sourceRoot":"","sources":["../../src/lmdb-v2/write_transaction.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"write_transaction.d.ts","sourceRoot":"","sources":["../../src/lmdb-v2/write_transaction.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,KAAK,EAA6B,MAAM,cAAc,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGxD,qBAAa,gBAAiB,SAAQ,eAAe;;IAEnD,SAAgB,SAAS,EAAE,KAAK,CAG9B;IACF,SAAgB,UAAU,EAAE,KAAK,CAG/B;IAEF,GAAG,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBrD;IAED,MAAM,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAYrC;IAEqB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAatE;IAED,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA2BxD;IAED,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAqC3D;IAEqB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAqBjE;IAEsB,OAAO,CAC5B,QAAQ,EAAE,UAAU,EACpB,MAAM,CAAC,EAAE,UAAU,EACnB,OAAO,CAAC,EAAE,OAAO,EACjB,KAAK,CAAC,EAAE,MAAM,GACb,aAAa,CAAC,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAWzC;IAEsB,YAAY,CACjC,QAAQ,EAAE,UAAU,EACpB,MAAM,CAAC,EAAE,UAAU,EACnB,OAAO,CAAC,EAAE,OAAO,EACjB,KAAK,CAAC,EAAE,MAAM,GACb,aAAa,CAAC,CAAC,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC,CAoB3C;IAkGY,MAAM,kBASlB;CACF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { dedupeSortedArray, findInSortedArray, findIndexInSortedArray, insertIntoSortedArray, merge, removeAnyOf, removeFromSortedArray } from '@aztec/foundation/array';
|
|
1
2
|
import { Database, LMDBMessageType } from './message.js';
|
|
2
3
|
import { ReadTransaction } from './read_transaction.js';
|
|
3
|
-
import {
|
|
4
|
+
import { keyCmp, singleKeyCmp } from './utils.js';
|
|
4
5
|
export class WriteTransaction extends ReadTransaction {
|
|
5
6
|
// exposed for tests
|
|
6
7
|
dataBatch = {
|
|
@@ -35,10 +36,10 @@ export class WriteTransaction extends ReadTransaction {
|
|
|
35
36
|
remove(key) {
|
|
36
37
|
const removeEntryIndex = findIndexInSortedArray(this.dataBatch.removeEntries, key, singleKeyCmp);
|
|
37
38
|
if (removeEntryIndex === -1) {
|
|
38
|
-
this.dataBatch.removeEntries
|
|
39
|
+
insertIntoSortedArray(this.dataBatch.removeEntries, [
|
|
39
40
|
key,
|
|
40
41
|
null
|
|
41
|
-
]);
|
|
42
|
+
], keyCmp);
|
|
42
43
|
}
|
|
43
44
|
const addEntryIndex = findIndexInSortedArray(this.dataBatch.addEntries, key, singleKeyCmp);
|
|
44
45
|
if (addEntryIndex > -1) {
|
|
@@ -155,10 +156,13 @@ export class WriteTransaction extends ReadTransaction {
|
|
|
155
156
|
}
|
|
156
157
|
async *#iterate(iterator, batch, startKey, endKey, reverse = false, limit, merge, map) {
|
|
157
158
|
this.assertIsOpen();
|
|
158
|
-
//
|
|
159
|
+
// Snapshot both add and remove entries at the start of iteration to ensure consistency
|
|
159
160
|
const uncommittedEntries = [
|
|
160
161
|
...batch.addEntries
|
|
161
162
|
];
|
|
163
|
+
const removeEntries = [
|
|
164
|
+
...batch.removeEntries
|
|
165
|
+
];
|
|
162
166
|
// used to check we're in the right order when comparing between a key and uncommittedEntries
|
|
163
167
|
let cmpDirection = -1;
|
|
164
168
|
if (reverse) {
|
|
@@ -198,7 +202,7 @@ export class WriteTransaction extends ReadTransaction {
|
|
|
198
202
|
if (!checkLimit()) {
|
|
199
203
|
break;
|
|
200
204
|
}
|
|
201
|
-
const toRemove = findInSortedArray(
|
|
205
|
+
const toRemove = findInSortedArray(removeEntries, key, singleKeyCmp);
|
|
202
206
|
// at this point we've either exhausted all uncommitted entries,
|
|
203
207
|
// we reached a key strictly greater/smaller than `key`
|
|
204
208
|
// or we found the key itself
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AztecAsyncArray } from '../interfaces/array.js';
|
|
2
|
+
import type { Value } from '../interfaces/common.js';
|
|
3
|
+
import type { AztecSQLiteOPFSStore } from './store.js';
|
|
4
|
+
/**
|
|
5
|
+
* Persistent array backed by SQLite. Entries share a common `key` (the array name)
|
|
6
|
+
* and are ordered by `key_count`, which doubles as the 1-indexed slot number.
|
|
7
|
+
*/
|
|
8
|
+
export declare class SQLiteOPFSAztecArray<T extends Value> implements AztecAsyncArray<T> {
|
|
9
|
+
#private;
|
|
10
|
+
private readonly store;
|
|
11
|
+
constructor(store: AztecSQLiteOPFSStore, name: string);
|
|
12
|
+
lengthAsync(): Promise<number>;
|
|
13
|
+
push(...vals: T[]): Promise<number>;
|
|
14
|
+
pop(): Promise<T | undefined>;
|
|
15
|
+
atAsync(index: number): Promise<T | undefined>;
|
|
16
|
+
setAt(index: number, val: T): Promise<boolean>;
|
|
17
|
+
entriesAsync(): AsyncIterableIterator<[number, T]>;
|
|
18
|
+
valuesAsync(): AsyncIterableIterator<T>;
|
|
19
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<T>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXJyYXkuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zcWxpdGUtb3Bmcy9hcnJheS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFJQSxPQUFPLEtBQUssRUFBRSxlQUFlLEVBQUUsTUFBTSx3QkFBd0IsQ0FBQztBQUM5RCxPQUFPLEtBQUssRUFBRSxLQUFLLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUNyRCxPQUFPLEtBQUssRUFBRSxvQkFBb0IsRUFBRSxNQUFNLFlBQVksQ0FBQztBQUV2RDs7O0dBR0c7QUFDSCxxQkFBYSxvQkFBb0IsQ0FBQyxDQUFDLFNBQVMsS0FBSyxDQUFFLFlBQVcsZUFBZSxDQUFDLENBQUMsQ0FBQzs7SUFNNUUsT0FBTyxDQUFDLFFBQVEsQ0FBQyxLQUFLO0lBRHhCLFlBQ21CLEtBQUssRUFBRSxvQkFBb0IsRUFDNUMsSUFBSSxFQUFFLE1BQU0sRUFJYjtJQUVLLFdBQVcsSUFBSSxPQUFPLENBQUMsTUFBTSxDQUFDLENBTW5DO0lBRUssSUFBSSxDQUFDLEdBQUcsSUFBSSxFQUFFLENBQUMsRUFBRSxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FnQnhDO0lBRUssR0FBRyxJQUFJLE9BQU8sQ0FBQyxDQUFDLEdBQUcsU0FBUyxDQUFDLENBWWxDO0lBRUssT0FBTyxDQUFDLEtBQUssRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUFDLENBQUMsR0FBRyxTQUFTLENBQUMsQ0FTbkQ7SUFFSyxLQUFLLENBQUMsS0FBSyxFQUFFLE1BQU0sRUFBRSxHQUFHLEVBQUUsQ0FBQyxHQUFHLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FjbkQ7SUFFTSxZQUFZLElBQUkscUJBQXFCLENBQUMsQ0FBQyxNQUFNLEVBQUUsQ0FBQyxDQUFDLENBQUMsQ0FZeEQ7SUFFTSxXQUFXLElBQUkscUJBQXFCLENBQUMsQ0FBQyxDQUFDLENBSTdDO0lBRUQsQ0FBQyxNQUFNLENBQUMsYUFBYSxDQUFDLElBQUkscUJBQXFCLENBQUMsQ0FBQyxDQUFDLENBRWpEO0NBU0YifQ==
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../src/sqlite-opfs/array.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEvD;;;GAGG;AACH,qBAAa,oBAAoB,CAAC,CAAC,SAAS,KAAK,CAAE,YAAW,eAAe,CAAC,CAAC,CAAC;;IAM5E,OAAO,CAAC,QAAQ,CAAC,KAAK;IADxB,YACmB,KAAK,EAAE,oBAAoB,EAC5C,IAAI,EAAE,MAAM,EAIb;IAEK,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC,CAMnC;IAEK,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAgBxC;IAEK,GAAG,IAAI,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAYlC;IAEK,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CASnD;IAEK,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAcnD;IAEM,YAAY,IAAI,qBAAqB,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAYxD;IAEM,WAAW,IAAI,qBAAqB,CAAC,CAAC,CAAC,CAI7C;IAED,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,qBAAqB,CAAC,CAAC,CAAC,CAEjD;CASF"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
var _computedKey;
|
|
2
|
+
import { Encoder } from '#msgpackr';
|
|
3
|
+
import { toBufferKey } from '#ordered-binary';
|
|
4
|
+
import { hash } from 'ohash';
|
|
5
|
+
_computedKey = Symbol.asyncIterator;
|
|
6
|
+
/**
|
|
7
|
+
* Persistent array backed by SQLite. Entries share a common `key` (the array name)
|
|
8
|
+
* and are ordered by `key_count`, which doubles as the 1-indexed slot number.
|
|
9
|
+
*/ export class SQLiteOPFSAztecArray {
|
|
10
|
+
store;
|
|
11
|
+
#name;
|
|
12
|
+
#container;
|
|
13
|
+
#encoder;
|
|
14
|
+
constructor(store, name){
|
|
15
|
+
this.store = store;
|
|
16
|
+
this.#encoder = new Encoder();
|
|
17
|
+
this.#name = name;
|
|
18
|
+
this.#container = `array:${name}`;
|
|
19
|
+
}
|
|
20
|
+
async lengthAsync() {
|
|
21
|
+
const rows = await this.store.allAsync('SELECT COUNT(*) FROM data WHERE container = ? AND key = ?', [
|
|
22
|
+
this.#container,
|
|
23
|
+
this.#encodedKey()
|
|
24
|
+
]);
|
|
25
|
+
return Number(rows[0]?.[0] ?? 0);
|
|
26
|
+
}
|
|
27
|
+
async push(...vals) {
|
|
28
|
+
if (vals.length === 0) {
|
|
29
|
+
return this.lengthAsync();
|
|
30
|
+
}
|
|
31
|
+
return await this.store.transactionAsync(async ()=>{
|
|
32
|
+
let length = await this.lengthAsync();
|
|
33
|
+
for (const val of vals){
|
|
34
|
+
await this.store.runAsync(`INSERT INTO data (slot, container, key, key_count, hash, value)
|
|
35
|
+
VALUES (?, ?, ?, ?, ?, ?)`, [
|
|
36
|
+
this.#slot(length),
|
|
37
|
+
this.#container,
|
|
38
|
+
this.#encodedKey(),
|
|
39
|
+
length + 1,
|
|
40
|
+
hash(val),
|
|
41
|
+
this.#encoder.pack(val)
|
|
42
|
+
]);
|
|
43
|
+
length += 1;
|
|
44
|
+
}
|
|
45
|
+
return length;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
async pop() {
|
|
49
|
+
return await this.store.transactionAsync(async ()=>{
|
|
50
|
+
const length = await this.lengthAsync();
|
|
51
|
+
if (length === 0) {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
const slot = this.#slot(length - 1);
|
|
55
|
+
const rows = await this.store.allAsync('SELECT value FROM data WHERE slot = ? LIMIT 1', [
|
|
56
|
+
slot
|
|
57
|
+
]);
|
|
58
|
+
await this.store.runAsync('DELETE FROM data WHERE slot = ?', [
|
|
59
|
+
slot
|
|
60
|
+
]);
|
|
61
|
+
const raw = rows[0]?.[0];
|
|
62
|
+
return raw instanceof Uint8Array ? this.#encoder.unpack(raw) : undefined;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
async atAsync(index) {
|
|
66
|
+
const length = await this.lengthAsync();
|
|
67
|
+
const resolved = index < 0 ? length + index : index;
|
|
68
|
+
if (resolved < 0 || resolved >= length) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
const rows = await this.store.allAsync('SELECT value FROM data WHERE slot = ? LIMIT 1', [
|
|
72
|
+
this.#slot(resolved)
|
|
73
|
+
]);
|
|
74
|
+
const raw = rows[0]?.[0];
|
|
75
|
+
return raw instanceof Uint8Array ? this.#encoder.unpack(raw) : undefined;
|
|
76
|
+
}
|
|
77
|
+
async setAt(index, val) {
|
|
78
|
+
return await this.store.transactionAsync(async ()=>{
|
|
79
|
+
const length = await this.lengthAsync();
|
|
80
|
+
const resolved = index < 0 ? length + index : index;
|
|
81
|
+
if (resolved < 0 || resolved >= length) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
await this.store.runAsync(`INSERT OR REPLACE INTO data (slot, container, key, key_count, hash, value)
|
|
85
|
+
VALUES (?, ?, ?, ?, ?, ?)`, [
|
|
86
|
+
this.#slot(resolved),
|
|
87
|
+
this.#container,
|
|
88
|
+
this.#encodedKey(),
|
|
89
|
+
resolved + 1,
|
|
90
|
+
hash(val),
|
|
91
|
+
this.#encoder.pack(val)
|
|
92
|
+
]);
|
|
93
|
+
return true;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
async *entriesAsync() {
|
|
97
|
+
const rows = await this.store.allAsync('SELECT key_count, value FROM data WHERE container = ? AND key = ? ORDER BY key_count ASC', [
|
|
98
|
+
this.#container,
|
|
99
|
+
this.#encodedKey()
|
|
100
|
+
]);
|
|
101
|
+
for (const row of rows){
|
|
102
|
+
const keyCount = Number(row[0]);
|
|
103
|
+
const raw = row[1];
|
|
104
|
+
if (raw instanceof Uint8Array) {
|
|
105
|
+
yield [
|
|
106
|
+
keyCount - 1,
|
|
107
|
+
this.#encoder.unpack(raw)
|
|
108
|
+
];
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async *valuesAsync() {
|
|
113
|
+
for await (const [, val] of this.entriesAsync()){
|
|
114
|
+
yield val;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
[_computedKey]() {
|
|
118
|
+
return this.valuesAsync();
|
|
119
|
+
}
|
|
120
|
+
#encodedKey() {
|
|
121
|
+
return toBufferKey([
|
|
122
|
+
this.#name
|
|
123
|
+
]);
|
|
124
|
+
}
|
|
125
|
+
#slot(index) {
|
|
126
|
+
return `array:${this.#name}:slot:${index}`;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed error surface for sqlite3mc-backed page-level encryption failures.
|
|
3
|
+
*
|
|
4
|
+
* Three concrete failure modes are surfaced:
|
|
5
|
+
*
|
|
6
|
+
* - `invalid_key_length`: caller-side pre-flight (key not 32 bytes).
|
|
7
|
+
* - `encryption_not_supported_for_ephemeral`: caller-side pre-flight (encryption was requested on an ephemeral
|
|
8
|
+
* `:memory:` store, which sqlite3mc does not support).
|
|
9
|
+
* - `decrypt_failed`: runtime failure raised when sqlite3mc cannot decode page 1 of an existing database. Covers
|
|
10
|
+
* both "wrong key supplied" and "no key supplied to an encrypted DB".
|
|
11
|
+
*/
|
|
12
|
+
export type SqliteEncryptionErrorCode = 'invalid_key_length' | 'encryption_not_supported_for_ephemeral' | 'decrypt_failed';
|
|
13
|
+
/**
|
|
14
|
+
* Error thrown by sqlite-opfs when an encryption operation fails.
|
|
15
|
+
**/
|
|
16
|
+
export declare class SqliteEncryptionError extends Error {
|
|
17
|
+
readonly code: SqliteEncryptionErrorCode;
|
|
18
|
+
constructor(code: SqliteEncryptionErrorCode, message: string, opts?: {
|
|
19
|
+
cause?: unknown;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Returns `true` if `message` matches one of the known sqlite3mc decrypt-failure
|
|
24
|
+
* strings.
|
|
25
|
+
**/
|
|
26
|
+
export declare function isDecryptFailureMessage(message: string): boolean;
|
|
27
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXJyb3JzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc3FsaXRlLW9wZnMvZXJyb3JzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7Ozs7O0dBVUc7QUFDSCxNQUFNLE1BQU0seUJBQXlCLEdBQ2pDLG9CQUFvQixHQUNwQix3Q0FBd0MsR0FDeEMsZ0JBQWdCLENBQUM7QUFFckI7O0lBRUk7QUFDSixxQkFBYSxxQkFBc0IsU0FBUSxLQUFLO0lBQzlDLFFBQVEsQ0FBQyxJQUFJLEVBQUUseUJBQXlCLENBQUM7SUFFekMsWUFBWSxJQUFJLEVBQUUseUJBQXlCLEVBQUUsT0FBTyxFQUFFLE1BQU0sRUFBRSxJQUFJLENBQUMsRUFBRTtRQUFFLEtBQUssQ0FBQyxFQUFFLE9BQU8sQ0FBQTtLQUFFLEVBSXZGO0NBQ0Y7QUFVRDs7O0lBR0k7QUFDSix3QkFBZ0IsdUJBQXVCLENBQUMsT0FBTyxFQUFFLE1BQU0sR0FBRyxPQUFPLENBRWhFIn0=
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/sqlite-opfs/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,MAAM,yBAAyB,GACjC,oBAAoB,GACpB,wCAAwC,GACxC,gBAAgB,CAAC;AAErB;;IAEI;AACJ,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,QAAQ,CAAC,IAAI,EAAE,yBAAyB,CAAC;IAEzC,YAAY,IAAI,EAAE,yBAAyB,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,EAIvF;CACF;AAUD;;;IAGI;AACJ,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAEhE"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed error surface for sqlite3mc-backed page-level encryption failures.
|
|
3
|
+
*
|
|
4
|
+
* Three concrete failure modes are surfaced:
|
|
5
|
+
*
|
|
6
|
+
* - `invalid_key_length`: caller-side pre-flight (key not 32 bytes).
|
|
7
|
+
* - `encryption_not_supported_for_ephemeral`: caller-side pre-flight (encryption was requested on an ephemeral
|
|
8
|
+
* `:memory:` store, which sqlite3mc does not support).
|
|
9
|
+
* - `decrypt_failed`: runtime failure raised when sqlite3mc cannot decode page 1 of an existing database. Covers
|
|
10
|
+
* both "wrong key supplied" and "no key supplied to an encrypted DB".
|
|
11
|
+
*/ /**
|
|
12
|
+
* Error thrown by sqlite-opfs when an encryption operation fails.
|
|
13
|
+
**/ export class SqliteEncryptionError extends Error {
|
|
14
|
+
code;
|
|
15
|
+
constructor(code, message, opts){
|
|
16
|
+
super(message, opts?.cause !== undefined ? {
|
|
17
|
+
cause: opts.cause
|
|
18
|
+
} : undefined);
|
|
19
|
+
this.name = 'SqliteEncryptionError';
|
|
20
|
+
this.code = code;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Strings raised by sqlite3mc when page 1 cannot be decoded.
|
|
25
|
+
**/ const SQLITE3MC_DECRYPT_ERROR_PATTERNS = [
|
|
26
|
+
/file is not a database/i,
|
|
27
|
+
/file is encrypted or is not a database/i
|
|
28
|
+
];
|
|
29
|
+
/**
|
|
30
|
+
* Returns `true` if `message` matches one of the known sqlite3mc decrypt-failure
|
|
31
|
+
* strings.
|
|
32
|
+
**/ export function isDecryptFailureMessage(message) {
|
|
33
|
+
return SQLITE3MC_DECRYPT_ERROR_PATTERNS.some((p)=>p.test(message));
|
|
34
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Logger } from '@aztec/foundation/log';
|
|
2
|
+
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
3
|
+
import { AztecSQLiteOPFSStore } from './store.js';
|
|
4
|
+
export { AztecSQLiteOPFSStore } from './store.js';
|
|
5
|
+
export { SqliteEncryptionError } from './errors.js';
|
|
6
|
+
export type { SqliteEncryptionErrorCode } from './errors.js';
|
|
7
|
+
export declare function createStore(name: string, config: DataStoreConfig, schemaVersion?: number | undefined, log?: Logger): Promise<AztecSQLiteOPFSStore>;
|
|
8
|
+
export declare function openTmpStore(ephemeral?: boolean): Promise<AztecSQLiteOPFSStore>;
|
|
9
|
+
/**
|
|
10
|
+
* Convenience helper for tests and consumers that want an encrypted sqlite-opfs
|
|
11
|
+
* store without dealing with the full `open()` parameter order. Key must be 32
|
|
12
|
+
* bytes. Creates a fresh persistent store (sqlite3mc does not support encryption
|
|
13
|
+
* on ephemeral `:memory:` databases) in an auto-generated OPFS directory.
|
|
14
|
+
*/
|
|
15
|
+
export declare function openEncryptedStore(encryptionKey: Uint8Array, name?: string, poolDirectory?: string): Promise<AztecSQLiteOPFSStore>;
|
|
16
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zcWxpdGUtb3Bmcy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsS0FBSyxNQUFNLEVBQWdCLE1BQU0sdUJBQXVCLENBQUM7QUFDbEUsT0FBTyxLQUFLLEVBQUUsZUFBZSxFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFHOUQsT0FBTyxFQUFFLG9CQUFvQixFQUFFLE1BQU0sWUFBWSxDQUFDO0FBRWxELE9BQU8sRUFBRSxvQkFBb0IsRUFBRSxNQUFNLFlBQVksQ0FBQztBQUNsRCxPQUFPLEVBQUUscUJBQXFCLEVBQUUsTUFBTSxhQUFhLENBQUM7QUFDcEQsWUFBWSxFQUFFLHlCQUF5QixFQUFFLE1BQU0sYUFBYSxDQUFDO0FBRTdELHdCQUFzQixXQUFXLENBQy9CLElBQUksRUFBRSxNQUFNLEVBQ1osTUFBTSxFQUFFLGVBQWUsRUFDdkIsYUFBYSxHQUFFLE1BQU0sR0FBRyxTQUFxQixFQUM3QyxHQUFHLEdBQUUsTUFBaUMsaUNBVXZDO0FBRUQsd0JBQWdCLFlBQVksQ0FBQyxTQUFTLEdBQUUsT0FBZSxHQUFHLE9BQU8sQ0FBQyxvQkFBb0IsQ0FBQyxDQUV0RjtBQUVEOzs7OztHQUtHO0FBQ0gsd0JBQWdCLGtCQUFrQixDQUFDLGFBQWEsRUFBRSxVQUFVLEVBQUUsSUFBSSxDQUFDLEVBQUUsTUFBTSxFQUFFLGFBQWEsQ0FBQyxFQUFFLE1BQU0saUNBRWxHIn0=
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sqlite-opfs/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAG9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,YAAY,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAE7D,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,eAAe,EACvB,aAAa,GAAE,MAAM,GAAG,SAAqB,EAC7C,GAAG,GAAE,MAAiC,iCAUvC;AAED,wBAAgB,YAAY,CAAC,SAAS,GAAE,OAAe,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAEtF;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,iCAElG"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { initStoreForRollupAndSchemaVersion } from '../utils.js';
|
|
3
|
+
import { AztecSQLiteOPFSStore } from './store.js';
|
|
4
|
+
export { AztecSQLiteOPFSStore } from './store.js';
|
|
5
|
+
export { SqliteEncryptionError } from './errors.js';
|
|
6
|
+
export async function createStore(name, config, schemaVersion = undefined, log = createLogger('kv-store')) {
|
|
7
|
+
const { dataDirectory } = config;
|
|
8
|
+
log.info(dataDirectory ? `Creating ${name} SQLite-OPFS data store with map size ${config.dataStoreMapSizeKb} KB` : `Creating ${name} ephemeral SQLite-OPFS data store with map size ${config.dataStoreMapSizeKb} KB`);
|
|
9
|
+
const store = await AztecSQLiteOPFSStore.open(createLogger('kv-store:sqlite-opfs'), name, false);
|
|
10
|
+
return initStoreForRollupAndSchemaVersion(store, schemaVersion, config.rollupAddress, log);
|
|
11
|
+
}
|
|
12
|
+
export function openTmpStore(ephemeral = false) {
|
|
13
|
+
return AztecSQLiteOPFSStore.open(createLogger('kv-store:sqlite-opfs'), undefined, ephemeral);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Convenience helper for tests and consumers that want an encrypted sqlite-opfs
|
|
17
|
+
* store without dealing with the full `open()` parameter order. Key must be 32
|
|
18
|
+
* bytes. Creates a fresh persistent store (sqlite3mc does not support encryption
|
|
19
|
+
* on ephemeral `:memory:` databases) in an auto-generated OPFS directory.
|
|
20
|
+
*/ export function openEncryptedStore(encryptionKey, name, poolDirectory) {
|
|
21
|
+
return AztecSQLiteOPFSStore.open(createLogger('kv-store:sqlite-opfs'), name, false, poolDirectory, encryptionKey);
|
|
22
|
+
}
|