@aztec/kv-store 0.0.1-commit.b655e406 → 0.0.1-commit.b8a057fa
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 +10 -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/deprecated/indexeddb/array.d.ts +22 -0
- package/dest/deprecated/indexeddb/array.d.ts.map +1 -0
- package/dest/{indexeddb → deprecated/indexeddb}/array.js +21 -7
- package/dest/deprecated/indexeddb/index.d.ts +13 -0
- package/dest/deprecated/indexeddb/index.d.ts.map +1 -0
- package/dest/{indexeddb → deprecated/indexeddb}/index.js +8 -7
- package/dest/deprecated/indexeddb/map.d.ts +38 -0
- package/dest/deprecated/indexeddb/map.d.ts.map +1 -0
- package/dest/{indexeddb → deprecated/indexeddb}/map.js +23 -13
- package/dest/deprecated/indexeddb/multi_map.d.ts +14 -0
- package/dest/deprecated/indexeddb/multi_map.d.ts.map +1 -0
- package/dest/{indexeddb → deprecated/indexeddb}/multi_map.js +30 -1
- package/dest/deprecated/indexeddb/set.d.ts +17 -0
- package/dest/deprecated/indexeddb/set.d.ts.map +1 -0
- package/dest/deprecated/indexeddb/singleton.d.ts +17 -0
- package/dest/deprecated/indexeddb/singleton.d.ts.map +1 -0
- package/dest/{indexeddb → deprecated/indexeddb}/singleton.js +3 -1
- package/dest/deprecated/indexeddb/store.d.ts +98 -0
- package/dest/deprecated/indexeddb/store.d.ts.map +1 -0
- package/dest/{indexeddb → deprecated/indexeddb}/store.js +8 -4
- package/dest/interfaces/array.d.ts +1 -1
- 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 +1 -1
- package/dest/interfaces/counter.d.ts +1 -1
- package/dest/interfaces/index.d.ts +2 -2
- package/dest/interfaces/index.d.ts.map +1 -1
- package/dest/interfaces/map.d.ts +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 +74 -29
- package/dest/interfaces/multi_map.d.ts +7 -1
- package/dest/interfaces/multi_map.d.ts.map +1 -1
- package/dest/interfaces/multi_map_test_suite.d.ts +1 -1
- package/dest/interfaces/multi_map_test_suite.d.ts.map +1 -1
- package/dest/interfaces/multi_map_test_suite.js +154 -36
- 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 +1 -1
- package/dest/interfaces/utils.d.ts +2 -1
- package/dest/interfaces/utils.d.ts.map +1 -1
- package/dest/interfaces/utils.js +2 -1
- package/dest/lmdb/array.d.ts +1 -1
- 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 +4 -4
- package/dest/lmdb/map.d.ts +1 -1
- package/dest/lmdb/map.d.ts.map +1 -1
- package/dest/lmdb/multi_map.d.ts +2 -1
- package/dest/lmdb/multi_map.d.ts.map +1 -1
- package/dest/lmdb/multi_map.js +15 -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 +4 -5
- package/dest/lmdb/store.d.ts.map +1 -1
- package/dest/lmdb/store.js +13 -9
- package/dest/lmdb-v2/array.d.ts +2 -2
- package/dest/lmdb-v2/array.d.ts.map +1 -1
- package/dest/lmdb-v2/array.js +4 -3
- package/dest/lmdb-v2/factory.d.ts +33 -10
- package/dest/lmdb-v2/factory.d.ts.map +1 -1
- package/dest/lmdb-v2/factory.js +72 -16
- package/dest/lmdb-v2/index.d.ts +1 -1
- package/dest/lmdb-v2/map.d.ts +2 -2
- package/dest/lmdb-v2/map.d.ts.map +1 -1
- package/dest/lmdb-v2/map.js +1 -2
- package/dest/lmdb-v2/message.d.ts +1 -1
- package/dest/lmdb-v2/multi_map.d.ts +3 -2
- package/dest/lmdb-v2/multi_map.d.ts.map +1 -1
- package/dest/lmdb-v2/multi_map.js +11 -1
- package/dest/lmdb-v2/read_transaction.d.ts +1 -1
- package/dest/lmdb-v2/read_transaction.d.ts.map +1 -1
- package/dest/lmdb-v2/read_transaction.js +21 -19
- package/dest/lmdb-v2/set.d.ts +1 -1
- package/dest/lmdb-v2/set.d.ts.map +1 -1
- 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 -2
- package/dest/lmdb-v2/store.d.ts +4 -5
- package/dest/lmdb-v2/store.d.ts.map +1 -1
- package/dest/lmdb-v2/store.js +6 -28
- 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 +1 -10
- 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 +1 -1
- 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 +248 -0
- package/dest/stores/index.d.ts +1 -1
- package/dest/stores/l2_tips_store.d.ts +19 -10
- package/dest/stores/l2_tips_store.d.ts.map +1 -1
- package/dest/stores/l2_tips_store.js +43 -53
- package/dest/utils.d.ts +9 -6
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +51 -16
- package/package.json +34 -27
- package/src/bench/shared_map_bench.ts +111 -0
- package/src/{indexeddb → deprecated/indexeddb}/array.ts +6 -6
- package/src/{indexeddb → deprecated/indexeddb}/index.ts +15 -7
- package/src/{indexeddb → deprecated/indexeddb}/map.ts +26 -13
- package/src/{indexeddb → deprecated/indexeddb}/multi_map.ts +29 -3
- package/src/{indexeddb → deprecated/indexeddb}/set.ts +2 -2
- package/src/{indexeddb → deprecated/indexeddb}/singleton.ts +3 -3
- package/src/{indexeddb → deprecated/indexeddb}/store.ts +23 -15
- package/src/interfaces/array_test_suite.ts +33 -35
- package/src/interfaces/index.ts +1 -1
- package/src/interfaces/map_test_suite.ts +56 -30
- package/src/interfaces/multi_map.ts +7 -0
- package/src/interfaces/multi_map_test_suite.ts +167 -37
- package/src/interfaces/set_test_suite.ts +13 -15
- package/src/interfaces/singleton_test_suite.ts +6 -8
- package/src/interfaces/utils.ts +1 -0
- package/src/lmdb/index.ts +10 -5
- package/src/lmdb/multi_map.ts +16 -0
- package/src/lmdb/store.ts +13 -9
- package/src/lmdb-v2/array.ts +2 -2
- package/src/lmdb-v2/factory.ts +99 -19
- package/src/lmdb-v2/map.ts +2 -2
- package/src/lmdb-v2/multi_map.ts +10 -1
- package/src/lmdb-v2/read_transaction.ts +23 -23
- package/src/lmdb-v2/singleton.ts +2 -2
- package/src/lmdb-v2/store.ts +9 -33
- package/src/lmdb-v2/tx-helpers.ts +29 -0
- package/src/lmdb-v2/utils.ts +0 -118
- package/src/lmdb-v2/write_transaction.ts +9 -8
- 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 +230 -0
- package/src/stores/l2_tips_store.ts +45 -57
- 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 -26
- package/dest/indexeddb/array.d.ts +0 -22
- package/dest/indexeddb/array.d.ts.map +0 -1
- package/dest/indexeddb/index.d.ts +0 -7
- package/dest/indexeddb/index.d.ts.map +0 -1
- package/dest/indexeddb/map.d.ts +0 -32
- package/dest/indexeddb/map.d.ts.map +0 -1
- package/dest/indexeddb/multi_map.d.ts +0 -12
- package/dest/indexeddb/multi_map.d.ts.map +0 -1
- package/dest/indexeddb/set.d.ts +0 -17
- package/dest/indexeddb/set.d.ts.map +0 -1
- package/dest/indexeddb/singleton.d.ts +0 -17
- package/dest/indexeddb/singleton.d.ts.map +0 -1
- package/dest/indexeddb/store.d.ts +0 -96
- package/dest/indexeddb/store.d.ts.map +0 -1
- package/src/config.ts +0 -36
- /package/dest/{indexeddb → deprecated/indexeddb}/set.js +0 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/// <reference lib="webworker" />
|
|
2
|
+
import sqlite3InitModule, { type Database, type SAHPoolUtil, type Sqlite3Static } from '@aztec/sqlite3mc-wasm';
|
|
3
|
+
|
|
4
|
+
import { SqliteEncryptionError, type SqliteEncryptionErrorCode, isDecryptFailureMessage } from './errors.js';
|
|
5
|
+
import type { ResultRow, SqlValue, WorkerRequest, WorkerResponse } from './messages.js';
|
|
6
|
+
|
|
7
|
+
const SCHEMA_SQL = `
|
|
8
|
+
CREATE TABLE IF NOT EXISTS data (
|
|
9
|
+
slot TEXT NOT NULL PRIMARY KEY,
|
|
10
|
+
container TEXT NOT NULL,
|
|
11
|
+
key BLOB NOT NULL,
|
|
12
|
+
key_count INTEGER NOT NULL,
|
|
13
|
+
hash TEXT NOT NULL,
|
|
14
|
+
value BLOB
|
|
15
|
+
) WITHOUT ROWID;
|
|
16
|
+
|
|
17
|
+
CREATE INDEX IF NOT EXISTS idx_container_key ON data(container, key);
|
|
18
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_container_key_count ON data(container, key, key_count);
|
|
19
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_container_key_hash ON data(container, key, hash);
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
const DEFAULT_SAH_POOL_DIRECTORY = '.aztec-kv';
|
|
23
|
+
const SAH_POOL_VFS_NAME = 'aztec-kv-opfs';
|
|
24
|
+
const MC_SAH_POOL_VFS_NAME = `multipleciphers-${SAH_POOL_VFS_NAME}`;
|
|
25
|
+
|
|
26
|
+
let sqlite3: Sqlite3Static | undefined;
|
|
27
|
+
let pool: SAHPoolUtil | undefined;
|
|
28
|
+
let db: Database | undefined;
|
|
29
|
+
let dbPath: string | undefined;
|
|
30
|
+
|
|
31
|
+
async function ensurePool(directory: string): Promise<SAHPoolUtil> {
|
|
32
|
+
const s = (sqlite3 ??= await sqlite3InitModule());
|
|
33
|
+
if (!pool) {
|
|
34
|
+
pool = await s.installOpfsSAHPoolVfs({
|
|
35
|
+
name: SAH_POOL_VFS_NAME,
|
|
36
|
+
directory,
|
|
37
|
+
initialCapacity: 8,
|
|
38
|
+
});
|
|
39
|
+
// Register a sqlite3mc-wrapped VFS pointing at our SAH Pool VFS.
|
|
40
|
+
// Encrypted DBs must be opened through this wrapper so sqlite3mc can
|
|
41
|
+
// intercept file I/O; plain DBs continue using the SAH Pool VFS directly.
|
|
42
|
+
// The wrapper name is `multipleciphers-<underlying>`.
|
|
43
|
+
(s.capi as unknown as { sqlite3mc_vfs_create(name: string, makeDefault: number): number }).sqlite3mc_vfs_create(
|
|
44
|
+
SAH_POOL_VFS_NAME,
|
|
45
|
+
0,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
return pool!;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Applies sqlite3mc's ChaCha20 page cipher using a pre-derived 32-byte key.
|
|
53
|
+
* The PRAGMAs must run before any schema DDL so sqlite3mc can decrypt existing
|
|
54
|
+
* pages and encrypt new ones. Zeroes the caller-held key array after the PRAGMA
|
|
55
|
+
* completes to minimize residency of the raw key bytes outside sqlite3mc's heap.
|
|
56
|
+
*/
|
|
57
|
+
function applyEncryptionKey(conn: Database, key: Uint8Array): void {
|
|
58
|
+
const hex = Array.from(key, b => b.toString(16).padStart(2, '0')).join('');
|
|
59
|
+
conn.exec(`PRAGMA cipher = 'chacha20'`);
|
|
60
|
+
conn.exec(`PRAGMA key = "x'${hex}'"`);
|
|
61
|
+
key.fill(0);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function handleInit(
|
|
65
|
+
dbName: string,
|
|
66
|
+
ephemeral: boolean,
|
|
67
|
+
directory?: string,
|
|
68
|
+
encryptionKey?: Uint8Array,
|
|
69
|
+
): Promise<void> {
|
|
70
|
+
const s = (sqlite3 ??= await sqlite3InitModule());
|
|
71
|
+
if (encryptionKey !== undefined && ephemeral) {
|
|
72
|
+
throw new SqliteEncryptionError(
|
|
73
|
+
'encryption_not_supported_for_ephemeral',
|
|
74
|
+
'encryptionKey is not supported for ephemeral (:memory:) stores',
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
if (ephemeral) {
|
|
78
|
+
db = new s.oo1.DB(':memory:', 'c');
|
|
79
|
+
} else {
|
|
80
|
+
const activePool = await ensurePool(directory ?? DEFAULT_SAH_POOL_DIRECTORY);
|
|
81
|
+
dbPath = normalizeDbPath(dbName);
|
|
82
|
+
if (encryptionKey !== undefined) {
|
|
83
|
+
const conn = new s.oo1.DB({ filename: dbPath, flags: 'c', vfs: MC_SAH_POOL_VFS_NAME });
|
|
84
|
+
db = conn;
|
|
85
|
+
applyEncryptionKey(conn, encryptionKey);
|
|
86
|
+
} else {
|
|
87
|
+
db = new activePool.OpfsSAHPoolDb(dbPath);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
runSql(SCHEMA_SQL);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function handleClose(): void {
|
|
94
|
+
db?.close();
|
|
95
|
+
db = undefined;
|
|
96
|
+
dbPath = undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async function handleExport(): Promise<Uint8Array> {
|
|
100
|
+
if (!db || !dbPath) {
|
|
101
|
+
throw new Error('SQLite worker: no database open to export');
|
|
102
|
+
}
|
|
103
|
+
if (!pool) {
|
|
104
|
+
throw new Error('SQLite worker: no SAH Pool available (ephemeral DBs cannot be exported)');
|
|
105
|
+
}
|
|
106
|
+
return await pool.exportFile(dbPath);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function handleDeleteDb(dbName: string): void {
|
|
110
|
+
const path = normalizeDbPath(dbName);
|
|
111
|
+
if (db && dbPath === path) {
|
|
112
|
+
db.close();
|
|
113
|
+
db = undefined;
|
|
114
|
+
dbPath = undefined;
|
|
115
|
+
}
|
|
116
|
+
// Ephemeral :memory: DBs never back a file — skip installing a pool just to unlink
|
|
117
|
+
// nothing. installOpfsSAHPoolVfs acquires an exclusive lock on the OPFS SAH
|
|
118
|
+
// directory, and under heavy test churn that can contend with workers from
|
|
119
|
+
// previous tests whose OPFS handles Chromium hasn't yet released, hanging the RPC
|
|
120
|
+
// and then the whole test run.
|
|
121
|
+
if (!pool) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
try {
|
|
125
|
+
pool.unlink(path);
|
|
126
|
+
} catch {
|
|
127
|
+
// File may not exist; ignore.
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function requireDb(): Database {
|
|
132
|
+
if (!db) {
|
|
133
|
+
throw new Error('SQLite worker: no database open');
|
|
134
|
+
}
|
|
135
|
+
return db;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function runSql(sql: string, bind?: SqlValue[]): { changes: number } {
|
|
139
|
+
const conn = requireDb();
|
|
140
|
+
conn.exec({ sql, bind });
|
|
141
|
+
return { changes: conn.changes() };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function selectAll(sql: string, bind?: SqlValue[]): ResultRow[] {
|
|
145
|
+
const conn = requireDb();
|
|
146
|
+
const rows: ResultRow[] = [];
|
|
147
|
+
conn.exec({ sql, bind, rowMode: 'array', resultRows: rows });
|
|
148
|
+
return rows;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function normalizeDbPath(dbName: string): string {
|
|
152
|
+
return dbName.startsWith('/') ? dbName : `/${dbName}`;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function respond(msg: WorkerResponse): void {
|
|
156
|
+
(self as DedicatedWorkerGlobalScope).postMessage(msg);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
(self as DedicatedWorkerGlobalScope).onmessage = async (ev: MessageEvent<WorkerRequest>) => {
|
|
160
|
+
const req = ev.data;
|
|
161
|
+
try {
|
|
162
|
+
switch (req.type) {
|
|
163
|
+
case 'init':
|
|
164
|
+
await handleInit(req.dbName, req.ephemeral, req.poolDirectory, req.encryptionKey);
|
|
165
|
+
return respond({ type: 'ok', id: req.id });
|
|
166
|
+
case 'close':
|
|
167
|
+
handleClose();
|
|
168
|
+
return respond({ type: 'ok', id: req.id });
|
|
169
|
+
case 'deleteDb':
|
|
170
|
+
handleDeleteDb(req.dbName);
|
|
171
|
+
return respond({ type: 'ok', id: req.id });
|
|
172
|
+
case 'run': {
|
|
173
|
+
const { changes } = runSql(req.sql, req.bind);
|
|
174
|
+
return respond({ type: 'ok', id: req.id, changes });
|
|
175
|
+
}
|
|
176
|
+
case 'all': {
|
|
177
|
+
const rows = selectAll(req.sql, req.bind);
|
|
178
|
+
return respond({ type: 'ok', id: req.id, rows });
|
|
179
|
+
}
|
|
180
|
+
case 'export': {
|
|
181
|
+
const bytes = await handleExport();
|
|
182
|
+
return respond({ type: 'ok', id: req.id, bytes });
|
|
183
|
+
}
|
|
184
|
+
case 'begin':
|
|
185
|
+
runSql('BEGIN');
|
|
186
|
+
return respond({ type: 'ok', id: req.id });
|
|
187
|
+
case 'commit':
|
|
188
|
+
runSql('COMMIT');
|
|
189
|
+
return respond({ type: 'ok', id: req.id });
|
|
190
|
+
case 'rollback':
|
|
191
|
+
runSql('ROLLBACK');
|
|
192
|
+
return respond({ type: 'ok', id: req.id });
|
|
193
|
+
default: {
|
|
194
|
+
const _exhaustive: never = req;
|
|
195
|
+
throw new Error(`Unknown request: ${JSON.stringify(_exhaustive)}`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
} catch (err) {
|
|
199
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
200
|
+
respond({ type: 'err', id: req.id, message, encryptionCode: detectEncryptionCode(req, err, message) });
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Maps a thrown error during request handling to a typed encryption code, so the
|
|
206
|
+
* main thread can re-hydrate it as a {@link SqliteEncryptionError}. Returns
|
|
207
|
+
* `undefined` for non-encryption errors (preserves the existing untyped path).
|
|
208
|
+
*
|
|
209
|
+
* Two sources:
|
|
210
|
+
* - The error was already a `SqliteEncryptionError` (pre-flight throws inside
|
|
211
|
+
* this worker — e.g. ephemeral + encryptionKey). Forward its code as-is.
|
|
212
|
+
* - The error came from SQLite/sqlite3mc with a known decrypt-failure message
|
|
213
|
+
* during an `init` request. Both "wrong key supplied" and "no key supplied
|
|
214
|
+
* to an encrypted DB" surface as SQLITE_NOTADB ("file is not a database") —
|
|
215
|
+
* we don't constrain on `req.encryptionKey` because the no-key-on-encrypted-DB
|
|
216
|
+
* case is exactly when the caller most needs the typed signal.
|
|
217
|
+
*/
|
|
218
|
+
function detectEncryptionCode(
|
|
219
|
+
req: WorkerRequest,
|
|
220
|
+
err: unknown,
|
|
221
|
+
message: string,
|
|
222
|
+
): SqliteEncryptionErrorCode | undefined {
|
|
223
|
+
if (err instanceof SqliteEncryptionError) {
|
|
224
|
+
return err.code;
|
|
225
|
+
}
|
|
226
|
+
if (req.type === 'init' && isDecryptFailureMessage(message)) {
|
|
227
|
+
return 'decrypt_failed';
|
|
228
|
+
}
|
|
229
|
+
return undefined;
|
|
230
|
+
}
|
|
@@ -1,79 +1,67 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
L2BlockStreamEvent,
|
|
4
|
-
L2BlockStreamEventHandler,
|
|
5
|
-
L2BlockStreamLocalDataProvider,
|
|
6
|
-
L2BlockTag,
|
|
7
|
-
L2Tips,
|
|
8
|
-
} from '@aztec/stdlib/block';
|
|
1
|
+
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { type BlockHash, type CheckpointId, type L2BlockTag, L2TipsStoreBase } from '@aztec/stdlib/block';
|
|
9
3
|
|
|
10
4
|
import type { AztecAsyncMap } from '../interfaces/map.js';
|
|
11
5
|
import type { AztecAsyncKVStore } from '../interfaces/store.js';
|
|
12
6
|
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
private readonly l2TipsStore: AztecAsyncMap<L2BlockTag, number>;
|
|
16
|
-
private readonly l2BlockHashesStore: AztecAsyncMap<number, string>;
|
|
7
|
+
/** Serialized form of a per-tip checkpoint id stored in the KV store. */
|
|
8
|
+
type StoredCheckpointId = { number: number; hash: string };
|
|
17
9
|
|
|
18
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Persistent implementation of L2 tips store backed by a KV store.
|
|
12
|
+
* Used by nodes that need to persist chain state across restarts.
|
|
13
|
+
*/
|
|
14
|
+
export class L2TipsKVStore extends L2TipsStoreBase {
|
|
15
|
+
private readonly l2TipsStore: AztecAsyncMap<L2BlockTag, BlockNumber>;
|
|
16
|
+
private readonly l2TipCheckpointsStore: AztecAsyncMap<L2BlockTag, StoredCheckpointId>;
|
|
17
|
+
private readonly l2BlockHashesStore: AztecAsyncMap<BlockNumber, string>;
|
|
18
|
+
|
|
19
|
+
constructor(
|
|
20
|
+
private store: AztecAsyncKVStore,
|
|
21
|
+
namespace: string,
|
|
22
|
+
initialBlockHash: BlockHash,
|
|
23
|
+
) {
|
|
24
|
+
super(initialBlockHash);
|
|
19
25
|
this.l2TipsStore = store.openMap([namespace, 'l2_tips'].join('_'));
|
|
26
|
+
this.l2TipCheckpointsStore = store.openMap([namespace, 'l2_tip_checkpoints'].join('_'));
|
|
20
27
|
this.l2BlockHashesStore = store.openMap([namespace, 'l2_block_hashes'].join('_'));
|
|
21
28
|
}
|
|
22
29
|
|
|
23
|
-
|
|
24
|
-
return this.
|
|
30
|
+
protected getTip(tag: L2BlockTag): Promise<BlockNumber | undefined> {
|
|
31
|
+
return this.l2TipsStore.getAsync(tag);
|
|
25
32
|
}
|
|
26
33
|
|
|
27
|
-
|
|
28
|
-
return
|
|
29
|
-
latest: await this.getL2Tip('latest'),
|
|
30
|
-
finalized: await this.getL2Tip('finalized'),
|
|
31
|
-
proven: await this.getL2Tip('proven'),
|
|
32
|
-
};
|
|
34
|
+
protected setTip(tag: L2BlockTag, blockNumber: BlockNumber): Promise<void> {
|
|
35
|
+
return this.l2TipsStore.set(tag, blockNumber);
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
if (
|
|
38
|
-
return
|
|
39
|
-
}
|
|
40
|
-
const blockHash = await this.l2BlockHashesStore.getAsync(blockNumber);
|
|
41
|
-
if (!blockHash) {
|
|
42
|
-
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
38
|
+
protected async getTipCheckpoint(tag: L2BlockTag): Promise<CheckpointId | undefined> {
|
|
39
|
+
const stored = await this.l2TipCheckpointsStore.getAsync(tag);
|
|
40
|
+
if (stored === undefined) {
|
|
41
|
+
return undefined;
|
|
43
42
|
}
|
|
43
|
+
return { number: CheckpointNumber(stored.number), hash: stored.hash };
|
|
44
|
+
}
|
|
44
45
|
|
|
45
|
-
|
|
46
|
+
protected setTipCheckpoint(tag: L2BlockTag, checkpoint: CheckpointId): Promise<void> {
|
|
47
|
+
return this.l2TipCheckpointsStore.set(tag, { number: checkpoint.number, hash: checkpoint.hash });
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
case 'blocks-added': {
|
|
51
|
-
const blocks = event.blocks.map(b => b.block);
|
|
52
|
-
for (const block of blocks) {
|
|
53
|
-
await this.l2BlockHashesStore.set(block.number, (await block.hash()).toString());
|
|
54
|
-
}
|
|
55
|
-
await this.l2TipsStore.set('latest', blocks.at(-1)!.number);
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
case 'chain-pruned':
|
|
59
|
-
await this.saveTag('latest', event.block);
|
|
60
|
-
break;
|
|
61
|
-
case 'chain-proven':
|
|
62
|
-
await this.saveTag('proven', event.block);
|
|
63
|
-
break;
|
|
64
|
-
case 'chain-finalized':
|
|
65
|
-
await this.saveTag('finalized', event.block);
|
|
66
|
-
for await (const key of this.l2BlockHashesStore.keysAsync({ end: event.block.number })) {
|
|
67
|
-
await this.l2BlockHashesStore.delete(key);
|
|
68
|
-
}
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
50
|
+
protected getStoredBlockHash(blockNumber: BlockNumber): Promise<string | undefined> {
|
|
51
|
+
return this.l2BlockHashesStore.getAsync(blockNumber);
|
|
71
52
|
}
|
|
72
53
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
54
|
+
protected setBlockHash(blockNumber: BlockNumber, hash: string): Promise<void> {
|
|
55
|
+
return this.l2BlockHashesStore.set(blockNumber, hash);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
protected async deleteBlockHashesBefore(blockNumber: BlockNumber): Promise<void> {
|
|
59
|
+
for await (const key of this.l2BlockHashesStore.keysAsync({ end: blockNumber })) {
|
|
60
|
+
await this.l2BlockHashesStore.delete(key);
|
|
77
61
|
}
|
|
78
62
|
}
|
|
63
|
+
|
|
64
|
+
protected runInTransaction<T>(fn: () => Promise<T>): Promise<T> {
|
|
65
|
+
return this.store.transactionAsync(fn);
|
|
66
|
+
}
|
|
79
67
|
}
|
package/src/utils.ts
CHANGED
|
@@ -1,40 +1,98 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
2
|
import type { Logger } from '@aztec/foundation/log';
|
|
3
|
+
import { DatabaseVersion } from '@aztec/stdlib/database-version/version';
|
|
3
4
|
|
|
4
5
|
import type { AztecAsyncSingleton, AztecSingleton } from './interfaces/singleton.js';
|
|
5
6
|
import type { AztecAsyncKVStore, AztecKVStore } from './interfaces/store.js';
|
|
6
7
|
import { isSyncStore } from './interfaces/utils.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
|
-
* Clears the store if the rollup address does not match the one stored in the database.
|
|
10
|
-
*
|
|
10
|
+
* Clears the store if the schema version or rollup address does not match the one stored in the database.
|
|
11
|
+
* Also clears if migrating from an older store format that didn't track schema version.
|
|
12
|
+
* This is to prevent data from being accidentally mixed up between different rollup instances or schema versions.
|
|
11
13
|
* @param store - The store to check
|
|
14
|
+
* @param targetSchemaVersion - The current schema version
|
|
12
15
|
* @param rollupAddress - The ETH address of the rollup contract
|
|
13
|
-
* @
|
|
16
|
+
* @param log - Optional logger
|
|
17
|
+
* @returns The store (cleared if necessary)
|
|
14
18
|
*/
|
|
15
|
-
export async function
|
|
19
|
+
export async function initStoreForRollupAndSchemaVersion<T extends AztecKVStore | AztecAsyncKVStore>(
|
|
16
20
|
store: T,
|
|
17
|
-
|
|
21
|
+
schemaVersion: number | undefined,
|
|
22
|
+
rollupAddress: EthAddress | undefined,
|
|
18
23
|
log?: Logger,
|
|
19
24
|
): Promise<T> {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
const targetSchemaVersion = schemaVersion ?? 0;
|
|
26
|
+
const targetRollupAddress = rollupAddress ?? EthAddress.ZERO;
|
|
27
|
+
const targetDatabaseVersion = new DatabaseVersion(targetSchemaVersion, targetRollupAddress);
|
|
28
|
+
|
|
29
|
+
// DB version: database schema version + rollup address combined)
|
|
30
|
+
const dbVersion = store.openSingleton<string>('dbVersion');
|
|
31
|
+
|
|
32
|
+
const storedDatabaseVersion = isSyncStore(store)
|
|
33
|
+
? (dbVersion as AztecSingleton<string>).get()
|
|
34
|
+
: await (dbVersion as AztecAsyncSingleton<string>).getAsync();
|
|
35
|
+
|
|
36
|
+
// Check if this is an old format store (has rollupAddress singleton but no dbVersion)
|
|
37
|
+
const oldRollupSingleton = store.openSingleton<string>('rollupAddress');
|
|
38
|
+
const hasOldFormat = isSyncStore(store)
|
|
39
|
+
? !storedDatabaseVersion && !!(oldRollupSingleton as AztecSingleton<string>).get()
|
|
40
|
+
: !storedDatabaseVersion && !!(await (oldRollupSingleton as AztecAsyncSingleton<string>).getAsync());
|
|
34
41
|
|
|
42
|
+
if (
|
|
43
|
+
hasOldFormat ||
|
|
44
|
+
doesStoreNeedToBeCleared(
|
|
45
|
+
targetDatabaseVersion,
|
|
46
|
+
storedDatabaseVersion,
|
|
47
|
+
targetSchemaVersion,
|
|
48
|
+
targetRollupAddress,
|
|
49
|
+
log,
|
|
50
|
+
)
|
|
51
|
+
) {
|
|
52
|
+
if (hasOldFormat) {
|
|
53
|
+
log?.warn('Detected old store format without dbVersion, clearing database');
|
|
54
|
+
}
|
|
35
55
|
await store.clear();
|
|
36
56
|
}
|
|
37
57
|
|
|
38
|
-
await
|
|
58
|
+
await dbVersion.set(targetDatabaseVersion.toBuffer().toString('utf-8'));
|
|
59
|
+
|
|
39
60
|
return store;
|
|
40
61
|
}
|
|
62
|
+
|
|
63
|
+
function doesStoreNeedToBeCleared(
|
|
64
|
+
targetDatabaseVersion: DatabaseVersion,
|
|
65
|
+
storedDatabaseVersion: string | undefined,
|
|
66
|
+
targetSchemaVersion: number,
|
|
67
|
+
targetRollupAddress: EthAddress,
|
|
68
|
+
log?: Logger,
|
|
69
|
+
) {
|
|
70
|
+
if (storedDatabaseVersion) {
|
|
71
|
+
try {
|
|
72
|
+
const storedVersion = DatabaseVersion.fromBuffer(Buffer.from(storedDatabaseVersion, 'utf-8'));
|
|
73
|
+
const cmp = storedVersion.cmp(targetDatabaseVersion);
|
|
74
|
+
|
|
75
|
+
if (cmp === undefined) {
|
|
76
|
+
log?.warn('Rollup address changed, clearing database', {
|
|
77
|
+
stored: storedVersion.rollupAddress.toString(),
|
|
78
|
+
current: targetRollupAddress.toString(),
|
|
79
|
+
});
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (cmp !== 0) {
|
|
84
|
+
log?.warn('Schema version changed, clearing database', {
|
|
85
|
+
stored: storedVersion.schemaVersion,
|
|
86
|
+
current: targetSchemaVersion,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
} catch (err) {
|
|
92
|
+
log?.warn('Failed to parse stored version, clearing database', { err });
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return false;
|
|
98
|
+
}
|
package/dest/config.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { type ConfigMappingsType } from '@aztec/foundation/config';
|
|
2
|
-
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
-
export type DataStoreConfig = {
|
|
4
|
-
dataDirectory: string | undefined;
|
|
5
|
-
dataStoreMapSizeKb: number;
|
|
6
|
-
l1Contracts?: {
|
|
7
|
-
rollupAddress: EthAddress;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
export declare const dataConfigMappings: ConfigMappingsType<DataStoreConfig>;
|
|
11
|
-
/**
|
|
12
|
-
* Returns the archiver configuration from the environment variables.
|
|
13
|
-
* Note: If an environment variable is not set, the default value is used.
|
|
14
|
-
* @returns The archiver configuration.
|
|
15
|
-
*/
|
|
16
|
-
export declare function getDataConfigFromEnv(): DataStoreConfig;
|
|
17
|
-
//# sourceMappingURL=config.d.ts.map
|
package/dest/config.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,kBAAkB,EAA6C,MAAM,0BAA0B,CAAC;AAC9G,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAEhE,MAAM,MAAM,eAAe,GAAG;IAC5B,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,WAAW,CAAC,EAAE;QAAE,aAAa,EAAE,UAAU,CAAA;KAAE,CAAC;CAC7C,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,kBAAkB,CAAC,eAAe,CAgBlE,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,oBAAoB,IAAI,eAAe,CAEtD"}
|
package/dest/config.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { l1ContractAddressesMapping } from '@aztec/ethereum/l1-contract-addresses';
|
|
2
|
-
import { getConfigFromMappings, numberConfigHelper } from '@aztec/foundation/config';
|
|
3
|
-
export const dataConfigMappings = {
|
|
4
|
-
dataDirectory: {
|
|
5
|
-
env: 'DATA_DIRECTORY',
|
|
6
|
-
description: 'Optional dir to store data. If omitted will store in memory.'
|
|
7
|
-
},
|
|
8
|
-
dataStoreMapSizeKb: {
|
|
9
|
-
env: 'DATA_STORE_MAP_SIZE_KB',
|
|
10
|
-
description: 'The maximum possible size of a data store DB in KB. Can be overridden by component-specific options.',
|
|
11
|
-
...numberConfigHelper(128 * 1_024 * 1_024)
|
|
12
|
-
},
|
|
13
|
-
l1Contracts: {
|
|
14
|
-
description: 'The deployed L1 contract addresses',
|
|
15
|
-
nested: {
|
|
16
|
-
rollupAddress: l1ContractAddressesMapping.rollupAddress
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Returns the archiver configuration from the environment variables.
|
|
22
|
-
* Note: If an environment variable is not set, the default value is used.
|
|
23
|
-
* @returns The archiver configuration.
|
|
24
|
-
*/ export function getDataConfigFromEnv() {
|
|
25
|
-
return getConfigFromMappings(dataConfigMappings);
|
|
26
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { IDBPDatabase, IDBPObjectStore } from 'idb';
|
|
2
|
-
import type { AztecAsyncArray } from '../interfaces/array.js';
|
|
3
|
-
import type { Value } from '../interfaces/common.js';
|
|
4
|
-
import type { AztecIDBSchema } from './store.js';
|
|
5
|
-
/**
|
|
6
|
-
* A persistent array backed by IndexedDB.
|
|
7
|
-
*/
|
|
8
|
-
export declare class IndexedDBAztecArray<T extends Value> implements AztecAsyncArray<T> {
|
|
9
|
-
#private;
|
|
10
|
-
constructor(rootDB: IDBPDatabase<AztecIDBSchema>, name: string);
|
|
11
|
-
set db(db: IDBPObjectStore<AztecIDBSchema, ['data'], 'data', 'readwrite'> | undefined);
|
|
12
|
-
get db(): IDBPObjectStore<AztecIDBSchema, ['data'], 'data', 'readwrite'>;
|
|
13
|
-
lengthAsync(): Promise<number>;
|
|
14
|
-
push(...vals: T[]): Promise<number>;
|
|
15
|
-
pop(): Promise<T | undefined>;
|
|
16
|
-
atAsync(index: number): Promise<T | undefined>;
|
|
17
|
-
setAt(index: number, val: T): Promise<boolean>;
|
|
18
|
-
entriesAsync(): AsyncIterableIterator<[number, T]>;
|
|
19
|
-
valuesAsync(): AsyncIterableIterator<T>;
|
|
20
|
-
[Symbol.asyncIterator](): AsyncIterableIterator<T>;
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=array.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../src/indexeddb/array.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;AAGzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;GAEG;AACH,qBAAa,mBAAmB,CAAC,CAAC,SAAS,KAAK,CAAE,YAAW,eAAe,CAAC,CAAC,CAAC;;gBAMjE,MAAM,EAAE,YAAY,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,MAAM;IAM9D,IAAI,EAAE,CAAC,EAAE,EAAE,eAAe,CAAC,cAAc,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,GAAG,SAAS,EAEpF;IAED,IAAI,EAAE,IAAI,eAAe,CAAC,cAAc,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,CAEvE;IAEK,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAQ9B,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAgBnC,GAAG,IAAI,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAa7B,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAW9C,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAsB7C,YAAY,IAAI,qBAAqB,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAQlD,WAAW,IAAI,qBAAqB,CAAC,CAAC,CAAC;IAM9C,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,qBAAqB,CAAC,CAAC,CAAC;CAOnD"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type Logger } from '@aztec/foundation/log';
|
|
2
|
-
import type { DataStoreConfig } from '../config.js';
|
|
3
|
-
import { AztecIndexedDBStore } from './store.js';
|
|
4
|
-
export { AztecIndexedDBStore } from './store.js';
|
|
5
|
-
export declare function createStore(name: string, config: DataStoreConfig, log?: Logger): Promise<AztecIndexedDBStore>;
|
|
6
|
-
export declare function openTmpStore(ephemeral?: boolean): Promise<AztecIndexedDBStore>;
|
|
7
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/indexeddb/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAElE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,GAAE,MAAiC,gCAgB9G;AAED,wBAAgB,YAAY,CAAC,SAAS,GAAE,OAAe,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAErF"}
|
package/dest/indexeddb/map.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { IDBPDatabase, IDBPObjectStore } from 'idb';
|
|
2
|
-
import type { Key, Range, Value } from '../interfaces/common.js';
|
|
3
|
-
import type { AztecAsyncMap } from '../interfaces/map.js';
|
|
4
|
-
import type { AztecIDBSchema } from './store.js';
|
|
5
|
-
/**
|
|
6
|
-
* A map backed by IndexedDB.
|
|
7
|
-
*/
|
|
8
|
-
export declare class IndexedDBAztecMap<K extends Key, V extends Value> implements AztecAsyncMap<K, V> {
|
|
9
|
-
#private;
|
|
10
|
-
protected name: string;
|
|
11
|
-
protected container: string;
|
|
12
|
-
constructor(rootDB: IDBPDatabase<AztecIDBSchema>, mapName: string);
|
|
13
|
-
set db(db: IDBPObjectStore<AztecIDBSchema, ['data'], 'data', 'readwrite'> | undefined);
|
|
14
|
-
get db(): IDBPObjectStore<AztecIDBSchema, ['data'], 'data', 'readwrite'>;
|
|
15
|
-
getAsync(key: K): Promise<V | undefined>;
|
|
16
|
-
hasAsync(key: K): Promise<boolean>;
|
|
17
|
-
sizeAsync(): Promise<number>;
|
|
18
|
-
set(key: K, val: V): Promise<void>;
|
|
19
|
-
setMany(entries: {
|
|
20
|
-
key: K;
|
|
21
|
-
value: V;
|
|
22
|
-
}[]): Promise<void>;
|
|
23
|
-
swap(_key: K, _fn: (val: V | undefined) => V): Promise<void>;
|
|
24
|
-
setIfNotExists(key: K, val: V): Promise<boolean>;
|
|
25
|
-
delete(key: K): Promise<void>;
|
|
26
|
-
entriesAsync(range?: Range<K>): AsyncIterableIterator<[K, V]>;
|
|
27
|
-
valuesAsync(range?: Range<K>): AsyncIterableIterator<V>;
|
|
28
|
-
keysAsync(range?: Range<K>): AsyncIterableIterator<K>;
|
|
29
|
-
protected normalizeKey(key: K): string;
|
|
30
|
-
protected slot(key: K, index?: number): string;
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=map.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/indexeddb/map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;AAGzD,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;GAEG;AACH,qBAAa,iBAAiB,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC,SAAS,KAAK,CAAE,YAAW,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC;;IAC3F,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC;gBAKhB,MAAM,EAAE,YAAY,CAAC,cAAc,CAAC,EAAE,OAAO,EAAE,MAAM;IAMjE,IAAI,EAAE,CAAC,EAAE,EAAE,eAAe,CAAC,cAAc,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,GAAG,SAAS,EAEpF;IAED,IAAI,EAAE,IAAI,eAAe,CAAC,cAAc,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,CAEvE;IAEK,QAAQ,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAKxC,QAAQ,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAKlC,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IAM5B,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAWlC,OAAO,CAAC,OAAO,EAAE;QAAE,GAAG,EAAE,CAAC,CAAC;QAAC,KAAK,EAAE,CAAC,CAAA;KAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAM7D,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,SAAS,KAAK,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAItD,cAAc,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAQhD,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5B,YAAY,CAAC,KAAK,GAAE,KAAK,CAAC,CAAC,CAAM,GAAG,qBAAqB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAkBjE,WAAW,CAAC,KAAK,GAAE,KAAK,CAAC,CAAC,CAAM,GAAG,qBAAqB,CAAC,CAAC,CAAC;IAM3D,SAAS,CAAC,KAAK,GAAE,KAAK,CAAC,CAAC,CAAM,GAAG,qBAAqB,CAAC,CAAC,CAAC;IAWhE,SAAS,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,GAAG,MAAM;IAKtC,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,GAAE,MAAU,GAAG,MAAM;CAGlD"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Key, Value } from '../interfaces/common.js';
|
|
2
|
-
import type { AztecAsyncMultiMap } from '../interfaces/multi_map.js';
|
|
3
|
-
import { IndexedDBAztecMap } from './map.js';
|
|
4
|
-
/**
|
|
5
|
-
* A multi map backed by IndexedDB.
|
|
6
|
-
*/
|
|
7
|
-
export declare class IndexedDBAztecMultiMap<K extends Key, V extends Value> extends IndexedDBAztecMap<K, V> implements AztecAsyncMultiMap<K, V> {
|
|
8
|
-
set(key: K, val: V): Promise<void>;
|
|
9
|
-
getValuesAsync(key: K): AsyncIterableIterator<V>;
|
|
10
|
-
deleteValue(key: K, val: V): Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=multi_map.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"multi_map.d.ts","sourceRoot":"","sources":["../../src/indexeddb/multi_map.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C;;GAEG;AACH,qBAAa,sBAAsB,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC,SAAS,KAAK,CAChE,SAAQ,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAC9B,YAAW,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC;IAEpB,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAoC1C,cAAc,CAAC,GAAG,EAAE,CAAC,GAAG,qBAAqB,CAAC,CAAC,CAAC;IAcjD,WAAW,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAejD"}
|
package/dest/indexeddb/set.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { IDBPDatabase, IDBPObjectStore } from 'idb';
|
|
2
|
-
import type { Key, Range } from '../interfaces/common.js';
|
|
3
|
-
import type { AztecAsyncSet } from '../interfaces/set.js';
|
|
4
|
-
import type { AztecIDBSchema } from './store.js';
|
|
5
|
-
/**
|
|
6
|
-
* A set backed by IndexedDB.
|
|
7
|
-
*/
|
|
8
|
-
export declare class IndexedDBAztecSet<K extends Key> implements AztecAsyncSet<K> {
|
|
9
|
-
private map;
|
|
10
|
-
constructor(rootDb: IDBPDatabase<AztecIDBSchema>, mapName: string);
|
|
11
|
-
set db(db: IDBPObjectStore<AztecIDBSchema, ['data'], 'data', 'readwrite'> | undefined);
|
|
12
|
-
hasAsync(key: K): Promise<boolean>;
|
|
13
|
-
add(key: K): Promise<void>;
|
|
14
|
-
delete(key: K): Promise<void>;
|
|
15
|
-
entriesAsync(range?: Range<K>): AsyncIterableIterator<K>;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=set.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"set.d.ts","sourceRoot":"","sources":["../../src/indexeddb/set.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;AAEzD,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;GAEG;AACH,qBAAa,iBAAiB,CAAC,CAAC,SAAS,GAAG,CAAE,YAAW,aAAa,CAAC,CAAC,CAAC;IACvE,OAAO,CAAC,GAAG,CAAgC;gBAE/B,MAAM,EAAE,YAAY,CAAC,cAAc,CAAC,EAAE,OAAO,EAAE,MAAM;IAIjE,IAAI,EAAE,CAAC,EAAE,EAAE,eAAe,CAAC,cAAc,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,GAAG,SAAS,EAEpF;IAED,QAAQ,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAIlC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1B,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAItB,YAAY,CAAC,KAAK,GAAE,KAAK,CAAC,CAAC,CAAM,GAAG,qBAAqB,CAAC,CAAC,CAAC;CAGpE"}
|