From c873d59d9e1d7654c11d025e73bb2bf7d2499c1a Mon Sep 17 00:00:00 2001 From: Paul Marechal Date: Fri, 1 Oct 2021 19:24:34 -0400 Subject: [PATCH] improve RestClient typings --- src/protocol/rest-client.ts | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/protocol/rest-client.ts b/src/protocol/rest-client.ts index 5a7616f..4dedd19 100644 --- a/src/protocol/rest-client.ts +++ b/src/protocol/rest-client.ts @@ -27,15 +27,15 @@ export interface HttpResponse { */ export class RestClient { - public static get(url: string, parameters?: Map): Promise>>; - public static get(url: string, parameters?: Map, normalizer?: Normalizer): Promise>; + static get(url: string, parameters?: Map): Promise>>; + static get(url: string, parameters: Map | undefined, normalizer: Normalizer): Promise>; /** * Perform GET * @template T is the expected type of the json object returned by this request * @param url URL to query without query parameters * @param parameters Query parameters. Mapped keys and values are used to build the final URL */ - public static async get(url: string, parameters?: Map, normalizer?: Normalizer) { + static async get(url: string, parameters?: Map, normalizer?: Normalizer) { let getUrl = url; if (parameters) { const urlParameters = this.encodeURLParameters(parameters); @@ -44,39 +44,39 @@ export class RestClient { return this.performRequest('get', getUrl, undefined, normalizer); } - public static post(url: string, body?: any): Promise>>; - public static post(url: string, body?: any, normalizer?: Normalizer): Promise>; + static post(url: string, body?: any): Promise>>; + static post(url: string, body: any, normalizer: Normalizer): Promise>; /** * Perform POST * @template T is the expected type of the json object returned by this request * @param url URL to query * @param body Query object as defined by the Query interface */ - public static async post(url: string, body?: any, normalizer?: Normalizer) { + static async post(url: string, body?: any, normalizer?: Normalizer) { return this.performRequest('post', url, body, normalizer); } - public static put(url: string, body?: any): Promise>>; - public static put(url: string, body?: any, normalizer?: Normalizer): Promise>; + static put(url: string, body?: any): Promise>>; + static put(url: string, body: any, normalizer: Normalizer): Promise>; /** * Perform PUT * @template T is the expected type of the json object returned by this request * @param url URL to query * @param body Query object as defined by the Query interface */ - public static async put(url: string, body?: any, normalizer?: Normalizer) { + static async put(url: string, body?: any, normalizer?: Normalizer) { return this.performRequest('put', url, body, normalizer); } - public static delete(url: string, parameters?: Map): Promise>>; - public static delete(url: string, parameters?: Map, normalizer?: Normalizer): Promise>; + static delete(url: string, parameters?: Map): Promise>>; + static delete(url: string, parameters: Map | undefined, normalizer: Normalizer): Promise>; /** * Perform DELETE * @template T is the expected type of the json object returned by this request * @param url URL to query without query parameters * @param parameters Query parameters. Mapped keys and values are used to build the final URL */ - public static async delete(url: string, parameters?: Map, normalizer?: Normalizer) { + static async delete(url: string, parameters?: Map, normalizer?: Normalizer) { let deleteUrl = url; if (parameters) { const urlParameters = this.encodeURLParameters(parameters); @@ -85,9 +85,7 @@ export class RestClient { return this.performRequest('delete', deleteUrl, undefined, normalizer); } - protected static performRequest(method: string, url: string, body?: any): Promise>>; - protected static performRequest(method: string, url: string, body: any, normalizer?: Normalizer): Promise>; - protected static async performRequest(method, url, body?, normalizer?) { + protected static async performRequest(method: string, url: string, body?: any, normalizer?: Normalizer) { const response = await this.httpRequest({ url, method, @@ -126,15 +124,15 @@ export class RestClient { } /** - * Stringify JS objects. Can stringify `BigInt`s. + * Stringify JS objects. Can stringify `BigInt` values. */ protected static jsonStringify(data: any): string { return JSONBig.stringify(data); } /** - * Parse JSON-encoded data. If a number is too large to fit - * into a regular `number` then it will be deserialized as `BigInt`. + * Parse JSON-encoded data. If a number is too large to fit into a regular + * `number` then it will be deserialized as `BigInt`. */ protected static jsonParse(text: string): any { return JSONBig.parse(text);