Prefer type over interface

This commit is contained in:
RMidhunSuresh 2021-12-01 11:42:24 +05:30
parent b328c54da8
commit 82de3c9867
7 changed files with 30 additions and 30 deletions

View file

@ -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<string, string | number> = new Map();
if (accessToken) {
headers.set("Authorization", `Bearer ${accessToken}`);

View file

@ -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<BlobHandle> {
async downloadEncryptedFile(fileEntry: EncryptedFile, cache: boolean = false): Promise<BlobHandle> {
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<BlobHandle> {
async downloadAttachment(content: Attachment, cache: boolean = false): Promise<BlobHandle> {
if (content.file) {
return this.downloadEncryptedFile(content.file, cache);
} else {

View file

@ -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<ConnectionStatus>;
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;
}

View file

@ -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, any>): string {
.join("&");
}
export function encodeBody(body: Record<string, any>): IEncodedBody {
export function encodeBody(body: Record<string, any>): EncodedBody {
// todo: code change here
if (body instanceof BlobHandle) {
const blob = body as BlobHandle;

View file

@ -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;

View file

@ -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<string, boolean>;
}

View file

@ -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<string, string|number>;
cache?: boolean;
log?: LogItem;