Feature idea: Using Joi for prop definition and validation, or adding Joi-like features
See original GitHub issueHave you guys used Joi? I use Joi on the server-side with Hapi and really love it.
I just got started with Ampersand and also really, really love ampersand-state
. What a great tool. I was just in the middle of defining some properties on a view (!!!) and wanted to define valid values for one properties a function of the value of another property. Joi lets you do this with alternatives and references.
If Joi was adopted for properties, it could then also be used for validation. It would be a great win, I think. Defining a properties schema already gets you quite close to using that schema for validation.
This wouldn’t be trivial, of course. But I wanted to get this out there to see what you think. Joi is apparently browser-compatible via browserify, though they don’t run browser tests and they support things like Buffers. So, Joi may be too heavy for this purpose, and if so, perhaps just the above-mentioned reference/alternatives features could be added. And validation via properties’ schemas, I think, would be great too.
Thank you.
Issue Analytics
- State:
- Created 9 years ago
- Comments:13 (5 by maintainers)
Top GitHub Comments
This would be doable as a
dataType
mixin with a minor non-breaking change todataType.set
anddef.test
.original
becomes
I ran a quick spike and this worked perfectly. I was able to create and use a
Joi
dataType mixin. The benefit of this change is that it allow much more powerful dataType mixing even outside ofJoi
. Further, the above changes does not break anything and the tests continue to pass.If this looks good, I’ll make it a PR.
This would be a wonderful thing as a mixin, great idea.