import type { Page } from './types'; /** * getNextPageParam factory for offset/total infinite queries that fetch * Page envelopes (items + total + limit + offset) and stop when the * loaded count reaches the server-reported total. * * Use with TanStack svelte-query's createInfiniteQuery: * getNextPageParam: pageGetNextPageParam() * * NOTE: the spec for this task described a bare-array shape * (lastPage: T[], pageSize-based stop). No call site in this repo uses * that shape — every paged endpoint returns Page. The helper matches * the actual canonical shape so the 8 verbatim copies can collapse. */ export function pageGetNextPageParam() { return (last: Page): number | undefined => { const loaded = last.offset + last.items.length; return loaded >= last.total ? undefined : loaded; }; }