Fix indexed meta to json transformation

This commit is contained in:
Alexander Nozik 2021-06-20 10:29:37 +03:00
parent bc9cd3b5a8
commit 9d3c7149b7
5 changed files with 16 additions and 9 deletions

View File

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

View File

@ -4,7 +4,7 @@ plugins {
allprojects {
group = "space.kscience"
version = "0.4.2"
version = "0.4.3"
}
subprojects {

View File

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

View File

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

View File

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