mirror of
https://github.com/versia-pub/api.git
synced 2026-03-13 12:19:15 +01:00
refactor(federation): 🚚 Rename schemas to validators
Fixes issues with Bun bundling
This commit is contained in:
parent
ebf16a82cb
commit
f80cffd01a
19 changed files with 40 additions and 37 deletions
|
|
@ -1,52 +0,0 @@
|
|||
/**
|
||||
* 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(),
|
||||
),
|
||||
});
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
import { z } from "zod";
|
||||
import { EntitySchema } from "../base.ts";
|
||||
|
||||
/**
|
||||
* @description Like entity
|
||||
* @see https://versia.pub/extensions/likes
|
||||
* @example
|
||||
* {
|
||||
* "id": "3e7e4750-afd4-4d99-a256-02f0710a0520",
|
||||
* "type": "pub.versia:likes/Like",
|
||||
* "created_at": "2021-01-01T00:00:00.000Z",
|
||||
* "author": "https://example.com/users/6e0204a2-746c-4972-8602-c4f37fc63bbe",
|
||||
* "uri": "https://example.com/likes/3e7e4750-afd4-4d99-a256-02f0710a0520",
|
||||
* "liked": "https://otherexample.org/notes/fmKZ763jzIU8"
|
||||
* }
|
||||
*/
|
||||
export const LikeSchema = EntitySchema.extend({
|
||||
type: z.literal("pub.versia:likes/Like"),
|
||||
author: z.string().url(),
|
||||
liked: z.string().url(),
|
||||
});
|
||||
|
||||
/**
|
||||
* @description Dislike entity
|
||||
* @see https://versia.pub/extensions/likes
|
||||
* @example
|
||||
* {
|
||||
* "id": "3e7e4750-afd4-4d99-a256-02f0710a0520",
|
||||
* "type": "pub.versia:likes/Dislike",
|
||||
* "created_at": "2021-01-01T00:00:00.000Z",
|
||||
* "author": "https://example.com/users/6e0204a2-746c-4972-8602-c4f37fc63bbe",
|
||||
* "uri": "https://example.com/dislikes/3e7e4750-afd4-4d99-a256-02f0710a0520",
|
||||
* "disliked": "https://otherexample.org/notes/fmKZ763jzIU8"
|
||||
* }
|
||||
*/
|
||||
export const DislikeSchema = EntitySchema.extend({
|
||||
type: z.literal("pub.versia:likes/Dislike"),
|
||||
author: z.string().url(),
|
||||
disliked: z.string().url(),
|
||||
});
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
/**
|
||||
* Polls extension
|
||||
* @module federation/schemas/extensions/polls
|
||||
* @see module:federation/schemas/base
|
||||
* @see https://versia.pub/extensions/polls
|
||||
*/
|
||||
import { z } from "zod";
|
||||
import { EntitySchema } from "../base.ts";
|
||||
|
||||
/**
|
||||
* @description Vote extension entity
|
||||
* @see https://versia.pub/extensions/polls
|
||||
* @example
|
||||
* {
|
||||
* "id": "6f27bc77-58ee-4c9b-b804-8cc1c1182fa9",
|
||||
* "type": "pub.versia:polls/Vote",
|
||||
* "uri": "https://example.com/actions/6f27bc77-58ee-4c9b-b804-8cc1c1182fa9",
|
||||
* "created_at": "2021-01-01T00:00:00.000Z",
|
||||
* "author": "https://example.com/users/6e0204a2-746c-4972-8602-c4f37fc63bbe",
|
||||
* "poll": "https://example.com/notes/f08a124e-fe90-439e-8be4-15a428a72a19",
|
||||
* "option": 1
|
||||
* }
|
||||
*/
|
||||
export const VoteSchema = EntitySchema.extend({
|
||||
type: z.literal("pub.versia:polls/Vote"),
|
||||
author: z.string().url(),
|
||||
poll: z.string().url(),
|
||||
option: z
|
||||
.number()
|
||||
.int()
|
||||
.nonnegative()
|
||||
.max(2 ** 64 - 1),
|
||||
});
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
/**
|
||||
* Reactions extension
|
||||
* @module federation/schemas/extensions/reactions
|
||||
* @see module:federation/schemas/base
|
||||
* @see https://versia.pub/extensions/reactions
|
||||
*/
|
||||
import { z } from "zod";
|
||||
import { EntitySchema } from "../base.ts";
|
||||
|
||||
/**
|
||||
* @description Reaction extension entity
|
||||
* @see https://versia.pub/extensions/reactions
|
||||
* @example
|
||||
* {
|
||||
* "id": "6f27bc77-58ee-4c9b-b804-8cc1c1182fa9",
|
||||
* "type": "pub.versia:reactions/Reaction",
|
||||
* "uri": "https://example.com/actions/6f27bc77-58ee-4c9b-b804-8cc1c1182fa9",
|
||||
* "created_at": "2021-01-01T00:00:00.000Z",
|
||||
* "author": "https://example.com/users/6e0204a2-746c-4972-8602-c4f37fc63bbe",
|
||||
* "object": "https://example.com/publications/f08a124e-fe90-439e-8be4-15a428a72a19",
|
||||
* "content": "😀",
|
||||
* }
|
||||
*/
|
||||
export const ReactionSchema = EntitySchema.extend({
|
||||
type: z.literal("pub.versia:reactions/Reaction"),
|
||||
author: z.string().url(),
|
||||
object: z.string().url(),
|
||||
content: z.string().min(1).max(256),
|
||||
});
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
import { z } from "zod";
|
||||
import { EntitySchema } from "../base.ts";
|
||||
|
||||
/**
|
||||
* @description Share entity
|
||||
* @see https://versia.pub/extensions/share
|
||||
* @example
|
||||
* {
|
||||
* "id": "3e7e4750-afd4-4d99-a256-02f0710a0520",
|
||||
* "type": "pub.versia:share/Share",
|
||||
* "created_at": "2021-01-01T00:00:00.000Z",
|
||||
* "author": "https://example.com/users/6e0204a2-746c-4972-8602-c4f37fc63bbe",
|
||||
* "uri": "https://example.com/shares/3e7e4750-afd4-4d99-a256-02f0710a0520",
|
||||
* "shared": "https://otherexample.org/notes/fmKZ763jzIU8"
|
||||
* }
|
||||
*/
|
||||
export const ShareSchema = EntitySchema.extend({
|
||||
type: z.literal("pub.versia:share/Share"),
|
||||
author: z.string().url(),
|
||||
shared: z.string().url(),
|
||||
});
|
||||
|
|
@ -1,107 +0,0 @@
|
|||
/**
|
||||
* Vanity extension schema.
|
||||
* @module federation/schemas/extensions/vanity
|
||||
* @see module:federation/schemas/base
|
||||
* @see https://versia.pub/extensions/vanity
|
||||
*/
|
||||
|
||||
import { z } from "zod";
|
||||
import {
|
||||
AudioOnlyContentFormatSchema,
|
||||
ImageOnlyContentFormatSchema,
|
||||
} from "../content_format.ts";
|
||||
import { isISOString } from "../regex.ts";
|
||||
|
||||
/**
|
||||
* @description Vanity extension entity
|
||||
* @see https://versia.pub/extensions/vanity
|
||||
* @example
|
||||
* {
|
||||
* // ...
|
||||
* "type": "User",
|
||||
* // ...
|
||||
* "extensions": {
|
||||
* "pub.versia:vanity": {
|
||||
* "avatar_overlays": [
|
||||
* {
|
||||
* "image/png": {
|
||||
* "content": "https://cdn.example.com/ab5081cf-b11f-408f-92c2-7c246f290593/cat_ears.png",
|
||||
* "remote": true,
|
||||
* }
|
||||
* }
|
||||
* ],
|
||||
* "avatar_mask": {
|
||||
* "image/png": {
|
||||
* "content": "https://cdn.example.com/d8c42be1-d0f7-43ef-b4ab-5f614e1beba4/rounded_square.jpeg",
|
||||
* "remote": true,
|
||||
* }
|
||||
* },
|
||||
* "background": {
|
||||
* "image/png": {
|
||||
* "content": "https://cdn.example.com/6492ddcd-311e-4921-9567-41b497762b09/untitled-file-0019822.png",
|
||||
* "remote": true,
|
||||
* }
|
||||
* },
|
||||
* "audio": {
|
||||
* "audio/mpeg": {
|
||||
* "content": "https://cdn.example.com/4da2f0d4-4728-4819-83e4-d614e4c5bebc/michael-jackson-thriller.mp3",
|
||||
* "remote": true,
|
||||
* }
|
||||
* },
|
||||
* "pronouns": {
|
||||
* "en-us": [
|
||||
* "he/him",
|
||||
* {
|
||||
* "subject": "they",
|
||||
* "object": "them",
|
||||
* "dependent_possessive": "their",
|
||||
* "independent_possessive": "theirs",
|
||||
* "reflexive": "themself"
|
||||
* },
|
||||
* ]
|
||||
* },
|
||||
* "birthday": "1998-04-12",
|
||||
* "location": "+40.6894-074.0447/",
|
||||
* "aliases": [
|
||||
* "https://burger.social/accounts/349ee237-c672-41c1-aadc-677e185f795a",
|
||||
* "https://versia.social/users/f565ef02-035d-4974-ba5e-f62a8558331d"
|
||||
* ]
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
export const VanityExtensionSchema = z
|
||||
.object({
|
||||
avatar_overlays: z
|
||||
.array(ImageOnlyContentFormatSchema)
|
||||
.optional()
|
||||
.nullable(),
|
||||
avatar_mask: ImageOnlyContentFormatSchema.optional().nullable(),
|
||||
background: ImageOnlyContentFormatSchema.optional().nullable(),
|
||||
audio: AudioOnlyContentFormatSchema.optional().nullable(),
|
||||
pronouns: z.record(
|
||||
z.string(),
|
||||
z.array(
|
||||
z.union([
|
||||
z
|
||||
.object({
|
||||
subject: z.string(),
|
||||
object: z.string(),
|
||||
dependent_possessive: z.string(),
|
||||
independent_possessive: z.string(),
|
||||
reflexive: z.string(),
|
||||
})
|
||||
.strict(),
|
||||
z.string(),
|
||||
]),
|
||||
),
|
||||
),
|
||||
birthday: z
|
||||
.string()
|
||||
.refine((v) => isISOString(v), "must be a valid ISO8601 datetime")
|
||||
.optional()
|
||||
.nullable(),
|
||||
location: z.string().optional().nullable(),
|
||||
aliases: z.array(z.string().url()).optional().nullable(),
|
||||
})
|
||||
.strict();
|
||||
Loading…
Add table
Add a link
Reference in a new issue