Open craigspaeth opened 9 years ago
maybe we could just include the bson module?
I would really like this.
I've just created a pull request in joi which would cover exactly what you are asking. The PR wasn't merged because of the added BSON dependency. However, you might find a way to reutilise the code in this plugin.
is it not possible to put that logic in this module? my thinking is that Hapi shouldn't need to care about validating everyone's custom types itself and instead should provide the APIs which we can hook into. separation of concerns
I think that it is not possible as things are right now. I totally agree with you in that an API which we can hook into would be an awesome enhancement to joi.
I didn't start using Joi for its pretty syntax (there are validators with more compact/prettier syntaxes out there) but because it also provided typecasting/parsing of types to create proper DTOs from the input. As it stands, this plugin is rather half-done IMHO. It needs to support type-casting!
SGTM. anyone want to open a quick PR with tests?
I'm in. Will start working on this.
FYI, joi is working on a way to officially support plugins/extensibility (actively being discussed): https://github.com/hapijs/joi/issues/577
Joi does implicit type casting for things like Date. I find myself wanting this plugin to type cast a 24 char alphanumeric string into a
require('mongodb').ObjectID
. I'm not sure if it makes sense to include mongodb-native as a dependency of this project to do that, but I thought I would throw the idea out there.If that sounds like something you're interested in I would be happy to submit a pull request for it.