From 69e67ad5ace7210dff60f5ca5a2faa2d1aa5047f Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Tue, 23 Nov 2021 19:31:13 +0530 Subject: [PATCH] Make more functions private --- src/matrix/net/HomeServerApi.ts | 19 +++++++++---------- src/matrix/net/MediaRepository.ts | 2 +- src/matrix/net/Reconnector.ts | 4 ++-- src/matrix/net/RequestScheduler.ts | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/matrix/net/HomeServerApi.ts b/src/matrix/net/HomeServerApi.ts index d8da297f..3f99497d 100644 --- a/src/matrix/net/HomeServerApi.ts +++ b/src/matrix/net/HomeServerApi.ts @@ -42,11 +42,11 @@ export class HomeServerApi { this._reconnector = reconnector; } - _url(csPath: string, prefix: string = CS_R0_PREFIX): string { + private _url(csPath: string, prefix: string = CS_R0_PREFIX): string { return this._homeserver + prefix + csPath; } - _baseRequest(method: RequestMethod, url: string, queryParams?: Record, body?: Record, options?: IRequestOptions, accessToken?: string): HomeServerRequest { + private _baseRequest(method: RequestMethod, url: string, queryParams?: Record, body?: Record, options?: IRequestOptions, accessToken?: string): HomeServerRequest { const queryString = encodeQueryParams(queryParams); url = `${url}?${queryString}`; let log: LogItem | undefined; @@ -98,23 +98,23 @@ export class HomeServerApi { return hsRequest; } - _unauthedRequest(method: RequestMethod, url: string, queryParams?: Record, body?: Record, options?: IRequestOptions): HomeServerRequest { + private _unauthedRequest(method: RequestMethod, url: string, queryParams?: Record, body?: Record, options?: IRequestOptions): HomeServerRequest { return this._baseRequest(method, url, queryParams, body, options); } - _authedRequest(method: RequestMethod, url: string, queryParams?: Record, body?: Record, options?: IRequestOptions): HomeServerRequest { + private _authedRequest(method: RequestMethod, url: string, queryParams?: Record, body?: Record, options?: IRequestOptions): HomeServerRequest { return this._baseRequest(method, url, queryParams, body, options, this._accessToken); } - _post(csPath: string, queryParams: Record, body: Record, options?: IRequestOptions): HomeServerRequest { + private _post(csPath: string, queryParams: Record, body: Record, options?: IRequestOptions): HomeServerRequest { return this._authedRequest("POST", this._url(csPath, options?.prefix || CS_R0_PREFIX), queryParams, body, options); } - _put(csPath: string, queryParams: Record, body?: Record, options?: IRequestOptions): HomeServerRequest { + private _put(csPath: string, queryParams: Record, body?: Record, options?: IRequestOptions): HomeServerRequest { return this._authedRequest("PUT", this._url(csPath, options?.prefix || CS_R0_PREFIX), queryParams, body, options); } - _get(csPath: string, queryParams?: Record, body?: Record, options?: IRequestOptions): HomeServerRequest { + private _get(csPath: string, queryParams?: Record, body?: Record, options?: IRequestOptions): HomeServerRequest { return this._authedRequest("GET", this._url(csPath, options?.prefix || CS_R0_PREFIX), queryParams, body, options); } @@ -275,9 +275,8 @@ export function tests() { request: () => new MockRequest().respond(200, 42), homeserver: "https://hs.tld", }); - const result = await hsApi - ._get("foo", undefined, undefined, undefined) - .response(); + // @ts-ignore + const result = await hsApi._get("foo", undefined, undefined, undefined).response(); assert.strictEqual(result, 42); } } diff --git a/src/matrix/net/MediaRepository.ts b/src/matrix/net/MediaRepository.ts index 0bf70149..a19eac9a 100644 --- a/src/matrix/net/MediaRepository.ts +++ b/src/matrix/net/MediaRepository.ts @@ -49,7 +49,7 @@ export class MediaRepository { } } - _parseMxcUrl(url: string): string[] | null { + private _parseMxcUrl(url: string): string[] | null { const prefix = "mxc://"; if (url.startsWith(prefix)) { return url.substr(prefix.length).split("/", 2); diff --git a/src/matrix/net/Reconnector.ts b/src/matrix/net/Reconnector.ts index b1394425..0d20b623 100644 --- a/src/matrix/net/Reconnector.ts +++ b/src/matrix/net/Reconnector.ts @@ -93,7 +93,7 @@ export class Reconnector { } } - _setState(state: ConnectionStatus): void { + private _setState(state: ConnectionStatus): void { if (state !== this._state.get()) { if (state === ConnectionStatus.Waiting) { this._stateSince = this._createTimeMeasure(); @@ -104,7 +104,7 @@ export class Reconnector { } } - async _reconnectLoop(hsApi: HomeServerApi): Promise { + private async _reconnectLoop(hsApi: HomeServerApi): Promise { this._versionsResponse = undefined; this._retryDelay.reset(); diff --git a/src/matrix/net/RequestScheduler.ts b/src/matrix/net/RequestScheduler.ts index 2b9fe855..c0ab1d60 100644 --- a/src/matrix/net/RequestScheduler.ts +++ b/src/matrix/net/RequestScheduler.ts @@ -97,7 +97,7 @@ export class RequestScheduler { this._stopped = false; } - _hsApiRequest(name: string, args: any[]): Request { + private _hsApiRequest(name: string, args: any[]): Request { const request = new Request(name, args); this._doSend(request); return request;