diff --git a/dataforge-io/dataforge-io-yaml/src/main/kotlin/hep/dataforge/io/yaml/FrontMatterEnvelopeFormat.kt b/dataforge-io/dataforge-io-yaml/src/main/kotlin/hep/dataforge/io/yaml/FrontMatterEnvelopeFormat.kt index 0fc1d68a..8c3a3c34 100644 --- a/dataforge-io/dataforge-io-yaml/src/main/kotlin/hep/dataforge/io/yaml/FrontMatterEnvelopeFormat.kt +++ b/dataforge-io/dataforge-io-yaml/src/main/kotlin/hep/dataforge/io/yaml/FrontMatterEnvelopeFormat.kt @@ -11,9 +11,9 @@ import kotlinx.io.text.readUtf8Line import kotlinx.io.text.writeUtf8String @DFExperimental -class FrontMatterEnvelopeFormat( - val io: IOPlugin, - val meta: Meta = Meta.EMPTY, +public class FrontMatterEnvelopeFormat( + private val io: IOPlugin, + private val meta: Meta = Meta.EMPTY, ) : EnvelopeFormat { override fun readPartial(input: Input): PartialEnvelope { @@ -80,8 +80,8 @@ class FrontMatterEnvelopeFormat( META_KEY put meta } - companion object : EnvelopeFormatFactory { - const val SEPARATOR = "---" + public companion object : EnvelopeFormatFactory { + public const val SEPARATOR = "---" private val metaTypeRegex = "---(\\w*)\\s*".toRegex() diff --git a/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/ioMisc.kt b/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/ioMisc.kt index edb05bf5..283f7638 100644 --- a/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/ioMisc.kt +++ b/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/ioMisc.kt @@ -3,26 +3,26 @@ package hep.dataforge.io import kotlinx.io.* import kotlin.math.min -fun Output.writeRawString(str: String) { +public fun Output.writeRawString(str: String) { str.forEach { writeByte(it.toByte()) } } -fun Input.readRawString(size: Int): String { +public fun Input.readRawString(size: Int): String { val array = CharArray(size) { readByte().toChar() } return array.concatToString() } -inline fun buildByteArray(expectedSize: Int = 16, block: Output.() -> Unit): ByteArray = +public inline fun buildByteArray(expectedSize: Int = 16, block: Output.() -> Unit): ByteArray = ByteArrayOutput(expectedSize).apply(block).toByteArray() @Suppress("FunctionName") -inline fun Binary(expectedSize: Int = 16, block: Output.() -> Unit): Binary = +public inline fun Binary(expectedSize: Int = 16, block: Output.() -> Unit): Binary = buildByteArray(expectedSize, block).asBinary() /** * View section of a [Binary] as an independent binary */ -class BinaryView(private val source: Binary, private val start: Int, override val size: Int) : Binary { +public class BinaryView(private val source: Binary, private val start: Int, override val size: Int) : Binary { init { require(start > 0) @@ -34,6 +34,6 @@ class BinaryView(private val source: Binary, private val start: Int, override va } } -fun Binary.view(start: Int, size: Int) = BinaryView(this, start, size) +public fun Binary.view(start: Int, size: Int): BinaryView = BinaryView(this, start, size) -operator fun Binary.get(range: IntRange) = view(range.first, range.last - range.first) \ No newline at end of file +public operator fun Binary.get(range: IntRange): BinaryView = view(range.first, range.last - range.first) \ No newline at end of file diff --git a/dataforge-output/src/commonMain/kotlin/hep/dataforge/output/OutputManager.kt b/dataforge-output/src/commonMain/kotlin/hep/dataforge/output/OutputManager.kt index a8b1697d..f0c71525 100644 --- a/dataforge-output/src/commonMain/kotlin/hep/dataforge/output/OutputManager.kt +++ b/dataforge-output/src/commonMain/kotlin/hep/dataforge/output/OutputManager.kt @@ -11,7 +11,7 @@ import kotlin.reflect.KClass /** * A manager for outputs */ -interface OutputManager { +public interface OutputManager { /** * Get an output specialized for given type, name and stage. @@ -19,7 +19,7 @@ interface OutputManager { * @param name represents the name inside the node. * @param meta configuration for [Renderer] (not for rendered object) */ - operator fun get( + public operator fun get( type: KClass, name: Name, stage: Name = Name.EMPTY, @@ -30,12 +30,12 @@ interface OutputManager { /** * Get an output manager for a context */ -val Context.output: OutputManager get() = plugins.get() ?: ConsoleOutputManager() +public val Context.output: OutputManager get() = plugins.get() ?: ConsoleOutputManager() /** * Get an output with given [name], [stage] and reified content type */ -inline operator fun OutputManager.get( +public inline operator fun OutputManager.get( name: Name, stage: Name = Name.EMPTY, meta: Meta = Meta.EMPTY @@ -46,14 +46,14 @@ inline operator fun OutputManager.get( /** * Directly render an object using the most suitable renderer */ -fun OutputManager.render(obj: Any, name: Name, stage: Name = Name.EMPTY, meta: Meta = Meta.EMPTY) = +public fun OutputManager.render(obj: Any, name: Name, stage: Name = Name.EMPTY, meta: Meta = Meta.EMPTY): Unit = get(obj::class, name, stage).render(obj, meta) /** * System console output. * The [CONSOLE_RENDERER] is used when no other [OutputManager] is provided. */ -val CONSOLE_RENDERER: Renderer = object : Renderer { +public val CONSOLE_RENDERER: Renderer = object : Renderer { override fun render(obj: Any, meta: Meta) { println(obj) } @@ -62,21 +62,21 @@ val CONSOLE_RENDERER: Renderer = object : Renderer { } -class ConsoleOutputManager : AbstractPlugin(), OutputManager { +public class ConsoleOutputManager : AbstractPlugin(), OutputManager { override val tag: PluginTag get() = ConsoleOutputManager.tag override fun get(type: KClass, name: Name, stage: Name, meta: Meta): Renderer = CONSOLE_RENDERER - companion object : PluginFactory { - override val tag = PluginTag("output.console", group = DATAFORGE_GROUP) + public companion object : PluginFactory { + override val tag: PluginTag = PluginTag("output.console", group = DATAFORGE_GROUP) - override val type = ConsoleOutputManager::class + override val type: KClass = ConsoleOutputManager::class - override fun invoke(meta: Meta, context: Context) = ConsoleOutputManager() + override fun invoke(meta: Meta, context: Context): ConsoleOutputManager = ConsoleOutputManager() } } /** * A dispatcher for output tasks. */ -expect val Dispatchers.Output: CoroutineDispatcher \ No newline at end of file +public expect val Dispatchers.Output: CoroutineDispatcher \ No newline at end of file diff --git a/dataforge-output/src/commonMain/kotlin/hep/dataforge/output/Renderer.kt b/dataforge-output/src/commonMain/kotlin/hep/dataforge/output/Renderer.kt index 9f8009d1..6e3bee19 100644 --- a/dataforge-output/src/commonMain/kotlin/hep/dataforge/output/Renderer.kt +++ b/dataforge-output/src/commonMain/kotlin/hep/dataforge/output/Renderer.kt @@ -10,12 +10,12 @@ import hep.dataforge.meta.Meta * based on its configuration and provided meta * */ -interface Renderer : ContextAware { +public interface Renderer : ContextAware { /** * Render specific object with configuration. * * By convention actual render is called in asynchronous mode, so this method should never * block execution */ - fun render(obj: T, meta: Meta = Meta.EMPTY) + public fun render(obj: T, meta: Meta = Meta.EMPTY) } diff --git a/dataforge-output/src/commonMain/kotlin/hep/dataforge/output/TextRenderer.kt b/dataforge-output/src/commonMain/kotlin/hep/dataforge/output/TextRenderer.kt index cc9d24f3..b70030e4 100644 --- a/dataforge-output/src/commonMain/kotlin/hep/dataforge/output/TextRenderer.kt +++ b/dataforge-output/src/commonMain/kotlin/hep/dataforge/output/TextRenderer.kt @@ -11,7 +11,41 @@ import kotlinx.io.Output import kotlinx.io.text.writeUtf8String import kotlin.reflect.KClass -class TextRenderer(override val context: Context, private val output: Output) : Renderer { + +/** + * A text or binary renderer based on [Output] + */ +@Type(TEXT_RENDERER_TYPE) +public interface TextFormat { + /** + * The priority of this renderer compared to other renderers + */ + public val priority: Int + /** + * The type of the content served by this renderer + */ + public val type: KClass<*> + + public suspend fun Output.render(obj: Any) + + public companion object { + public const val TEXT_RENDERER_TYPE: String = "dataforge.textRenderer" + } +} + +public object DefaultTextFormat : TextFormat { + override val priority: Int = Int.MAX_VALUE + override val type: KClass<*> = Any::class + + override suspend fun Output.render(obj: Any) { + writeUtf8String(obj.toString() + "\n") + } +} + +/** + * A text-based renderer + */ +public class TextRenderer(override val context: Context, private val output: Output) : Renderer { private val cache = HashMap, TextFormat>() /** @@ -39,34 +73,4 @@ class TextRenderer(override val context: Context, private val output: Output) : format.run { output.render(obj) } } } -} - -/** - * A text or binary renderer based on [Output] - */ -@Type(TEXT_RENDERER_TYPE) -interface TextFormat { - /** - * The priority of this renderer compared to other renderers - */ - val priority: Int - /** - * The type of the content served by this renderer - */ - val type: KClass<*> - - suspend fun Output.render(obj: Any) - - companion object { - const val TEXT_RENDERER_TYPE = "dataforge.textRenderer" - } -} - -object DefaultTextFormat : TextFormat { - override val priority: Int = Int.MAX_VALUE - override val type: KClass<*> = Any::class - - override suspend fun Output.render(obj: Any) { - writeUtf8String(obj.toString() + "\n") - } } \ No newline at end of file diff --git a/dataforge-output/src/jsMain/kotlin/hep/dataforge/output/outputJS.kt b/dataforge-output/src/jsMain/kotlin/hep/dataforge/output/outputJS.kt index 18a71f07..be973122 100644 --- a/dataforge-output/src/jsMain/kotlin/hep/dataforge/output/outputJS.kt +++ b/dataforge-output/src/jsMain/kotlin/hep/dataforge/output/outputJS.kt @@ -4,4 +4,4 @@ import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers -actual val Dispatchers.Output: CoroutineDispatcher get() = Dispatchers.Default \ No newline at end of file +public actual val Dispatchers.Output: CoroutineDispatcher get() = Default \ No newline at end of file diff --git a/dataforge-output/src/jvmMain/kotlin/hep/dataforge/output/outputJVM.kt b/dataforge-output/src/jvmMain/kotlin/hep/dataforge/output/outputJVM.kt index ea7c416c..24c789fd 100644 --- a/dataforge-output/src/jvmMain/kotlin/hep/dataforge/output/outputJVM.kt +++ b/dataforge-output/src/jvmMain/kotlin/hep/dataforge/output/outputJVM.kt @@ -1,5 +1,6 @@ package hep.dataforge.output +import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers -actual val Dispatchers.Output get() = Dispatchers.IO \ No newline at end of file +public actual val Dispatchers.Output: CoroutineDispatcher get() = IO \ No newline at end of file diff --git a/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/ColumnDef.kt b/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/ColumnDef.kt index 2df51d41..2dd2e85b 100644 --- a/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/ColumnDef.kt +++ b/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/ColumnDef.kt @@ -3,7 +3,7 @@ package hep.dataforge.tables import hep.dataforge.meta.Meta import kotlin.reflect.KClass -data class ColumnDef( +public data class ColumnDef( override val name: String, override val type: KClass, override val meta: Meta diff --git a/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/ColumnHeader.kt b/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/ColumnHeader.kt index 2023d11b..a226de26 100644 --- a/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/ColumnHeader.kt +++ b/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/ColumnHeader.kt @@ -8,25 +8,25 @@ import hep.dataforge.values.Value import hep.dataforge.values.ValueType import kotlin.reflect.KClass -typealias TableHeader = List> +public typealias TableHeader = List> -typealias ValueTableHeader = List> +public typealias ValueTableHeader = List> -interface ColumnHeader { - val name: String - val type: KClass - val meta: Meta +public interface ColumnHeader { + public val name: String + public val type: KClass + public val meta: Meta } -data class SimpleColumnHeader( +public data class SimpleColumnHeader( override val name: String, override val type: KClass, override val meta: Meta ) : ColumnHeader -val ColumnHeader.valueType: ValueType? get() = meta["valueType"].string?.let { ValueType.valueOf(it) } +public val ColumnHeader.valueType: ValueType? get() = meta["valueType"].string?.let { ValueType.valueOf(it) } -val ColumnHeader.textWidth: Int +public val ColumnHeader.textWidth: Int get() = meta["columnWidth"].int ?: when (valueType) { ValueType.NUMBER -> 8 ValueType.STRING -> 16 diff --git a/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/ColumnScheme.kt b/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/ColumnScheme.kt index c71ee53f..17968a82 100644 --- a/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/ColumnScheme.kt +++ b/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/ColumnScheme.kt @@ -6,12 +6,12 @@ import hep.dataforge.meta.enum import hep.dataforge.meta.string import hep.dataforge.values.ValueType -open class ColumnScheme : Scheme() { - var title by string() +public open class ColumnScheme : Scheme() { + public var title: String? by string() - companion object : SchemeSpec(::ColumnScheme) + public companion object : SchemeSpec(::ColumnScheme) } -class ValueColumnScheme : ColumnScheme() { - var valueType by enum(ValueType.STRING) +public class ValueColumnScheme : ColumnScheme() { + public var valueType: ValueType by enum(ValueType.STRING) } \ No newline at end of file diff --git a/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/ColumnTable.kt b/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/ColumnTable.kt index db80b6fa..e79ebd08 100644 --- a/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/ColumnTable.kt +++ b/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/ColumnTable.kt @@ -3,7 +3,7 @@ package hep.dataforge.tables /** * @param T bottom type for all columns in the table */ -class ColumnTable(override val columns: Collection>) : Table { +public class ColumnTable(override val columns: Collection>) : Table { private val rowsNum = columns.first().size init { diff --git a/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/ListColumn.kt b/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/ListColumn.kt index fc7f03ea..7b0549fa 100644 --- a/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/ListColumn.kt +++ b/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/ListColumn.kt @@ -3,7 +3,7 @@ package hep.dataforge.tables import hep.dataforge.meta.Meta import kotlin.reflect.KClass -class ListColumn( +public class ListColumn( override val name: String, private val data: List, override val type: KClass, @@ -13,14 +13,14 @@ class ListColumn( override fun get(index: Int): T? = data[index] - companion object { - inline operator fun invoke( + public companion object { + public inline operator fun invoke( name: String, def: ColumnScheme, data: List ): ListColumn = ListColumn(name, data, T::class, def.toMeta()) - inline operator fun invoke( + public inline operator fun invoke( name: String, def: ColumnScheme, size: Int, @@ -29,7 +29,7 @@ class ListColumn( } } -inline fun Column.map(meta: Meta = this.meta, noinline block: (T?) -> R): Column { +public inline fun Column.map(meta: Meta = this.meta, noinline block: (T?) -> R): Column { val data = List(size) { block(get(it)) } return ListColumn(name, data, R::class, meta) } \ No newline at end of file diff --git a/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/MutableColumnTable.kt b/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/MutableColumnTable.kt index 4b93a13d..eb69d7e7 100644 --- a/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/MutableColumnTable.kt +++ b/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/MutableColumnTable.kt @@ -3,7 +3,7 @@ package hep.dataforge.tables /** * Mutable table with a fixed size, but dynamic columns */ -class MutableColumnTable(val size: Int) : Table { +public class MutableColumnTable(public val size: Int) : Table { private val _columns = ArrayList>() override val columns: List> get() = _columns @@ -16,7 +16,7 @@ class MutableColumnTable(val size: Int) : Table { /** * Add a fixed column to the end of the table */ - fun add(column: Column) { + public fun add(column: Column) { require(column.size == this.size) { "Required column size $size, but found ${column.size}" } _columns.add(column) } @@ -24,7 +24,7 @@ class MutableColumnTable(val size: Int) : Table { /** * Insert a column at [index] */ - fun insert(index: Int, column: Column) { + public fun insert(index: Int, column: Column) { require(column.size == this.size) { "Required column size $size, but found ${column.size}" } _columns.add(index, column) } diff --git a/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/MutableTable.kt b/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/MutableTable.kt index a59108a6..7a1e0376 100644 --- a/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/MutableTable.kt +++ b/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/MutableTable.kt @@ -4,37 +4,37 @@ import hep.dataforge.meta.Meta import hep.dataforge.values.Value import kotlin.reflect.KClass -class MutableTable( +public class MutableTable( override val rows: MutableList>, override val header: MutableList> ) : RowTable(rows, header) { - fun column(name: String, type: KClass, meta: Meta): ColumnHeader { + public fun column(name: String, type: KClass, meta: Meta): ColumnHeader { val column = SimpleColumnHeader(name, type, meta) header.add(column) return column } - inline fun column( + public inline fun column( name: String, noinline columnMetaBuilder: ColumnScheme.() -> Unit = {} ): ColumnHeader { return column(name, T::class, ColumnScheme(columnMetaBuilder).toMeta()) } - fun row(map: Map): Row { + public fun row(map: Map): Row { val row = MapRow(map) rows.add(row) return row } - fun row(vararg pairs: Pair, T>): Row = + public fun row(vararg pairs: Pair, T>): Row = row(pairs.associate { it.first.name to it.second }) } -fun MutableTable.row(vararg pairs: Pair, Any?>): Row = +public fun MutableTable.row(vararg pairs: Pair, Any?>): Row = row(pairs.associate { it.first.name to Value.of(it.second) }) -fun Table.edit(block: MutableTable.() -> Unit): Table { +public fun Table.edit(block: MutableTable.() -> Unit): Table { return MutableTable(rows.toMutableList(), header.toMutableList()).apply(block) } \ No newline at end of file diff --git a/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/RowTable.kt b/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/RowTable.kt index aa3449fb..9ea908cc 100644 --- a/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/RowTable.kt +++ b/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/RowTable.kt @@ -4,7 +4,7 @@ import hep.dataforge.meta.Meta import kotlinx.coroutines.flow.toList import kotlin.reflect.KClass -inline class MapRow(val values: Map) : Row { +public inline class MapRow(private val values: Map) : Row { override fun getValue(column: String): C? = values[column] } @@ -17,10 +17,10 @@ internal class RowTableColumn(val table: Table, val header: C override fun get(index: Int): T? = table.rows[index].getValue(name, type) } -open class RowTable(override val rows: List>, override val header: List>) : Table { +public open class RowTable(override val rows: List>, override val header: List>) : Table { override fun getValue(row: Int, column: String): C? = rows[row].getValue(column) override val columns: List> get() = header.map { RowTableColumn(this, it) } } -suspend fun Rows.collect(): Table = this as? Table ?: RowTable(rowFlow().toList(), header) \ No newline at end of file +public suspend fun Rows.collect(): Table = this as? Table ?: RowTable(rowFlow().toList(), header) \ No newline at end of file diff --git a/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/Table.kt b/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/Table.kt index 0197955d..72875a05 100644 --- a/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/Table.kt +++ b/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/Table.kt @@ -9,57 +9,57 @@ import kotlin.reflect.cast * Finite or infinite row set. Rows are produced in a lazy suspendable [Flow]. * Each row must contain at least all the fields mentioned in [header]. */ -interface Rows { - val header: TableHeader - fun rowFlow(): Flow> +public interface Rows { + public val header: TableHeader + public fun rowFlow(): Flow> } -interface Table : Rows { - fun getValue(row: Int, column: String): T? - val columns: Collection> +public interface Table : Rows { + public fun getValue(row: Int, column: String): T? + public val columns: Collection> override val header: TableHeader get() = columns.toList() - val rows: List> + public val rows: List> override fun rowFlow(): Flow> = rows.asFlow() /** * Apply typed query to this table and return lazy [Flow] of resulting rows. The flow could be empty. */ //fun select(query: Any): Flow = error("Query of type ${query::class} is not supported by this table") - companion object { - inline operator fun invoke(block: MutableTable.() -> Unit): Table = + public companion object { + public inline operator fun invoke(block: MutableTable.() -> Unit): Table = MutableTable(arrayListOf(), arrayListOf()).apply(block) } } -fun Table.getValue(row: Int, column: String, type: KClass): T? = +public fun Table.getValue(row: Int, column: String, type: KClass): T? = type.cast(getValue(row, column)) -operator fun Collection>.get(name: String): Column? = find { it.name == name } +public operator fun Collection>.get(name: String): Column? = find { it.name == name } -inline operator fun Table.get(row: Int, column: String): T? = +public inline operator fun Table.get(row: Int, column: String): T? = getValue(row, column, T::class) -operator fun Table.get(row: Int, column: ColumnHeader): T? = +public operator fun Table.get(row: Int, column: ColumnHeader): T? = getValue(row, column.name, column.type) -interface Column : ColumnHeader { - val size: Int - operator fun get(index: Int): T? +public interface Column : ColumnHeader { + public val size: Int + public operator fun get(index: Int): T? } -val Column<*>.indices get() = (0 until size) +public val Column<*>.indices: IntRange get() = (0 until size) -operator fun Column.iterator() = iterator { +public operator fun Column.iterator(): Iterator = iterator { for (i in indices) { yield(get(i)) } } -interface Row { - fun getValue(column: String): T? +public interface Row { + public fun getValue(column: String): T? } -fun Row.getValue(column: String, type: KClass): T? = type.cast(getValue(column)) +public fun Row.getValue(column: String, type: KClass): T? = type.cast(getValue(column)) -inline operator fun Row.get(column: String): T? = T::class.cast(getValue(column)) -operator fun Row.get(column: ColumnHeader): T? = getValue(column.name, column.type) \ No newline at end of file +public inline operator fun Row.get(column: String): T? = T::class.cast(getValue(column)) +public operator fun Row.get(column: ColumnHeader): T? = getValue(column.name, column.type) \ No newline at end of file diff --git a/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/TransformationColumn.kt b/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/TransformationColumn.kt index 3c4fa2b4..83fdc06b 100644 --- a/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/TransformationColumn.kt +++ b/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/TransformationColumn.kt @@ -6,12 +6,12 @@ import kotlin.reflect.KClass /** * A virtual column obtained by transforming Given row to a single value */ -class TransformationColumn( - val table: Table, +public class TransformationColumn( + public val table: Table, override val type: KClass, override val name: String, override val meta: Meta, - val mapper: (Row) -> R? + public val mapper: (Row) -> R? ) : Column { override val size: Int get() = table.rows.size @@ -23,12 +23,12 @@ class TransformationColumn( * * Calls are not thread safe */ -class CachedTransformationColumn( - val table: Table, +public class CachedTransformationColumn( + public val table: Table, override val type: KClass, override val name: String, override val meta: Meta, - val mapper: (Row) -> R? + public val mapper: (Row) -> R? ) : Column { override val size: Int get() = table.rows.size private val values: HashMap = HashMap() @@ -38,7 +38,7 @@ class CachedTransformationColumn( /** * Create a virtual column from a given column */ -inline fun Table.mapRows( +public inline fun Table.mapRows( name: String, meta: Meta = Meta.EMPTY, cache: Boolean = false, @@ -49,12 +49,12 @@ inline fun Table.mapRows( TransformationColumn(this, R::class, name, meta, mapper) } -fun Table.mapRowsToDouble(name: String, meta: Meta = Meta.EMPTY, block: (Row) -> Double): RealColumn { +public fun Table.mapRowsToDouble(name: String, meta: Meta = Meta.EMPTY, block: (Row) -> Double): RealColumn { val data = DoubleArray(rows.size) { block(rows[it]) } return RealColumn(name, data, meta) } -fun Table.mapRowsToInt(name: String, meta: Meta = Meta.EMPTY, block: (Row) -> Int): IntColumn { +public fun Table.mapRowsToInt(name: String, meta: Meta = Meta.EMPTY, block: (Row) -> Int): IntColumn { val data = IntArray(rows.size) { block(rows[it]) } return IntColumn(name, data, meta) } \ No newline at end of file diff --git a/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/io/TextRows.kt b/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/io/TextRows.kt index 293031f8..31f5baaa 100644 --- a/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/io/TextRows.kt +++ b/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/io/TextRows.kt @@ -32,12 +32,12 @@ private fun readLine(header: ValueTableHeader, line: String): Row { * Finite or infinite [Rows] created from a fixed width text binary */ @ExperimentalIoApi -class TextRows(override val header: ValueTableHeader, val binary: Binary) : Rows { +public class TextRows(override val header: ValueTableHeader, private val binary: Binary) : Rows { /** * A flow of indexes of string start offsets ignoring empty strings */ - fun indexFlow(): Flow = binary.read { + public fun indexFlow(): Flow = binary.read { var counter: Int = 0 flow { val string = readUtf8StringUntilDelimiter('\n') @@ -59,23 +59,23 @@ class TextRows(override val header: ValueTableHeader, val binary: Binary) : Rows } } - companion object + public companion object } /** * Create a row offset index for [TextRows] */ @ExperimentalIoApi -suspend fun TextRows.buildRowIndex(): List = indexFlow().toList() +public suspend fun TextRows.buildRowIndex(): List = indexFlow().toList() /** * Finite table created from [RandomAccessBinary] with fixed width text table */ @ExperimentalIoApi -class TextTable( +public class TextTable( override val header: ValueTableHeader, - val binary: Binary, - val index: List + private val binary: Binary, + public val index: List ) : Table { override val columns: Collection> get() = header.map { RowTableColumn(this, it) } @@ -96,8 +96,8 @@ class TextTable( return readAt(offset)[column] } - companion object { - suspend operator fun invoke(header: ValueTableHeader, binary: Binary): TextTable { + public companion object { + public suspend operator fun invoke(header: ValueTableHeader, binary: Binary): TextTable { val index = TextRows(header, binary).buildRowIndex() return TextTable(header, binary, index) } @@ -131,7 +131,7 @@ private fun Output.writeValue(value: Value, width: Int, left: Boolean = true) { /** * Write rows without header to the output */ -suspend fun Output.writeRows(rows: Rows) { +public suspend fun Output.writeRows(rows: Rows) { val widths: List = rows.header.map { it.textWidth } diff --git a/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/io/textTableEnvelope.kt b/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/io/textTableEnvelope.kt index 10c9b3fc..4deb84e6 100644 --- a/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/io/textTableEnvelope.kt +++ b/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/io/textTableEnvelope.kt @@ -12,7 +12,7 @@ import kotlinx.io.asBinary @ExperimentalIoApi -suspend fun Table.wrap(): Envelope = Envelope { +public suspend fun Table.wrap(): Envelope = Envelope { meta { header.forEachIndexed { index, columnHeader -> set("column", index.toString(), Meta { @@ -32,7 +32,7 @@ suspend fun Table.wrap(): Envelope = Envelope { @DFExperimental @ExperimentalIoApi -fun TextRows.Companion.readEnvelope(envelope: Envelope): TextRows { +public fun TextRows.Companion.readEnvelope(envelope: Envelope): TextRows { val header = envelope.meta.getIndexed("column") .entries.sortedBy { it.key?.toInt() } .map { (_, item) -> diff --git a/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/numericColumns.kt b/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/numericColumns.kt index 7f80b082..cc386c35 100644 --- a/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/numericColumns.kt +++ b/dataforge-tables/src/commonMain/kotlin/hep/dataforge/tables/numericColumns.kt @@ -4,9 +4,9 @@ import hep.dataforge.meta.Meta import kotlin.reflect.KClass -class RealColumn( +public class RealColumn( override val name: String, - val data: DoubleArray, + public val data: DoubleArray, override val meta: Meta = Meta.EMPTY ) : Column { override val type: KClass get() = Double::class @@ -34,8 +34,8 @@ class RealColumn( return result } - companion object { - inline operator fun invoke( + public companion object { + public inline operator fun invoke( name: String, data: DoubleArray, noinline metaBuilder: ColumnScheme.() -> Unit @@ -43,9 +43,9 @@ class RealColumn( } } -class IntColumn( +public class IntColumn( override val name: String, - val data: IntArray, + public val data: IntArray, override val meta: Meta = Meta.EMPTY ) : Column { override val type: KClass get() = Int::class @@ -73,8 +73,8 @@ class IntColumn( return result } - companion object { - inline operator fun invoke( + public companion object { + public inline operator fun invoke( name: String, data: IntArray, noinline metaBuilder: ColumnScheme.() -> Unit diff --git a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/Dependency.kt b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/Dependency.kt index ed5ab7f0..10bf38d6 100644 --- a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/Dependency.kt +++ b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/Dependency.kt @@ -4,6 +4,7 @@ import hep.dataforge.data.DataFilter import hep.dataforge.data.DataNode import hep.dataforge.data.filter import hep.dataforge.meta.Meta +import hep.dataforge.meta.MetaBuilder import hep.dataforge.meta.MetaRepr import hep.dataforge.names.Name import hep.dataforge.names.asName @@ -13,11 +14,11 @@ import hep.dataforge.names.plus /** * A dependency of the task which allows to lazily create a data tree for single dependency */ -sealed class Dependency : MetaRepr { - abstract fun apply(workspace: Workspace): DataNode +public sealed class Dependency : MetaRepr { + public abstract fun apply(workspace: Workspace): DataNode } -class DataDependency(val filter: DataFilter, val placement: Name = Name.EMPTY) : Dependency() { +public class DataDependency(private val filter: DataFilter, private val placement: Name = Name.EMPTY) : Dependency() { override fun apply(workspace: Workspace): DataNode { val result = workspace.data.filter(filter) return if (placement.isEmpty()) { @@ -33,29 +34,29 @@ class DataDependency(val filter: DataFilter, val placement: Name = Name.EMPTY) : } } -class AllDataDependency(val placement: Name = Name.EMPTY) : Dependency() { +public class AllDataDependency(private val placement: Name = Name.EMPTY) : Dependency() { override fun apply(workspace: Workspace): DataNode = if (placement.isEmpty()) { workspace.data } else { DataNode.invoke(Any::class) { this[placement] = workspace.data } } - override fun toMeta() = Meta { + override fun toMeta(): MetaBuilder = Meta { "data" put "@all" "to" put placement.toString() } } -abstract class TaskDependency( - val meta: Meta, - val placement: Name = Name.EMPTY +public abstract class TaskDependency( + public val meta: Meta, + public val placement: Name = Name.EMPTY ) : Dependency() { - abstract fun resolveTask(workspace: Workspace): Task + public abstract fun resolveTask(workspace: Workspace): Task /** * A name of the dependency for logging and serialization */ - abstract val name: Name + public abstract val name: Name override fun apply(workspace: Workspace): DataNode { val task = resolveTask(workspace) @@ -75,8 +76,8 @@ abstract class TaskDependency( } } -class DirectTaskDependency( - val task: Task, +public class DirectTaskDependency( + public val task: Task, meta: Meta, placement: Name ) : TaskDependency(meta, placement) { @@ -84,12 +85,12 @@ class DirectTaskDependency( override val name: Name get() = DIRECT_TASK_NAME + task.name - companion object { - val DIRECT_TASK_NAME = "@direct".asName() + public companion object { + public val DIRECT_TASK_NAME: Name = "@direct".asName() } } -class WorkspaceTaskDependency( +public class WorkspaceTaskDependency( override val name: Name, meta: Meta, placement: Name diff --git a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/GenericTask.kt b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/GenericTask.kt index 4e0ca715..d3844096 100644 --- a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/GenericTask.kt +++ b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/GenericTask.kt @@ -1,8 +1,8 @@ package hep.dataforge.workspace import hep.dataforge.data.DataNode -import hep.dataforge.meta.descriptors.NodeDescriptor import hep.dataforge.meta.Meta +import hep.dataforge.meta.descriptors.NodeDescriptor import hep.dataforge.meta.get import hep.dataforge.meta.node import hep.dataforge.names.Name @@ -11,7 +11,7 @@ import kotlin.reflect.KClass //data class TaskEnv(val workspace: Workspace, val model: TaskModel) -class GenericTask( +public class GenericTask( override val name: Name, override val type: KClass, override val descriptor: NodeDescriptor, @@ -19,14 +19,6 @@ class GenericTask( private val dataTransform: Workspace.() -> TaskModel.(DataNode) -> DataNode ) : Task { -// private fun gather(workspace: Workspace, model: TaskModel): DataNode { -// return DataNode.invoke(Any::class) { -// model.dependencies.forEach { dep -> -// update(dep.apply(workspace)) -// } -// } -// } - override fun run(workspace: Workspace, model: TaskModel): DataNode { //validate model validate(model) diff --git a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/SimpleWorkspace.kt b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/SimpleWorkspace.kt index 5648a822..4159ea30 100644 --- a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/SimpleWorkspace.kt +++ b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/SimpleWorkspace.kt @@ -11,7 +11,7 @@ import hep.dataforge.names.Name /** * A simple workspace without caching */ -class SimpleWorkspace( +public class SimpleWorkspace( override val context: Context, override val data: DataNode, override val targets: Map, @@ -22,7 +22,7 @@ class SimpleWorkspace( context.resolve>(Task.TYPE) + tasks.toMap() } - companion object { + public companion object { } } \ No newline at end of file diff --git a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/Task.kt b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/Task.kt index 7511bda9..fbc8637d 100644 --- a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/Task.kt +++ b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/Task.kt @@ -2,23 +2,23 @@ package hep.dataforge.workspace import hep.dataforge.context.Named import hep.dataforge.data.DataNode -import hep.dataforge.meta.descriptors.Described import hep.dataforge.meta.Meta +import hep.dataforge.meta.descriptors.Described import hep.dataforge.provider.Type import hep.dataforge.workspace.Task.Companion.TYPE import kotlin.reflect.KClass @Type(TYPE) -interface Task : Named, Described { +public interface Task : Named, Described { /** * Terminal task is the one that could not build model lazily */ - val isTerminal: Boolean get() = false + public val isTerminal: Boolean get() = false /** * The explicit type of the node returned by the task */ - val type: KClass + public val type: KClass /** * Build a model for this task @@ -27,14 +27,14 @@ interface Task : Named, Described { * @param taskConfig * @return */ - fun build(workspace: Workspace, taskConfig: Meta): TaskModel + public fun build(workspace: Workspace, taskConfig: Meta): TaskModel /** * Check if the model is valid and is acceptable by the task. Throw exception if not. * * @param model */ - fun validate(model: TaskModel) { + public fun validate(model: TaskModel) { if(this.name != model.name) error("The task $name could not be run with model from task ${model.name}") } @@ -46,9 +46,9 @@ interface Task : Named, Described { * @param model - a model to be executed * @return */ - fun run(workspace: Workspace, model: TaskModel): DataNode + public fun run(workspace: Workspace, model: TaskModel): DataNode - companion object { - const val TYPE = "task" + public companion object { + public const val TYPE = "task" } } \ No newline at end of file diff --git a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/TaskBuilder.kt b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/TaskBuilder.kt index 502c669d..4cb48843 100644 --- a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/TaskBuilder.kt +++ b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/TaskBuilder.kt @@ -14,11 +14,11 @@ import kotlin.jvm.JvmName import kotlin.reflect.KClass @DFBuilder -class TaskBuilder(val name: Name, val type: KClass) { +public class TaskBuilder(public val name: Name, public val type: KClass) { private var modelTransform: TaskModelBuilder.(Meta) -> Unit = { allData() } // private val additionalDependencies = HashSet() - var descriptor: NodeDescriptor? = null + private var descriptor: NodeDescriptor? = null private val dataTransforms: MutableList = ArrayList() /** @@ -43,7 +43,7 @@ class TaskBuilder(val name: Name, val type: KClass) { // additionalDependencies.add(dependency) // } - fun model(modelTransform: TaskModelBuilder.(Meta) -> Unit) { + public fun model(modelTransform: TaskModelBuilder.(Meta) -> Unit) { this.modelTransform = modelTransform } @@ -51,7 +51,7 @@ class TaskBuilder(val name: Name, val type: KClass) { * Add a transformation on untyped data */ @JvmName("rawTransform") - fun transform( + public fun transform( from: String = "", to: String = "", block: TaskEnv.(DataNode<*>) -> DataNode @@ -62,7 +62,7 @@ class TaskBuilder(val name: Name, val type: KClass) { } } - fun transform( + public fun transform( inputType: KClass, from: String = "", to: String = "", @@ -75,7 +75,7 @@ class TaskBuilder(val name: Name, val type: KClass) { } } - inline fun transform( + public inline fun transform( from: String = "", to: String = "", noinline block: TaskEnv.(DataNode) -> DataNode @@ -86,7 +86,7 @@ class TaskBuilder(val name: Name, val type: KClass) { /** * Perform given action on data elements in `from` node in input and put the result to `to` node */ - inline fun action( + public inline fun action( from: String = "", to: String = "", crossinline block: TaskEnv.() -> Action @@ -96,8 +96,8 @@ class TaskBuilder(val name: Name, val type: KClass) { } } - class TaskEnv(val name: Name, val meta: Meta, val context: Context, val data: DataNode) { - operator fun DirectTaskDependency.invoke(): DataNode = if (placement.isEmpty()) { + public class TaskEnv(public val name: Name, public val meta: Meta, public val context: Context, public val data: DataNode) { + public operator fun DirectTaskDependency.invoke(): DataNode = if (placement.isEmpty()) { data.cast(task.type) } else { data[placement].node?.cast(task.type) @@ -108,7 +108,7 @@ class TaskBuilder(val name: Name, val type: KClass) { /** * A customized map action with ability to change meta and name */ - inline fun mapAction( + public inline fun mapAction( from: String = "", to: String = "", crossinline block: MapActionBuilder.(TaskEnv) -> Unit @@ -127,7 +127,7 @@ class TaskBuilder(val name: Name, val type: KClass) { /** * A simple map action without changing meta or name */ - inline fun map( + public inline fun map( from: String = "", to: String = "", crossinline block: suspend TaskEnv.(T) -> R @@ -148,7 +148,7 @@ class TaskBuilder(val name: Name, val type: KClass) { /** * Join elements in gathered data by multiple groups */ - inline fun reduceByGroup( + public inline fun reduceByGroup( from: String = "", to: String = "", crossinline block: ReduceGroupBuilder.(TaskEnv) -> Unit //TODO needs KEEP-176 @@ -165,7 +165,7 @@ class TaskBuilder(val name: Name, val type: KClass) { /** * Join all elemlents in gathered data matching input type */ - inline fun reduce( + public inline fun reduce( from: String = "", to: String = "", crossinline block: suspend TaskEnv.(Map) -> R @@ -188,7 +188,7 @@ class TaskBuilder(val name: Name, val type: KClass) { /** * Split each element in gathered data into fixed number of fragments */ - inline fun split( + public inline fun split( from: String = "", to: String = "", crossinline block: SplitBuilder.(TaskEnv) -> Unit //TODO needs KEEP-176 @@ -205,16 +205,11 @@ class TaskBuilder(val name: Name, val type: KClass) { /** * Use DSL to create a descriptor for this task */ - fun description(transform: NodeDescriptor.() -> Unit) { + public fun description(transform: NodeDescriptor.() -> Unit) { this.descriptor = NodeDescriptor().apply(transform) } internal fun build(): GenericTask { -// val actualTransform: TaskModelBuilder.(Meta) -> Unit = { -// modelTransform -// dependencies.addAll(additionalDependencies) -// } - return GenericTask( name, type, diff --git a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/TaskModel.kt b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/TaskModel.kt index acd16b2d..d9a558e0 100644 --- a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/TaskModel.kt +++ b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/TaskModel.kt @@ -21,7 +21,7 @@ import hep.dataforge.workspace.TaskModel.Companion.MODEL_TARGET_KEY * @param meta the meta for the task (not for the whole configuration) * @param dependencies a list of direct dependencies for this task */ -data class TaskModel( +public data class TaskModel( val name: Name, val meta: Meta, val dependencies: Collection @@ -45,15 +45,15 @@ data class TaskModel( } } - companion object { - val MODEL_TARGET_KEY = "@target".asName() + public companion object { + public val MODEL_TARGET_KEY = "@target".asName() } } /** * Build input for the task */ -fun TaskModel.buildInput(workspace: Workspace): DataTree { +public fun TaskModel.buildInput(workspace: Workspace): DataTree { return DataTreeBuilder(Any::class).apply { dependencies.forEach { dep -> update(dep.apply(workspace)) @@ -61,43 +61,43 @@ fun TaskModel.buildInput(workspace: Workspace): DataTree { }.build() } -interface TaskDependencyContainer { - val defaultMeta: Meta - fun add(dependency: Dependency) +public interface TaskDependencyContainer { + public val defaultMeta: Meta + public fun add(dependency: Dependency) } /** * Add dependency for a task defined in a workspace and resolved by */ -fun TaskDependencyContainer.dependsOn( +public fun TaskDependencyContainer.dependsOn( name: Name, placement: Name = Name.EMPTY, meta: Meta = defaultMeta ): WorkspaceTaskDependency = WorkspaceTaskDependency(name, meta, placement).also { add(it) } -fun TaskDependencyContainer.dependsOn( +public fun TaskDependencyContainer.dependsOn( name: String, placement: Name = Name.EMPTY, meta: Meta = defaultMeta ): WorkspaceTaskDependency = dependsOn(name.toName(), placement, meta) -fun TaskDependencyContainer.dependsOn( +public fun TaskDependencyContainer.dependsOn( task: Task, placement: Name = Name.EMPTY, meta: Meta = defaultMeta ): DirectTaskDependency = DirectTaskDependency(task, meta, placement).also { add(it) } -fun TaskDependencyContainer.dependsOn( +public fun TaskDependencyContainer.dependsOn( task: Task, placement: String, meta: Meta = defaultMeta ): DirectTaskDependency = DirectTaskDependency(task, meta, placement.toName()).also { add(it) } -fun TaskDependencyContainer.dependsOn( +public fun TaskDependencyContainer.dependsOn( task: Task, placement: Name = Name.EMPTY, metaBuilder: MetaBuilder.() -> Unit @@ -107,13 +107,13 @@ fun TaskDependencyContainer.dependsOn( /** * Add custom data dependency */ -fun TaskDependencyContainer.data(action: DataFilter.() -> Unit): DataDependency = +public fun TaskDependencyContainer.data(action: DataFilter.() -> Unit): DataDependency = DataDependency(DataFilter(action)).also { add(it) } /** * User-friendly way to add data dependency */ -fun TaskDependencyContainer.data(pattern: String? = null, from: String? = null, to: String? = null): DataDependency = +public fun TaskDependencyContainer.data(pattern: String? = null, from: String? = null, to: String? = null): DataDependency = data { pattern?.let { this.pattern = it } from?.let { this.from = it } @@ -123,17 +123,17 @@ fun TaskDependencyContainer.data(pattern: String? = null, from: String? = null, /** * Add all data as root node */ -fun TaskDependencyContainer.allData(to: Name = Name.EMPTY) = AllDataDependency(to).also { add(it) } +public fun TaskDependencyContainer.allData(to: Name = Name.EMPTY): AllDataDependency = AllDataDependency(to).also { add(it) } /** * A builder for [TaskModel] */ -class TaskModelBuilder(val name: Name, meta: Meta = Meta.EMPTY) : TaskDependencyContainer { +public class TaskModelBuilder(public val name: Name, meta: Meta = Meta.EMPTY) : TaskDependencyContainer { /** * Meta for current task. By default uses the whole input meta */ - var meta: MetaBuilder = meta.builder() - val dependencies = HashSet() + public var meta: MetaBuilder = meta.builder() + private val dependencies: HashSet = HashSet() override val defaultMeta: Meta get() = meta @@ -141,11 +141,11 @@ class TaskModelBuilder(val name: Name, meta: Meta = Meta.EMPTY) : TaskDependency dependencies.add(dependency) } - var target: String by this.meta.string(key = MODEL_TARGET_KEY, default = "") + public var target: String by this.meta.string(key = MODEL_TARGET_KEY, default = "") - fun build(): TaskModel = TaskModel(name, meta.seal(), dependencies) + public fun build(): TaskModel = TaskModel(name, meta.seal(), dependencies) } -val TaskModel.target get() = meta[MODEL_TARGET_KEY]?.string ?: "" \ No newline at end of file +public val TaskModel.target: String get() = meta[MODEL_TARGET_KEY]?.string ?: "" \ No newline at end of file diff --git a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/Workspace.kt b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/Workspace.kt index ac2b1131..063ac25d 100644 --- a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/Workspace.kt +++ b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/Workspace.kt @@ -15,21 +15,21 @@ import hep.dataforge.provider.Type @Type(Workspace.TYPE) -interface Workspace : ContextAware, Provider { +public interface Workspace : ContextAware, Provider { /** * The whole data node for current workspace */ - val data: DataNode + public val data: DataNode /** * All targets associated with the workspace */ - val targets: Map + public val targets: Map /** * All tasks associated with the workspace */ - val tasks: Map> + public val tasks: Map> override fun provideTop(target: String): Map { return when (target) { @@ -44,7 +44,7 @@ interface Workspace : ContextAware, Provider { /** * Invoke a task in the workspace utilizing caching if possible */ - fun run(task: Task, config: Meta): DataNode { + public fun run(task: Task, config: Meta): DataNode { context.activate(this) try { val model = task.build(this, config) @@ -55,27 +55,27 @@ interface Workspace : ContextAware, Provider { } } - companion object { - const val TYPE = "workspace" - operator fun invoke(parent: Context = Global, block: SimpleWorkspaceBuilder.() -> Unit): SimpleWorkspace = + public companion object { + public const val TYPE: String = "workspace" + public operator fun invoke(parent: Context = Global, block: SimpleWorkspaceBuilder.() -> Unit): SimpleWorkspace = SimpleWorkspaceBuilder(parent).apply(block).build() } } -fun Workspace.run(task: Task<*>, target: String): DataNode { +public fun Workspace.run(task: Task<*>, target: String): DataNode { val meta = targets[target] ?: error("A target with name $target not found in ${this}") return run(task, meta) } -fun Workspace.run(task: String, target: String) = +public fun Workspace.run(task: String, target: String): DataNode = tasks[task.toName()]?.let { run(it, target) } ?: error("Task with name $task not found") -fun Workspace.run(task: String, meta: Meta) = +public fun Workspace.run(task: String, meta: Meta): DataNode = tasks[task.toName()]?.let { run(it, meta) } ?: error("Task with name $task not found") -fun Workspace.run(task: String, block: MetaBuilder.() -> Unit = {}) = +public fun Workspace.run(task: String, block: MetaBuilder.() -> Unit = {}): DataNode = run(task, Meta(block)) -fun Workspace.run(task: Task, metaBuilder: MetaBuilder.() -> Unit = {}): DataNode = +public fun Workspace.run(task: Task, metaBuilder: MetaBuilder.() -> Unit = {}): DataNode = run(task, Meta(metaBuilder)) \ No newline at end of file diff --git a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/WorkspaceBuilder.kt b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/WorkspaceBuilder.kt index a7da78e0..b7f74079 100644 --- a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/WorkspaceBuilder.kt +++ b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/WorkspaceBuilder.kt @@ -12,25 +12,25 @@ import kotlin.jvm.JvmName import kotlin.reflect.KClass @DFBuilder -interface WorkspaceBuilder { - val parentContext: Context - var context: Context - var data: DataTreeBuilder - var tasks: MutableSet> - var targets: MutableMap +public interface WorkspaceBuilder { + public val parentContext: Context + public var context: Context + public var data: DataTreeBuilder + public var tasks: MutableSet> + public var targets: MutableMap - fun build(): Workspace + public fun build(): Workspace } /** * Set the context for future workspcace */ -fun WorkspaceBuilder.context(name: String = "WORKSPACE", block: ContextBuilder.() -> Unit = {}) { +public fun WorkspaceBuilder.context(name: String = "WORKSPACE", block: ContextBuilder.() -> Unit = {}) { context = ContextBuilder(parentContext, name).apply(block).build() } -inline fun WorkspaceBuilder.data( +public inline fun WorkspaceBuilder.data( name: Name = Name.EMPTY, noinline block: DataTreeBuilder.() -> Unit ): DataNode { @@ -45,20 +45,20 @@ inline fun WorkspaceBuilder.data( } @JvmName("rawData") -fun WorkspaceBuilder.data( +public fun WorkspaceBuilder.data( name: Name = Name.EMPTY, block: DataTreeBuilder.() -> Unit ): DataNode = data(name, block) -fun WorkspaceBuilder.target(name: String, block: MetaBuilder.() -> Unit) { +public fun WorkspaceBuilder.target(name: String, block: MetaBuilder.() -> Unit) { targets[name] = Meta(block).seal() } /** * Use existing target as a base updating it with the block */ -fun WorkspaceBuilder.target(name: String, base: String, block: MetaBuilder.() -> Unit) { +public fun WorkspaceBuilder.target(name: String, base: String, block: MetaBuilder.() -> Unit) { val parentTarget = targets[base] ?: error("Base target with name $base not found") targets[name] = parentTarget.builder() .apply { "@baseTarget" put base } @@ -66,19 +66,19 @@ fun WorkspaceBuilder.target(name: String, base: String, block: MetaBuilder.() -> .seal() } -fun WorkspaceBuilder.task( +public fun WorkspaceBuilder.task( name: String, type: KClass, builder: TaskBuilder.() -> Unit ): Task = TaskBuilder(name.toName(), type).apply(builder).build().also { tasks.add(it) } -inline fun WorkspaceBuilder.task( +public inline fun WorkspaceBuilder.task( name: String, noinline builder: TaskBuilder.() -> Unit ): Task = task(name, T::class, builder) @JvmName("rawTask") -fun WorkspaceBuilder.task( +public fun WorkspaceBuilder.task( name: String, builder: TaskBuilder.() -> Unit ): Task = task(name, Any::class, builder) @@ -86,7 +86,7 @@ fun WorkspaceBuilder.task( /** * A builder for a simple workspace */ -class SimpleWorkspaceBuilder(override val parentContext: Context) : WorkspaceBuilder { +public class SimpleWorkspaceBuilder(override val parentContext: Context) : WorkspaceBuilder { override var context: Context = parentContext override var data: DataTreeBuilder = DataTreeBuilder(Any::class) override var tasks: MutableSet> = HashSet() diff --git a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/WorkspacePlugin.kt b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/WorkspacePlugin.kt index a377c023..f608b59d 100644 --- a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/WorkspacePlugin.kt +++ b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/WorkspacePlugin.kt @@ -9,9 +9,9 @@ import kotlin.reflect.KClass /** * An abstract plugin with some additional boilerplate to effectively work with workspace context */ -abstract class WorkspacePlugin : AbstractPlugin() { +public abstract class WorkspacePlugin : AbstractPlugin() { private val _tasks = HashSet>() - val tasks: Collection> get() = _tasks + public val tasks: Collection> get() = _tasks override fun provideTop(target: String): Map { return when (target) { @@ -20,11 +20,11 @@ abstract class WorkspacePlugin : AbstractPlugin() { } } - fun task(task: Task<*>){ + public fun task(task: Task<*>){ _tasks.add(task) } - fun task( + public fun task( name: String, type: KClass, builder: TaskBuilder.() -> Unit @@ -32,7 +32,7 @@ abstract class WorkspacePlugin : AbstractPlugin() { _tasks.add(it) } - inline fun task( + public inline fun task( name: String, noinline builder: TaskBuilder.() -> Unit ) = task(name, T::class, builder) diff --git a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/envelopeData.kt b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/envelopeData.kt index 248e819c..461409e2 100644 --- a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/envelopeData.kt +++ b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/envelopeData.kt @@ -8,11 +8,11 @@ import kotlin.reflect.KClass /** * Convert an [Envelope] to a data via given format. The actual parsing is done lazily. */ -fun Envelope.toData(type: KClass, format: IOFormat): Data = Data(type, meta) { +public fun Envelope.toData(type: KClass, format: IOFormat): Data = Data(type, meta) { data?.readWith(format) ?: error("Can't convert envelope without data to Data") } -suspend fun Data.toEnvelope(format: IOFormat): Envelope { +public suspend fun Data.toEnvelope(format: IOFormat): Envelope { val obj = await() val binary = format.toBinary(obj) return SimpleEnvelope(meta, binary)