Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to kotlinx-io #116

Merged
merged 16 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@ jobs:
run: ./gradlew apiCheck

- name: Generate kover coverage report
run: ./gradlew koverMergedXmlReport
run: ./gradlew koverXmlReport

- name: Add coverage report to PR
if: ${{ github.event_name == 'pull_request' }}
id: kover
uses: mi-kas/kover-report@v1
continue-on-error: true # https://github.com/mi-kas/kover-report/issues/111
with:
path: ${{ github.workspace }}/build/reports/kover/merged/xml/report.xml
path: ${{ github.workspace }}/kstore/build/reports/kover/report.xml
token: ${{ secrets.GITHUB_TOKEN }}
title: Code Coverage
update-comment: true
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/build/classes/kotlin/jvm/main/
/build/classes/kotlin/jvm/test/
local.properties
/.kotlin/

# Mac
.DS_Store
.DS_Store
4 changes: 0 additions & 4 deletions .idea/encodings.xml

This file was deleted.

9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Build](https://github.com/xxfast/KStore/actions/workflows/build.yml/badge.svg)](https://github.com/xxfast/KStore/actions/workflows/build.yml)

[![Kotlin Alpha](https://kotl.in/badges/alpha.svg)](https://kotlinlang.org/docs/components-stability.html)
[![Kotlin](https://img.shields.io/badge/Kotlin-1.9.21-blue.svg?style=flat&logo=kotlin)](https://kotlinlang.org)
[![Kotlin](https://img.shields.io/badge/Kotlin-2.0.10-blue.svg?style=flat&logo=kotlin)](https://kotlinlang.org)
[![Maven Central](https://img.shields.io/maven-central/v/io.github.xxfast/kstore?color=blue)](https://search.maven.org/search?q=g:io.github.xxfast)

![badge-android](http://img.shields.io/badge/platform-android-6EDB8D.svg?style=flat)
Expand All @@ -19,7 +19,7 @@
![badge-jsBrowser](https://img.shields.io/badge/platform-jsBrowser-F8DB5D.svg?style=flat)
![badge-wasmJsBrowser](https://img.shields.io/badge/platform-wasmJsBrowser-F8DB5D.svg?style=flat)

A tiny Kotlin multiplatform library that assists in saving and restoring objects to and from disk using kotlinx.coroutines, kotlinx.serialisation and okio.
A tiny Kotlin multiplatform library that assists in saving and restoring objects to and from disk using kotlinx.coroutines, kotlinx.serialization and kotlinx.io.
Inspired by [RxStore](https://github.com/Gridstone/RxStore)

## Features
Expand Down Expand Up @@ -56,11 +56,14 @@ Depending on your target platforms, you will need to add platform configurations
## At a glance

```kotlin
import kotlin.io.path.Path
import kotlinx.serialization.Serializable

// Take any serializable model
@Serializable data class Pet(val name: String, val age: Int)

// Create a store
val store: KStore<Pet> = storeOf(file = "path/to/my_cats.json".toPath())
val store: KStore<Pet> = storeOf(file = Path("path/to/my_cats.json"))

// Get, set, update or delete values
val mylo: Pet? = store.get()
Expand Down
10 changes: 3 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties

plugins {
id("org.jetbrains.kotlinx.kover") version "0.6.1"
id("org.jetbrains.dokka") version "1.9.10"
id("org.jetbrains.kotlinx.kover") version "0.8.2"
id("org.jetbrains.dokka") version "1.9.20"
}

buildscript {
Expand All @@ -26,7 +26,7 @@ allprojects {
}

group = "io.github.xxfast"
version = "0.8.0"
version = "0.9.0-SNAPSHOT"

apply(plugin = "org.jetbrains.kotlin.plugin.serialization")
apply(plugin = "org.jetbrains.kotlinx.kover")
Expand Down Expand Up @@ -104,7 +104,3 @@ allprojects {
dependsOn(project.tasks.withType(Sign::class.java))
}
}

koverMerged {
enable()
}
4 changes: 2 additions & 2 deletions docs/topics/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Build](https://github.com/xxfast/KStore/actions/workflows/build.yml/badge.svg)](https://github.com/xxfast/KStore/actions/workflows/build.yml)

[![Kotlin Alpha](https://kotl.in/badges/alpha.svg)](https://kotlinlang.org/docs/components-stability.html)
[![Kotlin](https://img.shields.io/badge/Kotlin-1.9.21-blue.svg?style=flat&logo=kotlin)](https://kotlinlang.org)
[![Kotlin](https://img.shields.io/badge/Kotlin-2.0.10-blue.svg?style=flat&logo=kotlin)](https://kotlinlang.org)
[![Maven Central](https://img.shields.io/maven-central/v/io.github.xxfast/kstore?color=blue)](https://search.maven.org/search?q=g:io.github.xxfast)

![badge-android](http://img.shields.io/badge/platform-android-6EDB8D.svg?style=flat)
Expand Down Expand Up @@ -35,7 +35,7 @@ Inspired by [RxStore](https://github.com/Gridstone/RxStore)
@Serializable data class Pet(val name: String, val age: Int)

// Create a store
val store: KStore<Pet> = storeOf(filePath = "path/to/my_cats.json")
val store: KStore<Pet> = storeOf(file = Path("path/to/my_cats.json"))

// Get, set, update or delete values
val mylo: Pet? = store.get()
Expand Down
2 changes: 1 addition & 1 deletion docs/topics/usage-list-store.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ KStore provides you with some convenient extensions to manage stores that contai
## Create a list store
`listStoreOf` is the same as `storeOf`, but defaults to empty list instead of `null`
```kotlin
val listStore: KStore<List<Pet>> = listStoreOf("path/to/file")
val listStore: KStore<List<Pet>> = listStoreOf(file = "path/to/file")
```

## Get values
Expand Down
16 changes: 10 additions & 6 deletions docs/topics/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Initialise your stores and keep a reference to it in your app (_preferably_ usin

### KStore File
```kotlin
val store: KStore<Pet> = storeOf(file = "$appDir/my_cats.json".toPath())
val store: KStore<Pet> = storeOf(file = Path("$appDir/my_cats.json"))
```

> **NOTE** - Setting up the `appDir` is covered [here](using-platform-paths.md)
Expand All @@ -16,15 +16,19 @@ val store: KStore<Pet> = storeOf(file = "$appDir/my_cats.json".toPath())
```

### Other configuration options
Everything you want is in the factory method
Everything you want is in factory methods

```kotlin
val store: KStore<Pet> = storeOf(
// For kstore-file
file = "$appDir/$fileName.json".toPath(),
// For kstore-file with json
file = Path("$appDir/$fileName.json"),

// For kstore-storage
// Or for kstore-storage
key = "$keyName",
storage = localStorage, // optional

// Or your own custom codec
codec = YourCustomCodec<Pet>(), // optional

// Returns this value if the file is not found. Defaults to null
default = null, // optional
Expand All @@ -36,7 +40,7 @@ val store: KStore<Pet> = storeOf(
version = 0, // optional
migration = { version, jsonElement -> default }, // optional

// Serializer to use. Defaults serializer ignores unknown keys and encodes the defaults
// For kstore-file, the serializer to use.
serializer = Json {
ignoreUnknownKeys = true
encodeDefaults = true
Expand Down
17 changes: 8 additions & 9 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[versions]
agp = "8.0.2"
androidx-test-junit = "1.1.5"
androidx-test-junit = "1.2.1"
junit = "4.13.2"
junit-jupiter="5.9.3"
kotlin = "1.9.22"
kotlinx-coroutines = "1.8.0"
kotlinx-serialization = "1.6.2"
okio = "3.9.0"
junit-jupiter="5.10.1"
kotlin = "2.0.10"
kotlinx-coroutines = "1.9.0-RC"
kotlinx-serialization = "1.7.1"
kotlinx-io = "0.5.0"
turbine = "1.1.0"

[libraries]
Expand All @@ -20,7 +20,6 @@ kotlinx-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core",
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx-coroutines" }
kotlin-serialization = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" }
kotlinx-serialization-json-okio = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json-okio", version.ref = "kotlinx-serialization" }
okio = { module = "com.squareup.okio:okio", version.ref = "okio" }
okio-nodefilesystem = { module = "com.squareup.okio:okio-nodefilesystem", version.ref = "okio" }
kotlinx-serialization-json-io = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json-io", version.ref = "kotlinx-serialization" }
kotlinx-io = { module = "org.jetbrains.kotlinx:kotlinx-io-core", version.ref = "kotlinx-io" }
turbine = { module = "app.cash.turbine:turbine", version.ref = "turbine" }
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading
Loading