2024-10-13 15:25:30 -07:00
|
|
|
import * as v from 'valibot';
|
2024-09-01 05:57:41 -07:00
|
|
|
|
|
|
|
import { accountSchema } from './account';
|
|
|
|
|
|
|
|
const scrobbleSchema = z.preprocess((scrobble: any) => scrobble ? {
|
|
|
|
external_link: scrobble.externalLink,
|
|
|
|
...scrobble,
|
2024-10-13 15:25:30 -07:00
|
|
|
} : null, v.object({
|
2024-10-14 13:50:34 -07:00
|
|
|
id: v.pipe(v.unknown(), v.transform(String)),
|
2024-09-01 05:57:41 -07:00
|
|
|
account: accountSchema,
|
|
|
|
created_at: z.string().datetime({ offset: true }),
|
2024-10-13 15:25:30 -07:00
|
|
|
title: v.string(),
|
|
|
|
artist: v.fallback(v.string(), ''),
|
|
|
|
album: v.fallback(v.string(), ''),
|
|
|
|
external_link: v.fallback(v.nullable(v.string()), null),
|
|
|
|
length: v.fallback(v.nullable(v.number()), null),
|
2024-09-01 05:57:41 -07:00
|
|
|
}));
|
|
|
|
|
2024-10-13 15:25:30 -07:00
|
|
|
type Scrobble = v.InferOutput<typeof scrobbleSchema>;
|
2024-09-01 05:57:41 -07:00
|
|
|
|
|
|
|
export { scrobbleSchema, type Scrobble };
|