@aztec/kv-store 1.0.0-nightly.20250707 → 1.0.0-staging.0

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.
@@ -1 +1 @@
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,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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"}
@@ -25,8 +25,7 @@ import { hash } from 'ohash';
25
25
  const result = await this.getAsync(key) !== undefined;
26
26
  return result;
27
27
  }
28
- async sizeAsync() {
29
- const index = this.db.index('key');
28
+ sizeAsync() {
30
29
  const rangeQuery = IDBKeyRange.bound([
31
30
  this.container,
32
31
  ''
@@ -34,7 +33,7 @@ import { hash } from 'ohash';
34
33
  this.container,
35
34
  '\uffff'
36
35
  ]);
37
- return await index.count(rangeQuery);
36
+ return this.db.count(rangeQuery);
38
37
  }
39
38
  async set(key, val) {
40
39
  await this.db.put({
@@ -68,10 +67,10 @@ import { hash } from 'ohash';
68
67
  const index = this.db.index('key');
69
68
  const rangeQuery = IDBKeyRange.bound([
70
69
  this.container,
71
- range.start ? this.normalizeKey(range.start) : ''
70
+ range.start ?? ''
72
71
  ], [
73
72
  this.container,
74
- range.end ? this.normalizeKey(range.end) : '\uffff'
73
+ range.end ?? '\uffff'
75
74
  ], !!range.reverse, !range.reverse);
76
75
  let count = 0;
77
76
  for await (const cursor of index.iterate(rangeQuery, range.reverse ? 'prev' : 'next')){
@@ -79,7 +78,7 @@ import { hash } from 'ohash';
79
78
  return;
80
79
  }
81
80
  yield [
82
- this.#denormalizeKey(cursor.value.key),
81
+ cursor.value.key,
83
82
  cursor.value.value
84
83
  ];
85
84
  count++;
@@ -92,18 +91,18 @@ import { hash } from 'ohash';
92
91
  }
93
92
  async *keysAsync(range = {}) {
94
93
  for await (const [key, _] of this.entriesAsync(range)){
95
- yield key;
94
+ yield this.#denormalizeKey(key);
96
95
  }
97
96
  }
98
97
  #denormalizeKey(key) {
99
- const denormalizedKey = key.split(',').map((part)=>part.startsWith('n_') ? Number(part.slice(2)) : part);
100
- return denormalizedKey.length > 1 ? denormalizedKey : denormalizedKey[0];
98
+ const denormalizedKey = key.split(',').map((part)=>isNaN(parseInt(part)) ? part : parseInt(part));
99
+ return denormalizedKey.length > 1 ? denormalizedKey : key;
101
100
  }
102
101
  normalizeKey(key) {
103
102
  const arrayKey = Array.isArray(key) ? key : [
104
103
  key
105
104
  ];
106
- return arrayKey.map((element)=>typeof element === 'number' ? `n_${element}` : element).join(',');
105
+ return arrayKey.join(',');
107
106
  }
108
107
  slot(key, index = 0) {
109
108
  return `map:${this.name}:slot:${this.normalizeKey(key)}:${index}`;
@@ -1 +1 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/indexeddb/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAGpD,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,YAAY,EAAoB,MAAM,KAAK,CAAC;AAEzE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAA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a,CAAC,CAAC,EAAE,CAAC,CAAC;IAM1E;;;;OAIG;IACH,OAAO,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,aAAa,CAAC,CAAC,CAAC;IAMtD;;;;OAIG;IACH,YAAY,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC,SAAS,KAAK,EAAE,IAAI,EAAE,MAAM,GAAG,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC;IAMpF,WAAW,CAAC,CAAC,SAAS,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,iBAAiB,CAAC,CAAC,CAAC;IAI/D;;;;OAIG;IACH,SAAS,CAAC,CAAC,SAAS,KAAK,EAAE,IAAI,EAAE,MAAM,GAAG,eAAe,CAAC,CAAC,CAAC;IAM5D;;;;OAIG;IACH,aAAa,CAAC,CAAC,SAAS,KAAK,EAAE,IAAI,EAAE,MAAM,GAAG,mBAAmB,CAAC,CAAC,CAAC;IAMpE;;;;OAIG;IACG,gBAAgB,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAwBjE;;OAEG;IACG,KAAK;IAIX,kDAAkD;IAClD,MAAM;IAMN,YAAY,IAAI,OAAO,CAAC,SAAS,CAAC;IAIlC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAG9D"}
@@ -1,4 +1,3 @@
1
- import { SerialQueue } from '@aztec/foundation/queue';
2
1
  import { deleteDB, openDB } from 'idb';
3
2
  import { IndexedDBAztecArray } from './array.js';
4
3
  import { IndexedDBAztecMap } from './map.js';
@@ -11,15 +10,13 @@ import { IndexedDBAztecSingleton } from './singleton.js';
11
10
  isEphemeral;
12
11
  #rootDB;
13
12
  #name;
14
- #txQueue;
13
+ #currentTx;
15
14
  #containers;
16
15
  constructor(rootDB, isEphemeral, name){
17
16
  this.isEphemeral = isEphemeral;
18
17
  this.#containers = new Set();
19
18
  this.#rootDB = rootDB;
20
19
  this.#name = name;
21
- this.#txQueue = new SerialQueue();
22
- this.#txQueue.start();
23
20
  }
24
21
  /**
25
22
  * Creates a new AztecKVStore backed by IndexedDB. The path to the database is optional. If not provided,
@@ -119,26 +116,27 @@ import { IndexedDBAztecSingleton } from './singleton.js';
119
116
  * Runs a callback in a transaction.
120
117
  * @param callback - Function to execute in a transaction
121
118
  * @returns A promise that resolves to the return value of the callback
122
- */ transactionAsync(callback) {
119
+ */ async transactionAsync(callback) {
123
120
  // We can only have one transaction at a time for the same store
124
121
  // So we need to wait for the current one to finish
125
- return this.#txQueue.put(async ()=>{
126
- const tx = this.#rootDB.transaction('data', 'readwrite');
127
- for (const container of this.#containers){
128
- container.db = tx.store;
129
- }
130
- // Avoid awaiting this promise so it doesn't get scheduled in the next microtask
131
- // By then, the tx would be closed
132
- const runningPromise = callback();
133
- // Wait for the transaction to finish
134
- await tx.done;
135
- for (const container of this.#containers){
136
- container.db = undefined;
137
- }
138
- // Return the result of the callback.
139
- // Tx is guaranteed to already be closed, so the await doesn't hurt anything here
140
- return await runningPromise;
141
- });
122
+ if (this.#currentTx) {
123
+ await this.#currentTx.done;
124
+ }
125
+ this.#currentTx = this.#rootDB.transaction('data', 'readwrite');
126
+ for (const container of this.#containers){
127
+ container.db = this.#currentTx.store;
128
+ }
129
+ // Avoid awaiting this promise so it doesn't get scheduled in the next microtask
130
+ // By then, the tx would be closed
131
+ const runningPromise = callback();
132
+ // Wait for the transaction to finish
133
+ await this.#currentTx.done;
134
+ for (const container of this.#containers){
135
+ container.db = undefined;
136
+ }
137
+ // Return the result of the callback.
138
+ // Tx is guaranteed to already be closed, so the await doesn't hurt anything here
139
+ return await runningPromise;
142
140
  }
143
141
  /**
144
142
  * Clears all entries in the store & sub DBs.
@@ -1 +1 @@
1
- {"version":3,"file":"map_test_suite.d.ts","sourceRoot":"","sources":["../../src/interfaces/map_test_suite.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAGlE,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,YAAY,GAAG,OAAO,CAAC,iBAAiB,CAAC,EACzD,UAAU,GAAE,OAAe,QA+J5B"}
1
+ {"version":3,"file":"map_test_suite.d.ts","sourceRoot":"","sources":["../../src/interfaces/map_test_suite.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAGlE,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,YAAY,GAAG,OAAO,CAAC,iBAAiB,CAAC,EACzD,UAAU,GAAE,OAAe,QAuJ5B"}
@@ -104,14 +104,6 @@ export function describeAztecMap(testName, getStore, forceAsync = false) {
104
104
  'foo'
105
105
  ]);
106
106
  });
107
- it('should be able to iterate over string keys that represent numbers', async ()=>{
108
- await map.set('0x22', 'bar');
109
- await map.set('0x31', 'qux');
110
- expect(await keys()).to.deep.equal([
111
- '0x22',
112
- '0x31'
113
- ]);
114
- });
115
107
  for (const [name, data] of [
116
108
  [
117
109
  'chars',
@@ -131,8 +123,15 @@ export function describeAztecMap(testName, getStore, forceAsync = false) {
131
123
  4
132
124
  ]
133
125
  ],
134
- // disabled because indexeddb sorts lexigographically
135
- // ['negative numbers', [-4, -3, -2, -1]],
126
+ [
127
+ 'negative numbers',
128
+ [
129
+ -4,
130
+ -3,
131
+ -2,
132
+ -1
133
+ ]
134
+ ],
136
135
  [
137
136
  'strings',
138
137
  [
@@ -11,7 +11,6 @@ export declare const mockLogger: {
11
11
  level: "trace";
12
12
  isLevelEnabled: (_level: string) => boolean;
13
13
  module: string;
14
- createChild: () => /*elided*/ any;
15
14
  };
16
15
  export declare function isSyncStore(store: AztecKVStore | AztecAsyncKVStore): store is AztecAsyncKVStore;
17
16
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/interfaces/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAGlE,eAAO,MAAM,UAAU;iBACR,MAAM,QAAQ,GAAG;gBAClB,MAAM,QAAQ,GAAG;gBACjB,MAAM,QAAQ,GAAG;iBAChB,MAAM,QAAQ,GAAG;iBACjB,MAAM,QAAQ,GAAG;mBACf,MAAM,SAAS,GAAG;mBAClB,MAAM,QAAQ,GAAG;iBACnB,MAAM,QAAQ,GAAG;;6BAEL,MAAM;;;CAGhC,CAAC;AAGF,wBAAgB,WAAW,CAAC,KAAK,EAAE,YAAY,GAAG,iBAAiB,GAAG,KAAK,IAAI,iBAAiB,CAE/F"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/interfaces/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAGlE,eAAO,MAAM,UAAU;iBACR,MAAM,QAAQ,GAAG;gBAClB,MAAM,QAAQ,GAAG;gBACjB,MAAM,QAAQ,GAAG;iBAChB,MAAM,QAAQ,GAAG;iBACjB,MAAM,QAAQ,GAAG;mBACf,MAAM,SAAS,GAAG;mBAClB,MAAM,QAAQ,GAAG;iBACnB,MAAM,QAAQ,GAAG;;6BAEL,MAAM;;CAEhC,CAAC;AAGF,wBAAgB,WAAW,CAAC,KAAK,EAAE,YAAY,GAAG,iBAAiB,GAAG,KAAK,IAAI,iBAAiB,CAE/F"}
@@ -9,8 +9,7 @@
9
9
  trace: (msg, data)=>console.log(msg, data),
