meteor / validated-method

Meteor methods with better scoping, argument checking, and good defaults.
https://atmospherejs.com/mdg/validated-method
MIT License
194 stars 28 forks source link

Make a function that throws validation errors based on a check pattern #3

Open stubailo opened 8 years ago

stubailo commented 8 years ago

Mostly for transition purposes for people who are familiar with check.

Hard requirement - it still needs to throw ValidationError errors, but I think this is achievable by using simple-schema under the hood.

stubailo commented 8 years ago

@aldeed is this easy to do with SimpleSchema? Can I somehow easily convert a check pattern into a SimpleSchema instance, and then get a validator function out of it?

aldeed commented 8 years ago

SS does not use match patterns internally and I'm not aware of anyone having written a converter.

The simple option is a wrapper function that just catches the check error, smooshes it into a ValidationError, and rethrows it. This would not have field-specific errors I think.

Otherwise a pkg that converts match patterns to SS syntax could be useful, similar to https://atmospherejs.com/bshamblen/json-simple-schema (validate: (new MatchPattern({})).toSimpleSchema().validator())

stubailo commented 8 years ago

Hmm, yeah. I am also probably OK with people not getting the fancy validator functionality if they use check in the meanwhile.