api/federation/validators/extensions/custom_emojis.ts
Jesse Wierzbinski f80cffd01a
refactor(federation): 🚚 Rename schemas to validators
Fixes issues with Bun bundling
2024-09-22 17:15:19 +02:00

53 lines
1.5 KiB
TypeScript

/**
* Custom emojis extension.
* @module federation/schemas/extensions/custom_emojis
* @see module:federation/schemas/base
* @see https://versia.pub/extensions/custom-emojis
*/
import { z } from "zod";
import { ImageOnlyContentFormatSchema } from "../content_format.ts";
import { emojiRegex } from "../regex.ts";
/**
* @description Used to validate the properties the extension's custom field
* @see https://versia.pub/extensions/custom-emojis
* @example
* {
* // ...
* "extensions": {
* "pub.versia:custom_emojis": {
* "emojis": [
* {
* "name": ":happy_face:",
* "url": {
* "image/png": {
* "content": "https://cdn.example.com/emojis/happy_face.png",
* "remote": true
* }
* }
* },
* // ...
* ]
* }
* }
* // ...
* }
*/
export const CustomEmojiExtensionSchema = z.object({
emojis: z.array(
z
.object({
name: z
.string()
.min(1)
.max(256)
.regex(
emojiRegex,
"Emoji name must be alphanumeric, underscores, or dashes, and surrounded by identifiers",
),
url: ImageOnlyContentFormatSchema,
})
.strict(),
),
});