// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { AbstractPage, Response, APIClient, FinalRequestOptions, PageInfo } from './core'; export interface PageResponse { data: Array; object: string; } /** * Note: no pagination actually occurs yet, this is for forwards-compatibility. */ export class Page extends AbstractPage implements PageResponse { data: Array; object: string; constructor(client: APIClient, response: Response, body: PageResponse, options: FinalRequestOptions) { super(client, response, body, options); this.data = body.data || []; this.object = body.object; } getPaginatedItems(): Item[] { return this.data ?? []; } // @deprecated Please use `nextPageInfo()` instead /** * This page represents a response that isn't actually paginated at the API level * so there will never be any next page params. */ nextPageParams(): null { return null; } nextPageInfo(): null { return null; } } export interface CursorPageResponse { data: Array; } export interface CursorPageParams { after?: string; limit?: number; } export class CursorPage extends AbstractPage implements CursorPageResponse { data: Array; constructor( client: APIClient, response: Response, body: CursorPageResponse, options: FinalRequestOptions, ) { super(client, response, body, options); this.data = body.data || []; } getPaginatedItems(): Item[] { return this.data ?? []; } // @deprecated Please use `nextPageInfo()` instead nextPageParams(): Partial | null { const info = this.nextPageInfo(); if (!info) return null; if ('params' in info) return info.params; const params = Object.fromEntries(info.url.searchParams); if (!Object.keys(params).length) return null; return params; } nextPageInfo(): PageInfo | null { const data = this.getPaginatedItems(); if (!data.length) { return null; } const id = data[data.length - 1]?.id; if (!id) { return null; } return { params: { after: id } }; } }