Open marshall007 opened 9 years ago
+1 for this as well.
Yes, the current syntax is based on Joi. I don't remember who showed it to me, but I found the syntax way nicer that what we used to have.
I don't remember exactly all the reasons, but the main one I think was that ReQL values are not checked on save
but on retrieval. Typicall r.now()
will pass the validation for save
.
That being said, I'm not an expert on Joi and may have missed an option to skip validation in special cases (or they may have added it since last time?).
@neumino does Joi need to skip all validation or just validation on certain fields?
It needs to skip validation sometimes (for ReQL terms like r.now()
), or have a special handling for binaries/dates when they are in the ReQL raw format.
+1
I think the solution to validating on retrieval would be for thinky
to inspect the Joi schema you pass in to create the Model and replace (for example) instances of Joi.date()
(i.e. schema._type === 'date'
) with:
Joi.alternatives().try(
Joi.date(),
Joi.object().keys({
'$reql_type$': 'TIME'
}).and('epoch_time', 'timezone')
)
I'm still unsure how we'd get Joi to not complain about validating r.now()
before save, though.
On second thought, it might be as simple as adding another alternative Joi.object().type(r._Term)
?
+1
+1
That would really be great!
Any chance if this is implemented? Any fork implementing this?
👍 Would love to see this
+1
@schettino @at0g please stop spamming this thread. Use the reaction buttons above
Does anyone know if there a tool to export thinky schema to joi schema ? I understand thinky have some requirements that joi don't have due to the database (for date), but it would be great to have a tool, even if it does not handle every options, that could export to joi which can then be used for routes validation.
+1
I believe the existing schema API is already based heavily on
Joi
. I think it would make a lot of sense to just move to it completely.thinky
.Joi
can be browserify'd, so schemas could be shared between client and server (this would be huge!).