![JAR search and dependency download from the Maven repository](/logo.png)
commonMain.com.harmony.kotlin.data.datasource.flow.FlowDataSourceValidator.kt Maven / Gradle / Ivy
package com.harmony.kotlin.data.datasource.flow
import com.harmony.kotlin.data.query.Query
import com.harmony.kotlin.data.validator.ListValidator
import com.harmony.kotlin.data.validator.Validator
import com.harmony.kotlin.error.DataNotValidException
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
class FlowDataSourceValidator(
private val getDataSource: FlowGetDataSource,
private val putDataSource: FlowPutDataSource,
private val deleteDataSource: FlowDeleteDataSource,
private val validator: Validator
) : FlowGetDataSource, FlowPutDataSource, FlowDeleteDataSource {
override fun get(query: Query): Flow = getDataSource.get(query).map {
if (!validator.isValid(it)) throw DataNotValidException() else it
}
@Deprecated("Use get instead")
override fun getAll(query: Query): Flow> = getDataSource.getAll(query).map {
if (!ListValidator(validator).isValid(it)) throw DataNotValidException() else it
}
override fun put(query: Query, value: T?): Flow = putDataSource.put(query, value)
@Deprecated("Use put instead")
override fun putAll(query: Query, value: List?): Flow> = putDataSource.putAll(query, value)
override fun delete(query: Query): Flow = deleteDataSource.delete(query)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy