1515 * limitations under the License.
1616 */
1717
18- import { DBWrapper , openDB } from '@firebase/util ' ;
18+ import { DBSchema , IDBPDatabase , openDB } from 'idb ' ;
1919import { AppConfig } from '../interfaces/installation-impl' ;
2020import { InstallationEntry } from '../interfaces/installation-entry' ;
2121import { getKey } from '../util/get-key' ;
@@ -25,18 +25,27 @@ const DATABASE_NAME = 'firebase-installations-database';
2525const DATABASE_VERSION = 1 ;
2626const OBJECT_STORE_NAME = 'firebase-installations-store' ;
2727
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 > > {
3037 if ( ! dbPromise ) {
31- dbPromise = openDB ( DATABASE_NAME , DATABASE_VERSION , ( db , oldVersion ) => {
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 ( oldVersion ) {
38- case 0 :
39- db . createObjectStore ( OBJECT_STORE_NAME ) ;
38+ dbPromise = openDB ( DATABASE_NAME , DATABASE_VERSION , {
39+ upgrade : ( db , oldVersion ) => {
40+ // We don't use 'break' in this switch statement, the fall-through
41+ // behavior is what we want, because if there are multiple versions between
42+ // the old version and the current version, we want ALL the migrations
43+ // that correspond to those versions to run, not only the last one.
44+ // eslint-disable-next-line default-case
45+ switch ( oldVersion ) {
46+ case 0 :
47+ db . createObjectStore ( OBJECT_STORE_NAME ) ;
48+ }
4049 }
4150 } ) ;
4251 }
@@ -66,7 +75,7 @@ export async function set<ValueType extends InstallationEntry>(
6675 const objectStore = tx . objectStore ( OBJECT_STORE_NAME ) ;
6776 const oldValue = ( await objectStore . get ( key ) ) as InstallationEntry ;
6877 await objectStore . put ( value , key ) ;
69- await tx . complete ;
78+ await tx . done ;
7079
7180 if ( ! oldValue || oldValue . fid !== value . fid ) {
7281 fidChanged ( appConfig , value . fid ) ;
@@ -81,7 +90,7 @@ export async function remove(appConfig: AppConfig): Promise<void> {
8190 const db = await getDbPromise ( ) ;
8291 const tx = db . transaction ( OBJECT_STORE_NAME , 'readwrite' ) ;
8392 await tx . objectStore ( OBJECT_STORE_NAME ) . delete ( key ) ;
84- await tx . complete ;
93+ await tx . done ;
8594}
8695
8796/**
@@ -108,7 +117,7 @@ export async function update<ValueType extends InstallationEntry | undefined>(
108117 } else {
109118 await store . put ( newValue , key ) ;
110119 }
111- await tx . complete ;
120+ await tx . done ;
112121
113122 if ( newValue && ( ! oldValue || oldValue . fid !== newValue . fid ) ) {
114123 fidChanged ( appConfig , newValue . fid ) ;
@@ -121,5 +130,5 @@ export async function clear(): Promise<void> {
121130 const db = await getDbPromise ( ) ;
122131 const tx = db . transaction ( OBJECT_STORE_NAME , 'readwrite' ) ;
123132 await tx . objectStore ( OBJECT_STORE_NAME ) . clear ( ) ;
124- await tx . complete ;
133+ await tx . done ;
125134}
0 commit comments