UNPKG

splitwise

Version:

A TypeScript SDK for the Splitwise API.

36 lines 1.98 kB
/** * Pagination helper for Splitwise list endpoints. * * Splitwise uses a simple `limit`/`offset` scheme with no continuation tokens, * so a "page" is exhausted when the server returns fewer rows than requested * (or none at all). `PagedResult` wraps that loop in a value that is: * - awaitable: `await result` resolves to the first page's array (sends the * user's `limit` as-is so the server's default applies when omitted) * - async-iterable: `for await (const item of result)` yields every item * - page-iterable: `for await (const page of result.byPage())` yields arrays * * Iteration needs a known page size to detect end-of-data, so when iterating * without an explicit `limit` the SDK uses `ITERATION_PAGE_SIZE` for batching. * * The first page fetched via `await` is cached, so repeated awaits don't * re-hit the network. Iteration always starts a fresh sequence from the * configured offset. */ import type { HttpClient, RequestOverrides } from './http.js'; export interface PagedResultOptions extends RequestOverrides { /** Page size. If omitted, the server's default applies for `await result`, * and `ITERATION_PAGE_SIZE` (100) applies for iteration. */ limit?: number; /** Starting offset; default 0. */ offset?: number; /** Other query params to send with each page request. */ query?: Record<string, unknown>; } export interface PagedResult<T> extends AsyncIterable<T> { /** Awaitable: returns the first page array. */ then<TResult1 = T[], TResult2 = never>(onfulfilled?: ((value: T[]) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>; /** Page-by-page iteration. */ byPage(): AsyncIterable<T[]>; } export declare function createPagedResult<T>(http: HttpClient, path: string, unwrapKey: string, options?: PagedResultOptions): PagedResult<T>; //# sourceMappingURL=pagination.d.ts.map