You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-29 16:43:09 +03:00
fix missing types and linting errors
This commit is contained in:
@@ -17,34 +17,13 @@ limitations under the License.
|
|||||||
|
|
||||||
/** @module auto-discovery */
|
/** @module auto-discovery */
|
||||||
|
|
||||||
|
import { IClientWellKnown, IWellKnownConfig, AutoDiscoveryAction } from "./client";
|
||||||
import { logger } from './logger';
|
import { logger } from './logger';
|
||||||
import { URL as NodeURL } from "url";
|
import { URL as NodeURL } from "url";
|
||||||
|
|
||||||
// Dev note: Auto discovery is part of the spec.
|
// Dev note: Auto discovery is part of the spec.
|
||||||
// See: https://matrix.org/docs/spec/client_server/r0.4.0.html#server-discovery
|
// 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
|
* Utilities for automatically discovery resources, such as homeservers
|
||||||
* for users to log in to.
|
* for users to log in to.
|
||||||
@@ -133,7 +112,7 @@ export class AutoDiscovery {
|
|||||||
* configuration, which may include error states. Rejects on unexpected
|
* configuration, which may include error states. Rejects on unexpected
|
||||||
* failure, not when verification fails.
|
* 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.
|
// 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
|
// 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
|
* configuration, which may include error states. Rejects on unexpected
|
||||||
* failure, not when discovery fails.
|
* 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) {
|
if (!domain || typeof(domain) !== "string" || domain.length === 0) {
|
||||||
throw new Error("'domain' must be a string of non-zero length");
|
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
|
* @returns {Promise<object>} Resolves to the domain's client config. Can
|
||||||
* be an empty object.
|
* 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) {
|
if (!domain || typeof(domain) !== "string" || domain.length === 0) {
|
||||||
throw new Error("'domain' must be a string of non-zero length");
|
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.
|
* @return {Promise<object>} Resolves to the returned state.
|
||||||
* @private
|
* @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) {
|
return new Promise(function(resolve, reject) {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
const request = require("./matrix").getRequest();
|
const request = require("./matrix").getRequest();
|
||||||
|
|||||||
@@ -475,14 +475,27 @@ interface IServerVersions {
|
|||||||
unstable_features: Record<string, boolean>;
|
unstable_features: Record<string, boolean>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IClientWellKnown {
|
export interface IClientWellKnown {
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
"m.homeserver": {
|
"m.homeserver"?: IWellKnownConfig;
|
||||||
base_url: string;
|
"m.identity_server"?: IWellKnownConfig;
|
||||||
};
|
}
|
||||||
"m.identity_server"?: {
|
|
||||||
base_url: string;
|
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 {
|
interface IKeyBackupPath {
|
||||||
|
|||||||
@@ -34,11 +34,16 @@ const TIMER_CHECK_PERIOD_MS = 1000;
|
|||||||
let count = 0;
|
let count = 0;
|
||||||
|
|
||||||
// the key for our callback with the real global.setTimeout
|
// 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.
|
// a sorted list of the callbacks to be run.
|
||||||
// each is an object with keys [runAt, func, params, key].
|
// 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);
|
// var debuglog = logger.log.bind(logger);
|
||||||
const debuglog = function(...params: any[]) {};
|
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.
|
// use the real global.setTimeout to schedule a callback to runCallbacks.
|
||||||
function scheduleRealCallback(): void {
|
function scheduleRealCallback(): void {
|
||||||
if (realCallbackKey) {
|
if (realCallbackKey) {
|
||||||
global.clearTimeout(realCallbackKey);
|
global.clearTimeout(realCallbackKey as NodeJS.Timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
const first = callbackList[0];
|
const first = callbackList[0];
|
||||||
@@ -182,7 +187,7 @@ function runCallbacks(): void {
|
|||||||
* returns the index of the last element for which func returns
|
* returns the index of the last element for which func returns
|
||||||
* greater than zero, or array.length if no such element exists.
|
* 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.
|
// min is inclusive, max exclusive.
|
||||||
let min = 0;
|
let min = 0;
|
||||||
let max = array.length;
|
let max = array.length;
|
||||||
|
|||||||
Reference in New Issue
Block a user