Compare commits
No commits in common. "c62dc2c698ad802e38542c2490f9996d4944ae9f" and "2cd18854209cdf332e14581fa7c2cf7145dcf25c" have entirely different histories.
c62dc2c698
...
2cd1885420
16
CHANGELOG.md
16
CHANGELOG.md
@ -14,22 +14,6 @@
|
||||
|
||||
### Security
|
||||
|
||||
## 0.9.0 - 2024-06-04
|
||||
|
||||
### Added
|
||||
|
||||
- Custom CoroutineContext during `Context` creation.
|
||||
|
||||
### Changed
|
||||
|
||||
- Kotlin 2.0
|
||||
- `MetaSpec` renamed to `MetaReader`. MetaSpec is now reserved for builder-based generation of meta descriptors.
|
||||
- Add self-type for Meta. Remove unsafe cast method for meta instances.
|
||||
|
||||
### Removed
|
||||
|
||||
- Automatic descriptors for schema. It is not possible to implement them without heavy reflection.
|
||||
|
||||
## 0.8.2 - 2024-04-27
|
||||
|
||||
### Added
|
||||
|
@ -3,21 +3,21 @@ import space.kscience.gradle.useApache2Licence
|
||||
import space.kscience.gradle.useSPCTeam
|
||||
|
||||
plugins {
|
||||
alias(spclibs.plugins.kscience.project)
|
||||
alias(spclibs.plugins.kotlinx.kover)
|
||||
id("space.kscience.gradle.project")
|
||||
id("org.jetbrains.kotlinx.kover") version "0.7.6"
|
||||
}
|
||||
|
||||
allprojects {
|
||||
group = "space.kscience"
|
||||
version = "0.9.0"
|
||||
version = "0.8.2"
|
||||
}
|
||||
|
||||
subprojects {
|
||||
apply(plugin = "maven-publish")
|
||||
|
||||
tasks.withType<KotlinCompile> {
|
||||
compilerOptions {
|
||||
freeCompilerArgs.add("-Xcontext-receivers")
|
||||
kotlinOptions {
|
||||
freeCompilerArgs = freeCompilerArgs + "-Xcontext-receivers"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ Context and provider definitions
|
||||
|
||||
## Artifact:
|
||||
|
||||
The Maven coordinates of this project are `space.kscience:dataforge-context:0.9.0-dev-1`.
|
||||
The Maven coordinates of this project are `space.kscience:dataforge-context:0.8.2`.
|
||||
|
||||
**Gradle Kotlin DSL:**
|
||||
```kotlin
|
||||
@ -16,6 +16,6 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("space.kscience:dataforge-context:0.9.0-dev-1")
|
||||
implementation("space.kscience:dataforge-context:0.8.2")
|
||||
}
|
||||
```
|
||||
|
@ -57,7 +57,6 @@ public abstract interface class space/kscience/dataforge/context/ContextAware {
|
||||
|
||||
public final class space/kscience/dataforge/context/ContextBuilder {
|
||||
public final fun build ()Lspace/kscience/dataforge/context/Context;
|
||||
public final fun coroutineContext (Lkotlin/coroutines/CoroutineContext;)V
|
||||
public final fun getName ()Lspace/kscience/dataforge/names/Name;
|
||||
public final fun plugin (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
|
||||
public final fun plugin (Lspace/kscience/dataforge/context/Plugin;)V
|
||||
@ -70,6 +69,9 @@ public final class space/kscience/dataforge/context/ContextBuilder {
|
||||
public final fun properties (Lkotlin/jvm/functions/Function1;)V
|
||||
}
|
||||
|
||||
public final class space/kscience/dataforge/context/ContextBuilderKt {
|
||||
}
|
||||
|
||||
public final class space/kscience/dataforge/context/DefaultLogManager : space/kscience/dataforge/context/AbstractPlugin, space/kscience/dataforge/context/LogManager {
|
||||
public static final field Companion Lspace/kscience/dataforge/context/DefaultLogManager$Companion;
|
||||
public fun <init> ()V
|
||||
@ -210,14 +212,14 @@ public final class space/kscience/dataforge/context/PluginTag : space/kscience/d
|
||||
public fun toString ()Ljava/lang/String;
|
||||
}
|
||||
|
||||
public synthetic class space/kscience/dataforge/context/PluginTag$$serializer : kotlinx/serialization/internal/GeneratedSerializer {
|
||||
public final class space/kscience/dataforge/context/PluginTag$$serializer : kotlinx/serialization/internal/GeneratedSerializer {
|
||||
public static final field INSTANCE Lspace/kscience/dataforge/context/PluginTag$$serializer;
|
||||
public final fun childSerializers ()[Lkotlinx/serialization/KSerializer;
|
||||
public fun childSerializers ()[Lkotlinx/serialization/KSerializer;
|
||||
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
|
||||
public final fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lspace/kscience/dataforge/context/PluginTag;
|
||||
public final fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
|
||||
public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lspace/kscience/dataforge/context/PluginTag;
|
||||
public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
|
||||
public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V
|
||||
public final fun serialize (Lkotlinx/serialization/encoding/Encoder;Lspace/kscience/dataforge/context/PluginTag;)V
|
||||
public fun serialize (Lkotlinx/serialization/encoding/Encoder;Lspace/kscience/dataforge/context/PluginTag;)V
|
||||
public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer;
|
||||
}
|
||||
|
||||
@ -262,6 +264,15 @@ public abstract interface annotation class space/kscience/dataforge/descriptors/
|
||||
public abstract interface annotation class space/kscience/dataforge/descriptors/Multiple : java/lang/annotation/Annotation {
|
||||
}
|
||||
|
||||
public final class space/kscience/dataforge/descriptors/ReflectiveDescriptorsKt {
|
||||
}
|
||||
|
||||
public final class space/kscience/dataforge/properties/MetaAsFlowKt {
|
||||
}
|
||||
|
||||
public final class space/kscience/dataforge/provider/DfTypeKt {
|
||||
}
|
||||
|
||||
public final class space/kscience/dataforge/provider/Path : java/lang/Iterable, kotlin/jvm/internal/markers/KMappedMarker {
|
||||
public static final field Companion Lspace/kscience/dataforge/provider/Path$Companion;
|
||||
public static final field PATH_SEGMENT_SEPARATOR Ljava/lang/String;
|
||||
|
@ -10,7 +10,6 @@ import space.kscience.dataforge.misc.ThreadSafe
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.provider.Provider
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlin.coroutines.EmptyCoroutineContext
|
||||
|
||||
/**
|
||||
* The local environment for anything being done in DataForge framework. Contexts are organized into tree structure with [Global] at the top.
|
||||
@ -27,7 +26,6 @@ public open class Context internal constructor(
|
||||
public val parent: Context?,
|
||||
plugins: Set<Plugin>, // set of unattached plugins
|
||||
meta: Meta,
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
) : Named, MetaRepr, Provider, CoroutineScope {
|
||||
|
||||
/**
|
||||
@ -67,7 +65,7 @@ public open class Context internal constructor(
|
||||
|
||||
override val coroutineContext: CoroutineContext by lazy {
|
||||
(parent ?: Global).coroutineContext.let { parenContext ->
|
||||
parenContext + coroutineContext + SupervisorJob(parenContext[Job])
|
||||
parenContext + SupervisorJob(parenContext[Job])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,8 +13,6 @@ import space.kscience.dataforge.names.plus
|
||||
import kotlin.collections.component1
|
||||
import kotlin.collections.component2
|
||||
import kotlin.collections.set
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlin.coroutines.EmptyCoroutineContext
|
||||
|
||||
/**
|
||||
* A convenience builder for context
|
||||
@ -61,15 +59,8 @@ public class ContextBuilder internal constructor(
|
||||
plugin(DeFactoPluginFactory(plugin))
|
||||
}
|
||||
|
||||
private var coroutineContext: CoroutineContext = EmptyCoroutineContext
|
||||
|
||||
public fun coroutineContext(coroutineContext: CoroutineContext) {
|
||||
this.coroutineContext = coroutineContext
|
||||
}
|
||||
|
||||
|
||||
public fun build(): Context {
|
||||
val contextName = name ?: NameToken("@auto", hashCode().toUInt().toString(16)).asName()
|
||||
val contextName = name ?: NameToken("@auto",hashCode().toUInt().toString(16)).asName()
|
||||
val plugins = HashMap<PluginTag, Plugin>()
|
||||
|
||||
fun addPlugin(factory: PluginFactory<*>, meta: Meta) {
|
||||
@ -95,7 +86,7 @@ public class ContextBuilder internal constructor(
|
||||
addPlugin(factory, meta)
|
||||
}
|
||||
|
||||
return Context(contextName, parent, plugins.values.toSet(), meta.seal(), coroutineContext)
|
||||
return Context(contextName, parent, plugins.values.toSet(), meta.seal())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ import space.kscience.dataforge.meta.*
|
||||
import space.kscience.dataforge.misc.DFExperimental
|
||||
|
||||
@DFExperimental
|
||||
public fun <T> ObservableMeta.asFlow(converter: MetaReader<T>): Flow<T> = callbackFlow {
|
||||
public fun <T> ObservableMeta.asFlow(converter: MetaSpec<T>): Flow<T> = callbackFlow {
|
||||
onChange(this){
|
||||
trySend(converter.read(this))
|
||||
}
|
||||
|
@ -4,12 +4,18 @@ import kotlinx.serialization.ExperimentalSerializationApi
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.decodeFromStream
|
||||
import org.slf4j.LoggerFactory
|
||||
import space.kscience.dataforge.meta.Scheme
|
||||
import space.kscience.dataforge.meta.SchemeSpec
|
||||
import space.kscience.dataforge.meta.ValueType
|
||||
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
|
||||
import space.kscience.dataforge.meta.descriptors.MetaDescriptorBuilder
|
||||
import space.kscience.dataforge.meta.descriptors.node
|
||||
import space.kscience.dataforge.misc.DFExperimental
|
||||
import java.net.URL
|
||||
import kotlin.reflect.KAnnotatedElement
|
||||
import kotlin.reflect.KProperty
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.full.isSubclassOf
|
||||
import kotlin.reflect.full.memberProperties
|
||||
|
||||
|
||||
/**
|
||||
* Description text for meta property, node or whole object
|
||||
@ -53,8 +59,18 @@ private fun MetaDescriptorBuilder.loadDescriptorFromResource(resource: Descripto
|
||||
}
|
||||
|
||||
@DFExperimental
|
||||
public fun MetaDescriptorBuilder.forAnnotatedElement(element: KAnnotatedElement) {
|
||||
element.annotations.forEach {
|
||||
public fun MetaDescriptor.Companion.forClass(
|
||||
kClass: KClass<out Any>,
|
||||
mod: MetaDescriptorBuilder.() -> Unit = {},
|
||||
): MetaDescriptor = MetaDescriptor {
|
||||
when {
|
||||
kClass.isSubclassOf(Number::class) -> valueType(ValueType.NUMBER)
|
||||
kClass == String::class -> ValueType.STRING
|
||||
kClass == Boolean::class -> ValueType.BOOLEAN
|
||||
kClass == DoubleArray::class -> ValueType.LIST
|
||||
}
|
||||
|
||||
kClass.annotations.forEach {
|
||||
when (it) {
|
||||
is Description -> description = it.value
|
||||
|
||||
@ -63,70 +79,47 @@ public fun MetaDescriptorBuilder.forAnnotatedElement(element: KAnnotatedElement)
|
||||
is DescriptorUrl -> loadDescriptorFromUrl(URL(it.url))
|
||||
}
|
||||
}
|
||||
kClass.memberProperties.forEach { property ->
|
||||
|
||||
var flag = false
|
||||
|
||||
val descriptor = MetaDescriptor {
|
||||
//use base type descriptor as a base
|
||||
(property.returnType.classifier as? KClass<*>)?.let {
|
||||
from(forClass(it))
|
||||
}
|
||||
|
||||
property.annotations.forEach {
|
||||
when (it) {
|
||||
is Description -> {
|
||||
description = it.value
|
||||
flag = true
|
||||
}
|
||||
|
||||
is Multiple -> {
|
||||
multiple = true
|
||||
flag = true
|
||||
}
|
||||
|
||||
is DescriptorResource -> {
|
||||
loadDescriptorFromResource(it)
|
||||
flag = true
|
||||
}
|
||||
|
||||
is DescriptorUrl -> {
|
||||
loadDescriptorFromUrl(URL(it.url))
|
||||
flag = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
node(property.name, descriptor)
|
||||
}
|
||||
}
|
||||
mod()
|
||||
}
|
||||
|
||||
@DFExperimental
|
||||
public fun MetaDescriptorBuilder.forProperty(property: KProperty<*>) {
|
||||
property.annotations.forEach {
|
||||
when (it) {
|
||||
is Description -> description = it.value
|
||||
|
||||
is DescriptorResource -> loadDescriptorFromResource(it)
|
||||
|
||||
is DescriptorUrl -> loadDescriptorFromUrl(URL(it.url))
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
//@DFExperimental
|
||||
//public fun <T : Scheme> MetaDescriptor.Companion.forScheme(
|
||||
// spec: SchemeSpec<T>,
|
||||
// mod: MetaDescriptorBuilder.() -> Unit = {},
|
||||
//): MetaDescriptor = MetaDescriptor {
|
||||
// val scheme = spec.empty()
|
||||
// val kClass: KClass<T> = scheme::class as KClass<T>
|
||||
// when {
|
||||
// kClass.isSubclassOf(Number::class) -> valueType(ValueType.NUMBER)
|
||||
// kClass == String::class -> ValueType.STRING
|
||||
// kClass == Boolean::class -> ValueType.BOOLEAN
|
||||
// kClass == DoubleArray::class -> ValueType.LIST
|
||||
// kClass == ByteArray::class -> ValueType.LIST
|
||||
// }
|
||||
//
|
||||
// forAnnotatedElement(kClass)
|
||||
// kClass.memberProperties.forEach { property ->
|
||||
// node(property.name) {
|
||||
//
|
||||
// (property.getDelegate(scheme) as? MetaDelegate<*>)?.descriptor?.let {
|
||||
// from(it)
|
||||
// }
|
||||
//
|
||||
// property.annotations.forEach {
|
||||
// when (it) {
|
||||
// is Description -> {
|
||||
// description = it.value
|
||||
// }
|
||||
//
|
||||
// is Multiple -> {
|
||||
// multiple = true
|
||||
// }
|
||||
//
|
||||
// is DescriptorResource -> {
|
||||
// loadDescriptorFromResource(it)
|
||||
// }
|
||||
//
|
||||
// is DescriptorUrl -> {
|
||||
// loadDescriptorFromUrl(URL(it.url))
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// mod()
|
||||
//}
|
||||
//
|
||||
//@DFExperimental
|
||||
//public inline fun <reified T : Scheme> SchemeSpec<T>.autoDescriptor(
|
||||
// noinline mod: MetaDescriptorBuilder.() -> Unit = {},
|
||||
//): MetaDescriptor = MetaDescriptor.forScheme(this, mod)
|
||||
public inline fun <reified T : Scheme> SchemeSpec<T>.autoDescriptor(noinline mod: MetaDescriptorBuilder.() -> Unit = {}): MetaDescriptor =
|
||||
MetaDescriptor.forClass(T::class, mod)
|
@ -2,28 +2,35 @@
|
||||
|
||||
package space.kscience.dataforge.descriptors
|
||||
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.junit.jupiter.api.Test
|
||||
import space.kscience.dataforge.meta.Scheme
|
||||
import space.kscience.dataforge.meta.SchemeSpec
|
||||
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
|
||||
import space.kscience.dataforge.meta.int
|
||||
import space.kscience.dataforge.meta.string
|
||||
import space.kscience.dataforge.misc.DFExperimental
|
||||
|
||||
//
|
||||
//class TestScheme : Scheme() {
|
||||
//
|
||||
// @Description("A")
|
||||
// val a by string()
|
||||
//
|
||||
// @Description("B")
|
||||
// val b by int()
|
||||
//
|
||||
// val c by int()
|
||||
//
|
||||
// companion object : SchemeSpec<TestScheme>(::TestScheme) {
|
||||
// override val descriptor: MetaDescriptor = autoDescriptor()
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//class TestAutoDescriptors {
|
||||
// @Test
|
||||
// fun autoDescriptor() {
|
||||
// val autoDescriptor = MetaDescriptor.forScheme(TestScheme)
|
||||
// println(Json { prettyPrint = true }.encodeToString(autoDescriptor))
|
||||
// }
|
||||
//}
|
||||
private class TestScheme : Scheme() {
|
||||
|
||||
@Description("A")
|
||||
val a by string()
|
||||
|
||||
@Description("B")
|
||||
val b by int()
|
||||
|
||||
val c by int()
|
||||
|
||||
companion object : SchemeSpec<TestScheme>(::TestScheme) {
|
||||
override val descriptor: MetaDescriptor = autoDescriptor()
|
||||
}
|
||||
}
|
||||
|
||||
class TestAutoDescriptors {
|
||||
@Test
|
||||
fun autoDescriptor() {
|
||||
val autoDescriptor = MetaDescriptor.forClass(TestScheme::class)
|
||||
println(Json { prettyPrint = true }.encodeToString(autoDescriptor))
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
|
||||
## Artifact:
|
||||
|
||||
The Maven coordinates of this project are `space.kscience:dataforge-data:0.9.0-dev-1`.
|
||||
The Maven coordinates of this project are `space.kscience:dataforge-data:0.8.2`.
|
||||
|
||||
**Gradle Kotlin DSL:**
|
||||
```kotlin
|
||||
@ -16,6 +16,6 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("space.kscience:dataforge-data:0.9.0-dev-1")
|
||||
implementation("space.kscience:dataforge-data:0.8.2")
|
||||
}
|
||||
```
|
||||
|
@ -18,24 +18,6 @@ public data class NamedValueWithMeta<T>(val name: Name, val value: T, val meta:
|
||||
public suspend fun <T> NamedData<T>.awaitWithMeta(): NamedValueWithMeta<T> =
|
||||
NamedValueWithMeta(name, await(), meta)
|
||||
|
||||
/**
|
||||
* Lazily transform this data to another data. By convention [block] should not use external data (be pure).
|
||||
* @param type explicit type of the resulting [Data]
|
||||
* @param coroutineContext additional [CoroutineContext] elements used for data computation.
|
||||
* @param meta for the resulting data. By default equals input data.
|
||||
* @param block the transformation itself
|
||||
*/
|
||||
@UnsafeKType
|
||||
public fun <T, R> Data<T>.transform(
|
||||
type: KType,
|
||||
meta: Meta = this.meta,
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
block: suspend (T) -> R,
|
||||
): Data<R> = Data(type, meta, coroutineContext, listOf(this)) {
|
||||
block(await())
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Lazily transform this data to another data. By convention [block] should not use external data (be pure).
|
||||
|
@ -43,7 +43,6 @@ internal class ActionsTest {
|
||||
repeat(10) {
|
||||
source.updateValue(it.toString(), it)
|
||||
}
|
||||
|
||||
result.updates.take(10).onEach { println(it.name) }.collect()
|
||||
|
||||
assertEquals(2, result["1"]?.await())
|
||||
|
@ -6,7 +6,7 @@ IO module
|
||||
|
||||
## Artifact:
|
||||
|
||||
The Maven coordinates of this project are `space.kscience:dataforge-io:0.9.0-dev-1`.
|
||||
The Maven coordinates of this project are `space.kscience:dataforge-io:0.8.2`.
|
||||
|
||||
**Gradle Kotlin DSL:**
|
||||
```kotlin
|
||||
@ -16,6 +16,6 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("space.kscience:dataforge-io:0.9.0-dev-1")
|
||||
implementation("space.kscience:dataforge-io:0.8.2")
|
||||
}
|
||||
```
|
||||
|
@ -6,7 +6,7 @@ YAML meta IO
|
||||
|
||||
## Artifact:
|
||||
|
||||
The Maven coordinates of this project are `space.kscience:dataforge-io-yaml:0.9.0-dev-1`.
|
||||
The Maven coordinates of this project are `space.kscience:dataforge-io-yaml:0.8.2`.
|
||||
|
||||
**Gradle Kotlin DSL:**
|
||||
```kotlin
|
||||
@ -16,6 +16,6 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("space.kscience:dataforge-io-yaml:0.9.0-dev-1")
|
||||
implementation("space.kscience:dataforge-io-yaml:0.8.2")
|
||||
}
|
||||
```
|
||||
|
@ -6,7 +6,7 @@ Meta definition and basic operations on meta
|
||||
|
||||
## Artifact:
|
||||
|
||||
The Maven coordinates of this project are `space.kscience:dataforge-meta:0.9.0-dev-1`.
|
||||
The Maven coordinates of this project are `space.kscience:dataforge-meta:0.8.2`.
|
||||
|
||||
**Gradle Kotlin DSL:**
|
||||
```kotlin
|
||||
@ -16,6 +16,6 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("space.kscience:dataforge-meta:0.9.0-dev-1")
|
||||
implementation("space.kscience:dataforge-meta:0.8.2")
|
||||
}
|
||||
```
|
||||
|
@ -103,8 +103,6 @@ public final class space/kscience/dataforge/meta/Laminate : space/kscience/dataf
|
||||
public synthetic fun get (Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/TypedMeta;
|
||||
public fun getItems ()Ljava/util/Map;
|
||||
public final fun getLayers ()Ljava/util/List;
|
||||
public fun getSelf ()Lspace/kscience/dataforge/meta/Laminate;
|
||||
public synthetic fun getSelf ()Lspace/kscience/dataforge/meta/TypedMeta;
|
||||
public fun getValue ()Lspace/kscience/dataforge/meta/Value;
|
||||
public fun hashCode ()I
|
||||
public final fun merge ()Lspace/kscience/dataforge/meta/SealedMeta;
|
||||
@ -200,7 +198,7 @@ public final class space/kscience/dataforge/meta/MetaBuilder : space/kscience/da
|
||||
public abstract interface annotation class space/kscience/dataforge/meta/MetaBuilderMarker : java/lang/annotation/Annotation {
|
||||
}
|
||||
|
||||
public abstract interface class space/kscience/dataforge/meta/MetaConverter : space/kscience/dataforge/meta/MetaReader {
|
||||
public abstract interface class space/kscience/dataforge/meta/MetaConverter : space/kscience/dataforge/meta/MetaSpec {
|
||||
public static final field Companion Lspace/kscience/dataforge/meta/MetaConverter$Companion;
|
||||
public abstract fun convert (Ljava/lang/Object;)Lspace/kscience/dataforge/meta/Meta;
|
||||
public fun getDescriptor ()Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor;
|
||||
@ -248,15 +246,15 @@ public final class space/kscience/dataforge/meta/MetaDelegateKt {
|
||||
public static final fun int (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun int$default (Lspace/kscience/dataforge/meta/MetaProvider;ILspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun int$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun listOfSpec (Lspace/kscience/dataforge/meta/Meta;Lspace/kscience/dataforge/meta/MetaReader;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun listOfSpec$default (Lspace/kscience/dataforge/meta/Meta;Lspace/kscience/dataforge/meta/MetaReader;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun listOfSpec (Lspace/kscience/dataforge/meta/Meta;Lspace/kscience/dataforge/meta/MetaSpec;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun listOfSpec$default (Lspace/kscience/dataforge/meta/Meta;Lspace/kscience/dataforge/meta/MetaSpec;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun long (Lspace/kscience/dataforge/meta/MetaProvider;JLspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun long (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun long$default (Lspace/kscience/dataforge/meta/MetaProvider;JLspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun long$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun node (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lspace/kscience/dataforge/meta/MetaReader;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static final fun node (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lspace/kscience/dataforge/meta/MetaSpec;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static final fun node (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun node$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lspace/kscience/dataforge/meta/MetaReader;ILjava/lang/Object;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static synthetic fun node$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lspace/kscience/dataforge/meta/MetaSpec;ILjava/lang/Object;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static synthetic fun node$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun number (Lspace/kscience/dataforge/meta/MetaProvider;Ljava/lang/Number;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun number (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
@ -264,8 +262,8 @@ public final class space/kscience/dataforge/meta/MetaDelegateKt {
|
||||
public static synthetic fun number$default (Lspace/kscience/dataforge/meta/MetaProvider;Ljava/lang/Number;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun number$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun number$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun spec (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/meta/MetaReader;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun spec$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/meta/MetaReader;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun spec (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/meta/MetaSpec;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun spec$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/meta/MetaSpec;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun string (Lspace/kscience/dataforge/meta/MetaProvider;Ljava/lang/String;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun string (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun string (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function0;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
@ -296,6 +294,7 @@ public final class space/kscience/dataforge/meta/MetaKt {
|
||||
public static final fun getLong (Lspace/kscience/dataforge/meta/Meta;)Ljava/lang/Long;
|
||||
public static final synthetic fun getNonNullable (Lspace/kscience/dataforge/meta/Meta;Lspace/kscience/dataforge/names/NameToken;)Lspace/kscience/dataforge/meta/Meta;
|
||||
public static final fun getNumber (Lspace/kscience/dataforge/meta/Meta;)Ljava/lang/Number;
|
||||
public static final fun getSelf (Lspace/kscience/dataforge/meta/TypedMeta;)Lspace/kscience/dataforge/meta/TypedMeta;
|
||||
public static final fun getShort (Lspace/kscience/dataforge/meta/Meta;)Ljava/lang/Short;
|
||||
public static final fun getString (Lspace/kscience/dataforge/meta/Meta;)Ljava/lang/String;
|
||||
public static final fun getStringList (Lspace/kscience/dataforge/meta/Meta;)Ljava/util/List;
|
||||
@ -312,16 +311,6 @@ public abstract interface class space/kscience/dataforge/meta/MetaProvider : spa
|
||||
public fun getValue (Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/Value;
|
||||
}
|
||||
|
||||
public abstract interface class space/kscience/dataforge/meta/MetaReader : space/kscience/dataforge/meta/descriptors/Described {
|
||||
public fun read (Lspace/kscience/dataforge/meta/Meta;)Ljava/lang/Object;
|
||||
public abstract fun readOrNull (Lspace/kscience/dataforge/meta/Meta;)Ljava/lang/Object;
|
||||
}
|
||||
|
||||
public final class space/kscience/dataforge/meta/MetaReaderKt {
|
||||
public static final fun readNullable (Lspace/kscience/dataforge/meta/MetaReader;Lspace/kscience/dataforge/meta/Meta;)Ljava/lang/Object;
|
||||
public static final fun readValue (Lspace/kscience/dataforge/meta/MetaReader;Lspace/kscience/dataforge/meta/Value;)Ljava/lang/Object;
|
||||
}
|
||||
|
||||
public abstract interface class space/kscience/dataforge/meta/MetaRepr {
|
||||
public abstract fun toMeta ()Lspace/kscience/dataforge/meta/Meta;
|
||||
}
|
||||
@ -335,6 +324,16 @@ public final class space/kscience/dataforge/meta/MetaSerializer : kotlinx/serial
|
||||
public fun serialize (Lkotlinx/serialization/encoding/Encoder;Lspace/kscience/dataforge/meta/Meta;)V
|
||||
}
|
||||
|
||||
public abstract interface class space/kscience/dataforge/meta/MetaSpec : space/kscience/dataforge/meta/descriptors/Described {
|
||||
public fun read (Lspace/kscience/dataforge/meta/Meta;)Ljava/lang/Object;
|
||||
public abstract fun readOrNull (Lspace/kscience/dataforge/meta/Meta;)Ljava/lang/Object;
|
||||
}
|
||||
|
||||
public final class space/kscience/dataforge/meta/MetaSpecKt {
|
||||
public static final fun readNullable (Lspace/kscience/dataforge/meta/MetaSpec;Lspace/kscience/dataforge/meta/Meta;)Ljava/lang/Object;
|
||||
public static final fun readValue (Lspace/kscience/dataforge/meta/MetaSpec;Lspace/kscience/dataforge/meta/Value;)Ljava/lang/Object;
|
||||
}
|
||||
|
||||
public final class space/kscience/dataforge/meta/MetaTransformation {
|
||||
public static final field Companion Lspace/kscience/dataforge/meta/MetaTransformation$Companion;
|
||||
public static final fun apply-impl (Ljava/util/Collection;Lspace/kscience/dataforge/meta/Meta;)Lspace/kscience/dataforge/meta/Meta;
|
||||
@ -552,8 +551,6 @@ public abstract interface class space/kscience/dataforge/meta/ObservableMutableM
|
||||
public fun get (Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/ObservableMutableMeta;
|
||||
public synthetic fun get (Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/TypedMeta;
|
||||
public abstract fun getOrCreate (Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/ObservableMutableMeta;
|
||||
public fun getSelf ()Lspace/kscience/dataforge/meta/ObservableMutableMeta;
|
||||
public synthetic fun getSelf ()Lspace/kscience/dataforge/meta/TypedMeta;
|
||||
}
|
||||
|
||||
public final class space/kscience/dataforge/meta/RegexItemTransformationRule : space/kscience/dataforge/meta/TransformationRule {
|
||||
@ -627,21 +624,19 @@ public final class space/kscience/dataforge/meta/SealedMeta : space/kscience/dat
|
||||
public fun <init> (Lspace/kscience/dataforge/meta/Value;Ljava/util/Map;)V
|
||||
public fun equals (Ljava/lang/Object;)Z
|
||||
public fun getItems ()Ljava/util/Map;
|
||||
public fun getSelf ()Lspace/kscience/dataforge/meta/SealedMeta;
|
||||
public synthetic fun getSelf ()Lspace/kscience/dataforge/meta/TypedMeta;
|
||||
public fun getValue ()Lspace/kscience/dataforge/meta/Value;
|
||||
public fun hashCode ()I
|
||||
public fun toString ()Ljava/lang/String;
|
||||
}
|
||||
|
||||
public synthetic class space/kscience/dataforge/meta/SealedMeta$$serializer : kotlinx/serialization/internal/GeneratedSerializer {
|
||||
public final class space/kscience/dataforge/meta/SealedMeta$$serializer : kotlinx/serialization/internal/GeneratedSerializer {
|
||||
public static final field INSTANCE Lspace/kscience/dataforge/meta/SealedMeta$$serializer;
|
||||
public final fun childSerializers ()[Lkotlinx/serialization/KSerializer;
|
||||
public fun childSerializers ()[Lkotlinx/serialization/KSerializer;
|
||||
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
|
||||
public final fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lspace/kscience/dataforge/meta/SealedMeta;
|
||||
public final fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
|
||||
public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lspace/kscience/dataforge/meta/SealedMeta;
|
||||
public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
|
||||
public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V
|
||||
public final fun serialize (Lkotlinx/serialization/encoding/Encoder;Lspace/kscience/dataforge/meta/SealedMeta;)V
|
||||
public fun serialize (Lkotlinx/serialization/encoding/Encoder;Lspace/kscience/dataforge/meta/SealedMeta;)V
|
||||
public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer;
|
||||
}
|
||||
|
||||
@ -715,7 +710,6 @@ public abstract interface class space/kscience/dataforge/meta/TypedMeta : space/
|
||||
public synthetic fun get (Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/Meta;
|
||||
public fun get (Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/TypedMeta;
|
||||
public abstract fun getItems ()Ljava/util/Map;
|
||||
public abstract fun getSelf ()Lspace/kscience/dataforge/meta/TypedMeta;
|
||||
public fun toMeta ()Lspace/kscience/dataforge/meta/Meta;
|
||||
}
|
||||
|
||||
@ -850,14 +844,14 @@ public final class space/kscience/dataforge/meta/descriptors/MetaDescriptor {
|
||||
public fun toString ()Ljava/lang/String;
|
||||
}
|
||||
|
||||
public synthetic class space/kscience/dataforge/meta/descriptors/MetaDescriptor$$serializer : kotlinx/serialization/internal/GeneratedSerializer {
|
||||
public final class space/kscience/dataforge/meta/descriptors/MetaDescriptor$$serializer : kotlinx/serialization/internal/GeneratedSerializer {
|
||||
public static final field INSTANCE Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor$$serializer;
|
||||
public final fun childSerializers ()[Lkotlinx/serialization/KSerializer;
|
||||
public fun childSerializers ()[Lkotlinx/serialization/KSerializer;
|
||||
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
|
||||
public final fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor;
|
||||
public final fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
|
||||
public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor;
|
||||
public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
|
||||
public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V
|
||||
public final fun serialize (Lkotlinx/serialization/encoding/Encoder;Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor;)V
|
||||
public fun serialize (Lkotlinx/serialization/encoding/Encoder;Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor;)V
|
||||
public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer;
|
||||
}
|
||||
|
||||
@ -882,7 +876,6 @@ public final class space/kscience/dataforge/meta/descriptors/MetaDescriptorBuild
|
||||
public final fun getMultiple ()Z
|
||||
public final fun getValueRestriction ()Lspace/kscience/dataforge/meta/descriptors/ValueRestriction;
|
||||
public final fun getValueTypes ()Ljava/util/List;
|
||||
public final fun node (Lspace/kscience/dataforge/names/Name;Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor;)V
|
||||
public final fun setAllowedValues (Ljava/util/List;)V
|
||||
public final fun setAttributes (Lspace/kscience/dataforge/meta/MutableMeta;)V
|
||||
public final fun setChildren (Ljava/util/Map;)V
|
||||
@ -934,6 +927,10 @@ public final class space/kscience/dataforge/meta/descriptors/ValueRestriction$Co
|
||||
public final fun serializer ()Lkotlinx/serialization/KSerializer;
|
||||
}
|
||||
|
||||
public final class space/kscience/dataforge/misc/CastJvmKt {
|
||||
public static final fun unsafeCast (Ljava/lang/Object;)Ljava/lang/Object;
|
||||
}
|
||||
|
||||
public abstract interface annotation class space/kscience/dataforge/misc/DFBuilder : java/lang/annotation/Annotation {
|
||||
}
|
||||
|
||||
|
@ -9,8 +9,6 @@ import space.kscience.dataforge.names.NameToken
|
||||
*/
|
||||
public class Laminate internal constructor(public val layers: List<Meta>) : TypedMeta<Laminate> {
|
||||
|
||||
override val self: Laminate get() = this
|
||||
|
||||
override val value: Value? = layers.firstNotNullOfOrNull { it.value }
|
||||
|
||||
override val items: Map<NameToken, Laminate> by lazy {
|
||||
|
@ -3,6 +3,7 @@ package space.kscience.dataforge.meta
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
import space.kscience.dataforge.misc.DfType
|
||||
import space.kscience.dataforge.misc.unsafeCast
|
||||
import space.kscience.dataforge.names.*
|
||||
import kotlin.jvm.JvmName
|
||||
|
||||
@ -150,8 +151,6 @@ public interface TypedMeta<out M : TypedMeta<M>> : Meta {
|
||||
|
||||
override val items: Map<NameToken, M>
|
||||
|
||||
public val self: M
|
||||
|
||||
override fun get(name: Name): M? {
|
||||
tailrec fun M.find(name: Name): M? = if (name.isEmpty()) {
|
||||
this
|
||||
@ -165,6 +164,11 @@ public interface TypedMeta<out M : TypedMeta<M>> : Meta {
|
||||
override fun toMeta(): Meta = this
|
||||
}
|
||||
|
||||
/**
|
||||
* Access self as a recursive type instance
|
||||
*/
|
||||
public inline val <M : TypedMeta<M>> TypedMeta<M>.self: M get() = unsafeCast()
|
||||
|
||||
//public typealias Meta = TypedMeta<*>
|
||||
|
||||
public operator fun <M : TypedMeta<M>> TypedMeta<M>?.get(token: NameToken): M? = this?.items?.get(token)
|
||||
|
@ -11,7 +11,7 @@ import space.kscience.dataforge.misc.DFExperimental
|
||||
/**
|
||||
* A converter of generic object to and from [Meta]
|
||||
*/
|
||||
public interface MetaConverter<T>: MetaReader<T> {
|
||||
public interface MetaConverter<T>: MetaSpec<T> {
|
||||
|
||||
/**
|
||||
* A descriptor for resulting meta
|
||||
|
@ -25,16 +25,16 @@ public fun MetaProvider.node(
|
||||
}
|
||||
|
||||
/**
|
||||
* Use [metaReader] to read the Meta node
|
||||
* Use [metaSpec] to read the Meta node
|
||||
*/
|
||||
public fun <T> MetaProvider.spec(
|
||||
metaReader: MetaReader<T>,
|
||||
metaSpec: MetaSpec<T>,
|
||||
key: Name? = null,
|
||||
): MetaDelegate<T?> = object : MetaDelegate<T?> {
|
||||
override val descriptor: MetaDescriptor? get() = metaReader.descriptor
|
||||
override val descriptor: MetaDescriptor? get() = metaSpec.descriptor
|
||||
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): T? {
|
||||
return get(key ?: property.name.asName())?.let { metaReader.read(it) }
|
||||
return get(key ?: property.name.asName())?.let { metaSpec.read(it) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,14 +50,14 @@ public inline fun <reified T> MetaProvider.serializable(
|
||||
@Deprecated("Use convertable", ReplaceWith("convertable(converter, key)"))
|
||||
public fun <T> MetaProvider.node(
|
||||
key: Name? = null,
|
||||
converter: MetaReader<T>,
|
||||
converter: MetaSpec<T>,
|
||||
): ReadOnlyProperty<Any?, T?> = spec(converter, key)
|
||||
|
||||
/**
|
||||
* Use [converter] to convert a list of same name siblings meta to object
|
||||
*/
|
||||
public fun <T> Meta.listOfSpec(
|
||||
converter: MetaReader<T>,
|
||||
converter: MetaSpec<T>,
|
||||
key: Name? = null,
|
||||
): MetaDelegate<List<T>> = object : MetaDelegate<List<T>> {
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): List<T> {
|
||||
|
@ -1,64 +0,0 @@
|
||||
package space.kscience.dataforge.meta
|
||||
|
||||
import space.kscience.dataforge.meta.descriptors.Described
|
||||
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
|
||||
import space.kscience.dataforge.meta.descriptors.MetaDescriptorBuilder
|
||||
import space.kscience.dataforge.misc.DFExperimental
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.names.asName
|
||||
import kotlin.properties.PropertyDelegateProvider
|
||||
import kotlin.properties.ReadOnlyProperty
|
||||
|
||||
|
||||
/**
|
||||
* A reference to a read-only value of type [T] inside [MetaProvider]
|
||||
*/
|
||||
@DFExperimental
|
||||
public data class MetaRef<T>(
|
||||
public val name: Name,
|
||||
public val converter: MetaConverter<T>,
|
||||
override val descriptor: MetaDescriptor? = converter.descriptor,
|
||||
) : Described
|
||||
|
||||
@DFExperimental
|
||||
public operator fun <T> MetaProvider.get(ref: MetaRef<T>): T? = get(ref.name)?.let { ref.converter.readOrNull(it) }
|
||||
|
||||
@DFExperimental
|
||||
public operator fun <T> MutableMetaProvider.set(ref: MetaRef<T>, value: T) {
|
||||
set(ref.name, ref.converter.convert(value))
|
||||
}
|
||||
|
||||
@DFExperimental
|
||||
public class MetaSpec(
|
||||
private val configuration: MetaDescriptorBuilder.() -> Unit = {},
|
||||
) : Described {
|
||||
private val refs: MutableList<MetaRef<*>> = mutableListOf()
|
||||
|
||||
private fun registerRef(ref: MetaRef<*>) {
|
||||
refs.add(ref)
|
||||
}
|
||||
|
||||
public fun <T> item(
|
||||
converter: MetaConverter<T>,
|
||||
descriptor: MetaDescriptor? = converter.descriptor,
|
||||
key: Name? = null,
|
||||
): PropertyDelegateProvider<MetaSpec, ReadOnlyProperty<MetaSpec, MetaRef<T>>> =
|
||||
PropertyDelegateProvider { _, property ->
|
||||
val ref = MetaRef(key ?: property.name.asName(), converter, descriptor)
|
||||
registerRef(ref)
|
||||
ReadOnlyProperty { _, _ ->
|
||||
ref
|
||||
}
|
||||
}
|
||||
|
||||
override val descriptor: MetaDescriptor by lazy {
|
||||
MetaDescriptor {
|
||||
refs.forEach { ref ->
|
||||
ref.descriptor?.let {
|
||||
node(ref.name, ref.descriptor)
|
||||
}
|
||||
}
|
||||
configuration()
|
||||
}
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@ package space.kscience.dataforge.meta
|
||||
|
||||
import space.kscience.dataforge.meta.descriptors.Described
|
||||
|
||||
public interface MetaReader<out T> : Described {
|
||||
public interface MetaSpec<out T> : Described {
|
||||
|
||||
/**
|
||||
* Read the source meta into an object and return null if Meta could not be interpreted as a target type
|
||||
@ -10,12 +10,12 @@ public interface MetaReader<out T> : Described {
|
||||
public fun readOrNull(source: Meta): T?
|
||||
|
||||
/**
|
||||
* Read generic read-only meta with this [MetaReader] producing instance of the desired type.
|
||||
* Read generic read-only meta with this [MetaSpec] producing instance of the desired type.
|
||||
* Throws an error if conversion could not be done.
|
||||
*/
|
||||
public fun read(source: Meta): T = readOrNull(source) ?: error("Meta $source could not be interpreted by $this")
|
||||
}
|
||||
|
||||
|
||||
public fun <T : Any> MetaReader<T>.readNullable(item: Meta?): T? = item?.let { read(it) }
|
||||
public fun <T> MetaReader<T>.readValue(value: Value): T? = read(Meta(value))
|
||||
public fun <T : Any> MetaSpec<T>.readNullable(item: Meta?): T? = item?.let { read(it) }
|
||||
public fun <T> MetaSpec<T>.readValue(value: Value): T? = read(Meta(value))
|
@ -253,9 +253,6 @@ private class MutableMetaImpl(
|
||||
value: Value?,
|
||||
children: Map<NameToken, Meta> = emptyMap(),
|
||||
) : AbstractObservableMeta(), ObservableMutableMeta {
|
||||
|
||||
override val self get() = this
|
||||
|
||||
override var value = value
|
||||
@ThreadSafe set(value) {
|
||||
val oldValue = field
|
||||
|
@ -39,9 +39,6 @@ public interface ObservableMeta : Meta {
|
||||
* A [Meta] which is both observable and mutable
|
||||
*/
|
||||
public interface ObservableMutableMeta : ObservableMeta, MutableMeta, MutableTypedMeta<ObservableMutableMeta> {
|
||||
|
||||
override val self: ObservableMutableMeta get() = this
|
||||
|
||||
override fun getOrCreate(name: Name): ObservableMutableMeta
|
||||
|
||||
override fun get(name: Name): ObservableMutableMeta? {
|
||||
|
@ -14,9 +14,6 @@ private class ObservableMetaWrapper(
|
||||
val nodeName: Name,
|
||||
val listeners: MutableSet<MetaListener>,
|
||||
) : ObservableMutableMeta {
|
||||
|
||||
override val self get() = this
|
||||
|
||||
override val items: Map<NameToken, ObservableMutableMeta>
|
||||
get() = root[nodeName]?.items?.keys?.associateWith {
|
||||
ObservableMetaWrapper(root, nodeName + it, listeners)
|
||||
|
@ -12,7 +12,7 @@ import kotlin.reflect.KProperty
|
||||
import kotlin.reflect.KProperty1
|
||||
|
||||
/**
|
||||
* A base for delegate-based or descriptor-based scheme. [Scheme] has an empty constructor to simplify usage from [MetaReader].
|
||||
* A base for delegate-based or descriptor-based scheme. [Scheme] has an empty constructor to simplify usage from [MetaSpec].
|
||||
*
|
||||
* @param prototype default values provided by this scheme
|
||||
*/
|
||||
@ -80,9 +80,6 @@ public open class Scheme(
|
||||
override fun toString(): String = meta.toString()
|
||||
|
||||
private inner class SchemeMeta(val pathName: Name) : ObservableMutableMeta {
|
||||
|
||||
override val self get() = this
|
||||
|
||||
override var value: Value?
|
||||
get() = target[pathName]?.value
|
||||
?: prototype?.get(pathName)?.value
|
||||
@ -219,7 +216,7 @@ public fun <T : Scheme> Configurable.updateWith(
|
||||
|
||||
|
||||
/**
|
||||
* A delegate that uses a [MetaReader] to wrap a child of this provider
|
||||
* A delegate that uses a [MetaSpec] to wrap a child of this provider
|
||||
*/
|
||||
public fun <T : Scheme> MutableMeta.scheme(
|
||||
spec: SchemeSpec<T>,
|
||||
@ -242,7 +239,7 @@ public fun <T : Scheme> Scheme.scheme(
|
||||
): ReadWriteProperty<Any?, T> = meta.scheme(spec, key)
|
||||
|
||||
/**
|
||||
* A delegate that uses a [MetaReader] to wrap a child of this provider.
|
||||
* A delegate that uses a [MetaSpec] to wrap a child of this provider.
|
||||
* Returns null if meta with given name does not exist.
|
||||
*/
|
||||
public fun <T : Scheme> MutableMeta.schemeOrNull(
|
||||
@ -267,7 +264,7 @@ public fun <T : Scheme> Scheme.schemeOrNull(
|
||||
): ReadWriteProperty<Any?, T?> = meta.schemeOrNull(spec, key)
|
||||
|
||||
/**
|
||||
* A delegate that uses a [MetaReader] to wrap a list of child providers.
|
||||
* A delegate that uses a [MetaSpec] to wrap a list of child providers.
|
||||
* If children are mutable, the changes in list elements are reflected on them.
|
||||
* The list is a snapshot of children state, so change in structure is not reflected on its composition.
|
||||
*/
|
||||
|
@ -13,9 +13,6 @@ public class SealedMeta(
|
||||
override val value: Value?,
|
||||
override val items: Map<NameToken, SealedMeta>,
|
||||
) : TypedMeta<SealedMeta> {
|
||||
|
||||
override val self: SealedMeta get() = this
|
||||
|
||||
override fun toString(): String = Meta.toString(this)
|
||||
override fun equals(other: Any?): Boolean = Meta.equals(this, other as? Meta)
|
||||
|
||||
|
@ -58,7 +58,7 @@ public class MetaDescriptorBuilder @PublishedApi internal constructor() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun node(
|
||||
internal fun node(
|
||||
name: Name,
|
||||
descriptorBuilder: MetaDescriptor,
|
||||
): Unit {
|
||||
|
@ -0,0 +1,3 @@
|
||||
package space.kscience.dataforge.misc
|
||||
|
||||
public expect inline fun <T> Any?.unsafeCast(): T
|
@ -58,7 +58,7 @@ public class Name(public val tokens: List<NameToken>) {
|
||||
*/
|
||||
public fun parse(string: String): Name {
|
||||
if (string.isBlank()) return EMPTY
|
||||
val tokens = buildList<NameToken> {
|
||||
val tokens = sequence {
|
||||
var bodyBuilder = StringBuilder()
|
||||
var queryBuilder = StringBuilder()
|
||||
var bracketCount = 0
|
||||
@ -91,7 +91,7 @@ public class Name(public val tokens: List<NameToken>) {
|
||||
else -> when (it) {
|
||||
'.' -> {
|
||||
val query = if (queryBuilder.isEmpty()) null else queryBuilder.toString()
|
||||
add(NameToken(bodyBuilder.toString(), query))
|
||||
yield(NameToken(bodyBuilder.toString(), query))
|
||||
bodyBuilder = StringBuilder()
|
||||
queryBuilder = StringBuilder()
|
||||
}
|
||||
@ -106,9 +106,9 @@ public class Name(public val tokens: List<NameToken>) {
|
||||
}
|
||||
}
|
||||
val query = if (queryBuilder.isEmpty()) null else queryBuilder.toString()
|
||||
add(NameToken(bodyBuilder.toString(), query))
|
||||
yield(NameToken(bodyBuilder.toString(), query))
|
||||
}
|
||||
return Name(tokens)
|
||||
return Name(tokens.toList())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,9 +31,6 @@ public fun Meta.toDynamic(): dynamic {
|
||||
}
|
||||
|
||||
public class DynamicMeta(internal val obj: dynamic) : TypedMeta<DynamicMeta> {
|
||||
|
||||
override val self: DynamicMeta get() = this
|
||||
|
||||
private fun keys(): Array<String> = js("Object").keys(obj) as Array<String>
|
||||
|
||||
private fun isArray(obj: dynamic): Boolean =
|
||||
|
@ -0,0 +1,5 @@
|
||||
package space.kscience.dataforge.misc
|
||||
import kotlin.js.unsafeCast as unsafeCastJs
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
public actual inline fun <T> Any?.unsafeCast(): T = unsafeCastJs<T>()
|
@ -0,0 +1,4 @@
|
||||
package space.kscience.dataforge.misc
|
||||
|
||||
@Suppress("UNCHECKED_CAST", "NOTHING_TO_INLINE")
|
||||
public actual inline fun <T> Any?.unsafeCast(): T = this as T
|
@ -0,0 +1,4 @@
|
||||
package space.kscience.dataforge.misc
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
public actual inline fun <T> Any?.unsafeCast(): T = this as T
|
@ -0,0 +1,4 @@
|
||||
package space.kscience.dataforge.misc
|
||||
|
||||
@Suppress("UNCHECKED_CAST", "NOTHING_TO_INLINE")
|
||||
public actual inline fun <T> Any?.unsafeCast(): T = this as T
|
@ -6,7 +6,7 @@
|
||||
|
||||
## Artifact:
|
||||
|
||||
The Maven coordinates of this project are `space.kscience:dataforge-scripting:0.9.0-dev-1`.
|
||||
The Maven coordinates of this project are `space.kscience:dataforge-scripting:0.8.2`.
|
||||
|
||||
**Gradle Kotlin DSL:**
|
||||
```kotlin
|
||||
@ -16,6 +16,6 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("space.kscience:dataforge-scripting:0.9.0-dev-1")
|
||||
implementation("space.kscience:dataforge-scripting:0.8.2")
|
||||
}
|
||||
```
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
## Artifact:
|
||||
|
||||
The Maven coordinates of this project are `space.kscience:dataforge-workspace:0.9.0-dev-1`.
|
||||
The Maven coordinates of this project are `space.kscience:dataforge-workspace:0.8.2`.
|
||||
|
||||
**Gradle Kotlin DSL:**
|
||||
```kotlin
|
||||
@ -16,6 +16,6 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("space.kscience:dataforge-workspace:0.9.0-dev-1")
|
||||
implementation("space.kscience:dataforge-workspace:0.8.2")
|
||||
}
|
||||
```
|
||||
|
@ -5,8 +5,8 @@ import space.kscience.dataforge.data.DataSink
|
||||
import space.kscience.dataforge.data.GoalExecutionRestriction
|
||||
import space.kscience.dataforge.data.MutableDataTree
|
||||
import space.kscience.dataforge.meta.Meta
|
||||
import space.kscience.dataforge.meta.MetaReader
|
||||
import space.kscience.dataforge.meta.MetaRepr
|
||||
import space.kscience.dataforge.meta.MetaSpec
|
||||
import space.kscience.dataforge.meta.descriptors.Described
|
||||
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
|
||||
import space.kscience.dataforge.misc.DfType
|
||||
@ -44,10 +44,10 @@ public interface Task<T> : Described {
|
||||
}
|
||||
|
||||
/**
|
||||
* A [Task] with [MetaReader] for wrapping and unwrapping task configuration
|
||||
* A [Task] with [MetaSpec] for wrapping and unwrapping task configuration
|
||||
*/
|
||||
public interface TaskWithSpec<T, C : Any> : Task<T> {
|
||||
public val spec: MetaReader<C>
|
||||
public val spec: MetaSpec<C>
|
||||
override val descriptor: MetaDescriptor? get() = spec.descriptor
|
||||
|
||||
public suspend fun execute(workspace: Workspace, taskName: Name, configuration: C): TaskResult<T>
|
||||
@ -122,10 +122,10 @@ public inline fun <reified T : Any> Task(
|
||||
@Suppress("FunctionName")
|
||||
public fun <T : Any, C : MetaRepr> Task(
|
||||
resultType: KType,
|
||||
specification: MetaReader<C>,
|
||||
specification: MetaSpec<C>,
|
||||
builder: suspend TaskResultBuilder<T>.(C) -> Unit,
|
||||
): TaskWithSpec<T, C> = object : TaskWithSpec<T, C> {
|
||||
override val spec: MetaReader<C> = specification
|
||||
override val spec: MetaSpec<C> = specification
|
||||
|
||||
override suspend fun execute(
|
||||
workspace: Workspace,
|
||||
@ -143,6 +143,6 @@ public fun <T : Any, C : MetaRepr> Task(
|
||||
}
|
||||
|
||||
public inline fun <reified T : Any, C : MetaRepr> Task(
|
||||
specification: MetaReader<C>,
|
||||
specification: MetaSpec<C>,
|
||||
noinline builder: suspend TaskResultBuilder<T>.(C) -> Unit,
|
||||
): Task<T> = Task(typeOf<T>(), specification, builder)
|
@ -71,10 +71,10 @@ public inline fun <reified T : Any> TaskContainer.task(
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a task based on [MetaReader]
|
||||
* Create a task based on [MetaSpec]
|
||||
*/
|
||||
public inline fun <reified T : Any, C : MetaRepr> TaskContainer.task(
|
||||
specification: MetaReader<C>,
|
||||
specification: MetaSpec<C>,
|
||||
noinline builder: suspend TaskResultBuilder<T>.(C) -> Unit,
|
||||
): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, TaskReference<T>>> = PropertyDelegateProvider { _, property ->
|
||||
val taskName = Name.parse(property.name)
|
||||
|
@ -1,9 +1,10 @@
|
||||
kotlin.code.style=official
|
||||
|
||||
org.gradle.parallel=true
|
||||
org.gradle.jvmargs=-Xmx4096m
|
||||
|
||||
kotlin.code.style=official
|
||||
kotlin.mpp.stability.nowarn=true
|
||||
kotlin.incremental.js.ir=true
|
||||
kotlin.native.ignoreDisabledTargets=true
|
||||
|
||||
toolsVersion=0.15.4-kotlin-2.0.0
|
||||
toolsVersion=0.15.2-kotlin-1.9.21
|
||||
#kotlin.experimental.tryK2=true
|
Loading…
Reference in New Issue
Block a user