Skip to content

Commit 24646ac

Browse files
committed
format
1 parent 54476b3 commit 24646ac

File tree

5 files changed

+107
-140
lines changed

5 files changed

+107
-140
lines changed

common/api-review/util.api.md

-29
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,6 @@ export function createMockUserToken(token: EmulatorMockTokenOptions, projectId?:
8787
// @public
8888
export function createSubscribe<T>(executor: Executor<T>, onNoObservers?: Executor<T>): Subscribe<T>;
8989

90-
// Warning: (ae-internal-missing-underscore) The name "DBWrapper" should be prefixed with an underscore because the declaration is marked as @internal
91-
//
92-
// @internal (undocumented)
93-
export class DBWrapper {
94-
constructor(_db: IDBDatabase);
95-
// (undocumented)
96-
close(): void;
97-
// Warning: (ae-forgotten-export) The symbol "ObjectStoreWrapper" needs to be exported by the entry point index.d.ts
98-
//
99-
// (undocumented)
100-
createObjectStore(storeName: string, options?: IDBObjectStoreParameters): ObjectStoreWrapper;
101-
// (undocumented)
102-
objectStoreNames: DOMStringList;
103-
// Warning: (ae-forgotten-export) The symbol "TransactionWrapper" needs to be exported by the entry point index.d.ts
104-
//
105-
// (undocumented)
106-
transaction(storeNames: string[] | string, mode?: IDBTransactionMode): TransactionWrapper;
107-
}
108-
10990
// Warning: (ae-forgotten-export) The symbol "DecodedToken" needs to be exported by the entry point index.d.ts
11091
// Warning: (ae-missing-release-tag) "decode" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
11192
//
@@ -141,11 +122,6 @@ export class Deferred<R> {
141122
wrapCallback(callback?: (error?: unknown, value?: unknown) => void): (error: unknown, value?: unknown) => void;
142123
}
143124

144-
// Warning: (ae-internal-missing-underscore) The name "deleteDB" should be prefixed with an underscore because the declaration is marked as @internal
145-
//
146-
// @internal (undocumented)
147-
export function deleteDB(dbName: string): Promise<void>;
148-
149125
// Warning: (ae-forgotten-export) The symbol "FirebaseIdToken" needs to be exported by the entry point index.d.ts
150126
// Warning: (ae-missing-release-tag) "EmulatorMockTokenOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
151127
//
@@ -360,11 +336,6 @@ export interface Observer<T> {
360336
next: NextFn<T>;
361337
}
362338

363-
// Warning: (ae-internal-missing-underscore) The name "openDB" should be prefixed with an underscore because the declaration is marked as @internal
364-
//
365-
// @internal (undocumented)
366-
export function openDB(dbName: string, dbVersion: number, upgradeCallback: (db: DBWrapper, oldVersion: number, newVersion: number | null, transaction: TransactionWrapper) => void): Promise<DBWrapper>;
367-
368339
// Warning: (ae-missing-release-tag) "ordinal" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
369340
//
370341
// @public

packages/app/src/indexeddb.ts

+15-13
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,27 @@ const STORE_NAME = 'firebase-heartbeat-store';
2626

2727
interface AppDB extends DBSchema {
2828
'firebase-heartbeat-store': {
29-
key: string,
30-
value: HeartbeatsInIndexedDB
31-
}
29+
key: string;
30+
value: HeartbeatsInIndexedDB;
31+
};
3232
}
3333

