From 0d1e0e1ea074dbf00fef8310e31e349d0ba135bd Mon Sep 17 00:00:00 2001 From: Alex Sokol Date: Sun, 13 Jun 2021 21:05:18 +0300 Subject: [PATCH] 1.0.1 (#29) * close #28 --- buildSrc/src/main/kotlin/AppInfo.kt | 2 +- buildSrc/src/main/kotlin/Version.kt | 1 - .../fun/kotlingang/kds/KFileDataStorage.kt | 47 ++----------------- .../fun/kotlingang/kds/KFileDataStorage.kt | 38 +++++++++++++++ .../fun/kotlingang/kds/KFileDataStorage.kt | 42 +++++++++++++++-- 5 files changed, 79 insertions(+), 51 deletions(-) create mode 100644 json/json-files/src/jsMain/kotlin/fun/kotlingang/kds/KFileDataStorage.kt diff --git a/buildSrc/src/main/kotlin/AppInfo.kt b/buildSrc/src/main/kotlin/AppInfo.kt index dfc4e5f..ab45dbf 100644 --- a/buildSrc/src/main/kotlin/AppInfo.kt +++ b/buildSrc/src/main/kotlin/AppInfo.kt @@ -1,6 +1,6 @@ object AppInfo { const val PACKAGE = "fun.kotlingang.kds" - const val VERSION = "1.0.0" + const val VERSION = "1.0.1" const val NAME = "Kotlin Data Storage" const val DESCRIPTION = "Multiplatform Coroutine-Based Kotlin Library for storing data via kotlinx.serialization" } diff --git a/buildSrc/src/main/kotlin/Version.kt b/buildSrc/src/main/kotlin/Version.kt index 06d3db3..1f794c2 100644 --- a/buildSrc/src/main/kotlin/Version.kt +++ b/buildSrc/src/main/kotlin/Version.kt @@ -1,7 +1,6 @@ object Version { const val COMPILE_SDK = 30 const val MIN_SDK = 10 - const val BUILD_TOOLS = "30.0.2" const val SERIALIZATION = "1.2.1" const val COROUTINES = "1.5.0" diff --git a/json/json-files/src/commonMain/kotlin/fun/kotlingang/kds/KFileDataStorage.kt b/json/json-files/src/commonMain/kotlin/fun/kotlingang/kds/KFileDataStorage.kt index 74b7f10..1fbc409 100644 --- a/json/json-files/src/commonMain/kotlin/fun/kotlingang/kds/KFileDataStorage.kt +++ b/json/json-files/src/commonMain/kotlin/fun/kotlingang/kds/KFileDataStorage.kt @@ -11,29 +11,16 @@ import kotlinx.serialization.json.Json @OptIn(DelicateCoroutinesApi::class, InternalKDSApi::class) -public open class KFileDataStorage private constructor ( - json: Json, - private val storage: JsonElementFileDataStorage -) : KJsonDataStorage(json, storage), AsyncCommittableStorage { - - internal constructor ( - file: CommonFile, - json: Json, - scope: CoroutineScope - ) : this(json, JsonElementFileDataStorage(json, file, scope)) - +public expect open class KFileDataStorage : KJsonDataStorage, AsyncCommittableStorage { public constructor ( absolutePath: String, json: Json = Json, scope: CoroutineScope = GlobalScope + SupervisorJob() - ) : this(CommonFile(absolutePath), json, scope) + ) public constructor ( json: Json = Json, scope: CoroutineScope = GlobalScope + SupervisorJob() - ) : this ( - CommonFile.HOME_DIR.join(path = "data").join(path = "data.json"), - json, scope ) public companion object { @@ -41,34 +28,6 @@ public open class KFileDataStorage private constructor ( name: String, json: Json = Json, scope: CoroutineScope = GlobalScope + SupervisorJob() - ): KFileDataStorage = KFileDataStorage ( - CommonFile.HOME_DIR.join(path = "data").join(path = "$name.json"), - json, scope - ) - } - - final override suspend fun setup(): Unit = storage.setup() - final override fun setupBlocking(): Unit = storage.setupBlocking() - - @OptIn(RawSetterGetter::class, DelicateKDSApi::class) - private fun applyMutations() = platformSynchronized(lock = this) { - encodeReferences().forEach { (k, v) -> - storage.putJsonElement(k, v) - } - } - - final override fun launchCommit() { - applyMutations() - storage.launchCommit() - } - - final override suspend fun commit() { - applyMutations() - storage.commit() - } - - final override fun commitBlocking() { - applyMutations() - storage.commitBlocking() + ): KFileDataStorage } } diff --git a/json/json-files/src/jsMain/kotlin/fun/kotlingang/kds/KFileDataStorage.kt b/json/json-files/src/jsMain/kotlin/fun/kotlingang/kds/KFileDataStorage.kt new file mode 100644 index 0000000..3a4455e --- /dev/null +++ b/json/json-files/src/jsMain/kotlin/fun/kotlingang/kds/KFileDataStorage.kt @@ -0,0 +1,38 @@ +package `fun`.kotlingang.kds + +import `fun`.kotlingang.kds.file.CommonFile +import `fun`.kotlingang.kds.storage.AsyncCommittableStorage +import kotlinx.coroutines.CoroutineScope +import kotlinx.serialization.json.Json + + +public actual open class KFileDataStorage private constructor ( + json: Json, + private val storage: JsonElementFileDataStorage +) : KJsonDataStorage(json, storage), AsyncCommittableStorage { + public actual constructor ( + absolutePath: String, + json: Json, + scope: CoroutineScope + ) : this(json, JsonElementFileDataStorage(json, CommonFile(absolutePath), scope)) + + public actual constructor(json: Json, scope: CoroutineScope) : this ( + absolutePath = CommonFile.HOME_DIR.join(path = "data").join(path = "data.json").absolutePath, + json, scope + ) + + public actual companion object { + public actual fun ofName ( + name: String, + json: Json, + scope: CoroutineScope + ): KFileDataStorage = KFileDataStorage ( + absolutePath = CommonFile.HOME_DIR.join(path = "data").join(path = "$name.json").absolutePath, + json, scope + ) + } + + final override fun commitBlocking(): Unit = storage.commitBlocking() + final override fun launchCommit(): Unit = storage.launchCommit() + final override suspend fun commit(): Unit = storage.commit() +} \ No newline at end of file diff --git a/json/json-files/src/jvmMain/kotlin/fun/kotlingang/kds/KFileDataStorage.kt b/json/json-files/src/jvmMain/kotlin/fun/kotlingang/kds/KFileDataStorage.kt index cae1f77..ff08350 100644 --- a/json/json-files/src/jvmMain/kotlin/fun/kotlingang/kds/KFileDataStorage.kt +++ b/json/json-files/src/jvmMain/kotlin/fun/kotlingang/kds/KFileDataStorage.kt @@ -1,14 +1,46 @@ package `fun`.kotlingang.kds import `fun`.kotlingang.kds.file.CommonFile +import `fun`.kotlingang.kds.storage.AsyncCommittableStorage import kotlinx.coroutines.* import kotlinx.serialization.json.Json import java.io.File @OptIn(DelicateCoroutinesApi::class) -public fun KFileDataStorage ( - file: File, - json: Json = Json, - scope: CoroutineScope = GlobalScope + SupervisorJob() -): KFileDataStorage = KFileDataStorage(CommonFile(file), json, scope) +public actual open class KFileDataStorage private constructor ( + json: Json, + private val storage: JsonElementFileDataStorage +) : KJsonDataStorage(json, storage), AsyncCommittableStorage { + public actual constructor ( + absolutePath: String, + json: Json, + scope: CoroutineScope + ) : this(json, JsonElementFileDataStorage(json, CommonFile(absolutePath), scope)) + + public actual constructor(json: Json, scope: CoroutineScope) : this ( + absolutePath = CommonFile.HOME_DIR.join(path = "data").join(path = "data.json").absolutePath, + json, scope + ) + + public constructor ( + file: File, + json: Json = Json, + scope: CoroutineScope = GlobalScope + SupervisorJob() + ) : this(file.absolutePath, json, scope) + + public actual companion object { + public actual fun ofName ( + name: String, + json: Json, + scope: CoroutineScope + ): KFileDataStorage = KFileDataStorage ( + absolutePath = CommonFile.HOME_DIR.join(path = "data").join(path = "$name.json").absolutePath, + json, scope + ) + } + + final override fun commitBlocking(): Unit = storage.commitBlocking() + final override fun launchCommit(): Unit = storage.launchCommit() + final override suspend fun commit(): Unit = storage.commit() +}