dave08
10/17/2023, 1:47 PMval validateInstallActionList = dev.nesk.akkurate.Validator<List<InstallAction>> {
// ....?
}
(notice that Intellij had troubles importing Validator
...?)dave08
10/17/2023, 3:22 PMdave08
10/18/2023, 12:45 PMRonny BrΓ€unlich
10/20/2023, 6:34 AMValidationResult
class instead of e.g. using Arrow's Either
. I guess the latter would make for a better interoperability.dave08
10/29/2023, 10:36 AM.bind()
and function with Raise
that returns the success's value, or raises the error or exception... but then maybe both error types should be encapsulated in their own sealed interface? That would avoid the overhead of having to convert to Either just to bind or raise etc...Johann Pardanaud
10/30/2023, 1:18 PMValidator<List<Any>?> { each { ... } }
β’ The configuration of a Validator
has been revamped to a DSL builder.
What to expect in the next weeks π¦
β’ Better documentation: Kdoc for every public symbol, and server validation tutorials
β’ The first integration in a long series: arrow ArrowJohann Pardanaud
11/11/2023, 6:03 PMrocketraman
11/14/2023, 2:47 PMPATCH
is impossible to do with the same types, because the incoming data is incomplete, so even if the server-side code can deserialize it (unlikely), we still need to know which subset of fields was actually sent by the client.
I had implemented https://github.com/rocketraman/kpropmap to deal with these scenarios in the past. The idea is to receive the data from the API in a flexible way, and then do validation and conversion to the strongly typed model on the server-side.
Any thoughts on introducing a similar capability to Akkurate? I've long wanted, but haven't had the time to have kpropmap use KSP and kotlinx-serialization rather than runtime reflection, and Akkurate already uses these tools.Johann Pardanaud
11/17/2023, 4:04 PMJohann Pardanaud
11/17/2023, 4:05 PMJohann Pardanaud
11/29/2023, 12:44 PMJohann Pardanaud
12/06/2023, 11:32 AMJohann Pardanaud
12/12/2023, 1:22 PMJohann Pardanaud
12/12/2023, 4:49 PMdave08
12/25/2023, 10:39 AMValidator { }
that generates a Raise<NonEmptySet<ConstraintViolation>>.() -> T
that way it could be used in an either without toEither()
and bind(..)
?Johann Pardanaud
02/09/2024, 1:57 PMJohann Pardanaud
05/27/2024, 8:56 AMhashtags.each {
// Trim hashtags for leading "#", and only then ensure that it's not empty
map { it.trimStart('#') }.isNotEmpty()
}
New constraints:
// Validate the type of a value
someValue.isInstanceOf<String>()
// Validate elements are unique in a collection
someCollection.hasNoDuplicates()
It is now easier than ever to validate a specific index of a collection:
someCollection.first().isNotEmpty()
someCollection.last().isNotEmpty()
someCollection[index].isNotEmpty()
What's next? π
Probably Kotlin 2.0 and KMP πCies
06/19/2024, 1:42 PM@Validate
annotation given that Kotlin tries to avoid them (and the reflection based control flows that result from them) over explicit call chains; and (2) is it possible to inspect the validation constrains (in other words: are the validation constrains "just data" so we can write programs that, for instance, add a max-length=X
attribute a HTML form element if there is a maxLength constraint on the field that backs up the form element)?Johann Pardanaud
09/10/2024, 3:17 PMJohann Pardanaud
09/10/2024, 4:31 PMmap { it.map { it.id } }
.hasNoDuplicates()
Johann Pardanaud
09/12/2024, 3:26 PMJohann Pardanaud
09/24/2024, 6:16 PMaudax
10/24/2024, 8:17 AMCies
11/04/2024, 9:42 AMdata class Person(val name: String?, val dateOfBirth: LocalDate?) {
fun validate(): ValidationResult { ... }
}
When we submit an empty form name
and dateOfBirth
are null
. Say this is fine for dateOfBirth
(it's not a required field) and name
fails validation. So we present the user with the validation errors and allow 'm to try again.
Now user submits again with a name
and the dto validates. Only all the required fields (in this case only one) are still nullable! So mapping the dto to db records (we use jOOQ for that) we have a lot of `!!`s, i.e. record.name = dto.name!!
. Ideally I'd like the validate method to return a ValidatedPerson
data class which has all required fields marked as non-nullable. And the only way I can imagine to have this, is by doing A LOT of boiler plate: defining the ``ValidatedPerson`` myself, mapping to it by hand, etc. This is so much work that I rather do the `!!`s on the mapping to the record.
Like I said: just curious is you are doing something similar to me, or have found another way to handle this.Johann Pardanaud
11/16/2024, 9:38 AMJohann Pardanaud
12/10/2024, 1:56 PMmudasar187
12/12/2024, 9:40 AMdave08
01/06/2025, 2:47 PMotherwise { }
only supports strings right? It's not so great when validating forms in Jetpack Compose where an error is an R.string.XXX (an Int...)... any chance of expanding that to support other types?Cies
05/28/2025, 2:01 PM@Validate
annotation needed?Artem Kobzar
06/11/2025, 9:11 AM@Validate
data class Book(val title: String)
val bookValidator = Validator<Book> { // this: Validatable<Book>
title.hasLengthLowerThan(50)
}
val titleValidator = bookValidator::title // Validator.Runner<String>