1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-25 05:23:13 +03:00
This commit is contained in:
Jorik Schellekens
2020-07-21 10:33:16 +01:00
parent 0f559050d8
commit 72675f7266
6 changed files with 241 additions and 215 deletions

View File

@@ -1,5 +1,5 @@
module.exports = {
extends: ["matrix-org", "matrix-org/legacy"],
extends: ["matrix-org"],
plugins: [
"babel",
"jest",
@@ -10,10 +10,32 @@ module.exports = {
},
rules: {
quotes: ["off"],
"no-var": ["warn"],
"prefer-rest-params": ["warn"],
"prefer-spread": ["warn"],
"one-var": ["warn"],
"padded-blocks": ["warn"],
"no-extend-native": ["warn"],
"camelcase": ["warn"],
"no-multi-spaces": ["error", { "ignoreEOLComments": true }],
"space-before-function-paren": ["error", {
"anonymous": "never",
"named": "never",
"asyncArrow": "always",
}],
"arrow-parens": "off",
"prefer-promise-reject-errors": "off",
"quotes": "off",
"indent": "off",
"no-constant-condition": "off",
"no-async-promise-executor": "off",
},
overrides: [{
files: ["src/**/*.{ts, tsx}"],
"extends": ["matrix-org/ts"],
"rules": {
// While we're converting to ts we make heavy use of this
"@typescript-eslint/no-explicit-any": "off",
}
}],
}

View File

@@ -14,7 +14,7 @@
"build:minify-browser": "terser dist/browser-matrix.js --compress --mangle --source-map --output dist/browser-matrix.min.js",
"gendoc": "jsdoc -c jsdoc.json -P package.json",
"lint": "yarn lint:types && yarn lint:js",
"lint:js": "eslint --max-warnings 81 src spec",
"lint:js": "eslint --max-warnings 76 src spec --fix",
"lint:types": "tsc --noEmit",
"test": "jest spec/ --coverage --testEnvironment node",
"test:watch": "jest spec/ --coverage --testEnvironment node --watch"

View File

@@ -14,19 +14,20 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import * as matrixcs from "./matrix";
import * as utils from "./utils";
import request from "request";
import * as matrixcs from './matrix';
import * as utils from './utils';
import request from 'request';
matrixcs.request(request);
utils.runPolyfills();
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const crypto = require('crypto');
utils.setCrypto(crypto);
} catch (err) {
console.log('nodejs was compiled without crypto support');
}
export * from "./matrix";
export * from './matrix';
export default matrixcs;

View File

