All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jsMain.schemas.IntSchema.kt Maven / Gradle / Ivy

There is a newer version: 4.10.0-legacy-ie11
Show newest version
package pt.lightweightform.lfkotlin.schemas

import pt.lightweightform.lfkotlin.AllowedValues
import pt.lightweightform.lfkotlin.Bound
import pt.lightweightform.lfkotlin.ComputedValue
import pt.lightweightform.lfkotlin.InitialValue
import pt.lightweightform.lfkotlin.IsRequired
import pt.lightweightform.lfkotlin.Schema
import pt.lightweightform.lfkotlin.Validation
import pt.lightweightform.lfkotlin.internal.addCommonPropsToSchema
import pt.lightweightform.lfkotlin.internal.toStorageBound

@Suppress("UNCHECKED_CAST_TO_EXTERNAL_INTERFACE")
internal actual fun intSchemaImpl(
    isNullable: Boolean,
    initialValue: Int?,
    computedInitialValue: InitialValue?,
    computedValue: ComputedValue?,
    mismatchedComputedCode: String?,
    isClientOnly: Boolean?,
    isRequired: Boolean?,
    computedIsRequired: IsRequired?,
    isRequiredCode: String?,
    allowedValues: List?,
    computedAllowedValues: AllowedValues?,
    disallowedValueCode: String?,
    min: Int?,
    computedMin: Bound?,
    minCode: String?,
    max: Int?,
    computedMax: Bound?,
    maxCode: String?,
    validations: List>?,
    initialState: Map?,
    extra: Map?
): Schema {
    val schema = js("{}") as Schema

    schema.asDynamic().isInteger = true

    addCommonPropsToSchema(
        schema,
        "number",
        isNullable,
        initialValue,
        computedInitialValue,
        computedValue,
        isClientOnly,
        isRequired,
        computedIsRequired,
        isRequiredCode,
        allowedValues,
        computedAllowedValues,
        disallowedValueCode,
        validations,
        initialState,
        extra
    )

    schema.asDynamic().min =
        when {
            min != null -> min
            computedMin != null -> toStorageBound(computedMin)
            else -> Int.MIN_VALUE
        }
    schema.asDynamic().minCode = minCode ?: undefined
    schema.asDynamic().max =
        when {
            max != null -> max
            computedMax != null -> toStorageBound(computedMax)
            else -> Int.MAX_VALUE
        }
    schema.asDynamic().maxCode = maxCode ?: undefined

    return schema
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy