deepsource-mcp-server
Version:
Model Context Protocol server for DeepSource
58 lines (57 loc) • 2.67 kB
TypeScript
/**
* @fileoverview Pagination manager for handling multi-page data fetching
* This module provides utilities for orchestrating pagination across multiple pages.
*/
import { PaginationParams, PaginatedResponse, MultiPageOptions, MultiPageResult, PaginatedResponseWithMetadata } from './types.js';
/**
* Type for a function that fetches a page of data
* @template T The type of items being fetched
*/
export type PageFetcher<T> = (cursor?: string, pageSize?: number) => Promise<PaginatedResponse<T>>;
/**
* Fetches multiple pages of data with configurable limits
* @template T The type of items being fetched
* @param fetcher Function that fetches a single page
* @param options Configuration for multi-page fetching
* @returns Aggregated results from all fetched pages
*/
export declare function fetchMultiplePages<T>(fetcher: PageFetcher<T>, options?: MultiPageOptions): Promise<MultiPageResult<T>>;
/**
* Adds user-friendly pagination metadata to a standard response
* @template T The type of items in the response
* @param response Standard paginated response
* @param pagesFetched Number of pages that were fetched (for multi-page operations)
* @param limitReached Whether a max_pages limit was reached
* @returns Response with additional metadata
*/
export declare function addPaginationMetadata<T>(response: PaginatedResponse<T>, pagesFetched?: number, limitReached?: boolean): PaginatedResponseWithMetadata<T>;
/**
* Handles pagination parameters including page_size alias and max_pages
* @param params Raw pagination parameters from user input
* @returns Normalized parameters ready for API calls
*/
export declare function processPaginationParams(params: PaginationParams): {
normalizedParams: PaginationParams;
maxPages?: number;
};
/**
* Creates a pagination iterator for async iteration over pages
* @template T The type of items being fetched
* @param fetcher Function that fetches a single page
* @param pageSize Size of each page
* @returns Async iterator for pages
*/
export declare function createPaginationIterator<T>(fetcher: PageFetcher<T>, pageSize?: number): AsyncIterable<T[]>;
/**
* Validates cursor format and checks for expiration
* @param cursor The cursor to validate
* @returns Whether the cursor is valid
*/
export declare function isValidCursor(cursor: string | undefined): boolean;
/**
* Merges multiple paginated responses into a single response
* @template T The type of items being merged
* @param responses Array of paginated responses to merge
* @returns Merged paginated response
*/
export declare function mergeResponses<T>(responses: PaginatedResponse<T>[]): PaginatedResponse<T>;