@@ -18,7 +18,7 @@ type FakeIndexedDbDatabaseConnection = {
1818} ;
1919
2020type FakeIndexedDbDatabasePrototype = FakeIndexedDbDatabaseConnection & {
21- transaction ?: ( ... args : unknown [ ] ) => unknown ;
21+ transaction ?: IDBDatabase [ "transaction" ] ;
2222 [ PRUNER_INSTALLED ] ?: true ;
2323} ;
2424
@@ -50,11 +50,12 @@ function isMatrixCryptoDatabase(rawDatabase: FakeIndexedDbRawDatabase | undefine
5050}
5151
5252export function pruneFinishedFakeIndexedDbTransactions ( rawDatabase : unknown ) : number {
53- if ( ! isMatrixCryptoDatabase ( rawDatabase as FakeIndexedDbRawDatabase | undefined ) ) {
53+ const matrixRawDatabase = rawDatabase as FakeIndexedDbRawDatabase | undefined ;
54+ if ( ! isMatrixCryptoDatabase ( matrixRawDatabase ) ) {
5455 return 0 ;
5556 }
5657
57- const transactions = rawDatabase . transactions ;
58+ const transactions = matrixRawDatabase . transactions ;
5859 const activeTransactions = transactions . filter ( ( transaction ) => transaction ?. _state !== "finished" ) ;
5960 const removed = transactions . length - activeTransactions . length ;
6061 if ( removed > 0 ) {
@@ -77,13 +78,13 @@ export function installFakeIndexedDbTransactionPruner(): void {
7778 value : true ,
7879 } ) ;
7980
80- databasePrototype . transaction = function patchedMatrixFakeIndexedDbTransaction (
81- this : FakeIndexedDbDatabaseConnection ,
82- ...args : unknown [ ]
83- ) : unknown {
81+ const patchedTransaction = function patchedMatrixFakeIndexedDbTransaction (
82+ this : IDBDatabase & FakeIndexedDbDatabaseConnection ,
83+ ...args : Parameters < IDBDatabase [ "transaction" ] >
84+ ) : ReturnType < IDBDatabase [ "transaction" ] > {
8485 pruneFinishedFakeIndexedDbTransactions ( getRawDatabase ( this ) ) ;
8586
86- const transaction = originalTransaction . apply ( this , args ) as FakeIndexedDbTransaction ;
87+ const transaction = originalTransaction . apply ( this , args ) as IDBTransaction & FakeIndexedDbTransaction ;
8788 const rawDatabase = getRawDatabase ( transaction ?. db ) ?? getRawDatabase ( this ) ;
8889 if ( isMatrixCryptoDatabase ( rawDatabase ) && typeof transaction ?. addEventListener === "function" ) {
8990 const prune = ( ) : void => {
@@ -94,5 +95,7 @@ export function installFakeIndexedDbTransactionPruner(): void {
9495 }
9596
9697 return transaction ;
97- } ;
98+ } as IDBDatabase [ "transaction" ] ;
99+
100+ databasePrototype . transaction = patchedTransaction ;
98101}
0 commit comments