mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-17 14:29:24 +00:00
Compare commits
38 Commits
Author | SHA1 | Date | |
---|---|---|---|
c6eab182f6 | |||
3e3fbd97eb | |||
feb695caa7 | |||
1bd46d9651 | |||
32eabb6b36 | |||
9bfe6dc6d8 | |||
3f366aeea4 | |||
4338fd46f2 | |||
36974f5b49 | |||
d48f767408 | |||
bd2558e852 | |||
9f7c963cd5 | |||
2db0eadbfe | |||
580c7b8842 | |||
88fba347ea | |||
c8c5255e62 | |||
01a1a2760a | |||
6d34df8d48 | |||
b124ea65e1 | |||
f3214347a9 | |||
6b8724b59f | |||
ac3e378edf | |||
5d31fd1c91 | |||
046fe1ec08 | |||
721873c843 | |||
f6ffbfc10a | |||
4e91649e0a | |||
4f7f8abec4 | |||
6370562dbc | |||
94e2e67522 | |||
1d8330015d | |||
e5017b0258 | |||
cd412ca31b | |||
d2b6473095 | |||
ab42507275 | |||
dcef844e20 | |||
3244708c1b | |||
73ac1f1741 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -14,3 +14,6 @@ local.properties
|
|||||||
kotlin-js-store
|
kotlin-js-store
|
||||||
|
|
||||||
publishing.sh
|
publishing.sh
|
||||||
|
|
||||||
|
local.*
|
||||||
|
local/
|
||||||
|
70
CHANGELOG.md
70
CHANGELOG.md
@@ -1,5 +1,75 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.20.49
|
||||||
|
|
||||||
|
* `Repos`:
|
||||||
|
* `Common`:
|
||||||
|
* All `Repo`s get `diff` extensions
|
||||||
|
* `KeyValueRepo` and `KeyValuesRepo` get `applyDiff` extension
|
||||||
|
* Add new extensions `on*` flows for crud repos
|
||||||
|
|
||||||
|
## 0.20.48
|
||||||
|
|
||||||
|
* `Versions`:
|
||||||
|
* `Android Core KTX`: `1.13.0` -> `1.13.1`
|
||||||
|
* `AndroidX Fragment`: `1.6.2` -> `1.7.0`
|
||||||
|
|
||||||
|
## 0.20.47
|
||||||
|
|
||||||
|
* `Versions`:
|
||||||
|
* `Exposed`: `0.49.0` -> `0.50.0`
|
||||||
|
|
||||||
|
## 0.20.46
|
||||||
|
|
||||||
|
* `Common`:
|
||||||
|
* Now this repo depends on `klock`
|
||||||
|
* Add new object-serializer `DateTimeSerializer` for `klock` serializer
|
||||||
|
|
||||||
|
## 0.20.45
|
||||||
|
|
||||||
|
* `Versions`:
|
||||||
|
* `Android Core KTX`: `1.12.0` -> `1.13.0`
|
||||||
|
|
||||||
|
## 0.20.44
|
||||||
|
|
||||||
|
* `Versions`:
|
||||||
|
* `Compose`: `1.6.1` -> `1.6.2`
|
||||||
|
* `Koin`: `3.5.4` -> `3.5.6`
|
||||||
|
|
||||||
|
## 0.20.43
|
||||||
|
|
||||||
|
* `Versions`:
|
||||||
|
* `Ktor`: `2.3.9` -> `2.3.10`
|
||||||
|
* `Koin`: `3.5.3` -> `3.5.4`
|
||||||
|
|
||||||
|
## 0.20.42
|
||||||
|
|
||||||
|
* `Repos`:
|
||||||
|
* `Generator`:
|
||||||
|
* Improvements
|
||||||
|
|
||||||
|
## 0.20.41
|
||||||
|
|
||||||
|
* `Repos`:
|
||||||
|
* `Exposed`:
|
||||||
|
* `AbstractExposedKeyValueRepo`, `ExposedKeyValueRepo`, `AbstractExposedKeyValuesRepo`, `ExposedKeyValuesRepo` got opportunity to setup some part of their flows
|
||||||
|
|
||||||
|
## 0.20.40
|
||||||
|
|
||||||
|
* `Versions`:
|
||||||
|
* `KSLog`: `1.3.2` -> `1.3.3`
|
||||||
|
* `Exposed`: `0.48.0` -> `0.49.0`
|
||||||
|
* `UUID`: `0.8.2` -> `0.8.4`
|
||||||
|
|
||||||
|
## 0.20.39
|
||||||
|
|
||||||
|
* `Versions`:
|
||||||
|
* `Kotlin`: `1.9.22` -> `1.9.23`
|
||||||
|
* `Korlibs`: `5.3.2` -> `5.4.0`
|
||||||
|
* `Okio`: `3.8.0` -> `3.9.0`
|
||||||
|
* `Compose`: `1.6.0` -> `1.6.1`
|
||||||
|
* `ComposeMaterial3`: `1.2.0` -> `1.2.1`
|
||||||
|
|
||||||
## 0.20.38
|
## 0.20.38
|
||||||
|
|
||||||
* `Versions`:
|
* `Versions`:
|
||||||
|
@@ -8,6 +8,11 @@ apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
|
|||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
sourceSets {
|
sourceSets {
|
||||||
|
commonMain {
|
||||||
|
dependencies {
|
||||||
|
api libs.klock
|
||||||
|
}
|
||||||
|
}
|
||||||
jvmMain {
|
jvmMain {
|
||||||
dependencies {
|
dependencies {
|
||||||
api project(":micro_utils.coroutines")
|
api project(":micro_utils.coroutines")
|
||||||
|
@@ -0,0 +1,23 @@
|
|||||||
|
package dev.inmo.micro_utils.common
|
||||||
|
|
||||||
|
import korlibs.time.DateTime
|
||||||
|
import kotlinx.serialization.KSerializer
|
||||||
|
import kotlinx.serialization.Serializer
|
||||||
|
import kotlinx.serialization.builtins.serializer
|
||||||
|
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||||
|
import kotlinx.serialization.encoding.Decoder
|
||||||
|
import kotlinx.serialization.encoding.Encoder
|
||||||
|
|
||||||
|
@Serializer(DateTime::class)
|
||||||
|
object DateTimeSerializer : KSerializer<DateTime> {
|
||||||
|
override val descriptor: SerialDescriptor
|
||||||
|
get() = Double.serializer().descriptor
|
||||||
|
|
||||||
|
override fun deserialize(decoder: Decoder): DateTime {
|
||||||
|
return DateTime(decoder.decodeDouble())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun serialize(encoder: Encoder, value: DateTime) {
|
||||||
|
encoder.encodeDouble(value.unixMillis)
|
||||||
|
}
|
||||||
|
}
|
@@ -15,5 +15,5 @@ crypto_js_version=4.1.1
|
|||||||
# Project data
|
# Project data
|
||||||
|
|
||||||
group=dev.inmo
|
group=dev.inmo
|
||||||
version=0.20.38
|
version=0.20.49
|
||||||
android_code_version=244
|
android_code_version=255
|
||||||
|
@@ -1,41 +1,41 @@
|
|||||||
[versions]
|
[versions]
|
||||||
|
|
||||||
kt = "1.9.22"
|
kt = "1.9.23"
|
||||||
kt-serialization = "1.6.3"
|
kt-serialization = "1.6.3"
|
||||||
kt-coroutines = "1.8.0"
|
kt-coroutines = "1.8.0"
|
||||||
|
|
||||||
kslog = "1.3.2"
|
kslog = "1.3.3"
|
||||||
|
|
||||||
jb-compose = "1.6.0"
|
jb-compose = "1.6.2"
|
||||||
jb-exposed = "0.48.0"
|
jb-exposed = "0.50.0"
|
||||||
jb-dokka = "1.9.20"
|
jb-dokka = "1.9.20"
|
||||||
|
|
||||||
korlibs = "5.3.2"
|
korlibs = "5.4.0"
|
||||||
uuid = "0.8.2"
|
uuid = "0.8.4"
|
||||||
|
|
||||||
ktor = "2.3.9"
|
ktor = "2.3.10"
|
||||||
|
|
||||||
gh-release = "2.5.2"
|
gh-release = "2.5.2"
|
||||||
|
|
||||||
koin = "3.5.3"
|
koin = "3.5.6"
|
||||||
|
|
||||||
okio = "3.8.0"
|
okio = "3.9.0"
|
||||||
|
|
||||||
ksp = "1.9.22-1.0.18"
|
ksp = "1.9.23-1.0.20"
|
||||||
kotlin-poet = "1.16.0"
|
kotlin-poet = "1.16.0"
|
||||||
|
|
||||||
versions = "0.51.0"
|
versions = "0.51.0"
|
||||||
|
|
||||||
android-gradle = "8.3.0"
|
android-gradle = "8.4.0"
|
||||||
dexcount = "4.0.0"
|
dexcount = "4.0.0"
|
||||||
|
|
||||||
android-coreKtx = "1.12.0"
|
android-coreKtx = "1.13.1"
|
||||||
android-recyclerView = "1.3.2"
|
android-recyclerView = "1.3.2"
|
||||||
android-appCompat = "1.6.1"
|
android-appCompat = "1.6.1"
|
||||||
android-fragment = "1.6.2"
|
android-fragment = "1.7.0"
|
||||||
android-espresso = "3.5.1"
|
android-espresso = "3.5.1"
|
||||||
android-test = "1.1.5"
|
android-test = "1.1.5"
|
||||||
android-compose-material3 = "1.2.0"
|
android-compose-material3 = "1.2.1"
|
||||||
|
|
||||||
android-props-minSdk = "21"
|
android-props-minSdk = "21"
|
||||||
android-props-compileSdk = "34"
|
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
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
@@ -12,7 +12,6 @@ kotlin {
|
|||||||
dependencies {
|
dependencies {
|
||||||
api internalProject("micro_utils.common")
|
api internalProject("micro_utils.common")
|
||||||
api libs.kt.serialization.cbor
|
api libs.kt.serialization.cbor
|
||||||
api libs.klock
|
|
||||||
api libs.uuid
|
api libs.uuid
|
||||||
api libs.ktor.io
|
api libs.ktor.io
|
||||||
}
|
}
|
||||||
|
@@ -42,6 +42,22 @@ interface WriteCRUDRepo<ObjectType, IdType, InputValueType> : Repo {
|
|||||||
}
|
}
|
||||||
typealias WriteStandardCRUDRepo<ObjectType, IdType, InputValueType> = WriteCRUDRepo<ObjectType, IdType, InputValueType>
|
typealias WriteStandardCRUDRepo<ObjectType, IdType, InputValueType> = WriteCRUDRepo<ObjectType, IdType, InputValueType>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Just mirroring [WriteCRUDRepo.newObjectsFlow] to be same as in KV repos
|
||||||
|
*/
|
||||||
|
val <ObjectType> WriteCRUDRepo<ObjectType, *, *>.onNewObjects: Flow<ObjectType>
|
||||||
|
get() = newObjectsFlow
|
||||||
|
/**
|
||||||
|
* Just mirroring [WriteCRUDRepo.updatedObjectsFlow] to be same as in KV repos
|
||||||
|
*/
|
||||||
|
val <ObjectType> WriteCRUDRepo<ObjectType, *, *>.onUpdatedObjects: Flow<ObjectType>
|
||||||
|
get() = updatedObjectsFlow
|
||||||
|
/**
|
||||||
|
* Just mirroring [WriteCRUDRepo.deletedObjectsIdsFlow] to be same as in KV repos
|
||||||
|
*/
|
||||||
|
val <IdType> WriteCRUDRepo<*, IdType, *>.onDeletedObjectsIds: Flow<IdType>
|
||||||
|
get() = deletedObjectsIdsFlow
|
||||||
|
|
||||||
suspend fun <ObjectType, IdType, InputValueType> WriteCRUDRepo<ObjectType, IdType, InputValueType>.create(
|
suspend fun <ObjectType, IdType, InputValueType> WriteCRUDRepo<ObjectType, IdType, InputValueType>.create(
|
||||||
vararg values: InputValueType
|
vararg values: InputValueType
|
||||||
): List<ObjectType> = create(values.toList())
|
): List<ObjectType> = create(values.toList())
|
||||||
|
@@ -0,0 +1,20 @@
|
|||||||
|
package dev.inmo.micro_utils.repos.diff
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.common.MapDiff
|
||||||
|
import dev.inmo.micro_utils.common.applyDiff
|
||||||
|
import dev.inmo.micro_utils.common.diff
|
||||||
|
import dev.inmo.micro_utils.repos.CRUDRepo
|
||||||
|
import dev.inmo.micro_utils.repos.ReadCRUDRepo
|
||||||
|
import dev.inmo.micro_utils.repos.unset
|
||||||
|
|
||||||
|
suspend fun <Id, Registered> ReadCRUDRepo<Registered, Id>.diff(other: Map<Id, Registered>): MapDiff<Id, Registered> {
|
||||||
|
return getAll().diff(other)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun <Id, Registered> Map<Id, Registered>.diff(other: ReadCRUDRepo<Registered, Id>): MapDiff<Id, Registered> {
|
||||||
|
return diff(other.getAll())
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun <Id, Registered> MutableMap<Id, Registered>.applyDiff(other: ReadCRUDRepo<Registered, Id>) {
|
||||||
|
applyDiff(diff(other))
|
||||||
|
}
|
@@ -0,0 +1,33 @@
|
|||||||
|
package dev.inmo.micro_utils.repos.diff
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.common.MapDiff
|
||||||
|
import dev.inmo.micro_utils.common.applyDiff
|
||||||
|
import dev.inmo.micro_utils.common.diff
|
||||||
|
import dev.inmo.micro_utils.repos.KeyValueRepo
|
||||||
|
import dev.inmo.micro_utils.repos.ReadKeyValueRepo
|
||||||
|
import dev.inmo.micro_utils.repos.unset
|
||||||
|
|
||||||
|
suspend fun <Id, Registered> ReadKeyValueRepo<Id, Registered>.diff(other: Map<Id, Registered>): MapDiff<Id, Registered> {
|
||||||
|
return getAll().diff(other)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun <Id, Registered> Map<Id, Registered>.diff(other: ReadKeyValueRepo<Id, Registered>): MapDiff<Id, Registered> {
|
||||||
|
return diff(other.getAll())
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun <Id, Registered> KeyValueRepo<Id, Registered>.applyDiff(diff: MapDiff<Id, Registered>) {
|
||||||
|
unset(diff.removed.map { it.key })
|
||||||
|
set(
|
||||||
|
diff.changed.map { (k, oldNew) ->
|
||||||
|
k to oldNew.second
|
||||||
|
}.toMap() + diff.added
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun <Id, Registered> KeyValueRepo<Id, Registered>.applyDiff(other: Map<Id, Registered>) {
|
||||||
|
applyDiff(diff(other))
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun <Id, Registered> MutableMap<Id, Registered>.applyDiff(other: ReadKeyValueRepo<Id, Registered>) {
|
||||||
|
applyDiff(diff(other))
|
||||||
|
}
|
@@ -0,0 +1,33 @@
|
|||||||
|
package dev.inmo.micro_utils.repos.diff
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.common.MapDiff
|
||||||
|
import dev.inmo.micro_utils.common.applyDiff
|
||||||
|
import dev.inmo.micro_utils.common.diff
|
||||||
|
import dev.inmo.micro_utils.repos.*
|
||||||
|
|
||||||
|
suspend fun <Id, Registered> ReadKeyValuesRepo<Id, Registered>.diff(other: Map<Id, List<Registered>>): MapDiff<Id, List<Registered>> {
|
||||||
|
return getAll().diff(other)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun <Id, Registered> Map<Id, List<Registered>>.diff(other: ReadKeyValuesRepo<Id, Registered>): MapDiff<Id, List<Registered>> {
|
||||||
|
return diff(other.getAll())
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun <Id, Registered> KeyValuesRepo<Id, Registered>.applyDiff(diff: MapDiff<Id, List<Registered>>) {
|
||||||
|
diff.removed.forEach {
|
||||||
|
clear(it.key)
|
||||||
|
}
|
||||||
|
set(
|
||||||
|
diff.changed.map { (k, oldNew) ->
|
||||||
|
k to oldNew.second
|
||||||
|
}.toMap() + diff.added
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun <Id, Registered> KeyValuesRepo<Id, Registered>.applyDiff(other: Map<Id, List<Registered>>) {
|
||||||
|
applyDiff(diff(other))
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun <Id, Registered> MutableMap<Id, List<Registered>>.applyDiff(other: ReadKeyValuesRepo<Id, Registered>) {
|
||||||
|
applyDiff(diff(other))
|
||||||
|
}
|
@@ -1,6 +1,7 @@
|
|||||||
package dev.inmo.micro_utils.repos.exposed.keyvalue
|
package dev.inmo.micro_utils.repos.exposed.keyvalue
|
||||||
|
|
||||||
import dev.inmo.micro_utils.repos.KeyValueRepo
|
import dev.inmo.micro_utils.repos.KeyValueRepo
|
||||||
|
import kotlinx.coroutines.channels.BufferOverflow
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.*
|
||||||
import org.jetbrains.exposed.sql.*
|
import org.jetbrains.exposed.sql.*
|
||||||
import org.jetbrains.exposed.sql.statements.*
|
import org.jetbrains.exposed.sql.statements.*
|
||||||
@@ -8,13 +9,15 @@ import org.jetbrains.exposed.sql.transactions.transaction
|
|||||||
|
|
||||||
abstract class AbstractExposedKeyValueRepo<Key, Value>(
|
abstract class AbstractExposedKeyValueRepo<Key, Value>(
|
||||||
override val database: Database,
|
override val database: Database,
|
||||||
tableName: String? = null
|
tableName: String? = null,
|
||||||
|
flowsExtraBufferCapacity: Int = Int.MAX_VALUE,
|
||||||
|
flowsBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND
|
||||||
) : KeyValueRepo<Key, Value>, AbstractExposedReadKeyValueRepo<Key, Value>(
|
) : KeyValueRepo<Key, Value>, AbstractExposedReadKeyValueRepo<Key, Value>(
|
||||||
database,
|
database,
|
||||||
tableName
|
tableName
|
||||||
) {
|
) {
|
||||||
protected val _onNewValue = MutableSharedFlow<Pair<Key, Value>>()
|
protected val _onNewValue = MutableSharedFlow<Pair<Key, Value>>(extraBufferCapacity = flowsExtraBufferCapacity, onBufferOverflow = flowsBufferOverflow)
|
||||||
protected val _onValueRemoved = MutableSharedFlow<Key>()
|
protected val _onValueRemoved = MutableSharedFlow<Key>(extraBufferCapacity = flowsExtraBufferCapacity, onBufferOverflow = flowsBufferOverflow)
|
||||||
|
|
||||||
override val onNewValue: Flow<Pair<Key, Value>> = _onNewValue.asSharedFlow()
|
override val onNewValue: Flow<Pair<Key, Value>> = _onNewValue.asSharedFlow()
|
||||||
override val onValueRemoved: Flow<Key> = _onValueRemoved.asSharedFlow()
|
override val onValueRemoved: Flow<Key> = _onValueRemoved.asSharedFlow()
|
||||||
|
@@ -2,6 +2,7 @@ package dev.inmo.micro_utils.repos.exposed.keyvalue
|
|||||||
|
|
||||||
import dev.inmo.micro_utils.repos.KeyValueRepo
|
import dev.inmo.micro_utils.repos.KeyValueRepo
|
||||||
import dev.inmo.micro_utils.repos.exposed.ColumnAllocator
|
import dev.inmo.micro_utils.repos.exposed.ColumnAllocator
|
||||||
|
import kotlinx.coroutines.channels.BufferOverflow
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.*
|
||||||
import org.jetbrains.exposed.sql.*
|
import org.jetbrains.exposed.sql.*
|
||||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||||
@@ -13,15 +14,17 @@ open class ExposedKeyValueRepo<Key, Value>(
|
|||||||
database: Database,
|
database: Database,
|
||||||
keyColumnAllocator: ColumnAllocator<Key>,
|
keyColumnAllocator: ColumnAllocator<Key>,
|
||||||
valueColumnAllocator: ColumnAllocator<Value>,
|
valueColumnAllocator: ColumnAllocator<Value>,
|
||||||
tableName: String? = null
|
tableName: String? = null,
|
||||||
|
flowsExtraBufferCapacity: Int = Int.MAX_VALUE,
|
||||||
|
flowsBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND
|
||||||
) : KeyValueRepo<Key, Value>, ExposedReadKeyValueRepo<Key, Value>(
|
) : KeyValueRepo<Key, Value>, ExposedReadKeyValueRepo<Key, Value>(
|
||||||
database,
|
database,
|
||||||
keyColumnAllocator,
|
keyColumnAllocator,
|
||||||
valueColumnAllocator,
|
valueColumnAllocator,
|
||||||
tableName
|
tableName
|
||||||
) {
|
) {
|
||||||
protected val _onNewValue = MutableSharedFlow<Pair<Key, Value>>()
|
protected val _onNewValue = MutableSharedFlow<Pair<Key, Value>>(extraBufferCapacity = flowsExtraBufferCapacity, onBufferOverflow = flowsBufferOverflow)
|
||||||
protected val _onValueRemoved = MutableSharedFlow<Key>()
|
protected val _onValueRemoved = MutableSharedFlow<Key>(extraBufferCapacity = flowsExtraBufferCapacity, onBufferOverflow = flowsBufferOverflow)
|
||||||
|
|
||||||
override val onNewValue: Flow<Pair<Key, Value>> = _onNewValue.asSharedFlow()
|
override val onNewValue: Flow<Pair<Key, Value>> = _onNewValue.asSharedFlow()
|
||||||
override val onValueRemoved: Flow<Key> = _onValueRemoved.asSharedFlow()
|
override val onValueRemoved: Flow<Key> = _onValueRemoved.asSharedFlow()
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package dev.inmo.micro_utils.repos.exposed.onetomany
|
package dev.inmo.micro_utils.repos.exposed.onetomany
|
||||||
|
|
||||||
import dev.inmo.micro_utils.repos.KeyValuesRepo
|
import dev.inmo.micro_utils.repos.KeyValuesRepo
|
||||||
|
import kotlinx.coroutines.channels.BufferOverflow
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.*
|
||||||
import org.jetbrains.exposed.sql.*
|
import org.jetbrains.exposed.sql.*
|
||||||
import org.jetbrains.exposed.sql.statements.InsertStatement
|
import org.jetbrains.exposed.sql.statements.InsertStatement
|
||||||
@@ -8,18 +9,20 @@ import org.jetbrains.exposed.sql.transactions.transaction
|
|||||||
|
|
||||||
abstract class AbstractExposedKeyValuesRepo<Key, Value>(
|
abstract class AbstractExposedKeyValuesRepo<Key, Value>(
|
||||||
override val database: Database,
|
override val database: Database,
|
||||||
tableName: String? = null
|
tableName: String? = null,
|
||||||
|
flowsExtraBufferCapacity: Int = Int.MAX_VALUE,
|
||||||
|
flowsBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND
|
||||||
) : KeyValuesRepo<Key, Value>, AbstractExposedReadKeyValuesRepo<Key, Value>(
|
) : KeyValuesRepo<Key, Value>, AbstractExposedReadKeyValuesRepo<Key, Value>(
|
||||||
database,
|
database,
|
||||||
tableName
|
tableName
|
||||||
) {
|
) {
|
||||||
protected val _onNewValue: MutableSharedFlow<Pair<Key, Value>> = MutableSharedFlow()
|
protected val _onNewValue: MutableSharedFlow<Pair<Key, Value>> = MutableSharedFlow(extraBufferCapacity = flowsExtraBufferCapacity, onBufferOverflow = flowsBufferOverflow)
|
||||||
override val onNewValue: Flow<Pair<Key, Value>>
|
override val onNewValue: Flow<Pair<Key, Value>>
|
||||||
get() = _onNewValue.asSharedFlow()
|
get() = _onNewValue.asSharedFlow()
|
||||||
protected val _onValueRemoved: MutableSharedFlow<Pair<Key, Value>> = MutableSharedFlow()
|
protected val _onValueRemoved: MutableSharedFlow<Pair<Key, Value>> = MutableSharedFlow(extraBufferCapacity = flowsExtraBufferCapacity, onBufferOverflow = flowsBufferOverflow)
|
||||||
override val onValueRemoved: Flow<Pair<Key, Value>>
|
override val onValueRemoved: Flow<Pair<Key, Value>>
|
||||||
get() = _onValueRemoved.asSharedFlow()
|
get() = _onValueRemoved.asSharedFlow()
|
||||||
protected val _onDataCleared: MutableSharedFlow<Key> = MutableSharedFlow()
|
protected val _onDataCleared: MutableSharedFlow<Key> = MutableSharedFlow(extraBufferCapacity = flowsExtraBufferCapacity, onBufferOverflow = flowsBufferOverflow)
|
||||||
override val onDataCleared: Flow<Key>
|
override val onDataCleared: Flow<Key>
|
||||||
get() = _onDataCleared.asSharedFlow()
|
get() = _onDataCleared.asSharedFlow()
|
||||||
|
|
||||||
|
@@ -2,6 +2,7 @@ package dev.inmo.micro_utils.repos.exposed.onetomany
|
|||||||
|
|
||||||
import dev.inmo.micro_utils.repos.KeyValuesRepo
|
import dev.inmo.micro_utils.repos.KeyValuesRepo
|
||||||
import dev.inmo.micro_utils.repos.exposed.ColumnAllocator
|
import dev.inmo.micro_utils.repos.exposed.ColumnAllocator
|
||||||
|
import kotlinx.coroutines.channels.BufferOverflow
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.*
|
||||||
import org.jetbrains.exposed.sql.*
|
import org.jetbrains.exposed.sql.*
|
||||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||||
@@ -13,20 +14,22 @@ open class ExposedKeyValuesRepo<Key, Value>(
|
|||||||
database: Database,
|
database: Database,
|
||||||
keyColumnAllocator: ColumnAllocator<Key>,
|
keyColumnAllocator: ColumnAllocator<Key>,
|
||||||
valueColumnAllocator: ColumnAllocator<Value>,
|
valueColumnAllocator: ColumnAllocator<Value>,
|
||||||
tableName: String? = null
|
tableName: String? = null,
|
||||||
|
flowsExtraBufferCapacity: Int = Int.MAX_VALUE,
|
||||||
|
flowsBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND
|
||||||
) : KeyValuesRepo<Key, Value>, ExposedReadKeyValuesRepo<Key, Value>(
|
) : KeyValuesRepo<Key, Value>, ExposedReadKeyValuesRepo<Key, Value>(
|
||||||
database,
|
database,
|
||||||
keyColumnAllocator,
|
keyColumnAllocator,
|
||||||
valueColumnAllocator,
|
valueColumnAllocator,
|
||||||
tableName
|
tableName
|
||||||
) {
|
) {
|
||||||
protected val _onNewValue: MutableSharedFlow<Pair<Key, Value>> = MutableSharedFlow()
|
protected val _onNewValue: MutableSharedFlow<Pair<Key, Value>> = MutableSharedFlow(extraBufferCapacity = flowsExtraBufferCapacity, onBufferOverflow = flowsBufferOverflow)
|
||||||
override val onNewValue: Flow<Pair<Key, Value>>
|
override val onNewValue: Flow<Pair<Key, Value>>
|
||||||
get() = _onNewValue
|
get() = _onNewValue
|
||||||
protected val _onValueRemoved: MutableSharedFlow<Pair<Key, Value>> = MutableSharedFlow()
|
protected val _onValueRemoved: MutableSharedFlow<Pair<Key, Value>> = MutableSharedFlow(extraBufferCapacity = flowsExtraBufferCapacity, onBufferOverflow = flowsBufferOverflow)
|
||||||
override val onValueRemoved: Flow<Pair<Key, Value>>
|
override val onValueRemoved: Flow<Pair<Key, Value>>
|
||||||
get() = _onValueRemoved
|
get() = _onValueRemoved
|
||||||
protected val _onDataCleared: MutableSharedFlow<Key> = MutableSharedFlow()
|
protected val _onDataCleared: MutableSharedFlow<Key> = MutableSharedFlow(extraBufferCapacity = flowsExtraBufferCapacity, onBufferOverflow = flowsBufferOverflow)
|
||||||
override val onDataCleared: Flow<Key>
|
override val onDataCleared: Flow<Key>
|
||||||
get() = _onDataCleared
|
get() = _onDataCleared
|
||||||
|
|
||||||
|
@@ -1,8 +1,6 @@
|
|||||||
package dev.inmo.micro_utils.repos.generator
|
package dev.inmo.micro_utils.repos.generator
|
||||||
|
|
||||||
import com.google.devtools.ksp.KspExperimental
|
import com.google.devtools.ksp.*
|
||||||
import com.google.devtools.ksp.getAnnotationsByType
|
|
||||||
import com.google.devtools.ksp.isAnnotationPresent
|
|
||||||
import com.google.devtools.ksp.processing.CodeGenerator
|
import com.google.devtools.ksp.processing.CodeGenerator
|
||||||
import com.google.devtools.ksp.processing.Resolver
|
import com.google.devtools.ksp.processing.Resolver
|
||||||
import com.google.devtools.ksp.processing.SymbolProcessor
|
import com.google.devtools.ksp.processing.SymbolProcessor
|
||||||
@@ -36,6 +34,7 @@ import kotlinx.serialization.Serializable
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import kotlin.reflect.KProperty1
|
import kotlin.reflect.KProperty1
|
||||||
import kotlin.reflect.full.memberProperties
|
import kotlin.reflect.full.memberProperties
|
||||||
|
import kotlin.reflect.jvm.jvmName
|
||||||
|
|
||||||
private fun KSClassifierReference.quilifiedName(): String = "${qualifier ?.let { "${it.quilifiedName()}." } ?: ""}${referencedName()}"
|
private fun KSClassifierReference.quilifiedName(): String = "${qualifier ?.let { "${it.quilifiedName()}." } ?: ""}${referencedName()}"
|
||||||
|
|
||||||
@@ -75,16 +74,29 @@ class Processor(
|
|||||||
ORIGINAL FILE: ${ksFile.fileName}
|
ORIGINAL FILE: ${ksFile.fileName}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
|
|
||||||
val newName = "New${ksClassDeclaration.simpleName.getShortName()}"
|
val newName = "New${ksClassDeclaration.simpleName.getShortName()}"
|
||||||
val registeredName = "Registered${ksClassDeclaration.simpleName.getShortName()}"
|
val registeredName = "Registered${ksClassDeclaration.simpleName.getShortName()}"
|
||||||
|
|
||||||
val allKSClassProperties = ksClassDeclaration.getAllProperties()
|
val allKSClassProperties = ksClassDeclaration.getAllProperties()
|
||||||
val excludedKSClassProperties = allKSClassProperties.filter {
|
val excludedKSClassProperties = allKSClassProperties.filter { property ->
|
||||||
it.isAnnotationPresent(GenerateCRUDModelExcludeOverride::class)
|
property.isAnnotationPresent(GenerateCRUDModelExcludeOverride::class) || (property.findOverridee() ?.isAnnotationPresent(GenerateCRUDModelExcludeOverride::class) == true)
|
||||||
}
|
}
|
||||||
val excludedKSClassPropertiesNames = excludedKSClassProperties.map { it.simpleName.asString() }
|
val excludedKSClassPropertiesNames = excludedKSClassProperties.map { it.simpleName.asString() }
|
||||||
val ksClassProperties = allKSClassProperties.filter {
|
val ksClassProperties = allKSClassProperties.filter {
|
||||||
it !in excludedKSClassProperties
|
it !in excludedKSClassProperties
|
||||||
|
}.groupBy { it.simpleName.asString() }.map {
|
||||||
|
var current = it.value.first()
|
||||||
|
var currentType = current.type.resolve()
|
||||||
|
it.value.forEach {
|
||||||
|
val type = it.type.resolve()
|
||||||
|
|
||||||
|
if (currentType.isAssignableFrom(type) && !type.isAssignableFrom(currentType)) {
|
||||||
|
current = it
|
||||||
|
currentType = type
|
||||||
|
}
|
||||||
|
}
|
||||||
|
current
|
||||||
}
|
}
|
||||||
val ksClassPropertiesNames = ksClassProperties.map { it.simpleName.asString() }
|
val ksClassPropertiesNames = ksClassProperties.map { it.simpleName.asString() }
|
||||||
val newNewType = TypeSpec.classBuilder(newName).apply {
|
val newNewType = TypeSpec.classBuilder(newName).apply {
|
||||||
@@ -99,17 +111,20 @@ class Processor(
|
|||||||
}
|
}
|
||||||
primaryConstructor(
|
primaryConstructor(
|
||||||
FunSpec.constructorBuilder().apply {
|
FunSpec.constructorBuilder().apply {
|
||||||
|
val withoutDefaults = mutableListOf<Pair<ParameterSpec.Builder, PropertySpec.Builder>>()
|
||||||
ksClassProperties.forEach {
|
ksClassProperties.forEach {
|
||||||
addParameter(
|
val property = PropertySpec.builder(it.simpleName.getShortName(), it.type.toTypeName(), KModifier.OVERRIDE).apply {
|
||||||
ParameterSpec.builder(it.simpleName.getShortName(), it.typeName).apply {
|
initializer(it.simpleName.getShortName())
|
||||||
annotations += it.annotations.map { it.toAnnotationSpec() }
|
}
|
||||||
}.build()
|
ParameterSpec.builder(it.simpleName.getShortName(), it.type.toTypeName()).apply {
|
||||||
)
|
withoutDefaults.add(this to property)
|
||||||
typeBuilder.addProperty(
|
annotations += it.annotations.map { it.toAnnotationSpec() }
|
||||||
PropertySpec.builder(it.simpleName.getShortName(), it.typeName, KModifier.OVERRIDE).apply {
|
}
|
||||||
initializer(it.simpleName.getShortName())
|
}
|
||||||
}.build()
|
|
||||||
)
|
withoutDefaults.forEach {
|
||||||
|
addParameter(it.first.build())
|
||||||
|
addProperty(it.second.build())
|
||||||
}
|
}
|
||||||
}.build()
|
}.build()
|
||||||
)
|
)
|
||||||
@@ -125,14 +140,25 @@ class Processor(
|
|||||||
(it.arguments.first().value as List<KSType>).map { it.declaration as KSClassDeclaration }
|
(it.arguments.first().value as List<KSType>).map { it.declaration as KSClassDeclaration }
|
||||||
}.toList()
|
}.toList()
|
||||||
|
|
||||||
|
|
||||||
val registeredTypesProperties: List<KSPropertyDeclaration> = registeredSupertypes.flatMap { registeredType ->
|
val registeredTypesProperties: List<KSPropertyDeclaration> = registeredSupertypes.flatMap { registeredType ->
|
||||||
registeredType.getAllProperties()
|
registeredType.getAllProperties()
|
||||||
}.filter {
|
}.filter {
|
||||||
it.simpleName.asString() !in excludedKSClassPropertiesNames && it.getAnnotationsByType(GenerateCRUDModelExcludeOverride::class).none()
|
it.simpleName.asString() !in excludedKSClassPropertiesNames && !it.isAnnotationPresent(GenerateCRUDModelExcludeOverride::class)
|
||||||
}
|
}
|
||||||
val allProperties: List<KSPropertyDeclaration> = ksClassProperties.toList() + registeredTypesProperties
|
val allProperties: List<KSPropertyDeclaration> = registeredTypesProperties + ksClassProperties.toList()
|
||||||
val propertiesToOverrideInRegistered = allProperties.distinctBy { it.simpleName.asString() }.sortedBy { property ->
|
val propertiesToOverrideInRegistered = allProperties.groupBy { it.simpleName.asString() }.map {
|
||||||
|
var current = it.value.first()
|
||||||
|
var currentType = current.type.resolve()
|
||||||
|
it.value.forEach {
|
||||||
|
val type = it.type.resolve()
|
||||||
|
|
||||||
|
if (currentType.isAssignableFrom(type) && !type.isAssignableFrom(currentType)) {
|
||||||
|
current = it
|
||||||
|
currentType = type
|
||||||
|
}
|
||||||
|
}
|
||||||
|
current
|
||||||
|
}.sortedBy { property ->
|
||||||
val name = property.simpleName.asString()
|
val name = property.simpleName.asString()
|
||||||
|
|
||||||
ksClassPropertiesNames.indexOf(name).takeIf { it > -1 } ?.let {
|
ksClassPropertiesNames.indexOf(name).takeIf { it > -1 } ?.let {
|
||||||
@@ -156,17 +182,20 @@ class Processor(
|
|||||||
addModifiers(KModifier.DATA)
|
addModifiers(KModifier.DATA)
|
||||||
primaryConstructor(
|
primaryConstructor(
|
||||||
FunSpec.constructorBuilder().apply {
|
FunSpec.constructorBuilder().apply {
|
||||||
|
val withoutDefaults = mutableListOf<Pair<ParameterSpec.Builder, PropertySpec.Builder>>()
|
||||||
propertiesToOverrideInRegistered.forEach {
|
propertiesToOverrideInRegistered.forEach {
|
||||||
addParameter(
|
val property = PropertySpec.builder(it.simpleName.getShortName(), it.type.toTypeName(), KModifier.OVERRIDE).apply {
|
||||||
ParameterSpec.builder(it.simpleName.getShortName(), it.typeName).apply {
|
initializer(it.simpleName.getShortName())
|
||||||
annotations += it.annotations.map { it.toAnnotationSpec() }
|
}
|
||||||
}.build()
|
ParameterSpec.builder(it.simpleName.getShortName(), it.type.toTypeName()).apply {
|
||||||
)
|
withoutDefaults.add(this to property)
|
||||||
typeBuilder.addProperty(
|
annotations += it.annotations.map { it.toAnnotationSpec() }
|
||||||
PropertySpec.builder(it.simpleName.getShortName(), it.typeName, KModifier.OVERRIDE).apply {
|
}
|
||||||
initializer(it.simpleName.getShortName())
|
}
|
||||||
}.build()
|
|
||||||
)
|
withoutDefaults.forEach {
|
||||||
|
addParameter(it.first.build())
|
||||||
|
addProperty(it.second.build())
|
||||||
}
|
}
|
||||||
}.build()
|
}.build()
|
||||||
)
|
)
|
||||||
@@ -191,7 +220,7 @@ class Processor(
|
|||||||
FunSpec.builder("asRegistered").apply {
|
FunSpec.builder("asRegistered").apply {
|
||||||
receiver(ksClassDeclaration.toClassName())
|
receiver(ksClassDeclaration.toClassName())
|
||||||
(registeredTypesProperties.filter { it.simpleName.asString() !in ksClassPropertiesNames }).forEach {
|
(registeredTypesProperties.filter { it.simpleName.asString() !in ksClassPropertiesNames }).forEach {
|
||||||
addParameter(it.simpleName.asString(), it.typeName)
|
addParameter(it.simpleName.asString(), it.type.toTypeName())
|
||||||
}
|
}
|
||||||
addCode(
|
addCode(
|
||||||
CodeBlock.of(
|
CodeBlock.of(
|
||||||
|
@@ -14,6 +14,7 @@ public data class NewTest(
|
|||||||
override val property1: String,
|
override val property1: String,
|
||||||
override val property2: Int,
|
override val property2: Int,
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@SerialName(`value` = "custom_parent_name")
|
||||||
override val parent: ParentTypeId?,
|
override val parent: ParentTypeId?,
|
||||||
) : Test
|
) : Test
|
||||||
|
|
||||||
@@ -24,6 +25,7 @@ public data class RegisteredTest(
|
|||||||
override val property1: String,
|
override val property1: String,
|
||||||
override val property2: Int,
|
override val property2: Int,
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@SerialName(`value` = "custom_parent_name")
|
||||||
override val parent: ParentTypeId?,
|
override val parent: ParentTypeId?,
|
||||||
) : Test, IRegisteredTest
|
) : Test, IRegisteredTest
|
||||||
|
|
||||||
|
@@ -2,6 +2,7 @@ package dev.inmo.micro_utils.repos.generator.test
|
|||||||
|
|
||||||
import dev.inmo.micro_utils.repos.annotations.GenerateCRUDModel
|
import dev.inmo.micro_utils.repos.annotations.GenerateCRUDModel
|
||||||
import dev.inmo.micro_utils.repos.annotations.GenerateCRUDModelExcludeOverride
|
import dev.inmo.micro_utils.repos.annotations.GenerateCRUDModelExcludeOverride
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlin.jvm.JvmInline
|
import kotlin.jvm.JvmInline
|
||||||
|
|
||||||
@@ -18,6 +19,7 @@ sealed interface Test {
|
|||||||
val property1: String
|
val property1: String
|
||||||
val property2: Int
|
val property2: Int
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@SerialName("custom_parent_name")
|
||||||
val parent: ParentTypeId?
|
val parent: ParentTypeId?
|
||||||
|
|
||||||
@GenerateCRUDModelExcludeOverride
|
@GenerateCRUDModelExcludeOverride
|
||||||
|
Reference in New Issue
Block a user