@aztec/kv-store 0.0.1-commit.9badcec54 → 0.0.1-commit.9ebd450e8
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.
|
@@ -51,18 +51,19 @@ export class ReadTransaction {
|
|
|
51
51
|
}
|
|
52
52
|
async *#iterate(db, startKey, endKey, reverse, limit, map) {
|
|
53
53
|
this.assertIsOpen();
|
|
54
|
-
|
|
55
|
-
key: startKey,
|
|
56
|
-
reverse,
|
|
57
|
-
count: typeof limit === 'number' ? Math.min(limit, CURSOR_PAGE_SIZE) : CURSOR_PAGE_SIZE,
|
|
58
|
-
onePage: typeof limit === 'number' && limit < CURSOR_PAGE_SIZE,
|
|
59
|
-
db
|
|
60
|
-
});
|
|
61
|
-
const cursor = response.cursor;
|
|
62
|
-
let entries = response.entries;
|
|
63
|
-
let done = typeof cursor !== 'number';
|
|
64
|
-
let count = 0;
|
|
54
|
+
let cursor;
|
|
65
55
|
try {
|
|
56
|
+
const response = await this.channel.sendMessage(LMDBMessageType.START_CURSOR, {
|
|
57
|
+
key: startKey,
|
|
58
|
+
reverse,
|
|
59
|
+
count: typeof limit === 'number' ? Math.min(limit, CURSOR_PAGE_SIZE) : CURSOR_PAGE_SIZE,
|
|
60
|
+
onePage: typeof limit === 'number' && limit < CURSOR_PAGE_SIZE,
|
|
61
|
+
db
|
|
62
|
+
});
|
|
63
|
+
cursor = response.cursor ?? undefined;
|
|
64
|
+
let entries = response.entries;
|
|
65
|
+
let done = typeof cursor !== 'number';
|
|
66
|
+
let count = 0;
|
|
66
67
|
// emit the first page and any subsequent pages in a while loop
|
|
67
68
|
// NB: end contition is in the middle of the while loop
|
|
68
69
|
while(entries.length > 0){
|
|
@@ -106,15 +107,16 @@ export class ReadTransaction {
|
|
|
106
107
|
}
|
|
107
108
|
async #countEntries(db, startKey, endKey, reverse) {
|
|
108
109
|
this.assertIsOpen();
|
|
109
|
-
|
|
110
|
-
key: startKey,
|
|
111
|
-
reverse,
|
|
112
|
-
count: 0,
|
|
113
|
-
onePage: false,
|
|
114
|
-
db
|
|
115
|
-
});
|
|
116
|
-
const cursor = response.cursor;
|
|
110
|
+
let cursor;
|
|
117
111
|
try {
|
|
112
|
+
const response = await this.channel.sendMessage(LMDBMessageType.START_CURSOR, {
|
|
113
|
+
key: startKey,
|
|
114
|
+
reverse,
|
|
115
|
+
count: 0,
|
|
116
|
+
onePage: false,
|
|
117
|
+
db
|
|
118
|
+
});
|
|
119
|
+
cursor = response.cursor ?? undefined;
|
|
118
120
|
if (!cursor) {
|
|
119
121
|
return 0;
|
|
120
122
|
}
|
|
@@ -18,13 +18,11 @@ const DEFAULT_SAH_POOL_DIRECTORY = '.aztec-kv';
|
|
|
18
18
|
const SAH_POOL_VFS_NAME = 'aztec-kv-opfs';
|
|
19
19
|
let sqlite3;
|
|
20
20
|
let pool;
|
|
21
|
-
let poolDirectory;
|
|
22
21
|
let db;
|
|
23
22
|
let dbPath;
|
|
24
23
|
async function ensurePool(directory) {
|
|
25
24
|
sqlite3 ??= await sqlite3InitModule();
|
|
26
25
|
if (!pool) {
|
|
27
|
-
poolDirectory = directory;
|
|
28
26
|
pool = await sqlite3.installOpfsSAHPoolVfs({
|
|
29
27
|
name: SAH_POOL_VFS_NAME,
|
|
30
28
|
directory,
|
|
@@ -58,16 +56,23 @@ async function handleExport() {
|
|
|
58
56
|
}
|
|
59
57
|
return await pool.exportFile(dbPath);
|
|
60
58
|
}
|
|
61
|
-
|
|
59
|
+
function handleDeleteDb(dbName) {
|
|
62
60
|
const path = normalizeDbPath(dbName);
|
|
63
61
|
if (db && dbPath === path) {
|
|
64
62
|
db.close();
|
|
65
63
|
db = undefined;
|
|
66
64
|
dbPath = undefined;
|
|
67
65
|
}
|
|
68
|
-
|
|
66
|
+
// Ephemeral :memory: DBs never back a file — skip installing a pool just to unlink
|
|
67
|
+
// nothing. installOpfsSAHPoolVfs acquires an exclusive lock on the OPFS SAH
|
|
68
|
+
// directory, and under heavy test churn that can contend with workers from
|
|
69
|
+
// previous tests whose OPFS handles Chromium hasn't yet released, hanging the RPC
|
|
70
|
+
// and then the whole test run.
|
|
71
|
+
if (!pool) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
69
74
|
try {
|
|
70
|
-
|
|
75
|
+
pool.unlink(path);
|
|
71
76
|
} catch {
|
|
72
77
|
// File may not exist; ignore.
|
|
73
78
|
}
|
|
@@ -122,7 +127,7 @@ self.onmessage = async (ev)=>{
|
|
|
122
127
|
id: req.id
|
|
123
128
|
});
|
|
124
129
|
case 'deleteDb':
|
|
125
|
-
|
|
130
|
+
handleDeleteDb(req.dbName);
|
|
126
131
|
return respond({
|
|
127
132
|
type: 'ok',
|
|
128
133
|
id: req.id
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/kv-store",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.9ebd450e8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/interfaces/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"test:node": "NODE_NO_WARNINGS=1 mocha --config ./.mocharc.json",
|
|
19
19
|
"test:browser": "vitest run --config ./vitest.config.ts",
|
|
20
20
|
"bench:browser": "VITE_BENCH=1 vitest run --config ./vitest.config.ts src/bench",
|
|
21
|
-
"test": "yarn test:node
|
|
21
|
+
"test": "yarn test:node",
|
|
22
22
|
"test:jest": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
23
23
|
},
|
|
24
24
|
"inherits": [
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
"./package.local.json"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@aztec/constants": "0.0.1-commit.
|
|
30
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
31
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
32
|
-
"@aztec/native": "0.0.1-commit.
|
|
33
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
29
|
+
"@aztec/constants": "0.0.1-commit.9ebd450e8",
|
|
30
|
+
"@aztec/ethereum": "0.0.1-commit.9ebd450e8",
|
|
31
|
+
"@aztec/foundation": "0.0.1-commit.9ebd450e8",
|
|
32
|
+
"@aztec/native": "0.0.1-commit.9ebd450e8",
|
|
33
|
+
"@aztec/stdlib": "0.0.1-commit.9ebd450e8",
|
|
34
34
|
"@sqlite.org/sqlite-wasm": "3.50.4-build1",
|
|
35
35
|
"idb": "^8.0.0",
|
|
36
36
|
"lmdb": "^3.2.0",
|
|
@@ -66,20 +66,20 @@ export class ReadTransaction {
|
|
|
66
66
|
): AsyncIterable<[Uint8Array, T]> {
|
|
67
67
|
this.assertIsOpen();
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
key: startKey,
|
|
71
|
-
reverse,
|
|
72
|
-
count: typeof limit === 'number' ? Math.min(limit, CURSOR_PAGE_SIZE) : CURSOR_PAGE_SIZE,
|
|
73
|
-
onePage: typeof limit === 'number' && limit < CURSOR_PAGE_SIZE,
|
|
74
|
-
db,
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
const cursor = response.cursor;
|
|
78
|
-
let entries = response.entries;
|
|
79
|
-
let done = typeof cursor !== 'number';
|
|
80
|
-
let count = 0;
|
|
81
|
-
|
|
69
|
+
let cursor: number | undefined;
|
|
82
70
|
try {
|
|
71
|
+
const response = await this.channel.sendMessage(LMDBMessageType.START_CURSOR, {
|
|
72
|
+
key: startKey,
|
|
73
|
+
reverse,
|
|
74
|
+
count: typeof limit === 'number' ? Math.min(limit, CURSOR_PAGE_SIZE) : CURSOR_PAGE_SIZE,
|
|
75
|
+
onePage: typeof limit === 'number' && limit < CURSOR_PAGE_SIZE,
|
|
76
|
+
db,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
cursor = response.cursor ?? undefined;
|
|
80
|
+
let entries = response.entries;
|
|
81
|
+
let done = typeof cursor !== 'number';
|
|
82
|
+
let count = 0;
|
|
83
83
|
// emit the first page and any subsequent pages in a while loop
|
|
84
84
|
// NB: end contition is in the middle of the while loop
|
|
85
85
|
while (entries.length > 0) {
|
|
@@ -125,17 +125,17 @@ export class ReadTransaction {
|
|
|
125
125
|
async #countEntries(db: string, startKey: Uint8Array, endKey: Uint8Array, reverse: boolean): Promise<number> {
|
|
126
126
|
this.assertIsOpen();
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
key: startKey,
|
|
130
|
-
reverse,
|
|
131
|
-
count: 0,
|
|
132
|
-
onePage: false,
|
|
133
|
-
db,
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
const cursor = response.cursor;
|
|
137
|
-
|
|
128
|
+
let cursor: number | undefined;
|
|
138
129
|
try {
|
|
130
|
+
const response = await this.channel.sendMessage(LMDBMessageType.START_CURSOR, {
|
|
131
|
+
key: startKey,
|
|
132
|
+
reverse,
|
|
133
|
+
count: 0,
|
|
134
|
+
onePage: false,
|
|
135
|
+
db,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
cursor = response.cursor ?? undefined;
|
|
139
139
|
if (!cursor) {
|
|
140
140
|
return 0;
|
|
141
141
|
}
|
|
@@ -23,14 +23,12 @@ const SAH_POOL_VFS_NAME = 'aztec-kv-opfs';
|
|
|
23
23
|
|
|
24
24
|
let sqlite3: Sqlite3Static | undefined;
|
|
25
25
|
let pool: SAHPoolUtil | undefined;
|
|
26
|
-
let poolDirectory: string | undefined;
|
|
27
26
|
let db: Database | undefined;
|
|
28
27
|
let dbPath: string | undefined;
|
|
29
28
|
|
|
30
29
|
async function ensurePool(directory: string): Promise<SAHPoolUtil> {
|
|
31
30
|
sqlite3 ??= await sqlite3InitModule();
|
|
32
31
|
if (!pool) {
|
|
33
|
-
poolDirectory = directory;
|
|
34
32
|
pool = await sqlite3.installOpfsSAHPoolVfs({
|
|
35
33
|
name: SAH_POOL_VFS_NAME,
|
|
36
34
|
directory,
|
|
@@ -68,16 +66,23 @@ async function handleExport(): Promise<Uint8Array> {
|
|
|
68
66
|
return await pool.exportFile(dbPath);
|
|
69
67
|
}
|
|
70
68
|
|
|
71
|
-
|
|
69
|
+
function handleDeleteDb(dbName: string): void {
|
|
72
70
|
const path = normalizeDbPath(dbName);
|
|
73
71
|
if (db && dbPath === path) {
|
|
74
72
|
db.close();
|
|
75
73
|
db = undefined;
|
|
76
74
|
dbPath = undefined;
|
|
77
75
|
}
|
|
78
|
-
|
|
76
|
+
// Ephemeral :memory: DBs never back a file — skip installing a pool just to unlink
|
|
77
|
+
// nothing. installOpfsSAHPoolVfs acquires an exclusive lock on the OPFS SAH
|
|
78
|
+
// directory, and under heavy test churn that can contend with workers from
|
|
79
|
+
// previous tests whose OPFS handles Chromium hasn't yet released, hanging the RPC
|
|
80
|
+
// and then the whole test run.
|
|
81
|
+
if (!pool) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
79
84
|
try {
|
|
80
|
-
|
|
85
|
+
pool.unlink(path);
|
|
81
86
|
} catch {
|
|
82
87
|
// File may not exist; ignore.
|
|
83
88
|
}
|
|
@@ -122,7 +127,7 @@ function respond(msg: WorkerResponse): void {
|
|
|
122
127
|
handleClose();
|
|
123
128
|
return respond({ type: 'ok', id: req.id });
|
|
124
129
|
case 'deleteDb':
|
|
125
|
-
|
|
130
|
+
handleDeleteDb(req.dbName);
|
|
126
131
|
return respond({ type: 'ok', id: req.id });
|
|
127
132
|
case 'run': {
|
|
128
133
|
const { changes } = runSql(req.sql, req.bind);
|