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

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

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  tableSchemaImpl(
    rowsSchema: ClassSchema,
    isNullable: Boolean,
    initialValue: Array?,
    computedInitialValue: InitialValue?>?,
    computedValue: ComputedValue?>?,
    mismatchedComputedCode: String?,
    isClientOnly: Boolean?,
    isRequired: Boolean?,
    computedIsRequired: IsRequired?,
    isRequiredCode: String?,
    allowedValues: List>?,
    computedAllowedValues: AllowedValues>?,
    disallowedValueCode: String?,
    minSize: Int?,
    computedMinSize: Bound?,
    minSizeCode: String?,
    maxSize: Int?,
    computedMaxSize: Bound?,
    maxSizeCode: String?,
    validations: List>>?,
    initialState: Map?,
    extra: Map?
): Schema?> {
    val schema = js("{}") as Schema?>

    schema.asDynamic().rowsSchema = rowsSchema

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

    schema.asDynamic().minSize =
        when {
            minSize != null -> minSize
            computedMinSize != null -> toStorageBound(computedMinSize)
            else -> undefined
        }
    schema.asDynamic().minSizeCode = minSizeCode ?: undefined
    schema.asDynamic().maxSize =
        when {
            maxSize != null -> maxSize
            computedMaxSize != null -> toStorageBound(computedMaxSize)
            else -> undefined
        }
    schema.asDynamic().maxSizeCode = maxSizeCode ?: undefined

    return schema
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy