11import selfoss from './selfoss-base' ;
22import { OfflineStorageNotAvailableError } from './errors' ;
3- import Dexie from 'dexie' ;
3+ import Dexie , {
4+ PromiseExtended ,
5+ Table ,
6+ Transaction ,
7+ TransactionMode ,
8+ } from 'dexie' ;
49import { OfflineDb } from './model/OfflineDb' ;
510import { FilterType } from './Filter' ;
611
7- const ENTRY_STATUS_NAMES = [ 'unread' , 'starred' ] ;
12+ const ENTRY_STATUS_NAMES : Array < 'unread' | 'starred' > = [ 'unread' , 'starred' ] ;
813
914export default class DbOffline {
1015 /** @var Date the datetime of the newest garbage collected entry, i.e. deleted because not of interest. */
@@ -17,25 +22,31 @@ export default class DbOffline {
1722 public olderEntriesOnline : boolean = false ;
1823 public needsSync : boolean ;
1924
20- _tr ( ... args ) {
21- return selfoss . db . storage . transaction ( ... args ) . catch ( ( error ) => {
22- selfoss . app . showError (
23- selfoss . app . _ ( 'error_offline_storage' , {
24- '0' : error . message ,
25- } ) ,
26- ) ;
27- selfoss . db . broken = true ;
28- selfoss . db . enableOffline . update ( false ) ;
29- selfoss . entries ?. reload ( ) ;
30-
31- // If this is a QuotaExceededError, garbage collect more
32- // entries and hope it helps.
33- if ( error . name === Dexie . errnames . QuotaExceeded ) {
34- this . GCEntries ( true ) ;
35- }
25+ _tr < U > (
26+ mode : TransactionMode ,
27+ tables : Table [ ] ,
28+ scope : ( trans : Transaction ) => PromiseLike < U > | U ,
29+ ) : PromiseExtended < U > {
30+ return selfoss . db . storage
31+ . transaction ( mode , tables , scope )
32+ . catch ( ( error ) => {
33+ selfoss . app . showError (
34+ selfoss . app . _ ( 'error_offline_storage' , {
35+ '0' : error . message ,
36+ } ) ,
37+ ) ;
38+ selfoss . db . broken = true ;
39+ selfoss . db . enableOffline . update ( false ) ;
40+ selfoss . entries ?. reload ( ) ;
3641
37- return Promise . reject ( error ) ;
38- } ) ;
42+ // If this is a QuotaExceededError, garbage collect more
43+ // entries and hope it helps.
44+ if ( error . name === Dexie . errnames . QuotaExceeded ) {
45+ this . GCEntries ( true ) ;
46+ }
47+
48+ return Promise . reject ( error ) ;
49+ } ) ;
3950 }
4051
4152 init ( ) {
0 commit comments