@@ -22,7 +22,7 @@ import com.google.firestore.v1.Pipeline
2222import com.google.firestore.v1.Value
2323
2424abstract class Stage
25- private constructor (private val name: String , private val options: InternalOptions ) {
25+ private constructor (protected val name: String , private val options: InternalOptions ) {
2626 internal constructor (name: String ) : this (name, InternalOptions .EMPTY )
2727 internal constructor (name: String , options: AbstractOptions <* >) : this (name, options.options)
2828 internal fun toProtoStage (userDataReader : UserDataReader ): Pipeline .Stage {
@@ -35,10 +35,20 @@ private constructor(private val name: String, private val options: InternalOptio
3535 internal abstract fun args (userDataReader : UserDataReader ): Sequence <Value >
3636}
3737
38- internal class GenericStage
39- internal constructor (name: String , private val params: List <GenericArg >) : Stage (name) {
38+ class GenericStage
39+ private constructor (name: String , private val arguments: List <GenericArg >, private val options: GenericOptions ) : Stage (name, options) {
40+ internal constructor (name: String , arguments: List <GenericArg >) : this (name, arguments, GenericOptions .DEFAULT )
41+ companion object {
42+ @JvmStatic
43+ fun of (name : String ) = GenericStage (name, emptyList())
44+ }
45+
46+ fun withArguments (vararg arguments : Any ): GenericStage = GenericStage (name, arguments.map(GenericArg ::from), options)
47+
48+ fun withOptions (options : GenericOptions ): GenericStage = GenericStage (name, arguments, options)
49+
4050 override fun args (userDataReader : UserDataReader ): Sequence <Value > =
41- params .asSequence().map { it.toProto(userDataReader) }
51+ arguments .asSequence().map { it.toProto(userDataReader) }
4252}
4353
4454internal sealed class GenericArg {
@@ -77,6 +87,14 @@ internal sealed class GenericArg {
7787 }
7888}
7989
90+ class GenericOptions private constructor(options : InternalOptions ) : AbstractOptions<GenericOptions>(options) {
91+ companion object {
92+ @JvmField
93+ val DEFAULT = GenericOptions (InternalOptions .EMPTY )
94+ }
95+ override fun self (options : InternalOptions ) = GenericOptions (options)
96+ }
97+
8098internal class DatabaseSource : Stage (" database" ) {
8199 override fun args (userDataReader : UserDataReader ): Sequence <Value > = emptySequence()
82100}
0 commit comments