bigbuffet-rw/packages/pl-api/lib/entities/scrobble.ts
marcin mikołajczak c618e1f619 Default to whatever content type is supported
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
2024-10-21 20:39:23 +02:00

26 lines
724 B
TypeScript

import * as v from 'valibot';
import { accountSchema } from './account';
import { datetimeSchema } from './utils';
const scrobbleSchema = v.pipe(
v.any(),
v.transform((scrobble: any) => scrobble ? {
external_link: scrobble.externalLink,
...scrobble,
} : null),
v.object({
id: v.pipe(v.unknown(), v.transform(String)),
account: accountSchema,
created_at: datetimeSchema,
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),
}),
);
type Scrobble = v.InferOutput<typeof scrobbleSchema>;
export { scrobbleSchema, type Scrobble };