orb-billing
Version:
The official TypeScript library for the Orb API
67 lines • 2.74 kB
text/typescript
import { FinalRequestOptions } from "../internal/request-options.mjs";
import { type Orb } from "../client.mjs";
import { APIPromise } from "./api-promise.mjs";
import { type APIResponseProps } from "../internal/parse.mjs";
export type PageRequestOptions = Pick<FinalRequestOptions, 'query' | 'headers' | 'body' | 'path' | 'method'>;
export declare abstract class AbstractPage<Item> implements AsyncIterable<Item> {
#private;
protected options: FinalRequestOptions;
protected response: Response;
protected body: unknown;
constructor(client: Orb, response: Response, body: unknown, options: FinalRequestOptions);
abstract nextPageRequestOptions(): PageRequestOptions | null;
abstract getPaginatedItems(): Item[];
hasNextPage(): boolean;
getNextPage(): Promise<this>;
iterPages(): AsyncGenerator<this>;
[Symbol.asyncIterator](): AsyncGenerator<Item>;
}
/**
* This subclass of Promise will resolve to an instantiated Page once the request completes.
*
* It also implements AsyncIterable to allow auto-paginating iteration on an unawaited list call, eg:
*
* for await (const item of client.items.list()) {
* console.log(item)
* }
*/
export declare class PagePromise<PageClass extends AbstractPage<Item>, Item = ReturnType<PageClass['getPaginatedItems']>[number]> extends APIPromise<PageClass> implements AsyncIterable<Item> {
constructor(client: Orb, request: Promise<APIResponseProps>, Page: new (...args: ConstructorParameters<typeof AbstractPage>) => PageClass);
/**
* Allow auto-paginating iteration on an unawaited list call, eg:
*
* for await (const item of client.items.list()) {
* console.log(item)
* }
*/
[Symbol.asyncIterator](): AsyncGenerator<Item>;
}
export interface PageResponse<Item> {
data: Array<Item>;
pagination_metadata: PageResponse.PaginationMetadata;
}
export declare namespace PageResponse {
interface PaginationMetadata {
has_more: boolean;
next_cursor: string | null;
}
}
export interface PageParams {
/**
* Cursor for pagination. This can be populated by the `next_cursor` value returned
* from the initial request.
*/
cursor?: string | null;
/**
* The number of items to fetch. Defaults to 20.
*/
limit?: number;
}
export declare class Page<Item> extends AbstractPage<Item> implements PageResponse<Item> {
data: Array<Item>;
pagination_metadata: PageResponse.PaginationMetadata;
constructor(client: Orb, response: Response, body: PageResponse<Item>, options: FinalRequestOptions);
getPaginatedItems(): Item[];
nextPageRequestOptions(): PageRequestOptions | null;
}
//# sourceMappingURL=pagination.d.mts.map