-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
query_snapshot.dart
99 lines (82 loc) 路 2.87 KB
/
query_snapshot.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2020, the Chromium project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
part of cloud_firestore;
/// Contains the results of a query.
/// It can contain zero or more [DocumentSnapshot] objects.
abstract class QuerySnapshot<T extends Object?> {
/// Gets a list of all the documents included in this snapshot.
List<QueryDocumentSnapshot<T>> get docs;
/// An array of the documents that changed since the last snapshot. If this
/// is the first snapshot, all documents will be in the list as Added changes.
List<DocumentChange<T>> get docChanges;
/// Returns the [SnapshotMetadata] for this snapshot.
SnapshotMetadata get metadata;
/// Returns the size (number of documents) of this snapshot.
int get size;
}
/// Contains the results of a query.
/// It can contain zero or more [DocumentSnapshot] objects.
class _JsonQuerySnapshot implements QuerySnapshot<Map<String, dynamic>> {
_JsonQuerySnapshot(this._firestore, this._delegate) {
QuerySnapshotPlatform.verify(_delegate);
}
final FirebaseFirestore _firestore;
final QuerySnapshotPlatform _delegate;
@override
List<QueryDocumentSnapshot<Map<String, dynamic>>> get docs => _delegate.docs
.map(
(documentDelegate) =>
_JsonQueryDocumentSnapshot(_firestore, documentDelegate),
)
.toList();
@override
List<DocumentChange<Map<String, dynamic>>> get docChanges {
return _delegate.docChanges.map((documentDelegate) {
return _JsonDocumentChange(_firestore, documentDelegate);
}).toList();
}
@override
SnapshotMetadata get metadata => SnapshotMetadata._(_delegate.metadata);
@override
int get size => _delegate.size;
}
/// Contains the results of a query.
/// It can contain zero or more [DocumentSnapshot] objects.
class _WithConverterQuerySnapshot<T extends Object?>
implements QuerySnapshot<T> {
_WithConverterQuerySnapshot(
this._originalQuerySnapshot,
this._fromFirestore,
this._toFirestore,
);
final QuerySnapshot<Map<String, dynamic>> _originalQuerySnapshot;
final FromFirestore<T> _fromFirestore;
final ToFirestore<T> _toFirestore;
@override
List<QueryDocumentSnapshot<T>> get docs {
return [
for (final snapshot in _originalQuerySnapshot.docs)
_WithConverterQueryDocumentSnapshot<T>(
snapshot,
_fromFirestore,
_toFirestore,
),
];
}
@override
List<DocumentChange<T>> get docChanges {
return [
for (final change in _originalQuerySnapshot.docChanges)
_WithConverterDocumentChange<T>(
change,
_fromFirestore,
_toFirestore,
),
];
}
@override
SnapshotMetadata get metadata => _originalQuerySnapshot.metadata;
@override
int get size => _originalQuerySnapshot.size;
}