thenativeweb / node-cqrs-domain

Node-cqrs-domain is a node.js module based on nodeEventStore that. It can be very useful as domain component if you work with (d)ddd, cqrs, eventdenormalizer, host, etc.
http://cqrs.js.org/pages/domain.html
MIT License
269 stars 57 forks source link

Is it possible to replace the t4-validation? #133

Closed blissi closed 6 years ago

blissi commented 6 years ago

Hallo,

I'd like to use Joi for validating the commands. Is it possible to replace the built-in t4-validation with something different? What's the purpose of the validator extension? Can it be used for this?

Thanks, Steven

nanov commented 6 years ago

Hi!

It is totally possible to replace the default ( probably outdated ) validator with something else. We use in production ajv.

With that being said, the validator must validate the (command) object against JSON schemas, which in my opinion is a far better option than JOI taking into account its standardisation cross-language and cross-platfrom support.

Alternatively you could implement completely custom validations in pre-load-conditions ( the validation is basically the same ) and throw validation errors as wish there.

If you decide to go with the JSON schema way, i would be more than happy to provide you with an example that uses custom validator.

blissi commented 6 years ago

@nanov I'm not limited to Joi and would highly appreciate your ajv-example.

nanov commented 6 years ago

I am on it.

nanov commented 6 years ago

Ok,

I've tried to come up with something quickly. I will continue to update those examples when I find the time as i truly believe those are useful.

As per your specific question :

Complete AJV validation and error reporting is implemented in this example. Take a look at it and how it works, and let me know if this is helpful.

blissi commented 6 years ago

Thanks, that's definately helpful! I'll play around with it.