From 89f1a281fea66b986fc0a003dc10446f6ed6e4a2 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 2 Dec 2020 14:55:04 +0100 Subject: backup WIP --- packages/taler-wallet-core/src/util/http.ts | 20 ++++++++++++++++++++ packages/taler-wallet-core/src/util/query.ts | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'packages/taler-wallet-core/src/util') diff --git a/packages/taler-wallet-core/src/util/http.ts b/packages/taler-wallet-core/src/util/http.ts index 1a2459f7e..1ec9c2f50 100644 --- a/packages/taler-wallet-core/src/util/http.ts +++ b/packages/taler-wallet-core/src/util/http.ts @@ -17,6 +17,8 @@ /** * Helpers for doing XMLHttpRequest-s that are based on ES6 promises. * Allows for easy mocking for test cases. + * + * The API is inspired by the HTML5 fetch API. */ /** @@ -47,16 +49,20 @@ export interface HttpResponse { headers: Headers; json(): Promise; text(): Promise; + bytes(): Promise; } export interface HttpRequestOptions { + method?: "POST" | "PUT" | "GET"; headers?: { [name: string]: string }; timeout?: Duration; + body?: string | ArrayBuffer | ArrayBufferView; } export enum HttpResponseStatus { Ok = 200, Gone = 210, + PaymentRequired = 402, } /** @@ -82,6 +88,12 @@ export class Headers { this.headerMap.set(normalizedName, value); } } + + toJSON(): any { + const m: Record = {}; + this.headerMap.forEach((v, k) => m[k] = v); + return m; + } } /** @@ -104,6 +116,14 @@ export interface HttpRequestLibrary { body: any, opt?: HttpRequestOptions, ): Promise; + + /** + * Make an HTTP POST request with a JSON body. + */ + fetch( + url: string, + opt?: HttpRequestOptions, + ): Promise; } type TalerErrorResponse = { diff --git a/packages/taler-wallet-core/src/util/query.ts b/packages/taler-wallet-core/src/util/query.ts index 08572fbd2..beb14cad0 100644 --- a/packages/taler-wallet-core/src/util/query.ts +++ b/packages/taler-wallet-core/src/util/query.ts @@ -595,8 +595,8 @@ export class Database { } async put>( - store: St extends Store ? Store : never, - value: St extends Store ? R : never, + store: St, + value: StoreContent, key?: any, ): Promise { const tx = this.db.transaction([store.name], "readwrite"); -- cgit v1.2.3