-
Notifications
You must be signed in to change notification settings - Fork 28
Description
This library is great! It handles a lot of common validation constraints and coverage the vast majority of use cases. I'd really like to use this library but I have a few more complex business requirements for validations that are not covered natively. Before I put together a PR for this, I wanted to get some initial thoughts and feedback.
One such validation requirement is that the fields in a column need to exist in a remote system. I'm sure there are a number of other use cases other folks might have.
Here's what I am thinking:
In the field.constraints
allow the user to pass in custom names and any arguments for that function.
{
"fields": [
{
"name": "col",
"constraints": {
"required": true,
"customFunction1": "scalarArgument", /* int, string, bool, etc. */
"customFunction2": ["array", "of", 1, "mixed", true, "arguments"],
"customFunction3": {
"object": "of",
"arguments": {
"including": "nested"
}
}
}
}
]
}
We can add new validation rules to the table
. Perhaps something like table.customValidators()
or similar. customValidators
accepts a map of synchronous and async functions and should be defined before table.read
or table.iter
.
table.customValidators({
customFunction1: async (row, ...args) => {
// do some async validation
},
customFunction2: (row, ...args) => {
// something sync
}
customFunction3:(row, ...args) => {
// something sync
}
})
This will allow the tableschema library more flexibility when it comes to validating data.
Thoughts?