Skip to content

Update Lite tests with Query API v2 #3446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions packages/firestore/exp-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export interface FirestoreDataConverter<T> {
toFirestore(modelObject: Partial<T>, options: SetOptions): DocumentData;
fromFirestore(
snapshot: QueryDocumentSnapshot<DocumentData>,
options: SnapshotOptions
options?: SnapshotOptions
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to make this interface compatible with the FirestoreDataConverter in lite.

): T;
}

Expand Down Expand Up @@ -242,9 +242,11 @@ export type SetOptions =
export class DocumentReference<T = DocumentData> {
private constructor();
readonly type: 'document';
readonly id: string;
readonly firestore: FirebaseFirestore;
readonly converter: FirestoreDataConverter<T> | null;
readonly path: string;
readonly id: string;

withConverter<U>(converter: FirestoreDataConverter<U>): DocumentReference<U>;
}

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

withConverter<U>(converter: FirestoreDataConverter<U>): Query<U>;
}
Expand Down
14 changes: 5 additions & 9 deletions packages/firestore/exp/src/api/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ import {
} from '../../../lite/src/api/snapshot';
import { Firestore } from './database';
import { cast } from '../../../lite/src/api/util';
import {
DocumentReference,
Query,
queryEqual
} from '../../../lite/src/api/reference';
import { DocumentReference, Query, queryEqual } from '../../../lite';
import {
changesFromSnapshot,
SnapshotMetadata
Expand Down Expand Up @@ -85,8 +81,8 @@ export class DocumentSnapshot<T = firestore.DocumentData>
key =>
new DocumentReference(
this._firestore,
key.path,
/* converter= */ null
/* converter= */ null,
key.path
)
);
return userDataWriter.convertValue(this._document.toProto()) as T;
Expand All @@ -107,7 +103,7 @@ export class DocumentSnapshot<T = firestore.DocumentData>
/* timestampsInSnapshots= */ true,
options.serverTimestamps || DEFAULT_SERVER_TIMESTAMP_BEHAVIOR,
key =>
new DocumentReference(this._firestore, key.path, this._converter)
new DocumentReference(this._firestore, this._converter, key.path)
);
return userDataWriter.convertValue(value);
}
Expand Down Expand Up @@ -210,7 +206,7 @@ export class QuerySnapshot<T = firestore.DocumentData>
doc.key,
doc,
new SnapshotMetadata(hasPendingWrites, fromCache),
this.query._converter
this.query.converter
);
}
}
Expand Down
5 changes: 4 additions & 1 deletion packages/firestore/lite-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,11 @@ export type SetOptions =
export class DocumentReference<T = DocumentData> {
private constructor();
readonly type: 'document';
readonly id: string;
readonly firestore: FirebaseFirestore;
readonly converter: FirestoreDataConverter<T> | null;
readonly path: string;
readonly id: string;

withConverter<U>(converter: FirestoreDataConverter<U>): DocumentReference<U>;
}

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

withConverter<U>(converter: FirestoreDataConverter<U>): Query<U>;
}
Expand Down
62 changes: 29 additions & 33 deletions packages/firestore/lite/src/api/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ export class DocumentReference<T = firestore.DocumentData>

constructor(
readonly firestore: Firestore,
readonly _path: ResourcePath,
readonly _converter: firestore.FirestoreDataConverter<T> | null
readonly converter: firestore.FirestoreDataConverter<T> | null,
readonly _path: ResourcePath
) {
super(firestore._databaseId, new DocumentKey(_path), _converter);
super(firestore._databaseId, new DocumentKey(_path), converter);
}

get id(): string {
Expand All @@ -109,7 +109,7 @@ export class DocumentReference<T = firestore.DocumentData>
withConverter<U>(
converter: firestore.FirestoreDataConverter<U>
): firestore.DocumentReference<U> {
return new DocumentReference<U>(this.firestore, this._path, converter);
return new DocumentReference<U>(this.firestore, converter, this._path);
}
}

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

withConverter<U>(
converter: firestore.FirestoreDataConverter<U>
): firestore.Query<U> {
return new Query<U>(this.firestore, this._query, converter);
return new Query<U>(this.firestore, converter, this._query);
}
}

