2024-10-13 15:25:30 -07:00
|
|
|
import * as v from 'valibot';
|
2024-08-28 04:43:23 -07:00
|
|
|
|
2024-11-01 09:30:32 -07:00
|
|
|
import { previewCardAuthorSchema } from './preview-card-author';
|
|
|
|
import { filteredArray } from './utils';
|
|
|
|
|
2024-10-29 14:44:28 -07:00
|
|
|
/**
|
|
|
|
* @category Schemas
|
|
|
|
* @see {@link https://docs.joinmastodon.org/entities/PreviewCard/}
|
|
|
|
*/
|
2024-10-13 15:25:30 -07:00
|
|
|
const previewCardSchema = v.object({
|
2024-11-01 09:30:32 -07:00
|
|
|
/** @deprecated */
|
2024-10-13 15:25:30 -07:00
|
|
|
author_name: v.fallback(v.string(), ''),
|
2024-11-01 09:30:32 -07:00
|
|
|
/** @deprecated */
|
2024-10-14 11:54:44 -07:00
|
|
|
author_url: v.fallback(v.pipe(v.string(), v.url()), ''),
|
2024-11-01 09:30:32 -07:00
|
|
|
authors: filteredArray(previewCardAuthorSchema),
|
2024-10-13 15:25:30 -07:00
|
|
|
blurhash: v.fallback(v.nullable(v.string()), null),
|
|
|
|
description: v.fallback(v.string(), ''),
|
2024-10-14 11:54:44 -07:00
|
|
|
embed_url: v.fallback(v.pipe(v.string(), v.url()), ''),
|
2024-10-13 15:25:30 -07:00
|
|
|
height: v.fallback(v.number(), 0),
|
|
|
|
html: v.fallback(v.string(), ''),
|
|
|
|
image: v.fallback(v.nullable(v.string()), null),
|
|
|
|
image_description: v.fallback(v.string(), ''),
|
|
|
|
provider_name: v.fallback(v.string(), ''),
|
2024-10-14 11:54:44 -07:00
|
|
|
provider_url: v.fallback(v.pipe(v.string(), v.url()), ''),
|
2024-10-13 15:25:30 -07:00
|
|
|
title: v.fallback(v.string(), ''),
|
2024-10-14 11:54:44 -07:00
|
|
|
type: v.fallback(v.picklist(['link', 'photo', 'video', 'rich']), 'link'),
|
|
|
|
url: v.pipe(v.string(), v.url()),
|
2024-10-13 15:25:30 -07:00
|
|
|
width: v.fallback(v.number(), 0),
|
2024-08-28 04:43:23 -07:00
|
|
|
});
|
|
|
|
|
2024-11-29 07:01:54 -08:00
|
|
|
/**
|
|
|
|
* @category Entity types
|
|
|
|
*/
|
2024-10-13 15:25:30 -07:00
|
|
|
type PreviewCard = v.InferOutput<typeof previewCardSchema>;
|
2024-08-28 04:43:23 -07:00
|
|
|
|
|
|
|
export { previewCardSchema, type PreviewCard };
|