2024-10-13 15:25:30 -07:00
|
|
|
import * as v from 'valibot';
|
2024-08-28 04:43:23 -07:00
|
|
|
|
|
|
|
import { dateSchema } from './utils';
|
|
|
|
|
2024-09-05 14:50:43 -07:00
|
|
|
const markerSchema = z.preprocess((marker: any) => marker ? ({
|
2024-08-28 04:43:23 -07:00
|
|
|
unread_count: marker.pleroma?.unread_count,
|
|
|
|
...marker,
|
2024-10-13 15:25:30 -07:00
|
|
|
}) : null, v.object({
|
|
|
|
last_read_id: v.string(),
|
2024-10-14 11:54:44 -07:00
|
|
|
version: v.pipe(v.number(), v.integer()),
|
2024-08-28 04:43:23 -07:00
|
|
|
updated_at: dateSchema,
|
2024-10-14 13:50:34 -07:00
|
|
|
unread_count: v.fallback(v.optional(v.pipe(v.number(), v.integer())), undefined),
|
2024-08-28 04:43:23 -07:00
|
|
|
}));
|
|
|
|
|
|
|
|
/** @see {@link https://docs.joinmastodon.org/entities/Marker/} */
|
2024-10-13 15:25:30 -07:00
|
|
|
type Marker = v.InferOutput<typeof markerSchema>;
|
2024-08-28 04:43:23 -07:00
|
|
|
|
2024-10-14 11:54:44 -07:00
|
|
|
const markersSchema = v.record(v.string(), markerSchema);
|
2024-08-28 04:43:23 -07:00
|
|
|
|
2024-10-13 15:25:30 -07:00
|
|
|
type Markers = v.InferOutput<typeof markersSchema>;
|
2024-08-28 04:43:23 -07:00
|
|
|
|
|
|
|
export {
|
|
|
|
markerSchema,
|
|
|
|
markersSchema,
|
|
|
|
type Marker,
|
|
|
|
type Markers,
|
|
|
|
};
|