diff --git a/sources/flows/AggregateFlow.kt b/sources/flows/AggregateFlow.kt index 0446ad7..d271078 100644 --- a/sources/flows/AggregateFlow.kt +++ b/sources/flows/AggregateFlow.kt @@ -17,6 +17,8 @@ package io.fluidsonic.mongo import com.mongodb.client.model.* +import kotlinx.coroutines.* +import kotlinx.coroutines.flow.* import kotlinx.coroutines.flow.Flow import org.bson.conversions.* import java.util.concurrent.* @@ -135,4 +137,59 @@ interface AggregateFlow : Flow { * @since 1.8 */ suspend fun firstOrNull(): TResult? + + + companion object { + + fun empty(): AggregateFlow = + Empty + } + + + private object Empty : AggregateFlow { + + override fun allowDiskUse(allowDiskUse: Boolean?) = + this + + + override fun maxTime(maxTime: Long, timeUnit: TimeUnit) = + this + + + override fun maxAwaitTime(maxAwaitTime: Long, timeUnit: TimeUnit) = + this + + + override fun bypassDocumentValidation(bypassDocumentValidation: Boolean?) = + this + + + override suspend fun toCollection() = + Unit + + + override fun collation(collation: Collation?) = + this + + + override fun comment(comment: String?) = + this + + + override fun hint(hint: Bson?) = + this + + + override fun batchSize(batchSize: Int) = + this + + + override suspend fun firstOrNull() = + null + + + @InternalCoroutinesApi + override suspend fun collect(collector: FlowCollector) = + Unit + } } diff --git a/sources/flows/ChangeStreamFlow.kt b/sources/flows/ChangeStreamFlow.kt index 4209c84..8f5530d 100644 --- a/sources/flows/ChangeStreamFlow.kt +++ b/sources/flows/ChangeStreamFlow.kt @@ -18,6 +18,8 @@ package io.fluidsonic.mongo import com.mongodb.client.model.* import com.mongodb.client.model.changestream.* +import kotlinx.coroutines.* +import kotlinx.coroutines.flow.* import kotlinx.coroutines.flow.Flow import org.bson.* import java.util.concurrent.* @@ -132,4 +134,55 @@ interface ChangeStreamFlow : Flow? + + + companion object { + + fun empty(): ChangeStreamFlow = + Empty + } + + + private object Empty : ChangeStreamFlow { + + override fun fullDocument(fullDocument: FullDocument) = + this + + + override fun resumeAfter(resumeToken: BsonDocument) = + this + + + override fun startAtOperationTime(startAtOperationTime: BsonTimestamp) = + this + + + override fun startAfter(startAfter: BsonDocument) = + this + + + override fun maxAwaitTime(maxAwaitTime: Long, timeUnit: TimeUnit) = + this + + + override fun collation(collation: Collation?) = + this + + + override fun withDocumentClass(clazz: KClass) = + emptyFlow() + + + override fun batchSize(batchSize: Int) = + this + + + override suspend fun firstOrNull(): Nothing? = + null + + + @InternalCoroutinesApi + override suspend fun collect(collector: FlowCollector>) = + Unit + } } diff --git a/sources/flows/DistinctFlow.kt b/sources/flows/DistinctFlow.kt index 344924e..75ea55b 100644 --- a/sources/flows/DistinctFlow.kt +++ b/sources/flows/DistinctFlow.kt @@ -17,6 +17,8 @@ package io.fluidsonic.mongo import com.mongodb.client.model.* +import kotlinx.coroutines.* +import kotlinx.coroutines.flow.* import kotlinx.coroutines.flow.Flow import org.bson.conversions.* import java.util.concurrent.* @@ -78,4 +80,39 @@ interface DistinctFlow : Flow { * @since 1.8 */ suspend fun firstOrNull(): TResult? + + + companion object { + + fun empty(): DistinctFlow = + Empty + } + + + private object Empty : DistinctFlow { + + override fun filter(filter: Bson?) = + this + + + override fun maxTime(maxTime: Long, timeUnit: TimeUnit) = + this + + + override fun collation(collation: Collation?) = + this + + + override fun batchSize(batchSize: Int) = + this + + + override suspend fun firstOrNull() = + null + + + @InternalCoroutinesApi + override suspend fun collect(collector: FlowCollector) = + Unit + } } diff --git a/sources/flows/FindFlow.kt b/sources/flows/FindFlow.kt index d70bf82..2c2c2c5 100644 --- a/sources/flows/FindFlow.kt +++ b/sources/flows/FindFlow.kt @@ -18,6 +18,8 @@ package io.fluidsonic.mongo import com.mongodb.* import com.mongodb.client.model.* +import kotlinx.coroutines.* +import kotlinx.coroutines.flow.* import kotlinx.coroutines.flow.Flow import org.bson.conversions.* import java.util.concurrent.* @@ -224,4 +226,99 @@ interface FindFlow : Flow { * @since 1.8 */ suspend fun firstOrNull(): TResult? + + + companion object { + + fun empty(): FindFlow = + Empty + } + + + private object Empty : FindFlow { + + override fun filter(filter: Bson?) = + this + + + override fun limit(limit: Int) = + this + + + override fun skip(skip: Int) = + this + + + override fun maxTime(maxTime: Long, timeUnit: TimeUnit) = + this + + + override fun maxAwaitTime(maxAwaitTime: Long, timeUnit: TimeUnit) = + this + + + override fun projection(projection: Bson?) = + this + + + override fun sort(sort: Bson?) = + this + + + override fun noCursorTimeout(noCursorTimeout: Boolean) = + this + + + override fun oplogReplay(oplogReplay: Boolean) = + this + + + override fun partial(partial: Boolean) = + this + + + override fun cursorType(cursorType: CursorType) = + this + + + override fun collation(collation: Collation?) = + this + + + override fun comment(comment: String?) = + this + + + override fun hint(hint: Bson?) = + this + + + override fun max(max: Bson?) = + this + + + override fun min(min: Bson?) = + this + + + override fun returnKey(returnKey: Boolean) = + this + + + override fun showRecordId(showRecordId: Boolean) = + this + + + override fun batchSize(batchSize: Int) = + this + + + override suspend fun firstOrNull() = + null + + + @InternalCoroutinesApi + override suspend fun collect(collector: FlowCollector) = + Unit + } } diff --git a/sources/flows/ListCollectionsFlow.kt b/sources/flows/ListCollectionsFlow.kt index 8b1b297..b72a5f7 100644 --- a/sources/flows/ListCollectionsFlow.kt +++ b/sources/flows/ListCollectionsFlow.kt @@ -16,6 +16,8 @@ package io.fluidsonic.mongo +import kotlinx.coroutines.* +import kotlinx.coroutines.flow.* import kotlinx.coroutines.flow.Flow import org.bson.conversions.* import java.util.concurrent.* @@ -67,4 +69,35 @@ interface ListCollectionsFlow : Flow { * @since 1.8 */ suspend fun firstOrNull(): TResult? + + + companion object { + + fun empty(): ListCollectionsFlow = + Empty + } + + + private object Empty : ListCollectionsFlow { + + override fun filter(filter: Bson?) = + this + + + override fun maxTime(maxTime: Long, timeUnit: TimeUnit) = + this + + + override fun batchSize(batchSize: Int) = + this + + + override suspend fun firstOrNull() = + null + + + @InternalCoroutinesApi + override suspend fun collect(collector: FlowCollector) = + Unit + } } diff --git a/sources/flows/ListDatabasesFlow.kt b/sources/flows/ListDatabasesFlow.kt index e0b5e94..9342ca8 100644 --- a/sources/flows/ListDatabasesFlow.kt +++ b/sources/flows/ListDatabasesFlow.kt @@ -16,6 +16,8 @@ package io.fluidsonic.mongo +import kotlinx.coroutines.* +import kotlinx.coroutines.flow.* import kotlinx.coroutines.flow.Flow import org.bson.conversions.* import java.util.concurrent.* @@ -78,4 +80,39 @@ interface ListDatabasesFlow : Flow { * @since 1.8 */ suspend fun firstOrNull(): TResult? + + + companion object { + + fun empty(): ListDatabasesFlow = + Empty + } + + + private object Empty : ListDatabasesFlow { + + override fun maxTime(maxTime: Long, timeUnit: TimeUnit) = + this + + + override fun filter(filter: Bson?) = + this + + + override fun nameOnly(nameOnly: Boolean?) = + this + + + override fun batchSize(batchSize: Int) = + this + + + override suspend fun firstOrNull() = + null + + + @InternalCoroutinesApi + override suspend fun collect(collector: FlowCollector) = + Unit + } } diff --git a/sources/flows/ListIndexesFlow.kt b/sources/flows/ListIndexesFlow.kt index a5b0ba6..29295ac 100644 --- a/sources/flows/ListIndexesFlow.kt +++ b/sources/flows/ListIndexesFlow.kt @@ -16,6 +16,8 @@ package io.fluidsonic.mongo +import kotlinx.coroutines.* +import kotlinx.coroutines.flow.* import kotlinx.coroutines.flow.Flow import java.util.concurrent.* @@ -57,4 +59,31 @@ interface ListIndexesFlow : Flow { * @since 1.8 */ suspend fun firstOrNull(): TResult? + + + companion object { + + fun empty(): ListIndexesFlow = + Empty + } + + + private object Empty : ListIndexesFlow { + + override fun maxTime(maxTime: Long, timeUnit: TimeUnit) = + this + + + override fun batchSize(batchSize: Int) = + this + + + override suspend fun firstOrNull() = + null + + + @InternalCoroutinesApi + override suspend fun collect(collector: FlowCollector) = + Unit + } } diff --git a/sources/flows/MapReduceFlow.kt b/sources/flows/MapReduceFlow.kt index 5415ad6..464310e 100644 --- a/sources/flows/MapReduceFlow.kt +++ b/sources/flows/MapReduceFlow.kt @@ -17,6 +17,8 @@ package io.fluidsonic.mongo import com.mongodb.client.model.* +import kotlinx.coroutines.* +import kotlinx.coroutines.flow.* import kotlinx.coroutines.flow.Flow import org.bson.conversions.* import java.util.concurrent.* @@ -205,4 +207,91 @@ interface MapReduceFlow : Flow { * @since 1.8 */ suspend fun firstOrNull(): TResult? + + + companion object { + + fun empty(): MapReduceFlow = + Empty + } + + + private object Empty : MapReduceFlow { + + override fun collectionName(collectionName: String) = + this + + + override fun finalizeFunction(finalizeFunction: String?) = + this + + + override fun scope(scope: Bson?) = + this + + + override fun sort(sort: Bson?) = + this + + + override fun filter(filter: Bson?) = + this + + + override fun limit(limit: Int) = + this + + + override fun jsMode(jsMode: Boolean) = + this + + + override fun verbose(verbose: Boolean) = + this + + + override fun maxTime(maxTime: Long, timeUnit: TimeUnit) = + this + + + override fun action(action: MapReduceAction) = + this + + + override fun databaseName(databaseName: String?) = + this + + + override fun sharded(sharded: Boolean) = + this + + + override fun nonAtomic(nonAtomic: Boolean) = + this + + + override fun bypassDocumentValidation(bypassDocumentValidation: Boolean?) = + this + + + override suspend fun toCollection() = + Unit + + + override fun collation(collation: Collation?) = + this + + + override fun batchSize(batchSize: Int) = + this + + + override suspend fun firstOrNull() = + null + + + @InternalCoroutinesApi + override suspend fun collect(collector: FlowCollector) = + Unit + } }