Skip to content

Releases: adonisjs/validator

Updating underlying dependencies

15 Apr 11:42
Compare
Choose a tag to compare

request.validate can also accept the class constructor

15 Apr 08:19
Compare
Choose a tag to compare
  • feat: accept Validator as a class constructor in request.validate method da1f5f6

v7.0.0...v7.0.1

Making validator API consistent and less verbose

13 Apr 14:09
Compare
Choose a tag to compare

This release removes the compile and compileAndCache methods from the validator object. This is done in the favor of removing too many ways of doing the same thing.

Why these APIs were added in the first place

The validator schema created using schema.create needs to be compiled to re-usable function and then use the compiled output for validating runtime data. The compilation step ensures, we are not paying the performance penalty every time, when even the underlying schema is same. Because of this, we added the validator.compile method. So you will write the code as follows:

validator.compile

validator.validate({
  schema: validator.compile(schema.create({
    username: schema.string(),
  }))
})

But, there is a problem with the above approach, what if, you want to use dynamic data inside your schema. For example:

validator.validate({
  schema: validator.compile(schema.create({
    username: schema.string({}, [
      rules.unique(ctx.auth.user.id)
    ]),
  }))
})

The above schema uses a dynamic value ctx.auth.user.id, but the compiler will compile the schema with the first value and re-uses it afterwards. To overcome this situation, we added another method called compileAndCache

validator.compileAndCache

validator.validate({
  schema: validator.compileAndCache(schema.create({
    username: schema.string({}, [
      rules.unique(ctx.auth.user.id)
    ]),
  }), `cache-key-${ctx.auth.user.id}`)
})

The above method will cache the compiled schema against the cached key, so if the key changes, it will re-compile the schema.

Conclusion

Both APIs have subtle differences and this subtlety demands too much attention in order to use the correct API. We have removed both the methods and now, you always have to define the cacheKey in order to avoid re-compiling.

This is how it looks

validate.validate({
  schema: schema.create({
    username: schema.string({}, [
      rules.unique(ctx.auth.user.id)
    ]),
  }),
  cacheKey: `cache-key-${ctx.auth.user.id}`
})

Most of the times, the cache key can be URL of the HTTP request, unless, you are using dynamic values inside the schema, which are not part of the URL.

I hope, all this justifies the breaking change

Commits

  • refactor: move validations based helpers to Validator/helpers 36273b4
  • improvement: cleanup validator API to be more consistent and predictable bf9349a
  • chore: remove unwanted dependencies ebd08ac
  • chore: update dependencies 9308c26

v6.3.0...v7.0.0

Updating underlying dependencies

12 Apr 17:51
Compare
Choose a tag to compare
  • chore: update depdendencies and improve types a bit 7987d50
  • Merge pull request #77 from gustavopch/patch-1 5d4ad5f
  • docs: fix typo in readme file 3bf23d5

v6.2.7...v6.3.0

Fixing `request.validate` method to return validated body

03 Mar 15:58
Compare
Choose a tag to compare

#74

  • fix: request.validate return validated properties cb73630

v6.2.6...v6.2.7

Install @types/validator as prod dependency

01 Mar 06:55
Compare
Choose a tag to compare
  • docs: update badge url 5daff56
  • fix: install @types/validator as prod dependency 2079773
  • chore: update dependencies 044e161

v6.2.5...v6.2.6

Adding bunch of new rules

27 Feb 13:12
Compare
Choose a tag to compare
  • feat: add min length rules f669bcd
  • feat: add mobile validation rule 531391d
  • feat: add ip validation rule f6190fd
  • feat: add trim option property to string rule 71c5e02
  • feat: add option to escape string values inside validator 312f739
  • feat: add email validation rule 0d39c64
  • style: keep code consitent c130080
  • feat: profile request validation action 238e454
  • style: remove console.log statement from one of the tests bb5bb58
  • chore(package): update dependencies 53e46ad

v6.2.4...v6.2.5

Handful of bug fixes and adding support for decide the non existing fields behavior

15 Feb 04:59
Compare
Choose a tag to compare

It is always tricky to decide when to consider a field value is non-existing. Some may want to treat only undefined as non-existing, some may not undefined and null both and some may want empty strings as well.

Infact, treating empty string as non-existing becomes mandatory when dealing with traditional HTML forms, since if a field value is not filled out the server will receive it as an empty string.

With this release we allow you to control the behavior of what should be treated as non-existing value.

  • chore: remove doctoc precommit hook 34c2197
  • docs: update readme and pr template 84b94d2
  • docs: update benchmarks e747555
  • feat: allow configuring value existence behavior 3101c06
  • fix(validationexception): extend base exception class 4ef075f
  • chore: update dependencies 0b1721a

v6.2.3...v6.2.4

Handful of bug fixes

14 Feb 12:57
Compare
Choose a tag to compare
  • refactor: do not use destructuring to keep code performant 84d16d5
  • refactor: re-define the validate method api to be more user friendly f30f5b2
  • fix: wrap content negotiation checks inside switch case c0208ae
  • fix: read validate method from validator.validator object inside provider 0c0f730

v6.2.2...v6.2.3

Fix by installing endent as production dependency

14 Feb 10:40
Compare
Choose a tag to compare
  • chore(package): add endent as prod dependency 46aa026

v6.2.1...v6.2.2