Releases: open-circle/valibot
v0.19.0
Many thanks to @lo1tuma, @Saeris, @sillvva, @kazizi55, @FleetAdmiralJakob, @kurtextrem, @xinha-sh and @husseyexplores for contributing to this release.
- Add
notBytes,notLength,notSizeandnotValuevalidation function (pull request #194) - Add support for unions as key of
recordandrecordAsyncschema (issue #201) - Add support for pipeline validation to
transformandtransformAsync(issue #197) - Change regex of
emailvalidation to improve performance and security (pull request #180) - Change
objectandobjectAsyncschema to exclude non-existing keys (issue #199) - Fix types at
brand,transformandunwrapmethod (issue #195) - Deprecate
equalvalidation function in favor ofvalue(issue #192)
v0.18.0
Many thanks to @alonidiom, @davidmyersdev, @Karakatiza666, @abd2561024 and @brandonpittman for contributing to this release.
v0.17.1
v0.17.0
Many thanks to @zkulbeda, @vicimpa, @jonlambert and @gmaxlev for contributing to this release.
v0.16.0
Many thanks to @jmcdo29, @divndev and @demarchenac for contributing to this release.
- Add
ulidvalidation (pull request #151) - Add
getIssues,getOutputandgetPipeIssuesutil and refactor code - Fix type check in
numberandnumberAsyncschema (issue #157) - Change
PipeResulttype to allow multiple issues (issue #161) - Rename previous
getIssuesutil togetSchemaIssues
Migration guide
For individual validation within a pipeline, it is now possible to return multiple issues. In addition, we provide two helper functions with getOutput and getPipeIssues to make your code more readable.
import { getOutput, getPipeIssues, string } from 'valibot';
// Change this
const StringSchema = string([
(input) => {
if (input.length > 10) {
return {
issue: {
validation: 'custom',
message: 'Invalid length',
input,
},
};
}
return { output: input };
},
]);
// To that
const StringSchema = string([
(input) =>
input.length > 10
? getPipeIssues('custom', 'Invalid length', input)
: getOutput(input),
]);v0.15.0
Many thanks to @demarchenac, @Demivan, @david-plugge, @abd2561024 and @ooga for contributing to this release.
- Add possibility to define path of pipeline issue (issue #133)
- Add support for enums as key of
recordandrecordAsyncschema (issue #134) - Add support for default values to
optional,optionalAsync,nullable,nullableAsync,nullishandnullishAsyncschema (issue #96, #118) - Add
getDefaultmethod to get default value of schema (issue #105) - Deprecate
withDefaultmethod in favor ofoptionalschema
v0.14.0
Many thanks to @samualtnorman, @dmorosinotto, @FabienDehopre and @Yovach for contributing to this release.
v0.13.1
- Change object type check in
objectandrecordschema
v0.13.0
Many thanks to @naruaway, @zkulbeda, @kurtextrem, @BastiDood, @ssalbdivad, @jussisaurio, @FlorianDevPhynix, @milankinen, @fvckDesa and @Demivan for contributing to this release.
- Add
fallbackandfallbackAsyncmethod (pull request #103) - Add
excludesvalidation as negation ofincludes - Add support for more primitives to
literalschema (pull request #102) - Add support for dynamic values to
withDefaultmethod - Change
flattenfunction so that issues are also accepted as argument - Change return type of
safeParseandsafeParseAsyncmethod - Change error handling and refactor library to improve performance
- Rename
.parseto._parseand.typesto._typesto mark it as internal
Migration guide
This version brings extreme performance improvements. However, this also required a few breaking changes. Below is an explanation of how these can be solved quite easily.
.parse
If you have been using the internal .parse API of a schema for validation directly, you must now switch to the parse method.
// Change this
YourSchema.parse(input);
// To that
parse(YourSchema, input);safeParse
For safeParse we have depredated .data and .error. Use .output and .issues instead.
const result = safeParse(YourSchema, input);
if (result.success) {
// Change this
const output = result.data;
// To that
const output = result.output;
} else {
// Change this
const issues = result.error.issues;
// To that
const issues = result.issues;
}If you still want to work with a ValiError, you can easily create a ValiError yourself.
const error = new ValiError(result.issues)Custom validation
If you previously threw a ValiError on your own, for example in the pipeline of a schema, you must now return an object with an issue or output.
// Change this
const StringSchema = string([
(input, info) => {
if (input.length > 10) {
throw new ValiError([
{
validation: 'custom',
origin: 'value',
message: 'Invalid length',
input,
...info,
},
]);
}
return input;
},
]);
// To that
const StringSchema = string([
(input) => {
if (input.length > 10) {
return {
issue: {
validation: 'custom',
message: 'Invalid length',
input,
},
};
}
return { output: input };
},
]);tRPC
Unfortunately we could not find a solution for tRPC yet. Currently you can either explicitly set your Valibot version to v0.12.0, call parse on your own or use TypeSchema as a layer in between.
Option 1:
npm install [email protected] # npm
yarn add [email protected] # yarn
pnpm add [email protected] # pnpm
bun add [email protected] # bunOption 2:
import { parse } from 'valibot';
.input((input) => parse(YourSchema, input))Option 3:
import { wrap } from '@decs/typeschema';
.input(wrap(YourSchema))