diff --git a/src/db/index.ts b/src/db/index.ts index 26dcee0..e6d469e 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -1,6 +1,12 @@ import BaseDexie, { Table } from "dexie"; import { encrypted, Encryption } from "@pvermeer/dexie-encrypted-addon"; -import { Account, accountsSchema } from "./tables/accounts"; +import { + Account, + AccountsSchema, + MASTER_SETTINGS, + Settings, + SettingsSchema, +} from "./tables"; /** * In order to make the next line be acceptable, the program needs to have its linter suppress a rule: @@ -12,10 +18,13 @@ import { Account, accountsSchema } from "./tables/accounts"; */ type DexieTables = { accounts: Table; + settings: Table; }; + export type Dexie = BaseDexie & T; export const db = new BaseDexie("KickStart") as Dexie; -const schema = Object.assign({}, accountsSchema); + +const AllSchemas = Object.assign({}, AccountsSchema, SettingsSchema); /** * Needed to enable a special webpack setting to allow *await* below: @@ -29,6 +38,12 @@ const secret = if (localStorage.getItem("secret") == null) { localStorage.setItem("secret", secret); } -console.log(secret); +console.log("Secret:", secret); encrypted(db, { secretKey: secret }); -db.version(1).stores(schema); +db.version(1).stores(AllSchemas); + +// initialize, a la https://dexie.org/docs/Tutorial/Design#the-populate-event +db.on("populate", function () { + // ensure there's an initial entry for settings + db.settings.add({ id: MASTER_SETTINGS }); +}); diff --git a/src/db/tables/accounts.ts b/src/db/tables/index.ts similarity index 66% rename from src/db/tables/accounts.ts rename to src/db/tables/index.ts index d4a4e61..1c48594 100644 --- a/src/db/tables/accounts.ts +++ b/src/db/tables/index.ts @@ -9,7 +9,20 @@ export type Account = { // mark encrypted field by starting with a $ character // see https://github.com/PVermeer/dexie-addon-suite-monorepo/tree/master/packages/dexie-encrypted-addon -export const accountsSchema = { +export const AccountsSchema = { accounts: "++id, dateCreated, derivationPath, $identity, $mnemonic, publicKeyHex", }; + +// a singleton +export type Settings = { + id: number; + firstName?: string; + lastName?: string; +}; + +export const SettingsSchema = { + settings: "id", +}; + +export const MASTER_SETTINGS = 1; diff --git a/src/views/AccountViewView.vue b/src/views/AccountViewView.vue index a202dfa..e97cabe 100644 --- a/src/views/AccountViewView.vue +++ b/src/views/AccountViewView.vue @@ -185,46 +185,47 @@