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