Releases: fabian-hiller/valibot
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
ulid
validation (pull request #151) - Add
getIssues
,getOutput
andgetPipeIssues
util and refactor code - Fix type check in
number
andnumberAsync
schema (issue #157) - Change
PipeResult
type to allow multiple issues (issue #161) - Rename previous
getIssues
util 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
record
andrecordAsync
schema (issue #134) - Add support for default values to
optional
,optionalAsync
,nullable
,nullableAsync
,nullish
andnullishAsync
schema (issue #96, #118) - Add
getDefault
method to get default value of schema (issue #105) - Deprecate
withDefault
method in favor ofoptional
schema
v0.14.0
Many thanks to @samualtnorman, @dmorosinotto, @FabienDehopre and @Yovach for contributing to this release.
v0.13.1
- Change object type check in
object
andrecord
schema
v0.13.0
Many thanks to @naruaway, @zkulbeda, @kurtextrem, @BastiDood, @ssalbdivad, @jussisaurio, @FlorianDevPhynix, @milankinen, @fvckDesa and @Demivan for contributing to this release.
- Add
fallback
andfallbackAsync
method (pull request #103) - Add
excludes
validation as negation ofincludes
- Add support for more primitives to
literal
schema (pull request #102) - Add support for dynamic values to
withDefault
method - Change
flatten
function so that issues are also accepted as argument - Change return type of
safeParse
andsafeParseAsync
method - Change error handling and refactor library to improve performance
- Rename
.parse
to._parse
and.types
to._types
to 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 valibot@0.12.0 # npm
yarn add valibot@0.12.0 # yarn
pnpm add valibot@0.12.0 # pnpm
bun add valibot@0.12.0 # bun
Option 2:
import { parse } from 'valibot';
.input((input) => parse(YourSchema, input))
Option 3:
import { wrap } from '@decs/typeschema';
.input(wrap(YourSchema))
v0.12.0
v0.11.1
Many thanks to @jdgamble555 and @BastiDood for contributing to this release.