Releases: vinejs/vine
Fix: Make schema classes Macroable to be extensible
Add API to make validation metadata type-safe
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
- fix: export testing factories ffe8279
Full Changelog: v1.4.0...v1.4.1
Add strict mode to number schema type
- feat: add strict mode to number type 84c3890
Full Changelog: v1.3.0...v1.4.0
Implement additional rules
- 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
New Contributors
Full Changelog: v1.2.0...v1.3.0
Adding new rules
- 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
- 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
First working release
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