@@ -21,7 +21,6 @@ import com.google.common.collect.ImmutableList
2121import com.google.firebase.Timestamp
2222import com.google.firebase.firestore.model.DocumentKey
2323import com.google.firebase.firestore.model.Values
24- import com.google.firebase.firestore.pipeline.AbstractOptions
2524import com.google.firebase.firestore.pipeline.AddFieldsStage
2625import com.google.firebase.firestore.pipeline.AggregateFunction
2726import com.google.firebase.firestore.pipeline.AggregateStage
@@ -39,7 +38,6 @@ import com.google.firebase.firestore.pipeline.FindNearestStage
3938import com.google.firebase.firestore.pipeline.FunctionExpr
4039import com.google.firebase.firestore.pipeline.GenericArg
4140import com.google.firebase.firestore.pipeline.GenericStage
42- import com.google.firebase.firestore.pipeline.InternalOptions
4341import com.google.firebase.firestore.pipeline.LimitStage
4442import com.google.firebase.firestore.pipeline.OffsetStage
4543import com.google.firebase.firestore.pipeline.Ordering
@@ -54,7 +52,6 @@ import com.google.firebase.firestore.pipeline.Stage
5452import com.google.firebase.firestore.pipeline.UnionStage
5553import com.google.firebase.firestore.pipeline.UnnestStage
5654import com.google.firebase.firestore.pipeline.WhereStage
57- import com.google.firebase.firestore.util.Preconditions
5855import com.google.firestore.v1.ExecutePipelineRequest
5956import com.google.firestore.v1.StructuredPipeline
6057import com.google.firestore.v1.Value
@@ -614,7 +611,7 @@ class PipelineSource internal constructor(private val firestore: FirebaseFiresto
614611 * Convert the given Query into an equivalent Pipeline.
615612 *
616613 * @param query A Query to be converted into a Pipeline.
617- * @return Pipeline that is equivalent to [query]
614+ * @return A new [ Pipeline] object that is equivalent to [query]
618615 * @throws [IllegalArgumentException] Thrown if the [query] provided targets a different project
619616 * or database than the pipeline.
620617 */
@@ -629,7 +626,7 @@ class PipelineSource internal constructor(private val firestore: FirebaseFiresto
629626 * Convert the given Aggregate Query into an equivalent Pipeline.
630627 *
631628 * @param aggregateQuery An Aggregate Query to be converted into a Pipeline.
632- * @return Pipeline that is equivalent to [aggregateQuery]
629+ * @return A new [ Pipeline] object that is equivalent to [aggregateQuery]
633630 * @throws [IllegalArgumentException] Thrown if the [aggregateQuery] provided targets a different
634631 * project or database than the pipeline.
635632 */
@@ -646,46 +643,50 @@ class PipelineSource internal constructor(private val firestore: FirebaseFiresto
646643 * Set the pipeline's source to the collection specified by the given path.
647644 *
648645 * @param path A path to a collection that will be the source of this pipeline.
649- * @return Pipeline with documents from target collection.
646+ * @return A new [ Pipeline] object with documents from target collection.
650647 */
651- fun collection (path : String ): Pipeline =
652- // Validate path by converting to CollectionReference
653- collection(firestore.collection(path))
648+ fun collection (path : String ): Pipeline = collection(CollectionSource .of(path))
654649
655650 /* *
656- * Set the pipeline's source to the collection specified by the given CollectionReference.
651+ * Set the pipeline's source to the collection specified by the given [ CollectionReference] .
657652 *
658- * @param ref A CollectionReference for a collection that will be the source of this pipeline.
659- * @return Pipeline with documents from target collection.
653+ * @param ref A [ CollectionReference] for a collection that will be the source of this pipeline.
654+ * @return A new [ Pipeline] object with documents from target collection.
660655 * @throws [IllegalArgumentException] Thrown if the [ref] provided targets a different project or
661656 * database than the pipeline.
662657 */
663- fun collection (ref : CollectionReference ): Pipeline {
664- if (ref.firestore.databaseId != firestore.databaseId) {
665- throw IllegalArgumentException (
666- " Provided collection reference is from a different Firestore instance."
667- )
658+ fun collection (ref : CollectionReference ): Pipeline = collection(CollectionSource .of(ref))
659+
660+ /* *
661+ * Set the pipeline's source to the collection specified by CollectionSource.
662+ *
663+ * @param stage A [CollectionSource] that will be the source of this pipeline.
664+ * @return Pipeline with documents from target collection.
665+ * @throws [IllegalArgumentException] Thrown if the [stage] provided targets a different project
666+ * or database than the pipeline.
667+ */
668+ fun collection (stage : CollectionSource ): Pipeline {
669+ if (stage.firestore != null && stage.firestore.databaseId != firestore.databaseId) {
670+ throw IllegalArgumentException (" Provided collection is from a different Firestore instance." )
668671 }
669- return Pipeline (firestore, firestore.userDataReader, CollectionSource (ref.path) )
672+ return Pipeline (firestore, firestore.userDataReader, stage )
670673 }
671674
672675 /* *
673676 * Set the pipeline's source to the collection group with the given id.
674677 *
675- * @param collectionid The id of a collection group that will be the source of this pipeline.
678+ * @param collectionId The id of a collection group that will be the source of this pipeline.
676679 */
677- fun collectionGroup (collectionId : String ): Pipeline {
678- Preconditions .checkNotNull(collectionId, " Provided collection ID must not be null." )
679- require(! collectionId.contains(" /" )) {
680- " Invalid collectionId '$collectionId '. Collection IDs must not contain '/'."
681- }
682- return Pipeline (firestore, firestore.userDataReader, CollectionGroupSource (collectionId))
683- }
680+ fun collectionGroup (collectionId : String ): Pipeline =
681+ pipeline(CollectionGroupSource .of((collectionId)))
682+
683+ fun pipeline (stage : CollectionGroupSource ): Pipeline =
684+ Pipeline (firestore, firestore.userDataReader, stage)
684685
685686 /* *
686687 * Set the pipeline's source to be all documents in this database.
687688 *
688- * @return Pipeline with all documents in this database.
689+ * @return A new [ Pipeline] object with all documents in this database.
689690 */
690691 fun database (): Pipeline = Pipeline (firestore, firestore.userDataReader, DatabaseSource ())
691692
@@ -694,7 +695,7 @@ class PipelineSource internal constructor(private val firestore: FirebaseFiresto
694695 *
695696 * @param documents Paths specifying the individual documents that will be the source of this
696697 * pipeline.
697- * @return Pipeline with [documents].
698+ * @return A new [ Pipeline] object with [documents].
698699 */
699700 fun documents (vararg documents : String ): Pipeline =
700701 // Validate document path by converting to DocumentReference
0 commit comments