Compare commits

...

17 Commits

Author SHA1 Message Date
e3ff1b9609 fill changelog 2022-07-22 16:31:33 +06:00
70c31966ca Update gradle-wrapper.properties 2022-07-18 14:33:04 +06:00
0e4188882f Update libs.versions.toml 2022-07-18 14:08:23 +06:00
6bf0ce92ba Update libs.versions.toml 2022-07-18 13:51:00 +06:00
d51bdc5086 Update gradle.properties 2022-07-18 13:48:09 +06:00
e5dd4363f1 Merge pull request #175 from InsanusMokrassar/0.11.12
0.11.12
2022-07-02 02:50:47 +06:00
a3a48bbaac fixes in file key value repo 2022-07-02 02:28:43 +06:00
5e716fb9a8 start 0.11.12 2022-07-02 02:26:58 +06:00
11a36153cc Merge pull request #174 from InsanusMokrassar/0.11.11
0.11.11: improvements of cache repos
2022-06-30 14:03:29 +06:00
8bee354f04 improvements of cache repos 2022-06-30 13:59:32 +06:00
f7dd2b5ce7 Merge pull request #173 from InsanusMokrassar/0.11.11
0.11.11
2022-06-30 13:41:43 +06:00
8ca10c00bb update dokka workflow 2022-06-30 13:41:12 +06:00
905c7e8eda deprecate hmacSha256 2022-06-30 13:19:37 +06:00
d4c5e849bf deprecate BodyPair 2022-06-30 13:15:19 +06:00
8250a2a021 start 0.11.11 2022-06-30 13:14:06 +06:00
01b3df7b8c Update github_release.gradle 2022-06-30 10:12:54 +06:00
daa6e4aff5 Merge pull request #172 from InsanusMokrassar/0.11.10
0.11.10
2022-06-30 02:56:14 +06:00
22 changed files with 80 additions and 42 deletions

View File

@@ -15,7 +15,7 @@ jobs:
continue-on-error: true continue-on-error: true
run: cd /usr/local/lib/android/sdk/build-tools/32.0.0/ && mv d8 dx && cd lib && mv d8.jar dx.jar run: cd /usr/local/lib/android/sdk/build-tools/32.0.0/ && mv d8 dx && cd lib && mv d8.jar dx.jar
- name: Build - name: Build
run: ./gradlew dokkaHtml run: ./gradlew build && ./gradlew dokkaHtml
- name: Publish KDocs - name: Publish KDocs
uses: peaceiris/actions-gh-pages@v3 uses: peaceiris/actions-gh-pages@v3
with: with:

View File

@@ -1,5 +1,31 @@
# Changelog # Changelog
## 0.11.13
* `Versions`:
* `Coroutines`: `1.6.3` -> `1.6.4`
* `Compose`: `1.2.0-alpha01-dev629` -> `1.2.0-alpha01-dev731`
## 0.11.12
* `Repos`:
* `Common`:
* `JVM`:
* Fixes in `ReadFileKeyValueRepo` methods (`values`/`keys`)
## 0.11.11
* `Crypto`:
* `hmacSha256` has been deprecated
* `Ktor`:
* `Client`:
* `BodyPair` has been deprecated
* `Repos`:
* `Cache`:
* New interface `CacheRepo`
* New interface `FullCacheRepo`
* `actualize*` methods inside of full cache repos now open for overriding
## 0.11.10 ## 0.11.10
* `Repos`: * `Repos`:

View File

@@ -1,3 +1,4 @@
package dev.inmo.micro_utils.crypto package dev.inmo.micro_utils.crypto
@Deprecated("Deprecated due to incorrect of work sometimes and redundancy. Can be replaced by korlibs krypto")
expect fun SourceString.hmacSha256(key: String): String expect fun SourceString.hmacSha256(key: String): String

View File

