diff options
author | Florian Dold <florian@dold.me> | 2020-11-16 14:12:37 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2020-11-16 14:12:37 +0100 |
commit | 292160f7e979a0d9fdea7430f0d26b2dc1122a16 (patch) | |
tree | f82a576398408ebbe04d96a93355de61d745c925 /packages/taler-wallet-core/src/util | |
parent | cdf5cc583cd7fc938f38137da25aaee2aeaf28a9 (diff) | |
download | wallet-core-292160f7e979a0d9fdea7430f0d26b2dc1122a16.tar.xz |
fix tip record creation, migrate DB
Diffstat (limited to 'packages/taler-wallet-core/src/util')
-rw-r--r-- | packages/taler-wallet-core/src/util/helpers.ts | 4 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/util/query.ts | 28 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/util/taleruri.ts | 9 |
3 files changed, 34 insertions, 7 deletions
diff --git a/packages/taler-wallet-core/src/util/helpers.ts b/packages/taler-wallet-core/src/util/helpers.ts index ae4b0359e..570df441d 100644 --- a/packages/taler-wallet-core/src/util/helpers.ts +++ b/packages/taler-wallet-core/src/util/helpers.ts @@ -146,3 +146,7 @@ export function strcmp(s1: string, s2: string): number { } return 0; } + +export function j2s(x: any): string { + return JSON.stringify(x, undefined, 2); +}
\ No newline at end of file diff --git a/packages/taler-wallet-core/src/util/query.ts b/packages/taler-wallet-core/src/util/query.ts index 6ebc3bbc4..f533c4cfd 100644 --- a/packages/taler-wallet-core/src/util/query.ts +++ b/packages/taler-wallet-core/src/util/query.ts @@ -44,14 +44,25 @@ const logger = new Logger("query.ts"); */ export const TransactionAbort = Symbol("transaction_abort"); +export interface StoreParams<T> { + validator?: (v: T) => T; + autoIncrement?: boolean; + keyPath?: string | string[] | null; + + /** + * Database version that this store was added in, or + * undefined if added in the first version. + */ + versionAdded?: number; +} + /** * Definition of an object store. */ export class Store<T> { constructor( public name: string, - public storeParams?: IDBObjectStoreParameters, - public validator?: (v: T) => T, + public storeParams?: StoreParams<T>, ) {} } @@ -66,6 +77,12 @@ export interface IndexOptions { * Defaults to false. */ multiEntry?: boolean; + + /** + * Database version that this store was added in, or + * undefined if added in the first version. + */ + versionAdded?: number; } function requestToPromise(req: IDBRequest): Promise<any> { @@ -425,6 +442,7 @@ export function openDatabase( db: IDBDatabase, oldVersion: number, newVersion: number, + upgradeTransaction: IDBTransaction, ) => void, ): Promise<IDBDatabase> { return new Promise<IDBDatabase>((resolve, reject) => { @@ -449,7 +467,11 @@ export function openDatabase( if (!newVersion) { throw Error("upgrade needed, but new version unknown"); } - onUpgradeNeeded(db, e.oldVersion, newVersion); + const transaction = req.transaction; + if (!transaction) { + throw Error("no transaction handle available in upgrade handler"); + } + onUpgradeNeeded(db, e.oldVersion, newVersion, transaction); }; }); } diff --git a/packages/taler-wallet-core/src/util/taleruri.ts b/packages/taler-wallet-core/src/util/taleruri.ts index 839d0b29f..ee055a32f 100644 --- a/packages/taler-wallet-core/src/util/taleruri.ts +++ b/packages/taler-wallet-core/src/util/taleruri.ts @@ -14,6 +14,7 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ +import { canonicalizeBaseUrl } from './helpers'; import { URLSearchParams } from "./url"; export interface PayUriResult { @@ -59,7 +60,7 @@ export function parseWithdrawUri(s: string): WithdrawUriResult | undefined { const p = [host, ...pathSegments].join("/"); return { - bankIntegrationApiBaseUrl: `${pi.innerProto}://${p}/`, + bankIntegrationApiBaseUrl: canonicalizeBaseUrl(`${pi.innerProto}://${p}/`), withdrawalOperationId: withdrawId, }; } @@ -155,7 +156,7 @@ export function parsePayUri(s: string): PayUriResult | undefined { const orderId = parts[parts.length - 2]; const pathSegments = parts.slice(1, parts.length - 2); const p = [host, ...pathSegments].join("/"); - const merchantBaseUrl = `${pi.innerProto}://${p}/`; + const merchantBaseUrl = canonicalizeBaseUrl(`${pi.innerProto}://${p}/`); return { merchantBaseUrl, @@ -183,7 +184,7 @@ export function parseTipUri(s: string): TipUriResult | undefined { const tipId = parts[parts.length - 1]; const pathSegments = parts.slice(1, parts.length - 1); const p = [host, ...pathSegments].join("/"); - const merchantBaseUrl = `${pi.innerProto}://${p}/`; + const merchantBaseUrl = canonicalizeBaseUrl(`${pi.innerProto}://${p}/`); return { merchantBaseUrl, @@ -210,7 +211,7 @@ export function parseRefundUri(s: string): RefundUriResult | undefined { const orderId = parts[parts.length - 2]; const pathSegments = parts.slice(1, parts.length - 2); const p = [host, ...pathSegments].join("/"); - const merchantBaseUrl = `${pi.innerProto}://${p}/`; + const merchantBaseUrl = canonicalizeBaseUrl(`${pi.innerProto}://${p}/`); return { merchantBaseUrl, |