15
15
* limitations under the License.
16
16
*/
17
17
18
- import { DB , openDb } from 'idb' ;
18
+ import { IDBPDatabase , openDB } from 'idb' ;
19
19
import { AppConfig } from '../interfaces/installation-impl' ;
20
20
import { InstallationEntry } from '../interfaces/installation-entry' ;
21
21
import { getKey } from '../util/get-key' ;
@@ -25,20 +25,20 @@ const DATABASE_NAME = 'firebase-installations-database';
25
25
const DATABASE_VERSION = 1 ;
26
26
const OBJECT_STORE_NAME = 'firebase-installations-store' ;
27
27
28
- let dbPromise : Promise < DB > | null = null ;
29
- function getDbPromise ( ) : Promise < DB > {
28
+ let dbPromise : Promise < IDBPDatabase > | null = null ;
29
+ function getDbPromise ( ) : Promise < IDBPDatabase > {
30
30
if ( ! dbPromise ) {
31
- dbPromise = openDb ( DATABASE_NAME , DATABASE_VERSION , upgradeDB => {
31
+ dbPromise = openDB ( DATABASE_NAME , DATABASE_VERSION , { upgrade : ( db , oldVersion ) => {
32
32
// We don't use 'break' in this switch statement, the fall-through
33
33
// behavior is what we want, because if there are multiple versions between
34
34
// the old version and the current version, we want ALL the migrations
35
35
// that correspond to those versions to run, not only the last one.
36
36
// eslint-disable-next-line default-case
37
- switch ( upgradeDB . oldVersion ) {
37
+ switch ( oldVersion ) {
38
38
case 0 :
39
- upgradeDB . createObjectStore ( OBJECT_STORE_NAME ) ;
39
+ db . createObjectStore ( OBJECT_STORE_NAME ) ;
40
40
}
41
- } ) ;
41
+ } } ) ;
42
42
}
43
43
return dbPromise ;
44
44
}
@@ -66,7 +66,7 @@ export async function set<ValueType extends InstallationEntry>(
66
66
const objectStore = tx . objectStore ( OBJECT_STORE_NAME ) ;
67
67
const oldValue = await objectStore . get ( key ) ;
68
68
await objectStore . put ( value , key ) ;
69
- await tx . complete ;
69
+ await tx . done ;
70
70
71
71
if ( ! oldValue || oldValue . fid !== value . fid ) {
72
72
fidChanged ( appConfig , value . fid ) ;
@@ -81,7 +81,7 @@ export async function remove(appConfig: AppConfig): Promise<void> {
81
81
const db = await getDbPromise ( ) ;
82
82
const tx = db . transaction ( OBJECT_STORE_NAME , 'readwrite' ) ;
83
83
await tx . objectStore ( OBJECT_STORE_NAME ) . delete ( key ) ;
84
- await tx . complete ;
84
+ await tx . done ;
85
85
}
86
86
87
87
/**
@@ -106,7 +106,7 @@ export async function update<ValueType extends InstallationEntry | undefined>(
106
106
} else {
107
107
await store . put ( newValue , key ) ;
108
108
}
109
- await tx . complete ;
109
+ await tx . done ;
110
110
111
111
if ( newValue && ( ! oldValue || oldValue . fid !== newValue . fid ) ) {
112
112
fidChanged ( appConfig , newValue . fid ) ;
@@ -119,5 +119,5 @@ export async function clear(): Promise<void> {
119
119
const db = await getDbPromise ( ) ;
120
120
const tx = db . transaction ( OBJECT_STORE_NAME , 'readwrite' ) ;
121
121
await tx . objectStore ( OBJECT_STORE_NAME ) . clear ( ) ;
122
- await tx . complete ;
122
+ await tx . done ;
123
123
}
0 commit comments