Expand Down Expand Up @@ -175,8 +175,8 @@ class QueryFilterConstraint extends QueryConstraint {
);
return new Query(
query.firestore,
queryWithAddedFilter(query._query, filter),
query._converter
query.converter,
queryWithAddedFilter(query._query, filter)
);
}
}
Expand Down Expand Up @@ -207,8 +207,8 @@ class QueryOrderByConstraint extends QueryConstraint {
const orderBy = newQueryOrderBy(query._query, this._field, this._direction);
return new Query(
query.firestore,
queryWithAddedOrderBy(query._query, orderBy),
query._converter
query.converter,
queryWithAddedOrderBy(query._query, orderBy)
);
}
}
Expand Down Expand Up @@ -236,8 +236,8 @@ class QueryLimitConstraint extends QueryConstraint {
apply<T>(query: Query<T>): Query<T> {
return new Query(
query.firestore,
queryWithLimit(query._query, this._limit, this._limitType),
query._converter
query.converter,
queryWithLimit(query._query, this._limit, this._limitType)
);
}
}
Expand Down Expand Up @@ -272,8 +272,8 @@ class QueryStartAtConstraint extends QueryConstraint {
);
return new Query(
query.firestore,
queryWithStartAt(query._query, bound),
query._converter
query.converter,
queryWithStartAt(query._query, bound)
);
}
}
Expand Down Expand Up @@ -314,8 +314,8 @@ class QueryEndAtConstraint extends QueryConstraint {
);
return new Query(
query.firestore,
queryWithEndAt(query._query, bound),
query._converter
query.converter,
queryWithEndAt(query._query, bound)
);
}
}
Expand Down Expand Up @@ -368,9 +368,9 @@ export class CollectionReference<T = firestore.DocumentData> extends Query<T>
constructor(
readonly firestore: Firestore,
readonly _path: ResourcePath,
readonly _converter: firestore.FirestoreDataConverter<T> | null
converter: firestore.FirestoreDataConverter<T> | null
) {
super(firestore, newQueryForPath(_path), _converter);
super(firestore, converter, newQueryForPath(_path));
}

get id(): string {
Expand Down Expand Up @@ -454,8 +454,8 @@ export function collectionGroup(

return new Query(
firestoreClient,
newQueryForCollectionGroup(collectionId),
/* converter= */ null
/* converter= */ null,
newQueryForCollectionGroup(collectionId)
);
}

Expand Down Expand Up @@ -488,7 +488,7 @@ export function doc<T>(
if (parent instanceof Firestore) {
const absolutePath = ResourcePath.fromString(relativePath!);
validateDocumentPath(absolutePath);
return new DocumentReference(parent, absolutePath, /* converter= */ null);
return new DocumentReference(parent, /* converter= */ null, absolutePath);
} else {
if (
!(parent instanceof DocumentReference) &&
Expand All @@ -506,8 +506,8 @@ export function doc<T>(
validateDocumentPath(absolutePath);
return new DocumentReference(
parent.firestore,
absolutePath,
parent instanceof CollectionReference ? parent._converter : null
parent instanceof CollectionReference ? parent.converter : null,
absolutePath
);
}
}
Expand All @@ -526,11 +526,7 @@ export function parent<T>(
if (parentPath.isEmpty()) {
return null;
} else {
return new DocumentReference(
child.firestore,
parentPath,
/* converter= */ null
);
return new DocumentReference(child.firestore, null, parentPath);
}
} else {
const doc = cast<DocumentReference<T>>(child, DocumentReference);
Expand Down Expand Up @@ -573,7 +569,7 @@ export function getQuery<T>(
internalQuery.firestore,
doc.key,
doc,
internalQuery._converter
internalQuery.converter
)
);

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

const convertedValue = applyFirestoreDataConverter(collRef._converter, data);
const convertedValue = applyFirestoreDataConverter(collRef.converter, data);

const dataReader = newUserDataReader(collRef.firestore);
const parsed = parseSetData(
Expand Down Expand Up @@ -735,7 +731,7 @@ export function refEqual<T>(
return (
left.firestore === right.firestore &&
left.path === right.path &&
left._converter === right._converter
left.converter === right.converter
);
}
return false;
Expand All @@ -749,7 +745,7 @@ export function queryEqual<T>(
return (
left.firestore === right.firestore &&
queryEquals(left._query, right._query) &&
left._converter === right._converter
left.converter === right.converter
);
}
return false;
Expand Down
10 changes: 5 additions & 5 deletions packages/firestore/lite/src/api/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export class DocumentSnapshot<T = firestore.DocumentData>
get ref(): firestore.DocumentReference<T> {
return new DocumentReference<T>(
this._firestore,
this._key.path,
this._converter
this._converter,
this._key.path
);
}

Expand Down Expand Up @@ -82,8 +82,8 @@ export class DocumentSnapshot<T = firestore.DocumentData>
key =>
new DocumentReference(
this._firestore,
key.path,
/* converter= */ null
/* converter= */ null,
key.path
)
);
return userDataWriter.convertValue(this._document.toProto()) as T;
Expand All @@ -101,7 +101,7 @@ export class DocumentSnapshot<T = firestore.DocumentData>
/* timestampsInSnapshots= */ true,
/* serverTimestampBehavior=*/ 'none',
key =>
new DocumentReference(this._firestore, key.path, this._converter)
new DocumentReference(this._firestore, this._converter, key.path)
);
return userDataWriter.convertValue(value);
}
Expand Down
Loading