@aztec/kv-store 1.0.0-staging.3 → 1.0.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":"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,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;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,WAAW,cAAe,SAAQ,QAAQ;IAC9C,IAAI,EAAE;QACJ,KAAK,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;QACvB,GAAG,EAAE,MAAM,CAAC;QACZ,OAAO,EAAE;YAAE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Aa,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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/kv-store",
3
- "version": "1.0.0-staging.3",
3
+ "version": "1.0.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-staging.3",
28
- "@aztec/foundation": "1.0.0-staging.3",
29
- "@aztec/native": "1.0.0-staging.3",
30
- "@aztec/stdlib": "1.0.0-staging.3",
27
+ "@aztec/ethereum": "1.0.0",
28
+ "@aztec/foundation": "1.0.0",
29
+ "@aztec/native": "1.0.0",
30
+ "@aztec/stdlib": "1.0.0",
31
31
  "idb": "^8.0.0",
32
32
  "lmdb": "^3.2.0",
33
33
  "msgpackr": "^1.11.2",
@@ -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
  /**