Browse Source

updated dependencies & broke everything! yay!

main
James Fenn 1 month ago
parent
commit
358088c705
11 changed files with 38 additions and 33 deletions
  1. +4
    -4
      build.gradle
  2. +0
    -1
      example-android/build.gradle
  3. +1
    -1
      example-nodejs/build.gradle
  4. +3
    -0
      example-nodejs/src/index.js
  5. +3
    -3
      gitrest/build.gradle
  6. +8
    -11
      gitrest/src/androidMain/kotlin/me/jfenn/gitrest/service/DiskCache.kt
  7. +0
    -1
      gitrest/src/commonMain/kotlin/me/jfenn/gitrest/base/ServiceBuilder.kt
  8. +3
    -2
      gitrest/src/commonMain/kotlin/me/jfenn/gitrest/model/GitrestConfig.kt
  9. +3
    -1
      gitrest/src/commonMain/kotlin/me/jfenn/gitrest/util/Serialization.kt
  10. +12
    -8
      gitrest/src/jsMain/kotlin/Client.kt
  11. +1
    -1
      gradle/wrapper/gradle-wrapper.properties

+ 4
- 4
build.gradle View File

@@ -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"


+ 0
- 1
example-android/build.gradle View File

@@ -1,6 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 29


+ 1
- 1
example-nodejs/build.gradle View File

@@ -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'


+ 3
- 0
example-nodejs/src/index.js View File

@@ -3,6 +3,9 @@ const { Client } = require("git-rest-wrapper-gitrest");
let gitrest = new Client({
cache: {
type: "disk"
},
tokens: {
'a.b': "c"
}
});



+ 3
- 3
gitrest/build.gradle View File

@@ -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"


+ 8
- 11
gitrest/src/androidMain/kotlin/me/jfenn/gitrest/service/DiskCache.kt View File

@@ -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<Any>
@@ -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<Any>
serializer = ListSerializer(type.serializer()) as KSerializer<Any>
typeName = "list:${type.java.name}"
} else {
serializer = value::class.serializerOrNull() as KSerializer<Any>
@@ -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 <T> 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<Any>
ListSerializer(Class.forName(className.substring(5)).kotlin.serializer()) as KSerializer<Any>
else Class.forName(className).kotlin.serializer() as KSerializer<Any>

// 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}")


+ 0
- 1
gitrest/src/commonMain/kotlin/me/jfenn/gitrest/base/ServiceBuilder.kt View File

@@ -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<T: RequestProvider> {


+ 3
- 2
gitrest/src/commonMain/kotlin/me/jfenn/gitrest/model/GitrestConfig.kt View File

@@ -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()



+ 3
- 1
gitrest/src/commonMain/kotlin/me/jfenn/gitrest/util/Serialization.kt View File

@@ -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<String?> {

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? {


+ 12
- 8
gitrest/src/jsMain/kotlin/Client.kt View File

@@ -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<Array<Array<String>>>()
.map {
it[0].unsafeCast<String>() 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)
}
}



+ 1
- 1
gradle/wrapper/gradle-wrapper.properties View File

@@ -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

Loading…
Cancel
Save