10
10
  level: 'trace',
11
11
  isLevelEnabled: (_level)=>true,
12
- module: 'kv-store:mock-logger',
13
- createChild: ()=>mockLogger
12
+ module: 'kv-store:mock-logger'
14
13
  };
15
14
  /* eslint-enable no-console */ export function isSyncStore(store) {
16
15
  return store.syncGetters === true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/kv-store",
3
- "version": "1.0.0-nightly.20250707",
3
+ "version": "1.0.0-staging.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/interfaces/index.js",
@@ -24,10 +24,10 @@
24
24
  "./package.local.json"
25
25
  ],
26
26
  "dependencies": {
27
- "@aztec/ethereum": "1.0.0-nightly.20250707",
28
- "@aztec/foundation": "1.0.0-nightly.20250707",
29
- "@aztec/native": "1.0.0-nightly.20250707",
30
- "@aztec/stdlib": "1.0.0-nightly.20250707",
27
+ "@aztec/ethereum": "1.0.0-staging.0",
28
+ "@aztec/foundation": "1.0.0-staging.0",
29
+ "@aztec/native": "1.0.0-staging.0",
30
+ "@aztec/stdlib": "1.0.0-staging.0",
31
31
  "idb": "^8.0.0",
32
32
  "lmdb": "^3.2.0",
33
33
  "msgpackr": "^1.11.2",
@@ -39,10 +39,9 @@ export class IndexedDBAztecMap<K extends Key, V extends Value> implements AztecA
39
39
  return result;
40
40
  }
