bigbuffet-rw/packages/pl-api/lib/entities/announcement.ts
marcin mikołajczak 2f7e149f75 pl-api: Mostly finish migration to valibot
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
2024-10-16 01:08:56 +02:00

34 lines
1.2 KiB
TypeScript

import * as v from 'valibot';
import { announcementReactionSchema } from './announcement-reaction';
import { customEmojiSchema } from './custom-emoji';
import { mentionSchema } from './mention';
import { tagSchema } from './tag';
import { dateSchema, filteredArray } from './utils';
/** @see {@link https://docs.joinmastodon.org/entities/announcement/} */
const announcementSchema = v.object({
id: v.string(),
content: v.fallback(v.string(), ''),
starts_at: v.fallback(v.nullable(z.string().datetime()), null),
ends_at: v.fallback(v.nullable(z.string().datetime()), null),
all_day: v.fallback(v.boolean(), false),
read: v.fallback(v.boolean(), false),
published_at: dateSchema,
reactions: filteredArray(announcementReactionSchema),
statuses: v.pipe(
v.any(),
v.transform((statuses: any) => Array.isArray(statuses)
? Object.fromEntries(statuses.map((status: any) => [status.url, status.account?.acct]) || [])
: statuses),
v.record(v.string(), v.string()),
),
mentions: filteredArray(mentionSchema),
tags: filteredArray(tagSchema),
emojis: filteredArray(customEmojiSchema),
updated_at: dateSchema,
});
type Announcement = v.InferOutput<typeof announcementSchema>;
export { announcementSchema, type Announcement };