diff --git a/build.gradle.kts b/build.gradle.kts index 3395cacc..f87fced4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,9 +1,10 @@ plugins { - val toolsVersion = "0.4.2" + val toolsVersion = "0.5.5" id("scientifik.mpp") version toolsVersion apply false id("scientifik.jvm") version toolsVersion apply false id("scientifik.publish") version toolsVersion apply false + id("org.jetbrains.dokka") version "0.10.1" } val dataforgeVersion by extra("0.1.8-dev-2") @@ -22,4 +23,5 @@ allprojects { subprojects { apply(plugin = "scientifik.publish") + apply(plugin = "org.jetbrains.dokka") } \ No newline at end of file diff --git a/dataforge-context/build.gradle.kts b/dataforge-context/build.gradle.kts index 261933fe..3c13042d 100644 --- a/dataforge-context/build.gradle.kts +++ b/dataforge-context/build.gradle.kts @@ -13,19 +13,19 @@ kotlin { val commonMain by getting { dependencies { api(project(":dataforge-meta")) - api("io.github.microutils:kotlin-logging-common:1.7.8") + api("io.github.microutils:kotlin-logging-common:1.7.9") } } val jvmMain by getting { dependencies { api(kotlin("reflect")) - api("io.github.microutils:kotlin-logging:1.7.8") + api("io.github.microutils:kotlin-logging:1.7.9") api("ch.qos.logback:logback-classic:1.2.3") } } val jsMain by getting { dependencies { - api("io.github.microutils:kotlin-logging-js:1.7.8") + api("io.github.microutils:kotlin-logging-js:1.7.9") } } } diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Configurable.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Configurable.kt index 884c1c26..a078c37f 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Configurable.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Configurable.kt @@ -50,6 +50,13 @@ interface Configurable : Described { } } +/** + * Reset the property to its default value + */ +fun Configurable.resetProperty(name: Name) { + setProperty(name, null) +} + fun Configurable.getProperty(key: String) = getProperty(key.toName()) fun Configurable.setProperty(name: Name, value: Value?) = setProperty(name, value?.let { MetaItem.ValueItem(value) }) diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/ConfigurableDelegate.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/ConfigurableDelegate.kt index 1999ced4..a94b3667 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/ConfigurableDelegate.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/ConfigurableDelegate.kt @@ -201,8 +201,8 @@ fun Configurable.doubleArray(vararg doubles: Double, key: Name? = null): ReadWri /* Node delegates */ -fun Configurable.config(key: Name? = null): ReadWriteProperty = - config.node(key) +fun Configurable.config(default: Config? = null, key: Name? = null): ReadWriteProperty = + config.node(default,key) fun Configurable.node(key: Name? = null): ReadWriteProperty = item(key).map( reader = { it.node }, diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MutableMetaDelegate.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MutableMetaDelegate.kt index 39a022f4..3230afbe 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MutableMetaDelegate.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MutableMetaDelegate.kt @@ -84,8 +84,8 @@ fun > M.boolean(default: Boolean? = null, key: Name? = null): fun > M.number(default: Number? = null, key: Name? = null): ReadWriteProperty = item(default, key).transform { it.number } -inline fun > M.node(key: Name? = null) = - item(this, key).transform { it.node as? M } +inline fun > M.node(default: M? = null, key: Name? = null) = + item(default, key = key).transform { it.node as? M } @JvmName("safeString") fun > M.string(default: String, key: Name? = null) = diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/descriptors/ItemDescriptor.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/descriptors/ItemDescriptor.kt index a551b313..7f748ff2 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/descriptors/ItemDescriptor.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/descriptors/ItemDescriptor.kt @@ -47,10 +47,20 @@ fun ItemDescriptor.attributes(block: Config.() -> Unit) { (attributes ?: Config().also { this.attributes = it }).apply(block) } +/** + * Set specific attribute in the descriptor + */ +fun ItemDescriptor.setAttribute(name: Name, value: Any?) { + attributes { + set(name, value) + } +} + /** * Check if given item suits the descriptor */ fun ItemDescriptor.validateItem(item: MetaItem<*>?): Boolean { + if (item == null) return !required return when (this) { is ValueDescriptor -> isAllowedValue(item.value ?: return false) is NodeDescriptor -> items.all { (key, d) ->