@aztec/kv-store 0.87.5 → 0.87.6
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":"store.d.ts","sourceRoot":"","sources":["../../src/indexeddb/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,YAAY,
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/indexeddb/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,YAAY,EAA0C,MAAM,KAAK,CAAC;AAE/F,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,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAOhE,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,KAAK,IAAI;IACxC,KAAK,EAAE,CAAC,CAAC;IACT,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IAC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AAC,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"}
|
package/dest/indexeddb/store.js
CHANGED
|
@@ -10,6 +10,7 @@ import { IndexedDBAztecSingleton } from './singleton.js';
|
|
|
10
10
|
isEphemeral;
|
|
11
11
|
#rootDB;
|
|
12
12
|
#name;
|
|
13
|
+
#currentTx;
|
|
13
14
|
#containers;
|
|
14
15
|
constructor(rootDB, isEphemeral, name){
|
|
15
16
|
this.isEphemeral = isEphemeral;
|
|
@@ -116,15 +117,20 @@ import { IndexedDBAztecSingleton } from './singleton.js';
|
|
|
116
117
|
* @param callback - Function to execute in a transaction
|
|
117
118
|
* @returns A promise that resolves to the return value of the callback
|
|
118
119
|
*/ async transactionAsync(callback) {
|
|
119
|
-
|
|
120
|
+
// We can only have one transaction at a time for the same store
|
|
121
|
+
// So we need to wait for the current one to finish
|
|
122
|
+
if (this.#currentTx) {
|
|
123
|
+
await this.#currentTx.done;
|
|
124
|
+
}
|
|
125
|
+
this.#currentTx = this.#rootDB.transaction('data', 'readwrite');
|
|
120
126
|
for (const container of this.#containers){
|
|
121
|
-
container.db =
|
|
127
|
+
container.db = this.#currentTx.store;
|
|
122
128
|
}
|
|
123
129
|
// Avoid awaiting this promise so it doesn't get scheduled in the next microtask
|
|
124
130
|
// By then, the tx would be closed
|
|
125
131
|
const runningPromise = callback();
|
|
126
132
|
// Wait for the transaction to finish
|
|
127
|
-
await
|
|
133
|
+
await this.#currentTx.done;
|
|
128
134
|
for (const container of this.#containers){
|
|
129
135
|
container.db = undefined;
|
|
130
136
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/kv-store",
|
|
3
|
-
"version": "0.87.
|
|
3
|
+
"version": "0.87.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/interfaces/index.js",
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
"./package.local.json"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@aztec/ethereum": "0.87.
|
|
27
|
-
"@aztec/foundation": "0.87.
|
|
28
|
-
"@aztec/native": "0.87.
|
|
29
|
-
"@aztec/stdlib": "0.87.
|
|
26
|
+
"@aztec/ethereum": "0.87.6",
|
|
27
|
+
"@aztec/foundation": "0.87.6",
|
|
28
|
+
"@aztec/native": "0.87.6",
|
|
29
|
+
"@aztec/stdlib": "0.87.6",
|
|
30
30
|
"idb": "^8.0.0",
|
|
31
31
|
"lmdb": "^3.2.0",
|
|
32
32
|
"msgpackr": "^1.11.2",
|
package/src/indexeddb/store.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Logger } from '@aztec/foundation/log';
|
|
2
2
|
|
|
3
|
-
import { type DBSchema, type IDBPDatabase, deleteDB, openDB } from 'idb';
|
|
3
|
+
import { type DBSchema, type IDBPDatabase, type IDBPTransaction, deleteDB, openDB } from 'idb';
|
|
4
4
|
|
|
5
5
|
import type { AztecAsyncArray } from '../interfaces/array.js';
|
|
6
6
|
import type { Key, StoreSize, Value } from '../interfaces/common.js';
|
|
@@ -40,6 +40,7 @@ export interface AztecIDBSchema extends DBSchema {
|
|
|
40
40
|
export class AztecIndexedDBStore implements AztecAsyncKVStore {
|
|
41
41
|
#rootDB: IDBPDatabase<AztecIDBSchema>;
|
|
42
42
|
#name: string;
|
|
43
|
+
#currentTx?: IDBPTransaction<AztecIDBSchema, ['data'], 'readwrite'>;
|
|
43
44
|
|
|
44
45
|
#containers = new Set<
|
|
45
46
|
| IndexedDBAztecArray<any>
|
|
@@ -153,18 +154,24 @@ export class AztecIndexedDBStore implements AztecAsyncKVStore {
|
|
|
153
154
|
* @returns A promise that resolves to the return value of the callback
|
|
154
155
|
*/
|
|
155
156
|
async transactionAsync<T>(callback: () => Promise<T>): Promise<T> {
|
|
156
|
-
|
|
157
|
+
// We can only have one transaction at a time for the same store
|
|
158
|
+
// So we need to wait for the current one to finish
|
|
159
|
+
if (this.#currentTx) {
|
|
160
|
+
await this.#currentTx.done;
|
|
161
|
+
}
|
|
162
|
+
this.#currentTx = this.#rootDB.transaction('data', 'readwrite');
|
|
157
163
|
for (const container of this.#containers) {
|
|
158
|
-
container.db =
|
|
164
|
+
container.db = this.#currentTx.store;
|
|
159
165
|
}
|
|
160
166
|
// Avoid awaiting this promise so it doesn't get scheduled in the next microtask
|
|
161
167
|
// By then, the tx would be closed
|
|
162
168
|
const runningPromise = callback();
|
|
163
169
|
// Wait for the transaction to finish
|
|
164
|
-
await
|
|
170
|
+
await this.#currentTx.done;
|
|
165
171
|
for (const container of this.#containers) {
|
|
166
172
|
container.db = undefined;
|
|
167
173
|
}
|
|
174
|
+
|
|
168
175
|
// Return the result of the callback.
|
|
169
176
|
// Tx is guaranteed to already be closed, so the await doesn't hurt anything here
|
|
170
177
|
return await runningPromise;
|