forwardAsync
Forwards the issues of the passed validation action.
const Action = v.forwardAsync<TInput, TIssue, TPath>(action, path);
Generics
TInputextends Record<string, unknown> | ArrayLike<unknown>TIssueextends BaseIssue<unknown>TPathextends RequiredPath
Parameters
actionBaseValidation<TInput, TInput, TIssue> | BaseValidationAsync<TInput, TInput, TIssue>pathValidPath<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
ActionBaseValidationAsync<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
Actions
check, checkItems, empty, everyItem, excludes, filterItems, findItem, guard, includes, length, mapItems, maxLength, metadata, minLength, nonEmpty, notLength, partialCheck, rawCheck, reduceItems, someItem, sortItems
Utils
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/