Skip to main content

Built and signed on GitHub Actions

Federation types, validators and cryptography for Versia server implementations.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
52%
Published
2 days ago (0.1.1)
class EntityValidator

Validates entities against their respective schemas.

Examples

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 = { ... };

Methods

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.

Delete(data: unknown): Promise<Delete>

Validates a Delete entity.

DislikeExtension(data: unknown): Promise<DislikeExtension>

Validates a Dislike entity.

Entity(data: unknown): Promise<Entity>

Validates an Entity.

EntityExtensionProperty(data: unknown): Promise<EntityExtensionProperty>

Validates an ExtensionProperty.

Follow(data: unknown): Promise<Follow>

Validates a Follow entity.

FollowAccept(data: unknown): Promise<FollowAccept>

Validates a FollowAccept entity.

FollowReject(data: unknown): Promise<FollowReject>

Validates a FollowReject entity.

Group(data: unknown): Promise<Group>

Validates a Group entity.

InstanceMetadata(data: unknown): Promise<InstanceMetadata>

Validates an InstanceMetadata entity.

LikeExtension(data: unknown): Promise<LikeExtension>

Validates a Like entity.

Note(data: unknown): Promise<Note>

Validates a Note entity.

PollVoteExtension(data: unknown): Promise<PollVoteExtension>

Validates a Vote entity.

ReactionExtension(data: unknown): Promise<ReactionExtension>

Validates a Reaction entity.

ShareExtension(data: unknown): Promise<ShareExtension>

Validates a Share entity.

Unfollow(data: unknown): Promise<Unfollow>

Validates an Unfollow entity.

User(data: unknown): Promise<User>

Validates a User entity.

VanityExtension(data: unknown): Promise<VanityExtension>

Validates a VanityExtension entity.

private
validate<T extends AnyZod>(
schema: T,
data: unknown,
): Promise<InferType<T>>

Add Package

deno add jsr:@versia/federation

Import symbol

import { EntityValidator } from "@versia/federation";

---- OR ----

Import directly with a jsr specifier

import { EntityValidator } from "jsr:@versia/federation";

Add Package

npx jsr add @versia/federation

Import symbol

import { EntityValidator } from "@versia/federation";

Add Package

yarn dlx jsr add @versia/federation

Import symbol

import { EntityValidator } from "@versia/federation";

Add Package

pnpm dlx jsr add @versia/federation

Import symbol

import { EntityValidator } from "@versia/federation";

Add Package

bunx jsr add @versia/federation

Import symbol

import { EntityValidator } from "@versia/federation";