Skip to content

Commit

Permalink
4.0.0 pull request #13
Browse files Browse the repository at this point in the history
4.0.0: New Dependencies and modules management
  • Loading branch information
y9san9 committed May 28, 2021
2 parents 1eb69ed + a1e40be commit 77d188e
Show file tree
Hide file tree
Showing 44 changed files with 159 additions and 160 deletions.
15 changes: 10 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
/.gradle/
/.idea/

/build/
/data/
/buildSrc/build/
/core/build/
/files/build/
/local-storage/build/

/.gradle/
/buildSrc/.gradle/

/data/

/local.properties
/jsCommon/build/
/utils/build/
/.idea/
/deploy.properties
52 changes: 27 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![Last Version](https://badge.kotlingang.fun/maven/fun/kotlingang/kds/kds/)](https://maven.kotlingang.fun/fun/kotlingang/kds/kds)
[![Hits-of-Code](https://hitsofcode.com/github/y9san9/kds)](https://hitsofcode.com/view/github/y9san9/kds)
[![Last Version](https://badge.kotlingang.fun/maven/fun/kotlingang/kds/core/)](https://maven.kotlingang.fun/fun/kotlingang/kds/kds)
[![Hits-of-Code](https://hitsofcode.com/github/y9san9/kds)](https://hitsofcode.com/view/github/kotlingang/kds)

# kds

Expand Down Expand Up @@ -33,29 +33,31 @@ fun main() = storage.mutateBlocking {

There are both blocking and asynchronous implementations (except JS-browser where there is only blocking implementation due to using `localStorage` instead of files).

Library may be fully customized since you can implement your own [DataManager](src/commonMain/kotlin/fun/kotlingang/kds/manager/DataManager.kt)
Library may be fully customized since you can implement your own [DataManager](core/src/commonMain/kotlin/fun/kotlingang/kds/manager/DataManager.kt)

## Installation
## Implementation
`$version` - library version, can be found in badge above

### Groovy Gradle
```gradle
repositories {
maven {
url 'https://maven.kotlingang.fun/'
}
}
dependencies {
implementation "fun.kotlingang.kds:kds:$version"
}
```
### Kotlin Gradle Dsl
```gradle
repositories {
maven("https://maven.kotlingang.fun/")
}
dependencies {
implementation("fun.kotlingang.kds:kds:$version")
}
```
> Note: for nodejs you should use `kds-node` artifact
All `kds` packages are located at repository [maven.kotlingang.fun](https://maven.kotlingang.fun/fun/kotlingang/kds) so make sure you include one.

### KFileDataStorage
KDataStorage async/sync [implementation](files) with files.

**Platforms**: Jvm / NodeJS <br>
**Dependency**: `fun.kotlingang.kds:files:$version`

### KLocalDataStorage
KDataStorage sync [implementation](local-storage) with browser `localStorage`

**Platforms**: Browser JS <br>
**Dependency**: `fun.kotlingang.kds:local-storage:$version`

### Custom
There **are** plans for other implementations (shared-preferences, ns-user-default, etc.), but if you want to create your own implementation, use following dependency

`// You can provide more platforms with PR/Issue` <br>
**Platforms**: Jvm / NodeJS / BrowserJS <br>
**Dependency**: `fun.kotlingang.kds:core:$version`

## Plans
Now the library primarily depends on JSON, it means that there is only ability to define custom `save(data)`, `load(): String` methods, but it would be nice to make more expressive `DataManager`, so I could integrate with Exposed (any kinds of Tables) and JSON could be just special case for KDS
101 changes: 8 additions & 93 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,98 +1,13 @@
@file:Suppress("UNUSED_VARIABLE")

plugins {
kotlin(plugin.multiplatform)
kotlin(plugin.serialization) version Version.SERIALIZATION_PLUGIN
}

group = AppInfo.PACKAGE
version = AppInfo.VERSION

repositories {
mavenCentral()
// Required for nodejs bindings. Waiting for deploy to mavenCentral()
@kotlin.Suppress("DEPRECATION") jcenter()
}

kotlin {
val jsType = Attribute.of("jsType", String::class.java)
js(IR) {
attributes.attribute(jsType, "browser")
browser()
}
js("node", IR) {
attributes.attribute(jsType, "node")
useCommonJs()
nodejs()
}
jvm()

// native targets are not implemented; if you need it, create an issue

sourceSets {
val commonMain by getting {
dependencies {
implementation(coroutines)
api(serialization)
}
}

val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}

val filesTarget by creating {
dependsOn(commonMain)
}

val jvmMain by getting {
dependsOn(filesTarget)
}
val jvmTest by getting {
dependencies {
implementation(kotlin("test-junit"))
}
}

val commonJsMain by creating {
dependsOn(commonMain)
}

val nodeMain by getting {
dependsOn(filesTarget)
dependsOn(commonJsMain)

dependencies {
implementation(nodejsExternals)
}
}
val nodeTest by getting {
dependencies {
implementation(kotlin("test-js"))
}
}

val jsMain by getting {
dependsOn(commonJsMain)
}
val jsTest by getting {
dependencies {
implementation(kotlin("test-js"))
}
}

all {
languageSettings.useExperimentalAnnotation("kotlin.RequiresOptIn")
}
allprojects {
repositories {
mavenCentral()
// Required for nodejs bindings. Waiting for deploy to mavenCentral()
@kotlin.Suppress("DEPRECATION") jcenter()
}
}

val root = project
allprojects {
subprojects {
group = AppInfo.PACKAGE
version = AppInfo.VERSION
applyDeploy()
group = root.group
version = root.version
}
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 = "3.0.4"
const val VERSION = "4.0.0"
const val NAME = "Kotlin Data Storage"
const val DESCRIPTION = "Multiplatform Coroutine-Based Kotlin Library for storing data via kotlinx.serialization"
}
7 changes: 7 additions & 0 deletions buildSrc/src/main/kotlin/Modules.kt
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.kotlin.dsl.project
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler


val KotlinDependencyHandler.core get() = project(":core")

val DependencyHandler.core get() = project(":core")
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/Plugins.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Plugins internal constructor() {
val multiplatform = "multiplatform"
val jvm = "jvm"
val js = "js"

val serialization = "plugin.serialization"
}
Expand Down
4 changes: 4 additions & 0 deletions core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Core
This module is used to split KDS implementations from core, so you can define your own one without implementation of other realizations

**Dependency**: `fun.kotlingang.kds:core:$version`
27 changes: 27 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@file:Suppress("UNUSED_VARIABLE")

plugins {
kotlin(plugin.multiplatform)
}

kotlin {
jvm()
js(BOTH) {
browser()
nodejs()
useCommonJs()
}

sourceSets {
val commonMain by getting {
dependencies {
implementation(coroutines)
implementation(serialization)
}
}

all {
languageSettings.useExperimentalAnnotation("kotlin.RequiresOptIn")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package `fun`.kotlingang.kds.extensions.any


@Suppress("unused")
val Any?.unit get() = Unit
internal val Any?.unit get() = Unit
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package `fun`.kotlingang.kds.sync


@PublishedApi
internal actual inline fun <R> platformSynchronized(lock: Any, block: () -> R) = block()
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package `fun`.kotlingang.kds.sync


internal actual inline fun <R> platformSynchronized(lock: Any, block: () -> R) = synchronized(lock) { block() }
@PublishedApi
internal actual inline fun <R> platformSynchronized(lock: Any, block: () -> R) = synchronized(lock, block)
5 changes: 5 additions & 0 deletions files/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Files
`KFileDataStorage` is `KAsyncDataStorage` implementation with files.

**Platforms**: JVM, NodeJS <br>
**Dependency**: `fun.kotlingang.kds:files:$version`
37 changes: 37 additions & 0 deletions files/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@file:Suppress("UNUSED_VARIABLE")

plugins {
kotlin(plugin.multiplatform)
}

kotlin {
jvm()
js(BOTH) {
nodejs()
useCommonJs()
}

sourceSets {
val commonMain by getting {
dependencies {
api(core)
implementation(coroutines)
implementation(serialization)
}
}
val jsMain by getting {
dependencies {
implementation(nodejsExternals)
}
}
val jvmTest by getting {
dependencies {
implementation(kotlin("test-junit"))
}
}

all {
languageSettings.useExperimentalAnnotation("kotlin.RequiresOptIn")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import `fun`.kotlingang.kds.delegate.KDSDelegate
import `fun`.kotlingang.kds.delegate.property
import `fun`.kotlingang.kds.mutate.mutate
import `fun`.kotlingang.kds.mutate.mutateCommit
import `fun`.kotlingang.kds.test.launchTest
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.builtins.serializer
import org.junit.Test
import kotlin.random.Random
Expand All @@ -27,7 +26,7 @@ val mutableList by storage.property { mutableListOf<String>() }
@DelicateCoroutinesApi
class StorageTests {
@Test
fun simpleStorageTest() = GlobalScope.launchTest {
fun simpleStorageTest() = runBlocking {
with(storage) {
println("Awaiting loading")
storage.loadDataBlocking()
Expand All @@ -49,7 +48,7 @@ class StorageTests {
}

@Test
fun mutableStorageTest() = GlobalScope.launchTest {
fun mutableStorageTest() = runBlocking {
with(storage) {
mutateCommit {
mutableList += "Test"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import `fun`.kotlingang.kds.delegate.property
import `fun`.kotlingang.kds.test.launchTest
import kotlinx.coroutines.*
import org.junit.Test

Expand All @@ -9,7 +8,7 @@ var stressTest by storage.property { "" }
@DelicateCoroutinesApi
class StressTest {
@Test
fun stressTest() = GlobalScope.launchTest {
fun stressTest() = runBlocking {
withContext(Dispatchers.IO) {
(1..1_000).map { i ->
async {
Expand Down
5 changes: 5 additions & 0 deletions local-storage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Local Storage
`KLocalDataStorage` is `KBlockingDataStorage` implementation with browser `localStorage`

**Platforms**: Browser JS <br>
**Dependency**: `fun.kotlingang.kds:local-storage:$version`
15 changes: 15 additions & 0 deletions local-storage/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
plugins {
kotlin(plugin.js)
}

kotlin {
js(BOTH) {
browser()
useCommonJs()
}
}

dependencies {
api(core)
implementation(serialization)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package `fun`.kotlingang.kds

import `fun`.kotlingang.kds.manager.BlockingDataManager
import `fun`.kotlingang.kds.manager.LocalStorageDataManager
import kotlinx.serialization.json.Json

Expand Down
4 changes: 4 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
rootProject.name = "kds"

include("core")
include("files")
include("local-storage")
8 changes: 0 additions & 8 deletions src/commonJsMain/kotlin/fun/kotlingang/kds/test/launchTest.kt

This file was deleted.

Loading

0 comments on commit 77d188e

Please sign in to comment.