Spec-Zone.ru › Valibot

metadata

Creates a custom metadata action.

const Action = v.metadata<TInput, TMetadata>(metadata_);

Generics

  • TInput extends any
  • TMetadata extends Record<string, unknown>

Parameters

  • metadata_ TMetadata

Explanation

With metadata you can attach custom metadata to a schema. This can be useful when working with AI tools or for documentation purposes.

Returns

  • Action MetadataAction<TInput, TMetadata>

Examples

The following examples show how metadata can be used.

Profile table schema

Schema to describe a profile table.

const ProfileTableSchema = v.pipe(
  v.object({
    username: v.pipe(v.string(), v.nonEmpty()),
    email: v.pipe(v.string(), v.email()),
    avatar: v.pipe(v.string(), v.url()),
    description: v.pipe(v.string(), v.maxLength(500)),
  }),
  v.metadata({
    table: 'profiles',
    primaryKey: 'username',
    indexes: ['email'],
  })
);

Related

The following APIs can be combined with metadata.

Schemas

any, array, bigint, blob, boolean, custom, date, enum, exactOptional, file, function, instance, intersect, lazy, literal, looseObject, looseTuple, map, nan, never, nonNullable, nonNullish, nonOptional, null, nullable, nullish, number, object, objectWithRest, optional, picklist, promise, record, set, strictObject, strictTuple, string, symbol, tuple, tupleWithRest, undefined, undefinedable, union, unknown, variant, void

Methods

getMetadata, pipe

Utils

isOfKind, isOfType

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

Spec-Zone.ru

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