divkit.dsl.Patch.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-json-builder Show documentation
Show all versions of kotlin-json-builder Show documentation
DivKit is an open source Server-Driven UI (SDUI) framework. SDUI is a an emerging technique that leverage the server to build the user interfaces of their mobile app.
@file:Suppress(
"unused",
"UNUSED_PARAMETER",
)
package divkit.dsl
import com.fasterxml.jackson.annotation.JsonAnyGetter
import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonValue
import divkit.dsl.annotation.*
import divkit.dsl.core.*
import divkit.dsl.scope.*
import kotlin.Any
import kotlin.String
import kotlin.Suppress
import kotlin.collections.List
import kotlin.collections.Map
/**
* Edits the element.
*
* Can be created using the method [patch].
*
* Required parameters: `changes`.
*/
@Generated
class Patch internal constructor(
@JsonIgnore
val properties: Properties,
) {
@JsonAnyGetter
internal fun getJsonProperties(): Map = properties.mergeWith(emptyMap())
class Properties internal constructor(
/**
* Element changes.
*/
val changes: Property>?,
/**
* Procedure for applying changes:`transactional` — if an error occurs during application of at least one element, the changes aren't applied. `partial` — all possible changes are applied. If there are errors, they are reported.
* Default value: `partial`.
*/
val mode: Property?,
/**
* Actions after applying patch.
*/
val onAppliedActions: Property>?,
/**
* Actions after an error applying patch in transactional mode.
*/
val onFailedActions: Property>?,
) {
internal fun mergeWith(properties: Map): Map {
val result = mutableMapOf()
result.putAll(properties)
result.tryPutProperty("changes", changes)
result.tryPutProperty("mode", mode)
result.tryPutProperty("on_applied_actions", onAppliedActions)
result.tryPutProperty("on_failed_actions", onFailedActions)
return result
}
}
/**
* Procedure for applying changes:`transactional` — if an error occurs during application of at least one element, the changes aren't applied. `partial` — all possible changes are applied. If there are errors, they are reported.
*
* Possible values: [transactional], [partial].
*/
@Generated
sealed interface Mode
/**
* Can be created using the method [patchChange].
*
* Required parameters: `id`.
*/
@Generated
class Change internal constructor(
@JsonIgnore
val properties: Properties,
) {
@JsonAnyGetter
internal fun getJsonProperties(): Map = properties.mergeWith(emptyMap())
operator fun plus(additive: Properties): Change = Change(
Properties(
id = additive.id ?: properties.id,
items = additive.items ?: properties.items,
)
)
class Properties internal constructor(
/**
* ID of an element to be replaced or removed.
*/
val id: Property?,
/**
* Elements to be inserted. If the parameter isn't specified, the element will be removed.
*/
val items: Property>?,
) {
internal fun mergeWith(properties: Map): Map {
val result = mutableMapOf()
result.putAll(properties)
result.tryPutProperty("id", id)
result.tryPutProperty("items", items)
return result
}
}
}
}
/**
* @param changes Element changes.
* @param mode Procedure for applying changes:`transactional` — if an error occurs during application of at least one element, the changes aren't applied. `partial` — all possible changes are applied. If there are errors, they are reported.
* @param onAppliedActions Actions after applying patch.
* @param onFailedActions Actions after an error applying patch in transactional mode.
*/
@Generated
fun DivScope.patch(
`use named arguments`: Guard = Guard.instance,
changes: List,
mode: Patch.Mode? = null,
onAppliedActions: List? = null,
onFailedActions: List? = null,
): Patch = Patch(
Patch.Properties(
changes = valueOrNull(changes),
mode = valueOrNull(mode),
onAppliedActions = valueOrNull(onAppliedActions),
onFailedActions = valueOrNull(onFailedActions),
)
)
/**
* @param changes Element changes.
* @param mode Procedure for applying changes:`transactional` — if an error occurs during application of at least one element, the changes aren't applied. `partial` — all possible changes are applied. If there are errors, they are reported.
* @param onAppliedActions Actions after applying patch.
* @param onFailedActions Actions after an error applying patch in transactional mode.
*/
@Generated
fun DivScope.patchProps(
`use named arguments`: Guard = Guard.instance,
changes: List? = null,
mode: Patch.Mode? = null,
onAppliedActions: List? = null,
onFailedActions: List? = null,
) = Patch.Properties(
changes = valueOrNull(changes),
mode = valueOrNull(mode),
onAppliedActions = valueOrNull(onAppliedActions),
onFailedActions = valueOrNull(onFailedActions),
)
/**
* @param changes Element changes.
* @param mode Procedure for applying changes:`transactional` — if an error occurs during application of at least one element, the changes aren't applied. `partial` — all possible changes are applied. If there are errors, they are reported.
* @param onAppliedActions Actions after applying patch.
* @param onFailedActions Actions after an error applying patch in transactional mode.
*/
@Generated
fun TemplateScope.patchRefs(
`use named arguments`: Guard = Guard.instance,
changes: ReferenceProperty>? = null,
mode: ReferenceProperty? = null,
onAppliedActions: ReferenceProperty>? = null,
onFailedActions: ReferenceProperty>? = null,
) = Patch.Properties(
changes = changes,
mode = mode,
onAppliedActions = onAppliedActions,
onFailedActions = onFailedActions,
)
/**
* @param changes Element changes.
* @param mode Procedure for applying changes:`transactional` — if an error occurs during application of at least one element, the changes aren't applied. `partial` — all possible changes are applied. If there are errors, they are reported.
* @param onAppliedActions Actions after applying patch.
* @param onFailedActions Actions after an error applying patch in transactional mode.
*/
@Generated
fun Patch.override(
`use named arguments`: Guard = Guard.instance,
changes: List? = null,
mode: Patch.Mode? = null,
onAppliedActions: List? = null,
onFailedActions: List? = null,
): Patch = Patch(
Patch.Properties(
changes = valueOrNull(changes) ?: properties.changes,
mode = valueOrNull(mode) ?: properties.mode,
onAppliedActions = valueOrNull(onAppliedActions) ?: properties.onAppliedActions,
onFailedActions = valueOrNull(onFailedActions) ?: properties.onFailedActions,
)
)
/**
* @param changes Element changes.
* @param mode Procedure for applying changes:`transactional` — if an error occurs during application of at least one element, the changes aren't applied. `partial` — all possible changes are applied. If there are errors, they are reported.
* @param onAppliedActions Actions after applying patch.
* @param onFailedActions Actions after an error applying patch in transactional mode.
*/
@Generated
fun Patch.defer(
`use named arguments`: Guard = Guard.instance,
changes: ReferenceProperty>? = null,
mode: ReferenceProperty? = null,
onAppliedActions: ReferenceProperty>? = null,
onFailedActions: ReferenceProperty>? = null,
): Patch = Patch(
Patch.Properties(
changes = changes ?: properties.changes,
mode = mode ?: properties.mode,
onAppliedActions = onAppliedActions ?: properties.onAppliedActions,
onFailedActions = onFailedActions ?: properties.onFailedActions,
)
)
/**
* @param mode Procedure for applying changes:`transactional` — if an error occurs during application of at least one element, the changes aren't applied. `partial` — all possible changes are applied. If there are errors, they are reported.
*/
@Generated
fun Patch.evaluate(
`use named arguments`: Guard = Guard.instance,
mode: ExpressionProperty? = null,
): Patch = Patch(
Patch.Properties(
changes = properties.changes,
mode = mode ?: properties.mode,
onAppliedActions = properties.onAppliedActions,
onFailedActions = properties.onFailedActions,
)
)
@Generated
fun Patch.asList() = listOf(this)
/**
* @param id ID of an element to be replaced or removed.
* @param items Elements to be inserted. If the parameter isn't specified, the element will be removed.
*/
@Generated
fun DivScope.patchChange(
`use named arguments`: Guard = Guard.instance,
id: String? = null,
items: List? = null,
): Patch.Change = Patch.Change(
Patch.Change.Properties(
id = valueOrNull(id),
items = valueOrNull(items),
)
)
/**
* @param id ID of an element to be replaced or removed.
* @param items Elements to be inserted. If the parameter isn't specified, the element will be removed.
*/
@Generated
fun DivScope.patchChangeProps(
`use named arguments`: Guard = Guard.instance,
id: String? = null,
items: List? = null,
) = Patch.Change.Properties(
id = valueOrNull(id),
items = valueOrNull(items),
)
/**
* @param id ID of an element to be replaced or removed.
* @param items Elements to be inserted. If the parameter isn't specified, the element will be removed.
*/
@Generated
fun TemplateScope.patchChangeRefs(
`use named arguments`: Guard = Guard.instance,
id: ReferenceProperty? = null,
items: ReferenceProperty>? = null,
) = Patch.Change.Properties(
id = id,
items = items,
)
/**
* @param id ID of an element to be replaced or removed.
* @param items Elements to be inserted. If the parameter isn't specified, the element will be removed.
*/
@Generated
fun Patch.Change.override(
`use named arguments`: Guard = Guard.instance,
id: String? = null,
items: List? = null,
): Patch.Change = Patch.Change(
Patch.Change.Properties(
id = valueOrNull(id) ?: properties.id,
items = valueOrNull(items) ?: properties.items,
)
)
/**
* @param id ID of an element to be replaced or removed.
* @param items Elements to be inserted. If the parameter isn't specified, the element will be removed.
*/
@Generated
fun Patch.Change.defer(
`use named arguments`: Guard = Guard.instance,
id: ReferenceProperty? = null,
items: ReferenceProperty>? = null,
): Patch.Change = Patch.Change(
Patch.Change.Properties(
id = id ?: properties.id,
items = items ?: properties.items,
)
)
@Generated
fun Patch.Change.asList() = listOf(this)
@Generated
fun Patch.Mode.asList() = listOf(this)
© 2015 - 2024 Weber Informatics LLC | Privacy Policy