mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-01-11 18:29:57 +00:00
commit
4c0cb73d69
3
.gitignore
vendored
3
.gitignore
vendored
@ -14,3 +14,6 @@ local.properties
|
||||
kotlin-js-store
|
||||
|
||||
publishing.sh
|
||||
|
||||
local.*
|
||||
local/
|
||||
|
@ -1,5 +1,13 @@
|
||||
# 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`:
|
||||
|
@ -15,5 +15,5 @@ crypto_js_version=4.1.1
|
||||
# Project data
|
||||
|
||||
group=dev.inmo
|
||||
version=0.20.48
|
||||
android_code_version=254
|
||||
version=0.20.49
|
||||
android_code_version=255
|
||||
|
@ -42,6 +42,22 @@ interface WriteCRUDRepo<ObjectType, IdType, InputValueType> : Repo {
|
||||
}
|
||||
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(
|
||||
vararg values: InputValueType
|
||||
): 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))
|
||||
}
|
Loading…
Reference in New Issue
Block a user