intersectAsync
Creates an intersect schema.
I recommend to read the intersections guide before using this schema function.
const Schema = v.intersectAsync<TOptions, TMessage>(options, message);
Generics
TOptionsextends IntersectOptionsAsyncTMessageextends ErrorMessage<IntersectIssue> | undefined
Parameters
optionsTOptionsmessageTMessage
Explanation
With intersectAsync you can validate if the input matches each of the given options. If the output of the intersection cannot be successfully merged, you can use message to customize the error message.
Returns
SchemaIntersectSchemaAsync<TOptions, TMessage>
Examples
The following examples show how intersectAsync can be used.
Donation schema
Schema that combines objects to validate donation details.
import { isOrganizationPresent } from '~/api';
const DonationSchema = v.intersectAsync([
v.objectAsync({
organizationId: v.pipeAsync(
v.string(),
v.uuid(),
v.checkAsync(
isOrganizationPresent,
'The organization is not in the database.'
)
),
}),
// Assume the schemas below are from different files and are reused here
v.object({
amount: v.pipe(v.number(), v.minValue(100)),
message: v.pipe(v.string(), v.nonEmpty()),
}),
v.object({
amount: v.pipe(v.number(), v.maxValue(1_000_000)),
message: v.pipe(v.string(), v.maxLength(500)),
}),
]);
Related
The following APIs can be combined with intersectAsync.
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
config, getDefault, getFallback
Actions
args, base64, bic, brand, bytes, check, checkItems, codePoints, creditCard, cuid2, decimal, description, digits, domain, email, emoji, empty, endsWith, entries, everyItem, excludes, filterItems, findItem, finite, flavor, graphemes, gtValue, guard, hash, hexColor, hexadecimal, imei, includes, integer, ip, ipv4, ipv6, isbn, isrc, isoDate, isoDateTime, isoDateTimeSecond, isoTime, isoTimeSecond, isoTimestamp, isoWeek, ksuid, length, ltValue, mac, mac48, mac64, mapItems, maxBytes, maxCodePoints, maxEntries, maxGraphemes, maxLength, maxSize, maxValue, maxWords, metadata, mimeType, minBytes, minCodePoints, minEntries, minGraphemes, minLength, minSize, minValue, minWords, multipleOf, nanoid, nonEmpty, notBytes, notCodePoints, notEntries, notGraphemes, notLength, notSize, notValue, notValues, notWords, octal, parseJson, partialCheck, rawCheck, rawTransform, readonly, reduceItems, regex, returns, rfcEmail, safeInteger, size, slug, someItem, sortItems, startsWith, stringifyJson, title, toCamelCase, toKebabCase, toLowerCase, toMaxValue, toMinValue, toPascalCase, toSnakeCase, toUpperCase, transform, trim, trimEnd, trimStart, ulid, url, uuid, value, values, words
Utils
entriesFromList, isOfKind, isOfType
Async
arrayAsync, awaitAsync, checkAsync, customAsync, exactOptionalAsync, fallbackAsync, getDefaultsAsync, getFallbacksAsync, lazyAsync, looseObjectAsync, looseTupleAsync, mapAsync, nonNullableAsync, nonNullishAsync, nonOptionalAsync, nullableAsync, nullishAsync, objectAsync, objectWithRestAsync, optionalAsync, parseAsync, parserAsync, partialCheckAsync, pipeAsync, rawCheckAsync, rawTransformAsync, recordAsync, safeParseAsync, safeParserAsync, setAsync, strictObjectAsync, strictTupleAsync, transformAsync, tupleAsync, tupleWithRestAsync, unionAsync, variantAsync
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/intersectAsync/