2024-10-13 15:25:30 -07:00
|
|
|
import * as v from 'valibot';
|
2024-08-28 04:43:23 -07:00
|
|
|
|
|
|
|
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/} */
|
2024-10-13 15:25:30 -07:00
|
|
|
const announcementSchema = v.object({
|
|
|
|
id: v.string(),
|
|
|
|
content: v.fallback(v.string(), ''),
|
2024-10-14 11:54:44 -07:00
|
|
|
starts_at: v.fallback(v.nullable(z.string().datetime()), null),
|
|
|
|
ends_at: v.fallback(v.nullable(z.string().datetime()), null),
|
2024-10-13 15:25:30 -07:00
|
|
|
all_day: v.fallback(v.boolean(), false),
|
|
|
|
read: v.fallback(v.boolean(), false),
|
2024-08-28 04:43:23 -07:00
|
|
|
published_at: dateSchema,
|
|
|
|
reactions: filteredArray(announcementReactionSchema),
|
|
|
|
statuses: z.preprocess(
|
|
|
|
(statuses: any) => Array.isArray(statuses)
|
|
|
|
? Object.fromEntries(statuses.map((status: any) => [status.url, status.account?.acct]) || [])
|
|
|
|
: statuses,
|
2024-10-14 11:54:44 -07:00
|
|
|
v.record(v.string(), v.string(), v.string()),
|
2024-08-28 04:43:23 -07:00
|
|
|
),
|
|
|
|
mentions: filteredArray(mentionSchema),
|
|
|
|
tags: filteredArray(tagSchema),
|
|
|
|
emojis: filteredArray(customEmojiSchema),
|
|
|
|
updated_at: dateSchema,
|
|
|
|
});
|
|
|
|
|
2024-10-13 15:25:30 -07:00
|
|
|
type Announcement = v.InferOutput<typeof announcementSchema>;
|
2024-08-28 04:43:23 -07:00
|
|
|
|
|
|
|
export { announcementSchema, type Announcement };
|