UNPKG

deepsource-mcp-server

Version:
72 lines (71 loc) 3.13 kB
/** * @fileoverview Pagination helpers for the DeepSource MCP Server * This module provides utilities for working with pagination. */ import { PageInfo, PaginationParams, PaginatedResponse, PaginationMetadata } from './types.js'; /** * Creates an empty paginated response with no items * @template T The type of items in the response * @returns {PaginatedResponse<T>} Empty paginated response with consistent structure * @public */ export declare function createEmptyPaginatedResponse<T>(): PaginatedResponse<T>; /** * Normalizes pagination parameters for GraphQL queries * Ensures consistency in pagination parameters following Relay pagination best practices * * Normalization rules: * 1. If 'before' is provided (backward pagination): * - Use 'last' as the count parameter (default: 10) * - Remove any 'first' parameter to avoid ambiguity * 2. If 'last' is provided without 'before' (non-standard but supported): * - Keep 'last' as is * - Remove any 'first' parameter to avoid ambiguity * - Log a warning about non-standard usage * 3. Otherwise (forward pagination or defaults): * - Use 'first' as the count parameter (default: 10) * - Remove any 'last' parameter to avoid ambiguity * * @template T Type that extends PaginationParams * @param {T} params - Original pagination parameters * @returns {T} Normalized pagination parameters with consistent values * @public */ export declare function normalizePaginationParams<T extends PaginationParams>(params: T): T; /** * Creates a formatted pagination help object for API responses * @param pageInfo The page information to create help documentation for * @returns Pagination help documentation object * @public */ export declare function createPaginationHelp(pageInfo: PageInfo): Record<string, unknown>; /** * Creates a detailed pagination help object for API responses with more examples * @param pageInfo The page information to create help documentation for * @param itemCount The number of items in the current page * @returns Enhanced pagination help documentation object * @public */ export declare function createEnhancedPaginationHelp(pageInfo: PageInfo, itemCount: number): Record<string, unknown>; /** * Handles page_size parameter as an alias for first * @param params Pagination parameters that may include page_size * @returns Normalized params with first set appropriately * @public */ export declare function handlePageSizeAlias(params: PaginationParams): PaginationParams; /** * Determines if multi-page fetching is needed based on parameters * @param params Pagination parameters * @returns Whether multiple pages should be fetched * @public */ export declare function shouldFetchMultiplePages(params: PaginationParams): boolean; /** * Creates pagination metadata from a standard response * @param response Paginated response * @param pagesFetched Number of pages fetched (for multi-page operations) * @returns User-friendly pagination metadata * @public */ export declare function createPaginationMetadata<T>(response: PaginatedResponse<T>, pagesFetched?: number): PaginationMetadata;