All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.harmony.kotlin.data.datasource.DataSource.kt Maven / Gradle / Ivy

package com.harmony.kotlin.data.datasource

import com.harmony.kotlin.data.mapper.Mapper
import com.harmony.kotlin.data.query.Query
import com.harmony.kotlin.data.repository.GetRepository
import com.harmony.kotlin.data.repository.PutRepository
import com.harmony.kotlin.data.repository.SingleDeleteDataSourceRepository
import com.harmony.kotlin.data.repository.SingleGetDataSourceRepository
import com.harmony.kotlin.data.repository.SinglePutDataSourceRepository
import com.harmony.kotlin.data.repository.withMapping

// DataSources
interface GetDataSource {
  suspend fun get(query: Query): V

  @Deprecated(message = "Use get instead")
  suspend fun getAll(query: Query): List
}

interface PutDataSource {
  suspend fun put(query: Query, value: V?): V

  @Deprecated(message = "Use put instead")
  suspend fun putAll(query: Query, value: List? = emptyList()): List
}

interface DeleteDataSource {
  suspend fun delete(query: Query)
}

// Extensions to create
fun  GetDataSource.toGetRepository() = SingleGetDataSourceRepository(this)

fun  GetDataSource.toGetRepository(mapper: Mapper): GetRepository = toGetRepository().withMapping(mapper)

fun  PutDataSource.toPutRepository() = SinglePutDataSourceRepository(this)

fun  PutDataSource.toPutRepository(toMapper: Mapper, fromMapper: Mapper): PutRepository =
  toPutRepository().withMapping(toMapper, fromMapper)

fun DeleteDataSource.toDeleteRepository() = SingleDeleteDataSourceRepository(this)




© 2015 - 2025 Weber Informatics LLC | Privacy Policy