Spec-Zone.ru › Valibot

forwardAsync

Forwards the issues of the passed validation action.

const Action = v.forwardAsync<TInput, TIssue, TPath>(action, path);

Generics

  • TInput extends Record<string, unknown> | ArrayLike<unknown>
  • TIssue extends BaseIssue<unknown>
  • TPath extends RequiredPath

Parameters

  • action BaseValidation<TInput, TInput, TIssue> | BaseValidationAsync<TInput, TInput, TIssue>
  • path ValidPath<TInput, TPath>

Explanation

forwardAsync allows you to forward the issues of the passed validation action via path to a nested field of a schema.

Returns

  • Action BaseValidationAsync<TInput, TInput, TIssue>

Examples

The following examples show how forwardAsync can be used.

Allowed action schema

Schema that checks if the user is allowed to complete an action.

import { isAllowedAction, isUsernamePresent } from '~/api';

const AllowedActionSchema = v.pipeAsync(
  v.objectAsync({
    username: v.pipeAsync(
      v.string(),
      v.minLength(3),
      v.checkAsync(isUsernamePresent, 'The username is not in the database.')
    ),
    action: v.picklist(['view', 'edit', 'delete']),
  }),
  v.forwardAsync(
    v.checkAsync(
      isAllowedAction,
      'The user is not allowed to complete the action.'
    ),
    ['action']
  )
);

Related

The following APIs can be combined with forwardAsync.

Schemas

any, array, custom, looseObject, looseTuple, object, objectWithRest, record, strictObject, strictTuple, tuple, tupleWithRest, union, unknown, variant

Methods

omit, pick

Actions

check, checkItems, empty, everyItem, excludes, filterItems, findItem, guard, includes, length, mapItems, maxLength, metadata, minLength, nonEmpty, notLength, partialCheck, rawCheck, reduceItems, someItem, sortItems

Utils

isOfKind, isOfType

Async

arrayAsync, awaitAsync, checkAsync, customAsync, looseObjectAsync, looseTupleAsync, objectAsync, objectWithRestAsync, partialAsync, partialCheckAsync, rawCheckAsync, recordAsync, requiredAsync, strictObjectAsync, strictTupleAsync, tupleAsync, tupleWithRestAsync, unionAsync, variantAsync

© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/forwardAsync/

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API