performDocumentRead method

  1. @override
Stream<Snapshot> performDocumentRead (
  1. DocumentReadRequest request
)
override

Implementation

@override
Stream<Snapshot> performDocumentRead(DocumentReadRequest request) async* {
  final document = request.document;
  final collection = document.parent;
  final collectionId = _validateCollectionId(collection.collectionId);
  final documentId = _validateDocumentId(document.documentId);

  //
  // Dispatch request
  //
  final apiResponse = await _apiRequest(
    method: 'GET',
    path: '/1/indexes/$collectionId/$documentId',
  );

  if (apiResponse.statusCode == HttpStatus.notFound) {
    yield (Snapshot.notFound(document));
    return;
  }

  //
  // Handle error
  //
  final error = apiResponse.error;
  if (error != null) {
    throw error;
  }

  // Create data
  final data = <String, Object>{};
  data.addAll(apiResponse.json);
  data.remove('objectID');

  // Yield
  yield (Snapshot(
    vendorData: apiResponse.json,
    document: document,
    data: data,
  ));
}