2024-10-13 15:25:30 -07:00
|
|
|
import * as v from 'valibot';
|
2024-08-28 04:43:23 -07:00
|
|
|
|
2024-10-29 14:44:28 -07:00
|
|
|
/**
|
|
|
|
* @category Schemas
|
|
|
|
* @see {@link https://docs.joinmastodon.org/entities/Status/#Mention}
|
|
|
|
*/
|
2024-10-15 16:08:56 -07:00
|
|
|
const mentionSchema = v.pipe(
|
|
|
|
v.object({
|
|
|
|
id: v.string(),
|
|
|
|
username: v.fallback(v.string(), ''),
|
|
|
|
url: v.fallback(v.pipe(v.string(), v.url()), ''),
|
|
|
|
acct: v.string(),
|
|
|
|
}),
|
|
|
|
v.transform((mention) => {
|
|
|
|
if (!mention.username) {
|
|
|
|
mention.username = mention.acct.split('@')[0];
|
|
|
|
}
|
2024-08-28 04:43:23 -07:00
|
|
|
|
2024-10-15 16:08:56 -07:00
|
|
|
return mention;
|
|
|
|
}),
|
|
|
|
);
|
2024-08-28 04:43:23 -07:00
|
|
|
|
2024-10-13 15:25:30 -07:00
|
|
|
type Mention = v.InferOutput<typeof mentionSchema>;
|
2024-08-28 04:43:23 -07:00
|
|
|
|
|
|
|
export { mentionSchema, type Mention };
|