Skip to content

Commit 596f9c6

Browse files
Update and enable Lite tests
1 parent eb44f4a commit 596f9c6

File tree

10 files changed

+103
-94
lines changed

10 files changed

+103
-94
lines changed

packages/firestore/.idea/runConfigurations/firestore_exp_Tests__Emulator__.xml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/firestore/.idea/runConfigurations/firestore_exp_Tests__Emulator_w__Mock_Persistence_.xml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/firestore/exp-types/index.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export interface FirestoreDataConverter<T> {
6868
toFirestore(modelObject: Partial<T>, options: SetOptions): DocumentData;
6969
fromFirestore(
7070
snapshot: QueryDocumentSnapshot<DocumentData>,
71-
options: SnapshotOptions
71+
options?: SnapshotOptions
7272
): T;
7373
}
7474

@@ -242,9 +242,11 @@ export type SetOptions =
242242
export class DocumentReference<T = DocumentData> {
243243
private constructor();
244244
readonly type: 'document';
245-
readonly id: string;
246245
readonly firestore: FirebaseFirestore;
246+
readonly converter: FirestoreDataConverter<T> | null;
247247
readonly path: string;
248+
readonly id: string;
249+
248250
withConverter<U>(converter: FirestoreDataConverter<U>): DocumentReference<U>;
249251
}
250252

@@ -284,6 +286,7 @@ export class Query<T = DocumentData> {
284286
protected constructor();
285287
readonly type: 'query' | 'collection';
286288
readonly firestore: FirebaseFirestore;
289+
readonly converter: FirestoreDataConverter<T> | null;
287290

288291
withConverter<U>(converter: FirestoreDataConverter<U>): Query<U>;
289292
}

packages/firestore/exp/src/api/snapshot.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ import {
2929
} from '../../../lite/src/api/snapshot';
3030
import { Firestore } from './database';
3131
import { cast } from '../../../lite/src/api/util';
32-
import {
33-
DocumentReference,
34-
Query,
35-
queryEqual
36-
} from '../../../lite/src/api/reference';
32+
import { DocumentReference, Query, queryEqual } from '../../../lite';
3733
import {
3834
changesFromSnapshot,
3935
SnapshotMetadata
@@ -85,8 +81,8 @@ export class DocumentSnapshot<T = firestore.DocumentData>
8581
key =>
8682
new DocumentReference(
8783
this._firestore,
88-
key.path,
89-
/* converter= */ null
84+
/* converter= */ null,
85+
key.path
9086
)
9187
);
9288
return userDataWriter.convertValue(this._document.toProto()) as T;
@@ -107,7 +103,7 @@ export class DocumentSnapshot<T = firestore.DocumentData>
107103
/* timestampsInSnapshots= */ true,
108104
options.serverTimestamps || DEFAULT_SERVER_TIMESTAMP_BEHAVIOR,
109105
key =>
110-
new DocumentReference(this._firestore, key.path, this._converter)
106+
new DocumentReference(this._firestore, this._converter, key.path)
111107
);
112108
return userDataWriter.convertValue(value);
113109
}
@@ -210,7 +206,7 @@ export class QuerySnapshot<T = firestore.DocumentData>
210206
doc.key,
211207
doc,
212208
new SnapshotMetadata(hasPendingWrites, fromCache),
213-
this.query._converter
209+
this.query.converter
214210
);
215211
}
216212
}

packages/firestore/lite-types/index.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,11 @@ export type SetOptions =
202202
export class DocumentReference<T = DocumentData> {
203203
private constructor();
204204
readonly type: 'document';
205-
readonly id: string;
206205
readonly firestore: FirebaseFirestore;
206+
readonly converter: FirestoreDataConverter<T> | null;
207207
readonly path: string;
208+
readonly id: string;
209+
208210
withConverter<U>(converter: FirestoreDataConverter<U>): DocumentReference<U>;
209211
}
210212

@@ -238,6 +240,7 @@ export class Query<T = DocumentData> {
238240
protected constructor();
239241
readonly type: 'query' | 'collection';
240242
readonly firestore: FirebaseFirestore;
243+
readonly converter: FirestoreDataConverter<T> | null;
241244

242245
withConverter<U>(converter: FirestoreDataConverter<U>): Query<U>;
243246
}

