commonMain.internal.actions.GetExternalContextAction.kt Maven / Gradle / Ivy
package io.kform.internal.actions
import io.kform.AbsolutePath
import io.kform.ExternalContextHandler
import io.kform.FormManager
import io.kform.internal.AccessExternalContext
import io.kform.internal.ActionAccessType
/**
* Action that returns the external context with name [externalContextName] available to
* validations.
*/
internal class GetExternalContextAction(
formManager: FormManager,
private val externalContextName: String,
private val externalContextHandler: ExternalContextHandler
) : FormManagerAction(formManager) {
override fun toString() = "GetExternalContext($externalContextName)"
override val accesses = listOf(AccessExternalContext(ActionAccessType.Read))
override val accessedPaths: List = emptyList()
override suspend fun run(): T =
@Suppress("UNCHECKED_CAST")
externalContextHandler(formManager.externalContexts[externalContextName] as TContext)
}