-
Notifications
You must be signed in to change notification settings - Fork 928
add option to merge settings #3464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
6b80d73
d1815db
86b46e0
f2c0aa7
bbcdf2f
1922a36
920d050
1832824
727ec62
f97b6c2
1a7a1cd
a25cce6
e9f508b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'firebase': patch | ||
'@firebase/firestore': patch | ||
'@firebase/firestore-types': patch | ||
--- | ||
|
||
feat: Added `inherit` setting to merge existing settings with new settings when calling `firestore.settings()`. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7758,10 +7758,18 @@ declare namespace firebase.firestore { | |
/** | ||
* Whether to skip nested properties that are set to `undefined` during | ||
* object serialization. If set to `true`, these properties are skipped | ||
* and not written to Firestore. If set `false` or omitted, the SDK throws | ||
* an exception when it encounters properties of type `undefined`. | ||
* and not written to Firestore. If set to `false` or omitted, the SDK | ||
* throws an exception when it encounters properties of type `undefined`. | ||
*/ | ||
ignoreUndefinedProperties?: boolean; | ||
|
||
/** | ||
* Whether to merge the provided settings with the existing settings. If | ||
* set to `true`, the settings will be merged with existing settings. If | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We avoid "will" when possible. So this could be "are merged" and the line below just "settings replace..." |
||
* set to `false` or left unset, the settings will replace the existing | ||
* settings. | ||
*/ | ||
inherit?: boolean; | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -363,6 +363,12 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService { | |
validateExactNumberOfArgs('Firestore.settings', arguments, 1); | ||
validateArgType('Firestore.settings', 'object', 1, settingsLiteral); | ||
|
||
if (settingsLiteral.inherit) { | ||
settingsLiteral = this.mergeSettings(settingsLiteral); | ||
// Remove the property from the settings once the merge is completed. | ||
delete settingsLiteral.inherit; | ||
} | ||
|
||
const newSettings = new FirestoreSettings(settingsLiteral); | ||
if (this._firestoreClient && !this._settings.isEqual(newSettings)) { | ||
throw new FirestoreError( | ||
|
@@ -379,6 +385,33 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService { | |
} | ||
} | ||
|
||
private mergeSettings( | ||
settingsLiteral: firestore.Settings | ||
): firestore.Settings { | ||
settingsLiteral.host = | ||
settingsLiteral.host === undefined | ||
? this._settings.host | ||
: settingsLiteral.host; | ||
settingsLiteral.ssl = | ||
settingsLiteral.ssl === undefined | ||
? this._settings.ssl | ||
: settingsLiteral.ssl; | ||
settingsLiteral.timestampsInSnapshots = | ||
settingsLiteral.timestampsInSnapshots === undefined | ||
? this._settings.timestampsInSnapshots | ||
: settingsLiteral.timestampsInSnapshots; | ||
settingsLiteral.cacheSizeBytes = | ||
settingsLiteral.cacheSizeBytes === undefined | ||
? this._settings.cacheSizeBytes | ||
: settingsLiteral.cacheSizeBytes; | ||
settingsLiteral.ignoreUndefinedProperties = | ||
settingsLiteral.ignoreUndefinedProperties === undefined | ||
? this._settings.ignoreUndefinedProperties | ||
: settingsLiteral.ignoreUndefinedProperties; | ||
|
||
return settingsLiteral; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return {...this._settings, ...settingsLiteral } There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. Renamed |
||
} | ||
|
||
enableNetwork(): Promise<void> { | ||
this.ensureClientConfigured(); | ||
return this._firestoreClient!.enableNetwork(); | ||
|
@@ -674,6 +707,11 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService { | |
_areTimestampsInSnapshotsEnabled(): boolean { | ||
return this._settings.timestampsInSnapshots; | ||
} | ||
|
||
// Visible for testing. | ||
_getSettings(): firestore.Settings { | ||
return this._settings; | ||
} | ||
} | ||
|
||
/** Registers the listener for onSnapshotsInSync() */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,17 @@ export function firestore(): Firestore { | |
return FIRESTORE; | ||
} | ||
|
||
export function namedFirestore(projectId: string): Firestore { | ||
return new Firestore( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need the name, do you? I think you just need to return a new instance. This could just be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
{ | ||
projectId, | ||
database: '(default)' | ||
}, | ||
new Provider('auth-internal', new ComponentContainer('default')), | ||
new MultiTabIndexedDbComponentProvider() | ||
); | ||
} | ||
|
||
export function collectionReference(path: string): CollectionReference { | ||
const firestoreClient = firestore(); | ||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something with "the settings from a previous call. This allows customizing custom settings on top of the settings that were applied by
@firestore/testing
. Yadadada."There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated.