Skip to content

Commit 2433390

Browse files
committed
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk into ida-size-analysis-phase-2
2 parents 0ae6ab4 + 61b4cd3 commit 2433390

File tree

27 files changed

+227
-397
lines changed

27 files changed

+227
-397
lines changed

.changeset/little-cycles-fold.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"firebase": minor
3+
"@firebase/performance": minor
4+
---
5+
6+
Issue 2393 - Add environment check to Performance Module

.changeset/mean-jokes-tan.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'firebase': patch
3+
'@firebase/firestore': patch
4+
'@firebase/firestore-types': patch
5+
---
6+
feat: Added `merge` option to `firestore.settings()`, which merges the provided settings with
7+
settings from a previous call. This allows adding settings on top of the settings that were applied
8+
by `@firebase/testing`.

.changeset/silver-trainers-rhyme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/firestore": patch
3+
---
4+
5+
Enable fallback for auto-generated identifiers in environments that support `crypto` but not `crypto.getRandomValues`.

packages/firebase/index.d.ts

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6952,9 +6952,9 @@ declare namespace firebase.messaging {
69526952
* Do not call this constructor directly. Instead, use
69536953
* {@link firebase.messaging `firebase.messaging()`}.
69546954
*
6955-
* See {@link https://firebase.google.com/docs/cloud-messaging/js/client Set Up a JavaScript
6956-
* Firebase Cloud Messaging Client App} for a full guide on how to use the Firebase Messaging
6957-
* service.
6955+
* See {@link https://firebase.google.com/docs/cloud-messaging/js/client
6956+
* Set Up a JavaScript Firebase Cloud Messaging Client App} for a full guide on how to use the
6957+
* Firebase Messaging service.
69586958
*
69596959
*/
69606960
interface Messaging {
@@ -7109,13 +7109,13 @@ declare namespace firebase.messaging {
71097109

71107110
/**
71117111
* Message payload that contains the notification payload that is represented with
7112-
* {@link firebase.Messaging.NotificationPayload} and the data payload that contains an arbitrary
7112+
* {@link firebase.messaging.NotificationPayload} and the data payload that contains an arbitrary
71137113
* number of key-value pairs sent by developers through the
71147114
* {@link https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#notification Send API}
71157115
*/
71167116
export interface MessagePayload {
71177117
/**
7118-
* See {@link firebase.Messaging.NotificationPayload}.
7118+
* See {@link firebase.messaging.NotificationPayload}.
71197119
*/
71207120
notification?: NotificationPayload;
71217121

@@ -7125,7 +7125,7 @@ declare namespace firebase.messaging {
71257125
data?: { [key: string]: string };
71267126

71277127
/**
7128-
* See {@link firebase.Messaging.FcmOptions}.
7128+
* See {@link firebase.messaging.FcmOptions}.
71297129
*/
71307130
fcmOptions?: FcmOptions;
71317131

@@ -7135,15 +7135,17 @@ declare namespace firebase.messaging {
71357135
from: string;
71367136

71377137
/**
7138-
* The collapse key of this message. See more
7139-
* {@link https://firebase.google.com/docs/cloud-messaging/concept-options#collapsible_and_non-collapsible_messages}.
7138+
* The collapse key of this message. See
7139+
* {@link https://firebase.google.com/docs/cloud-messaging/concept-options#collapsible_and_non-collapsible_messages
7140+
* Collapsible and non-collapsible messages}.
71407141
*/
71417142
collapseKey: string;
71427143
}
71437144

71447145
/**
7145-
* Options for features provided by the FCM SDK for Web. See more
7146-
* {@link https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#webpushfcmoptions}.
7146+
* Options for features provided by the FCM SDK for Web. See
7147+
* {@link https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#webpushfcmoptions
7148+
* WebpushFcmOptions}.
71477149
*/
71487150
export interface FcmOptions {
71497151
/**
@@ -7154,8 +7156,9 @@ declare namespace firebase.messaging {
71547156
link?: string;
71557157

71567158
/**
7157-
* Label associated with the message's analytics data. See more
7158-
* {@link https://firebase.google.com/docs/cloud-messaging/understand-delivery#adding-analytics-labels-to-messages}.
7159+
* Label associated with the message's analytics data. See
7160+
* {@link https://firebase.google.com/docs/cloud-messaging/understand-delivery#adding-analytics-labels-to-messages
7161+
* Adding analytics labels}.
71597162
*/
71607163
analyticsLabel?: string;
71617164
}
@@ -7176,8 +7179,8 @@ declare namespace firebase.messaging {
71767179

71777180
/**
71787181
* The URL of the image that is shown with the notification. See
7179-
* {@link https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#notification}
7180-
* for supported image format.
7182+
* {@link https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#notification
7183+
* `notification.image`} for supported image format.
71817184
*/
71827185
image?: string;
71837186
}
@@ -7888,10 +7891,18 @@ declare namespace firebase.firestore {
78887891
/**
78897892
* Whether to skip nested properties that are set to `undefined` during
78907893
* object serialization. If set to `true`, these properties are skipped
7891-
* and not written to Firestore. If set `false` or omitted, the SDK throws
7892-
* an exception when it encounters properties of type `undefined`.
7894+
* and not written to Firestore. If set to `false` or omitted, the SDK
7895+
* throws an exception when it encounters properties of type `undefined`.
78937896
*/
78947897
ignoreUndefinedProperties?: boolean;
7898+
7899+
/**
7900+
* Whether to merge the provided settings with the existing settings. If
7901+
* set to `true`, the settings are merged with existing settings. If
7902+
* set to `false` or left unset, the settings replace the existing
7903+
* settings.
7904+
*/
7905+
merge?: boolean;
78957906
}
78967907

78977908
/**

packages/firestore-types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface Settings {
3030
cacheSizeBytes?: number;
3131
experimentalForceLongPolling?: boolean;
3232
ignoreUndefinedProperties?: boolean;
33+
merge?: boolean;
3334
}
3435

3536
export interface PersistenceSettings {

packages/firestore/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"bundle": "rollup -c",
1111
"build": "run-p 'bundle rollup.config.browser.js' 'bundle rollup.config.browser.memory.js' 'bundle rollup.config.node.js' 'bundle rollup.config.node.memory.js' 'bundle rollup.config.rn.js' 'bundle rollup.config.rn.memory.js' build:lite build:exp",
1212
"build:scripts": "tsc -moduleResolution node --module commonjs scripts/*.ts && ls scripts/*.js | xargs -I % sh -c 'terser % -o %'",
13-
"build:release": "rollup -c rollup.config.es2017.js && rollup -c rollup.config.es5.js",
13+
"build:release": "run-p 'bundle rollup.config.browser.js' 'bundle rollup.config.browser.memory.js' 'bundle rollup.config.node.js' 'bundle rollup.config.node.memory.js' 'bundle rollup.config.rn.js' 'bundle rollup.config.rn.memory.js'",
1414
"build:deps": "lerna run --scope @firebase/'{app,firestore}' --include-dependencies build",
1515
"build:console": "node tools/console.build.js",
1616
"build:exp": "rollup -c rollup.config.exp.js",
@@ -57,7 +57,6 @@
5757
"license": "Apache-2.0",
5858
"files": [
5959
"dist",
60-
"lite/package.json",
6160
"memory/package.json"
6261
],
6362
"dependencies": {

packages/firestore/rollup.config.exp.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import alias from '@rollup/plugin-alias';
2121
import typescriptPlugin from 'rollup-plugin-typescript2';
2222
import typescript from 'typescript';
2323
import path from 'path';
24-
import sourcemaps from 'rollup-plugin-sourcemaps';
24+
import replace from 'rollup-plugin-replace';
25+
import copy from 'rollup-plugin-copy-assets';
2526
import { terser } from 'rollup-plugin-terser';
2627
import { importPathTransformer } from '../../scripts/exp/ts-transform-import-path';
2728

@@ -41,7 +42,14 @@ const nodePlugins = [
4142
abortOnError: false,
4243
transformers: [util.removeAssertTransformer, importPathTransformer]
4344
}),
44-
json({ preferConst: true })
45+
json({ preferConst: true }),
46+
// Needed as we also use the *.proto files
47+
copy({
48+
assets: ['./src/protos']
49+
}),
50+
replace({
51+
'process.env.FIRESTORE_PROTO_ROOT': JSON.stringify('../src/protos')
52+
})
4553
];
4654

4755
const browserPlugins = [
@@ -87,18 +95,7 @@ const allBuilds = [
8795
name: 'firebase.firestore',
8896
sourcemap: true
8997
},
90-
plugins: [
91-
typescriptPlugin({
92-
typescript,
93-
compilerOptions: {
94-
allowJs: true,
95-
target: 'es5'
96-
},
97-
include: ['dist/exp/*.js']
98-
}),
99-
json(),
100-
sourcemaps()
101-
],
98+
plugins: util.es2017ToEs5Plugins(/* mangled= */ false),
10299
external: util.resolveNodeExterns,
103100
treeshake: {
104101
moduleSideEffects: false

packages/firestore/rollup.shared.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ exports.es2017ToEs5Plugins = function (mangled = false) {
178178
compilerOptions: {
179179
allowJs: true
180180
},
181-
include: ['dist/*.js']
181+
include: ['dist/*.js', 'dist/exp/*.js']
182182
}),
183183
terser({
184184
output: {
@@ -196,7 +196,7 @@ exports.es2017ToEs5Plugins = function (mangled = false) {
196196
compilerOptions: {
197197
allowJs: true
198198
},
199-
include: ['dist/*.js']
199+
include: ['dist/*.js', 'dist/exp/*.js']
200200
}),
201201
sourcemaps()
202202
];

packages/firestore/src/api/database.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class FirestoreSettings {
160160

161161
readonly cacheSizeBytes: number;
162162

163-
readonly forceLongPolling: boolean;
163+
readonly experimentalForceLongPolling: boolean;
164164

165165
readonly ignoreUndefinedProperties: boolean;
166166

@@ -263,7 +263,7 @@ class FirestoreSettings {
263263
'experimentalForceLongPolling',
264264
settings.experimentalForceLongPolling
265265
);
266-
this.forceLongPolling =
266+
this.experimentalForceLongPolling =
267267
settings.experimentalForceLongPolling ?? DEFAULT_FORCE_LONG_POLLING;
268268
}
269269

@@ -274,7 +274,8 @@ class FirestoreSettings {
274274
this.timestampsInSnapshots === other.timestampsInSnapshots &&
275275
this.credentials === other.credentials &&
276276
this.cacheSizeBytes === other.cacheSizeBytes &&
277-
this.forceLongPolling === other.forceLongPolling &&
277+
this.experimentalForceLongPolling ===
278+
other.experimentalForceLongPolling &&
278279
this.ignoreUndefinedProperties === other.ignoreUndefinedProperties
279280
);
280281
}
@@ -361,6 +362,12 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
361362
validateExactNumberOfArgs('Firestore.settings', arguments, 1);
362363
validateArgType('Firestore.settings', 'object', 1, settingsLiteral);
363364

365+
if (settingsLiteral.merge) {
366+
settingsLiteral = { ...this._settings, ...settingsLiteral };
367+
// Remove the property from the settings once the merge is completed
368+
delete settingsLiteral.merge;
369+
}
370+
364371
const newSettings = new FirestoreSettings(settingsLiteral);
365372
if (this._firestoreClient && !this._settings.isEqual(newSettings)) {
366373
throw new FirestoreError(
@@ -516,7 +523,7 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
516523
this._persistenceKey,
517524
this._settings.host,
518525
this._settings.ssl,
519-
this._settings.forceLongPolling
526+
this._settings.experimentalForceLongPolling
520527
);
521528
}
522529

@@ -681,6 +688,11 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
681688
_areTimestampsInSnapshotsEnabled(): boolean {
682689
return this._settings.timestampsInSnapshots;
683690
}
691+
692+
// Visible for testing.
693+
_getSettings(): firestore.Settings {
694+
return this._settings;
695+
}
684696
}
685697

686698
/**

packages/firestore/src/core/transaction.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import {
3333
import { fail, debugAssert } from '../util/assert';
3434
import { Code, FirestoreError } from '../util/error';
3535
import { SnapshotVersion } from './snapshot_version';
36-
import { ResourcePath } from '../model/path';
3736

3837
/**
3938
* Internal transaction object responsible for accumulating the mutations to
@@ -57,7 +56,7 @@ export class Transaction {
5756
* When there's more than one write to the same key in a transaction, any
5857
* writes after the first are handled differently.
5958
*/
60-
private writtenDocs: Set<DocumentKey> = new Set();
59+
private writtenDocs: Set</* path= */ string> = new Set();
6160

6261
constructor(private datastore: Datastore) {}
6362

@@ -83,7 +82,7 @@ export class Transaction {
8382

8483
set(key: DocumentKey, data: ParsedSetData): void {
8584
this.write(data.toMutations(key, this.precondition(key)));
86-
this.writtenDocs.add(key);
85+
this.writtenDocs.add(key.toString());
8786
}
8887

8988
update(key: DocumentKey, data: ParsedUpdateData): void {
@@ -92,12 +91,12 @@ export class Transaction {
9291
} catch (e) {
9392
this.lastWriteError = e;
9493
}
95-
this.writtenDocs.add(key);
94+
this.writtenDocs.add(key.toString());
9695
}
9796

9897
delete(key: DocumentKey): void {
9998
this.write([new DeleteMutation(key, this.precondition(key))]);
100-
this.writtenDocs.add(key);
99+
this.writtenDocs.add(key.toString());
101100
}
102101

103102
async commit(): Promise<void> {
@@ -114,7 +113,7 @@ export class Transaction {
114113
// For each document that was read but not written to, we want to perform
115114
// a `verify` operation.
116115
unwritten.forEach((_, path) => {
117-
const key = new DocumentKey(ResourcePath.fromString(path));
116+
const key = DocumentKey.fromPath(path);
118117
this.mutations.push(new VerifyMutation(key, this.precondition(key)));
119118
});
120119
await invokeCommitRpc(this.datastore, this.mutations);
@@ -153,7 +152,7 @@ export class Transaction {
153152
*/
154153
private precondition(key: DocumentKey): Precondition {
155154
const version = this.readVersions.get(key.toString());
156-
if (!this.writtenDocs.has(key) && version) {
155+
if (!this.writtenDocs.has(key.toString()) && version) {
157156
return Precondition.updateTime(version);
158157
} else {
159158
return Precondition.none();
@@ -167,7 +166,7 @@ export class Transaction {
167166
const version = this.readVersions.get(key.toString());
168167
// The first time a document is written, we want to take into account the
169168
// read time and existence
170-
if (!this.writtenDocs.has(key) && version) {
169+
if (!this.writtenDocs.has(key.toString()) && version) {
171170
if (version.isEqual(SnapshotVersion.min())) {
172171
// The document doesn't exist, so fail the transaction.
173172

0 commit comments

Comments
 (0)