UNPKG

aniql

Version:

A library for interacting with the AniList API.

83 lines (82 loc) 2.81 kB
import type { FieldsSelection, Mutation, MutationGenqlSelection, Query, QueryGenqlSelection } from './genql'; import { type ClientOptions } from './genql/runtime'; /** Represents a value that can be awaited. */ export type Awaitable<T> = Promise<T> | T; interface AniQLAuthBase { client_id: number; } interface AniQLAuthResCode extends AniQLAuthBase { response_type: 'code'; client_secret: string; redirect_uri: string; } interface AniQLAuthResToken extends AniQLAuthBase { response_type: 'token'; } export type AniQLAuth = AniQLAuthResCode | AniQLAuthResToken; /** Options for the AniQL client. */ export type AniQLOptions = ClientOptions & { auth: AniQLAuth; get_token?: () => Awaitable<string | undefined>; }; /** Options for the request made by the AniQL client. */ export type AniQLRequestOptions = { token?: string; }; /** * AniQLClientError is an error class for errors that occur in the AniQL client. * * It extends the built-in Error class and includes a status code. */ export declare class AniQLClientError extends Error { status: number; constructor(status: number, message: string); } export type RateLimitData = { limit: number; remaining: number; reset: number; }; export interface AniQLClientEvents { rate_limit: Array<(data: RateLimitData) => Awaitable<any>>; } /** * AniQLClient is a client for interacting with the AniList GraphQL API. * It allows you to perform queries and mutations against the AniList API. * You can also get the login URL to authenticate users. * * The client will automatically include the token, if provided via options, in the Authorization header for requests. * * For documentation on the AniList API, see https://docs.anilist.co/ */ export declare class AniQLClient { #private; static base_url: string; rate_limit: RateLimitData; on<K extends keyof AniQLClientEvents>(event: K, listener: AniQLClientEvents[K][number]): this; constructor(opts: AniQLOptions); query<R extends QueryGenqlSelection>(request: R & { __name?: string; }, opts?: AniQLRequestOptions): Promise<FieldsSelection<Query, R>>; mutation<R extends MutationGenqlSelection>(request: R & { __name?: string; }, opts?: AniQLRequestOptions): Promise<FieldsSelection<Mutation, R>>; make_query: <R extends QueryGenqlSelection>(request: R & { __name?: string; }) => R & { __name?: string; }; make_mutation: <R extends MutationGenqlSelection>(request: R & { __name?: string; }) => R & { __name?: string; }; get auth_url(): string; auth_exchange(code: string): Promise<{ access_token: string; token_type: string; expires_in: number; refresh_token: string; }>; } export * from './genql';