Schemas & Reactive Forms (crow-schema)
Zod-style Kotlin validation DSL with typed ParseResults, cross-field rules, signal-backed FormState, and JSON Schema export.
crow-schema brings a concise, composable Zod-style validation DSL directly to Kotlin — paired with a fine-grained FormState where every field's value, error, touched, dirty, valid, and async-validating status is a reactive Signal / Read.
Building Schemas
val emailSchema = Schemas.string()
.trim()
.email("Enter a valid email address")
val doseSchema = Schemas.int()
.min(10, "Minimum dose is 10g")
.max(40, "Maximum dose is 40g")
val titleSchema = Schemas.string()
.trim()
.min(1, "Title is required")
.max(60, "Keep title under 60 characters")Call schema.safeParse(input) anywhere (UI, network layer, tests) for typed ParseResult.Success<T> / ParseResult.Failure with structured error paths — or call schema.toJsonSchema() to emit standard JSON Schema definitions.
Signal-Backed FormState
Bind schemas directly to Crow inputs so each field validates independently with zero whole-form recomposition:
@Ui
fun LogBrewForm(@Once onSaved: (String, String) -> Unit) {
val form = FormState(mode = ValidationMode.OnChange)
onCleanup { form.dispose() }
val title = form.field("title", "", titleSchema)
val notes = form.field("notes", "", Schemas.string().trim().max(240))
// Cross-field validation runs reactively alongside individual fields
form.crossField("notes", "Add notes when logging a custom blend") {
!(title.value.value.contains("Blend", ignoreCase = true) && notes.value.value.isBlank())
}
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
OutlinedTextField(
value = title.value,
label = { Text("Brew title") },
isError = title.error.value != null,
supportingText = { Text(title.error.value ?: "") },
)
Button(
onClick = { form.submit { onSaved(title.value.value, notes.value.value) } },
enabled = form.isValid.value && !form.isSubmitting.value,
) {
Text("Save Brew")
}
}
}Features
- Validation modes:
OnChange,OnBlur,OnTouched, orOnSubmitper form. - Async field validators: Attach
AsyncFieldValidator(e.g., username availability checks) with automatic cancellation andfield.validatingstatus signal. - External errors: Surface server-side validation messages directly onto any field with
field.setExternalError("Already taken"). - Pure JVM:
crow-schemahas zero Android dependencies (checkCorePurityverified).
How is this guide?
Local Reactive Store (crow-store)
Platform-free reactive key/document persistence with fine-grained Signal keys, reflection-free codecs, transactions, migrations, and atomic file writes.
Perceptual Color & Palettes (crow-color)
OKLab and OKLCH color spaces, WCAG 2.1 and APCA contrast solvers, color harmonies, tonal ramps, and artwork palette extraction.