PatchField

sealed interface PatchField<out T>(source)

A property of an update command that tells "not supplied" (Unset) apart from "supplied, possibly as null" (Value).

Gives update commands PATCH semantics: only supplied fields are touched and a field can be explicitly cleared. Has no persistence dependencies, so it can also be used by an HTTP layer.

Inheritors

Types

Link copied to clipboard
data object Unset : PatchField<Nothing>

The field was not supplied.

Link copied to clipboard
data class Value<T>(val value: T?) : PatchField<T>

The field was supplied, value may be null.

Properties

Link copied to clipboard

True for Value, false for Unset.

Functions

Link copied to clipboard
fun <T> PatchField<T>.nullAs(replacement: T): PatchField<T>

Returns Value of replacement for Value(null), otherwise this field unchanged.

Link copied to clipboard
fun <T> PatchField<T>.orKeep(current: T?): T?

Returns current for Unset, otherwise the supplied value (even when null).

Link copied to clipboard
fun <T> PatchField<T>.orKeepRequired(current: T, fieldName: String): T

Same as orKeep for a field that must never be null.

Link copied to clipboard

Returns the supplied collection, or null if the group must not be touched (PatchField.Unset).

Link copied to clipboard

Same as toTargetIdsOrNull for elements that already are raw ids.

fun <T, R> PatchField<Collection<T>?>.toTargetIdsOrNull(transform: (T) -> R): Set<R>?

Converts this field to the set of target ids a junction relation must be synced to, or null if the relation must not be touched (PatchField.Unset).