packages/firestore/lite/src/api/reference.ts

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ export class DocumentReference<T = firestore.DocumentData>
9292

9393
constructor(
9494
readonly firestore: Firestore,
95-
readonly _path: ResourcePath,
96-
readonly _converter: firestore.FirestoreDataConverter<T> | null
95+
readonly converter: firestore.FirestoreDataConverter<T> | null,
96+
readonly _path: ResourcePath
9797
) {
98-
super(firestore._databaseId, new DocumentKey(_path), _converter);
98+
super(firestore._databaseId, new DocumentKey(_path), converter);
9999
}
100100

101101
get id(): string {
@@ -109,7 +109,7 @@ export class DocumentReference<T = firestore.DocumentData>
109109
withConverter<U>(
110110
converter: firestore.FirestoreDataConverter<U>
111111
): firestore.DocumentReference<U> {
112-
return new DocumentReference<U>(this.firestore, this._path, converter);
112+
return new DocumentReference<U>(this.firestore, converter, this._path);
113113
}
114114
}
115115

@@ -119,14 +119,14 @@ export class Query<T = firestore.DocumentData> implements firestore.Query<T> {
119119
// This is the lite version of the Query class in the main SDK.
120120
constructor(
121121
readonly firestore: Firestore,
122-
readonly _query: InternalQuery,
123-
readonly _converter: firestore.FirestoreDataConverter<T> | null
122+
readonly converter: firestore.FirestoreDataConverter<T> | null,
123+
readonly _query: InternalQuery
124124
) {}
125125

126126
withConverter<U>(
127127
converter: firestore.FirestoreDataConverter<U>
128128
): firestore.Query<U> {
129-
return new Query<U>(this.firestore, this._query, converter);
129+
return new Query<U>(this.firestore, converter, this._query);
130130
}
131131
}
132132

@@ -175,8 +175,8 @@ class QueryFilterConstraint extends QueryConstraint {
175175
);
176176
return new Query(
177177
query.firestore,
178-
queryWithAddedFilter(query._query, filter),
179-
query._converter
178+
query.converter,
179+
queryWithAddedFilter(query._query, filter)
180180
);
181181
}
182182
}
@@ -207,8 +207,8 @@ class QueryOrderByConstraint extends QueryConstraint {
207207
const orderBy = newQueryOrderBy(query._query, this._field, this._direction);
208208
return new Query(
209209
query.firestore,
210-
queryWithAddedOrderBy(query._query, orderBy),
211-
query._converter
210+
query.converter,
211+
queryWithAddedOrderBy(query._query, orderBy)
212212
);
213213
}
214214
}
@@ -236,8 +236,8 @@ class QueryLimitConstraint extends QueryConstraint {
236236
apply<T>(query: Query<T>): Query<T> {
237237
return new Query(
238238
query.firestore,
239-
queryWithLimit(query._query, this._limit, this._limitType),
240-
query._converter
239+
query.converter,
240+
queryWithLimit(query._query, this._limit, this._limitType)
241241
);
242242
}
243243
}
@@ -272,8 +272,8 @@ class QueryStartAtConstraint extends QueryConstraint {
272272
);
273273
return new Query(
274274
query.firestore,
275-
queryWithStartAt(query._query, bound),
276-
query._converter
275+
query.converter,
276+
queryWithStartAt(query._query, bound)
277277
);
278278
}
279279
}
@@ -314,8 +314,8 @@ class QueryEndAtConstraint extends QueryConstraint {
314314
);
315315
return new Query(
316316
query.firestore,
317-
queryWithEndAt(query._query, bound),
318-
query._converter
317+
query.converter,
318+
queryWithEndAt(query._query, bound)
319319
);
320320
}
321321
}
@@ -368,9 +368,9 @@ export class CollectionReference<T = firestore.DocumentData> extends Query<T>
368368
constructor(
369369
readonly firestore: Firestore,
370370
readonly _path: ResourcePath,
371-
readonly _converter: firestore.FirestoreDataConverter<T> | null
371+
converter: firestore.FirestoreDataConverter<T> | null
372372
) {
373-
super(firestore, newQueryForPath(_path), _converter);
373+
super(firestore, converter, newQueryForPath(_path));
374374
}
375375

