import type { PaginatedResult } from "./types"; export const DEFAULT_PAGE_SIZE = 20; /** * Builds a PaginatedResult from rows fetched with limit+1 strategy. * Caller should fetch `limit + 1` rows — the extra row determines hasNextPage. */ export function buildPaginatedResult( rows: T[], limit: number, total?: number, ): PaginatedResult { const hasNextPage = rows.length > limit; const items = hasNextPage ? rows.slice(0, limit) : rows; const result: PaginatedResult = { items, hasNextPage }; if (total !== undefined) { result.total = total; } return result; }