commonMain.schemas.AnySchema.kt Maven / Gradle / Ivy
package io.kform.schemas
import io.kform.TypeInfo
import io.kform.Validation
import io.kform.schemas.util.commonRestrictions
/** Function responsible for creating a clone of a value of this schema. */
public typealias CloneFunction = (value: T?) -> T?
/**
* "Catch-all" schema representing (possibly nullable) values of any given type.
*
* @property clone Function used to create a clone of a value of this schema.
*/
public open class AnySchema(
validations: Iterable> = emptyList(),
override val initialValue: T? = null,
public val clone: CloneFunction? = null
) : AbstractSimpleSchema(validations) {
public constructor(
vararg validations: Validation,
initialValue: T? = null,
clone: CloneFunction? = null
) : this(validations.toList(), initialValue, clone)
override val typeInfo: TypeInfo =
TypeInfo(Any::class, nullable = true, restrictions = commonRestrictions(validations))
override suspend fun clone(value: T?): T? = clone?.invoke(value) ?: value
}