@@ -98,6 +98,7 @@ const DEFAULT_HOST = 'firestore.googleapis.com';
98
98
const DEFAULT_SSL = true ;
99
99
const DEFAULT_TIMESTAMPS_IN_SNAPSHOTS = true ;
100
100
const DEFAULT_FORCE_LONG_POLLING = false ;
101
+ const DEFAULT_IGNORE_UNDEFINED_PROPERTIES = false ;
101
102
102
103
/**
103
104
* Constant used to indicate the LRU garbage collection should be disabled.
@@ -142,6 +143,8 @@ class FirestoreSettings {
142
143
143
144
readonly forceLongPolling : boolean ;
144
145
146
+ readonly ignoreUndefinedProperties : boolean ;
147
+
145
148
// Can be a google-auth-library or gapi client.
146
149
// eslint-disable-next-line @typescript-eslint/no-explicit-any
147
150
credentials ?: any ;
@@ -169,7 +172,8 @@ class FirestoreSettings {
169
172
'credentials' ,
170
173
'timestampsInSnapshots' ,
171
174
'cacheSizeBytes' ,
172
- 'experimentalForceLongPolling'
175
+ 'experimentalForceLongPolling' ,
176
+ 'ignoreUndefinedProperties'
173
177
] ) ;
174
178
175
179
validateNamedOptionalType (
@@ -187,6 +191,13 @@ class FirestoreSettings {
187
191
settings . timestampsInSnapshots
188
192
) ;
189
193
194
+ validateNamedOptionalType (
195
+ 'settings' ,
196
+ 'boolean' ,
197
+ 'ignoreUndefinedProperties' ,
198
+ settings . ignoreUndefinedProperties
199
+ ) ;
200
+
190
201
// Nobody should set timestampsInSnapshots anymore, but the error depends on
191
202
// whether they set it to true or false...
192
203
if ( settings . timestampsInSnapshots === true ) {
@@ -202,6 +213,8 @@ class FirestoreSettings {
202
213
}
203
214
this . timestampsInSnapshots =
204
215
settings . timestampsInSnapshots ?? DEFAULT_TIMESTAMPS_IN_SNAPSHOTS ;
216
+ this . ignoreUndefinedProperties =
217
+ settings . ignoreUndefinedProperties ?? DEFAULT_IGNORE_UNDEFINED_PROPERTIES ;
205
218
206
219
validateNamedOptionalType (
207
220
'settings' ,
@@ -232,9 +245,7 @@ class FirestoreSettings {
232
245
settings . experimentalForceLongPolling
233
246
) ;
234
247
this . forceLongPolling =
235
- settings . experimentalForceLongPolling === undefined
236
- ? DEFAULT_FORCE_LONG_POLLING
237
- : settings . experimentalForceLongPolling ;
248
+ settings . experimentalForceLongPolling ?? DEFAULT_FORCE_LONG_POLLING ;
238
249
}
239
250
240
251
isEqual ( other : FirestoreSettings ) : boolean {
@@ -244,7 +255,8 @@ class FirestoreSettings {
244
255
this . timestampsInSnapshots === other . timestampsInSnapshots &&
245
256
this . credentials === other . credentials &&
246
257
this . cacheSizeBytes === other . cacheSizeBytes &&
247
- this . forceLongPolling === other . forceLongPolling
258
+ this . forceLongPolling === other . forceLongPolling &&
259
+ this . ignoreUndefinedProperties === other . ignoreUndefinedProperties
248
260
) ;
249
261
}
250
262
}
@@ -275,7 +287,7 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
275
287
// TODO(mikelehen): Use modularized initialization instead.
276
288
readonly _queue = new AsyncQueue ( ) ;
277
289
278
- readonly _dataReader : UserDataReader ;
290
+ _userDataReader : UserDataReader | undefined ;
279
291
280
292
// Note: We are using `MemoryComponentProvider` as a default
281
293
// ComponentProvider to ensure backwards compatibility with the format
@@ -310,7 +322,21 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
310
322
311
323
this . _componentProvider = componentProvider ;
312
324
this . _settings = new FirestoreSettings ( { } ) ;
313
- this . _dataReader = new UserDataReader ( this . _databaseId ) ;
325
+ }
326
+
327
+ get _dataReader ( ) : UserDataReader {
328
+ debugAssert (
329
+ ! ! this . _firestoreClient ,
330
+ 'Cannot obtain UserDataReader before instance is intitialized'
331
+ ) ;
332
+ if ( ! this . _userDataReader ) {
333
+ // Lazy initialize UserDataReader once the settings are frozen
334
+ this . _userDataReader = new UserDataReader (
335
+ this . _databaseId ,
336
+ this . _settings . ignoreUndefinedProperties
337
+ ) ;
338
+ }
339
+ return this . _userDataReader ;
314
340
}
315
341
316
342
settings ( settingsLiteral : firestore . Settings ) : void {
0 commit comments