Skip to content

Commit 4f3b950

Browse files
time to test
1 parent 4f3662b commit 4f3b950

30 files changed

+2395
-2312
lines changed

packages/firestore/src/api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ export { FirestoreErrorCode, FirestoreError } from './util/error';
133133

134134
export { AbstractUserDataWriter } from './lite-api/user_data_writer';
135135

136+
export { FirestoreSettings as Settings } from './lite-api/settings';
137+
136138
export {
137139
Primitive,
138140
NestedUpdateFields,

packages/firestore/src/api/snapshot.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ import { SnapshotListenOptions } from './reference_impl';
5959
* }
6060
*
6161
* const postConverter = {
62-
* toFirestore(post: WithFieldValue<Post>): firebase.firestore.DocumentData {
62+
* toFirestore(post: WithFieldValue<Post>): DocumentData {
6363
* return {title: post.title, author: post.author};
6464
* },
6565
* fromFirestore(
66-
* snapshot: firebase.firestore.QueryDocumentSnapshot,
67-
* options: firebase.firestore.SnapshotOptions
66+
* snapshot: QueryDocumentSnapshot,
67+
* options: SnapshotOptions
6868
* ): Post {
6969
* const data = snapshot.data(options)!;
7070
* return new Post(data.title, data.author);
@@ -269,7 +269,7 @@ export class DocumentSnapshot<
269269
* Retrieves all fields in the document as an `Object`. Returns `undefined` if
270270
* the document doesn't exist.
271271
*
272-
* By default, `FieldValue.serverTimestamp()` values that have not yet been
272+
* By default, `serverTimestamp()` values that have not yet been
273273
* set to their final value will be returned as `null`. You can override
274274
* this by passing an options object.
275275
*
@@ -306,7 +306,7 @@ export class DocumentSnapshot<
306306
* Retrieves the field specified by `fieldPath`. Returns `undefined` if the
307307
* document or field doesn't exist.
308308
*
309-
* By default, a `FieldValue.serverTimestamp()` that has not yet been set to
309+
* By default, a `serverTimestamp()` that has not yet been set to
310310
* its final value will be returned as `null`. You can override this by
311311
* passing an options object.
312312
*
@@ -353,7 +353,7 @@ export class QueryDocumentSnapshot<
353353
/**
354354
* Retrieves all fields in the document as an `Object`.
355355
*
356-
* By default, `FieldValue.serverTimestamp()` values that have not yet been
356+
* By default, `serverTimestamp()` values that have not yet been
357357
* set to their final value will be returned as `null`. You can override
358358
* this by passing an options object.
359359
*

packages/firestore/src/lite-api/query.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,7 @@ export function newQueryFilter(
480480
if (op === Operator.ARRAY_CONTAINS || op === Operator.ARRAY_CONTAINS_ANY) {
481481
throw new FirestoreError(
482482
Code.INVALID_ARGUMENT,
483-
`Invalid Query. You can't perform '${op}' ` +
484-
'queries on FieldPath.documentId().'
483+
`Invalid Query. You can't perform '${op}' ` + 'queries on documentId().'
485484
);
486485
} else if (op === Operator.IN || op === Operator.NOT_IN) {
487486
validateDisjunctiveFilterElements(value, op);
@@ -639,7 +638,7 @@ export function newQueryBoundFromFields(
639638
if (!isCollectionGroupQuery(query) && rawValue.indexOf('/') !== -1) {
640639
throw new FirestoreError(
641640
Code.INVALID_ARGUMENT,
642-
`Invalid query. When querying a collection and ordering by FieldPath.documentId(), ` +
641+
`Invalid query. When querying a collection and ordering by documentId(), ` +
643642
`the value passed to ${methodName}() must be a plain document ID, but ` +
644643
`'${rawValue}' contains a slash.`
645644
);
@@ -649,7 +648,7 @@ export function newQueryBoundFromFields(
649648
throw new FirestoreError(
650649
Code.INVALID_ARGUMENT,
651650
`Invalid query. When querying a collection group and ordering by ` +
652-
`FieldPath.documentId(), the value passed to ${methodName}() must result in a ` +
651+
`documentId(), the value passed to ${methodName}() must result in a ` +
653652
`valid document path, but '${path}' is not because it contains an odd number ` +
654653
`of segments.`
655654
);
@@ -681,15 +680,15 @@ function parseDocumentIdValue(
681680
if (documentIdValue === '') {
682681
throw new FirestoreError(
683682
Code.INVALID_ARGUMENT,
684-
'Invalid query. When querying with FieldPath.documentId(), you ' +
683+
'Invalid query. When querying with documentId(), you ' +
685684
'must provide a valid document ID, but it was an empty string.'
686685
);
687686
}
688687
if (!isCollectionGroupQuery(query) && documentIdValue.indexOf('/') !== -1) {
689688
throw new FirestoreError(
690689
Code.INVALID_ARGUMENT,
691690
`Invalid query. When querying a collection by ` +
692-
`FieldPath.documentId(), you must provide a plain document ID, but ` +
691+
`documentId(), you must provide a plain document ID, but ` +
693692
`'${documentIdValue}' contains a '/' character.`
694693
);
695694
}
@@ -698,7 +697,7 @@ function parseDocumentIdValue(
698697
throw new FirestoreError(
699698
Code.INVALID_ARGUMENT,
700699
`Invalid query. When querying a collection group by ` +
701-
`FieldPath.documentId(), the value provided must result in a valid document path, ` +
700+
`documentId(), the value provided must result in a valid document path, ` +
702701
`but '${path}' is not because it has an odd number of segments (${path.length}).`
703702
);
704703
}
@@ -708,7 +707,7 @@ function parseDocumentIdValue(
708707
} else {
709708
throw new FirestoreError(
710709
Code.INVALID_ARGUMENT,
711-
`Invalid query. When querying with FieldPath.documentId(), you must provide a valid ` +
710+
`Invalid query. When querying with documentId(), you must provide a valid ` +
712711
`string or a DocumentReference, but it was: ` +
713712
`${valueDescription(documentIdValue)}.`
714713
);

packages/firestore/src/lite-api/snapshot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ import { AbstractUserDataWriter } from './user_data_writer';
5757
* }
5858
*
5959
* const postConverter = {
60-
* toFirestore(post: WithFieldValue<Post>): firebase.firestore.DocumentData {
60+
* toFirestore(post: WithFieldValue<Post>): DocumentData {
6161
* return {title: post.title, author: post.author};
6262
* },
63-
* fromFirestore(snapshot: firebase.firestore.QueryDocumentSnapshot): Post {
63+
* fromFirestore(snapshot: QueryDocumentSnapshot): Post {
6464
* const data = snapshot.data(options)!;
6565
* return new Post(data.title, data.author);
6666
* }

packages/firestore/src/lite-api/user_data_reader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ export function parseData(
722722
validatePlainObject('Unsupported field value:', context, input);
723723
return parseObject(input, context);
724724
} else if (input instanceof FieldValue) {
725-
// FieldValues usually parse into transforms (except FieldValue.delete())
725+
// FieldValues usually parse into transforms (except deleteField())
726726
// in which case we do not want to include this field in our parsed data
727727
// (as doing so will overwrite the field directly prior to the transform
728728
// trying to transform it). So we don't add this location to

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

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,26 @@
1515
* limitations under the License.
1616
*/
1717

18-
import * as firestore from '@firebase/firestore-types';
1918
import { expect } from 'chai';
2019

2120
import { addEqualityMatcher } from '../../util/equality_matcher';
2221
import { EventsAccumulator } from '../util/events_accumulator';
23-
import * as firebaseExport from '../util/firebase_export';
22+
import {
23+
doc,
24+
DocumentData,
25+
DocumentReference,
26+
DocumentSnapshot,
27+
getDocFromCache,
28+
onSnapshot,
29+
setDoc,
30+
updateDoc,
31+
arrayRemove,
32+
arrayUnion
33+
} from '../util/firebase_export';
2434
import { apiDescribe, withTestDb, withTestDoc } from '../util/helpers';
2535

2636
addEqualityMatcher();
2737

28-
const FieldValue = firebaseExport.FieldValue;
29-
3038
/**
3139
* Note: Transforms are tested pretty thoroughly in server_timestamp.test.ts
3240
* (via set, update, transactions, nested in documents, multiple transforms
@@ -35,27 +43,25 @@ const FieldValue = firebaseExport.FieldValue;
3543
*/
3644
apiDescribe('Array Transforms:', (persistence: boolean) => {
3745
// A document reference to read and write to.
38-
let docRef: firestore.DocumentReference;
46+
let docRef: DocumentReference;
3947

4048
// Accumulator used to capture events during the test.
41-
let accumulator: EventsAccumulator<firestore.DocumentSnapshot>;
49+
let accumulator: EventsAccumulator<DocumentSnapshot>;
4250

4351
// Listener registration for a listener maintained during the course of the
4452
// test.
4553
let unsubscribe: () => void;
4654

4755
/** Writes some initialData and consumes the events generated. */
48-
async function writeInitialData(
49-
initialData: firestore.DocumentData
50-
): Promise<void> {
51-
await docRef.set(initialData);
56+
async function writeInitialData(initialData: DocumentData): Promise<void> {
57+
await setDoc(docRef, initialData);
5258
await accumulator.awaitLocalEvent();
5359
const snapshot = await accumulator.awaitRemoteEvent();
5460
expect(snapshot.data()).to.deep.equal(initialData);
5561
}
5662

5763
async function expectLocalAndRemoteEvent(
58-
expected: firestore.DocumentData
64+
expected: DocumentData
5965
): Promise<void> {
6066
const localSnap = await accumulator.awaitLocalEvent();
6167
expect(localSnap.data()).to.deep.equal(expected);
@@ -70,8 +76,9 @@ apiDescribe('Array Transforms:', (persistence: boolean) => {
7076
async function withTestSetup<T>(test: () => Promise<T>): Promise<void> {
7177
await withTestDoc(persistence, async doc => {
7278
docRef = doc;
73-
accumulator = new EventsAccumulator<firestore.DocumentSnapshot>();
74-
unsubscribe = docRef.onSnapshot(
79+
accumulator = new EventsAccumulator<DocumentSnapshot>();
80+
unsubscribe = onSnapshot(
81+
docRef,
7582
{ includeMetadataChanges: true },
7683
accumulator.storeEvent
7784
);
@@ -86,35 +93,32 @@ apiDescribe('Array Transforms:', (persistence: boolean) => {
8693

8794
it('create document with arrayUnion()', async () => {
8895
await withTestSetup(async () => {
89-
await docRef.set({ array: FieldValue.arrayUnion(1, 2) });
96+
await setDoc(docRef, { array: arrayUnion(1, 2) });
9097
await expectLocalAndRemoteEvent({ array: [1, 2] });
9198
});
9299
});
93100

94101
it('append to array via update()', async () => {
95102
await withTestSetup(async () => {
96103
await writeInitialData({ array: [1, 3] });
97-
await docRef.update({ array: FieldValue.arrayUnion(2, 1, 4) });
104+
await updateDoc(docRef, { array: arrayUnion(2, 1, 4) });
98105
await expectLocalAndRemoteEvent({ array: [1, 3, 2, 4] });
99106
});
100107
});
101108

102109
it('append to array via set(..., {merge: true})', async () => {
103110
await withTestSetup(async () => {
104111
await writeInitialData({ array: [1, 3] });
105-
await docRef.set(
106-
{ array: FieldValue.arrayUnion(2, 1, 4) },
107-
{ merge: true }
108-
);
112+
await setDoc(docRef, { array: arrayUnion(2, 1, 4) }, { merge: true });
109113
await expectLocalAndRemoteEvent({ array: [1, 3, 2, 4] });
110114
});
111115
});
112116

113117
it('append object to array via update()', async () => {
114118
await withTestSetup(async () => {
115119
await writeInitialData({ array: [{ a: 'hi' }] });
116-
await docRef.update({
117-
array: FieldValue.arrayUnion({ a: 'hi' }, { a: 'bye' })
120+
await updateDoc(docRef, {
121+
array: arrayUnion({ a: 'hi' }, { a: 'bye' })
118122
});
119123
await expectLocalAndRemoteEvent({ array: [{ a: 'hi' }, { a: 'bye' }] });
120124
});
@@ -123,33 +127,30 @@ apiDescribe('Array Transforms:', (persistence: boolean) => {
123127
it('remove from array via update()', async () => {
124128
await withTestSetup(async () => {
125129
await writeInitialData({ array: [1, 3, 1, 3] });
126-
await docRef.update({ array: FieldValue.arrayRemove(1, 4) });
130+
await updateDoc(docRef, { array: arrayRemove(1, 4) });
127131
await expectLocalAndRemoteEvent({ array: [3, 3] });
128132
});
129133
});
130134

131135
it('remove from array via set(..., {merge: true})', async () => {
132136
await withTestSetup(async () => {
133137
await writeInitialData({ array: [1, 3, 1, 3] });
134-
await docRef.set(
135-
{ array: FieldValue.arrayRemove(1, 4) },
136-
{ merge: true }
137-
);
138+
await setDoc(docRef, { array: arrayRemove(1, 4) }, { merge: true });
138139
await expectLocalAndRemoteEvent({ array: [3, 3] });
139140
});
140141
});
141142

142143
it('remove object from array via update()', async () => {
143144
await withTestSetup(async () => {
144145
await writeInitialData({ array: [{ a: 'hi' }, { a: 'bye' }] });
145-
await docRef.update({ array: FieldValue.arrayRemove({ a: 'hi' }) });
146+
await updateDoc(docRef, { array: arrayRemove({ a: 'hi' }) });
146147
await expectLocalAndRemoteEvent({ array: [{ a: 'bye' }] });
147148
});
148149
});
149150

150151
it('arrayUnion() supports DocumentReference', async () => {
151152
await withTestSetup(async () => {
152-
await docRef.set({ array: FieldValue.arrayUnion(docRef) });
153+
await setDoc(docRef, { array: arrayUnion(docRef) });
153154
await expectLocalAndRemoteEvent({ array: [docRef] });
154155
});
155156
});
@@ -165,8 +166,8 @@ apiDescribe('Array Transforms:', (persistence: boolean) => {
165166
(persistence ? describe : describe.skip)('Server Application: ', () => {
166167
it('set() with no cached base doc', async () => {
167168
await withTestDoc(persistence, async docRef => {
168-
await docRef.set({ array: FieldValue.arrayUnion(1, 2) });
169-
const snapshot = await docRef.get({ source: 'cache' });
169+
await setDoc(docRef, { array: arrayUnion(1, 2) });
170+
const snapshot = await getDocFromCache(docRef);
170171
expect(snapshot.data()).to.deep.equal({ array: [1, 2] });
171172
});
172173
});
@@ -177,18 +178,18 @@ apiDescribe('Array Transforms:', (persistence: boolean) => {
177178
// stored in our cache
178179
await withTestDoc(persistence, async docRef => {
179180
path = docRef.path;
180-
await docRef.set({ array: [42] });
181+
await setDoc(docRef, { array: [42] });
181182
});
182183

183184
await withTestDb(persistence, async db => {
184-
const docRef = db.doc(path!);
185-
await docRef.update({ array: FieldValue.arrayUnion(1, 2) });
185+
const docRef = doc(db, path!);
186+
await updateDoc(docRef, { array: arrayUnion(1, 2) });
186187

187188
// Nothing should be cached since it was an update and we had no base
188189
// doc.
189190
let errCaught = false;
190191
try {
191-
await docRef.get({ source: 'cache' });
192+
await getDocFromCache(docRef);
192193
} catch (err) {
193194
expect(err.code).to.equal('unavailable');
194195
errCaught = true;
@@ -203,36 +204,33 @@ apiDescribe('Array Transforms:', (persistence: boolean) => {
203204
// stored in our cache
204205
await withTestDoc(persistence, async docRef => {
205206
path = docRef.path;
206-
await docRef.set({ array: [42] });
207+
await setDoc(docRef, { array: [42] });
207208
});
208209

209210
await withTestDb(persistence, async db => {
210-
const docRef = db.doc(path!);
211-
await docRef.set(
212-
{ array: FieldValue.arrayUnion(1, 2) },
213-
{ merge: true }
214-
);
211+
const docRef = doc(db, path!);
212+
await setDoc(docRef, { array: arrayUnion(1, 2) }, { merge: true });
215213

216214
// Document will be cached but we'll be missing 42.
217-
const snapshot = await docRef.get({ source: 'cache' });
215+
const snapshot = await getDocFromCache(docRef);
218216
expect(snapshot.data()).to.deep.equal({ array: [1, 2] });
219217
});
220218
});
221219

222220
it('update() with cached base doc using arrayUnion()', async () => {
223221
await withTestDoc(persistence, async docRef => {
224-
await docRef.set({ array: [42] });
225-
await docRef.update({ array: FieldValue.arrayUnion(1, 2) });
226-
const snapshot = await docRef.get({ source: 'cache' });
222+
await setDoc(docRef, { array: [42] });
223+
await updateDoc(docRef, { array: arrayUnion(1, 2) });
224+
const snapshot = await getDocFromCache(docRef);
227225
expect(snapshot.data()).to.deep.equal({ array: [42, 1, 2] });
228226
});
229227
});
230228

231229
it('update() with cached base doc using arrayRemove()', async () => {
232230
await withTestDoc(persistence, async docRef => {
233-
await docRef.set({ array: [42, 1, 2] });
234-
await docRef.update({ array: FieldValue.arrayRemove(1, 2) });
235-
const snapshot = await docRef.get({ source: 'cache' });
231+
await setDoc(docRef, { array: [42, 1, 2] });
232+
await updateDoc(docRef, { array: arrayRemove(1, 2) });
233+
const snapshot = await getDocFromCache(docRef);
236234
expect(snapshot.data()).to.deep.equal({ array: [42] });
237235
});
238236
});

0 commit comments

Comments
 (0)