Validator

abstract class Validator<D, M : ValidationMessage, T>

Describes the logic for validating a given data-model. By implementing this you must describe, how a certain data-model should be validated. This is done by returning a List of ValidationMessages in the validate functions.

It is recommended to put the concrete implementation of this Validator right next to your data classes in the commonMain section of your Kotlin multiplatform project. Then you can write the validation logic once and use them in the JS and JVM world.

Constructors

Validator
Link copied to clipboard
fun Validator()

Functions

filter
Link copied to clipboard
js
fun filter(predicate: (M) -> Boolean): Flow<List<M>>
Returns a Flow of list containing only ValidationMessages matching the given predicate.
find
Link copied to clipboard
js
fun find(predicate: (M) -> Boolean): Flow<M?>
Finds the first ValidationMessage matching the given predicate.
isValid
Link copied to clipboard
js
fun isValid(data: D, metadata: T): Boolean
validates the given model by using the validate functions which must be implemented with the validation rules.
fun isValid(data: D, metadata: T): Boolean
evaluates the List of ValidationMessage to see if your data is valid or not
reset
Link copied to clipboard
js
fun reset(messages: List<M> = emptyList())
Resets the validation result.
fun reset(messages: List<M> = emptyList())
Resets the validation result.
validate
Link copied to clipboard
common
abstract fun validate(data: D, metadata: T): List<M>
method that has to be implemented to describe the validation-rules
js
abstract fun validate(data: D, metadata: T): List<M>
validates the given data by using the given metadata and returns a List of ValidationMessages.
abstract fun validate(data: D, metadata: T): List<M>

Properties

current
Link copied to clipboard
js
val current: List<M>
Represents the current List of ValidationMessages.
current
Link copied to clipboard
val current: List<M>
Represents the current List of ValidationMessages.
data
Link copied to clipboard
js
val data: Flow<List<M>>
Gives a Flow of ValidationMessages which gets updated every time when isValid gets called.
isValid
Link copied to clipboard
js
val isValid: Flow<Boolean>
A Flow representing the current state of the model (valid or not).