2023-10-19 15:21:54 +02:00
|
|
|
import { Fields, Fn, OperationParser } from "../types/Anilist.ts"
|
2023-10-11 02:09:35 +02:00
|
|
|
import { Media } from "./Media.ts"
|
|
|
|
import { FuzzyDate } from "../anilist.ts"
|
|
|
|
import { User } from "./User.ts"
|
2023-10-22 09:06:25 +02:00
|
|
|
import { MediaListScoreArgs } from "../../graphql-codegen/generated/graphql.ts"
|
2023-10-11 02:09:35 +02:00
|
|
|
|
2023-10-20 00:04:03 +02:00
|
|
|
export const MediaListTypeOptions = ({ operation, level }: Fields<OperationParser>) => ({
|
2023-10-14 19:46:57 +02:00
|
|
|
/** The order each list should be displayed in */
|
2023-10-21 22:31:57 +02:00
|
|
|
withSectionOrder(op?: { alias?: string }) {
|
2023-10-20 01:58:21 +02:00
|
|
|
operation.set({ alias: op?.alias, subField: "sectionOrder", level })
|
2023-10-14 19:46:57 +02:00
|
|
|
return this
|
|
|
|
},
|
|
|
|
/** If the completed sections of the list should be separated by format */
|
2023-10-21 22:31:57 +02:00
|
|
|
withSplitCompletedSectionByFormat(op?: { alias?: string }) {
|
2023-10-20 01:58:21 +02:00
|
|
|
operation.set({ alias: op?.alias, subField: "splitCompletedSectionByFormat", level })
|
2023-10-14 19:46:57 +02:00
|
|
|
return this
|
|
|
|
},
|
|
|
|
/** The names of the user's custom lists */
|
2023-10-21 22:31:57 +02:00
|
|
|
withCustomLists(op?: { alias?: string }) {
|
2023-10-20 01:58:21 +02:00
|
|
|
operation.set({ alias: op?.alias, subField: "customLists", level })
|
2023-10-14 19:46:57 +02:00
|
|
|
return this
|
|
|
|
},
|
|
|
|
/** The names of the user's advanced scoring sections */
|
2023-10-21 22:31:57 +02:00
|
|
|
withAdvancedScoring(op?: { alias?: string }) {
|
2023-10-20 01:58:21 +02:00
|
|
|
operation.set({ alias: op?.alias, subField: "advancedScoring", level })
|
2023-10-14 19:46:57 +02:00
|
|
|
return this
|
|
|
|
},
|
|
|
|
/** If advanced scoring is enabled */
|
2023-10-21 22:31:57 +02:00
|
|
|
withAdvancedScoringEnabled(op?: { alias?: string }) {
|
2023-10-20 01:58:21 +02:00
|
|
|
operation.set({ alias: op?.alias, subField: "advancedScoringEnabled", level })
|
2023-10-14 19:46:57 +02:00
|
|
|
return this
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2023-10-20 00:04:03 +02:00
|
|
|
export const MediaListOptions = ({ operation, level }: Fields<OperationParser>) => ({
|
2023-10-14 19:46:57 +02:00
|
|
|
/** The score format the user is using for media lists */
|
2023-10-21 22:31:57 +02:00
|
|
|
withScoreFormat(op?: { alias?: string }) {
|
2023-10-20 01:58:21 +02:00
|
|
|
operation.set({ alias: op?.alias, subField: "scoreFormat", level })
|
2023-10-14 19:46:57 +02:00
|
|
|
return this
|
|
|
|
},
|
|
|
|
/** The default order list rows should be displayed in */
|
2023-10-21 22:31:57 +02:00
|
|
|
withRowOrder(op?: { alias?: string }) {
|
2023-10-20 01:58:21 +02:00
|
|
|
operation.set({ alias: op?.alias, subField: "rowOrder", level })
|
2023-10-14 19:46:57 +02:00
|
|
|
return this
|
|
|
|
},
|
|
|
|
/** The user's anime list options */
|
2023-10-20 01:58:21 +02:00
|
|
|
withAnimeList(op: { alias?: string; fn: Fn<typeof MediaListTypeOptions> }) {
|
2023-10-22 00:50:13 +02:00
|
|
|
operation.set({ alias: op.alias, subField: "animeList", level, hasSubField: true })
|
2023-10-20 00:04:03 +02:00
|
|
|
op.fn(MediaListTypeOptions({ operation, level: level + 1 }))
|
2023-10-14 19:46:57 +02:00
|
|
|
return this
|
|
|
|
},
|
|
|
|
/** The user's manga list options */
|
2023-10-20 01:58:21 +02:00
|
|
|
withMangaList(op: { alias?: string; fn: Fn<typeof MediaListTypeOptions> }) {
|
2023-10-22 00:50:13 +02:00
|
|
|
operation.set({ alias: op.alias, subField: "mangaList", level, hasSubField: true })
|
2023-10-20 00:04:03 +02:00
|
|
|
op.fn(MediaListTypeOptions({ operation, level: level + 1 }))
|
2023-10-14 19:46:57 +02:00
|
|
|
return this
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2023-10-20 00:04:03 +02:00
|
|
|
export const MediaList = ({ operation, level }: Fields<OperationParser>) => ({
|
2023-10-20 01:58:21 +02:00
|
|
|
withCompletedAt(op: { alias?: string; fn: Fn<typeof FuzzyDate> }) {
|
|
|
|
operation.set({ alias: op.alias, subField: "completedAt", level, hasSubField: true })
|
2023-10-20 00:04:03 +02:00
|
|
|
op.fn(FuzzyDate({ operation, level: level + 1 }))
|
2023-10-11 02:09:35 +02:00
|
|
|
return this
|
|
|
|
},
|
2023-10-20 01:58:21 +02:00
|
|
|
withStartedAt(op: { alias?: string; fn: Fn<typeof FuzzyDate> }) {
|
|
|
|
operation.set({ alias: op.alias, subField: "startedAt", level, hasSubField: true })
|
2023-10-20 00:04:03 +02:00
|
|
|
op.fn(FuzzyDate({ operation, level: level + 1 }))
|
2023-10-11 02:09:35 +02:00
|
|
|
return this
|
|
|
|
},
|
2023-10-21 22:31:57 +02:00
|
|
|
withId(op?: { alias?: string }) {
|
2023-10-20 01:58:21 +02:00
|
|
|
operation.set({ alias: op?.alias, subField: "id", level })
|
2023-10-11 02:09:35 +02:00
|
|
|
return this
|
|
|
|
},
|
2023-10-21 22:31:57 +02:00
|
|
|
withUserId(op?: { alias?: string }) {
|
2023-10-20 01:58:21 +02:00
|
|
|
operation.set({ alias: op?.alias, subField: "userId", level })
|
2023-10-11 02:09:35 +02:00
|
|
|
return this
|
|
|
|
},
|
2023-10-21 22:31:57 +02:00
|
|
|
withMediaId(op?: { alias?: string }) {
|
2023-10-20 01:58:21 +02:00
|
|
|
operation.set({ alias: op?.alias, subField: "mediaId", level })
|
2023-10-11 02:09:35 +02:00
|
|
|
return this
|
|
|
|
},
|
2023-10-22 01:47:34 +02:00
|
|
|
withScore(op?: { alias?: string; args?: MediaListScoreArgs }) {
|
|
|
|
operation.set({ alias: op?.alias, subField: "score", level, variables: op?.args })
|
|
|
|
return this
|
|
|
|
},
|
2023-10-21 22:31:57 +02:00
|
|
|
withStatus(op?: { alias?: string }) {
|
2023-10-20 01:58:21 +02:00
|
|
|
operation.set({ alias: op?.alias, subField: "status", level })
|
2023-10-11 02:09:35 +02:00
|
|
|
return this
|
|
|
|
},
|
2023-10-21 22:31:57 +02:00
|
|
|
withProgress(op?: { alias?: string }) {
|
2023-10-20 01:58:21 +02:00
|
|
|
operation.set({ alias: op?.alias, subField: "progress", level })
|
2023-10-11 02:09:35 +02:00
|
|
|
return this
|
|
|
|
},
|
2023-10-21 22:31:57 +02:00
|
|
|
withProgressVolumes(op?: { alias?: string }) {
|
2023-10-20 01:58:21 +02:00
|
|
|
operation.set({ alias: op?.alias, subField: "progressVolumes", level })
|
2023-10-11 02:09:35 +02:00
|
|
|
return this
|
|
|
|
},
|
2023-10-21 22:31:57 +02:00
|
|
|
withRepeat(op?: { alias?: string }) {
|
2023-10-20 01:58:21 +02:00
|
|
|
operation.set({ alias: op?.alias, subField: "repeat", level })
|
2023-10-11 02:09:35 +02:00
|
|
|
return this
|
|
|
|
},
|
2023-10-21 22:31:57 +02:00
|
|
|
withPriority(op?: { alias?: string }) {
|
2023-10-20 01:58:21 +02:00
|
|
|
operation.set({ alias: op?.alias, subField: "priority", level })
|
2023-10-11 02:09:35 +02:00
|
|
|
return this
|
|
|
|
},
|
2023-10-21 22:31:57 +02:00
|
|
|
withPrivate(op?: { alias?: string }) {
|
2023-10-20 01:58:21 +02:00
|
|
|
operation.set({ alias: op?.alias, subField: "private", level })
|
2023-10-11 02:09:35 +02:00
|
|
|
return this
|
|
|
|
},
|
2023-10-21 22:31:57 +02:00
|
|
|
withNotes(op?: { alias?: string }) {
|
2023-10-20 01:58:21 +02:00
|
|
|
operation.set({ alias: op?.alias, subField: "notes", level })
|
2023-10-11 02:09:35 +02:00
|
|
|
return this
|
|
|
|
},
|
2023-10-21 22:31:57 +02:00
|
|
|
withAdvancedScores(op?: { alias?: string }) {
|
2023-10-20 01:58:21 +02:00
|
|
|
operation.set({ alias: op?.alias, subField: "advancedScores", level })
|
2023-10-11 02:09:35 +02:00
|
|
|
return this
|
|
|
|
},
|
2023-10-21 22:31:57 +02:00
|
|
|
withHiddenFromStatusLists(op?: { alias?: string }) {
|
2023-10-20 01:58:21 +02:00
|
|
|
operation.set({ alias: op?.alias, subField: "hiddenFromStatusLists", level })
|
2023-10-11 02:09:35 +02:00
|
|
|
return this
|
|
|
|
},
|
2023-10-21 22:31:57 +02:00
|
|
|
withUpdatedAt(op?: { alias?: string }) {
|
2023-10-20 01:58:21 +02:00
|
|
|
operation.set({ alias: op?.alias, subField: "updatedAt", level })
|
2023-10-11 02:09:35 +02:00
|
|
|
return this
|
|
|
|
},
|
2023-10-21 22:31:57 +02:00
|
|
|
withCreatedAt(op?: { alias?: string }) {
|
2023-10-20 01:58:21 +02:00
|
|
|
operation.set({ alias: op?.alias, subField: "createdAt", level })
|
2023-10-11 02:09:35 +02:00
|
|
|
return this
|
|
|
|
},
|
2023-10-20 01:58:21 +02:00
|
|
|
withMedia(op?: { alias?: string; fn?: Fn<typeof Media> }) {
|
|
|
|
operation.set({ alias: op?.alias, subField: "media", level, hasSubField: true })
|
2023-10-20 00:04:03 +02:00
|
|
|
if (op?.fn) op.fn(Media({ operation, level: level + 1 }))
|
|
|
|
else Media({ operation, level: level + 1 }).withId()
|
2023-10-11 02:09:35 +02:00
|
|
|
return this
|
|
|
|
},
|
2023-10-20 01:58:21 +02:00
|
|
|
withUser(op?: { alias?: string; fn?: Fn<typeof User> }) {
|
|
|
|
operation.set({ alias: op?.alias, subField: "user", level, hasSubField: true })
|
2023-10-20 00:04:03 +02:00
|
|
|
if (op?.fn) op.fn(User({ operation, level: level + 1 }))
|
|
|
|
else User({ operation, level: level + 1 }).withId()
|
2023-10-11 02:09:35 +02:00
|
|
|
return this
|
|
|
|
},
|
|
|
|
})
|