@aztec/kv-store 0.0.1-commit.9ef841308 → 0.0.1-commit.a5db02d

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.
Files changed (137) hide show
  1. package/README.md +10 -1
  2. package/dest/bench/shared_map_bench.d.ts +19 -0
  3. package/dest/bench/shared_map_bench.d.ts.map +1 -0
  4. package/dest/bench/shared_map_bench.js +91 -0
  5. package/dest/deprecated/indexeddb/array.d.ts +22 -0
  6. package/dest/deprecated/indexeddb/array.d.ts.map +1 -0
  7. package/dest/deprecated/indexeddb/index.d.ts +7 -0
  8. package/dest/deprecated/indexeddb/index.d.ts.map +1 -0
  9. package/dest/deprecated/indexeddb/index.js +8 -0
  10. package/dest/deprecated/indexeddb/map.d.ts +38 -0
  11. package/dest/deprecated/indexeddb/map.d.ts.map +1 -0
  12. package/dest/deprecated/indexeddb/multi_map.d.ts +14 -0
  13. package/dest/deprecated/indexeddb/multi_map.d.ts.map +1 -0
  14. package/dest/deprecated/indexeddb/set.d.ts +17 -0
  15. package/dest/deprecated/indexeddb/set.d.ts.map +1 -0
  16. package/dest/deprecated/indexeddb/singleton.d.ts +17 -0
  17. package/dest/deprecated/indexeddb/singleton.d.ts.map +1 -0
  18. package/dest/deprecated/indexeddb/store.d.ts +98 -0
  19. package/dest/deprecated/indexeddb/store.d.ts.map +1 -0
  20. package/dest/{indexeddb → deprecated/indexeddb}/store.js +2 -0
  21. package/dest/interfaces/array_test_suite.d.ts +1 -1
  22. package/dest/interfaces/array_test_suite.d.ts.map +1 -1
  23. package/dest/interfaces/array_test_suite.js +33 -34
  24. package/dest/interfaces/index.d.ts +2 -2
  25. package/dest/interfaces/index.d.ts.map +1 -1
  26. package/dest/interfaces/map_test_suite.d.ts +1 -1
  27. package/dest/interfaces/map_test_suite.d.ts.map +1 -1
  28. package/dest/interfaces/map_test_suite.js +32 -33
  29. package/dest/interfaces/multi_map_test_suite.d.ts +1 -1
  30. package/dest/interfaces/multi_map_test_suite.d.ts.map +1 -1
  31. package/dest/interfaces/multi_map_test_suite.js +68 -69
  32. package/dest/interfaces/set_test_suite.d.ts +1 -1
  33. package/dest/interfaces/set_test_suite.d.ts.map +1 -1
  34. package/dest/interfaces/set_test_suite.js +13 -14
  35. package/dest/interfaces/singleton_test_suite.d.ts +1 -1
  36. package/dest/interfaces/singleton_test_suite.d.ts.map +1 -1
  37. package/dest/interfaces/singleton_test_suite.js +6 -7
  38. package/dest/lmdb/index.js +2 -2
  39. package/dest/lmdb-v2/factory.d.ts +29 -3
  40. package/dest/lmdb-v2/factory.d.ts.map +1 -1
  41. package/dest/lmdb-v2/factory.js +62 -10
  42. package/dest/lmdb-v2/read_transaction.js +21 -19
  43. package/dest/lmdb-v2/store.d.ts +2 -2
  44. package/dest/lmdb-v2/store.d.ts.map +1 -1
  45. package/dest/lmdb-v2/store.js +4 -4
  46. package/dest/sqlite-opfs/array.d.ts +21 -0
  47. package/dest/sqlite-opfs/array.d.ts.map +1 -0
  48. package/dest/sqlite-opfs/array.js +128 -0
  49. package/dest/sqlite-opfs/errors.d.ts +27 -0
  50. package/dest/sqlite-opfs/errors.d.ts.map +1 -0
  51. package/dest/sqlite-opfs/errors.js +34 -0
  52. package/dest/sqlite-opfs/index.d.ts +14 -0
  53. package/dest/sqlite-opfs/index.d.ts.map +1 -0
  54. package/dest/sqlite-opfs/index.js +16 -0
  55. package/dest/sqlite-opfs/internal/ordered-binary-browser.d.ts +32 -0
  56. package/dest/sqlite-opfs/internal/ordered-binary-browser.d.ts.map +1 -0
  57. package/dest/sqlite-opfs/internal/ordered-binary-browser.js +448 -0
  58. package/dest/sqlite-opfs/manage.d.ts +20 -0
  59. package/dest/sqlite-opfs/manage.d.ts.map +1 -0
  60. package/dest/sqlite-opfs/manage.js +31 -0
  61. package/dest/sqlite-opfs/map.d.ts +35 -0
  62. package/dest/sqlite-opfs/map.d.ts.map +1 -0
  63. package/dest/sqlite-opfs/map.js +163 -0
  64. package/dest/sqlite-opfs/messages.d.ts +66 -0
  65. package/dest/sqlite-opfs/messages.d.ts.map +1 -0
  66. package/dest/sqlite-opfs/messages.js +5 -0
  67. package/dest/sqlite-opfs/multi_map.d.ts +16 -0
  68. package/dest/sqlite-opfs/multi_map.d.ts.map +1 -0
  69. package/dest/sqlite-opfs/multi_map.js +67 -0
  70. package/dest/sqlite-opfs/set.d.ts +13 -0
  71. package/dest/sqlite-opfs/set.d.ts.map +1 -0
  72. package/dest/sqlite-opfs/set.js +19 -0
  73. package/dest/sqlite-opfs/singleton.d.ts +13 -0
  74. package/dest/sqlite-opfs/singleton.d.ts.map +1 -0
  75. package/dest/sqlite-opfs/singleton.js +48 -0
  76. package/dest/sqlite-opfs/store.d.ts +79 -0
  77. package/dest/sqlite-opfs/store.d.ts.map +1 -0
  78. package/dest/sqlite-opfs/store.js +281 -0
  79. package/dest/sqlite-opfs/worker.d.ts +2 -0
  80. package/dest/sqlite-opfs/worker.d.ts.map +1 -0
  81. package/dest/sqlite-opfs/worker.js +264 -0
  82. package/dest/stores/l2_tips_store.d.ts +7 -13
  83. package/dest/stores/l2_tips_store.d.ts.map +1 -1
  84. package/dest/stores/l2_tips_store.js +24 -43
  85. package/package.json +23 -20
  86. package/src/bench/shared_map_bench.ts +111 -0
  87. package/src/{indexeddb → deprecated/indexeddb}/array.ts +2 -2
  88. package/src/deprecated/indexeddb/index.ts +12 -0
  89. package/src/{indexeddb → deprecated/indexeddb}/map.ts +2 -2
  90. package/src/{indexeddb → deprecated/indexeddb}/multi_map.ts +2 -2
  91. package/src/{indexeddb → deprecated/indexeddb}/set.ts +2 -2
  92. package/src/{indexeddb → deprecated/indexeddb}/singleton.ts +2 -2
  93. package/src/{indexeddb → deprecated/indexeddb}/store.ts +10 -9
  94. package/src/interfaces/array_test_suite.ts +33 -35
  95. package/src/interfaces/index.ts +1 -1
  96. package/src/interfaces/map_test_suite.ts +32 -34
  97. package/src/interfaces/multi_map_test_suite.ts +65 -67
  98. package/src/interfaces/set_test_suite.ts +13 -15
  99. package/src/interfaces/singleton_test_suite.ts +6 -8
  100. package/src/lmdb/index.ts +2 -2
  101. package/src/lmdb-v2/factory.ts +85 -9
  102. package/src/lmdb-v2/read_transaction.ts +23 -23
  103. package/src/lmdb-v2/store.ts +4 -2
  104. package/src/sqlite-opfs/array.ts +124 -0
  105. package/src/sqlite-opfs/errors.ts +44 -0
  106. package/src/sqlite-opfs/index.ts +22 -0
  107. package/src/sqlite-opfs/internal/ordered-binary-browser.js +465 -0
  108. package/src/sqlite-opfs/manage.ts +36 -0
  109. package/src/sqlite-opfs/map.ts +163 -0
  110. package/src/sqlite-opfs/messages.ts +39 -0
  111. package/src/sqlite-opfs/multi_map.ts +74 -0
  112. package/src/sqlite-opfs/set.ts +29 -0
  113. package/src/sqlite-opfs/singleton.ts +48 -0
  114. package/src/sqlite-opfs/store.ts +296 -0
  115. package/src/sqlite-opfs/worker.ts +248 -0
  116. package/src/stores/l2_tips_store.ts +20 -41
  117. package/dest/indexeddb/array.d.ts +0 -22
  118. package/dest/indexeddb/array.d.ts.map +0 -1
  119. package/dest/indexeddb/index.d.ts +0 -7
  120. package/dest/indexeddb/index.d.ts.map +0 -1
  121. package/dest/indexeddb/index.js +0 -16
  122. package/dest/indexeddb/map.d.ts +0 -38
  123. package/dest/indexeddb/map.d.ts.map +0 -1
  124. package/dest/indexeddb/multi_map.d.ts +0 -14
  125. package/dest/indexeddb/multi_map.d.ts.map +0 -1
  126. package/dest/indexeddb/set.d.ts +0 -17
  127. package/dest/indexeddb/set.d.ts.map +0 -1
  128. package/dest/indexeddb/singleton.d.ts +0 -17
  129. package/dest/indexeddb/singleton.d.ts.map +0 -1
  130. package/dest/indexeddb/store.d.ts +0 -96
  131. package/dest/indexeddb/store.d.ts.map +0 -1
  132. package/src/indexeddb/index.ts +0 -31
  133. /package/dest/{indexeddb → deprecated/indexeddb}/array.js +0 -0
  134. /package/dest/{indexeddb → deprecated/indexeddb}/map.js +0 -0
  135. /package/dest/{indexeddb → deprecated/indexeddb}/multi_map.js +0 -0
  136. /package/dest/{indexeddb → deprecated/indexeddb}/set.js +0 -0
  137. /package/dest/{indexeddb → deprecated/indexeddb}/singleton.js +0 -0
