• Get multiple manga by their AniList media IDs. Returns results in original order matching input array.

    Parameters

    • ids: number[]

      Array of AniList manga media IDs.

    • Optionaltoken: string

      Optional access token for authenticated requests.

    • OptionalabortSignal: AbortSignal

      Optional AbortSignal to cancel the request.

    • OptionalnoRetry: boolean

      Disable automatic retry logic (default: false).

    Returns Promise<AniListManga[]>

    Promise resolving to array of AniListManga objects.

    export async function getMangaByIds(
    ids: number[],
    token?: string,
    abortSignal?: AbortSignal,
    noRetry?: boolean,
    ): Promise<AniListManga[]> {
    return withGroupAsync(
    `[AniListClient] Get Manga (${ids.length} IDs)`,
    async () => {
    if (!ids.length) {
    return [];
    }

    try {
    // Updated type parameter to handle potential nested data structure
    const response = await request<{
    data?: { Page: { media: AniListManga[] } };
    Page?: { media: AniListManga[] };
    }>(GET_MANGA_BY_IDS, { ids }, token, abortSignal, undefined, noRetry);

    // Validate response structure
    if (!response?.data) {
    console.error(
    `[AniListClient] ❌ Invalid API response when fetching manga by IDs:`,
    response,
    );
    return [];
    }

    // Check for nested data structure
    const responseData = response.data.data ?? response.data;

    // Safely access media array or return empty array if not found
    return responseData.Page?.media || [];
    } catch (error) {
    console.error(
    `[AniListClient] ❌ Error fetching manga by IDs [${ids.join(", ")}]:`,
    error,
    );
    throw error;
    }
    },
    );
    }