mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-26 03:58:45 +00:00
renames in kevalues repos
This commit is contained in:
parent
18593c530b
commit
8d955c4b9d
@ -8,8 +8,6 @@ import dev.inmo.micro_utils.repos.*
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
|
||||
open class ReadKeyValuesCacheRepo<Key,Value>(
|
||||
protected val parentRepo: ReadKeyValuesRepo<Key, Value>,
|
||||
|
@ -1,11 +1,10 @@
|
||||
package dev.inmo.micro_utils.repos
|
||||
|
||||
import dev.inmo.micro_utils.pagination.*
|
||||
import dev.inmo.micro_utils.pagination.utils.doForAllWithCurrentPaging
|
||||
import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface ReadOneToManyKeyValueRepo<Key, Value> : Repo {
|
||||
interface ReadKeyValuesRepo<Key, Value> : Repo {
|
||||
suspend fun get(k: Key, pagination: Pagination, reversed: Boolean = false): PaginationResult<Value>
|
||||
suspend fun keys(pagination: Pagination, reversed: Boolean = false): PaginationResult<Key>
|
||||
suspend fun keys(v: Value, pagination: Pagination, reversed: Boolean = false): PaginationResult<Key>
|
||||
@ -36,9 +35,9 @@ interface ReadOneToManyKeyValueRepo<Key, Value> : Repo {
|
||||
}
|
||||
}
|
||||
}
|
||||
typealias ReadKeyValuesRepo<Key,Value> = ReadOneToManyKeyValueRepo<Key, Value>
|
||||
typealias ReadOneToManyKeyValueRepo<Key,Value> = ReadKeyValuesRepo<Key, Value>
|
||||
|
||||
interface WriteOneToManyKeyValueRepo<Key, Value> : Repo {
|
||||
interface WriteKeyValuesRepo<Key, Value> : Repo {
|
||||
val onNewValue: Flow<Pair<Key, Value>>
|
||||
val onValueRemoved: Flow<Pair<Key, Value>>
|
||||
val onDataCleared: Flow<Key>
|
||||
@ -55,41 +54,41 @@ interface WriteOneToManyKeyValueRepo<Key, Value> : Repo {
|
||||
add(toSet)
|
||||
}
|
||||
}
|
||||
typealias WriteKeyValuesRepo<Key,Value> = WriteOneToManyKeyValueRepo<Key, Value>
|
||||
typealias WriteOneToManyKeyValueRepo<Key,Value> = WriteKeyValuesRepo<Key, Value>
|
||||
|
||||
suspend inline fun <Key, Value, REPO : WriteOneToManyKeyValueRepo<Key, Value>> REPO.add(
|
||||
suspend inline fun <Key, Value, REPO : WriteKeyValuesRepo<Key, Value>> REPO.add(
|
||||
keysAndValues: List<Pair<Key, List<Value>>>
|
||||
) = add(keysAndValues.toMap())
|
||||
|
||||
suspend inline fun <Key, Value, REPO : WriteOneToManyKeyValueRepo<Key, Value>> REPO.add(
|
||||
suspend inline fun <Key, Value, REPO : WriteKeyValuesRepo<Key, Value>> REPO.add(
|
||||
vararg keysAndValues: Pair<Key, List<Value>>
|
||||
) = add(keysAndValues.toMap())
|
||||
|
||||
suspend inline fun <Key, Value> WriteOneToManyKeyValueRepo<Key, Value>.add(
|
||||
suspend inline fun <Key, Value> WriteKeyValuesRepo<Key, Value>.add(
|
||||
k: Key, v: List<Value>
|
||||
) = add(mapOf(k to v))
|
||||
|
||||
suspend inline fun <Key, Value> WriteOneToManyKeyValueRepo<Key, Value>.add(
|
||||
suspend inline fun <Key, Value> WriteKeyValuesRepo<Key, Value>.add(
|
||||
k: Key, vararg v: Value
|
||||
) = add(k, v.toList())
|
||||
|
||||
suspend inline fun <Key, Value, REPO : WriteOneToManyKeyValueRepo<Key, Value>> REPO.set(
|
||||
suspend inline fun <Key, Value, REPO : WriteKeyValuesRepo<Key, Value>> REPO.set(
|
||||
keysAndValues: List<Pair<Key, List<Value>>>
|
||||
) = set(keysAndValues.toMap())
|
||||
|
||||
suspend inline fun <Key, Value, REPO : WriteOneToManyKeyValueRepo<Key, Value>> REPO.set(
|
||||
suspend inline fun <Key, Value, REPO : WriteKeyValuesRepo<Key, Value>> REPO.set(
|
||||
vararg keysAndValues: Pair<Key, List<Value>>
|
||||
) = set(keysAndValues.toMap())
|
||||
|
||||
suspend inline fun <Key, Value> WriteOneToManyKeyValueRepo<Key, Value>.set(
|
||||
suspend inline fun <Key, Value> WriteKeyValuesRepo<Key, Value>.set(
|
||||
k: Key, v: List<Value>
|
||||
) = set(mapOf(k to v))
|
||||
|
||||
suspend inline fun <Key, Value> WriteOneToManyKeyValueRepo<Key, Value>.set(
|
||||
suspend inline fun <Key, Value> WriteKeyValuesRepo<Key, Value>.set(
|
||||
k: Key, vararg v: Value
|
||||
) = set(k, v.toList())
|
||||
|
||||
interface OneToManyKeyValueRepo<Key, Value> : ReadOneToManyKeyValueRepo<Key, Value>, WriteOneToManyKeyValueRepo<Key, Value> {
|
||||
interface KeyValuesRepo<Key, Value> : ReadKeyValuesRepo<Key, Value>, WriteKeyValuesRepo<Key, Value> {
|
||||
override suspend fun clearWithValue(v: Value) {
|
||||
doWithPagination {
|
||||
val keysResult = keys(v, it)
|
||||
@ -102,29 +101,29 @@ interface OneToManyKeyValueRepo<Key, Value> : ReadOneToManyKeyValueRepo<Key, Val
|
||||
}
|
||||
}
|
||||
}
|
||||
typealias KeyValuesRepo<Key,Value> = OneToManyKeyValueRepo<Key, Value>
|
||||
typealias OneToManyKeyValueRepo<Key,Value> = KeyValuesRepo<Key, Value>
|
||||
|
||||
class DelegateBasedOneToManyKeyValueRepo<Key, Value>(
|
||||
readDelegate: ReadOneToManyKeyValueRepo<Key, Value>,
|
||||
writeDelegate: WriteOneToManyKeyValueRepo<Key, Value>
|
||||
) : OneToManyKeyValueRepo<Key, Value>,
|
||||
ReadOneToManyKeyValueRepo<Key, Value> by readDelegate,
|
||||
WriteOneToManyKeyValueRepo<Key, Value> by writeDelegate
|
||||
class DelegateBasedKeyValuesRepo<Key, Value>(
|
||||
readDelegate: ReadKeyValuesRepo<Key, Value>,
|
||||
writeDelegate: WriteKeyValuesRepo<Key, Value>
|
||||
) : KeyValuesRepo<Key, Value>,
|
||||
ReadKeyValuesRepo<Key, Value> by readDelegate,
|
||||
WriteKeyValuesRepo<Key, Value> by writeDelegate
|
||||
|
||||
suspend inline fun <Key, Value> WriteOneToManyKeyValueRepo<Key, Value>.remove(
|
||||
suspend inline fun <Key, Value> WriteKeyValuesRepo<Key, Value>.remove(
|
||||
keysAndValues: List<Pair<Key, List<Value>>>
|
||||
) = remove(keysAndValues.toMap())
|
||||
|
||||
suspend inline fun <Key, Value> WriteOneToManyKeyValueRepo<Key, Value>.remove(
|
||||
suspend inline fun <Key, Value> WriteKeyValuesRepo<Key, Value>.remove(
|
||||
vararg keysAndValues: Pair<Key, List<Value>>
|
||||
) = remove(keysAndValues.toMap())
|
||||
|
||||
suspend inline fun <Key, Value> WriteOneToManyKeyValueRepo<Key, Value>.remove(
|
||||
suspend inline fun <Key, Value> WriteKeyValuesRepo<Key, Value>.remove(
|
||||
k: Key,
|
||||
v: List<Value>
|
||||
) = remove(mapOf(k to v))
|
||||
|
||||
suspend inline fun <Key, Value> WriteOneToManyKeyValueRepo<Key, Value>.remove(
|
||||
suspend inline fun <Key, Value> WriteKeyValuesRepo<Key, Value>.remove(
|
||||
k: Key,
|
||||
vararg v: Value
|
||||
) = remove(k, v.toList())
|
@ -6,10 +6,12 @@ import dev.inmo.micro_utils.repos.*
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
open class MapperReadOneToManyKeyValueRepo<FromKey, FromValue, ToKey, ToValue>(
|
||||
private val to: ReadOneToManyKeyValueRepo<ToKey, ToValue>,
|
||||
@Deprecated("Renamed", ReplaceWith("MapperReadKeyValuesRepo", "dev.inmo.micro_utils.repos.mappers.MapperReadKeyValuesRepo"))
|
||||
typealias MapperReadOneToManyKeyValueRepo<FromKey, FromValue, ToKey, ToValue> = MapperReadKeyValuesRepo<FromKey, FromValue, ToKey, ToValue>
|
||||
open class MapperReadKeyValuesRepo<FromKey, FromValue, ToKey, ToValue>(
|
||||
private val to: ReadKeyValuesRepo<ToKey, ToValue>,
|
||||
mapper: MapperRepo<FromKey, FromValue, ToKey, ToValue>
|
||||
) : ReadOneToManyKeyValueRepo<FromKey, FromValue>, MapperRepo<FromKey, FromValue, ToKey, ToValue> by mapper {
|
||||
) : ReadKeyValuesRepo<FromKey, FromValue>, MapperRepo<FromKey, FromValue, ToKey, ToValue> by mapper {
|
||||
override suspend fun get(
|
||||
k: FromKey,
|
||||
pagination: Pagination,
|
||||
@ -67,24 +69,26 @@ open class MapperReadOneToManyKeyValueRepo<FromKey, FromValue, ToKey, ToValue>(
|
||||
}
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun <FromKey, FromValue, ToKey, ToValue> ReadOneToManyKeyValueRepo<ToKey, ToValue>.withMapper(
|
||||
inline fun <FromKey, FromValue, ToKey, ToValue> ReadKeyValuesRepo<ToKey, ToValue>.withMapper(
|
||||
mapper: MapperRepo<FromKey, FromValue, ToKey, ToValue>
|
||||
): ReadOneToManyKeyValueRepo<FromKey, FromValue> = MapperReadOneToManyKeyValueRepo(this, mapper)
|
||||
): ReadKeyValuesRepo<FromKey, FromValue> = MapperReadKeyValuesRepo(this, mapper)
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun <reified FromKey, reified FromValue, reified ToKey, reified ToValue> ReadOneToManyKeyValueRepo<ToKey, ToValue>.withMapper(
|
||||
inline fun <reified FromKey, reified FromValue, reified ToKey, reified ToValue> ReadKeyValuesRepo<ToKey, ToValue>.withMapper(
|
||||
crossinline keyFromToTo: suspend FromKey.() -> ToKey = { this as ToKey },
|
||||
crossinline valueFromToTo: suspend FromValue.() -> ToValue = { this as ToValue },
|
||||
crossinline keyToToFrom: suspend ToKey.() -> FromKey = { this as FromKey },
|
||||
crossinline valueToToFrom: suspend ToValue.() -> FromValue = { this as FromValue },
|
||||
): ReadOneToManyKeyValueRepo<FromKey, FromValue> = withMapper(
|
||||
): ReadKeyValuesRepo<FromKey, FromValue> = withMapper(
|
||||
mapper(keyFromToTo, valueFromToTo, keyToToFrom, valueToToFrom)
|
||||
)
|
||||
|
||||
open class MapperWriteOneToManyKeyValueRepo<FromKey, FromValue, ToKey, ToValue>(
|
||||
private val to: WriteOneToManyKeyValueRepo<ToKey, ToValue>,
|
||||
@Deprecated("Renamed", ReplaceWith("MapperWriteKeyValuesRepo", "dev.inmo.micro_utils.repos.mappers.MapperWriteKeyValuesRepo"))
|
||||
typealias MapperWriteOneToManyKeyValueRepo<FromKey, FromValue, ToKey, ToValue> = MapperWriteKeyValuesRepo<FromKey, FromValue, ToKey, ToValue>
|
||||
open class MapperWriteKeyValuesRepo<FromKey, FromValue, ToKey, ToValue>(
|
||||
private val to: WriteKeyValuesRepo<ToKey, ToValue>,
|
||||
mapper: MapperRepo<FromKey, FromValue, ToKey, ToValue>
|
||||
) : WriteOneToManyKeyValueRepo<FromKey, FromValue>, MapperRepo<FromKey, FromValue, ToKey, ToValue> by mapper {
|
||||
) : WriteKeyValuesRepo<FromKey, FromValue>, MapperRepo<FromKey, FromValue, ToKey, ToValue> by mapper {
|
||||
override val onNewValue: Flow<Pair<FromKey, FromValue>> = to.onNewValue.map { (k, v) ->
|
||||
k.toInnerKey() to v.toInnerValue()
|
||||
}
|
||||
@ -118,40 +122,42 @@ open class MapperWriteOneToManyKeyValueRepo<FromKey, FromValue, ToKey, ToValue>(
|
||||
}
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun <FromKey, FromValue, ToKey, ToValue> WriteOneToManyKeyValueRepo<ToKey, ToValue>.withMapper(
|
||||
inline fun <FromKey, FromValue, ToKey, ToValue> WriteKeyValuesRepo<ToKey, ToValue>.withMapper(
|
||||
mapper: MapperRepo<FromKey, FromValue, ToKey, ToValue>
|
||||
): WriteOneToManyKeyValueRepo<FromKey, FromValue> = MapperWriteOneToManyKeyValueRepo(this, mapper)
|
||||
): WriteKeyValuesRepo<FromKey, FromValue> = MapperWriteKeyValuesRepo(this, mapper)
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun <reified FromKey, reified FromValue, reified ToKey, reified ToValue> WriteOneToManyKeyValueRepo<ToKey, ToValue>.withMapper(
|
||||
inline fun <reified FromKey, reified FromValue, reified ToKey, reified ToValue> WriteKeyValuesRepo<ToKey, ToValue>.withMapper(
|
||||
crossinline keyFromToTo: suspend FromKey.() -> ToKey = { this as ToKey },
|
||||
crossinline valueFromToTo: suspend FromValue.() -> ToValue = { this as ToValue },
|
||||
crossinline keyToToFrom: suspend ToKey.() -> FromKey = { this as FromKey },
|
||||
crossinline valueToToFrom: suspend ToValue.() -> FromValue = { this as FromValue },
|
||||
): WriteOneToManyKeyValueRepo<FromKey, FromValue> = withMapper(
|
||||
): WriteKeyValuesRepo<FromKey, FromValue> = withMapper(
|
||||
mapper(keyFromToTo, valueFromToTo, keyToToFrom, valueToToFrom)
|
||||
)
|
||||
|
||||
@Deprecated("Renamed", ReplaceWith("MapperKeyValuesRepo", "dev.inmo.micro_utils.repos.mappers.MapperKeyValuesRepo"))
|
||||
typealias MapperOneToManyKeyValueRepo<FromKey, FromValue, ToKey, ToValue> = MapperKeyValuesRepo<FromKey, FromValue, ToKey, ToValue>
|
||||
@Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE")
|
||||
open class MapperOneToManyKeyValueRepo<FromKey, FromValue, ToKey, ToValue>(
|
||||
private val to: OneToManyKeyValueRepo<ToKey, ToValue>,
|
||||
open class MapperKeyValuesRepo<FromKey, FromValue, ToKey, ToValue>(
|
||||
private val to: KeyValuesRepo<ToKey, ToValue>,
|
||||
mapper: MapperRepo<FromKey, FromValue, ToKey, ToValue>
|
||||
) : OneToManyKeyValueRepo<FromKey, FromValue>,
|
||||
) : KeyValuesRepo<FromKey, FromValue>,
|
||||
MapperRepo<FromKey, FromValue, ToKey, ToValue> by mapper,
|
||||
ReadOneToManyKeyValueRepo<FromKey, FromValue> by MapperReadOneToManyKeyValueRepo(to, mapper),
|
||||
WriteOneToManyKeyValueRepo<FromKey, FromValue> by MapperWriteOneToManyKeyValueRepo(to, mapper)
|
||||
ReadKeyValuesRepo<FromKey, FromValue> by MapperReadKeyValuesRepo(to, mapper),
|
||||
WriteKeyValuesRepo<FromKey, FromValue> by MapperWriteKeyValuesRepo(to, mapper)
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun <FromKey, FromValue, ToKey, ToValue> OneToManyKeyValueRepo<ToKey, ToValue>.withMapper(
|
||||
inline fun <FromKey, FromValue, ToKey, ToValue> KeyValuesRepo<ToKey, ToValue>.withMapper(
|
||||
mapper: MapperRepo<FromKey, FromValue, ToKey, ToValue>
|
||||
): OneToManyKeyValueRepo<FromKey, FromValue> = MapperOneToManyKeyValueRepo(this, mapper)
|
||||
): KeyValuesRepo<FromKey, FromValue> = MapperKeyValuesRepo(this, mapper)
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun <reified FromKey, reified FromValue, reified ToKey, reified ToValue> OneToManyKeyValueRepo<ToKey, ToValue>.withMapper(
|
||||
inline fun <reified FromKey, reified FromValue, reified ToKey, reified ToValue> KeyValuesRepo<ToKey, ToValue>.withMapper(
|
||||
crossinline keyFromToTo: suspend FromKey.() -> ToKey = { this as ToKey },
|
||||
crossinline valueFromToTo: suspend FromValue.() -> ToValue = { this as ToValue },
|
||||
crossinline keyToToFrom: suspend ToKey.() -> FromKey = { this as FromKey },
|
||||
crossinline valueToToFrom: suspend ToValue.() -> FromValue = { this as FromValue },
|
||||
): OneToManyKeyValueRepo<FromKey, FromValue> = withMapper(
|
||||
): KeyValuesRepo<FromKey, FromValue> = withMapper(
|
||||
mapper(keyFromToTo, valueFromToTo, keyToToFrom, valueToToFrom)
|
||||
)
|
||||
|
@ -2,9 +2,9 @@ package dev.inmo.micro_utils.repos.pagination
|
||||
|
||||
import dev.inmo.micro_utils.pagination.*
|
||||
import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging
|
||||
import dev.inmo.micro_utils.repos.ReadOneToManyKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.ReadKeyValuesRepo
|
||||
|
||||
suspend inline fun <Key, Value, REPO : ReadOneToManyKeyValueRepo<Key, Value>> REPO.getAll(
|
||||
suspend inline fun <Key, Value, REPO : ReadKeyValuesRepo<Key, Value>> REPO.getAll(
|
||||
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
|
||||
crossinline methodCaller: suspend REPO.(Pagination) -> PaginationResult<Key>
|
||||
): List<Pair<Key, List<Value>>> = getAllWithNextPaging {
|
||||
|
@ -9,7 +9,6 @@ import dev.inmo.micro_utils.repos.*
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.asSharedFlow
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
@ -26,7 +25,7 @@ class OneToManyAndroidRepo<Key, Value>(
|
||||
private val keyFromString: String.() -> Key,
|
||||
private val valueFromString: String.() -> Value,
|
||||
private val helper: SQLiteOpenHelper
|
||||
) : OneToManyKeyValueRepo<Key, Value> {
|
||||
) : KeyValuesRepo<Key, Value> {
|
||||
private val _onNewValue: MutableSharedFlow<Pair<Key, Value>> = MutableSharedFlow()
|
||||
override val onNewValue: Flow<Pair<Key, Value>> = _onNewValue.asSharedFlow()
|
||||
private val _onValueRemoved: MutableSharedFlow<Pair<Key, Value>> = MutableSharedFlow()
|
||||
|
@ -1,18 +1,18 @@
|
||||
package dev.inmo.micro_utils.repos.exposed.onetomany
|
||||
|
||||
import dev.inmo.micro_utils.repos.OneToManyKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.KeyValuesRepo
|
||||
import dev.inmo.micro_utils.repos.exposed.ColumnAllocator
|
||||
import kotlinx.coroutines.flow.*
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
|
||||
typealias ExposedKeyValuesRepo<Key, Value> = ExposedOneToManyKeyValueRepo<Key, Value>
|
||||
open class ExposedOneToManyKeyValueRepo<Key, Value>(
|
||||
typealias ExposedOneToManyKeyValueRepo1<Key, Value> = ExposedKeyValuesRepo<Key, Value>
|
||||
open class ExposedKeyValuesRepo<Key, Value>(
|
||||
database: Database,
|
||||
keyColumnAllocator: ColumnAllocator<Key>,
|
||||
valueColumnAllocator: ColumnAllocator<Value>,
|
||||
tableName: String? = null
|
||||
) : OneToManyKeyValueRepo<Key, Value>, ExposedReadOneToManyKeyValueRepo<Key, Value>(
|
||||
) : KeyValuesRepo<Key, Value>, ExposedReadKeyValuesRepo<Key, Value>(
|
||||
database,
|
||||
keyColumnAllocator,
|
||||
valueColumnAllocator,
|
@ -1,20 +1,19 @@
|
||||
package dev.inmo.micro_utils.repos.exposed.onetomany
|
||||
|
||||
import dev.inmo.micro_utils.pagination.*
|
||||
import dev.inmo.micro_utils.repos.ReadOneToManyKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.ReadKeyValuesRepo
|
||||
import dev.inmo.micro_utils.repos.exposed.*
|
||||
import dev.inmo.micro_utils.repos.exposed.keyvalue.ExposedReadKeyValueRepo
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
|
||||
typealias ExposedReadKeyValuesRepo<Key, Value> = ExposedReadOneToManyKeyValueRepo<Key, Value>
|
||||
typealias ExposedReadOneToManyKeyValueRepo<Key, Value> = ExposedReadKeyValuesRepo<Key, Value>
|
||||
|
||||
open class ExposedReadOneToManyKeyValueRepo<Key, Value>(
|
||||
open class ExposedReadKeyValuesRepo<Key, Value>(
|
||||
override val database: Database,
|
||||
keyColumnAllocator: ColumnAllocator<Key>,
|
||||
valueColumnAllocator: ColumnAllocator<Value>,
|
||||
tableName: String? = null
|
||||
) : ReadOneToManyKeyValueRepo<Key, Value>, ExposedRepo, Table(tableName ?: "") {
|
||||
) : ReadKeyValuesRepo<Key, Value>, ExposedRepo, Table(tableName ?: "") {
|
||||
val keyColumn: Column<Key> = keyColumnAllocator()
|
||||
val valueColumn: Column<Value> = valueColumnAllocator()
|
||||
|
@ -5,9 +5,11 @@ import dev.inmo.micro_utils.pagination.utils.paginate
|
||||
import dev.inmo.micro_utils.pagination.utils.reverse
|
||||
import kotlinx.coroutines.flow.*
|
||||
|
||||
class MapReadOneToManyKeyValueRepo<Key, Value>(
|
||||
@Deprecated("Renamed", ReplaceWith("MapReadKeyValuesRepo", "dev.inmo.micro_utils.repos.MapReadKeyValuesRepo"))
|
||||
typealias MapReadOneToManyKeyValueRepo<Key, Value> = MapReadKeyValuesRepo<Key, Value>
|
||||
class MapReadKeyValuesRepo<Key, Value>(
|
||||
private val map: Map<Key, List<Value>> = emptyMap()
|
||||
) : ReadOneToManyKeyValueRepo<Key, Value> {
|
||||
) : ReadKeyValuesRepo<Key, Value> {
|
||||
override suspend fun get(k: Key, pagination: Pagination, reversed: Boolean): PaginationResult<Value> {
|
||||
val list = map[k] ?: return emptyPaginationResult()
|
||||
|
||||
@ -53,9 +55,11 @@ class MapReadOneToManyKeyValueRepo<Key, Value>(
|
||||
override suspend fun count(): Long = map.size.toLong()
|
||||
}
|
||||
|
||||
class MapWriteOneToManyKeyValueRepo<Key, Value>(
|
||||
@Deprecated("Renamed", ReplaceWith("MapWriteKeyValuesRepo", "dev.inmo.micro_utils.repos.MapWriteKeyValuesRepo"))
|
||||
typealias MapWriteOneToManyKeyValueRepo<Key, Value> = MapWriteKeyValuesRepo<Key, Value>
|
||||
class MapWriteKeyValuesRepo<Key, Value>(
|
||||
private val map: MutableMap<Key, MutableList<Value>> = mutableMapOf()
|
||||
) : WriteOneToManyKeyValueRepo<Key, Value> {
|
||||
) : WriteKeyValuesRepo<Key, Value> {
|
||||
private val _onNewValue: MutableSharedFlow<Pair<Key, Value>> = MutableSharedFlow()
|
||||
override val onNewValue: Flow<Pair<Key, Value>> = _onNewValue.asSharedFlow()
|
||||
private val _onValueRemoved: MutableSharedFlow<Pair<Key, Value>> = MutableSharedFlow()
|
||||
@ -98,12 +102,17 @@ class MapWriteOneToManyKeyValueRepo<Key, Value>(
|
||||
}
|
||||
}
|
||||
|
||||
class MapOneToManyKeyValueRepo<Key, Value>(
|
||||
@Deprecated("Renamed", ReplaceWith("MapKeyValuesRepo", "dev.inmo.micro_utils.repos.MapKeyValuesRepo"))
|
||||
typealias MapOneToManyKeyValueRepo1<Key, Value> = MapKeyValuesRepo<Key, Value>
|
||||
class MapKeyValuesRepo<Key, Value>(
|
||||
private val map: MutableMap<Key, MutableList<Value>> = mutableMapOf()
|
||||
) : OneToManyKeyValueRepo<Key, Value>,
|
||||
ReadOneToManyKeyValueRepo<Key, Value> by MapReadOneToManyKeyValueRepo(map),
|
||||
WriteOneToManyKeyValueRepo<Key, Value> by MapWriteOneToManyKeyValueRepo(map)
|
||||
) : KeyValuesRepo<Key, Value>,
|
||||
ReadKeyValuesRepo<Key, Value> by MapReadKeyValuesRepo(map),
|
||||
WriteKeyValuesRepo<Key, Value> by MapWriteKeyValuesRepo(map)
|
||||
|
||||
fun <K, V> MutableMap<K, List<V>>.asOneToManyKeyValueRepo(): OneToManyKeyValueRepo<K, V> = MapOneToManyKeyValueRepo(
|
||||
fun <K, V> MutableMap<K, List<V>>.asKeyValuesRepo(): KeyValuesRepo<K, V> = MapKeyValuesRepo(
|
||||
map { (k, v) -> k to v.toMutableList() }.toMap().toMutableMap()
|
||||
)
|
||||
|
||||
@Deprecated("Renamed", ReplaceWith("asKeyValuesRepo", "dev.inmo.micro_utils.repos.asKeyValuesRepo"))
|
||||
fun <K, V> MutableMap<K, List<V>>.asOneToManyKeyValueRepo(): KeyValuesRepo<K, V> = asKeyValuesRepo()
|
@ -7,10 +7,10 @@ import io.ktor.http.ContentType
|
||||
import io.ktor.http.encodeURLQueryComponent
|
||||
import kotlinx.serialization.*
|
||||
|
||||
class KtorStandardKeyValuesRepoClient<Key, Value> (
|
||||
readDelegate: ReadOneToManyKeyValueRepo<Key, Value>,
|
||||
writeDelegate: WriteOneToManyKeyValueRepo<Key, Value>
|
||||
) : OneToManyKeyValueRepo<Key, Value> by DelegateBasedOneToManyKeyValueRepo(
|
||||
class KtorKeyValuesRepoClient<Key, Value> (
|
||||
readDelegate: ReadKeyValuesRepo<Key, Value>,
|
||||
writeDelegate: WriteKeyValuesRepo<Key, Value>
|
||||
) : KeyValuesRepo<Key, Value> by DelegateBasedKeyValuesRepo(
|
||||
readDelegate,
|
||||
writeDelegate
|
||||
) {
|
||||
@ -21,15 +21,15 @@ class KtorStandardKeyValuesRepoClient<Key, Value> (
|
||||
contentType: ContentType,
|
||||
noinline keySerializer: suspend (Key) -> String,
|
||||
noinline valueSerializer: suspend (Value) -> String
|
||||
) = KtorStandardKeyValuesRepoClient(
|
||||
KtorReadStandardKeyValuesRepoClient(
|
||||
) = KtorKeyValuesRepoClient(
|
||||
KtorReadKeyValuesRepoClient(
|
||||
baseUrl,
|
||||
httpClient,
|
||||
contentType,
|
||||
keySerializer,
|
||||
valueSerializer
|
||||
),
|
||||
KtorWriteStandardKeyValuesRepoClient(
|
||||
KtorWriteKeyValuesRepoClient(
|
||||
baseUrl,
|
||||
httpClient,
|
||||
contentType
|
||||
@ -42,7 +42,7 @@ class KtorStandardKeyValuesRepoClient<Key, Value> (
|
||||
contentType: ContentType,
|
||||
noinline keySerializer: suspend (Key) -> String,
|
||||
noinline valueSerializer: suspend (Value) -> String
|
||||
) = KtorStandardKeyValuesRepoClient(
|
||||
) = KtorKeyValuesRepoClient(
|
||||
buildStandardUrl(baseUrl, subpart),
|
||||
httpClient,
|
||||
contentType,
|
||||
@ -52,14 +52,14 @@ class KtorStandardKeyValuesRepoClient<Key, Value> (
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified Key : Any, reified Value : Any> KtorStandardKeyValuesRepoClient(
|
||||
inline fun <reified Key : Any, reified Value : Any> KtorKeyValuesRepoClient(
|
||||
baseUrl: String,
|
||||
httpClient: HttpClient,
|
||||
contentType: ContentType,
|
||||
keySerializer: SerializationStrategy<Key>,
|
||||
valueSerializer: SerializationStrategy<Value>,
|
||||
serialFormat: StringFormat,
|
||||
) = KtorStandardKeyValuesRepoClient<Key, Value>(
|
||||
) = KtorKeyValuesRepoClient<Key, Value>(
|
||||
baseUrl,
|
||||
httpClient,
|
||||
contentType,
|
||||
@ -70,14 +70,14 @@ inline fun <reified Key : Any, reified Value : Any> KtorStandardKeyValuesRepoCli
|
||||
serialFormat.encodeToString(valueSerializer, it).encodeURLQueryComponent()
|
||||
}
|
||||
|
||||
inline fun <reified Key : Any, reified Value : Any> KtorStandardKeyValuesRepoClient(
|
||||
inline fun <reified Key : Any, reified Value : Any> KtorKeyValuesRepoClient(
|
||||
baseUrl: String,
|
||||
httpClient: HttpClient,
|
||||
contentType: ContentType,
|
||||
keySerializer: SerializationStrategy<Key>,
|
||||
valueSerializer: SerializationStrategy<Value>,
|
||||
serialFormat: BinaryFormat,
|
||||
) = KtorStandardKeyValuesRepoClient<Key, Value>(
|
||||
) = KtorKeyValuesRepoClient<Key, Value>(
|
||||
baseUrl,
|
||||
httpClient,
|
||||
contentType,
|
@ -7,20 +7,21 @@ import dev.inmo.micro_utils.repos.*
|
||||
import io.ktor.client.HttpClient
|
||||
import kotlinx.serialization.KSerializer
|
||||
|
||||
@Deprecated("Should be replaced with KtorKeyValuesRepoClient")
|
||||
class KtorOneToManyKeyValueRepo<Key, Value>(
|
||||
baseUrl: String,
|
||||
baseSubpart: String,
|
||||
unifiedRequester: UnifiedRequester,
|
||||
keySerializer: KSerializer<Key>,
|
||||
valueSerializer: KSerializer<Value>,
|
||||
) : OneToManyKeyValueRepo<Key, Value>,
|
||||
ReadOneToManyKeyValueRepo<Key, Value> by KtorReadOneToManyKeyValueRepo<Key, Value> (
|
||||
) : KeyValuesRepo<Key, Value>,
|
||||
ReadKeyValuesRepo<Key, Value> by KtorReadOneToManyKeyValueRepo<Key, Value> (
|
||||
"$baseUrl/$baseSubpart",
|
||||
unifiedRequester,
|
||||
keySerializer,
|
||||
valueSerializer,
|
||||
),
|
||||
WriteOneToManyKeyValueRepo<Key, Value> by KtorWriteOneToManyKeyValueRepo<Key, Value> (
|
||||
WriteKeyValuesRepo<Key, Value> by KtorWriteOneToManyKeyValueRepo<Key, Value> (
|
||||
"$baseUrl/$baseSubpart",
|
||||
unifiedRequester,
|
||||
keySerializer,
|
||||
|
@ -2,9 +2,8 @@ package dev.inmo.micro_utils.repos.ktor.client.one_to_many
|
||||
|
||||
import dev.inmo.micro_utils.ktor.common.*
|
||||
import dev.inmo.micro_utils.pagination.*
|
||||
import dev.inmo.micro_utils.repos.ReadOneToManyKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.ReadKeyValuesRepo
|
||||
import dev.inmo.micro_utils.repos.ktor.common.*
|
||||
import dev.inmo.micro_utils.repos.ktor.common.crud.*
|
||||
import dev.inmo.micro_utils.repos.ktor.common.one_to_many.*
|
||||
import dev.inmo.micro_utils.repos.ktor.common.reversedParameterName
|
||||
import io.ktor.client.HttpClient
|
||||
@ -15,7 +14,7 @@ import io.ktor.util.reflect.TypeInfo
|
||||
import io.ktor.util.reflect.typeInfo
|
||||
import kotlinx.serialization.*
|
||||
|
||||
class KtorReadStandardKeyValuesRepoClient<Key, Value>(
|
||||
class KtorReadKeyValuesRepoClient<Key, Value>(
|
||||
private val baseUrl: String,
|
||||
private val httpClient: HttpClient,
|
||||
private val contentType: ContentType,
|
||||
@ -23,7 +22,7 @@ class KtorReadStandardKeyValuesRepoClient<Key, Value>(
|
||||
private val paginationResultKeysTypeInfo: TypeInfo,
|
||||
private val keySerializer: suspend (Key) -> String,
|
||||
private val valueSerializer: suspend (Value) -> String
|
||||
) : ReadOneToManyKeyValueRepo<Key, Value> {
|
||||
) : ReadKeyValuesRepo<Key, Value> {
|
||||
override suspend fun get(
|
||||
k: Key,
|
||||
pagination: Pagination,
|
||||
@ -106,13 +105,13 @@ class KtorReadStandardKeyValuesRepoClient<Key, Value>(
|
||||
}.body()
|
||||
}
|
||||
|
||||
inline fun <reified Key, reified Value> KtorReadStandardKeyValuesRepoClient(
|
||||
inline fun <reified Key, reified Value> KtorReadKeyValuesRepoClient(
|
||||
baseUrl: String,
|
||||
httpClient: HttpClient,
|
||||
contentType: ContentType,
|
||||
noinline keySerializer: suspend (Key) -> String,
|
||||
noinline valueSerializer: suspend (Value) -> String
|
||||
) = KtorReadStandardKeyValuesRepoClient<Key, Value>(
|
||||
) = KtorReadKeyValuesRepoClient<Key, Value>(
|
||||
baseUrl,
|
||||
httpClient,
|
||||
contentType,
|
||||
@ -122,14 +121,14 @@ inline fun <reified Key, reified Value> KtorReadStandardKeyValuesRepoClient(
|
||||
valueSerializer
|
||||
)
|
||||
|
||||
inline fun <reified Key, reified Value> KtorReadStandardKeyValuesRepoClient(
|
||||
inline fun <reified Key, reified Value> KtorReadKeyValuesRepoClient(
|
||||
baseUrl: String,
|
||||
httpClient: HttpClient,
|
||||
idsSerializer: KSerializer<Key>,
|
||||
valueSerializer: KSerializer<Value>,
|
||||
serialFormat: StringFormat,
|
||||
contentType: ContentType,
|
||||
) = KtorReadStandardKeyValuesRepoClient<Key, Value>(
|
||||
) = KtorReadKeyValuesRepoClient<Key, Value>(
|
||||
baseUrl,
|
||||
httpClient,
|
||||
contentType,
|
||||
@ -140,14 +139,14 @@ inline fun <reified Key, reified Value> KtorReadStandardKeyValuesRepoClient(
|
||||
serialFormat.encodeToString(valueSerializer, it).encodeURLQueryComponent()
|
||||
}
|
||||
|
||||
inline fun <reified Key, reified Value> KtorReadStandardKeyValuesRepoClient(
|
||||
inline fun <reified Key, reified Value> KtorReadKeyValuesRepoClient(
|
||||
baseUrl: String,
|
||||
httpClient: HttpClient,
|
||||
idsSerializer: KSerializer<Key>,
|
||||
valuesSerializer: KSerializer<Value>,
|
||||
serialFormat: BinaryFormat,
|
||||
contentType: ContentType,
|
||||
) = KtorReadStandardKeyValuesRepoClient<Key, Value>(
|
||||
) = KtorReadKeyValuesRepoClient<Key, Value>(
|
||||
baseUrl,
|
||||
httpClient,
|
||||
contentType,
|
@ -3,7 +3,7 @@ package dev.inmo.micro_utils.repos.ktor.client.one_to_many
|
||||
import dev.inmo.micro_utils.ktor.client.*
|
||||
import dev.inmo.micro_utils.ktor.common.*
|
||||
import dev.inmo.micro_utils.pagination.*
|
||||
import dev.inmo.micro_utils.repos.ReadOneToManyKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.ReadKeyValuesRepo
|
||||
import dev.inmo.micro_utils.repos.ktor.common.keyParameterName
|
||||
import dev.inmo.micro_utils.repos.ktor.common.one_to_many.*
|
||||
import dev.inmo.micro_utils.repos.ktor.common.reversedParameterName
|
||||
@ -12,12 +12,13 @@ import io.ktor.client.HttpClient
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
|
||||
@Deprecated("Should be replaced with KtorReadKeyValuesRepoClient")
|
||||
class KtorReadOneToManyKeyValueRepo<Key, Value> (
|
||||
private val baseUrl: String,
|
||||
private val unifiedRequester: UnifiedRequester,
|
||||
private val keySerializer: KSerializer<Key>,
|
||||
private val valueSerializer: KSerializer<Value>
|
||||
) : ReadOneToManyKeyValueRepo<Key, Value> {
|
||||
) : ReadKeyValuesRepo<Key, Value> {
|
||||
private val paginationValueResultSerializer = PaginationResult.serializer(valueSerializer)
|
||||
private val paginationKeyResultSerializer = PaginationResult.serializer(keySerializer)
|
||||
|
||||
|
@ -3,7 +3,7 @@ package dev.inmo.micro_utils.repos.ktor.client.one_to_many
|
||||
import dev.inmo.micro_utils.ktor.client.createStandardWebsocketFlow
|
||||
import dev.inmo.micro_utils.ktor.client.throwOnUnsuccess
|
||||
import dev.inmo.micro_utils.ktor.common.*
|
||||
import dev.inmo.micro_utils.repos.WriteOneToManyKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.WriteKeyValuesRepo
|
||||
import dev.inmo.micro_utils.repos.ktor.common.one_to_many.*
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.request.post
|
||||
@ -13,7 +13,7 @@ import io.ktor.util.reflect.TypeInfo
|
||||
import io.ktor.util.reflect.typeInfo
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
class KtorWriteStandardKeyValuesRepoClient<Key : Any, Value : Any>(
|
||||
class KtorWriteKeyValuesRepoClient<Key : Any, Value : Any>(
|
||||
private val baseUrl: String,
|
||||
private val httpClient: HttpClient,
|
||||
private val contentType: ContentType,
|
||||
@ -23,7 +23,7 @@ class KtorWriteStandardKeyValuesRepoClient<Key : Any, Value : Any>(
|
||||
private val keyTypeInfo: TypeInfo,
|
||||
private val valueTypeInfo: TypeInfo,
|
||||
private val keyToValuesMapTypeInfo: TypeInfo
|
||||
) : WriteOneToManyKeyValueRepo<Key, Value> {
|
||||
) : WriteKeyValuesRepo<Key, Value> {
|
||||
|
||||
@OptIn(InternalAPI::class)
|
||||
override suspend fun add(toAdd: Map<Key, List<Value>>) {
|
||||
@ -85,7 +85,7 @@ class KtorWriteStandardKeyValuesRepoClient<Key : Any, Value : Any>(
|
||||
baseUrl: String,
|
||||
httpClient: HttpClient,
|
||||
contentType: ContentType
|
||||
) = KtorWriteStandardKeyValuesRepoClient<Key, Value>(
|
||||
) = KtorWriteKeyValuesRepoClient<Key, Value>(
|
||||
baseUrl,
|
||||
httpClient,
|
||||
contentType,
|
@ -2,19 +2,20 @@ package dev.inmo.micro_utils.repos.ktor.client.one_to_many
|
||||
|
||||
import dev.inmo.micro_utils.ktor.client.*
|
||||
import dev.inmo.micro_utils.ktor.common.*
|
||||
import dev.inmo.micro_utils.repos.WriteOneToManyKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.WriteKeyValuesRepo
|
||||
import dev.inmo.micro_utils.repos.ktor.common.one_to_many.*
|
||||
import io.ktor.client.HttpClient
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.builtins.*
|
||||
|
||||
@Deprecated("Should be replaced with KtorWriteKeyValuesRepoClient")
|
||||
class KtorWriteOneToManyKeyValueRepo<Key, Value> (
|
||||
private val baseUrl: String,
|
||||
private val unifiedRequester: UnifiedRequester,
|
||||
private val keySerializer: KSerializer<Key>,
|
||||
private val valueSerializer: KSerializer<Value>
|
||||
) : WriteOneToManyKeyValueRepo<Key, Value> {
|
||||
) : WriteKeyValuesRepo<Key, Value> {
|
||||
private val keyValueSerializer = PairSerializer(keySerializer, valueSerializer)
|
||||
private val keyValueMapSerializer = MapSerializer(keySerializer, ListSerializer(valueSerializer))
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
import dev.inmo.micro_utils.pagination.firstPageWithOneElementPagination
|
||||
import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging
|
||||
import dev.inmo.micro_utils.repos.*
|
||||
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.client.one_to_many.KtorKeyValuesRepoClient
|
||||
import dev.inmo.micro_utils.repos.ktor.server.one_to_many.configureKeyValuesRepoRoutes
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.plugins.logging.Logging
|
||||
import io.ktor.http.ContentType
|
||||
@ -25,7 +25,7 @@ class KVsTests {
|
||||
fun testKVsFunctions() {
|
||||
runTest {
|
||||
val map = mutableMapOf<Int, MutableList<ComplexData>>()
|
||||
val repo = MapOneToManyKeyValueRepo(map)
|
||||
val repo = MapKeyValuesRepo(map)
|
||||
val server = io.ktor.server.engine.embeddedServer(
|
||||
CIO,
|
||||
23456,
|
||||
@ -38,7 +38,7 @@ class KVsTests {
|
||||
contentConverter = KotlinxWebsocketSerializationConverter(Json)
|
||||
}
|
||||
routing {
|
||||
configureStandardKeyValuesRepoRoutes(
|
||||
configureKeyValuesRepoRoutes(
|
||||
repo,
|
||||
Int.serializer(),
|
||||
ComplexData.serializer(),
|
||||
@ -55,7 +55,7 @@ class KVsTests {
|
||||
contentConverter = KotlinxWebsocketSerializationConverter(Json)
|
||||
}
|
||||
}
|
||||
val crudClient = KtorStandardKeyValuesRepoClient(
|
||||
val crudClient = KtorKeyValuesRepoClient(
|
||||
"http://127.0.0.1:23456",
|
||||
client,
|
||||
ContentType.Application.Json,
|
||||
|
@ -4,7 +4,7 @@ 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.standardKtorSerialFormatContentType
|
||||
import dev.inmo.micro_utils.repos.OneToManyKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.KeyValuesRepo
|
||||
import io.ktor.http.ContentType
|
||||
import io.ktor.server.routing.Route
|
||||
import io.ktor.server.routing.route
|
||||
@ -12,7 +12,7 @@ import kotlinx.serialization.KSerializer
|
||||
|
||||
fun <Key, Value> Route.configureOneToManyKeyValueRepoRoutes(
|
||||
baseSubpart: String,
|
||||
originalRepo: OneToManyKeyValueRepo<Key, Value>,
|
||||
originalRepo: KeyValuesRepo<Key, Value>,
|
||||
keySerializer: KSerializer<Key>,
|
||||
valueSerializer: KSerializer<Value>,
|
||||
unifiedRouter: UnifiedRouter
|
||||
@ -25,7 +25,7 @@ fun <Key, Value> Route.configureOneToManyKeyValueRepoRoutes(
|
||||
|
||||
fun <Key, Value> Route.configureOneToManyKeyValueRepoRoutes(
|
||||
baseSubpart: String,
|
||||
originalRepo: OneToManyKeyValueRepo<Key, Value>,
|
||||
originalRepo: KeyValuesRepo<Key, Value>,
|
||||
keySerializer: KSerializer<Key>,
|
||||
valueSerializer: KSerializer<Value>,
|
||||
serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat,
|
||||
|
@ -5,7 +5,7 @@ import dev.inmo.micro_utils.ktor.common.standardKtorSerialFormat
|
||||
import dev.inmo.micro_utils.ktor.server.*
|
||||
import dev.inmo.micro_utils.pagination.PaginationResult
|
||||
import dev.inmo.micro_utils.pagination.extractPagination
|
||||
import dev.inmo.micro_utils.repos.ReadOneToManyKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.ReadKeyValuesRepo
|
||||
import dev.inmo.micro_utils.repos.ktor.common.keyParameterName
|
||||
import dev.inmo.micro_utils.repos.ktor.common.one_to_many.*
|
||||
import dev.inmo.micro_utils.repos.ktor.common.valueParameterName
|
||||
@ -18,7 +18,7 @@ import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
|
||||
fun <Key, Value> Route.configureOneToManyReadKeyValueRepoRoutes(
|
||||
originalRepo: ReadOneToManyKeyValueRepo<Key, Value>,
|
||||
originalRepo: ReadKeyValuesRepo<Key, Value>,
|
||||
keySerializer: KSerializer<Key>,
|
||||
valueSerializer: KSerializer<Value>,
|
||||
unifiedRouter: UnifiedRouter
|
||||
@ -121,7 +121,7 @@ fun <Key, Value> Route.configureOneToManyReadKeyValueRepoRoutes(
|
||||
}
|
||||
|
||||
inline fun <Key, Value> Route.configureOneToManyReadKeyValueRepoRoutes(
|
||||
originalRepo: ReadOneToManyKeyValueRepo<Key, Value>,
|
||||
originalRepo: ReadKeyValuesRepo<Key, Value>,
|
||||
keySerializer: KSerializer<Key>,
|
||||
valueSerializer: KSerializer<Value>,
|
||||
serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat,
|
||||
|
@ -3,7 +3,7 @@ package dev.inmo.micro_utils.repos.ktor.server.one_to_many
|
||||
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.repos.WriteOneToManyKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.WriteKeyValuesRepo
|
||||
import dev.inmo.micro_utils.repos.ktor.common.one_to_many.*
|
||||
import io.ktor.http.ContentType
|
||||
import io.ktor.server.routing.Route
|
||||
@ -12,7 +12,7 @@ import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.builtins.*
|
||||
|
||||
fun <Key, Value> Route.configureOneToManyWriteKeyValueRepoRoutes(
|
||||
originalRepo: WriteOneToManyKeyValueRepo<Key, Value>,
|
||||
originalRepo: WriteKeyValuesRepo<Key, Value>,
|
||||
keySerializer: KSerializer<Key>,
|
||||
valueSerializer: KSerializer<Value>,
|
||||
unifiedRouter: UnifiedRouter
|
||||
@ -95,7 +95,7 @@ fun <Key, Value> Route.configureOneToManyWriteKeyValueRepoRoutes(
|
||||
}
|
||||
|
||||
fun <Key, Value> Route.configureOneToManyWriteKeyValueRepoRoutes(
|
||||
originalRepo: WriteOneToManyKeyValueRepo<Key, Value>,
|
||||
originalRepo: WriteKeyValuesRepo<Key, Value>,
|
||||
keySerializer: KSerializer<Key>,
|
||||
valueSerializer: KSerializer<Value>,
|
||||
serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat,
|
||||
|
@ -6,21 +6,21 @@ import io.ktor.http.*
|
||||
import io.ktor.server.routing.Route
|
||||
import kotlinx.serialization.*
|
||||
|
||||
inline fun <reified Key : Any, reified Value : Any> Route.configureStandardKeyValuesRepoRoutes (
|
||||
originalRepo: OneToManyKeyValueRepo<Key, Value>,
|
||||
inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValuesRepoRoutes (
|
||||
originalRepo: KeyValuesRepo<Key, Value>,
|
||||
noinline idDeserializer: suspend (String) -> Key,
|
||||
noinline valueDeserializer: suspend (String) -> Value
|
||||
) {
|
||||
configureReadStandardKeyValuesRepoRoutes(originalRepo, idDeserializer, valueDeserializer)
|
||||
configureWriteStandardKeyValuesRepoRoutes(originalRepo)
|
||||
configureReadKeyValuesRepoRoutes(originalRepo, idDeserializer, valueDeserializer)
|
||||
configureWriteKeyValuesRepoRoutes(originalRepo)
|
||||
}
|
||||
|
||||
inline fun <reified Key : Any, reified Value : Any> Route.configureStandardKeyValuesRepoRoutes(
|
||||
originalRepo: OneToManyKeyValueRepo<Key, Value>,
|
||||
inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValuesRepoRoutes(
|
||||
originalRepo: KeyValuesRepo<Key, Value>,
|
||||
idsSerializer: DeserializationStrategy<Key>,
|
||||
valueSerializer: DeserializationStrategy<Value>,
|
||||
serialFormat: StringFormat
|
||||
) = configureStandardKeyValuesRepoRoutes(
|
||||
) = configureKeyValuesRepoRoutes(
|
||||
originalRepo,
|
||||
{
|
||||
serialFormat.decodeFromString(idsSerializer, it.decodeURLQueryComponent())
|
||||
@ -30,12 +30,12 @@ inline fun <reified Key : Any, reified Value : Any> Route.configureStandardKeyVa
|
||||
}
|
||||
)
|
||||
|
||||
inline fun <reified Key : Any, reified Value : Any> Route.configureStandardKeyValuesRepoRoutes(
|
||||
originalRepo: OneToManyKeyValueRepo<Key, Value>,
|
||||
inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValuesRepoRoutes(
|
||||
originalRepo: KeyValuesRepo<Key, Value>,
|
||||
idsSerializer: DeserializationStrategy<Key>,
|
||||
valueSerializer: DeserializationStrategy<Value>,
|
||||
serialFormat: BinaryFormat
|
||||
) = configureStandardKeyValuesRepoRoutes(
|
||||
) = configureKeyValuesRepoRoutes(
|
||||
originalRepo,
|
||||
{
|
||||
serialFormat.decodeHex(idsSerializer, it)
|
@ -4,7 +4,7 @@ import dev.inmo.micro_utils.ktor.common.*
|
||||
import dev.inmo.micro_utils.ktor.server.*
|
||||
import dev.inmo.micro_utils.pagination.PaginationResult
|
||||
import dev.inmo.micro_utils.pagination.extractPagination
|
||||
import dev.inmo.micro_utils.repos.ReadOneToManyKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.ReadKeyValuesRepo
|
||||
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.one_to_many.*
|
||||
@ -18,8 +18,8 @@ import io.ktor.util.reflect.typeInfo
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@OptIn(InternalAPI::class)
|
||||
inline fun <reified Key, reified Value> Route.configureReadStandardKeyValuesRepoRoutes (
|
||||
originalRepo: ReadOneToManyKeyValueRepo<Key, Value>,
|
||||
inline fun <reified Key, reified Value> Route.configureReadKeyValuesRepoRoutes (
|
||||
originalRepo: ReadKeyValuesRepo<Key, Value>,
|
||||
noinline idDeserializer: suspend (String) -> Key,
|
||||
noinline valueDeserializer: suspend (String) -> Value
|
||||
) {
|
||||
@ -75,12 +75,12 @@ inline fun <reified Key, reified Value> Route.configureReadStandardKeyValuesRepo
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified Key, reified Value> Route.configureReadStandardKeyValuesRepoRoutes(
|
||||
originalRepo: ReadOneToManyKeyValueRepo<Key, Value>,
|
||||
inline fun <reified Key, reified Value> Route.configureReadKeyValuesRepoRoutes(
|
||||
originalRepo: ReadKeyValuesRepo<Key, Value>,
|
||||
idsSerializer: DeserializationStrategy<Key>,
|
||||
valueSerializer: DeserializationStrategy<Value>,
|
||||
serialFormat: StringFormat
|
||||
) = configureReadStandardKeyValuesRepoRoutes(
|
||||
) = configureReadKeyValuesRepoRoutes(
|
||||
originalRepo,
|
||||
{
|
||||
serialFormat.decodeFromString(idsSerializer, it.decodeURLQueryComponent())
|
||||
@ -90,12 +90,12 @@ inline fun <reified Key, reified Value> Route.configureReadStandardKeyValuesRepo
|
||||
}
|
||||
)
|
||||
|
||||
inline fun <reified Key, reified Value> Route.configureReadStandardKeyValuesRepoRoutes(
|
||||
originalRepo: ReadOneToManyKeyValueRepo<Key, Value>,
|
||||
inline fun <reified Key, reified Value> Route.configureReadKeyValuesRepoRoutes(
|
||||
originalRepo: ReadKeyValuesRepo<Key, Value>,
|
||||
idsSerializer: DeserializationStrategy<Key>,
|
||||
valueSerializer: DeserializationStrategy<Value>,
|
||||
serialFormat: BinaryFormat
|
||||
) = configureReadStandardKeyValuesRepoRoutes(
|
||||
) = configureReadKeyValuesRepoRoutes(
|
||||
originalRepo,
|
||||
{
|
||||
serialFormat.decodeHex(idsSerializer, it)
|
@ -1,7 +1,7 @@
|
||||
package dev.inmo.micro_utils.repos.ktor.server.one_to_many
|
||||
|
||||
import dev.inmo.micro_utils.ktor.server.*
|
||||
import dev.inmo.micro_utils.repos.WriteOneToManyKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.WriteKeyValuesRepo
|
||||
import dev.inmo.micro_utils.repos.ktor.common.one_to_many.*
|
||||
import io.ktor.http.HttpStatusCode
|
||||
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.util.reflect.typeInfo
|
||||
|
||||
inline fun <reified Key : Any, reified Value : Any> Route.configureWriteStandardKeyValuesRepoRoutes (
|
||||
originalRepo: WriteOneToManyKeyValueRepo<Key, Value>
|
||||
inline fun <reified Key : Any, reified Value : Any> Route.configureWriteKeyValuesRepoRoutes (
|
||||
originalRepo: WriteKeyValuesRepo<Key, Value>
|
||||
) {
|
||||
includeWebsocketHandling(
|
||||
onNewValueRoute,
|
Loading…
Reference in New Issue
Block a user