aboutsummaryrefslogtreecommitdiff
path: root/packages/idb-bridge/src/MemoryBackend.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2021-02-23 20:16:10 +0100
committerFlorian Dold <florian@dold.me>2021-02-23 20:16:10 +0100
commit9c85f6277bf85606eb4fbbca47f1a1b5404d2a2e (patch)
tree553a3b9ff58be2962e81b16d87b97ea42c257081 /packages/idb-bridge/src/MemoryBackend.ts
parent29d23b192da66b38d7bf8d80303d3cfb61fc9bdd (diff)
downloadwallet-core-9c85f6277bf85606eb4fbbca47f1a1b5404d2a2e.tar.gz
wallet-core-9c85f6277bf85606eb4fbbca47f1a1b5404d2a2e.tar.bz2
wallet-core-9c85f6277bf85606eb4fbbca47f1a1b5404d2a2e.zip
idb: implement missing methods
Diffstat (limited to 'packages/idb-bridge/src/MemoryBackend.ts')
-rw-r--r--packages/idb-bridge/src/MemoryBackend.ts39
1 files changed, 39 insertions, 0 deletions
diff --git a/packages/idb-bridge/src/MemoryBackend.ts b/packages/idb-bridge/src/MemoryBackend.ts
index 2317fb163..68f60f756 100644
--- a/packages/idb-bridge/src/MemoryBackend.ts
+++ b/packages/idb-bridge/src/MemoryBackend.ts
@@ -860,6 +860,45 @@ export class MemoryBackend implements Backend {
});
}
+ async clearObjectStore(
+ btx: DatabaseTransaction,
+ objectStoreName: string,
+ ): Promise<void> {
+ const myConn = this.requireConnectionFromTransaction(btx);
+ const db = this.databases[myConn.dbName];
+ if (!db) {
+ throw Error("db not found");
+ }
+ if (db.txLevel < TransactionLevel.Write) {
+ throw Error("only allowed in write transaction");
+ }
+ if (
+ db.txRestrictObjectStores &&
+ !db.txRestrictObjectStores.includes(objectStoreName)
+ ) {
+ throw Error(
+ `Not allowed to access store '${objectStoreName}', transaction is over ${JSON.stringify(
+ db.txRestrictObjectStores,
+ )}`,
+ );
+ }
+
+ const schema = myConn.modifiedSchema;
+ const objectStoreMapEntry = myConn.objectStoreMap[objectStoreName];
+
+ objectStoreMapEntry.store.modifiedData = new BTree([], compareKeys);
+
+ for (const indexName of Object.keys(
+ schema.objectStores[objectStoreName].indexes,
+ )) {
+ const index = myConn.objectStoreMap[objectStoreName].indexMap[indexName];
+ if (!index) {
+ throw Error("index referenced by object store does not exist");
+ }
+ index.modifiedData = new BTree([], compareKeys);
+ }
+ }
+
async deleteRecord(
btx: DatabaseTransaction,
objectStoreName: string,