recordAsync

Creates a record schema.

const Schema = v.recordAsync<TKey, TValue, TMessage>(key, value, message);

Generics

Parameters

  • key TKey
  • value TValue
  • message TMessage

Explanation

With recordAsync you can validate the data type of the input and whether the entries match key and value. If the input is not an object, you can use message to customize the error message.

This schema filters certain entries from the record for security reasons.

This schema marks an entry as optional if it detects that its key is a literal type. The reason for this is that it is not technically possible to detect missing literal keys without restricting the key schema to string, enum and picklist. However, if enum and picklist are used, it is better to use objectAsync with entriesFromList because it already covers the needed functionality. This decision also reduces the bundle size of recordAsync, because it only needs to check the entries of the input and not any missing keys.

Returns

Examples

The following examples show how recordAsync can be used.

ID to email schema

Schema to validate a record that maps an ID to a public user email.

import { isEmailPublic } from '~/api';

const IdToEmailSchema = v.recordAsync(
  v.pipe(v.string(), v.uuid()),
  v.pipeAsync(
    v.string(),
    v.email(),
    v.checkAsync(isEmailPublic, 'The email address is private.')
  )
);

The following APIs can be combined with recordAsync.

Schemas

Methods

Actions

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