From 358088c705d7487f1409c770b569f056736a8305 Mon Sep 17 00:00:00 2001 From: James Fenn Date: Tue, 8 Dec 2020 22:54:27 -0500 Subject: [PATCH] updated dependencies & broke everything! yay! --- build.gradle | 8 ++++---- example-android/build.gradle | 1 - example-nodejs/build.gradle | 2 +- example-nodejs/src/index.js | 3 +++ gitrest/build.gradle | 6 +++--- .../me/jfenn/gitrest/service/DiskCache.kt | 19 ++++++++---------- .../me/jfenn/gitrest/base/ServiceBuilder.kt | 1 - .../me/jfenn/gitrest/model/GitrestConfig.kt | 5 +++-- .../me/jfenn/gitrest/util/Serialization.kt | 4 +++- gitrest/src/jsMain/kotlin/Client.kt | 20 +++++++++++-------- gradle/wrapper/gradle-wrapper.properties | 2 +- 11 files changed, 38 insertions(+), 33 deletions(-) diff --git a/build.gradle b/build.gradle index e6a4f68..cb6f99d 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 07ac79d..9609b18 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 a4a7faa..d9ac6ff 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 6055189..a7d10f2 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 d421548..f5e99a8 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 c65953f..772cbe3 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 b063064..e2b39b4 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 c1bef16..0e0c046 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 48c0123..e03e9fd 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 8ae0668..c1a0efe 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 b926dfc..86beb6a 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 -- GitLab