metadata
Creates a custom metadata action.
const Action = v.metadata<TInput, TMetadata>(metadata_);
Generics
TInputextends anyTMetadataextends 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
ActionMetadataAction<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
Utils
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/metadata/