41
41
 
42
- async sizeAsync(): Promise<number> {
43
- const index = this.db.index('key');
42
+ sizeAsync(): Promise<number> {
44
43
  const rangeQuery = IDBKeyRange.bound([this.container, ''], [this.container, '\uffff']);
45
- return await index.count(rangeQuery);
44
+ return this.db.count(rangeQuery);
46
45
  }
47
46
 
48
47
  async set(key: K, val: V): Promise<void> {
@@ -81,8 +80,8 @@ export class IndexedDBAztecMap<K extends Key, V extends Value> implements AztecA
81
80
  async *entriesAsync(range: Range<K> = {}): AsyncIterableIterator<[K, V]> {
82
81
  const index = this.db.index('key');
83
82
  const rangeQuery = IDBKeyRange.bound(
84
- [this.container, range.start ? this.normalizeKey(range.start) : ''],
85
- [this.container, range.end ? this.normalizeKey(range.end) : '\uffff'],
83
+ [this.container, range.start ?? ''],
84
+ [this.container, range.end ?? '\uffff'],
86
85
  !!range.reverse,
87
86
  !range.reverse,
88
87
  );
@@ -91,7 +90,7 @@ export class IndexedDBAztecMap<K extends Key, V extends Value> implements AztecA
91
90
  if (range.limit && count >= range.limit) {
92
91
  return;
93
92
  }
94
- yield [this.#denormalizeKey(cursor.value.key), cursor.value.value] as [K, V];
93
+ yield [cursor.value.key, cursor.value.value] as [K, V];
95
94
  count++;
96
95
  }
97
96
  }
@@ -104,18 +103,18 @@ export class IndexedDBAztecMap<K extends Key, V extends Value> implements AztecA
104
103
 
105
104
  async *keysAsync(range: Range<K> = {}): AsyncIterableIterator<K> {
106
105
  for await (const [key, _] of this.entriesAsync(range)) {
107
- yield key;
106
+ yield this.#denormalizeKey(key as string);
108
107
  }
109
108
  }
110
109
 
111
110
  #denormalizeKey(key: string): K {
112
- const denormalizedKey = key.split(',').map(part => (part.startsWith('n_') ? Number(part.slice(2)) : part));
113
- return (denormalizedKey.length > 1 ? denormalizedKey : denormalizedKey[0]) as K;
111
+ const denormalizedKey = (key as string).split(',').map(part => (isNaN(parseInt(part)) ? part : parseInt(part)));
112
+ return (denormalizedKey.length > 1 ? denormalizedKey : key) as K;
114
113
  }
115
114
 
116
115
  protected normalizeKey(key: K): string {
117
116
  const arrayKey = Array.isArray(key) ? key : [key];
118
- return (arrayKey as K[]).map((element: K) => (typeof element === 'number' ? `n_${element}` : element)).join(',');
117
+ return arrayKey.join(',');
119
118
  }
120
119
 
121
120
  protected slot(key: K, index: number = 0): string {
@@ -1,7 +1,6 @@
1
1
  import type { Logger } from '@aztec/foundation/log';
2
- import { SerialQueue } from '@aztec/foundation/queue';
3
2
 
4
- import { type DBSchema, type IDBPDatabase, deleteDB, openDB } from 'idb';
3
+ import { type DBSchema, type IDBPDatabase, type IDBPTransaction, deleteDB, openDB } from 'idb';
5
4
 
6
5
  import type { AztecAsyncArray } from '../interfaces/array.js';
7
6
  import type { Key, StoreSize, Value } from '../interfaces/common.js';
@@ -41,7 +40,7 @@ export interface AztecIDBSchema extends DBSchema {
41
40
  export class AztecIndexedDBStore implements AztecAsyncKVStore {
42
41
  #rootDB: IDBPDatabase<AztecIDBSchema>;
43
42
  #name: string;
44
- #txQueue: SerialQueue;
43
+ #currentTx: IDBPTransaction<AztecIDBSchema, ['data'], 'readwrite'> | undefined;
45
44
 
46
45
  #containers = new Set<
47
46
  | IndexedDBAztecArray<any>
@@ -58,8 +57,6 @@ export class AztecIndexedDBStore implements AztecAsyncKVStore {
58
57
  ) {
59
58
  this.#rootDB = rootDB;
60
59
  this.#name = name;
61
- this.#txQueue = new SerialQueue();
62
- this.#txQueue.start();
63
60
  }
64
61
  /**
65
62
  * Creates a new AztecKVStore backed by IndexedDB. The path to the database is optional. If not provided,
@@ -156,27 +153,28 @@ export class AztecIndexedDBStore implements AztecAsyncKVStore {
156
153
  * @param callback - Function to execute in a transaction
157
154
  * @returns A promise that resolves to the return value of the callback
158
155
  */
159
- transactionAsync<T>(callback: () => Promise<T>): Promise<T> {
156
+ async transactionAsync<T>(callback: () => Promise<T>): Promise<T> {
160
157
  // We can only have one transaction at a time for the same store
161
158
  // So we need to wait for the current one to finish
162
- return this.#txQueue.put(async () => {
163
- const tx = this.#rootDB.transaction('data', 'readwrite');
164
- for (const container of this.#containers) {
165
- container.db = tx.store;
166
- }
167
- // Avoid awaiting this promise so it doesn't get scheduled in the next microtask
168
- // By then, the tx would be closed
169
- const runningPromise = callback();
170
- // Wait for the transaction to finish
171
- await tx.done;
172
- for (const container of this.#containers) {
173
- container.db = undefined;
174
- }
175
-
176
- // Return the result of the callback.
177
- // Tx is guaranteed to already be closed, so the await doesn't hurt anything here
178
- return await runningPromise;
179
- });
159
+ if (this.#currentTx) {
160
+ await this.#currentTx.done;
161
+ }
162
+ this.#currentTx = this.#rootDB.transaction('data', 'readwrite');
163
+ for (const container of this.#containers) {
164
+ container.db = this.#currentTx.store;
165
+ }
166
+ // Avoid awaiting this promise so it doesn't get scheduled in the next microtask
167
+ // By then, the tx would be closed
168
+ const runningPromise = callback();
169
+ // Wait for the transaction to finish
170
+ await this.#currentTx.done;
171
+ for (const container of this.#containers) {
172
+ container.db = undefined;
173
+ }
174
+
175
+ // Return the result of the callback.
176
+ // Tx is guaranteed to already be closed, so the await doesn't hurt anything here
177
+ return await runningPromise;
180
178
  }
181
179
 
182
180
  /**
@@ -135,18 +135,10 @@ export function describeAztecMap(
135
135
  expect(await keys()).to.deep.equal(['baz', 'foo']);
136
136
  });
137
137
 
138
- it('should be able to iterate over string keys that represent numbers', async () => {
139
- await map.set('0x22', 'bar');
140
- await map.set('0x31', 'qux');
141
-
142
- expect(await keys()).to.deep.equal(['0x22', '0x31']);
143
- });
144
-
145
138
  for (const [name, data] of [
146
139
  ['chars', ['a', 'b', 'c', 'd']],
147
140
  ['numbers', [1, 2, 3, 4]],
148
- // disabled because indexeddb sorts lexigographically
149
- // ['negative numbers', [-4, -3, -2, -1]],
141
+ ['negative numbers', [-4, -3, -2, -1]],
150
142
  ['strings', ['aaa', 'bbb', 'ccc', 'ddd']],
151
143
  ['zero-based numbers', [0, 1, 2, 3]],
152
144
  ]) {
@@ -13,7 +13,6 @@ export const mockLogger = {
13
13
  level: 'trace' as const,
14
14
  isLevelEnabled: (_level: string) => true,
15
15
  module: 'kv-store:mock-logger',
16
- createChild: () => mockLogger,
17
16
  };
18
17
  /* eslint-enable no-console */
19
18