@aztec/kv-store 0.0.0-test.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.
- package/README.md +10 -0
- package/dest/config.d.ts +17 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/config.js +24 -0
- package/dest/indexeddb/array.d.ts +21 -0
- package/dest/indexeddb/array.d.ts.map +1 -0
- package/dest/indexeddb/array.js +104 -0
- package/dest/indexeddb/index.d.ts +7 -0
- package/dest/indexeddb/index.d.ts.map +1 -0
- package/dest/indexeddb/index.js +19 -0
- package/dest/indexeddb/map.d.ts +26 -0
- package/dest/indexeddb/map.d.ts.map +1 -0
- package/dest/indexeddb/map.js +133 -0
- package/dest/indexeddb/set.d.ts +17 -0
- package/dest/indexeddb/set.d.ts.map +1 -0
- package/dest/indexeddb/set.js +24 -0
- package/dest/indexeddb/singleton.d.ts +16 -0
- package/dest/indexeddb/singleton.d.ts.map +1 -0
- package/dest/indexeddb/singleton.js +37 -0
- package/dest/indexeddb/store.d.ts +97 -0
- package/dest/indexeddb/store.d.ts.map +1 -0
- package/dest/indexeddb/store.js +164 -0
- package/dest/interfaces/array.d.ts +80 -0
- package/dest/interfaces/array.d.ts.map +1 -0
- package/dest/interfaces/array.js +3 -0
- package/dest/interfaces/array_test_suite.d.ts +3 -0
- package/dest/interfaces/array_test_suite.d.ts.map +1 -0
- package/dest/interfaces/array_test_suite.js +104 -0
- package/dest/interfaces/common.d.ts +23 -0
- package/dest/interfaces/common.d.ts.map +1 -0
- package/dest/interfaces/common.js +3 -0
- package/dest/interfaces/counter.d.ts +59 -0
- package/dest/interfaces/counter.d.ts.map +1 -0
- package/dest/interfaces/counter.js +1 -0
- package/dest/interfaces/index.d.ts +8 -0
- package/dest/interfaces/index.d.ts.map +1 -0
- package/dest/interfaces/index.js +6 -0
- package/dest/interfaces/map.d.ts +134 -0
- package/dest/interfaces/map.d.ts.map +1 -0
- package/dest/interfaces/map.js +3 -0
- package/dest/interfaces/map_test_suite.d.ts +3 -0
- package/dest/interfaces/map_test_suite.d.ts.map +1 -0
- package/dest/interfaces/map_test_suite.js +151 -0
- package/dest/interfaces/set.d.ts +44 -0
- package/dest/interfaces/set.d.ts.map +1 -0
- package/dest/interfaces/set.js +1 -0
- package/dest/interfaces/set_test_suite.d.ts +3 -0
- package/dest/interfaces/set_test_suite.d.ts.map +1 -0
- package/dest/interfaces/set_test_suite.js +96 -0
- package/dest/interfaces/singleton.d.ts +29 -0
- package/dest/interfaces/singleton.d.ts.map +1 -0
- package/dest/interfaces/singleton.js +4 -0
- package/dest/interfaces/singleton_test_suite.d.ts +3 -0
- package/dest/interfaces/singleton_test_suite.d.ts.map +1 -0
- package/dest/interfaces/singleton_test_suite.js +30 -0
- package/dest/interfaces/store.d.ts +145 -0
- package/dest/interfaces/store.d.ts.map +1 -0
- package/dest/interfaces/store.js +1 -0
- package/dest/interfaces/store_test_suite.d.ts +3 -0
- package/dest/interfaces/store_test_suite.d.ts.map +1 -0
- package/dest/interfaces/store_test_suite.js +37 -0
- package/dest/interfaces/utils.d.ts +16 -0
- package/dest/interfaces/utils.d.ts.map +1 -0
- package/dest/interfaces/utils.js +16 -0
- package/dest/lmdb/array.d.ts +23 -0
- package/dest/lmdb/array.d.ts.map +1 -0
- package/dest/lmdb/array.js +117 -0
- package/dest/lmdb/counter.d.ts +19 -0
- package/dest/lmdb/counter.d.ts.map +1 -0
- package/dest/lmdb/counter.js +50 -0
- package/dest/lmdb/index.d.ts +12 -0
- package/dest/lmdb/index.d.ts.map +1 -0
- package/dest/lmdb/index.js +25 -0
- package/dest/lmdb/map.d.ts +52 -0
- package/dest/lmdb/map.d.ts.map +1 -0
- package/dest/lmdb/map.js +222 -0
- package/dest/lmdb/set.d.ts +18 -0
- package/dest/lmdb/set.d.ts.map +1 -0
- package/dest/lmdb/set.js +32 -0
- package/dest/lmdb/singleton.d.ts +14 -0
- package/dest/lmdb/singleton.d.ts.map +1 -0
- package/dest/lmdb/singleton.js +26 -0
- package/dest/lmdb/store.d.ts +110 -0
- package/dest/lmdb/store.d.ts.map +1 -0
- package/dest/lmdb/store.js +216 -0
- package/dest/lmdb-v2/array.d.ts +18 -0
- package/dest/lmdb-v2/array.d.ts.map +1 -0
- package/dest/lmdb-v2/array.js +101 -0
- package/dest/lmdb-v2/factory.d.ts +12 -0
- package/dest/lmdb-v2/factory.d.ts.map +1 -0
- package/dest/lmdb-v2/factory.js +60 -0
- package/dest/lmdb-v2/index.d.ts +3 -0
- package/dest/lmdb-v2/index.d.ts.map +1 -0
- package/dest/lmdb-v2/index.js +2 -0
- package/dest/lmdb-v2/map.d.ts +86 -0
- package/dest/lmdb-v2/map.d.ts.map +1 -0
- package/dest/lmdb-v2/map.js +193 -0
- package/dest/lmdb-v2/message.d.ts +112 -0
- package/dest/lmdb-v2/message.d.ts.map +1 -0
- package/dest/lmdb-v2/message.js +18 -0
- package/dest/lmdb-v2/read_transaction.d.ts +14 -0
- package/dest/lmdb-v2/read_transaction.d.ts.map +1 -0
- package/dest/lmdb-v2/read_transaction.js +101 -0
- package/dest/lmdb-v2/singleton.d.ts +12 -0
- package/dest/lmdb-v2/singleton.d.ts.map +1 -0
- package/dest/lmdb-v2/singleton.js +31 -0
- package/dest/lmdb-v2/store.d.ts +43 -0
- package/dest/lmdb-v2/store.d.ts.map +1 -0
- package/dest/lmdb-v2/store.js +181 -0
- package/dest/lmdb-v2/utils.d.ts +19 -0
- package/dest/lmdb-v2/utils.d.ts.map +1 -0
- package/dest/lmdb-v2/utils.js +126 -0
- package/dest/lmdb-v2/write_transaction.d.ts +19 -0
- package/dest/lmdb-v2/write_transaction.d.ts.map +1 -0
- package/dest/lmdb-v2/write_transaction.js +254 -0
- package/dest/stores/index.d.ts +2 -0
- package/dest/stores/index.d.ts.map +1 -0
- package/dest/stores/index.js +1 -0
- package/dest/stores/l2_tips_store.d.ts +13 -0
- package/dest/stores/l2_tips_store.d.ts.map +1 -0
- package/dest/stores/l2_tips_store.js +65 -0
- package/dest/utils.d.ts +12 -0
- package/dest/utils.d.ts.map +1 -0
- package/dest/utils.js +24 -0
- package/package.json +99 -0
- package/src/config.ts +34 -0
- package/src/indexeddb/array.ts +118 -0
- package/src/indexeddb/index.ts +29 -0
- package/src/indexeddb/map.ts +142 -0
- package/src/indexeddb/set.ts +37 -0
- package/src/indexeddb/singleton.ts +49 -0
- package/src/indexeddb/store.ts +197 -0
- package/src/interfaces/array.ts +90 -0
- package/src/interfaces/array_test_suite.ts +130 -0
- package/src/interfaces/common.ts +20 -0
- package/src/interfaces/counter.ts +65 -0
- package/src/interfaces/index.ts +7 -0
- package/src/interfaces/map.ts +151 -0
- package/src/interfaces/map_test_suite.ts +143 -0
- package/src/interfaces/set.ts +48 -0
- package/src/interfaces/set_test_suite.ts +81 -0
- package/src/interfaces/singleton.ts +29 -0
- package/src/interfaces/singleton_test_suite.ts +46 -0
- package/src/interfaces/store.ts +177 -0
- package/src/interfaces/store_test_suite.ts +56 -0
- package/src/interfaces/utils.ts +21 -0
- package/src/lmdb/array.ts +139 -0
- package/src/lmdb/counter.ts +67 -0
- package/src/lmdb/index.ts +37 -0
- package/src/lmdb/map.ts +248 -0
- package/src/lmdb/set.ts +45 -0
- package/src/lmdb/singleton.ts +35 -0
- package/src/lmdb/store.ts +263 -0
- package/src/lmdb-v2/array.ts +115 -0
- package/src/lmdb-v2/factory.ts +98 -0
- package/src/lmdb-v2/index.ts +2 -0
- package/src/lmdb-v2/map.ts +233 -0
- package/src/lmdb-v2/message.ts +146 -0
- package/src/lmdb-v2/read_transaction.ts +116 -0
- package/src/lmdb-v2/singleton.ts +34 -0
- package/src/lmdb-v2/store.ts +237 -0
- package/src/lmdb-v2/utils.ts +150 -0
- package/src/lmdb-v2/write_transaction.ts +314 -0
- package/src/stores/index.ts +1 -0
- package/src/stores/l2_tips_store.ts +70 -0
- package/src/utils.ts +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# KV Store
|
|
2
|
+
|
|
3
|
+
The Aztec KV store is an implementation of a durable key-value database with a pluggable backend. The only supported backend right now is LMDB by using the [`lmdb-js` package](https://github.com/kriszyp/lmdb-js).
|
|
4
|
+
|
|
5
|
+
This package exports a number of primitive data structures that can be used to build domain-specific databases in each node component (e.g. a PXE database or an Archiver database). The data structures supported:
|
|
6
|
+
|
|
7
|
+
- singleton - holds a single value. Great for when a value needs to be stored but it's not a collection (e.g. the latest block header or the length of an array)
|
|
8
|
+
- array - works like a normal in-memory JS array. It can't contain holes and it can be used as a stack (push-pop mechanics).
|
|
9
|
+
- map - a hashmap where keys can be numbers or strings
|
|
10
|
+
- multi-map - just like a map but each key holds multiple values. Can be used for indexing into other data structures
|
package/dest/config.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,CAclE,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,oBAAoB,IAAI,eAAe,CAEtD"}
|
package/dest/config.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
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: 'DB mapping size to be applied to all key/value stores',
|
|
11
|
+
...numberConfigHelper(128 * 1_024 * 1_024)
|
|
12
|
+
},
|
|
13
|
+
l1Contracts: {
|
|
14
|
+
description: 'The deployed L1 contract addresses',
|
|
15
|
+
nested: l1ContractAddressesMapping
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Returns the archiver configuration from the environment variables.
|
|
20
|
+
* Note: If an environment variable is not set, the default value is used.
|
|
21
|
+
* @returns The archiver configuration.
|
|
22
|
+
*/ export function getDataConfigFromEnv() {
|
|
23
|
+
return getConfigFromMappings(dataConfigMappings);
|
|
24
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { IDBPDatabase, IDBPObjectStore } from 'idb';
|
|
2
|
+
import type { AztecAsyncArray } from '../interfaces/array.js';
|
|
3
|
+
import type { AztecIDBSchema } from './store.js';
|
|
4
|
+
/**
|
|
5
|
+
* A persistent array backed by IndexedDB.
|
|
6
|
+
*/
|
|
7
|
+
export declare class IndexedDBAztecArray<T> implements AztecAsyncArray<T> {
|
|
8
|
+
#private;
|
|
9
|
+
constructor(rootDB: IDBPDatabase<AztecIDBSchema>, name: string);
|
|
10
|
+
set db(db: IDBPObjectStore<AztecIDBSchema, ['data'], 'data', 'readwrite'> | undefined);
|
|
11
|
+
get db(): IDBPObjectStore<AztecIDBSchema, ['data'], 'data', 'readwrite'>;
|
|
12
|
+
lengthAsync(): Promise<number>;
|
|
13
|
+
push(...vals: T[]): Promise<number>;
|
|
14
|
+
pop(): Promise<T | undefined>;
|
|
15
|
+
atAsync(index: number): Promise<T | undefined>;
|
|
16
|
+
setAt(index: number, val: T): Promise<boolean>;
|
|
17
|
+
entriesAsync(): AsyncIterableIterator<[number, T]>;
|
|
18
|
+
valuesAsync(): AsyncIterableIterator<T>;
|
|
19
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<T>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=array.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;AAEzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;GAEG;AACH,qBAAa,mBAAmB,CAAC,CAAC,CAAE,YAAW,eAAe,CAAC,CAAC,CAAC;;gBAMnD,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;IAenC,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;IAqB7C,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"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A persistent array backed by IndexedDB.
|
|
3
|
+
*/ export class IndexedDBAztecArray {
|
|
4
|
+
#_db;
|
|
5
|
+
#rootDB;
|
|
6
|
+
#container;
|
|
7
|
+
#name;
|
|
8
|
+
constructor(rootDB, name){
|
|
9
|
+
this.#rootDB = rootDB;
|
|
10
|
+
this.#name = name;
|
|
11
|
+
this.#container = `array:${this.#name}`;
|
|
12
|
+
}
|
|
13
|
+
set db(db) {
|
|
14
|
+
this.#_db = db;
|
|
15
|
+
}
|
|
16
|
+
get db() {
|
|
17
|
+
return this.#_db ? this.#_db : this.#rootDB.transaction('data', 'readwrite').store;
|
|
18
|
+
}
|
|
19
|
+
async lengthAsync() {
|
|
20
|
+
return await this.db.index('key').count(IDBKeyRange.bound([
|
|
21
|
+
this.#container,
|
|
22
|
+
this.#name
|
|
23
|
+
], [
|
|
24
|
+
this.#container,
|
|
25
|
+
this.#name
|
|
26
|
+
])) ?? 0;
|
|
27
|
+
}
|
|
28
|
+
async push(...vals) {
|
|
29
|
+
let length = await this.lengthAsync();
|
|
30
|
+
for (const val of vals){
|
|
31
|
+
await this.db.put({
|
|
32
|
+
value: val,
|
|
33
|
+
container: this.#container,
|
|
34
|
+
key: this.#name,
|
|
35
|
+
keyCount: length + 1,
|
|
36
|
+
slot: this.#slot(length)
|
|
37
|
+
});
|
|
38
|
+
length += 1;
|
|
39
|
+
}
|
|
40
|
+
return length;
|
|
41
|
+
}
|
|
42
|
+
async pop() {
|
|
43
|
+
const length = await this.lengthAsync();
|
|
44
|
+
if (length === 0) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
const slot = this.#slot(length - 1);
|
|
48
|
+
const data = await this.db.get(slot);
|
|
49
|
+
await this.db.delete(slot);
|
|
50
|
+
return data?.value;
|
|
51
|
+
}
|
|
52
|
+
async atAsync(index) {
|
|
53
|
+
const length = await this.lengthAsync();
|
|
54
|
+
if (index < 0) {
|
|
55
|
+
index = length + index;
|
|
56
|
+
}
|
|
57
|
+
const data = await this.db.get(this.#slot(index));
|
|
58
|
+
return data?.value;
|
|
59
|
+
}
|
|
60
|
+
async setAt(index, val) {
|
|
61
|
+
const length = await this.lengthAsync();
|
|
62
|
+
if (index < 0) {
|
|
63
|
+
index = length + index;
|
|
64
|
+
}
|
|
65
|
+
if (index < 0 || index >= length) {
|
|
66
|
+
return Promise.resolve(false);
|
|
67
|
+
}
|
|
68
|
+
await this.db.put({
|
|
69
|
+
value: val,
|
|
70
|
+
container: this.#container,
|
|
71
|
+
key: this.#name,
|
|
72
|
+
keyCount: index + 1,
|
|
73
|
+
slot: this.#slot(index)
|
|
74
|
+
});
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
async *entriesAsync() {
|
|
78
|
+
const index = this.db.index('key');
|
|
79
|
+
const rangeQuery = IDBKeyRange.bound([
|
|
80
|
+
this.#container,
|
|
81
|
+
this.#name
|
|
82
|
+
], [
|
|
83
|
+
this.#container,
|
|
84
|
+
this.#name
|
|
85
|
+
]);
|
|
86
|
+
for await (const cursor of index.iterate(rangeQuery)){
|
|
87
|
+
yield [
|
|
88
|
+
cursor.value.keyCount - 1,
|
|
89
|
+
cursor.value.value
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async *valuesAsync() {
|
|
94
|
+
for await (const [_, value] of this.entriesAsync()){
|
|
95
|
+
yield value;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
[Symbol.asyncIterator]() {
|
|
99
|
+
return this.valuesAsync();
|
|
100
|
+
}
|
|
101
|
+
#slot(index) {
|
|
102
|
+
return `array:${this.#name}:slot:${index}`;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { initStoreForRollup } from '../utils.js';
|
|
3
|
+
import { AztecIndexedDBStore } from './store.js';
|
|
4
|
+
export { AztecIndexedDBStore } from './store.js';
|
|
5
|
+
export async function createStore(name, config, log = createLogger('kv-store')) {
|
|
6
|
+
let { dataDirectory } = config;
|
|
7
|
+
if (typeof dataDirectory !== 'undefined') {
|
|
8
|
+
dataDirectory = `${dataDirectory}/${name}`;
|
|
9
|
+
}
|
|
10
|
+
log.info(dataDirectory ? `Creating ${name} data store at directory ${dataDirectory} with map size ${config.dataStoreMapSizeKB} KB` : `Creating ${name} ephemeral data store with map size ${config.dataStoreMapSizeKB} KB`);
|
|
11
|
+
const store = await AztecIndexedDBStore.open(createLogger('kv-store:indexeddb'), dataDirectory ?? '', false);
|
|
12
|
+
if (config.l1Contracts?.rollupAddress) {
|
|
13
|
+
return initStoreForRollup(store, config.l1Contracts.rollupAddress, log);
|
|
14
|
+
}
|
|
15
|
+
return store;
|
|
16
|
+
}
|
|
17
|
+
export function openTmpStore(ephemeral = false) {
|
|
18
|
+
return AztecIndexedDBStore.open(createLogger('kv-store:indexeddb'), undefined, ephemeral);
|
|
19
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { IDBPDatabase, IDBPObjectStore } from 'idb';
|
|
2
|
+
import type { Key, Range } from '../interfaces/common.js';
|
|
3
|
+
import type { AztecAsyncMultiMap } 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> implements AztecAsyncMultiMap<K, V> {
|
|
9
|
+
#private;
|
|
10
|
+
protected name: string;
|
|
11
|
+
constructor(rootDB: IDBPDatabase<AztecIDBSchema>, mapName: string);
|
|
12
|
+
set db(db: IDBPObjectStore<AztecIDBSchema, ['data'], 'data', 'readwrite'> | undefined);
|
|
13
|
+
get db(): IDBPObjectStore<AztecIDBSchema, ['data'], 'data', 'readwrite'>;
|
|
14
|
+
getAsync(key: K): Promise<V | undefined>;
|
|
15
|
+
getValuesAsync(key: K): AsyncIterableIterator<V>;
|
|
16
|
+
hasAsync(key: K): Promise<boolean>;
|
|
17
|
+
set(key: K, val: V): Promise<void>;
|
|
18
|
+
swap(_key: K, _fn: (val: V | undefined) => V): Promise<void>;
|
|
19
|
+
setIfNotExists(key: K, val: V): Promise<boolean>;
|
|
20
|
+
delete(key: K): Promise<void>;
|
|
21
|
+
deleteValue(key: K, val: V): Promise<void>;
|
|
22
|
+
entriesAsync(range?: Range<K>): AsyncIterableIterator<[K, V]>;
|
|
23
|
+
valuesAsync(range?: Range<K>): AsyncIterableIterator<V>;
|
|
24
|
+
keysAsync(range?: Range<K>): AsyncIterableIterator<K>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=map.d.ts.map
|
|
@@ -0,0 +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;AAEzD,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;GAEG;AACH,qBAAa,iBAAiB,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC,CAAE,YAAW,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC;;IAClF,SAAS,CAAC,IAAI,EAAE,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E,KAAK,CAAC,CAAC,CAAM,GAAG,qBAAqB,CAAC,CAAC,CAAC;CAmBjE"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A map backed by IndexedDB.
|
|
3
|
+
*/ export class IndexedDBAztecMap {
|
|
4
|
+
name;
|
|
5
|
+
#container;
|
|
6
|
+
#_db;
|
|
7
|
+
#rootDB;
|
|
8
|
+
constructor(rootDB, mapName){
|
|
9
|
+
this.name = mapName;
|
|
10
|
+
this.#container = `map:${mapName}`;
|
|
11
|
+
this.#rootDB = rootDB;
|
|
12
|
+
}
|
|
13
|
+
set db(db) {
|
|
14
|
+
this.#_db = db;
|
|
15
|
+
}
|
|
16
|
+
get db() {
|
|
17
|
+
return this.#_db ? this.#_db : this.#rootDB.transaction('data', 'readwrite').store;
|
|
18
|
+
}
|
|
19
|
+
async getAsync(key) {
|
|
20
|
+
const data = await this.db.get(this.#slot(key));
|
|
21
|
+
return data?.value;
|
|
22
|
+
}
|
|
23
|
+
async *getValuesAsync(key) {
|
|
24
|
+
const index = this.db.index('keyCount');
|
|
25
|
+
const rangeQuery = IDBKeyRange.bound([
|
|
26
|
+
this.#container,
|
|
27
|
+
this.#normalizeKey(key),
|
|
28
|
+
0
|
|
29
|
+
], [
|
|
30
|
+
this.#container,
|
|
31
|
+
this.#normalizeKey(key),
|
|
32
|
+
Number.MAX_SAFE_INTEGER
|
|
33
|
+
], false, false);
|
|
34
|
+
for await (const cursor of index.iterate(rangeQuery)){
|
|
35
|
+
yield cursor.value.value;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async hasAsync(key) {
|
|
39
|
+
const result = await this.getAsync(key) !== undefined;
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
async set(key, val) {
|
|
43
|
+
const count = await this.db.index('key').count(IDBKeyRange.bound([
|
|
44
|
+
this.#container,
|
|
45
|
+
this.#normalizeKey(key)
|
|
46
|
+
], [
|
|
47
|
+
this.#container,
|
|
48
|
+
this.#normalizeKey(key)
|
|
49
|
+
]));
|
|
50
|
+
await this.db.put({
|
|
51
|
+
value: val,
|
|
52
|
+
container: this.#container,
|
|
53
|
+
key: this.#normalizeKey(key),
|
|
54
|
+
keyCount: count + 1,
|
|
55
|
+
slot: this.#slot(key, count)
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
swap(_key, _fn) {
|
|
59
|
+
throw new Error('Not implemented');
|
|
60
|
+
}
|
|
61
|
+
async setIfNotExists(key, val) {
|
|
62
|
+
if (!await this.hasAsync(key)) {
|
|
63
|
+
await this.set(key, val);
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
async delete(key) {
|
|
69
|
+
await this.db.delete(this.#slot(key));
|
|
70
|
+
}
|
|
71
|
+
async deleteValue(key, val) {
|
|
72
|
+
const index = this.db.index('keyCount');
|
|
73
|
+
const rangeQuery = IDBKeyRange.bound([
|
|
74
|
+
this.#container,
|
|
75
|
+
this.#normalizeKey(key),
|
|
76
|
+
0
|
|
77
|
+
], [
|
|
78
|
+
this.#container,
|
|
79
|
+
this.#normalizeKey(key),
|
|
80
|
+
Number.MAX_SAFE_INTEGER
|
|
81
|
+
], false, false);
|
|
82
|
+
for await (const cursor of index.iterate(rangeQuery)){
|
|
83
|
+
if (JSON.stringify(cursor.value.value) === JSON.stringify(val)) {
|
|
84
|
+
await cursor.delete();
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async *entriesAsync(range = {}) {
|
|
90
|
+
const index = this.db.index('key');
|
|
91
|
+
const rangeQuery = IDBKeyRange.bound([
|
|
92
|
+
this.#container,
|
|
93
|
+
range.start ?? ''
|
|
94
|
+
], [
|
|
95
|
+
this.#container,
|
|
96
|
+
range.end ?? '\uffff'
|
|
97
|
+
], !!range.reverse, !range.reverse);
|
|
98
|
+
let count = 0;
|
|
99
|
+
for await (const cursor of index.iterate(rangeQuery, range.reverse ? 'prev' : 'next')){
|
|
100
|
+
if (range.limit && count >= range.limit) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
yield [
|
|
104
|
+
cursor.value.key,
|
|
105
|
+
cursor.value.value
|
|
106
|
+
];
|
|
107
|
+
count++;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async *valuesAsync(range = {}) {
|
|
111
|
+
for await (const [_, value] of this.entriesAsync(range)){
|
|
112
|
+
yield value;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
async *keysAsync(range = {}) {
|
|
116
|
+
for await (const [key, _] of this.entriesAsync(range)){
|
|
117
|
+
yield this.#denormalizeKey(key);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
#denormalizeKey(key) {
|
|
121
|
+
const denormalizedKey = key.split(',').map((part)=>isNaN(parseInt(part)) ? part : parseInt(part));
|
|
122
|
+
return denormalizedKey.length > 1 ? denormalizedKey : key;
|
|
123
|
+
}
|
|
124
|
+
#normalizeKey(key) {
|
|
125
|
+
const arrayKey = Array.isArray(key) ? key : [
|
|
126
|
+
key
|
|
127
|
+
];
|
|
128
|
+
return arrayKey.join(',');
|
|
129
|
+
}
|
|
130
|
+
#slot(key, index = 0) {
|
|
131
|
+
return `map:${this.name}:slot:${this.#normalizeKey(key)}:${index}`;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IndexedDBAztecMap } from './map.js';
|
|
2
|
+
/**
|
|
3
|
+
* A set backed by IndexedDB.
|
|
4
|
+
*/ export class IndexedDBAztecSet {
|
|
5
|
+
map;
|
|
6
|
+
constructor(rootDb, mapName){
|
|
7
|
+
this.map = new IndexedDBAztecMap(rootDb, mapName);
|
|
8
|
+
}
|
|
9
|
+
set db(db) {
|
|
10
|
+
this.map.db = db;
|
|
11
|
+
}
|
|
12
|
+
hasAsync(key) {
|
|
13
|
+
return this.map.hasAsync(key);
|
|
14
|
+
}
|
|
15
|
+
add(key) {
|
|
16
|
+
return this.map.set(key, true);
|
|
17
|
+
}
|
|
18
|
+
delete(key) {
|
|
19
|
+
return this.map.delete(key);
|
|
20
|
+
}
|
|
21
|
+
async *entriesAsync(range = {}) {
|
|
22
|
+
yield* this.map.keysAsync(range);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { IDBPDatabase, IDBPObjectStore } from 'idb';
|
|
2
|
+
import type { AztecAsyncSingleton } from '../interfaces/singleton.js';
|
|
3
|
+
import type { AztecIDBSchema } from './store.js';
|
|
4
|
+
/**
|
|
5
|
+
* Stores a single value in IndexedDB.
|
|
6
|
+
*/
|
|
7
|
+
export declare class IndexedDBAztecSingleton<T> implements AztecAsyncSingleton<T> {
|
|
8
|
+
#private;
|
|
9
|
+
constructor(rootDB: IDBPDatabase<AztecIDBSchema>, name: string);
|
|
10
|
+
set db(db: IDBPObjectStore<AztecIDBSchema, ['data'], 'data', 'readwrite'> | undefined);
|
|
11
|
+
get db(): IDBPObjectStore<AztecIDBSchema, ['data'], 'data', 'readwrite'>;
|
|
12
|
+
getAsync(): Promise<T | undefined>;
|
|
13
|
+
set(val: T): Promise<boolean>;
|
|
14
|
+
delete(): Promise<boolean>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=singleton.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"singleton.d.ts","sourceRoot":"","sources":["../../src/indexeddb/singleton.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;AAEzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;GAEG;AACH,qBAAa,uBAAuB,CAAC,CAAC,CAAE,YAAW,mBAAmB,CAAC,CAAC,CAAC;;gBAM3D,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,QAAQ,IAAI,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAKlC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAW7B,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC;CAIjC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stores a single value in IndexedDB.
|
|
3
|
+
*/ export class IndexedDBAztecSingleton {
|
|
4
|
+
#_db;
|
|
5
|
+
#rootDB;
|
|
6
|
+
#container;
|
|
7
|
+
#slot;
|
|
8
|
+
constructor(rootDB, name){
|
|
9
|
+
this.#rootDB = rootDB;
|
|
10
|
+
this.#container = `singleton:${name}`;
|
|
11
|
+
this.#slot = `singleton:${name}:value`;
|
|
12
|
+
}
|
|
13
|
+
set db(db) {
|
|
14
|
+
this.#_db = db;
|
|
15
|
+
}
|
|
16
|
+
get db() {
|
|
17
|
+
return this.#_db ? this.#_db : this.#rootDB.transaction('data', 'readwrite').store;
|
|
18
|
+
}
|
|
19
|
+
async getAsync() {
|
|
20
|
+
const data = await this.db.get(this.#slot);
|
|
21
|
+
return data?.value;
|
|
22
|
+
}
|
|
23
|
+
async set(val) {
|
|
24
|
+
const result = await this.db.put({
|
|
25
|
+
container: this.#container,
|
|
26
|
+
slot: this.#slot,
|
|
27
|
+
key: this.#slot,
|
|
28
|
+
keyCount: 1,
|
|
29
|
+
value: val
|
|
30
|
+
});
|
|
31
|
+
return result !== undefined;
|
|
32
|
+
}
|
|
33
|
+
async delete() {
|
|
34
|
+
await this.db.delete(this.#slot);
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
2
|
+
import { type DBSchema, type IDBPDatabase } from 'idb';
|
|
3
|
+
import type { AztecAsyncArray } from '../interfaces/array.js';
|
|
4
|
+
import type { Key, StoreSize } from '../interfaces/common.js';
|
|
5
|
+
import type { AztecAsyncCounter } from '../interfaces/counter.js';
|
|
6
|
+
import type { AztecAsyncMap, AztecAsyncMultiMap } from '../interfaces/map.js';
|
|
7
|
+
import type { AztecAsyncSet } from '../interfaces/set.js';
|
|
8
|
+
import type { AztecAsyncSingleton } from '../interfaces/singleton.js';
|
|
9
|
+
import type { AztecAsyncKVStore } from '../interfaces/store.js';
|
|
10
|
+
export type StoredData<V> = {
|
|
11
|
+
value: V;
|
|
12
|
+
container: string;
|
|
13
|
+
key: string;
|
|
14
|
+
keyCount: number;
|
|
15
|
+
slot: string;
|
|
16
|
+
};
|
|
17
|
+
export interface AztecIDBSchema extends DBSchema {
|
|
18
|
+
data: {
|
|
19
|
+
value: StoredData<any>;
|
|
20
|
+
key: string;
|
|
21
|
+
indexes: {
|
|
22
|
+
container: string;
|
|
23
|
+
key: string;
|
|
24
|
+
keyCount: number;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A key-value store backed by IndexedDB.
|
|
30
|
+
*/
|
|
31
|
+
export declare class AztecIndexedDBStore implements AztecAsyncKVStore {
|
|
32
|
+
#private;
|
|
33
|
+
readonly isEphemeral: boolean;
|
|
34
|
+
constructor(rootDB: IDBPDatabase<AztecIDBSchema>, isEphemeral: boolean, log: Logger, name: string);
|
|
35
|
+
/**
|
|
36
|
+
* Creates a new AztecKVStore backed by IndexedDB. The path to the database is optional. If not provided,
|
|
37
|
+
* the database will be stored in a temporary location and be deleted when the process exists.
|
|
38
|
+
*
|
|
39
|
+
*
|
|
40
|
+
* @param path - A path on the disk to store the database. Optional
|
|
41
|
+
* @param ephemeral - true if the store should only exist in memory and not automatically be flushed to disk. Optional
|
|
42
|
+
* @param log - A logger to use. Optional
|
|
43
|
+
* @returns The store
|
|
44
|
+
*/
|
|
45
|
+
static open(log: Logger, name?: string, ephemeral?: boolean): Promise<AztecIndexedDBStore>;
|
|
46
|
+
/**
|
|
47
|
+
* Forks the current DB into a new DB by backing it up to a temporary location and opening a new indexedb.
|
|
48
|
+
* @returns A new AztecIndexedDBStore.
|
|
49
|
+
*/
|
|
50
|
+
fork(): Promise<AztecAsyncKVStore>;
|
|
51
|
+
/**
|
|
52
|
+
* Creates a new AztecMap in the store.
|
|
53
|
+
* @param name - Name of the map
|
|
54
|
+
* @returns A new AztecMap
|
|
55
|
+
*/
|
|
56
|
+
openMap<K extends Key, V>(name: string): AztecAsyncMap<K, V>;
|
|
57
|
+
/**
|
|
58
|
+
* Creates a new AztecSet in the store.
|
|
59
|
+
* @param name - Name of the set
|
|
60
|
+
* @returns A new AztecSet
|
|
61
|
+
*/
|
|
62
|
+
openSet<K extends Key>(name: string): AztecAsyncSet<K>;
|
|
63
|
+
/**
|
|
64
|
+
* Creates a new AztecMultiMap in the store. A multi-map stores multiple values for a single key automatically.
|
|
65
|
+
* @param name - Name of the map
|
|
66
|
+
* @returns A new AztecMultiMap
|
|
67
|
+
*/
|
|
68
|
+
openMultiMap<K extends Key, V>(name: string): AztecAsyncMultiMap<K, V>;
|
|
69
|
+
openCounter<K extends Key>(_name: string): AztecAsyncCounter<K>;
|
|
70
|
+
/**
|
|
71
|
+
* Creates a new AztecArray in the store.
|
|
72
|
+
* @param name - Name of the array
|
|
73
|
+
* @returns A new AztecArray
|
|
74
|
+
*/
|
|
75
|
+
openArray<T>(name: string): AztecAsyncArray<T>;
|
|
76
|
+
/**
|
|
77
|
+
* Creates a new AztecSingleton in the store.
|
|
78
|
+
* @param name - Name of the singleton
|
|
79
|
+
* @returns A new AztecSingleton
|
|
80
|
+
*/
|
|
81
|
+
openSingleton<T>(name: string): AztecAsyncSingleton<T>;
|
|
82
|
+
/**
|
|
83
|
+
* Runs a callback in a transaction.
|
|
84
|
+
* @param callback - Function to execute in a transaction
|
|
85
|
+
* @returns A promise that resolves to the return value of the callback
|
|
86
|
+
*/
|
|
87
|
+
transactionAsync<T>(callback: () => Promise<T>): Promise<T>;
|
|
88
|
+
/**
|
|
89
|
+
* Clears all entries in the store & sub DBs.
|
|
90
|
+
*/
|
|
91
|
+
clear(): Promise<void>;
|
|
92
|
+
/** Deletes this store and removes the database */
|
|
93
|
+
delete(): Promise<void>;
|
|
94
|
+
estimateSize(): Promise<StoreSize>;
|
|
95
|
+
close(): Promise<void>;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +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,EAAoB,MAAM,KAAK,CAAC;AAEzE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAA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