Skip to content

Commit fd7fbd7

Browse files
Remove error messages for deprecated APIs (#2857)
1 parent 5b90965 commit fd7fbd7

File tree

3 files changed

+27
-95
lines changed

3 files changed

+27
-95
lines changed

packages/firebase/index.d.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7682,11 +7682,23 @@ declare namespace firebase.firestore {
76827682
* causes unexpected behavior when using a timestamp from a snapshot as a
76837683
* part of a subsequent query.
76847684
*
7685-
* So now Firestore returns `Timestamp` values instead of `Date`, avoiding
7686-
* this kind of problem.
7687-
*
7688-
* To opt into the old behavior of returning `Date` objects, you can
7689-
* temporarily set `timestampsInSnapshots` to false.
7685+
* Now, Firestore returns `Timestamp` values for all timestamp values stored
7686+
* in Cloud Firestore instead of system `Date` objects, avoiding this kind
7687+
* of problem. Consequently, you must update your code to handle `Timestamp`
7688+
* objects instead of `Date` objects.
7689+
*
7690+
* If you want to **temporarily** opt into the old behavior of returning
7691+
* `Date` objects, you may **temporarily** set `timestampsInSnapshots` to
7692+
* false. Opting into this behavior will no longer be possible in the next
7693+
* major release of Firestore, after which code that expects Date objects
7694+
* **will break**.
7695+
*
7696+
* @example **Using Date objects in Firestore.**
7697+
* // With deprecated setting `timestampsInSnapshot: true`:
7698+
* const date : Date = snapshot.get('created_at');
7699+
* // With new default behavior:
7700+
* const timestamp : Timestamp = snapshot.get('created_at');
7701+
* const date : Date = timestamp.toDate();
76907702
*
76917703
* @deprecated This setting will be removed in a future release. You should
76927704
* update your code to expect `Timestamp` objects and stop using the

packages/firestore/src/api/database.ts

Lines changed: 9 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -194,32 +194,15 @@ class FirestoreSettings {
194194
// Nobody should set timestampsInSnapshots anymore, but the error depends on
195195
// whether they set it to true or false...
196196
if (settings.timestampsInSnapshots === true) {
197-
logError(`
198-
The timestampsInSnapshots setting now defaults to true and you no
199-
longer need to explicitly set it. In a future release, the setting
200-
will be removed entirely and so it is recommended that you remove it
201-
from your firestore.settings() call now.`);
197+
logError(
198+
"The setting 'timestampsInSnapshots: true' is no longer required " +
199+
'and should be removed.'
200+
);
202201
} else if (settings.timestampsInSnapshots === false) {
203-
logError(`
204-
The timestampsInSnapshots setting will soon be removed. YOU MUST UPDATE
205-
YOUR CODE.
206-
207-
To hide this warning, stop using the timestampsInSnapshots setting in your
208-
firestore.settings({ ... }) call.
209-
210-
Once you remove the setting, Timestamps stored in Cloud Firestore will be
211-
read back as Firebase Timestamp objects instead of as system Date objects.
212-
So you will also need to update code expecting a Date to instead expect a
213-
Timestamp. For example:
214-
215-
// Old:
216-
const date = snapshot.get('created_at');
217-
// New:
218-
const timestamp = snapshot.get('created_at'); const date =
219-
timestamp.toDate();
220-
221-
Please audit all existing usages of Date when you enable the new
222-
behavior.`);
202+
logError(
203+
"Support for 'timestampsInSnapshots: false' will be removed soon. " +
204+
'You must update your code to handle Timestamp objects.'
205+
);
223206
}
224207
this.timestampsInSnapshots =
225208
settings.timestampsInSnapshots ?? DEFAULT_TIMESTAMPS_IN_SNAPSHOTS;
@@ -338,14 +321,6 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
338321
validateExactNumberOfArgs('Firestore.settings', arguments, 1);
339322
validateArgType('Firestore.settings', 'object', 1, settingsLiteral);
340323

341-
if (contains(settingsLiteral, 'persistence')) {
342-
throw new FirestoreError(
343-
Code.INVALID_ARGUMENT,
344-
'"persistence" is now specified with a separate call to ' +
345-
'firestore.enablePersistence().'
346-
);
347-
}
348-
349324
const newSettings = new FirestoreSettings(settingsLiteral);
350325
if (this._firestoreClient && !this._settings.isEqual(newSettings)) {
351326
throw new FirestoreError(
@@ -387,10 +362,7 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
387362
if (settings) {
388363
if (settings.experimentalTabSynchronization !== undefined) {
389364
logError(
390-
"The 'experimentalTabSynchronization' setting has been renamed to " +
391-
"'synchronizeTabs'. In a future release, the setting will be removed " +
392-
'and it is recommended that you update your ' +
393-
"firestore.enablePersistence() call to use 'synchronizeTabs'."
365+
"The 'experimentalTabSynchronization' setting will be removed. Use 'synchronizeTabs' instead."
394366
);
395367
}
396368
synchronizeTabs =
@@ -2305,42 +2277,6 @@ export class QuerySnapshot<T = firestore.DocumentData>
23052277
}
23062278
}
23072279

2308-
// TODO(2018/11/01): As of 2018/04/17 we're changing docChanges from an array
2309-
// into a method. Because this is a runtime breaking change and somewhat subtle
2310-
// (both Array and Function have a .length, etc.), we'll replace commonly-used
2311-
// properties (including Symbol.iterator) to throw a custom error message. In
2312-
// ~6 months we can delete the custom error as most folks will have hopefully
2313-
// migrated.
2314-
function throwDocChangesMethodError(): never {
2315-
throw new FirestoreError(
2316-
Code.INVALID_ARGUMENT,
2317-
'QuerySnapshot.docChanges has been changed from a property into a ' +
2318-
'method, so usages like "querySnapshot.docChanges" should become ' +
2319-
'"querySnapshot.docChanges()"'
2320-
);
2321-
}
2322-
2323-
const docChangesPropertiesToOverride = [
2324-
'length',
2325-
'forEach',
2326-
'map',
2327-
...(typeof Symbol !== 'undefined' ? [Symbol.iterator] : [])
2328-
];
2329-
docChangesPropertiesToOverride.forEach(property => {
2330-
/**
2331-
* We are (re-)defining properties on QuerySnapshot.prototype.docChanges which
2332-
* is a Function. This could fail, in particular in the case of 'length' which
2333-
* already exists on Function.prototype and on IE11 is improperly defined with
2334-
* `{ configurable: false }`. So we wrap this in a try/catch to ensure that we
2335-
* still have a functional SDK.
2336-
*/
2337-
try {
2338-
Object.defineProperty(QuerySnapshot.prototype.docChanges, property, {
2339-
get: () => throwDocChangesMethodError()
2340-
});
2341-
} catch (err) {} // Ignore this failure intentionally
2342-
});
2343-
23442280
export class CollectionReference<T = firestore.DocumentData> extends Query<T>
23452281
implements firestore.CollectionReference<T> {
23462282
constructor(

packages/firestore/test/integration/api/query.test.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2017 Google Inc.
3+
* Copyright 2017 Google LLC
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -784,22 +784,6 @@ apiDescribe('Queries', (persistence: boolean) => {
784784
});
785785
});
786786

787-
it('throws custom error when using docChanges as property', () => {
788-
return withTestCollection(persistence, {}, async coll => {
789-
const snapshot = await coll.get();
790-
const expectedError =
791-
'QuerySnapshot.docChanges has been changed from a property into a method';
792-
// We are testing invalid API usage.
793-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
794-
const docChange = snapshot.docChanges as any;
795-
expect(() => docChange.length).to.throw(expectedError);
796-
expect(() => {
797-
for (const _ of docChange) {
798-
}
799-
}).to.throw(expectedError);
800-
});
801-
});
802-
803787
it('can query collection groups', async () => {
804788
await withTestDb(persistence, async db => {
805789
// Use .doc() to get a random collection group name to use but ensure it starts with 'b' for

0 commit comments

Comments
 (0)