376376
get id(): string {
@@ -454,8 +454,8 @@ export function collectionGroup(
454454

455455
return new Query(
456456
firestoreClient,
457-
newQueryForCollectionGroup(collectionId),
458-
/* converter= */ null
457+
/* converter= */ null,
458+
newQueryForCollectionGroup(collectionId)
459459
);
460460
}
461461

@@ -488,7 +488,7 @@ export function doc<T>(
488488
if (parent instanceof Firestore) {
489489
const absolutePath = ResourcePath.fromString(relativePath!);
490490
validateDocumentPath(absolutePath);
491-
return new DocumentReference(parent, absolutePath, /* converter= */ null);
491+
return new DocumentReference(parent, /* converter= */ null, absolutePath);
492492
} else {
493493
if (
494494
!(parent instanceof DocumentReference) &&
@@ -506,8 +506,8 @@ export function doc<T>(
506506
validateDocumentPath(absolutePath);
507507
return new DocumentReference(
508508
parent.firestore,
509-
absolutePath,
510-
parent instanceof CollectionReference ? parent._converter : null
509+
parent instanceof CollectionReference ? parent.converter : null,
510+
absolutePath
511511
);
512512
}
513513
}
@@ -526,11 +526,7 @@ export function parent<T>(
526526
if (parentPath.isEmpty()) {
527527
return null;
528528
} else {
529-
return new DocumentReference(
530-
child.firestore,
531-
parentPath,
532-
/* converter= */ null
533-
);
529+
return new DocumentReference(child.firestore, null, parentPath);
534530
}
535531
} else {
536532
const doc = cast<DocumentReference<T>>(child, DocumentReference);
@@ -573,7 +569,7 @@ export function getQuery<T>(
573569
internalQuery.firestore,
574570
doc.key,
575571
doc,
576-
internalQuery._converter
572+
internalQuery.converter
577573
)
578574
);
579575

@@ -700,7 +696,7 @@ export function addDoc<T>(
700696
const collRef = cast<CollectionReference<T>>(reference, CollectionReference);
701697
const docRef = doc(collRef);
702698

703-
const convertedValue = applyFirestoreDataConverter(collRef._converter, data);
699+
const convertedValue = applyFirestoreDataConverter(collRef.converter, data);
704700

705701
const dataReader = newUserDataReader(collRef.firestore);
706702
const parsed = parseSetData(
@@ -735,7 +731,7 @@ export function refEqual<T>(
735731
return (
736732
left.firestore === right.firestore &&
737733
left.path === right.path &&
738-
left._converter === right._converter
734+
left.converter === right.converter
739735
);
740736
}
741737
return false;
@@ -749,7 +745,7 @@ export function queryEqual<T>(
749745
return (
750746
left.firestore === right.firestore &&
751747
queryEquals(left._query, right._query) &&
752-
left._converter === right._converter
748+
left.converter === right.converter
753749
);
754750
}
755751
return false;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ export class DocumentSnapshot<T = firestore.DocumentData>
5252
get ref(): firestore.DocumentReference<T> {
5353
return new DocumentReference<T>(
5454
this._firestore,
55-
this._key.path,
56-
this._converter
55+
this._converter,
56+
this._key.path
5757
);
5858
}
5959

@@ -82,8 +82,8 @@ export class DocumentSnapshot<T = firestore.DocumentData>
8282
key =>
8383
new DocumentReference(
8484
this._firestore,
85-
key.path,
86-
/* converter= */ null
85+
/* converter= */ null,
86+
key.path
8787
)
8888
);
8989
return userDataWriter.convertValue(this._document.toProto()) as T;
@@ -101,7 +101,7 @@ export class DocumentSnapshot<T = firestore.DocumentData>
101101
/* timestampsInSnapshots= */ true,
102102
/* serverTimestampBehavior=*/ 'none',
103103
key =>
104-
new DocumentReference(this._firestore, key.path, this._converter)
104+
new DocumentReference(this._firestore, this._converter, key.path)
105105
);
106106
return userDataWriter.convertValue(value);
107107
}

0 commit comments

Comments
 (0)