Skip to content

Commit f5e2cef

Browse files
Review
1 parent 2ca465c commit f5e2cef

File tree

3 files changed

+33
-42
lines changed

3 files changed

+33
-42
lines changed

packages/firestore/exp/test/shim.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ import {
6565
} from '../../exp/index';
6666
import { UntypedFirestoreDataConverter } from '../../src/api/user_data_reader';
6767
import { isPartialObserver, PartialObserver } from '../../src/api/observer';
68-
import { isPlainObject } from '../../src/util/input_validation';
68+
import {
69+
isPlainObject,
70+
validateSetOptions
71+
} from '../../src/util/input_validation';
6972
import { Compat } from '../../src/compat/compat';
70-
import { validateSetOptions } from '../../src/api/database';
7173

7274
export { GeoPoint, Timestamp } from '../index';
7375
export { FieldValue } from '../../src/compat/field_value';

packages/firestore/src/api/database.ts

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ import {
9898
validateIsNotUsedTogether,
9999
validateNonEmptyArgument,
100100
validatePositiveNumber,
101+
validateSetOptions,
101102
valueDescription
102103
} from '../util/input_validation';
103104
import { setLogLevel as setClientLogLevel, logWarn } from '../util/log';
@@ -140,9 +141,6 @@ import {
140141
// settings() defaults:
141142
const DEFAULT_HOST = 'firestore.googleapis.com';
142143
const DEFAULT_SSL = true;
143-
const DEFAULT_FORCE_LONG_POLLING = false;
144-
const DEFAULT_FORCE_AUTO_DETECT_LONG_POLLING = false;
145-
const DEFAULT_IGNORE_UNDEFINED_PROPERTIES = false;
146144

147145
/**
148146
* Constant used to indicate the LRU garbage collection should be disabled.
@@ -151,10 +149,6 @@ const DEFAULT_IGNORE_UNDEFINED_PROPERTIES = false;
151149
*/
152150
export const CACHE_SIZE_UNLIMITED = LruParams.COLLECTION_DISABLED;
153151

154-
// enablePersistence() defaults:
155-
const DEFAULT_SYNCHRONIZE_TABS = false;
156-
const DEFAULT_FORCE_OWNING_TAB = false;
157-
158152
/** Undocumented, private additional settings not exposed in our public API. */
159153
interface PrivateSettings extends PublicSettings {
160154
// Can be a google-auth-library or gapi client.
@@ -206,13 +200,11 @@ class FirestoreSettings {
206200
this.ssl = DEFAULT_SSL;
207201
} else {
208202
this.host = settings.host;
209-
210203
this.ssl = settings.ssl ?? DEFAULT_SSL;
211204
}
212205

213206
this.credentials = settings.credentials;
214-
this.ignoreUndefinedProperties =
215-
settings.ignoreUndefinedProperties ?? DEFAULT_IGNORE_UNDEFINED_PROPERTIES;
207+
this.ignoreUndefinedProperties = !!settings.ignoreUndefinedProperties;
216208

217209
if (settings.cacheSizeBytes === undefined) {
218210
this.cacheSizeBytes = LruParams.DEFAULT_CACHE_SIZE_BYTES;
@@ -230,12 +222,8 @@ class FirestoreSettings {
230222
}
231223
}
232224

233-
this.experimentalForceLongPolling =
234-
settings.experimentalForceLongPolling ?? DEFAULT_FORCE_LONG_POLLING;
235-
236-
this.experimentalAutoDetectLongPolling =
237-
settings.experimentalAutoDetectLongPolling ??
238-
DEFAULT_FORCE_AUTO_DETECT_LONG_POLLING;
225+
this.experimentalForceLongPolling = !!settings.experimentalForceLongPolling;
226+
this.experimentalAutoDetectLongPolling = !!settings.experimentalAutoDetectLongPolling;
239227

240228
validateIsNotUsedTogether(
241229
'experimentalForceLongPolling',
@@ -495,9 +483,8 @@ export class Firestore implements PublicFirestore, FirebaseService {
495483
let experimentalForceOwningTab = false;
496484

497485
if (settings) {
498-
synchronizeTabs = settings.synchronizeTabs ?? DEFAULT_SYNCHRONIZE_TABS;
499-
experimentalForceOwningTab =
500-
settings.experimentalForceOwningTab ?? DEFAULT_FORCE_OWNING_TAB;
486+
synchronizeTabs = !!settings.synchronizeTabs;
487+
experimentalForceOwningTab = !!settings.experimentalForceOwningTab;
501488

502489
validateIsNotUsedTogether(
503490
'synchronizeTabs',
@@ -2274,27 +2261,6 @@ export class CollectionReference<T = DocumentData>
22742261
}
22752262
}
22762263

2277-
export function validateSetOptions(
2278-
methodName: string,
2279-
options: SetOptions | undefined
2280-
): SetOptions {
2281-
if (options === undefined) {
2282-
return {
2283-
merge: false
2284-
};
2285-
}
2286-
2287-
if (options.mergeFields !== undefined && options.merge !== undefined) {
2288-
throw new FirestoreError(
2289-
Code.INVALID_ARGUMENT,
2290-
`Invalid options passed to function ${methodName}(): You cannot specify both "merge" ` +
2291-
`and "mergeFields".`
2292-
);
2293-
}
2294-
2295-
return options;
2296-
}
2297-
22982264
function validateGetOptions(
22992265
methodName: string,
23002266
options: GetOptions | undefined

packages/firestore/src/util/input_validation.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
18+
import { SetOptions } from '@firebase/firestore-types';
1719
import { fail } from './assert';
1820
import { Code, FirestoreError } from './error';
1921
import { DocumentKey } from '../model/document_key';
@@ -42,6 +44,27 @@ export function validateNonEmptyArgument(
4244
}
4345
}
4446

47+
export function validateSetOptions(
48+
methodName: string,
49+
options: SetOptions | undefined
50+
): SetOptions {
51+
if (options === undefined) {
52+
return {
53+
merge: false
54+
};
55+
}
56+
57+
if (options.mergeFields !== undefined && options.merge !== undefined) {
58+
throw new FirestoreError(
59+
Code.INVALID_ARGUMENT,
60+
`Invalid options passed to function ${methodName}(): You cannot ` +
61+
'specify both "merge" and "mergeFields".'
62+
);
63+
}
64+
65+
return options;
66+
}
67+
4568
/**
4669
* Validates that two boolean options are not set at the same time.
4770
*/

0 commit comments

Comments
 (0)