mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-18 14:59:24 +00:00
Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
c6eab182f6 | |||
3e3fbd97eb | |||
feb695caa7 | |||
1bd46d9651 | |||
32eabb6b36 | |||
9bfe6dc6d8 | |||
3f366aeea4 | |||
4338fd46f2 | |||
36974f5b49 | |||
d48f767408 | |||
bd2558e852 | |||
9f7c963cd5 | |||
2db0eadbfe | |||
580c7b8842 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -14,3 +14,6 @@ local.properties
|
|||||||
kotlin-js-store
|
kotlin-js-store
|
||||||
|
|
||||||
publishing.sh
|
publishing.sh
|
||||||
|
|
||||||
|
local.*
|
||||||
|
local/
|
||||||
|
25
CHANGELOG.md
25
CHANGELOG.md
@@ -1,5 +1,30 @@
|
|||||||
# 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
|
## 0.20.45
|
||||||
|
|
||||||
* `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.45
|
version=0.20.49
|
||||||
android_code_version=251
|
android_code_version=255
|
||||||
|
@@ -7,7 +7,7 @@ kt-coroutines = "1.8.0"
|
|||||||
kslog = "1.3.3"
|
kslog = "1.3.3"
|
||||||
|
|
||||||
jb-compose = "1.6.2"
|
jb-compose = "1.6.2"
|
||||||
jb-exposed = "0.49.0"
|
jb-exposed = "0.50.0"
|
||||||
jb-dokka = "1.9.20"
|
jb-dokka = "1.9.20"
|
||||||
|
|
||||||
korlibs = "5.4.0"
|
korlibs = "5.4.0"
|
||||||
@@ -26,13 +26,13 @@ kotlin-poet = "1.16.0"
|
|||||||
|
|
||||||
versions = "0.51.0"
|
versions = "0.51.0"
|
||||||
|
|
||||||
android-gradle = "8.3.2"
|
android-gradle = "8.4.0"
|
||||||
dexcount = "4.0.0"
|
dexcount = "4.0.0"
|
||||||
|
|
||||||
android-coreKtx = "1.13.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.1"
|
android-compose-material3 = "1.2.1"
|
||||||
|
@@ -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))
|
||||||
|
}
|
Reference in New Issue
Block a user