renames in key value repos

This commit is contained in:
InsanusMokrassar 2022-06-04 14:42:16 +06:00
parent 78903cd4eb
commit 18593c530b
25 changed files with 161 additions and 161 deletions

View File

@ -4,8 +4,6 @@ import dev.inmo.micro_utils.repos.*
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.* import kotlinx.coroutines.flow.*
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
open class ReadKeyValueCacheRepo<Key,Value>( open class ReadKeyValueCacheRepo<Key,Value>(
protected val parentRepo: ReadKeyValueRepo<Key, Value>, protected val parentRepo: ReadKeyValueRepo<Key, Value>,

View File

@ -4,7 +4,7 @@ import dev.inmo.micro_utils.pagination.*
import dev.inmo.micro_utils.pagination.utils.doAllWithCurrentPaging import dev.inmo.micro_utils.pagination.utils.doAllWithCurrentPaging
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
interface ReadStandardKeyValueRepo<Key, Value> : Repo { interface ReadKeyValueRepo<Key, Value> : Repo {
suspend fun get(k: Key): Value? suspend fun get(k: Key): Value?
suspend fun values(pagination: Pagination, reversed: Boolean = false): PaginationResult<Value> suspend fun values(pagination: Pagination, reversed: Boolean = false): PaginationResult<Value>
suspend fun keys(pagination: Pagination, reversed: Boolean = false): PaginationResult<Key> suspend fun keys(pagination: Pagination, reversed: Boolean = false): PaginationResult<Key>
@ -12,9 +12,9 @@ interface ReadStandardKeyValueRepo<Key, Value> : Repo {
suspend fun contains(key: Key): Boolean suspend fun contains(key: Key): Boolean
suspend fun count(): Long suspend fun count(): Long
} }
typealias ReadKeyValueRepo<Key,Value> = ReadStandardKeyValueRepo<Key, Value> typealias ReadStandardKeyValueRepo<Key,Value> = ReadKeyValueRepo<Key, Value>
interface WriteStandardKeyValueRepo<Key, Value> : Repo { interface WriteKeyValueRepo<Key, Value> : Repo {
val onNewValue: Flow<Pair<Key, Value>> val onNewValue: Flow<Pair<Key, Value>>
val onValueRemoved: Flow<Key> val onValueRemoved: Flow<Key>
@ -22,25 +22,25 @@ interface WriteStandardKeyValueRepo<Key, Value> : Repo {
suspend fun unset(toUnset: List<Key>) suspend fun unset(toUnset: List<Key>)
suspend fun unsetWithValues(toUnset: List<Value>) suspend fun unsetWithValues(toUnset: List<Value>)
} }
typealias WriteKeyValueRepo<Key,Value> = WriteStandardKeyValueRepo<Key, Value> typealias WriteStandardKeyValueRepo<Key,Value> = WriteKeyValueRepo<Key, Value>
suspend inline fun <Key, Value> WriteStandardKeyValueRepo<Key, Value>.set( suspend inline fun <Key, Value> WriteKeyValueRepo<Key, Value>.set(
vararg toSet: Pair<Key, Value> vararg toSet: Pair<Key, Value>
) = set(toSet.toMap()) ) = set(toSet.toMap())
suspend inline fun <Key, Value> WriteStandardKeyValueRepo<Key, Value>.set( suspend inline fun <Key, Value> WriteKeyValueRepo<Key, Value>.set(
k: Key, v: Value k: Key, v: Value
) = set(k to v) ) = set(k to v)
suspend inline fun <Key, Value> WriteStandardKeyValueRepo<Key, Value>.unset( suspend inline fun <Key, Value> WriteKeyValueRepo<Key, Value>.unset(
vararg k: Key vararg k: Key
) = unset(k.toList()) ) = unset(k.toList())
suspend inline fun <Key, Value> WriteStandardKeyValueRepo<Key, Value>.unsetWithValues( suspend inline fun <Key, Value> WriteKeyValueRepo<Key, Value>.unsetWithValues(
vararg v: Value vararg v: Value
) = unsetWithValues(v.toList()) ) = unsetWithValues(v.toList())
interface StandardKeyValueRepo<Key, Value> : ReadStandardKeyValueRepo<Key, Value>, WriteStandardKeyValueRepo<Key, Value> { interface KeyValueRepo<Key, Value> : ReadKeyValueRepo<Key, Value>, WriteKeyValueRepo<Key, Value> {
override suspend fun unsetWithValues(toUnset: List<Value>) = toUnset.forEach { v -> override suspend fun unsetWithValues(toUnset: List<Value>) = toUnset.forEach { v ->
doAllWithCurrentPaging { doAllWithCurrentPaging {
keys(v, it).also { keys(v, it).also {
@ -49,11 +49,11 @@ interface StandardKeyValueRepo<Key, Value> : ReadStandardKeyValueRepo<Key, Value
} }
} }
} }
typealias KeyValueRepo<Key,Value> = StandardKeyValueRepo<Key, Value> typealias StandardKeyValueRepo<Key,Value> = KeyValueRepo<Key, Value>
class DelegateBasedStandardKeyValueRepo<Key, Value>( class DelegateBasedKeyValueRepo<Key, Value>(
readDelegate: ReadStandardKeyValueRepo<Key, Value>, readDelegate: ReadKeyValueRepo<Key, Value>,
writeDelegate: WriteStandardKeyValueRepo<Key, Value> writeDelegate: WriteKeyValueRepo<Key, Value>
) : StandardKeyValueRepo<Key, Value>, ) : KeyValueRepo<Key, Value>,
ReadStandardKeyValueRepo<Key, Value> by readDelegate, ReadKeyValueRepo<Key, Value> by readDelegate,
WriteStandardKeyValueRepo<Key, Value> by writeDelegate WriteKeyValueRepo<Key, Value> by writeDelegate

View File

@ -6,10 +6,12 @@ import dev.inmo.micro_utils.repos.*
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
open class MapperReadStandardKeyValueRepo<FromKey, FromValue, ToKey, ToValue>( @Deprecated("Renamed", ReplaceWith("MapperReadKeyValueRepo", "dev.inmo.micro_utils.repos.mappers.MapperReadKeyValueRepo"))
private val to: ReadStandardKeyValueRepo<ToKey, ToValue>, typealias MapperReadStandardKeyValueRepo<FromKey, FromValue, ToKey, ToValue> = MapperReadKeyValueRepo<FromKey, FromValue, ToKey, ToValue>
open class MapperReadKeyValueRepo<FromKey, FromValue, ToKey, ToValue>(
private val to: ReadKeyValueRepo<ToKey, ToValue>,
mapper: MapperRepo<FromKey, FromValue, ToKey, ToValue> mapper: MapperRepo<FromKey, FromValue, ToKey, ToValue>
) : ReadStandardKeyValueRepo<FromKey, FromValue>, MapperRepo<FromKey, FromValue, ToKey, ToValue> by mapper { ) : ReadKeyValueRepo<FromKey, FromValue>, MapperRepo<FromKey, FromValue, ToKey, ToValue> by mapper {
override suspend fun get(k: FromKey): FromValue? = to.get( override suspend fun get(k: FromKey): FromValue? = to.get(
k.toOutKey() k.toOutKey()
) ?.toInnerValue() ) ?.toInnerValue()
@ -69,24 +71,26 @@ open class MapperReadStandardKeyValueRepo<FromKey, FromValue, ToKey, ToValue>(
} }
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun <FromKey, FromValue, ToKey, ToValue> ReadStandardKeyValueRepo<ToKey, ToValue>.withMapper( inline fun <FromKey, FromValue, ToKey, ToValue> ReadKeyValueRepo<ToKey, ToValue>.withMapper(
mapper: MapperRepo<FromKey, FromValue, ToKey, ToValue> mapper: MapperRepo<FromKey, FromValue, ToKey, ToValue>
): ReadStandardKeyValueRepo<FromKey, FromValue> = MapperReadStandardKeyValueRepo(this, mapper) ): ReadKeyValueRepo<FromKey, FromValue> = MapperReadKeyValueRepo(this, mapper)
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun <reified FromKey, reified FromValue, reified ToKey, reified ToValue> ReadStandardKeyValueRepo<ToKey, ToValue>.withMapper( inline fun <reified FromKey, reified FromValue, reified ToKey, reified ToValue> ReadKeyValueRepo<ToKey, ToValue>.withMapper(
crossinline keyFromToTo: suspend FromKey.() -> ToKey = { this as ToKey }, crossinline keyFromToTo: suspend FromKey.() -> ToKey = { this as ToKey },
crossinline valueFromToTo: suspend FromValue.() -> ToValue = { this as ToValue }, crossinline valueFromToTo: suspend FromValue.() -> ToValue = { this as ToValue },
crossinline keyToToFrom: suspend ToKey.() -> FromKey = { this as FromKey }, crossinline keyToToFrom: suspend ToKey.() -> FromKey = { this as FromKey },
crossinline valueToToFrom: suspend ToValue.() -> FromValue = { this as FromValue }, crossinline valueToToFrom: suspend ToValue.() -> FromValue = { this as FromValue },
): ReadStandardKeyValueRepo<FromKey, FromValue> = withMapper( ): ReadKeyValueRepo<FromKey, FromValue> = withMapper(
mapper(keyFromToTo, valueFromToTo, keyToToFrom, valueToToFrom) mapper(keyFromToTo, valueFromToTo, keyToToFrom, valueToToFrom)
) )
open class MapperWriteStandardKeyValueRepo<FromKey, FromValue, ToKey, ToValue>( @Deprecated("Renamed", ReplaceWith("MapperWriteKeyValueRepo", "dev.inmo.micro_utils.repos.mappers.MapperWriteKeyValueRepo"))
private val to: WriteStandardKeyValueRepo<ToKey, ToValue>, typealias MapperWriteStandardKeyValueRepo<FromKey, FromValue, ToKey, ToValue> = MapperWriteKeyValueRepo<FromKey, FromValue, ToKey, ToValue>
open class MapperWriteKeyValueRepo<FromKey, FromValue, ToKey, ToValue>(
private val to: WriteKeyValueRepo<ToKey, ToValue>,
mapper: MapperRepo<FromKey, FromValue, ToKey, ToValue> mapper: MapperRepo<FromKey, FromValue, ToKey, ToValue>
) : WriteStandardKeyValueRepo<FromKey, FromValue>, MapperRepo<FromKey, FromValue, ToKey, ToValue> by mapper { ) : WriteKeyValueRepo<FromKey, FromValue>, MapperRepo<FromKey, FromValue, ToKey, ToValue> by mapper {
override val onNewValue: Flow<Pair<FromKey, FromValue>> = to.onNewValue.map { (k, v) -> override val onNewValue: Flow<Pair<FromKey, FromValue>> = to.onNewValue.map { (k, v) ->
k.toInnerKey() to v.toInnerValue() k.toInnerKey() to v.toInnerValue()
} }
@ -112,40 +116,42 @@ open class MapperWriteStandardKeyValueRepo<FromKey, FromValue, ToKey, ToValue>(
} }
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun <FromKey, FromValue, ToKey, ToValue> WriteStandardKeyValueRepo<ToKey, ToValue>.withMapper( inline fun <FromKey, FromValue, ToKey, ToValue> WriteKeyValueRepo<ToKey, ToValue>.withMapper(
mapper: MapperRepo<FromKey, FromValue, ToKey, ToValue> mapper: MapperRepo<FromKey, FromValue, ToKey, ToValue>
): WriteStandardKeyValueRepo<FromKey, FromValue> = MapperWriteStandardKeyValueRepo(this, mapper) ): WriteKeyValueRepo<FromKey, FromValue> = MapperWriteKeyValueRepo(this, mapper)
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun <reified FromKey, reified FromValue, reified ToKey, reified ToValue> WriteStandardKeyValueRepo<ToKey, ToValue>.withMapper( inline fun <reified FromKey, reified FromValue, reified ToKey, reified ToValue> WriteKeyValueRepo<ToKey, ToValue>.withMapper(
crossinline keyFromToTo: suspend FromKey.() -> ToKey = { this as ToKey }, crossinline keyFromToTo: suspend FromKey.() -> ToKey = { this as ToKey },
crossinline valueFromToTo: suspend FromValue.() -> ToValue = { this as ToValue }, crossinline valueFromToTo: suspend FromValue.() -> ToValue = { this as ToValue },
crossinline keyToToFrom: suspend ToKey.() -> FromKey = { this as FromKey }, crossinline keyToToFrom: suspend ToKey.() -> FromKey = { this as FromKey },
crossinline valueToToFrom: suspend ToValue.() -> FromValue = { this as FromValue }, crossinline valueToToFrom: suspend ToValue.() -> FromValue = { this as FromValue },
): WriteStandardKeyValueRepo<FromKey, FromValue> = withMapper( ): WriteKeyValueRepo<FromKey, FromValue> = withMapper(
mapper(keyFromToTo, valueFromToTo, keyToToFrom, valueToToFrom) mapper(keyFromToTo, valueFromToTo, keyToToFrom, valueToToFrom)
) )
@Deprecated("Renamed", ReplaceWith("MapperKeyValueRepo", "dev.inmo.micro_utils.repos.mappers.MapperKeyValueRepo"))
typealias MapperStandardKeyValueRepo<FromKey, FromValue, ToKey, ToValue> = MapperKeyValueRepo<FromKey, FromValue, ToKey, ToValue>
@Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE") @Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE")
open class MapperStandardKeyValueRepo<FromKey, FromValue, ToKey, ToValue>( open class MapperKeyValueRepo<FromKey, FromValue, ToKey, ToValue>(
private val to: StandardKeyValueRepo<ToKey, ToValue>, private val to: KeyValueRepo<ToKey, ToValue>,
private val mapper: MapperRepo<FromKey, FromValue, ToKey, ToValue> private val mapper: MapperRepo<FromKey, FromValue, ToKey, ToValue>
) : StandardKeyValueRepo<FromKey, FromValue>, ) : KeyValueRepo<FromKey, FromValue>,
MapperRepo<FromKey, FromValue, ToKey, ToValue> by mapper, MapperRepo<FromKey, FromValue, ToKey, ToValue> by mapper,
ReadStandardKeyValueRepo<FromKey, FromValue> by MapperReadStandardKeyValueRepo(to, mapper), ReadKeyValueRepo<FromKey, FromValue> by MapperReadKeyValueRepo(to, mapper),
WriteStandardKeyValueRepo<FromKey, FromValue> by MapperWriteStandardKeyValueRepo(to, mapper) WriteKeyValueRepo<FromKey, FromValue> by MapperWriteKeyValueRepo(to, mapper)
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun <FromKey, FromValue, ToKey, ToValue> StandardKeyValueRepo<ToKey, ToValue>.withMapper( inline fun <FromKey, FromValue, ToKey, ToValue> KeyValueRepo<ToKey, ToValue>.withMapper(
mapper: MapperRepo<FromKey, FromValue, ToKey, ToValue> mapper: MapperRepo<FromKey, FromValue, ToKey, ToValue>
): StandardKeyValueRepo<FromKey, FromValue> = MapperStandardKeyValueRepo(this, mapper) ): KeyValueRepo<FromKey, FromValue> = MapperKeyValueRepo(this, mapper)
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun <reified FromKey, reified FromValue, reified ToKey, reified ToValue> StandardKeyValueRepo<ToKey, ToValue>.withMapper( inline fun <reified FromKey, reified FromValue, reified ToKey, reified ToValue> KeyValueRepo<ToKey, ToValue>.withMapper(
crossinline keyFromToTo: suspend FromKey.() -> ToKey = { this as ToKey }, crossinline keyFromToTo: suspend FromKey.() -> ToKey = { this as ToKey },
crossinline valueFromToTo: suspend FromValue.() -> ToValue = { this as ToValue }, crossinline valueFromToTo: suspend FromValue.() -> ToValue = { this as ToValue },
crossinline keyToToFrom: suspend ToKey.() -> FromKey = { this as FromKey }, crossinline keyToToFrom: suspend ToKey.() -> FromKey = { this as FromKey },
crossinline valueToToFrom: suspend ToValue.() -> FromValue = { this as FromValue }, crossinline valueToToFrom: suspend ToValue.() -> FromValue = { this as FromValue },
): StandardKeyValueRepo<FromKey, FromValue> = withMapper( ): KeyValueRepo<FromKey, FromValue> = withMapper(
mapper(keyFromToTo, valueFromToTo, keyToToFrom, valueToToFrom) mapper(keyFromToTo, valueFromToTo, keyToToFrom, valueToToFrom)
) )

View File

@ -2,9 +2,9 @@ package dev.inmo.micro_utils.repos.pagination
import dev.inmo.micro_utils.pagination.* import dev.inmo.micro_utils.pagination.*
import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging
import dev.inmo.micro_utils.repos.ReadStandardKeyValueRepo import dev.inmo.micro_utils.repos.ReadKeyValueRepo
suspend inline fun <Key, Value, REPO : ReadStandardKeyValueRepo<Key, Value>> REPO.getAll( suspend inline fun <Key, Value, REPO : ReadKeyValueRepo<Key, Value>> REPO.getAll(
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE") @Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
crossinline methodCaller: suspend REPO.(Pagination) -> PaginationResult<Key> crossinline methodCaller: suspend REPO.(Pagination) -> PaginationResult<Key>
): List<Pair<Key, Value>> = getAllWithNextPaging { ): List<Pair<Key, Value>> = getAllWithNextPaging {

View File

@ -1,10 +1,10 @@
package dev.inmo.micro_utils.repos.versions package dev.inmo.micro_utils.repos.versions
import dev.inmo.micro_utils.repos.StandardKeyValueRepo import dev.inmo.micro_utils.repos.KeyValueRepo
import dev.inmo.micro_utils.repos.set import dev.inmo.micro_utils.repos.set
class KeyValueBasedVersionsRepoProxy<T>( class KeyValueBasedVersionsRepoProxy<T>(
private val keyValueStore: StandardKeyValueRepo<String, Int>, private val keyValueStore: KeyValueRepo<String, Int>,
override val database: T override val database: T
) : StandardVersionsRepoProxy<T> { ) : StandardVersionsRepoProxy<T> {
override suspend fun getTableVersion(tableName: String): Int? = keyValueStore.get(tableName) override suspend fun getTableVersion(tableName: String): Int? = keyValueStore.get(tableName)

View File

@ -13,9 +13,12 @@ import java.nio.file.StandardWatchEventKinds.*
private inline val String.isAbsolute private inline val String.isAbsolute
get() = startsWith(File.separator) get() = startsWith(File.separator)
class FileReadStandardKeyValueRepo( @Deprecated("Renamed", ReplaceWith("FileReadKeyValueRepo", "dev.inmo.micro_utils.repos.FileReadKeyValueRepo"))
typealias FileReadStandardKeyValueRepo = FileReadKeyValueRepo
class FileReadKeyValueRepo(
private val folder: File private val folder: File
) : ReadStandardKeyValueRepo<String, File> { ) : ReadKeyValueRepo<String, File> {
init { init {
folder.mkdirs() folder.mkdirs()
} }
@ -79,14 +82,17 @@ class FileReadStandardKeyValueRepo(
override suspend fun count(): Long = folder.list() ?.size ?.toLong() ?: 0L override suspend fun count(): Long = folder.list() ?.size ?.toLong() ?: 0L
} }
@Deprecated("Renamed", ReplaceWith("FileWriteKeyValueRepo", "dev.inmo.micro_utils.repos.FileWriteKeyValueRepo"))
typealias FileWriteStandardKeyValueRepo = FileWriteKeyValueRepo
/** /**
* Files watching will not correctly works on Android with version of API lower than API 26 * Files watching will not correctly works on Android with version of API lower than API 26
*/ */
@Warning("Files watching will not correctly works on Android Platform with version of API lower than API 26") @Warning("Files watching will not correctly works on Android Platform with version of API lower than API 26")
class FileWriteStandardKeyValueRepo( class FileWriteKeyValueRepo(
private val folder: File, private val folder: File,
filesChangedProcessingScope: CoroutineScope? = null filesChangedProcessingScope: CoroutineScope? = null
) : WriteStandardKeyValueRepo<String, File> { ) : WriteKeyValueRepo<String, File> {
private val _onNewValue = MutableSharedFlow<Pair<String, File>>() private val _onNewValue = MutableSharedFlow<Pair<String, File>>()
override val onNewValue: Flow<Pair<String, File>> = _onNewValue.asSharedFlow() override val onNewValue: Flow<Pair<String, File>> = _onNewValue.asSharedFlow()
private val _onValueRemoved = MutableSharedFlow<String>() private val _onValueRemoved = MutableSharedFlow<String>()
@ -174,12 +180,15 @@ class FileWriteStandardKeyValueRepo(
} }
} }
@Deprecated("Renamed", ReplaceWith("FileKeyValueRepo", "dev.inmo.micro_utils.repos.FileKeyValueRepo"))
typealias FileStandardKeyValueRepo = FileKeyValueRepo
@Warning("Files watching will not correctly works on Android Platform with version of API lower than API 26") @Warning("Files watching will not correctly works on Android Platform with version of API lower than API 26")
@Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE") @Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE")
class FileStandardKeyValueRepo( class FileKeyValueRepo(
folder: File, folder: File,
filesChangedProcessingScope: CoroutineScope? = null filesChangedProcessingScope: CoroutineScope? = null
) : StandardKeyValueRepo<String, File>, ) : KeyValueRepo<String, File>,
WriteStandardKeyValueRepo<String, File> by FileWriteStandardKeyValueRepo(folder, filesChangedProcessingScope), WriteKeyValueRepo<String, File> by FileWriteKeyValueRepo(folder, filesChangedProcessingScope),
ReadStandardKeyValueRepo<String, File> by FileReadStandardKeyValueRepo(folder) { ReadKeyValueRepo<String, File> by FileReadKeyValueRepo(folder) {
} }

View File

@ -7,7 +7,7 @@ import dev.inmo.micro_utils.pagination.Pagination
import dev.inmo.micro_utils.pagination.PaginationResult import dev.inmo.micro_utils.pagination.PaginationResult
import dev.inmo.micro_utils.pagination.utils.paginate import dev.inmo.micro_utils.pagination.utils.paginate
import dev.inmo.micro_utils.pagination.utils.reverse import dev.inmo.micro_utils.pagination.utils.reverse
import dev.inmo.micro_utils.repos.StandardKeyValueRepo import dev.inmo.micro_utils.repos.KeyValueRepo
import kotlinx.coroutines.flow.* import kotlinx.coroutines.flow.*
private val cache = HashMap<String, KeyValueStore<*>>() private val cache = HashMap<String, KeyValueStore<*>>()
@ -15,7 +15,7 @@ private val cache = HashMap<String, KeyValueStore<*>>()
fun <T : Any> Context.keyValueStore( fun <T : Any> Context.keyValueStore(
name: String = "default", name: String = "default",
cacheValues: Boolean = false cacheValues: Boolean = false
): StandardKeyValueRepo<String, T> { ): KeyValueRepo<String, T> {
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
return cache.getOrPut(name) { return cache.getOrPut(name) {
KeyValueStore<T>(this, name, cacheValues) KeyValueStore<T>(this, name, cacheValues)
@ -26,7 +26,7 @@ class KeyValueStore<T : Any> internal constructor (
c: Context, c: Context,
preferencesName: String, preferencesName: String,
useCache: Boolean = false useCache: Boolean = false
) : SharedPreferences.OnSharedPreferenceChangeListener, StandardKeyValueRepo<String, T> { ) : SharedPreferences.OnSharedPreferenceChangeListener, KeyValueRepo<String, T> {
private val sharedPreferences = c.getSharedPreferences(preferencesName, Context.MODE_PRIVATE) private val sharedPreferences = c.getSharedPreferences(preferencesName, Context.MODE_PRIVATE)
private val cachedData = if (useCache) { private val cachedData = if (useCache) {

View File

@ -4,13 +4,11 @@ package dev.inmo.micro_utils.repos.versions
import android.content.Context import android.content.Context
import android.database.sqlite.SQLiteOpenHelper import android.database.sqlite.SQLiteOpenHelper
import androidx.core.content.contentValuesOf
import dev.inmo.micro_utils.repos.* import dev.inmo.micro_utils.repos.*
import dev.inmo.micro_utils.repos.keyvalue.keyValueStore import dev.inmo.micro_utils.repos.keyvalue.keyValueStore
import kotlinx.coroutines.runBlocking
/** /**
* Will create [VersionsRepo] based on [T], but versions will be stored in [StandardKeyValueRepo] * Will create [VersionsRepo] based on [T], but versions will be stored in [KeyValueRepo]
* *
* @receiver Will be used to create [KeyValueBasedVersionsRepoProxy] via [keyValueStore] and pass it to [StandardVersionsRepo] * @receiver Will be used to create [KeyValueBasedVersionsRepoProxy] via [keyValueStore] and pass it to [StandardVersionsRepo]
* *
@ -26,9 +24,9 @@ inline fun <T> Context.versionsKeyValueRepo(
) )
) )
/** /**
* Will create [VersionsRepo] based on [SQLiteOpenHelper], but versions will be stored in [StandardKeyValueRepo] * Will create [VersionsRepo] based on [SQLiteOpenHelper], but versions will be stored in [KeyValueRepo]
* *
* @receiver Will be used to create [StandardKeyValueRepo] via [keyValueStore] and pass it to [StandardVersionsRepo] * @receiver Will be used to create [KeyValueRepo] via [keyValueStore] and pass it to [StandardVersionsRepo]
* *
* @see [keyValueStore] * @see [keyValueStore]
*/ */
@ -37,9 +35,9 @@ inline fun Context.versionsKeyValueRepoForSQL(
) = versionsKeyValueRepo(database) ) = versionsKeyValueRepo(database)
/** /**
* Will create [VersionsRepo] based on [SQLiteOpenHelper], but versions will be stored in [StandardKeyValueRepo] * Will create [VersionsRepo] based on [SQLiteOpenHelper], but versions will be stored in [KeyValueRepo]
* *
* @param context Will be used to create [StandardKeyValueRepo] via [keyValueStore] and pass it to [StandardVersionsRepo] * @param context Will be used to create [KeyValueRepo] via [keyValueStore] and pass it to [StandardVersionsRepo]
* *
* @see [keyValueStore] * @see [keyValueStore]
*/ */

View File

@ -1,9 +1,7 @@
package dev.inmo.micro_utils.repos.exposed.keyvalue package dev.inmo.micro_utils.repos.exposed.keyvalue
import dev.inmo.micro_utils.repos.StandardKeyValueRepo import dev.inmo.micro_utils.repos.KeyValueRepo
import dev.inmo.micro_utils.repos.exposed.ColumnAllocator import dev.inmo.micro_utils.repos.exposed.ColumnAllocator
import dev.inmo.micro_utils.repos.exposed.initTable
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.* import kotlinx.coroutines.flow.*
import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.transactions.transaction import org.jetbrains.exposed.sql.transactions.transaction
@ -13,7 +11,7 @@ open class ExposedKeyValueRepo<Key, Value>(
keyColumnAllocator: ColumnAllocator<Key>, keyColumnAllocator: ColumnAllocator<Key>,
valueColumnAllocator: ColumnAllocator<Value>, valueColumnAllocator: ColumnAllocator<Value>,
tableName: String? = null tableName: String? = null
) : StandardKeyValueRepo<Key, Value>, ExposedReadKeyValueRepo<Key, Value>( ) : KeyValueRepo<Key, Value>, ExposedReadKeyValueRepo<Key, Value>(
database, database,
keyColumnAllocator, keyColumnAllocator,
valueColumnAllocator, valueColumnAllocator,

View File

@ -1,7 +1,7 @@
package dev.inmo.micro_utils.repos.exposed.keyvalue package dev.inmo.micro_utils.repos.exposed.keyvalue
import dev.inmo.micro_utils.pagination.* import dev.inmo.micro_utils.pagination.*
import dev.inmo.micro_utils.repos.ReadStandardKeyValueRepo import dev.inmo.micro_utils.repos.ReadKeyValueRepo
import dev.inmo.micro_utils.repos.exposed.* import dev.inmo.micro_utils.repos.exposed.*
import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.transactions.transaction import org.jetbrains.exposed.sql.transactions.transaction
@ -11,7 +11,7 @@ open class ExposedReadKeyValueRepo<Key, Value>(
keyColumnAllocator: ColumnAllocator<Key>, keyColumnAllocator: ColumnAllocator<Key>,
valueColumnAllocator: ColumnAllocator<Value>, valueColumnAllocator: ColumnAllocator<Value>,
tableName: String? = null tableName: String? = null
) : ReadStandardKeyValueRepo<Key, Value>, ExposedRepo, Table(tableName ?: "") { ) : ReadKeyValueRepo<Key, Value>, ExposedRepo, Table(tableName ?: "") {
val keyColumn: Column<Key> = keyColumnAllocator() val keyColumn: Column<Key> = keyColumnAllocator()
val valueColumn: Column<Value> = valueColumnAllocator() val valueColumn: Column<Value> = valueColumnAllocator()
override val primaryKey: PrimaryKey = PrimaryKey(keyColumn, valueColumn) override val primaryKey: PrimaryKey = PrimaryKey(keyColumn, valueColumn)

View File

@ -9,7 +9,7 @@ import kotlinx.coroutines.flow.MutableSharedFlow
class ReadMapKeyValueRepo<Key, Value>( class ReadMapKeyValueRepo<Key, Value>(
protected val map: Map<Key, Value> = emptyMap() protected val map: Map<Key, Value> = emptyMap()
) : ReadStandardKeyValueRepo<Key, Value> { ) : ReadKeyValueRepo<Key, Value> {
override suspend fun get(k: Key): Value? = map[k] override suspend fun get(k: Key): Value? = map[k]
override suspend fun values( override suspend fun values(
@ -58,7 +58,7 @@ class ReadMapKeyValueRepo<Key, Value>(
class WriteMapKeyValueRepo<Key, Value>( class WriteMapKeyValueRepo<Key, Value>(
private val map: MutableMap<Key, Value> = mutableMapOf() private val map: MutableMap<Key, Value> = mutableMapOf()
) : WriteStandardKeyValueRepo<Key, Value> { ) : WriteKeyValueRepo<Key, Value> {
private val _onNewValue: MutableSharedFlow<Pair<Key, Value>> = MutableSharedFlow() private val _onNewValue: MutableSharedFlow<Pair<Key, Value>> = MutableSharedFlow()
override val onNewValue: Flow<Pair<Key, Value>> override val onNewValue: Flow<Pair<Key, Value>>
get() = _onNewValue get() = _onNewValue
@ -89,8 +89,8 @@ class WriteMapKeyValueRepo<Key, Value>(
class MapKeyValueRepo<Key, Value>( class MapKeyValueRepo<Key, Value>(
private val map: MutableMap<Key, Value> = mutableMapOf() private val map: MutableMap<Key, Value> = mutableMapOf()
) : StandardKeyValueRepo<Key, Value>, ) : KeyValueRepo<Key, Value>,
ReadStandardKeyValueRepo<Key, Value> by ReadMapKeyValueRepo(map), ReadKeyValueRepo<Key, Value> by ReadMapKeyValueRepo(map),
WriteStandardKeyValueRepo<Key, Value> by WriteMapKeyValueRepo(map) WriteKeyValueRepo<Key, Value> by WriteMapKeyValueRepo(map)
fun <K, V> MutableMap<K, V>.asKeyValueRepo(): StandardKeyValueRepo<K, V> = MapKeyValueRepo(this) fun <K, V> MutableMap<K, V>.asKeyValueRepo(): KeyValueRepo<K, V> = MapKeyValueRepo(this)

View File

@ -7,10 +7,10 @@ import io.ktor.http.ContentType
import io.ktor.http.encodeURLQueryComponent import io.ktor.http.encodeURLQueryComponent
import kotlinx.serialization.* import kotlinx.serialization.*
class KtorStandardKeyValueRepoClient<Key, Value> ( class KtorKeyValueRepoClient<Key, Value> (
readDelegate: ReadStandardKeyValueRepo<Key, Value>, readDelegate: ReadKeyValueRepo<Key, Value>,
writeDelegate: WriteStandardKeyValueRepo<Key, Value> writeDelegate: WriteKeyValueRepo<Key, Value>
) : StandardKeyValueRepo<Key, Value> by DelegateBasedStandardKeyValueRepo( ) : KeyValueRepo<Key, Value> by DelegateBasedKeyValueRepo(
readDelegate, readDelegate,
writeDelegate writeDelegate
) { ) {
@ -21,11 +21,11 @@ class KtorStandardKeyValueRepoClient<Key, Value> (
contentType: ContentType, contentType: ContentType,
noinline idSerializer: suspend (Key) -> String, noinline idSerializer: suspend (Key) -> String,
noinline valueSerializer: suspend (Value) -> String noinline valueSerializer: suspend (Value) -> String
) = KtorStandardKeyValueRepoClient( ) = KtorKeyValueRepoClient(
KtorReadStandardKeyValueRepoClient( KtorReadKeyValueRepoClient(
baseUrl, httpClient, contentType, idSerializer, valueSerializer baseUrl, httpClient, contentType, idSerializer, valueSerializer
), ),
KtorWriteStandardKeyValueRepoClient( KtorWriteKeyValueRepoClient(
baseUrl, baseUrl,
httpClient, httpClient,
contentType contentType
@ -38,7 +38,7 @@ class KtorStandardKeyValueRepoClient<Key, Value> (
contentType: ContentType, contentType: ContentType,
noinline idSerializer: suspend (Key) -> String, noinline idSerializer: suspend (Key) -> String,
noinline valueSerializer: suspend (Value) -> String noinline valueSerializer: suspend (Value) -> String
) = KtorStandardKeyValueRepoClient( ) = KtorKeyValueRepoClient(
buildStandardUrl(baseUrl, subpart), buildStandardUrl(baseUrl, subpart),
httpClient, httpClient,
contentType, contentType,
@ -48,14 +48,14 @@ class KtorStandardKeyValueRepoClient<Key, Value> (
} }
} }
inline fun <reified Key, reified Value> KtorStandardKeyValueRepoClient( inline fun <reified Key, reified Value> KtorKeyValueRepoClient(
baseUrl: String, baseUrl: String,
httpClient: HttpClient, httpClient: HttpClient,
contentType: ContentType, contentType: ContentType,
idSerializer: SerializationStrategy<Key>, idSerializer: SerializationStrategy<Key>,
valueSerializer: SerializationStrategy<Value>, valueSerializer: SerializationStrategy<Value>,
serialFormat: StringFormat, serialFormat: StringFormat,
) = KtorStandardKeyValueRepoClient<Key, Value>( ) = KtorKeyValueRepoClient<Key, Value>(
baseUrl, baseUrl,
httpClient, httpClient,
contentType, contentType,
@ -66,14 +66,14 @@ inline fun <reified Key, reified Value> KtorStandardKeyValueRepoClient(
serialFormat.encodeToString(valueSerializer, it).encodeURLQueryComponent() serialFormat.encodeToString(valueSerializer, it).encodeURLQueryComponent()
} }
inline fun <reified Key, reified Value> KtorStandardKeyValueRepoClient( inline fun <reified Key, reified Value> KtorKeyValueRepoClient(
baseUrl: String, baseUrl: String,
httpClient: HttpClient, httpClient: HttpClient,
contentType: ContentType, contentType: ContentType,
idSerializer: SerializationStrategy<Key>, idSerializer: SerializationStrategy<Key>,
valueSerializer: SerializationStrategy<Value>, valueSerializer: SerializationStrategy<Value>,
serialFormat: BinaryFormat, serialFormat: BinaryFormat,
) = KtorStandardKeyValueRepoClient<Key, Value>( ) = KtorKeyValueRepoClient<Key, Value>(
baseUrl, baseUrl,
httpClient, httpClient,
contentType, contentType,

View File

@ -2,7 +2,7 @@ package dev.inmo.micro_utils.repos.ktor.client.key_value
import dev.inmo.micro_utils.ktor.common.* import dev.inmo.micro_utils.ktor.common.*
import dev.inmo.micro_utils.pagination.* import dev.inmo.micro_utils.pagination.*
import dev.inmo.micro_utils.repos.ReadStandardKeyValueRepo import dev.inmo.micro_utils.repos.ReadKeyValueRepo
import dev.inmo.micro_utils.repos.ktor.common.* import dev.inmo.micro_utils.repos.ktor.common.*
import dev.inmo.micro_utils.repos.ktor.common.containsRoute import dev.inmo.micro_utils.repos.ktor.common.containsRoute
import dev.inmo.micro_utils.repos.ktor.common.key_value.* import dev.inmo.micro_utils.repos.ktor.common.key_value.*
@ -15,7 +15,7 @@ import io.ktor.util.reflect.TypeInfo
import io.ktor.util.reflect.typeInfo import io.ktor.util.reflect.typeInfo
import kotlinx.serialization.* import kotlinx.serialization.*
class KtorReadStandardKeyValueRepoClient<Key, Value>( class KtorReadKeyValueRepoClient<Key, Value>(
private val baseUrl: String, private val baseUrl: String,
private val httpClient: HttpClient, private val httpClient: HttpClient,
private val contentType: ContentType, private val contentType: ContentType,
@ -24,7 +24,7 @@ class KtorReadStandardKeyValueRepoClient<Key, Value>(
private val paginationResultIdsTypeInfo: TypeInfo, private val paginationResultIdsTypeInfo: TypeInfo,
private val idSerializer: suspend (Key) -> String, private val idSerializer: suspend (Key) -> String,
private val valueSerializer: suspend (Value) -> String private val valueSerializer: suspend (Value) -> String
) : ReadStandardKeyValueRepo<Key, Value> { ) : ReadKeyValueRepo<Key, Value> {
override suspend fun get(k: Key): Value? = httpClient.get( override suspend fun get(k: Key): Value? = httpClient.get(
buildStandardUrl( buildStandardUrl(
baseUrl, baseUrl,
@ -89,13 +89,13 @@ class KtorReadStandardKeyValueRepoClient<Key, Value>(
}.body() }.body()
} }
inline fun <reified Key, reified Value> KtorReadStandardKeyValueRepoClient( inline fun <reified Key, reified Value> KtorReadKeyValueRepoClient(
baseUrl: String, baseUrl: String,
httpClient: HttpClient, httpClient: HttpClient,
contentType: ContentType, contentType: ContentType,
noinline idSerializer: suspend (Key) -> String, noinline idSerializer: suspend (Key) -> String,
noinline valueSerializer: suspend (Value) -> String noinline valueSerializer: suspend (Value) -> String
) = KtorReadStandardKeyValueRepoClient<Key, Value>( ) = KtorReadKeyValueRepoClient<Key, Value>(
baseUrl, baseUrl,
httpClient, httpClient,
contentType, contentType,
@ -106,14 +106,14 @@ inline fun <reified Key, reified Value> KtorReadStandardKeyValueRepoClient(
valueSerializer valueSerializer
) )
inline fun <reified Key, reified Value> KtorReadStandardKeyValueRepoClient( inline fun <reified Key, reified Value> KtorReadKeyValueRepoClient(
baseUrl: String, baseUrl: String,
httpClient: HttpClient, httpClient: HttpClient,
idsSerializer: KSerializer<Key>, idsSerializer: KSerializer<Key>,
valueSerializer: KSerializer<Value>, valueSerializer: KSerializer<Value>,
serialFormat: StringFormat, serialFormat: StringFormat,
contentType: ContentType, contentType: ContentType,
) = KtorReadStandardKeyValueRepoClient<Key, Value>( ) = KtorReadKeyValueRepoClient<Key, Value>(
baseUrl, baseUrl,
httpClient, httpClient,
contentType, contentType,
@ -124,14 +124,14 @@ inline fun <reified Key, reified Value> KtorReadStandardKeyValueRepoClient(
serialFormat.encodeToString(valueSerializer, it).encodeURLQueryComponent() serialFormat.encodeToString(valueSerializer, it).encodeURLQueryComponent()
} }
inline fun <reified Key, reified Value> KtorReadStandardKeyValueRepoClient( inline fun <reified Key, reified Value> KtorReadKeyValueRepoClient(
baseUrl: String, baseUrl: String,
httpClient: HttpClient, httpClient: HttpClient,
idsSerializer: KSerializer<Key>, idsSerializer: KSerializer<Key>,
valuesSerializer: KSerializer<Value>, valuesSerializer: KSerializer<Value>,
serialFormat: BinaryFormat, serialFormat: BinaryFormat,
contentType: ContentType, contentType: ContentType,
) = KtorReadStandardKeyValueRepoClient<Key, Value>( ) = KtorReadKeyValueRepoClient<Key, Value>(
baseUrl, baseUrl,
httpClient, httpClient,
contentType, contentType,

View File

@ -3,7 +3,7 @@ package dev.inmo.micro_utils.repos.ktor.client.key_value
import dev.inmo.micro_utils.ktor.client.* import dev.inmo.micro_utils.ktor.client.*
import dev.inmo.micro_utils.ktor.common.* import dev.inmo.micro_utils.ktor.common.*
import dev.inmo.micro_utils.pagination.* import dev.inmo.micro_utils.pagination.*
import dev.inmo.micro_utils.repos.ReadStandardKeyValueRepo import dev.inmo.micro_utils.repos.ReadKeyValueRepo
import dev.inmo.micro_utils.repos.ktor.common.* import dev.inmo.micro_utils.repos.ktor.common.*
import dev.inmo.micro_utils.repos.ktor.common.containsRoute import dev.inmo.micro_utils.repos.ktor.common.containsRoute
import dev.inmo.micro_utils.repos.ktor.common.countRoute import dev.inmo.micro_utils.repos.ktor.common.countRoute
@ -14,13 +14,14 @@ import io.ktor.client.HttpClient
import kotlinx.serialization.* import kotlinx.serialization.*
import kotlinx.serialization.builtins.serializer import kotlinx.serialization.builtins.serializer
@Deprecated("Replaced with KtorReadKeyValueRepoClient")
class KtorReadStandardKeyValueRepo<Key, Value> ( class KtorReadStandardKeyValueRepo<Key, Value> (
private val baseUrl: String, private val baseUrl: String,
private val unifiedRequester: UnifiedRequester, private val unifiedRequester: UnifiedRequester,
private val keySerializer: KSerializer<Key>, private val keySerializer: KSerializer<Key>,
private val valueSerializer: KSerializer<Value>, private val valueSerializer: KSerializer<Value>,
private val valueNullableSerializer: KSerializer<Value?> private val valueNullableSerializer: KSerializer<Value?>
) : ReadStandardKeyValueRepo<Key, Value> { ) : ReadKeyValueRepo<Key, Value> {
constructor( constructor(
baseUrl: String, baseUrl: String,
client: HttpClient, client: HttpClient,

View File

@ -7,6 +7,7 @@ import dev.inmo.micro_utils.repos.*
import io.ktor.client.HttpClient import io.ktor.client.HttpClient
import kotlinx.serialization.* import kotlinx.serialization.*
@Deprecated("Replaced with KtorKeyValueRepoClient")
@Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE") @Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE")
class KtorStandartKeyValueRepo<K, V> ( class KtorStandartKeyValueRepo<K, V> (
baseUrl: String, baseUrl: String,
@ -15,15 +16,15 @@ class KtorStandartKeyValueRepo<K, V> (
keySerializer: KSerializer<K>, keySerializer: KSerializer<K>,
valueSerializer: KSerializer<V>, valueSerializer: KSerializer<V>,
valueNullableSerializer: KSerializer<V?> valueNullableSerializer: KSerializer<V?>
) : StandardKeyValueRepo<K, V>, ) : KeyValueRepo<K, V>,
ReadStandardKeyValueRepo<K, V> by KtorReadStandardKeyValueRepo( ReadKeyValueRepo<K, V> by KtorReadStandardKeyValueRepo(
"$baseUrl/$baseSubpart", "$baseUrl/$baseSubpart",
unifiedRequester, unifiedRequester,
keySerializer, keySerializer,
valueSerializer, valueSerializer,
valueNullableSerializer valueNullableSerializer
), ),
WriteStandardKeyValueRepo<K, V> by KtorWriteStandardKeyValueRepo( WriteKeyValueRepo<K, V> by KtorWriteStandardKeyValueRepo(
"$baseUrl/$baseSubpart", "$baseUrl/$baseSubpart",
unifiedRequester, unifiedRequester,
keySerializer, keySerializer,

View File

@ -3,7 +3,7 @@ package dev.inmo.micro_utils.repos.ktor.client.key_value
import dev.inmo.micro_utils.ktor.client.createStandardWebsocketFlow import dev.inmo.micro_utils.ktor.client.createStandardWebsocketFlow
import dev.inmo.micro_utils.ktor.client.throwOnUnsuccess import dev.inmo.micro_utils.ktor.client.throwOnUnsuccess
import dev.inmo.micro_utils.ktor.common.* import dev.inmo.micro_utils.ktor.common.*
import dev.inmo.micro_utils.repos.WriteStandardKeyValueRepo import dev.inmo.micro_utils.repos.WriteKeyValueRepo
import dev.inmo.micro_utils.repos.ktor.common.key_value.* import dev.inmo.micro_utils.repos.ktor.common.key_value.*
import io.ktor.client.HttpClient import io.ktor.client.HttpClient
import io.ktor.client.request.post import io.ktor.client.request.post
@ -13,7 +13,7 @@ import io.ktor.util.reflect.TypeInfo
import io.ktor.util.reflect.typeInfo import io.ktor.util.reflect.typeInfo
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
class KtorWriteStandardKeyValueRepoClient<Key, Value>( class KtorWriteKeyValueRepoClient<Key, Value>(
private val baseUrl: String, private val baseUrl: String,
private val httpClient: HttpClient, private val httpClient: HttpClient,
private val contentType: ContentType, private val contentType: ContentType,
@ -22,7 +22,7 @@ class KtorWriteStandardKeyValueRepoClient<Key, Value>(
private val idsListTypeInfo: TypeInfo, private val idsListTypeInfo: TypeInfo,
private val objectsListTypeInfo: TypeInfo, private val objectsListTypeInfo: TypeInfo,
private val idsToObjectsMapTypeInfo: TypeInfo private val idsToObjectsMapTypeInfo: TypeInfo
) : WriteStandardKeyValueRepo<Key, Value> { ) : WriteKeyValueRepo<Key, Value> {
@OptIn(InternalAPI::class) @OptIn(InternalAPI::class)
override suspend fun unsetWithValues(toUnset: List<Value>) { override suspend fun unsetWithValues(toUnset: List<Value>) {
httpClient.post( httpClient.post(
@ -61,7 +61,7 @@ class KtorWriteStandardKeyValueRepoClient<Key, Value>(
baseUrl: String, baseUrl: String,
httpClient: HttpClient, httpClient: HttpClient,
contentType: ContentType contentType: ContentType
) = KtorWriteStandardKeyValueRepoClient<Key, Value>( ) = KtorWriteKeyValueRepoClient<Key, Value>(
baseUrl, baseUrl,
httpClient, httpClient,
contentType, contentType,

View File

@ -2,19 +2,20 @@ package dev.inmo.micro_utils.repos.ktor.client.key_value
import dev.inmo.micro_utils.ktor.client.* import dev.inmo.micro_utils.ktor.client.*
import dev.inmo.micro_utils.ktor.common.* import dev.inmo.micro_utils.ktor.common.*
import dev.inmo.micro_utils.repos.WriteStandardKeyValueRepo import dev.inmo.micro_utils.repos.WriteKeyValueRepo
import dev.inmo.micro_utils.repos.ktor.common.key_value.* import dev.inmo.micro_utils.repos.ktor.common.key_value.*
import io.ktor.client.HttpClient import io.ktor.client.HttpClient
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.serialization.KSerializer import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.* import kotlinx.serialization.builtins.*
@Deprecated("Replaced with KtorWriteKeyValueRepoClient")
class KtorWriteStandardKeyValueRepo<K, V> ( class KtorWriteStandardKeyValueRepo<K, V> (
private var baseUrl: String, private var baseUrl: String,
private var unifiedRequester: UnifiedRequester, private var unifiedRequester: UnifiedRequester,
private var keySerializer: KSerializer<K>, private var keySerializer: KSerializer<K>,
private var valueSerializer: KSerializer<V>, private var valueSerializer: KSerializer<V>,
) : WriteStandardKeyValueRepo<K, V> { ) : WriteKeyValueRepo<K, V> {
private val keyValueMapSerializer = MapSerializer(keySerializer, valueSerializer) private val keyValueMapSerializer = MapSerializer(keySerializer, valueSerializer)
private val keysListSerializer = ListSerializer(keySerializer) private val keysListSerializer = ListSerializer(keySerializer)
private val valuesListSerializer = ListSerializer(valueSerializer) private val valuesListSerializer = ListSerializer(valueSerializer)

View File

@ -1,8 +1,8 @@
import dev.inmo.micro_utils.pagination.firstPageWithOneElementPagination import dev.inmo.micro_utils.pagination.firstPageWithOneElementPagination
import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging
import dev.inmo.micro_utils.repos.* import dev.inmo.micro_utils.repos.*
import dev.inmo.micro_utils.repos.ktor.client.key_value.KtorStandardKeyValueRepoClient import dev.inmo.micro_utils.repos.ktor.client.key_value.KtorKeyValueRepoClient
import dev.inmo.micro_utils.repos.ktor.server.key_value.configureStandardKeyValueRepoRoutes import dev.inmo.micro_utils.repos.ktor.server.key_value.configureKeyValueRepoRoutes
import io.ktor.client.HttpClient import io.ktor.client.HttpClient
import io.ktor.client.plugins.logging.Logging import io.ktor.client.plugins.logging.Logging
import io.ktor.http.ContentType import io.ktor.http.ContentType
@ -38,7 +38,7 @@ class KVTests {
contentConverter = KotlinxWebsocketSerializationConverter(Json) contentConverter = KotlinxWebsocketSerializationConverter(Json)
} }
routing { routing {
configureStandardKeyValueRepoRoutes( configureKeyValueRepoRoutes(
repo, repo,
Int.serializer(), Int.serializer(),
ComplexData.serializer(), ComplexData.serializer(),
@ -55,7 +55,7 @@ class KVTests {
contentConverter = KotlinxWebsocketSerializationConverter(Json) contentConverter = KotlinxWebsocketSerializationConverter(Json)
} }
} }
val crudClient = KtorStandardKeyValueRepoClient<Int, ComplexData>( val crudClient = KtorKeyValueRepoClient<Int, ComplexData>(
"http://127.0.0.1:23456", "http://127.0.0.1:23456",
client, client,
ContentType.Application.Json, ContentType.Application.Json,

View File

@ -1,7 +1,6 @@
import dev.inmo.micro_utils.pagination.firstPageWithOneElementPagination import dev.inmo.micro_utils.pagination.firstPageWithOneElementPagination
import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging
import dev.inmo.micro_utils.repos.* import dev.inmo.micro_utils.repos.*
import dev.inmo.micro_utils.repos.ktor.client.key_value.KtorStandardKeyValueRepoClient
import dev.inmo.micro_utils.repos.ktor.client.one_to_many.KtorStandardKeyValuesRepoClient import dev.inmo.micro_utils.repos.ktor.client.one_to_many.KtorStandardKeyValuesRepoClient
import dev.inmo.micro_utils.repos.ktor.server.one_to_many.configureStandardKeyValuesRepoRoutes import dev.inmo.micro_utils.repos.ktor.server.one_to_many.configureStandardKeyValuesRepoRoutes
import io.ktor.client.HttpClient import io.ktor.client.HttpClient

View File

@ -4,15 +4,15 @@ import dev.inmo.micro_utils.ktor.common.StandardKtorSerialFormat
import dev.inmo.micro_utils.ktor.common.standardKtorSerialFormat import dev.inmo.micro_utils.ktor.common.standardKtorSerialFormat
import dev.inmo.micro_utils.ktor.server.UnifiedRouter import dev.inmo.micro_utils.ktor.server.UnifiedRouter
import dev.inmo.micro_utils.ktor.server.standardKtorSerialFormatContentType import dev.inmo.micro_utils.ktor.server.standardKtorSerialFormatContentType
import dev.inmo.micro_utils.repos.StandardKeyValueRepo import dev.inmo.micro_utils.repos.KeyValueRepo
import io.ktor.http.ContentType import io.ktor.http.ContentType
import io.ktor.server.routing.Route import io.ktor.server.routing.Route
import io.ktor.server.routing.route import io.ktor.server.routing.route
import kotlinx.serialization.KSerializer import kotlinx.serialization.KSerializer
fun <K, V> Route.configureStandardKeyValueRepoRoutes( fun <K, V> Route.configureKeyValueRepoRoutes(
baseSubpart: String, baseSubpart: String,
originalRepo: StandardKeyValueRepo<K, V>, originalRepo: KeyValueRepo<K, V>,
keySerializer: KSerializer<K>, keySerializer: KSerializer<K>,
valueSerializer: KSerializer<V>, valueSerializer: KSerializer<V>,
valueNullableSerializer: KSerializer<V?>, valueNullableSerializer: KSerializer<V?>,
@ -26,7 +26,7 @@ fun <K, V> Route.configureStandardKeyValueRepoRoutes(
valueNullableSerializer, valueNullableSerializer,
unifiedRouter unifiedRouter
) )
configureWriteStandardKeyValueRepoRoutes( configureWriteValueRepoRoutes(
originalRepo, originalRepo,
keySerializer, keySerializer,
valueSerializer, valueSerializer,
@ -37,10 +37,10 @@ fun <K, V> Route.configureStandardKeyValueRepoRoutes(
fun <K, V> Route.configureStandartKeyValueRepoRoutes( fun <K, V> Route.configureStandartKeyValueRepoRoutes(
baseSubpart: String, baseSubpart: String,
originalRepo: StandardKeyValueRepo<K, V>, originalRepo: KeyValueRepo<K, V>,
keySerializer: KSerializer<K>, keySerializer: KSerializer<K>,
valueSerializer: KSerializer<V>, valueSerializer: KSerializer<V>,
valueNullableSerializer: KSerializer<V?>, valueNullableSerializer: KSerializer<V?>,
serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat, serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat,
serialFormatContentType: ContentType = standardKtorSerialFormatContentType serialFormatContentType: ContentType = standardKtorSerialFormatContentType
) = configureStandardKeyValueRepoRoutes(baseSubpart, originalRepo, keySerializer, valueSerializer, valueNullableSerializer, UnifiedRouter(serialFormat, serialFormatContentType)) ) = configureKeyValueRepoRoutes(baseSubpart, originalRepo, keySerializer, valueSerializer, valueNullableSerializer, UnifiedRouter(serialFormat, serialFormatContentType))

View File

@ -5,7 +5,7 @@ import dev.inmo.micro_utils.ktor.common.standardKtorSerialFormat
import dev.inmo.micro_utils.ktor.server.* import dev.inmo.micro_utils.ktor.server.*
import dev.inmo.micro_utils.pagination.PaginationResult import dev.inmo.micro_utils.pagination.PaginationResult
import dev.inmo.micro_utils.pagination.extractPagination import dev.inmo.micro_utils.pagination.extractPagination
import dev.inmo.micro_utils.repos.ReadStandardKeyValueRepo import dev.inmo.micro_utils.repos.ReadKeyValueRepo
import dev.inmo.micro_utils.repos.ktor.common.* import dev.inmo.micro_utils.repos.ktor.common.*
import dev.inmo.micro_utils.repos.ktor.common.containsRoute import dev.inmo.micro_utils.repos.ktor.common.containsRoute
import dev.inmo.micro_utils.repos.ktor.common.countRoute import dev.inmo.micro_utils.repos.ktor.common.countRoute
@ -20,7 +20,7 @@ import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.serializer import kotlinx.serialization.builtins.serializer
fun <K, V> Route.configureReadStandartKeyValueRepoRoutes ( fun <K, V> Route.configureReadStandartKeyValueRepoRoutes (
originalRepo: ReadStandardKeyValueRepo<K, V>, originalRepo: ReadKeyValueRepo<K, V>,
keySerializer: KSerializer<K>, keySerializer: KSerializer<K>,
valueSerializer: KSerializer<V>, valueSerializer: KSerializer<V>,
valueNullableSerializer: KSerializer<V?>, valueNullableSerializer: KSerializer<V?>,
@ -96,7 +96,7 @@ fun <K, V> Route.configureReadStandartKeyValueRepoRoutes (
} }
inline fun <K, V> Route.configureReadStandartKeyValueRepoRoutes ( inline fun <K, V> Route.configureReadStandartKeyValueRepoRoutes (
originalRepo: ReadStandardKeyValueRepo<K, V>, originalRepo: ReadKeyValueRepo<K, V>,
keySerializer: KSerializer<K>, keySerializer: KSerializer<K>,
valueSerializer: KSerializer<V>, valueSerializer: KSerializer<V>,
valueNullableSerializer: KSerializer<V?>, valueNullableSerializer: KSerializer<V?>,

View File

@ -3,7 +3,7 @@ package dev.inmo.micro_utils.repos.ktor.server.key_value
import dev.inmo.micro_utils.ktor.common.StandardKtorSerialFormat import dev.inmo.micro_utils.ktor.common.StandardKtorSerialFormat
import dev.inmo.micro_utils.ktor.common.standardKtorSerialFormat import dev.inmo.micro_utils.ktor.common.standardKtorSerialFormat
import dev.inmo.micro_utils.ktor.server.* import dev.inmo.micro_utils.ktor.server.*
import dev.inmo.micro_utils.repos.WriteStandardKeyValueRepo import dev.inmo.micro_utils.repos.WriteKeyValueRepo
import dev.inmo.micro_utils.repos.ktor.common.key_value.* import dev.inmo.micro_utils.repos.ktor.common.key_value.*
import io.ktor.http.ContentType import io.ktor.http.ContentType
import io.ktor.server.routing.Route import io.ktor.server.routing.Route
@ -11,8 +11,8 @@ import io.ktor.server.routing.post
import kotlinx.serialization.KSerializer import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.* import kotlinx.serialization.builtins.*
fun <K, V> Route.configureWriteStandardKeyValueRepoRoutes ( fun <K, V> Route.configureWriteValueRepoRoutes (
originalRepo: WriteStandardKeyValueRepo<K, V>, originalRepo: WriteKeyValueRepo<K, V>,
keySerializer: KSerializer<K>, keySerializer: KSerializer<K>,
valueSerializer: KSerializer<V>, valueSerializer: KSerializer<V>,
unifiedRouter: UnifiedRouter unifiedRouter: UnifiedRouter
@ -62,9 +62,9 @@ fun <K, V> Route.configureWriteStandardKeyValueRepoRoutes (
} }
fun <K, V> Route.configureWriteStandartKeyValueRepoRoutes ( fun <K, V> Route.configureWriteStandartKeyValueRepoRoutes (
originalRepo: WriteStandardKeyValueRepo<K, V>, originalRepo: WriteKeyValueRepo<K, V>,
keySerializer: KSerializer<K>, keySerializer: KSerializer<K>,
valueSerializer: KSerializer<V>, valueSerializer: KSerializer<V>,
serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat, serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat,
serialFormatContentType: ContentType = standardKtorSerialFormatContentType serialFormatContentType: ContentType = standardKtorSerialFormatContentType
) = configureWriteStandardKeyValueRepoRoutes(originalRepo, keySerializer, valueSerializer, UnifiedRouter(serialFormat, serialFormatContentType)) ) = configureWriteValueRepoRoutes(originalRepo, keySerializer, valueSerializer, UnifiedRouter(serialFormat, serialFormatContentType))

View File

@ -1,37 +1,26 @@
package dev.inmo.micro_utils.repos.ktor.server.key_value package dev.inmo.micro_utils.repos.ktor.server.key_value
import dev.inmo.micro_utils.ktor.common.* import dev.inmo.micro_utils.ktor.common.*
import dev.inmo.micro_utils.ktor.server.* import dev.inmo.micro_utils.repos.KeyValueRepo
import dev.inmo.micro_utils.pagination.PaginationResult
import dev.inmo.micro_utils.pagination.extractPagination
import dev.inmo.micro_utils.repos.StandardCRUDRepo
import dev.inmo.micro_utils.repos.StandardKeyValueRepo
import dev.inmo.micro_utils.repos.ktor.common.idParameterName
import dev.inmo.micro_utils.repos.ktor.common.key_value.*
import dev.inmo.micro_utils.repos.ktor.common.valueParameterName
import io.ktor.http.* import io.ktor.http.*
import io.ktor.server.application.call
import io.ktor.server.response.respond
import io.ktor.server.routing.Route import io.ktor.server.routing.Route
import io.ktor.server.routing.get
import kotlinx.serialization.* import kotlinx.serialization.*
import kotlinx.serialization.builtins.serializer
inline fun <reified Key : Any, reified Value : Any> Route.configureStandardKeyValueRepoRoutes ( inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValueRepoRoutes (
originalRepo: StandardKeyValueRepo<Key, Value>, originalRepo: KeyValueRepo<Key, Value>,
noinline idDeserializer: suspend (String) -> Key, noinline idDeserializer: suspend (String) -> Key,
noinline valueDeserializer: suspend (String) -> Value noinline valueDeserializer: suspend (String) -> Value
) { ) {
configureReadStandardKeyValueRepoRoutes(originalRepo, idDeserializer, valueDeserializer) configureReadKeyValueRepoRoutes(originalRepo, idDeserializer, valueDeserializer)
configureWriteStandardKeyValueRepoRoutes(originalRepo) configureWriteValueRepoRoutes(originalRepo)
} }
inline fun <reified Key : Any, reified Value : Any> Route.configureStandardKeyValueRepoRoutes( inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValueRepoRoutes(
originalRepo: StandardKeyValueRepo<Key, Value>, originalRepo: KeyValueRepo<Key, Value>,
idsSerializer: DeserializationStrategy<Key>, idsSerializer: DeserializationStrategy<Key>,
valueSerializer: DeserializationStrategy<Value>, valueSerializer: DeserializationStrategy<Value>,
serialFormat: StringFormat serialFormat: StringFormat
) = configureStandardKeyValueRepoRoutes( ) = configureKeyValueRepoRoutes(
originalRepo, originalRepo,
{ {
serialFormat.decodeFromString(idsSerializer, it.decodeURLQueryComponent()) serialFormat.decodeFromString(idsSerializer, it.decodeURLQueryComponent())
@ -41,12 +30,12 @@ inline fun <reified Key : Any, reified Value : Any> Route.configureStandardKeyVa
} }
) )
inline fun <reified Key : Any, reified Value : Any> Route.configureStandardKeyValueRepoRoutes( inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValueRepoRoutes(
originalRepo: StandardKeyValueRepo<Key, Value>, originalRepo: KeyValueRepo<Key, Value>,
idsSerializer: DeserializationStrategy<Key>, idsSerializer: DeserializationStrategy<Key>,
valueSerializer: DeserializationStrategy<Value>, valueSerializer: DeserializationStrategy<Value>,
serialFormat: BinaryFormat serialFormat: BinaryFormat
) = configureStandardKeyValueRepoRoutes( ) = configureKeyValueRepoRoutes(
originalRepo, originalRepo,
{ {
serialFormat.decodeHex(idsSerializer, it) serialFormat.decodeHex(idsSerializer, it)

View File

@ -4,7 +4,7 @@ import dev.inmo.micro_utils.ktor.common.*
import dev.inmo.micro_utils.ktor.server.* import dev.inmo.micro_utils.ktor.server.*
import dev.inmo.micro_utils.pagination.PaginationResult import dev.inmo.micro_utils.pagination.PaginationResult
import dev.inmo.micro_utils.pagination.extractPagination import dev.inmo.micro_utils.pagination.extractPagination
import dev.inmo.micro_utils.repos.ReadStandardKeyValueRepo import dev.inmo.micro_utils.repos.ReadKeyValueRepo
import dev.inmo.micro_utils.repos.ktor.common.* import dev.inmo.micro_utils.repos.ktor.common.*
import dev.inmo.micro_utils.repos.ktor.common.containsRoute import dev.inmo.micro_utils.repos.ktor.common.containsRoute
import dev.inmo.micro_utils.repos.ktor.common.countRoute import dev.inmo.micro_utils.repos.ktor.common.countRoute
@ -20,8 +20,8 @@ import io.ktor.util.reflect.typeInfo
import kotlinx.serialization.* import kotlinx.serialization.*
@OptIn(InternalAPI::class) @OptIn(InternalAPI::class)
inline fun <reified Key, reified Value> Route.configureReadStandardKeyValueRepoRoutes ( inline fun <reified Key, reified Value> Route.configureReadKeyValueRepoRoutes (
originalRepo: ReadStandardKeyValueRepo<Key, Value>, originalRepo: ReadKeyValueRepo<Key, Value>,
noinline idDeserializer: suspend (String) -> Key, noinline idDeserializer: suspend (String) -> Key,
noinline valueDeserializer: suspend (String) -> Value noinline valueDeserializer: suspend (String) -> Value
) { ) {
@ -74,12 +74,12 @@ inline fun <reified Key, reified Value> Route.configureReadStandardKeyValueRepoR
} }
} }
inline fun <reified Key, reified Value> Route.configureReadStandardKeyValueRepoRoutes( inline fun <reified Key, reified Value> Route.configureReadKeyValueRepoRoutes(
originalRepo: ReadStandardKeyValueRepo<Key, Value>, originalRepo: ReadKeyValueRepo<Key, Value>,
idsSerializer: DeserializationStrategy<Key>, idsSerializer: DeserializationStrategy<Key>,
valueSerializer: DeserializationStrategy<Value>, valueSerializer: DeserializationStrategy<Value>,
serialFormat: StringFormat serialFormat: StringFormat
) = configureReadStandardKeyValueRepoRoutes( ) = configureReadKeyValueRepoRoutes(
originalRepo, originalRepo,
{ {
serialFormat.decodeFromString(idsSerializer, it.decodeURLQueryComponent()) serialFormat.decodeFromString(idsSerializer, it.decodeURLQueryComponent())
@ -89,12 +89,12 @@ inline fun <reified Key, reified Value> Route.configureReadStandardKeyValueRepoR
} }
) )
inline fun <reified Key, reified Value> Route.configureReadStandardKeyValueRepoRoutes( inline fun <reified Key, reified Value> Route.configureReadKeyValueRepoRoutes(
originalRepo: ReadStandardKeyValueRepo<Key, Value>, originalRepo: ReadKeyValueRepo<Key, Value>,
idsSerializer: DeserializationStrategy<Key>, idsSerializer: DeserializationStrategy<Key>,
valueSerializer: DeserializationStrategy<Value>, valueSerializer: DeserializationStrategy<Value>,
serialFormat: BinaryFormat serialFormat: BinaryFormat
) = configureReadStandardKeyValueRepoRoutes( ) = configureReadKeyValueRepoRoutes(
originalRepo, originalRepo,
{ {
serialFormat.decodeHex(idsSerializer, it) serialFormat.decodeHex(idsSerializer, it)

View File

@ -1,7 +1,7 @@
package dev.inmo.micro_utils.repos.ktor.server.key_value package dev.inmo.micro_utils.repos.ktor.server.key_value
import dev.inmo.micro_utils.ktor.server.* import dev.inmo.micro_utils.ktor.server.*
import dev.inmo.micro_utils.repos.WriteStandardKeyValueRepo import dev.inmo.micro_utils.repos.WriteKeyValueRepo
import dev.inmo.micro_utils.repos.ktor.common.key_value.* import dev.inmo.micro_utils.repos.ktor.common.key_value.*
import io.ktor.http.HttpStatusCode import io.ktor.http.HttpStatusCode
import io.ktor.server.application.call import io.ktor.server.application.call
@ -11,8 +11,8 @@ import io.ktor.server.routing.Route
import io.ktor.server.routing.post import io.ktor.server.routing.post
import io.ktor.util.reflect.typeInfo import io.ktor.util.reflect.typeInfo
inline fun <reified Key : Any, reified Value : Any> Route.configureWriteStandardKeyValueRepoRoutes ( inline fun <reified Key : Any, reified Value : Any> Route.configureWriteValueRepoRoutes (
originalRepo: WriteStandardKeyValueRepo<Key, Value> originalRepo: WriteKeyValueRepo<Key, Value>
) { ) {
includeWebsocketHandling( includeWebsocketHandling(
onNewValueRoute, onNewValueRoute,