Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
@file:JvmName("AsyncValidationRunner")
package io.kform.test
import io.kform.*
import io.kform.schemas.AnySchema
import java.util.concurrent.CompletableFuture
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.future.future
/** Default coroutine scope for running validations within futures. */
private val defaultScope =
CoroutineScope(Dispatchers.Default + CoroutineName("Async validation runner"))
/**
* Runs a given [validation] within a form with schema [formSchema] and returns a future that
* completes with a list of its issues.
*
* It is necessary to provide all information required to run the validation: the [path] of the
* value being validated, the [value] itself, the [values of the dependencies][dependencyValues] (by
* dependency name), and the values of the [external contexts][externalContexts] that the validation
* depends on.
*
* If the validation depends on values within the value being validated, then these may be omitted
* from the provided [dependencyValues].
*
* Otherwise, missing dependencies or external contexts will be passed to the validation as `null`,
* in which case the validation may or may not throw depending on its implementation.
*
* Exceptions thrown while running the validation will not be caught by this function. As opposed to
* how a [form validator][FormValidator] or [form manager][FormManager] operate, exceptions are
* **not** wrapped in a [ValidationExceptionError] nor emitted as part of the issues flow.
*
* The future will complete exceptionally with [InvalidPathException] if [path] matches no schemas,
* with [InvalidDependencyPathException] if [validation] contains an invalid dependency, or with
* [IllegalArgumentException] when providing unknown names for [dependencyValues] or
* [externalContexts] or when providing mismatching dependency values for dependencies within
* [value].
*/
@JvmOverloads
@JvmName("runValidation")
public fun runValidationAsync(
formSchema: Schema<*>,
validation: Validation,
value: T,
path: Path = AbsolutePath.ROOT,
dependencyValues: Map? = null,
externalContexts: ExternalContexts? = null,
coroutineScope: CoroutineScope = defaultScope
): CompletableFuture> =
coroutineScope.future {
runValidation(formSchema, validation, value, path, dependencyValues, externalContexts)
.toList()
}
/**
* Runs a given [validation] within a form with schema [formSchema] and returns a future that
* completes with a list of its issues.
*
* It is necessary to provide all information required to run the validation: the [path] of the
* value being validated, the [value] itself, the [values of the dependencies][dependencyValues] (by
* dependency name), and the values of the [external contexts][externalContexts] that the validation
* depends on.
*
* If the validation depends on values within the value being validated, then these may be omitted
* from the provided [dependencyValues].
*
* Otherwise, missing dependencies or external contexts will be passed to the validation as `null`,
* in which case the validation may or may not throw depending on its implementation.
*
* Exceptions thrown while running the validation will not be caught by this function. As opposed to
* how a [form validator][FormValidator] or [form manager][FormManager] operate, exceptions are
* **not** wrapped in a [ValidationExceptionError] nor emitted as part of the issues flow.
*
* The future will complete exceptionally with [InvalidPathException] if [path] matches no schemas,
* with [InvalidDependencyPathException] if [validation] contains an invalid dependency, or with
* [IllegalArgumentException] when providing unknown names for [dependencyValues] or
* [externalContexts] or when providing mismatching dependency values for dependencies within
* [value].
*/
@JvmOverloads
@JvmName("runValidation")
public fun runValidationAsync(
formSchema: Schema<*>,
validation: Validation,
value: T,
path: String,
dependencyValues: Map? = null,
externalContexts: ExternalContexts? = null,
coroutineScope: CoroutineScope = defaultScope
): CompletableFuture> =
runValidationAsync(
formSchema,
validation,
value,
AbsolutePath(path),
dependencyValues,
externalContexts,
coroutineScope
)
/**
* Runs a given [validation] within a form with a schema of type [AnySchema] and returns a future
* that completes with a list of its issues.
*
* It is necessary to provide all information required to run the validation: the [path] of the
* value being validated, the [value] itself, the [values of the dependencies][dependencyValues] (by
* dependency name), and the values of the [external contexts][externalContexts] that the validation
* depends on.
*
* If the validation depends on values within the value being validated, then these may be omitted
* from the provided [dependencyValues].
*
* Otherwise, missing dependencies or external contexts will be passed to the validation as `null`,
* in which case the validation may or may not throw depending on its implementation.
*
* Exceptions thrown while running the validation will not be caught by this function. As opposed to
* how a [form validator][FormValidator] or [form manager][FormManager] operate, exceptions are
* **not** wrapped in a [ValidationExceptionError] nor emitted as part of the issues flow.
*
* The future will complete exceptionally with [InvalidPathException] if [path] matches no schemas,
* with [InvalidDependencyPathException] if [validation] contains an invalid dependency, or with
* [IllegalArgumentException] when providing unknown names for [dependencyValues] or
* [externalContexts] or when providing mismatching dependency values for dependencies within
* [value].
*/
@JvmOverloads
@JvmName("runValidation")
public fun runValidationAsync(
validation: Validation,
value: T,
path: Path = AbsolutePath.ROOT,
dependencyValues: Map? = null,
externalContexts: ExternalContexts? = null,
coroutineScope: CoroutineScope = defaultScope
): CompletableFuture> =
coroutineScope.future {
runValidation(validation, value, path, dependencyValues, externalContexts).toList()
}
/**
* Runs a given [validation] within a form with a schema of type [AnySchema] and returns a future
* that completes with a list of its issues.
*
* It is necessary to provide all information required to run the validation: the [path] of the
* value being validated, the [value] itself, the [values of the dependencies][dependencyValues] (by
* dependency name), and the values of the [external contexts][externalContexts] that the validation
* depends on.
*
* If the validation depends on values within the value being validated, then these may be omitted
* from the provided [dependencyValues].
*
* Otherwise, missing dependencies or external contexts will be passed to the validation as `null`,
* in which case the validation may or may not throw depending on its implementation.
*
* Exceptions thrown while running the validation will not be caught by this function. As opposed to
* how a [form validator][FormValidator] or [form manager][FormManager] operate, exceptions are
* **not** wrapped in a [ValidationExceptionError] nor emitted as part of the issues flow.
*
* The future will complete exceptionally with [InvalidPathException] if [path] matches no schemas,
* with [InvalidDependencyPathException] if [validation] contains an invalid dependency, or with
* [IllegalArgumentException] when providing unknown names for [dependencyValues] or
* [externalContexts] or when providing mismatching dependency values for dependencies within
* [value].
*/
@JvmOverloads
@JvmName("runValidation")
public fun runValidationAsync(
validation: Validation,
value: T,
path: String,
dependencyValues: Map? = null,
externalContexts: ExternalContexts? = null,
coroutineScope: CoroutineScope = defaultScope
): CompletableFuture> =
runValidationAsync(
validation,
value,
AbsolutePath(path),
dependencyValues,
externalContexts,
coroutineScope
)