From e026e94cbf02a683b094d9a56895a0166f6a8c8b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 25 Oct 2020 21:52:36 +0600 Subject: [PATCH 1/5] start 0.2.2 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb396f6008a..ad4594b8140 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.2.2 + ## 0.2.1 * `Pagination` diff --git a/gradle.properties b/gradle.properties index 03f3e2ae9bb..7103c62bf89 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,4 +19,4 @@ github_release_plugin_version=2.2.12 uuidVersion=0.2.2 group=dev.inmo -version=0.2.1 +version=0.2.2 From 6115c1bcac7fccf657eb3d06bbe98d95343ac17b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 25 Oct 2020 22:08:42 +0600 Subject: [PATCH 2/5] add extensions for OneToManyKeyValueRepo --- .../repos/OneToManyKeyValueRepo.kt | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/OneToManyKeyValueRepo.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/OneToManyKeyValueRepo.kt index 4c6b71e6b9b..e1313311baf 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/OneToManyKeyValueRepo.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/OneToManyKeyValueRepo.kt @@ -1,7 +1,6 @@ package dev.inmo.micro_utils.repos -import dev.inmo.micro_utils.pagination.Pagination -import dev.inmo.micro_utils.pagination.PaginationResult +import dev.inmo.micro_utils.pagination.* import kotlinx.coroutines.flow.Flow interface ReadOneToManyKeyValueRepo : Repo { @@ -11,6 +10,30 @@ interface ReadOneToManyKeyValueRepo : Repo { suspend fun contains(k: Key, v: Value): Boolean suspend fun count(k: Key): Long suspend fun count(): Long + + suspend fun getAll(k: Key, reversed: Boolean = false): List = mutableListOf().also { list -> + doWithPagination { + get(k, it).also { + list.addAll(it.results) + }.nextPageIfNotEmpty() + } + if (reversed) { + list.reverse() + } + } + + /** + * WARNING!!! THIS METHOD PROBABLY IS NOT EFFICIENT, USE WITH CAUTION + */ + suspend fun getAll(): Map> = mutableMapOf>().also { map -> + doWithPagination { + keys(it).also { paginationResult -> + paginationResult.results.forEach { k -> + map[k] = getAll(k) + } + }.nextPageIfNotEmpty() + } + } } @Deprecated("Renamed", ReplaceWith("ReadOneToManyKeyValueRepo", "dev.inmo.micro_utils.repos.ReadOneToManyKeyValueRepo")) typealias OneToManyReadKeyValueRepo = ReadOneToManyKeyValueRepo @@ -20,8 +43,20 @@ interface WriteOneToManyKeyValueRepo : Repo { val onValueRemoved: Flow> val onDataCleared: Flow + @Deprecated("Will be extracted as extension for other add method") suspend fun add(k: Key, v: Value) + suspend fun add(toAdd: Map>) = toAdd.forEach { (k, values) -> + values.forEach { v -> + add(k, v) + } + } + @Deprecated("Will be extracted as extension for other remove method") suspend fun remove(k: Key, v: Value) + suspend fun remove(toRemove: Map>) = toRemove.forEach { (k, values) -> + values.forEach { v -> + remove(k, v) + } + } suspend fun clear(k: Key) } @Deprecated("Renamed", ReplaceWith("WriteOneToManyKeyValueRepo", "dev.inmo.micro_utils.repos.WriteOneToManyKeyValueRepo")) From 9ece160aa8133f402669c22efa3b1a6535305d47 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 25 Oct 2020 22:21:23 +0600 Subject: [PATCH 3/5] add extensions for onetomany functions --- CHANGELOG.md | 6 ++++ .../repos/OneToManyKeyValueRepo.kt | 32 +++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad4594b8140..c0c7930620e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## 0.2.2 +* `Repos` + * `Common` + * Several new methods `ReadOneToManyKeyValueRepo#getAll` + * Several new method `WriteOneToManyKeyValueRepo#add` and several extensions + * Several new method `WriteOneToManyKeyValueRepo#remove` and several extensions + ## 0.2.1 * `Pagination` diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/OneToManyKeyValueRepo.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/OneToManyKeyValueRepo.kt index e1313311baf..6fe71e2f445 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/OneToManyKeyValueRepo.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/OneToManyKeyValueRepo.kt @@ -25,11 +25,11 @@ interface ReadOneToManyKeyValueRepo : Repo { /** * WARNING!!! THIS METHOD PROBABLY IS NOT EFFICIENT, USE WITH CAUTION */ - suspend fun getAll(): Map> = mutableMapOf>().also { map -> + suspend fun getAll(reverseLists: Boolean = false): Map> = mutableMapOf>().also { map -> doWithPagination { keys(it).also { paginationResult -> paginationResult.results.forEach { k -> - map[k] = getAll(k) + map[k] = getAll(k, reverseLists) } }.nextPageIfNotEmpty() } @@ -62,4 +62,30 @@ interface WriteOneToManyKeyValueRepo : Repo { @Deprecated("Renamed", ReplaceWith("WriteOneToManyKeyValueRepo", "dev.inmo.micro_utils.repos.WriteOneToManyKeyValueRepo")) typealias OneToManyWriteKeyValueRepo = WriteOneToManyKeyValueRepo -interface OneToManyKeyValueRepo : ReadOneToManyKeyValueRepo, WriteOneToManyKeyValueRepo \ No newline at end of file +interface OneToManyKeyValueRepo : ReadOneToManyKeyValueRepo, WriteOneToManyKeyValueRepo + +suspend inline fun > REPO.add( + k: Key, + vararg v: Value +) = add(mapOf(k to v.toList())) + +suspend inline fun > REPO.add( + keysAndValues: List>> +) = add(keysAndValues.toMap()) + +suspend inline fun > REPO.add( + vararg keysAndValues: Pair> +) = add(keysAndValues.toMap()) + +suspend inline fun > REPO.remove( + k: Key, + vararg v: Value +) = remove(mapOf(k to v.toList())) + +suspend inline fun > REPO.remove( + keysAndValues: List>> +) = remove(keysAndValues.toMap()) + +suspend inline fun > REPO.remove( + vararg keysAndValues: Pair> +) = remove(keysAndValues.toMap()) From 6928ca53293018c1680a74d6ef05b1be5463c67f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 25 Oct 2020 22:21:54 +0600 Subject: [PATCH 4/5] optimize imports --- .../repos/pagination/KeyValuePaginationExtensions.kt | 2 +- .../repos/pagination/OneToManyPaginationExtensions.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/KeyValuePaginationExtensions.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/KeyValuePaginationExtensions.kt index 4442571948c..9a4b3391f2f 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/KeyValuePaginationExtensions.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/KeyValuePaginationExtensions.kt @@ -1,7 +1,7 @@ package dev.inmo.micro_utils.repos.pagination import dev.inmo.micro_utils.pagination.* -import dev.inmo.micro_utils.repos.* +import dev.inmo.micro_utils.repos.ReadStandardKeyValueRepo suspend inline fun > REPO.doForAll( @Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE") diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/OneToManyPaginationExtensions.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/OneToManyPaginationExtensions.kt index 0c3de2def3c..28d3405e595 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/OneToManyPaginationExtensions.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/OneToManyPaginationExtensions.kt @@ -1,7 +1,7 @@ package dev.inmo.micro_utils.repos.pagination import dev.inmo.micro_utils.pagination.* -import dev.inmo.micro_utils.repos.* +import dev.inmo.micro_utils.repos.ReadOneToManyKeyValueRepo suspend inline fun > REPO.doForAll( @Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE") From dbd2e963a14149e5a1e4e1307221c861ad884400 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 25 Oct 2020 22:23:24 +0600 Subject: [PATCH 5/5] change order of functions in read one to many interface --- .../inmo/micro_utils/repos/OneToManyKeyValueRepo.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/OneToManyKeyValueRepo.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/OneToManyKeyValueRepo.kt index 6fe71e2f445..d21048b6db0 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/OneToManyKeyValueRepo.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/OneToManyKeyValueRepo.kt @@ -43,20 +43,22 @@ interface WriteOneToManyKeyValueRepo : Repo { val onValueRemoved: Flow> val onDataCleared: Flow - @Deprecated("Will be extracted as extension for other add method") - suspend fun add(k: Key, v: Value) suspend fun add(toAdd: Map>) = toAdd.forEach { (k, values) -> values.forEach { v -> add(k, v) } } - @Deprecated("Will be extracted as extension for other remove method") - suspend fun remove(k: Key, v: Value) + @Deprecated("Will be extracted as extension for other add method") + suspend fun add(k: Key, v: Value) + suspend fun remove(toRemove: Map>) = toRemove.forEach { (k, values) -> values.forEach { v -> remove(k, v) } } + @Deprecated("Will be extracted as extension for other remove method") + suspend fun remove(k: Key, v: Value) + suspend fun clear(k: Key) } @Deprecated("Renamed", ReplaceWith("WriteOneToManyKeyValueRepo", "dev.inmo.micro_utils.repos.WriteOneToManyKeyValueRepo"))