valibot

The modular and type safe schema library for validating structural data 🤖

MIT License

Downloads
1.6M
Stars
5.2K
Committers
105

Bot releases are hidden (Show)

valibot - v0.20.0

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.

  • Add getRestAndDefaultArgs utility function
  • Add rest argument to object and objectAsync schema
  • Add variant and variantAsync schema (issue #90, #216)
  • Add getFallback property to schema in fallback method (pull request #177)
  • Add PartialObjectEntries and PartialObjectEntriesAsync type (issue #217)
  • Add export for any validation regex (pull request #219)
  • Add getDefaultAsync, getDefaults and getDefaultsAsync, getFallback, getFallbackAsync, getFallbacks, getFallbacksAsync method (issue #155)
  • Add support for schema validation to transform and transformAsync
  • Fix type check in date and dateAsync for invalid dates (pull request #214)
  • Improve security of regular expressions (pull request #202)
  • Improve optional, optionalAsync, nullable, nullableAsync, nullish and nullishAsync schema
  • Change ObjectSchema and ObjectSchemaAsync type
  • Change type check in tuple and tupleAsync to be less strict
  • Change return type of action argument in coerce and coerceAsync to unknown
  • Change type of brand, getDefault, transform and transformAsync method
  • Change type of array, arrayAsync, intersection, intersectionAsync, map, mapAsync, object, objectAsync, union, unionAsync, record, recordAsync, set, setAsync, tuple and tupleAsync schema
  • Rename schema property of every schema type to type
  • Rename intersection and intersectionAsync schema to intersect and intersectAsync
  • Rename enumType and enumTypeAsync schema to picklist and picklistAsync
  • Rename nativeEnum and nativeEnumAsync schema to enum_ and enumAsync
  • Rename nullType and nullTypeAsync schema to null_ and nullAsync
  • Rename undefinedType and undefinedTypeAsync schema to undefined_ and undefinedAsync
  • Rename voidType and voidTypeAsync schema to void_ and voidAsync
  • Rename default property of optional, optionalAsync, nullable, nullableAsync, nullish and nullishAsync schema to getDefault
  • Rename ObjectShape and ObjectShapeAsync types to ObjectEntries and ObjectEntriesAsync
  • Rename TupleShape and TupleShapeAsync types to TupleItems and TupleItemsAsync
  • Deprecate passthrough, strict and strip method in favor of object schema with rest argument

Migration guide

Unfortunately, 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.

valibot - v0.19.0

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.

  • Add notBytes, notLength, notSize and notValue validation function (pull request #194)
  • Add support for unions as key of record and recordAsync schema (issue #201)
  • Add support for pipeline validation to transform and transformAsync (issue #197)
  • Change regex of email validation to improve performance and security (pull request #180)
  • Change object and objectAsync schema to exclude non-existing keys (issue #199)
  • Fix types at brand, transform and unwrap method (issue #195)
  • Deprecate equal validation function in favor of value (issue #192)
valibot - v0.18.0

Published by fabian-hiller about 1 year ago

Many thanks to @alonidiom, @davidmyersdev, @Karakatiza666, @abd2561024 and @brandonpittman for contributing to this release.

  • Add intersection and intersectionAsync schema (pull request #117)
  • Fix RecordInput and RecordOutput type (pull request #184)
  • Change RecordSchema and RecordSchemaAsync type
  • Change flatten function and improve types
valibot - v0.17.1

Published by fabian-hiller about 1 year ago

Many thanks to @syhol and @adoublef for contributing to this release.

  • Fix missing file extensions for Deno (pull request #178, #181)
valibot - v0.17.0

Published by fabian-hiller about 1 year ago

Many thanks to @zkulbeda, @vicimpa, @jonlambert and @gmaxlev for contributing to this release.

  • Add support for multiple branding of a value (pull request #88)
  • Add support for dynamic error messages via functions (pull request #136)
  • Add skipPipe option to skip execution of pipelines (pull request #164)
valibot - v0.16.0

Published by fabian-hiller about 1 year ago

Many thanks to @jmcdo29, @divndev and @demarchenac for contributing to this release.

  • Add ulid validation (pull request #151)
  • Add getIssues, getOutput and getPipeIssues util and refactor code
  • Fix type check in number and numberAsync schema (issue #157)
  • Change PipeResult type to allow multiple issues (issue #161)
  • Rename previous getIssues util to getSchemaIssues

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 }

// 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),
]);
valibot - v0.15.0

Published by fabian-hiller about 1 year ago

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 and recordAsync schema (issue #134)
  • Add support for default values to optional, optionalAsync, nullable, nullableAsync, nullish and nullishAsync schema (issue #96, #118)
  • Add getDefault method to get default value of schema (issue #105)
  • Deprecate withDefault method in favor of optional schema
valibot - v0.14.0

Published by fabian-hiller about 1 year ago

Many thanks to @samualtnorman, @dmorosinotto, @FabienDehopre and @Yovach for contributing to this release.

  • Add cuid2 validation (pull request #130)
  • Add passthrough, passthroughAsync, strip and stripAsync method
  • Add InstanceSchemaAsync overload to transformAsync method (pull request #138)
  • Fix bug in strict and strictAsync method for optional keys (issue #131)
valibot - v0.13.1

Published by fabian-hiller about 1 year ago

  • Change object type check in object and record schema
valibot - v0.13.0

Published 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.

  • Add fallback and fallbackAsync method (pull request #103)
  • Add excludes validation as negation of includes
  • Add support for more primitives to literal schema (pull request #102)
  • Add support for dynamic values to withDefault method
  • Change flatten method so that issues are also accepted as argument
  • Change return type of safeParse and safeParseAsync 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 [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))
valibot - v0.12.0

Published by fabian-hiller about 1 year ago

Many thanks to @naruaway, @MineLPPhynix, @mrsekut and @zkulbeda for contributing to this release.

  • Change input type of mimeType validation to Blob
  • Rename useDefault method to withDefault (issue #80)
  • Add brand method to support branded types (pull request #85)
valibot - v0.11.1

Published by fabian-hiller about 1 year ago

Many thanks to @jdgamble555 and @BastiDood for contributing to this release.

  • Fix types of enumType and enumTypeAsync schema (issue #70)
  • Improve performance of loops with for...of (pull request #68)
valibot - v0.11.0

Published by fabian-hiller about 1 year ago

Many thanks to @NiclasHaderer and @gmaxlev for contributing to this release.

  • Fix prototype pollution vulnerability of record and recordAsync (pull request #67)
  • Add finite, safeInteger and multipleOf validation (pull request #64, #65, #66)
valibot - v0.10.0

Published by fabian-hiller about 1 year ago

Many thanks to @gmaxlev for contributing to this release.

  • Add integer validation (pull request #62)
valibot - v0.9.0

Published by fabian-hiller about 1 year ago

Many thanks to @Danielwinkelmann and @sillvva for contributing to this release.

  • Add imei validation and isLuhnAlgo util (pull request #37)
  • Fix isoDateTime, isoTime, isoTimeSecond and isoTimestamp validation (pull request #42)
valibot - v0.8.0

Published by fabian-hiller about 1 year ago

Many thanks to @Thanaen, @hungify and @yamiteru for contributing to this release.

  • Fix infered object and record types (issue #9, #10, #34)
  • Add strict and strictAsync method to detect unknown object keys
valibot - v0.7.0

Published by fabian-hiller about 1 year ago

Many thanks to @JoakimDeak, @jasikpark, @luxferoo, @logaretm and @Yovach for contributing to this release.

  • Add is method which can be used as a type guard (pull request #13)
  • Throw all validation issues of a pipeline by default (issues #18)
  • Add abortPipeEarly option to abort pipe on first error (issues #18)
  • Add abortEarly option to abort on first error
valibot - v0.6.0

Published by fabian-hiller about 1 year ago

  • Add toMinValue and toMaxValue transformation
valibot - v0.5.0

Published by fabian-hiller about 1 year ago

Many thanks to @lino-levan, @emilbonnek and @kiliman for contributing to this release.

  • Fix invalid comparable import when using Deno
  • Add util functions to exports of library
  • Rename minRange and maxRange to minValue and maxValue (issue #20)
  • Add value validation function
valibot - v0.4.0

Published by fabian-hiller about 1 year ago

Many thanks to @lino-levan for contributing to this release.

  • Add instance and instanceAsync schema
  • Refactor library to work with Deno