Skip to content

Commit

Permalink
1.0.1 (#29)
Browse files Browse the repository at this point in the history
* close #28
  • Loading branch information
y9san9 committed Jun 13, 2021
1 parent 645eeea commit 0d1e0e1
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 51 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/AppInfo.kt
Original file line number Diff line number Diff line change
@@ -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"
}
1 change: 0 additions & 1 deletion buildSrc/src/main/kotlin/Version.kt
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,64 +11,23 @@ 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 {
public fun ofName (
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
}
}
Original file line number Diff line number Diff line change
@@ -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()
}
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit 0d1e0e1

Please sign in to comment.