@@ -8,6 +8,7 @@ external interface CryptoJs {
@JsNonModule @JsNonModule
external val CryptoJS: CryptoJs external val CryptoJS: CryptoJs
@Deprecated("Deprecated due to incorrect of work sometimes and redundancy. Can be replaced by korlibs krypto")
actual fun SourceString.hmacSha256(key: String): String { actual fun SourceString.hmacSha256(key: String): String {
return CryptoJS.asDynamic().HmacSHA256(this, key).toString().unsafeCast<String>() return CryptoJS.asDynamic().HmacSHA256(this, key).toString().unsafeCast<String>()
} }

View File

@@ -3,6 +3,7 @@ package dev.inmo.micro_utils.crypto
import javax.crypto.Mac import javax.crypto.Mac
import javax.crypto.spec.SecretKeySpec import javax.crypto.spec.SecretKeySpec
@Deprecated("Deprecated due to incorrect of work sometimes and redundancy. Can be replaced by korlibs krypto")
actual fun SourceString.hmacSha256(key: String): String { actual fun SourceString.hmacSha256(key: String): String {
val mac = Mac.getInstance("HmacSHA256") val mac = Mac.getInstance("HmacSHA256")

View File

@@ -21,7 +21,7 @@ if (new File(projectDir, "secret.gradle").exists()) {
owner "InsanusMokrassar" owner "InsanusMokrassar"
repo "MicroUtils" repo "MicroUtils"
tagName "${project.version}" tagName "v${project.version}"
releaseName "${project.version}" releaseName "${project.version}"
targetCommitish "${project.version}" targetCommitish "${project.version}"

View File

@@ -14,5 +14,5 @@ crypto_js_version=4.1.1
# Project data # Project data
group=dev.inmo group=dev.inmo
version=0.11.10 version=0.11.13
android_code_version=134 android_code_version=137

View File

@@ -2,9 +2,9 @@
kt = "1.6.21" kt = "1.6.21"
kt-serialization = "1.3.3" kt-serialization = "1.3.3"
kt-coroutines = "1.6.3" kt-coroutines = "1.6.4"
jb-compose = "1.2.0-alpha01-dev729" jb-compose = "1.2.0-alpha01-dev731"
jb-exposed = "0.38.2" jb-exposed = "0.38.2"
jb-dokka = "1.6.21" jb-dokka = "1.6.21"

View File

@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View File

@@ -12,6 +12,7 @@ import io.ktor.http.*
import io.ktor.utils.io.core.ByteReadPacket import io.ktor.utils.io.core.ByteReadPacket
import kotlinx.serialization.* import kotlinx.serialization.*
@Deprecated("This class will be removed in next")
typealias BodyPair<T> = Pair<SerializationStrategy<T>, T> typealias BodyPair<T> = Pair<SerializationStrategy<T>, T>
class UnifiedRequester( class UnifiedRequester(
@@ -33,7 +34,7 @@ class UnifiedRequester(
suspend fun <BodyType, ResultType> unipost( suspend fun <BodyType, ResultType> unipost(
url: String, url: String,
bodyInfo: BodyPair<BodyType>, bodyInfo: Pair<SerializationStrategy<BodyType>, BodyType>,
resultDeserializer: DeserializationStrategy<ResultType> resultDeserializer: DeserializationStrategy<ResultType>
) = client.unipost(url, bodyInfo, resultDeserializer, serialFormat) ) = client.unipost(url, bodyInfo, resultDeserializer, serialFormat)
@@ -52,7 +53,7 @@ class UnifiedRequester(
url: String, url: String,
filename: String, filename: String,
inputProvider: InputProvider, inputProvider: InputProvider,
otherData: BodyPair<BodyType>, otherData: Pair<SerializationStrategy<BodyType>, BodyType>,
resultDeserializer: DeserializationStrategy<ResultType>, resultDeserializer: DeserializationStrategy<ResultType>,
mimetype: String = "*/*", mimetype: String = "*/*",
additionalParametersBuilder: FormBuilder.() -> Unit = {}, additionalParametersBuilder: FormBuilder.() -> Unit = {},
@@ -75,7 +76,7 @@ class UnifiedRequester(
suspend fun <BodyType, ResultType> unimultipart( suspend fun <BodyType, ResultType> unimultipart(
url: String, url: String,
mppFile: MPPFile, mppFile: MPPFile,
otherData: BodyPair<BodyType>, otherData: Pair<SerializationStrategy<BodyType>, BodyType>,
resultDeserializer: DeserializationStrategy<ResultType>, resultDeserializer: DeserializationStrategy<ResultType>,
mimetype: String = "*/*", mimetype: String = "*/*",
additionalParametersBuilder: FormBuilder.() -> Unit = {}, additionalParametersBuilder: FormBuilder.() -> Unit = {},
@@ -120,7 +121,7 @@ fun <T> SerializationStrategy<T>.encodeUrlQueryValue(
suspend fun <BodyType, ResultType> HttpClient.unipost( suspend fun <BodyType, ResultType> HttpClient.unipost(
url: String, url: String,
bodyInfo: BodyPair<BodyType>, bodyInfo: Pair<SerializationStrategy<BodyType>, BodyType>,
resultDeserializer: DeserializationStrategy<ResultType>, resultDeserializer: DeserializationStrategy<ResultType>,
serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat
) = post(url) { ) = post(url) {
@@ -162,7 +163,7 @@ suspend fun <ResultType> HttpClient.unimultipart(
suspend fun <BodyType, ResultType> HttpClient.unimultipart( suspend fun <BodyType, ResultType> HttpClient.unimultipart(
url: String, url: String,
filename: String, filename: String,
otherData: BodyPair<BodyType>, otherData: Pair<SerializationStrategy<BodyType>, BodyType>,
inputProvider: InputProvider, inputProvider: InputProvider,
resultDeserializer: DeserializationStrategy<ResultType>, resultDeserializer: DeserializationStrategy<ResultType>,
mimetype: String = "*/*", mimetype: String = "*/*",
@@ -220,7 +221,7 @@ suspend fun <ResultType> HttpClient.unimultipart(
suspend fun <BodyType, ResultType> HttpClient.unimultipart( suspend fun <BodyType, ResultType> HttpClient.unimultipart(
url: String, url: String,
mppFile: MPPFile, mppFile: MPPFile,
otherData: BodyPair<BodyType>, otherData: Pair<SerializationStrategy<BodyType>, BodyType>,
resultDeserializer: DeserializationStrategy<ResultType>, resultDeserializer: DeserializationStrategy<ResultType>,
mimetype: String = "*/*", mimetype: String = "*/*",
additionalParametersBuilder: FormBuilder.() -> Unit = {}, additionalParametersBuilder: FormBuilder.() -> Unit = {},

View File

@@ -10,7 +10,7 @@ open class ReadCRUDCacheRepo<ObjectType, IdType>(
protected open val parentRepo: ReadCRUDRepo<ObjectType, IdType>, protected open val parentRepo: ReadCRUDRepo<ObjectType, IdType>,
protected open val kvCache: KVCache<IdType, ObjectType>, protected open val kvCache: KVCache<IdType, ObjectType>,
protected open val idGetter: (ObjectType) -> IdType protected open val idGetter: (ObjectType) -> IdType
) : ReadCRUDRepo<ObjectType, IdType> by parentRepo { ) : ReadCRUDRepo<ObjectType, IdType> by parentRepo, CacheRepo {
override suspend fun getById(id: IdType): ObjectType? = kvCache.get(id) ?: (parentRepo.getById(id) ?.also { override suspend fun getById(id: IdType): ObjectType? = kvCache.get(id) ?: (parentRepo.getById(id) ?.also {
kvCache.set(id, it) kvCache.set(id, it)
}) })
@@ -28,7 +28,7 @@ open class WriteCRUDCacheRepo<ObjectType, IdType, InputValueType>(
protected open val kvCache: KVCache<IdType, ObjectType>, protected open val kvCache: KVCache<IdType, ObjectType>,
protected open val scope: CoroutineScope = CoroutineScope(Dispatchers.Default), protected open val scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
protected open val idGetter: (ObjectType) -> IdType protected open val idGetter: (ObjectType) -> IdType
) : WriteCRUDRepo<ObjectType, IdType, InputValueType> { ) : WriteCRUDRepo<ObjectType, IdType, InputValueType>, CacheRepo {
override val newObjectsFlow: Flow<ObjectType> by parentRepo::newObjectsFlow override val newObjectsFlow: Flow<ObjectType> by parentRepo::newObjectsFlow
override val updatedObjectsFlow: Flow<ObjectType> by parentRepo::updatedObjectsFlow override val updatedObjectsFlow: Flow<ObjectType> by parentRepo::updatedObjectsFlow
override val deletedObjectsIdsFlow: Flow<IdType> by parentRepo::deletedObjectsIdsFlow override val deletedObjectsIdsFlow: Flow<IdType> by parentRepo::deletedObjectsIdsFlow

View File

@@ -0,0 +1,3 @@
package dev.inmo.micro_utils.repos.cache
interface CacheRepo

View File

@@ -11,7 +11,7 @@ import kotlinx.coroutines.flow.*
open class ReadKeyValueCacheRepo<Key,Value>( open class ReadKeyValueCacheRepo<Key,Value>(
protected open val parentRepo: ReadKeyValueRepo<Key, Value>, protected open val parentRepo: ReadKeyValueRepo<Key, Value>,
protected open val kvCache: KVCache<Key, Value>, protected open val kvCache: KVCache<Key, Value>,
) : ReadKeyValueRepo<Key,Value> by parentRepo { ) : ReadKeyValueRepo<Key,Value> by parentRepo, CacheRepo {
override suspend fun get(k: Key): Value? = kvCache.get(k) ?: parentRepo.get(k) ?.also { kvCache.set(k, it) } override suspend fun get(k: Key): Value? = kvCache.get(k) ?: parentRepo.get(k) ?.also { kvCache.set(k, it) }
override suspend fun contains(key: Key): Boolean = kvCache.contains(key) || parentRepo.contains(key) override suspend fun contains(key: Key): Boolean = kvCache.contains(key) || parentRepo.contains(key)
} }
@@ -24,7 +24,7 @@ open class KeyValueCacheRepo<Key,Value>(
parentRepo: KeyValueRepo<Key, Value>, parentRepo: KeyValueRepo<Key, Value>,
kvCache: KVCache<Key, Value>, kvCache: KVCache<Key, Value>,
scope: CoroutineScope = CoroutineScope(Dispatchers.Default) scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
) : ReadKeyValueCacheRepo<Key,Value>(parentRepo, kvCache), KeyValueRepo<Key,Value>, WriteKeyValueRepo<Key, Value> by parentRepo { ) : ReadKeyValueCacheRepo<Key,Value>(parentRepo, kvCache), KeyValueRepo<Key,Value>, WriteKeyValueRepo<Key, Value> by parentRepo, CacheRepo {
protected val onNewJob = parentRepo.onNewValue.onEach { kvCache.set(it.first, it.second) }.launchIn(scope) protected val onNewJob = parentRepo.onNewValue.onEach { kvCache.set(it.first, it.second) }.launchIn(scope)
protected val onRemoveJob = parentRepo.onValueRemoved.onEach { kvCache.unset(it) }.launchIn(scope) protected val onRemoveJob = parentRepo.onValueRemoved.onEach { kvCache.unset(it) }.launchIn(scope)
} }

View File

@@ -13,7 +13,7 @@ import kotlinx.coroutines.flow.*
open class ReadKeyValuesCacheRepo<Key,Value>( open class ReadKeyValuesCacheRepo<Key,Value>(
protected open val parentRepo: ReadKeyValuesRepo<Key, Value>, protected open val parentRepo: ReadKeyValuesRepo<Key, Value>,
protected open val kvCache: KVCache<Key, List<Value>> protected open val kvCache: KVCache<Key, List<Value>>
) : ReadKeyValuesRepo<Key,Value> by parentRepo { ) : ReadKeyValuesRepo<Key,Value> by parentRepo, CacheRepo {
override suspend fun get(k: Key, pagination: Pagination, reversed: Boolean): PaginationResult<Value> { override suspend fun get(k: Key, pagination: Pagination, reversed: Boolean): PaginationResult<Value> {
return kvCache.get(k) ?.paginate( return kvCache.get(k) ?.paginate(
pagination.let { if (reversed) it.reverse(count(k)) else it } pagination.let { if (reversed) it.reverse(count(k)) else it }
@@ -38,7 +38,7 @@ open class KeyValuesCacheRepo<Key,Value>(
parentRepo: KeyValuesRepo<Key, Value>, parentRepo: KeyValuesRepo<Key, Value>,
kvCache: KVCache<Key, List<Value>>, kvCache: KVCache<Key, List<Value>>,
scope: CoroutineScope = CoroutineScope(Dispatchers.Default) scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
) : ReadKeyValuesCacheRepo<Key,Value>(parentRepo, kvCache), KeyValuesRepo<Key,Value>, WriteKeyValuesRepo<Key,Value> by parentRepo { ) : ReadKeyValuesCacheRepo<Key,Value>(parentRepo, kvCache), KeyValuesRepo<Key,Value>, WriteKeyValuesRepo<Key,Value> by parentRepo, CacheRepo {
protected val onNewJob = parentRepo.onNewValue.onEach { kvCache.set(it.first, kvCache.get(it.first) ?.plus(it.second) ?: listOf(it.second)) }.launchIn(scope) protected val onNewJob = parentRepo.onNewValue.onEach { kvCache.set(it.first, kvCache.get(it.first) ?.plus(it.second) ?: listOf(it.second)) }.launchIn(scope)
protected val onRemoveJob = parentRepo.onValueRemoved.onEach { kvCache.set(it.first, kvCache.get(it.first) ?.minus(it.second) ?: return@onEach) }.launchIn(scope) protected val onRemoveJob = parentRepo.onValueRemoved.onEach { kvCache.set(it.first, kvCache.get(it.first) ?.minus(it.second) ?: return@onEach) }.launchIn(scope)
protected val onDataClearedJob = parentRepo.onDataCleared.onEach { kvCache.unset(it) }.launchIn(scope) protected val onDataClearedJob = parentRepo.onDataCleared.onEach { kvCache.unset(it) }.launchIn(scope)

View File

@@ -15,7 +15,7 @@ open class FullReadCRUDCacheRepo<ObjectType, IdType>(
protected open val parentRepo: ReadCRUDRepo<ObjectType, IdType>, protected open val parentRepo: ReadCRUDRepo<ObjectType, IdType>,
protected open val kvCache: FullKVCache<IdType, ObjectType>, protected open val kvCache: FullKVCache<IdType, ObjectType>,
protected open val idGetter: (ObjectType) -> IdType protected open val idGetter: (ObjectType) -> IdType
) : ReadCRUDRepo<ObjectType, IdType> { ) : ReadCRUDRepo<ObjectType, IdType>, FullCacheRepo {
protected inline fun <T> doOrTakeAndActualize( protected inline fun <T> doOrTakeAndActualize(
action: FullKVCache<IdType, ObjectType>.() -> Optional<T>, action: FullKVCache<IdType, ObjectType>.() -> Optional<T>,
actionElse: ReadCRUDRepo<ObjectType, IdType>.() -> T, actionElse: ReadCRUDRepo<ObjectType, IdType>.() -> T,
@@ -31,7 +31,7 @@ open class FullReadCRUDCacheRepo<ObjectType, IdType>(
error("The result should be returned above") error("The result should be returned above")
} }
protected suspend fun actualizeAll() { protected open suspend fun actualizeAll() {
kvCache.clear() kvCache.clear()
doForAllWithNextPaging { doForAllWithNextPaging {
parentRepo.getByPagination(it).also { parentRepo.getByPagination(it).also {

View File

@@ -0,0 +1,5 @@
package dev.inmo.micro_utils.repos.cache.full
import dev.inmo.micro_utils.repos.cache.CacheRepo
interface FullCacheRepo : CacheRepo

View File

@@ -13,7 +13,7 @@ import kotlinx.coroutines.flow.*
open class FullReadKeyValueCacheRepo<Key,Value>( open class FullReadKeyValueCacheRepo<Key,Value>(
protected open val parentRepo: ReadKeyValueRepo<Key, Value>, protected open val parentRepo: ReadKeyValueRepo<Key, Value>,
protected open val kvCache: FullKVCache<Key, Value>, protected open val kvCache: FullKVCache<Key, Value>,
) : ReadKeyValueRepo<Key, Value> { ) : ReadKeyValueRepo<Key, Value>, FullCacheRepo {
protected inline fun <T> doOrTakeAndActualize( protected inline fun <T> doOrTakeAndActualize(
action: FullKVCache<Key, Value>.() -> Optional<T>, action: FullKVCache<Key, Value>.() -> Optional<T>,
actionElse: ReadKeyValueRepo<Key, Value>.() -> T, actionElse: ReadKeyValueRepo<Key, Value>.() -> T,
@@ -28,7 +28,7 @@ open class FullReadKeyValueCacheRepo<Key,Value>(
} }
error("The result should be returned above") error("The result should be returned above")
} }
protected suspend fun actualizeAll() { protected open suspend fun actualizeAll() {
kvCache.clear() kvCache.clear()
kvCache.set(parentRepo.getAll { keys(it) }.toMap()) kvCache.set(parentRepo.getAll { keys(it) }.toMap())
} }
@@ -78,7 +78,7 @@ open class FullWriteKeyValueCacheRepo<Key,Value>(
protected open val parentRepo: WriteKeyValueRepo<Key, Value>, protected open val parentRepo: WriteKeyValueRepo<Key, Value>,
protected open val kvCache: FullKVCache<Key, Value>, protected open val kvCache: FullKVCache<Key, Value>,
scope: CoroutineScope = CoroutineScope(Dispatchers.Default) scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
) : WriteKeyValueRepo<Key, Value> by parentRepo { ) : WriteKeyValueRepo<Key, Value> by parentRepo, FullCacheRepo {
protected val onNewJob = parentRepo.onNewValue.onEach { kvCache.set(it.first, it.second) }.launchIn(scope) protected val onNewJob = parentRepo.onNewValue.onEach { kvCache.set(it.first, it.second) }.launchIn(scope)
protected val onRemoveJob = parentRepo.onValueRemoved.onEach { kvCache.unset(it) }.launchIn(scope) protected val onRemoveJob = parentRepo.onValueRemoved.onEach { kvCache.unset(it) }.launchIn(scope)
} }

View File

@@ -12,7 +12,7 @@ import kotlinx.coroutines.flow.*
open class FullReadKeyValuesCacheRepo<Key,Value>( open class FullReadKeyValuesCacheRepo<Key,Value>(
protected open val parentRepo: ReadKeyValuesRepo<Key, Value>, protected open val parentRepo: ReadKeyValuesRepo<Key, Value>,
protected open val kvCache: FullKVCache<Key, List<Value>>, protected open val kvCache: FullKVCache<Key, List<Value>>,
) : ReadKeyValuesRepo<Key, Value> { ) : ReadKeyValuesRepo<Key, Value>, FullCacheRepo {
protected inline fun <T> doOrTakeAndActualize( protected inline fun <T> doOrTakeAndActualize(
action: FullKVCache<Key, List<Value>>.() -> Optional<T>, action: FullKVCache<Key, List<Value>>.() -> Optional<T>,
actionElse: ReadKeyValuesRepo<Key, Value>.() -> T, actionElse: ReadKeyValuesRepo<Key, Value>.() -> T,
@@ -28,11 +28,11 @@ open class FullReadKeyValuesCacheRepo<Key,Value>(
error("The result should be returned above") error("The result should be returned above")
} }
protected suspend fun actualizeKey(k: Key) { protected open suspend fun actualizeKey(k: Key) {
kvCache.set(k, parentRepo.getAll(k)) kvCache.set(k, parentRepo.getAll(k))
} }
protected suspend fun actualizeAll() { protected open suspend fun actualizeAll() {
doAllWithCurrentPaging { kvCache.keys(it).also { kvCache.unset(it.results) } } doAllWithCurrentPaging { kvCache.keys(it).also { kvCache.unset(it.results) } }
kvCache.set(parentRepo.getAll()) kvCache.set(parentRepo.getAll())
} }
@@ -112,7 +112,7 @@ open class FullWriteKeyValuesCacheRepo<Key,Value>(
protected open val parentRepo: WriteKeyValuesRepo<Key, Value>, protected open val parentRepo: WriteKeyValuesRepo<Key, Value>,
protected open val kvCache: FullKVCache<Key, List<Value>>, protected open val kvCache: FullKVCache<Key, List<Value>>,
scope: CoroutineScope = CoroutineScope(Dispatchers.Default) scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
) : WriteKeyValuesRepo<Key, Value> by parentRepo { ) : WriteKeyValuesRepo<Key, Value> by parentRepo, FullCacheRepo {
protected val onNewJob = parentRepo.onNewValue.onEach { protected val onNewJob = parentRepo.onNewValue.onEach {
kvCache.set( kvCache.set(
it.first, it.first,

View File

@@ -34,7 +34,7 @@ class FileReadKeyValueRepo(
override suspend fun values(pagination: Pagination, reversed: Boolean): PaginationResult<File> { override suspend fun values(pagination: Pagination, reversed: Boolean): PaginationResult<File> {
val count = count() val count = count()
val resultPagination = if (reversed) pagination.reverse(count) else pagination val resultPagination = if (reversed) pagination.reverse(count) else pagination
val filesPaths = folder.list() ?.copyOfRange(resultPagination.firstIndex, resultPagination.lastIndex) ?: return emptyPaginationResult() val filesPaths = folder.list() ?.copyOfRange(resultPagination.firstIndex, resultPagination.lastIndexExclusive) ?: return emptyPaginationResult()
if (reversed) { if (reversed) {
filesPaths.reverse() filesPaths.reverse()
} }
@@ -47,7 +47,7 @@ class FileReadKeyValueRepo(
override suspend fun keys(pagination: Pagination, reversed: Boolean): PaginationResult<String> { override suspend fun keys(pagination: Pagination, reversed: Boolean): PaginationResult<String> {
val count = count() val count = count()
val resultPagination = if (reversed) pagination.reverse(count) else pagination val resultPagination = if (reversed) pagination.reverse(count) else pagination
val filesPaths = folder.list() ?.copyOfRange(resultPagination.firstIndex, resultPagination.lastIndex) ?: return emptyPaginationResult() val filesPaths = folder.list() ?.copyOfRange(resultPagination.firstIndex, resultPagination.lastIndexExclusive) ?: return emptyPaginationResult()
if (reversed) { if (reversed) {
filesPaths.reverse() filesPaths.reverse()
} }

View File

@@ -56,25 +56,25 @@ class KtorWriteStandardCrudRepo<ObjectType, IdType, InputValue> (
override suspend fun create(values: List<InputValue>): List<ObjectType> = unifiedRequester.unipost( override suspend fun create(values: List<InputValue>): List<ObjectType> = unifiedRequester.unipost(
buildStandardUrl(baseUrl, createRouting), buildStandardUrl(baseUrl, createRouting),
BodyPair(listInputSerializer, values), Pair(listInputSerializer, values),
listObjectsSerializer listObjectsSerializer
) )
override suspend fun update(id: IdType, value: InputValue): ObjectType? = unifiedRequester.unipost( override suspend fun update(id: IdType, value: InputValue): ObjectType? = unifiedRequester.unipost(
buildStandardUrl(baseUrl, updateRouting), buildStandardUrl(baseUrl, updateRouting),
BodyPair(inputUpdateSerializer, id to value), Pair(inputUpdateSerializer, id to value),
objectsNullableSerializer objectsNullableSerializer
) )
override suspend fun update(values: List<UpdatedValuePair<IdType, InputValue>>): List<ObjectType> = unifiedRequester.unipost( override suspend fun update(values: List<UpdatedValuePair<IdType, InputValue>>): List<ObjectType> = unifiedRequester.unipost(
buildStandardUrl(baseUrl, updateManyRouting), buildStandardUrl(baseUrl, updateManyRouting),
BodyPair(listInputUpdateSerializer, values), Pair(listInputUpdateSerializer, values),
listObjectsSerializer listObjectsSerializer
) )
override suspend fun deleteById(ids: List<IdType>) = unifiedRequester.unipost( override suspend fun deleteById(ids: List<IdType>) = unifiedRequester.unipost(
buildStandardUrl(baseUrl, deleteByIdRouting), buildStandardUrl(baseUrl, deleteByIdRouting),
BodyPair(listIdsSerializer, ids), Pair(listIdsSerializer, ids),
Unit.serializer() Unit.serializer()
) )
} }

View File

@@ -45,7 +45,7 @@ class KtorWriteStandardKeyValueRepo<K, V> (
baseUrl, baseUrl,
setRoute setRoute
), ),
BodyPair(keyValueMapSerializer, toSet), Pair(keyValueMapSerializer, toSet),
Unit.serializer() Unit.serializer()
) )
@@ -54,7 +54,7 @@ class KtorWriteStandardKeyValueRepo<K, V> (
baseUrl, baseUrl,
unsetRoute, unsetRoute,
), ),
BodyPair(keysListSerializer, toUnset), Pair(keysListSerializer, toUnset),
Unit.serializer() Unit.serializer()
) )
@@ -63,7 +63,7 @@ class KtorWriteStandardKeyValueRepo<K, V> (
baseUrl, baseUrl,
unsetWithValuesRoute, unsetWithValuesRoute,
), ),
BodyPair(valuesListSerializer, toUnset), Pair(valuesListSerializer, toUnset),
Unit.serializer() Unit.serializer()
) )
} }

View File

@@ -47,7 +47,7 @@ class KtorWriteOneToManyKeyValueRepo<Key, Value> (
baseUrl, baseUrl,
removeRoute, removeRoute,
), ),
BodyPair(keyValueMapSerializer, toRemove), Pair(keyValueMapSerializer, toRemove),
Unit.serializer(), Unit.serializer(),
) )
@@ -56,7 +56,7 @@ class KtorWriteOneToManyKeyValueRepo<Key, Value> (
baseUrl, baseUrl,
addRoute, addRoute,
), ),
BodyPair(keyValueMapSerializer, toAdd), Pair(keyValueMapSerializer, toAdd),
Unit.serializer(), Unit.serializer(),
) )
override suspend fun clear(k: Key) = unifiedRequester.unipost( override suspend fun clear(k: Key) = unifiedRequester.unipost(
@@ -64,7 +64,7 @@ class KtorWriteOneToManyKeyValueRepo<Key, Value> (
baseUrl, baseUrl,
clearRoute, clearRoute,
), ),
BodyPair(keySerializer, k), Pair(keySerializer, k),
Unit.serializer(), Unit.serializer(),
) )
@@ -73,7 +73,7 @@ class KtorWriteOneToManyKeyValueRepo<Key, Value> (
baseUrl, baseUrl,
clearWithValueRoute, clearWithValueRoute,
), ),
BodyPair(valueSerializer, v), Pair(valueSerializer, v),
Unit.serializer(), Unit.serializer(),
) )
@@ -82,7 +82,7 @@ class KtorWriteOneToManyKeyValueRepo<Key, Value> (
baseUrl, baseUrl,
setRoute, setRoute,
), ),
BodyPair(keyValueMapSerializer, toSet), Pair(keyValueMapSerializer, toSet),
Unit.serializer(), Unit.serializer(),
) )
} }