import * as v from 'valibot'; import { filteredArray } from './utils'; const translationPollSchema = v.object({ id: v.string(), options: v.array(v.object({ title: v.string(), })), }); const translationMediaAttachment = v.object({ id: v.string(), description: v.fallback(v.string(), ''), }); /** @see {@link https://docs.joinmastodon.org/entities/Translation/} */ const translationSchema = z.preprocess((translation: any) => { /** * handle Akkoma * @see {@link https://akkoma.dev/AkkomaGang/akkoma/src/branch/develop/lib/pleroma/web/mastodon_api/controllers/status_controller.ex#L504} */ if (translation?.text) return { content: translation.text, detected_source_language: translation.detected_language, provider: '', }; return translation; }, v.object({ id: v.fallback(v.nullable(v.string()), null), content: v.fallback(v.string(), ''), spoiler_text: v.fallback(v.string(), ''), poll: v.fallback(v.optional(translationPollSchema), undefined), media_attachments: filteredArray(translationMediaAttachment), detected_source_language: v.string(), provider: v.string(), })); type Translation = v.InferOutput; export { translationSchema, type Translation };