documents method
Reads the given documents: slash-separated paths (String) or
DocumentReferences.
Implementation
Pipeline documents(
List<Object> documents, {
Map<String, Object?>? rawOptions,
}) {
if (documents.isEmpty) {
throw ArgumentError('documents() needs at least one document.');
}
final List<String> paths = <String>[];
for (final Object document in documents) {
final String path;
if (document is DocumentReference) {
_validateDatabase(
document.firestore.modelDatabaseId,
'DocumentReference',
);
path = document.path;
} else if (document is String) {
path = document;
} else {
throw ArgumentError(
'documents() takes paths and DocumentReferences, but got: '
'$document',
);
}
final ResourcePath resourcePath = _parsePath(path, 'documents');
if (resourcePath.length.isOdd) {
throw ArgumentError(
'Invalid document path ($path). A document path must have an even '
'number of segments.',
);
}
if (paths.contains(resourcePath.canonicalString)) {
// As the JS SDK's DocumentsSource.
throw ArgumentError(
'Duplicate document paths are not allowed in documents(): $path',
);
}
paths.add(resourcePath.canonicalString);
}
return _start(
Stage(
'documents',
args: <pb.Value Function(PipelineEncoder)>[
for (final String path in paths) (_) => relativeReferenceValue(path),
],
rawOptions: rawOptions,
),
);
}