summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/util
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2020-12-02 14:55:04 +0100
committerFlorian Dold <florian@dold.me>2020-12-02 14:55:04 +0100
commit89f1a281fea66b986fc0a003dc10446f6ed6e4a2 (patch)
tree8ffe90d572bc6967ee86bdcffc1eb6dc1240d17c /packages/taler-wallet-core/src/util
parent0828e65f8845dc4b148c0d3b0697fb589b338239 (diff)
downloadwallet-core-89f1a281fea66b986fc0a003dc10446f6ed6e4a2.tar.gz
wallet-core-89f1a281fea66b986fc0a003dc10446f6ed6e4a2.tar.bz2
wallet-core-89f1a281fea66b986fc0a003dc10446f6ed6e4a2.zip
backup WIP
Diffstat (limited to 'packages/taler-wallet-core/src/util')
-rw-r--r--packages/taler-wallet-core/src/util/http.ts20
-rw-r--r--packages/taler-wallet-core/src/util/query.ts4
2 files changed, 22 insertions, 2 deletions
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<any>;
text(): Promise<string>;
+ bytes(): Promise<ArrayBuffer>;
}
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<string, string> = {};
+ this.headerMap.forEach((v, k) => m[k] = v);
+ return m;
+ }
}
/**
@@ -104,6 +116,14 @@ export interface HttpRequestLibrary {
body: any,
opt?: HttpRequestOptions,
): Promise<HttpResponse>;
+
+ /**
+ * Make an HTTP POST request with a JSON body.
+ */
+ fetch(
+ url: string,
+ opt?: HttpRequestOptions,
+ ): Promise<HttpResponse>;
}
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<St extends Store<string, any>>(
- store: St extends Store<infer N, infer R> ? Store<N, R> : never,
- value: St extends Store<any, infer R> ? R : never,
+ store: St,
+ value: StoreContent<St>,
key?: any,
): Promise<any> {
const tx = this.db.transaction([store.name], "readwrite");