Skip to content

Commit c11e067

Browse files
author
Brian Chen
committed
update comments and changeset
1 parent a2df21b commit c11e067

File tree

4 files changed

+29
-32
lines changed

4 files changed

+29
-32
lines changed

.changeset/dirty-pandas-pay.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@
33
'@firebase/firestore': major
44
---
55

6-
Added support for FieldValues when using a FirestoreDataConverter and support for update() calls with a converter
6+
This change contains multiple quality-of-life improvements when using the `FirestoreDataConverter` in `@firebase/firestore/lite` and `@firebase/firestore/exp`:
7+
- Support for passing in `FieldValue` property values when using a converter (via `WithFieldValue<T>` and `PartialWithFieldValue<T>`).
8+
- Support for omitting properties in nested fields when performing a set operation with `{merge: true}` with a converter (via `PartialWithFieldValue<T>`).
9+
- [breaking] Support for typed update operations when using a converter (via the newly typed `UpdateData`). Improperly typed fields in
10+
update operations on typed document references will no longer compile.

packages/firestore/src/lite/reference.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ export type WithFieldValue<T> = T extends Primitive
7575
/**
7676
* Update data (for use with {@link (setDoc:1)}) that consists of field paths
7777
* (e.g. 'foo' or 'foo.baz') mapped to values. Fields that contain dots
78-
* reference nested fields within the document.
78+
* reference nested fields within the document. FieldValues can be passed in
79+
* as property values.
7980
*/
8081
export type UpdateData<T> = T extends Primitive
8182
? T

packages/firestore/src/lite/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717

1818
import { UpdateData } from './reference';
1919

20+
/**
21+
* These types primarily exist to support the `UpdateData`,
22+
* `WithFieldValue`, and `PartialWithFieldValue` types and are not consumed
23+
* directly by the end developer.
24+
*/
25+
2026
/** Primitive types. */
2127
export type Primitive = string | number | boolean | undefined | null;
2228

packages/firestore/test/lite/integration.test.ts

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,10 +1285,8 @@ describe('withConverter() support', () => {
12851285
};
12861286

12871287
it('supports FieldValues', async () => {
1288-
return withTestDb(async db => {
1289-
const ref = doc(collection(db, 'testobj')).withConverter(
1290-
testConverterMerge
1291-
);
1288+
return withTestDoc(async doc => {
1289+
const ref = doc.withConverter(testConverter);
12921290

12931291
// Allow Field Values in nested partials.
12941292
await setDoc(
@@ -1318,10 +1316,8 @@ describe('withConverter() support', () => {
13181316
});
13191317

13201318
it('validates types in outer and inner fields', async () => {
1321-
return withTestDb(async db => {
1322-
const ref = doc(collection(db, 'testobj')).withConverter(
1323-
testConverterMerge
1324-
);
1319+
return withTestDoc(async doc => {
1320+
const ref = doc.withConverter(testConverter);
13251321

13261322
// Check top-level fields.
13271323
await setDoc(
@@ -1362,10 +1358,8 @@ describe('withConverter() support', () => {
13621358
});
13631359

13641360
it('checks for nonexistent properties', async () => {
1365-
return withTestDb(async db => {
1366-
const ref = doc(collection(db, 'testobj')).withConverter(
1367-
testConverterMerge
1368-
);
1361+
return withTestDoc(async doc => {
1362+
const ref = doc.withConverter(testConverter);
13691363
// Top-level property.
13701364
await setDoc(
13711365
ref,
@@ -1393,10 +1387,8 @@ describe('withConverter() support', () => {
13931387

13941388
describe('WithFieldValue', () => {
13951389
it('supports FieldValues', async () => {
1396-
return withTestDb(async db => {
1397-
const ref = doc(collection(db, 'testobj')).withConverter(
1398-
testConverter
1399-
);
1390+
return withTestDoc(async doc => {
1391+
const ref = doc.withConverter(testConverter);
14001392

14011393
// Allow Field Values and nested partials.
14021394
await setDoc(ref, {
@@ -1414,10 +1406,8 @@ describe('withConverter() support', () => {
14141406
});
14151407

14161408
it('requires all fields to be present', async () => {
1417-
return withTestDb(async db => {
1418-
const ref = doc(collection(db, 'testobj')).withConverter(
1419-
testConverter
1420-
);
1409+
return withTestDoc(async doc => {
1410+
const ref = doc.withConverter(testConverter);
14211411

14221412
// Allow Field Values and nested partials.
14231413
// @ts-expect-error
@@ -1435,10 +1425,8 @@ describe('withConverter() support', () => {
14351425
});
14361426

14371427
it('validates inner and outer fields', async () => {
1438-
return withTestDb(async db => {
1439-
const ref = doc(collection(db, 'testobj')).withConverter(
1440-
testConverter
1441-
);
1428+
return withTestDoc(async doc => {
1429+
const ref = doc.withConverter(testConverter);
14421430

14431431
await setDoc(ref, {
14441432
outerString: 'foo',
@@ -1457,10 +1445,8 @@ describe('withConverter() support', () => {
14571445
});
14581446

14591447
it('checks for nonexistent properties', async () => {
1460-
return withTestDb(async db => {
1461-
const ref = doc(collection(db, 'testobj')).withConverter(
1462-
testConverter
1463-
);
1448+
return withTestDoc(async doc => {
1449+
const ref = doc.withConverter(testConverter);
14641450

14651451
// Top-level nonexistent fields should error
14661452
await setDoc(ref, {
@@ -1590,8 +1576,8 @@ describe('withConverter() support', () => {
15901576

15911577
describe('methods', () => {
15921578
it('addDoc()', () => {
1593-
return withTestDb(async db => {
1594-
const ref = collection(db, 'testobj').withConverter(testConverter);
1579+
return withTestDoc(async doc => {
1580+
const ref = doc.withConverter(testConverter);
15951581

15961582
// Requires all fields to be present
15971583
// @ts-expect-error

0 commit comments

Comments
 (0)