diff --git a/build.gradle b/build.gradle index e6a4f68e74e4751199474cca5d76d5880e40534f..cb6f99dc4cf88ec48a195c084e6811e641e4e472 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,8 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.72' - ext.ktor_version = '1.3.2' - ext.serialization_version = '0.20.0' + ext.kotlin_version = '1.4.21' + ext.ktor_version = '1.4.3' + ext.serialization_version = '1.0.1' repositories { google() @@ -15,7 +15,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:4.0.0' + classpath 'com.android.tools.build:gradle:4.1.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" classpath "gradle.plugin.com.github.salomonbrys.gradle.kotlin.js:kotlin-js-npm-bundle:1.0.0" diff --git a/example-android/build.gradle b/example-android/build.gradle index 07ac79d142070ae2c9a748bb55e6985e138d5140..9609b189d38b01948f0487a185add7d89f555db0 100644 --- a/example-android/build.gradle +++ b/example-android/build.gradle @@ -1,6 +1,5 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 29 diff --git a/example-nodejs/build.gradle b/example-nodejs/build.gradle index a4a7faa1b5d40b057a037acbe6b703d128b01a38..d9ac6ffec1a576380de372b792c3f7329b56a811 100644 --- a/example-nodejs/build.gradle +++ b/example-nodejs/build.gradle @@ -6,7 +6,7 @@ buildscript { } } dependencies { - classpath 'com.moowork.gradle:gradle-node-plugin:1.2.0' + classpath 'com.moowork.gradle:gradle-node-plugin:1.3.1' } } apply plugin: 'base' diff --git a/example-nodejs/src/index.js b/example-nodejs/src/index.js index 605518990f50fca9ca2fc548b303cd448fc65da8..a7d10f2e3d1ac5297e64fccd5e423f28aa3df091 100644 --- a/example-nodejs/src/index.js +++ b/example-nodejs/src/index.js @@ -3,6 +3,9 @@ const { Client } = require("git-rest-wrapper-gitrest"); let gitrest = new Client({ cache: { type: "disk" + }, + tokens: { + 'a.b': "c" } }); diff --git a/gitrest/build.gradle b/gitrest/build.gradle index d42154870acf770c94f34a38e4dfd3a1623e33ab..f5e99a8854772f61b17004ba347ffb72ae258136 100644 --- a/gitrest/build.gradle +++ b/gitrest/build.gradle @@ -84,11 +84,11 @@ kotlin { dependencies { compileOnly kotlin('stdlib-common') compileOnly 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.4' - compileOnly "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version" + compileOnly "org.jetbrains.kotlinx:kotlinx-serialization-json:$serialization_version" compileOnly "io.ktor:ktor-client-core:$ktor_version" compileOnly "io.ktor:ktor-client-json:$ktor_version" compileOnly ("io.ktor:ktor-client-serialization:$ktor_version") { - exclude group: "org.jetbrains.kotlinx", module: "kotlinx-serialization-runtime-common" + exclude group: "org.jetbrains.kotlinx", module: "kotlinx-serialization-json-common" } } } @@ -139,7 +139,7 @@ kotlin { dependencies { implementation kotlin('stdlib-js') implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.3.6' - implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serialization_version" + implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:$serialization_version" implementation "io.ktor:ktor-client-js:$ktor_version" implementation "io.ktor:ktor-client-json-js:$ktor_version" implementation "io.ktor:ktor-client-serialization-js:$ktor_version" diff --git a/gitrest/src/androidMain/kotlin/me/jfenn/gitrest/service/DiskCache.kt b/gitrest/src/androidMain/kotlin/me/jfenn/gitrest/service/DiskCache.kt index c65953f925a5f030e24b653889d875e05b9b3e5d..772cbe3bce8ed0fdc7efed55012f2fc3d9eb2cdc 100644 --- a/gitrest/src/androidMain/kotlin/me/jfenn/gitrest/service/DiskCache.kt +++ b/gitrest/src/androidMain/kotlin/me/jfenn/gitrest/service/DiskCache.kt @@ -1,10 +1,7 @@ package me.jfenn.gitrest.service -import kotlinx.serialization.ImplicitReflectionSerializer -import kotlinx.serialization.KSerializer -import kotlinx.serialization.builtins.list -import kotlinx.serialization.serializer -import kotlinx.serialization.serializerOrNull +import kotlinx.serialization.* +import kotlinx.serialization.builtins.ListSerializer import me.jfenn.gitrest.model.GitrestConfig import me.jfenn.gitrest.provider.gitea.model.GiteaUser import java.io.File @@ -24,7 +21,7 @@ class DiskCache( fun String.cacheFile() = File(cacheDir, "${this.replace(File.separator, "_")}.json") - @ImplicitReflectionSerializer + @InternalSerializationApi override suspend fun set(key: String, value: Any) { // obtain a serializer + type for the value (this is all just a ridiculous hack) val serializer: KSerializer @@ -32,7 +29,7 @@ class DiskCache( if (value is List<*>) { // GiteaUser is just a default list hack for when the list is empty; it's never actually serialized in this case val type = value.firstOrNull()?.let { it::class } ?: GiteaUser::class - serializer = type.serializer().list as KSerializer + serializer = ListSerializer(type.serializer()) as KSerializer typeName = "list:${type.java.name}" } else { serializer = value::class.serializerOrNull() as KSerializer @@ -40,7 +37,7 @@ class DiskCache( } // add type + expiration metadata before serializing - val string = typeName + "#" + System.currentTimeMillis() + "#" + config.jsonSerializer.stringify(serializer, value) + val string = typeName + "#" + System.currentTimeMillis() + "#" + config.jsonSerializer.encodeToString(serializer, value) try { cacheDir.mkdirs() @@ -50,7 +47,7 @@ class DiskCache( } } - @ImplicitReflectionSerializer + @InternalSerializationApi override suspend fun get(key: String): T? { return try { // check contents; destructure file parts if safe @@ -60,12 +57,12 @@ class DiskCache( // obtain the correct serializer for {className} val serializer = if (className.startsWith("list:")) - Class.forName(className.substring(5)).kotlin.serializer().list as KSerializer + ListSerializer(Class.forName(className.substring(5)).kotlin.serializer()) as KSerializer else Class.forName(className).kotlin.serializer() as KSerializer // parse JSON if before expiry date; else return null for default behavior (fetch the actual request) if (System.currentTimeMillis() - lastModified.toLong() < cacheDuration) { - config.jsonSerializer.parse(serializer, json) as? T + config.jsonSerializer.decodeFromString(serializer, json) as? T } else null } catch (e : IOException) { config.logError("GIT-REST: ${e::class.simpleName} - ${e.message}") diff --git a/gitrest/src/commonMain/kotlin/me/jfenn/gitrest/base/ServiceBuilder.kt b/gitrest/src/commonMain/kotlin/me/jfenn/gitrest/base/ServiceBuilder.kt index b063064ee1ecba5229e46ce8c750f65b968e90a1..e2b39b47f26a1f67d331a98cbd5d97dbb2a0b637 100644 --- a/gitrest/src/commonMain/kotlin/me/jfenn/gitrest/base/ServiceBuilder.kt +++ b/gitrest/src/commonMain/kotlin/me/jfenn/gitrest/base/ServiceBuilder.kt @@ -5,7 +5,6 @@ import io.ktor.client.HttpClientConfig import io.ktor.client.features.json.JsonFeature import io.ktor.client.features.json.serializer.KotlinxSerializer import kotlinx.serialization.json.Json -import kotlinx.serialization.json.JsonConfiguration import me.jfenn.gitrest.model.GitrestConfig interface ServiceBuilder { diff --git a/gitrest/src/commonMain/kotlin/me/jfenn/gitrest/model/GitrestConfig.kt b/gitrest/src/commonMain/kotlin/me/jfenn/gitrest/model/GitrestConfig.kt index c1bef1604ad777c1489b75dc066c1da0729f8fc1..0e0c0468199c4c1bb31699337a11277b3c1dccf5 100644 --- a/gitrest/src/commonMain/kotlin/me/jfenn/gitrest/model/GitrestConfig.kt +++ b/gitrest/src/commonMain/kotlin/me/jfenn/gitrest/model/GitrestConfig.kt @@ -1,7 +1,6 @@ package me.jfenn.gitrest.model import kotlinx.serialization.json.Json -import kotlinx.serialization.json.JsonConfiguration import me.jfenn.gitrest.base.ServiceBuilder import me.jfenn.gitrest.provider.gitea.GiteaProvider import me.jfenn.gitrest.provider.github.GithubProvider @@ -22,7 +21,9 @@ class GitrestConfig { var logDebug: (String) -> Unit = {} // TODO: implement a more robust log handler + check BuildConfig.DEBUG before logging var logError: (String) -> Unit = { println(it) } - var jsonSerializer = Json(JsonConfiguration.Stable.copy(ignoreUnknownKeys = true)) + var jsonSerializer = Json { + ignoreUnknownKeys = true + } var cache : Cache = MemoryCache() diff --git a/gitrest/src/commonMain/kotlin/me/jfenn/gitrest/util/Serialization.kt b/gitrest/src/commonMain/kotlin/me/jfenn/gitrest/util/Serialization.kt index 48c0123d80556b35de0f29d517efe32cbe71a76a..e03e9fd5e3800743b9319a197e4623956f1d6a75 100644 --- a/gitrest/src/commonMain/kotlin/me/jfenn/gitrest/util/Serialization.kt +++ b/gitrest/src/commonMain/kotlin/me/jfenn/gitrest/util/Serialization.kt @@ -1,6 +1,8 @@ package me.jfenn.gitrest.util import kotlinx.serialization.* +import kotlinx.serialization.encoding.* +import kotlinx.serialization.descriptors.* import kotlinx.serialization.builtins.serializer /** @@ -8,7 +10,7 @@ import kotlinx.serialization.builtins.serializer */ open class OptionalStringSerializer : KSerializer { - final override val descriptor: SerialDescriptor = PrimitiveDescriptor("kotlin.OptionalString", PrimitiveKind.STRING) + final override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("kotlin.OptionalString", PrimitiveKind.STRING) private val valueSerializer = String.serializer() final override fun deserialize(decoder: Decoder): String? { diff --git a/gitrest/src/jsMain/kotlin/Client.kt b/gitrest/src/jsMain/kotlin/Client.kt index 8ae06680577589476f252135eee3b2854633ba1d..c1a0efe08cfe2ac7cca0611c0f717d54d630a40b 100644 --- a/gitrest/src/jsMain/kotlin/Client.kt +++ b/gitrest/src/jsMain/kotlin/Client.kt @@ -15,16 +15,20 @@ class Client( ) { val client = gitrest { - this.providers.forEach { - if (config?.tokens != null) { - this.providers.forEach { - it.tokens.putAll(config.tokens) - } + if (config?.tokens != null) { + val tokens = js("Object").entries(config.tokens) + .unsafeCast>>() + .map { + it[0].unsafeCast() to it[1] + }.toMap() + + this.providers.forEach { + it.tokens.putAll(tokens) } + } - if (config?.cache?.type == "disk") { - this.cache = DiskCache(this) - } + if (config?.cache?.type == "disk") { + this.cache = DiskCache(this) } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b926dfc51cd00d83eda2e2201978114270c67891..86beb6a786b1c8419a05381a1e694004a1b73116 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip