UNPKG

tianji-mcp-server

Version:

Tianji MCP Server

33 lines 1.02 kB
/** * Generic paginated data fetcher * Automatically fetches all pages of data using a cursor-based pagination approach */ export async function fetchAllPaginatedData(fetchFunction, params) { const allResults = []; let currentCursor = params.cursor; let hasMore = true; while (hasMore) { // Create a new params object with the current cursor const currentParams = { ...params, cursor: currentCursor, }; const results = await fetchFunction(currentParams); // Add current page results to the total results array if (results.items && Array.isArray(results.items)) { allResults.push(...results.items); } // Check if there are more pages if (results.nextCursor) { currentCursor = results.nextCursor; } else { hasMore = false; } } return { total: allResults.length, items: allResults, }; } //# sourceMappingURL=pagination.js.map