New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@adonisjs/validator

Package Overview
Dependencies
Maintainers
2
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@adonisjs/validator

Validator for adonis framework

  • 6.2.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13K
decreased by-26.85%
Maintainers
2
Weekly downloads
 
Created
Source

AdonisJS Validator

Schema validator for AdonisJS

circleci-image typescript-image npm-image license-image

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.

  • Treat Typescript as a first class citizen. Runtime validations and static types should always be in sync. In other words, no need to write seperate interfaces for maintaining types.
  • Performance is important. Validating user input is a very common task every Web server has to perform and hence squeezing out more performance on this front is critical.
  • Do not mutate original data: The validator returns a new copy of data, holding only the validated properties. In the process, the original data object is never mutated.
  • Don't be stringent about errors format: Many validation libraries returns errors in a single hardcoded structure. If you need them in a different shape, then running a loop on the errors is the only option. With AdonisJS, it is as simple as creating an Error Formatter with couple of methods on it.

Usage

Docs will be added soon to the AdonisJS official website

Keywords

FAQs

Package last updated on 14 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc