The modular and type safe schema library for validating structural data 🤖
MIT License
Bot releases are hidden (Show)
Published by fabian-hiller 12 months ago
Many thanks to @lo1tuma, @Karakatiza666, @naveen-bharathi, @jsudelko, @danielo515, @iamriajul, @brandonpittman, @marek-hanzal, @kurtextrem, @BThomann, @hermanseder, @sillvva, @tjenkinson and many more peoples for contributing to this release.
getRestAndDefaultArgs
utility functionrest
argument to object
and objectAsync
schemavariant
and variantAsync
schema (issue #90, #216)getFallback
property to schema in fallback
method (pull request #177)PartialObjectEntries
and PartialObjectEntriesAsync
type (issue #217)getDefaultAsync
, getDefaults
and getDefaultsAsync
, getFallback
, getFallbackAsync
, getFallbacks
, getFallbacksAsync
method (issue #155)transform
and transformAsync
date
and dateAsync
for invalid dates (pull request #214)optional
, optionalAsync
, nullable
, nullableAsync
, nullish
and nullishAsync
schemaObjectSchema
and ObjectSchemaAsync
typetuple
and tupleAsync
to be less strictaction
argument in coerce
and coerceAsync
to unknown
brand
, getDefault
, transform
and transformAsync
methodarray
, arrayAsync
, intersection
, intersectionAsync
, map
, mapAsync
, object
, objectAsync
, union
, unionAsync
, record
, recordAsync
, set
, setAsync
, tuple
and tupleAsync
schemaschema
property of every schema type to type
intersection
and intersectionAsync
schema to intersect
and intersectAsync
enumType
and enumTypeAsync
schema to picklist
and picklistAsync
nativeEnum
and nativeEnumAsync
schema to enum_
and enumAsync
nullType
and nullTypeAsync
schema to null_
and nullAsync
undefinedType
and undefinedTypeAsync
schema to undefined_
and undefinedAsync
voidType
and voidTypeAsync
schema to void_
and voidAsync
default
property of optional
, optionalAsync
, nullable
, nullableAsync
, nullish
and nullishAsync
schema to getDefault
ObjectShape
and ObjectShapeAsync
types to ObjectEntries
and ObjectEntriesAsync
TupleShape
and TupleShapeAsync
types to TupleItems
and TupleItemsAsync
passthrough
, strict
and strip
method in favor of object
schema with rest
argumentUnfortunately, I haven't had time to write a migration guide yet. If you have any questions or problems, please have a look at the source code or create an issue. I usually respond within 24 hours.
Published by fabian-hiller about 1 year ago
Many thanks to @lo1tuma, @Saeris, @sillvva, @kazizi55, @FleetAdmiralJakob, @kurtextrem, @xinha-sh and @husseyexplores for contributing to this release.
notBytes
, notLength
, notSize
and notValue
validation function (pull request #194)record
and recordAsync
schema (issue #201)transform
and transformAsync
(issue #197)email
validation to improve performance and security (pull request #180)object
and objectAsync
schema to exclude non-existing keys (issue #199)brand
, transform
and unwrap
method (issue #195)equal
validation function in favor of value
(issue #192)Published by fabian-hiller about 1 year ago
Many thanks to @alonidiom, @davidmyersdev, @Karakatiza666, @abd2561024 and @brandonpittman for contributing to this release.
intersection
and intersectionAsync
schema (pull request #117)RecordInput
and RecordOutput
type (pull request #184)RecordSchema
and RecordSchemaAsync
typeflatten
function and improve typesPublished by fabian-hiller about 1 year ago
Many thanks to @syhol and @adoublef for contributing to this release.
Published by fabian-hiller about 1 year ago
Many thanks to @zkulbeda, @vicimpa, @jonlambert and @gmaxlev for contributing to this release.
skipPipe
option to skip execution of pipelines (pull request #164)Published by fabian-hiller about 1 year ago
Many thanks to @jmcdo29, @divndev and @demarchenac for contributing to this release.
ulid
validation (pull request #151)getIssues
, getOutput
and getPipeIssues
util and refactor codenumber
and numberAsync
schema (issue #157)PipeResult
type to allow multiple issues (issue #161)getIssues
util to getSchemaIssues
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 }
// 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),
]);
Published by fabian-hiller about 1 year ago
Many thanks to @demarchenac, @Demivan, @david-plugge, @abd2561024 and @ooga for contributing to this release.
record
and recordAsync
schema (issue #134)optional
, optionalAsync
, nullable
, nullableAsync
, nullish
and nullishAsync
schema (issue #96, #118)getDefault
method to get default value of schema (issue #105)withDefault
method in favor of optional
schemaPublished by fabian-hiller about 1 year ago
Many thanks to @samualtnorman, @dmorosinotto, @FabienDehopre and @Yovach for contributing to this release.
cuid2
validation (pull request #130)passthrough
, passthroughAsync
, strip
and stripAsync
methodInstanceSchemaAsync
overload to transformAsync
method (pull request #138)strict
and strictAsync
method for optional keys (issue #131)Published by fabian-hiller about 1 year ago
object
and record
schemaPublished by fabian-hiller about 1 year ago
Many thanks to @naruaway, @zkulbeda, @kurtextrem, @BastiDood, @ssalbdivad, @jussisaurio, @FlorianDevPhynix, @milankinen, @fvckDesa and @Demivan for contributing to this release.
fallback
and fallbackAsync
method (pull request #103)excludes
validation as negation of includes
literal
schema (pull request #102)withDefault
methodflatten
method so that issues are also accepted as argumentsafeParse
and safeParseAsync
method.parse
to ._parse
and .types
to ._types
to mark it as internalThis 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)
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 };
},
]);
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] # bun
Option 2:
import { parse } from 'valibot';
.input((input) => parse(YourSchema, input))
Option 3:
import { wrap } from '@decs/typeschema';
.input(wrap(YourSchema))
Published by fabian-hiller about 1 year ago
Many thanks to @naruaway, @MineLPPhynix, @mrsekut and @zkulbeda for contributing to this release.
mimeType
validation to Blob
useDefault
method to withDefault
(issue #80)brand
method to support branded types (pull request #85)Published by fabian-hiller about 1 year ago
Many thanks to @jdgamble555 and @BastiDood for contributing to this release.
enumType
and enumTypeAsync
schema (issue #70)Published by fabian-hiller about 1 year ago
Many thanks to @NiclasHaderer and @gmaxlev for contributing to this release.
record
and recordAsync
(pull request #67)finite
, safeInteger
and multipleOf
validation (pull request #64, #65, #66)Published by fabian-hiller about 1 year ago
Many thanks to @gmaxlev for contributing to this release.
integer
validation (pull request #62)Published by fabian-hiller about 1 year ago
Many thanks to @Danielwinkelmann and @sillvva for contributing to this release.
imei
validation and isLuhnAlgo
util (pull request #37)isoDateTime
, isoTime
, isoTimeSecond
and isoTimestamp
validation (pull request #42)Published by fabian-hiller about 1 year ago
Many thanks to @Thanaen, @hungify and @yamiteru for contributing to this release.
object
and record
types (issue #9, #10, #34)strict
and strictAsync
method to detect unknown object keysPublished by fabian-hiller about 1 year ago
Many thanks to @JoakimDeak, @jasikpark, @luxferoo, @logaretm and @Yovach for contributing to this release.
is
method which can be used as a type guard (pull request #13)abortPipeEarly
option to abort pipe on first error (issues #18)abortEarly
option to abort on first errorPublished by fabian-hiller about 1 year ago
toMinValue
and toMaxValue
transformationPublished by fabian-hiller about 1 year ago
Many thanks to @lino-levan, @emilbonnek and @kiliman for contributing to this release.
comparable
import when using DenominRange
and maxRange
to minValue
and maxValue
(issue #20)value
validation functionPublished by fabian-hiller about 1 year ago
Many thanks to @lino-levan for contributing to this release.
instance
and instanceAsync
schema