mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-22 16:47:15 +00:00
commit
8379f5b388
2
.gitignore
vendored
2
.gitignore
vendored
@ -8,3 +8,5 @@ settings.xml
|
||||
.gradle/
|
||||
build/
|
||||
out/
|
||||
|
||||
secret.gradle
|
||||
|
14
CHANGELOG.md
Normal file
14
CHANGELOG.md
Normal file
@ -0,0 +1,14 @@
|
||||
# Changelog
|
||||
|
||||
## 0.1.0
|
||||
|
||||
Inited :)
|
||||
|
||||
### 0.1.1
|
||||
|
||||
* `Repos`
|
||||
* `Common`
|
||||
* Extensions `doForAll` and `getAll` were added for all current types of repos:
|
||||
* `ReadStandardCRUDRepo`
|
||||
* `StandardReadKeyValueRepo`
|
||||
* `OneToManyReadKeyValueRepo`
|
@ -10,6 +10,7 @@ buildscript {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
|
||||
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$gradle_bintray_plugin_version"
|
||||
classpath "com.github.breadmoirai:github-release:$github_release_plugin_version"
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,3 +22,4 @@ repositories {
|
||||
}
|
||||
|
||||
apply from: "./extensions.gradle"
|
||||
apply from: "./github_release.gradle"
|
||||
|
24
changelog_info_retriever
Executable file
24
changelog_info_retriever
Executable file
@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
function parse() {
|
||||
version=$1
|
||||
|
||||
while IFS= read -r line && [ -z "`echo $line | grep -e "^#\+ $version"`" ]
|
||||
do
|
||||
: # do nothing
|
||||
done
|
||||
|
||||
while IFS= read -r line && [ -z "`echo $line | grep -e "^#\+"`" ]
|
||||
do
|
||||
echo "$line"
|
||||
done
|
||||
}
|
||||
|
||||
version=$1
|
||||
file=$2
|
||||
|
||||
if [ -n "$file" ]; then
|
||||
parse $version < "$file"
|
||||
else
|
||||
parse $version
|
||||
fi
|
27
github_release.gradle
Normal file
27
github_release.gradle
Normal file
@ -0,0 +1,27 @@
|
||||
private String getCurrentVersionChangelog() {
|
||||
OutputStream changelogDataOS = new ByteArrayOutputStream()
|
||||
exec {
|
||||
standardOutput = changelogDataOS
|
||||
commandLine './changelog_info_retriever', "$library_version", 'CHANGELOG.md'
|
||||
}
|
||||
|
||||
return changelogDataOS.toString().trim()
|
||||
}
|
||||
|
||||
if (new File(projectDir, "secret.gradle").exists()) {
|
||||
apply from: './secret.gradle'
|
||||
apply plugin: "com.github.breadmoirai.github-release"
|
||||
|
||||
githubRelease {
|
||||
token "${project.property('GITHUB_RELEASE_TOKEN')}"
|
||||
|
||||
owner "InsanusMokrassar"
|
||||
repo "MicroUtils"
|
||||
|
||||
tagName "$library_version"
|
||||
releaseName "$library_version"
|
||||
targetCommitish "$library_version"
|
||||
|
||||
body getCurrentVersionChangelog()
|
||||
}
|
||||
}
|
@ -10,8 +10,9 @@ ktor_version=1.4.1
|
||||
klockVersion=1.12.1
|
||||
|
||||
gradle_bintray_plugin_version=1.8.5
|
||||
github_release_plugin_version=2.2.12
|
||||
|
||||
uuidVersion=0.2.2
|
||||
|
||||
group=dev.inmo
|
||||
version=0.1.0
|
||||
version=0.1.1
|
||||
|
@ -6,8 +6,8 @@ import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface StandardReadKeyValueRepo<Key, Value> : Repo {
|
||||
suspend fun get(k: Key): Value?
|
||||
suspend fun values(pagination: Pagination, reversed: Boolean): PaginationResult<Value>
|
||||
suspend fun keys(pagination: Pagination, reversed: Boolean): PaginationResult<Key>
|
||||
suspend fun values(pagination: Pagination, reversed: Boolean = false): PaginationResult<Value>
|
||||
suspend fun keys(pagination: Pagination, reversed: Boolean = false): PaginationResult<Key>
|
||||
suspend fun contains(key: Key): Boolean
|
||||
suspend fun count(): Long
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
package dev.inmo.micro_utils.repos.pagination
|
||||
|
||||
import dev.inmo.micro_utils.pagination.*
|
||||
import dev.inmo.micro_utils.repos.ReadStandardCRUDRepo
|
||||
|
||||
suspend inline fun <T, ID, REPO : ReadStandardCRUDRepo<T, ID>> REPO.doForAll(
|
||||
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
|
||||
methodCaller: suspend REPO.(Pagination) -> PaginationResult<T>,
|
||||
block: (List<T>) -> Unit
|
||||
) {
|
||||
doWithPagination {
|
||||
methodCaller(it).also {
|
||||
block(it.results)
|
||||
}.nextPageIfNotEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
suspend inline fun <T, ID, REPO : ReadStandardCRUDRepo<T, ID>> REPO.doForAll(
|
||||
block: (List<T>) -> Unit
|
||||
) = doForAll({ getByPagination(it) }, block)
|
||||
|
||||
suspend inline fun <T, ID, REPO : ReadStandardCRUDRepo<T, ID>> REPO.getAll(
|
||||
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
|
||||
methodCaller: suspend REPO.(Pagination) -> PaginationResult<T>
|
||||
): List<T> {
|
||||
val resultList = mutableListOf<T>()
|
||||
doForAll(methodCaller) {
|
||||
resultList.addAll(it)
|
||||
}
|
||||
return resultList
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package dev.inmo.micro_utils.repos.pagination
|
||||
|
||||
import dev.inmo.micro_utils.pagination.*
|
||||
import dev.inmo.micro_utils.repos.*
|
||||
|
||||
suspend inline fun <Key, Value, REPO : StandardReadKeyValueRepo<Key, Value>> REPO.doForAll(
|
||||
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
|
||||
methodCaller: suspend REPO.(Pagination) -> PaginationResult<Key>,
|
||||
block: (List<Pair<Key, Value>>) -> Unit
|
||||
) {
|
||||
doWithPagination {
|
||||
methodCaller(it).also { keys ->
|
||||
block(keys.results.mapNotNull { key -> get(key) ?.let { value -> key to value } })
|
||||
}.nextPageIfNotEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
suspend inline fun <Key, Value, REPO : StandardReadKeyValueRepo<Key, Value>> REPO.doForAll(
|
||||
block: (List<Pair<Key, Value>>) -> Unit
|
||||
) = doForAll({ keys(it, false) }, block)
|
||||
|
||||
suspend inline fun <Key, Value, REPO : StandardReadKeyValueRepo<Key, Value>> REPO.getAll(
|
||||
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
|
||||
methodCaller: suspend REPO.(Pagination) -> PaginationResult<Key>
|
||||
): List<Pair<Key, Value>> {
|
||||
val resultList = mutableListOf<Pair<Key, Value>>()
|
||||
doForAll(methodCaller) {
|
||||
resultList.addAll(it)
|
||||
}
|
||||
return resultList
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package dev.inmo.micro_utils.repos.pagination
|
||||
|
||||
import dev.inmo.micro_utils.pagination.*
|
||||
import dev.inmo.micro_utils.repos.*
|
||||
|
||||
suspend inline fun <Key, Value, REPO : OneToManyReadKeyValueRepo<Key, Value>> REPO.doForAll(
|
||||
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
|
||||
methodCaller: suspend REPO.(Pagination) -> PaginationResult<Key>,
|
||||
block: (List<Pair<Key, List<Value>>>) -> Unit
|
||||
) {
|
||||
doWithPagination {
|
||||
methodCaller(it).also { keys ->
|
||||
block(
|
||||
keys.results.mapNotNull { key ->
|
||||
val values = mutableListOf<Value>()
|
||||
doWithPagination {
|
||||
get(key, it).also {
|
||||
values.addAll(it.results)
|
||||
}.nextPageIfNotEmpty()
|
||||
}
|
||||
key to values
|
||||
}
|
||||
)
|
||||
}.nextPageIfNotEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
suspend inline fun <Key, Value, REPO : OneToManyReadKeyValueRepo<Key, Value>> REPO.doForAll(
|
||||
block: (List<Pair<Key, List<Value>>>) -> Unit
|
||||
) = doForAll({ keys(it, false) }, block)
|
||||
|
||||
suspend inline fun <Key, Value, REPO : OneToManyReadKeyValueRepo<Key, Value>> REPO.getAll(
|
||||
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
|
||||
methodCaller: suspend REPO.(Pagination) -> PaginationResult<Key>
|
||||
): List<Pair<Key, List<Value>>> {
|
||||
val resultList = mutableListOf<Pair<Key, List<Value>>>()
|
||||
doForAll(methodCaller) {
|
||||
resultList.addAll(it)
|
||||
}
|
||||
return resultList
|
||||
}
|
Loading…
Reference in New Issue
Block a user