Skip to content

Commit 3e7dd37

Browse files
Address feedback
1 parent dd98632 commit 3e7dd37

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

packages/firestore/src/local/indexeddb_mutation_queue.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import { LocalSerializer } from './local_serializer';
4747
import { MutationQueue } from './mutation_queue';
4848
import { PersistenceTransaction, ReferenceDelegate } from './persistence';
4949
import { PersistencePromise } from './persistence_promise';
50-
import { SimpleDbStore, SimpleDbTransaction } from './simple_db';
50+
import { SimpleDb, SimpleDbStore, SimpleDbTransaction } from './simple_db';
5151

5252
/** A mutation queue for a specific user, backed by IndexedDB. */
5353
export class IndexedDbMutationQueue implements MutationQueue {
@@ -675,8 +675,7 @@ function convertStreamToken(token: ProtoByteString): string {
675675
if (token instanceof Uint8Array) {
676676
// TODO(b/78771403): Convert tokens to strings during deserialization
677677
assert(
678-
typeof process !== 'undefined' &&
679-
process.env.USE_MOCK_PERSISTENCE === 'YES',
678+
SimpleDb.isMockPersistence(),
680679
'Persisting non-string stream tokens is only supported with mock persistence.'
681680
);
682681
return token.toString();

packages/firestore/src/local/local_serializer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
DbUnknownDocument
4444
} from './indexeddb_schema';
4545
import { QueryData, QueryPurpose } from './query_data';
46+
import { SimpleDb } from './simple_db';
4647

4748
/** Serializer for values stored in the LocalStore. */
4849
export class LocalSerializer {
@@ -251,8 +252,7 @@ export class LocalSerializer {
251252
if (queryData.resumeToken instanceof Uint8Array) {
252253
// TODO(b/78771403): Convert tokens to strings during deserialization
253254
assert(
254-
typeof process !== 'undefined' &&
255-
process.env.USE_MOCK_PERSISTENCE === 'YES',
255+
SimpleDb.isMockPersistence(),
256256
'Persisting non-string stream tokens is only supported with mock persistence .'
257257
);
258258
resumeToken = queryData.resumeToken.toString();

packages/firestore/src/local/simple_db.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,18 @@ export class SimpleDb {
149149
if (typeof window === 'undefined' || window.indexedDB == null) {
150150
return false;
151151
}
152+
153+
if (SimpleDb.isMockPersistence()) {
154+
return true;
155+
}
156+
152157
// We extensively use indexed array values and compound keys,
153158
// which IE and Edge do not support. However, they still have indexedDB
154159
// defined on the window, so we need to check for them here and make sure
155160
// to return that persistence is not enabled for those browsers.
156161
// For tracking support of this feature, see here:
157162
// https://developer.microsoft.com/en-us/microsoft-edge/platform/status/indexeddbarraysandmultientrysupport/
158163

159-
// If we are running in Node using the IndexedDBShim, `window` is defined,
160-
// but `window.navigator` is not. In this case, we support IndexedDB and
161-
// return `true`.
162-
if (window.navigator === undefined && typeof process !== undefined) {
163-
return process.env.USE_MOCK_PERSISTENCE === 'YES';
164-
}
165-
166164
// Check the UA string to find out the browser.
167165
const ua = getUA();
168166

@@ -197,6 +195,17 @@ export class SimpleDb {
197195
}
198196
}
199197

198+
/**
199+
* Returns true if the backing IndexedDB store is the Node IndexedDBShim
200+
* (see https://github.com/axemclion/IndexedDBShim).
201+
*/
202+
static isMockPersistence(): boolean {
203+
return (
204+
typeof process !== 'undefined' &&
205+
process.env.USE_MOCK_PERSISTENCE === 'YES'
206+
);
207+
}
208+
200209
/** Helper to get a typed SimpleDbStore from a transaction. */
201210
static getStore<KeyType extends IDBValidKey, ValueType extends unknown>(
202211
txn: SimpleDbTransaction,

0 commit comments

Comments
 (0)