15
15
* limitations under the License.
16
16
*/
17
17
18
- import { DBWrapper , openDB } from '@firebase/util ' ;
18
+ import { DBSchema , 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,10 +25,17 @@ 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 < DBWrapper > | null = null ;
29
- function getDbPromise ( ) : Promise < DBWrapper > {
28
+ interface InstallationsDB extends DBSchema {
29
+ 'firebase-installations-store' : {
30
+ key : string ,
31
+ value : InstallationEntry | undefined
32
+ }
33
+ }
34
+
35
+ let dbPromise : Promise < IDBPDatabase < InstallationsDB > > | null = null ;
36
+ function getDbPromise ( ) : Promise < IDBPDatabase < InstallationsDB > > {
30
37
if ( ! dbPromise ) {
31
- dbPromise = openDB ( DATABASE_NAME , DATABASE_VERSION , ( db , oldVersion ) => {
38
+ dbPromise = openDB ( DATABASE_NAME , DATABASE_VERSION , { upgrade : ( db , oldVersion ) => {
32
39
// We don't use 'break' in this switch statement, the fall-through
33
40
// behavior is what we want, because if there are multiple versions between
34
41
// the old version and the current version, we want ALL the migrations
@@ -38,7 +45,7 @@ function getDbPromise(): Promise<DBWrapper> {
38
45
case 0 :
39
46
db . createObjectStore ( OBJECT_STORE_NAME ) ;
40
47
}
41
- } ) ;
48
+ } } ) ;
42
49
}
43
50
return dbPromise ;
44
51
}
@@ -66,7 +73,7 @@ export async function set<ValueType extends InstallationEntry>(
66
73
const objectStore = tx . objectStore ( OBJECT_STORE_NAME ) ;
67
74
const oldValue = ( await objectStore . get ( key ) ) as InstallationEntry ;
68
75
await objectStore . put ( value , key ) ;
69
- await tx . complete ;
76
+ await tx . done ;
70
77
71
78
if ( ! oldValue || oldValue . fid !== value . fid ) {
72
79
fidChanged ( appConfig , value . fid ) ;
@@ -81,7 +88,7 @@ export async function remove(appConfig: AppConfig): Promise<void> {
81
88
const db = await getDbPromise ( ) ;
82
89
const tx = db . transaction ( OBJECT_STORE_NAME , 'readwrite' ) ;
83
90
await tx . objectStore ( OBJECT_STORE_NAME ) . delete ( key ) ;
84
- await tx . complete ;
91
+ await tx . done ;
85
92
}
86
93
87
94
/**
@@ -108,7 +115,7 @@ export async function update<ValueType extends InstallationEntry | undefined>(
108
115
} else {
109
116
await store . put ( newValue , key ) ;
110
117
}
111
- await tx . complete ;
118
+ await tx . done ;
112
119
113
120
if ( newValue && ( ! oldValue || oldValue . fid !== newValue . fid ) ) {
114
121
fidChanged ( appConfig , newValue . fid ) ;
@@ -121,5 +128,5 @@ export async function clear(): Promise<void> {
121
128
const db = await getDbPromise ( ) ;
122
129
const tx = db . transaction ( OBJECT_STORE_NAME , 'readwrite' ) ;
123
130
await tx . objectStore ( OBJECT_STORE_NAME ) . clear ( ) ;
124
- await tx . complete ;
131
+ await tx . done ;
125
132
}
0 commit comments