Validates entities against their respective schemas.
▶import { EntityValidator, type ValidationError } from "@versia/federation";
const validator = new EntityValidator();
import { EntityValidator, type ValidationError } from "@versia/federation"; const validator = new EntityValidator();
// Will throw a special ValidationError with a human-friendly error message // and a machine-friendly error object if the data is invalid. const note = await validator.Note({ type: "Note", content: "Hello, world!", });
try { await validator.Note({ type: "Note", content: 123, }); } catch (error) { sendUser((error as ValidationError).toString()); }
// Types are also included for TypeScript users that don't use the extracted ones import type { Note } from "@versia/federation/types";
const note: Note = { ... };
Collection(data: unknown): Promise<Collection>
Validates a Collection entity.
ContentFormat(data: unknown): Promise<ContentFormat>
Validates a ContentFormat entity.
CustomEmojiExtension(data: unknown): Promise<CustomEmojiExtension>
Validates a CustomEmojiExtension entity.
DislikeExtension(data: unknown): Promise<DislikeExtension>
Validates a Dislike entity.
EntityExtensionProperty(data: unknown): Promise<EntityExtensionProperty>
Validates an ExtensionProperty.
FollowAccept(data: unknown): Promise<FollowAccept>
Validates a FollowAccept entity.
FollowReject(data: unknown): Promise<FollowReject>
Validates a FollowReject entity.
InstanceMetadata(data: unknown): Promise<InstanceMetadata>
Validates an InstanceMetadata entity.
LikeExtension(data: unknown): Promise<LikeExtension>
Validates a Like entity.
PollVoteExtension(data: unknown): Promise<PollVoteExtension>
Validates a Vote entity.
ReactionExtension(data: unknown): Promise<ReactionExtension>
Validates a Reaction entity.
VanityExtension(data: unknown): Promise<VanityExtension>
Validates a VanityExtension entity.