1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-28 05:03:59 +03:00

fix missing types and linting errors

This commit is contained in:
Germain Souquet
2021-09-11 16:06:29 +01:00
parent 0722dafe58
commit 375b228bb2
3 changed files with 34 additions and 37 deletions

View File

@@ -17,34 +17,13 @@ limitations under the License.
/** @module auto-discovery */
import { IClientWellKnown, IWellKnownConfig, AutoDiscoveryAction } from "./client";
import { logger } from './logger';
import { URL as NodeURL } from "url";
// Dev note: Auto discovery is part of the spec.
// See: https://matrix.org/docs/spec/client_server/r0.4.0.html#server-discovery
enum AutoDiscoveryAction {
SUCCESS = "SUCCESS",
IGNORE = "IGNORE",
PROMPT = "PROMPT",
FAIL_PROMPT = "FAIL_PROMPT",
FAIL_ERROR = "FAIL_ERROR",
}
interface DiscoveredClientConfig {
"m.homeserver"?: WellKnownConfig;
"m.identity_server"?: WellKnownConfig;
}
interface WellKnownConfig {
raw?: any; // todo typings
action?: AutoDiscoveryAction;
reason?: string;
error?: Error | string;
// eslint-disable-next-line
base_url?: string | null;
}
/**
* Utilities for automatically discovery resources, such as homeservers
* for users to log in to.
@@ -133,7 +112,7 @@ export class AutoDiscovery {
* configuration, which may include error states. Rejects on unexpected
* failure, not when verification fails.
*/
public static async fromDiscoveryConfig(wellknown: string): Promise<DiscoveredClientConfig> {
public static async fromDiscoveryConfig(wellknown: string): Promise<IClientWellKnown> {
// Step 1 is to get the config, which is provided to us here.
// We default to an error state to make the first few checks easier to
@@ -293,7 +272,7 @@ export class AutoDiscovery {
* configuration, which may include error states. Rejects on unexpected
* failure, not when discovery fails.
*/
public static async findClientConfig(domain: string): Promise<DiscoveredClientConfig> {
public static async findClientConfig(domain: string): Promise<IClientWellKnown> {
if (!domain || typeof(domain) !== "string" || domain.length === 0) {
throw new Error("'domain' must be a string of non-zero length");
}
@@ -361,7 +340,7 @@ export class AutoDiscovery {
* @returns {Promise<object>} Resolves to the domain's client config. Can
* be an empty object.
*/
public static async getRawClientConfig(domain: string): Promise<DiscoveredClientConfig> {
public static async getRawClientConfig(domain: string): Promise<IClientWellKnown> {
if (!domain || typeof(domain) !== "string" || domain.length === 0) {
throw new Error("'domain' must be a string of non-zero length");
}
@@ -429,7 +408,7 @@ export class AutoDiscovery {
* @return {Promise<object>} Resolves to the returned state.
* @private
*/
private static async fetchWellKnownObject(url: string): Promise<WellKnownConfig> { // TODO: TYPES
private static async fetchWellKnownObject(url: string): Promise<IWellKnownConfig> { // TODO: TYPES
return new Promise(function(resolve, reject) {
// eslint-disable-next-line
const request = require("./matrix").getRequest();

View File

@@ -475,14 +475,27 @@ interface IServerVersions {
unstable_features: Record<string, boolean>;
}
interface IClientWellKnown {
export interface IClientWellKnown {
[key: string]: any;
"m.homeserver": {
base_url: string;
};
"m.identity_server"?: {
base_url: string;
};
"m.homeserver"?: IWellKnownConfig;
"m.identity_server"?: IWellKnownConfig;
}
export interface IWellKnownConfig {
raw?: any; // todo typings
action?: AutoDiscoveryAction;
reason?: string;
error?: Error | string;
// eslint-disable-next-line
base_url?: string | null;
}
export enum AutoDiscoveryAction {
SUCCESS = "SUCCESS",
IGNORE = "IGNORE",
PROMPT = "PROMPT",
FAIL_PROMPT = "FAIL_PROMPT",
FAIL_ERROR = "FAIL_ERROR",
}
interface IKeyBackupPath {

View File

@@ -34,11 +34,16 @@ const TIMER_CHECK_PERIOD_MS = 1000;
let count = 0;
// the key for our callback with the real global.setTimeout
let realCallbackKey;
let realCallbackKey: NodeJS.Timeout | number;
// a sorted list of the callbacks to be run.
// each is an object with keys [runAt, func, params, key].
const callbackList = [];
const callbackList: {
runAt: number;
func: (...params: any[]) => void;
params: any[];
key: number;
}[] = [];
// var debuglog = logger.log.bind(logger);
const debuglog = function(...params: any[]) {};
@@ -126,7 +131,7 @@ export function clearTimeout(key: number): void {
// use the real global.setTimeout to schedule a callback to runCallbacks.
function scheduleRealCallback(): void {
if (realCallbackKey) {
global.clearTimeout(realCallbackKey);
global.clearTimeout(realCallbackKey as NodeJS.Timeout);
}
const first = callbackList[0];
@@ -182,7 +187,7 @@ function runCallbacks(): void {
* returns the index of the last element for which func returns
* greater than zero, or array.length if no such element exists.
*/
function binarySearch<T>(array: T[], func: (T) => number): number {
function binarySearch<T>(array: T[], func: (v: T) => number): number {
// min is inclusive, max exclusive.
let min = 0;
let max = array.length;