taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit c6f1a4b1d884171a109561a6dbd425a7fe537f79
parent ff474cb8865e660f4670b117225b78106a3d99e5
Author: Florian Dold <florian@dold.me>
Date:   Tue,  5 Nov 2024 11:55:16 +0100

qjs: allow directory as persistentStoragePath

Diffstat:
Mpackages/taler-wallet-embedded/src/wallet-qjs.ts | 37++++++++++++++++++++++++++++++++-----
1 file changed, 32 insertions(+), 5 deletions(-)

diff --git a/packages/taler-wallet-embedded/src/wallet-qjs.ts b/packages/taler-wallet-embedded/src/wallet-qjs.ts @@ -49,7 +49,7 @@ import { testWithFdold, testWithGv, testWithLocal, -} from './wallet-qjs-tests.js'; +} from "./wallet-qjs-tests.js"; setGlobalLogLevelFromString("trace"); @@ -88,6 +88,28 @@ class NativeWalletMessageHandler { switch (operation) { case "init": { + // Allow specifying a directory as the storage path. + // In that case, we pick the filename and use the sqlite3 + // backend. + // + // We still allow specifying a filename for backwards + // compatibility and control over the exact file. + // + // Specifying a directory allows us to automatically + // migrate to a new DB file in the future. + const p = args.args.persistentStoragePath; + let persistentStoragePath: string | undefined; + if (p != null) { + if (typeof p !== "string") { + throw Error("persistentStoragePath must be a string"); + } + if (p.endsWith("/")) { + persistentStoragePath = `${p}talerwalletdb-v30.sqlite3`; + } else { + persistentStoragePath = p; + } + } + const wR = await createNativeWalletHost2({ notifyHandler: async (notification: WalletNotification) => { sendNativeMessage({ type: "notification", payload: notification }); @@ -106,11 +128,16 @@ class NativeWalletMessageHandler { enableNativeLogging(); } - const resp = await wR.wallet.handleCoreApiRequest("initWallet", "native-init", { - config: args.config ?? {}, - }); + const resp = await wR.wallet.handleCoreApiRequest( + "initWallet", + "native-init", + { + config: args.config ?? {}, + }, + ); - let initResponse: any = resp.type == "response" ? resp.result : resp.error; + let initResponse: any = + resp.type == "response" ? resp.result : resp.error; this.wp.resolve(wR.wallet);