@@ -1,31 +1,26 @@
1
+ import { CheckpointNumber } from '@aztec/foundation/branded-types';
1
2
  import { L2TipsStoreBase } from '@aztec/stdlib/block';
2
- import { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
3
3
  /**
4
4
  * Persistent implementation of L2 tips store backed by a KV store.
5
5
  * Used by nodes that need to persist chain state across restarts.
6
6
  */ export class L2TipsKVStore extends L2TipsStoreBase {
7
7
  store;
8
8
  l2TipsStore;
9
+ l2TipCheckpointsStore;
9
10
  l2BlockHashesStore;
10
- l2BlockNumberToCheckpointNumberStore;
11
- l2CheckpointStore;
12
- constructor(store, namespace){
13
- super(), this.store = store;
11
+ constructor(store, namespace, initialBlockHash){
12
+ super(initialBlockHash), this.store = store;
14
13
  this.l2TipsStore = store.openMap([
15
14
  namespace,
16
15
  'l2_tips'
17
16
  ].join('_'));
18
- this.l2BlockHashesStore = store.openMap([
19
- namespace,
20
- 'l2_block_hashes'
21
- ].join('_'));
22
- this.l2BlockNumberToCheckpointNumberStore = store.openMap([
17
+ this.l2TipCheckpointsStore = store.openMap([
23
18
  namespace,
24
- 'l2_block_number_to_checkpoint_number'
19
+ 'l2_tip_checkpoints'
25
20
  ].join('_'));
26
- this.l2CheckpointStore = store.openMap([
21
+ this.l2BlockHashesStore = store.openMap([
27
22
  namespace,
28
- 'l2_checkpoint_store'
23
+ 'l2_block_hashes'
29
24
  ].join('_'));
30
25
  }
31
26
  getTip(tag) {
@@ -34,6 +29,22 @@ import { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
34
29
  setTip(tag, blockNumber) {
35
30
  return this.l2TipsStore.set(tag, blockNumber);
36
31
  }
32
+ async getTipCheckpoint(tag) {
33
+ const stored = await this.l2TipCheckpointsStore.getAsync(tag);
34
+ if (stored === undefined) {
35
+ return undefined;
36
+ }
37
+ return {
38
+ number: CheckpointNumber(stored.number),
39
+ hash: stored.hash
40
+ };
41
+ }
42
+ setTipCheckpoint(tag, checkpoint) {
43
+ return this.l2TipCheckpointsStore.set(tag, {
44
+ number: checkpoint.number,
45
+ hash: checkpoint.hash
46
+ });
47
+ }
37
48
  getStoredBlockHash(blockNumber) {
38
49
  return this.l2BlockHashesStore.getAsync(blockNumber);
39
50
  }
@@ -47,36 +58,6 @@ import { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
47
58
  await this.l2BlockHashesStore.delete(key);
48
59
  }
49
60
  }
50
- getCheckpointNumberForBlock(blockNumber) {
51
- return this.l2BlockNumberToCheckpointNumberStore.getAsync(blockNumber);
52
- }
53
- setCheckpointNumberForBlock(blockNumber, checkpointNumber) {
54
- return this.l2BlockNumberToCheckpointNumberStore.set(blockNumber, checkpointNumber);
55
- }
56
- async deleteBlockToCheckpointBefore(blockNumber) {
57
- for await (const key of this.l2BlockNumberToCheckpointNumberStore.keysAsync({
58
- end: blockNumber
59
- })){
60
- await this.l2BlockNumberToCheckpointNumberStore.delete(key);
61
- }
62
- }
63
- async getCheckpoint(checkpointNumber) {
64
- const buffer = await this.l2CheckpointStore.getAsync(checkpointNumber);
65
- if (!buffer) {
66
- return undefined;
67
- }
68
- return PublishedCheckpoint.fromBuffer(buffer);
69
- }
70
- saveCheckpointData(checkpoint) {
71
- return this.l2CheckpointStore.set(checkpoint.checkpoint.number, checkpoint.toBuffer());
72
- }
73
- async deleteCheckpointsBefore(checkpointNumber) {
74
- for await (const key of this.l2CheckpointStore.keysAsync({
75
- end: checkpointNumber
76
- })){
77
- await this.l2CheckpointStore.delete(key);
78
- }
79
- }
80
61
  runInTransaction(fn) {
81
62
  return this.store.transactionAsync(fn);
82
63
  }
package/package.json CHANGED
@@ -1,22 +1,34 @@
1
1
  {
2
2
  "name": "@aztec/kv-store",
3
- "version": "0.0.1-commit.9ef841308",
3
+ "version": "0.0.1-commit.a5db02d",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/interfaces/index.js",
7
7
  "./interfaces": "./dest/interfaces/index.js",
8
8
  "./lmdb": "./dest/lmdb/index.js",
9
9
  "./lmdb-v2": "./dest/lmdb-v2/index.js",
10
- "./indexeddb": "./dest/indexeddb/index.js",
10
+ "./deprecated/indexeddb": "./dest/deprecated/indexeddb/index.js",
11
+ "./sqlite-opfs": "./dest/sqlite-opfs/index.js",
11
12
  "./stores": "./dest/stores/index.js"
12
13
  },
14
+ "imports": {
15
+ "#msgpackr": {
16
+ "browser": "msgpackr/index-no-eval",
17
+ "default": "msgpackr"
18
+ },
19
+ "#ordered-binary": {
20
+ "browser": "./dest/sqlite-opfs/internal/ordered-binary-browser.js",
21
+ "default": "ordered-binary"
22
+ }
23
+ },
13
24
  "scripts": {
14
25
  "build": "yarn clean && ../scripts/tsc.sh",
15
26
  "build:dev": "../scripts/tsc.sh --watch",
16
27
  "clean": "rm -rf ./dest .tsbuildinfo",
17
- "test:node": "NODE_NO_WARNINGS=1 mocha --config ./.mocharc.json",
18
- "test:browser": "vitest run --config ./vitest.config.ts",
19
- "test": "yarn test:node && yarn test:browser",
28
+ "test:node": "vitest run --project node",
29
+ "test:browser": "bash scripts/run-browser-tests.sh",
30
+ "bench:browser": "VITE_BENCH=1 vitest run --project browser src/bench",
31
+ "test": "vitest run",
20
32
  "test:jest": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
21
33
  },
22
34
  "inherits": [
@@ -24,11 +36,12 @@
24
36
  "./package.local.json"
25
37
  ],
26
38
  "dependencies": {
27
- "@aztec/constants": "0.0.1-commit.9ef841308",
28
- "@aztec/ethereum": "0.0.1-commit.9ef841308",
29
- "@aztec/foundation": "0.0.1-commit.9ef841308",
30
- "@aztec/native": "0.0.1-commit.9ef841308",
31
- "@aztec/stdlib": "0.0.1-commit.9ef841308",
39
+ "@aztec/constants": "0.0.1-commit.a5db02d",
40
+ "@aztec/ethereum": "0.0.1-commit.a5db02d",
41
+ "@aztec/foundation": "0.0.1-commit.a5db02d",
42
+ "@aztec/native": "0.0.1-commit.a5db02d",
43
+ "@aztec/sqlite3mc-wasm": "0.0.1-commit.a5db02d",
44
+ "@aztec/stdlib": "0.0.1-commit.a5db02d",
32
45
  "idb": "^8.0.0",
33
46
  "lmdb": "^3.2.0",
34
47
  "msgpackr": "^1.11.2",
@@ -37,23 +50,13 @@
37
50
  },
38
51
  "devDependencies": {
39
52
  "@jest/globals": "^30.0.0",
40
- "@types/chai": "^5.0.1",
41
- "@types/chai-as-promised": "^8.0.1",
42
53
  "@types/jest": "^30.0.0",
43
- "@types/mocha": "^10.0.10",
44
- "@types/mocha-each": "^2.0.4",
45
54
  "@types/node": "^22.15.17",
46
- "@types/sinon": "^17.0.3",
47
55
  "@typescript/native-preview": "7.0.0-dev.20260113.1",
48
56
  "@vitest/browser-playwright": "^4.0.0",
49
57
  "buffer": "^6.0.3",
50
- "chai": "^5.1.2",
51
- "chai-as-promised": "^8.0.1",
52
58
  "jest": "^30.0.0",
53
- "mocha": "^10.8.2",
54
- "mocha-each": "^2.0.1",
55
59
  "playwright": "1.49.0",
56
- "sinon": "^19.0.2",
57
60
  "ts-node": "^10.9.1",
58
61
  "typescript": "^5.3.3",
59
62
  "util": "^0.12.5",
@@ -0,0 +1,111 @@
1
+ import type { Logger } from '@aztec/foundation/log';
2
+ import { Timer } from '@aztec/foundation/timer';
3
+
4
+ import type { Key } from '../interfaces/common.js';
5
+ import type { AztecAsyncMap } from '../interfaces/map.js';
6
+ import type { AztecAsyncKVStore } from '../interfaces/store.js';
7
+
8
+ /** One benchmark measurement. */
9
+ export type BenchResult = {
10
+ /** Benchmark name (includes the backend prefix for disambiguation). */
11
+ name: string;
12
+ value: number;
13
+ unit: 'ms' | 'us';
14
+ };
15
+
16
+ export type BenchReporter = (results: BenchResult[]) => void | Promise<void>;
17
+
18
+ /**
19
+ * Runs the standard Map benchmark suite against any `AztecAsyncKVStore` backend,
20
+ * populates `results`, and calls `reporter` in `afterAll`.
21
+ *
22
+ * Kept free of Node-only deps (`fs`, `path`) so the same runner works under
23
+ * vitest-browser for IndexedDB and SQLite-OPFS.
24
+ */
25
+ export function describeAztecMapBench(
26
+ backendPrefix: string,
27
+ getStore: () => Promise<AztecAsyncKVStore>,
28
+ logger: Logger,
29
+ reporter: BenchReporter,
30
+ ) {
31
+ describe(`${backendPrefix} Map benchmarks`, () => {
32
+ let store: AztecAsyncKVStore;
33
+ let map: AztecAsyncMap<Key, string>;
34
+
35
+ const results: BenchResult[] = [];
36
+
37
+ const generateKeyValuePairs = (count: number, offset = 0) => {
38
+ const keys = Array.from({ length: count }, (_, i) => `key-${i + offset}`);
39
+ const values = Array.from({ length: count }, (_, i) => `value-${i + offset}`);
40
+ return keys.map((key, i) => ({ key, value: values[i] }));
41
+ };
42
+
43
+ const record = (name: string, value: number, unit: BenchResult['unit']) => {
44
+ results.push({ name: `${backendPrefix}/Map/${name}`, value, unit });
45
+ };
46
+
47
+ beforeEach(async () => {
48
+ store = await getStore();
49
+ map = store.openMap<Key, string>('test');
50
+ });
51
+
52
+ afterEach(async () => {
53
+ await store.delete();
54
+ });
55
+
56
+ afterAll(async () => {
57
+ const pretty = results.map(r => `${r.name}: ${r.value.toFixed(2)} ${r.unit}`).join('\n');
58
+ logger.info(`\n${pretty}\n`);
59
+ await reporter(results);
60
+ });
61
+
62
+ it('adds individual values', async () => {
63
+ const pairs = generateKeyValuePairs(1000);
64
+ const timer = new Timer();
65
+ for (const pair of pairs) {
66
+ await map.set(pair.key, pair.value);
67
+ }
68
+ record('Individual insertion', timer.ms() / pairs.length, 'ms');
69
+ });
70
+
71
+ it('adds batched values', async () => {
72
+ const batches = Array.from({ length: 100 }, (_, i) => generateKeyValuePairs(1000, i * 1000));
73
+ const timer = new Timer();
74
+ for (const batch of batches) {
75
+ await map.setMany(batch);
76
+ }
77
+ record(`Batch insertion of ${batches[0].length} items`, timer.ms() / batches.length, 'ms');
78
+ });
79
+
80
+ it('reads individual values', async () => {
81
+ const pairs = generateKeyValuePairs(10000);
82
+ await map.setMany(pairs);
83
+ const timer = new Timer();
84
+ for (const pair of pairs) {
85
+ await map.getAsync(pair.key);
86
+ }
87
+ record('Individual read', (timer.ms() * 1000) / pairs.length, 'us');
88
+ });
89
+
90
+ it('reads via a cursor', async () => {
91
+ const pairs = generateKeyValuePairs(10000);
92
+ await map.setMany(pairs);
93
+ const timer = new Timer();
94
+ for await (const _ of map.entriesAsync()) {
95
+ // consume
96
+ }
97
+ record(`Iterator per item read of ${pairs.length} items`, (timer.ms() * 1000) / pairs.length, 'us');
98
+ });
99
+
100
+ it('reads the size of the map', async () => {
101
+ const numIterations = 1000;
102
+ const pairs = generateKeyValuePairs(10000);
103
+ await map.setMany(pairs);
104
+ const timer = new Timer();
105
+ for (let i = 0; i < numIterations; i++) {
106
+ await map.sizeAsync();
107
+ }
108
+ record(`Read size of ${pairs.length} items`, (timer.ms() * 1000) / numIterations, 'us');
109
+ });
110
+ });
111
+ }
@@ -1,8 +1,8 @@
1
1
  import type { IDBPDatabase, IDBPObjectStore } from 'idb';
2
2
  import { hash } from 'ohash';
3
3
 
4
- import type { AztecAsyncArray } from '../interfaces/array.js';
5
- import type { Value } from '../interfaces/common.js';
4
+ import type { AztecAsyncArray } from '../../interfaces/array.js';
5
+ import type { Value } from '../../interfaces/common.js';
6
6
  import type { AztecIDBSchema } from './store.js';
7
7
 
8
8
  /**
@@ -0,0 +1,12 @@
1
+ import { createLogger } from '@aztec/foundation/log';
2
+
3
+ import { AztecIndexedDBStore } from './store.js';
4
+
5
+ export { AztecIndexedDBStore } from './store.js';
6
+
7
+ /**
8
+ * @deprecated The IndexedDB backend is being retired. Use `@aztec/kv-store/sqlite-opfs` instead.
9
+ */
10
+ export function openTmpStore(ephemeral: boolean = false): Promise<AztecIndexedDBStore> {
11
+ return AztecIndexedDBStore.open(createLogger('kv-store:indexeddb'), undefined, ephemeral);
12
+ }
@@ -1,8 +1,8 @@
1
1
  import type { IDBPDatabase, IDBPObjectStore } from 'idb';
2
2
  import { hash } from 'ohash';
3
3
 
4
- import type { Key, Range, Value } from '../interfaces/common.js';
5
- import type { AztecAsyncMap } from '../interfaces/map.js';
4
+ import type { Key, Range, Value } from '../../interfaces/common.js';
5
+ import type { AztecAsyncMap } from '../../interfaces/map.js';
6
6
  import type { AztecIDBSchema } from './store.js';
7
7
 
8
8
  /**
@@ -1,7 +1,7 @@
1
1
  import { hash } from 'ohash';
2
2
 
3
- import type { Key, Value } from '../interfaces/common.js';
4
- import type { AztecAsyncMultiMap } from '../interfaces/multi_map.js';
3
+ import type { Key, Value } from '../../interfaces/common.js';
4
+ import type { AztecAsyncMultiMap } from '../../interfaces/multi_map.js';
5
5
  import { IndexedDBAztecMap } from './map.js';
6
6
 
7
7
  /**
@@ -1,7 +1,7 @@
1
1
  import type { IDBPDatabase, IDBPObjectStore } from 'idb';
2
2
 
3
- import type { Key, Range } from '../interfaces/common.js';
4
- import type { AztecAsyncSet } from '../interfaces/set.js';
3
+ import type { Key, Range } from '../../interfaces/common.js';
4
+ import type { AztecAsyncSet } from '../../interfaces/set.js';
5
5
  import { IndexedDBAztecMap } from './map.js';
6
6
  import type { AztecIDBSchema } from './store.js';
7
7
 
@@ -1,8 +1,8 @@
1
1
  import type { IDBPDatabase, IDBPObjectStore } from 'idb';
2
2
  import { hash } from 'ohash';
3
3
 
4
- import type { Value } from '../interfaces/common.js';
5
- import type { AztecAsyncSingleton } from '../interfaces/singleton.js';
4
+ import type { Value } from '../../interfaces/common.js';
5
+ import type { AztecAsyncSingleton } from '../../interfaces/singleton.js';
6
6
  import type { AztecIDBSchema } from './store.js';
7
7
 
8
8
  /**
@@ -3,14 +3,14 @@ import { SerialQueue } from '@aztec/foundation/queue';
3
3
 
4
4
  import { type DBSchema, type IDBPDatabase, deleteDB, openDB } from 'idb';
5
5
 
6
- import type { AztecAsyncArray } from '../interfaces/array.js';
7
- import type { Key, StoreSize, Value } from '../interfaces/common.js';
8
- import type { AztecAsyncCounter } from '../interfaces/counter.js';
9
- import type { AztecAsyncMap } from '../interfaces/map.js';
10
- import type { AztecAsyncMultiMap } from '../interfaces/multi_map.js';
11
- import type { AztecAsyncSet } from '../interfaces/set.js';
12
- import type { AztecAsyncSingleton } from '../interfaces/singleton.js';
13
- import type { AztecAsyncKVStore } from '../interfaces/store.js';
6
+ import type { AztecAsyncArray } from '../../interfaces/array.js';
7
+ import type { Key, StoreSize, Value } from '../../interfaces/common.js';
8
+ import type { AztecAsyncCounter } from '../../interfaces/counter.js';
9
+ import type { AztecAsyncMap } from '../../interfaces/map.js';
10
+ import type { AztecAsyncMultiMap } from '../../interfaces/multi_map.js';
11
+ import type { AztecAsyncSet } from '../../interfaces/set.js';
12
+ import type { AztecAsyncSingleton } from '../../interfaces/singleton.js';
13
+ import type { AztecAsyncKVStore } from '../../interfaces/store.js';
14
14
  import { IndexedDBAztecArray } from './array.js';
15
15
  import { IndexedDBAztecMap } from './map.js';
16
16
  import { IndexedDBAztecMultiMap } from './multi_map.js';
@@ -41,8 +41,9 @@ export interface AztecIDBSchema extends DBSchema {
41
41
 
42
42
  /**
43
43
  * A key-value store backed by IndexedDB.
44
+ *
45
+ * @deprecated The IndexedDB backend is being retired. Use `@aztec/kv-store/sqlite-opfs` instead.
44
46
  */
45
-
46
47
  export class AztecIndexedDBStore implements AztecAsyncKVStore {
47
48
  #rootDB: IDBPDatabase<AztecIDBSchema>;
48
49
  #name: string;
@@ -1,7 +1,5 @@
1
1
  import { toArray } from '@aztec/foundation/iterable';
2
2
 
3
- import { expect } from 'chai';
4
-
5
3
  import type { AztecArray, AztecAsyncArray } from './array.js';
6
4
  import type { AztecAsyncKVStore, AztecKVStore } from './store.js';
7
5
  import { isSyncStore } from './utils.js';
@@ -53,12 +51,12 @@ export function describeAztecArray(
53
51
  await arr.push(2);
54
52
  await arr.push(3);
55
53
 
56
- expect(await length()).to.equal(3);
54
+ expect(await length()).toBe(3);
57
55
 
58
- expect(await arr.pop()).to.equal(3);
59
- expect(await arr.pop()).to.equal(2);
60
- expect(await arr.pop()).to.equal(1);
61
- expect(await arr.pop()).to.equal(undefined);
56
+ expect(await arr.pop()).toBe(3);
57
+ expect(await arr.pop()).toBe(2);
58
+ expect(await arr.pop()).toBe(1);
59
+ expect(await arr.pop()).toBe(undefined);
62
60
  });
63
61
 
64
62
  it('should be able to get values by index', async () => {
@@ -66,14 +64,14 @@ export function describeAztecArray(
66
64
  await arr.push(2);
67
65
  await arr.push(3);
68
66
 
69
- expect(await at(0)).to.equal(1);
70
- expect(await at(1)).to.equal(2);
71
- expect(await at(2)).to.equal(3);
72
- expect(await at(3)).to.equal(undefined);
73
- expect(await at(-1)).to.equal(3);
74
- expect(await at(-2)).to.equal(2);
75
- expect(await at(-3)).to.equal(1);
76
- expect(await at(-4)).to.equal(undefined);
67
+ expect(await at(0)).toBe(1);
68
+ expect(await at(1)).toBe(2);
69
+ expect(await at(2)).toBe(3);
70
+ expect(await at(3)).toBe(undefined);
71
+ expect(await at(-1)).toBe(3);
72
+ expect(await at(-2)).toBe(2);
73
+ expect(await at(-3)).toBe(1);
74
+ expect(await at(-4)).toBe(undefined);
77
75
  });
78
76
 
79
77
  it('should be able to set values by index', async () => {
@@ -81,27 +79,27 @@ export function describeAztecArray(
81
79
  await arr.push(2);
82
80
  await arr.push(3);
83
81
 
84
- expect(await arr.setAt(0, 4)).to.equal(true);
85
- expect(await arr.setAt(1, 5)).to.equal(true);
86
- expect(await arr.setAt(2, 6)).to.equal(true);
82
+ expect(await arr.setAt(0, 4)).toBe(true);
83
+ expect(await arr.setAt(1, 5)).toBe(true);
84
+ expect(await arr.setAt(2, 6)).toBe(true);
87
85
 
88
- expect(await arr.setAt(3, 7)).to.equal(false);
86
+ expect(await arr.setAt(3, 7)).toBe(false);
89
87
 
90
- expect(await at(0)).to.equal(4);
91
- expect(await at(1)).to.equal(5);
92
- expect(await at(2)).to.equal(6);
93
- expect(await at(3)).to.equal(undefined);
88
+ expect(await at(0)).toBe(4);
89
+ expect(await at(1)).toBe(5);
90
+ expect(await at(2)).toBe(6);
91
+ expect(await at(3)).toBe(undefined);
94
92
 
95
- expect(await arr.setAt(-1, 8)).to.equal(true);
96
- expect(await arr.setAt(-2, 9)).to.equal(true);
97
- expect(await arr.setAt(-3, 10)).to.equal(true);
93
+ expect(await arr.setAt(-1, 8)).toBe(true);
94
+ expect(await arr.setAt(-2, 9)).toBe(true);
95
+ expect(await arr.setAt(-3, 10)).toBe(true);
98
96
 
99
- expect(await arr.setAt(-4, 11)).to.equal(false);
97
+ expect(await arr.setAt(-4, 11)).toBe(false);
100
98
 
101
- expect(await at(-1)).to.equal(8);
102
- expect(await at(-2)).to.equal(9);
103
- expect(await at(-3)).to.equal(10);
104
- expect(await at(-4)).to.equal(undefined);
99
+ expect(await at(-1)).toBe(8);
100
+ expect(await at(-2)).toBe(9);
101
+ expect(await at(-3)).toBe(10);
102
+ expect(await at(-4)).toBe(undefined);
105
103
  });
106
104
 
107
105
  it('should be able to iterate over values', async () => {
@@ -109,8 +107,8 @@ export function describeAztecArray(
109
107
  await arr.push(2);
110
108
  await arr.push(3);
111
109
 
112
- expect(await values()).to.deep.equal([1, 2, 3]);
113
- expect(await entries()).to.deep.equal([
110
+ expect(await values()).toEqual([1, 2, 3]);
111
+ expect(await entries()).toEqual([
114
112
  [0, 1],
115
113
  [1, 2],
116
114
  [2, 3],
@@ -123,8 +121,8 @@ export function describeAztecArray(
123
121
  await arr.push(3);
124
122
 
125
123
  const arr2 = store.openArray<number>('test');
126
- expect(await length(arr2)).to.equal(3);
127
- expect(await values(arr2)).to.deep.equal(await values());
124
+ expect(await length(arr2)).toBe(3);
125
+ expect(await values(arr2)).toEqual(await values());
128
126
  });
129
127
  });
130
128
  }
@@ -6,4 +6,4 @@ export * from './store.js';
6
6
  export * from './set.js';
7
7
  export * from './multi_map.js';
8
8
  export { mapRange } from './common.js';
9
- export type { CustomRange, Range, StoreSize } from './common.js';
9
+ export type { CustomRange, Key, Range, StoreSize } from './common.js';