Here we go again with SimpleSchema. It’s a rabbit hole but that’s the way things are sometimes. So here we go:
I currently migrate SimpleSchema to 3.0. Many props of SimpleSchema fields are computable:
const propsThatCanBeFunction = [
'allowedValues',
'exclusiveMax',
'exclusiveMin',
'label',
'max',
'maxCount',
'min',
'minCount',
'optional',
'regEx',
'skipRegExCheckForEmptyStrings',
];
This means you assign a function that returns a value instead of the value itself. You could do something like
{
foo: {
type: String,
optional: () => {
const userId = Meteor.userId()
return Roles.userIsInRole(userId, 'canSkipThings')
}
}
}
If any of these computations involve a MongoDB call then they will not work anymore as they are all sync.
However it’s currently not possible to implement the validation adaptive to async, so it would support sync AND async. It’s just too much relying on synchonous code that a conditional async would lead to a running bug-carrousel
So my decision is very likely to make the whole SimpleSchema API fully async. I don’t see any benefit of putting even more hours into this to find a solution that works for everybody without breaking things.
Therefore, please expect breaking changes with this package that may bubble up to other packages (Collection2, AutoForm etc.)
Edit: it may read as if I will drop the work on this, this is not the case, I just need to come to a decision how to move on as there are other packages pressuring to be updated as well