diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f981e24..7dc1eeaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,14 +5,16 @@ - Experimental `listOfSpec` delegate. ### Changed -- **API breaking** Descriptor no has a member property `defaultValue` instead of `defaultItem()` extension. It cahces default value state on the first call. It is done because computing default on each call is too expensive. +- **API breaking** Descriptor no has a member property `defaultValue` instead of `defaultItem()` extension. It caches default value state on the first call. It is done because computing default on each call is too expensive. - Kotlin 1.5.10 +- Build tools 0.10.0 ### Deprecated ### Removed ### Fixed +- Proper json array index treatment ### Security ## [0.4.0] diff --git a/build.gradle.kts b/build.gradle.kts index 8a37909d..c4293377 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { allprojects { group = "space.kscience" - version = "0.4.2" + version = "0.4.3" } subprojects { diff --git a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/JsonMeta.kt b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/JsonMeta.kt index 3e708314..0929a188 100644 --- a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/JsonMeta.kt +++ b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/JsonMeta.kt @@ -55,7 +55,16 @@ private fun Meta.toJsonWithIndex(descriptor: NodeDescriptor?, indexValue: String //do nothing } 1 -> { - elementMap[jsonKey] = items.values.first().toJsonElement(itemDescriptor, null) + val (index, item) = items.entries.first() + val element = item.toJsonElement(itemDescriptor, null) + if (index == null) { + elementMap[jsonKey] = element + } else { + //treat arrays with single element + elementMap[jsonKey] = buildJsonArray { + add(element) + } + } } else -> { val array = buildJsonArray { diff --git a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/MutableItemProvider.kt b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/MutableItemProvider.kt index cb901c40..97b1af0f 100644 --- a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/MutableItemProvider.kt +++ b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/MutableItemProvider.kt @@ -53,7 +53,7 @@ public fun MutableItemProvider.setIndexedItems( val tokens = name.tokens.toMutableList() val last = tokens.last() items.forEachIndexed { index, meta -> - val indexedToken = NameToken(last.body, last.index + indexFactory(meta, index)) + val indexedToken = NameToken(last.body, (last.index ?: "") + indexFactory(meta, index)) tokens[tokens.lastIndex] = indexedToken set(Name(tokens), meta) } @@ -97,7 +97,6 @@ public fun MutableItemProvider.getChild(childName: Name): MutableItemProvider { public fun MutableItemProvider.getChild(childName: String): MutableItemProvider = getChild(childName.toName()) - /** * Update existing mutable node with another node. The rules are following: * * value replaces anything diff --git a/settings.gradle.kts b/settings.gradle.kts index 7040baaf..0a7bdf3d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,16 +5,13 @@ pluginManagement { gradlePluginPortal() } - val toolsVersion = "0.9.10" - val kotlinVersion = "1.5.10" + val toolsVersion = "0.10.0" plugins { id("ru.mipt.npm.gradle.project") version toolsVersion id("ru.mipt.npm.gradle.mpp") version toolsVersion id("ru.mipt.npm.gradle.jvm") version toolsVersion id("ru.mipt.npm.gradle.js") version toolsVersion - kotlin("jvm") version kotlinVersion - kotlin("js") version kotlinVersion } }