Skip to content

Releases: fabian-hiller/valibot

v0.17.1

25 Sep 04:30
Compare
Choose a tag to compare

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

  • Fix missing file extensions for Deno (pull request #178, #181)

v0.17.0

17 Sep 06:49
Compare
Choose a tag to compare

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)

v0.16.0

16 Sep 05:21
Compare
Choose a tag to compare

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 } 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

10 Sep 04:42
Compare
Choose a tag to compare

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

v0.14.0

09 Sep 00:57
Compare
Choose a tag to compare

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)

v0.13.1

23 Aug 09:38
Compare
Choose a tag to compare
  • Change object type check in object and record schema

v0.13.0

23 Aug 00:02
Compare
Choose a tag to compare

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 function 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 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

10 Aug 23:29
Compare
Choose a tag to compare

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)

v0.11.1

07 Aug 10:20
Compare
Choose a tag to compare

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)

v0.11.0

06 Aug 11:59
Compare
Choose a tag to compare

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)