Skip to content

Commit 6ff9a05

Browse files
committed
fix typing
1 parent 2d7a246 commit 6ff9a05

File tree

3 files changed

+90
-9
lines changed

3 files changed

+90
-9
lines changed

packages/cloud_firestore/cloud_firestore_platform_interface/lib/src/method_channel/method_channel_vector_query.dart

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:cloud_firestore_platform_interface/src/method_channel/method_channel_query_snapshot.dart';
5+
import 'package:cloud_firestore_platform_interface/src/method_channel/method_channel_vector_query_snapshot.dart';
66
import 'package:cloud_firestore_platform_interface/src/method_channel/utils/exception.dart';
7+
import 'package:cloud_firestore_platform_interface/src/platform_interface/platform_interface_vector_query_snapshot.dart';
78

89
import '../../cloud_firestore_platform_interface.dart';
910
import 'method_channel_firestore.dart';
@@ -35,7 +36,7 @@ class MethodChannelVectorQuery extends VectorQueryPlatform {
3536
final VectorQueryOptions _options;
3637

3738
@override
38-
Future<MethodChannelQuerySnapshot> get({
39+
Future<VectorQuerySnapshotPlatform> get({
3940
required VectorSource source,
4041
}) async {
4142
try {
@@ -52,7 +53,7 @@ class MethodChannelVectorQuery extends VectorQueryPlatform {
5253
_distanceMeasure,
5354
);
5455

55-
return MethodChannelQuerySnapshot(firestore, result);
56+
return MethodChannelVectorQuerySnapshot(firestore, result);
5657
} catch (e, stack) {
5758
convertPlatformException(e, stack);
5859
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// ignore_for_file: require_trailing_commas
2+
// Copyright 2017, the Chromium project authors. Please see the AUTHORS file
3+
// for details. All rights reserved. Use of this source code is governed by a
4+
// BSD-style license that can be found in the LICENSE file.
5+
6+
import 'package:cloud_firestore_platform_interface/cloud_firestore_platform_interface.dart';
7+
import 'package:cloud_firestore_platform_interface/src/platform_interface/platform_interface_vector_query_snapshot.dart';
8+
import 'package:collection/collection.dart';
9+
10+
import 'method_channel_document_change.dart';
11+
12+
/// An implementation of [QuerySnapshotPlatform] that uses [MethodChannel] to
13+
/// communicate with Firebase plugins.
14+
class MethodChannelVectorQuerySnapshot extends VectorQuerySnapshotPlatform {
15+
/// Creates a [MethodChannelVectorQuerySnapshot] from the given [data]
16+
MethodChannelVectorQuerySnapshot(
17+
FirebaseFirestorePlatform firestore, PigeonQuerySnapshot data)
18+
: super(
19+
data.documents
20+
.map<DocumentSnapshotPlatform?>((document) {
21+
if (document == null) {
22+
return null;
23+
}
24+
return DocumentSnapshotPlatform(
25+
firestore,
26+
document.path,
27+
document.data,
28+
document.metadata,
29+
);
30+
})
31+
.whereNotNull()
32+
.toList(),
33+
data.documentChanges
34+
.map((documentChange) {
35+
if (documentChange == null) {
36+
return null;
37+
}
38+
return MethodChannelDocumentChange(
39+
firestore,
40+
documentChange,
41+
);
42+
})
43+
.whereNotNull()
44+
.toList(),
45+
SnapshotMetadataPlatform(
46+
data.metadata.hasPendingWrites,
47+
data.metadata.isFromCache,
48+
));
49+
}

packages/cloud_firestore/cloud_firestore_platform_interface/lib/src/platform_interface/platform_interface_vector_query_snapshot.dart

+37-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,43 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:cloud_firestore_platform_interface/cloud_firestore_platform_interface.dart';
6+
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
67

7-
/// [VectorQuerySnapshotPlatform] represents a response to an [VectorQueryPlatform] request.
8-
class VectorQuerySnapshotPlatform extends QuerySnapshotPlatform {
8+
/// A interface that contains zero or more [DocumentSnapshotPlatform] objects
9+
/// representing the results of a query.
10+
///
11+
/// The documents can be accessed as a list by calling [docs()] and the number of documents
12+
/// can be determined by calling [size()].
13+
class VectorQuerySnapshotPlatform extends PlatformInterface {
14+
/// Create a [VectorQuerySnapshotPlatform]
915
VectorQuerySnapshotPlatform(
10-
super.docs,
11-
super.docChanges,
12-
super.metadata,
13-
) : super();
16+
this.docs,
17+
this.docChanges,
18+
this.metadata,
19+
) : super(token: _token);
20+
21+
static final Object _token = Object();
22+
23+
/// Throws an [AssertionError] if [instance] does not extend
24+
/// [VectorQuerySnapshotPlatform].
25+
///
26+
/// This is used by the app-facing [QuerySnapshot] to ensure that
27+
/// the object in which it's going to delegate calls has been
28+
/// constructed properly.
29+
static void verify(VectorQuerySnapshotPlatform instance) {
30+
PlatformInterface.verify(instance, _token);
31+
}
32+
33+
/// Gets a list of all the documents included in this [VectorQuerySnapshotPlatform]
34+
final List<DocumentSnapshotPlatform> docs;
35+
36+
/// An array of the documents that changed since the last snapshot. If this
37+
/// is the first snapshot, all documents will be in the list as Added changes.
38+
final List<DocumentChangePlatform> docChanges;
39+
40+
/// Metadata for the document
41+
final SnapshotMetadataPlatform metadata;
42+
43+
/// The number of documents in this [VectorQuerySnapshotPlatform].
44+
int get size => docs.length;
1445
}

0 commit comments

Comments
 (0)