Skip to content

Commit

Permalink
Update Kotlin to 2.0.20-RC2 and its dependencies (#1013)
Browse files Browse the repository at this point in the history
  • Loading branch information
hfhbd authored Aug 17, 2024
1 parent cb1747c commit 9b45927
Show file tree
Hide file tree
Showing 19 changed files with 499 additions and 1,218 deletions.
7 changes: 5 additions & 2 deletions backend/src/main/kotlin/app/softwork/composetodo/DTO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ import app.softwork.cloudkitclient.values.*
import app.softwork.composetodo.dao.*
import app.softwork.composetodo.dao.User
import app.softwork.composetodo.dto.*
import kotlinx.uuid.*
import app.softwork.uuid.*
import kotlin.uuid.ExperimentalUuidApi

@OptIn(ExperimentalUuidApi::class)
fun Todo.toDTO() = TodoDTO(
id = TodoDTO.ID(recordName.toUUID()),
id = TodoDTO.ID(recordName.toUuid()),
title = fields.title.value,
until = fields.until?.value,
finished = fields.finished.value.toBoolean(),
recordChangeTag = recordChangeTag
)

@OptIn(ExperimentalUuidApi::class)
fun TodoDTO.toDAO(user: User) = Todo(
recordName = id.id.toString(),
fields = Todo.Fields(
Expand Down
7 changes: 4 additions & 3 deletions backend/src/main/kotlin/app/softwork/composetodo/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import io.ktor.server.cio.*
import io.ktor.server.engine.*
import io.ktor.server.plugins.cors.routing.*
import io.ktor.server.plugins.forwardedheaders.*
import kotlinx.datetime.Clock
import org.slf4j.*
import java.util.*
import kotlin.reflect.*
import kotlin.time.Duration.Companion.minutes

fun main() {
val db = client().publicDB
val db = client(Clock.System).publicDB
val jwtProvider = JWTProvider(
Algorithm.HMAC512("secret"),
"app.softwork.todo",
Expand All @@ -37,9 +38,9 @@ fun main() {
}.start(wait = true)
}

private fun client(): Client {
private fun client(clock: Clock): Client {
val container = "iCloud.app.softwork.composetodo"
val keyID = System.getenv("keyID") ?: return TestClient()
val keyID = System.getenv("keyID") ?: return TestClient(clock)

val privateKey by Env
val logger = LoggerFactory.getLogger(CKClient::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import app.softwork.composetodo.*
import app.softwork.composetodo.dao.*
import app.softwork.composetodo.dao.User
import app.softwork.composetodo.dto.*
import kotlin.uuid.ExperimentalUuidApi

class TodoController(private val db: Client.Database) {

Expand All @@ -14,6 +15,7 @@ class TodoController(private val db: Client.Database) {

suspend fun create(newTodo: Todo) = db.create(newTodo, Todo)

@OptIn(ExperimentalUuidApi::class)
suspend fun getTodo(user: User, todoID: TodoDTO.ID) = db.read(todoID.id.toString(), Todo)?.takeIf {
it.fields.user.value.recordName == user.recordName
}
Expand Down
6 changes: 4 additions & 2 deletions backend/src/test/kotlin/app/softwork/composetodo/Helper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import io.ktor.http.*
import io.ktor.serialization.kotlinx.json.*
import io.ktor.server.application.*
import io.ktor.server.testing.*
import kotlinx.datetime.Clock
import kotlin.contracts.*
import kotlin.test.*

suspend fun dbTest(
clock: Clock,
test: suspend (Client.Database) -> Unit
) {
val db = TestClient().publicDB
val db = TestClient(clock).publicDB
test(db)
}

Expand All @@ -25,7 +27,7 @@ fun testApplication(
tests: suspend HttpClient.(Client.Database) -> Unit
) {
testApplication {
dbTest { db ->
dbTest(Clock.System) { db ->
application {
setup(db)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import com.auth0.jwt.algorithms.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import kotlinx.uuid.*
import kotlin.test.*
import kotlin.time.Duration.Companion.seconds
import kotlin.uuid.*

@ExperimentalUuidApi
internal class TodoModuleKtTest {
private val jwt = JWTProvider(Algorithm.HMAC256("secret"), "test.com", "test", 45.seconds)

Expand All @@ -30,7 +31,7 @@ internal class TodoModuleKtTest {
login("user", "password") {
val todo = createTodo(
TodoDTO(
id = TodoDTO.ID(UUID()),
id = TodoDTO.ID(Uuid.random()),
title = "New Todo",
until = null,
finished = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package app.softwork.composetodo.repository

import app.cash.sqldelight.*
import app.softwork.composetodo.dto.*
import kotlinx.uuid.*
import app.softwork.uuid.*
import kotlin.uuid.ExperimentalUuidApi

@OptIn(ExperimentalUuidApi::class)
object IDConverter : ColumnAdapter<TodoDTO.ID, String> {
override fun decode(databaseValue: String) = TodoDTO.ID(databaseValue.toUUID())
override fun decode(databaseValue: String) = TodoDTO.ID(databaseValue.toUuid())
override fun encode(value: TodoDTO.ID) = value.id.toString()
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import app.softwork.composetodo.dto.*
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import kotlinx.datetime.*
import kotlinx.uuid.*
import kotlin.uuid.*

interface TodoRepository {
companion object {
Expand Down Expand Up @@ -43,8 +43,9 @@ interface TodoRepository {
}
}

@OptIn(ExperimentalUuidApi::class)
override suspend fun create(title: String, until: Instant?) {
val id = TodoDTO.ID(UUID())
val id = TodoDTO.ID(Uuid.random())
dao.upsertTodo(id = id, title = title, until = until, finished = false, recordChangeTag = null)
}
}
Expand Down
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ org.gradle.configuration-cache=true
org.gradle.configureondemand=true

android.useAndroidX=true
android.enableJetifier=true
android.nonTransitiveRClass=true

kotlin.mpp.androidGradlePluginCompatibility.nowarn=true
Expand Down
12 changes: 6 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[versions]
kotlin = "2.0.10"
kotlin = "2.0.20-RC2"
detekt = "1.23.6"
coroutines = "1.8.1"
coroutines = "1.9.0-RC.2"
datetime = "0.6.0"
serialization = "1.7.1"
ktor = "2.3.12"
sqldelight = "2.0.2"
cloudkit = "0.1.0"
cloudkit = "0.2.0"
compose = "1.6.11"

[libraries]
Expand All @@ -28,9 +28,9 @@ sqldelight-coroutinesExtensions = { module = "app.cash.sqldelight:coroutines-ext

detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" }

uuid-core = { module = "app.softwork:kotlinx-uuid-core", version = "0.0.26" }
bootstrapCompose = { module = "app.softwork:bootstrap-compose", version = "0.2.1" }
routingCompose = { module = "app.softwork:routing-compose", version = "0.2.14" }
uuid-core = { module = "app.softwork:kotlinx-uuid-core", version = "0.1.0" }
bootstrapCompose = { module = "app.softwork:bootstrap-compose", version = "0.3.0" }
routingCompose = { module = "app.softwork:routing-compose", version = "0.3.0" }

ktor-resources = { module = "io.ktor:ktor-resources", version.ref = "ktor" }
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
Expand Down
4 changes: 1 addition & 3 deletions iosLib/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.9
// swift-tools-version: 5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -7,8 +7,6 @@ let package = Package(
name: "iosLib",
platforms: [
.iOS(.v17),
.tvOS(.v14),
.watchOS(.v10),
.macOS(.v14)
],
products: [
Expand Down
12 changes: 2 additions & 10 deletions iosLib/Sources/iosLib/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Combine

struct ContentView: View {
@ObservedObject var container: IosContainer

init(container: IosContainer) {
self._container = .init(initialValue: container)
self.isLoggedIn = APILoggedOut(client: container.client)
Expand Down Expand Up @@ -43,10 +43,6 @@ struct ContentView: View {
}

struct Login: View {
init(viewModel: @autoclosure @escaping () -> LoginViewModel) {
self._viewModel = StateObject(wrappedValue: viewModel())
}

@StateObject var viewModel: LoginViewModel

@State private var error: Failure?
Expand All @@ -57,7 +53,7 @@ struct Login: View {
TextField("Username", text: viewModel.binding(\.userName))
SecureField("Password", text: viewModel.binding(\.password))

if let error = error {
if let error {
Text(error.reason)
}
}.toolbar {
Expand All @@ -78,10 +74,6 @@ struct Login: View {
}

struct Register: View {
init(viewModel: @autoclosure @escaping () -> RegisterViewModel) {
self._viewModel = StateObject(wrappedValue: viewModel())
}

@StateObject var viewModel: RegisterViewModel

@State private var disableRegister = true
Expand Down
4 changes: 2 additions & 2 deletions iosLib/Sources/iosLib/TodoItemRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct TodoItemRow: View {
}
VStack(alignment: .leading) {
Text(item.title)
Text((item.id as! clients.UUID).toNsUUID().uuidString).font(.footnote)
Text((item.id as! clients.KotlinUuid).toNsUUID().uuidString).font(.footnote)
if let until = item.until {
Text(dateFormatter.string(from: until.toNSDate()))
}
Expand All @@ -37,6 +37,6 @@ private let dateFormatter: DateFormatter = {

struct TodoItemRowPreview: PreviewProvider {
static var previews: some View {
TodoItemRow(item: Todo(id: clients.UUID.companion.NIL, title: "TestItem", until: clients.Instant.companion.fromEpochMilliseconds(epochMilliseconds: 0), finished: false, recordChangeTag: nil))
TodoItemRow(item: Todo(id: KotlinUuid.companion.NIL, title: "TestItem", until: clients.Instant.companion.fromEpochMilliseconds(epochMilliseconds: 0), finished: false, recordChangeTag: nil))
}
}
10 changes: 2 additions & 8 deletions iosLib/Sources/iosLib/Todos.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import SwiftUI
import clients

struct Todos: View {
init(viewModel: @autoclosure @escaping () -> TodoViewModel) {
self._viewModel = StateObject(wrappedValue: viewModel())
}

@StateObject var viewModel: TodoViewModel

@State private var todos = [Todo]()
Expand All @@ -35,7 +31,7 @@ struct Todos_Previews: PreviewProvider {
Todos(viewModel: TodoViewModel.init(repo: TestRepo()))
}

class TestRepo: TodoRepository {
private final class TestRepo: TodoRepository {
init() {

}
Expand All @@ -49,9 +45,7 @@ struct Todos_Previews: PreviewProvider {
func sync() async throws { }

var todos: Flow {
get {
BuildersKt.emptyFlow()
}
BuildersKt.emptyFlow()
}
}
}
13 changes: 4 additions & 9 deletions iosLib/Tests/iosLibTests/iosLibTests.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import XCTest
import Testing
@testable import iosLib

final class iosLibTests: XCTestCase {
func testExample() throws {
// XCTest Documentation
// https://developer.apple.com/documentation/xctest

// Defining Test Cases and Test Methods
// https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods
}
@Test
func testExample() throws {

}
Loading

0 comments on commit 9b45927

Please sign in to comment.