diff options
author | Robert Jaros <rjaros@finn.pl> | 2020-03-11 16:18:17 +0100 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2020-03-11 16:18:17 +0100 |
commit | 9e243a469ae6544e8cf523ad09b959f541c3f565 (patch) | |
tree | be9c7447e221af49180c9e98434df7f988b940b8 /src/main | |
parent | ec6084c42c13a621e17b17bd40d90b5c7879f0ec (diff) | |
download | kvision-9e243a469ae6544e8cf523ad09b959f541c3f565.tar.gz kvision-9e243a469ae6544e8cf523ad09b959f541c3f565.tar.bz2 kvision-9e243a469ae6544e8cf523ad09b959f541c3f565.zip |
Upgrade to Kotlin 1.3.70 + other dependencies (Coroutinse, Serialization, Spring Boot)
Major refactoring of build architecture.
Diffstat (limited to 'src/main')
9 files changed, 46 insertions, 101 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/KVManager.kt b/src/main/kotlin/pl/treksoft/kvision/KVManager.kt index 0ba694eb..1cd41e7d 100644 --- a/src/main/kotlin/pl/treksoft/kvision/KVManager.kt +++ b/src/main/kotlin/pl/treksoft/kvision/KVManager.kt @@ -46,15 +46,15 @@ external fun require(name: String): dynamic object KVManager { init { try { - require("kvision-bootstrap-css").pl.treksoft.kvision.KVManagerBootstrapCss + require("kvision-kvision-bootstrap-css").pl.treksoft.kvision.KVManagerBootstrapCss } catch (e: Throwable) { } try { - require("kvision-bootstrap").pl.treksoft.kvision.KVManagerBootstrap + require("kvision-kvision-bootstrap").pl.treksoft.kvision.KVManagerBootstrap } catch (e: Throwable) { } try { - require("kvision-fontawesome").pl.treksoft.kvision.KVManagerFontAwesome + require("kvision-kvision-fontawesome").pl.treksoft.kvision.KVManagerFontAwesome } catch (e: Throwable) { } require("./css/style.css") diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt index 918d0ad0..c03316ab 100644 --- a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt +++ b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt @@ -355,7 +355,7 @@ open class Widget(classes: Set<String> = setOf()) : StyledComponent(), Component * } * } */ - @Suppress("UNCHECKED_CAST") + @Suppress("UNCHECKED_CAST", "UnsafeCastFromDynamic") open fun <T : Widget> setEventListener(block: SnOn<T>.() -> Unit): Int { val handlerCounter = listenerCounter++ val blockAsWidget = block as SnOn<Widget>.() -> Unit diff --git a/src/main/kotlin/pl/treksoft/kvision/form/Form.kt b/src/main/kotlin/pl/treksoft/kvision/form/Form.kt index 5e49e1b4..3eb94f64 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/Form.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/Form.kt @@ -21,19 +21,22 @@ */ package pl.treksoft.kvision.form +import kotlinx.serialization.DynamicObjectParser import kotlinx.serialization.ImplicitReflectionSerializer import kotlinx.serialization.KSerializer -import kotlinx.serialization.Mapper +import kotlinx.serialization.builtins.list import kotlinx.serialization.modules.serializersModuleOf import kotlinx.serialization.serializer import pl.treksoft.kvision.i18n.I18n.trans import pl.treksoft.kvision.types.DateSerializer import pl.treksoft.kvision.types.KFile import pl.treksoft.kvision.types.toStringF +import pl.treksoft.kvision.utils.JSON.toObj import kotlin.js.Date import kotlin.js.Json import kotlin.reflect.KClass import kotlin.reflect.KProperty1 +import kotlin.js.JSON as NativeJSON /** * Internal data class containing form field parameters. @@ -46,27 +49,6 @@ internal data class FieldParams<in F : FormControl>( ) /** - * A wrapper for a Map with a custom containsKey method implementation. - * Used with kotlinx.serialization Mapper. - */ -private class FormMapWrapper<out V>(private val map: Map<String, V>) : Map<String, V> { - override fun equals(other: Any?): Boolean = map == other - override fun hashCode(): Int = map.hashCode() - override fun toString(): String = map.toString() - override val size: Int get() = map.size - override fun isEmpty(): Boolean = map.isEmpty() - override fun containsKey(key: String): Boolean = - if (key.indexOf('.') != -1) map.containsKey(key) else - !(map.containsKey("$key.time") || map.containsKey("$key.size")) - - override fun containsValue(value: @UnsafeVariance V): Boolean = map.containsValue(value) - override fun get(key: String): V? = map[key] - override val keys: Set<String> get() = map.keys - override val values: Collection<V> get() = map.values - override val entries: Set<Map.Entry<String, V>> get() = map.entries -} - -/** * The form definition class. Can be used directly or indirectly inside a [FormPanel]. * * @constructor Creates a form with a given modelFactory function @@ -89,36 +71,26 @@ class Form<K : Any>( init { modelFactory = { - val map = it.flatMap { entry -> - when (entry.value) { + val json = js("{}") + it.forEach { (key, value) -> + val v = when (value) { is Date -> { - listOf(entry.key to (entry.value as? Date)?.toStringF()) + value.toStringF() } is List<*> -> { @Suppress("UNCHECKED_CAST") - (entry.value as? List<KFile>)?.let { list -> - listOf(entry.key to entry.value, "${entry.key}.size" to list.size) + - list.mapIndexed { index, kFile -> - listOf( - "${entry.key}.$index.name" to kFile.name, - "${entry.key}.$index.size" to kFile.size, - "${entry.key}.$index.content" to kFile.content - ) - }.flatten() - } ?: listOf() + ((value as? List<KFile>)?.toObj(KFile.serializer().list)) } - else -> listOf(entry.key to entry.value) + else -> value } - }.toMap() + json[key] = v + } val serializersModule = if (customSerializers == null) { serializersModuleOf(Date::class, DateSerializer) } else { serializersModuleOf(customSerializers + (Date::class to DateSerializer)) } - Mapper(context = serializersModule).unmapNullable( - serializer, - FormMapWrapper(map) - ) + DynamicObjectParser(serializersModule).parse(json, serializer) } } @@ -315,7 +287,7 @@ class Form<K : Any>( } else { serializersModuleOf(customSerializers + (Date::class to DateSerializer)) } - return JSON.parse( + return NativeJSON.parse( kotlinx.serialization.json.Json(context = serializersModule).stringify( serializer, getData() @@ -361,7 +333,7 @@ class Form<K : Any>( } companion object { - @UseExperimental(ImplicitReflectionSerializer::class) + @OptIn(ImplicitReflectionSerializer::class) inline fun <reified K : Any> create( panel: FormPanel<K>? = null, customSerializers: Map<KClass<*>, KSerializer<*>>? = null, diff --git a/src/main/kotlin/pl/treksoft/kvision/form/FormPanel.kt b/src/main/kotlin/pl/treksoft/kvision/form/FormPanel.kt index ba144137..8f918a97 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/FormPanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/FormPanel.kt @@ -114,34 +114,42 @@ open class FormPanel<K : Any>( * HTTP method. */ var method by refreshOnUpdate(method) + /** * The URL address to send data. */ var action by refreshOnUpdate(action) + /** * The form encoding type. */ var enctype by refreshOnUpdate(enctype) + /** * The form name. */ var name: String? by refreshOnUpdate() + /** * The form target. */ var target: FormTarget? by refreshOnUpdate() + /** * Determines if the form is not validated. */ var novalidate: Boolean? by refreshOnUpdate() + /** * Determines if the form should have autocomplete. */ var autocomplete: Boolean? by refreshOnUpdate() + /** * Determines if the form is condensed. */ var condensed by refreshOnUpdate(condensed) + /** * Horizontal form layout ratio. */ @@ -155,6 +163,7 @@ open class FormPanel<K : Any>( set(value) { form.validatorMessage = value } + /** * Validation function. */ @@ -178,6 +187,7 @@ open class FormPanel<K : Any>( */ @Suppress("LeakingThis") val form = Form(this, serializer, customSerializers) + /** * @suppress * Internal property. @@ -459,7 +469,7 @@ open class FormPanel<K : Any>( companion object { - @UseExperimental(ImplicitReflectionSerializer::class) + @OptIn(ImplicitReflectionSerializer::class) inline fun <reified K : Any> create( method: FormMethod? = null, action: String? = null, enctype: FormEnctype? = null, type: FormType? = null, condensed: Boolean = false, diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Template.kt b/src/main/kotlin/pl/treksoft/kvision/html/Template.kt index 7b5b26a5..b9e165ef 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Template.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Template.kt @@ -66,7 +66,7 @@ fun <K> Template.setData(obj: K, serializer: SerializationStrategy<K>) { /** * Extension function to set serializable object as a template data. */ -@UseExperimental(ImplicitReflectionSerializer::class) +@OptIn(ImplicitReflectionSerializer::class) inline fun <reified K : Any> Template.setData(obj: K) { this.setData(obj, K::class.serializer()) } diff --git a/src/main/kotlin/pl/treksoft/kvision/rest/RestClient.kt b/src/main/kotlin/pl/treksoft/kvision/rest/RestClient.kt index b1ab97b6..9011c780 100644 --- a/src/main/kotlin/pl/treksoft/kvision/rest/RestClient.kt +++ b/src/main/kotlin/pl/treksoft/kvision/rest/RestClient.kt @@ -180,7 +180,7 @@ open class RestClient { * @param transform a function to transform the result of the call * @return a promise of the result */ - @UseExperimental(ImplicitReflectionSerializer::class) + @OptIn(ImplicitReflectionSerializer::class) inline fun <reified T : Any> call( url: String, data: dynamic = null, @@ -201,7 +201,7 @@ open class RestClient { * @param beforeSend a function to set request parameters * @return a promise of the result */ - @UseExperimental(ImplicitReflectionSerializer::class) + @OptIn(ImplicitReflectionSerializer::class) inline fun <reified V : Any> call( url: String, data: V, @@ -230,7 +230,7 @@ open class RestClient { * @param transform a function to transform the result of the call * @return a promise of the result */ - @UseExperimental(ImplicitReflectionSerializer::class) + @OptIn(ImplicitReflectionSerializer::class) inline fun <T : Any, reified V : Any> call( url: String, data: V, @@ -263,7 +263,7 @@ open class RestClient { * @param transform a function to transform the result of the call * @return a promise of the result */ - @UseExperimental(ImplicitReflectionSerializer::class) + @OptIn(ImplicitReflectionSerializer::class) inline fun <reified T : Any, V : Any> call( url: String, serializer: SerializationStrategy<V>, @@ -295,7 +295,7 @@ open class RestClient { * @param transform a function to transform the result of the call * @return a promise of the result */ - @UseExperimental(ImplicitReflectionSerializer::class) + @OptIn(ImplicitReflectionSerializer::class) inline fun <reified T : Any, reified V : Any> call( url: String, data: V, @@ -470,7 +470,7 @@ open class RestClient { * @param transform a function to transform the result of the call * @return a promise of the response */ - @UseExperimental(ImplicitReflectionSerializer::class) + @OptIn(ImplicitReflectionSerializer::class) inline fun <reified T : Any> request( url: String, data: dynamic = null, @@ -491,7 +491,7 @@ open class RestClient { * @param beforeSend a function to set request parameters * @return a promise of the response */ - @UseExperimental(ImplicitReflectionSerializer::class) + @OptIn(ImplicitReflectionSerializer::class) inline fun <reified V : Any> request( url: String, data: V, @@ -520,7 +520,7 @@ open class RestClient { * @param transform a function to transform the result of the call * @return a promise of the response */ - @UseExperimental(ImplicitReflectionSerializer::class) + @OptIn(ImplicitReflectionSerializer::class) inline fun <T : Any, reified V : Any> request( url: String, data: V, @@ -553,7 +553,7 @@ open class RestClient { * @param transform a function to transform the result of the call * @return a promise of the response */ - @UseExperimental(ImplicitReflectionSerializer::class) + @OptIn(ImplicitReflectionSerializer::class) inline fun <reified T : Any, V : Any> request( url: String, serializer: SerializationStrategy<V>, @@ -585,7 +585,7 @@ open class RestClient { * @param transform a function to transform the result of the call * @return a promise of the response */ - @UseExperimental(ImplicitReflectionSerializer::class) + @OptIn(ImplicitReflectionSerializer::class) inline fun <reified T : Any, reified V : Any> request( url: String, data: V, diff --git a/src/main/kotlin/pl/treksoft/kvision/types/Date.kt b/src/main/kotlin/pl/treksoft/kvision/types/Date.kt index 889d26fc..74bcc28d 100644 --- a/src/main/kotlin/pl/treksoft/kvision/types/Date.kt +++ b/src/main/kotlin/pl/treksoft/kvision/types/Date.kt @@ -25,22 +25,9 @@ import kotlinx.serialization.Decoder import kotlinx.serialization.Encoder import kotlinx.serialization.KSerializer import kotlinx.serialization.SerialDescriptor -import kotlinx.serialization.internal.SerialClassDescImpl import pl.treksoft.kvision.KVManager import kotlin.js.Date -const val KV_DEFAULT_DATE_FORMAT = "YYYY-MM-DD HH:mm:ss" - -actual typealias LocalDateTime = Date - -actual typealias LocalDate = Date - -actual typealias LocalTime = Date - -actual typealias OffsetDateTime = Date - -actual typealias OffsetTime = Date - /** * Extension function to convert String to Date with a given date format. * @param format date/time format @@ -63,7 +50,7 @@ fun Date.toStringF(format: String = KV_DEFAULT_DATE_FORMAT): String { } object DateSerializer : KSerializer<Date> { - override val descriptor: SerialDescriptor = SerialClassDescImpl("kotlin.js.Date") + override val descriptor: SerialDescriptor = SerialDescriptor("kotlin.js.Date") override fun deserialize(decoder: Decoder): Date { val str = decoder.decodeString() @@ -74,7 +61,7 @@ object DateSerializer : KSerializer<Date> { } } - override fun serialize(encoder: Encoder, obj: Date) { - encoder.encodeString(obj.toStringF()) + override fun serialize(encoder: Encoder, value: Date) { + encoder.encodeString(value.toStringF()) } } diff --git a/src/main/kotlin/pl/treksoft/kvision/types/Decimal.kt b/src/main/kotlin/pl/treksoft/kvision/types/Decimal.kt deleted file mode 100644 index d1c0366e..00000000 --- a/src/main/kotlin/pl/treksoft/kvision/types/Decimal.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2017-present Robert Jaros - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package pl.treksoft.kvision.types - -actual typealias Decimal = Double diff --git a/src/main/kotlin/pl/treksoft/kvision/utils/JSON.kt b/src/main/kotlin/pl/treksoft/kvision/utils/JSON.kt index 8dd8a504..4d951028 100644 --- a/src/main/kotlin/pl/treksoft/kvision/utils/JSON.kt +++ b/src/main/kotlin/pl/treksoft/kvision/utils/JSON.kt @@ -38,14 +38,14 @@ object JSON { val plain = Json(context = serializersModuleOf(Date::class, DateSerializer)) val nonstrict = Json( - configuration = JsonConfiguration.Stable.copy(strictMode = false), + configuration = JsonConfiguration.Stable.copy(ignoreUnknownKeys = true), context = serializersModuleOf(Date::class, DateSerializer) ) /** * An extension function to convert Serializable object to JS dynamic object */ - @UseExperimental(ImplicitReflectionSerializer::class) + @OptIn(ImplicitReflectionSerializer::class) inline fun <reified T : Any> T.toObj(): dynamic { return this.toObj(T::class.serializer()) } |