mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-17 14:29:24 +00:00
Compare commits
58 Commits
Author | SHA1 | Date | |
---|---|---|---|
7a78742162 | |||
c01e240f66 | |||
fef4fcbac6 | |||
5ab18bce4b | |||
24aec7271a | |||
9b19a2cb95 | |||
efdd7b8a57 | |||
6df4cc9c3b | |||
b9d93db0f5 | |||
d7ee45ca64 | |||
d7c31b1b22 | |||
7d6794a358 | |||
473eb87346 | |||
8b18b07790 | |||
ab3c80a5ec | |||
075b93ecd6 | |||
f6d0f72e49 | |||
fcda3af862 | |||
d5c7a589b1 | |||
86e099ed25 | |||
ebd7befe73 | |||
b8c7e581a1 | |||
8281259179 | |||
d3e06b07df | |||
4967018418 | |||
537a3c38fa | |||
0124957833 | |||
f0420e2d61 | |||
7090566041 | |||
f0d5035cd0 | |||
0fb9b8dc30 | |||
eef6e81134 | |||
1593159a3f | |||
3da9eb9dbe | |||
f17613f3fb | |||
14337ccb46 | |||
1a3913b09c | |||
039aed2747 | |||
173991e3cb | |||
8b3f8cab01 | |||
2a20d24589 | |||
53c2d552ec | |||
af11c1a83d | |||
a65cf1481c | |||
0318716236 | |||
88eb4b3342 | |||
4810d1ef6a | |||
f2a9514d89 | |||
925ba6ac24 | |||
|
ef407268a2 | ||
cd6c4bbe38 | |||
c058e18408 | |||
6d3ca565ca | |||
236a7b4fd2 | |||
e1f387dbf7 | |||
3d113dd31e | |||
e0e57f0336 | |||
e775b58d41 |
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -8,7 +8,7 @@ jobs:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 11
|
||||
java-version: 17
|
||||
- name: Rewrite version
|
||||
run: |
|
||||
branch="`echo "${{ github.ref }}" | grep -o "[^/]*$"`"
|
||||
|
2
.github/workflows/dokka_push.yml
vendored
2
.github/workflows/dokka_push.yml
vendored
@@ -10,7 +10,7 @@ jobs:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 11
|
||||
java-version: 17
|
||||
- name: Build
|
||||
run: ./gradlew build && ./gradlew dokkaHtml
|
||||
- name: Publish KDocs
|
||||
|
90
CHANGELOG.md
90
CHANGELOG.md
@@ -1,5 +1,95 @@
|
||||
# Changelog
|
||||
|
||||
## 0.20.14
|
||||
|
||||
* `Versions`:
|
||||
* `Serialization`: `1.6.0` -> `1.6.1`
|
||||
* `KSLog`: `1.2.4` -> `1.3.0`
|
||||
|
||||
## 0.20.13
|
||||
|
||||
* `Versions`:
|
||||
* `Ktor`: `2.3.5` -> `2.3.6`
|
||||
* `UUID`: `0.8.1` -> `0.8.2`
|
||||
|
||||
## 0.20.12
|
||||
|
||||
**It is experimental migration onto new gradle version. Be careful in use of this version**
|
||||
|
||||
**This update have JDK 17 in `compatibility` and `target` versions**
|
||||
|
||||
## 0.20.11
|
||||
|
||||
* `Versions`:
|
||||
* `Kotlin`: `1.9.20-RC2` -> `1.9.20`
|
||||
* `Exposed`: `0.44.0` -> `0.44.1`
|
||||
* `Compose`: `1.5.10-rc02` -> `1.5.10`
|
||||
* `Coroutines`:
|
||||
* `SmartRWLocker` now will wait first unlock of write mutex for acquiring read
|
||||
|
||||
## 0.20.10
|
||||
|
||||
* `Versions`:
|
||||
* `Kotlin`: `1.9.20-RC` -> `1.9.20-RC1`
|
||||
* `KSLog`: `1.2.1` -> `1.2.2`
|
||||
* `Compose`: `1.5.10-rc01` -> `1.5.10-rc02`
|
||||
* `RecyclerView`: `1.3.1` -> `1.3.2`
|
||||
|
||||
## 0.20.9
|
||||
|
||||
* Most of common modules now supports `linuxArm64` target
|
||||
|
||||
## 0.20.8
|
||||
|
||||
**THIS VERSION CONTAINS UPDATES OF DEPENDENCIES UP TO RC VERSIONS. USE WITH CAUTION**
|
||||
|
||||
* `Versions`:
|
||||
* `Kotlin`: `1.9.20-Beta2` -> `1.9.20-RC`
|
||||
* `Compose`: `1.5.10-beta02` -> `1.5.10-rc01`
|
||||
|
||||
## 0.20.7
|
||||
|
||||
**THIS VERSION CONTAINS UPDATES OF DEPENDENCIES UP TO BETA VERSIONS. USE WITH CAUTION**
|
||||
|
||||
* `Versions`:
|
||||
* `Kotlin`: `1.9.10` -> `1.9.20-Beta2`
|
||||
* `Compose`: `1.5.1` -> `1.5.10-beta02`
|
||||
* `Exposed`: `0.43.0` -> `0.44.0`
|
||||
* `Ktor`: `2.3.4` -> `2.3.5`
|
||||
* `Koin`: `3.4.3` -> `3.5.0`
|
||||
* `Okio`: `3.5.0` -> `3.6.0`
|
||||
* `Android Core`: `1.10.1` -> `1.12.0`
|
||||
* `Android Compose Material`: `1.1.1` -> `1.1.2`
|
||||
|
||||
## 0.20.6
|
||||
|
||||
* `Repos`:
|
||||
* `Exposed`
|
||||
* Fixes in exposed key-values repos
|
||||
|
||||
## 0.20.5
|
||||
|
||||
* `Coroutines`:
|
||||
* Fixes in `SmartRWLocker`
|
||||
|
||||
## 0.20.4
|
||||
|
||||
* `Versions`:
|
||||
* `Kotlin`: `1.9.0` -> `1.9.10`
|
||||
* `KSLog`: `1.2.0` -> `1.2.1`
|
||||
* `Compose`: `1.5.0` -> `1.5.1`
|
||||
* `UUID`: `0.8.0` -> `0.8.1`
|
||||
|
||||
## 0.20.3
|
||||
|
||||
* `Versions`:
|
||||
* `Compose`: `1.4.3` -> `1.5.0`
|
||||
* `Exposed`: `0.42.1` -> `0.43.0`
|
||||
* `Ktor`: `2.3.3` -> `2.3.4`
|
||||
* `Repos`:
|
||||
* `Cache`:
|
||||
* Fixes in locks of caches
|
||||
|
||||
## 0.20.2
|
||||
|
||||
* All main repos uses `SmartRWLocker`
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.android.alerts.common"/>
|
||||
<manifest/>
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.android.alerts.recyclerview"/>
|
||||
<manifest/>
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.android.pickers"/>
|
||||
<manifest/>
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.android.recyclerview"/>
|
||||
<manifest/>
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.android.smalltextfield"/>
|
||||
<manifest/>
|
@@ -4,7 +4,7 @@ plugins {
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
@@ -31,5 +31,10 @@ kotlin {
|
||||
api libs.okio
|
||||
}
|
||||
}
|
||||
linuxArm64Main {
|
||||
dependencies {
|
||||
api libs.okio
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.common.compose"/>
|
||||
<manifest/>
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.common"/>
|
||||
<manifest/>
|
36
common/src/linuxArm64Main/kotlin/ActualMPPFile.kt
Normal file
36
common/src/linuxArm64Main/kotlin/ActualMPPFile.kt
Normal file
@@ -0,0 +1,36 @@
|
||||
package dev.inmo.micro_utils.common
|
||||
|
||||
import okio.FileSystem
|
||||
import okio.Path
|
||||
import okio.use
|
||||
|
||||
actual typealias MPPFile = Path
|
||||
|
||||
/**
|
||||
* @suppress
|
||||
*/
|
||||
actual val MPPFile.filename: FileName
|
||||
get() = FileName(toString())
|
||||
/**
|
||||
* @suppress
|
||||
*/
|
||||
actual val MPPFile.filesize: Long
|
||||
get() = FileSystem.SYSTEM.openReadOnly(this).use {
|
||||
it.size()
|
||||
}
|
||||
/**
|
||||
* @suppress
|
||||
*/
|
||||
actual val MPPFile.bytesAllocatorSync: ByteArrayAllocator
|
||||
get() = {
|
||||
FileSystem.SYSTEM.read(this) {
|
||||
readByteArray()
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @suppress
|
||||
*/
|
||||
actual val MPPFile.bytesAllocator: SuspendByteArrayAllocator
|
||||
get() = {
|
||||
bytesAllocatorSync()
|
||||
}
|
25
common/src/linuxArm64Main/kotlin/fixed.kt
Normal file
25
common/src/linuxArm64Main/kotlin/fixed.kt
Normal file
@@ -0,0 +1,25 @@
|
||||
package dev.inmo.micro_utils.common
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
import platform.posix.snprintf
|
||||
import platform.posix.sprintf
|
||||
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
actual fun Float.fixed(signs: Int): Float {
|
||||
return memScoped {
|
||||
val buff = allocArray<ByteVar>(Float.SIZE_BYTES * 2)
|
||||
|
||||
sprintf(buff, "%.${signs}f", this@fixed)
|
||||
buff.toKString().toFloat()
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
actual fun Double.fixed(signs: Int): Double {
|
||||
return memScoped {
|
||||
val buff = allocArray<ByteVar>(Double.SIZE_BYTES * 2)
|
||||
|
||||
sprintf(buff, "%.${signs}f", this@fixed)
|
||||
buff.toKString().toDouble()
|
||||
}
|
||||
}
|
@@ -4,7 +4,7 @@ plugins {
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.coroutines.compose"/>
|
||||
<manifest/>
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.coroutines"/>
|
||||
<manifest/>
|
@@ -23,9 +23,8 @@ class SmartRWLocker(private val readPermits: Int = Int.MAX_VALUE, writeIsLocked:
|
||||
* Do lock in [readSemaphore] inside of [writeMutex] locking
|
||||
*/
|
||||
suspend fun acquireRead() {
|
||||
_writeMutex.withLock {
|
||||
_readSemaphore.acquire()
|
||||
}
|
||||
_writeMutex.waitUnlock()
|
||||
_readSemaphore.acquire()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,14 +39,18 @@ class SmartRWLocker(private val readPermits: Int = Int.MAX_VALUE, writeIsLocked:
|
||||
*/
|
||||
suspend fun lockWrite() {
|
||||
_writeMutex.lock()
|
||||
readSemaphore.waitRelease(readPermits)
|
||||
_readSemaphore.acquire(readPermits)
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlock [writeMutex]
|
||||
*/
|
||||
suspend fun unlockWrite(): Boolean {
|
||||
return _writeMutex.unlock()
|
||||
return _writeMutex.unlock().also {
|
||||
if (it) {
|
||||
_readSemaphore.release(readPermits)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -42,11 +42,11 @@ sealed interface SmartSemaphore {
|
||||
* Mutable variant of [SmartSemaphore]. With that variant you may [lock] and [unlock]. Besides, you may create
|
||||
* [Immutable] variant of [this] instance with [immutable] factory
|
||||
*
|
||||
* @param locked Preset state of [freePermits] and its internal [_permitsStateFlow]
|
||||
* @param locked Preset state of [freePermits] and its internal [_freePermitsStateFlow]
|
||||
*/
|
||||
class Mutable(private val permits: Int, acquiredPermits: Int = 0) : SmartSemaphore {
|
||||
private val _permitsStateFlow = MutableStateFlow<Int>(permits - acquiredPermits)
|
||||
override val permitsStateFlow: StateFlow<Int> = _permitsStateFlow.asStateFlow()
|
||||
private val _freePermitsStateFlow = MutableStateFlow<Int>(permits - acquiredPermits)
|
||||
override val permitsStateFlow: StateFlow<Int> = _freePermitsStateFlow.asStateFlow()
|
||||
|
||||
private val internalChangesMutex = Mutex(false)
|
||||
|
||||
@@ -54,19 +54,45 @@ sealed interface SmartSemaphore {
|
||||
|
||||
private fun checkedPermits(permits: Int) = permits.coerceIn(1 .. this.permits)
|
||||
|
||||
/**
|
||||
* Holds call until this [SmartSemaphore] will be re-locked. That means that current method will
|
||||
*/
|
||||
suspend fun acquire(permits: Int = 1) {
|
||||
var acquiredPermits = 0
|
||||
val checkedPermits = checkedPermits(permits)
|
||||
try {
|
||||
do {
|
||||
val shouldContinue = internalChangesMutex.withLock {
|
||||
val requiredPermits = checkedPermits - acquiredPermits
|
||||
val acquiring = minOf(freePermits, requiredPermits).takeIf { it > 0 } ?: return@withLock true
|
||||
acquiredPermits += acquiring
|
||||
_freePermitsStateFlow.value -= acquiring
|
||||
|
||||
acquiredPermits != checkedPermits
|
||||
}
|
||||
if (shouldContinue) {
|
||||
waitRelease()
|
||||
}
|
||||
} while (shouldContinue && currentCoroutineContext().isActive)
|
||||
} catch (e: Throwable) {
|
||||
release(acquiredPermits)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds call until this [SmartSemaphore] will be re-locked. That means that while [freePermits] == true, [holds] will
|
||||
* wait for [freePermits] == false and then try to lock
|
||||
*/
|
||||
suspend fun acquire(permits: Int = 1) {
|
||||
suspend fun acquireByOne(permits: Int = 1) {
|
||||
val checkedPermits = checkedPermits(permits)
|
||||
do {
|
||||
val checkedPermits = checkedPermits(permits)
|
||||
waitRelease(checkedPermits)
|
||||
val shouldContinue = internalChangesMutex.withLock {
|
||||
if (_permitsStateFlow.value < checkedPermits) {
|
||||
if (_freePermitsStateFlow.value < checkedPermits) {
|
||||
true
|
||||
} else {
|
||||
_permitsStateFlow.value -= checkedPermits
|
||||
_freePermitsStateFlow.value -= checkedPermits
|
||||
false
|
||||
}
|
||||
}
|
||||
@@ -80,10 +106,10 @@ sealed interface SmartSemaphore {
|
||||
*/
|
||||
suspend fun tryAcquire(permits: Int = 1): Boolean {
|
||||
val checkedPermits = checkedPermits(permits)
|
||||
return if (_permitsStateFlow.value < checkedPermits) {
|
||||
return if (_freePermitsStateFlow.value < checkedPermits) {
|
||||
internalChangesMutex.withLock {
|
||||
if (_permitsStateFlow.value < checkedPermits) {
|
||||
_permitsStateFlow.value -= checkedPermits
|
||||
if (_freePermitsStateFlow.value < checkedPermits) {
|
||||
_freePermitsStateFlow.value -= checkedPermits
|
||||
true
|
||||
} else {
|
||||
false
|
||||
@@ -100,10 +126,10 @@ sealed interface SmartSemaphore {
|
||||
*/
|
||||
suspend fun release(permits: Int = 1): Boolean {
|
||||
val checkedPermits = checkedPermits(permits)
|
||||
return if (_permitsStateFlow.value < this.permits) {
|
||||
return if (_freePermitsStateFlow.value < this.permits) {
|
||||
internalChangesMutex.withLock {
|
||||
if (_permitsStateFlow.value < this.permits) {
|
||||
_permitsStateFlow.value = minOf(_permitsStateFlow.value + checkedPermits, this.permits)
|
||||
if (_freePermitsStateFlow.value < this.permits) {
|
||||
_freePermitsStateFlow.value = minOf(_freePermitsStateFlow.value + checkedPermits, this.permits)
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
@@ -1,10 +1,6 @@
|
||||
import dev.inmo.micro_utils.coroutines.SmartRWLocker
|
||||
import dev.inmo.micro_utils.coroutines.withReadAcquire
|
||||
import dev.inmo.micro_utils.coroutines.withWriteLock
|
||||
import kotlinx.coroutines.CoroutineStart
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.joinAll
|
||||
import kotlinx.coroutines.launch
|
||||
import dev.inmo.micro_utils.coroutines.*
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import kotlinx.coroutines.test.runTest
|
||||
@@ -57,4 +53,99 @@ class SmartRWLockerTests {
|
||||
assertEquals(expected = readAndWriteWorkers, actual = doneWrites)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun simpleWithWriteLockTest() {
|
||||
val locker = SmartRWLocker()
|
||||
|
||||
runTest {
|
||||
locker.withWriteLock {
|
||||
assertEquals(0, locker.readSemaphore.freePermits)
|
||||
assertEquals(true, locker.writeMutex.isLocked)
|
||||
}
|
||||
assertEquals(Int.MAX_VALUE, locker.readSemaphore.freePermits)
|
||||
assertEquals(false, locker.writeMutex.isLocked)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun failureWithWriteLockTest() {
|
||||
val locker = SmartRWLocker()
|
||||
|
||||
val exception = IllegalArgumentException()
|
||||
try {
|
||||
runTest {
|
||||
val subscope = kotlinx.coroutines.CoroutineScope(this.coroutineContext)
|
||||
var happenException: Throwable? = null
|
||||
try {
|
||||
locker.withWriteLock {
|
||||
val checkFunction = fun (): Deferred<Unit> {
|
||||
return subscope.async {
|
||||
assertEquals(0, locker.readSemaphore.freePermits)
|
||||
assertEquals(true, locker.writeMutex.isLocked)
|
||||
throw exception
|
||||
}
|
||||
}
|
||||
doInDefault {
|
||||
assertEquals(0, locker.readSemaphore.freePermits)
|
||||
assertEquals(true, locker.writeMutex.isLocked)
|
||||
checkFunction().await()
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
happenException = e
|
||||
}
|
||||
if (exception != happenException) {
|
||||
assertEquals(exception, happenException ?.cause)
|
||||
}
|
||||
assertEquals(Int.MAX_VALUE, locker.readSemaphore.freePermits)
|
||||
assertEquals(false, locker.writeMutex.isLocked)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
assertEquals(exception, e)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun simpleWithReadAcquireTest() {
|
||||
val locker = SmartRWLocker()
|
||||
|
||||
runTest {
|
||||
locker.withReadAcquire {
|
||||
assertEquals(Int.MAX_VALUE - 1, locker.readSemaphore.freePermits)
|
||||
assertEquals(false, locker.writeMutex.isLocked)
|
||||
locker.withReadAcquire {
|
||||
assertEquals(Int.MAX_VALUE - 2, locker.readSemaphore.freePermits)
|
||||
assertEquals(false, locker.writeMutex.isLocked)
|
||||
}
|
||||
}
|
||||
assertEquals(Int.MAX_VALUE, locker.readSemaphore.freePermits)
|
||||
assertEquals(false, locker.writeMutex.isLocked)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun simple2WithWriteLockTest() {
|
||||
val locker = SmartRWLocker()
|
||||
|
||||
val unlockDelay = 1000L // 1 sec
|
||||
var unlocked: Boolean = false
|
||||
runTest {
|
||||
launch {
|
||||
locker.withReadAcquire {
|
||||
delay(unlockDelay)
|
||||
}
|
||||
unlocked = true
|
||||
}
|
||||
locker.readSemaphore.permitsStateFlow.first { it == Int.MAX_VALUE - 1 }
|
||||
assertEquals(false, unlocked)
|
||||
locker.withWriteLock {
|
||||
assertEquals(true, unlocked)
|
||||
assertEquals(0, locker.readSemaphore.freePermits)
|
||||
assertEquals(true, locker.writeMutex.isLocked)
|
||||
}
|
||||
assertEquals(Int.MAX_VALUE, locker.readSemaphore.freePermits)
|
||||
assertEquals(false, locker.writeMutex.isLocked)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@ plugins {
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.crypto"/>
|
||||
<manifest/>
|
@@ -9,6 +9,7 @@ android {
|
||||
targetSdkVersion libs.versions.android.props.compileSdk.get().toInteger()
|
||||
versionCode "${android_code_version}".toInteger()
|
||||
versionName "$version"
|
||||
namespace "${project.group}.${project.name}"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
@@ -26,7 +27,7 @@ android {
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
sourceCompatibility JavaVersion.VERSION_17
|
||||
targetCompatibility JavaVersion.VERSION_17
|
||||
}
|
||||
}
|
||||
|
@@ -106,7 +106,7 @@ tasks.dokkaHtml {
|
||||
skipDeprecated.set(true)
|
||||
|
||||
sourceLink {
|
||||
localDirectory.set(file("./"))
|
||||
localDirectory.set(file("../"))
|
||||
remoteUrl.set(new URL("https://github.com/InsanusMokrassar/MicroUtils/blob/master/"))
|
||||
remoteLineSuffix.set("#L")
|
||||
}
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.dokka"/>
|
||||
<manifest/>
|
@@ -19,11 +19,19 @@ allprojects {
|
||||
}
|
||||
|
||||
releaseMode = (project.hasProperty('RELEASE_MODE') && project.property('RELEASE_MODE') == "true") || System.getenv('RELEASE_MODE') == "true"
|
||||
// String compilerPluginVersionFromProperties = (String) project.properties["compose.kotlinCompilerPluginVersion"]
|
||||
// String compilerPluginVersionFromLibrariesVersions = libs.versions.compose.kotlin.get()
|
||||
// composePluginKotlinVersion = compilerPluginVersionFromProperties
|
||||
// if (compilerPluginVersionFromProperties == null) {
|
||||
// composePluginKotlinVersion = compilerPluginVersionFromLibrariesVersions
|
||||
// }
|
||||
|
||||
mppProjectWithSerializationPresetPath = "${rootProject.projectDir.absolutePath}/mppProjectWithSerialization.gradle"
|
||||
mppProjectWithSerializationPresetPath = "${rootProject.projectDir.absolutePath}/mppJvmJsAndroidProject.gradle"
|
||||
mppProjectWithSerializationAndComposePresetPath = "${rootProject.projectDir.absolutePath}/mppProjectWithSerializationAndCompose.gradle"
|
||||
mppJavaProjectPresetPath = "${rootProject.projectDir.absolutePath}/mppJavaProject.gradle"
|
||||
mppJvmJsLinuxMingwProjectPresetPath = "${rootProject.projectDir.absolutePath}/mppJvmJsLinuxMingwProject.gradle"
|
||||
mppJvmJsLinuxMingwLinuxArm64ProjectPresetPath = "${rootProject.projectDir.absolutePath}/mppJvmJsLinuxMingwLinuxArm64Project.gradle"
|
||||
mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath = "${rootProject.projectDir.absolutePath}/mppJvmJsAndroidLinuxMingwLinuxArm64Project.gradle"
|
||||
mppAndroidProjectPresetPath = "${rootProject.projectDir.absolutePath}/mppAndroidProject.gradle"
|
||||
|
||||
defaultAndroidSettingsPresetPath = "${rootProject.projectDir.absolutePath}/defaultAndroidSettings.gradle"
|
||||
|
@@ -4,7 +4,7 @@ plugins {
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.fsm.common"/>
|
||||
<manifest/>
|
||||
|
@@ -4,7 +4,7 @@ plugins {
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.fsm.repos.common"/>
|
||||
<manifest/>
|
||||
|
@@ -6,7 +6,7 @@ kotlin.incremental.js=true
|
||||
#kotlin.experimental.tryK2=true
|
||||
android.useAndroidX=true
|
||||
android.enableJetifier=true
|
||||
org.gradle.jvmargs=-Xmx2g
|
||||
org.gradle.jvmargs=-Xmx2500m
|
||||
|
||||
# JS NPM
|
||||
|
||||
@@ -15,5 +15,5 @@ crypto_js_version=4.1.1
|
||||
# Project data
|
||||
|
||||
group=dev.inmo
|
||||
version=0.20.2
|
||||
android_code_version=208
|
||||
version=0.20.14
|
||||
android_code_version=220
|
||||
|
@@ -1,41 +1,41 @@
|
||||
[versions]
|
||||
|
||||
kt = "1.9.0"
|
||||
kt-serialization = "1.6.0"
|
||||
kt = "1.9.20"
|
||||
kt-serialization = "1.6.1"
|
||||
kt-coroutines = "1.7.3"
|
||||
|
||||
kslog = "1.2.0"
|
||||
kslog = "1.3.0"
|
||||
|
||||
jb-compose = "1.4.3"
|
||||
jb-exposed = "0.42.1"
|
||||
jb-dokka = "1.8.20"
|
||||
jb-compose = "1.5.10"
|
||||
jb-exposed = "0.44.1"
|
||||
jb-dokka = "1.9.10"
|
||||
|
||||
korlibs = "4.0.10"
|
||||
uuid = "0.8.0"
|
||||
uuid = "0.8.2"
|
||||
|
||||
ktor = "2.3.3"
|
||||
ktor = "2.3.6"
|
||||
|
||||
gh-release = "2.4.1"
|
||||
|
||||
koin = "3.4.3"
|
||||
koin = "3.5.0"
|
||||
|
||||
okio = "3.5.0"
|
||||
okio = "3.6.0"
|
||||
|
||||
ksp = "1.9.0-1.0.13"
|
||||
ksp = "1.9.20-1.0.14"
|
||||
kotlin-poet = "1.14.2"
|
||||
|
||||
versions = "0.47.0"
|
||||
versions = "0.50.0"
|
||||
|
||||
android-gradle = "7.4.2"
|
||||
android-gradle = "8.1.4"
|
||||
dexcount = "4.0.0"
|
||||
|
||||
android-coreKtx = "1.10.1"
|
||||
android-recyclerView = "1.3.1"
|
||||
android-coreKtx = "1.12.0"
|
||||
android-recyclerView = "1.3.2"
|
||||
android-appCompat = "1.6.1"
|
||||
android-fragment = "1.6.1"
|
||||
android-fragment = "1.6.2"
|
||||
android-espresso = "3.5.1"
|
||||
android-test = "1.1.5"
|
||||
android-compose-material3 = "1.1.1"
|
||||
android-compose-material3 = "1.1.2"
|
||||
|
||||
android-props-minSdk = "21"
|
||||
android-props-compileSdk = "34"
|
||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
@@ -2,11 +2,11 @@ apply plugin: 'maven-publish'
|
||||
|
||||
task javadocJar(type: Jar) {
|
||||
from javadoc
|
||||
classifier = 'javadoc'
|
||||
archiveClassifier = 'javadoc'
|
||||
}
|
||||
task sourcesJar(type: Jar) {
|
||||
from sourceSets.main.allSource
|
||||
classifier = 'sources'
|
||||
archiveClassifier = 'sources'
|
||||
}
|
||||
|
||||
publishing {
|
||||
@@ -115,4 +115,10 @@ if (project.hasProperty("signing.gnupg.keyName")) {
|
||||
dependsOn(it)
|
||||
}
|
||||
}
|
||||
|
||||
// Workaround to make android sign operations depend on signing tasks
|
||||
project.getTasks().withType(AbstractPublishToMaven.class).configureEach {
|
||||
def signingTasks = project.getTasks().withType(Sign.class)
|
||||
mustRunAfter(signingTasks)
|
||||
}
|
||||
}
|
||||
|
@@ -15,6 +15,6 @@ dependencies {
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.koin.generator.test"/>
|
||||
<manifest/>
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.koin"/>
|
||||
<manifest/>
|
||||
|
@@ -4,7 +4,7 @@ plugins {
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
@@ -30,5 +30,11 @@ kotlin {
|
||||
api internalProject("micro_utils.mime_types")
|
||||
}
|
||||
}
|
||||
|
||||
linuxArm64Main {
|
||||
dependencies {
|
||||
api internalProject("micro_utils.mime_types")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.ktor.client"/>
|
||||
<manifest/>
|
@@ -0,0 +1,40 @@
|
||||
package dev.inmo.micro_utils.ktor.client
|
||||
|
||||
import dev.inmo.micro_utils.common.MPPFile
|
||||
import dev.inmo.micro_utils.common.filename
|
||||
import dev.inmo.micro_utils.ktor.common.TemporalFileId
|
||||
import dev.inmo.micro_utils.mime_types.getMimeTypeOrAny
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.plugins.onUpload
|
||||
import io.ktor.client.request.forms.formData
|
||||
import io.ktor.client.request.forms.submitFormWithBinaryData
|
||||
import io.ktor.client.statement.bodyAsText
|
||||
import io.ktor.http.Headers
|
||||
import io.ktor.http.HttpHeaders
|
||||
|
||||
internal val MPPFile.mimeType: String
|
||||
get() = getMimeTypeOrAny(filename.extension).raw
|
||||
|
||||
actual suspend fun HttpClient.tempUpload(
|
||||
fullTempUploadDraftPath: String,
|
||||
file: MPPFile,
|
||||
onUpload: OnUploadCallback
|
||||
): TemporalFileId {
|
||||
val inputProvider = file.inputProvider()
|
||||
val fileId = submitFormWithBinaryData(
|
||||
fullTempUploadDraftPath,
|
||||
formData = formData {
|
||||
append(
|
||||
"data",
|
||||
inputProvider,
|
||||
Headers.build {
|
||||
append(HttpHeaders.ContentType, file.mimeType)
|
||||
append(HttpHeaders.ContentDisposition, "filename=\"${file.filename.string}\"")
|
||||
}
|
||||
)
|
||||
}
|
||||
) {
|
||||
onUpload(onUpload)
|
||||
}.bodyAsText()
|
||||
return TemporalFileId(fileId)
|
||||
}
|
107
ktor/client/src/linuxArm64Main/kotlin/ActualUniUpload.kt
Normal file
107
ktor/client/src/linuxArm64Main/kotlin/ActualUniUpload.kt
Normal file
@@ -0,0 +1,107 @@
|
||||
package dev.inmo.micro_utils.ktor.client
|
||||
|
||||
import dev.inmo.micro_utils.common.MPPFile
|
||||
import dev.inmo.micro_utils.common.Progress
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.engine.mergeHeaders
|
||||
import io.ktor.client.plugins.onUpload
|
||||
import io.ktor.client.request.HttpRequestBuilder
|
||||
import io.ktor.client.request.forms.InputProvider
|
||||
import io.ktor.client.request.forms.formData
|
||||
import io.ktor.client.request.forms.submitForm
|
||||
import io.ktor.client.request.forms.submitFormWithBinaryData
|
||||
import io.ktor.client.request.headers
|
||||
import io.ktor.client.statement.bodyAsText
|
||||
import io.ktor.http.Headers
|
||||
import io.ktor.http.HttpHeaders
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.http.Parameters
|
||||
import io.ktor.http.content.PartData
|
||||
import kotlinx.serialization.DeserializationStrategy
|
||||
import kotlinx.serialization.InternalSerializationApi
|
||||
import kotlinx.serialization.SerializationStrategy
|
||||
import kotlinx.serialization.StringFormat
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.serializer
|
||||
|
||||
/**
|
||||
* Will execute submitting of multipart data request
|
||||
*
|
||||
* @param data [Map] where keys will be used as names for multipart parts and values as values. If you will pass
|
||||
* [dev.inmo.micro_utils.common.MPPFile] (File from JS or JVM platform). Also you may pass [UniUploadFileInfo] as value
|
||||
* in case you wish to pass other source of multipart binary data than regular file
|
||||
* @suppress
|
||||
*/
|
||||
@OptIn(InternalSerializationApi::class)
|
||||
actual suspend fun <T> HttpClient.uniUpload(
|
||||
url: String,
|
||||
data: Map<String, Any>,
|
||||
resultDeserializer: DeserializationStrategy<T>,
|
||||
headers: Headers,
|
||||
stringFormat: StringFormat,
|
||||
onUpload: OnUploadCallback
|
||||
): T? {
|
||||
val withBinary = data.values.any { it is MPPFile || it is UniUploadFileInfo }
|
||||
|
||||
val formData = formData {
|
||||
for (k in data.keys) {
|
||||
val v = data[k] ?: continue
|
||||
when (v) {
|
||||
is MPPFile -> append(
|
||||
k,
|
||||
v.inputProvider(),
|
||||
Headers.build {
|
||||
append(HttpHeaders.ContentType, v.mimeType)
|
||||
append(HttpHeaders.ContentDisposition, "filename=\"${v.name}\"")
|
||||
}
|
||||
)
|
||||
is UniUploadFileInfo -> append(
|
||||
k,
|
||||
InputProvider(block = v.inputAllocator),
|
||||
Headers.build {
|
||||
append(HttpHeaders.ContentType, v.mimeType)
|
||||
append(HttpHeaders.ContentDisposition, "filename=\"${v.fileName.name}\"")
|
||||
}
|
||||
)
|
||||
else -> append(
|
||||
k,
|
||||
stringFormat.encodeToString(v::class.serializer() as SerializationStrategy<in Any>, v)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val requestBuilder: HttpRequestBuilder.() -> Unit = {
|
||||
headers {
|
||||
appendAll(headers)
|
||||
}
|
||||
onUpload { bytesSentTotal, contentLength ->
|
||||
onUpload(bytesSentTotal, contentLength)
|
||||
}
|
||||
}
|
||||
|
||||
val response = if (withBinary) {
|
||||
submitFormWithBinaryData(
|
||||
url,
|
||||
formData,
|
||||
block = requestBuilder
|
||||
)
|
||||
} else {
|
||||
submitForm(
|
||||
url,
|
||||
Parameters.build {
|
||||
for (it in formData) {
|
||||
val formItem = (it as PartData.FormItem)
|
||||
append(it.name!!, it.value)
|
||||
}
|
||||
},
|
||||
block = requestBuilder
|
||||
)
|
||||
}
|
||||
|
||||
return if (response.status == HttpStatusCode.OK) {
|
||||
stringFormat.decodeFromString(resultDeserializer, response.bodyAsText())
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
@@ -4,7 +4,7 @@ plugins {
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.ktor.common"/>
|
||||
<manifest/>
|
11
ktor/common/src/linuxArm64Main/kotlin/ActualMPPFileInput.kt
Normal file
11
ktor/common/src/linuxArm64Main/kotlin/ActualMPPFileInput.kt
Normal file
@@ -0,0 +1,11 @@
|
||||
package dev.inmo.micro_utils.ktor.common
|
||||
|
||||
import dev.inmo.micro_utils.common.MPPFile
|
||||
import dev.inmo.micro_utils.common.bytesAllocatorSync
|
||||
import io.ktor.utils.io.core.ByteReadPacket
|
||||
import io.ktor.utils.io.core.Input
|
||||
|
||||
actual fun MPPFile.input(): Input {
|
||||
return ByteReadPacket(bytesAllocatorSync())
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@ plugins {
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
|
@@ -26,6 +26,6 @@ dependencies {
|
||||
mainClassName="MainKt"
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.language_codes"/>
|
||||
<manifest/>
|
||||
|
@@ -4,4 +4,4 @@ plugins {
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.matrix"/>
|
||||
<manifest/>
|
@@ -4,4 +4,4 @@ plugins {
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.mime_types"/>
|
||||
<manifest/>
|
@@ -4,8 +4,13 @@ project.group = "$group"
|
||||
apply from: "$publishGradlePath"
|
||||
|
||||
kotlin {
|
||||
android {
|
||||
androidTarget {
|
||||
publishAllLibraryVariants()
|
||||
compilations.all {
|
||||
kotlinOptions {
|
||||
jvmTarget = "17"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
@@ -27,6 +32,6 @@ kotlin {
|
||||
apply from: "$defaultAndroidSettingsPresetPath"
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ kotlin {
|
||||
jvm {
|
||||
compilations.main {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
jvmTarget = "17"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,6 @@ kotlin {
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
71
mppJvmJsAndroidLinuxMingwLinuxArm64Project.gradle
Normal file
71
mppJvmJsAndroidLinuxMingwLinuxArm64Project.gradle
Normal file
@@ -0,0 +1,71 @@
|
||||
project.version = "$version"
|
||||
project.group = "$group"
|
||||
|
||||
apply from: "$publishGradlePath"
|
||||
|
||||
kotlin {
|
||||
jvm {
|
||||
compilations.main {
|
||||
kotlinOptions {
|
||||
jvmTarget = "17"
|
||||
}
|
||||
}
|
||||
}
|
||||
js (IR) {
|
||||
browser()
|
||||
nodejs()
|
||||
}
|
||||
androidTarget {
|
||||
publishAllLibraryVariants()
|
||||
compilations.all {
|
||||
kotlinOptions {
|
||||
jvmTarget = "17"
|
||||
}
|
||||
}
|
||||
}
|
||||
linuxX64()
|
||||
mingwX64()
|
||||
linuxArm64()
|
||||
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
implementation kotlin('stdlib')
|
||||
api libs.kt.serialization
|
||||
}
|
||||
}
|
||||
commonTest {
|
||||
dependencies {
|
||||
implementation kotlin('test-common')
|
||||
implementation kotlin('test-annotations-common')
|
||||
implementation libs.kt.coroutines.test
|
||||
}
|
||||
}
|
||||
|
||||
androidUnitTest {
|
||||
dependencies {
|
||||
implementation kotlin('test-junit')
|
||||
implementation libs.android.test.junit
|
||||
implementation libs.android.espresso
|
||||
}
|
||||
}
|
||||
jvmTest {
|
||||
dependencies {
|
||||
implementation kotlin('test-junit')
|
||||
}
|
||||
}
|
||||
jsTest {
|
||||
dependencies {
|
||||
implementation kotlin('test-js')
|
||||
implementation kotlin('test-junit')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
apply from: "$defaultAndroidSettingsPresetPath"
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
@@ -7,7 +7,7 @@ kotlin {
|
||||
jvm {
|
||||
compilations.main {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
jvmTarget = "17"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,8 +15,13 @@ kotlin {
|
||||
browser()
|
||||
nodejs()
|
||||
}
|
||||
android {
|
||||
androidTarget {
|
||||
publishAllLibraryVariants()
|
||||
compilations.all {
|
||||
kotlinOptions {
|
||||
jvmTarget = "17"
|
||||
}
|
||||
}
|
||||
}
|
||||
linuxX64()
|
||||
mingwX64()
|
||||
@@ -71,6 +76,6 @@ kotlin {
|
||||
apply from: "$defaultAndroidSettingsPresetPath"
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
54
mppJvmJsLinuxMingwLinuxArm64Project.gradle
Normal file
54
mppJvmJsLinuxMingwLinuxArm64Project.gradle
Normal file
@@ -0,0 +1,54 @@
|
||||
project.version = "$version"
|
||||
project.group = "$group"
|
||||
|
||||
apply from: "$publishGradlePath"
|
||||
|
||||
kotlin {
|
||||
jvm {
|
||||
compilations.main {
|
||||
kotlinOptions {
|
||||
jvmTarget = "17"
|
||||
}
|
||||
}
|
||||
}
|
||||
js (IR) {
|
||||
browser()
|
||||
nodejs()
|
||||
}
|
||||
linuxX64()
|
||||
mingwX64()
|
||||
linuxArm64()
|
||||
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
implementation kotlin('stdlib')
|
||||
api libs.kt.serialization
|
||||
}
|
||||
}
|
||||
commonTest {
|
||||
dependencies {
|
||||
implementation kotlin('test-common')
|
||||
implementation kotlin('test-annotations-common')
|
||||
implementation libs.kt.coroutines.test
|
||||
}
|
||||
}
|
||||
|
||||
jvmTest {
|
||||
dependencies {
|
||||
implementation kotlin('test-junit')
|
||||
}
|
||||
}
|
||||
jsTest {
|
||||
dependencies {
|
||||
implementation kotlin('test-js')
|
||||
implementation kotlin('test-junit')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
@@ -7,7 +7,7 @@ kotlin {
|
||||
jvm {
|
||||
compilations.main {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
jvmTarget = "17"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ kotlin {
|
||||
commonMain {
|
||||
dependencies {
|
||||
implementation kotlin('stdlib')
|
||||
api libs.kt.serialization
|
||||
}
|
||||
}
|
||||
commonTest {
|
||||
@@ -43,10 +44,22 @@ kotlin {
|
||||
implementation kotlin('test-junit')
|
||||
}
|
||||
}
|
||||
mingwX64Test {
|
||||
dependencies {
|
||||
implementation kotlin('test-junit')
|
||||
}
|
||||
}
|
||||
linuxX64Test {
|
||||
dependencies {
|
||||
implementation kotlin('test-junit')
|
||||
}
|
||||
}
|
||||
|
||||
androidMain.dependsOn jvmMain
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ kotlin {
|
||||
jvm {
|
||||
compilations.main {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
jvmTarget = "17"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,8 +15,13 @@ kotlin {
|
||||
browser()
|
||||
nodejs()
|
||||
}
|
||||
android {
|
||||
androidTarget {
|
||||
publishAllLibraryVariants()
|
||||
compilations.all {
|
||||
kotlinOptions {
|
||||
jvmTarget = "17"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
@@ -70,6 +75,13 @@ kotlin {
|
||||
apply from: "$defaultAndroidSettingsPresetPath"
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
|
||||
//compose {
|
||||
// if (composePluginKotlinVersion != null && !composePluginKotlinVersion.isEmpty()) {
|
||||
// kotlinCompilerPlugin.set(composePluginKotlinVersion)
|
||||
// }
|
||||
//}
|
||||
|
@@ -4,7 +4,7 @@ plugins {
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.pagination.common"/>
|
||||
<manifest/>
|
@@ -4,7 +4,7 @@ plugins {
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.pagination.ktor.common"/>
|
||||
<manifest/>
|
@@ -1,7 +1,7 @@
|
||||
apply plugin: 'maven-publish'
|
||||
|
||||
task javadocsJar(type: Jar) {
|
||||
classifier = 'javadoc'
|
||||
archiveClassifier = 'javadoc'
|
||||
}
|
||||
|
||||
publishing {
|
||||
@@ -19,29 +19,29 @@ publishing {
|
||||
}
|
||||
|
||||
developers {
|
||||
|
||||
|
||||
developer {
|
||||
id = "InsanusMokrassar"
|
||||
name = "Aleksei Ovsiannikov"
|
||||
email = "ovsyannikov.alexey95@gmail.com"
|
||||
}
|
||||
|
||||
|
||||
|
||||
developer {
|
||||
id = "000Sanya"
|
||||
name = "Syrov Aleksandr"
|
||||
email = "000sanya.000sanya@gmail.com"
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
licenses {
|
||||
|
||||
|
||||
license {
|
||||
name = "Apache Software License 2.0"
|
||||
url = "https://github.com/InsanusMokrassar/MicroUtils/blob/master/LICENSE"
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
repositories {
|
||||
@@ -49,57 +49,64 @@ publishing {
|
||||
maven {
|
||||
name = "GithubPackages"
|
||||
url = uri("https://maven.pkg.github.com/InsanusMokrassar/MicroUtils")
|
||||
|
||||
|
||||
credentials {
|
||||
username = project.hasProperty('GITHUBPACKAGES_USER') ? project.property('GITHUBPACKAGES_USER') : System.getenv('GITHUBPACKAGES_USER')
|
||||
password = project.hasProperty('GITHUBPACKAGES_PASSWORD') ? project.property('GITHUBPACKAGES_PASSWORD') : System.getenv('GITHUBPACKAGES_PASSWORD')
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
if (project.hasProperty('GITEA_TOKEN') || System.getenv('GITEA_TOKEN') != null) {
|
||||
maven {
|
||||
name = "Gitea"
|
||||
url = uri("https://git.inmo.dev/api/packages/InsanusMokrassar/maven")
|
||||
|
||||
|
||||
credentials(HttpHeaderCredentials) {
|
||||
name = "Authorization"
|
||||
value = project.hasProperty('GITEA_TOKEN') ? project.property('GITEA_TOKEN') : System.getenv('GITEA_TOKEN')
|
||||
}
|
||||
|
||||
|
||||
authentication {
|
||||
header(HttpHeaderAuthentication)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
|
||||
maven {
|
||||
name = "sonatype"
|
||||
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
|
||||
|
||||
|
||||
credentials {
|
||||
username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
|
||||
password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (project.hasProperty("signing.gnupg.keyName")) {
|
||||
apply plugin: 'signing'
|
||||
|
||||
|
||||
signing {
|
||||
useGpgCmd()
|
||||
|
||||
|
||||
sign publishing.publications
|
||||
}
|
||||
|
||||
|
||||
task signAll {
|
||||
tasks.withType(Sign).forEach {
|
||||
dependsOn(it)
|
||||
}
|
||||
}
|
||||
|
||||
// Workaround to make android sign operations depend on signing tasks
|
||||
project.getTasks().withType(AbstractPublishToMaven.class).configureEach {
|
||||
def signingTasks = project.getTasks().withType(Sign.class)
|
||||
mustRunAfter(signingTasks)
|
||||
}
|
||||
}
|
||||
|
2
repos/cache/build.gradle
vendored
2
repos/cache/build.gradle
vendored
@@ -4,7 +4,7 @@ plugins {
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.repos.cache"/>
|
||||
<manifest/>
|
@@ -61,18 +61,28 @@ open class WriteCRUDCacheRepo<ObjectType, IdType, InputValueType>(
|
||||
override val deletedObjectsIdsFlow: Flow<IdType> by parentRepo::deletedObjectsIdsFlow
|
||||
|
||||
val createdObjectsFlowJob = parentRepo.newObjectsFlow.onEach {
|
||||
locker.withWriteLock { kvCache.set(idGetter(it), it) }
|
||||
locker.withWriteLock {
|
||||
kvCache.set(idGetter(it), it)
|
||||
}
|
||||
}.launchIn(scope)
|
||||
|
||||
val updatedObjectsFlowJob = parentRepo.updatedObjectsFlow.onEach {
|
||||
locker.withWriteLock { kvCache.set(idGetter(it), it) }
|
||||
locker.withWriteLock {
|
||||
kvCache.set(idGetter(it), it)
|
||||
}
|
||||
}.launchIn(scope)
|
||||
|
||||
val deletedObjectsFlowJob = parentRepo.deletedObjectsIdsFlow.onEach {
|
||||
locker.withWriteLock { kvCache.unset(it) }
|
||||
locker.withWriteLock {
|
||||
kvCache.unset(it)
|
||||
}
|
||||
}.launchIn(scope)
|
||||
|
||||
override suspend fun deleteById(ids: List<IdType>) = parentRepo.deleteById(ids)
|
||||
override suspend fun deleteById(ids: List<IdType>) = parentRepo.deleteById(ids).also {
|
||||
locker.withWriteLock {
|
||||
kvCache.unset(ids)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun update(values: List<UpdatedValuePair<IdType, InputValueType>>): List<ObjectType> {
|
||||
val updated = parentRepo.update(values)
|
||||
|
@@ -28,9 +28,18 @@ open class FullReadCRUDCacheRepo<ObjectType, IdType>(
|
||||
kvCache.action().onPresented { return it }
|
||||
}
|
||||
return parentRepo.actionElse().also {
|
||||
locker.withWriteLock { kvCache.actualize(it) }
|
||||
kvCache.actualize(it)
|
||||
}
|
||||
}
|
||||
protected suspend inline fun <T> doOrTakeAndActualizeWithWriteLock(
|
||||
action: KeyValueRepo<IdType, ObjectType>.() -> Optional<T>,
|
||||
actionElse: ReadCRUDRepo<ObjectType, IdType>.() -> T,
|
||||
actualize: KeyValueRepo<IdType, ObjectType>.(T) -> Unit
|
||||
): T = doOrTakeAndActualize(
|
||||
action = action,
|
||||
actionElse = actionElse,
|
||||
actualize = { locker.withWriteLock { actualize(it) } }
|
||||
)
|
||||
|
||||
protected open suspend fun actualizeAll() {
|
||||
locker.withWriteLock { kvCache.actualizeAll(parentRepo) }
|
||||
@@ -54,22 +63,22 @@ open class FullReadCRUDCacheRepo<ObjectType, IdType>(
|
||||
{ if (it != 0L) actualizeAll() }
|
||||
)
|
||||
|
||||
override suspend fun contains(id: IdType): Boolean = doOrTakeAndActualize(
|
||||
override suspend fun contains(id: IdType): Boolean = doOrTakeAndActualizeWithWriteLock(
|
||||
{ contains(id).takeIf { it }.optionalOrAbsentIfNull },
|
||||
{ contains(id) },
|
||||
{ if (it) parentRepo.getById(id) ?.let { set(id, it) } }
|
||||
{ if (it) parentRepo.getById(id) ?.let { kvCache.set(id, it) } }
|
||||
)
|
||||
|
||||
override suspend fun getAll(): Map<IdType, ObjectType> = doOrTakeAndActualize(
|
||||
override suspend fun getAll(): Map<IdType, ObjectType> = doOrTakeAndActualizeWithWriteLock(
|
||||
{ getAll().takeIf { it.isNotEmpty() }.optionalOrAbsentIfNull },
|
||||
{ getAll() },
|
||||
{ kvCache.actualizeAll(clear = true) { it } }
|
||||
)
|
||||
|
||||
override suspend fun getById(id: IdType): ObjectType? = doOrTakeAndActualize(
|
||||
override suspend fun getById(id: IdType): ObjectType? = doOrTakeAndActualizeWithWriteLock(
|
||||
{ get(id) ?.optional ?: Optional.absent() },
|
||||
{ getById(id) },
|
||||
{ it ?.let { set(idGetter(it), it) } }
|
||||
{ it ?.let { kvCache.set(idGetter(it), it) } }
|
||||
)
|
||||
|
||||
override suspend fun invalidate() {
|
||||
|
@@ -28,20 +28,29 @@ open class FullReadKeyValueCacheRepo<Key,Value>(
|
||||
kvCache.action().onPresented { return it }
|
||||
}
|
||||
return parentRepo.actionElse().also {
|
||||
locker.withWriteLock { kvCache.actualize(it) }
|
||||
kvCache.actualize(it)
|
||||
}
|
||||
}
|
||||
protected suspend inline fun <T> doOrTakeAndActualizeWithWriteLock(
|
||||
action: KeyValueRepo<Key, Value>.() -> Optional<T>,
|
||||
actionElse: ReadKeyValueRepo<Key, Value>.() -> T,
|
||||
actualize: KeyValueRepo<Key, Value>.(T) -> Unit
|
||||
): T = doOrTakeAndActualize(
|
||||
action = action,
|
||||
actionElse = actionElse,
|
||||
actualize = { locker.withWriteLock { actualize(it) } }
|
||||
)
|
||||
protected open suspend fun actualizeAll() {
|
||||
locker.withWriteLock {
|
||||
kvCache.clear()
|
||||
kvCache.set(parentRepo.getAll { keys(it) }.toMap())
|
||||
kvCache.set(parentRepo.getAll())
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun get(k: Key): Value? = doOrTakeAndActualize(
|
||||
override suspend fun get(k: Key): Value? = doOrTakeAndActualizeWithWriteLock(
|
||||
{ get(k) ?.optional ?: Optional.absent() },
|
||||
{ get(k) },
|
||||
{ set(k, it ?: return@doOrTakeAndActualize) }
|
||||
{ kvCache.set(k, it ?: return@doOrTakeAndActualizeWithWriteLock) }
|
||||
)
|
||||
|
||||
override suspend fun values(pagination: Pagination, reversed: Boolean): PaginationResult<Value> = doOrTakeAndActualize(
|
||||
@@ -56,13 +65,13 @@ open class FullReadKeyValueCacheRepo<Key,Value>(
|
||||
{ if (it != 0L) actualizeAll() }
|
||||
)
|
||||
|
||||
override suspend fun contains(key: Key): Boolean = doOrTakeAndActualize(
|
||||
override suspend fun contains(key: Key): Boolean = doOrTakeAndActualizeWithWriteLock(
|
||||
{ contains(key).takeIf { it }.optionalOrAbsentIfNull },
|
||||
{ contains(key) },
|
||||
{ if (it) parentRepo.get(key) ?.also { kvCache.set(key, it) } }
|
||||
)
|
||||
|
||||
override suspend fun getAll(): Map<Key, Value> = doOrTakeAndActualize(
|
||||
override suspend fun getAll(): Map<Key, Value> = doOrTakeAndActualizeWithWriteLock(
|
||||
{ getAll().takeIf { it.isNotEmpty() }.optionalOrAbsentIfNull },
|
||||
{ getAll() },
|
||||
{ kvCache.actualizeAll(clear = true) { it } }
|
||||
|
@@ -27,9 +27,18 @@ open class FullReadKeyValuesCacheRepo<Key,Value>(
|
||||
kvCache.action().onPresented { return it }
|
||||
}
|
||||
return parentRepo.actionElse().also {
|
||||
locker.withWriteLock { kvCache.actualize(it) }
|
||||
kvCache.actualize(it)
|
||||
}
|
||||
}
|
||||
protected suspend inline fun <T> doOrTakeAndActualizeWithWriteLock(
|
||||
action: KeyValueRepo<Key, List<Value>>.() -> Optional<T>,
|
||||
actionElse: ReadKeyValuesRepo<Key, Value>.() -> T,
|
||||
actualize: KeyValueRepo<Key, List<Value>>.(T) -> Unit
|
||||
): T = doOrTakeAndActualize(
|
||||
action = action,
|
||||
actionElse = actionElse,
|
||||
actualize = { locker.withWriteLock { actualize(it) } }
|
||||
)
|
||||
|
||||
protected open suspend fun actualizeKey(k: Key) {
|
||||
locker.withWriteLock {
|
||||
|
@@ -4,7 +4,7 @@ plugins {
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.repos.common"/>
|
||||
<manifest/>
|
@@ -1,12 +1,10 @@
|
||||
package dev.inmo.micro_utils.repos.exposed.onetomany
|
||||
|
||||
import dev.inmo.micro_utils.pagination.*
|
||||
import dev.inmo.micro_utils.repos.ReadKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.ReadKeyValuesRepo
|
||||
import dev.inmo.micro_utils.repos.exposed.*
|
||||
import dev.inmo.micro_utils.repos.exposed.utils.selectPaginated
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
|
||||
abstract class AbstractExposedReadKeyValuesRepo<Key, Value>(
|
||||
@@ -73,4 +71,26 @@ abstract class AbstractExposedReadKeyValuesRepo<Key, Value>(
|
||||
override suspend fun contains(k: Key, v: Value): Boolean = transaction(database) {
|
||||
select { selectById(k).and(selectByValue(v)) }.limit(1).any()
|
||||
}
|
||||
|
||||
override suspend fun getAll(reverseLists: Boolean): Map<Key, List<Value>> = transaction(database) {
|
||||
val query = if (reverseLists) {
|
||||
selectAll().orderBy(keyColumn, SortOrder.DESC)
|
||||
} else {
|
||||
selectAll()
|
||||
}
|
||||
query.asSequence().map { it.asKey to it.asObject }.groupBy { it.first }.mapValues {
|
||||
it.value.map { it.second }
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getAll(k: Key, reverseLists: Boolean): List<Value> = transaction(database) {
|
||||
val query = if (reverseLists) {
|
||||
select { selectById(k) }.orderBy(keyColumn, SortOrder.DESC)
|
||||
} else {
|
||||
select { selectById(k) }
|
||||
}
|
||||
query.map {
|
||||
it.asObject
|
||||
}
|
||||
}
|
||||
}
|
@@ -16,6 +16,6 @@ dependencies {
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@ plugins {
|
||||
id "com.google.devtools.ksp"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
|
||||
|
||||
|
||||
kotlin {
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.repos.generator.test"/>
|
||||
<manifest/>
|
||||
|
@@ -4,7 +4,7 @@ plugins {
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.repos.inmemory"/>
|
||||
<manifest/>
|
@@ -65,12 +65,12 @@ abstract class WriteMapCRUDRepo<ObjectType, IdType, InputValueType>(
|
||||
protected val map: MutableMap<IdType, ObjectType> = mutableMapOf(),
|
||||
protected val locker: SmartRWLocker = SmartRWLocker()
|
||||
) : WriteCRUDRepo<ObjectType, IdType, InputValueType> {
|
||||
protected val _newObjectsFlow: MutableSharedFlow<ObjectType> = MutableSharedFlow()
|
||||
override val newObjectsFlow: Flow<ObjectType> = _newObjectsFlow.asSharedFlow()
|
||||
protected val _updatedObjectsFlow: MutableSharedFlow<ObjectType> = MutableSharedFlow()
|
||||
override val updatedObjectsFlow: Flow<ObjectType> = _updatedObjectsFlow.asSharedFlow()
|
||||
protected val _deletedObjectsIdsFlow: MutableSharedFlow<IdType> = MutableSharedFlow()
|
||||
override val deletedObjectsIdsFlow: Flow<IdType> = _deletedObjectsIdsFlow.asSharedFlow()
|
||||
protected open val _newObjectsFlow: MutableSharedFlow<ObjectType> = MapsReposDefaultMutableSharedFlow()
|
||||
override val newObjectsFlow: Flow<ObjectType> by lazy { _newObjectsFlow.asSharedFlow() }
|
||||
protected open val _updatedObjectsFlow: MutableSharedFlow<ObjectType> = MapsReposDefaultMutableSharedFlow()
|
||||
override val updatedObjectsFlow: Flow<ObjectType> by lazy { _updatedObjectsFlow.asSharedFlow() }
|
||||
protected open val _deletedObjectsIdsFlow: MutableSharedFlow<IdType> = MapsReposDefaultMutableSharedFlow()
|
||||
override val deletedObjectsIdsFlow: Flow<IdType> by lazy { _deletedObjectsIdsFlow.asSharedFlow() }
|
||||
|
||||
protected abstract suspend fun updateObject(newValue: InputValueType, id: IdType, old: ObjectType): ObjectType
|
||||
protected abstract suspend fun createObject(newValue: InputValueType): Pair<IdType, ObjectType>
|
||||
@@ -80,10 +80,10 @@ abstract class WriteMapCRUDRepo<ObjectType, IdType, InputValueType>(
|
||||
values.map {
|
||||
val (id, newObject) = createObject(it)
|
||||
map[id] = newObject
|
||||
newObject.also { _ ->
|
||||
_newObjectsFlow.emit(newObject)
|
||||
}
|
||||
newObject
|
||||
}
|
||||
}.onEach {
|
||||
_newObjectsFlow.emit(it)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,8 +93,9 @@ abstract class WriteMapCRUDRepo<ObjectType, IdType, InputValueType>(
|
||||
|
||||
newValue.also {
|
||||
map[id] = it
|
||||
_updatedObjectsFlow.emit(it)
|
||||
}
|
||||
} ?.also {
|
||||
_updatedObjectsFlow.emit(it)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,10 +105,10 @@ abstract class WriteMapCRUDRepo<ObjectType, IdType, InputValueType>(
|
||||
|
||||
override suspend fun deleteById(ids: List<IdType>) {
|
||||
locker.withWriteLock {
|
||||
ids.forEach {
|
||||
map.remove(it) ?.also { _ -> _deletedObjectsIdsFlow.emit(it) }
|
||||
ids.mapNotNull {
|
||||
it.takeIf { map.remove(it) != null }
|
||||
}
|
||||
}
|
||||
}.onEach { _deletedObjectsIdsFlow.emit(it) }
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@ import dev.inmo.micro_utils.pagination.utils.paginate
|
||||
import dev.inmo.micro_utils.pagination.utils.reverse
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.asSharedFlow
|
||||
|
||||
/**
|
||||
* [Map]-based [ReadKeyValueRepo]. All internal operations will be locked with [locker] (mostly with
|
||||
@@ -88,12 +89,14 @@ class WriteMapKeyValueRepo<Key, Value>(
|
||||
private val map: MutableMap<Key, Value>,
|
||||
private val locker: SmartRWLocker
|
||||
) : WriteKeyValueRepo<Key, Value> {
|
||||
private val _onNewValue: MutableSharedFlow<Pair<Key, Value>> = MutableSharedFlow()
|
||||
override val onNewValue: Flow<Pair<Key, Value>>
|
||||
get() = _onNewValue
|
||||
private val _onValueRemoved: MutableSharedFlow<Key> = MutableSharedFlow()
|
||||
override val onValueRemoved: Flow<Key>
|
||||
get() = _onValueRemoved
|
||||
private val _onNewValue: MutableSharedFlow<Pair<Key, Value>> = MapsReposDefaultMutableSharedFlow()
|
||||
override val onNewValue: Flow<Pair<Key, Value>> by lazy {
|
||||
_onNewValue.asSharedFlow()
|
||||
}
|
||||
private val _onValueRemoved: MutableSharedFlow<Key> = MapsReposDefaultMutableSharedFlow()
|
||||
override val onValueRemoved: Flow<Key> by lazy {
|
||||
_onValueRemoved.asSharedFlow()
|
||||
}
|
||||
constructor(map: MutableMap<Key, Value> = mutableMapOf()) : this(map, SmartRWLocker())
|
||||
|
||||
override suspend fun set(toSet: Map<Key, Value>) {
|
||||
@@ -103,10 +106,10 @@ class WriteMapKeyValueRepo<Key, Value>(
|
||||
|
||||
override suspend fun unset(toUnset: List<Key>) {
|
||||
locker.withWriteLock {
|
||||
toUnset.forEach { k ->
|
||||
map.remove(k) ?.also { _ -> _onValueRemoved.emit(k) }
|
||||
toUnset.mapNotNull { k ->
|
||||
map.remove(k) ?.let { _ -> k }
|
||||
}
|
||||
}
|
||||
}.forEach { _onValueRemoved.emit(it) }
|
||||
}
|
||||
|
||||
override suspend fun unsetWithValues(toUnset: List<Value>) {
|
||||
|
@@ -81,68 +81,94 @@ class MapWriteKeyValuesRepo<Key, Value>(
|
||||
private val map: MutableMap<Key, MutableList<Value>> = mutableMapOf(),
|
||||
private val locker: SmartRWLocker = SmartRWLocker()
|
||||
) : WriteKeyValuesRepo<Key, Value> {
|
||||
private val _onNewValue: MutableSharedFlow<Pair<Key, Value>> = MutableSharedFlow()
|
||||
override val onNewValue: Flow<Pair<Key, Value>> = _onNewValue.asSharedFlow()
|
||||
private val _onValueRemoved: MutableSharedFlow<Pair<Key, Value>> = MutableSharedFlow()
|
||||
override val onValueRemoved: Flow<Pair<Key, Value>> = _onValueRemoved.asSharedFlow()
|
||||
private val _onDataCleared: MutableSharedFlow<Key> = MutableSharedFlow()
|
||||
override val onDataCleared: Flow<Key> = _onDataCleared.asSharedFlow()
|
||||
private val _onNewValue: MutableSharedFlow<Pair<Key, Value>> = MapsReposDefaultMutableSharedFlow()
|
||||
override val onNewValue: Flow<Pair<Key, Value>> by lazy {
|
||||
_onNewValue.asSharedFlow()
|
||||
}
|
||||
private val _onValueRemoved: MutableSharedFlow<Pair<Key, Value>> = MapsReposDefaultMutableSharedFlow()
|
||||
override val onValueRemoved: Flow<Pair<Key, Value>> by lazy {
|
||||
_onValueRemoved.asSharedFlow()
|
||||
}
|
||||
private val _onDataCleared: MutableSharedFlow<Key> = MapsReposDefaultMutableSharedFlow()
|
||||
override val onDataCleared: Flow<Key> by lazy {
|
||||
_onDataCleared.asSharedFlow()
|
||||
}
|
||||
|
||||
override suspend fun add(toAdd: Map<Key, List<Value>>) {
|
||||
locker.withWriteLock {
|
||||
toAdd.keys.forEach { k ->
|
||||
if (map.getOrPut(k) { mutableListOf() }.addAll(toAdd[k] ?: return@forEach)) {
|
||||
toAdd[k] ?.forEach { v ->
|
||||
_onNewValue.emit(k to v)
|
||||
}
|
||||
toAdd.keys.mapNotNull { k ->
|
||||
(k to toAdd[k]).takeIf {
|
||||
map.getOrPut(k) { mutableListOf() }.addAll(toAdd[k] ?: return@mapNotNull null)
|
||||
}
|
||||
}
|
||||
}.forEach { (k, vs) ->
|
||||
vs ?.forEach { v ->
|
||||
_onNewValue.emit(k to v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun remove(toRemove: Map<Key, List<Value>>) {
|
||||
val removed = mutableListOf<Pair<Key, Value>>()
|
||||
val cleared = mutableListOf<Key>()
|
||||
locker.withWriteLock {
|
||||
toRemove.keys.forEach { k ->
|
||||
if (map[k]?.removeAll(toRemove[k] ?: return@forEach) == true) {
|
||||
toRemove[k]?.forEach { v ->
|
||||
_onValueRemoved.emit(k to v)
|
||||
removed.add(k to v)
|
||||
}
|
||||
}
|
||||
if (map[k]?.isEmpty() == true) {
|
||||
map.remove(k)
|
||||
_onDataCleared.emit(k)
|
||||
cleared.add(k)
|
||||
}
|
||||
}
|
||||
}
|
||||
removed.forEach {
|
||||
_onValueRemoved.emit(it)
|
||||
}
|
||||
cleared.forEach {
|
||||
_onDataCleared.emit(it)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun removeWithValue(v: Value) {
|
||||
locker.withWriteLock {
|
||||
map.forEach { (k, values) ->
|
||||
map.mapNotNull { (k, values) ->
|
||||
if (values.remove(v)) {
|
||||
_onValueRemoved.emit(k to v)
|
||||
k to v
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}.forEach {
|
||||
_onValueRemoved.emit(it)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun clear(k: Key) {
|
||||
locker.withWriteLock {
|
||||
map.remove(k) ?.also { _onDataCleared.emit(k) }
|
||||
}
|
||||
map.remove(k)
|
||||
} ?.also { _onDataCleared.emit(k) }
|
||||
}
|
||||
|
||||
override suspend fun clearWithValue(v: Value) {
|
||||
locker.withWriteLock {
|
||||
map.filter { (_, values) ->
|
||||
values.contains(v)
|
||||
}.forEach {
|
||||
map.remove(it.key)?.onEach { v ->
|
||||
_onValueRemoved.emit(it.key to v)
|
||||
}?.also { _ ->
|
||||
_onDataCleared.emit(it.key)
|
||||
}.mapNotNull {
|
||||
if (map.remove(it.key) != null) {
|
||||
it.toPair()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}.forEach {
|
||||
it.second.onEach { v ->
|
||||
_onValueRemoved.emit(it.first to v)
|
||||
}.also { _ ->
|
||||
_onDataCleared.emit(it.first)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,7 @@
|
||||
package dev.inmo.micro_utils.repos
|
||||
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
|
||||
fun <T> MapsReposDefaultMutableSharedFlow() = MutableSharedFlow<T>(
|
||||
extraBufferCapacity = Int.MAX_VALUE
|
||||
)
|
@@ -4,7 +4,7 @@ plugins {
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.repos.ktor.client"/>
|
||||
<manifest/>
|
@@ -4,7 +4,7 @@ plugins {
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.repos.ktor.common"/>
|
||||
<manifest/>
|
@@ -4,7 +4,7 @@ plugins {
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.safe_wrapper"/>
|
||||
<manifest/>
|
||||
|
@@ -4,7 +4,7 @@ plugins {
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.selector"/>
|
||||
<manifest/>
|
@@ -4,7 +4,7 @@ plugins {
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.serialization.base64"/>
|
||||
<manifest/>
|
@@ -4,4 +4,4 @@ plugins {
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.serialization.encapsulator"/>
|
||||
<manifest/>
|
@@ -4,4 +4,4 @@ plugins {
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.serialization.mapper"/>
|
||||
<manifest/>
|
||||
|
@@ -4,4 +4,4 @@ plugins {
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
|
||||
|
@@ -1 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.serialization.typed_serializer"/>
|
||||
<manifest/>
|
@@ -59,5 +59,3 @@ includes.each { originalName ->
|
||||
project.name = projectName
|
||||
project.projectDir = new File(projectDirectory)
|
||||
}
|
||||
|
||||
enableFeaturePreview("VERSION_CATALOGS")
|
||||
|
@@ -28,8 +28,8 @@ application {
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
@@ -10,7 +10,6 @@ kotlin {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api libs.koin
|
||||
api libs.kt.serialization
|
||||
api libs.kslog
|
||||
api libs.kt.reflect
|
||||
api project(":micro_utils.coroutines")
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user