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