jsMain.schemas.ClassSchema.kt Maven / Gradle / Ivy
package pt.lightweightform.lfkotlin.schemas
import kotlin.reflect.KClass
import kotlin.reflect.KMutableProperty1
import pt.lightweightform.lfkotlin.AllowedValues
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
public actual external interface ClassSchema : Schema {
public actual var kClass: KClass
public actual var childInfoByName: Map>
public actual var constructorFunction: ConstructorFunction?
public var fieldsSchemas: dynamic
}
@Suppress("UNCHECKED_CAST", "UNCHECKED_CAST_TO_EXTERNAL_INTERFACE")
public actual fun classSchemaImpl(
kClass: KClass,
childrenSchemas: Map, Schema<*>>,
constructorFunction: ConstructorFunction?,
isNullable: Boolean,
initialValue: T?,
computedInitialValue: InitialValue?,
computedValue: ComputedValue?,
mismatchedComputedCode: String?,
isClientOnly: Boolean?,
isRequired: Boolean?,
computedIsRequired: IsRequired?,
isRequiredCode: String?,
allowedValues: List?,
computedAllowedValues: AllowedValues?,
disallowedValueCode: String?,
validations: List>?,
initialState: Map?,
extra: Map?
): ClassSchema {
val schema = js("{}") as ClassSchema
schema.kClass = kClass as KClass
schema.constructorFunction = constructorFunction
val childInfoByName = mutableMapOf>()
for ((prop, childSchema) in childrenSchemas) {
childInfoByName[prop.name] = ChildInfo(prop, childSchema)
}
schema.childInfoByName = childInfoByName as Map>
schema.fieldsSchemas = js("{}")
for ((prop, childSchema) in childrenSchemas) {
schema.fieldsSchemas[prop.name] = childSchema
}
return addCommonPropsToSchema(
schema,
"record",
isNullable,
initialValue,
computedInitialValue,
computedValue,
isClientOnly,
isRequired,
computedIsRequired,
isRequiredCode,
allowedValues,
computedAllowedValues,
disallowedValueCode,
validations,
initialState,
extra
)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy