Skip to content

Commit

Permalink
fix: use JsMap wrapper (JS component) (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
vgarciabnz authored Apr 10, 2024
1 parent 657a867 commit fff002a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
6 changes: 5 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ kotlin {
}
val jvmMain by getting
val jvmTest by getting
val jsMain by getting
val jsMain by getting {
dependencies {
api("org.jetbrains.kotlin-wrappers:kotlin-js:1.0.0-pre.722")
}
}
val jsTest by getting
val nativeMain by getting
val nativeTest by getting
Expand Down
5 changes: 0 additions & 5 deletions src/jsMain/kotlin/org.hisp.dhis.lib.expression.js/Entry.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.hisp.dhis.lib.expression.js

import js.collections.JsMap

@OptIn(ExperimentalJsExport::class)
@JsExport
data class ExpressionDataJs(
val programRuleVariableValues: Array<Entry<String, VariableValueJs>> = emptyArray(),
val programVariableValues: Array<Entry<String, Any>> = emptyArray(),
val supplementaryValues: Array<Entry<String, Array<String>>> = emptyArray(),
val dataItemValues: Array<Entry<DataItemJs, Any>> = emptyArray(),
val namedValues: Array<Entry<String, Any>> = emptyArray()
val programRuleVariableValues: JsMap<String, VariableValueJs> = JsMap(),
val programVariableValues: JsMap<String, Any> = JsMap(),
val supplementaryValues: JsMap<String, Array<String>> = JsMap(),
val dataItemValues: JsMap<DataItemJs, Any> = JsMap(),
val namedValues: JsMap<String, Any> = JsMap()
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.hisp.dhis.lib.expression.js

import js.collections.JsMap
import kotlinx.datetime.LocalDate
import org.hisp.dhis.lib.expression.Expression
import org.hisp.dhis.lib.expression.ast.AggregationType
Expand Down Expand Up @@ -41,19 +42,19 @@ class ExpressionJs(expression: String, mode: String) {
return expr.collectUIDs().map(::toIdJS).toTypedArray()
}

fun describe(displayNames: Array<Entry<String, String>>): String {
fun describe(displayNames: JsMap<String, String>): String {
return expr.describe(toMap(displayNames, { it }, { it }))
}

fun validate(displayNamesKeys: Array<Entry<String, String>>) {
fun validate(displayNamesKeys: JsMap<String, String>) {
expr.validate(toMap(displayNamesKeys, { it }, { e -> ValueType.valueOf(e) }))
}

fun collectDataItemForRegenerate(): Array<DataItemJs> {
return expr.collectDataItemForRegenerate().map(::toDataItemJS).toTypedArray()
}

fun regenerate(dataItemValues: Array<Entry<DataItemJs, Double>>): String {
fun regenerate(dataItemValues: JsMap<DataItemJs, Double>): String {
return expr.regenerate(toMap(dataItemValues, ::toDataItemJava) { it })
}

Expand All @@ -68,9 +69,9 @@ class ExpressionJs(expression: String, mode: String) {
companion object {
val MODES = Expression.Mode.entries.map { it.name }.toTypedArray()

internal fun <Kf, Vf, K, V> toMap(map: Array<Entry<Kf, Vf>>, key: (Kf) -> K, value: (Vf) -> V): Map<K, V> {
internal fun <Kf, Vf, K, V> toMap(map: JsMap<Kf, Vf>, key: (Kf) -> K, value: (Vf) -> V): Map<K, V> {
val res : MutableMap<K, V> = mutableMapOf()
map.forEach { e -> res[key(e.key)] = value(e.value) }
map.forEach { v, k -> res[key(k)] = value(v) }
return res;
}

Expand Down

0 comments on commit fff002a

Please sign in to comment.