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

Convert bunch of things to TypeScript

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski
2020-04-21 11:45:54 +01:00
parent 414279f644
commit 77a1fc9e60
3 changed files with 46 additions and 3 deletions

25
src/@types/global.d.ts vendored Normal file
View File

@@ -0,0 +1,25 @@
/*
Copyright 2020 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
export {};
declare global {
namespace NodeJS {
interface Global {
localStorage: any;
}
}
}

View File

@@ -17,7 +17,12 @@ limitations under the License.
*/ */
import {MemoryCryptoStore} from "./crypto/store/memory-crypto-store"; 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 {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 {MatrixScheduler} from "./scheduler";
import {MatrixClient} from "./client"; import {MatrixClient} from "./client";
@@ -89,6 +94,10 @@ export function wrapRequest(wrapper) {
}; };
} }
type Store =
StubStore | MemoryStore | LocalIndexedDBStoreBackend | RemoteIndexedDBStoreBackend;
type CryptoStore = MemoryCryptoStore | LocalStorageCryptoStore | IndexedDBCryptoStore;
let cryptoStoreFactory = () => new MemoryCryptoStore; let cryptoStoreFactory = () => new MemoryCryptoStore;
@@ -102,6 +111,15 @@ export function setCryptoStoreFactory(fac) {
cryptoStoreFactory = fac; cryptoStoreFactory = fac;
} }
interface ICreateClientOpts {
baseUrl: string;
store?: Store;
cryptoStore?: CryptoStore;
scheduler?: MatrixScheduler;
request?: any; // TODO
}
/** /**
* Construct a Matrix Client. Similar to {@link module:client.MatrixClient} * Construct a Matrix Client. Similar to {@link module:client.MatrixClient}
* except that the 'request', 'store' and 'scheduler' dependencies are satisfied. * except that the 'request', 'store' and 'scheduler' dependencies are satisfied.
@@ -125,10 +143,10 @@ export function setCryptoStoreFactory(fac) {
* @see {@link module:client.MatrixClient} for the full list of options for * @see {@link module:client.MatrixClient} for the full list of options for
* <code>opts</code>. * <code>opts</code>.
*/ */
export function createClient(opts) { export function createClient(opts: ICreateClientOpts | string) {
if (typeof opts === "string") { if (typeof opts === "string") {
opts = { opts = {
"baseUrl": opts, "baseUrl": opts as string,
}; };
} }
opts.request = opts.request || requestInstance; opts.request = opts.request || requestInstance;

View File

@@ -265,7 +265,7 @@ export function checkObjectHasNoAdditionalKeys(obj: object, allowedKeys: string[
* @param {Object} obj The object to deep copy. * @param {Object} obj The object to deep copy.
* @return {Object} A copy of the object without any references to the original. * @return {Object} A copy of the object without any references to the original.
*/ */
export function deepCopy(obj: object): object { export function deepCopy<T>(obj: T): T {
return JSON.parse(JSON.stringify(obj)); return JSON.parse(JSON.stringify(obj));
} }