Skip to content

Commit 7dce485

Browse files
committed
getPrivateSettings
1 parent 02ca42e commit 7dce485

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

common/api-review/firestore-lite.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,4 +494,5 @@ export class WriteBatch {
494494
// @public
495495
export function writeBatch(firestore: Firestore): WriteBatch;
496496

497+
497498
```

packages/firestore/src/lite-api/database.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export class Firestore implements FirestoreService {
7272

7373
private _settings = new FirestoreSettingsImpl({});
7474
private _settingsFrozen = false;
75+
private _emulatorOptions? : { mockUserToken?: EmulatorMockTokenOptions | string; };
7576

7677
// A task that is assigned when the terminate() is invoked and resolved when
7778
// all components have shut down. Otherwise, Firestore is not terminated,
@@ -120,6 +121,8 @@ export class Firestore implements FirestoreService {
120121
);
121122
}
122123
this._settings = new FirestoreSettingsImpl(settings);
124+
this._emulatorOptions = settings.emulatorOptions;
125+
123126
if (settings.credentials !== undefined) {
124127
this._authCredentials = makeAuthCredentialsProvider(settings.credentials);
125128
}
@@ -129,6 +132,17 @@ export class Firestore implements FirestoreService {
129132
return this._settings;
130133
}
131134

135+
_getPrivateSettings() : PrivateSettings {
136+
const privateSettings : PrivateSettings = {
137+
...this._settings,
138+
emulatorOptions: this._emulatorOptions
139+
};
140+
if(this._settings.localCache !== undefined) {
141+
privateSettings.localCache = this._settings.localCache;
142+
}
143+
return privateSettings;
144+
}
145+
132146
_freezeSettings(): FirestoreSettingsImpl {
133147
this._settingsFrozen = true;
134148
return this._settings;
@@ -316,7 +330,7 @@ export function connectFirestoreEmulator(
316330
} = {}
317331
): void {
318332
firestore = cast(firestore, Firestore);
319-
const settings = firestore._getSettings();
333+
const settings = firestore._getPrivateSettings();
320334
const newHostSetting = `${host}:${port}`;
321335

322336
if (settings.host !== DEFAULT_HOST && settings.host !== newHostSetting) {
@@ -325,20 +339,22 @@ export function connectFirestoreEmulator(
325339
'will be used.'
326340
);
327341
}
328-
const privateSettings = {
342+
const newSettings = {
329343
...settings,
330344
host: newHostSetting,
331-
ssl: false
345+
ssl: false,
346+
emulatorOptions: options
332347
};
333348

334-
// Turn this invocation into a no-op if the new configuration matches the current configuration.
335-
// This helps support SSR enviornments where `connectFirestoreEmulator` could be called multiple
336-
// times.
337-
if(deepEqual(privateSettings, settings)) {
349+
// No-op if the new configuration matches the current configuration. This supports SSR
350+
// enviornments which might call `connectFirestoreEmulator` multiple times as a standard practice.
351+
if(deepEqual(newSettings, settings)) {
352+
console.error("DEDB settings are the same!");
338353
return;
339354
}
355+
console.error("DEDB settings differ!")
340356

341-
firestore._setSettings(privateSettings);
357+
firestore._setSettings(newSettings);
342358

343359
if (options.mockUserToken) {
344360
let token: string;

packages/firestore/src/lite-api/settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
import { LRU_MINIMUM_CACHE_SIZE_BYTES } from '../local/lru_garbage_collector_impl';
3030
import { Code, FirestoreError } from '../util/error';
3131
import { validateIsNotUsedTogether } from '../util/input_validation';
32+
import { EmulatorMockTokenOptions } from '@firebase/util';
3233

3334
// settings() defaults:
3435
export const DEFAULT_HOST = 'firestore.googleapis.com';
@@ -80,6 +81,7 @@ export interface PrivateSettings extends FirestoreSettings {
8081
experimentalAutoDetectLongPolling?: boolean;
8182
experimentalLongPollingOptions?: ExperimentalLongPollingOptions;
8283
useFetchStreams?: boolean;
84+
emulatorOptions?: { mockUserToken?: EmulatorMockTokenOptions | string; };
8385

8486
localCache?: FirestoreLocalCache;
8587
}

0 commit comments

Comments
 (0)