Cleaned up old Dexie class. Added mnemonic and dateCreated columns.

This commit is contained in:
Matthew Aaron Raymer
2022-12-16 13:34:01 +08:00
parent c9d5ab82fd
commit 607230b51c
8 changed files with 7 additions and 119 deletions

View File

@@ -1,34 +0,0 @@
import Dexie, { type Table } from "dexie";
import { encrypted, Encryption } from "@pvermeer/dexie-encrypted-addon";
import { AppString } from "@/constants/app";
import { AppTable } from "../constants/table";
import { Field } from "@/constants/model";
import { IDBAccount } from "@/models/Account";
export class DexieWrapper extends Dexie {
[AppTable.ACCOUNTS]!: Table<IDBAccount>;
constructor(name: string, secret: string) {
super(name, { autoOpen: true });
encrypted(this, { secretKey: secret });
this.version(1).stores({
[AppTable.ACCOUNTS]: `#&${Field.ID}, $${Field.IDENTITY}`,
});
}
}
const secret =
localStorage.getItem("secret") || Encryption.createRandomEncryptionKey();
if (localStorage.getItem("secret") == null) {
localStorage.setItem("secret", secret);
}
/**
* Preconfigured DexieWrapper
*/
export const dexieWrapper = new DexieWrapper(
`${AppString.APP_NAME} v${AppString.VERSION}`,
secret
);