AdonisJS Validator
Schema validator for AdonisJS
I have been maintaining indicative (used by this repo) for many years and learned a lot about the validation engines. This time I want to approach data validation from scratch and address lot of design issues that Indicative has and also squeeze out maximum performance this time.
Table of contents
Benchmarks
Let's compare the validator performance in comparison to some of the famous libraries in the Node.js Ecosystem.
- Joi is one of the most famous and widely used schema validator for Node.js.
- Class Validator is a popular library in the Typescript world, since it allows you to keep your static types in sync with the runtime validations.
- Indicative My own work.
Textual Version
Benchmarking against flat object
AdonisJS x 6,777,738 ops/sec ±0.53% (81 runs sampled)
Joi x 705,094 ops/sec ±0.62% (81 runs sampled)
Indicative x 855,792 ops/sec ±0.30% (84 runs sampled)
Class Validator x 372,847 ops/sec ±0.38% (84 runs sampled)
Fastest is AdonisJS
Benchmarking against flat object with extra properties
AdonisJS x 6,685,496 ops/sec ±0.41% (81 runs sampled)
Joi x 445,545 ops/sec ±0.45% (83 runs sampled)
Indicative x 836,625 ops/sec ±0.44% (84 runs sampled)
Fastest is AdonisJS
Benchmarking against nested object
AdonisJS x 4,742,486 ops/sec ±0.52% (82 runs sampled)
Joi x 395,813 ops/sec ±0.48% (84 runs sampled)
Indicative x 532,652 ops/sec ±0.27% (85 runs sampled)
Class Validator x 216,392 ops/sec ±0.82% (83 runs sampled)
Fastest is AdonisJS
Benchmarking against array of objects
AdonisJS x 2,330,326 ops/sec ±0.42% (82 runs sampled)
Joi x 297,187 ops/sec ±0.47% (82 runs sampled)
Indicative x 394,948 ops/sec ±0.30% (83 runs sampled)
Class Validator x 192,939 ops/sec ±1.25% (82 runs sampled)
Fastest is AdonisJS
Goals
No code is the fastest code. In other words, making something fast is not a big deal, if you cut out all the features and compromise usability on every front.
I didn't started with making one of the fastest validation engines for Node.js. The goals were completely different and performance was just one of them.
Usage
Docs will be added soon to the AdonisJS official website