3434
let dbPromise: Promise<IDBPDatabase<AppDB>> | null = null;
3535
function getDbPromise(): Promise<IDBPDatabase<AppDB>> {
3636
if (!dbPromise) {
37-
dbPromise = openDB<AppDB>(DB_NAME, DB_VERSION, {upgrade: (db, oldVersion) => {
38-
// We don't use 'break' in this switch statement, the fall-through
39-
// behavior is what we want, because if there are multiple versions between
40-
// the old version and the current version, we want ALL the migrations
41-
// that correspond to those versions to run, not only the last one.
42-
// eslint-disable-next-line default-case
43-
switch (oldVersion) {
44-
case 0:
45-
db.createObjectStore(STORE_NAME);
37+
dbPromise = openDB<AppDB>(DB_NAME, DB_VERSION, {
38+
upgrade: (db, oldVersion) => {
39+
// We don't use 'break' in this switch statement, the fall-through
40+
// behavior is what we want, because if there are multiple versions between
41+
// the old version and the current version, we want ALL the migrations
42+
// that correspond to those versions to run, not only the last one.
43+
// eslint-disable-next-line default-case
44+
switch (oldVersion) {
45+
case 0:
46+
db.createObjectStore(STORE_NAME);
47+
}
4648
}
47-
}}).catch(e => {
49+
}).catch(e => {
4850
throw ERROR_FACTORY.create(AppError.STORAGE_OPEN, {
4951
originalErrorMessage: e.message
5052
});

packages/installations/src/helpers/idb-manager.ts

+15-13
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,27 @@ const OBJECT_STORE_NAME = 'firebase-installations-store';
2727

2828
interface InstallationsDB extends DBSchema {
2929
'firebase-installations-store': {
30-
key: string,
31-
value: InstallationEntry | undefined
32-
}
30+
key: string;
31+
value: InstallationEntry | undefined;
32+
};
3333
}
3434

3535
let dbPromise: Promise<IDBPDatabase<InstallationsDB>> | null = null;
3636
function getDbPromise(): Promise<IDBPDatabase<InstallationsDB>> {
3737
if (!dbPromise) {
38-
dbPromise = openDB(DATABASE_NAME, DATABASE_VERSION, {upgrade: (db, oldVersion) => {
39-
// We don't use 'break' in this switch statement, the fall-through
40-
// behavior is what we want, because if there are multiple versions between
41-
// the old version and the current version, we want ALL the migrations
42-
// that correspond to those versions to run, not only the last one.
43-
// eslint-disable-next-line default-case
44-
switch (oldVersion) {
45-
case 0:
46-
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+
}
4749
}
48-
}});
50+
});
4951
}
5052
return dbPromise;
5153
}

packages/messaging/src/helpers/migrate-old-database.ts

+64-68
Original file line numberDiff line numberDiff line change
@@ -88,83 +88,79 @@ export async function migrateOldDatabase(
8888

8989
let tokenDetails: TokenDetails | null = null;
9090

91-
const db = await openDB(
92-
OLD_DB_NAME,
93-
OLD_DB_VERSION,
94-
{
95-
upgrade: async (db, oldVersion, newVersion, upgradeTransaction) => {
96-
if (oldVersion < 2) {
97-
// Database too old, skip migration.
98-
return;
99-
}
91+
const db = await openDB(OLD_DB_NAME, OLD_DB_VERSION, {
92+
upgrade: async (db, oldVersion, newVersion, upgradeTransaction) => {
93+
if (oldVersion < 2) {
94+
// Database too old, skip migration.
95+
return;
96+
}
10097

101-
if (!db.objectStoreNames.contains(OLD_OBJECT_STORE_NAME)) {
102-
// Database did not exist. Nothing to do.
103-
return;
104-
}
98+
if (!db.objectStoreNames.contains(OLD_OBJECT_STORE_NAME)) {
99+
// Database did not exist. Nothing to do.
100+
return;
101+
}
105102

106-
const objectStore = upgradeTransaction.objectStore(OLD_OBJECT_STORE_NAME);
107-
const value = await objectStore.index('fcmSenderId').get(senderId);
108-
await objectStore.clear();
103+
const objectStore = upgradeTransaction.objectStore(OLD_OBJECT_STORE_NAME);
104+
const value = await objectStore.index('fcmSenderId').get(senderId);
105+
await objectStore.clear();
106+
107+
if (!value) {
108+
// No entry in the database, nothing to migrate.
109+
return;
110+
}
109111

110-
if (!value) {
111-
// No entry in the database, nothing to migrate.
112+
if (oldVersion === 2) {
113+
const oldDetails = value as V2TokenDetails;
114+
115+
if (!oldDetails.auth || !oldDetails.p256dh || !oldDetails.endpoint) {
112116
return;
113117
}
114118

115-
if (oldVersion === 2) {
116-
const oldDetails = value as V2TokenDetails;
117-
118-
if (!oldDetails.auth || !oldDetails.p256dh || !oldDetails.endpoint) {
119-
return;
119+
tokenDetails = {
120+
token: oldDetails.fcmToken,
121+
createTime: oldDetails.createTime ?? Date.now(),
122+
subscriptionOptions: {
123+
auth: oldDetails.auth,
124+
p256dh: oldDetails.p256dh,
125+
endpoint: oldDetails.endpoint,
126+
swScope: oldDetails.swScope,
127+
vapidKey:
128+
typeof oldDetails.vapidKey === 'string'
129+
? oldDetails.vapidKey
130+
: arrayToBase64(oldDetails.vapidKey)
120131
}
121-
122-
tokenDetails = {
123-
token: oldDetails.fcmToken,
124-
createTime: oldDetails.createTime ?? Date.now(),
125-
subscriptionOptions: {
126-
auth: oldDetails.auth,
127-
p256dh: oldDetails.p256dh,
128-
endpoint: oldDetails.endpoint,
129-
swScope: oldDetails.swScope,
130-
vapidKey:
131-
typeof oldDetails.vapidKey === 'string'
132-
? oldDetails.vapidKey
133-
: arrayToBase64(oldDetails.vapidKey)
134-
}
135-
};
136-
} else if (oldVersion === 3) {
137-
const oldDetails = value as V3TokenDetails;
138-
139-
tokenDetails = {
140-
token: oldDetails.fcmToken,
141-
createTime: oldDetails.createTime,
142-
subscriptionOptions: {
143-
auth: arrayToBase64(oldDetails.auth),
144-
p256dh: arrayToBase64(oldDetails.p256dh),
145-
endpoint: oldDetails.endpoint,
146-
swScope: oldDetails.swScope,
147-
vapidKey: arrayToBase64(oldDetails.vapidKey)
148-
}
149-
};
150-
} else if (oldVersion === 4) {
151-
const oldDetails = value as V4TokenDetails;
152-
153-
tokenDetails = {
154-
token: oldDetails.fcmToken,
155-
createTime: oldDetails.createTime,
156-
subscriptionOptions: {
157-
auth: arrayToBase64(oldDetails.auth),
158-
p256dh: arrayToBase64(oldDetails.p256dh),
159-
endpoint: oldDetails.endpoint,
160-
swScope: oldDetails.swScope,
161-
vapidKey: arrayToBase64(oldDetails.vapidKey)
162-
}
163-
};
164-
}
132+
};
133+
} else if (oldVersion === 3) {
134+
const oldDetails = value as V3TokenDetails;
135+
136+
tokenDetails = {
137+
token: oldDetails.fcmToken,
138+
createTime: oldDetails.createTime,
139+
subscriptionOptions: {
140+
auth: arrayToBase64(oldDetails.auth),
141+
p256dh: arrayToBase64(oldDetails.p256dh),
142+
endpoint: oldDetails.endpoint,
143+
swScope: oldDetails.swScope,
144+
vapidKey: arrayToBase64(oldDetails.vapidKey)
145+
}
146+
};
147+
} else if (oldVersion === 4) {
148+
const oldDetails = value as V4TokenDetails;
149+
150+
tokenDetails = {
151+
token: oldDetails.fcmToken,
152+
createTime: oldDetails.createTime,
153+
subscriptionOptions: {
154+
auth: arrayToBase64(oldDetails.auth),
155+
p256dh: arrayToBase64(oldDetails.p256dh),
156+
endpoint: oldDetails.endpoint,
157+
swScope: oldDetails.swScope,
158+
vapidKey: arrayToBase64(oldDetails.vapidKey)
159+
}
160+
};
165161
}
166162
}
167-
);
163+
});
168164
db.close();
169165

170166
// Delete all old databases.

packages/messaging/src/internals/idb-manager.ts

+13-17
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,26 @@ const OBJECT_STORE_NAME = 'firebase-messaging-store';
2828

2929
interface MessagingDB extends DBSchema {
3030
'firebase-messaging-store': {
31-
key: string,
32-
value: TokenDetails
33-
}
31+
key: string;
32+
value: TokenDetails;
33+
};
3434
}
3535

3636
let dbPromise: Promise<IDBPDatabase<MessagingDB>> | null = null;
3737
function getDbPromise(): Promise<IDBPDatabase<MessagingDB>> {
3838
if (!dbPromise) {
39-
dbPromise = openDB(
40-
DATABASE_NAME,
41-
DATABASE_VERSION,
42-
{
43-
upgrade: (upgradeDb, oldVersion) => {
44-
// We don't use 'break' in this switch statement, the fall-through behavior is what we want,
45-
// because if there are multiple versions between the old version and the current version, we
46-
// want ALL the migrations that correspond to those versions to run, not only the last one.
47-
// eslint-disable-next-line default-case
48-
switch (oldVersion) {
49-
case 0:
50-
upgradeDb.createObjectStore(OBJECT_STORE_NAME);
51-
}
39+
dbPromise = openDB(DATABASE_NAME, DATABASE_VERSION, {
40+
upgrade: (upgradeDb, oldVersion) => {
41+
// We don't use 'break' in this switch statement, the fall-through behavior is what we want,
42+
// because if there are multiple versions between the old version and the current version, we
43+
// want ALL the migrations 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+
upgradeDb.createObjectStore(OBJECT_STORE_NAME);
5248
}
5349
}
54-
);
50+
});
5551
}
5652
return dbPromise;
5753
}

0 commit comments

Comments
 (0)