13 lines
435 B
Plaintext
13 lines
435 B
Plaintext
# NonEmptyId: ensures the `id` field of any record is a non-empty string.
|
|
# Apply as: `data | c.NonEmptyId` before merging with schema.
|
|
std.contract.custom (
|
|
fun label =>
|
|
fun value =>
|
|
if !(std.record.has_field "id" value) then
|
|
'Error { message = "record must have an 'id' field" }
|
|
else if std.string.length value.id == 0 then
|
|
'Error { message = "id must not be empty" }
|
|
else
|
|
'Ok value
|
|
)
|