mal api schema impl
This commit is contained in:
@@ -1,87 +1,81 @@
|
|||||||
/*
|
import { z } from "zod";
|
||||||
|
|
||||||
query Parameters
|
export const MalAnimeListStatusEnum = z.enum([
|
||||||
status
|
"watching",
|
||||||
string
|
"completed",
|
||||||
|
"on_hold",
|
||||||
|
"dropped",
|
||||||
|
"plan_to_watch",
|
||||||
|
]);
|
||||||
|
export type MalAnimeListStatus = z.infer<typeof MalAnimeListStatusEnum>;
|
||||||
|
|
||||||
Filters returned anime list by these statuses.
|
export const MalAnimeListSortEnum = z.enum([
|
||||||
|
"list_score",
|
||||||
|
"list_updated_at",
|
||||||
|
"anime_title",
|
||||||
|
"anime_start_date",
|
||||||
|
"anime_id",
|
||||||
|
]);
|
||||||
|
export type MalAnimeListSort = z.infer<typeof MalAnimeListSortEnum>;
|
||||||
|
|
||||||
To return all anime, don't specify this field.
|
const NumericQueryParamSchema = z
|
||||||
|
.union([z.number(), z.string()])
|
||||||
|
.transform((v) => (typeof v === "string" ? Number(v) : v));
|
||||||
|
|
||||||
Valid values:
|
export const MalAnimeListQuerySchema = z
|
||||||
|
.object({
|
||||||
|
status: MalAnimeListStatusEnum.optional(),
|
||||||
|
sort: MalAnimeListSortEnum.optional(),
|
||||||
|
limit: NumericQueryParamSchema.pipe(
|
||||||
|
z.number().int().min(1).max(1000),
|
||||||
|
).optional(),
|
||||||
|
offset: NumericQueryParamSchema.pipe(z.number().int().min(0)).optional(),
|
||||||
|
})
|
||||||
|
.strict();
|
||||||
|
export type MalAnimeListQuery = z.infer<typeof MalAnimeListQuerySchema>;
|
||||||
|
|
||||||
watching
|
export const MalAnimeEntry = z
|
||||||
completed
|
.object({
|
||||||
on_hold
|
id: z.number().int().positive(),
|
||||||
dropped
|
title: z.string(),
|
||||||
plan_to_watch
|
main_picture: z
|
||||||
|
.object({
|
||||||
|
medium: z.string(),
|
||||||
|
large: z.string(),
|
||||||
|
})
|
||||||
|
.strict()
|
||||||
|
.optional(),
|
||||||
|
})
|
||||||
|
.strict();
|
||||||
|
|
||||||
sort
|
export const MalAnimeListEntry = z
|
||||||
string
|
.object({
|
||||||
|
status: MalAnimeListStatusEnum,
|
||||||
|
score: z.number().int().min(0).max(10),
|
||||||
|
num_episodes_watched: z.number().int().min(0),
|
||||||
|
is_rewatching: z.boolean(),
|
||||||
|
updated_at: z.iso.datetime(),
|
||||||
|
start_date: z.iso.date().optional(),
|
||||||
|
finish_date: z.iso.date().optional(),
|
||||||
|
})
|
||||||
|
.strict();
|
||||||
|
|
||||||
Valid values:
|
export const MalAnimeListResponseSchema = z
|
||||||
Value Order
|
.object({
|
||||||
list_score Descending
|
data: z.array(
|
||||||
list_updated_at Descending
|
z
|
||||||
anime_title Ascending
|
.object({
|
||||||
anime_start_date Descending
|
node: MalAnimeEntry,
|
||||||
anime_id (Under Development) Ascending
|
list_status: MalAnimeListEntry,
|
||||||
limit
|
})
|
||||||
integer
|
.strict(),
|
||||||
Default: 100
|
),
|
||||||
|
paging: z
|
||||||
The maximum value is 1000.
|
.object({
|
||||||
offset
|
next: z.string().optional(),
|
||||||
integer
|
previous: z.string().optional(),
|
||||||
Default: 0
|
})
|
||||||
|
.strict(),
|
||||||
*/
|
})
|
||||||
|
.strict();
|
||||||
/*
|
export type MalAnimeListResponse = z.infer<typeof MalAnimeListResponseSchema>;
|
||||||
sample response
|
|
||||||
|
|
||||||
{
|
|
||||||
"data": [
|
|
||||||
{
|
|
||||||
"node": {
|
|
||||||
"id": 31646,
|
|
||||||
"title": "3-gatsu no Lion",
|
|
||||||
"main_picture": {
|
|
||||||
"medium": "https://cdn.myanimelist.net/images/anime/3/82899.jpg",
|
|
||||||
"large": "https://cdn.myanimelist.net/images/anime/3/82899l.jpg"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"list_status": {
|
|
||||||
"status": "watching",
|
|
||||||
"score": 0,
|
|
||||||
"num_episodes_watched": 2,
|
|
||||||
"is_rewatching": false,
|
|
||||||
"updated_at": "2025-07-17T00:57:26+00:00",
|
|
||||||
"start_date": "2025-07-16"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"node": {
|
|
||||||
"id": 38101,
|
|
||||||
"title": "5-toubun no Hanayome",
|
|
||||||
"main_picture": {
|
|
||||||
"medium": "https://cdn.myanimelist.net/images/anime/1819/97947.jpg",
|
|
||||||
"large": "https://cdn.myanimelist.net/images/anime/1819/97947l.jpg"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"list_status": {
|
|
||||||
"status": "completed",
|
|
||||||
"score": 0,
|
|
||||||
"num_episodes_watched": 12,
|
|
||||||
"is_rewatching": false,
|
|
||||||
"updated_at": "2019-06-02T09:12:42+00:00",
|
|
||||||
"start_date": "2019-05-31",
|
|
||||||
"finish_date": "2019-06-02"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"paging": {
|
|
||||||
"next": "https://api.myanimelist.net/v2/users/CaZzzer/animelist?offset=2&fields=list_status&limit=2"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|||||||
Reference in New Issue
Block a user