Skip to content

Releases: vinejs/vine

Fix: Make schema classes Macroable to be extensible

11 Jul 07:29
Compare
Choose a tag to compare
  • ci: fix failing tests 2f5258c
  • ci: remove test.yml workflow file 89efc20
  • test: fix failing tests d04800c
  • test: add test for extending Vine class a417418
  • fix: make schema classes Macroable 41bd3d5

Full Changelog: v1.5.0...v1.5.1

Add API to make validation metadata type-safe

10 Jul 11:46
Compare
Choose a tag to compare

In VineJS, you can pass runtime metadata to the validation pipeline, which you can access from the validation rules, union predicates, etc. The metadata API was not type-safe until now. However, this release allows you to define the static metadata types and a validation function to validate them at runtime.

Note: The metadata API is kept very simple because only a few schemas might need runtime metadata with a few properties to be functional.

One example is the unique validation rule. You might want the unique validation rule to check all the database rows except the one for the currently logged-in user. In that case, you will pass the currently logged-in userId to the statically compiled validation schema using metadata as follows.

const updateUserValidator = vine.compile(
  vine.object({
    email: vine.string().email().unique((field) => {
      console.log(field.meta.userId)
    }),
  })
)
await updateUserValidator.validate(data, {
  meta: { userId: request.auth.user.id }
})

However, there is no way to know that updateUserValidator needs the currently logged-in user id to be functional.

From @vinejs/vine@1.5.0, you can use the withMetaData method to define static types for the metadata a validator accepts. The schema will look as follows.

const updateUserValidator = vine
  .withMetaData<{ userId: number }>()
  .compile(
    vine.object({
      email: vine.string().email().unique((field) => {
        console.log(field.meta.userId)
      }),
    })
  )

You can pass a callback to withMetaData to validate the metadata at runtime if needed.

vine
  .withMetaData<{ userId: number }>((meta) => {
    // validate id and throw an error
 })

Commits

  • feat: add support for defining static metadata types and validator function 09c4097
  • chore: use @adonisjs/tooling presets for tooling config a02908d
  • chore: upgrade japa to v3 4181ee4
  • chore: update dependencies f24ebb8
  • chore: add labels to exempt from stale and lock bot 92697c4
  • docs: fix contributing link fcad2fb

Full Changelog: v1.4.1...v1.5.0

Export testing factories

16 Jun 05:27
Compare
Choose a tag to compare
  • fix: export testing factories ffe8279

Full Changelog: v1.4.0...v1.4.1

Add strict mode to number schema type

15 Jun 04:37
Compare
Choose a tag to compare
  • feat: add strict mode to number type 84c3890

Full Changelog: v1.3.0...v1.4.0

Implement additional rules

14 Jun 07:04
Compare
Choose a tag to compare
  • feat: implement normalizeUrl rule c3a893f
  • refactor: remove he dependency and encode rule b16ea5d
  • feat: implement escape and encode rules 7d6ba6d
  • feat: implement toUpperCase, toLowerCase and toCamelCase rules 0c9be26
  • feat: implement ascii, iban, jwt, and coordinates rules 0ae33d7
  • feat: implement uuid rule 2372fae
  • feat: implement postal code rule eff6f61
  • feat: implement passport rule 53f402a
  • feat: implement creditCard rule 9cd8fdf
  • chore: update dependencies dd68dfe
  • refactor: export SimpleMessagesProvider and SimpleErrorReporter 8eaf6d2
  • docs: update benchmarks 8532cfa
  • feat: define otherwise error reporter for unions 45646f2
  • chore(benchmarks): union conditions (#1) 869d787

What's Changed

  • fix(benchmarks): union conditions by @webNeat in #1

New Contributors

Full Changelog: v1.2.0...v1.3.0

Adding new rules

13 Jun 10:53
Compare
Choose a tag to compare
  • feat: implement ipAddress rule df41d23
  • feat: implement in and notIn rules ed9fa5c
  • feat: implement sameAs and notSameAs rules 5817f2b
  • feat: implement startsWith and endsWith rules c6fb726
  • feat: implement trim and normalizeEmail rules 63dcdef
  • feat: implement confirmed rule cf27cb5
  • feat: add size based string rules 935a751
  • test: use datasets be04d1c
  • feat: implement string rules bee7a9e
  • refactor: rename ctx references with field ea63dd2
  • chore: update dependencies e44de42

Full Changelog: v1.1.1...v1.2.0

Exporting additionally classes

12 Jun 11:31
Compare
Choose a tag to compare
  • feat: enable defining custom error reporter at all layers 0138b5f
  • feat: export Vine class bc38c04
  • feat: export base classes 33026e3

Full Changelog: v1.1.0...v1.1.1

Improvements to the API for defining messages and fields

12 Jun 06:31
Compare
Choose a tag to compare
  • docs: update benchmarks b874b87
  • feat: export defaults submodule b9cbbeb
  • refactor: cleanup messages and fields API 68a1186
  • chore: update dependencies 22996f5
  • docs: fix npm badge URL 4479bdf
  • chore: add repo details cf9905b

v1.0.0...v1.1.0

First working release

10 Jun 04:35
Compare
Choose a tag to compare

Hold your horses, the release is not polished and some of the APIs are rough. Wait for the official announcement

Full Changelog: https://github.com/vinejs/vine/commits/v1.0.0