From 82de3c9867b4cd1996f9fb1fa2dc2c0e49b58c57 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Wed, 1 Dec 2021 11:42:24 +0530 Subject: [PATCH] Prefer type over interface --- src/matrix/net/HomeServerApi.ts | 4 ++-- src/matrix/net/MediaRepository.ts | 6 +++--- src/matrix/net/Reconnector.ts | 6 +++--- src/matrix/net/common.ts | 4 ++-- src/matrix/net/request/replay.ts | 18 +++++++++--------- src/matrix/net/types/response.ts | 18 +++++++++--------- src/platform/types/types.ts | 4 ++-- 7 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/matrix/net/HomeServerApi.ts b/src/matrix/net/HomeServerApi.ts index 1de5a4dc..69b86bbb 100644 --- a/src/matrix/net/HomeServerApi.ts +++ b/src/matrix/net/HomeServerApi.ts @@ -19,7 +19,7 @@ import {encodeQueryParams, encodeBody} from "./common"; import {HomeServerRequest} from "./HomeServerRequest"; import type {IHomeServerRequest} from "./HomeServerRequest"; import type {Reconnector} from "./Reconnector"; -import type {IEncodedBody} from "./common"; +import type {EncodedBody} from "./common"; import type {IRequestOptions, RequestFunction} from "../../platform/types/types"; import type {LogItem} from "../../logging/LogItem"; @@ -66,7 +66,7 @@ export class HomeServerApi { method, }, parent.level.Info); } - let encodedBody: IEncodedBody["body"]; + let encodedBody: EncodedBody["body"]; const headers: Map = new Map(); if (accessToken) { headers.set("Authorization", `Bearer ${accessToken}`); diff --git a/src/matrix/net/MediaRepository.ts b/src/matrix/net/MediaRepository.ts index a19eac9a..357b17c6 100644 --- a/src/matrix/net/MediaRepository.ts +++ b/src/matrix/net/MediaRepository.ts @@ -18,7 +18,7 @@ import {encodeQueryParams} from "./common"; import {decryptAttachment} from "../e2ee/attachment.js"; import {Platform} from "../../platform/web/Platform.js"; import {BlobHandle} from "../../platform/web/dom/BlobHandle.js"; -import type {IAttachment, IEncryptedFile} from "./types/response"; +import type {Attachment, EncryptedFile} from "./types/response"; export class MediaRepository { private readonly _homeserver: string; @@ -58,7 +58,7 @@ export class MediaRepository { } } - async downloadEncryptedFile(fileEntry: IEncryptedFile, cache: boolean = false): Promise { + async downloadEncryptedFile(fileEntry: EncryptedFile, cache: boolean = false): Promise { const url = this.mxcUrl(fileEntry.url); const {body: encryptedBuffer} = await this._platform.request(url, {method: "GET", format: "buffer", cache}).response(); const decryptedBuffer = await decryptAttachment(this._platform, encryptedBuffer, fileEntry); @@ -71,7 +71,7 @@ export class MediaRepository { return this._platform.createBlob(buffer, mimetype); } - async downloadAttachment(content: IAttachment, cache: boolean = false): Promise { + async downloadAttachment(content: Attachment, cache: boolean = false): Promise { if (content.file) { return this.downloadEncryptedFile(content.file, cache); } else { diff --git a/src/matrix/net/Reconnector.ts b/src/matrix/net/Reconnector.ts index 607ba0b4..bc54ab73 100644 --- a/src/matrix/net/Reconnector.ts +++ b/src/matrix/net/Reconnector.ts @@ -18,7 +18,7 @@ import {ObservableValue} from "../../observable/ObservableValue"; import type {ExponentialRetryDelay} from "./ExponentialRetryDelay"; import type {TimeMeasure} from "../../platform/web/dom/Clock.js"; import type {OnlineStatus} from "../../platform/web/dom/OnlineStatus.js"; -import type {IVersionResponse} from "./types/response"; +import type {VersionResponse} from "./types/response"; import type {HomeServerApi} from "./HomeServerApi"; export enum ConnectionStatus { @@ -39,7 +39,7 @@ export class Reconnector { private readonly _onlineStatus: OnlineStatus; private readonly _state: ObservableValue; private _isReconnecting: boolean; - private _versionsResponse?: IVersionResponse; + private _versionsResponse?: VersionResponse; private _stateSince: TimeMeasure; constructor({retryDelay, createMeasure, onlineStatus}: Ctor) { @@ -51,7 +51,7 @@ export class Reconnector { this._isReconnecting = false; } - get lastVersionsResponse(): IVersionResponse | undefined { + get lastVersionsResponse(): VersionResponse | undefined { return this._versionsResponse; } diff --git a/src/matrix/net/common.ts b/src/matrix/net/common.ts index ea7970d4..287e5e9e 100644 --- a/src/matrix/net/common.ts +++ b/src/matrix/net/common.ts @@ -17,7 +17,7 @@ limitations under the License. import {BlobHandle} from "../../platform/web/dom/BlobHandle.js"; -export interface IEncodedBody { +export type EncodedBody = { mimeType: string; body: BlobHandle | string; length: number; @@ -35,7 +35,7 @@ export function encodeQueryParams(queryParams?: Record): string { .join("&"); } -export function encodeBody(body: Record): IEncodedBody { +export function encodeBody(body: Record): EncodedBody { // todo: code change here if (body instanceof BlobHandle) { const blob = body as BlobHandle; diff --git a/src/matrix/net/request/replay.ts b/src/matrix/net/request/replay.ts index 32a059d3..461049f8 100644 --- a/src/matrix/net/request/replay.ts +++ b/src/matrix/net/request/replay.ts @@ -18,21 +18,21 @@ import {AbortError, ConnectionError} from "../../error.js"; import type {IRequestOptions, RequestFunction} from "../../../platform/types/types.js"; import type {RequestResult} from "../../../platform/web/dom/request/fetch.js"; -interface IOptions extends IRequestOptions { +type Options = IRequestOptions & { method?: any; delay?: boolean; } class RequestLogItem { public readonly url: string; - public readonly options: IOptions; + public readonly options: Options; public error: {aborted: boolean, network: boolean, message: string}; public status: number; public body: Response["body"]; public start: number = performance.now(); public end: number = 0; - constructor(url: string, options: IOptions) { + constructor(url: string, options: Options) { this.url = url; this.options = options; } @@ -62,7 +62,7 @@ export class RecordRequester { this.request = this.request.bind(this); } - request(url: string, options: IOptions): RequestResult { + request(url: string, options: Options): RequestResult { const requestItem = new RequestLogItem(url, options); this._requestLog.push(requestItem); try { @@ -84,15 +84,15 @@ export class RecordRequester { export class ReplayRequester { private readonly _log: RequestLogItem[]; - private readonly _options: IOptions; + private readonly _options: Options; - constructor(log: RequestLogItem[], options: IOptions) { + constructor(log: RequestLogItem[], options: Options) { this._log = log.slice(); this._options = options; this.request = this.request.bind(this); } - request(url: string, options: IOptions): ReplayRequestResult { + request(url: string, options: Options): ReplayRequestResult { const idx = this._log.findIndex((item) => { return item.url === url && options.method === item.options.method; }); @@ -107,10 +107,10 @@ export class ReplayRequester { class ReplayRequestResult { private readonly _item: RequestLogItem; - private readonly _options: IOptions; + private readonly _options: Options; private _aborted: boolean; - constructor(item: RequestLogItem, options: IOptions) { + constructor(item: RequestLogItem, options: Options) { this._item = item; this._options = options; this._aborted = false; diff --git a/src/matrix/net/types/response.ts b/src/matrix/net/types/response.ts index e4b71d36..4f0af7ec 100644 --- a/src/matrix/net/types/response.ts +++ b/src/matrix/net/types/response.ts @@ -14,17 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -export interface IAttachment { +export type Attachment = { body: string; - info: IAttachmentInfo; + info: AttachmentInfo; // todo: what about m.audio? msgtype: "m.image" | "m.file" | "m.video"; url?: string; - file?: IEncryptedFile; + file?: EncryptedFile; filename?: string; } -export interface IEncryptedFile { +export type EncryptedFile = { key: JsonWebKey; iv: string; hashes: { @@ -35,25 +35,25 @@ export interface IEncryptedFile { mimetype?: string; } -interface IAttachmentInfo { +type AttachmentInfo = { h?: number; w?: number; mimetype: string; size: number; duration?: number; thumbnail_url?: string; - thumbnail_file?: IEncryptedFile; - thumbnail_info?: IThumbnailInfo; + thumbnail_file?: EncryptedFile; + thumbnail_info?: ThumbnailInfo; } -interface IThumbnailInfo { +type ThumbnailInfo = { h: number; w: number; mimetype: string; size: number; } -export interface IVersionResponse { +export type VersionResponse = { versions: string[]; unstable_features?: Record; } diff --git a/src/platform/types/types.ts b/src/platform/types/types.ts index 817f3739..f619c706 100644 --- a/src/platform/types/types.ts +++ b/src/platform/types/types.ts @@ -15,13 +15,13 @@ limitations under the License. */ import type {RequestResult} from "../web/dom/request/fetch.js"; -import type {IEncodedBody} from "../../matrix/net/common"; +import type {EncodedBody} from "../../matrix/net/common"; import type {LogItem} from "../../logging/LogItem"; export interface IRequestOptions { uploadProgress?: (loadedBytes: number) => void; timeout?: number; - body?: IEncodedBody; + body?: EncodedBody; headers?: Map; cache?: boolean; log?: LogItem;