Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions packages/cloud_firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.12.8+1

* Add `metadata` to `QuerySnapshot`.

## 0.12.8

* Updated how document ids are generated to more closely match native implementations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ private Map<String, Object> parseQuerySnapshot(QuerySnapshot querySnapshot) {
}
data.put("documentChanges", documentChanges);

Map<String, Object> metadata = new HashMap<>();
metadata.put("hasPendingWrites", querySnapshot.getMetadata().hasPendingWrites());
metadata.put("isFromCache", querySnapshot.getMetadata().isFromCache());
data.put("metadata", metadata);

return data;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void main() {
.where('message', isEqualTo: 'Hello world!')
.limit(1);
final QuerySnapshot querySnapshot = await query.getDocuments();
expect(querySnapshot.metadata, isNotNull);
expect(querySnapshot.documents.first['message'], 'Hello world!');
final DocumentReference firstDoc =
querySnapshot.documents.first.reference;
Expand All @@ -70,6 +71,7 @@ void main() {
.limit(1);
final QuerySnapshot querySnapshot = await query.getDocuments();
expect(querySnapshot.documents.first['stars'], 5);
expect(querySnapshot.metadata, isNotNull);
});

test('increment', () async {
Expand Down
4 changes: 4 additions & 0 deletions packages/cloud_firestore/ios/Classes/CloudFirestorePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ static FIRFirestoreSource getSource(NSDictionary *arguments) {
@"documentChanges" : documentChanges,
@"documents" : documents,
@"metadatas" : metadatas,
@"metadata" : @{
@"hasPendingWrites" : @(snapshot.metadata.hasPendingWrites),
@"isFromCache" : @(snapshot.metadata.isFromCache),
}
};
}

Expand Down
8 changes: 7 additions & 1 deletion packages/cloud_firestore/lib/src/query_snapshot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ class QuerySnapshot {
data['documentChanges'][index],
_firestore,
);
});
}),
metadata = SnapshotMetadata._(
data['metadata']['hasPendingWrites'],
data['metadata']['isFromCache'],
);

/// Gets a list of all the documents included in this snapshot
final List<DocumentSnapshot> documents;
Expand All @@ -34,5 +38,7 @@ class QuerySnapshot {
/// is the first snapshot, all documents will be in the list as Added changes.
final List<DocumentChange> documentChanges;

final SnapshotMetadata metadata;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should be able to add unit testing and a basic integration test for this, right? Even just asserting that hasPendingWrites and isFromCache aren't null would be better than nothing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, I checked that the metadata property of the QuerySnapshot was not null.


final Firestore _firestore;
}
2 changes: 1 addition & 1 deletion packages/cloud_firestore/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for Cloud Firestore, a cloud-hosted, noSQL database
live synchronization and offline support on Android and iOS.
author: Flutter Team <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/cloud_firestore
version: 0.12.8
version: 0.12.8+1

flutter:
plugin:
Expand Down
10 changes: 10 additions & 0 deletions packages/cloud_firestore/test/cloud_firestore_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ void main() {
'paths': <String>["${methodCall.arguments['path']}/0"],
'documents': <dynamic>[kMockDocumentSnapshotData],
'metadatas': <Map<String, dynamic>>[kMockSnapshotMetadata],
'metadata': kMockSnapshotMetadata,
'documentChanges': <dynamic>[
<String, dynamic>{
'oldIndex': -1,
Expand Down Expand Up @@ -105,6 +106,7 @@ void main() {
'paths': <String>["${methodCall.arguments['path']}/0"],
'documents': <dynamic>[kMockDocumentSnapshotData],
'metadatas': <Map<String, dynamic>>[kMockSnapshotMetadata],
'metadata': kMockSnapshotMetadata,
'documentChanges': <dynamic>[
<String, dynamic>{
'oldIndex': -1,
Expand Down Expand Up @@ -614,6 +616,10 @@ void main() {
test('getDocumentsFromCollection', () async {
QuerySnapshot snapshot =
await collectionReference.getDocuments(source: Source.server);
expect(snapshot.metadata.hasPendingWrites,
equals(kMockSnapshotMetadata['hasPendingWrites']));
expect(snapshot.metadata.isFromCache,
equals(kMockSnapshotMetadata['isFromCache']));
DocumentSnapshot document = snapshot.documents.first;
expect(document.documentID, equals('0'));
expect(document.reference.path, equals('foo/0'));
Expand Down Expand Up @@ -781,6 +787,10 @@ void main() {
});
test('getDocumentsFromCollectionGroup', () async {
QuerySnapshot snapshot = await collectionGroupQuery.getDocuments();
expect(snapshot.metadata.hasPendingWrites,
equals(kMockSnapshotMetadata['hasPendingWrites']));
expect(snapshot.metadata.isFromCache,
equals(kMockSnapshotMetadata['isFromCache']));
DocumentSnapshot document = snapshot.documents.first;
expect(document.documentID, equals('0'));
expect(document.reference.path, equals('bar/0'));
Expand Down