Skip to content

Commit f30be87

Browse files
authored
Fix more function typings relating to key backup (#2086)
* Fix more function typings relating to key backup * Use function overloads to specify allowed params
1 parent ab19480 commit f30be87

File tree

1 file changed

+106
-3
lines changed

1 file changed

+106
-3
lines changed

src/client.ts

Lines changed: 106 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2658,7 +2658,14 @@ export class MatrixClient extends EventEmitter {
26582658
);
26592659
}
26602660

2661-
private makeKeyBackupPath(roomId: string, sessionId: string, version: string): IKeyBackupPath {
2661+
private makeKeyBackupPath(roomId: undefined, sessionId: undefined, version: string): IKeyBackupPath;
2662+
private makeKeyBackupPath(roomId: string, sessionId: undefined, version: string): IKeyBackupPath;
2663+
private makeKeyBackupPath(roomId: string, sessionId: string, version: string): IKeyBackupPath;
2664+
private makeKeyBackupPath(
2665+
roomId: string | undefined,
2666+
sessionId: string | undefined,
2667+
version: string,
2668+
): IKeyBackupPath {
26622669
let path;
26632670
if (sessionId !== undefined) {
26642671
path = utils.encodeUri("/room_keys/keys/$roomId/$sessionId", {
@@ -2685,7 +2692,15 @@ export class MatrixClient extends EventEmitter {
26852692
* @return {Promise} a promise that will resolve when the keys
26862693
* are uploaded
26872694
*/
2688-
public sendKeyBackup(roomId: string, sessionId: string, version: string, data: IKeyBackup): Promise<void> {
2695+
public sendKeyBackup(roomId: undefined, sessionId: undefined, version: string, data: IKeyBackup): Promise<void>;
2696+
public sendKeyBackup(roomId: string, sessionId: undefined, version: string, data: IKeyBackup): Promise<void>;
2697+
public sendKeyBackup(roomId: string, sessionId: string, version: string, data: IKeyBackup): Promise<void>;
2698+
public sendKeyBackup(
2699+
roomId: string,
2700+
sessionId: string | undefined,
2701+
version: string | undefined,
2702+
data: IKeyBackup,
2703+
): Promise<void> {
26892704
if (!this.crypto) {
26902705
throw new Error("End-to-end encryption disabled");
26912706
}
@@ -2771,12 +2786,33 @@ export class MatrixClient extends EventEmitter {
27712786
* @return {Promise<object>} Status of restoration with `total` and `imported`
27722787
* key counts.
27732788
*/
2789+
public async restoreKeyBackupWithPassword(
2790+
password: string,
2791+
targetRoomId: undefined,
2792+
targetSessionId: undefined,
2793+
backupInfo: IKeyBackupInfo,
2794+
opts: IKeyBackupRestoreOpts,
2795+
): Promise<IKeyBackupRestoreResult>;
2796+
public async restoreKeyBackupWithPassword(
2797+
password: string,
2798+
targetRoomId: string,
2799+
targetSessionId: undefined,
2800+
backupInfo: IKeyBackupInfo,
2801+
opts: IKeyBackupRestoreOpts,
2802+
): Promise<IKeyBackupRestoreResult>;
27742803
public async restoreKeyBackupWithPassword(
27752804
password: string,
27762805
targetRoomId: string,
27772806
targetSessionId: string,
27782807
backupInfo: IKeyBackupInfo,
27792808
opts: IKeyBackupRestoreOpts,
2809+
): Promise<IKeyBackupRestoreResult>;
2810+
public async restoreKeyBackupWithPassword(
2811+
password: string,
2812+
targetRoomId: string | undefined,
2813+
targetSessionId: string | undefined,
2814+
backupInfo: IKeyBackupInfo,
2815+
opts: IKeyBackupRestoreOpts,
27802816
): Promise<IKeyBackupRestoreResult> {
27812817
const privKey = await keyFromAuthData(backupInfo.auth_data, password);
27822818
return this.restoreKeyBackup(
@@ -2833,22 +2869,61 @@ export class MatrixClient extends EventEmitter {
28332869
* @return {Promise<object>} Status of restoration with `total` and `imported`
28342870
* key counts.
28352871
*/
2872+
public restoreKeyBackupWithRecoveryKey(
2873+
recoveryKey: string,
2874+
targetRoomId: undefined,
2875+
targetSessionId: undefined,
2876+
backupInfo: IKeyBackupInfo,
2877+
opts: IKeyBackupRestoreOpts,
2878+
): Promise<IKeyBackupRestoreResult>;
2879+
public restoreKeyBackupWithRecoveryKey(
2880+
recoveryKey: string,
2881+
targetRoomId: string,
2882+
targetSessionId: undefined,
2883+
backupInfo: IKeyBackupInfo,
2884+
opts: IKeyBackupRestoreOpts,
2885+
): Promise<IKeyBackupRestoreResult>;
28362886
public restoreKeyBackupWithRecoveryKey(
28372887
recoveryKey: string,
28382888
targetRoomId: string,
28392889
targetSessionId: string,
28402890
backupInfo: IKeyBackupInfo,
28412891
opts: IKeyBackupRestoreOpts,
2892+
): Promise<IKeyBackupRestoreResult>;
2893+
public restoreKeyBackupWithRecoveryKey(
2894+
recoveryKey: string,
2895+
targetRoomId: string | undefined,
2896+
targetSessionId: string | undefined,
2897+
backupInfo: IKeyBackupInfo,
2898+
opts: IKeyBackupRestoreOpts,
28422899
): Promise<IKeyBackupRestoreResult> {
28432900
const privKey = decodeRecoveryKey(recoveryKey);
28442901
return this.restoreKeyBackup(privKey, targetRoomId, targetSessionId, backupInfo, opts);
28452902
}
28462903

2904+
public async restoreKeyBackupWithCache(
2905+
targetRoomId: undefined,
2906+
targetSessionId: undefined,
2907+
backupInfo: IKeyBackupInfo,
2908+
opts?: IKeyBackupRestoreOpts,
2909+
): Promise<IKeyBackupRestoreResult>;
2910+
public async restoreKeyBackupWithCache(
2911+
targetRoomId: string,
2912+
targetSessionId: undefined,
2913+
backupInfo: IKeyBackupInfo,
2914+
opts?: IKeyBackupRestoreOpts,
2915+
): Promise<IKeyBackupRestoreResult>;
28472916
public async restoreKeyBackupWithCache(
28482917
targetRoomId: string,
28492918
targetSessionId: string,
28502919
backupInfo: IKeyBackupInfo,
28512920
opts?: IKeyBackupRestoreOpts,
2921+
): Promise<IKeyBackupRestoreResult>;
2922+
public async restoreKeyBackupWithCache(
2923+
targetRoomId: string | undefined,
2924+
targetSessionId: string | undefined,
2925+
backupInfo: IKeyBackupInfo,
2926+
opts?: IKeyBackupRestoreOpts,
28522927
): Promise<IKeyBackupRestoreResult> {
28532928
const privKey = await this.crypto.getSessionBackupPrivateKey();
28542929
if (!privKey) {
@@ -2857,12 +2932,33 @@ export class MatrixClient extends EventEmitter {
28572932
return this.restoreKeyBackup(privKey, targetRoomId, targetSessionId, backupInfo, opts);
28582933
}
28592934

2935+
private async restoreKeyBackup(
2936+
privKey: ArrayLike<number>,
2937+
targetRoomId: undefined,
2938+
targetSessionId: undefined,
2939+
backupInfo: IKeyBackupInfo,
2940+
opts?: IKeyBackupRestoreOpts,
2941+
): Promise<IKeyBackupRestoreResult>;
2942+
private async restoreKeyBackup(
2943+
privKey: ArrayLike<number>,
2944+
targetRoomId: string,
2945+
targetSessionId: undefined,
2946+
backupInfo: IKeyBackupInfo,
2947+
opts?: IKeyBackupRestoreOpts,
2948+
): Promise<IKeyBackupRestoreResult>;
28602949
private async restoreKeyBackup(
28612950
privKey: ArrayLike<number>,
28622951
targetRoomId: string,
28632952
targetSessionId: string,
28642953
backupInfo: IKeyBackupInfo,
28652954
opts?: IKeyBackupRestoreOpts,
2955+
): Promise<IKeyBackupRestoreResult>;
2956+
private async restoreKeyBackup(
2957+
privKey: ArrayLike<number>,
2958+
targetRoomId: string | undefined,
2959+
targetSessionId: string | undefined,
2960+
backupInfo: IKeyBackupInfo,
2961+
opts?: IKeyBackupRestoreOpts,
28662962
): Promise<IKeyBackupRestoreResult> {
28672963
const cacheCompleteCallback = opts?.cacheCompleteCallback;
28682964
const progressCallback = opts?.progressCallback;
@@ -2953,7 +3049,14 @@ export class MatrixClient extends EventEmitter {
29533049
return { total: totalKeyCount, imported: keys.length };
29543050
}
29553051

2956-
public deleteKeysFromBackup(roomId: string, sessionId: string, version: string): Promise<void> {
3052+
public deleteKeysFromBackup(roomId: undefined, sessionId: undefined, version: string): Promise<void>;
3053+
public deleteKeysFromBackup(roomId: string, sessionId: undefined, version: string): Promise<void>;
3054+
public deleteKeysFromBackup(roomId: string, sessionId: string, version: string): Promise<void>;
3055+
public deleteKeysFromBackup(
3056+
roomId: string | undefined,
3057+
sessionId: string | undefined,
3058+
version: string,
3059+
): Promise<void> {
29573060
if (!this.crypto) {
29583061
throw new Error("End-to-end encryption disabled");
29593062
}

0 commit comments

Comments
 (0)