rawCheckAsync

Creates a raw check validation action.

const Action = v.rawCheckAsync<TInput>(action);

Generics

  • TInput extends any

Parameters

Explanation

With rawCheckAsync you can freely validate the input with a custom action and add issues if necessary.

Returns

Examples

The following examples show how rawCheckAsync can be used.

Add users schema

Object schema that ensures that only users not already in the group are included.

This rawCheckAsync validation action adds an issue for any invalid username and forwards it via path to the appropriate nested field.

import { isAlreadyInGroup } from '~/api';

const AddUsersSchema = v.pipeAsync(
  v.object({
    groupId: v.pipe(v.string(), v.uuid()),
    usernames: v.array(v.pipe(v.string(), v.nonEmpty())),
  }),
  v.rawCheckAsync(async ({ dataset, addIssue }) => {
    if (dataset.typed) {
      await Promise.all(
        dataset.value.usernames.map(async (username, index) => {
          if (await isAlreadyInGroup(username, dataset.value.groupId)) {
            addIssue({
              received: username,
              message: 'The user is already in the group.',
              path: [
                {
                  type: 'object',
                  origin: 'value',
                  input: dataset.value,
                  key: 'usernames',
                  value: dataset.value.usernames,
                },
                {
                  type: 'array',
                  origin: 'value',
                  input: dataset.value.usernames,
                  key: index,
                  value: username,
                },
              ],
            });
          }
        })
      );
    }
  })
);

The following APIs can be combined with rawCheckAsync.

Schemas

Utils

Async

Contributors

Thanks to all the contributors who helped make this page better!

  • GitHub profile picture of fabian-hiller
  • GitHub profile picture of EltonLobo07

Partners

Thanks to our partners who support the project ideally and financially.

Sponsors

Thanks to our GitHub sponsors who support the project financially.

  • GitHub profile picture of antfu
  • GitHub profile picture of Thanaen
  • GitHub profile picture of osdiab
  • GitHub profile picture of ruiaraujo012
  • GitHub profile picture of hyunbinseo
  • GitHub profile picture of F0rce
  • GitHub profile picture of fabulousgk
  • GitHub profile picture of jdgamble555
  • GitHub profile picture of isoden
  • GitHub profile picture of nickytonline
  • GitHub profile picture of caegdeveloper
  • GitHub profile picture of luckasnix
  • GitHub profile picture of andrew-3kb
  • GitHub profile picture of dslatkin