@@ -16,49 +16,49 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import type Request from "request";
import type Request from 'request';
import {MemoryCryptoStore} from "./crypto/store/memory-crypto-store";
import {LocalStorageCryptoStore} from "./crypto/store/localStorage-crypto-store";
import {IndexedDBCryptoStore} from "./crypto/store/indexeddb-crypto-store";
import {MemoryStore} from "./store/memory";
import {StubStore} from "./store/stub";
import {LocalIndexedDBStoreBackend} from "./store/indexeddb-local-backend";
import {RemoteIndexedDBStoreBackend} from "./store/indexeddb-remote-backend";
import {MatrixScheduler} from "./scheduler";
import {MatrixClient} from "./client";
import {MemoryCryptoStore} from './crypto/store/memory-crypto-store';
import {LocalStorageCryptoStore} from './crypto/store/localStorage-crypto-store';
import {IndexedDBCryptoStore} from './crypto/store/indexeddb-crypto-store';
import {MemoryStore} from './store/memory';
import {StubStore} from './store/stub';
import {LocalIndexedDBStoreBackend} from './store/indexeddb-local-backend';
import {RemoteIndexedDBStoreBackend} from './store/indexeddb-remote-backend';
import {MatrixScheduler} from './scheduler';
import {MatrixClient} from './client';
export * from "./client";
export * from "./http-api";
export * from "./autodiscovery";
export * from "./sync-accumulator";
export * from "./errors";
export * from "./models/event";
export * from "./models/room";
export * from "./models/group";
export * from "./models/event-timeline";
export * from "./models/event-timeline-set";
export * from "./models/room-member";
export * from "./models/room-state";
export * from "./models/user";
export * from "./scheduler";
export * from "./filter";
export * from "./timeline-window";
export * from "./interactive-auth";
export * from "./service-types";
export * from "./store/memory";
export * from "./store/indexeddb";
export * from "./store/session/webstorage";
export * from "./crypto/store/memory-crypto-store";
export * from "./crypto/store/indexeddb-crypto-store";
export * from "./content-repo";
export const ContentHelpers = import("./content-helpers");
export * from './client';
export * from './http-api';
export * from './autodiscovery';
export * from './sync-accumulator';
export * from './errors';
export * from './models/event';
export * from './models/room';
export * from './models/group';
export * from './models/event-timeline';
export * from './models/event-timeline-set';
export * from './models/room-member';
export * from './models/room-state';
export * from './models/user';
export * from './scheduler';
export * from './filter';
export * from './timeline-window';
export * from './interactive-auth';
export * from './service-types';
export * from './store/memory';
export * from './store/indexeddb';
export * from './store/session/webstorage';
export * from './crypto/store/memory-crypto-store';
export * from './crypto/store/indexeddb-crypto-store';
export * from './content-repo';
export const ContentHelpers = import('./content-helpers');
export {
createNewMatrixCall,
setAudioOutput as setMatrixCallAudioOutput,
setAudioInput as setMatrixCallAudioInput,
setVideoInput as setMatrixCallVideoInput,
} from "./webrtc/call";
} from './webrtc/call';
// expose the underlying request object so different environments can use
@@ -146,9 +146,9 @@ interface ICreateClientOpts {
* <code>opts</code>.
*/
export function createClient(opts: ICreateClientOpts | string) {
if (typeof opts === "string") {
if (typeof opts === 'string') {
opts = {
"baseUrl": opts as string,
'baseUrl': opts as string,
};
}
opts.request = opts.request || requestInstance;

View File

@@ -16,8 +16,8 @@ limitations under the License.
*/
export function randomString(len: number): string {
let ret = "";
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let ret = '';
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (let i = 0; i < len; ++i) {
ret += chars.charAt(Math.floor(Math.random() * chars.length));

View File

@@ -20,8 +20,10 @@ limitations under the License.
* @module utils
*/
// We do some funky stuff in this module
/* eslint-disable no-extend-native */
import unhomoglyph from 'unhomoglyph';
import {ConnectionError} from "./http-api";
/**
* Encode a dictionary of query parameters.
@@ -30,12 +32,12 @@ import {ConnectionError} from "./http-api";
* @return {string} The encoded string e.g. foo=bar&baz=taz
*/
export function encodeParams(params: Record<string, string>): string {
let qs = "";
let qs = '';
for (const key in params) {
if (!params.hasOwnProperty(key)) {
continue;
}
qs += "&" + encodeURIComponent(key) + "=" +
qs += '&' + encodeURIComponent(key) + '=' +
encodeURIComponent(params[key]);
}
return qs.substring(1);
@@ -154,7 +156,7 @@ export function forEach<T>(array: T[], fn: (t: T, i: number) => void) {
export function findElement<T>(
array: T[],
fn: (t: T, i?: number, a?: T[]) => boolean,
reverse?: boolean
reverse?: boolean,
) {
let i;
if (reverse) {
@@ -185,7 +187,7 @@ export function findElement<T>(
export function removeElement<T>(
array: T[],
fn: (t: T, i?: number, a?: T[]) => boolean,
reverse?: boolean
reverse?: boolean,
) {
let i;
let removed;
@@ -215,7 +217,7 @@ export function removeElement<T>(
* @return {boolean} True if it is a function.
*/
export function isFunction(value: any) {
return Object.prototype.toString.call(value) === "[object Function]";
return Object.prototype.toString.call(value) === '[object Function]';
}
/**
@@ -238,7 +240,7 @@ export function isArray(value: any) {
export function checkObjectHasKeys(obj: object, keys_: string[]) {
for (let i = 0; i < keys_.length; i++) {
if (!obj.hasOwnProperty(keys_[i])) {
throw new Error("Missing required key: " + keys_[i]);
throw new Error('Missing required key: ' + keys_[i]);
}
}
}
@@ -255,7 +257,7 @@ export function checkObjectHasNoAdditionalKeys(obj: object, allowedKeys: string[
continue;
}
if (allowedKeys.indexOf(key) === -1) {
throw new Error("Unknown key: " + key);
throw new Error('Unknown key: ' + key);
}
}
}
@@ -369,10 +371,10 @@ export function deepCompare(x: any, y: any): boolean {
*
* @return {Object} target
*/
export function extend() {
const target = arguments[0] || {};
for (let i = 1; i < arguments.length; i++) {
const source = arguments[i];
export function extend(...restParams) {
const target = restParams[0] || {};
for (let i = 1; i < restParams.length; i++) {
const source = restParams[i];
if (!source) continue;
for (const propName in source) { // eslint-disable-line guard-for-in
target[propName] = source[propName];
@@ -390,7 +392,7 @@ export function runPolyfills() {
// SOURCE:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
if (!Array.prototype.filter) {
Array.prototype.filter = function(fun: Function/*, thisArg*/) {
Array.prototype.filter = function(fun: Function, thisArg?: any) {
if (this === void 0 || this === null) {
throw new TypeError();
}
@@ -402,7 +404,7 @@ export function runPolyfills() {
}
const res = [];
const thisArg = arguments.length >= 2 ? arguments[1] : void 0;
const thisArg = thisArg ? thisArg : void 0;
for (let i = 0; i < len; i++) {
if (i in t) {
const val = t[i];
@@ -430,7 +432,7 @@ export function runPolyfills() {
// Reference: http://es5.github.io/#x15.4.4.19
if (!Array.prototype.map) {
Array.prototype.map = function(callback, thisArg) {
let T, k;
let T; let k;
if (this === null || this === undefined) {
throw new TypeError(' this is null or not defined');
@@ -466,7 +468,7 @@ export function runPolyfills() {
// 8. Repeat, while k < len
while (k < len) {
let kValue, mappedValue;
let kValue; let mappedValue;
// a. Let Pk be ToString(k).
// This is implicit for LHS operands of the in operator
@@ -520,7 +522,7 @@ export function runPolyfills() {
// Reference: http://es5.github.io/#x15.4.4.18
if (!Array.prototype.forEach) {
Array.prototype.forEach = function(callback, thisArg) {
let T, k;
let T; let k;
if (this === null || this === undefined) {
throw new TypeError(' this is null or not defined');
@@ -537,7 +539,7 @@ export function runPolyfills() {
// 4. If IsCallable(callback) is false, throw a TypeError exception.
// See: http://es5.github.com/#x9.11
if (typeof callback !== "function") {
if (typeof callback !== 'function') {
throw new TypeError(callback + ' is not a function');
}
@@ -667,10 +669,11 @@ export function removeHiddenChars(str: string): string {
// LTR/RTL and other directional formatting marks U+202A - U+202F
// Combining characters U+0300 - U+036F
// Zero width no-break space (BOM) U+FEFF
// eslint-disable-next-line no-misleading-character-class
const removeHiddenCharsRegex = /[\u2000-\u200F\u202A-\u202F\u0300-\u036f\uFEFF\s]/g;
export function escapeRegExp(string: string): string {
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
export function globToRegexp(glob: string, extended: any): string {
@@ -693,7 +696,7 @@ export function globToRegexp(glob: string, extended: any): string {
}
export function ensureNoTrailingSlash(url: string): string {
if (url && url.endsWith("/")) {
if (url && url.endsWith('/')) {
return url.substr(0, url.length - 1);
} else {
return url;
@@ -726,7 +729,7 @@ export function defer() {
export async function promiseMapSeries<T>(
promises: Promise<T>[],
fn: (t: T) => void
fn: (t: T) => void,
): Promise<void> {
for (const o of await promises) {
await fn(await o);