315 lines
12 KiB
TypeScript
315 lines
12 KiB
TypeScript
import {
|
|
StaffCharacterMediaArgs,
|
|
StaffCharactersArgs,
|
|
StaffStaffMediaArgs,
|
|
} from "../../graphql-codegen/generated/graphql.ts"
|
|
import { Fields, Fn, OperationParser } from "../types/Anilist.ts"
|
|
import { FuzzyDate } from "../anilist.ts"
|
|
import { PageInfo } from "./Page.ts"
|
|
import { User } from "./User.ts"
|
|
import { CharacterConnection } from "./Character.ts"
|
|
import { MediaConnection } from "./Media.ts"
|
|
import { AtLeastOne } from "../types/AtLeastOne.ts"
|
|
|
|
export const StaffRoleType = ({ operation, level }: Fields<OperationParser>) => ({
|
|
/** The voice actors of the character */
|
|
withVoiceActor(op: { alias?: string; fn: Fn<typeof Staff> }) {
|
|
operation.set({ alias: op.alias, subField: "voiceActor", level, hasSubField: true })
|
|
op.fn(Staff({ operation, level: level + 1 }))
|
|
return this
|
|
},
|
|
/** Notes regarding the VA's role for the character */
|
|
withRoleNotes(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "roleNotes", level })
|
|
return this
|
|
},
|
|
/** Used for grouping roles where multiple dubs exist for the same language. Either dubbing company name or language variant. */
|
|
withDubGroup(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "dubGroup", level })
|
|
return this
|
|
},
|
|
})
|
|
|
|
const StaffEdge = ({ operation, level }: Fields<OperationParser>) => ({
|
|
withNode(op?: { alias?: string; fn?: Fn<typeof Staff> }) {
|
|
operation.set({ alias: op?.alias, subField: "node", level, hasSubField: true })
|
|
if (op?.fn) op.fn(Staff({ operation, level: level + 1 }))
|
|
else Staff({ operation, level: level + 1 }).withId()
|
|
return this
|
|
},
|
|
/** The id of the connection */
|
|
withId(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "id", level })
|
|
return this
|
|
},
|
|
/** The role of the staff member in the production of the media */
|
|
withRole(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "role", level })
|
|
return this
|
|
},
|
|
/** The order the staff should be displayed from the users favourites */
|
|
withFavouriteOrder(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "favouriteOrder", level })
|
|
return this
|
|
},
|
|
})
|
|
|
|
export const StaffConnection = ({ operation, level }: Fields<OperationParser>) => ({
|
|
withEdges(op?: { alias?: string; fn?: Fn<typeof StaffEdge> }) {
|
|
operation.set({ alias: op?.alias, subField: "edges", level, hasSubField: true })
|
|
if (op?.fn) op.fn(StaffEdge({ operation, level: level + 1 }))
|
|
else StaffEdge({ operation, level: level + 1 }).withNode()
|
|
return this
|
|
},
|
|
withNodes(op?: { alias?: string; fn?: Fn<typeof Staff> }) {
|
|
operation.set({ alias: op?.alias, subField: "nodes", level, hasSubField: true })
|
|
if (op?.fn) op.fn(Staff({ operation, level: level + 1 }))
|
|
else Staff({ operation, level: level + 1 }).withId()
|
|
return this
|
|
},
|
|
/** The pagination information */
|
|
withPageInfo(op: { alias?: string; fn: Fn<typeof PageInfo> }) {
|
|
operation.set({ alias: op.alias, subField: "pageInfo", level, hasSubField: true })
|
|
op.fn(PageInfo({ operation, level: level + 1 }))
|
|
return this
|
|
},
|
|
})
|
|
|
|
const StaffName = ({ operation, level }: Fields<OperationParser>) => ({
|
|
/** The person's given name */
|
|
withFirst(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "first", level })
|
|
return this
|
|
},
|
|
/** The person's middle name */
|
|
withMiddle(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "middle", level })
|
|
return this
|
|
},
|
|
/** The person's surname */
|
|
withLast(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "last", level })
|
|
return this
|
|
},
|
|
/** The person's first and last name */
|
|
withFull(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "full", level })
|
|
return this
|
|
},
|
|
/** The person's full name in their native language */
|
|
withNative(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "native", level })
|
|
return this
|
|
},
|
|
/** Other names the staff member might be referred to as (pen names) */
|
|
withAlternative(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "alternative", level })
|
|
return this
|
|
},
|
|
/** The currently authenticated users preferred name language. Default romaji for non-authenticated */
|
|
withUserPreferred(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "userPreferred", level })
|
|
return this
|
|
},
|
|
})
|
|
|
|
const StaffImage = ({ operation, level }: Fields<OperationParser>) => ({
|
|
/** The person's image of media at its largest size */
|
|
withLarge(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "large", level })
|
|
return this
|
|
},
|
|
/** The person's image of media at medium size */
|
|
withMedium(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "medium", level })
|
|
return this
|
|
},
|
|
})
|
|
|
|
export const Staff = ({ operation, level }: Fields<OperationParser>) => ({
|
|
/** The id of the staff member */
|
|
withId(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "id", level })
|
|
return this
|
|
},
|
|
/** The names of the staff member */
|
|
withName(op?: { alias?: string; fn?: Fn<typeof StaffName> }) {
|
|
operation.set({ alias: op?.alias, subField: "name", level, hasSubField: true })
|
|
if (op?.fn) op.fn(StaffName({ operation, level: level + 1 }))
|
|
else StaffName({ operation, level: level + 1 }).withUserPreferred()
|
|
return this
|
|
},
|
|
/** The primary language of the staff member. Current values: Japanese, English, Korean, Italian, Spanish, Portuguese, French, German, Hebrew, Hungarian, Chinese, Arabic, Filipino, Catalan, Finnish, Turkish, Dutch, Swedish, Thai, Tagalog, Malaysian, Indonesian, Vietnamese, Nepali, Hindi, Urdu */
|
|
withLanguageV2(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "languageV2", level })
|
|
return this
|
|
},
|
|
/** The staff images */
|
|
withImage(op?: { alias?: string; fn?: Fn<typeof StaffImage> }) {
|
|
operation.set({ alias: op?.alias, subField: "image", level, hasSubField: true })
|
|
if (op?.fn) op.fn(StaffImage({ operation, level: level + 1 }))
|
|
else StaffImage({ operation, level: level + 1 }).withMedium()
|
|
return this
|
|
},
|
|
/** A general description of the staff member */
|
|
withDescription(op?: { alias?: string; args?: { asHtml: boolean } }) {
|
|
operation.set({ alias: op?.alias, subField: "description", level, variables: op?.args })
|
|
return this
|
|
},
|
|
/** The person's primary occupations */
|
|
withPrimaryOccupations(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "primaryOccupations", level })
|
|
return this
|
|
},
|
|
/** The staff's gender. Usually Male, Female, or Non-binary but can be any string. */
|
|
withGender(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "gender", level })
|
|
return this
|
|
},
|
|
withDateOfBirth(op?: { alias?: string; fn?: Fn<typeof FuzzyDate> }) {
|
|
operation.set({ alias: op?.alias, subField: "dateOfBirth", level, hasSubField: true })
|
|
if (op?.fn) op.fn(FuzzyDate({ operation, level: level + 1 }))
|
|
else {
|
|
FuzzyDate({ operation, level: level + 1 })
|
|
.withYear()
|
|
.withMonth()
|
|
.withDay()
|
|
}
|
|
return this
|
|
},
|
|
withDateOfDeath(op?: { alias?: string; fn?: Fn<typeof FuzzyDate> }) {
|
|
operation.set({ alias: op?.alias, subField: "dateOfDeath", level, hasSubField: true })
|
|
if (op?.fn) op.fn(FuzzyDate({ operation, level: level + 1 }))
|
|
else {
|
|
FuzzyDate({ operation, level: level + 1 })
|
|
.withYear()
|
|
.withMonth()
|
|
.withDay()
|
|
}
|
|
return this
|
|
},
|
|
/** The person's age in years */
|
|
withAge(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "age", level })
|
|
return this
|
|
},
|
|
/** [startYear, endYear] (If the 2nd value is not present staff is still active) */
|
|
withYearsActive(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "yearsActive", level })
|
|
return this
|
|
},
|
|
/** The persons birthplace or hometown */
|
|
withHomeTown(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "homeTown", level })
|
|
return this
|
|
},
|
|
/** The persons blood type */
|
|
withBloodType(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "bloodType", level })
|
|
return this
|
|
},
|
|
/** If the staff member is marked as favourite by the currently authenticated user */
|
|
withIsFavourite(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "isFavourite", level })
|
|
return this
|
|
},
|
|
/** If the staff member is blocked from being added to favourites */
|
|
withIsFavouriteBlocked(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "isFavouriteBlocked", level })
|
|
return this
|
|
},
|
|
/** The url for the staff page on the AniList website */
|
|
withSiteUrl(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "siteUrl", level })
|
|
return this
|
|
},
|
|
/** Media where the staff member has a production role */
|
|
withStaffMedia(
|
|
op: {
|
|
alias?: string
|
|
args?: AtLeastOne<StaffStaffMediaArgs> | undefined
|
|
fn: Fn<typeof MediaConnection>
|
|
},
|
|
) {
|
|
operation.set({
|
|
alias: op.alias,
|
|
subField: "staffMedia",
|
|
level,
|
|
variables: op?.args,
|
|
hasSubField: true,
|
|
})
|
|
op.fn(MediaConnection({ operation, level: level + 1 }))
|
|
return this
|
|
},
|
|
/** Characters voiced by the actor */
|
|
withCharacters(
|
|
op: {
|
|
alias?: string
|
|
args?: AtLeastOne<StaffCharactersArgs> | undefined
|
|
fn: Fn<typeof CharacterConnection>
|
|
},
|
|
) {
|
|
operation.set({
|
|
alias: op.alias,
|
|
subField: "characters",
|
|
level,
|
|
variables: op?.args,
|
|
hasSubField: true,
|
|
})
|
|
op.fn(CharacterConnection({ operation, level: level + 1 }))
|
|
return this
|
|
},
|
|
/** Media the actor voiced characters in. (Same data as characters with media as node instead of characters) */
|
|
withCharacterMedia(
|
|
op: {
|
|
alias?: string
|
|
args?: AtLeastOne<StaffCharacterMediaArgs>
|
|
fn: Fn<typeof MediaConnection>
|
|
},
|
|
) {
|
|
operation.set({
|
|
alias: op.alias,
|
|
subField: "characterMedia",
|
|
level,
|
|
variables: op?.args,
|
|
hasSubField: true,
|
|
})
|
|
op.fn(MediaConnection({ operation, level: level + 1 }))
|
|
return this
|
|
},
|
|
/** Staff member that the submission is referencing */
|
|
withStaff(op?: { alias?: string; fn?: Fn<typeof Staff> }) {
|
|
operation.set({ alias: op?.alias, subField: "staff", level, hasSubField: true })
|
|
if (op?.fn) op.fn(Staff({ operation, level: level + 1 }))
|
|
else Staff({ operation, level: level + 1 }).withId()
|
|
return this
|
|
},
|
|
/** Submitter for the submission */
|
|
withSubmitter(op?: { alias?: string; fn?: Fn<typeof User> }) {
|
|
operation.set({ alias: op?.alias, subField: "submitter", level, hasSubField: true })
|
|
if (op?.fn) op.fn(User({ operation, level: level + 1 }))
|
|
else User({ operation, level: level + 1 }).withId()
|
|
return this
|
|
},
|
|
/** Status of the submission */
|
|
withSubmissionStatus(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "submissionStatus", level })
|
|
return this
|
|
},
|
|
/** Inner details of submission status */
|
|
withSubmissionNotes(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "submissionNotes", level })
|
|
return this
|
|
},
|
|
/** The amount of user's who have favourited the staff member */
|
|
withFavourites(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "favourites", level })
|
|
return this
|
|
},
|
|
/** Notes for site moderators */
|
|
withModNotes(op?: { alias?: string }) {
|
|
operation.set({ alias: op?.alias, subField: "modNotes", level })
|
|
return this
|
|
},
|
|
})
|