@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
35 lines • 1.88 kB
TypeScript
import type { PageFetch } from '../../types.ts';
/** Notion's continuation: `next_cursor`, while `has_more` holds. */
export declare function hasMoreCursor(data: Readonly<Record<string, unknown>>): string | null;
/**
* Airtable's continuation: an `offset` on every page but the last. Records
* drop the key on the last page and comments send it as null; both read as
* the end.
*/
export declare function offsetCursor(data: Readonly<Record<string, unknown>>): string | null;
/** Where a cursor-paginated reply keeps its items and its cursor. */
export interface PageShape {
readonly itemsKey: string;
readonly nextCursor: (data: Readonly<Record<string, unknown>>) => string | null;
}
export declare const HAS_MORE_PAGES: PageShape;
/**
* Collect every item from a cursor-paginated endpoint.
*
* The default reply protocol is the `results` / `has_more` / `next_cursor`
* shape (Notion's); `shape` names another one (an Airtable list is `records`
* plus an `offset` that vanishes on the last page). Where the resume cursor
* goes on the request — a `start_cursor` body field, a query parameter — is
* the caller's, so `fetchPage` owns that merge. Pagination stops when the
* reply stops naming a cursor, and fails with `PaginationStalledError` when
* it names one it already sent. `maxResults` stops early and slices the tail
* of the last page.
*/
export declare function cursorItems(fetchPage: PageFetch, maxResults?: number, shape?: PageShape): Promise<unknown[]>;
/**
* Each page's items from a cursor-paginated endpoint, the next page fetched
* only when the caller pulls it. Fails with `PaginationStalledError` when the
* reply names a cursor it already sent. Mirrors Python's `cursor_pages`.
*/
export declare function cursorPages(fetchPage: PageFetch, shape?: PageShape): AsyncGenerator<unknown[], void>;
//# sourceMappingURL=paginate.d.ts.map