diff options
Diffstat (limited to 'packages/taler-wallet-core/src/db.ts')
-rw-r--r-- | packages/taler-wallet-core/src/db.ts | 98 |
1 files changed, 49 insertions, 49 deletions
diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index 0aae2ddff..ff1e87ccb 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -64,10 +64,7 @@ import { DbRetryInfo, TaskIdentifiers } from "./operations/common.js"; import { DbAccess, DbReadOnlyTransaction, - DbReadOnlyTransactionArr, DbReadWriteTransaction, - DbReadWriteTransactionArr, - GetReadWriteAccess, IndexDescriptor, StoreDescriptor, StoreNames, @@ -1338,9 +1335,9 @@ export enum ConfigRecordKey { */ export type ConfigRecord = | { - key: ConfigRecordKey.WalletBackupState; - value: WalletBackupConfState; - } + key: ConfigRecordKey.WalletBackupState; + value: WalletBackupConfState; + } | { key: ConfigRecordKey.CurrencyDefaultsApplied; value: boolean } | { key: ConfigRecordKey.DevMode; value: boolean } | { key: ConfigRecordKey.TestLoopTx; value: number }; @@ -1618,15 +1615,15 @@ export enum BackupProviderStateTag { export type BackupProviderState = | { - tag: BackupProviderStateTag.Provisional; - } + tag: BackupProviderStateTag.Provisional; + } | { - tag: BackupProviderStateTag.Ready; - nextBackupTimestamp: DbPreciseTimestamp; - } + tag: BackupProviderStateTag.Ready; + nextBackupTimestamp: DbPreciseTimestamp; + } | { - tag: BackupProviderStateTag.Retrying; - }; + tag: BackupProviderStateTag.Retrying; + }; export interface BackupProviderTerms { supportedProtocolVersion: string; @@ -2715,21 +2712,23 @@ export const WalletStoresV1 = { type WalletStoreNames = StoreNames<typeof WalletStoresV1>; -export type WalletDbReadOnlyTransaction< - Stores extends StoreNames<typeof WalletStoresV1> & string, -> = DbReadOnlyTransaction<typeof WalletStoresV1, Stores>; - export type WalletDbReadWriteTransaction< - Stores extends StoreNames<typeof WalletStoresV1> & string, -> = DbReadWriteTransaction<typeof WalletStoresV1, Stores>; - -export type WalletDbReadWriteTransactionArr< StoresArr extends Array<StoreNames<typeof WalletStoresV1>>, -> = DbReadWriteTransactionArr<typeof WalletStoresV1, StoresArr>; +> = DbReadWriteTransaction<typeof WalletStoresV1, StoresArr>; -export type WalletDbReadOnlyTransactionArr< +export type WalletDbReadOnlyTransaction< StoresArr extends Array<StoreNames<typeof WalletStoresV1>>, -> = DbReadOnlyTransactionArr<typeof WalletStoresV1, StoresArr>; +> = DbReadOnlyTransaction<typeof WalletStoresV1, StoresArr>; + +export type WalletDbAllStoresReadOnlyTransaction<> = DbReadOnlyTransaction< + typeof WalletStoresV1, + Array<StoreNames<typeof WalletStoresV1>> +>; + +export type WalletDbAllStoresReadWriteTransaction<> = DbReadWriteTransaction< + typeof WalletStoresV1, + Array<StoreNames<typeof WalletStoresV1>> +>; /** * An applied migration. @@ -2939,7 +2938,12 @@ export async function importDb(db: IDBDatabase, dumpJson: any): Promise<void> { export interface FixupDescription { name: string; - fn(tx: GetReadWriteAccess<typeof WalletStoresV1>): Promise<void>; + fn( + tx: DbReadWriteTransaction< + typeof WalletStoresV1, + Array<StoreNames<typeof WalletStoresV1>> + >, + ): Promise<void>; } /** @@ -2953,7 +2957,7 @@ export async function applyFixups( db: DbAccess<typeof WalletStoresV1>, ): Promise<void> { logger.trace("applying fixups"); - await db.mktxAll().runReadWrite(async (tx) => { + await db.runAllStoresReadWriteTx(async (tx) => { for (const fixupInstruction of walletDbFixups) { logger.trace(`checking fixup ${fixupInstruction.name}`); const fixupRecord = await tx.fixups.get(fixupInstruction.name); @@ -3156,7 +3160,7 @@ export async function openStoredBackupsDatabase( idbFactory, TALER_WALLET_STORED_BACKUPS_DB_NAME, 1, - () => { }, + () => {}, onStoredBackupsDbUpgradeNeeded, ); @@ -3179,26 +3183,24 @@ export async function openTalerDatabase( idbFactory, TALER_WALLET_META_DB_NAME, 1, - () => { }, + () => {}, onMetaDbUpgradeNeeded, ); const metaDb = new DbAccess(metaDbHandle, walletMetadataStore); let currentMainVersion: string | undefined; - await metaDb - .mktx((stores) => [stores.metaConfig]) - .runReadWrite(async (tx) => { - const dbVersionRecord = await tx.metaConfig.get(CURRENT_DB_CONFIG_KEY); - if (!dbVersionRecord) { - currentMainVersion = TALER_WALLET_MAIN_DB_NAME; - await tx.metaConfig.put({ - key: CURRENT_DB_CONFIG_KEY, - value: TALER_WALLET_MAIN_DB_NAME, - }); - } else { - currentMainVersion = dbVersionRecord.value; - } - }); + await metaDb.runReadWriteTx(["metaConfig"], async (tx) => { + const dbVersionRecord = await tx.metaConfig.get(CURRENT_DB_CONFIG_KEY); + if (!dbVersionRecord) { + currentMainVersion = TALER_WALLET_MAIN_DB_NAME; + await tx.metaConfig.put({ + key: CURRENT_DB_CONFIG_KEY, + value: TALER_WALLET_MAIN_DB_NAME, + }); + } else { + currentMainVersion = dbVersionRecord.value; + } + }); if (currentMainVersion !== TALER_WALLET_MAIN_DB_NAME) { switch (currentMainVersion) { @@ -3212,14 +3214,12 @@ export async function openTalerDatabase( case "taler-wallet-main-v9": // We consider this a pre-release // development version, no migration is done. - await metaDb - .mktx((stores) => [stores.metaConfig]) - .runReadWrite(async (tx) => { - await tx.metaConfig.put({ - key: CURRENT_DB_CONFIG_KEY, - value: TALER_WALLET_MAIN_DB_NAME, - }); + await metaDb.runReadWriteTx(["metaConfig"], async (tx) => { + await tx.metaConfig.put({ + key: CURRENT_DB_CONFIG_KEY, + value: TALER_WALLET_MAIN_DB_NAME, }); + }); break; default: throw Error( |